Online-Lobby, Arenen, Lackiererei, ComfyGen-Grafik, Verschleierung
Grosse Erweiterung ueber die erste spielbare Version hinaus: - Online (Firebase ueber REST, kein SDK): Konto per E-Mail, globale Lobby mit Laender-Raeumen, Herausfordern, Live-PvP (Host rechnet, Gast interpoliert, KI-Uebernahme bei Lag). Gast kann anonym beitreten. net.js / lobby.js / netfight.js, Regeln in docs/firebase. - 3 Arenen in verschiedenen Groessen (RC.ARENAS, half 8/12/16), Kamera + Licht + Boden skalieren; Liga skaliert die Arena mit, Setting + online aus Seed. Harte Rams/Wandtreffer schleudern Roboter auf den Rucken. - Intro (3D-Kamerafahrt), Titel, Einstellungen (Kamera, Schwierigkeit, Steuerung, Grafik, Arena), Lackiererei (painter.js, selbst bemalen). - Shop mit ComfyGen-Sprites (aus den 3D-Teilen erzeugt), Liga-Gegner sehen aus wie ihre Portraits (looks.js), kraeftigere Waffen-Modelle. - Oekonomie: Startgeld 800, Schadensbonus, Schaukaempfe, Online-Preisgeld. - Verschleierung: build.ps1 -Obfuscate (terser), tablet-taugliche Touch-UI. - Tests: tests/sim.test.js, balance.js, online.test.js. Dev-Tools in tools/. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
273
game/render3d.js
273
game/render3d.js
@@ -41,8 +41,8 @@
|
||||
c.fillStyle = g; c.fillRect(0, 0, 64, 64);
|
||||
});
|
||||
|
||||
function floorTex() {
|
||||
const A = RC.ARENA, S = 64, N = A.half * 2 * S; // 64 px per metre
|
||||
function floorTex(A) {
|
||||
const S = 64, N = A.half * 2 * S; // 64 px per metre
|
||||
const P = (x, z) => [(x + A.half) * S, (z + A.half) * S];
|
||||
let plate = null; // tex_floor.jpg from ComfyGen (make_tileable)
|
||||
const tex = canvasTex(N, N, draw);
|
||||
@@ -105,6 +105,20 @@
|
||||
}
|
||||
}
|
||||
|
||||
// image from assets/Sprites as a WebGL texture; skipped quietly where file:// taints it (release embeds data: URIs)
|
||||
function loadTex(file, onReady) {
|
||||
const im = new Image();
|
||||
im.onload = () => {
|
||||
const probe = document.createElement('canvas').getContext('2d');
|
||||
probe.drawImage(im, 0, 0, 1, 1);
|
||||
try { probe.getImageData(0, 0, 1, 1); } catch (e) { return; }
|
||||
const tex = new T.Texture(im);
|
||||
tex.encoding = T.sRGBEncoding; tex.anisotropy = 4; tex.needsUpdate = true;
|
||||
onReady(tex);
|
||||
};
|
||||
im.src = Kit.asset('assets/Sprites/' + file);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- particles
|
||||
function Particles(scene, max, size, additive, tex) {
|
||||
const pos = new Float32Array(max * 3), col = new Float32Array(max * 4);
|
||||
@@ -161,6 +175,8 @@
|
||||
M.flame = new T.MeshBasicMaterial({ color: 0xff3a08, transparent: true, opacity: 0.42, 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;
|
||||
}
|
||||
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; };
|
||||
@@ -216,10 +232,16 @@
|
||||
root.add(tilt);
|
||||
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 c = big ? 0.12 : 0.1; // ground clearance
|
||||
const ws = look.wheelScale || 1;
|
||||
const c = big ? 0.12 : 0.1 * ws; // ground clearance
|
||||
out.c = c;
|
||||
|
||||
// every piece gets userData.part = slot (lets tools/partshot.html render one part alone)
|
||||
let from = 0;
|
||||
const mark = part => { for (let i = from; i < tilt.children.length; i++) tilt.children[i].userData.part = part; from = tilt.children.length; };
|
||||
|
||||
// chassis
|
||||
let top = c + H;
|
||||
if (ch.shape === 'wedge') {
|
||||
@@ -243,7 +265,21 @@
|
||||
const s2 = box(0.06, H * 0.6, Wd * 1.002, m.stripe); s2.position.set(-L / 2 + 0.08, c + H / 2, 0); tilt.add(s2);
|
||||
}
|
||||
}
|
||||
// look extras: raised cab with window slit, eye bumps (like the portraits)
|
||||
if (look.cab) {
|
||||
const cw = L * 0.4, chh = H * 0.62, cd = Wd * 0.64;
|
||||
const cab = sk(new T.BoxGeometry(cw, chh, cd), cw, chh, cd, -chh / 2); cab.position.set(-L * 0.16, top + chh / 2, 0); tilt.add(cab);
|
||||
const win = box(0.02, chh * 0.25, cd * 0.8, m.dark); win.position.set(-L * 0.16 + cw / 2 + 0.005, top + chh * 0.62, 0); tilt.add(win);
|
||||
top += chh;
|
||||
}
|
||||
if (look.bumps) {
|
||||
for (const sz of [-1, 1]) {
|
||||
const b = sk(new T.SphereGeometry(1, 16, 8, 0, Math.PI * 2, 0, Math.PI / 2), 2, 1, 2, 0);
|
||||
b.scale.set(0.13, 0.11, 0.13); b.position.set(L * 0.18, top - (ch.shape === 'wedge' ? H * 0.45 : 0), sz * Wd * 0.26); tilt.add(b);
|
||||
}
|
||||
}
|
||||
out.top = top;
|
||||
mark('chassis');
|
||||
|
||||
// armour plates (sides + rear), bolts
|
||||
if (armour) {
|
||||
@@ -255,10 +291,12 @@
|
||||
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');
|
||||
|
||||
// wheels
|
||||
out.wheels = [];
|
||||
const side = Wd / 2 + (armour ? 0.13 : 0.08);
|
||||
if (wh.kind === 'tracks') {
|
||||
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); }
|
||||
@@ -274,61 +312,83 @@
|
||||
out.wheelR = r;
|
||||
} else {
|
||||
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
|
||||
const w = new T.Group(); w.position.set(sx * L * 0.32, 0.16, sz * side);
|
||||
const tyre = cyl(0.16, 0.16, 0.12, m.rubber, 16); tyre.rotation.x = Math.PI / 2; w.add(tyre);
|
||||
const hub = cyl(0.07, 0.07, 0.13, m.hub, 8); hub.rotation.x = Math.PI / 2; w.add(hub);
|
||||
const wr = 0.16 * ws;
|
||||
const w = new T.Group(); w.position.set(sx * L * 0.32, wr, sz * (side + (ws - 1) * 0.08));
|
||||
const tyre = cyl(wr, wr, 0.12 * ws, m.rubber, 16); tyre.rotation.x = Math.PI / 2; w.add(tyre);
|
||||
const hub = cyl(wr * 0.44, wr * 0.44, 0.13 * ws, m.hub, 8); hub.rotation.x = Math.PI / 2; w.add(hub);
|
||||
tilt.add(w); out.wheels.push(w);
|
||||
}
|
||||
out.wheelR = 0.16;
|
||||
out.wheelR = 0.16 * ws;
|
||||
}
|
||||
|
||||
// headlights + antenna
|
||||
for (const sz of [-0.3, 0.3]) { const l = box(0.03, 0.05, 0.1, m.glowW); l.position.set(L / 2 + 0.005, c + H * 0.62, sz * Wd); tilt.add(l); }
|
||||
mark('wheels');
|
||||
|
||||
// headlights, or glowing eyes for opponents with a look
|
||||
if (look.eyes) {
|
||||
const eyeMat = new T.MeshStandardMaterial({ color: look.eyes, emissive: look.eyes, emissiveIntensity: 2.2 });
|
||||
for (const sz of [-1, 1]) {
|
||||
const e = new T.Mesh(new T.SphereGeometry(0.055, 12, 8), eyeMat);
|
||||
e.position.set(L / 2 + 0.01, c + H * (ch.shape === 'wedge' ? 0.3 : 0.7), sz * Wd * 0.24); tilt.add(e);
|
||||
}
|
||||
} else for (const sz of [-0.3, 0.3]) { const l = box(0.03, 0.05, 0.1, m.glowW); l.position.set(L / 2 + 0.005, c + H * 0.62, sz * Wd); tilt.add(l); }
|
||||
const ant = cyl(0.01, 0.01, 0.45, m.dark, 6); ant.position.set(-L / 2 + 0.12, top + 0.22, Wd / 2 - 0.12); tilt.add(ant);
|
||||
const tip = new T.Mesh(new T.SphereGeometry(0.035, 8, 6), new T.MeshStandardMaterial({ color: paint.accent, emissive: paint.accent, emissiveIntensity: 0.9 }));
|
||||
tip.position.set(-L / 2 + 0.12, top + 0.46, Wd / 2 - 0.12); tilt.add(tip);
|
||||
|
||||
mark('lights');
|
||||
|
||||
// main weapon (front = +x)
|
||||
const w = st.weapon;
|
||||
if (w) {
|
||||
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
|
||||
if (w.type === 'wedge') {
|
||||
const p = box(0.55, 0.04, Wd * 1.05, m.steel); p.position.set(L / 2 + 0.22, c * 0.5 + 0.08, 0); p.rotation.z = -0.42; tilt.add(p);
|
||||
// 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 piv = new T.Group(); piv.position.set(L / 2 - 0.08, c + H * 0.3, 0); tilt.add(piv);
|
||||
const p = box(0.62, 0.05, Wd * 0.92, m.steel); p.position.x = 0.31; piv.add(p);
|
||||
const s = box(0.6, 0.012, Wd * 0.3, accent); s.position.set(0.31, 0.03, 0); piv.add(s);
|
||||
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 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 piv = new T.Group(); piv.position.set(-L * 0.08, top + 0.06, 0); tilt.add(piv);
|
||||
const post = box(0.12, 0.14, 0.18, m.dark); post.position.set(-L * 0.08, top + 0.03, 0); tilt.add(post);
|
||||
const arm = box(L * 0.72, 0.07, 0.07, m.dark); arm.position.x = L * 0.36; piv.add(arm);
|
||||
const head = box(0.1, 0.34, 0.06, m.steel); head.position.set(L * 0.72, -0.1, 0); piv.add(head);
|
||||
const back = box(0.14, 0.12, 0.12, accent); back.position.set(L * 0.72, 0.08, 0); piv.add(back);
|
||||
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);
|
||||
out.hammer = piv;
|
||||
} else if (w.type === 'saw') {
|
||||
const arm = box(0.35, 0.08, 0.08, m.dark); arm.position.set(L / 2 + 0.05, c + H * 0.55, 0); tilt.add(arm);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.2, c + H * 0.55, 0); tilt.add(g);
|
||||
const d = cyl(0.3, 0.3, 0.025, m.steel, 28); d.rotation.x = Math.PI / 2; g.add(d);
|
||||
for (let k = 0; k < 14; k++) { const t = box(0.07, 0.04, 0.026, m.steel); const a = k / 14 * Math.PI * 2; t.position.set(Math.cos(a) * 0.31, Math.sin(a) * 0.31, 0); t.rotation.z = a + 0.6; g.add(t); }
|
||||
const hub = cyl(0.06, 0.06, 0.04, accent, 10); hub.rotation.x = Math.PI / 2; g.add(hub);
|
||||
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;
|
||||
} else if (w.type === 'spinner') {
|
||||
const post = cyl(0.07, 0.07, 0.25, m.dark, 10); post.position.set(L / 2 + 0.02, c + H * 0.35, 0); tilt.add(post);
|
||||
const g = new T.Group(); g.position.set(L / 2 + 0.02, c + H * 0.32, 0); tilt.add(g);
|
||||
const bar = box(1.25, 0.07, 0.16, m.steel); g.add(bar);
|
||||
for (const sx of [-1, 1]) { const t = box(0.1, 0.09, 0.2, accent); t.position.x = sx * 0.6; g.add(t); }
|
||||
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 === 'crusher') {
|
||||
out.jaws = [];
|
||||
for (const sz of [-1, 1]) {
|
||||
const piv = new T.Group(); piv.position.set(L / 2 - 0.02, c + H * 0.45, sz * Wd * 0.34); tilt.add(piv);
|
||||
const j = box(0.58, 0.14, 0.08, m.steel); j.position.x = 0.29; piv.add(j);
|
||||
const tooth = box(0.08, 0.14, 0.14, accent); tooth.position.set(0.56, 0, -sz * 0.05); piv.add(tooth);
|
||||
const piv = new T.Group(); piv.position.set(L / 2 - 0.02, c + H * 0.45, sz * Wd * 0.32); tilt.add(piv);
|
||||
const j = box(0.68, 0.2, 0.14, WS); j.position.x = 0.34; piv.add(j);
|
||||
for (let k = 0; k < 3; k++) { const tooth = box(0.1, 0.18, 0.14, accent); tooth.position.set(0.3 + k * 0.18, -sz * 0.02, -sz * 0.07); tooth.rotation.z = -sz * 0.25; piv.add(tooth); }
|
||||
piv.userData.side = sz; out.jaws.push(piv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mark('weapon');
|
||||
|
||||
// tower on top
|
||||
const tw = st.tower;
|
||||
if (tw) {
|
||||
@@ -353,6 +413,7 @@
|
||||
}
|
||||
out.turret = g;
|
||||
}
|
||||
mark('tower');
|
||||
root.traverse(o => { if (o.isMesh && !o.material.transparent) { o.castShadow = true; } });
|
||||
return out;
|
||||
}
|
||||
@@ -392,38 +453,77 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- arena
|
||||
function buildArena(scene) {
|
||||
const A = RC.ARENA, m = mats(), half = A.half;
|
||||
const out = {};
|
||||
scene.background = new T.Color(0x07090d);
|
||||
scene.fog = new T.Fog(0x07090d, 26, 60);
|
||||
// theme colours per arena (combat.js arena.theme)
|
||||
const THEME = {
|
||||
steel: { bg: 0x07090d, fog: 0x07090d, rimA: 0xff7a1a, rimB: 0x4fa8ff, hazard: 0xd33 },
|
||||
lava: { bg: 0x0d0604, fog: 0x1a0a06, rimA: 0xff5a1a, rimB: 0xff2a10, hazard: 0xff6020 },
|
||||
blue: { bg: 0x05080f, fog: 0x070d1a, rimA: 0x3aa0ff, rimB: 0x9a60ff, hazard: 0x40c0ff },
|
||||
};
|
||||
|
||||
// lights: one shadow-casting key light + floodlight colours
|
||||
// persistent lights (reused across arena rebuilds)
|
||||
function buildArena(scene) {
|
||||
const out = {};
|
||||
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);
|
||||
Object.assign(key.shadow.camera, { left: -11, right: 11, top: 11, bottom: -11, near: 1, far: 40 });
|
||||
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);
|
||||
const rimA = new T.PointLight(0xff7a1a, 1.1, 22); rimA.position.set(-9, 5, 9); scene.add(rimA);
|
||||
const rimB = new T.PointLight(0x4fa8ff, 0.9, 22); rimB.position.set(9, 5, -9); scene.add(rimB);
|
||||
const rimA = new T.PointLight(0xff7a1a, 1.1, 22); scene.add(rimA);
|
||||
const rimB = new T.PointLight(0x4fa8ff, 0.9, 22); scene.add(rimB);
|
||||
out.lights = { key, rimA, rimB, hemi: scene.children.find(o => o.isHemisphereLight) };
|
||||
out.flashLight = new T.PointLight(0xffaa55, 0, 9); scene.add(out.flashLight);
|
||||
out.scene = scene; out.group = null; out.id = null;
|
||||
out.rocketGeo = new T.CylinderGeometry(0.05, 0.05, 0.32, 8); out.rocketGeo.rotateZ(Math.PI / 2);
|
||||
out.rocketMat = new T.MeshStandardMaterial({ color: 0xdddddd, emissive: 0x331100 });
|
||||
out.rocketMeshes = [];
|
||||
buildArenaGeo(out, RC.ARENA);
|
||||
return out;
|
||||
}
|
||||
|
||||
function disposeGroup(g) {
|
||||
g.traverse(o => {
|
||||
if (o.geometry) o.geometry.dispose();
|
||||
if (o.material) [].concat(o.material).forEach(mm => { if (mm.map && mm.map.dispose) mm.map.dispose(); mm.dispose(); });
|
||||
});
|
||||
}
|
||||
|
||||
// (re)build all arena geometry for arena def A into a fresh group
|
||||
function buildArenaGeo(out, A) {
|
||||
const m = mats(), half = A.half, th = THEME[A.theme] || THEME.steel;
|
||||
const scene = out.scene;
|
||||
if (out.group) { scene.remove(out.group); disposeGroup(out.group); }
|
||||
const group = new T.Group(); scene.add(group); out.group = group; out.id = A.id;
|
||||
const scene_add = o => group.add(o);
|
||||
scene.background = new T.Color(th.bg);
|
||||
scene.fog = new T.Fog(th.fog, half * 3, half * 5.5);
|
||||
const { key, rimA, rimB, flashLight } = out.lights;
|
||||
const sc = Math.max(11, half + 3);
|
||||
Object.assign(key.shadow.camera, { left: -sc, right: sc, top: sc, bottom: -sc }); key.shadow.camera.updateProjectionMatrix();
|
||||
rimA.color.setHex(th.rimA); rimA.position.set(-half - 1, 5, half + 1); rimA.distance = half * 2.6;
|
||||
rimB.color.setHex(th.rimB); rimB.position.set(half + 1, 5, -half - 1); rimB.distance = half * 2.6;
|
||||
out.hazardCol = th.hazard;
|
||||
{ const scene = { add: scene_add }; buildArenaBody(scene, out, A, m, half, th); }
|
||||
}
|
||||
|
||||
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(), metalness: 0.55, roughness: 0.62 }));
|
||||
const floor = new T.Mesh(new T.PlaneGeometry(half * 2, half * 2), 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);
|
||||
|
||||
// spike walls (instanced spikes)
|
||||
const wallMat = new T.MeshStandardMaterial({ color: 0x30343b, metalness: 0.7, roughness: 0.45 });
|
||||
// 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 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, wallMat);
|
||||
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);
|
||||
@@ -522,11 +622,6 @@
|
||||
const l = new T.Mesh(new T.SphereGeometry(0.09, 10, 6), new T.MeshStandardMaterial({ color: 0x400000, emissive: 0xff1a1a, emissiveIntensity: 0 }));
|
||||
l.position.set(pit.x + sx * (pit.hw + 0.12), 0.08, pit.z + sz * (pit.hd + 0.12)); scene.add(l); return l;
|
||||
});
|
||||
// rockets
|
||||
out.rocketGeo = new T.CylinderGeometry(0.05, 0.05, 0.32, 8); out.rocketGeo.rotateZ(Math.PI / 2);
|
||||
out.rocketMat = new T.MeshStandardMaterial({ color: 0xdddddd, emissive: 0x331100 });
|
||||
out.rocketMeshes = [];
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- garage
|
||||
@@ -550,6 +645,8 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- view
|
||||
RC.buildRobotModel = buildRobot;
|
||||
|
||||
RC.Render = function (canvas, W, H) {
|
||||
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true });
|
||||
renderer.setClearColor(0x000000, 0);
|
||||
@@ -567,9 +664,18 @@
|
||||
const smoke = Particles(arenaScene, 300, 34, false, tex);
|
||||
const fire = Particles(arenaScene, 300, 18, true, tex);
|
||||
|
||||
const VIEW = 15.4, asp = W / H;
|
||||
const cam = new T.OrthographicCamera(-VIEW * asp / 2, VIEW * asp / 2, VIEW / 2, -VIEW / 2, 0.1, 120);
|
||||
const asp = W / H;
|
||||
const cam = new T.OrthographicCamera(-1, 1, 1, -1, 0.1, 200);
|
||||
const camBase = new T.Vector3(15.2, 15.5, 15.2), camLook = new T.Vector3(-1.25, 0, -1.25);
|
||||
// fit the orthographic camera to an arena of half-size h
|
||||
function fitCam(h) {
|
||||
const VIEW = h * 1.95;
|
||||
cam.left = -VIEW * asp / 2; cam.right = VIEW * asp / 2; cam.top = VIEW / 2; cam.bottom = -VIEW / 2;
|
||||
cam.updateProjectionMatrix();
|
||||
const d = h * 1.9;
|
||||
camBase.set(d, h * 1.95, d); camLook.set(-h * 0.16, 0, -h * 0.16);
|
||||
}
|
||||
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);
|
||||
@@ -578,7 +684,7 @@
|
||||
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;
|
||||
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false;
|
||||
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]; });
|
||||
|
||||
@@ -602,7 +708,7 @@
|
||||
},
|
||||
// intro fly-over, then a slow orbit behind the title screen; skip() jumps to the orbit
|
||||
showIntro(builds, paints) {
|
||||
api.showArena(RC.Combat.create({ robots: builds.map(b => RC.stats(b)), seed: 3 }), builds, paints);
|
||||
api.showArena(RC.Combat.create({ robots: builds.map(b => RC.stats(b)), seed: 3, arena: 'workshop' }), builds, paints);
|
||||
mode = 'intro'; introT = 0; pointMode(true);
|
||||
},
|
||||
skipIntro() { if (mode === 'intro' && introT < INTRO_END) introT = INTRO_END; },
|
||||
@@ -625,9 +731,28 @@
|
||||
// turntable angle that points the robot's side (+z = right) at the camera
|
||||
garage.turntable.rotation.y = Math.atan2(gcam.position.x, gcam.position.z) + a; hold = 1e9;
|
||||
},
|
||||
portrait(build, paint) {
|
||||
api.showGarage(build, paint);
|
||||
garage.turntable.rotation.y = 0.55;
|
||||
gcam.clearViewOffset(); gcam.position.set(1.75, 1.3, 2.1); gcam.lookAt(0, 0.4, 0);
|
||||
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);
|
||||
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); },
|
||||
// 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; }
|
||||
RC.setArena(A.id);
|
||||
robots.forEach(R => arenaScene.remove(R.root)); robots = [];
|
||||
buildArenaGeo(arena, A);
|
||||
fitCam(A.half);
|
||||
},
|
||||
showArena(s, builds, paints) {
|
||||
mode = 'arena'; state = s; pointMode(false); lightsOn(1);
|
||||
api.setArena(s.arena);
|
||||
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;
|
||||
@@ -657,8 +782,18 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
// fight camera: 'iso' (whole arena) | 'chase' (behind robot 0) | 'fpv' (cockpit of robot 0)
|
||||
get camMode() { return camMode; },
|
||||
setCam(m) {
|
||||
camMode = m; chaseInit = false;
|
||||
pcam.fov = m === 'fpv' ? 72 : 55; pcam.updateProjectionMatrix();
|
||||
if (mode === 'arena') pointMode(m !== 'iso');
|
||||
if (robots[0] && robots[0].turret) robots[0].turret.visible = m !== 'fpv';
|
||||
},
|
||||
project(x, y, z) {
|
||||
const v = new T.Vector3(x, y, z).project(cam);
|
||||
const v = new T.Vector3(x, y, z).project(mode === 'arena' && camMode !== 'iso' ? pcam : cam);
|
||||
// behind the camera (chase / cockpit): off screen
|
||||
if (v.z > 1) return { x: -999, y: -999 };
|
||||
return { x: (v.x + 1) / 2 * W, y: (1 - v.y) / 2 * H };
|
||||
},
|
||||
frame(dt, now) {
|
||||
@@ -679,14 +814,40 @@
|
||||
sparks.update(dt, 9, 1.2); smoke.update(dt, -0.6, 1.4); fire.update(dt, -2.5, 2);
|
||||
shake = Math.max(0, shake - dt * 1.2);
|
||||
const sx = (Math.random() - 0.5) * shake, sz = (Math.random() - 0.5) * shake;
|
||||
cam.position.set(camBase.x + sx, camBase.y, camBase.z + sz);
|
||||
cam.lookAt(camLook.x + sx, camLook.y, camLook.z + sz);
|
||||
flashT = Math.max(0, flashT - dt * 3);
|
||||
arena.flashLight.intensity = flashT * 4;
|
||||
if (camMode !== 'iso' && state && robots[0]) {
|
||||
followCam(dt, sx, sz);
|
||||
renderer.render(arenaScene, pcam);
|
||||
return;
|
||||
}
|
||||
cam.position.set(camBase.x + sx, camBase.y, camBase.z + sz);
|
||||
cam.lookAt(camLook.x + sx, camLook.y, camLook.z + sz);
|
||||
renderer.render(arenaScene, cam);
|
||||
},
|
||||
};
|
||||
|
||||
// chase: smooth camera behind and above robot 0 · fpv: eyes at the front edge of its top
|
||||
const cpos = new T.Vector3(), clook = new T.Vector3();
|
||||
function followCam(dt, sx, sz) {
|
||||
const r = state.robots[0], R = robots[0], half = (state.arena || RC.ARENA).half;
|
||||
const fx = Math.cos(r.a), fz = Math.sin(r.a);
|
||||
let px, py, pz, lx, ly, lz;
|
||||
if (camMode === 'fpv') {
|
||||
const k = R.st.len * 0.08;
|
||||
px = r.x + fx * k; pz = r.z + fz * k; py = Math.max(0.25, r.y) + R.top + 0.55;
|
||||
lx = px + fx * 6; lz = pz + fz * 6; ly = py - 1.25;
|
||||
cpos.set(px + sx * 0.3, py, pz + sz * 0.3); clook.set(lx, ly, lz);
|
||||
} else {
|
||||
px = Kit.clamp(r.x - fx * 3.6, -half - 1.2, half + 1.2); pz = Kit.clamp(r.z - fz * 3.6, -half - 1.2, half + 1.2); py = 2.2 + r.y * 0.5;
|
||||
lx = r.x + fx * 1.6; lz = r.z + fz * 1.6; ly = 0.3 + r.y * 0.5;
|
||||
const k = chaseInit ? Math.min(1, dt * 5) : 1;
|
||||
chaseInit = true;
|
||||
cpos.lerp(new T.Vector3(px + sx, py, pz + sz), k); clook.lerp(new T.Vector3(lx, ly, lz), k);
|
||||
}
|
||||
pcam.position.copy(cpos); pcam.lookAt(clook);
|
||||
}
|
||||
|
||||
// ---- intro: dark arena -> floodlights flicker on -> camera sweeps up -> two robots are lowered in
|
||||
const INTRO_END = RC.INTRO_END = 7.5;
|
||||
const ease = u => (u < 0.5 ? 2 * u * u : 1 - Math.pow(-2 * u + 2, 2) / 2);
|
||||
@@ -744,7 +905,7 @@
|
||||
|
||||
function animateArena(dt, now) {
|
||||
const s = state; if (!s) return;
|
||||
const A = RC.ARENA;
|
||||
const A = state.arena || RC.ARENA;
|
||||
robots.forEach((R, i) => {
|
||||
const r = s.robots[i];
|
||||
poseRobot(R, r, dt);
|
||||
|
||||
Reference in New Issue
Block a user