Static site
Browse files- index.html +2 -2
- static/city.js +89 -3
- static/game.js +5 -2
- static/main.js +3 -1
- static/nav.js +1 -1
- static/npc.js +16 -2
index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
<meta name="theme-color" content="#10131b">
|
| 9 |
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
<link href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;800;900&family=Inter:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@700&display=swap" rel="stylesheet">
|
| 11 |
-
<link rel="stylesheet" href="/static/style.css?v=
|
| 12 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 64 64%27%3E%3Crect width=%2764%27 height=%2764%27 rx=%2714%27 fill=%27%23050506%27/%3E%3Ccircle cx=%2732%27 cy=%2732%27 r=%2716%27 fill=%27none%27 stroke=%27%23fff%27 stroke-width=%275%27/%3E%3C/svg%3E">
|
| 13 |
<script type="importmap">
|
| 14 |
{ "imports": {
|
|
@@ -215,6 +215,6 @@
|
|
| 215 |
<div id="toast" role="status"></div>
|
| 216 |
<noscript><p style="position:fixed;inset:auto 0 0;padding:16px;background:#111;color:#fff;text-align:center">VOID needs JavaScript for the 3D car.</p></noscript>
|
| 217 |
<script src="/static/hub.js" data-app="void" defer></script>
|
| 218 |
-
<script type="module" src="/static/main.js?v=
|
| 219 |
</body>
|
| 220 |
</html>
|
|
|
|
| 8 |
<meta name="theme-color" content="#10131b">
|
| 9 |
<link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
<link href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;800;900&family=Inter:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@700&display=swap" rel="stylesheet">
|
| 11 |
+
<link rel="stylesheet" href="/static/style.css?v=1793116079">
|
| 12 |
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 64 64%27%3E%3Crect width=%2764%27 height=%2764%27 rx=%2714%27 fill=%27%23050506%27/%3E%3Ccircle cx=%2732%27 cy=%2732%27 r=%2716%27 fill=%27none%27 stroke=%27%23fff%27 stroke-width=%275%27/%3E%3C/svg%3E">
|
| 13 |
<script type="importmap">
|
| 14 |
{ "imports": {
|
|
|
|
| 215 |
<div id="toast" role="status"></div>
|
| 216 |
<noscript><p style="position:fixed;inset:auto 0 0;padding:16px;background:#111;color:#fff;text-align:center">VOID needs JavaScript for the 3D car.</p></noscript>
|
| 217 |
<script src="/static/hub.js" data-app="void" defer></script>
|
| 218 |
+
<script type="module" src="/static/main.js?v=1793116079"></script>
|
| 219 |
</body>
|
| 220 |
</html>
|
static/city.js
CHANGED
|
@@ -556,6 +556,50 @@ export async function buildCity(scene, canvasTex, COARSE) {
|
|
| 556 |
return { height, trail: TRAIL.map(([x, z]) => [x, height(x, z), z]), peak: [sx, sh, sz2] };
|
| 557 |
}
|
| 558 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
// ---- Times Square: big glowing billboards round one intersection ----
|
| 560 |
const TSX = GRID.ax(7), TSZ = GRID.sz(6), billboards = [];
|
| 561 |
ADS.forEach(([t1, t2, fg, bg], k) => {
|
|
@@ -623,8 +667,14 @@ export async function buildCity(scene, canvasTex, COARSE) {
|
|
| 623 |
const at = (x, y, z, ry = 0, s = 1) => m4.compose(v.set(x, y, z), q0.setFromAxisAngle(Y, ry), sc.set(s, s, s));
|
| 624 |
// trees: a trunk and two leafy blobs, each a little different green
|
| 625 |
instT(new THREE.CylinderGeometry(.18, .28, 3, 5).translate(0, 1.5, 0), mat({ color: 0x5a4330, roughness: .9 }), P.trees, ([x, z, s]) => at(x, 0, z, 0, s), null, 520);
|
| 626 |
-
const leafGeo = mergeGeometries([new THREE.IcosahedronGeometry(2.2, 0).translate(0, 4.4, 0), new THREE.IcosahedronGeometry(1.7, 0).translate(.8, 5.8, .3), new THREE.IcosahedronGeometry(1.5, 0).translate(-.9, 5.3, -.4)].map(g => g.toNonIndexed()))
|
| 627 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
// street lamps: a pole, an arm and a warm head
|
| 629 |
// pools of warm light under every lamp (only at night)
|
| 630 |
const poolTex = canvasTex(128, 128, (g, w) => { const r = g.createRadialGradient(64, 64, 0, 64, 64, 64); r.addColorStop(0, "rgba(255,200,130,.55)"); r.addColorStop(.5, "rgba(255,180,110,.18)"); r.addColorStop(1, "rgba(255,170,100,0)"); g.fillStyle = r; g.fillRect(0, 0, w, w); });
|
|
@@ -666,6 +716,28 @@ export async function buildCity(scene, canvasTex, COARSE) {
|
|
| 666 |
instT(stack, mat({ vertexColors: true, roughness: .6, side: THREE.DoubleSide }), P.steam, ([x, z]) => at(x, 0, z), null, 300);
|
| 667 |
P.steam.forEach(([x, z]) => solid(x - .5, x + .5, z - .5, z + .5, 2.4));
|
| 668 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
const steamTex = canvasTex(64, 64, (g, w) => { const r = g.createRadialGradient(32, 32, 0, 32, 32, 32); r.addColorStop(0, "rgba(255,255,255,.55)"); r.addColorStop(1, "rgba(255,255,255,0)"); g.fillStyle = r; g.fillRect(0, 0, w, w); });
|
| 670 |
const NPUFF = COARSE ? 40 : 90, steamMat = new THREE.MeshBasicMaterial({ map: steamTex, transparent: true, depthWrite: false });
|
| 671 |
steamMat.onBeforeCompile = sh => { // each puff fades on its own: its instance colour's red is its opacity
|
|
@@ -741,7 +813,7 @@ export async function buildCity(scene, canvasTex, COARSE) {
|
|
| 741 |
near, nearR, nearFast, helipads, carts: P.carts, lawn, lake, stations, asphaltMat, poolMat, emissive, glassMats, billboards,
|
| 742 |
// ground under a point: rooftops count (so you can land and drive on them), water is -1
|
| 743 |
roofAt(x, z) { let h = 0; for (const b of near(x, z)) if (!b.noRoof && Math.abs(x - b.x) < b.hw && Math.abs(z - b.z) < b.hd && b.h > h) h = b.h; return h; },
|
| 744 |
-
terrainH: terrain.height, mountains: { ...MT, trail: terrain.trail, peak: terrain.peak },
|
| 745 |
isWater(x, z) {
|
| 746 |
if (x > HW0 && x < W1) return !(x > W1 - 80 && Math.abs(((z - ZA + 8) % 140 + 140) % 140 - 8) < 8); // the Hudson, except on the piers
|
| 747 |
if (x > W2 && x < EW1) return Math.abs(z) > 15; // the East River, except on the bridge
|
|
@@ -752,6 +824,20 @@ export async function buildCity(scene, canvasTex, COARSE) {
|
|
| 752 |
if (cam && (++cullN % 10) === 0) { const far = (1 + Math.max(0, cam.y - 20) / 60) * (this.detail || 1); for (const pt of propTiles) pt.mesh.visible = Math.hypot(pt.x - cam.x, pt.z - cam.z) < pt.far * far + 283 * Math.min(1, far); /* Lite pulls the margin in too */ }
|
| 753 |
waveTex.offset.set((t * .004) % 1, (t * .011) % 1);
|
| 754 |
avMat.opacity = Math.sin(t * 3) > 0 ? 1 : .15;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 755 |
if (t - screenT > .05) { screenT = t; drawScreen(screenK, t); screenK = (screenK + 1) % 6; } // one screen redrawn per tick, each at about 3 fps
|
| 756 |
// steam from the stacks near the camera
|
| 757 |
const dt = Math.min(.1, Math.max(0, t - (this._t || t))); this._t = t;
|
|
|
|
| 556 |
return { height, trail: TRAIL.map(([x, z]) => [x, height(x, z), z]), peak: [sx, sh, sz2] };
|
| 557 |
}
|
| 558 |
|
| 559 |
+
// ---- the El: an elevated subway over avenue 9, four stations, a train running up and down ----
|
| 560 |
+
const EL = { x: GRID.ax(9), top: 10.5, z0: ZA - 20, z1: ZB + 20, stations: [GRID.sz(5) + 35, GRID.sz(15) + 35, GRID.sz(25) + 35, GRID.sz(35) + 35] };
|
| 561 |
+
{
|
| 562 |
+
const steel = mat({ color: 0x4a5058, roughness: .55, metalness: .6 }), X = EL.x, L = EL.z1 - EL.z0, zc = (EL.z0 + EL.z1) / 2, parts = [];
|
| 563 |
+
const bx = (w, h, d, x, y, z) => parts.push(new THREE.BoxGeometry(w, h, d).translate(x, y, z).toNonIndexed());
|
| 564 |
+
bx(8, .8, L, X, EL.top - .4, zc); bx(.3, .7, L, X - 3.95, EL.top + .35, zc); bx(.3, .7, L, X + 3.95, EL.top + .35, zc);
|
| 565 |
+
bx(.2, .15, L, X - .75, EL.top + .07, zc); bx(.2, .15, L, X + .75, EL.top + .07, zc);
|
| 566 |
+
const onStreet = z => { for (let j = 0; j < NZ; j++) if (Math.abs(z - GRID.sz(j)) < GRID.stW(j) / 2 + 3) return true; return false; };
|
| 567 |
+
for (let z = EL.z0 + 10; z < EL.z1; z += 32) { if (onStreet(z)) continue; bx(1, EL.top - .8, 1, X, (EL.top - .8) / 2, z); bx(7, .6, .8, X, EL.top - 1.1, z); solid(X - .6, X + .6, z - .6, z + .6, EL.top - .8, { noRoof: true }); }
|
| 568 |
+
for (const z of EL.stations) for (const sgn of [-1, 1]) { bx(4, .5, 64, X + sgn * 6, EL.top - .25, z); bx(4, .15, 64, X + sgn * 6, EL.top + 3.6, z); for (let k = -30; k <= 30; k += 10) bx(.2, 3.6, .2, X + sgn * 7.8, EL.top + 1.8, z + k); solid(X + sgn * 6 - 2, X + sgn * 6 + 2, z - 32, z + 32, EL.top, { y0: EL.top - 1 }); }
|
| 569 |
+
solid(X - 4, X + 4, EL.z0, EL.z1, EL.top, { y0: EL.top - 1 }); // drive along the top if you land on it
|
| 570 |
+
scene.add(new THREE.Mesh(mergeGeometries(parts), steel));
|
| 571 |
+
// the train: four silver cars with a window band and a red stripe
|
| 572 |
+
const carTex = canvasTex(256, 64, (g, w, h) => { g.fillStyle = "#b8bcc4"; g.fillRect(0, 0, w, h); g.fillStyle = "#c1121f"; g.fillRect(0, 44, w, 5); for (let x = 6; x < w; x += 30) { g.fillStyle = "#1b2633"; g.fillRect(x, 12, 22, 24); g.fillStyle = "rgba(255,240,200,.25)"; g.fillRect(x, 12, 22, 5); } g.fillStyle = "#2a2d33"; g.fillRect(0, h - 6, w, 6); });
|
| 573 |
+
const train = new THREE.Group(), carM = new THREE.MeshStandardMaterial({ map: carTex, roughness: .35, metalness: .7 }), headM = new THREE.MeshBasicMaterial({ color: new THREE.Color(1, .95, .8).multiplyScalar(2), toneMapped: false });
|
| 574 |
+
for (let k = 0; k < 4; k++) { const c = new THREE.Mesh(new THREE.BoxGeometry(3, 3.4, 15.6), carM); c.position.set(0, 1.9, (k - 1.5) * 16.4); c.castShadow = true; train.add(c); }
|
| 575 |
+
for (const z of [-32.6, 32.6]) for (const x of [-.9, .9]) { const l = new THREE.Mesh(new THREE.BoxGeometry(.4, .3, .1), headM); l.position.set(x, 1.2, z); train.add(l); }
|
| 576 |
+
train.position.set(X, EL.top, EL.stations[0]); scene.add(train);
|
| 577 |
+
EL.train = { g: train, z: EL.stations[0], v: 0, dir: 1, wait: 6, len: 66 };
|
| 578 |
+
}
|
| 579 |
+
// ---- the Ferris wheel and a boardwalk on the East River esplanade ----
|
| 580 |
+
const FW = { x: (XB + 9 + W2) / 2, z: 1320, y: 31, R: 26, a: 0 };
|
| 581 |
+
{
|
| 582 |
+
const white = mat({ color: 0xe8e8ea, roughness: .4, metalness: .5 }), wood = mat({ color: 0x8a6a48, roughness: .85 });
|
| 583 |
+
const wheel = new THREE.Group(); wheel.position.set(FW.x, FW.y, FW.z); scene.add(wheel); FW.g = wheel;
|
| 584 |
+
for (const x of [-1.4, 1.4]) { const rim = new THREE.Mesh(new THREE.TorusGeometry(FW.R, .3, 8, 72), white); rim.rotation.y = Math.PI / 2; rim.position.x = x; wheel.add(rim); const inner = new THREE.Mesh(new THREE.TorusGeometry(FW.R * .55, .2, 6, 48), white); inner.rotation.y = Math.PI / 2; inner.position.x = x; wheel.add(inner); }
|
| 585 |
+
for (let k = 0; k < 18; k++) { const a = k / 18 * Math.PI * 2; for (const x of [-1.4, 1.4]) { const sp = new THREE.Mesh(new THREE.CylinderGeometry(.09, .09, FW.R, 5), white); sp.position.set(x, Math.cos(a) * FW.R / 2, Math.sin(a) * FW.R / 2); sp.rotation.x = a; wheel.add(sp); } }
|
| 586 |
+
const hub = new THREE.Mesh(new THREE.CylinderGeometry(1.2, 1.2, 3.6, 16).rotateZ(Math.PI / 2), white); wheel.add(hub);
|
| 587 |
+
const bulb = new THREE.MeshBasicMaterial({ color: new THREE.Color(1, .75, .4).multiplyScalar(2.4), toneMapped: false }); emissive.push(bulb);
|
| 588 |
+
const bulbs = new THREE.InstancedMesh(new THREE.SphereGeometry(.28, 6, 4), bulb, 144), bm = new THREE.Matrix4();
|
| 589 |
+
for (let k = 0; k < 72; k++) for (const [j, x] of [[0, -1.4], [1, 1.4]]) { const a = k / 72 * Math.PI * 2; bulbs.setMatrixAt(k * 2 + j, bm.makeTranslation(x, Math.cos(a) * FW.R, Math.sin(a) * FW.R)); }
|
| 590 |
+
wheel.add(bulbs);
|
| 591 |
+
for (const sx of [-1, 1]) for (const sz of [-1, 1]) { const len = Math.hypot(FW.y, 14), leg = new THREE.Mesh(new THREE.CylinderGeometry(.35, .5, len, 8), white); leg.position.set(FW.x + sx * 3.2, FW.y / 2, FW.z + sz * 7); leg.rotation.x = -sz * Math.atan2(14, FW.y) * .5; scene.add(leg); solid(FW.x + sx * 3.2 - .8, FW.x + sx * 3.2 + .8, FW.z + sz * 10 - .8, FW.z + sz * 10 + .8, 6, { noRoof: true }); }
|
| 592 |
+
const gondM = new THREE.MeshStandardMaterial({ vertexColors: false, roughness: .4 }); FW.gond = new THREE.InstancedMesh(new THREE.BoxGeometry(2.2, 2.2, 2.6).translate(0, -1.6, 0), gondM, 18);
|
| 593 |
+
for (let k = 0; k < 18; k++) FW.gond.setColorAt(k, new THREE.Color().setHSL(k / 18, .75, .55)); scene.add(FW.gond);
|
| 594 |
+
// the boardwalk: planks, a few stalls with striped awnings
|
| 595 |
+
const deck = new THREE.Mesh(new THREE.BoxGeometry(46, .2, 230), wood); deck.position.set(FW.x, .12, FW.z); deck.receiveShadow = true; scene.add(deck);
|
| 596 |
+
const stallT = canvasTex(64, 16, (g, w, h) => { for (let x = 0; x < w; x += 8) { g.fillStyle = (x / 8) % 2 ? "#ffffff" : "#d21f2b"; g.fillRect(x, 0, 8, h); } });
|
| 597 |
+
for (const [dz, c] of [[-70, 0xf7c414], [-50, 0x2e5aa8], [55, 0x2f6b3a], [75, 0xd21f2b]]) {
|
| 598 |
+
const st = new THREE.Mesh(new THREE.BoxGeometry(4, 2.4, 3), mat({ color: c, roughness: .6 })); st.position.set(FW.x - 12, 1.3, FW.z + dz); scene.add(st);
|
| 599 |
+
const aw = new THREE.Mesh(new THREE.BoxGeometry(4.6, .15, 3.8), new THREE.MeshStandardMaterial({ map: stallT })); aw.position.set(FW.x - 12, 2.8, FW.z + dz); scene.add(aw); solid(FW.x - 14, FW.x - 10, FW.z + dz - 1.5, FW.z + dz + 1.5, 2.6);
|
| 600 |
+
}
|
| 601 |
+
}
|
| 602 |
+
|
| 603 |
// ---- Times Square: big glowing billboards round one intersection ----
|
| 604 |
const TSX = GRID.ax(7), TSZ = GRID.sz(6), billboards = [];
|
| 605 |
ADS.forEach(([t1, t2, fg, bg], k) => {
|
|
|
|
| 667 |
const at = (x, y, z, ry = 0, s = 1) => m4.compose(v.set(x, y, z), q0.setFromAxisAngle(Y, ry), sc.set(s, s, s));
|
| 668 |
// trees: a trunk and two leafy blobs, each a little different green
|
| 669 |
instT(new THREE.CylinderGeometry(.18, .28, 3, 5).translate(0, 1.5, 0), mat({ color: 0x5a4330, roughness: .9 }), P.trees, ([x, z, s]) => at(x, 0, z, 0, s), null, 520);
|
| 670 |
+
const leafGeo = COARSE ? mergeGeometries([new THREE.IcosahedronGeometry(2.2, 0).translate(0, 4.4, 0), new THREE.IcosahedronGeometry(1.7, 0).translate(.8, 5.8, .3), new THREE.IcosahedronGeometry(1.5, 0).translate(-.9, 5.3, -.4)].map(g => g.toNonIndexed()))
|
| 671 |
+
: mergeGeometries([[2.2, 0, 4.4, 0], [1.8, .9, 5.9, .3], [1.6, -1, 5.4, -.5], [1.45, .2, 6.7, -.6], [1.35, -.3, 4.8, 1.2]].map(([rad, x, y, z]) => {
|
| 672 |
+
const g = new THREE.IcosahedronGeometry(rad, 1).toNonIndexed(), p = g.attributes.position, col = new Float32Array(p.count * 3);
|
| 673 |
+
for (let i = 0; i < p.count; i++) { const j = 1 + Math.sin(p.getX(i) * 7.1 + p.getY(i) * 3.3 + p.getZ(i) * 5.7) * .14; p.setXYZ(i, p.getX(i) * j, p.getY(i) * j, p.getZ(i) * j); }
|
| 674 |
+
g.translate(x, y, z); for (let i = 0; i < p.count; i++) { const v = .6 + .48 * Math.max(0, Math.min(1, (p.getY(i) - (y - rad)) / (2 * rad))); col[i * 3] = v; col[i * 3 + 1] = v; col[i * 3 + 2] = v; }
|
| 675 |
+
g.setAttribute("color", new THREE.BufferAttribute(col, 3)); g.computeVertexNormals(); return g;
|
| 676 |
+
}));
|
| 677 |
+
instT(leafGeo, mat({ roughness: .85, flatShading: true, vertexColors: !COARSE }), P.trees, ([x, z, s], i) => at(x, 0, z, i, s), () => new THREE.Color().setHSL(.26 + rnd() * .08, .45 + rnd() * .2, .26 + rnd() * .12), 520);
|
| 678 |
// street lamps: a pole, an arm and a warm head
|
| 679 |
// pools of warm light under every lamp (only at night)
|
| 680 |
const poolTex = canvasTex(128, 128, (g, w) => { const r = g.createRadialGradient(64, 64, 0, 64, 64, 64); r.addColorStop(0, "rgba(255,200,130,.55)"); r.addColorStop(.5, "rgba(255,180,110,.18)"); r.addColorStop(1, "rgba(255,170,100,0)"); g.fillStyle = r; g.fillRect(0, 0, w, w); });
|
|
|
|
| 716 |
instT(stack, mat({ vertexColors: true, roughness: .6, side: THREE.DoubleSide }), P.steam, ([x, z]) => at(x, 0, z), null, 300);
|
| 717 |
P.steam.forEach(([x, z]) => solid(x - .5, x + .5, z - .5, z + .5, 2.4));
|
| 718 |
}
|
| 719 |
+
const bladeTex = canvasTex(64, 64, (g, w, h) => { g.clearRect(0, 0, w, h); for (let k = 0; k < 26; k++) { const x = 4 + rnd() * 56, lean = (rnd() - .5) * 18, ht = 30 + rnd() * 30; g.strokeStyle = `rgb(${60 + rnd() * 40 | 0},${110 + rnd() * 60 | 0},${40 + rnd() * 30 | 0})`; g.lineWidth = 2 + rnd() * 2; g.beginPath(); g.moveTo(x, h); g.quadraticCurveTo(x + lean * .3, h - ht * .6, x + lean, h - ht); g.stroke(); } });
|
| 720 |
+
const tuftGeo = mergeGeometries([new THREE.PlaneGeometry(1.1, .6).translate(0, .3, 0), new THREE.PlaneGeometry(1.1, .6).translate(0, .3, 0).rotateY(Math.PI / 2)]);
|
| 721 |
+
const NTUFT = COARSE ? 0 : 3200, tufts = new THREE.InstancedMesh(tuftGeo, new THREE.MeshStandardMaterial({ map: bladeTex, alphaTest: .45, side: THREE.DoubleSide, roughness: .9 }), Math.max(1, NTUFT));
|
| 722 |
+
tufts.frustumCulled = false; tufts.count = 0; tufts.setColorAt(0, new THREE.Color(1, 1, 1)); scene.add(tufts);
|
| 723 |
+
let tuftAt = null;
|
| 724 |
+
const grassy = (x, z) => {
|
| 725 |
+
if (inPark(x, z)) return Math.hypot((x - lake.x) / (lake.rx + 6), (z - lake.z) / (lake.rz + 6)) > 1 ? .08 : -1;
|
| 726 |
+
if (x > MT.x0 && x < MT.x1 && z > MT.z0 && z < MT.z1 && terrain) { const h = terrain.height(x, z); return h > .3 && h < 165 ? h : -1; }
|
| 727 |
+
if (x < HW0 - 30 && !(x > -2660 && x < -1860 && Math.abs(z) < 34)) return 0; // New Jersey, off the runway
|
| 728 |
+
if (x > XA - 5 && x < XB + 5 && (z > ZB + 30 || z < ZA - 30)) return 0; // north and south of the city
|
| 729 |
+
return -1;
|
| 730 |
+
};
|
| 731 |
+
function placeTufts(cam) {
|
| 732 |
+
let k = 0; const S = 1.5, R = 42, gx0 = Math.floor((cam.x - R) / S), gz0 = Math.floor((cam.z - R) / S);
|
| 733 |
+
for (let gx = gx0; gx < gx0 + R * 2 / S && k < NTUFT; gx++) for (let gz = gz0; gz < gz0 + R * 2 / S && k < NTUFT; gz++) {
|
| 734 |
+
const hsh = Math.sin(gx * 127.1 + gz * 311.7) * 43758.5453, f = hsh - Math.floor(hsh), x = (gx + f) * S, z = (gz + (f * 7.3 % 1)) * S;
|
| 735 |
+
if ((x - cam.x) ** 2 + (z - cam.z) ** 2 > R * R || f < .25) continue;
|
| 736 |
+
const y = grassy(x, z); if (y < 0) continue;
|
| 737 |
+
m4.compose(v.set(x, y, z), q0.setFromAxisAngle(Y, f * 6.28), sc.set(.7 + f * .7, .7 + f * .8, .7 + f * .7)); tufts.setMatrixAt(k, m4); tufts.setColorAt(k++, new THREE.Color().setHSL(.24 + f * .06, .55, .32 + f * .14));
|
| 738 |
+
}
|
| 739 |
+
tufts.count = k; tufts.instanceMatrix.needsUpdate = true; if (tufts.instanceColor) tufts.instanceColor.needsUpdate = true;
|
| 740 |
+
}
|
| 741 |
const steamTex = canvasTex(64, 64, (g, w) => { const r = g.createRadialGradient(32, 32, 0, 32, 32, 32); r.addColorStop(0, "rgba(255,255,255,.55)"); r.addColorStop(1, "rgba(255,255,255,0)"); g.fillStyle = r; g.fillRect(0, 0, w, w); });
|
| 742 |
const NPUFF = COARSE ? 40 : 90, steamMat = new THREE.MeshBasicMaterial({ map: steamTex, transparent: true, depthWrite: false });
|
| 743 |
steamMat.onBeforeCompile = sh => { // each puff fades on its own: its instance colour's red is its opacity
|
|
|
|
| 813 |
near, nearR, nearFast, helipads, carts: P.carts, lawn, lake, stations, asphaltMat, poolMat, emissive, glassMats, billboards,
|
| 814 |
// ground under a point: rooftops count (so you can land and drive on them), water is -1
|
| 815 |
roofAt(x, z) { let h = 0; for (const b of near(x, z)) if (!b.noRoof && Math.abs(x - b.x) < b.hw && Math.abs(z - b.z) < b.hd && b.h > h) h = b.h; return h; },
|
| 816 |
+
terrainH: terrain.height, mountains: { ...MT, trail: terrain.trail, peak: terrain.peak }, el: EL, wheel: FW,
|
| 817 |
isWater(x, z) {
|
| 818 |
if (x > HW0 && x < W1) return !(x > W1 - 80 && Math.abs(((z - ZA + 8) % 140 + 140) % 140 - 8) < 8); // the Hudson, except on the piers
|
| 819 |
if (x > W2 && x < EW1) return Math.abs(z) > 15; // the East River, except on the bridge
|
|
|
|
| 824 |
if (cam && (++cullN % 10) === 0) { const far = (1 + Math.max(0, cam.y - 20) / 60) * (this.detail || 1); for (const pt of propTiles) pt.mesh.visible = Math.hypot(pt.x - cam.x, pt.z - cam.z) < pt.far * far + 283 * Math.min(1, far); /* Lite pulls the margin in too */ }
|
| 825 |
waveTex.offset.set((t * .004) % 1, (t * .011) % 1);
|
| 826 |
avMat.opacity = Math.sin(t * 3) > 0 ? 1 : .15;
|
| 827 |
+
// grass round the camera (High and Ultra), re-scattered every few metres
|
| 828 |
+
const grassOn = NTUFT > 0 && (this.detail || 1) >= 1 && cam && cam.y < 60; tufts.visible = grassOn;
|
| 829 |
+
if (grassOn && (!tuftAt || Math.hypot(cam.x - tuftAt.x, cam.z - tuftAt.z) > 7)) { tuftAt = { x: cam.x, z: cam.z }; placeTufts(cam); }
|
| 830 |
+
// the El train: up and down the line, stopping at every station
|
| 831 |
+
{ const dtt = Math.min(.1, Math.max(0, t - (this._tt || t))); this._tt = t; const T = EL.train;
|
| 832 |
+
if (T.wait > 0) { T.wait -= dtt; T.v = 0; } else {
|
| 833 |
+
const next = EL.stations.filter(z => (z - T.z) * T.dir > 1).sort((a, b) => (a - b) * T.dir)[0], end = T.dir > 0 ? EL.z1 - 40 : EL.z0 + 40, stopAt = next ?? end, dist = Math.abs(stopAt - T.z);
|
| 834 |
+
T.v = Math.min(T.v + 2.2 * dtt, 20, Math.sqrt(2 * 1.8 * dist) + .3); T.z += T.v * T.dir * dtt;
|
| 835 |
+
if (dist < .6) { T.z = stopAt; T.wait = next != null ? 7 : 4; if (next == null) T.dir *= -1; }
|
| 836 |
+
}
|
| 837 |
+
T.g.position.z = T.z; }
|
| 838 |
+
// the Ferris wheel turns; its gondolas hang level
|
| 839 |
+
FW.a += .045 * Math.min(.1, Math.max(0, t - (this._tf || t))); this._tf = t; FW.g.rotation.x = FW.a;
|
| 840 |
+
for (let k = 0; k < 18; k++) { const a = k / 18 * Math.PI * 2 + FW.a; m4.makeTranslation(FW.x, FW.y + Math.cos(a) * FW.R, FW.z + Math.sin(a) * FW.R); FW.gond.setMatrixAt(k, m4); } FW.gond.instanceMatrix.needsUpdate = true;
|
| 841 |
if (t - screenT > .05) { screenT = t; drawScreen(screenK, t); screenK = (screenK + 1) % 6; } // one screen redrawn per tick, each at about 3 fps
|
| 842 |
// steam from the stacks near the camera
|
| 843 |
const dt = Math.min(.1, Math.max(0, t - (this._t || t))); this._t = t;
|
static/game.js
CHANGED
|
@@ -83,7 +83,10 @@ export function createGame(W, car, sound, life, opts = {}) {
|
|
| 83 |
const RAMPS = [{ x: RAMP_X, z: LZ, yaw: 0, len: 14, h: 4.5, w: HW, main: true }];
|
| 84 |
const W2 = 1040;
|
| 85 |
for (const r of [{ x: W2 + 60, z: -6, yaw: 0, len: 22, h: 7 }, { x: W2 + 60, z: 6, yaw: 0, len: 22, h: 7 }, { x: -1040, z: 0, yaw: Math.PI, len: 16, h: 5 }, { x: -1040, z: 280, yaw: Math.PI, len: 16, h: 5 },
|
| 86 |
-
{ x: city.lawn.x - 40, z: city.lawn.z, yaw: 0, len: 18, h: 5.5 }, { x: 1000, z: -300, yaw: -Math.PI / 2, len: 18, h: 6 }, { x: -1000, z: -500, yaw: Math.PI / 2, len: 18, h: 6 }
|
|
|
|
|
|
|
|
|
|
| 87 |
{
|
| 88 |
const rampMat = new THREE.MeshStandardMaterial({ color: 0x1b1c22, metalness: .6, roughness: .35 }), stripe = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.6), toneMapped: false });
|
| 89 |
for (const r of RAMPS) {
|
|
@@ -270,7 +273,7 @@ export function createGame(W, car, sound, life, opts = {}) {
|
|
| 270 |
// buildings: an axis-aligned box test against the city's spatial hash; returns the push-out normal
|
| 271 |
function hitBox(x, z, y, r) {
|
| 272 |
for (const b of city.nearFast(x, z, r + 2)) {
|
| 273 |
-
if (y >= b.h - .4) continue;
|
| 274 |
const dx = x - b.x, dz = z - b.z, ox = b.hw + r - Math.abs(dx), oz = b.hd + r - Math.abs(dz);
|
| 275 |
if (ox > 0 && oz > 0) return ox < oz ? { nx: Math.sign(dx), nz: 0, d: ox, b } : { nx: 0, nz: Math.sign(dz), d: oz, b };
|
| 276 |
}
|
|
|
|
| 83 |
const RAMPS = [{ x: RAMP_X, z: LZ, yaw: 0, len: 14, h: 4.5, w: HW, main: true }];
|
| 84 |
const W2 = 1040;
|
| 85 |
for (const r of [{ x: W2 + 60, z: -6, yaw: 0, len: 22, h: 7 }, { x: W2 + 60, z: 6, yaw: 0, len: 22, h: 7 }, { x: -1040, z: 0, yaw: Math.PI, len: 16, h: 5 }, { x: -1040, z: 280, yaw: Math.PI, len: 16, h: 5 },
|
| 86 |
+
{ x: city.lawn.x - 40, z: city.lawn.z, yaw: 0, len: 18, h: 5.5 }, { x: 1000, z: -300, yaw: -Math.PI / 2, len: 18, h: 6 }, { x: -1000, z: -500, yaw: Math.PI / 2, len: 18, h: 6 },
|
| 87 |
+
// the stunt park (south-west square)
|
| 88 |
+
{ x: -900, z: 1345, yaw: 0, len: 10, h: 2.2 }, { x: -860, z: 1365, yaw: 0, len: 8, h: 1.6 }, { x: -760, z: 1350, yaw: Math.PI, len: 10, h: 2.4 }, { x: -880, z: 1420, yaw: 0, len: 22, h: 7.5, w: 5 },
|
| 89 |
+
{ x: -680, z: 1440, yaw: Math.PI, len: 22, h: 7.5, w: 5 }, { x: -620, z: 1350, yaw: Math.PI / 2, len: 12, h: 3 }, { x: -560, z: 1460, yaw: -Math.PI / 2, len: 12, h: 3 }, { x: -800, z: 1395, yaw: Math.PI / 4, len: 9, h: 1.8 }]) RAMPS.push({ w: 4, ...r });
|
| 90 |
{
|
| 91 |
const rampMat = new THREE.MeshStandardMaterial({ color: 0x1b1c22, metalness: .6, roughness: .35 }), stripe = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.6), toneMapped: false });
|
| 92 |
for (const r of RAMPS) {
|
|
|
|
| 273 |
// buildings: an axis-aligned box test against the city's spatial hash; returns the push-out normal
|
| 274 |
function hitBox(x, z, y, r) {
|
| 275 |
for (const b of city.nearFast(x, z, r + 2)) {
|
| 276 |
+
if (y >= b.h - .4 || (b.y0 != null && y + 1.6 < b.y0)) continue;
|
| 277 |
const dx = x - b.x, dz = z - b.z, ox = b.hw + r - Math.abs(dx), oz = b.hd + r - Math.abs(dz);
|
| 278 |
if (ox > 0 && oz > 0) return ox < oz ? { nx: Math.sign(dx), nz: 0, d: ox, b } : { nx: 0, nz: Math.sign(dz), d: oz, b };
|
| 279 |
}
|
static/main.js
CHANGED
|
@@ -561,7 +561,9 @@ function frameLoop(fixed) {
|
|
| 561 |
extras.sky(dt, time);
|
| 562 |
// the living city: when switched on, the day turns and the weather changes on its own
|
| 563 |
if (SET.cycle === "on" && mode === "play" && (cycleT += dt) > 150) { cycleT = 0; cycleTime(); if (Math.random() < .5) { const w = ["clear", "clear", "rain", "fog", "storm", "snow"][Math.floor(Math.random() * 6)]; atmos.setWeather(w); SET.weather = w; } }
|
| 564 |
-
life.raining = atmos.weather === "rain" || atmos.weather === "storm";
|
|
|
|
|
|
|
| 565 |
if (mode === "play") { contracts.update(dt, time); dealer.update(dt, time); tutUpdate(); if ((dailyT += dt) > 1) { dailyT = 0; dailyCheck(); } extras.update(dt, time); goals.stats.coins = extras.coins().got; goals.update(dt, game.state, S.speed); if (time - lastChips > 2) { lastChips = time; chips(); } }
|
| 566 |
if (mode === "play" && time - lastGauge > .05) { lastGauge = time; drawGauge(S); const fu = document.getElementById("gFuel"); if (fu && S.fuel != null) { fu.style.setProperty("--v", S.fuel); fu.classList.toggle("low", S.fuel < .2); } }
|
| 567 |
if (heroDriven) { car.group.position.copy(S.pos); car.group.quaternion.copy(S.quat); } else if (gsx && gsx.heroPark) { car.group.position.set(gsx.heroPark.x, 0, gsx.heroPark.z); car.group.quaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), -gsx.heroPark.yaw); }
|
|
|
|
| 561 |
extras.sky(dt, time);
|
| 562 |
// the living city: when switched on, the day turns and the weather changes on its own
|
| 563 |
if (SET.cycle === "on" && mode === "play" && (cycleT += dt) > 150) { cycleT = 0; cycleTime(); if (Math.random() < .5) { const w = ["clear", "clear", "rain", "fog", "storm", "snow"][Math.floor(Math.random() * 6)]; atmos.setWeather(w); SET.weather = w; } }
|
| 564 |
+
life.raining = atmos.weather === "rain" || atmos.weather === "storm"; life.night = W.timeOfDay !== "day";
|
| 565 |
+
// the El train is solid: you get shoved off the track (and hurt if you hit it hard)
|
| 566 |
+
if (mode === "play" && W.city.el && game.state) { const T = W.city.el.train, s = game.state; if (Math.abs(s.x - W.city.el.x) < 2.6 && s.y > W.city.el.top - .5 && s.y < W.city.el.top + 4 && Math.abs(s.z - T.z) < T.len / 2 + 1) { s.x = W.city.el.x + (s.x >= W.city.el.x ? 3 : -3); const sp = Math.hypot(s.vel.x, s.vel.z); if (sp > 8 || T.v > 5) { game.api.hurt(8 + T.v, "Hit by the train"); sound.crash(); } } }
|
| 567 |
if (mode === "play") { contracts.update(dt, time); dealer.update(dt, time); tutUpdate(); if ((dailyT += dt) > 1) { dailyT = 0; dailyCheck(); } extras.update(dt, time); goals.stats.coins = extras.coins().got; goals.update(dt, game.state, S.speed); if (time - lastChips > 2) { lastChips = time; chips(); } }
|
| 568 |
if (mode === "play" && time - lastGauge > .05) { lastGauge = time; drawGauge(S); const fu = document.getElementById("gFuel"); if (fu && S.fuel != null) { fu.style.setProperty("--v", S.fuel); fu.classList.toggle("low", S.fuel < .2); } }
|
| 569 |
if (heroDriven) { car.group.position.copy(S.pos); car.group.quaternion.copy(S.quat); } else if (gsx && gsx.heroPark) { car.group.position.set(gsx.heroPark.x, 0, gsx.heroPark.z); car.group.quaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), -gsx.heroPark.yaw); }
|
static/nav.js
CHANGED
|
@@ -32,7 +32,7 @@ export function createNav(scene, api, W, ZONES, starts) {
|
|
| 32 |
}
|
| 33 |
// places
|
| 34 |
const PLACES = [
|
| 35 |
-
{ name: "Times Square", x: ax(7), z: sz(6) }, { name: "Central Park lawn", x: W.city.lawn.x, z: W.city.lawn.z, off: true }, { name: "Brooklyn (over the bridge)", x: 1690, z: 0 }, { name: "⛰️ Mountains (trail start)", x: 2640, z: 0, off: true }, { name: "🏔️ The summit", x: 3900, z: -380, off: true },
|
| 36 |
{ name: "Hudson piers", x: -1010, z: sz(5) }, { name: "Downtown", x: ax(11), z: sz(17) }, { name: "The loop and ramp", x: -100, z: 0 },
|
| 37 |
...ZONES.filter(z => z.safe && z.y).map(z => ({ name: `Helipad ${z.id} (${Math.round(z.y)} m up)`, x: z.x, z: z.z, y: z.y, air: true })),
|
| 38 |
...starts.map(s => ({ name: `Race: ${s.r.name}`, x: s.x, z: s.z, air: !!s.r.air && false })),
|
|
|
|
| 32 |
}
|
| 33 |
// places
|
| 34 |
const PLACES = [
|
| 35 |
+
{ name: "Times Square", x: ax(7), z: sz(6) }, { name: "Central Park lawn", x: W.city.lawn.x, z: W.city.lawn.z, off: true }, { name: "Brooklyn (over the bridge)", x: 1690, z: 0 }, { name: "⛰️ Mountains (trail start)", x: 2640, z: 0, off: true }, { name: "🏔️ The summit", x: 3900, z: -380, off: true }, { name: "🎡 Ferris wheel & boardwalk", x: 994, z: 1250, off: true }, { name: "🛹 Stunt park", x: -760, z: 1400, off: true },
|
| 36 |
{ name: "Hudson piers", x: -1010, z: sz(5) }, { name: "Downtown", x: ax(11), z: sz(17) }, { name: "The loop and ramp", x: -100, z: 0 },
|
| 37 |
...ZONES.filter(z => z.safe && z.y).map(z => ({ name: `Helipad ${z.id} (${Math.round(z.y)} m up)`, x: z.x, z: z.z, y: z.y, air: true })),
|
| 38 |
...starts.map(s => ({ name: `Race: ${s.r.name}`, x: s.x, z: s.z, air: !!s.r.air && false })),
|
static/npc.js
CHANGED
|
@@ -251,6 +251,13 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 251 |
const jetGeo = mergeGeometries([new THREE.CircleGeometry(.42, 14).rotateX(Math.PI / 2).translate(1.3, .12, 0), new THREE.CircleGeometry(.42, 14).rotateX(Math.PI / 2).translate(-1.3, .12, 0)]);
|
| 252 |
const jets = new THREE.InstancedMesh(jetGeo, new THREE.MeshBasicMaterial({ color: new THREE.Color(.4, 1.8, 2.4), toneMapped: false, transparent: true, opacity: .9, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide }), 900);
|
| 253 |
jets.frustumCulled = false; scene.add(jets); let jk = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
function place(c) { // drop a car somewhere on a random open segment
|
| 255 |
for (let tries = 0; tries < 40; tries++) {
|
| 256 |
const axis = rnd() < .5 ? 0 : 1, road = Math.floor(rnd() * (axis === 0 ? NZ : NX)), k = Math.floor(rnd() * ((axis === 0 ? NX : NZ) - 1));
|
|
@@ -407,7 +414,7 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 407 |
set onHit(f) { api.onHit = f; }, set onCrash(f) { api.onCrash = f; },
|
| 408 |
// the flying VOID cars: the real car's shape, or (Lite) the simple low-poly body traffic uses
|
| 409 |
setVoidGeo(geo) { const M = meshes[KINDS.findIndex(k => k.id === "voidcar")]; if (!M) return; M.simple = M.simple || { body: M.body.geometry, lights: M.lights.geometry }; geo.setAttribute("aRust", M.simple.body.attributes.aRust); M.full = geo; },
|
| 410 |
-
setVoidDetail(full) { const M = meshes[KINDS.findIndex(k => k.id === "voidcar")]; if (!M || !M.full) return; M.body.geometry = full ? M.full : M.simple.body; M.lights.geometry = full ? jetGeo : M.simple.lights; }, set collide(f) { api.collide = f; }, set raining(v) { api.raining = v; },
|
| 411 |
take(c) { c.taken = true; c.parked = false; c.turn = null; },
|
| 412 |
park(c, x, z, yaw) { Object.assign(c, { taken: false, parked: true, x, z, yaw, v: 0, y: 0, wreck: null, turn: null, crush: 0 }); },
|
| 413 |
geoOf(k) { const m = meshes[KINDS.indexOf(k)]; return m ? { body: m.body.geometry, lights: m.lights.geometry } : null; },
|
|
@@ -489,7 +496,11 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 489 |
if (ddx * ddx + ddz * ddz < RC2) {
|
| 490 |
e.set(c.rx, -c.yaw, c.rz + (c.turn ? (c.fly ? .25 : .05) : 0), "YXZ"); q.setFromEuler(e); const md = c.model; m4.compose(pos.set(c.x, c.y, c.z), q, squash.set(md.sl, (c.crush || 1 - (c.dent || 0) * .07) * md.sh, md.sw));
|
| 491 |
const M = meshes[c.ti], k = M.k++; M.body.setMatrixAt(k, m4); M.body.setColorAt(k, c.col); M.body.rust[k] = c.rust;
|
| 492 |
-
if (c.fly && !c.wreck && c.kind.id !== "hover" && jk < 900) jets.setMatrixAt(jk++, m4);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
}
|
| 494 |
// collisions among the cars near the camera: a hard hit wrecks both, mass and momentum decide where they go
|
| 495 |
crashT += dt;
|
|
@@ -517,6 +528,7 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 517 |
if ((reckT -= .05) < 0 && player) { reckT = 9 + rnd() * 10; for (let t = 0; t < 40; t++) { const c = cars[Math.floor(rnd() * cars.length)], d = Math.hypot(c.x - player.x, c.z - player.z); if (!c.fly && !c.wreck && !c.taken && !c.parked && d > 70 && d < 260 && !(MASS[c.kind.id] > 1.5)) { c.reck = 20 + rnd() * 15; break; } } }
|
| 518 |
}
|
| 519 |
jets.count = jk; jets.visible = jk > 0; jets.instanceMatrix.needsUpdate = true; jk = 0;
|
|
|
|
| 520 |
for (const m of meshes) { m.body.count = m.lights.count = m.k; m.body.visible = m.lights.visible = m.k > 0; m.body.instanceMatrix.needsUpdate = m.lights.instanceMatrix.needsUpdate = true; if (m.body.instanceColor) m.body.instanceColor.needsUpdate = true; m.body.geometry.attributes.aRust.needsUpdate = true; }
|
| 521 |
// debris (skipped once every piece has landed and been hidden)
|
| 522 |
if (debLive) { debLive = 0; for (let k = 0; k < DEB; k++) {
|
|
@@ -571,6 +583,7 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 571 |
if (p.jog && !(p.down > 0)) y += Math.abs(Math.sin(walk)) * .06;
|
| 572 |
e.set(rx + (p.jog && !(p.down > 0) ? 0 : 0), yaw + (p.fall ? p.fall.rot : 0), rz - (p.jog && !(p.down > 0) ? .12 : 0), "YXZ"); q.setFromEuler(e); m4.compose(pos.set(x, y, z), q, pscale.set(p.wd, p.h, p.wd));
|
| 573 |
bodies.setMatrixAt(pk, m4); heads.setMatrixAt(pk, m4); hair.setMatrixAt(pk, m4);
|
|
|
|
| 574 |
const amp = p.jog ? .85 : .5, swing = p.down > 0 ? (p.fall.air ? Math.sin(time * 19 + n) * .9 : .15) : p.wait > 0 ? 0 : Math.sin(walk) * amp;
|
| 575 |
LEGS[0][0] = legL; LEGS[1][0] = legR; for (const [leg, sgn, off] of LEGS) { legQ.setFromAxisAngle(Z, swing * sgn); legM.compose(pos.set(0, .88, off), legQ, one); leg.setMatrixAt(pk, legT.copy(m4).multiply(legM)); }
|
| 576 |
// arms swing against the legs; a phone or an umbrella keeps the right one up
|
|
@@ -591,6 +604,7 @@ export function createLife(scene, roads, walkways, COARSE) {
|
|
| 591 |
pk++;
|
| 592 |
}
|
| 593 |
}
|
|
|
|
| 594 |
for (const m of [bodies, heads, legL, legR, hair, armL, armR]) { m.count = pk; m.instanceMatrix.needsUpdate = true; if (m.instanceColor) m.instanceColor.needsUpdate = true; }
|
| 595 |
for (const [m, c] of [[hats, hk], [bags, bk], [skirts, sk], [umbs, uk], [dogs, dk]]) { m.count = c; m.visible = c > 0; m.instanceMatrix.needsUpdate = true; if (m.instanceColor) m.instanceColor.needsUpdate = true; }
|
| 596 |
updateBirds(dt, time, player, camPos);
|
|
|
|
| 251 |
const jetGeo = mergeGeometries([new THREE.CircleGeometry(.42, 14).rotateX(Math.PI / 2).translate(1.3, .12, 0), new THREE.CircleGeometry(.42, 14).rotateX(Math.PI / 2).translate(-1.3, .12, 0)]);
|
| 252 |
const jets = new THREE.InstancedMesh(jetGeo, new THREE.MeshBasicMaterial({ color: new THREE.Color(.4, 1.8, 2.4), toneMapped: false, transparent: true, opacity: .9, blending: THREE.AdditiveBlending, depthWrite: false, side: THREE.DoubleSide }), 900);
|
| 253 |
jets.frustumCulled = false; scene.add(jets); let jk = 0;
|
| 254 |
+
// soft contact shadows under every car and person near the camera, and the pool of light ahead of each car at night
|
| 255 |
+
const softTex = (() => { const c = document.createElement("canvas"); c.width = c.height = 64; const g = c.getContext("2d"), gr = g.createRadialGradient(32, 32, 4, 32, 32, 32); gr.addColorStop(0, "rgba(255,255,255,1)"); gr.addColorStop(.55, "rgba(255,255,255,.55)"); gr.addColorStop(1, "rgba(255,255,255,0)"); g.fillStyle = gr; g.fillRect(0, 0, 64, 64); const t = new THREE.CanvasTexture(c); return t; })();
|
| 256 |
+
const flat = new THREE.PlaneGeometry(1, 1).rotateX(-Math.PI / 2);
|
| 257 |
+
const blobs = new THREE.InstancedMesh(flat, new THREE.MeshBasicMaterial({ map: softTex, color: 0x000000, transparent: true, opacity: .62, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 }), 2200);
|
| 258 |
+
const beams = new THREE.InstancedMesh(flat, new THREE.MeshBasicMaterial({ map: softTex, color: new THREE.Color(1, .82, .55).multiplyScalar(.55), transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, toneMapped: false, polygonOffset: true, polygonOffsetFactor: -5, polygonOffsetUnits: -5 }), 600);
|
| 259 |
+
for (const m of [blobs, beams]) { m.frustumCulled = false; m.renderOrder = 1; scene.add(m); }
|
| 260 |
+
let bk2 = 0, hk2 = 0; const bQ = new THREE.Quaternion(), bE = new THREE.Euler(), bS = new THREE.Vector3(), bP = new THREE.Vector3();
|
| 261 |
function place(c) { // drop a car somewhere on a random open segment
|
| 262 |
for (let tries = 0; tries < 40; tries++) {
|
| 263 |
const axis = rnd() < .5 ? 0 : 1, road = Math.floor(rnd() * (axis === 0 ? NZ : NX)), k = Math.floor(rnd() * ((axis === 0 ? NX : NZ) - 1));
|
|
|
|
| 414 |
set onHit(f) { api.onHit = f; }, set onCrash(f) { api.onCrash = f; },
|
| 415 |
// the flying VOID cars: the real car's shape, or (Lite) the simple low-poly body traffic uses
|
| 416 |
setVoidGeo(geo) { const M = meshes[KINDS.findIndex(k => k.id === "voidcar")]; if (!M) return; M.simple = M.simple || { body: M.body.geometry, lights: M.lights.geometry }; geo.setAttribute("aRust", M.simple.body.attributes.aRust); M.full = geo; },
|
| 417 |
+
setVoidDetail(full) { const M = meshes[KINDS.findIndex(k => k.id === "voidcar")]; if (!M || !M.full) return; M.body.geometry = full ? M.full : M.simple.body; M.lights.geometry = full ? jetGeo : M.simple.lights; }, set collide(f) { api.collide = f; }, set raining(v) { api.raining = v; }, set night(v) { api.night = v; },
|
| 418 |
take(c) { c.taken = true; c.parked = false; c.turn = null; },
|
| 419 |
park(c, x, z, yaw) { Object.assign(c, { taken: false, parked: true, x, z, yaw, v: 0, y: 0, wreck: null, turn: null, crush: 0 }); },
|
| 420 |
geoOf(k) { const m = meshes[KINDS.indexOf(k)]; return m ? { body: m.body.geometry, lights: m.lights.geometry } : null; },
|
|
|
|
| 496 |
if (ddx * ddx + ddz * ddz < RC2) {
|
| 497 |
e.set(c.rx, -c.yaw, c.rz + (c.turn ? (c.fly ? .25 : .05) : 0), "YXZ"); q.setFromEuler(e); const md = c.model; m4.compose(pos.set(c.x, c.y, c.z), q, squash.set(md.sl, (c.crush || 1 - (c.dent || 0) * .07) * md.sh, md.sw));
|
| 498 |
const M = meshes[c.ti], k = M.k++; M.body.setMatrixAt(k, m4); M.body.setColorAt(k, c.col); M.body.rust[k] = c.rust;
|
| 499 |
+
if (c.fly && !c.wreck && c.kind.id !== "hover" && jk < 900) jets.setMatrixAt(jk++, m4);
|
| 500 |
+
if (!c.fly && c.y < 1.5 && bk2 < 2200 && ddx * ddx + ddz * ddz < 40000) {
|
| 501 |
+
bE.set(0, -c.yaw, 0); bQ.setFromEuler(bE); m4.compose(bP.set(c.x, .045, c.z), bQ, bS.set(c.kind.L * md.sl * 1.25, 1, c.kind.W * md.sw * 1.5)); blobs.setMatrixAt(bk2++, m4);
|
| 502 |
+
if (api.night && !c.wreck && hk2 < 600 && ddx * ddx + ddz * ddz < 25600) { const L = c.kind.L * md.sl; m4.compose(bP.set(c.x + Math.cos(c.yaw) * (L / 2 + 4.5), .05, c.z + Math.sin(c.yaw) * (L / 2 + 4.5)), bQ, bS.set(9, 1, 5.5)); beams.setMatrixAt(hk2++, m4); }
|
| 503 |
+
} M.lights.setMatrixAt(k, c.wreck ? m4.compose(pos, q, zero) : m4); }
|
| 504 |
}
|
| 505 |
// collisions among the cars near the camera: a hard hit wrecks both, mass and momentum decide where they go
|
| 506 |
crashT += dt;
|
|
|
|
| 528 |
if ((reckT -= .05) < 0 && player) { reckT = 9 + rnd() * 10; for (let t = 0; t < 40; t++) { const c = cars[Math.floor(rnd() * cars.length)], d = Math.hypot(c.x - player.x, c.z - player.z); if (!c.fly && !c.wreck && !c.taken && !c.parked && d > 70 && d < 260 && !(MASS[c.kind.id] > 1.5)) { c.reck = 20 + rnd() * 15; break; } } }
|
| 529 |
}
|
| 530 |
jets.count = jk; jets.visible = jk > 0; jets.instanceMatrix.needsUpdate = true; jk = 0;
|
| 531 |
+
beams.count = hk2; beams.visible = hk2 > 0; beams.instanceMatrix.needsUpdate = true; hk2 = 0;
|
| 532 |
for (const m of meshes) { m.body.count = m.lights.count = m.k; m.body.visible = m.lights.visible = m.k > 0; m.body.instanceMatrix.needsUpdate = m.lights.instanceMatrix.needsUpdate = true; if (m.body.instanceColor) m.body.instanceColor.needsUpdate = true; m.body.geometry.attributes.aRust.needsUpdate = true; }
|
| 533 |
// debris (skipped once every piece has landed and been hidden)
|
| 534 |
if (debLive) { debLive = 0; for (let k = 0; k < DEB; k++) {
|
|
|
|
| 583 |
if (p.jog && !(p.down > 0)) y += Math.abs(Math.sin(walk)) * .06;
|
| 584 |
e.set(rx + (p.jog && !(p.down > 0) ? 0 : 0), yaw + (p.fall ? p.fall.rot : 0), rz - (p.jog && !(p.down > 0) ? .12 : 0), "YXZ"); q.setFromEuler(e); m4.compose(pos.set(x, y, z), q, pscale.set(p.wd, p.h, p.wd));
|
| 585 |
bodies.setMatrixAt(pk, m4); heads.setMatrixAt(pk, m4); hair.setMatrixAt(pk, m4);
|
| 586 |
+
if (bk2 < 2200) { bE.set(0, yaw, 0); bQ.setFromEuler(bE); const sc = p.down > 0 ? 1.8 : .95; legM.compose(bP.set(x, .05, z), bQ, bS.set(sc * p.wd, 1, sc * .8 * p.wd)); blobs.setMatrixAt(bk2++, legM); }
|
| 587 |
const amp = p.jog ? .85 : .5, swing = p.down > 0 ? (p.fall.air ? Math.sin(time * 19 + n) * .9 : .15) : p.wait > 0 ? 0 : Math.sin(walk) * amp;
|
| 588 |
LEGS[0][0] = legL; LEGS[1][0] = legR; for (const [leg, sgn, off] of LEGS) { legQ.setFromAxisAngle(Z, swing * sgn); legM.compose(pos.set(0, .88, off), legQ, one); leg.setMatrixAt(pk, legT.copy(m4).multiply(legM)); }
|
| 589 |
// arms swing against the legs; a phone or an umbrella keeps the right one up
|
|
|
|
| 604 |
pk++;
|
| 605 |
}
|
| 606 |
}
|
| 607 |
+
blobs.count = bk2; blobs.visible = bk2 > 0; blobs.instanceMatrix.needsUpdate = true; bk2 = 0;
|
| 608 |
for (const m of [bodies, heads, legL, legR, hair, armL, armR]) { m.count = pk; m.instanceMatrix.needsUpdate = true; if (m.instanceColor) m.instanceColor.needsUpdate = true; }
|
| 609 |
for (const [m, c] of [[hats, hk], [bags, bk], [skirts, sk], [umbs, uk], [dogs, dk]]) { m.count = c; m.visible = c > 0; m.instanceMatrix.needsUpdate = true; if (m.instanceColor) m.instanceColor.needsUpdate = true; }
|
| 610 |
updateBirds(dt, time, player, camPos);
|