// Animals and characters, assembled from primitives. Forward is +Z, up is +Y, feet at y = 0. import * as THREE from 'three'; import { at, ball, box, cone, cyl, eyes, joint, mat, orb, rig, tint, torus } from './prims.js'; const DARK = 0x26262b, WHITE = 0xf4f4f0, SKIN = 0xe9b991; // ------------------------------------------------------------------ four-legged animals function quad(s, C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const c2 = s.c2 ?? tint(C, -0.1), nw = s.nw ?? s.W * 0.6, top = s.leg + s.H; body.add(at(box(s.W, s.H, s.L, C), 0, s.leg + s.H / 2, 0)); const legs = []; for (const [sx, sz] of [[1, 1], [-1, 1], [1, -1], [-1, -1]]) { const leg = joint(sx * (s.W / 2 - s.lw / 2), s.leg, sz * (s.L / 2 - s.lw * 0.7), at(box(s.lw, s.leg, s.lw, s.legC ?? c2), 0, -s.leg / 2, 0)); if (s.hoof) leg.add(at(box(s.lw * 1.06, s.leg * 0.16, s.lw * 1.06, s.hoof), 0, -s.leg * 0.92, 0)); body.add(leg); legs.push(leg); } const ny = Math.sin(s.na) * s.neck, nz = Math.cos(s.na) * s.neck; const head = joint(0, top - s.H * 0.25, s.L / 2 - nw * 0.3); if (s.neck > 0.05) head.add(at(box(nw, s.neck + nw * 0.6, nw, C), 0, ny / 2, nz / 2, Math.PI / 2 - s.na)); const hg = joint(0, ny, nz); head.add(hg); const [hw, hh, hl] = s.hd, hc = s.headC ?? C; hg.add(at(box(hw, hh, hl, hc), 0, hh * 0.15, hl * 0.25)); if (s.snout) { const [sw, sh, sl] = s.snout; hg.add(at(box(sw, sh, sl, s.snoutC ?? tint(hc, 0.1)), 0, -hh * 0.14, hl * 0.75 + sl / 2 - 0.02), at(box(sw * 0.45, sh * 0.4, 0.04, s.noseC ?? 0x1c1c20), 0, -hh * 0.14 + sh * 0.22, hl * 0.75 + sl)); } eyes(hg, hw / 2 + 0.004, hh * 0.32, hl * 0.42, s.eye ?? 0.045); const ey = hh * 0.65, ec = s.earC ?? c2; for (const sx of [1, -1]) { if (s.ears === 'point') hg.add(at(cone(hw * 0.2, hh * (s.earH ?? 0.5), ec, null, 4), sx * hw * 0.3, ey + hh * 0.2, hl * 0.1)); else if (s.ears === 'round') hg.add(at(ball(hw * 0.2, ec), sx * hw * 0.42, ey, hl * 0.1)); else if (s.ears === 'long') hg.add(at(box(hw * 0.2, hh * 1.3, 0.05, ec), sx * hw * 0.25, ey + hh * 0.6, 0, -0.15, 0, -sx * 0.12)); else if (s.ears === 'floppy') hg.add(at(box(0.05, hh * 0.7, hl * 0.4, ec), sx * (hw / 2 + 0.02), hh * 0.1, hl * 0.1, 0, 0, sx * 0.15)); else if (s.ears === 'big') hg.add(at(box(0.08, hh * 0.9, hl * 0.9, ec), sx * (hw / 2 + 0.05), hh * 0.15, -hl * 0.05, 0, sx * 0.5, 0)); } let tail = null; if (s.tail) { const t = s.tail; tail = joint(0, top - s.H * 0.2, -s.L / 2 + 0.03, at(box(t.w, t.len, t.w, t.c ?? c2), 0, t.len / 2, 0)); if (t.tip) tail.add(at(box(t.w * 1.25, t.len * 0.3, t.w * 1.25, t.tip), 0, t.len * 0.9, 0)); tail.rotation.x = t.ang; body.add(tail); } body.add(head); const parts = { body, head, tail, legs }; s.extra?.({ body, hg, head, C, c2, s, top, parts, hw, hh, hl }); return rig(root, 'quad', { h: top - s.H * 0.25 + ny + hh * 0.7, r: s.L / 2 + 0.25, top, seat: [0, top, -s.L * 0.08], leg: s.leg, hipZ: s.L / 2 - s.lw * 0.7, bodyH: s.H, flyer: !!s.flyer, }, parts); } const spots = (x, color, list) => { for (const [w, h, d, px, py, pz] of list) x.body.add(at(box(w, h, d, color), px, py, pz)); }; const QUADS = { dog: [0xb9783f, { L: 0.9, H: 0.38, W: 0.36, leg: 0.38, lw: 0.11, neck: 0.22, na: 1.0, nw: 0.2, hd: [0.3, 0.28, 0.3], snout: [0.16, 0.13, 0.18], ears: 'floppy', tail: { len: 0.36, w: 0.07, ang: -0.9 } }], cat: [0xe0964b, { L: 0.62, H: 0.26, W: 0.24, leg: 0.24, lw: 0.08, neck: 0.1, na: 1.0, nw: 0.14, hd: [0.26, 0.22, 0.22], snout: [0.1, 0.07, 0.05], noseC: 0xe58a9a, ears: 'point', tail: { len: 0.5, w: 0.05, ang: -0.4 }, eye: 0.04 }], horse: [0x8f5a36, { L: 1.7, H: 0.62, W: 0.5, leg: 1.0, lw: 0.15, neck: 0.7, na: 1.0, nw: 0.26, hd: [0.26, 0.3, 0.5], snout: [0.2, 0.2, 0.22], ears: 'point', earH: 0.4, hoof: DARK, tail: { len: 0.9, w: 0.14, ang: -2.7, c: 0x3a2617 }, extra: (x) => x.head.add(at(box(0.08, 0.75, 0.2, 0x3a2617), 0, 0.42, 0.1, Math.PI / 2 - 1.0)) }], cow: [0xf2efe8, { L: 1.6, H: 0.7, W: 0.62, leg: 0.65, lw: 0.17, neck: 0.3, na: 0.5, nw: 0.3, hd: [0.36, 0.36, 0.4], snout: [0.3, 0.2, 0.16], snoutC: 0xf0a8b0, noseC: 0xc97f8a, ears: 'floppy', hoof: DARK, tail: { len: 0.7, w: 0.06, ang: -2.85, tip: DARK }, extra: (x) => { const t = x.top, k = tint(x.C, -0.62); spots(x, k, [[0.4, 0.3, 0.5, 0.13, t - 0.14, 0.3], [0.35, 0.4, 0.45, -0.15, t - 0.3, -0.4], [0.2, 0.25, 0.3, 0.22, t - 0.45, -0.15]]); x.body.add(at(box(0.3, 0.14, 0.3, 0xf0a8b0), 0, x.s.leg - 0.05, -0.35)); for (const sx of [1, -1]) x.hg.add(at(cone(0.05, 0.2, 0xe8e0c8, null, 5), sx * 0.16, 0.34, 0.05, 0, 0, -sx * 0.5)); } }], pig: [0xf0a3ae, { L: 1.0, H: 0.52, W: 0.5, leg: 0.25, lw: 0.13, neck: 0.08, na: 0.3, nw: 0.3, hd: [0.4, 0.38, 0.3], snout: [0.2, 0.16, 0.12], noseC: 0xc96f80, ears: 'point', earH: 0.35, tail: { len: 0.2, w: 0.05, ang: -0.8 } }], sheep: [0xf2efe8, { L: 1.0, H: 0.55, W: 0.52, leg: 0.38, lw: 0.1, legC: 0x33302e, neck: 0.15, na: 0.8, nw: 0.2, hd: [0.24, 0.26, 0.3], headC: 0x33302e, earC: 0x33302e, ears: 'floppy', tail: { len: 0.14, w: 0.12, ang: -1.6 }, extra: (x) => { const y = x.s.leg + x.s.H / 2; for (const [px, py, pz, r] of [[0, 0.12, 0.3, 0.36], [0.1, 0.16, -0.05, 0.38], [-0.1, 0.12, -0.35, 0.36], [0, 0.3, 0.05, 0.3], [0, 0.42, 0.52, 0.2]]) x.body.add(at(ball(r, x.C), px, y + py, pz)); } }], fox: [0xe2702a, { L: 0.8, H: 0.28, W: 0.26, leg: 0.3, lw: 0.08, legC: 0x3a2a22, neck: 0.15, na: 0.9, nw: 0.16, hd: [0.26, 0.22, 0.24], snout: [0.1, 0.08, 0.2], snoutC: WHITE, ears: 'point', earH: 0.7, earC: 0x3a2a22, tail: { len: 0.55, w: 0.16, ang: -1.75, tip: WHITE } }], bear: [0x6b4530, { L: 1.5, H: 0.8, W: 0.75, leg: 0.55, lw: 0.24, neck: 0.2, na: 0.5, nw: 0.4, hd: [0.5, 0.45, 0.42], snout: [0.24, 0.2, 0.2], ears: 'round', tail: { len: 0.12, w: 0.14, ang: -1.5 } }], elephant: [0x8f949c, { L: 2.4, H: 1.4, W: 1.2, leg: 1.2, lw: 0.38, neck: 0.25, na: 0.2, nw: 0.7, hd: [0.9, 1.0, 0.8], ears: 'big', eye: 0.07, tail: { len: 0.7, w: 0.07, ang: -2.95, tip: DARK }, extra: (x) => { let p = x.hg, len = 0.42, w = 0.3; const trunk = joint(0, -0.15, 0.6); x.hg.add(trunk); p = trunk; p.rotation.x = 1.2; for (let i = 0; i < 4; i++) { p.add(at(box(w, len, w, x.C), 0, len / 2, 0)); const n = joint(0, len, 0); n.rotation.x = i === 2 ? -0.7 : 0.18; p.add(n); p = n; len *= 0.9; w *= 0.8; } x.parts.trunk = trunk; for (const sx of [1, -1]) x.hg.add(at(cone(0.07, 0.6, 0xf3ecd8, null, 6), sx * 0.3, -0.35, 0.72, 1.9, 0, 0)); } }], giraffe: [0xe8b84a, { L: 1.5, H: 0.7, W: 0.5, leg: 1.7, lw: 0.14, neck: 1.9, na: 1.25, nw: 0.26, hd: [0.24, 0.26, 0.5], snout: [0.2, 0.16, 0.2], ears: 'floppy', hoof: DARK, tail: { len: 0.8, w: 0.06, ang: -2.85, tip: DARK }, extra: (x) => { const k = tint(x.C, -0.3), t = x.top; spots(x, k, [[0.3, 0.3, 0.3, 0.12, t - 0.2, 0.3], [0.3, 0.3, 0.4, -0.12, t - 0.3, -0.3], [0.2, 0.3, 0.3, 0.17, t - 0.45, -0.2], [0.25, 0.2, 0.3, -0.14, t - 0.1, 0.1]]); for (let i = 0; i < 4; i++) x.head.add(at(box(0.28, 0.22, 0.2, k), i % 2 ? 0.02 : -0.02, 0.35 + i * 0.4, 0.1 + i * 0.13, Math.PI / 2 - 1.25)); for (const sx of [1, -1]) x.hg.add(at(cyl(0.03, 0.03, 0.18, k), sx * 0.07, 0.3, 0.1), at(ball(0.045, DARK), sx * 0.07, 0.4, 0.1)); } }], rabbit: [0xeeeae4, { L: 0.42, H: 0.26, W: 0.24, leg: 0.14, lw: 0.08, neck: 0.06, na: 1.0, nw: 0.16, hd: [0.24, 0.22, 0.22], snout: [0.1, 0.07, 0.05], noseC: 0xe58a9a, ears: 'long', earC: 0xeeeae4, c2: 0xe0dbd2, tail: { len: 0.1, w: 0.12, ang: -1.4, c: WHITE }, eye: 0.04 }], lion: [0xd9a441, { L: 1.5, H: 0.55, W: 0.48, leg: 0.6, lw: 0.16, neck: 0.2, na: 0.7, nw: 0.3, hd: [0.4, 0.38, 0.36], snout: [0.22, 0.16, 0.16], ears: 'round', tail: { len: 0.8, w: 0.06, ang: -2.3, tip: 0x5a3a1c }, extra: (x) => x.hg.add(at(ball(0.42, 0x8a5a24), 0, 0.05, -0.08, 0, 0, 0, [1, 1, 0.75])) }], dragon: [0x3d9a55, { L: 2.0, H: 0.7, W: 0.6, leg: 0.6, lw: 0.2, neck: 0.9, na: 1.0, nw: 0.3, hd: [0.4, 0.36, 0.6], snout: [0.3, 0.2, 0.3], flyer: true, tail: { len: 1.4, w: 0.22, ang: -1.8 }, eye: 0.06, extra: (x) => { const k = tint(x.C, -0.2), w = tint(x.C, 0.15); for (const sx of [1, -1]) x.hg.add(at(cone(0.06, 0.3, 0xf3ecd8, null, 5), sx * 0.13, 0.36, 0, -0.5, 0, 0)); for (let i = 0; i < 5; i++) x.body.add(at(cone(0.09, 0.24, k, null, 4), 0, x.top + 0.1, 0.8 - i * 0.4)); x.parts.wings = [1, -1].map((sx) => { const j = joint(sx * 0.28, x.top - 0.05, 0.3, at(box(1.7, 0.05, 0.9, w), sx * 0.85, 0, -0.1), at(box(0.9, 0.05, 0.6, w), sx * 1.9, 0, -0.3)); j.rotation.z = sx * 0.35; x.body.add(j); return j; }); } }], }; // ------------------------------------------------------------------ two-legged characters function biped(o, C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const leg = o.leg ?? 0.78, [tw, th, td] = o.torso ?? [0.5, 0.62, 0.28], aw = o.aw ?? 0.14, al = o.arm ?? 0.6, lw = o.lw ?? 0.19; const skin = o.skin ?? SKIN, pants = o.pants ?? 0x35445c, sleeve = o.sleeve ?? C; body.add(at(box(tw, th, td, C), 0, leg + th / 2, 0)); const legs = [1, -1].map((sx) => { const j = joint(sx * (tw / 2 - lw / 2), leg, 0, at(box(lw, leg, lw, pants), 0, -leg / 2, 0), at(box(lw * 1.05, 0.1, lw * 1.5, o.shoes ?? DARK), 0, -leg + 0.05, lw * 0.25)); body.add(j); return j; }); const arms = [1, -1].map((sx) => { const j = joint(sx * (tw / 2 + aw / 2), leg + th - aw * 0.4, 0, at(box(aw, al, aw, sleeve), 0, -al / 2 + aw * 0.4, 0), at(box(aw * 1.05, aw * 1.1, aw * 1.05, o.hand ?? skin), 0, -al + aw * 0.2, 0)); body.add(j); return j; }); const hs = o.head ?? 0.34; const head = joint(0, leg + th, 0); if (!o.noHead) { head.add(at(box(hs * 0.45, 0.1, hs * 0.45, skin), 0, 0.03, 0), at(box(hs, hs, hs, skin), 0, 0.06 + hs / 2, 0)); eyes(head, hs * 0.22, 0.06 + hs * 0.58, hs / 2 + 0.005, 0.035); } body.add(head); const parts = { body, head, legs, arms }; o.extra?.({ body, head, arms, legs, C, leg, tw, th, td, hs, parts, al, aw }); return rig(root, 'biped', { h: leg + th + hs + 0.1 + (o.hat ?? 0), r: 0.45, top: leg + th + hs + 0.08, seat: [0, leg + th, -0.1], leg }, parts); } const BIPEDS = { man: [0x3b76c4, { extra: (x) => x.head.add(at(box(0.36, 0.12, 0.36, 0x4a3323), 0, 0.37, -0.01), at(box(0.36, 0.2, 0.1, 0x4a3323), 0, 0.26, -0.14)) }], woman: [0xd9486e, { pants: SKIN, lw: 0.15, torso: [0.44, 0.6, 0.26], aw: 0.12, extra: (x) => { x.head.add(at(box(0.38, 0.14, 0.38, 0x6b3a1e), 0, 0.37, -0.01), at(box(0.38, 0.5, 0.12, 0x6b3a1e), 0, 0.14, -0.16)); x.body.add(at(cone(0.36, 0.5, x.C, null, 8), 0, x.leg - 0.12, 0)); } }], robot: [0xaab3bd, { skin: 0xaab3bd, noHead: true, torso: [0.56, 0.62, 0.36], aw: 0.15, lw: 0.2, extra: (x) => { const d = tint(x.C, -0.25); for (const p of [...x.legs, ...x.arms]) p.children.forEach((m, i) => { m.material = mat(i ? d : tint(x.C, -0.1), { metal: 1 }); }); x.head.add(at(box(0.12, 0.08, 0.12, d), 0, 0.03, 0), at(box(0.42, 0.34, 0.36, x.C, { metal: 1 }), 0, 0.24, 0), at(box(0.32, 0.1, 0.03, 0x4fe3ff, { emissive: 0x4fe3ff, glow: 1.4 }), 0, 0.27, 0.185), at(cyl(0.012, 0.012, 0.2, d), 0, 0.5, 0), at(orb(0.04, 0xff5a4a, { emissive: 0xff5a4a }), 0, 0.62, 0)); x.body.add(at(box(0.3, 0.22, 0.03, d), 0, x.leg + x.th * 0.6, x.td / 2 + 0.01), at(box(0.06, 0.06, 0.02, 0x7dff7a, { emissive: 0x7dff7a }), -0.07, x.leg + x.th * 0.62, x.td / 2 + 0.03), at(box(0.06, 0.06, 0.02, 0xffd24a, { emissive: 0xffd24a }), 0.07, x.leg + x.th * 0.62, x.td / 2 + 0.03)); }, hat: 0.2 }], alien: [0x6fcf5a, { noHead: true, torso: [0.36, 0.5, 0.22], leg: 0.6, aw: 0.09, lw: 0.11, arm: 0.6, extra: (x) => { const c = x.C, suit = tint(c, -0.28); x.body.children[0].material = mat(suit); for (const p of x.legs) p.children[0].material = mat(suit); for (const p of x.arms) p.children.forEach((m) => { m.material = mat(c); }); x.head.add(at(box(0.1, 0.1, 0.1, c), 0, 0.03, 0), at(ball(0.3, c), 0, 0.34, 0.02, 0, 0, 0, [1, 1.05, 0.95]), at(orb(0.085, 0x101014), 0.12, 0.34, 0.24, 0, 0, 0.5, [1, 1.5, 0.6]), at(orb(0.085, 0x101014), -0.12, 0.34, 0.24, 0, 0, -0.5, [1, 1.5, 0.6])); for (const sx of [1, -1]) x.head.add(at(cyl(0.012, 0.012, 0.26, c), sx * 0.12, 0.72, 0, 0, 0, -sx * 0.3), at(orb(0.04, 0xf2e85a, { emissive: 0xf2e85a }), sx * 0.16, 0.85, 0)); }, hat: 0.3 }], astronaut: [0xf4f4f0, { noHead: true, pants: null, torso: [0.6, 0.66, 0.4], aw: 0.18, lw: 0.23, shoes: 0x8d9199, hand: 0x8d9199, extra: (x) => { for (const p of x.legs) p.children[0].material = mat(tint(x.C, -0.06)); x.head.add(at(orb(0.3, x.C), 0, 0.3, 0), at(orb(0.24, 0x1d2b45, { metal: 1 }), 0, 0.3, 0.1, 0, 0, 0, [1, 0.85, 0.9])); x.body.add(at(box(0.46, 0.6, 0.2, tint(x.C, -0.14)), 0, x.leg + x.th * 0.55, -0.3), at(box(0.2, 0.14, 0.03, 0x2f6fde), 0.12, x.leg + x.th * 0.7, 0.21), at(box(0.1, 0.06, 0.03, 0xd63c33), -0.14, x.leg + x.th * 0.74, 0.21)); }, hat: 0.25 }], knight: [0xc4c9d1, { noHead: true, pants: null, torso: [0.56, 0.64, 0.34], aw: 0.16, lw: 0.21, shoes: 0x55585e, extra: (x) => { const m = { metal: 1 }, d = tint(x.C, -0.2); x.body.children[0].material = mat(x.C, m); for (const p of [...x.legs, ...x.arms]) p.children.forEach((q) => { q.material = mat(d, m); }); x.head.add(at(cyl(0.2, 0.2, 0.36, x.C, m, 8), 0, 0.22, 0), at(box(0.3, 0.05, 0.03, 0x101014), 0, 0.26, 0.19), at(box(0.04, 0.2, 0.03, 0x101014), 0, 0.18, 0.19), at(box(0.06, 0.2, 0.36, 0xd63c33), 0, 0.5, -0.04)); x.arms[1].add(at(box(0.05, 0.9, 0.09, 0xdfe4ea, m), 0, -0.52, 0.5, Math.PI / 2), at(box(0.26, 0.05, 0.08, 0x6b4a2a), 0, -0.52, 0.1)); x.arms[0].add(at(box(0.06, 0.6, 0.48, 0x2f6fde), 0.11, -0.32, 0.05), at(box(0.02, 0.4, 0.1, 0xe2b23a), 0.145, -0.32, 0.05)); }, hat: 0.3 }], wizard: [0x6a3fb5, { extra: (x) => { const c = x.C, d = tint(c, -0.15); x.body.add(at(cone(0.46, x.leg + 0.25, c, null, 9), 0, (x.leg + 0.25) / 2, 0)); x.head.add(at(cyl(0.34, 0.34, 0.04, d, null, 12), 0, 0.4, 0), at(cone(0.22, 0.6, c, null, 9), 0, 0.72, 0, -0.12), at(box(0.28, 0.34, 0.1, WHITE), 0, 0.02, 0.17), at(box(0.36, 0.1, 0.36, WHITE), 0, 0.33, -0.02)); x.arms[1].add(at(cyl(0.03, 0.03, 1.6, 0x6b4a2a, null, 6), 0, -0.3, 0.12), at(orb(0.1, 0x66e0ff, { emissive: 0x66e0ff, glow: 1.6 }), 0, 0.56, 0.12)); }, hat: 0.65 }], }; // ------------------------------------------------------------------ birds function birdy(o, C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const s = o.s ?? 1, leg = (o.leg ?? 0.16) * s, r = 0.2 * s, up = o.upright; const by = leg + r * (up ? 1.5 : 0.9); body.add(at(ball(r, C), 0, by, 0, 0, 0, 0, up ? [1, 1.7, 0.95] : [0.95, 0.95, 1.4])); if (o.belly) body.add(at(ball(r * 0.9, o.belly), 0, by - r * 0.05, r * 0.2, 0, 0, 0, up ? [0.9, 1.6, 0.85] : [0.8, 0.8, 1.2])); const head = joint(0, by + r * (up ? 1.75 : 0.8), r * (up ? 0.1 : 1.05)); head.add(at(ball(r * 0.62, o.headC ?? C), 0, r * 0.3, 0)); head.add(o.bill ? at(box(r * 0.5, r * 0.16, r * 0.6, o.beak ?? 0xf08a24), 0, r * 0.22, r * 0.8) : at(cone(r * 0.2, r * 0.55, o.beak ?? 0xf0a024, null, 5), 0, r * 0.26, r * 0.8, Math.PI / 2)); eyes(head, r * 0.4, r * 0.48, r * 0.38, r * 0.11); if (o.comb) head.add(at(box(r * 0.12, r * 0.4, r * 0.6, 0xd63c33), 0, r * 0.95, 0), at(box(r * 0.14, r * 0.3, r * 0.14, 0xd63c33), 0, -r * 0.05, r * 0.6)); body.add(head); const wc = o.wingC ?? tint(C, -0.12); const wings = [1, -1].map((sx) => { const j = up ? joint(sx * r * 0.95, by + r * 0.9, 0, at(box(r * 0.2, r * 1.7, r * 0.8, wc), sx * r * 0.08, -r * 0.8, 0)) : joint(sx * r * 0.8, by + r * 0.35, 0, at(box(r * 2.2, r * 0.14, r * 1.5, wc), sx * r * 1.05, 0, -r * 0.1)); if (!up) j.rotation.z = -sx * 1.25; body.add(j); return j; }); const tail = joint(0, by + r * 0.1, -r * (up ? 0.8 : 1.3), at(box(r * 0.9, r * 0.14, r * 0.9, wc), 0, 0, -r * 0.3)); tail.rotation.x = up ? -0.9 : 0.35; body.add(tail); const legs = [1, -1].map((sx) => { const j = joint(sx * r * 0.4, leg, 0, at(cyl(0.02 * s, 0.02 * s, leg, 0xf08a24, null, 5), 0, -leg / 2, 0), at(box(r * 0.45, 0.03 * s, r * 0.7, 0xf08a24), 0, -leg + 0.015, r * 0.15)); body.add(j); return j; }); const h = by + r * (up ? 2.7 : 1.7); return rig(root, 'bird', { h, r: r * 1.6, top: h, seat: [0, by + r * 0.9, 0], leg, flyer: !!o.flyer, upright: !!up, swims: !!o.swims }, { body, head, tail, legs, wings }); } const BIRDS = { bird: [0x4aa3df, { s: 1.3, flyer: true, belly: 0xf2e6c8 }], duck: [0xf5d04a, { s: 1.5, bill: true, flyer: true, swims: true }], chicken: [0xf4f4f0, { s: 1.6, comb: true, leg: 0.2 }], penguin: [0x2a2a30, { s: 2.0, upright: true, belly: 0xf4f4f0, leg: 0.06, swims: true }], }; // ------------------------------------------------------------------ fish function fishy(o, C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const s = o.s, y = o.hover; body.add(at(ball(0.3 * s, C), 0, y, 0, 0, 0, 0, [0.5, 0.75, 1.5])); if (o.belly) body.add(at(ball(0.28 * s, o.belly), 0, y - 0.05 * s, 0.02, 0, 0, 0, [0.48, 0.62, 1.4])); const fc = o.finC ?? tint(C, -0.15); const tail = joint(0, y, -0.4 * s, at(box(0.04 * s, 0.4 * s, 0.26 * s, fc), 0, 0, -0.14 * s), at(box(0.04 * s, 0.14 * s, 0.14 * s, fc), 0, 0.2 * s, -0.26 * s), at(box(0.04 * s, 0.14 * s, 0.14 * s, fc), 0, -0.2 * s, -0.26 * s)); body.add(tail, at(cone(0.1 * s, (o.dorsal ?? 0.22) * s, fc, null, 4), 0, y + (0.2 + (o.dorsal ?? 0.22) / 2) * s, -0.02 * s, -0.35, 0, 0, [0.3, 1, 1])); const fins = [1, -1].map((sx) => { const j = joint(sx * 0.13 * s, y - 0.08 * s, 0.12 * s, at(box(0.22 * s, 0.03 * s, 0.14 * s, fc), sx * 0.11 * s, 0, 0)); j.rotation.z = -sx * 0.5; body.add(j); return j; }); eyes(body, 0.13 * s, y + 0.05 * s, 0.26 * s, 0.035 * s); if (o.mouth) body.add(at(box(0.2 * s, 0.03 * s, 0.14 * s, 0x7a1f24), 0, y - 0.1 * s, 0.34 * s)); return rig(root, 'fish', { h: y + 0.3 * s, r: 0.5 * s, top: y + 0.25 * s, seat: [0, y + 0.2 * s, 0], swims: true, hover: y }, { body, tail, wings: fins }); } const FISH = { fish: [0xf08a24, { s: 1.0, hover: 0.7, belly: 0xf7d9a8 }], shark: [0x6e7f8f, { s: 3.2, hover: 1.2, belly: 0xe8ecef, dorsal: 0.3, mouth: true }], }; // ------------------------------------------------------------------ one-offs function snowman(C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const c = C ?? 0xc0392b; body.add(at(ball(0.55, WHITE), 0, 0.5, 0), at(ball(0.4, WHITE), 0, 1.2, 0)); const head = joint(0, 1.5, 0, at(ball(0.28, WHITE), 0, 0.22, 0), at(cone(0.05, 0.3, 0xf08a24, null, 6), 0, 0.22, 0.38, Math.PI / 2), at(cyl(0.3, 0.3, 0.03, DARK), 0, 0.44, 0), at(cyl(0.19, 0.19, 0.28, DARK), 0, 0.58, 0), at(cyl(0.195, 0.195, 0.06, c), 0, 0.49, 0)); eyes(head, 0.1, 0.3, 0.25, 0.035); body.add(head, at(torus(0.26, 0.06, c), 0, 1.5, 0, Math.PI / 2), at(box(0.1, 0.34, 0.05, c), 0.16, 1.32, 0.28, 0.1), at(orb(0.04, DARK), 0, 1.3, 0.38), at(orb(0.04, DARK), 0, 1.1, 0.4)); const arms = [1, -1].map((sx) => { const j = joint(sx * 0.36, 1.3, 0, at(cyl(0.02, 0.02, 0.6, 0x6b4a2a, null, 5), 0, -0.3, 0)); j.rotation.z = sx * 2.1; body.add(j); return j; }); return rig(root, 'blob', { h: 2.25, r: 0.6, top: 2.25, seat: [0, 2.2, 0] }, { body, head, arms }); } function ghost(C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const c = C ?? WHITE, o = { opacity: 0.9 }, y = 0.55; body.add(at(orb(0.42, c, o), 0, y + 0.9, 0), at(cyl(0.42, 0.46, 0.9, c, o, 14), 0, y + 0.45, 0)); for (let i = 0; i < 6; i++) body.add(at(cone(0.16, 0.3, c, o, 6), Math.cos(i * 1.047) * 0.3, y - 0.14, Math.sin(i * 1.047) * 0.3, Math.PI)); body.add(at(orb(0.07, 0x101014), 0.15, y + 0.95, 0.37, 0, 0, 0, [1, 1.4, 0.6]), at(orb(0.07, 0x101014), -0.15, y + 0.95, 0.37, 0, 0, 0, [1, 1.4, 0.6]), at(orb(0.06, 0x101014), 0, y + 0.72, 0.42, 0, 0, 0, [1, 1.3, 0.5])); const arms = [1, -1].map((sx) => { const j = joint(sx * 0.4, y + 0.7, 0.05, at(orb(0.13, c, o), sx * 0.02, -0.16, 0, 0, 0, 0, [0.8, 1.6, 0.8])); j.rotation.z = sx * 0.9; body.add(j); return j; }); return rig(root, 'blob', { h: y + 1.35, r: 0.55, top: y + 1.3, seat: [0, y + 1.3, 0], hover: 0.25, floaty: true }, { body, arms }); } function dinosaur(C) { const root = new THREE.Group(), body = new THREE.Group(); root.add(body); const c = C ?? 0x5c9a4a, d = tint(c, -0.12), l = tint(c, 0.16), leg = 1.3; const torso = joint(0, leg + 0.35, 0, at(box(0.85, 0.95, 1.9, c), 0, 0, 0), at(box(0.6, 0.3, 1.5, l), 0, -0.4, 0.1)); torso.rotation.x = -0.28; body.add(torso); const head = joint(0, 0.5, 0.95); head.rotation.x = 0.28; head.add(at(box(0.5, 0.5, 0.5, c), 0, 0.2, 0), at(box(0.62, 0.42, 1.0, c), 0, 0.6, 0.45), at(box(0.54, 0.16, 0.85, l), 0, 0.3, 0.5, 0.18)); for (let i = 0; i < 5; i++) for (const sx of [1, -1]) head.add(at(cone(0.035, 0.1, WHITE, null, 4), sx * 0.24, 0.36, 0.2 + i * 0.16, Math.PI)); eyes(head, 0.315, 0.7, 0.55, 0.06, 0xf2c230); torso.add(head); let tail = joint(0, 0, -0.95), p = tail, len = 0.7, w = 0.6; tail.rotation.x = 0.28 + 0.1; for (let i = 0; i < 4; i++) { p.add(at(box(w, w * 0.9, len, c), 0, 0, -len / 2)); const n = joint(0, 0, -len); p.add(n); p = n; w *= 0.68; len *= 0.95; } torso.add(tail); const arms = [1, -1].map((sx) => { const j = joint(sx * 0.4, -0.1, 0.8, at(box(0.11, 0.38, 0.11, d), 0, -0.19, 0), at(box(0.12, 0.1, 0.2, d), 0, -0.4, 0.06)); j.rotation.x = -0.9; torso.add(j); return j; }); const legs = [1, -1].map((sx) => { const j = joint(sx * 0.45, leg, -0.1, at(box(0.36, 0.7, 0.5, d), 0, -0.3, 0), at(box(0.24, 0.7, 0.26, d), 0, -0.9, 0.06), at(box(0.3, 0.14, 0.55, d), 0, -leg + 0.07, 0.2)); body.add(j); return j; }); return rig(root, 'biped', { h: 3.0, r: 1.5, top: leg + 0.9, seat: [0, leg + 0.85, -0.2], leg }, { body, head, tail, legs, arms }); } export const CREATURES = { ...Object.fromEntries(Object.entries(QUADS).map(([k, [c, s]]) => [k, (C) => quad(s, C ?? c)])), ...Object.fromEntries(Object.entries(BIPEDS).map(([k, [c, s]]) => [k, (C) => biped(s, C ?? c)])), ...Object.fromEntries(Object.entries(BIRDS).map(([k, [c, s]]) => [k, (C) => birdy(s, C ?? c)])), ...Object.fromEntries(Object.entries(FISH).map(([k, [c, s]]) => [k, (C) => fishy(s, C ?? c)])), snowman, ghost, dinosaur, };