hughe update

This commit is contained in:
2026-11-15 17:08:11 +01:00
parent 7a69651b6d
commit 319436a5f9
50 changed files with 1987 additions and 313 deletions

View File

@@ -173,12 +173,18 @@
M.lamp = new T.MeshStandardMaterial({ color: 0xffffff, emissive: 0xfff2c0, emissiveIntensity: 1.5 }); // floodlights (intro switches them on)
M.stripe = new T.MeshStandardMaterial({ map: stripeTex(), metalness: 0.3, roughness: 0.6 });
M.flame = new T.MeshBasicMaterial({ color: 0xff3a08, transparent: true, opacity: 0.42, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
M.flameCore = new T.MeshBasicMaterial({ color: 0xffd060, transparent: true, opacity: 0.55, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
M.arc = new T.MeshBasicMaterial({ color: 0x6ec8ff, transparent: true, opacity: 0.5, blending: T.AdditiveBlending, depthWrite: false, side: T.DoubleSide });
M.trackTex = canvasTex(64, 16, (c, w, h) => { c.fillStyle = '#17181b'; c.fillRect(0, 0, w, h); c.fillStyle = '#2c2e33'; for (let x = 0; x < w; x += 8) c.fillRect(x, 0, 4, h); }, [6, 1]);
M.track = new T.MeshStandardMaterial({ map: M.trackTex, roughness: 0.85, metalness: 0.2 });
M.wsteel = new T.MeshStandardMaterial({ color: 0xd2d7de, metalness: 0.95, roughness: 0.22 }); // bright weapon steel
M.wedge = new T.MeshStandardMaterial({ color: 0x9aa0a8, metalness: 0.85, roughness: 0.35 });
return M;
}
// shop: the robot is framed in the left column, not in the middle of the stage
const GARAGE_OFF_X = 455, GARAGE_OFF_Y = 16;
// shop zoom: 0.6 = furthest out (the default, whole robot in frame), 1.9 = closest
const GZ_MIN = 0.6, GZ_MAX = 1.9, GZ_DEF = GZ_MIN;
const box = (w, h, d, m) => { const o = new T.Mesh(new T.BoxGeometry(w, h, d), m); o.castShadow = true; o.receiveShadow = true; return o; };
const cyl = (r1, r2, h, m, seg = 20) => { const o = new T.Mesh(new T.CylinderGeometry(r1, r2, h, seg), m); o.castShadow = true; return o; };
@@ -220,6 +226,17 @@
return geo;
}
// body from a top-view outline, extruded upwards (shape plane XY -> XZ, extrusion -> +Y)
function prism(pts, h) {
const sh = new T.Shape();
sh.moveTo(pts[0][0], pts[0][1]);
for (let i = 1; i < pts.length; i++) sh.lineTo(pts[i][0], pts[i][1]);
sh.closePath();
const g = new T.ExtrudeGeometry(sh, { depth: h, bevelEnabled: true, bevelSize: 0.015, bevelThickness: 0.015, bevelSegments: 1 });
g.rotateX(-Math.PI / 2);
return g;
}
function buildRobot(build, paint) {
const m = mats(), st = RC.stats(build), P = RC.PARTS;
const ch = P[build.chassis], wh = P[build.wheels], ar = build.armour ? P[build.armour] : null;
@@ -233,7 +250,7 @@
const out = { root, tilt, body, skin, st, build, roll: 0, flash: 0, spinA: 0, sawA: 0, gunA: 0, smokeT: 0 };
const sk = (geo, w, h, d, y0) => { const o = new T.Mesh(skinUV(geo, w, d, h, y0), body); o.castShadow = o.receiveShadow = true; return o; };
const look = paint.look || {}; // opponent look (looks.js), cosmetic only
const big = wh && wh.kind === 'big';
const big = wh && (wh.kind === 'big' || wh.kind === 'stud');
const ws = look.wheelScale || 1;
const c = big ? 0.12 : 0.1 * ws; // ground clearance
out.c = c;
@@ -258,6 +275,44 @@
const ring = new T.Mesh(new T.TorusGeometry(1, 0.035, 8, 32), accent);
ring.rotation.x = Math.PI / 2; ring.scale.set(L * 0.5, Wd * 0.5, 1); ring.position.y = c + H * 0.5; tilt.add(ring);
top = c + H * 1.2;
} else if (ch.shape === 'hex' || ch.shape === 'arrow') {
const hx = L / 2, hz = Wd / 2;
const pts = ch.shape === 'hex'
? [[-hx * 0.55, -hz], [hx * 0.55, -hz], [hx, 0], [hx * 0.55, hz], [-hx * 0.55, hz], [-hx, 0]]
: [[hx, 0], [hx * 0.2, -hz], [-hx, -hz * 0.78], [-hx, hz * 0.78], [hx * 0.2, hz]];
const o = sk(prism(pts, H), L, H, Wd, 0); o.position.y = c; tilt.add(o);
if (!drawn) { const st1 = box(L * 0.28, 0.02, Wd * 0.5, m.stripe); st1.position.set(-L * 0.22, top + 0.012, 0); tilt.add(st1); }
} else if (ch.shape === 'barrel') {
const rr = Math.min(Wd, H * 1.9) / 2;
const g = new T.CylinderGeometry(rr, rr, L, 18); g.rotateZ(Math.PI / 2);
const o = sk(g, L, H, Wd, 0); o.position.y = c + rr; tilt.add(o);
for (const sx of [-1, 1]) { const cap = cyl(rr * 0.5, rr * 0.5, 0.07, m.hub, 14); cap.rotation.z = Math.PI / 2; cap.position.set(sx * L / 2, c + rr, 0); tilt.add(cap); }
for (const bx of [-0.22, 0.22]) { const band = cyl(rr * 1.03, rr * 1.03, 0.05, m.dark, 18); band.rotation.z = Math.PI / 2; band.position.set(bx * L, c + rr, 0); tilt.add(band); }
top = c + rr * 2;
} else if (ch.shape === 'saucer') {
const o = sk(new T.CylinderGeometry(1, 1, 1, 22), L, H, Wd, 0);
o.scale.set(L / 2, H, Wd / 2); o.position.y = c + H / 2; tilt.add(o);
const ring = new T.Mesh(new T.TorusGeometry(1, 0.035, 8, 30), accent);
ring.rotation.x = Math.PI / 2; ring.scale.set(L / 2 * 1.02, Wd / 2 * 1.02, 1); ring.position.y = c + H * 0.72; tilt.add(ring);
top = c + H;
} else if (ch.shape === 'plow') {
const bl = L * 0.84, bw = Wd * 0.9;
const o = sk(new T.BoxGeometry(bl, H, bw), bl, H, bw, -H / 2); o.position.set(-L * 0.08, c + H / 2, 0); tilt.add(o);
const plate = box(0.09, H * 1.35, Wd * 1.1, m.steel); plate.position.set(L / 2 - 0.04, c + H * 0.62, 0); plate.rotation.z = -0.32; tilt.add(plate);
const edge = box(0.12, 0.1, Wd * 1.12, m.stripe); edge.position.set(L / 2 + 0.16, c * 0.4, 0); tilt.add(edge);
top = c + H;
} else if (ch.shape === 'frame') {
const bm = 0.07;
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
const post = box(bm, H, bm, m.dark); post.position.set(sx * (L / 2 - bm / 2), c + H / 2, sz * (Wd / 2 - bm / 2)); tilt.add(post);
}
for (const y of [c + bm / 2, c + H - bm / 2]) {
for (const sz of [-1, 1]) { const rail = box(L, bm, bm, m.dark); rail.position.set(0, y, sz * (Wd / 2 - bm / 2)); tilt.add(rail); }
for (const sx of [-1, 1]) { const rail = box(bm, bm, Wd, m.dark); rail.position.set(sx * (L / 2 - bm / 2), y, 0); tilt.add(rail); }
}
const pan = sk(new T.BoxGeometry(L * 0.9, 0.09, Wd * 0.86), L * 0.9, 0.09, Wd * 0.86, -0.045);
pan.position.y = c + 0.07; tilt.add(pan);
top = c + H;
} else {
const o = sk(new T.BoxGeometry(L, H, Wd), L, H, Wd, -H / 2); o.position.y = c + H / 2; tilt.add(o);
if (!drawn) {
@@ -281,14 +336,41 @@
out.top = top;
mark('chassis');
// armour plates (sides + rear), bolts
// armour: every kind looks clearly different, so swapping it shows in the workshop preview
if (armour) {
for (const sz of [-1, 1]) {
const p = drawn ? sk(new T.BoxGeometry(L * 0.9, H * 0.78, 0.05), L * 0.9, H * 0.78, 0.05, -H * 0.39) : box(L * 0.9, H * 0.78, 0.05, armour);
p.position.set(0, c + H * 0.42, sz * (Wd / 2 + 0.028)); tilt.add(p);
for (const bx of [-0.36, 0, 0.36]) { const b = cyl(0.025, 0.025, 0.03, m.dark, 8); b.rotation.x = Math.PI / 2; b.position.set(bx * L, c + H * 0.55, sz * (Wd / 2 + 0.06)); tilt.add(b); }
const asty = (ar && ar.style) || 'plates';
const sideX = Wd / 2 + 0.028;
if (asty === 'mesh') { // open wire grille
for (const sz of [-1, 1]) {
for (const y of [c + H * 0.1, c + H * 0.74]) { const rail = box(L * 0.9, 0.05, 0.04, armour); rail.position.set(0, y, sz * sideX); tilt.add(rail); }
for (let k = 0; k < 6; k++) { const bar = box(0.045, H * 0.64, 0.04, armour); bar.position.set((k / 5 - 0.5) * L * 0.86, c + H * 0.42, sz * sideX); tilt.add(bar); }
}
} else if (asty === 'bumper') { // fat rubber buffers around the body
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
const b = new T.Mesh(new T.SphereGeometry(0.14, 12, 9), armour);
b.scale.set(1, 0.78, 1); b.castShadow = true;
b.position.set(sx * L * 0.4, c + H * 0.42, sz * (Wd / 2 + 0.055)); tilt.add(b);
}
for (const sx of [-1, 1]) { const b = box(0.11, H * 0.52, Wd * 0.78, armour); b.position.set(sx * (L / 2 + 0.055), c + H * 0.42, 0); tilt.add(b); }
} else if (asty === 'tiles') { // ceramic tiles with gaps
for (const sz of [-1, 1]) for (let kx = 0; kx < 4; kx++) for (let ky = 0; ky < 2; ky++) {
const tl = box(L * 0.19, H * 0.32, 0.05, armour);
tl.position.set((kx / 3 - 0.5) * L * 0.74, c + H * (0.26 + ky * 0.36), sz * sideX); tilt.add(tl);
}
const rr = box(0.05, H * 0.72, Wd * 0.9, armour); rr.position.set(-L / 2 - 0.028, c + H * 0.42, 0); tilt.add(rr);
} else { // solid plates (steel / titanium / hardox / spiked)
for (const sz of [-1, 1]) {
const p = drawn ? sk(new T.BoxGeometry(L * 0.9, H * 0.78, 0.05), L * 0.9, H * 0.78, 0.05, -H * 0.39) : box(L * 0.9, H * 0.78, 0.05, armour);
p.position.set(0, c + H * 0.42, sz * (Wd / 2 + 0.028)); tilt.add(p);
for (const bx of [-0.36, 0, 0.36]) { const b = cyl(0.025, 0.025, 0.03, m.dark, 8); b.rotation.x = Math.PI / 2; b.position.set(bx * L, c + H * 0.55, sz * (Wd / 2 + 0.06)); tilt.add(b); }
if (asty === 'spike') for (let k = 0; k < 4; k++) {
const sp = cyl(0.001, 0.055, 0.18, m.stripe, 8);
sp.rotation.x = sz * Math.PI / 2;
sp.position.set((k / 3 - 0.5) * L * 0.62, c + H * 0.5, sz * (Wd / 2 + 0.12)); tilt.add(sp);
}
}
const r = box(0.05, H * 0.78, Wd * 0.95, armour); r.position.set(-L / 2 - 0.028, c + H * 0.42, 0); tilt.add(r);
}
const r = box(0.05, H * 0.78, Wd * 0.95, armour); r.position.set(-L / 2 - 0.028, c + H * 0.42, 0); tilt.add(r);
}
mark('armour');
@@ -296,7 +378,23 @@
// wheels
out.wheels = [];
const side = Wd / 2 + (armour ? 0.13 : 0.08);
if (wh.kind === 'tracks' || look.tracksLook) {
if (wh.kind === 'hover') {
// air skirt: glowing ring, no wheels
const skirt = new T.Mesh(new T.CylinderGeometry(Wd * 0.6, Wd * 0.72, 0.14, 22),
new T.MeshStandardMaterial({ color: 0x223040, metalness: 0.5, roughness: 0.5, emissive: paint.accent, emissiveIntensity: 0.3 }));
skirt.scale.x = L / Wd * 0.92; skirt.position.set(-L * 0.04, 0.09, 0); skirt.castShadow = true; tilt.add(skirt);
const glow = new T.Mesh(new T.CylinderGeometry(Wd * 0.5, Wd * 0.5, 0.04, 22),
new T.MeshBasicMaterial({ color: paint.accent, transparent: true, opacity: 0.5, blending: T.AdditiveBlending, depthWrite: false }));
glow.scale.x = L / Wd * 0.92; glow.position.set(-L * 0.04, 0.02, 0); tilt.add(glow);
out.wheelR = 0.16;
} else if (wh.kind === 'drum') {
// one wide roller drum + two small rear casters
const R = (c + H) / 2 + 0.08;
const dr = cyl(R, R, Wd * 0.92, m.rubber, 20); dr.rotation.x = Math.PI / 2; dr.position.set(-L * 0.04, R, 0); tilt.add(dr); out.wheels.push(dr);
const hub = cyl(R * 0.4, R * 0.4, Wd * 0.94, m.hub, 12); hub.rotation.x = Math.PI / 2; hub.position.set(-L * 0.04, R, 0); tilt.add(hub);
for (const sz of [-1, 1]) { const w = new T.Group(); w.position.set(-L * 0.42, 0.13, sz * side); const t = cyl(0.13, 0.13, 0.14, m.hub, 10); t.rotation.x = Math.PI / 2; w.add(t); tilt.add(w); out.wheels.push(w); }
out.wheelR = R;
} else if (wh.kind === 'tracks' || look.tracksLook) {
for (const sz of [-1, 1]) {
const t = box(L * 1.02, 0.3, 0.2, m.track); t.position.set(0, 0.15, sz * side); tilt.add(t);
for (const bx of [-0.42, 0.42]) { const w = cyl(0.15, 0.15, 0.21, m.hub, 14); w.rotation.x = Math.PI / 2; w.position.set(bx * L, 0.15, sz * side); tilt.add(w); }
@@ -342,40 +440,86 @@
if (w) {
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
if (w.type === 'wedge') {
// short ramp plate at the front (as before - stays close to the body so it does not poke through)
const p = box(0.5, 0.05, Wd * 1.05, ED); p.position.set(L / 2 + 0.18, c * 0.5 + 0.08, 0); p.rotation.z = -0.42; tilt.add(p);
const edge = box(0.12, 0.16, Wd * 1.06, HZ); edge.position.set(L / 2 + 0.34, 0.02, 0); tilt.add(edge);
if (w.id === 'lance') {
// long spike lance
const shaft = cyl(0.05, 0.05, 0.85, m.dark, 8); shaft.rotation.z = Math.PI / 2; shaft.position.set(L / 2 + 0.42, c + H * 0.4, 0); tilt.add(shaft);
const tip = cyl(0.001, 0.13, 0.42, HZ, 12); tip.rotation.z = -Math.PI / 2; tip.position.set(L / 2 + 0.95, c + H * 0.4, 0); tilt.add(tip);
} else {
// short ramp plate at the front (as before - stays close to the body so it does not poke through)
const p = box(0.5, 0.05, Wd * 1.05, ED); p.position.set(L / 2 + 0.18, c * 0.5 + 0.08, 0); p.rotation.z = -0.42; tilt.add(p);
const edge = box(0.12, 0.16, Wd * 1.06, HZ); edge.position.set(L / 2 + 0.34, 0.02, 0); tilt.add(edge);
}
} else if (w.type === 'flipper') {
const lf = w.id === 'launcher' ? 1.3 : 1, wf = w.id === 'launcher' ? 1.12 : 1;
const piv = new T.Group(); piv.position.set(L / 2 - 0.1, c + H * 0.22, 0); tilt.add(piv);
const p = box(0.78, 0.09, Wd * 0.95, WS); p.position.x = 0.39; piv.add(p);
const s = box(0.78, 0.03, Wd * 0.4, accent); s.position.set(0.39, 0.06, 0); piv.add(s);
const edge = box(0.12, 0.14, Wd * 0.98, HZ); edge.position.set(0.78, 0, 0); piv.add(edge);
const p = box(0.78 * lf, 0.09, Wd * 0.95 * wf, WS); p.position.x = 0.39 * lf; piv.add(p);
const s = box(0.78 * lf, 0.03, Wd * 0.4, accent); s.position.set(0.39 * lf, 0.06, 0); piv.add(s);
const edge = box(0.12, 0.14, Wd * 0.98 * wf, HZ); edge.position.set(0.78 * lf, 0, 0); piv.add(edge);
const pist = cyl(0.05, 0.05, 0.4, m.hub, 8); pist.rotation.z = 1.0; pist.position.set(0.2, -0.16, 0); tilt.add(pist); // ram
out.flipper = piv;
} else if (w.type === 'hammer') {
const post = box(0.16, 0.26, 0.24, m.dark); post.position.set(-L * 0.1, top + 0.11, 0); tilt.add(post);
const piv = new T.Group(); piv.position.set(-L * 0.1, top + 0.16, 0); tilt.add(piv);
const arm = box(L * 0.82, 0.1, 0.1, m.dark); arm.position.x = L * 0.41; piv.add(arm);
const head = box(0.26, 0.42, 0.26, WS); head.position.set(L * 0.82, -0.12, 0); piv.add(head); // big mallet head
const face = box(0.1, 0.44, 0.28, HZ); face.position.set(L * 0.82 + 0.17, -0.12, 0); piv.add(face);
const spike = box(0.18, 0.12, 0.12, accent); spike.position.set(L * 0.82, 0.12, 0); piv.add(spike);
if (w.id === 'mace') {
const ball = new T.Mesh(new T.SphereGeometry(0.24, 14, 10), WS); ball.castShadow = true; ball.position.set(L * 0.82, -0.05, 0); piv.add(ball);
for (let k = 0; k < 6; k++) { const a = k / 6 * Math.PI * 2; const sp = box(0.16, 0.07, 0.07, HZ); sp.position.set(L * 0.82 + Math.cos(a) * 0.26, -0.05, Math.sin(a) * 0.26); sp.rotation.y = -a; piv.add(sp); }
} else {
const head = box(0.26, 0.42, 0.26, WS); head.position.set(L * 0.82, -0.12, 0); piv.add(head); // big mallet head
const face = box(0.1, 0.44, 0.28, HZ); face.position.set(L * 0.82 + 0.17, -0.12, 0); piv.add(face);
const spike = box(0.18, 0.12, 0.12, accent); spike.position.set(L * 0.82, 0.12, 0); piv.add(spike);
}
out.hammer = piv;
} else if (w.type === 'saw') {
const arm = box(0.4, 0.12, 0.12, m.dark); arm.position.set(L / 2 + 0.06, c + H * 0.5, 0); tilt.add(arm);
const guard = new T.Mesh(new T.TorusGeometry(0.42, 0.05, 8, 20, Math.PI), accent); // orange guard over the top
guard.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(guard);
const g = new T.Group(); g.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(g);
const d = cyl(0.38, 0.38, 0.04, WS, 32); d.rotation.x = Math.PI / 2; g.add(d);
for (let k = 0; k < 16; k++) { const t = box(0.11, 0.06, 0.05, WS); const a = k / 16 * Math.PI * 2; t.position.set(Math.cos(a) * 0.4, Math.sin(a) * 0.4, 0); t.rotation.z = a + 0.6; g.add(t); }
const hub = cyl(0.09, 0.09, 0.07, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
out.saw = g;
if (w.id === 'drill') {
// conical auger drill, spins on its forward (x) axis
const g = new T.Group(); g.position.set(L / 2 + 0.42, c + H * 0.5, 0); tilt.add(g);
const cone = cyl(0.001, 0.2, 0.72, WS, 14); cone.rotation.z = -Math.PI / 2; cone.castShadow = true; g.add(cone);
for (let k = 0; k < 3; k++) { const fl = box(0.6, 0.03, 0.06, HZ); fl.position.x = -0.1; fl.rotation.x = k / 3 * Math.PI * 2; g.add(fl); }
out.saw = g; out.sawAxis = 'x';
} else {
const guard = new T.Mesh(new T.TorusGeometry(0.42, 0.05, 8, 20, Math.PI), accent); // orange guard over the top
guard.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(guard);
const g = new T.Group(); g.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(g);
const d = cyl(0.38, 0.38, 0.04, WS, 32); d.rotation.x = Math.PI / 2; g.add(d);
for (let k = 0; k < 16; k++) { const t = box(0.11, 0.06, 0.05, WS); const a = k / 16 * Math.PI * 2; t.position.set(Math.cos(a) * 0.4, Math.sin(a) * 0.4, 0); t.rotation.z = a + 0.6; g.add(t); }
const hub = cyl(0.09, 0.09, 0.07, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
out.saw = g;
}
} else if (w.type === 'spinner') {
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.04, c + H * 0.32, 0); tilt.add(post);
const g = new T.Group(); g.position.set(L / 2 + 0.04, c + H * 0.3, 0); tilt.add(g);
const bar = box(1.5, 0.12, 0.22, WS); g.add(bar);
const stripe = box(1.5, 0.13, 0.08, HZ); g.add(stripe);
for (const sx of [-1, 1]) { const t = box(0.18, 0.16, 0.32, accent); t.position.x = sx * 0.72; g.add(t); }
out.spinner = g;
if (w.id === 'drum') {
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.02, c + H * 0.32, 0); tilt.add(post);
const g = new T.Group(); g.position.set(L / 2 + 0.12, c + H * 0.34, 0); tilt.add(g);
const drum = cyl(0.3, 0.3, 0.52, WS, 20); drum.castShadow = true; g.add(drum);
for (const sx of [-1, 1]) { const tb = box(0.14, 0.54, 0.12, HZ); tb.position.set(sx * 0.3, 0, 0); g.add(tb); }
out.spinner = g;
} else {
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.04, c + H * 0.32, 0); tilt.add(post);
const g = new T.Group(); g.position.set(L / 2 + 0.04, c + H * 0.3, 0); tilt.add(g);
const bar = box(1.5, 0.12, 0.22, WS); g.add(bar);
const stripe = box(1.5, 0.13, 0.08, HZ); g.add(stripe);
for (const sx of [-1, 1]) { const t = box(0.18, 0.16, 0.32, accent); t.position.x = sx * 0.72; g.add(t); }
out.spinner = g;
}
} else if (w.type === 'lifter') {
const piv = new T.Group(); piv.position.set(L / 2 - 0.08, c + H * 0.16, 0); tilt.add(piv);
const bar = box(0.12, 0.09, Wd * 0.95, m.dark); bar.position.set(0.06, 0, 0); piv.add(bar);
for (const sz of [-1, 1]) {
const prong = box(0.85, 0.07, Wd * 0.26, WS); prong.position.set(0.46, 0, sz * Wd * 0.3); piv.add(prong);
const tip = box(0.16, 0.1, Wd * 0.28, HZ); tip.position.set(0.9, 0.015, sz * Wd * 0.3); piv.add(tip);
}
out.flipper = piv;
} else if (w.type === 'vspinner') {
const arm = box(0.3, 0.14, 0.14, m.dark); arm.position.set(L / 2 + 0.02, c + H * 0.45, 0); tilt.add(arm);
const g = new T.Group(); g.position.set(L / 2 + 0.32, c + H * 0.42, 0); tilt.add(g);
const d = cyl(0.45, 0.45, 0.11, WS, 26); d.rotation.x = Math.PI / 2; g.add(d);
for (let k = 0; k < 4; k++) {
const tth = box(0.22, 0.17, 0.14, HZ); const a = k / 4 * Math.PI * 2;
tth.position.set(Math.cos(a) * 0.45, Math.sin(a) * 0.45, 0); tth.rotation.z = a; g.add(tth);
}
const hub = cyl(0.1, 0.1, 0.14, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
out.vspin = g;
} else if (w.type === 'crusher') {
out.jaws = [];
for (const sz of [-1, 1]) {
@@ -397,9 +541,12 @@
if (tw.type === 'flamer') {
const tank = cyl(0.08, 0.08, 0.26, new T.MeshStandardMaterial({ color: 0xc0392b, metalness: 0.4, roughness: 0.4 }), 12); tank.position.set(-0.08, 0.25, 0); g.add(tank);
const n = cyl(0.045, 0.06, 0.42, m.steel, 10); n.rotation.z = -Math.PI / 2; n.position.set(0.24, 0.18, 0); g.add(n);
const f = new T.Mesh(new T.ConeGeometry(0.42, 2.6, 14, 1, true), M.flame);
f.rotation.z = Math.PI / 2; f.position.set(0.45 + 1.3, 0.18, 0); f.visible = false; g.add(f);
out.flame = f;
const f = new T.Group(); f.visible = false; g.add(f);
const outer = new T.Mesh(new T.ConeGeometry(0.44, 2.7, 16, 1, true), M.flame);
outer.rotation.z = Math.PI / 2; outer.position.set(0.45 + 1.35, 0.18, 0); f.add(outer);
const core = new T.Mesh(new T.ConeGeometry(0.2, 1.5, 12, 1, true), M.flameCore);
core.rotation.z = Math.PI / 2; core.position.set(0.45 + 0.75, 0.18, 0); f.add(core);
out.flame = f; out.flameParts = [outer, core];
} else if (tw.type === 'minigun') {
const hous = box(0.22, 0.16, 0.2, accent); hous.position.y = 0.2; g.add(hous);
const brl = new T.Group(); brl.position.set(0.1, 0.2, 0); g.add(brl);
@@ -407,6 +554,25 @@
out.gun = brl;
const fl = new T.Mesh(new T.SphereGeometry(0.09, 8, 6), new T.MeshBasicMaterial({ color: 0xffd060, transparent: true, blending: T.AdditiveBlending, depthWrite: false }));
fl.position.set(0.62, 0.2, 0); fl.visible = false; g.add(fl); out.muzzle = fl;
} else if (tw.type === 'zapper') {
const coil = cyl(0.1, 0.13, 0.22, m.dark, 12); coil.position.y = 0.2; g.add(coil);
for (let k = 0; k < 3; k++) { const ring = new T.Mesh(new T.TorusGeometry(0.1, 0.018, 6, 14), accent); ring.rotation.x = Math.PI / 2; ring.position.y = 0.14 + k * 0.07; g.add(ring); }
const rod = cyl(0.022, 0.022, 0.34, m.steel, 8); rod.rotation.z = -Math.PI / 2; rod.position.set(0.2, 0.3, 0); g.add(rod);
const ball = new T.Mesh(new T.SphereGeometry(0.06, 10, 8), new T.MeshStandardMaterial({ color: 0x9fd8ff, emissive: 0x3aa0ff, emissiveIntensity: 1.6 }));
ball.position.set(0.38, 0.3, 0); g.add(ball);
const arc = new T.Mesh(new T.ConeGeometry(0.13, 1.5, 8, 1, true), M.arc);
arc.rotation.z = -Math.PI / 2; arc.position.set(1.1, 0.3, 0); arc.visible = false; g.add(arc);
out.gun = coil; out.muzzle = ball; out.flame = arc; // reuse the beam slots
} else if (tw.type === 'mortar') {
const base2 = cyl(0.14, 0.16, 0.1, m.dark, 12); base2.position.y = 0.14; g.add(base2);
const tube = cyl(0.11, 0.13, 0.52, m.steel, 14); tube.position.set(-0.05, 0.36, 0); tube.rotation.z = 0.5; g.add(tube);
const mouth = cyl(0.13, 0.13, 0.05, accent, 14); mouth.position.set(0.1, 0.58, 0); mouth.rotation.z = 0.5; g.add(mouth);
for (const sz of [-1, 1]) { const leg = cyl(0.02, 0.02, 0.3, m.dark, 6); leg.position.set(0.12, 0.17, sz * 0.1); leg.rotation.z = -0.5; g.add(leg); }
} else if (tw.type === 'swarm') {
const pod = box(0.42, 0.3, 0.42, accent); pod.position.set(0.02, 0.28, 0); g.add(pod);
for (const y of [0.19, 0.3, 0.41]) for (const sz of [-0.12, 0, 0.12]) {
const tube = cyl(0.04, 0.04, 0.07, m.dark, 8); tube.rotation.z = Math.PI / 2; tube.position.set(0.23, y, sz); g.add(tube);
}
} else if (tw.type === 'rockets') {
const pod = box(0.38, 0.26, 0.36, accent); pod.position.set(0.02, 0.27, 0); g.add(pod);
for (const [y, z] of [[0.2, -0.09], [0.2, 0.09], [0.34, -0.09], [0.34, 0.09]]) { const t = cyl(0.05, 0.05, 0.06, m.dark, 10); t.rotation.z = Math.PI / 2; t.position.set(0.22, y, z); g.add(t); }
@@ -414,6 +580,16 @@
out.turret = g;
}
mark('tower');
// gadget: small pod on the rear deck, colour-coded by type
const gd = st.gadget;
if (gd) {
const gc = { righter: 0x40c0ff, turbo: 0xff5020, shield: 0x40e0c0, repair: 0x50e060, emp: 0xc060ff }[gd.type] || 0xffffff;
const pod = box(0.24, 0.16, 0.3, m.dark); pod.position.set(-L * 0.33, top + 0.02, 0); tilt.add(pod);
const led = new T.Mesh(new T.SphereGeometry(0.05, 8, 6), new T.MeshStandardMaterial({ color: gc, emissive: gc, emissiveIntensity: 0.8, roughness: 0.4 }));
led.position.set(-L * 0.33, top + 0.12, 0); tilt.add(led);
}
mark('gadget');
root.traverse(o => { if (o.isMesh && !o.material.transparent) { o.castShadow = true; } });
return out;
}
@@ -441,11 +617,20 @@
else if (w && r.cd > 0) ang = lerp(-0.25, 1.9, clamp((w.cd - 0.43 - r.cd) / 0.5, 0, 1));
R.hammer.rotation.z = ang;
}
if (R.saw) { if (r.sawOn) R.sawA += dt * 40; R.saw.rotation.z = -R.sawA; }
if (R.saw) { if (r.sawOn) R.sawA += dt * 40; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
if (R.spinner) { R.spinA += dt * r.spin * 38; R.spinner.rotation.y = R.spinA; }
if (R.vspin) { R.spinA += dt * r.spin * 40; R.vspin.rotation.z = -R.spinA; }
if (R.jaws) for (const j of R.jaws) j.rotation.y = j.userData.side * (r.grab > 0 ? -0.18 : 0.45);
if (R.turret) R.turret.rotation.y = -(r.turretA - r.a);
if (R.flame) { R.flame.visible = r.flameOn; if (r.flameOn) { const f = 0.85 + Math.random() * 0.3; R.flame.scale.set(f, 1, f); } }
if (R.flame) {
const tw2 = R.st.tower, beam = r.flameOn || (tw2 && tw2.type === 'zapper' && r.gunOn);
R.flame.visible = !!beam;
if (beam) {
const f = 0.85 + Math.random() * 0.3;
R.flame.scale.set(f, 1, f);
if (R.flameParts) for (const fp of R.flameParts) { const n = 0.78 + Math.random() * 0.5; fp.scale.set(n, 0.9 + Math.random() * 0.35, n); }
}
}
if (R.gun) { if (r.gunOn) R.gunA += dt * 30; R.gun.rotation.x = R.gunA; R.muzzle.visible = r.gunOn && Math.random() < 0.6; }
R.flash = Math.max(0, R.flash - dt * 4);
R.body.emissive.setRGB(R.flash * 0.9, R.flash * 0.15, 0);
@@ -466,7 +651,7 @@
scene.add(new T.HemisphereLight(0x8fa6c8, 0x1a140f, 0.55));
const key = new T.DirectionalLight(0xfff1dc, 1.25);
key.position.set(6, 16, 9); key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.mapSize.set(1024, 1024); // 2048 was a big per-frame shadow pass; 1024 is plenty at this scale
Object.assign(key.shadow.camera, { left: -11, right: 11, top: 11, bottom: -11, near: 1, far: 50 });
key.shadow.bias = -0.0008;
scene.add(key);
@@ -507,9 +692,29 @@
{ const scene = { add: scene_add }; buildArenaBody(scene, out, A, m, half, th); }
}
// arena outline (same maths as wallPush in combat.js): square, octagon or a many-sided ring
function outline(A) {
const h = A.half;
if (A.shape === 'round') return Array.from({ length: 28 }, (_, i) => { const a = i / 28 * Math.PI * 2; return [Math.cos(a) * h, Math.sin(a) * h]; });
if (A.shape === 'octagon') { const d = h * 0.67; return [[-d, -h], [d, -h], [h, -d], [h, d], [d, h], [-d, h], [-h, d], [-h, -d]]; }
return [[-h, -h], [h, -h], [h, h], [-h, h]];
}
function floorGeo(A) {
const h = A.half;
if (A.shape === 'square') return new T.PlaneGeometry(h * 2, h * 2);
const pts = outline(A), sh = new T.Shape();
sh.moveTo(pts[0][0], pts[0][1]);
for (let i = 1; i < pts.length; i++) sh.lineTo(pts[i][0], pts[i][1]);
sh.closePath();
const g = new T.ShapeGeometry(sh), pos = g.attributes.position, uv = new Float32Array(pos.count * 2);
for (let i = 0; i < pos.count; i++) { uv[i * 2] = pos.getX(i) / (h * 2) + 0.5; uv[i * 2 + 1] = pos.getY(i) / (h * 2) + 0.5; }
g.setAttribute('uv', new T.BufferAttribute(uv, 2));
return g;
}
function buildArenaBody(scene, out, A, m, half, th) {
// floor
const floor = new T.Mesh(new T.PlaneGeometry(half * 2, half * 2), new T.MeshStandardMaterial({ map: floorTex(A), metalness: 0.55, roughness: 0.62 }));
const floor = new T.Mesh(floorGeo(A), new T.MeshStandardMaterial({ map: floorTex(A), metalness: 0.55, roughness: 0.62 }));
floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true; scene.add(floor);
const outer = new T.Mesh(new T.PlaneGeometry(80, 80), new T.MeshStandardMaterial({ color: 0x0d0f13, roughness: 1 }));
outer.rotation.x = -Math.PI / 2; outer.position.y = -0.02; outer.receiveShadow = true; scene.add(outer);
@@ -519,22 +724,30 @@
// ComfyGen wall panels (tex_wall.jpg) on the arena walls, if the browser lets the image into WebGL
const panelMat = new T.MeshStandardMaterial({ color: 0x30343b, metalness: 0.6, roughness: 0.5 });
loadTex('tex_wall.jpg', tex => { tex.wrapS = T.RepeatWrapping; tex.repeat.set(5, 1); panelMat.map = tex; panelMat.color.set(0xb0b4bc); panelMat.needsUpdate = true; });
const n = Math.round(half * 2 / 0.5);
const spikes = new T.InstancedMesh(new T.ConeGeometry(0.07, 0.28, 8), m.steel, n * 4);
const pts = outline(A);
let perim = 0;
for (let i = 0; i < pts.length; i++) { const a2 = pts[i], b2 = pts[(i + 1) % pts.length]; perim += Math.hypot(b2[0] - a2[0], b2[1] - a2[1]); }
const spikes = new T.InstancedMesh(new T.ConeGeometry(0.07, 0.28, 8), m.steel, Math.ceil(perim / 0.5) + pts.length + 4);
const dm = new T.Object3D(); let si = 0;
for (const [nx, nz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) {
const wall = box(nz ? half * 2 + 0.5 : 0.25, 0.55, nz ? 0.25 : half * 2 + 0.5, panelMat);
wall.position.set(nx * (half + 0.12), 0.275, nz * (half + 0.12)); scene.add(wall);
const strip = box(nz ? half * 2 + 0.5 : 0.26, 0.08, nz ? 0.26 : half * 2 + 0.5, m.stripe);
strip.position.set(nx * (half + 0.12), 0.58, nz * (half + 0.12)); scene.add(strip);
for (let k = 0; k < n; k++) {
const t = -half + 0.25 + k * 0.5;
dm.position.set(nx ? nx * (half - 0.02) : t, 0.3, nz ? nz * (half - 0.02) : t);
for (let i = 0; i < pts.length; i++) {
const [x1, z1] = pts[i], [x2, z2] = pts[(i + 1) % pts.length];
const mx = (x1 + x2) / 2, mz = (z1 + z2) / 2, len = Math.hypot(x2 - x1, z2 - z1), ang = Math.atan2(z2 - z1, x2 - x1);
const d = Math.hypot(mx, mz) || 1, ox = mx / d, oz = mz / d; // outwards from the middle
const wall = box(len + 0.3, 0.55, 0.25, panelMat);
wall.position.set(mx + ox * 0.12, 0.275, mz + oz * 0.12); wall.rotation.y = -ang; scene.add(wall);
const strip = box(len + 0.3, 0.08, 0.26, m.stripe);
strip.position.set(mx + ox * 0.12, 0.58, mz + oz * 0.12); strip.rotation.y = -ang; scene.add(strip);
const steps = Math.max(1, Math.round(len / 0.5));
for (let k = 0; k < steps; k++) {
const f = (k + 0.5) / steps;
dm.position.set(x1 + (x2 - x1) * f - ox * 0.02, 0.3, z1 + (z2 - z1) * f - oz * 0.02);
dm.rotation.set(0, 0, 0);
if (nx) dm.rotation.z = nx > 0 ? Math.PI / 2 : -Math.PI / 2; else dm.rotation.x = nz > 0 ? -Math.PI / 2 : Math.PI / 2;
dm.updateMatrix(); spikes.setMatrixAt(si++, dm.matrix);
dm.rotation.z = Math.PI / 2; dm.rotation.y = -Math.atan2(oz, ox); // point inwards
dm.updateMatrix();
if (si < spikes.count) spikes.setMatrixAt(si++, dm.matrix);
}
}
spikes.count = si;
spikes.castShadow = true; scene.add(spikes);
// glass + posts + floodlight rigs
@@ -566,6 +779,60 @@
seats.count = ci; dm.scale.set(1, 1, 1); scene.add(seats);
// floor saws
// --- cover and floor traps (static, built once per arena) ---
const BMAT = {
pillar: new T.MeshStandardMaterial({ color: 0x4a515c, metalness: 0.5, roughness: 0.6 }),
crate: new T.MeshStandardMaterial({ color: 0x6b5634, metalness: 0.2, roughness: 0.85 }),
scrap: new T.MeshStandardMaterial({ color: 0x5a5048, metalness: 0.6, roughness: 0.8 }),
barrier: new T.MeshStandardMaterial({ color: 0x9aa0a8, metalness: 0.6, roughness: 0.5 }),
};
let bseed = 7;
const brnd = () => { bseed = (bseed * 16807) % 2147483647; return bseed / 2147483647; };
for (const b of A.blocks) {
const g = new T.Group(); g.position.set(b.x, 0, b.z); scene.add(g);
const mat = BMAT[b.kind] || BMAT.crate;
if (b.kind === 'pillar') {
const rr = Math.min(b.hw, b.hd);
const col = cyl(rr, rr * 1.12, b.h, mat, 14); col.position.y = b.h / 2; col.castShadow = true; g.add(col);
const cap = cyl(rr * 1.18, rr * 1.18, 0.12, m.dark, 14); cap.position.y = b.h; g.add(cap);
const band = cyl(rr * 1.06, rr * 1.06, 0.18, m.stripe, 14); band.position.y = b.h * 0.42; g.add(band);
} else if (b.kind === 'scrap') {
for (let k = 0; k < 5; k++) {
const w2 = b.hw * (0.5 + brnd() * 0.75), h2 = b.h * (0.35 + brnd() * 0.65), d2 = b.hd * (0.5 + brnd() * 0.75);
const p2 = box(w2, h2, d2, mat);
p2.position.set((brnd() - 0.5) * b.hw, h2 / 2, (brnd() - 0.5) * b.hd);
p2.rotation.y = brnd() * 3; p2.castShadow = true; g.add(p2);
}
} else if (b.kind === 'barrier') {
const bar = box(b.hw * 2, b.h, b.hd * 2, mat); bar.position.y = b.h / 2; bar.castShadow = true; g.add(bar);
const top = box(b.hw * 2, 0.1, b.hd * 2.1, m.stripe); top.position.y = b.h; g.add(top);
} else {
const bx = box(b.hw * 2, b.h, b.hd * 2, mat); bx.position.y = b.h / 2; bx.castShadow = true; g.add(bx);
for (const sy of [0.28, 0.74]) { const band = box(b.hw * 2.05, 0.06, b.hd * 2.05, m.dark); band.position.y = b.h * sy; g.add(band); }
}
}
for (const b of A.belts) {
const g = new T.Group(); g.position.set(b.x, 0.012, b.z); scene.add(g);
const pad = new T.Mesh(new T.PlaneGeometry(b.hw * 2, b.hd * 2), new T.MeshStandardMaterial({ color: 0x191d24, roughness: 0.92 }));
pad.rotation.x = -Math.PI / 2; pad.receiveShadow = true; g.add(pad);
const along = Math.abs(b.ax) > Math.abs(b.az); // slats across the running direction
for (let k = -3; k <= 3; k++) {
const slat = box(along ? 0.14 : b.hw * 1.9, 0.05, along ? b.hd * 1.9 : 0.14, m.stripe);
slat.position.set(along ? k * b.hw / 3.4 : 0, 0.03, along ? 0 : k * b.hd / 3.4);
g.add(slat);
}
}
for (const o of A.oil) {
const sl = new T.Mesh(new T.CircleGeometry(o.r, 22), new T.MeshStandardMaterial({ color: 0x06070b, roughness: 0.2, metalness: 0.75 }));
sl.rotation.x = -Math.PI / 2; sl.position.set(o.x, 0.014, o.z); scene.add(sl);
}
out.rams = A.rams.map(d => {
const g = new T.Group(); g.position.set(d.x, 0, d.z); scene.add(g);
const head = box(0.5, 0.72, d.hd * 1.8, m.steel); head.position.y = 0.4; head.castShadow = true; g.add(head);
const face = box(0.12, 0.74, d.hd * 1.85, m.stripe); face.position.set(d.nx * 0.3, 0.4, d.nz * 0.3); g.add(face);
return { d, g, x0: d.x, z0: d.z };
});
out.saws = A.saws.map(h => {
const g = new T.Group(); g.position.set(h.x, 0.005, h.z); scene.add(g);
const d = cyl(h.r * 0.85, h.r * 0.85, 0.035, m.steel, 32); g.add(d);
@@ -648,7 +915,7 @@
RC.buildRobotModel = buildRobot;
RC.Render = function (canvas, W, H) {
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true });
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true, powerPreference: 'high-performance' });
renderer.setClearColor(0x000000, 0);
renderer.outputEncoding = T.sRGBEncoding;
renderer.toneMapping = T.ACESFilmicToneMapping;
@@ -678,13 +945,49 @@
fitCam(RC.ARENA.half);
cam.position.copy(camBase); cam.lookAt(camLook);
const gcam = new T.PerspectiveCamera(34, asp, 0.1, 60);
gcam.position.set(3.7, 2.5, 4.4); gcam.lookAt(0, 0.3, 0);
gcam.setViewOffset(W, H, 300, 40, W, H); // robot sits in the left part of the shop
// put the shop camera at the current zoom (base distance / zoom, aimed at the turntable)
function placeGarageCam() {
const look = new T.Vector3(0, 0.3, 0), base = new T.Vector3(3.7, 2.5, 4.4);
gcam.position.copy(look).add(base.clone().sub(look).multiplyScalar(1 / gcamZoom));
gcam.lookAt(look);
}
gcam.setViewOffset(W, H, GARAGE_OFF_X, GARAGE_OFF_Y, W, H); // robot sits in the left part of the shop
// intro / title: perspective camera flying over the arena
const pcam = new T.PerspectiveCamera(40, asp, 0.1, 120);
let mode = 'garage', gRobot = null, robots = [], state = null, shake = 0, flashT = 0, introT = 0, scale = 1, hold = 0;
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false;
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false, gcamZoom = GZ_DEF;
placeGarageCam(); // after gcamZoom exists: start fully zoomed out
// workshop: show what the fitted weapon / turret actually does, on a short loop
let demoT = 0;
function demoGarage(dt) {
const R = gRobot; if (!R) return;
demoT += dt;
const c = demoT % 3; // one signature move every 3 s
if (R.saw) { R.sawA += dt * 26; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
if (R.spinner) { R.spinA += dt * 17; R.spinner.rotation.y = R.spinA; }
if (R.vspin) { R.spinA += dt * 19; R.vspin.rotation.z = -R.spinA; }
if (R.hammer) {
const k = c < 0.35 ? c / 0.35 : c < 1.2 ? 1 - (c - 0.35) / 0.85 : 0;
R.hammer.rotation.z = lerp(1.9, -0.25, k);
}
if (R.flipper) R.flipper.rotation.z = -0.32 + (c < 0.3 ? Math.sin(c / 0.3 * Math.PI) * 1.5 : 0);
if (R.jaws) {
const k = c < 1.2 ? Math.abs(Math.sin(c / 1.2 * Math.PI)) : 0;
for (const j of R.jaws) j.rotation.y = j.userData.side * (0.45 - k * 0.63);
}
if (R.gun) { R.gunA += dt * 16; R.gun.rotation.x = R.gunA; }
const shooting = c > 1.5 && c < 2.3;
if (R.flame) R.flame.visible = shooting;
if (R.muzzle) R.muzzle.visible = shooting && Math.random() < 0.5;
// launchers have no moving part: show a short recoil kick instead
const tw2 = R.st.tower;
if (R.turret && tw2 && (tw2.type === 'mortar' || tw2.type === 'swarm')) {
const kick = c > 1.5 && c < 1.75 ? Math.sin((c - 1.5) / 0.25 * Math.PI) : 0;
R.turret.rotation.z = -0.14 * kick;
}
}
const PX = [6, 34, 18], WORLD = [0.07, 0.7, 0.32]; // particle sizes: ortho px / perspective m
const pointMode = persp => [sparks, smoke, fire].forEach((p, i) => { p.pts.material.size = persp ? WORLD[i] : PX[i]; });
@@ -693,7 +996,8 @@
get introTime() { return introT; },
resize(sc) {
scale = sc;
const cap = quality === 'low' ? 1 : quality === 'medium' ? 1.5 : 3;
// the stage is scaled up by CSS; rendering at full devicePixelRatio on top of that is the main CPU/GPU hog
const cap = quality === 'low' ? 1 : quality === 'medium' ? 1.25 : 1.5;
renderer.setPixelRatio(Math.min(cap, sc * (root.devicePixelRatio || 1)));
renderer.setSize(W, H);
},
@@ -702,7 +1006,7 @@
quality = q; fxMul = q === 'low' ? 0.35 : q === 'medium' ? 0.7 : 1;
const sh = q !== 'low';
renderer.shadowMap.enabled = sh;
renderer.shadowMap.type = q === 'high' ? T.PCFSoftShadowMap : T.PCFShadowMap;
renderer.shadowMap.type = q === 'high' ? T.PCFSoftShadowMap : T.PCFShadowMap; // soft shadows only on high
for (const sc of [arenaScene, garageScene]) sc.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
api.resize(scale);
},
@@ -738,10 +1042,16 @@
renderer.render(garageScene, gcam);
let url = '';
try { url = canvas.toDataURL('image/png'); } catch (e) { /* tainted canvas: no picture */ }
gcam.setViewOffset(W, H, 300, 40, W, H); api.paintCam(false);
gcam.setViewOffset(W, H, GARAGE_OFF_X, GARAGE_OFF_Y, W, H); api.paintCam(false);
return url;
},
paintCam(on) { gcam.position.set(on ? 2.6 : 3.7, on ? 2.2 : 2.5, on ? 3.1 : 4.4); gcam.lookAt(0, 0.3, 0); },
paintCam(on) {
gcamZoom = GZ_DEF;
if (on) { gcam.position.set(2.6, 2.2, 3.1); gcam.lookAt(0, 0.3, 0); } else placeGarageCam();
},
// garage preview zoom (shop "- Zoom +"): move the camera closer / further
zoomGarage(mult) { gcamZoom = Kit.clamp(gcamZoom * mult, GZ_MIN, GZ_MAX); placeGarageCam(); },
resetGarageZoom() { gcamZoom = GZ_DEF; placeGarageCam(); },
// rebuild the arena scene if the fight uses a different one; rescale the camera
setArena(A) {
if (!A || arena.id === A.id) { if (A) fitCam(A.half); return; }
@@ -755,7 +1065,7 @@
mode = 'arena'; state = s; pointMode(camMode !== 'iso'); lightsOn(1); chaseInit = false;
for (const R of robots) arenaScene.remove(R.root);
robots = builds.map((b, i) => { const R = buildRobot(b, paints[i]); arenaScene.add(R.root); return R; });
sparks.clear(); smoke.clear(); fire.clear(); shake = 0;
sparks.clear(); smoke.clear(); fire.clear(); clearDebris(); shake = 0;
for (const m of arena.rocketMeshes) arenaScene.remove(m);
arena.rocketMeshes = [];
},
@@ -778,6 +1088,11 @@
case 'press': puff(e.x, e.z, 14); burst(e.x, 0.1, e.z, 24, 5, [1, 0.8, 0.4]); shake = Math.max(shake, 0.45); break;
case 'drop': puff(e.x, e.z, 8); shake = Math.max(shake, 0.2); break;
case 'ko': explode(e.x, 0.5, e.z, 1.2); break;
case 'broke':
breakPart(robots[e.who], e.part);
burst(e.x, 0.45, e.z, 22, 5, [1, 0.8, 0.4]); puff(e.x, e.z, 6);
shake = Math.max(shake, 0.28);
break;
case 'boost': for (let k = 0; k < 6; k++) fire.spawn(e.x, 0.3, e.z, (Math.random() - 0.5), 0.6, (Math.random() - 0.5), 0.4, 1, 0.6, 0.2); break;
}
}
@@ -799,6 +1114,7 @@
frame(dt, now) {
if (mode === 'garage') {
if (hold > 0) hold -= dt; else garage.turntable.rotation.y += dt * 0.45;
demoGarage(dt);
renderer.render(garageScene, gcam);
return;
}
@@ -903,9 +1219,49 @@
arena.flashLight.position.set(x, 1.2, z); flashT = 1; shake = Math.max(shake, 0.3 * k);
}
// parts torn off in a fight: the real mesh leaves the robot and tumbles over the floor
const debris = [];
function dropPiece(obj) {
const wp = new T.Vector3(), wq = new T.Quaternion();
obj.getWorldPosition(wp); obj.getWorldQuaternion(wq);
arenaScene.add(obj);
obj.position.copy(wp); obj.quaternion.copy(wq);
debris.push({ o: obj, vx: (Math.random() - 0.5) * 3.5, vy: 2.2 + Math.random() * 1.8, vz: (Math.random() - 0.5) * 3.5,
rx: (Math.random() - 0.5) * 9, rz: (Math.random() - 0.5) * 9, t: 9 });
while (debris.length > 10) { const d = debris.shift(); arenaScene.remove(d.o); }
}
function updateDebris(dt) {
for (let i = debris.length - 1; i >= 0; i--) {
const d = debris[i];
d.t -= dt; d.vy -= 22 * dt;
d.o.position.x += d.vx * dt; d.o.position.y += d.vy * dt; d.o.position.z += d.vz * dt;
if (d.o.position.y < 0.07) { d.o.position.y = 0.07; d.vy = -d.vy * 0.3; d.vx *= 0.6; d.vz *= 0.6; d.rx *= 0.5; d.rz *= 0.5; }
d.o.rotation.x += d.rx * dt; d.o.rotation.z += d.rz * dt;
if (d.t <= 0) { arenaScene.remove(d.o); debris.splice(i, 1); }
}
}
function clearDebris() { for (const d of debris) arenaScene.remove(d.o); debris.length = 0; }
// combat.js says a part broke off -> take it off the model (one piece tumbles away)
function breakPart(R, part) {
if (!R) return;
if (part === 'wheels') {
const w = (R.wheels || []).find(o => o.parent === R.tilt);
if (w) { R.wheels.splice(R.wheels.indexOf(w), 1); dropPiece(w); }
return;
}
const kill = R.tilt.children.filter(o => o.userData.part === part && o.visible);
if (!kill.length) return;
const main = kill[0];
for (const o of kill) if (o !== main) o.visible = false;
dropPiece(main);
if (part === 'weapon') { R.saw = null; R.spinner = null; R.hammer = null; R.flipper = null; R.jaws = null; }
if (part === 'tower') { R.turret = null; R.flame = null; R.gun = null; R.muzzle = null; }
}
function animateArena(dt, now) {
const s = state; if (!s) return;
const A = state.arena || RC.ARENA;
updateDebris(dt);
robots.forEach((R, i) => {
const r = s.robots[i];
poseRobot(R, r, dt);
@@ -923,6 +1279,12 @@
fire.spawn(r.x + Math.cos(r.turretA) * 0.6, r.y + R.top + 0.18, r.z + Math.sin(r.turretA) * 0.6, Math.cos(a) * v, 0.3, Math.sin(a) * v, 0.45, 1, 0.55, 0.15);
}
});
// wall rams punch out while they are armed
for (const rm of arena.rams || []) {
const on = RC.hazardOn(rm.d, s.t) ? 1 : 0, k = Math.min(1, dt * (on ? 20 : 5));
rm.g.position.x = lerp(rm.g.position.x, rm.x0 + rm.d.nx * on * 1.2, k);
rm.g.position.z = lerp(rm.g.position.z, rm.z0 + rm.d.nz * on * 1.2, k);
}
// saws
for (const S of arena.saws) {
const on = RC.hazardOn(S.h, s.t), warn = RC.hazardOn(S.h, s.t + 0.6);
@@ -952,14 +1314,22 @@
for (const d of arena.pitDoors) { d.position.x = A.pit.x + d.userData.sx * (A.pit.hw / 2 + o * A.pit.hw * 1.02); d.position.y = 0.025 + o * 0.01; }
for (const l of arena.pitLamps) l.material.emissiveIntensity = s.pitAlarm ? (Math.sin(now / 150) > 0 ? 2.5 : 0.4) : 0;
// rockets
while (arena.rocketMeshes.length < s.rockets.length) { const m = new T.Mesh(arena.rocketGeo, arena.rocketMat); arenaScene.add(m); arena.rocketMeshes.push(m); }
while (arena.rocketMeshes.length < s.rockets.length) {
const gr = new T.Group();
const body = new T.Mesh(arena.rocketGeo, arena.rocketMat); gr.add(body);
const nose = new T.Mesh(new T.ConeGeometry(0.055, 0.12, 8), arena.rocketMat);
nose.rotation.z = -Math.PI / 2; nose.position.x = 0.21; gr.add(nose);
for (const sz of [-1, 1]) { const fin = new T.Mesh(new T.BoxGeometry(0.09, 0.012, 0.07), arena.rocketMat); fin.position.set(-0.13, 0, sz * 0.045); gr.add(fin); }
arenaScene.add(gr); arena.rocketMeshes.push(gr);
}
arena.rocketMeshes.forEach((m, i) => {
const k = s.rockets[i];
m.visible = !!k;
if (k) {
m.position.set(k.x, k.y, k.z); m.rotation.y = -k.a;
fire.spawn(k.x - Math.cos(k.a) * 0.2, k.y, k.z - Math.sin(k.a) * 0.2, 0, 0.2, 0, 0.3, 1, 0.6, 0.2);
if (Math.random() < 0.5) smoke.spawn(k.x, k.y, k.z, 0, 0.2, 0, 0.8, 0.5, 0.5, 0.5);
const bx = k.x - Math.cos(k.a) * 0.22, bz = k.z - Math.sin(k.a) * 0.22;
for (let q = 0; q < 2; q++) fire.spawn(bx, k.y, bz, (Math.random() - 0.5) * 0.4, 0.25, (Math.random() - 0.5) * 0.4, 0.26, 1, 0.65, 0.22);
smoke.spawn(bx, k.y, bz, (Math.random() - 0.5) * 0.3, 0.35, (Math.random() - 0.5) * 0.3, 1.1, 0.55, 0.55, 0.55);
}
});
}