Prompt specification
Build or customize the Three.js 3D scene "Bicycle trip preparation corner" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Bicycle trip preparation corner
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bicycle-trip-preparation-corner-x0607
Scene Description Prompt:
Stylized cyclists collect helmets, bags, and water before leaving a doorway. Make a Three.js scene from cdnjs in one HTML file.
Working Three.js Starter (bicycle-trip-preparation-corner-x0607):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ready to Ride</title>
<style>
:root {
--ink: #17343d;
--muted: #668088;
--cream: #fffaf0;
--green: #287d72;
--yellow: #f3bd42;
--coral: #eb725f;
--blue: #59a8c6;
--purple: #8d70b7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcece5;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.hud {
position: fixed;
top: 22px;
left: 22px;
width: min(330px, calc(100vw - 44px));
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 24px;
background: rgba(255, 250, 240, 0.88);
box-shadow:
0 18px 50px rgba(35, 76, 75, 0.14),
inset 0 1px 0 rgba(255, 255, 255, 0.9);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
pointer-events: auto;
z-index: 5;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: #55b88b;
box-shadow: 0 0 0 5px rgba(85, 184, 139, 0.15);
content: "";
}
h1 {
margin: 0;
font-size: clamp(24px, 4vw, 34px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 10px 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.checklist {
display: grid;
gap: 8px;
margin-bottom: 16px;
}
.check-row {
display: flex;
align-items: center;
gap: 11px;
min-height: 43px;
padding: 8px 12px;
border: 1px solid rgba(23, 52, 61, 0.08);
border-radius: 13px;
background: rgba(255, 255, 255, 0.5);
transition: 0.3s ease;
}
.check-row.done {
border-color: rgba(40, 125, 114, 0.16);
background: rgba(224, 246, 236, 0.8);
}
.check-icon {
position: relative;
width: 25px;
height: 25px;
flex: 0 0 25px;
border-radius: 8px;
background: var(--item-color);
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.08);
}
.check-icon::after {
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: white;
font-size: 14px;
font-weight: 900;
opacity: 0;
transform: scale(0.5);
transition: 0.25s ease;
content: "✓";
}
.done .check-icon::after {
opacity: 1;
transform: scale(1);
}
.check-copy {
flex: 1;
font-size: 13px;
font-weight: 750;
}
.check-state {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.done .check-state {
color: var(--green);
}
.button {
width: 100%;
min-height: 48px;
border: 0;
border-radius: 15px;
background: var(--green);
box-shadow: 0 8px 18px rgba(40, 125, 114, 0.23);
color: white;
cursor: pointer;
font: inherit;
font-size: 13px;
font-weight: 850;
letter-spacing: 0.015em;
transition:
transform 0.18s ease,
background 0.18s ease,
opacity 0.18s ease;
}
.button:hover:not(:disabled) {
background: #226e64;
transform: translateY(-2px);
}
.button:active:not(:disabled) {
transform: translateY(0);
}
.button:disabled {
cursor: not-allowed;
opacity: 0.43;
box-shadow: none;
}
.tools {
position: fixed;
top: 22px;
right: 22px;
z-index: 5;
display: flex;
gap: 9px;
pointer-events: auto;
}
.tool-button {
display: grid;
width: 44px;
height: 44px;
place-items: center;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 14px;
background: rgba(255, 250, 240, 0.86);
box-shadow: 0 10px 30px rgba(35, 76, 75, 0.12);
color: var(--ink);
cursor: pointer;
font-size: 18px;
transition: 0.2s ease;
}
.tool-button:hover {
background: white;
transform: translateY(-2px);
}
.hint {
position: fixed;
right: 22px;
bottom: 20px;
z-index: 4;
padding: 10px 14px;
border-radius: 999px;
background: rgba(255, 250, 240, 0.72);
color: #567078;
font-size: 11px;
font-weight: 700;
pointer-events: none;
backdrop-filter: blur(10px);
}
.toast {
position: fixed;
left: 50%;
bottom: 25px;
z-index: 7;
max-width: calc(100vw - 40px);
padding: 12px 18px;
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 999px;
background: rgba(23, 52, 61, 0.88);
box-shadow: 0 12px 40px rgba(23, 52, 61, 0.2);
color: white;
font-size: 12px;
font-weight: 750;
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, 12px);
transition: 0.35s ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.completion {
position: fixed;
top: 50%;
left: 50%;
z-index: 8;
width: min(360px, calc(100vw - 40px));
padding: 27px;
border: 1px solid rgba(255, 255, 255, 0.9);
border-radius: 28px;
background: rgba(255, 250, 240, 0.95);
box-shadow: 0 24px 90px rgba(23, 52, 61, 0.22);
text-align: center;
pointer-events: none;
opacity: 0;
transform: translate(-50%, -44%) scale(0.94);
transition: 0.4s cubic-bezier(0.2, 0.9, 0.25, 1.2);
}
.completion.show {
pointer-events: auto;
opacity: 1;
transform: translate(-50%, -50%) scale(1);
}
.completion-badge {
display: grid;
width: 58px;
height: 58px;
margin: 0 auto 13px;
place-items: center;
border-radius: 20px;
background: #e0f6ec;
color: var(--green);
font-size: 27px;
font-weight: 900;
}
.completion h2 {
margin: 0 0 8px;
font-size: 27px;
letter-spacing: -0.035em;
}
.completion p {
margin: 0 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dcece5;
color: var(--green);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.45s ease;
}
#loading.hide {
pointer-events: none;
opacity: 0;
}
@media (max-width: 700px) {
.hud {
top: 12px;
left: 12px;
width: min(310px, calc(100vw - 24px));
padding: 16px;
border-radius: 20px;
}
.subtitle {
display: none;
}
.checklist {
margin: 13px 0;
}
.tools {
top: auto;
right: 12px;
bottom: 12px;
}
.hint {
display: none;
}
.toast {
bottom: 70px;
}
}
</style>
</head>
<body>
<section class="hud">
<div class="eyebrow">Gear check</div>
<h1>Ready to ride?</h1>
<p class="subtitle">
Collect each piece of gear for the cycling crew before heading through the clubhouse door.
</p>
<div class="checklist">
<div class="check-row" data-type="helmet">
<span class="check-icon" style="--item-color:#f3bd42"></span>
<span class="check-copy">Helmet</span>
<span class="check-state">Waiting</span>
</div>
<div class="check-row" data-type="bag">
<span class="check-icon" style="--item-color:#8d70b7"></span>
<span class="check-copy">Day bag</span>
<span class="check-state">Waiting</span>
</div>
<div class="check-row" data-type="water">
<span class="check-icon" style="--item-color:#59a8c6"></span>
<span class="check-copy">Water bottle</span>
<span class="check-state">Waiting</span>
</div>
</div>
<button id="exitButton" class="button" disabled>
Collect gear to unlock exit
</button>
</section>
<div class="tools">
<button id="resetButton" class="tool-button" title="Reset scene" aria-label="Reset scene">↻</button>
<button id="cameraButton" class="tool-button" title="Reset camera" aria-label="Reset camera">⌂</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div id="toast" class="toast"></div>
<div id="completion" class="completion">
<div class="completion-badge">✓</div>
<h2>All geared up!</h2>
<p>The crew has their helmet, bag, and water. Everyone made it safely through the doorway.</p>
<button id="againButton" class="button">Ride another route</button>
</div>
<div id="loading">Building the bike club…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dcece5");
scene.fog = new THREE.Fog("#dcece5", 24, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-10,
10,
6,
-6,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0.4, 1.25, -0.2);
let cameraAzimuth = 0.57;
let cameraElevation = 0.59;
let cameraZoom = 1;
function updateCamera() {
const radius = 19;
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraAzimuth) * Math.cos(cameraElevation),
cameraTarget.y + radius * Math.sin(cameraElevation),
cameraTarget.z + radius * Math.cos(cameraAzimuth) * Math.cos(cameraElevation)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = aspect < 0.8 ? 15.8 : aspect < 1.25 ? 13.2 : 11.4;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
const hemi = new THREE.HemisphereLight("#fff9e9", "#729584", 2.35);
scene.add(hemi);
const sun = new THREE.DirectionalLight("#fff0cf", 4.2);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9d9ed", 1.35);
fill.position.set(9, 7, -8);
scene.add(fill);
// -------------------------------------------------------------------------
// Modeling helpers
// -------------------------------------------------------------------------
const standard = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const materials = {
ink: standard("#263b43"),
cream: standard("#f5eddb"),
wall: standard("#f3e9d4"),
wallShadow: standard("#dfd2bb"),
grass: standard("#94bd8e"),
grassDark: standard("#78a87c"),
path: standard("#dfc9a7"),
teal: standard("#3f8f83"),
tealDark: standard("#27695f"),
roof: standard("#397e78"),
roofEdge: standard("#28665f"),
coral: standard("#e96f5b"),
yellow: standard("#f3bd42"),
blue: standard("#59a8c6"),
purple: standard("#8d70b7"),
wood: standard("#9c7050"),
white: standard("#fffdf3")
};
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
geometry,
material?.isMaterial ? material : standard(material)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(parent, w, h, d, material, x = 0, y = 0, z = 0) {
return addMesh(parent, new THREE.BoxGeometry(w, h, d), material, x, y, z);
}
function sphere(parent, radius, material, x = 0, y = 0, z = 0, segments = 18) {
return addMesh(
parent,
new THREE.SphereGeometry(radius, segments, Math.max(8, segments / 2)),
material,
x,
y,
z
);
}
function cylinderBetween(parent, a, b, radius, material, segments = 8) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = addMesh(
parent,
new THREE.CylinderGeometry(radius, radius, direction.length(), segments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return mesh;
}
function makeTextTexture(text, subtitle = "") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 192;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#f8efd9";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = "#2d776e";
ctx.lineWidth = 12;
ctx.strokeRect(12, 12, canvas.width - 24, canvas.height - 24);
ctx.textAlign = "center";
ctx.fillStyle = "#245d59";
ctx.font = "900 62px sans-serif";
ctx.fillText(text, canvas.width / 2, subtitle ? 88 : 112);
if (subtitle) {
ctx.fillStyle = "#e36e59";
ctx.font = "800 29px sans-serif";
ctx.fillText(subtitle, canvas.width / 2, 140);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// -------------------------------------------------------------------------
// Landscape
// -------------------------------------------------------------------------
const ground = addMesh(
scene,
new THREE.PlaneGeometry(80, 80),
standard("#c8dfcb"),
0,
-0.48,
0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
box(scene, 15.5, 0.38, 10.4, materials.grass, 0, -0.25, 0);
const grassPatchMaterial = standard("#a8c99a");
[
[-5.8, -3.4, 2.0],
[5.7, -3.6, 1.6],
[-5.8, 3.4, 1.8],
[5.8, 3.4, 1.8],
[0.2, -4.2, 1.4]
].forEach(([x, z, radius]) => {
const patch = addMesh(
scene,
new THREE.CircleGeometry(radius, 24),
grassPatchMaterial,
x,
-0.045,
z
);
patch.rotation.x = -Math.PI / 2;
patch.castShadow = false;
});
// Warm stepping-stone route through the yard.
for (let i = 0; i < 9; i++) {
const stone = box(
scene,
0.72,
0.075,
0.48,
materials.path,
-5.4 + i * 0.77,
0.005,
2.28 + Math.sin(i * 0.7) * 0.12
);
stone.rotation.y = Math.sin(i * 1.7) * 0.09;
}
for (let i = 0; i < 4; i++) {
box(
scene,
0.62,
0.075,
0.48,
materials.path,
3.16,
0.006,
1.43 + i * 0.63
);
}
function makeTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
addMesh(
tree,
new THREE.CylinderGeometry(0.16, 0.23, 1.45, 7),
materials.wood,
0,
0.72,
0
);
const leafMat = standard("#5d9470");
const leafMat2 = standard("#74a879");
const crown = addMesh(
tree,
new THREE.IcosahedronGeometry(0.92, 1),
leafMat,
0,
1.75,
0
);
crown.scale.set(1.08, 1.18, 0.95);
const crown2 = addMesh(
tree,
new THREE.IcosahedronGeometry(0.66, 1),
leafMat2,
-0.45,
1.47,
0.08
);
crown2.scale.set(1.1, 0.9, 0.9);
const crown3 = addMesh(
tree,
new THREE.IcosahedronGeometry(0.68, 1),
leafMat,
0.46,
1.52,
-0.04
);
scene.add(tree);
return tree;
}
makeTree(-6.6, -3.45, 1.08);
makeTree(6.25, -3.7, 0.95);
makeTree(-6.7, 3.65, 0.76);
function makeBush(x, z, color) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const mat = standard(color);
sphere(group, 0.38, mat, 0, 0.31, 0, 14);
sphere(group, 0.31, mat, -0.31, 0.25, 0.08, 14);
sphere(group, 0.32, mat, 0.30, 0.26, 0.02, 14);
scene.add(group);
}
makeBush(5.95, 2.95, "#6fa075");
makeBush(-5.95, -1.75, "#78a776");
makeBush(6.15, 0.1, "#61966d");
makeBush(-6.1, 2.8, "#79aa78");
// Small flowers.
const flowerStem = standard("#4f855d");
const flowerColors = ["#fff2b0", "#ef8c83", "#f4b8d1"];
for (let i = 0; i < 18; i++) {
const x = -6.8 + (i * 1.73) % 13.5;
const z = -4.5 + (i * 2.31) % 8.8;
const flower = new THREE.Group();
flower.position.set(x, 0, z);
addMesh(
flower,
new THREE.CylinderGeometry(0.018, 0.018, 0.27, 5),
flowerStem,
0,
0.135,
0
);
const petalMat = standard(flowerColors[i % flowerColors.length]);
for (let p = 0; p < 5; p++) {
const angle = (p / 5) * Math.PI * 2;
sphere(
flower,
0.06,
petalMat,
Math.cos(angle) * 0.07,
0.29,
Math.sin(angle) * 0.07,
8
);
}
sphere(flower, 0.045, materials.yellow, 0, 0.31, 0, 8);
scene.add(flower);
}
// -------------------------------------------------------------------------
// Bike clubhouse and doorway
// -------------------------------------------------------------------------
const clubhouse = new THREE.Group();
scene.add(clubhouse);
box(clubhouse, 6.25, 0.28, 4.55, materials.wallShadow, 3.2, -0.02, -1.28);
// Side and back walls.
box(clubhouse, 0.24, 3.8, 4.0, materials.wall, 0.73, 1.9, -1.3);
box(clubhouse, 0.24, 3.8, 4.0, materials.wall, 5.67, 1.9, -1.3);
box(clubhouse, 5.2, 3.8, 0.24, materials.wallShadow, 3.2, 1.9, -3.28);
// Front facade with a wide opening.
box(clubhouse, 0.87, 3.8, 0.24, materials.wall, 1.165, 1.9, 0.7);
box(clubhouse, 0.87, 3.8, 0.24, materials.wall, 5.235, 1.9, 0.7);
box(clubhouse, 3.2, 0.72, 0.24, materials.wall, 3.2, 3.44, 0.7);
// Dark interior opening.
box(clubhouse, 3.18, 3.08, 0.08, standard("#395654"), 3.2, 1.54, 0.56);
box(clubhouse, 3.2, 0.12, 3.9, standard("#a89f8c"), 3.2, 0.08, -1.3);
// Pitched roof.
const leftRoof = box(
clubhouse,
3.0,
0.18,
4.48,
materials.roof,
1.83,
3.96,
-1.26
);
leftRoof.rotation.z = 0.14;
const rightRoof = box(
clubhouse,
3.0,
0.18,
4.48,
materials.roof,
4.57,
3.96,
-1.26
);
rightRoof.rotation.z = -0.14;
box(clubhouse, 0.22, 0.18, 4.55, materials.roofEdge, 3.2, 4.27, -1.26);
// Roof highlights.
for (let i = 0; i < 8; i++) {
const ridge = box(
clubhouse,
0.035,
0.025,
4.38,
standard("#5b9a90"),
0.62 + i * 0.74,
4.13 + Math.sin(i * 0.6) * 0.035,
-1.26
);
ridge.rotation.z = i < 4 ? 0.14 : -0.14;
}
// Door sign.
const signTexture = makeTextTexture("BIKE CLUB", "HELLO, ADVENTURE");
const sign = addMesh(
clubhouse,
new THREE.PlaneGeometry(2.55, 0.64),
new THREE.MeshBasicMaterial({ map: signTexture, toneMapped: false }),
3.2,
3.47,
0.835
);
sign.castShadow = false;
// Hinged teal door.
const doorPivot = new THREE.Group();
doorPivot.position.set(1.6, 0, 0.85);
clubhouse.add(doorPivot);
box(doorPivot, 3.16, 3.05, 0.13, materials.teal, 1.58, 1.525, 0);
box(doorPivot, 3.02, 0.10, 0.16, materials.tealDark, 1.58, 2.96, 0.01);
for (let i = 0; i < 6; i++) {
box(
doorPivot,
0.045,
2.79,
0.04,
materials.tealDark,
0.28 + i * 0.51,
1.52,
0.09
);
}
sphere(doorPivot, 0.085, materials.yellow, 2.83, 1.38, 0.16, 12);
// Small window on the side.
const sideWindow = box(
clubhouse,
0.05,
1.15,
1.42,
standard("#8ec6c8"),
5.805,
2.28,
-1.13
);
sideWindow.castShadow = false;
box(clubhouse, 0.07, 0.06, 1.48, materials.white, 5.84, 2.28, -1.13);
box(clubhouse, 0.07, 1.2, 0.06, materials.white, 5.84, 2.28, -1.13);
// -------------------------------------------------------------------------
// Bicycles and stylized cyclists
// -------------------------------------------------------------------------
function makeWheel(parent, x) {
const wheel = new THREE.Group();
wheel.position.set(x, 0.47, 0);
addMesh(
wheel,
new THREE.TorusGeometry(0.43, 0.058, 8, 28),
materials.ink
);
addMesh(
wheel,
new THREE.TorusGeometry(0.345, 0.018, 6, 24),
standard("#d6dfd9", 0.55, 0.15)
);
for (let i = 0; i < 6; i++) {
const angle = (i / 6) * Math.PI * 2;
cylinderBetween(
wheel,
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(Math.cos(angle) * 0.34, Math.sin(angle) * 0.34, 0),
0.009,
standard("#aabbb7", 0.6, 0.2),
5
);
}
parent.add(wheel);
return wheel;
}
function makeCyclist(index, jerseyMaterial, skinColor, hairColor) {
const root = new THREE.Group();
const bike = new THREE.Group();
const body = new THREE.Group();
root.add(bike);
root.add(body);
const rearWheel = makeWheel(bike, -0.67);
const frontWheel = makeWheel(bike, 0.67);
const rearHub = new THREE.Vector3(-0.67, 0.47, 0);
const frontHub = new THREE.Vector3(0.67, 0.47, 0);
const crank = new THREE.Vector3(-0.05, 0.47, 0);
const seatJoint = new THREE.Vector3(-0.25, 1.08, 0);
const handleJoint = new THREE.Vector3(0.47, 1.10, 0);
const frameMaterial = standard(index === 1 ? "#315a62" : "#364d55", 0.48, 0.35);
const accentFrame = standard(
index === 0 ? "#db6c58" : index === 1 ? "#4f93a6" : "#d2a93a",
0.48,
0.25
);
cylinderBetween(bike, rearHub, seatJoint, 0.045, frameMaterial);
cylinderBetween(bike, rearHub, crank, 0.045, frameMaterial);
cylinderBetween(bike, crank, seatJoint, 0.05, accentFrame);
cylinderBetween(bike, crank, handleJoint, 0.052, accentFrame);
cylinderBetween(bike, seatJoint, handleJoint, 0.045, frameMaterial);
cylinderBetween(
bike,
new THREE.Vector3(-0.25, 1.08, 0),
new THREE.Vector3(-0.27, 1.27, 0),
0.035,
materials.ink
);
const saddle = box(bike, 0.34, 0.07, 0.18, materials.ink, -0.29, 1.29, 0);
saddle.rotation.z = -0.08;
cylinderBetween(
bike,
new THREE.Vector3(0.47, 1.1, 0),
new THREE.Vector3(0.49, 1.27, 0),
0.034,
materials.ink
);
cylinderBetween(
bike,
new THREE.Vector3(0.49, 1.27, -0.28),
new THREE.Vector3(0.49, 1.27, 0.28),
0.028,
materials.ink
);
// Front basket.
box(bike, 0.34, 0.035, 0.40, materials.ink, 0.60, 1.17, 0);
box(bike, 0.34, 0.22, 0.035, materials.ink, 0.60, 1.25, -0.19);
box(bike, 0.34, 0.22, 0.035, materials.ink, 0.60, 1.25, 0.19);
box(bike, 0.035, 0.22, 0.40, materials.ink, 0.43, 1.25, 0);
// Pedal crank.
cylinderBetween(
bike,
new THREE.Vector3(-0.05, 0.47, -0.13),
new THREE.Vector3(0.04, 0.42, 0.13),
0.023,
materials.ink
);
box(bike, 0.20, 0.04, 0.08, materials.ink, 0.04, 0.42, 0.13);
// Rider body.
const skin = standard(skinColor);
const hair = standard(hairColor);
const hip = sphere(body, 0.23, materials.ink, -0.16, 1.52, 0);
hip.scale.set(1.1, 0.8, 0.9);
const torso = addMesh(
body,
new THREE.CapsuleGeometry(0.25, 0.47, 5, 10),
jerseyMaterial,
0.02,
1.94,
0
);
torso.rotation.z = -0.33;
// Jersey stripe.
const stripe = box(body, 0.06, 0.53, 0.52, materials.white, -0.01, 1.92, 0);
stripe.rotation.z = -0.33;
cylinderBetween(
body,
new THREE.Vector3(0.16, 2.20, 0),
new THREE.Vector3(0.23, 2.35, 0),
0.11,
skin
);
const head = new THREE.Group();
head.position.set(0.29, 2.48, 0);
body.add(head);
sphere(head, 0.25, skin, 0, 0, 0, 18);
const hairCap = sphere(head, 0.252, hair, -0.025, 0.11, 0, 18);
hairCap.scale.set(1, 0.66, 1);
sphere(head, 0.052, skin, 0.235, -0.01, 0, 10);
sphere(head, 0.021, materials.ink, 0.215, 0.045, -0.09, 8);
sphere(head, 0.021, materials.ink, 0.215, 0.045, 0.09, 8);
// Arms reaching the handlebar.
[-1, 1].forEach((side) => {
cylinderBetween(
body,
new THREE.Vector3(0.13, 2.10, side * 0.19),
new THREE.Vector3(0.31, 1.78, side * 0.25),
0.075,
jerseyMaterial
);
cylinderBetween(
body,
new THREE.Vector3(0.31, 1.78, side * 0.25),
new THREE.Vector3(0.49, 1.28, side * 0.24),
0.065,
skin
);
sphere(body, 0.075, skin, 0.49, 1.28, side * 0.24, 10);
});
// Legs reaching the pedals.
[-1, 1].forEach((side) => {
cylinderBetween(
body,
new THREE.Vector3(-0.16, 1.50, side * 0.13),
new THREE.Vector3(0.00, 1.04, side * 0.16),
0.095,
materials.ink
);
cylinderBetween(
body,
new THREE.Vector3(0.00, 1.04, side * 0.16),
new THREE.Vector3(-0.05, 0.48, side * 0.17),
0.075,
skin
);
box(body, 0.24, 0.09, 0.12, materials.ink, 0.02, 0.45, side * 0.17);
});
const headAnchor = new THREE.Object3D();
headAnchor.position.set(-0.015, 0.16, 0);
head.add(headAnchor);
const bagAnchor = new THREE.Object3D();
bagAnchor.position.set(-0.27, 1.93, 0);
root.add(bagAnchor);
const bottleAnchor = new THREE.Object3D();
bottleAnchor.position.set(0.60, 1.29, 0);
root.add(bottleAnchor);
scene.add(root);
return {
index,
root,
bike,
body,
head,
headAnchor,
bagAnchor,
bottleAnchor,
wheels: [rearWheel, frontWheel],
exitDistance: 0,
active: false,
hidden: false
};
}
const riders = [
makeCyclist(0, materials.coral, "#bd795c", "#3b2a29"),
makeCyclist(1, materials.blue, "#e0aa7d", "#5b3a2d"),
makeCyclist(2, materials.yellow, "#8f5d45", "#242a2e")
];
riders[0].root.position.set(-4.25, 0, 1.3);
riders[1].root.position.set(-2.35, 0, -0.92);
riders[2].root.position.set(-0.75, 0, 2.0);
riders[0].root.rotation.y = -0.07;
riders[1].root.rotation.y = 0.08;
riders[2].root.rotation.y = -0.04;
const exitPaths = [
[
new THREE.Vector3(-4.25, 0, 1.3),
new THREE.Vector3(1.15, 0, 1.3),
new THREE.Vector3(3.2, 0, 1.12),
new THREE.Vector3(3.2, 0, -4.15)
],
[
new THREE.Vector3(-2.35, 0, -0.92),
new THREE.Vector3(1.02, 0, -0.92),
new THREE.Vector3(3.2, 0, 0.18),
new THREE.Vector3(3.2, 0, -4.15)
],
[
new THREE.Vector3(-0.75, 0, 2.0),
new THREE.Vector3(1.18, 0, 2.0),
new THREE.Vector3(3.2, 0, 1.38),
new THREE.Vector3(3.2, 0, -4.15)
]
];
// -------------------------------------------------------------------------
// Collectible gear
// -------------------------------------------------------------------------
function makeHelmet() {
const group = new THREE.Group();
const shell = addMesh(
group,
new THREE.SphereGeometry(0.28, 18, 9, 0, Math.PI * 2, 0, Math.PI / 2),
materials.yellow
);
shell.scale.y = 0.82;
const rim = addMesh(
group,
new THREE.TorusGeometry(0.265, 0.025, 7, 24),
standard("#d9982f")
);
rim.rotation.x = Math.PI / 2;
box(group, 0.07, 0.04, 0.40, materials.white, -0.05, 0.18, 0);
box(group, 0.035, 0.035, 0.19, standard("#a36f21"), -0.04, 0.205, 0);
return group;
}
function makeBag() {
const group = new THREE.Group();
box(group, 0.43, 0.52, 0.30, materials.purple, 0, 0, 0);
box(group, 0.34, 0.17, 0.32, standard("#75589d"), 0, 0.18, 0.015);
box(group, 0.16, 0.08, 0.03, materials.yellow, 0, 0.11, 0.17);
box(group, 0.055, 0.39, 0.04, standard("#5e477e"), -0.13, -0.01, -0.17);
box(group, 0.055, 0.39, 0.04, standard("#5e477e"), 0.13, -0.01, -0.17);
return group;
}
function makeBottle() {
const group = new THREE.Group();
addMesh(
group,
new THREE.CylinderGeometry(0.105, 0.12, 0.48, 14),
materials.blue,
0,
0,
0
);
addMesh(
group,
new THREE.CylinderGeometry(0.075, 0.085, 0.11, 12),
materials.white,
0,
0.29,
0
);
addMesh(
group,
new THREE.CylinderGeometry(0.079, 0.079, 0.035, 12),
materials.tealDark,
0,
0.36,
0
);
box(group, 0.215, 0.16, 0.02, materials.white, 0, -0.02, 0.112);
box(group, 0.11, 0.035, 0.025, materials.blue, 0, 0.02, 0.126);
return group;
}
function makeGearModel(type) {
if (type === "helmet") return makeHelmet();
if (type === "bag") return makeBag();
return makeBottle();
}
const itemStates = new Map();
const clickMeshes = [];
function makeItem(type, x, z, ownerIndex, color) {
const root = new THREE.Group();
root.position.set(x, 0, z);
const ringMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.68,
depthWrite: false
});
const ring = addMesh(
root,
new THREE.TorusGeometry(0.44, 0.032, 8, 36),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.045;
ring.castShadow = false;
const model = makeGearModel(type);
model.position.y = 0.78;
root.add(model);
const hitbox = addMesh(
root,
new THREE.SphereGeometry(0.48, 12, 8),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
}),
0,
0.78,
0
);
hitbox.castShadow = false;
hitbox.receiveShadow = false;
const light = new THREE.PointLight(color, 0.65, 2.3, 2);
light.position.set(0, 0.9, 0);
root.add(light);
scene.add(root);
const item = {
type,
root,
model,
ring,
ringMaterial,
light,
ownerIndex,
state: "waiting",
elapsed: 0,
hovered: false
};
hitbox.userData.item = item;
clickMeshes.push(hitbox);
itemStates.set(type, item);
return item;
}
makeItem("helmet", -5.12, 2.48, 0, "#f3bd42");
makeItem("bag", -3.28, -2.12, 1, "#8d70b7");
makeItem("water", -0.12, 3.25, 2, "#59a8c6");
// -------------------------------------------------------------------------
// UI and interaction
// -------------------------------------------------------------------------
const exitButton = document.getElementById("exitButton");
const resetButton = document.getElementById("resetButton");
const cameraButton = document.getElementById("cameraButton");
const againButton = document.getElementById("againButton");
const toast = document.getElementById("toast");
const completion = document.getElementById("completion");
const loading = document.getElementById("loading");
let collectedCount = 0;
let exitState = null;
let totalTime = 0;
function showToast(message, duration = 2600) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(showToast.timer);
showToast.timer = setTimeout(() => {
toast.classList.remove("show");
}, duration);
}
function updateChecklist() {
document.querySelectorAll(".check-row").forEach((row) => {
const item = itemStates.get(row.dataset.type);
const done = item.state === "collected";
row.classList.toggle("done", done);
row.querySelector(".check-state").textContent = done ? "Ready" : "Waiting";
});
collectedCount = [...itemStates.values()].filter(
(item) => item.state === "collected"
).length;
exitButton.disabled = collectedCount !== 3 || exitState !== null;
if (collectedCount === 3 && exitState === null) {
exitButton.textContent = "Open the door and ride out";
} else if (exitState !== null) {
exitButton.textContent = "Crew is heading out…";
} else {
exitButton.textContent = `Collect gear to unlock exit (${collectedCount}/3)`;
}
}
function attachEquipment(item) {
const owner = riders[item.ownerIndex];
const equipment = makeGearModel(item.type);
if (item.type === "helmet") {
equipment.scale.setScalar(0.79);
equipment.position.set(-0.015, 0.02, 0);
owner.headAnchor.add(equipment);
} else if (item.type === "bag") {
equipment.scale.setScalar(0.9);
equipment.position.set(-0.02, 0, 0);
owner.bagAnchor.add(equipment);
} else {
equipment.scale.setScalar(0.74);
equipment.position.set(0.02, 0.02, 0);
owner.bottleAnchor.add(equipment);
}
}
function collectItem(item) {
if (item.state !== "waiting") return;
item.state = "collecting";
item.elapsed = 0;
item.hovered = false;
const owner = riders[item.ownerIndex];
item.startWorld = item.model.getWorldPosition(new THREE.Vector3());
item.targetWorld = new THREE.Vector3();
showToast(
item.type === "helmet"
? "Helmet collected — nice and safe!"
: item.type === "bag"
? "Day bag packed and ready!"
: "Water bottle secured!"
);
owner.root.updateMatrixWorld(true);
}
// Raycasting.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickItem(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickMeshes, false);
if (!hits.length) return null;
return hits[0].object.userData.item;
}
function setHover(item) {
itemStates.forEach((entry) => {
entry.hovered = entry === item && entry.state === "waiting";
});
renderer.domElement.style.cursor = item ? "pointer" : "grab";
}
// Custom orbit controls; no external examples or addons are used.
let pointerDown = false;
let pointerMoved = false;
let pointerStartX = 0;
let pointerStartY = 0;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
pointerDown = true;
pointerMoved = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (pointerDown) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
const totalDistance = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (totalDistance > 5) pointerMoved = true;
if (pointerMoved) {
cameraAzimuth -= dx * 0.006;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + dy * 0.004,
0.32,
1.08
);
updateCamera();
}
previousX = event.clientX;
previousY = event.clientY;
} else {
setHover(pickItem(event));
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!pointerDown) return;
if (!pointerMoved) {
const item = pickItem(event);
if (item) collectItem(item);
}
pointerDown = false;
renderer.domElement.releasePointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
pointerMoved = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.pow(0.999, event.deltaY),
0.7,
1.55
);
updateCamera();
},
{ passive: false }
);
exitButton.addEventListener("click", () => {
if (collectedCount !== 3 || exitState) return;
exitState = {
phase: "opening",
doorElapsed: 0,
nextRider: 0,
nextRiderAt: 0
};
exitButton.disabled = true;
exitButton.textContent = "Crew is heading out…";
showToast("Door open — let's ride!", 2200);
});
resetButton.addEventListener("click", () => window.location.reload());
againButton.addEventListener("click", () => window.location.reload());
cameraButton.addEventListener("click", () => {
cameraAzimuth = 0.57;
cameraElevation = 0.59;
cameraZoom = 1;
updateCamera();
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function damp(current, target, smoothing, dt) {
return THREE.MathUtils.lerp(current, target, 1 - Math.exp(-smoothing * dt));
}
function dampAngle(current, target, smoothing, dt) {
let difference = ((target - current + Math.PI) % (Math.PI * 2)) - Math.PI;
if (difference < -Math.PI) difference += Math.PI * 2;
return current + difference * (1 - Math.exp(-smoothing * dt));
}
function updateItems(dt, elapsed) {
itemStates.forEach((item) => {
if (item.state === "waiting") {
const floatY = 0.78 + Math.sin(elapsed * 2.2 + item.ownerIndex) * 0.11;
item.model.position.y = floatY;
item.model.rotation.y += dt * 0.75;
item.ring.rotation.z += dt * 0.35;
const targetScale = item.hovered ? 1.12 : 1;
const scale = damp(item.model.scale.x, targetScale, 10, dt);
item.model.scale.setScalar(scale);
item.light.intensity = item.hovered ? 1.15 : 0.65;
} else if (item.state === "collecting") {
item.elapsed += dt;
const t = THREE.MathUtils.clamp(item.elapsed / 0.9, 0, 1);
const owner = riders[item.ownerIndex];
owner.bagAnchor.updateWorldMatrix(true, false);
owner.bottleAnchor.updateWorldMatrix(true, false);
owner.headAnchor.updateWorldMatrix(true, false);
const anchor =
item.type === "helmet"
? owner.headAnchor
: item.type === "bag"
? owner.bagAnchor
: owner.bottleAnchor;
anchor.getWorldPosition(item.targetWorld);
const position = item.startWorld.clone().lerp(item.targetWorld, t);
position.y += Math.sin(t * Math.PI) * 1.15;
item.root.updateMatrixWorld(true);
const localPosition = item.root.worldToLocal(position.clone());
item.model.position.copy(localPosition);
item.model.rotation.y += dt * 3;
item.ringMaterial.opacity = 0.68 * (1 - t);
item.light.intensity = 0.65 * (1 - t);
if (t >= 1) {
item.state = "collected";
item.root.visible = false;
attachEquipment(item);
updateChecklist();
if (collectedCount === 3) {
showToast("All geared up! The exit is ready.", 3000);
}
}
}
});
}
function samplePath(path, distance) {
for (let i = 0; i < path.length - 1; i++) {
const a = path[i];
const b = path[i + 1];
const segmentLength = a.distanceTo(b);
if (distance <= segmentLength || i === path.length - 2) {
const t = segmentLength === 0 ? 0 : distance / segmentLength;
const position = a.clone().lerp(b, t);
const direction = b.clone().sub(a).normalize();
return { position, direction, segmentLength };
}
distance -= segmentLength;
}
}
function updateExit(dt) {
if (!exitState) return;
if (exitState.phase === "opening") {
exitState.doorElapsed += dt;
doorPivot.rotation.y = damp(
doorPivot.rotation.y,
-1.36,
5,
dt
);
if (exitState.doorElapsed > 1.05) {
exitState.phase = "riding";
exitState.nextRider = 0;
exitState.nextRiderAt = totalTime + 0.1;
}
return;
}
if (exitState.phase === "riding") {
if (exitState.nextRider < riders.length) {
if (totalTime >= exitState.nextRiderAt) {
const rider = riders[exitState.nextRider];
rider.active = true;
if (exitState.nextRider > 0) {
exitState.nextRiderAt = totalTime + 0.65;
}
exitState.nextRider++;
}
riders.forEach((rider) => {
if (!rider.active || rider.hidden) return;
const oldDistance = rider.exitDistance;
rider.exitDistance += dt * 2.75;
const path = exitPaths[rider.index];
const sample = samplePath(path, rider.exitDistance);
rider.root.position.copy(sample.position);
const targetAngle = Math.atan2(-sample.direction.z, sample.direction.x);
rider.root.rotation.y = dampAngle(
rider.root.rotation.y,
targetAngle,
9,
dt
);
const rolledDistance = rider.exitDistance - oldDistance;
rider.wheels.forEach((wheel) => {
wheel.rotation.z -= rolledDistance / 0.43;
});
rider.body.position.y = Math.sin(totalTime * 13) * 0.018;
const totalLength = path.reduce(
(sum, point, index) =>
index === 0 ? 0 : sum + point.distanceTo(path[index - 1]),
0
);
if (rider.exitDistance >= totalLength) {
rider.active = false;
rider.hidden = true;
rider.root.visible = false;
if (exitState.nextRider >= riders.length) {
exitState.phase = "complete";
completion.classList.add("show");
}
}
});
}
}
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
totalTime += dt;
updateItems(dt, totalTime);
updateExit(dt);
// Gentle idle motion and eye blinks.
riders.forEach((rider, index) => {
if (!rider.active && !rider.hidden) {
rider.body.position.y = Math.sin(totalTime * 2.1 + index * 1.8) * 0.013;
rider.head.rotation.y = Math.sin(totalTime * 0.65 + index) * 0.035;
}
});
renderer.render(scene, camera);
}
updateChecklist();
updateCamera();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hide");
setTimeout(() => {
showToast("Click the glowing helmet, bag, and water bottle.", 3500);
}, 500);
});
</script>
</body>
</html>
```