ZH
games/rob-revisited / src / Revisited / Render / Props.php · commit f9a1307
<?phpnamespace App\Revisited\Render;/** * The Wave 2 things (docs/reborn.md "Wave 2"), built in code like Models (which calls them): the colony shuttle, * its parts, the raft, the river people's bridges, huts, stalls and totems, the colony's terminals and drones, * the volcanic coast (fumaroles, geysers), wrecks, racks, a forge. Metres, y up, ground at 0, facing +z. */final class Props{    private static function rnd(int $seed, int $k): float    {        return Mesh::hash($seed, $k);    }    /** A flat disc on the ground (ash, scorch, a pool): $col at the centre fading to $edge. */    private static function disc(Mesh $m, float $x, float $y, float $z, float $r, array $col, array $edge, int $seed, int $n = 14): void    {        $m->color = $col;        $c = $m->vertex($x, $y, $z, 0, 1, 0, 0.5, 0.5);        $ring = [];        for ($k = 0; $k <= $n; $k++) {            $a = $k / $n * 2 * M_PI;            $rr = $r * (0.8 + 0.35 * self::rnd($seed, $k % $n));            $m->color = $edge;            $ring[] = $m->vertex($x + cos($a) * $rr, $y, $z + sin($a) * $rr, 0, 1, 0, 0.5 + 0.5 * cos($a), 0.5 + 0.5 * sin($a));        }        for ($k = 0; $k < $n; $k++) {            $m->tri($c, $ring[$k + 1], $ring[$k]);        }    }    /**     * The Halde lander: a 30 m colony shuttle lying on the black sand of the coast, on its landing legs (one bent),     * delta wings, a tail fin, three scorched engine bells, an open hatch with its ramp, soot and rain streaks,     * lianas and moss taking it back.     */    public static function shuttle(Mesh $m, int $seed, int $lod): void    {        $m->push()->translate(0, 3.0, 0)->rotate('z', 0.1)->rotate('x', -0.05);        $hull = [1.0, 1.0, 0.98];        // the fuselage        $m->cell = Atlas::HULL;        $m->color = $hull;        $m->bone = 0.4;        $secs = [];        $prof = [[-13.5, 2.1, 2.0], [-12.5, 2.6, 2.4], [-9.0, 2.9, 2.6], [-3.0, 3.0, 2.7], [3.0, 3.0, 2.65], [7.5, 2.8, 2.5], [10.5, 2.3, 2.1], [12.5, 1.6, 1.55], [13.6, 0.9, 0.95], [14.2, 0.3, 0.35]];        foreach ($prof as [$z, $rx, $ry]) {            $secs[] = [0.0, 0.0 + ($z > 10 ? -($z - 10) * 0.12 : 0.0), $z, $rx, $ry, 0];        }        $m->sweep($secs, $lod === 0 ? 20 : 14, 1.0);        // soot over the rear and the belly        $m->cell = Atlas::CHAR;        $m->color = [1.0, 1.0, 1.0];        $m->sweep([[0.0, 0.0, -13.62, 2.2, 2.1, 0], [0.0, 0.0, -12.5, 2.7, 2.5, 0], [0.0, 0.0, -10.5, 2.9, 2.64, 0], [0.0, 0.0, -9.6, 2.88, 2.6, 0]], $lod === 0 ? 20 : 14);        $m->cell = Atlas::HULL;        // cockpit windows        $m->cell = Atlas::PLAIN;        $m->color = [0.06, 0.09, 0.12];        $m->bone = 1.0;        foreach ([-1, 0, 1] as $k) {            $m->push()->translate($k * 0.85, 1.25, 11.4 - abs($k) * 0.3)->rotate('y', $k * 0.35)->rotate('x', -0.62);            $m->box(0, 0, 0, 0.75, 0.06, 0.6);            $m->pop();        }        $m->bone = 0.4;        // a dorsal spine and hatches        $m->cell = Atlas::METAL;        $m->color = [0.75, 0.76, 0.78];        $m->box(0, 2.72, -2.0, 0.8, 0.25, 14.0, 4.0);        // the delta wings        $m->cell = Atlas::HULL;        $m->color = [0.95, 0.95, 0.92];        foreach ([-1, 1] as $sd) {            $root0 = [$sd * 2.4, -0.9, -11.0];            $root1 = [$sd * 2.6, -0.8, 3.5];            $tip0 = [$sd * 10.5, -0.5, -12.0];            $tip1 = [$sd * 10.0, -0.45, -8.5];            foreach ([0.18, -0.18] as $th) {                $n = [0.0, $th > 0 ? 1.0 : -1.0, 0.0];                $a = [$root0[0], $root0[1] + $th, $root0[2]];                $b = [$root1[0], $root1[1] + $th, $root1[2]];                $c = [$tip1[0], $tip1[1] + $th * 0.4, $tip1[2]];                $d = [$tip0[0], $tip0[1] + $th * 0.4, $tip0[2]];                $m->quad4($a, $b, $c, $d, $n, 0.0, 0.0, 1.0, 1.0);            }            // leading edge and tip            $m->tube([[$root1[0], $root1[1], $root1[2], 0.2], [$tip1[0], $tip1[1], $tip1[2], 0.08]], 6, 3.0);            $m->tube([[$tip1[0], $tip1[1], $tip1[2], 0.08], [$tip0[0], $tip0[1], $tip0[2], 0.08]], 6, 3.0);            $m->tube([[$tip0[0], $tip0[1], $tip0[2], 0.1], [$root0[0], $root0[1], $root0[2], 0.2]], 6, 3.0);            // the orange band on the wing            $m->cell = Atlas::PLAIN;            $m->color = [1.1, 0.48, 0.18];            $m->quad4([$sd * 6.0, -0.68, -10.6], [$sd * 6.0, -0.68, -4.0], [$sd * 7.0, -0.65, -5.6], [$sd * 7.0, -0.65, -10.9], [0, 1, 0]);            $m->cell = Atlas::HULL;            $m->color = [0.95, 0.95, 0.92];        }        // the tail fin        $m->quad4([0.15, 2.4, -12.8], [0.15, 2.6, -6.5], [0.15, 7.0, -12.0], [0.15, 7.2, -13.8], [1, 0, 0]);        $m->quad4([-0.15, 2.4, -12.8], [-0.15, 7.2, -13.8], [-0.15, 7.0, -12.0], [-0.15, 2.6, -6.5], [-1, 0, 0]);        $m->tube([[0, 2.6, -6.5, 0.16], [0, 7.0, -12.0, 0.12], [0, 7.2, -13.8, 0.1]], 6, 3.0);        // engines: three bells, scorched inside        // the engine block: a flat plate closing the tail, three bells (thin flaring walls, sooty inside)        $m->cell = Atlas::METAL;        $m->color = [0.3, 0.29, 0.29];        $m->sweep([[0.0, 0.0, -13.7, 2.0, 1.9, 0], [0.0, 0.0, -13.72, 1.0, 0.9, 0], [0.0, 0.0, -13.74, 0.05, 0.05, 0]], 16);        foreach ([[-1.05, -0.55], [1.05, -0.55], [0.0, 0.8]] as [$ex, $ey]) {            $m->cell = Atlas::METAL;            $m->color = [0.42, 0.4, 0.4];            $m->tube([[$ex, $ey, -13.6, 0.32], [$ex, $ey, -14.0, 0.36], [$ex, $ey, -14.6, 0.55], [$ex, $ey, -15.2, 0.8]], 14, 1.0);            $m->cell = Atlas::CHAR;            $m->color = [0.55, 0.5, 0.48];            $m->tube([[$ex, $ey, -15.2, 0.77], [$ex, $ey, -14.6, 0.52], [$ex, $ey, -14.0, 0.33], [$ex, $ey, -13.65, 0.2]], 14, 1.0, true);        }        // the hatch, open, and its ramp to the ground        $m->cell = Atlas::PLAIN;        $m->color = [0.03, 0.03, 0.035];        $m->quad4([2.98, -1.2, 2.0], [2.98, -1.2, 4.2], [2.9, 1.0, 4.2], [2.9, 1.0, 2.0], [1, 0, 0]);        $m->cell = Atlas::METAL;        $m->color = [0.7, 0.7, 0.72];        $m->quad4([3.0, -1.2, 2.0], [5.8, -3.05, 2.0], [5.8, -3.05, 4.2], [3.0, -1.2, 4.2], [0.55, 0.83, 0.0], 0.0, 0.0, 1.0, 1.0);        $m->cell = Atlas::PLANKS;        $m->color = [0.4, 0.4, 0.42];        for ($k = 0; $k < 6; $k++) {            $t = ($k + 0.5) / 6;            $m->box(3.0 + 2.8 * $t, -1.2 - 1.85 * $t + 0.04, 3.1, 0.08, 0.05, 2.1);        }        // landing legs: struts and pads; the front right one bent        $m->cell = Atlas::METAL;        $m->color = [0.62, 0.62, 0.64];        foreach ([[-1.9, -9.0, 0.0], [1.9, -9.0, 0.0], [-1.7, 7.0, 0.0], [1.7, 7.0, 0.9]] as $i => [$lx, $lz, $bent]) {            $foot = [$lx * 1.5 + ($bent > 0 ? 0.8 : 0.0), -3.05, $lz + ($bent > 0 ? 0.8 : 0.0)];            $m->tube([[$lx, -1.6, $lz, 0.22], [$lx * 1.3, -2.4 + $bent * 0.5, $lz, 0.18], [$foot[0], $foot[1] + 0.25, $foot[2], 0.15]], 8, 2.0);            $m->tube([[$lx * 0.6, -2.0, $lz - 1.4, 0.08], [$lx * 1.25, -2.5, $lz, 0.08]], 6, 2.0);            $m->tube([[$foot[0], $foot[1], $foot[2], 0.75], [$foot[0], $foot[1] + 0.18, $foot[2], 0.65]], 10, 1.0, true);        }        $m->bone = 0.0;        // overgrowth: moss on top, lianas from the wings, a bush at the foot        $m->bone = 0.0;        if ($lod < 2) {            $m->cell = Atlas::MOSS;            $m->color = [0.85, 1.0, 0.8];            for ($k = 0; $k < 7; $k++) {                $z = -11.0 + $k * 3.3;                $m->ellipsoid((self::rnd($seed, $k) - 0.5) * 2.2, 2.55 + ($z > 10 ? -1.0 : 0.0), $z, 0.9 + self::rnd($seed, 10 + $k), 0.22, 1.3, 3, 7, 0.2, $k);            }            $m->cell = Atlas::LIANA;            $m->sway = 0.35;            foreach ([-1, 1] as $sd) {                for ($k = 0; $k < ($lod === 0 ? 4 : 2); $k++) {                    $x = $sd * (3.5 + $k * 1.7);                    $z = -11.6 + $k * 0.3 + self::rnd($seed, 20 + $k) * 1.5;                    $len = 0.9 + self::rnd($seed, 30 + $k) * 1.1;                    $m->card($x, -0.95 - $len / 2, $z, 0.8, $len, 0.3 * $k, 0.0, [$x, -0.5, $z]);                    $m->card($x, -0.95 - $len / 2, $z, 0.8, $len, 0.3 * $k + 1.57, 0.0, [$x, -0.5, $z]);                }            }            $m->cell = Atlas::BIG_LEAVES;            foreach ([[3.2, -6.0], [-3.4, 1.0], [-2.0, 10.0], [4.0, 8.5]] as $k => [$x, $z]) {                for ($c = 0; $c < 3; $c++) {                    $m->card($x, -2.3, $z, 1.8, 1.6, $c * 1.05 + $k, -0.15, [$x, -3.0, $z]);                }            }            $m->sway = 0.0;        }        $m->pop();        $m->color = [1.0, 1.0, 1.0];    }    /** A part salvaged from the colony: 0 an engine bell, 1 a fuel cell (glowing ring), 2 an avionics box. */    public static function shuttlePart(Mesh $m, int $variant): void    {        $m->bone = 0.5;        if ($variant === 0) {            $m->cell = Atlas::METAL;            $m->color = [0.55, 0.53, 0.52];            $m->push()->translate(0, 0.45, 0)->rotate('x', M_PI / 2 - 0.3);            $m->tube([[0, -0.3, 0, 0.18], [0, -0.1, 0, 0.22], [0, 0.4, 0, 0.42]], 12, 1.0);            $m->cell = Atlas::CHAR;            $m->color = [0.8, 0.8, 0.8];            $m->tube([[0, 0.4, 0, 0.4], [0, -0.1, 0, 0.18]], 12, 1.0, true);            $m->pop();        } elseif ($variant === 1) {            $m->cell = Atlas::HULL;            $m->color = [1.0, 1.0, 1.0];            $m->push()->translate(0, 0.25, 0)->rotate('z', M_PI / 2);            $m->tube([[0, -0.45, 0, 0.22], [0, 0.45, 0, 0.22]], 12, 1.0, true, true);            $m->cell = Atlas::PLAIN;            $m->color = [0.4, 2.2, 2.6];            $m->tube([[0, -0.08, 0, 0.23], [0, 0.08, 0, 0.23]], 12, 1.0);            $m->pop();        } else {            $m->cell = Atlas::METAL;            $m->color = [0.5, 0.52, 0.55];            $m->box(0, 0.2, 0, 0.6, 0.4, 0.45);            $m->cell = Atlas::SCREEN;            $m->color = [1.6, 1.6, 1.6];            $m->box(0, 0.25, 0.226, 0.4, 0.2, 0.005);            $m->cell = Atlas::PLAIN;            $m->color = [0.15, 0.15, 0.15];            $m->tube([[0.2, 0.4, -0.1, 0.012], [0.25, 0.75, -0.15, 0.008]], 4, 1.0);            $m->color = [0.8, 0.3, 0.1];            $m->tube([[-0.3, 0.1, 0.1, 0.015], [-0.5, 0.02, 0.3, 0.015], [-0.6, 0.02, 0.1, 0.015]], 4, 1.0);        }        $m->bone = 0.0;    }    /** Rob's raft: seven logs lashed with rope, two cross beams, a little deck of reeds. Floats at y = 0. */    public static function raft(Mesh $m, int $seed): void    {        $m->cell = Atlas::BARK;        for ($k = 0; $k < 7; $k++) {            $x = ($k - 3) * 0.34;            $l = 3.6 + (self::rnd($seed, $k) - 0.5) * 0.5;            $m->color = [0.95 + 0.1 * self::rnd($seed, 10 + $k), 0.88, 0.8];            $m->tube([[$x, 0.02, -$l / 2, 0.16], [$x + 0.02, 0.03, 0.0, 0.17], [$x, 0.02, $l / 2, 0.15]], 7, 1.2, true, true);        }        $m->color = [0.85, 0.78, 0.7];        foreach ([-1.1, 1.1] as $z) {            $m->tube([[-1.3, 0.22, $z, 0.08], [1.3, 0.22, $z, 0.08]], 6, 1.2, true, true);        }        $m->cell = Atlas::ROPE;        $m->color = [1.0, 0.95, 0.8];        foreach ([-1.1, 1.1] as $z) {            for ($k = 0; $k < 7; $k++) {                $x = ($k - 3) * 0.34;                $m->tube([[$x, 0.05, $z - 0.1, 0.175], [$x, 0.05, $z + 0.1, 0.175]], 7, 1.0);            }        }        $m->cell = Atlas::THATCH;        $m->color = [1.0, 0.95, 0.85];        $m->box(0.0, 0.2, 0.0, 1.6, 0.04, 1.4);        // a bundle and a gourd on the deck        $m->cell = Atlas::FABRIC;        $m->color = [0.8, 0.7, 0.55];        $m->ellipsoid(-0.5, 0.35, -0.3, 0.25, 0.16, 0.3, 4, 7, 0.08, 2);        $m->cell = Atlas::PLAIN;        $m->color = [0.7, 0.55, 0.3];        $m->ellipsoid(0.55, 0.32, 0.4, 0.1, 0.13, 0.1, 4, 6);        $m->color = [1.0, 1.0, 1.0];    }    /**     * A bridge of the river people: a sagging walkway of planks along +z over $len metres (its ends at y = 0), two     * rope handrails on posts, lianas hanging under it.     */    public static function lianaBridge(Mesh $m, int $seed, float $len): void    {        $sag = $len * 0.08;        $n = (int) max(6, round($len / 0.45));        $y = static fn (float $t): float => -$sag * 4 * $t * (1 - $t) + 0.3;        $m->cell = Atlas::PLANKS;        for ($k = 0; $k < $n; $k++) {            $t = ($k + 0.5) / $n;            $z = -$len / 2 + $t * $len;            $m->color = [0.85 + 0.2 * self::rnd($seed, $k), 0.8, 0.7];            $m->push()->translate((self::rnd($seed, 50 + $k) - 0.5) * 0.06, $y($t), $z)->rotate('y', (self::rnd($seed, 80 + $k) - 0.5) * 0.08)->rotate('x', -($y(min(1.0, $t + 0.01)) - $y(max(0.0, $t - 0.01))) / ($len * 0.02));            $m->box(0, 0, 0, 1.0, 0.05, 0.32);            $m->pop();        }        // ropes: two under the planks, two handrails        $m->cell = Atlas::ROPE;        $m->color = [0.9, 0.85, 0.7];        foreach ([[-0.45, -0.04], [0.45, -0.04], [-0.55, 1.0], [0.55, 1.0]] as [$x, $dy]) {            $rings = [];            for ($k = 0; $k <= 12; $k++) {                $t = $k / 12;                $rings[] = [$x, $y($t) + $dy + ($dy > 0 ? $sag * 0.25 * 4 * $t * (1 - $t) : 0.0), -$len / 2 + $t * $len, $dy > 0 ? 0.025 : 0.03];            }            $m->tube($rings, 4, 1.0);        }        // hangers between rail and walkway        for ($k = 1; $k < 10; $k++) {            $t = $k / 10;            foreach ([-0.5, 0.5] as $x) {                $m->tube([[$x, $y($t), -$len / 2 + $t * $len, 0.012], [$x * 1.1, $y($t) + 1.0 + $sag * 0.25 * 4 * $t * (1 - $t), -$len / 2 + $t * $len, 0.012]], 3, 1.0);            }        }        // posts at both ends        $m->cell = Atlas::BARK;        $m->color = [0.85, 0.75, 0.62];        foreach ([-1, 1] as $e) {            foreach ([-0.6, 0.6] as $x) {                $m->tube([[$x, -0.4, $e * ($len / 2 + 0.2), 0.08], [$x, 1.5, $e * ($len / 2 + 0.2), 0.07]], 6, 1.0, true);            }        }        // lianas hanging under        $m->cell = Atlas::LIANA;        $m->sway = 0.4;        for ($k = 0; $k < 5; $k++) {            $t = 0.2 + 0.6 * $k / 4;            $z = -$len / 2 + $t * $len;            $m->card(0.4 - 0.8 * ($k % 2), $y($t) - 0.9, $z, 0.6, 1.8, 0.0, 0.0, [0, $y($t), $z]);        }        $m->sway = 0.0;        $m->color = [1.0, 1.0, 1.0];    }    /** A hut on stilts (marsh, river): a platform 2 m up on poles, plank walls, a steep thatched roof, a ladder. */    public static function stiltHut(Mesh $m, int $seed): void    {        $up = 2.2;        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.72, 0.6];        foreach ([[-1.6, -1.6], [1.6, -1.6], [-1.6, 1.6], [1.6, 1.6], [0.0, -1.7], [0.0, 1.7]] as $k => [$x, $z]) {            $m->tube([[$x + (self::rnd($seed, $k) - 0.5) * 0.2, -1.0, $z, 0.11], [$x, $up + 0.1, $z, 0.09]], 6, 1.2);        }        // cross braces        $m->tube([[-1.6, 0.2, -1.6, 0.05], [1.6, $up - 0.2, -1.6, 0.05]], 4, 1.5);        $m->tube([[-1.6, 0.2, 1.6, 0.05], [1.6, $up - 0.2, 1.6, 0.05]], 4, 1.5);        $m->cell = Atlas::PLANKS;        $m->color = [0.85, 0.76, 0.64];        $m->box(0, $up, 0, 4.0, 0.12, 4.0, 2.0);        // walls with a door and a window        $m->color = [0.8, 0.7, 0.58];        $wy = $up + 1.0;        $m->box(0, $wy, -1.75, 3.5, 1.9, 0.08, 2.0);        $m->box(-1.75, $wy, 0, 0.08, 1.9, 3.5, 2.0);        $m->box(1.75, $wy, 0, 0.08, 1.9, 3.5, 2.0);        $m->box(-1.15, $wy, 1.75, 1.2, 1.9, 0.08, 2.0);        $m->box(1.15, $wy, 1.75, 1.2, 1.9, 0.08, 2.0);        $m->box(0, $wy + 0.75, 1.75, 1.1, 0.4, 0.08, 2.0);        $m->cell = Atlas::PLAIN;        $m->color = [0.05, 0.04, 0.03];        $m->quad4([-0.55, $up + 0.06, 1.7], [0.55, $up + 0.06, 1.7], [0.55, $up + 1.55, 1.7], [-0.55, $up + 1.55, 1.7], [0, 0, 1]);        // the roof: four steep thatched slopes, overhanging        $m->cell = Atlas::THATCH;        $m->color = [1.0, 0.92, 0.78];        $ry = $up + 1.95;        $peak = [0.0, $ry + 2.0, 0.0];        $c = [[-2.4, $ry - 0.3, -2.4], [2.4, $ry - 0.3, -2.4], [2.4, $ry - 0.3, 2.4], [-2.4, $ry - 0.3, 2.4]];        for ($k = 0; $k < 4; $k++) {            $a = $c[$k];            $b = $c[($k + 1) % 4];            $mx = ($a[0] + $b[0]) / 2;            $mz = ($a[2] + $b[2]) / 2;            $nl = sqrt($mx * $mx + $mz * $mz) ?: 1.0;            $n = [$mx / $nl, 1.0, $mz / $nl];            $i0 = $m->vertex($a[0], $a[1], $a[2], $n[0], $n[1], $n[2], 0.0, 1.0);            $i1 = $m->vertex($b[0], $b[1], $b[2], $n[0], $n[1], $n[2], 1.0, 1.0);            $i2 = $m->vertex($peak[0], $peak[1], $peak[2], $n[0], $n[1], $n[2], 0.5, 0.0);            $m->tri($i0, $i1, $i2);        }        // a ladder down from the door        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.7, 0.55];        foreach ([-0.3, 0.3] as $x) {            $m->tube([[$x, -0.5, 3.0, 0.04], [$x, $up + 0.1, 2.0, 0.04]], 4, 1.5);        }        for ($k = 0; $k < 6; $k++) {            $t = ($k + 0.5) / 6;            $m->tube([[-0.32, -0.5 + ($up + 0.6) * $t, 3.0 - $t, 0.025], [0.32, -0.5 + ($up + 0.6) * $t, 3.0 - $t, 0.025]], 4, 1.0);        }        $m->color = [1.0, 1.0, 1.0];    }    /** A market stall: four posts, a striped awning, a counter with baskets of fruit, pots and hides. */    public static function marketStall(Mesh $m, int $seed, int $variant): void    {        $m->cell = Atlas::BARK;        $m->color = [0.82, 0.72, 0.58];        foreach ([[-1.3, -0.8, 2.3], [1.3, -0.8, 2.3], [-1.3, 0.8, 2.0], [1.3, 0.8, 2.0]] as [$x, $z, $h]) {            $m->tube([[$x, -0.1, $z, 0.06], [$x, $h, $z, 0.05]], 5, 1.0, true);        }        $m->cell = Atlas::PATTERN;        $m->color = [[1.1, 0.75, 0.55], [0.85, 0.95, 1.05], [1.05, 1.0, 0.8]][$variant % 3];        $m->quad4([-1.5, 2.35, -1.0], [1.5, 2.35, -1.0], [1.5, 1.95, 1.25], [-1.5, 1.95, 1.25], [0, 1, 0.2]);        $m->quad4([-1.5, 2.35, -1.0], [-1.5, 1.95, 1.25], [1.5, 1.95, 1.25], [1.5, 2.35, -1.0], [0, -1, -0.2]);        $m->quad4([-1.5, 1.95, 1.25], [1.5, 1.95, 1.25], [1.5, 1.6, 1.32], [-1.5, 1.6, 1.32], [0, 0, 1]);        // the counter        $m->cell = Atlas::PLANKS;        $m->color = [0.85, 0.75, 0.6];        $m->box(0, 0.85, 0.75, 2.6, 0.08, 0.7, 2.0);        $m->box(0, 0.42, 1.08, 2.6, 0.8, 0.05, 2.0);        // goods        $m->cell = Atlas::THATCH;        foreach ([-0.9, -0.1, 0.7] as $k => $x) {            $m->color = [0.9, 0.8, 0.6];            $m->tube([[$x, 0.89, 0.75, 0.2], [$x, 1.05, 0.75, 0.24]], 9, 1.0, false, true);            $m->cell = Atlas::PLAIN;            $fruit = [[1.2, 0.5, 0.15], [0.9, 0.15, 0.2], [0.85, 0.9, 0.2]][($k + $variant) % 3];            for ($f = 0; $f < 6; $f++) {                $a = $f * 1.05;                $m->color = [$fruit[0] * (0.85 + 0.3 * self::rnd($seed, $f + $k * 7)), $fruit[1], $fruit[2]];                $m->ellipsoid($x + cos($a) * 0.1 * ($f % 2 + 0.4), 1.08 + 0.04 * ($f % 2), 0.75 + sin($a) * 0.1, 0.06, 0.06, 0.06, 3, 5);            }            $m->cell = Atlas::THATCH;        }        $m->cell = Atlas::STONE;        $m->color = [0.9, 0.55, 0.38];        foreach ([[-1.6, 0.2], [-1.75, -0.3], [1.65, 0.0]] as [$x, $z]) {            $m->tube([[$x, 0.0, $z, 0.14], [$x, 0.25, $z, 0.22], [$x, 0.45, $z, 0.1], [$x, 0.5, $z, 0.12]], 9, 1.0, false, true);        }        $m->cell = Atlas::FUR;        $m->color = [0.8, 0.6, 0.4];        $m->quad4([-1.2, 2.2, -0.95], [1.2, 2.2, -0.95], [1.1, 0.9, -0.92], [-1.1, 0.9, -0.92], [0, 0, 1]);        $m->color = [1.0, 1.0, 1.0];    }    /** A carved totem pole: stacked faces with eyes and beaks, painted, spread wings at the top. */    public static function totem(Mesh $m, int $seed): void    {        $m->cell = Atlas::PLANKS;        $paints = [[1.1, 0.35, 0.2], [0.2, 0.45, 0.55], [1.15, 0.9, 0.35], [0.12, 0.1, 0.09], [0.9, 0.85, 0.75]];        $m->color = [0.75, 0.58, 0.42];        $m->tube([[0, -0.3, 0, 0.32], [0, 4.6, 0, 0.28]], 10, 1.2, true);        for ($k = 0; $k < 3; $k++) {            $y = 0.8 + $k * 1.35;            $m->color = $paints[($k + $seed) % 3];            $m->ellipsoid(0, $y, 0.12, 0.34, 0.5, 0.25, 5, 10);            $m->cell = Atlas::PLAIN;            foreach ([-1, 1] as $sd) {                $m->color = $paints[4];                $m->ellipsoid($sd * 0.13, $y + 0.15, 0.33, 0.09, 0.07, 0.04, 3, 6);                $m->color = $paints[3];                $m->ellipsoid($sd * 0.13, $y + 0.15, 0.365, 0.045, 0.045, 0.02, 3, 5);            }            $m->color = $paints[($k + 2) % 3];            if ($k === 1) {                $m->tube([[0, $y, 0.33, 0.08], [0, $y - 0.2, 0.62, 0.02]], 6, 1.0);            } else {                $m->box(0, $y - 0.22, 0.35, 0.36, 0.1, 0.05);                $m->color = $paints[4];                for ($t = 0; $t < 5; $t++) {                    $m->box(-0.14 + $t * 0.07, $y - 0.22, 0.38, 0.03, 0.06, 0.02);                }            }            $m->cell = Atlas::PLANKS;        }        // wings        $m->color = $paints[1];        foreach ([-1, 1] as $sd) {            $m->quad4([$sd * 0.25, 4.3, 0.05], [$sd * 1.4, 4.9, 0.05], [$sd * 1.3, 4.4, 0.05], [$sd * 0.25, 3.8, 0.05], [0, 0, 1]);            $m->quad4([$sd * 0.25, 4.3, -0.05], [$sd * 0.25, 3.8, -0.05], [$sd * 1.3, 4.4, -0.05], [$sd * 1.4, 4.9, -0.05], [0, 0, -1]);        }        $m->color = [1.0, 1.0, 1.0];    }    /** A cage of lashed poles (a captive, an animal): a ring of bars, a roof, a rope-tied door. */    public static function cage(Mesh $m, int $seed): void    {        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.7, 0.56];        $n = 14;        for ($k = 0; $k < $n; $k++) {            $a = $k / $n * 2 * M_PI;            if ($k === 0) {                continue;            }            $m->tube([[cos($a) * 1.0, -0.1, sin($a) * 1.0, 0.045], [cos($a) * 0.95, 2.0, sin($a) * 0.95, 0.04]], 5, 1.2);        }        foreach ([0.15, 1.9] as $y) {            $rings = [];            for ($k = 0; $k <= 16; $k++) {                $a = $k / 16 * 2 * M_PI;                $rings[] = [cos($a) * 1.0, $y, sin($a) * 1.0, 0.05];            }            $m->tube($rings, 5, 1.5);        }        $m->cell = Atlas::THATCH;        $m->color = [0.9, 0.82, 0.66];        $m->tube([[0, 1.95, 0, 1.25], [0, 2.6, 0, 0.1]], 12, 1.0, true);        // the door, ajar        $m->cell = Atlas::BARK;        $m->color = [0.75, 0.65, 0.52];        $m->push()->translate(1.0, 0, 0)->rotate('y', -0.6);        foreach ([0.0, 0.22, 0.44] as $z) {            $m->tube([[0, 0.05, $z, 0.04], [0, 1.85, $z, 0.04]], 4, 1.2);        }        $m->tube([[0, 0.5, -0.02, 0.03], [0, 0.5, 0.48, 0.03]], 4, 1.2);        $m->tube([[0, 1.5, -0.02, 0.03], [0, 1.5, 0.48, 0.03]], 4, 1.2);        $m->pop();        $m->color = [1.0, 1.0, 1.0];    }    /** A colony terminal: a slanted console on a pedestal, its screen still glowing, cables, rust and moss. */    public static function terminal(Mesh $m, int $seed): void    {        $m->cell = Atlas::METAL;        $m->color = [0.62, 0.64, 0.66];        $m->bone = 0.5;        $m->box(0, 0.5, 0, 0.5, 1.0, 0.45);        $m->push()->translate(0, 1.08, 0.05)->rotate('x', -0.55);        $m->box(0, 0, 0, 0.8, 0.12, 0.6);        $m->cell = Atlas::SCREEN;        $m->color = [1.9, 1.9, 1.9];        $m->box(0, 0.062, 0.0, 0.66, 0.005, 0.48);        $m->pop();        $m->cell = Atlas::METAL;        $m->color = [0.5, 0.52, 0.55];        $m->push()->translate(0, 0.98, 0.32)->rotate('x', 0.25);        $m->box(0, 0, 0, 0.7, 0.05, 0.22);        $m->pop();        $m->cell = Atlas::PLAIN;        $m->color = [0.4, 2.4, 0.8];        $m->ellipsoid(0.3, 1.1, 0.28, 0.015, 0.015, 0.015, 2, 4);        $m->color = [0.12, 0.12, 0.13];        $m->tube([[-0.2, 0.05, -0.2, 0.03], [-0.5, 0.02, -0.5, 0.03], [-1.2, 0.03, -0.6, 0.03]], 5, 1.0);        $m->tube([[0.15, 0.05, -0.22, 0.025], [0.4, 0.02, -0.9, 0.025]], 5, 1.0);        $m->cell = Atlas::RUST;        $m->color = [1.0, 1.0, 1.0];        $m->box(0, 0.06, 0, 0.56, 0.12, 0.5);        $m->cell = Atlas::MOSS;        $m->color = [0.9, 1.0, 0.85];        $m->ellipsoid(-0.2, 0.95, -0.15, 0.2, 0.06, 0.2, 3, 6, 0.2, 2);        $m->bone = 0.0;        $m->color = [1.0, 1.0, 1.0];    }    /** A crashed survey drone: a cracked body, four arms (one torn off), rotors, a red eye still blinking. */    public static function droneWreck(Mesh $m, int $seed): void    {        $m->push()->translate(0, 0.25, 0)->rotate('z', 0.35)->rotate('x', 0.1);        $m->cell = Atlas::HULL;        $m->color = [0.85, 0.85, 0.85];        $m->bone = 0.5;        $m->ellipsoid(0, 0, 0, 0.45, 0.2, 0.55, 5, 10);        $m->cell = Atlas::METAL;        $m->color = [0.4, 0.42, 0.45];        foreach ([[0.785, true], [2.356, true], [3.927, false], [5.498, true]] as $k => [$a, $whole]) {            $l = $whole ? 1.0 : 0.45;            $ex = cos($a) * $l;            $ez = sin($a) * $l;            $m->tube([[cos($a) * 0.3, 0.0, sin($a) * 0.3, 0.05], [$ex, 0.02, $ez, 0.04]], 6, 1.0, true);            if ($whole) {                $m->tube([[$ex, 0.02, $ez, 0.06], [$ex, 0.1, $ez, 0.05]], 8, 1.0, true);                $m->color = [0.2, 0.2, 0.22];                $rings = [];                for ($i = 0; $i <= 16; $i++) {                    $b = $i / 16 * 2 * M_PI;                    $rings[] = [$ex + cos($b) * 0.38, 0.1, $ez + sin($b) * 0.38, 0.018];                }                $m->tube($rings, 4, 1.0);                $m->quad4([$ex - 0.32, 0.11, $ez - 0.03], [$ex + 0.32, 0.11, $ez - 0.03], [$ex + 0.32, 0.11, $ez + 0.03], [$ex - 0.32, 0.11, $ez + 0.03], [0, 1, 0]);                $m->color = [0.4, 0.42, 0.45];            }        }        $m->cell = Atlas::PLAIN;        $m->color = [0.05, 0.05, 0.06];        $m->ellipsoid(0, -0.05, 0.5, 0.12, 0.1, 0.08, 4, 7);        $m->color = [3.0, 0.3, 0.2];        $m->ellipsoid(0, -0.05, 0.57, 0.04, 0.04, 0.02, 3, 5);        $m->pop();        $m->cell = Atlas::METAL;        $m->color = [0.4, 0.42, 0.45];        $m->push()->translate(-1.1, 0.03, 0.6)->rotate('y', 0.7);        $m->tube([[0, 0, 0, 0.04], [0.5, 0, 0, 0.035]], 5, 1.0, true, true);        $m->pop();        $m->cell = Atlas::CHAR;        $m->color = [1.0, 1.0, 1.0];        self::disc($m, 0.0, 0.015, 0.0, 1.6, [0.3, 0.3, 0.3], [0.9, 0.9, 0.9], $seed);        $m->bone = 0.0;        $m->color = [1.0, 1.0, 1.0];    }    /** A signpost: a pole and three arrow boards pointing different ways, painted marks on them. */    public static function signpost(Mesh $m, int $seed): void    {        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.7, 0.58];        $m->tube([[0, -0.3, 0, 0.07], [0, 2.4, 0, 0.06]], 6, 1.2, true);        foreach ([[2.1, 0.3], [1.75, 2.2], [1.4, 4.0]] as $k => [$y, $a]) {            $m->push()->translate(0, $y, 0)->rotate('y', $a + (self::rnd($seed, $k) - 0.5) * 0.4);            $m->cell = Atlas::PLANKS;            $m->color = [0.9, 0.82, 0.68];            $m->box(0.0, 0, 0.5, 0.04, 0.22, 0.9);            $i0 = $m->vertex(0.02, 0.11, 0.95, 1, 0, 0);            $i1 = $m->vertex(0.02, -0.11, 0.95, 1, 0, 0);            $i2 = $m->vertex(0.02, 0.0, 1.15, 1, 0, 0);            $m->tri($i0, $i1, $i2);            $i0 = $m->vertex(-0.02, 0.11, 0.95, -1, 0, 0);            $i1 = $m->vertex(-0.02, 0.0, 1.15, -1, 0, 0);            $i2 = $m->vertex(-0.02, -0.11, 0.95, -1, 0, 0);            $m->tri($i0, $i1, $i2);            $m->cell = Atlas::PLAIN;            $m->color = [0.15, 0.1, 0.08];            for ($t = 0; $t < 4; $t++) {                $m->box(0.022, 0.0, 0.2 + $t * 0.17, 0.005, 0.1, 0.03 + 0.04 * self::rnd($seed, $t + $k * 5));                $m->box(-0.022, 0.0, 0.2 + $t * 0.17, 0.005, 0.1, 0.03 + 0.04 * self::rnd($seed, $t + $k * 5));            }            $m->pop();        }        $m->color = [1.0, 1.0, 1.0];    }    /** Ash on the ground (a burnt place; fire_patch: what burns, the flames are drawn by Graphics): grey and black, charred sticks. */    public static function ash(Mesh $m, int $seed, float $r): void    {        $m->cell = Atlas::CHAR;        self::disc($m, 0.0, 0.03, 0.0, $r, [0.55, 0.53, 0.5], [0.9, 0.88, 0.85], $seed, 16);        $m->cell = Atlas::CHAR;        $m->color = [0.8, 0.78, 0.76];        for ($k = 0; $k < 6; $k++) {            $a = self::rnd($seed, $k) * 6.28;            $d = self::rnd($seed, 10 + $k) * $r * 0.7;            $m->tube([[cos($a) * $d, 0.05, sin($a) * $d, 0.05], [cos($a) * $d + cos($a + 1.0) * 0.6, 0.06, sin($a) * $d + sin($a + 1.0) * 0.6, 0.035]], 4, 1.0, true, true);        }        $m->cell = Atlas::PLAIN;        $m->color = [2.6, 0.8, 0.2];        for ($k = 0; $k < 5; $k++) {            $a = self::rnd($seed, 30 + $k) * 6.28;            $d = self::rnd($seed, 40 + $k) * $r * 0.5;            $m->ellipsoid(cos($a) * $d, 0.04, sin($a) * $d, 0.05, 0.02, 0.05, 2, 4);        }        $m->color = [1.0, 1.0, 1.0];    }    /** A fumarole: a low mound of grey rock crusted with yellow sulphur around a vent (Graphics adds the steam). */    public static function fumarole(Mesh $m, int $seed): void    {        $m->cell = Atlas::BASALT;        $m->color = [1.05, 1.02, 1.0];        $m->ellipsoid(0, 0.0, 0, 1.6, 0.9, 1.4, 6, 12, 0.2, $seed, 0.2);        $m->ellipsoid(0.2, 0.55, -0.1, 0.9, 0.6, 0.85, 5, 10, 0.25, $seed + 1, 0.3);        // sulphur: yellow crusts around the vent, white salts        $m->cell = Atlas::STONE;        for ($k = 0; $k < 11; $k++) {            $a = $k / 11 * 6.28 + self::rnd($seed, $k);            $d = 0.3 + self::rnd($seed, 20 + $k) * 0.55;            $m->color = $k % 3 ? [1.5, 1.28, 0.32] : [1.35, 1.32, 1.2];            $m->ellipsoid(cos($a) * $d + 0.2, 1.05 - $d * 0.5, sin($a) * $d - 0.1, 0.18 + 0.1 * self::rnd($seed, 40 + $k), 0.07, 0.16, 3, 5, 0.3, $seed + $k, 0.4);        }        $m->cell = Atlas::PLAIN;        $m->color = [0.03, 0.025, 0.02];        $m->ellipsoid(0.2, 1.1, -0.1, 0.16, 0.05, 0.16, 3, 8);        $m->color = [1.0, 1.0, 1.0];    }    /** A geyser: terraces of pale sinter around a small blue pool (Graphics adds the eruption). */    public static function geyser(Mesh $m, int $seed): void    {        $m->cell = Atlas::STONE;        foreach ([[2.6, 0.18, [1.35, 1.2, 0.95]], [1.9, 0.32, [1.4, 1.1, 0.75]], [1.25, 0.44, [1.45, 1.3, 1.1]]] as $k => [$r, $y, $c]) {            $m->color = $c;            $m->ellipsoid(0, $y - 0.12, 0, $r, 0.16, $r * 0.92, 3, 14, 0.06, $seed + $k, 0.2);        }        $m->cell = Atlas::PLAIN;        $m->bone = 1.0;        self::disc($m, 0.0, 0.49, 0.0, 0.7, [0.05, 0.25, 0.4], [0.3, 0.7, 0.8], $seed, 14);        $m->bone = 0.0;        $m->color = [1.0, 1.0, 1.0];    }    /** An old boat stranded on the shore: the keel, a few ribs, broken planking, a snapped mast. */    public static function boatWreck(Mesh $m, int $seed): void    {        $m->push()->translate(0, 0.1, 0)->rotate('z', 0.35);        $m->cell = Atlas::PLANKS;        $m->color = [0.62, 0.55, 0.48];        $m->tube([[0, 0.0, -3.4, 0.12], [0, -0.05, 0.0, 0.14], [0, 0.2, 3.4, 0.1], [0, 0.9, 3.8, 0.08]], 6, 2.0);        for ($k = 0; $k < 9; $k++) {            $z = -3.0 + $k * 0.75;            $w = 1.2 * sin(M_PI * ($k + 0.5) / 9) + 0.25;            $broken = self::rnd($seed, $k) < 0.3;            foreach ([-1, 1] as $sd) {                if ($broken && $sd > 0) {                    continue;                }                $m->tube([[0, 0.0, $z, 0.06], [$sd * $w * 0.8, 0.35, $z, 0.055], [$sd * $w, 1.1, $z, 0.045]], 4, 1.5);            }        }        $m->color = [0.7, 0.62, 0.52];        foreach ([0.35, 0.7] as $k => $h) {            $m->push()->translate(-1.05, $h, 0.0)->rotate('z', 0.35);            $m->box(0, 0, -0.4 * $k, 0.05, 0.28, 5.0 - $k * 1.6, 2.0);            $m->pop();        }        $m->cell = Atlas::BARK;        $m->color = [0.7, 0.62, 0.5];        $m->tube([[0, 0.0, 0.8, 0.1], [0, 1.6, 0.8, 0.09], [0.3, 2.2, 0.9, 0.06]], 5, 1.5, true);        $m->pop();        $m->cell = Atlas::ROPE;        $m->color = [0.8, 0.75, 0.6];        $m->tube([[0.4, 0.05, 1.0, 0.025], [1.6, 0.03, 1.8, 0.025], [2.2, 0.03, 1.0, 0.025]], 4, 1.0);        $m->color = [1.0, 1.0, 1.0];    }    /** A weapon rack: an A-frame with spears, clubs and a bow leaning on it. */    public static function weaponRack(Mesh $m, int $seed): void    {        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.7, 0.55];        foreach ([-1.1, 1.1] as $x) {            $m->tube([[$x, 0.0, -0.5, 0.05], [$x, 1.6, 0.0, 0.045]], 5, 1.2);            $m->tube([[$x, 0.0, 0.5, 0.05], [$x, 1.6, 0.0, 0.045]], 5, 1.2);        }        $m->tube([[-1.2, 1.5, 0.0, 0.045], [1.2, 1.5, 0.0, 0.045]], 5, 1.2, true, true);        $m->tube([[-1.2, 0.6, 0.3, 0.035], [1.2, 0.6, 0.3, 0.035]], 5, 1.2, true, true);        foreach (['spear', 'spear', 'club', 'harpoon', 'machete', 'bow'] as $k => $item) {            $x = -0.9 + $k * 0.36;            $m->push()->translate($x, $item === 'club' || $item === 'machete' ? 0.1 : 0.45, 0.4)->rotate('x', -0.3)->rotate('y', (self::rnd($seed, $k) - 0.5) * 0.3);            $m->color = [1.0, 1.0, 1.0];            $m->append(Models::item($item));            $m->pop();        }        $m->color = [1.0, 1.0, 1.0];    }    /** A forge: a stone hearth with glowing coals, a hood and chimney, leather bellows, an anvil on a stump. */    public static function forge(Mesh $m, int $seed): void    {        $m->cell = Atlas::STONE;        $m->color = [0.8, 0.75, 0.7];        for ($k = 0; $k < 12; $k++) {            $a = $k / 12 * 2 * M_PI;            $m->ellipsoid(cos($a) * 0.65, 0.35, sin($a) * 0.55, 0.25, 0.35, 0.22, 4, 6, 0.2, $seed + $k, 0.6);        }        $m->box(0, 0.4, 0, 1.0, 0.8, 0.9);        $m->cell = Atlas::CHAR;        $m->color = [1.0, 1.0, 1.0];        $m->ellipsoid(0, 0.8, 0, 0.42, 0.08, 0.36, 3, 8, 0.3, 3);        $m->cell = Atlas::PLAIN;        $m->color = [3.0, 1.1, 0.3];        for ($k = 0; $k < 7; $k++) {            $a = self::rnd($seed, 20 + $k) * 6.28;            $d = self::rnd($seed, 30 + $k) * 0.25;            $m->ellipsoid(cos($a) * $d, 0.86, sin($a) * $d, 0.07, 0.04, 0.07, 2, 5);        }        // hood and chimney        $m->cell = Atlas::STONE;        $m->color = [0.7, 0.66, 0.62];        foreach ([[-0.5, -0.45], [0.5, -0.45]] as [$x, $z]) {            $m->box($x, 1.4, $z, 0.15, 1.2, 0.15);        }        $m->tube([[0, 2.0, -0.2, 0.6], [0, 2.4, -0.25, 0.35], [0, 3.6, -0.3, 0.3]], 8, 1.5, true);        // bellows        $m->cell = Atlas::LEATHER;        $m->color = [0.9, 0.7, 0.5];        $m->push()->translate(-0.95, 0.75, 0.1)->rotate('z', 0.25);        $m->ellipsoid(0, 0, 0, 0.32, 0.12, 0.25, 4, 7);        $m->pop();        // the anvil on a stump        $m->cell = Atlas::BARK;        $m->color = [0.8, 0.7, 0.55];        $m->tube([[1.3, -0.1, 0.4, 0.3], [1.3, 0.6, 0.4, 0.28]], 8, 1.0, true);        $m->cell = Atlas::METAL;        $m->color = [0.35, 0.35, 0.37];        $m->bone = 0.6;        $m->box(1.3, 0.72, 0.4, 0.22, 0.12, 0.5);        $m->box(1.3, 0.82, 0.4, 0.3, 0.1, 0.6);        $m->tube([[1.3, 0.82, 0.7, 0.05], [1.3, 0.84, 0.9, 0.005]], 6, 1.0);        $m->bone = 0.0;        $m->color = [1.0, 1.0, 1.0];    }    // ---- Rob's storage (Land\Chests) -------------------------------------------------------------------    /**     * A wooden chest Rob built: split planks (seams showing), two iron bands round it, corner brackets, a lock plate, a     * lid hinged at the back; $open: the lid up (the transfer screen is open) and the dark inside showing.     */    public static function chestWood(Mesh $m, int $seed, bool $open): void    {        $w = 1.0;        $h = 0.5;        $d = 0.6;        $m->cell = Atlas::PLANKS;        $m->color = [0.92, 0.8, 0.62];        $m->box(0, $h / 2, 0, $w, $h, $d, 0.6);        // plank seams on the front and the sides        $m->cell = Atlas::PLAIN;        $m->color = [0.22, 0.15, 0.09];        foreach ([0.17, 0.33] as $y) {            $m->box(0, $y, $d / 2 + 0.004, $w - 0.04, 0.012, 0.006);            $m->box(0, $y, -$d / 2 - 0.004, $w - 0.04, 0.012, 0.006);            $m->box($w / 2 + 0.004, $y, 0, 0.006, 0.012, $d - 0.04);            $m->box(-$w / 2 - 0.004, $y, 0, 0.006, 0.012, $d - 0.04);        }        if ($open) {            // the dark inside, a few things in it            $m->color = [0.08, 0.06, 0.04];            $m->box(0, $h - 0.02, 0, $w - 0.08, 0.02, $d - 0.08);            $m->cell = Atlas::ROPE;            $m->color = [0.9, 0.8, 0.6];            $m->ellipsoid(-0.22, $h - 0.02, 0.05, 0.13, 0.05, 0.13, 3, 7);            $m->cell = Atlas::LEATHER;            $m->color = [0.8, 0.6, 0.4];            $m->box(0.18, $h - 0.01, -0.06, 0.3, 0.05, 0.2);        }        // iron bands, brackets, the lock        $m->cell = Atlas::METAL;        $m->color = [0.34, 0.33, 0.32];        foreach ([-0.3, 0.3] as $x) {            $m->box($x, $h / 2, $d / 2 + 0.01, 0.06, $h + 0.01, 0.015);            $m->box($x, $h / 2, -$d / 2 - 0.01, 0.06, $h + 0.01, 0.015);            $m->box($x, 0.012, 0, 0.06, 0.015, $d + 0.02);        }        foreach ([-1, 1] as $sx) {            foreach ([-1, 1] as $sz) {                $m->box($sx * ($w / 2 - 0.03), $h / 2, $sz * ($d / 2 - 0.03), 0.075, $h + 0.012, 0.075);            }        }        $m->box(0, $h - 0.08, $d / 2 + 0.014, 0.1, 0.12, 0.012);        // the lid, hinged at the back edge of the top        $m->push()->translate(0, $h, -$d / 2)->rotate('x', $open ? -1.95 : 0.0);        $m->cell = Atlas::PLANKS;        $m->color = [0.98, 0.86, 0.66];        $m->box(0, 0.05, $d / 2, $w + 0.03, 0.1, $d + 0.03, 0.6);        $m->cell = Atlas::METAL;        $m->color = [0.34, 0.33, 0.32];        foreach ([-0.3, 0.3] as $x) {            $m->box($x, 0.102, $d / 2, 0.065, 0.012, $d + 0.04);            $m->box($x, 0.05, $d + 0.025, 0.065, 0.11, 0.012);        }        $m->box(0, 0.02, $d + 0.025, 0.07, 0.07, 0.014);   // the hasp        $m->pop();        $m->color = [1.0, 1.0, 1.0];    }    /** A woven basket: a round body of fibres and reeds, a thick braided rim, two loop handles; no lid. */    public static function basket(Mesh $m, int $seed, bool $open): void    {        $m->cell = Atlas::THATCH;        $m->color = [1.0, 0.86, 0.6];        $m->tube([[0, 0.0, 0, 0.26], [0, 0.18, 0, 0.32], [0, 0.4, 0, 0.35], [0, 0.5, 0, 0.36]], 14, 2.0, false, true, 3.0);        // the inside (darker), the bottom        $m->color = [0.42, 0.34, 0.22];        $m->tube([[0, 0.49, 0, 0.33], [0, 0.06, 0, 0.24]], 14, 1.5, false, true, 3.0);        // weave bands        $m->cell = Atlas::ROPE;        $m->color = [0.75, 0.6, 0.4];        foreach ([0.12, 0.3] as $y) {            $r = 0.26 + ($y / 0.5) * 0.1;            $m->tube([[0, $y - 0.015, 0, $r + 0.012], [0, $y + 0.015, 0, $r + 0.016]], 14, 0.5, false, false, 6.0);        }        // the rim: a ring of rope        $ring = [];        for ($k = 0; $k <= 16; $k++) {            $a = $k / 16 * 2 * M_PI;            $ring[] = [cos($a) * 0.36, 0.5, sin($a) * 0.36, 0.035];        }        $m->color = [0.9, 0.74, 0.5];        $m->tube($ring, 5, 6.0);        // handles        foreach ([-1, 1] as $sx) {            $arc = [];            for ($k = 0; $k <= 6; $k++) {                $a = $k / 6 * M_PI;                $arc[] = [$sx * 0.36, 0.5 + sin($a) * 0.12, cos($a) * 0.12, 0.018];            }            $m->tube($arc, 4, 2.0);        }        if ($open) {            $m->cell = Atlas::LEAVES;            $m->color = [0.9, 1.0, 0.85];            $m->ellipsoid(0.05, 0.42, 0.04, 0.2, 0.06, 0.18, 3, 7);        }        $m->color = [1.0, 1.0, 1.0];    }    /**     * A reinforced crate: dark planks framed with scrap metal (corner angles, two rusty bands, rivets), a latch, a lid     * hinged at the back; $open: the lid up.     */    public static function chestMetal(Mesh $m, int $seed, bool $open): void    {        $w = 1.2;        $h = 0.6;        $d = 0.75;        $m->cell = Atlas::PLANKS;        $m->color = [0.62, 0.55, 0.48];        $m->box(0, $h / 2, 0, $w, $h, $d, 0.6);        if ($open) {            $m->cell = Atlas::PLAIN;            $m->color = [0.06, 0.06, 0.06];            $m->box(0, $h - 0.02, 0, $w - 0.1, 0.02, $d - 0.1);        }        $m->cell = Atlas::RUST;        $m->color = [0.95, 0.9, 0.85];        foreach ([0.16, 0.44] as $y) {            $m->box(0, $y, 0, $w + 0.02, 0.07, $d + 0.02);        }        $m->cell = Atlas::METAL;        $m->color = [0.42, 0.43, 0.45];        foreach ([-1, 1] as $sx) {            foreach ([-1, 1] as $sz) {                $m->box($sx * ($w / 2 - 0.04), $h / 2, $sz * ($d / 2 - 0.04), 0.1, $h + 0.02, 0.1);            }        }        $m->color = [0.25, 0.25, 0.26];        foreach ([-0.45, -0.15, 0.15, 0.45] as $x) {            foreach ([0.16, 0.44] as $y) {                $m->box($x, $y, $d / 2 + 0.016, 0.025, 0.025, 0.01);            }        }        $m->color = [0.55, 0.5, 0.3];        $m->box(0, $h - 0.1, $d / 2 + 0.02, 0.14, 0.14, 0.02);        // the lid        $m->push()->translate(0, $h, -$d / 2)->rotate('x', $open ? -1.9 : 0.0);        $m->cell = Atlas::PLANKS;        $m->color = [0.66, 0.58, 0.5];        $m->box(0, 0.06, $d / 2, $w + 0.04, 0.12, $d + 0.04, 0.6);        $m->cell = Atlas::METAL;        $m->color = [0.42, 0.43, 0.45];        foreach ([-1, 1] as $sx) {            $m->box($sx * ($w / 2 - 0.02), 0.125, $d / 2, 0.08, 0.012, $d + 0.05);        }        $m->box(0, 0.125, $d / 2, $w + 0.05, 0.012, 0.08);        $m->color = [0.55, 0.5, 0.3];        $m->box(0, 0.03, $d + 0.035, 0.1, 0.09, 0.016);   // the latch        $m->pop();        $m->color = [1.0, 1.0, 1.0];    }}