Prompt specification
Build or customize the Three.js 3D scene "Stall deployment sequence" 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: Stall deployment sequence
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stall-deployment-sequence-x0510
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows folding market stalls. Animate legs extending, crossbars opening, canopy lifting, and counter unfolding in order; each component reaches its support position before products appear on the surface. Low-poly.
Working Three.js Starter (stall-deployment-sequence-x0510):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Folding Market Stalls</title>
<style>
:root {
color-scheme: light;
--ink: #26332f;
--paper: #f7f0df;
--accent: #df654c;
--muted: #6e776f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcd3bf;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#scene {
position: fixed;
inset: 0;
display: block;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.intro {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
max-width: min(440px, calc(100vw - 52px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 6px 10px;
border: 1px solid rgba(38, 51, 47, 0.18);
border-radius: 999px;
background: rgba(247, 240, 223, 0.78);
backdrop-filter: blur(8px);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 4px rgba(223, 101, 76, 0.15);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 67px);
font-weight: 600;
line-height: 0.92;
letter-spacing: -0.045em;
text-wrap: balance;
}
.subtitle {
max-width: 370px;
margin: 14px 0 0;
color: #4d5c55;
font-size: 13px;
line-height: 1.55;
}
.panel {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 6;
width: min(330px, calc(100vw - 48px));
padding: 17px;
border: 1px solid rgba(38, 51, 47, 0.16);
border-radius: 18px;
background: rgba(247, 240, 223, 0.88);
box-shadow: 0 18px 45px rgba(49, 54, 43, 0.16);
backdrop-filter: blur(14px);
}
.panel-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 13px;
}
.panel-title {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
#status {
color: var(--muted);
font-size: 11px;
font-weight: 650;
}
.progress-track {
height: 4px;
margin-bottom: 14px;
overflow: hidden;
border-radius: 99px;
background: rgba(38, 51, 47, 0.12);
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: var(--accent);
transition: width 80ms linear;
}
.steps {
display: grid;
gap: 9px;
}
.step {
display: grid;
grid-template-columns: 24px 1fr auto;
align-items: center;
gap: 9px;
color: #798078;
font-size: 12px;
font-weight: 650;
transition: color 180ms ease;
}
.step-number {
display: grid;
width: 24px;
height: 24px;
place-items: center;
border: 1px solid rgba(38, 51, 47, 0.15);
border-radius: 50%;
font-size: 10px;
font-weight: 800;
}
.step.active {
color: var(--ink);
}
.step.active .step-number {
border-color: var(--accent);
background: var(--accent);
color: white;
}
.step.done {
color: #4c7567;
}
.step.done .step-number {
border-color: #4c7567;
background: #4c7567;
color: white;
}
.step-check {
opacity: 0;
color: #4c7567;
font-size: 12px;
}
.step.done .step-check {
opacity: 1;
}
.panel-footer {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid rgba(38, 51, 47, 0.11);
}
.hint {
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
button {
border: 0;
border-radius: 999px;
padding: 9px 14px;
background: var(--ink);
color: #fff9eb;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: transform 140ms ease, background 140ms ease;
}
button:hover {
background: #3d5148;
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e8dfcb;
transition: opacity 500ms ease, visibility 500ms ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.loader::before {
content: "";
width: 20px;
height: 20px;
border: 3px solid rgba(38, 51, 47, 0.15);
border-top-color: var(--accent);
border-radius: 50%;
animation: spin 700ms linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
@media (max-width: 700px) {
.intro {
top: 16px;
left: 18px;
}
.subtitle {
display: none;
}
.panel {
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 14px;
}
.steps {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.step {
grid-template-columns: 22px 1fr;
font-size: 11px;
}
.step-check {
display: none;
}
.panel-footer {
margin-top: 12px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated folding market stalls"></canvas>
<header class="intro">
<div class="eyebrow">Low-poly assembly</div>
<h1>Market,<br>unfolded.</h1>
<p class="subtitle">
A compact stall opens in four deliberate stages. Every support locks into
place before the produce arrives on the counter.
</p>
</header>
<aside class="panel" aria-label="Assembly status">
<div class="panel-header">
<span class="panel-title">Opening sequence</span>
<span id="status">0%</span>
</div>
<div class="progress-track">
<div id="progress"></div>
</div>
<div class="steps">
<div class="step active" data-step="0">
<span class="step-number">1</span>
<span>Extend legs</span>
<span class="step-check">✓</span>
</div>
<div class="step" data-step="1">
<span class="step-number">2</span>
<span>Open crossbars</span>
<span class="step-check">✓</span>
</div>
<div class="step" data-step="2">
<span class="step-number">3</span>
<span>Lift canopy</span>
<span class="step-check">✓</span>
</div>
<div class="step" data-step="3">
<span class="step-number">4</span>
<span>Unfold counter</span>
<span class="step-check">✓</span>
</div>
</div>
<div class="panel-footer">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="replay" type="button">Replay</button>
</div>
</aside>
<div id="loading">
<div class="loader">Building the market</div>
</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 lighting
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dcd3bf");
scene.fog = new THREE.Fog("#dcd3bf", 22, 48);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight("#fff4d5", "#718477", 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0cd", 3.2);
sun.position.set(-8, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight("#a7c9c0", 1.15);
fill.position.set(8, 6, -8);
scene.add(fill);
// ------------------------------------------------------------
// Shared helpers and materials
// ------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const clamp = THREE.MathUtils.clamp;
const lerp = THREE.MathUtils.lerp;
function smooth01(value) {
const x = clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function easeOutBack(value) {
const x = clamp(value, 0, 1);
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const materials = {
darkMetal: material("#35443d", { metalness: 0.35, roughness: 0.58 }),
silverMetal: material("#9ca69b", { metalness: 0.48, roughness: 0.48 }),
wood: material("#b77b43"),
darkWood: material("#865431"),
paleWood: material("#d6aa70"),
cream: material("#f1d9a9"),
red: material("#d95d46"),
teal: material("#347f78"),
yellow: material("#d4a23b"),
green: material("#71934f"),
leaf: material("#4e7546"),
orange: material("#e59a42"),
apple: material("#c94f3f"),
lemon: material("#e5c34d"),
bottle: material("#6a927e", { roughness: 0.38 }),
crate: material("#c18b55")
};
function makeMesh(geometry, mat, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function updateBeam(mesh, pointA, pointB) {
const direction = new THREE.Vector3().subVectors(pointB, pointA);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(pointA, pointB)
.multiplyScalar(0.5);
mesh.position.copy(midpoint);
if (length > 0.0001) {
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
}
mesh.scale.set(
mesh.userData.thickness,
Math.max(length, 0.0001),
mesh.userData.thickness
);
}
function createBeam(mat, thickness, parent) {
const mesh = makeMesh(new THREE.BoxGeometry(1, 1, 1), mat, parent);
mesh.userData.thickness = thickness;
return mesh;
}
function createCrate(parent, x = 0, z = 0, scale = 1) {
const crate = new THREE.Group();
crate.position.set(x, 0, z);
crate.scale.setScalar(scale);
parent.add(crate);
const base = makeMesh(
new THREE.BoxGeometry(0.72, 0.08, 0.52),
materials.crate,
crate
);
base.position.y = 0.04;
const railGeometryHorizontal = new THREE.BoxGeometry(0.76, 0.16, 0.055);
const railGeometrySide = new THREE.BoxGeometry(0.055, 0.16, 0.52);
for (const y of [0.14, 0.29]) {
const front = makeMesh(railGeometryHorizontal, materials.darkWood, crate);
front.position.set(0, y, 0.25);
const back = makeMesh(railGeometryHorizontal, materials.darkWood, crate);
back.position.set(0, y, -0.25);
const left = makeMesh(railGeometrySide, materials.darkWood, crate);
left.position.set(-0.35, y, 0);
const right = makeMesh(railGeometrySide, materials.darkWood, crate);
right.position.set(0.35, y, 0);
}
for (const x of [-0.23, 0, 0.23]) {
for (const z of [-0.12, 0.12]) {
const apple = makeMesh(
new THREE.IcosahedronGeometry(0.105, 0),
materials.apple,
crate
);
apple.position.set(x, 0.28, z);
apple.scale.y = 0.9;
}
}
return crate;
}
// ------------------------------------------------------------
// Ground and market-square dressing
// ------------------------------------------------------------
const ground = makeMesh(
new THREE.PlaneGeometry(90, 90),
material("#b9b59f")
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.48;
ground.castShadow = false;
const platform = makeMesh(
new THREE.CylinderGeometry(11.2, 11.55, 0.44, 8),
material("#cbb58e")
);
platform.position.y = -0.22;
platform.castShadow = false;
const innerPlatform = makeMesh(
new THREE.CylinderGeometry(9.8, 9.95, 0.08, 8),
material("#ddcba7")
);
innerPlatform.position.y = 0.025;
innerPlatform.castShadow = false;
for (let i = 0; i < 7; i++) {
const seam = makeMesh(
new THREE.BoxGeometry(20, 0.012, 0.025),
material("#b69e77")
);
seam.position.set(0, 0.074, -8 + i * 2.65);
seam.castShadow = false;
}
// Low-poly trees around the perimeter.
function createTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
const trunk = makeMesh(
new THREE.CylinderGeometry(0.15, 0.21, 1.55, 6),
materials.darkWood,
tree
);
trunk.position.y = 0.78;
const crown = makeMesh(
new THREE.DodecahedronGeometry(0.95, 0),
material("#718b62"),
tree
);
crown.position.y = 2;
crown.scale.set(0.9, 1.15, 0.85);
}
createTree(-8.8, -6.8, 1.15);
createTree(8.6, -7.2, 1.25);
createTree(-10.2, -1.8, 0.85);
// Bunting behind the stalls.
const buntingGroup = new THREE.Group();
scene.add(buntingGroup);
for (const x of [-7.6, 7.6]) {
const pole = makeMesh(
new THREE.CylinderGeometry(0.07, 0.09, 5.4, 6),
materials.darkWood,
buntingGroup
);
pole.position.set(x, 2.7, -4.9);
}
const buntingPoints = [];
for (let i = 0; i <= 24; i++) {
const t = i / 24;
const x = lerp(-7.6, 7.6, t);
const y = 4.85 - Math.sin(t * Math.PI) * 0.75;
buntingPoints.push(new THREE.Vector3(x, y, -4.9));
}
const buntingLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(buntingPoints),
new THREE.LineBasicMaterial({ color: "#6c6658" })
);
buntingGroup.add(buntingLine);
const flagColors = ["#d65d47", "#e0ac3d", "#3f8179", "#f1d9a9"];
for (let i = 0; i < 16; i++) {
const t = (i + 0.5) / 16;
const x = lerp(-7.6, 7.6, t);
const y = 4.85 - Math.sin(t * Math.PI) * 0.75;
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[-0.22, 0, 0, 0.22, 0, 0, 0, -0.48, 0],
3
)
);
geometry.computeVertexNormals();
const flag = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: flagColors[i % flagColors.length],
side: THREE.DoubleSide,
flatShading: true,
roughness: 0.9
})
);
flag.position.set(x, y, -4.9);
flag.castShadow = true;
buntingGroup.add(flag);
}
createCrate(scene, -6.3, 1.8, 0.82);
createCrate(scene, 6.25, 1.5, 0.72);
createCrate(scene, 6.4, 0.55, 0.58);
// ------------------------------------------------------------
// Products: hidden until all structural supports are complete
// ------------------------------------------------------------
function createAppleCrate(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 1.84, z);
parent.add(group);
const base = makeMesh(
new THREE.BoxGeometry(0.66, 0.07, 0.45),
materials.crate,
group
);
base.position.y = 0.035;
for (const y of [0.13, 0.27]) {
for (const side of [-1, 1]) {
const rail = makeMesh(
new THREE.BoxGeometry(0.68, 0.075, 0.04),
materials.darkWood,
group
);
rail.position.set(0, y, side * 0.215);
}
}
for (const side of [-1, 1]) {
const rail = makeMesh(
new THREE.BoxGeometry(0.04, 0.075, 0.43),
materials.darkWood,
group
);
rail.position.set(side * 0.32, 0.2, 0);
}
for (const px of [-0.2, 0, 0.2]) {
for (const pz of [-0.1, 0.1]) {
const fruit = makeMesh(
new THREE.IcosahedronGeometry(0.1, 0),
materials.apple,
group
);
fruit.position.set(px, 0.27, pz);
}
}
return group;
}
function createBottles(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 1.84, z);
parent.add(group);
const positions = [
[-0.12, 0, -0.05],
[0.13, 0, -0.08],
[0, 0, 0.14]
];
for (const [px, , pz] of positions) {
const bottle = new THREE.Group();
bottle.position.set(px, 0, pz);
group.add(bottle);
const body = makeMesh(
new THREE.CylinderGeometry(0.09, 0.105, 0.3, 6),
materials.bottle,
bottle
);
body.position.y = 0.15;
const neck = makeMesh(
new THREE.CylinderGeometry(0.042, 0.055, 0.12, 6),
materials.bottle,
bottle
);
neck.position.y = 0.35;
const cap = makeMesh(
new THREE.CylinderGeometry(0.048, 0.048, 0.04, 6),
materials.yellow,
bottle
);
cap.position.y = 0.425;
}
return group;
}
function createGreens(parent, x, z) {
const group = new THREE.Group();
group.position.set(x, 1.84, z);
parent.add(group);
const bowl = makeMesh(
new THREE.CylinderGeometry(0.27, 0.18, 0.16, 7),
materials.cream,
group
);
bowl.position.y = 0.08;
for (let i = 0; i < 7; i++) {
const angle = (i / 7) * Math.PI * 2;
const leaf = makeMesh(
new THREE.DodecahedronGeometry(0.12, 0),
i % 2 ? materials.green : materials.leaf,
group
);
leaf.position.set(
Math.cos(angle) * 0.13,
0.2 + (i % 2) * 0.035,
Math.sin(angle) * 0.13
);
leaf.scale.set(0.8, 1.2, 0.8);
}
return group;
}
// ------------------------------------------------------------
// One folding market stall
// ------------------------------------------------------------
function createStall({
x,
scale,
canopyA,
canopyB,
delay
}) {
const root = new THREE.Group();
root.position.x = x;
root.scale.setScalar(scale);
scene.add(root);
const lowerLegs = [];
const feet = [];
const crossbars = [];
const scissorBars = [];
const roofPanels = [];
const valances = [];
const canopyBeams = [];
const counterBraces = [];
const products = [];
const width = 3.45;
const legX = 1.58;
const legZ = 0.77;
// Telescoping legs.
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const upper = makeMesh(
new THREE.BoxGeometry(0.16, 1.45, 0.16),
materials.silverMetal,
root
);
upper.position.set(sx * legX, 2.02, sz * legZ);
const lower = makeMesh(
new THREE.BoxGeometry(0.12, 1.5, 0.12),
materials.darkMetal,
root
);
lower.position.set(sx * legX, 1.29, sz * legZ);
const foot = makeMesh(
new THREE.BoxGeometry(0.28, 0.08, 0.25),
materials.darkMetal,
root
);
foot.position.set(sx * legX, 1.11, sz * legZ);
lowerLegs.push(lower);
feet.push(foot);
}
}
// Main frame beams that spread open during stage two.
crossbars.push({
mesh: createBeam(materials.silverMetal, 0.105, root),
type: "front"
});
crossbars.push({
mesh: createBeam(materials.silverMetal, 0.105, root),
type: "rear"
});
crossbars.push({
mesh: createBeam(materials.silverMetal, 0.105, root),
type: "left"
});
crossbars.push({
mesh: createBeam(materials.silverMetal, 0.105, root),
type: "right"
});
// Side scissor braces.
for (const side of [-1, 1]) {
for (let i = 0; i < 2; i++) {
const brace = createBeam(materials.darkMetal, 0.065, root);
scissorBars.push({ mesh: brace, side, index: i });
}
}
// Central telescoping mast.
const mastOuter = makeMesh(
new THREE.BoxGeometry(0.15, 2.15, 0.15),
materials.silverMetal,
root
);
mastOuter.position.set(0, 1.22, -0.68);
const mastInner = makeMesh(
new THREE.BoxGeometry(0.1, 1, 0.1),
materials.darkMetal,
root
);
// Eight fabric roof strips, each a dynamic low-poly sheet.
const stripeCount = 8;
const stripeWidth = width / stripeCount;
for (let i = 0; i < stripeCount; i++) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(18), 3)
);
geometry.setIndex([
0, 2, 1,
1, 2, 3,
0, 1, 4,
1, 5, 4
]);
geometry.attributes.position.setUsage(THREE.DynamicDrawUsage);
const roofMaterial = material(i % 2 === 0 ? canopyA : canopyB, {
side: THREE.DoubleSide,
roughness: 0.9
});
const panel = makeMesh(geometry, roofMaterial, root);
roofPanels.push({
mesh: panel,
geometry,
x0: -width / 2 + i * stripeWidth,
x1: -width / 2 + (i + 1) * stripeWidth
});
const frontValance = makeMesh(
new THREE.BoxGeometry(1, 0.27, 0.055),
roofMaterial,
root
);
const backValance = makeMesh(
new THREE.BoxGeometry(1, 0.2, 0.055),
roofMaterial,
root
);
valances.push({
front: frontValance,
back: backValance,
center: -width / 2 + (i + 0.5) * stripeWidth
});
}
// Ridge and roof support arms.
for (let i = 0; i < 7; i++) {
canopyBeams.push({
mesh: createBeam(materials.darkMetal, 0.055, root),
index: i
});
}
// Small hanging market sign.
const sign = new THREE.Group();
root.add(sign);
const signBoard = makeMesh(
new THREE.BoxGeometry(0.82, 0.36, 0.07),
materials.cream,
sign
);
const signEmblem = makeMesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.075, 8),
material(canopyA),
sign
);
signEmblem.rotation.x = Math.PI / 2;
signEmblem.position.z = 0.045;
// Counter folds from a vertical panel into a horizontal surface.
const counterHinge = new THREE.Group();
counterHinge.position.set(0, 1.78, 0.86);
root.add(counterHinge);
const counterTop = makeMesh(
new THREE.BoxGeometry(2.68, 0.68, 0.08),
materials.wood,
counterHinge
);
counterTop.position.y = -0.34;
const counterLip = makeMesh(
new THREE.BoxGeometry(2.68, 0.075, 0.18),
materials.darkWood,
counterHinge
);
counterLip.position.set(0, -0.67, 0.075);
for (const sx of [-1, 1]) {
counterBraces.push({
mesh: createBeam(materials.darkMetal, 0.055, root),
side: sx
});
}
// Products deliberately remain invisible during every support stage.
products.push({
object: createAppleCrate(root, -0.85, 1.18),
offset: 0
});
products.push({
object: createBottles(root, 0.02, 1.17),
offset: 0.13
});
products.push({
object: createGreens(root, 0.82, 1.27),
offset: 0.26
});
for (const item of products) {
item.object.visible = false;
item.object.scale.setScalar(0.001);
}
const stall = {
root,
delay,
lowerLegs,
feet,
crossbars,
scissorBars,
roofPanels,
valances,
canopyBeams,
mastInner,
sign,
counterHinge,
counterBraces,
products,
update(localTime) {
// 1. Legs extend.
const legProgress = smooth01(localTime / 1.7);
for (const lower of lowerLegs) {
const scale = lerp(0.28, 1, legProgress);
lower.scale.y = scale;
lower.position.y = 1.5 - 0.75 * scale;
}
for (const foot of feet) {
foot.position.y = 1.53 - 1.5 * legProgress;
}
// 2. Crossbars and side scissor braces open.
const crossProgress = smooth01((localTime - 1.7) / 1.5);
const spread = Math.max(0.0001, crossProgress);
for (const bar of crossbars) {
if (bar.type === "front" || bar.type === "rear") {
const z = bar.type === "front" ? 0.77 : -0.77;
updateBeam(
bar.mesh,
new THREE.Vector3(-1.62 * spread, 2.78, z),
new THREE.Vector3(1.62 * spread, 2.78, z)
);
} else {
const sideX = bar.type === "left" ? -1.62 : 1.62;
updateBeam(
bar.mesh,
new THREE.Vector3(sideX, 2.78, -0.77 * spread),
new THREE.Vector3(sideX, 2.78, 0.77 * spread)
);
}
}
for (const brace of scissorBars) {
const sideX = brace.side * 1.62;
let zA;
let zB;
if (brace.index === 0) {
zA = lerp(0.58, -0.72, crossProgress);
zB = lerp(0.62, 0.72, crossProgress);
} else {
zA = lerp(-0.58, 0.72, crossProgress);
zB = lerp(-0.62, -0.72, crossProgress);
}
updateBeam(
brace.mesh,
new THREE.Vector3(sideX, 2.23, zA),
new THREE.Vector3(sideX, 3.03, zB)
);
}
// 3. Canopy mast lifts and the fabric unfolds.
const canopyProgress = smooth01((localTime - 3.2) / 1.6);
const ridgeY = lerp(2.72, 3.77, canopyProgress);
const eaveY = ridgeY - 0.62 * canopyProgress;
const ridgeZ = -0.68;
const frontZ = lerp(ridgeZ, 1.35, canopyProgress);
const backZ = lerp(ridgeZ, -1.38, canopyProgress);
const roofSpread = Math.max(0.0001, canopyProgress);
const innerLength = Math.max(0.08, ridgeY - 2.12);
mastInner.scale.y = innerLength;
mastInner.position.set(0, 2.12 + innerLength / 2, ridgeZ);
const collapsedX = (base) => {
if (base === 0) return 0;
return Math.sign(base) * (0.025 + Math.abs(base) * canopyProgress);
};
for (const panel of roofPanels) {
const x0 = collapsedX(panel.x0);
const x1 = collapsedX(panel.x1);
const positions = panel.geometry.attributes.position.array;
positions.set([
x0, ridgeY, ridgeZ,
x1, ridgeY, ridgeZ,
x0, eaveY, frontZ,
x1, eaveY, frontZ,
x0, eaveY, backZ,
x1, eaveY, backZ
]);
panel.geometry.attributes.position.needsUpdate = true;
panel.geometry.computeVertexNormals();
panel.geometry.computeBoundingSphere();
}
for (const valance of valances) {
const segmentWidth = stripeWidth * roofSpread;
const x = valance.center * canopyProgress;
valance.front.scale.x = segmentWidth;
valance.front.position.set(x, eaveY - 0.135, frontZ + 0.015);
valance.back.scale.x = segmentWidth;
valance.back.position.set(x, eaveY - 0.1, backZ - 0.015);
}
// Ridge beam and four sloping canopy supports.
const halfWidth = width * 0.5 * canopyProgress;
const leftRidge = new THREE.Vector3(-halfWidth, ridgeY, ridgeZ);
const rightRidge = new THREE.Vector3(halfWidth, ridgeY, ridgeZ);
const mastTop = new THREE.Vector3(0, ridgeY, ridgeZ);
const frontLeft = new THREE.Vector3(-halfWidth, eaveY, frontZ);
const frontRight = new THREE.Vector3(halfWidth, eaveY, frontZ);
const backLeft = new THREE.Vector3(-halfWidth, eaveY, backZ);
const backRight = new THREE.Vector3(halfWidth, eaveY, backZ);
const beamEndpoints = [
[mastTop, leftRidge],
[mastTop, rightRidge],
[leftRidge, frontLeft],
[rightRidge, frontRight],
[leftRidge, backLeft],
[rightRidge, backRight]
];
beamEndpoints.forEach(([a, b], index) => {
updateBeam(canopyBeams[index].mesh, a, b);
});
sign.visible = canopyProgress > 0.03;
sign.scale.setScalar(Math.max(0.001, canopyProgress));
sign.position.set(0, eaveY - 0.36, frontZ + 0.065);
// 4. Counter unfolds down to its supported horizontal position.
const counterProgress = smooth01((localTime - 4.8) / 1.6);
counterHinge.rotation.x = -Math.PI * 0.5 * counterProgress;
for (const brace of counterBraces) {
const supportX = brace.side * 1.13;
const foldedTop = new THREE.Vector3(supportX, 1.72, 0.9);
const openTop = new THREE.Vector3(supportX, 1.68, 1.46);
const top = foldedTop.lerp(openTop, counterProgress);
updateBeam(
brace.mesh,
new THREE.Vector3(supportX, 0.12, 1.43),
top
);
}
// Products are allowed only after every support has reached 100%.
const supportReady =
legProgress >= 0.999 &&
crossProgress >= 0.999 &&
canopyProgress >= 0.999 &&
counterProgress >= 0.999;
for (const product of products) {
const q = supportReady
? clamp((localTime - 6.4 - product.offset) / 0.52, 0, 1)
: 0;
product.object.visible = q > 0;
product.object.scale.setScalar(
q > 0 ? Math.max(0.001, easeOutBack(q)) : 0.001
);
}
}
};
stall.update(-delay);
return stall;
}
// Three stalls, with slightly staggered opening sequences.
const stalls = [
createStall({
x: -4.15,
scale: 0.78,
canopyA: "#3d8178",
canopyB: "#f0d9a6",
delay: 0.9
}),
createStall({
x: 0,
scale: 1,
canopyA: "#d65d47",
canopyB: "#f3d7a2",
delay: 0
}),
createStall({
x: 4.15,
scale: 0.78,
canopyA: "#d3a039",
canopyB: "#f1d9a9",
delay: 1.65
})
];
// ------------------------------------------------------------
// Custom camera controls implemented directly in this file
// ------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.55, 0),
yaw: 0.34,
pitch: 1.12,
radius: window.innerWidth / window.innerHeight < 1 ? 22 : 16.5,
dragging: false,
pointerX: 0,
pointerY: 0,
interacted: false
};
function updateCamera() {
const sinPitch = Math.sin(controls.pitch);
camera.position.set(
controls.target.x + controls.radius * sinPitch * Math.sin(controls.yaw),
controls.target.y + controls.radius * Math.cos(controls.pitch),
controls.target.z + controls.radius * sinPitch * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.interacted = true;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.yaw -= dx * 0.006;
controls.pitch = clamp(controls.pitch + dy * 0.005, 0.58, 1.38);
updateCamera();
});
function stopDragging(event) {
controls.dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.interacted = true;
controls.radius = clamp(
controls.radius + event.deltaY * 0.012,
9,
27
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
controls.yaw = 0.34;
controls.pitch = 1.12;
controls.radius = window.innerWidth / window.innerHeight < 1 ? 22 : 16.5;
updateCamera();
});
updateCamera();
// ------------------------------------------------------------
// Timeline and interface
// ------------------------------------------------------------
const duration = 6.4;
const progressElement = document.querySelector("#progress");
const statusElement = document.querySelector("#status");
const stepElements = [...document.querySelectorAll(".step")];
const replayButton = document.querySelector("#replay");
let elapsed = 0;
let lastTime = performance.now();
replayButton.addEventListener("click", () => {
elapsed = 0;
stalls.forEach((stall) => stall.update(-stall.delay));
updateInterface(0);
});
function updateInterface(time) {
const progress = clamp(time / duration, 0, 1);
const percent = Math.round(progress * 100);
progressElement.style.width = `${percent}%`;
statusElement.textContent = `${percent}%`;
const phase = time < 1.7 ? 0 :
time < 3.2 ? 1 :
time < 4.8 ? 2 :
time < 6.4 ? 3 :
4;
stepElements.forEach((element, index) => {
element.classList.toggle("done", index < phase);
element.classList.toggle("active", index === phase && phase < 4);
});
if (time >= duration) {
statusElement.textContent = "Ready for market";
}
}
// ------------------------------------------------------------
// Animation loop
// ------------------------------------------------------------
function animate(now) {
const delta = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
elapsed += delta;
for (const stall of stalls) {
stall.update(elapsed - stall.delay);
}
if (!controls.dragging && !controls.interacted) {
controls.yaw += delta * 0.012;
updateCamera();
}
updateInterface(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
requestAnimationFrame(animate);
window.setTimeout(() => {
document.querySelector("#loading").classList.add("hidden");
}, 350);
</script>
</body>
</html>
```