update images and audio
This commit is contained in:
217
game/render3d.js
217
game/render3d.js
@@ -44,7 +44,29 @@
|
||||
function floorTex() {
|
||||
const A = RC.ARENA, S = 64, N = A.half * 2 * S; // 64 px per metre
|
||||
const P = (x, z) => [(x + A.half) * S, (z + A.half) * S];
|
||||
return canvasTex(N, N, (c) => {
|
||||
let plate = null; // tex_floor.jpg from ComfyGen (make_tileable)
|
||||
const tex = canvasTex(N, N, draw);
|
||||
const im = new Image();
|
||||
im.onload = () => {
|
||||
// under file:// Chrome taints the canvas with a disk image and WebGL refuses it -> keep the drawn plates
|
||||
// (the release HTML embeds images as data: URIs, there it works)
|
||||
const probe = document.createElement('canvas').getContext('2d');
|
||||
probe.drawImage(im, 0, 0, 1, 1);
|
||||
try { probe.getImageData(0, 0, 1, 1); } catch (e) { return; }
|
||||
plate = im; draw(tex.image.getContext('2d')); tex.needsUpdate = true;
|
||||
};
|
||||
im.src = Kit.asset('assets/Sprites/tex_floor.jpg');
|
||||
return tex;
|
||||
function draw(c) {
|
||||
if (plate) { // 4 m per texture tile, slightly darkened
|
||||
for (let x = 0; x < N; x += 256) for (let y = 0; y < N; y += 256) c.drawImage(plate, x, y, 256, 256);
|
||||
c.fillStyle = 'rgba(10,12,16,.35)'; c.fillRect(0, 0, N, N);
|
||||
c.strokeStyle = 'rgba(0,0,0,.55)'; c.lineWidth = 3;
|
||||
for (let k = 0; k <= N; k += 128) { c.beginPath(); c.moveTo(k, 0); c.lineTo(k, N); c.moveTo(0, k); c.lineTo(N, k); c.stroke(); }
|
||||
} else drawPlates(c);
|
||||
drawMarks(c);
|
||||
}
|
||||
function drawPlates(c) {
|
||||
// steel plates 2 m
|
||||
for (let i = 0; i < A.half; i++) for (let j = 0; j < A.half; j++) {
|
||||
const v = 52 + ((i * 7 + j * 13) % 5) * 4;
|
||||
@@ -54,6 +76,8 @@
|
||||
c.fillStyle = '#25272c';
|
||||
for (const [rx, ry] of [[10, 10], [118, 10], [10, 118], [118, 118]]) { c.beginPath(); c.arc(i * 128 + rx, j * 128 + ry, 3, 0, 7); c.fill(); }
|
||||
}
|
||||
}
|
||||
function drawMarks(c) {
|
||||
// scratches + oil
|
||||
let seed = 5; const r = () => { seed = (seed * 16807) % 2147483647; return seed / 2147483647; };
|
||||
for (let k = 0; k < 340; k++) {
|
||||
@@ -78,7 +102,7 @@
|
||||
// centre mark
|
||||
const [cx, cy] = P(0, 0);
|
||||
c.strokeStyle = 'rgba(255,122,26,.35)'; c.lineWidth = 5; c.beginPath(); c.arc(cx, cy, 1.4 * S, 0, 7); c.stroke();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- particles
|
||||
@@ -132,6 +156,7 @@
|
||||
M.rubber = new T.MeshStandardMaterial({ color: 0x15161a, metalness: 0, roughness: 0.92 });
|
||||
M.hub = new T.MeshStandardMaterial({ color: 0x9aa1aa, metalness: 0.8, roughness: 0.35 });
|
||||
M.glowW = new T.MeshStandardMaterial({ color: 0xffffff, emissive: 0xfff2c0, emissiveIntensity: 1.5 });
|
||||
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.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]);
|
||||
@@ -141,16 +166,56 @@
|
||||
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; };
|
||||
|
||||
// ---- skin: paint colour + the player's own drawing (paint.layer, 512x256 canvas:
|
||||
// left half = top view, front to the right; right half = side view, front to the right)
|
||||
const css = n => '#' + (n >>> 0).toString(16).padStart(6, '0');
|
||||
function makeSkin(paint) {
|
||||
const cv = document.createElement('canvas'); cv.width = 512; cv.height = 256;
|
||||
const tex = new T.CanvasTexture(cv);
|
||||
tex.encoding = T.sRGBEncoding; tex.anisotropy = 4;
|
||||
const mat = new T.MeshStandardMaterial({ map: tex, metalness: 0.4, roughness: 0.45 });
|
||||
function redraw(p = paint) {
|
||||
paint = p;
|
||||
const c = cv.getContext('2d');
|
||||
c.fillStyle = css(p.body); c.fillRect(0, 0, 512, 256);
|
||||
c.strokeStyle = 'rgba(0,0,0,.2)'; c.lineWidth = 3; c.strokeRect(5, 5, 246, 246); c.strokeRect(261, 5, 246, 246);
|
||||
if (p.layer) c.drawImage(p.layer, 0, 0, 512, 256);
|
||||
tex.needsUpdate = true;
|
||||
}
|
||||
redraw();
|
||||
return { mat, redraw };
|
||||
}
|
||||
// planar UVs by face direction: up/down faces -> top half, sides -> side half (readable on both sides)
|
||||
function skinUV(geo, L, Wd, H, y0) {
|
||||
geo = geo.index ? geo.toNonIndexed() : geo;
|
||||
geo.computeVertexNormals();
|
||||
const p = geo.attributes.position, n = geo.attributes.normal, uv = new Float32Array(p.count * 2);
|
||||
const cl = (v, a, b) => Math.min(b, Math.max(a, v));
|
||||
for (let i = 0; i < p.count; i++) {
|
||||
const fx = cl((p.getX(i) + L / 2) / L, 0, 1), fz = cl((p.getZ(i) + Wd / 2) / Wd, 0, 1), fy = cl((p.getY(i) - y0) / H, 0, 1);
|
||||
const ax = Math.abs(n.getX(i)), ay = Math.abs(n.getY(i)), az = Math.abs(n.getZ(i));
|
||||
let u, v;
|
||||
if (ay >= ax && ay >= az) { u = 0.004 + 0.492 * fx; v = 1 - fz; }
|
||||
else if (az >= ax) { u = 0.504 + 0.492 * (n.getZ(i) > 0 ? fx : 1 - fx); v = fy; }
|
||||
else { u = 0.504 + 0.492 * (n.getX(i) > 0 ? 1 - fz : fz); v = fy; }
|
||||
uv[i * 2] = u; uv[i * 2 + 1] = v;
|
||||
}
|
||||
geo.setAttribute('uv', new T.BufferAttribute(uv, 2));
|
||||
return geo;
|
||||
}
|
||||
|
||||
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;
|
||||
const L = st.len, Wd = st.wid, H = st.h;
|
||||
const body = new T.MeshStandardMaterial({ color: paint.body, metalness: 0.45, roughness: 0.42 });
|
||||
const skin = makeSkin(paint), body = skin.mat;
|
||||
const drawn = !!(paint.layer && paint.drawn); // own artwork: no stock stripes, painted armour
|
||||
const accent = new T.MeshStandardMaterial({ color: paint.accent, metalness: 0.3, roughness: 0.45 });
|
||||
const armour = ar ? new T.MeshStandardMaterial({ color: ar.tint, metalness: 0.9, roughness: 0.28 }) : null;
|
||||
const armour = ar ? (drawn ? body : new T.MeshStandardMaterial({ color: ar.tint, metalness: 0.9, roughness: 0.28 })) : null;
|
||||
const root = new T.Group(), tilt = new T.Group();
|
||||
root.add(tilt);
|
||||
const out = { root, tilt, body, st, build, roll: 0, flash: 0, spinA: 0, sawA: 0, gunA: 0, smokeT: 0 };
|
||||
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 big = wh && wh.kind === 'big';
|
||||
const c = big ? 0.12 : 0.1; // ground clearance
|
||||
out.c = c;
|
||||
@@ -162,26 +227,29 @@
|
||||
s.moveTo(-L / 2, 0); s.lineTo(L / 2, 0); s.lineTo(L / 2, H * 0.22); s.lineTo(-L / 2 + L * 0.38, H); s.lineTo(-L / 2, H); s.closePath();
|
||||
const g = new T.ExtrudeGeometry(s, { depth: Wd, bevelEnabled: true, bevelSize: 0.015, bevelThickness: 0.015, bevelSegments: 1 });
|
||||
g.translate(0, 0, -Wd / 2);
|
||||
const o = new T.Mesh(g, body); o.position.y = c; o.castShadow = o.receiveShadow = true; tilt.add(o);
|
||||
const st1 = box(L * 0.32, 0.02, Wd * 0.8, m.stripe); st1.position.set(-L / 2 + L * 0.19, top + 0.012, 0); tilt.add(st1);
|
||||
const o = sk(g, L, H, Wd, 0); o.position.y = c; tilt.add(o);
|
||||
if (!drawn) { const st1 = box(L * 0.32, 0.02, Wd * 0.8, m.stripe); st1.position.set(-L / 2 + L * 0.19, top + 0.012, 0); tilt.add(st1); }
|
||||
} else if (ch.shape === 'dome') {
|
||||
const o = box(L, H * 0.5, Wd, body); o.position.y = c + H * 0.25; tilt.add(o);
|
||||
const d = new T.Mesh(new T.SphereGeometry(1, 28, 12, 0, Math.PI * 2, 0, Math.PI / 2), body);
|
||||
d.scale.set(L * 0.5, H * 0.75, Wd * 0.5); d.position.y = c + H * 0.5; d.castShadow = true; tilt.add(d);
|
||||
const o = sk(new T.BoxGeometry(L, H * 0.5, Wd), L, H * 0.5, Wd, -H * 0.25); o.position.y = c + H * 0.25; tilt.add(o);
|
||||
const d = sk(new T.SphereGeometry(1, 28, 12, 0, Math.PI * 2, 0, Math.PI / 2), 2, 1, 2, 0);
|
||||
d.scale.set(L * 0.5, H * 0.75, Wd * 0.5); d.position.y = c + H * 0.5; tilt.add(d);
|
||||
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 {
|
||||
const o = box(L, H, Wd, body); o.position.y = c + H / 2; tilt.add(o);
|
||||
const s1 = box(L * 0.86, 0.02, Wd * 0.22, accent); s1.position.set(0, top + 0.01, 0); tilt.add(s1);
|
||||
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);
|
||||
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) {
|
||||
const s1 = box(L * 0.86, 0.02, Wd * 0.22, accent); s1.position.set(0, top + 0.01, 0); tilt.add(s1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
out.top = top;
|
||||
|
||||
// armour plates (sides + rear), bolts
|
||||
if (armour) {
|
||||
for (const sz of [-1, 1]) {
|
||||
const p = 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);
|
||||
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 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);
|
||||
@@ -340,6 +408,7 @@
|
||||
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);
|
||||
out.lights = { key, rimA, rimB, hemi: scene.children.find(o => o.isHemisphereLight) };
|
||||
out.flashLight = new T.PointLight(0xffaa55, 0, 9); scene.add(out.flashLight);
|
||||
|
||||
// floor
|
||||
@@ -376,7 +445,7 @@
|
||||
}
|
||||
for (const [px, pz] of [[-1, -1], [1, -1], [-1, 1]]) {
|
||||
const post = box(0.22, 3.4, 0.22, wallMat); post.position.set(px * (half + 0.35), 1.7, pz * (half + 0.35)); scene.add(post);
|
||||
const lamp = box(0.5, 0.3, 0.3, m.glowW); lamp.position.set(px * (half + 0.2), 3.5, pz * (half + 0.2)); scene.add(lamp);
|
||||
const lamp = box(0.5, 0.3, 0.3, m.lamp); lamp.position.set(px * (half + 0.2), 3.5, pz * (half + 0.2)); scene.add(lamp);
|
||||
}
|
||||
// audience stands behind the back walls
|
||||
const seats = new T.InstancedMesh(new T.BoxGeometry(0.32, 0.5, 0.32), new T.MeshStandardMaterial({ roughness: 0.9 }), 900);
|
||||
@@ -461,37 +530,29 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- garage
|
||||
// transparent: the painted workshop (bg_workshop.jpg, CSS) shows through; only a shadow catcher
|
||||
function buildGarage(scene) {
|
||||
scene.background = new T.Color(0x0c0f15);
|
||||
scene.background = null;
|
||||
scene.add(new T.HemisphereLight(0x9fb4d8, 0x1c160f, 0.6));
|
||||
const spot = new T.SpotLight(0xfff0d8, 2.2, 14, 0.62, 0.45);
|
||||
spot.position.set(1.6, 5, 2.6); spot.target.position.set(0, 0, 0); spot.castShadow = true; spot.shadow.mapSize.set(1024, 1024);
|
||||
scene.add(spot); scene.add(spot.target);
|
||||
const rim = new T.PointLight(0xff7a1a, 1.2, 8); rim.position.set(-2.5, 1.2, -1.5); scene.add(rim);
|
||||
const rim2 = new T.PointLight(0x4fa8ff, 0.8, 8); rim2.position.set(2.5, 1.0, -2); scene.add(rim2);
|
||||
const floor = new T.Mesh(new T.PlaneGeometry(30, 30), new T.MeshStandardMaterial({ color: 0x1a1d23, metalness: 0.3, roughness: 0.8 }));
|
||||
const floor = new T.Mesh(new T.PlaneGeometry(30, 30), new T.ShadowMaterial({ opacity: 0.55 }));
|
||||
floor.rotation.x = -Math.PI / 2; floor.receiveShadow = true; scene.add(floor);
|
||||
const turntable = new T.Group(); scene.add(turntable);
|
||||
const disc = cyl(1.5, 1.6, 0.12, new T.MeshStandardMaterial({ color: 0x3a3e46, metalness: 0.8, roughness: 0.35 }), 48);
|
||||
disc.position.y = 0.06; disc.receiveShadow = true; turntable.add(disc);
|
||||
const ring = new T.Mesh(new T.TorusGeometry(1.56, 0.03, 8, 64), new T.MeshStandardMaterial({ color: 0xff7a1a, emissive: 0xff7a1a, emissiveIntensity: 0.6 }));
|
||||
ring.rotation.x = Math.PI / 2; ring.position.y = 0.12; scene.add(ring);
|
||||
const wallMat = new T.MeshStandardMaterial({ map: canvasTex(256, 128, (c, w, h) => {
|
||||
c.fillStyle = '#171a20'; c.fillRect(0, 0, w, h); c.fillStyle = '#0d0f13';
|
||||
for (let x = 8; x < w; x += 16) for (let y = 8; y < h; y += 16) { c.beginPath(); c.arc(x, y, 2.5, 0, 7); c.fill(); }
|
||||
}, [6, 2]), roughness: 0.9 });
|
||||
const wall = new T.Mesh(new T.PlaneGeometry(24, 8), wallMat); wall.position.set(0, 4, -4); wall.receiveShadow = true; scene.add(wall);
|
||||
const st = box(24, 0.3, 0.05, mats().stripe); st.position.set(0, 0.4, -3.97); scene.add(st);
|
||||
// a few crates
|
||||
for (const [x, z, s] of [[-3.2, -3.2, 0.7], [-2.5, -3.4, 0.5], [3.4, -3.1, 0.8]]) {
|
||||
const b = box(s, s, s, new T.MeshStandardMaterial({ color: 0x4b3a26, roughness: 0.9 })); b.position.set(x, s / 2, z); scene.add(b);
|
||||
}
|
||||
return { turntable };
|
||||
return { turntable, spot };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- view
|
||||
RC.Render = function (canvas, W, H) {
|
||||
const renderer = new T.WebGLRenderer({ canvas, antialias: true });
|
||||
const renderer = new T.WebGLRenderer({ canvas, antialias: true, alpha: true });
|
||||
renderer.setClearColor(0x000000, 0);
|
||||
renderer.outputEncoding = T.sRGBEncoding;
|
||||
renderer.toneMapping = T.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.15;
|
||||
@@ -511,17 +572,40 @@
|
||||
const camBase = new T.Vector3(15.2, 15.5, 15.2), camLook = new T.Vector3(-1.25, 0, -1.25);
|
||||
cam.position.copy(camBase); cam.lookAt(camLook);
|
||||
const gcam = new T.PerspectiveCamera(34, asp, 0.1, 60);
|
||||
gcam.position.set(2.9, 1.8, 3.4); gcam.lookAt(0, 0.35, 0);
|
||||
gcam.setViewOffset(W, H, 170, 20, W, H);
|
||||
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
|
||||
// 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;
|
||||
let mode = 'garage', gRobot = null, robots = [], state = null, shake = 0, flashT = 0, introT = 0, scale = 1, hold = 0;
|
||||
let quality = 'high', fxMul = 1;
|
||||
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]; });
|
||||
|
||||
const api = {
|
||||
get mode() { return mode; },
|
||||
resize(scale) {
|
||||
renderer.setPixelRatio(Math.min(3, scale * (root.devicePixelRatio || 1)));
|
||||
get introTime() { return introT; },
|
||||
resize(sc) {
|
||||
scale = sc;
|
||||
const cap = quality === 'low' ? 1 : quality === 'medium' ? 1.5 : 3;
|
||||
renderer.setPixelRatio(Math.min(cap, sc * (root.devicePixelRatio || 1)));
|
||||
renderer.setSize(W, H);
|
||||
},
|
||||
// 'low' | 'medium' | 'high': shadows, resolution, particle amount
|
||||
setQuality(q) {
|
||||
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;
|
||||
for (const sc of [arenaScene, garageScene]) sc.traverse(o => { if (o.material) [].concat(o.material).forEach(m => { m.needsUpdate = true; }); });
|
||||
api.resize(scale);
|
||||
},
|
||||
// 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);
|
||||
mode = 'intro'; introT = 0; pointMode(true);
|
||||
},
|
||||
skipIntro() { if (mode === 'intro' && introT < INTRO_END) introT = INTRO_END; },
|
||||
showGarage(build, paint) {
|
||||
mode = 'garage';
|
||||
if (gRobot) garage.turntable.remove(gRobot.root);
|
||||
@@ -529,9 +613,21 @@
|
||||
gRobot.root.position.y = 0.12;
|
||||
garage.turntable.add(gRobot.root);
|
||||
},
|
||||
setPaint(paint) { if (gRobot) { gRobot.body.color.setHex(paint.body); } },
|
||||
// live update while painting (colour or drawing changed, no rebuild)
|
||||
setPaint(paint) { if (gRobot) gRobot.skin.redraw(paint); },
|
||||
// camera for the paint booth: closer, robot centred in the left part
|
||||
// drag to turn the robot on the turntable (auto-rotation pauses for a moment)
|
||||
turn(dx) { garage.turntable.rotation.y += dx * 0.012; hold = 2.5; },
|
||||
// view a side straight on: 'top' | 'left' | 'right' | 'front' | null (free)
|
||||
face(side) {
|
||||
const a = { right: 0, front: -Math.PI / 2, left: Math.PI, top: 0 }[side];
|
||||
if (a == null) { hold = 0; return; }
|
||||
// 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;
|
||||
},
|
||||
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); },
|
||||
showArena(s, builds, paints) {
|
||||
mode = 'arena'; state = s;
|
||||
mode = 'arena'; state = s; pointMode(false); lightsOn(1);
|
||||
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;
|
||||
@@ -567,10 +663,18 @@
|
||||
},
|
||||
frame(dt, now) {
|
||||
if (mode === 'garage') {
|
||||
garage.turntable.rotation.y += dt * 0.45;
|
||||
if (hold > 0) hold -= dt; else garage.turntable.rotation.y += dt * 0.45;
|
||||
renderer.render(garageScene, gcam);
|
||||
return;
|
||||
}
|
||||
if (mode === 'intro') {
|
||||
introT += dt;
|
||||
introScript(dt, now);
|
||||
animateArena(dt, now);
|
||||
sparks.update(dt, 9, 1.2); smoke.update(dt, -0.6, 1.4); fire.update(dt, -2.5, 2);
|
||||
renderer.render(arenaScene, pcam);
|
||||
return;
|
||||
}
|
||||
animateArena(dt, now);
|
||||
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);
|
||||
@@ -583,7 +687,46 @@
|
||||
},
|
||||
};
|
||||
|
||||
// ---- 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);
|
||||
function lightsOn(k) {
|
||||
const L = arena.lights;
|
||||
L.key.intensity = 1.25 * k; L.rimA.intensity = 1.1 * k; L.rimB.intensity = 0.9 * k;
|
||||
if (L.hemi) L.hemi.intensity = 0.55 * (0.12 + 0.88 * k);
|
||||
M.lamp.emissiveIntensity = 1.5 * k;
|
||||
}
|
||||
function introScript(dt) {
|
||||
const t = introT, s = state;
|
||||
// floodlights: off, flicker, on
|
||||
lightsOn(t < 1.2 ? 0 : t < 1.32 ? 1 : t < 1.5 ? 0.08 : t < 1.62 ? 0.8 : t < 1.85 ? 0.25 : 1);
|
||||
// camera path, then a slow orbit
|
||||
let ang, r, h, lx, lz;
|
||||
if (t < INTRO_END) {
|
||||
const e = ease(Math.min(1, t / INTRO_END));
|
||||
ang = lerp(-2.4, Math.PI / 4, e); r = lerp(5, 20.5, e); h = lerp(0.8, 13.5, Math.pow(e, 1.4));
|
||||
lx = lerp(RC.ARENA.pit.x, -0.6, e); lz = lerp(RC.ARENA.pit.z, -0.6, e);
|
||||
} else {
|
||||
ang = Math.PI / 4 + (t - INTRO_END) * 0.05; r = 20.5; h = 13.5; lx = lz = 0;
|
||||
}
|
||||
pcam.position.set(Math.cos(ang) * r, h, Math.sin(ang) * r);
|
||||
pcam.lookAt(lx, 0.3, lz);
|
||||
// robots lowered in from above, landing with sparks
|
||||
s.t = t + 2; // trap timing: flames ignite once the lights are on
|
||||
s.robots.forEach((rb, i) => {
|
||||
const k = clamp((t - 2.6 - i * 0.35) / 1.6, 0, 1);
|
||||
const was = rb.y;
|
||||
rb.y = 7 * Math.pow(1 - k, 2); rb.vx = rb.vz = 0; rb.lifted = rb.y > 0 ? 1 : 0; // lifted: no tumbling
|
||||
if (was > 0 && rb.y === 0) { burst(rb.x, 0.2, rb.z, Math.round(40 * fxMul), 5, [1, 0.8, 0.4]); puff(rb.x, rb.z, 10); }
|
||||
rb.spin = t > 5.4 ? Math.min(1, (t - 5.4) * 0.8) : 0; // spinners rev up
|
||||
rb.sawOn = t > 5.6;
|
||||
rb.flameOn = t > 5.8 && t < 6.6 || (t > INTRO_END && Math.sin(t * 0.9 + i * 2) > 0.97);
|
||||
rb.turretA = rb.a + Math.sin(t * 0.7 + i) * 0.4;
|
||||
});
|
||||
}
|
||||
|
||||
function burst(x, y, z, n, sp, c) {
|
||||
n = Math.max(1, Math.round(n * fxMul));
|
||||
for (let k = 0; k < n; k++) {
|
||||
const a = Math.random() * Math.PI * 2, v = sp * (0.3 + Math.random());
|
||||
sparks.spawn(x, y, z, Math.cos(a) * v, 1 + Math.random() * sp, Math.sin(a) * v, 0.25 + Math.random() * 0.45, c[0], c[1], c[2]);
|
||||
|
||||
Reference in New Issue
Block a user