Skip to content

Commit 34d04ed

Browse files
snow-jallenclaude
andcommitted
The Formics are insects in the 3D view
Whatever the theme, a seat the Formics play draws its units as a hive (3d/formics.js): drones with digging claws, mantis warriors with scythes, acid-sac spitters, hovering flyers and a siege beetle with a bile cannon, all on the theme's rig so they stride, dig, strike and cheer. The view picks a unit's model per seat and makes each model's instanced mesh when it first shows up. Siege poses and muzzles move to 3d/siege.js, keyed off the model (a gun has a muzzle) instead of the theme; util.js gains houseBot(name) for displayName and the view. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V8fdNFMnkyDNTFoKqQyD6L
1 parent 15ab37d commit 34d04ed

5 files changed

Lines changed: 253 additions & 46 deletions

File tree

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
// 3D match view: the Formics (the hardest house bot) aren't badgers or knights but a hive of insects.
2+
// Whatever the theme, a seat the Formics play draws its units with these models instead: chitin bodies
3+
// with the player's color on the abdomen and carapace, glowing eyes, four walking legs and two forelimbs.
4+
// They use the same rig as the theme's units (kit.js `limb`): legs swing from the hip (1), forelimbs from
5+
// the shoulder (2) so they dig, strike and cheer like arms, a flyer's legs dangle like a mount's (3), and
6+
// the siege beetle's cannon kicks back along its barrel (8) like the Snow Mobile's.
7+
//
8+
// One tile is one world unit; models stand on y = 0 and face +z.
9+
import * as THREE from 'three';
10+
import { col, K, Builder, cyl, ball, cone, box } from './kit.js';
11+
import { houseBot } from '../util.js';
12+
13+
const C = {
14+
chitin: col('#2a241e'), shell: col('#4a3d2e'), sheen: col('#55643a'), eye: col('#3fd11f'),
15+
acid: col('#9dff3a'), bone: col('#dcd2ae'), wing: col('#cfe6dc'),
16+
};
17+
const UP = new THREE.Vector3(0, 1, 0);
18+
19+
/** The seats the Formics play, from a frame's players. */
20+
export function formicSlots(players) {
21+
return new Set((players || []).filter((p) => houseBot(p.name) === 'formics').map((p) => p.slot));
22+
}
23+
24+
/** A tapering rod from one point to another (a leg or antenna segment). */
25+
function rod(b, from, to, r, color, opts = {}) {
26+
const a = new THREE.Vector3(...from), d = new THREE.Vector3(...to).sub(a);
27+
const e = new THREE.Euler().setFromQuaternion(new THREE.Quaternion().setFromUnitVectors(UP, d.clone().normalize()));
28+
return b.add(cyl(r * 0.75, r, d.length(), 5), color, { ...opts, at: a.addScaledVector(d, 0.5).toArray(), rot: [e.x, e.y, e.z] });
29+
}
30+
31+
/** A jointed limb through the points, with a knob at each joint; x is mirrored for the right side (side = -1). */
32+
function limb(b, points, r, color, side, opts = {}) {
33+
const p = points.map(([x, y, z]) => [x * side, y, z]);
34+
for (let i = 1; i < p.length; i++) {
35+
rod(b, p[i - 1], p[i], r * (1 - i * 0.15), color, opts);
36+
if (i < p.length - 1) b.add(ball(r * 1.05, 0), color, { ...opts, at: p[i] });
37+
}
38+
return p[p.length - 1];
39+
}
40+
41+
/** Big compound eyes, mandibles and feelers on a head centered at (0, y, z). */
42+
function face(b, y, z, { mandible = 1 } = {}) {
43+
for (const s of [-1, 1]) {
44+
b.add(ball(0.024, 1), C.eye, { glow: 0.45, at: [s * 0.036, y + 0.01, z + 0.028], scale: [0.8, 1, 1] })
45+
.add(cone(0.012 * mandible, 0.05 * mandible, 4), C.bone, { at: [s * 0.02, y - 0.03, z + 0.05], rot: [Math.PI / 2 + 0.3, 0, -s * 0.5] });
46+
limb(b, [[0.014, y + 0.04, z + 0.02], [0.05, y + 0.13, z + 0.06], [0.085, y + 0.12, z + 0.12]], 0.006, C.chitin, s);
47+
}
48+
}
49+
50+
/**
51+
* The upright body every walker shares: four splayed legs and a low thorax, the abdomen behind in the
52+
* player's color with dark bands, an upright torso and the head. abdomen scales the abdomen.
53+
*/
54+
function walker(b, { abdomen = 1, acid = false } = {}) {
55+
const r = 0.085 * abdomen, az = -0.12 - r;
56+
b.add(ball(0.055, 1), C.chitin, { at: [0, 0.15, -0.01], scale: [0.9, 0.75, 1.2] }) // hips
57+
.add(ball(0.026, 0), C.chitin, { at: [0, 0.165, -0.085] }) // waist
58+
.add(ball(r, 1), acid ? C.acid : K.teamShade, { team: acid ? 0 : 1, glow: acid ? 0.45 : 0, at: [0, 0.14 + r * 0.6, az], scale: [0.85, 0.8, 1.2] })
59+
.add(cone(0.02, 0.06, 5), C.chitin, { at: [0, 0.13 + r * 0.5, az - r * 1.25], rot: [-Math.PI / 2 - 0.3, 0, 0] }); // sting
60+
for (const dz of [-0.35, 0.3]) {
61+
b.add(cyl(r * 0.86, r * 0.86, 0.016, 10), acid ? K.teamShade : C.chitin, { team: acid ? 1 : 0, at: [0, 0.14 + r * 0.6, az + dz * r], rot: [Math.PI / 2, 0, 0], scale: [1, 1, 0.94] });
62+
}
63+
b.add(ball(0.05, 1), C.shell, { at: [0, 0.24, 0.035], rot: [0.25, 0, 0], scale: [0.95, 1.5, 0.85] }) // torso
64+
.add(ball(0.05, 1), C.chitin, { at: [0, 0.345, 0.075], scale: [1, 0.9, 1.15] }); // head
65+
face(b, 0.345, 0.075);
66+
// Front legs step with the far rear leg, like a trotting horse.
67+
for (const s of [-1, 1]) {
68+
limb(b, [[0.04, 0.15, 0.02], [0.11, 0.19, 0.06], [0.15, 0.005, 0.1]], 0.016, C.chitin, s, { limb: s, joint: 0.02 });
69+
limb(b, [[0.04, 0.15, -0.04], [0.11, 0.185, -0.09], [0.155, 0.005, -0.14]], 0.016, C.chitin, s, { limb: -s, joint: -0.04 });
70+
}
71+
}
72+
73+
/** The forelimbs, hanging forward from the shoulders; tool(side, hand) adds whatever each one holds. */
74+
function forelimbs(b, tool) {
75+
for (const s of [-1, 1]) {
76+
const opts = { limb: s * 2, joint: 0.04 };
77+
const hand = limb(b, [[0.055, 0.28, 0.05], [0.1, 0.21, 0.09], [0.085, 0.19, 0.18]], 0.013, C.shell, s, opts);
78+
tool(s, hand, opts);
79+
}
80+
}
81+
82+
function drone() {
83+
const b = new Builder();
84+
walker(b);
85+
forelimbs(b, (s, [x, y, z], opts) => {
86+
for (const d of [-1, 1]) b.add(cone(0.01, 0.045, 4), C.bone, { ...opts, at: [x + d * 0.008, y - 0.01, z + 0.02], rot: [Math.PI / 2 + 0.6, 0, 0] });
87+
});
88+
return b.build();
89+
}
90+
91+
function warrior() {
92+
const b = new Builder();
93+
walker(b, { abdomen: 1.1 });
94+
// Armor: a crest down the head and back, spiked shoulders and a chest plate, all in the player's color.
95+
b.add(box(0.014, 0.05, 0.11), K.team, { team: 1, at: [0, 0.39, 0.06], rot: [-0.3, 0, 0] })
96+
.add(box(0.08, 0.1, 0.02), K.team, { team: 1, at: [0, 0.25, 0.078], rot: [0.25, 0, 0] });
97+
for (const s of [-1, 1]) {
98+
b.add(ball(0.03, 0), C.shell, { at: [s * 0.06, 0.29, 0.04] })
99+
.add(cone(0.013, 0.07, 4), C.bone, { at: [s * 0.08, 0.33, 0.03], rot: [0, 0, -s * 0.6] })
100+
.add(cone(0.016, 0.07, 4), C.bone, { at: [s * 0.022, 0.31, 0.15], rot: [Math.PI / 2 + 0.2, 0, -s * 0.7] }); // big mandibles
101+
}
102+
// Scythes: a long hooked blade along each forearm.
103+
forelimbs(b, (s, [x, y, z], opts) => {
104+
b.add(box(0.012, 0.03, 0.2), C.bone, { ...opts, at: [x, y + 0.04, z + 0.02], rot: [-0.5, 0, 0] })
105+
.add(box(0.004, 0.012, 0.18), K.team, { ...opts, team: 1, at: [x, y + 0.058, z + 0.02], rot: [-0.5, 0, 0] })
106+
.add(cone(0.01, 0.06, 4), C.bone, { ...opts, at: [x, y + 0.08, z + 0.13], rot: [0.6, 0, 0] });
107+
});
108+
return b.build();
109+
}
110+
111+
function spitter() {
112+
const b = new Builder();
113+
walker(b, { abdomen: 1.35, acid: true });
114+
// A spout under the jaw and drips of acid down the sac.
115+
b.add(cyl(0.012, 0.02, 0.05, 6), C.sheen, { at: [0, 0.31, 0.135], rot: [Math.PI / 2 + 0.4, 0, 0] })
116+
.add(ball(0.01, 0), C.acid, { glow: 1.2, at: [0, 0.3, 0.16] })
117+
.add(box(0.07, 0.016, 0.05), K.team, { team: 1, at: [0, 0.37, 0.06], rot: [-0.2, 0, 0] });
118+
forelimbs(b, (s, [x, y, z], opts) => b.add(cone(0.008, 0.035, 4), C.bone, { ...opts, at: [x, y - 0.005, z + 0.025], rot: [Math.PI / 2 + 0.4, 0, 0] }));
119+
return b.build();
120+
}
121+
122+
function flyer() {
123+
// A hovering flyer: a long banded tail, four wings that sweep as it flies (limb 2) and legs dangling
124+
// underneath (limb 3).
125+
const b = new Builder();
126+
b.add(ball(0.05, 1), C.shell, { at: [0, 0.33, 0.02], scale: [0.9, 0.85, 1.3] })
127+
.add(ball(0.045, 1), C.chitin, { at: [0, 0.345, 0.11] })
128+
.add(box(0.02, 0.012, 0.09), K.team, { team: 1, at: [0, 0.373, 0.02] });
129+
face(b, 0.345, 0.11, { mandible: 0.7 });
130+
rod(b, [0, 0.33, -0.04], [0, 0.31, -0.32], 0.03, K.teamShade, { team: 1 });
131+
for (let i = 0; i < 4; i++) b.add(ball(0.03 - i * 0.004, 0), C.chitin, { at: [0, 0.327 - i * 0.006, -0.08 - i * 0.065], scale: [1.08, 1.08, 0.5] });
132+
b.add(cone(0.012, 0.05, 4), C.chitin, { at: [0, 0.305, -0.345], rot: [-Math.PI / 2, 0, 0] });
133+
for (const s of [-1, 1]) {
134+
for (const [z, w, sign] of [[0.045, 1, 1], [-0.025, 0.9, -1]]) {
135+
b.add(ball(0.1, 1), C.wing, { glow: 0.2, limb: s * sign * 2, joint: z, at: [s * 0.14 * w, 0.37, z], scale: [1.5 * w, 0.05, 0.36], rot: [0, s * 0.15 * sign, 0] });
136+
}
137+
for (const z of [0.06, 0.01, -0.04]) {
138+
limb(b, [[0.03, 0.3, z], [0.075, 0.22, z + 0.03], [0.06, 0.12, z + 0.02]], 0.008, C.chitin, s, { limb: (s < 0 ? 3 : -3) * (z > 0 ? 1 : -1), joint: z });
139+
}
140+
}
141+
return b.build();
142+
}
143+
144+
/** Where the siege beetle's shot leaves its cannon (model units, facing +z). */
145+
const MUZZLE = { y: 0.47, z: 0.25 };
146+
147+
function siegeBeetle() {
148+
// A siege beetle: a broad armored shell in the player's color, six stubby legs, a horned head, and an
149+
// acid sac on its back feeding a cannon that kicks back when it fires (limb 8).
150+
const b = new Builder();
151+
b.add(ball(0.2, 1), C.chitin, { at: [0, 0.13, -0.02], scale: [0.95, 0.5, 1.2] });
152+
for (const s of [-1, 1]) {
153+
b.add(ball(0.2, 1), K.teamShade, { team: 1, at: [s * 0.075, 0.19, -0.05], scale: [0.55, 0.5, 1.15] });
154+
for (const z of [0.12, 0, -0.14]) limb(b, [[0.12, 0.1, z], [0.22, 0.12, z + 0.03], [0.25, 0.005, z + 0.05]], 0.018, C.chitin, s);
155+
}
156+
b.add(box(0.012, 0.03, 0.4), C.chitin, { at: [0, 0.29, -0.06] }) // the seam
157+
.add(ball(0.08, 1), C.chitin, { at: [0, 0.14, 0.23], scale: [1, 0.85, 1] })
158+
.add(cone(0.03, 0.14, 5), C.bone, { at: [0, 0.22, 0.29], rot: [0.9, 0, 0] }); // horn
159+
face(b, 0.14, 0.24, { mandible: 1.5 });
160+
b.add(ball(0.09, 1), C.acid, { glow: 0.5, at: [0, 0.33, -0.13], scale: [1, 0.8, 1.1] });
161+
const gun = { limb: 8 };
162+
rod(b, [0, 0.31, -0.04], [0, MUZZLE.y, MUZZLE.z], 0.045, C.shell, gun);
163+
b.add(cyl(0.05, 0.05, 0.025, 8), C.chitin, { ...gun, at: [0, 0.35, 0.03], rot: [0.95, 0, 0] })
164+
.add(cyl(0.04, 0.04, 0.02, 8), C.acid, { ...gun, glow: 0.8, at: [0, MUZZLE.y - 0.005, MUZZLE.z - 0.005], rot: [0.95, 0, 0] });
165+
return b.build();
166+
}
167+
168+
/** The Formics' unit models, shaped like the theme's (buildModels): geometry, health-bar height, scale. */
169+
export function formicUnits() {
170+
return {
171+
Worker: { geo: drone(), height: 0.44, scale: 0.95 },
172+
Soldier: { geo: warrior(), height: 0.46, scale: 1.2 },
173+
Archer: { geo: spitter(), height: 0.48 },
174+
Scout: { geo: flyer(), height: 0.5 },
175+
Trebuchet: { geo: siegeBeetle(), height: 0.5, scale: 1.05, vehicle: true, muzzle: MUZZLE },
176+
};
177+
}

