<?phpnamespace App\Revisited\Render;/** * An indexed mesh being built in PHP (once, at load time), in the vertex format of the props / bodies shaders: * x y z | nx ny nz | u v (atlas) | r g b (tint, > 1 = glow) | ao sway | bone = STRIDE floats per vertex. * * Things (not skinned): "sway" is the wind's push (leaves, fronds), "bone" the gloss of the surface (0 matt .. 1 wet, * metal). Bodies (skinned): "sway" is the gloss (wet eyes, chitin, scales), "bone" packs two bones and the weight of * the second one: b1 + 32 * b2 + 1024 * round(w * 32) (see skin(); Shaders SKIN decodes it). * * Geometry goes through a current transform (translate / rotate / scale, push / pop) so that parts are written * in their own frame. UVs are given inside an atlas cell (0..1) and mapped to the cell (see Atlas). */final class Mesh{ public const STRIDE = 14; /** @var list<float> */ public array $v = []; /** @var list<int> */ public array $i = []; /** @var array{0: float, 1: float, 2: float} */ public array $color = [1.0, 1.0, 1.0]; public float $ao = 1.0; public float $sway = 0.0; public float $bone = 0.0; public int $cell = Atlas::PLAIN; /** wind: vertices higher than 0 sway more, by swayK * (y / swayH)² on top of $sway (a trunk bending) */ public float $swayH = 0.0; public float $swayK = 0.0; /** sweep(): the colour of the underside (countershading of animals), null = the same */ public ?array $belly = null; /** @var list<float> 3x4 transform: m0 m1 m2 (x axis) m3 m4 m5 (y) m6 m7 m8 (z) m9 m10 m11 (origin) */ private array $m = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]; /** @var list<list<float>> */ private array $stack = []; public function count(): int { return intdiv(count($this->v), self::STRIDE); } // ---- transform -------------------------------------------------------------------------------- public function push(): self { $this->stack[] = $this->m; return $this; } public function pop(): self { $this->m = array_pop($this->stack) ?? [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]; return $this; } public function reset(): self { $this->m = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]; $this->stack = []; return $this; } public function translate(float $x, float $y, float $z): self { $m = $this->m; $this->m[9] += $m[0] * $x + $m[3] * $y + $m[6] * $z; $this->m[10] += $m[1] * $x + $m[4] * $y + $m[7] * $z; $this->m[11] += $m[2] * $x + $m[5] * $y + $m[8] * $z; return $this; } public function scale(float $x, ?float $y = null, ?float $z = null): self { $y ??= $x; $z ??= $x; for ($k = 0; $k < 3; $k++) { $this->m[$k] *= $x; $this->m[3 + $k] *= $y; $this->m[6 + $k] *= $z; } return $this; } /** Rotation about the local axis 'x', 'y' or 'z' (radians). */ public function rotate(string $axis, float $a): self { $c = cos($a); $s = sin($a); [$p, $q] = match ($axis) { 'x' => [3, 6], // y and z axes turn 'y' => [6, 0], // z and x default => [0, 3], // x and y }; for ($k = 0; $k < 3; $k++) { $u = $this->m[$p + $k]; $w = $this->m[$q + $k]; $this->m[$p + $k] = $u * $c + $w * $s; $this->m[$q + $k] = $w * $c - $u * $s; } return $this; } /** The bones of the next vertices: $b1, blended toward $b2 by $w (0..1). */ public function skin(int $b1, int $b2 = -1, float $w = 0.0): self { if ($b2 < 0 || $w <= 0.0) { $this->bone = (float) $b1; return $this; } $w = max(0.0, min(1.0, $w)); $this->bone = (float) ($b1 + 32 * $b2 + 1024 * (int) round($w * 32)); return $this; } // ---- vertices --------------------------------------------------------------------------------- /** A vertex in the current frame; u, v inside the current atlas cell. @return int its index */ public function vertex(float $x, float $y, float $z, float $nx, float $ny, float $nz, float $u = 0.5, float $v = 0.5): int { $m = $this->m; $px = $m[0] * $x + $m[3] * $y + $m[6] * $z + $m[9]; $py = $m[1] * $x + $m[4] * $y + $m[7] * $z + $m[10]; $pz = $m[2] * $x + $m[5] * $y + $m[8] * $z + $m[11]; $qx = $m[0] * $nx + $m[3] * $ny + $m[6] * $nz; $qy = $m[1] * $nx + $m[4] * $ny + $m[7] * $nz; $qz = $m[2] * $nx + $m[5] * $ny + $m[8] * $nz; $l = sqrt($qx * $qx + $qy * $qy + $qz * $qz) ?: 1.0; [$au, $av] = Atlas::uv($this->cell, $u, $v); $sw = $this->swayH > 0 ? $this->sway + $this->swayK * min(1.0, max(0.0, $py / $this->swayH)) ** 2 : $this->sway; array_push($this->v, $px, $py, $pz, $qx / $l, $qy / $l, $qz / $l, $au, $av, $this->color[0], $this->color[1], $this->color[2], $this->ao, $sw, $this->bone); return intdiv(count($this->v), self::STRIDE) - 1; } /** A vertex whose normal is already in mesh space (foliage: normals pointing out of the crown). */ public function vertexN(float $x, float $y, float $z, float $nx, float $ny, float $nz, float $u, float $v): int { $m = $this->m; $px = $m[0] * $x + $m[3] * $y + $m[6] * $z + $m[9]; $py = $m[1] * $x + $m[4] * $y + $m[7] * $z + $m[10]; $pz = $m[2] * $x + $m[5] * $y + $m[8] * $z + $m[11]; $l = sqrt($nx * $nx + $ny * $ny + $nz * $nz) ?: 1.0; [$au, $av] = Atlas::uv($this->cell, $u, $v); $sw = $this->swayH > 0 ? $this->sway + $this->swayK * min(1.0, max(0.0, $py / $this->swayH)) ** 2 : $this->sway; array_push($this->v, $px, $py, $pz, $nx / $l, $ny / $l, $nz / $l, $au, $av, $this->color[0], $this->color[1], $this->color[2], $this->ao, $sw, $this->bone); return intdiv(count($this->v), self::STRIDE) - 1; } /** The current frame's point (for foliage normals). @return array{0: float, 1: float, 2: float} */ public function point(float $x, float $y, float $z): array { $m = $this->m; return [$m[0] * $x + $m[3] * $y + $m[6] * $z + $m[9], $m[1] * $x + $m[4] * $y + $m[7] * $z + $m[10], $m[2] * $x + $m[5] * $y + $m[8] * $z + $m[11]]; } public function tri(int $a, int $b, int $c): void { array_push($this->i, $a, $b, $c); } public function quad(int $a, int $b, int $c, int $d): void { array_push($this->i, $a, $b, $c, $a, $c, $d); } // ---- primitives ------------------------------------------------------------------------------- /** * A tube through rings [x, y, z, radius] (a trunk, a branch, a limb): $sides around, the texture repeated * once per $vRepeat metres of length (a new ring of vertices at each repeat keeps the UVs inside the cell). * @param list<array{0: float, 1: float, 2: float, 3: float}> $rings */ public function tube(array $rings, int $sides = 6, float $vRepeat = 1.0, bool $capTop = false, bool $capBottom = false, float $uRepeat = 1.0): void { $n = count($rings); if ($n < 2) { return; } $vAcc = 0.0; /** @var list<int>|null $prev */ $prev = null; for ($r = 0; $r < $n; $r++) { [$x, $y, $z, $rad] = $rings[$r]; // the ring's frame: its axis follows the tube $a = $rings[max(0, $r - 1)]; $b = $rings[min($n - 1, $r + 1)]; $ax = $b[0] - $a[0]; $ay = $b[1] - $a[1]; $az = $b[2] - $a[2]; $al = sqrt($ax * $ax + $ay * $ay + $az * $az) ?: 1.0; [$ax, $ay, $az] = [$ax / $al, $ay / $al, $az / $al]; // a side vector perpendicular to the axis [$sx, $sy, $sz] = abs($ay) < 0.9 ? [-$az, 0.0, $ax] : [1.0, 0.0, 0.0]; $sl = sqrt($sx * $sx + $sy * $sy + $sz * $sz) ?: 1.0; [$sx, $sy, $sz] = [$sx / $sl, $sy / $sl, $sz / $sl]; $tx = $ay * $sz - $az * $sy; $ty = $az * $sx - $ax * $sz; $tz = $ax * $sy - $ay * $sx; $vv = $vAcc; $wrap = false; if ($r > 0) { $p = $rings[$r - 1]; $vv += sqrt(($x - $p[0]) ** 2 + ($y - $p[1]) ** 2 + ($z - $p[2]) ** 2) / $vRepeat; if ($vv >= 1.0 && $r < $n - 1) { $vv = 1.0; $wrap = true; } $vv = min($vv, 1.0); } /** @var list<int> $ring */ $ring = []; /** @var list<int> $dup */ $dup = []; for ($k = 0; $k <= $sides; $k++) { $ang = $k / $sides * 2 * M_PI; $c = cos($ang); $s = sin($ang); $nx = $sx * $c + $tx * $s; $ny = $sy * $c + $ty * $s; $nz = $sz * $c + $tz * $s; $px = $x + $nx * $rad; $py = $y + $ny * $rad; $pz = $z + $nz * $rad; $ring[] = $this->vertex($px, $py, $pz, $nx, $ny, $nz, $k / $sides * $uRepeat, 1.0 - $vv); if ($wrap) { $dup[] = $this->vertex($px, $py, $pz, $nx, $ny, $nz, $k / $sides * $uRepeat, 1.0); } } if ($prev !== null) { for ($k = 0; $k < $sides; $k++) { $this->quad($prev[$k], $prev[$k + 1], $ring[$k + 1], $ring[$k]); } } $prev = $wrap ? $dup : $ring; $vAcc = $wrap ? 0.0 : $vv; } if ($capTop) { $this->cap($rings[$n - 1], $rings[$n - 2], $sides); } if ($capBottom) { $this->cap($rings[0], $rings[1], $sides); } } /** @param array{0: float, 1: float, 2: float, 3: float} $at @param array{0: float, 1: float, 2: float, 3: float} $from */ private function cap(array $at, array $from, int $sides): void { $ax = $at[0] - $from[0]; $ay = $at[1] - $from[1]; $az = $at[2] - $from[2]; $l = sqrt($ax * $ax + $ay * $ay + $az * $az) ?: 1.0; [$ax, $ay, $az] = [$ax / $l, $ay / $l, $az / $l]; [$sx, $sy, $sz] = abs($ay) < 0.9 ? [-$az, 0.0, $ax] : [1.0, 0.0, 0.0]; $sl = sqrt($sx * $sx + $sy * $sy + $sz * $sz) ?: 1.0; [$sx, $sy, $sz] = [$sx / $sl, $sy / $sl, $sz / $sl]; $tx = $ay * $sz - $az * $sy; $ty = $az * $sx - $ax * $sz; $tz = $ax * $sy - $ay * $sx; $c0 = $this->vertex($at[0], $at[1], $at[2], $ax, $ay, $az, 0.5, 0.5); $ring = []; for ($k = 0; $k <= $sides; $k++) { $ang = $k / $sides * 2 * M_PI; $c = cos($ang); $s = sin($ang); $ring[] = $this->vertex($at[0] + ($sx * $c + $tx * $s) * $at[3], $at[1] + ($sy * $c + $ty * $s) * $at[3], $at[2] + ($sz * $c + $tz * $s) * $at[3], $ax, $ay, $az, 0.5 + 0.5 * $c, 0.5 + 0.5 * $s); } for ($k = 0; $k < $sides; $k++) { $this->tri($c0, $ring[$k], $ring[$k + 1]); } } /** A box centred on (x, y, z), sizes sx sy sz (each face shows the whole cell, or $uv metres per repeat). */ public function box(float $x, float $y, float $z, float $sx, float $sy, float $sz, float $uvScale = 0.0): void { $hx = $sx / 2; $hy = $sy / 2; $hz = $sz / 2; $faces = [ [[1, 0, 0], [0, 0, -1], [0, 1, 0], $hx, $sz, $sy], [[-1, 0, 0], [0, 0, 1], [0, 1, 0], $hx, $sz, $sy], [[0, 1, 0], [1, 0, 0], [0, 0, -1], $hy, $sx, $sz], [[0, -1, 0], [1, 0, 0], [0, 0, 1], $hy, $sx, $sz], [[0, 0, 1], [1, 0, 0], [0, 1, 0], $hz, $sx, $sy], [[0, 0, -1], [-1, 0, 0], [0, 1, 0], $hz, $sx, $sy], ]; foreach ($faces as [$n, $u, $w, $d, $lu, $lw]) { $hu = $lu / 2; $hw = $lw / 2; $mu = $uvScale > 0 ? min(1.0, $lu / $uvScale) : 1.0; $mw = $uvScale > 0 ? min(1.0, $lw / $uvScale) : 1.0; $vs = []; foreach ([[-1, -1], [1, -1], [1, 1], [-1, 1]] as [$a, $b]) { $vs[] = $this->vertex( $x + $n[0] * $d + $u[0] * $a * $hu + $w[0] * $b * $hw, $y + $n[1] * $d + $u[1] * $a * $hu + $w[1] * $b * $hw, $z + $n[2] * $d + $u[2] * $a * $hu + $w[2] * $b * $hw, $n[0], $n[1], $n[2], ($a + 1) / 2 * $mu, 1 - ($b + 1) / 2 * $mw ); } $this->quad($vs[0], $vs[1], $vs[2], $vs[3]); } } /** * An ellipsoid (rx, ry, rz) displaced by noise ($rough: a rock, a lump), lat x lon vertices. * $flatBottom: the lower half squashed (rocks sit on the ground). */ public function ellipsoid(float $x, float $y, float $z, float $rx, float $ry, float $rz, int $lat = 6, int $lon = 8, float $rough = 0.0, int $seed = 1, float $bottom = 1.0): void { $base = $this->count(); $rows = []; for ($a = 0; $a <= $lat; $a++) { $phi = M_PI * $a / $lat - M_PI / 2; $row = []; for ($b = 0; $b <= $lon; $b++) { $th = 2 * M_PI * $b / $lon; $nx = cos($phi) * cos($th); $ny = sin($phi); $nz = cos($phi) * sin($th); $k = 1.0; if ($rough > 0 && $a > 0 && $a < $lat) { $bb = $b % $lon; $k += $rough * (self::hash($seed, $a * 31 + $bb) - 0.5) * 2; } $yy = $ny < 0 ? $ny * $bottom : $ny; $row[] = $this->vertex($x + $nx * $rx * $k, $y + $yy * $ry * $k, $z + $nz * $rz * $k, $nx / $rx, $ny / $ry, $nz / $rz, $b / $lon, 1 - $a / $lat); } $rows[] = $row; } for ($a = 0; $a < $lat; $a++) { for ($b = 0; $b < $lon; $b++) { $this->quad($rows[$a][$b], $rows[$a][$b + 1], $rows[$a + 1][$b + 1], $rows[$a + 1][$b]); } } unset($base); } /** * A foliage card: a quad of w x h around (x, y, z), turned by $yaw about y and tilted by $tilt, with normals * pointing from $centre (the crown's centre, in this frame) outwards: soft, round lighting. * @param array{0: float, 1: float, 2: float} $centre */ public function card(float $x, float $y, float $z, float $w, float $h, float $yaw, float $tilt, array $centre, float $bend = 0.0): void { $c = cos($yaw); $s = sin($yaw); $ct = cos($tilt); $st = sin($tilt); $corners = [[-0.5, -0.5, 0, 1], [0.5, -0.5, 1, 1], [0.5, 0.5, 1, 0], [-0.5, 0.5, 0, 0]]; $vs = []; $cw = $this->point($centre[0], $centre[1], $centre[2]); foreach ($corners as [$a, $b, $u, $v]) { // in the card's plane: a along (c, 0, -s), b up then tilted toward (s, 0, c) $by = $b * $h * $ct; $bf = $b * $h * $st + $bend * ($a * $a); $px = $x + $a * $w * $c + $bf * $s; $py = $y + $by; $pz = $z - $a * $w * $s + $bf * $c; $p = $this->point($px, $py, $pz); $vs[] = $this->vertexN($px, $py, $pz, $p[0] - $cw[0], $p[1] - $cw[1] + 0.3, $p[2] - $cw[2], $u, $v); } $this->quad($vs[0], $vs[1], $vs[2], $vs[3]); } /** A flat quad given its 4 corners (counter-clockwise seen from the front) and its normal. */ public function quad4(array $a, array $b, array $c, array $d, array $n, float $u0 = 0, float $v0 = 0, float $u1 = 1, float $v1 = 1): void { $i0 = $this->vertex($a[0], $a[1], $a[2], $n[0], $n[1], $n[2], $u0, $v1); $i1 = $this->vertex($b[0], $b[1], $b[2], $n[0], $n[1], $n[2], $u1, $v1); $i2 = $this->vertex($c[0], $c[1], $c[2], $n[0], $n[1], $n[2], $u1, $v0); $i3 = $this->vertex($d[0], $d[1], $d[2], $n[0], $n[1], $n[2], $u0, $v0); $this->quad($i0, $i1, $i2, $i3); } /** * An organic shape swept along a path of elliptic sections [x, y, z, rx, ry, b1, b2, w, colour?] (a torso, a neck, * a limb, a snout): rx is the half width (horizontal, across the path), ry the half height; each section's bones * blend its ring (smooth joints); a section's colour (index 8) holds from there on. $belly (if set) colours the * underside. The texture runs once along the whole path. * @param list<array<int, mixed>> $secs */ public function sweep(array $secs, int $sides = 10, float $uRepeat = 1.0, ?float $twist = null): void { $n = count($secs); if ($n < 2) { return; } $len = [0.0]; for ($k = 1; $k < $n; $k++) { $a = $secs[$k - 1]; $b = $secs[$k]; $len[$k] = $len[$k - 1] + sqrt(($b[0] - $a[0]) ** 2 + ($b[1] - $a[1]) ** 2 + ($b[2] - $a[2]) ** 2); } $total = $len[$n - 1] ?: 1.0; $top = $this->color; $first = $top; $prev = null; for ($k = 0; $k < $n; $k++) { $s = $secs[$k]; $a = $secs[max(0, $k - 1)]; $b = $secs[min($n - 1, $k + 1)]; $tx = $b[0] - $a[0]; $ty = $b[1] - $a[1]; $tz = $b[2] - $a[2]; $tl = sqrt($tx * $tx + $ty * $ty + $tz * $tz) ?: 1.0; [$tx, $ty, $tz] = [$tx / $tl, $ty / $tl, $tz / $tl]; // side: horizontal, across the path; for an upright path, x if (abs($ty) < 0.92) { $sx = $tz; $sy = 0.0; $sz = -$tx; } else { $sx = 1.0; $sy = 0.0; $sz = 0.0; } $sl = sqrt($sx * $sx + $sy * $sy + $sz * $sz) ?: 1.0; [$sx, $sy, $sz] = [$sx / $sl, $sy / $sl, $sz / $sl]; // up: perpendicular to both $ux = $ty * $sz - $tz * $sy; $uy = $tz * $sx - $tx * $sz; $uz = $tx * $sy - $ty * $sx; if ($uy < 0 && abs($ty) < 0.92) { [$ux, $uy, $uz] = [-$ux, -$uy, -$uz]; } if ($twist !== null) { $c = cos($twist * $k); $si = sin($twist * $k); [$sx, $sy, $sz, $ux, $uy, $uz] = [$sx * $c + $ux * $si, $sy * $c + $uy * $si, $sz * $c + $uz * $si, $ux * $c - $sx * $si, $uy * $c - $sy * $si, $uz * $c - $sz * $si]; } if (isset($s[8]) && is_array($s[8])) { $top = $s[8]; $this->color = $top; } $rx = (float) $s[3]; $ry = (float) $s[4]; $this->skin((int) ($s[5] ?? 0), (int) ($s[6] ?? -1), (float) ($s[7] ?? 0.0)); /** @var list<int> $ring */ $ring = []; for ($j = 0; $j <= $sides; $j++) { $ang = $j / $sides * 2 * M_PI; $c = cos($ang); $si = sin($ang); $px = $s[0] + $sx * $rx * $c + $ux * $ry * $si; $py = $s[1] + $sy * $rx * $c + $uy * $ry * $si; $pz = $s[2] + $sz * $rx * $c + $uz * $ry * $si; $nx = $sx * $c / max($rx, 1e-4) + $ux * $si / max($ry, 1e-4); $ny = $sy * $c / max($rx, 1e-4) + $uy * $si / max($ry, 1e-4); $nz = $sz * $c / max($rx, 1e-4) + $uz * $si / max($ry, 1e-4); if ($this->belly !== null) { $wb = max(0.0, min(1.0, -$si * 1.4 - 0.1)); $this->color = [$top[0] + ($this->belly[0] - $top[0]) * $wb, $top[1] + ($this->belly[1] - $top[1]) * $wb, $top[2] + ($this->belly[2] - $top[2]) * $wb]; } $ring[] = $this->vertex($px, $py, $pz, $nx, $ny, $nz, $j / $sides * $uRepeat, $len[$k] / $total); } if ($prev !== null) { for ($j = 0; $j < $sides; $j++) { $this->quad($prev[$j], $prev[$j + 1], $ring[$j + 1], $ring[$j]); } } $prev = $ring; } $this->color = $first; } /** * Appends $src (built in its own frame) through the current transform, colours times the current colour (a held * item in a hand, a part reused). $toBody: the destination is a skinned body: the vertices take the current bone * and the source's gloss (its bone slot, see Shaders) goes to the body's gloss slot (sway). */ public function append(Mesh $src, bool $toBody = false): void { $off = $this->count(); $m = $this->m; $sv = $src->v; $n = count($sv); [$tr, $tg, $tb] = $this->color; for ($k = 0; $k < $n; $k += self::STRIDE) { $x = $sv[$k]; $y = $sv[$k + 1]; $z = $sv[$k + 2]; $nx = $sv[$k + 3]; $ny = $sv[$k + 4]; $nz = $sv[$k + 5]; $qx = $m[0] * $nx + $m[3] * $ny + $m[6] * $nz; $qy = $m[1] * $nx + $m[4] * $ny + $m[7] * $nz; $qz = $m[2] * $nx + $m[5] * $ny + $m[8] * $nz; $l = sqrt($qx * $qx + $qy * $qy + $qz * $qz) ?: 1.0; array_push($this->v, $m[0] * $x + $m[3] * $y + $m[6] * $z + $m[9], $m[1] * $x + $m[4] * $y + $m[7] * $z + $m[10], $m[2] * $x + $m[5] * $y + $m[8] * $z + $m[11], $qx / $l, $qy / $l, $qz / $l, $sv[$k + 6], $sv[$k + 7], $sv[$k + 8] * $tr, $sv[$k + 9] * $tg, $sv[$k + 10] * $tb, $sv[$k + 11], $toBody ? $sv[$k + 13] : $sv[$k + 12], $toBody ? $this->bone : $sv[$k + 13]); } foreach ($src->i as $k) { $this->i[] = $k + $off; } } /** Appends another mesh (already in final coordinates). */ public function merge(Mesh $o): void { $off = $this->count(); array_push($this->v, ...$o->v); foreach ($o->i as $k) { $this->i[] = $k + $off; } } /** * Appends $src turned by $yaw about y, scaled, moved to (x, y, z), its colours times $tint, its ao times $ao * (a placed thing, baked into a chunk). * @param array{0: float, 1: float, 2: float} $tint */ public function place(Mesh $src, float $x, float $y, float $z, float $yaw, float $scale, array $tint = [1.0, 1.0, 1.0], float $ao = 1.0): void { $off = $this->count(); $c = cos($yaw); $s = sin($yaw); $sv = $src->v; $n = count($sv); [$tr, $tg, $tb] = $tint; $out = &$this->v; for ($k = 0; $k < $n; $k += self::STRIDE) { $lx = $sv[$k]; $lz = $sv[$k + 2]; $nx = $sv[$k + 3]; $nz = $sv[$k + 5]; $out[] = $x + ($lx * $c + $lz * $s) * $scale; $out[] = $y + $sv[$k + 1] * $scale; $out[] = $z + ($lz * $c - $lx * $s) * $scale; $out[] = $nx * $c + $nz * $s; $out[] = $sv[$k + 4]; $out[] = $nz * $c - $nx * $s; $out[] = $sv[$k + 6]; $out[] = $sv[$k + 7]; $out[] = $sv[$k + 8] * $tr; $out[] = $sv[$k + 9] * $tg; $out[] = $sv[$k + 10] * $tb; $out[] = $sv[$k + 11] * $ao; $out[] = $sv[$k + 12] * $scale; $out[] = $sv[$k + 13]; } unset($out); foreach ($src->i as $k) { $this->i[] = $k + $off; } } /** A float 0..1 from two integers (deterministic, 32-bit safe). */ public static function hash(int $a, int $b): float { $x = sin(fmod($a * 12.9898 + $b * 78.233, 6283.1853)) * 43758.5453; return $x - floor($x); }}