From fb1c951c410bad18b7a98028faf5a81c68e6cc8e Mon Sep 17 00:00:00 2001 From: Brian Fertig Date: Sun, 25 Oct 2026 20:26:29 -0600 Subject: [PATCH] Rework palm trees and flyby vehicles with detailed geometry and per-vehi - Palm trees now use a curved segmented trunk with ring joints, an icosahedral crown knot, and eight pinnate fronds built from bezier midribs with tapered leaflets, replacing the old cone-based leaves - Each vehicle (airplane, UFO, car, spaceship, helicopter, rocket) is rebuilt with richer line geometry: swept wings, spoked spinning wheels, rotor blades, engine nozzles, and a flickering exhaust plume - Vehicles now own their spawn/update behavior so each flies with natural, level attitudes and type-specific motion (banking turns, hover bob, gliding drift, wheel/rotor spin) instead of a shared generic rotation - Speeds are derived from per-vehicle base values scaled by distance for consistent perspective, and the motorcycle flyby is removed --- public/js/bg-grid.js | 498 +++++++++++++++++++++++++++++++++---------- 1 file changed, 390 insertions(+), 108 deletions(-) diff --git a/public/js/bg-grid.js b/public/js/bg-grid.js index 40ec076..9bf1f68 100644 --- a/public/js/bg-grid.js +++ b/public/js/bg-grid.js @@ -119,31 +119,103 @@ if (canvas) { } // ---------- Palm trees ---------- - const palmMat = new THREE.LineBasicMaterial({ color: 0x00e5ff, transparent: true, opacity: 0.7 }); + // Trunk: muted brown; fronds: teal-green — both dimmed to sit in the synthwave palette + const palmTrunkMat = new THREE.LineBasicMaterial({ color: 0x9a6a42, transparent: true, opacity: 0.8 }); + const palmFrondMat = new THREE.LineBasicMaterial({ color: 0x3fd68f, transparent: true, opacity: 0.7 }); + const UP = new THREE.Vector3(0, 1, 0); + + // A single feathered frond in local space: starts at the origin, arcs out + // toward +X and droops down. Built as a curved midrib with pinnate leaflets + // on both sides — widest near the middle, tapering to the tip. + function makeFrond(len, droop) { + const curve = new THREE.QuadraticBezierCurve3( + new THREE.Vector3(0, 0, 0), + new THREE.Vector3(len * 0.5, len * 0.32, 0), + new THREE.Vector3(len * 1.05, -len * droop, 0), + ); + const samples = 14; + const pts = curve.getPoints(samples); + + const verts = []; + const push = (a, b) => verts.push(a.x, a.y, a.z, b.x, b.y, b.z); + for (let i = 1; i < pts.length; i++) push(pts[i - 1], pts[i]); // midrib + + for (let i = 1; i <= samples; i++) { + const t = i / samples; + if (t < 0.1) continue; + const p = pts[i]; + const tangent = pts[i].clone().sub(pts[i - 1]).normalize(); + // Leaflet length follows a pinnate profile: 0 at base & tip, max mid-frond + const sideLen = Math.sin(t * Math.PI) * len * 0.30 * (0.9 + 0.1 * Math.sin(i * 3.7)); + for (const s of [1, -1]) { + // Out of the midrib plane, angled slightly upward like real leaflets + const dir = new THREE.Vector3(-tangent.y * s, tangent.x * s, 0).lerp(UP, 0.35).normalize(); + push(p, p.clone().addScaledVector(dir, sideLen)); + } + } + + const geo = new THREE.BufferGeometry(); + geo.setAttribute('position', new THREE.Float32BufferAttribute(verts, 3)); + return new THREE.LineSegments(geo, palmFrondMat); + } function makePalmTree() { const group = new THREE.Group(); - // Trunk - const trunkGeo = new THREE.CylinderGeometry(0.08, 0.15, 3.2, 5, 1); - const trunk = new THREE.LineSegments(new THREE.EdgesGeometry(trunkGeo), palmMat); - trunk.rotation.z = 0.12; - group.add(trunk); + // Gently curved trunk with ringed "joints" for a segmented look + const trunkHeight = 4.6; + const trunkCurve = new THREE.QuadraticBezierCurve3( + new THREE.Vector3(0, 0, 0), + new THREE.Vector3(0.24, trunkHeight * 0.55, 0), + new THREE.Vector3(0.6, trunkHeight, 0), + ); + const joints = trunkCurve.getPoints(6); + const trunk = []; + for (let i = 1; i < joints.length; i++) { + trunk.push(joints[i - 1].x, joints[i - 1].y, joints[i - 1].z); + trunk.push(joints[i].x, joints[i].y, joints[i].z); + } + // Two offset rails so the trunk reads with a bit of thickness + for (const p of joints) { + trunk.push(p.x, p.y, p.z + 0.13, p.x, p.y, p.z - 0.13); + } + const trunkGeo = new THREE.BufferGeometry(); + trunkGeo.setAttribute('position', new THREE.Float32BufferAttribute(trunk, 3)); + group.add(new THREE.LineSegments(trunkGeo, palmTrunkMat)); - // Fronds — 5 cone leaves spread around trunk top, long and drooping - for (let i = 0; i < 5; i++) { - const frondGeo = new THREE.ConeGeometry(0.75, 2.8, 4, 1); - const frond = new THREE.LineSegments(new THREE.EdgesGeometry(frondGeo), palmMat); - frond.position.y = 1.4; // half of cone height, so base sits at pivot + // Ring joints along the trunk + for (let i = 1; i < joints.length - 1; i++) { + const ring = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CircleGeometry(0.17, 7)), palmTrunkMat); + ring.rotation.x = Math.PI / 2; + ring.position.copy(joints[i]); + group.add(ring); + } + // Crown: small faceted knot where the fronds sprout + const crown = trunkCurve.getPoint(1); + const knot = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.IcosahedronGeometry(0.22, 0)), palmTrunkMat); + knot.position.copy(crown); + group.add(knot); + + // 8 fronds in two tiers — lower tier longer and droopier, upper tier shorter + const FRONDS = 8; + for (let i = 0; i < FRONDS; i++) { + const lower = i % 2 === 0; + const frond = makeFrond( + (lower ? 2.6 : 2.1) + Math.random() * 0.9, + (lower ? 0.72 : 0.45) + Math.random() * 0.15, + ); const pivot = new THREE.Object3D(); - pivot.position.set(0, 3.2, 0); // trunk top - pivot.rotation.z = -1.15; // droop outward ~66° - pivot.rotation.y = (Math.PI * 2 / 5) * i; + pivot.position.copy(crown); + pivot.rotation.y = (Math.PI * 2 / FRONDS) * i + Math.random() * 0.5; + if (lower) pivot.position.y -= 0.08; pivot.add(frond); group.add(pivot); } + // Randomize lean direction, and vary size slightly per tree + group.rotation.y = Math.random() * Math.PI * 2; + group.scale.setScalar(1.0 + Math.random() * 0.35); return group; } @@ -174,127 +246,341 @@ if (canvas) { return new THREE.LineBasicMaterial({ color: 0x00e5ff, transparent: true, opacity: 0.9 }); } - function addEdges(group, geo, mat) { - group.add(new THREE.LineSegments(new THREE.EdgesGeometry(geo), mat)); + + // Shared builders. Vehicles are built nose-first along +X so they can be + // spawned heading either way and flown with natural, level attitudes. + function addPart(group, mat, geo, x = 0, y = 0, z = 0, rx = 0, ry = 0, rz = 0) { + const part = new THREE.LineSegments(new THREE.EdgesGeometry(geo), mat); + part.position.set(x, y, z); + part.rotation.set(rx, ry, rz); + group.add(part); + return part; + } + + function addLoop(group, mat, pts) { + const loop = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(pts), mat); + group.add(loop); + return loop; + } + + const V3 = (x, y, z = 0) => new THREE.Vector3(x, y, z); + + function circlePtsX(r, n, x) { // ring in the YZ plane, normal along X + const pts = []; + for (let i = 0; i < n; i++) { + const a = (i / n) * Math.PI * 2; + pts.push(new THREE.Vector3(x, Math.cos(a) * r, Math.sin(a) * r)); + } + return pts; + } + + function circlePtsY(r, n, y) { // ring in the XZ plane (horizontal) + const pts = []; + for (let i = 0; i < n; i++) { + const a = (i / n) * Math.PI * 2; + pts.push(new THREE.Vector3(Math.cos(a) * r, y, Math.sin(a) * r)); + } + return pts; } function makeAirplane() { const mat = makeVehicleMat(); const g = new THREE.Group(); - addEdges(g, new THREE.BoxGeometry(4.0, 0.4, 0.6), mat); // fuselage - const lw = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(2.2, 0.12, 0.9)), mat); - lw.position.set(-1.8, 0, 0); g.add(lw); // left wing - const rw = lw.clone(); rw.position.set(1.8, 0, 0); g.add(rw); // right wing - const vf = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.1, 0.7, 0.45)), mat); - vf.position.set(-1.9, 0.3, 0); g.add(vf); // vertical tail fin - const hs = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.0, 0.1, 0.35)), mat); - hs.position.set(-1.9, 0.1, 0); g.add(hs); // horizontal stabiliser - return { group: g, mat }; + + // Fuselage: round tube, pointed nose, tapered tail + addPart(g, mat, new THREE.CylinderGeometry(0.26, 0.26, 5.2, 8, 1), 0, 0, 0, 0, 0, Math.PI / 2); + addPart(g, mat, new THREE.ConeGeometry(0.26, 1.1, 8, 1), 3.1, 0, 0, 0, 0, -Math.PI / 2); + addPart(g, mat, new THREE.CylinderGeometry(0.06, 0.26, 1.3, 8, 1), -3.25, 0, 0, 0, 0, Math.PI / 2); + + // Under-wing engines + addPart(g, mat, new THREE.CylinderGeometry(0.16, 0.2, 1.0, 8, 1), 0.55, -0.3, 0.85, 0, 0, Math.PI / 2); + addPart(g, mat, new THREE.CylinderGeometry(0.16, 0.2, 1.0, 8, 1), 0.55, -0.3, -0.85, 0, 0, Math.PI / 2); + + // Swept main wings with slight dihedral + addLoop(g, mat, [V3(0.55, 0, 0.2), V3(-0.85, 0.22, 2.2), V3(-1.65, 0.22, 1.75), V3(-1.15, 0, 0.2)]); + addLoop(g, mat, [V3(0.55, 0, -0.2), V3(-0.85, 0.22, -2.2), V3(-1.65, 0.22, -1.75), V3(-1.15, 0, -0.2)]); + + // Swept tailplane + addLoop(g, mat, [V3(-3.0, 0, 0.15), V3(-3.7, 0.12, 0.95), V3(-3.95, 0.12, 0.8), V3(-3.5, 0, 0.15)]); + addLoop(g, mat, [V3(-3.0, 0, -0.15), V3(-3.7, 0.12, -0.95), V3(-3.95, 0.12, -0.8), V3(-3.5, 0, -0.15)]); + + // Vertical stabiliser + addLoop(g, mat, [V3(-2.6, 0.15, 0), V3(-3.5, 1.05, 0), V3(-3.85, 1.05, 0), V3(-3.85, 0.15, 0)]); + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 6, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yBase = rnd(7, 12); + s.yawBase = dir > 0 ? 0 : Math.PI; + g.position.set(dir > 0 ? -75 : 75, s.yBase, z); + g.rotation.set(0, 0, 0); + }, + // Level cruise with a slow, gentle heading change and matching bank + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = s.yBase + Math.sin(ph * 0.18) * 0.35; + g.rotation.y = s.yawBase + Math.sin(ph * 0.21) * 0.16 * s.dir; + g.rotation.z = Math.cos(ph * 0.21) * 0.06 * s.dir; + }, + }; } function makeUFO() { const mat = makeVehicleMat(); const g = new THREE.Group(); - addEdges(g, new THREE.CylinderGeometry(1.8, 1.8, 0.35, 8, 1), mat); // main disc - const dome = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.SphereGeometry(0.8, 6, 4)), mat); - dome.position.set(0, 0.35, 0); g.add(dome); // top dome - const rim = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CylinderGeometry(2.1, 2.1, 0.1, 8, 1)), mat); - rim.position.set(0, -0.1, 0); g.add(rim); // outer rim - return { group: g, mat }; + + // Saucer body + addPart(g, mat, new THREE.CylinderGeometry(1.75, 1.45, 0.5, 14, 1)); + const dome = addPart(g, mat, new THREE.SphereGeometry(0.8, 10, 6), 0, 0.35, 0); + dome.scale.set(1, 0.75, 1); + const under = addPart(g, mat, new THREE.SphereGeometry(0.5, 8, 5), 0, -0.35, 0); + under.scale.set(1.4, 0.6, 1.4); + + // Light rings + addLoop(g, mat, circlePtsY(1.9, 20, -0.08)); + addLoop(g, mat, circlePtsY(1.25, 14, 0.3)); + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 3, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yBase = rnd(5, 11); + g.position.set(dir > 0 ? -75 : 75, s.yBase, z); + g.rotation.set(0, 0, 0); + }, + // Hovering drift: slow forward slide with a vertical bob and steady yaw + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = s.yBase + Math.sin(ph * 0.8) * 0.35; + g.rotation.y += dt * 0.22; + g.rotation.z = Math.sin(ph * 0.6) * 0.04; + }, + }; } function makeCar() { const mat = makeVehicleMat(); const g = new THREE.Group(); - addEdges(g, new THREE.BoxGeometry(2.8, 0.55, 1.2), mat); // body - const roof = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.4, 0.5, 1.0)), mat); - roof.position.set(-0.2, 0.52, 0); g.add(roof); - const wheelPositions = [[0.9, -0.2, 0.65], [0.9, -0.2, -0.65], [-0.9, -0.2, 0.65], [-0.9, -0.2, -0.65]]; - for (const [x, y, z] of wheelPositions) { - const w = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CylinderGeometry(0.3, 0.3, 0.2, 6, 1)), mat); - w.rotation.z = Math.PI / 2; - w.position.set(x, y, z); - g.add(w); + + // Lower body + cabin + addPart(g, mat, new THREE.BoxGeometry(4.4, 0.55, 1.85), 0, 0.62, 0); + addPart(g, mat, new THREE.BoxGeometry(2.4, 0.55, 1.65), -0.1, 1.18, 0); + + // Headlights and taillights + for (const z of [0.55, -0.55]) { + addPart(g, mat, new THREE.BoxGeometry(0.05, 0.12, 0.3), 2.21, 0.6, z); + addPart(g, mat, new THREE.BoxGeometry(0.05, 0.1, 0.25), -2.21, 0.65, z); } - return { group: g, mat }; + + // Spoked wheels that spin about their axle + const wheels = []; + for (const [wx, wz] of [[1.45, 0.85], [1.45, -0.85], [-1.45, 0.85], [-1.45, -0.85]]) { + const wheel = new THREE.Group(); + wheel.position.set(wx, 0.42, wz); + wheel.add(new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CircleGeometry(0.42, 10)), mat)); + wheel.add(new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CircleGeometry(0.12, 6)), mat)); + g.add(wheel); + wheels.push(wheel); + } + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 5, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yawBase = dir > 0 ? 0 : Math.PI; + g.position.set(dir > 0 ? -75 : 75, 0, z); + g.rotation.set(0, 0, 0); + }, + // Drives along the ground: level, steady, slight suspension bounce + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = Math.abs(Math.sin(ph * 2.2)) * -0.04; + g.rotation.y = s.yawBase; + for (const w of wheels) w.rotation.z += (s.dir * s.speed * dt) / 0.42; + }, + }; } function makeSpaceship() { const mat = makeVehicleMat(); const g = new THREE.Group(); - const front = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(2.0, 0.4, 0.8)), mat); - front.position.set(0.75, 0, 0); g.add(front); - const rear = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.5, 0.7, 1.4)), mat); - rear.position.set(-0.8, 0, 0); g.add(rear); - const cockpit = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.5, 0.3, 0.5)), mat); - cockpit.position.set(0.9, 0.35, 0); g.add(cockpit); - // swept wings - for (const side of [1, -1]) { - const wing = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.6, 0.1, 0.65)), mat); - wing.rotation.y = side * 0.35; - wing.position.set(-0.5, -0.1, side * 0.9); g.add(wing); - const nacelle = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.4, 0.3, 0.3)), mat); - nacelle.position.set(-1.6, 0, side * 0.55); g.add(nacelle); - } - return { group: g, mat }; + + // Hull: slim body, pointed nose, tapered aft section + addPart(g, mat, new THREE.CylinderGeometry(0.3, 0.3, 2.6, 8, 1), 0, 0, 0, 0, 0, Math.PI / 2); + addPart(g, mat, new THREE.ConeGeometry(0.3, 1.5, 8, 1), 2.0, 0, 0, 0, 0, -Math.PI / 2); + addPart(g, mat, new THREE.CylinderGeometry(0.18, 0.3, 1.1, 8, 1), -1.8, 0, 0, 0, 0, Math.PI / 2); + + // Canopy + const canopy = addPart(g, mat, new THREE.SphereGeometry(0.26, 8, 6), 0.7, 0.3, 0); + canopy.scale.set(1.3, 1, 1); + + // Swept delta wings + addLoop(g, mat, [V3(0.6, 0, 0.18), V3(-1.3, 0.05, 1.8), V3(-2.0, 0.15, 1.15), V3(-1.15, 0, 0.18)]); + addLoop(g, mat, [V3(0.6, 0, -0.18), V3(-1.3, 0.05, -1.8), V3(-2.0, 0.15, -1.15), V3(-1.15, 0, -0.18)]); + + // Twin dorsal fins + addLoop(g, mat, [V3(-1.5, 0.1, 0.3), V3(-2.2, 0.1, 0.3), V3(-2.2, 0.85, 0.3)]); + addLoop(g, mat, [V3(-1.5, 0.1, -0.3), V3(-2.2, 0.1, -0.3), V3(-2.2, 0.85, -0.3)]); + + // Twin engine nozzles + addPart(g, mat, new THREE.CylinderGeometry(0.17, 0.21, 0.3, 8, 1), -2.5, 0, 0.22, 0, 0, Math.PI / 2); + addPart(g, mat, new THREE.CylinderGeometry(0.17, 0.21, 0.3, 8, 1), -2.5, 0, -0.22, 0, 0, Math.PI / 2); + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 5.5, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yBase = rnd(6, 14); + s.yawBase = dir > 0 ? 0 : Math.PI; + g.position.set(dir > 0 ? -75 : 75, s.yBase, z); + g.rotation.set(0, 0, 0); + }, + // Gliding flight: slow yaw drift with a hint of roll and pitch + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = s.yBase + Math.sin(ph * 0.25) * 0.5; + g.rotation.y = s.yawBase + Math.sin(ph * 0.19) * 0.12 * s.dir; + g.rotation.z = Math.sin(ph * 0.16) * 0.08 * s.dir; + g.rotation.x = Math.sin(ph * 0.13) * 0.05; + }, + }; } function makeHelicopter() { const mat = makeVehicleMat(); const g = new THREE.Group(); - addEdges(g, new THREE.BoxGeometry(2.0, 0.8, 0.9), mat); // cabin - const tail = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.8, 0.2, 0.25)), mat); - tail.position.set(-1.8, 0.2, 0); g.add(tail); - const mainRotor = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CylinderGeometry(2.0, 2.0, 0.05, 8, 1)), mat); - mainRotor.position.set(0, 0.7, 0); g.add(mainRotor); - const tailRotor = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CylinderGeometry(0.45, 0.45, 0.06, 6, 1)), mat); - tailRotor.rotation.z = Math.PI / 2; - tailRotor.position.set(-2.7, 0.35, 0.15); g.add(tailRotor); - for (const side of [1, -1]) { - const skid = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.6, 0.1, 0.12)), mat); - skid.position.set(0, -0.5, side * 0.5); g.add(skid); + + // Cabin (front) + main body, nose at +X + const cabin = addPart(g, mat, new THREE.SphereGeometry(0.5, 8, 6), 1.05, 0.05, 0); + cabin.scale.set(1.25, 0.9, 1.0); + addPart(g, mat, new THREE.BoxGeometry(1.7, 0.7, 0.72), 0.1, 0, 0); + + // Tail boom + fin + addPart(g, mat, new THREE.BoxGeometry(1.7, 0.2, 0.2), -1.45, 0.1, 0); + addLoop(g, mat, [V3(-2.0, 0.15, 0), V3(-2.35, 0.7, 0), V3(-2.35, 0.15, 0)]); + + // Tail rotor (spins about Z) + const tailRotor = new THREE.Group(); + tailRotor.position.set(-2.35, 0.2, 0.15); + tailRotor.add(new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CircleGeometry(0.32, 10)), mat)); + g.add(tailRotor); + + // Main rotor: hub + spinning disc with two long blades + addPart(g, mat, new THREE.CylinderGeometry(0.09, 0.13, 0.2, 6, 1), 0.15, 0.52, 0); + const mainRotor = new THREE.Group(); + mainRotor.position.set(0.15, 0.65, 0); + const disc = new THREE.LineLoop(new THREE.BufferGeometry().setFromPoints(circlePtsY(1.55, 12, 0)), mat); + mainRotor.add(disc); + mainRotor.add(new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(3.1, 0.03, 0.14)), mat)); + const blade2 = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(3.1, 0.03, 0.14)), mat); + blade2.rotation.y = Math.PI / 2; + mainRotor.add(blade2); + g.add(mainRotor); + + // Landing skids + for (const z of [0.5, -0.5]) { + addPart(g, mat, new THREE.BoxGeometry(2.4, 0.06, 0.06), 0, -0.6, z); + addPart(g, mat, new THREE.BoxGeometry(0.08, 0.35, 0.08), 0.65, -0.35, z); + addPart(g, mat, new THREE.BoxGeometry(0.08, 0.35, 0.08), -0.65, -0.35, z); } - return { group: g, mat }; + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 4, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yBase = rnd(4, 8); + s.yawBase = dir > 0 ? 0 : Math.PI; + g.position.set(dir > 0 ? -75 : 75, s.yBase, z); + g.rotation.set(0, 0, 0); + }, + // Slow forward flight with rotor spin, hover bob and gentle sway + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = s.yBase + Math.sin(ph * 1.1) * 0.15; + g.rotation.y = s.yawBase + Math.sin(ph * 0.3) * 0.05 * s.dir; + g.rotation.z = Math.sin(ph * 0.7) * 0.05 * s.dir; + mainRotor.rotation.y += dt * 26; + tailRotor.rotation.z += dt * 42; + }, + }; } function makeRocket() { const mat = makeVehicleMat(); const g = new THREE.Group(); - // Build pointing along local Y, then rotate group so it flies along X - addEdges(g, new THREE.CylinderGeometry(0.22, 0.28, 3.0, 6, 1), mat); - const nose = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.ConeGeometry(0.25, 0.85, 6, 1)), mat); - nose.position.set(0, 1.93, 0); g.add(nose); - for (let i = 0; i < 3; i++) { - const fin = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.08, 0.7, 0.5)), mat); - fin.rotation.y = (Math.PI * 2 / 3) * i; - fin.position.set(Math.sin((Math.PI * 2 / 3) * i) * 0.28, -1.1, Math.cos((Math.PI * 2 / 3) * i) * 0.28); + + // Cylindrical body, conical nose + addPart(g, mat, new THREE.CylinderGeometry(0.3, 0.3, 3.4, 10, 1), 0, 0, 0, 0, 0, Math.PI / 2); + addPart(g, mat, new THREE.ConeGeometry(0.3, 1.4, 10, 1), 2.4, 0, 0, 0, 0, -Math.PI / 2); + + // Decorative bands + addLoop(g, mat, circlePtsX(0.31, 12, 0.5)); + addLoop(g, mat, circlePtsX(0.31, 12, -0.8)); + + // Four tail fins + for (let i = 0; i < 4; i++) { + const fin = new THREE.Group(); + fin.rotation.y = (Math.PI / 2) * i; + addLoop(fin, mat, [V3(-1.0, 0.28, 0), V3(-1.7, 0.28, 0), V3(-1.7, 0.85, 0)]); g.add(fin); } - g.rotation.z = Math.PI / 2; // point along X so xVelocity moves it naturally - return { group: g, mat }; - } - function makeMotorcycle() { - const mat = makeVehicleMat(); - const g = new THREE.Group(); - for (const x of [0.85, -0.75]) { - const wheel = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.CylinderGeometry(0.5, 0.5, 0.2, 8, 1)), mat); - wheel.rotation.z = Math.PI / 2; - wheel.position.set(x, 0, 0); g.add(wheel); - } - const frame = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(1.5, 0.6, 0.25)), mat); - frame.position.set(0, 0.5, 0); g.add(frame); - const seat = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.7, 0.15, 0.3)), mat); - seat.position.set(-0.1, 0.9, 0); g.add(seat); - const bar = new THREE.LineSegments(new THREE.EdgesGeometry(new THREE.BoxGeometry(0.3, 0.08, 0.7)), mat); - bar.position.set(0.7, 0.85, 0); g.add(bar); - g.scale.setScalar(1.5); - return { group: g, mat }; + // Nozzle ring + flickering exhaust plume + addLoop(g, mat, circlePtsX(0.24, 10, -1.75)); + const flame = new THREE.Group(); + flame.position.set(-1.8, 0, 0); + const flamePts = new THREE.BufferGeometry().setFromPoints([V3(0, 0, 0), V3(-0.8, 0, 0)]); + flame.add(new THREE.Line(flamePts, mat)); + g.add(flame); + + const s = { phase: Math.random() * 20 }; + return { + group: g, + mat, + speedBase: 8, + spawn(dir, z, speed) { + s.dir = dir; s.speed = speed; + s.yBase = rnd(10, 16); + s.yawBase = dir > 0 ? 0 : Math.PI; + g.position.set(dir > 0 ? -75 : 75, s.yBase, z); + g.rotation.set(0, 0, 0); + }, + // Long, steady high-altitude flight with a whisper of pitch wobble + update(dt, t) { + const ph = t + s.phase; + g.position.x += s.dir * s.speed * dt; + g.position.y = s.yBase + Math.sin(ph * 0.12) * 0.3; + g.rotation.y = s.yawBase; + g.rotation.z = Math.sin(ph * 0.5) * 0.04 * s.dir; + flame.scale.x = 0.7 + 0.35 * Math.sin(ph * 45); + }, + }; } const FLYBY_COLORS = [0x00e5ff, 0xff2bd6, 0x8f5bff]; - const flybyPool = [makeAirplane, makeUFO, makeCar, makeSpaceship, makeHelicopter, makeRocket, makeMotorcycle] + const flybyPool = [makeAirplane, makeUFO, makeCar, makeSpaceship, makeHelicopter, makeRocket] .map(fn => { const r = fn(); r.group.visible = false; @@ -304,26 +590,24 @@ if (canvas) { const flyby = { active: null, - xVel: 0, nextAt: performance.now() + rnd(5000, 12000), colorIdx: 0, }; function spawnFlyby() { const entry = flybyPool[Math.floor(Math.random() * flybyPool.length)]; - const goLeft = Math.random() < 0.5; + const dir = Math.random() < 0.5 ? -1 : 1; entry.mat.color.setHex(FLYBY_COLORS[flyby.colorIdx++ % FLYBY_COLORS.length]); - const z = rnd(-6, -45); + const z = rnd(-8, -45); // Closer passes move faster so they feel properly scaled in speed. const dist = Math.abs(camera.position.z - z); - const speed = rnd(7, 14) * (55 / dist); - entry.group.position.set(goLeft ? 65 : -65, rnd(5, 13), z); - entry.group.rotation.set(0, 0, 0); + const speed = entry.speedBase * (45 / dist); + entry.spawn(dir, z, speed); entry.group.visible = true; flyby.active = entry; - flyby.xVel = goLeft ? -speed : speed; } + // ---------- Beat / bass reactivity surface ---------- const state = { beat: 0, // smoothed bass energy 0..1 @@ -393,13 +677,11 @@ if (canvas) { // Flyby objects if (!flyby.active && now >= flyby.nextAt) spawnFlyby(); if (flyby.active) { - flyby.active.group.position.x += flyby.xVel * dt; - flyby.active.group.rotation.y += 0.3 * dt; - flyby.active.group.rotation.z += 0.12 * dt; - if (Math.abs(flyby.active.group.position.x) > 72) { + flyby.active.update(dt, now * 0.001); + if (Math.abs(flyby.active.group.position.x) > 80) { flyby.active.group.visible = false; flyby.active = null; - flyby.nextAt = now + rnd(5000, 12000); + flyby.nextAt = now + rnd(4000, 10000); } }