// Claudia on her lime scooter: the scooter, the rider (see rider.js) and the lime trail behind // the back wheel. She crouches at speed, leans into turns, tucks in the air and tumbles when // she hits something; her hair and skirt move with the wind of her speed. import * as THREE from "three"; import { RIDE_FEEL } from "../game.js"; import { LIME } from "../palette.js"; import { standard } from "./kit.js"; import { buildRider } from "./rider.js"; const DARK = 0x26282b; function part(geometry, material, x, y, z) { const m = new THREE.Mesh(geometry, material); m.position.set(x, y, z); m.castShadow = true; return m; } /** A rod from point a to point b, `t` thick. */ function rod(a, b, t, material) { const d = new THREE.Vector3().subVectors(b, a); const m = new THREE.Mesh(new THREE.CylinderGeometry(t / 2, t / 2, d.length(), 12), material); m.position.copy(a).addScaledVector(d, 0.5); m.quaternion.setFromUnitVectors(new THREE.Vector3(0, 1, 0), d.clone().normalize()); m.castShadow = true; return m; } export function buildClaudia(scene) { const lime = new THREE.MeshStandardMaterial({ color: LIME, roughness: 0.32, metalness: 0.15, emissive: LIME, emissiveIntensity: 0.16 }); const dark = new THREE.MeshStandardMaterial({ color: DARK, roughness: 0.55 }); const grip = standard(0x1a1b1d, { roughness: 0.8, flat: false }); const root = new THREE.Group(); const pitch = new THREE.Group(); const lean = new THREE.Group(); const scooter = new THREE.Group(); root.add(pitch); pitch.add(lean); // The scooter. It faces -z. const deck = new THREE.Shape(); deck.moveTo(-0.08, -0.36); deck.lineTo(0.08, -0.36); deck.quadraticCurveTo(0.095, 0, 0.08, 0.36); deck.lineTo(-0.08, 0.36); deck.quadraticCurveTo(-0.095, 0, -0.08, -0.36); const deckGeo = new THREE.ExtrudeGeometry(deck, { depth: 0.04, bevelEnabled: true, bevelThickness: 0.01, bevelSize: 0.01, bevelSegments: 2, curveSegments: 8 }); deckGeo.rotateX(Math.PI / 2); scooter.add(part(deckGeo, lime, 0, 0.16, 0)); scooter.add(part(new THREE.BoxGeometry(0.15, 0.006, 0.6), dark, 0, 0.165, 0.02)); const wheelGeo = new THREE.TorusGeometry(0.085, 0.03, 10, 20); wheelGeo.rotateY(Math.PI / 2); const hubGeo = new THREE.CylinderGeometry(0.05, 0.05, 0.05, 14); hubGeo.rotateZ(Math.PI / 2); const front = new THREE.Group(); const rear = new THREE.Group(); for (const [w, z] of [[front, -0.44], [rear, 0.4]]) { w.position.set(0, 0.115, z); w.add(part(wheelGeo, dark, 0, 0, 0), part(hubGeo, lime, 0, 0, 0)); scooter.add(w); } scooter.add(part(new THREE.BoxGeometry(0.1, 0.02, 0.24), lime, 0, 0.225, 0.43)); scooter.add(rod(new THREE.Vector3(0, 0.12, -0.44), new THREE.Vector3(0, 1.11, -0.335), 0.045, lime)); scooter.add(rod(new THREE.Vector3(0, 1.11, -0.335), new THREE.Vector3(0, 1.175, -0.33), 0.04, dark)); scooter.add(rod(new THREE.Vector3(-0.29, 1.175, -0.33), new THREE.Vector3(0.29, 1.175, -0.33), 0.026, dark)); for (const s of [-1, 1]) scooter.add(rod(new THREE.Vector3(0.19 * s, 1.175, -0.33), new THREE.Vector3(0.3 * s, 1.175, -0.33), 0.036, grip)); scooter.add(part(new THREE.BoxGeometry(0.07, 0.05, 0.03), new THREE.MeshBasicMaterial({ color: 0xfffbe8 }), 0, 0.98, -0.37)); lean.add(scooter); // Claudia. const rider = buildRider(); // her hair carries its own, dimmed copy of the sky: with the scene's (which wins otherwise) // black hair turns blue if (scene.environment) { rider.hairMaterial.envMap = scene.environment; rider.hairMaterial.envMapIntensity = 0.18; } lean.add(rider.group); scene.add(root); // The trail: a thin lime streak from where the back wheel has been. const N = 20; const trailGeo = new THREE.BufferGeometry(); const tp = new Float32Array(N * 2 * 3); const tc = new Float32Array(N * 2 * 4); const idx = []; for (let k = 0; k < N - 1; k++) idx.push(k * 2, k * 2 + 1, k * 2 + 2, k * 2 + 1, k * 2 + 3, k * 2 + 2); trailGeo.setIndex(idx); trailGeo.setAttribute("position", new THREE.BufferAttribute(tp, 3)); trailGeo.setAttribute("color", new THREE.BufferAttribute(tc, 4)); const trail = new THREE.Mesh(trailGeo, new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, depthWrite: false, blending: THREE.AdditiveBlending, side: THREE.DoubleSide, fog: true })); trail.frustumCulled = false; trail.renderOrder = 5; scene.add(trail); const limeC = new THREE.Color(LIME); const windDir = new THREE.Vector3(); return { root, update(game) { const p = game.p; root.position.set(p.x, p.y, p.z); root.rotation.y = -p.heading; pitch.rotation.x = p.pitch; const c = p.crouch; // wheels roll with the distance ridden, so a screenshot is the same every time const roll = -(game.stats.meters / 0.115); front.rotation.x = roll; rear.rotation.x = roll; let tumble = 0; if (p.tumble > 0) { const u = 1 - p.tumble / RIDE_FEEL.tumble; tumble = u; lean.rotation.z = Math.min(1, u * 4) * 1.45 * (p.lean >= 0 ? 1 : -1); rider.group.position.set(0, Math.sin(Math.min(1, u * 1.6) * Math.PI) * 0.5 - Math.min(1, u * 2) * 0.55, -Math.min(1, u * 1.4) * 1.2); rider.group.rotation.set(-Math.min(1, u * 1.3) * Math.PI * 2.1, 0, -lean.rotation.z); } else { lean.rotation.z = p.lean; rider.group.position.set(0, 0, 0); rider.group.rotation.set(0, 0, 0); } const state = { crouch: Math.min(1.3, c), air: p.air, tumble, steer: p.steer, wind: Math.min(1.3, Math.abs(p.speed) / 15 + (p.air ? 0.2 : 0)), windDir: windDir.set(-Math.sin(p.heading), -(p.vy ?? 0) * 0.04, Math.cos(p.heading)).normalize(), time: game.time, gust: Math.min(1, Math.max(0, (p.accel ?? 0) / 14)), }; rider.pose(state); root.updateMatrixWorld(true); rider.dress(state); // trail const pts = p.trail; const n = pts.length; for (let k = 0; k < N; k++) { const i = Math.max(0, n - N + k); const pt = pts[i] ?? [p.x, p.y + 0.06, p.z, 0]; // a thin upright streak at wheel height: a line from behind, a light trail from the side const hgt = (0.05 + (k / N) * 0.17) * (pt[4] ? 1.4 : 1); tp.set([pt[0], pt[1] + 0.03, pt[2], pt[0], pt[1] + 0.03 + hgt, pt[2]], k * 6); const fade = (k / (N - 1)) ** 1.8 * Math.min(1, Math.max(0, (pt[3] - 6) / 8)) * (n > 1 ? 1 : 0); for (const o of [0, 4]) tc.set([limeC.r, limeC.g, limeC.b, fade * (pt[4] ? 0.75 : 0.6)], k * 8 + o); } trailGeo.attributes.position.needsUpdate = true; trailGeo.attributes.color.needsUpdate = true; }, }; }