‎src/NetRts.Server/wwwroot/3d/models.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ export function buildModels(badger) {
717717
Archer: { geo: archer(badger), height: 0.52 },
718718
Scout: { geo: scout(badger), height: 0.7 },
719719
// A vehicle, not a walker: the view rolls it along instead of striding (see updateUnits).
720-
Trebuchet: { geo: badger ? snowMobile() : trebuchet(), height: 0.6, scale: 1.15, vehicle: true },
720+
// The Snow Mobile's cannon fires from its muzzle; a model without one throws from an arm (siege.js).
721+
Trebuchet: { geo: badger ? snowMobile() : trebuchet(), height: 0.6, scale: 1.15, vehicle: true, muzzle: badger ? { y: 0.635, z: 0.304 } : null },
721722
},
722723
building(type, slot) {
723724
if (badger && type === 'CommandCenter') {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// 3D match view: how siege engines move when they fire, and where their shots leave from. The trebuchet
2+
// (models.js) swings its arm over its axle; a gun (the Snow Mobile, the Formics' siege beetle: a unit
3+
// model with a `muzzle`) kicks back along its barrel.
4+
import { smoothstep } from './noise.js';
5+
6+
// The trebuchet's arm swings this far over (radians) to let its stone go, from rest at this angle about
7+
// its axle; the arm's tip is this far out.
8+
const ARM_UP = 2.5, ARM_REST = -2.44, ARM_AXLE = 0.36, ARM_TIP = 0.43;
9+
const SIEGE_COOLDOWN = 8; // GameRules: a trebuchet fires every 8 ticks
10+
11+
/**
12+
* A siege engine's moving parts (iDraw, see models.js) `since` ms after it fired, with ticks `interval` ms
13+
* apart. The trebuchet's arm swings over to let the stone go right at the shot's launch, quivers at the
14+
* top, then is winched back down before the next shot: [arm angle, 1 while the stone is away]. A gun kicks
15+
* back and runs out again: [recoil, 0].
16+
*/
17+
export function siegePose(def, since, interval) {
18+
if (def.muzzle) return [since < 0 || since > 1200 ? 0 : since < 40 ? since / 40 : Math.exp(-(since - 40) / 220), 0];
19+
const reload = Math.max(400, SIEGE_COOLDOWN * interval);
20+
const swing = Math.min(320, reload * 0.15), hold = Math.min(450, reload * 0.2), back = reload * 0.85;
21+
const t = since + swing; // the arm starts over before the stone lets go
22+
if (t < 0 || t >= back) return [0, 0];
23+
if (t < swing) return [ARM_UP * (t / swing) ** 2, 0];
24+
if (t < swing + hold) {
25+
const w = (t - swing) / hold;
26+
return [ARM_UP + Math.sin(w * Math.PI * 3) * 0.12 * (1 - w), 1];
27+
}
28+
return [ARM_UP * (1 - smoothstep(0, 1, (t - swing - hold) / (back - swing - hold))), 1];
29+
}
30+
31+
/** Where a siege engine's shot leaves it, in model units facing +z: the gun's muzzle, or the arm's tip at the top of its swing. */
32+
export function muzzleOf(def) {
33+
if (def.muzzle) return def.muzzle;
34+
const ang = ARM_REST - ARM_UP;
35+
return { y: ARM_AXLE + Math.sin(ang) * ARM_TIP, z: Math.cos(ang) * ARM_TIP };
36+
}

0 commit comments

Comments
 (0)