view update
This commit is contained in:
125
game/render3d.js
125
game/render3d.js
@@ -313,6 +313,25 @@
|
||||
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 if (ch.shape === 'ball') {
|
||||
const o = sk(new T.SphereGeometry(1, 24, 16), 2, 1, 2, 0);
|
||||
o.scale.set(L / 2, H / 2 + 0.06, Wd / 2); o.position.y = c + H / 2; tilt.add(o);
|
||||
const ring = new T.Mesh(new T.TorusGeometry(1, 0.045, 8, 28), accent);
|
||||
ring.rotation.x = Math.PI / 2; ring.scale.set(L / 2 * 1.01, Wd / 2 * 1.01, 1); ring.position.y = c + H * 0.5; tilt.add(ring);
|
||||
if (!drawn) { const st2 = box(0.05, H * 0.9, Wd * 0.5, m.stripe); st2.position.set(-L / 2 + 0.03, c + H * 0.5, 0); tilt.add(st2); }
|
||||
top = c + H * 1.05;
|
||||
} else if (ch.shape === 'tower') {
|
||||
const o = sk(new T.BoxGeometry(L, H, Wd), L, H, Wd, -H / 2); o.position.y = c + H / 2; tilt.add(o);
|
||||
const headH = H * 0.3, head = sk(new T.BoxGeometry(L * 0.7, headH, Wd * 0.7), L * 0.7, headH, Wd * 0.7, -headH / 2);
|
||||
head.position.set(0, c + H + headH / 2, 0); tilt.add(head);
|
||||
const vis = box(0.02, headH * 0.4, Wd * 0.5, m.glowW); vis.position.set(L * 0.35 + 0.005, c + H + headH * 0.6, 0); tilt.add(vis);
|
||||
if (!drawn) for (const sy of [0.3, 0.7]) { const band = box(L * 1.004, 0.05, Wd * 1.004, m.stripe); band.position.set(0, c + H * sy, 0); tilt.add(band); }
|
||||
top = c + H + headH;
|
||||
} else if (ch.shape === 'slab') {
|
||||
const o = sk(new T.BoxGeometry(L, H, Wd), L, H, Wd, -H / 2); o.position.y = c + H / 2; tilt.add(o);
|
||||
const nose = box(0.4, H * 0.9, Wd * 1.02, m.steel); nose.position.set(L / 2 + 0.06, c + H * 0.4, 0); nose.rotation.z = -0.5; tilt.add(nose);
|
||||
if (!drawn) { const edge = box(0.1, 0.07, Wd * 1.05, m.stripe); edge.position.set(L / 2 + 0.22, c * 0.5, 0); tilt.add(edge); }
|
||||
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) {
|
||||
@@ -327,6 +346,11 @@
|
||||
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.hump) {
|
||||
const hb = sk(new T.SphereGeometry(1, 18, 10, 0, Math.PI * 2, 0, Math.PI / 2), 2, 1, 2, 0);
|
||||
hb.scale.set(L * 0.3, H * 0.9, Wd * 0.4); hb.position.set(-L * 0.22, top, 0); tilt.add(hb);
|
||||
top += H * 0.6;
|
||||
}
|
||||
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);
|
||||
@@ -441,9 +465,12 @@
|
||||
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
|
||||
if (w.type === 'wedge') {
|
||||
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);
|
||||
// long spike lance on a sleeve - it thrusts forward when fired (poseRobot drives out.lance.position.x)
|
||||
const g = new T.Group(); g.position.set(L / 2, c + H * 0.4, 0); g.userData.baseX = L / 2; tilt.add(g);
|
||||
const sleeve = cyl(0.07, 0.08, 0.3, m.steel, 10); sleeve.rotation.z = Math.PI / 2; sleeve.position.x = -0.05; tilt.add(sleeve);
|
||||
const shaft = cyl(0.05, 0.05, 0.85, m.dark, 8); shaft.rotation.z = Math.PI / 2; shaft.position.x = 0.42; g.add(shaft);
|
||||
const tip = cyl(0.001, 0.13, 0.42, HZ, 12); tip.rotation.z = -Math.PI / 2; tip.position.x = 0.95; g.add(tip);
|
||||
out.lance = g;
|
||||
} 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);
|
||||
@@ -610,6 +637,11 @@
|
||||
const sp = Math.hypot(r.vx, r.vz) * (Math.cos(r.a) * r.vx + Math.sin(r.a) * r.vz >= 0 ? 1 : -1);
|
||||
for (const wl of R.wheels) wl.rotation.z -= sp * dt / (R.wheelR || 0.16);
|
||||
if (R.flipper) R.flipper.rotation.z = -0.32 + (r.flipAnim > 0 ? Math.sin((1 - r.flipAnim / 0.35) * Math.PI) * 1.5 : 0);
|
||||
if (R.lance) {
|
||||
// boost is set for 0.8 s when the lance fires -> fast stab out and back
|
||||
const k = r.boost > 0 ? r.boost / 0.8 : 0;
|
||||
R.lance.position.x = R.lance.userData.baseX + Math.sin(Math.min(1, (1 - k) * 2.2) * Math.PI) * 0.55;
|
||||
}
|
||||
if (R.hammer) {
|
||||
let ang = 1.9;
|
||||
if (r.swing > 0) { const k = 1 - r.swing / 0.28; ang = lerp(1.9, -0.25, k * k); }
|
||||
@@ -794,6 +826,9 @@
|
||||
scrap: new T.MeshStandardMaterial({ color: 0x5a5048, metalness: 0.6, roughness: 0.8 }),
|
||||
barrier: new T.MeshStandardMaterial({ color: 0x9aa0a8, metalness: 0.6, roughness: 0.5 }),
|
||||
};
|
||||
const RUST = new T.MeshStandardMaterial({ color: 0x6e3e22, metalness: 0.45, roughness: 0.92 });
|
||||
const PAINT = new T.MeshStandardMaterial({ color: 0x7a5230, metalness: 0.3, roughness: 0.85 });
|
||||
const scrapMats = [BMAT.scrap, RUST, PAINT, m.steel, m.dark];
|
||||
let bseed = 7;
|
||||
const brnd = () => { bseed = (bseed * 16807) % 2147483647; return bseed / 2147483647; };
|
||||
for (const b of A.blocks) {
|
||||
@@ -801,22 +836,43 @@
|
||||
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);
|
||||
const col = cyl(rr, rr * 1.12, b.h, mat, 16); 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, 16); cap.position.y = b.h; g.add(cap);
|
||||
const foot = cyl(rr * 1.25, rr * 1.35, 0.14, m.dark, 16); foot.position.y = 0.07; g.add(foot);
|
||||
for (const sy of [0.28, 0.64]) { const band = cyl(rr * 1.05, rr * 1.05, 0.14, m.stripe, 16); band.position.y = b.h * sy; g.add(band); }
|
||||
// warning light on top
|
||||
const wl = new T.Mesh(new T.SphereGeometry(0.07, 8, 6), new T.MeshStandardMaterial({ color: 0x401000, emissive: 0xff5a10, emissiveIntensity: 0.9 }));
|
||||
wl.position.y = b.h + 0.1; g.add(wl);
|
||||
} 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);
|
||||
// tumbled junk pile: mixed rusty/steel/painted plates, each tilted, with a dark edge lip
|
||||
for (let k = 0; k < 6; k++) {
|
||||
const w2 = b.hw * (0.45 + brnd() * 0.8), h2 = b.h * (0.22 + brnd() * 0.5), d2 = b.hd * (0.45 + brnd() * 0.8);
|
||||
const pm = scrapMats[(brnd() * scrapMats.length) | 0];
|
||||
const slab = new T.Group();
|
||||
const p2 = box(w2, h2, d2, pm); p2.castShadow = true; slab.add(p2);
|
||||
const lip = box(w2 + 0.04, 0.05, d2 + 0.04, m.dark); lip.position.y = h2 / 2; slab.add(lip); // crisp top edge
|
||||
slab.position.set((brnd() - 0.5) * b.hw * 1.1, h2 / 2 + brnd() * b.h * 0.5, (brnd() - 0.5) * b.hd * 1.1);
|
||||
slab.rotation.set((brnd() - 0.5) * 0.4, brnd() * 3, (brnd() - 0.5) * 0.4);
|
||||
g.add(slab);
|
||||
}
|
||||
// a rusty barrel wedged in, with a warning ring
|
||||
const br = Math.min(b.hw, b.hd) * 0.42;
|
||||
const barrel = cyl(br, br, b.h * 0.95, RUST, 14); barrel.position.set((brnd() - 0.5) * b.hw * 0.5, b.h * 0.48, (brnd() - 0.5) * b.hd * 0.5);
|
||||
barrel.rotation.z = 0.12; barrel.castShadow = true; g.add(barrel);
|
||||
const ring = cyl(br * 1.04, br * 1.04, 0.1, m.stripe, 14); ring.position.copy(barrel.position); ring.rotation.z = 0.12; g.add(ring);
|
||||
// a leaning hazard-striped plank
|
||||
const plank = box(0.1, b.h * 1.5, b.hd * 0.8, m.stripe); plank.position.set(b.hw * 0.7, b.h * 0.6, 0); plank.rotation.z = 0.5; plank.castShadow = true; g.add(plank);
|
||||
} 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 top = box(b.hw * 2 + 0.06, 0.12, b.hd * 2 + 0.06, m.stripe); top.position.y = b.h; g.add(top);
|
||||
const base = box(b.hw * 2 + 0.1, 0.1, b.hd * 2 + 0.1, m.dark); base.position.y = 0.05; g.add(base);
|
||||
} else { // crate: steel box with hazard bands, corner bolts and a plated top
|
||||
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); }
|
||||
const lid = box(b.hw * 2 + 0.05, 0.08, b.hd * 2 + 0.05, m.dark); lid.position.y = b.h; g.add(lid);
|
||||
for (const sy of [0.3, 0.72]) { const band = box(b.hw * 2.04, 0.08, b.hd * 2.04, m.stripe); band.position.y = b.h * sy; g.add(band); }
|
||||
for (const sx of [-1, 1]) for (const sz of [-1, 1]) {
|
||||
const bolt = cyl(0.03, 0.03, b.h * 0.9, m.dark, 6); bolt.position.set(sx * (b.hw - 0.05), b.h / 2, sz * (b.hd - 0.05)); g.add(bolt);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const b of A.belts) {
|
||||
@@ -887,11 +943,30 @@
|
||||
const mr = cyl(0.43, 0.43, 0.06, m.stripe, 20); mr.position.y = 0.08; mag.add(mr);
|
||||
out.crane = { post: cpost, boom, cable, mag, px: C.x - 2.4, pz: C.z + 2.4 };
|
||||
|
||||
// pit doors + warning lights
|
||||
// pit: a real shaft you fall into, a hazard-striped rim and a steel grate
|
||||
const pit = A.pit;
|
||||
const shaftMat = new T.MeshStandardMaterial({ color: 0x090a0d, metalness: 0.6, roughness: 0.9 });
|
||||
const floorHole = box(pit.hw * 2, 0.02, pit.hd * 2, new T.MeshBasicMaterial({ color: 0x000000 }));
|
||||
floorHole.position.set(pit.x, -0.01, pit.z); scene.add(floorHole);
|
||||
for (const [nx, nz] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) { // four shaft walls going down
|
||||
const w = box(nz ? pit.hw * 2 : 0.08, 1.6, nz ? 0.08 : pit.hd * 2, shaftMat);
|
||||
w.position.set(pit.x + nx * pit.hw, -0.8, pit.z + nz * pit.hd); scene.add(w);
|
||||
}
|
||||
for (const sx of [-1, 1]) for (const sz of [-1, 1]) { // striped rim around the edge
|
||||
const bx = box(pit.hw * 2 + 0.2, 0.09, 0.14, m.stripe); bx.position.set(pit.x, 0.05, pit.z + sz * (pit.hd + 0.05)); scene.add(bx);
|
||||
const bz = box(0.14, 0.09, pit.hd * 2 + 0.2, m.stripe); bz.position.set(pit.x + sx * (pit.hw + 0.05), 0.05, pit.z); scene.add(bz);
|
||||
}
|
||||
const grate = new T.Group(); out.pitGrate = grate; scene.add(grate); // retracts as the pit opens
|
||||
const gbarMat = new T.MeshStandardMaterial({ color: 0x4a515c, metalness: 0.85, roughness: 0.35 });
|
||||
const nb = Math.max(4, Math.round(pit.hw * 2 / 0.3));
|
||||
for (let k = 0; k <= nb; k++) {
|
||||
const t = -pit.hw + (k / nb) * pit.hw * 2;
|
||||
const b1 = box(0.05, 0.08, pit.hd * 2, gbarMat); b1.position.set(pit.x + t, 0.06, pit.z); grate.add(b1);
|
||||
const b2 = box(pit.hw * 2, 0.08, 0.05, gbarMat); b2.position.set(pit.x, 0.055, pit.z + t * (pit.hd / pit.hw)); grate.add(b2);
|
||||
}
|
||||
out.pitDoors = [-1, 1].map(sx => {
|
||||
const d = box(pit.hw, 0.05, pit.hd * 2, new T.MeshStandardMaterial({ color: 0x3d4148, metalness: 0.8, roughness: 0.4 }));
|
||||
d.position.set(pit.x + sx * pit.hw / 2, 0.025, pit.z); d.userData.sx = sx; scene.add(d); return d;
|
||||
d.position.set(pit.x + sx * pit.hw / 2, 0.03, pit.z); d.userData.sx = sx; scene.add(d); return d;
|
||||
});
|
||||
out.pitLamps = [[-1, -1], [1, -1], [-1, 1], [1, 1]].map(([sx, sz]) => {
|
||||
const l = new T.Mesh(new T.SphereGeometry(0.09, 10, 6), new T.MeshStandardMaterial({ color: 0x400000, emissive: 0xff1a1a, emissiveIntensity: 0 }));
|
||||
@@ -1278,6 +1353,23 @@
|
||||
robots.forEach((R, i) => {
|
||||
const r = s.robots[i];
|
||||
poseRobot(R, r, dt);
|
||||
// long front weapons must stop at the enemy, not stab through it
|
||||
if (R.lance) {
|
||||
const e = s.robots[1 - i];
|
||||
if (e && !e.out) {
|
||||
const dx = e.x - r.x, dz = e.z - r.z, d = Math.hypot(dx, dz) || 1;
|
||||
const fx = Math.cos(r.a), fz = Math.sin(r.a), facing = (dx * fx + dz * fz) / d;
|
||||
if (facing > 0.55) {
|
||||
const reach = d - e.st.rad * 0.85, base = R.st.len / 2 + 0.95;
|
||||
const maxThrust = Math.max(0, reach - base), bx = R.lance.userData.baseX;
|
||||
if (R.lance.position.x - bx > maxThrust) {
|
||||
const hit = R.lance.position.x - bx - maxThrust > 0.04;
|
||||
R.lance.position.x = bx + maxThrust;
|
||||
if (hit && Math.random() < 0.6) burst(e.x - fx * e.st.rad, 0.4, e.z - fz * e.st.rad, 10, 5, [1, 0.8, 0.4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// damaged robots smoke, dead ones burn
|
||||
const hp = r.hp / r.maxHp;
|
||||
R.smokeT -= dt;
|
||||
@@ -1335,6 +1427,7 @@
|
||||
// pit
|
||||
const o = s.pitOpen;
|
||||
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; }
|
||||
if (arena.pitGrate) { arena.pitGrate.position.y = -o * 1.5; arena.pitGrate.visible = o < 0.98; }
|
||||
for (const l of arena.pitLamps) l.material.emissiveIntensity = s.pitAlarm ? (Math.sin(now / 150) > 0 ? 2.5 : 0.4) : 0;
|
||||
// rockets
|
||||
// mines lying on the floor: dark puck, the lamp blinks fast once it is armed
|
||||
|
||||
Reference in New Issue
Block a user