Prompt specification
Build or customize the Three.js 3D scene "Shop-to-workshop conversion" 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: Shop-to-workshop conversion
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/shop-to-workshop-conversion-x0542
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Animate removable shelves leaving and worktables entering the same storefront; preserve walls, columns, and entrances so the functional change occurs within an unchanged building envelope.
Working Three.js Starter (shop-to-workshop-conversion-x0542):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Storefront Transformation</title>
<style>
:root {
--ink: #163432;
--muted: #62716c;
--paper: rgba(248, 247, 238, 0.91);
--line: rgba(22, 52, 50, 0.14);
--orange: #e8793e;
--blue: #277d91;
--green: #3e7566;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.ui > * {
pointer-events: auto;
}
.brand {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(24, 48, 43, 0.13);
backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 8px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 39px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 15px;
}
.badge {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 255, 255, 0.52);
color: #3e5752;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.badge::before {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--green);
content: "";
}
.guide {
top: 24px;
right: 24px;
padding: 11px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(248, 247, 238, 0.78);
color: var(--muted);
font-size: 11px;
line-height: 1.5;
backdrop-filter: blur(12px);
}
.guide strong {
display: block;
margin-bottom: 2px;
color: var(--ink);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.timeline {
right: 24px;
bottom: 24px;
left: 24px;
display: grid;
grid-template-columns: auto minmax(180px, 1fr) auto auto;
grid-template-areas:
"play track time buttons"
"phase phase phase buttons";
align-items: center;
gap: 12px 18px;
padding: 16px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 18px 55px rgba(24, 48, 43, 0.17);
backdrop-filter: blur(16px);
}
.play {
grid-area: play;
display: grid;
width: 45px;
height: 45px;
padding: 0;
place-items: center;
border: 0;
border-radius: 13px;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 16px;
transition: transform 150ms ease, background 150ms ease;
}
.play:hover {
background: #24514d;
transform: translateY(-1px);
}
.track {
grid-area: track;
min-width: 0;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
outline: none;
background:
linear-gradient(
to right,
var(--orange) 0%,
var(--orange) var(--progress, 0%),
rgba(22, 52, 50, 0.13) var(--progress, 0%),
rgba(22, 52, 50, 0.13) 100%
);
appearance: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
border: 3px solid white;
border-radius: 5px;
background: var(--ink);
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
appearance: none;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 5px;
background: var(--ink);
box-shadow: 0 2px 7px rgba(0, 0, 0, 0.22);
}
.track-labels {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.time {
grid-area: time;
min-width: 76px;
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 12px;
text-align: right;
}
.phase {
grid-area: phase;
color: var(--ink);
font-size: 12px;
font-weight: 750;
}
.phase::before {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 8px;
border-radius: 2px;
background: var(--orange);
content: "";
vertical-align: 1px;
}
.buttons {
grid-area: buttons;
display: flex;
gap: 7px;
}
.small-button {
min-height: 39px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.65);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
transition: background 150ms ease, transform 150ms ease;
}
.small-button:hover {
background: white;
transform: translateY(-1px);
}
.loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #dce5dd;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
}
.brand p {
display: none;
}
.guide {
display: none;
}
.timeline {
right: 12px;
bottom: 12px;
left: 12px;
grid-template-columns: auto 1fr auto;
grid-template-areas:
"play track time"
"phase phase phase"
"buttons buttons buttons";
gap: 10px;
padding: 13px;
}
.buttons {
justify-content: flex-end;
}
}
</style>
</head>
<body>
<div class="loading" id="loading">Building the storefront…</div>
<div class="ui brand">
<p class="eyebrow">Voxel Retail / Transformation 01</p>
<h1>One shell.<br />New function.</h1>
<p>
Removable shelving exits through the central entrance while modular
worktables enter the same opening. The building envelope never changes.
</p>
<div class="badges">
<span class="badge">Walls locked</span>
<span class="badge">Columns locked</span>
<span class="badge">Entrance locked</span>
</div>
</div>
<div class="ui guide">
<strong>Direct camera controls</strong>
Drag to orbit · Wheel to zoom<br />
Arrow keys to rotate · R to reset
</div>
<div class="ui timeline">
<button class="play" id="play" aria-label="Pause animation">❚❚</button>
<div class="track">
<input
id="progress"
type="range"
min="0"
max="1000"
value="0"
aria-label="Transformation timeline"
/>
<div class="track-labels">
<span>Shelves installed</span>
<span>Shared threshold</span>
<span>Worktables installed</span>
</div>
</div>
<output class="time" id="time">00:00 / 00:10</output>
<div class="phase" id="phase">Preparing the transition</div>
<div class="buttons">
<button class="small-button" id="replay">Replay</button>
<button class="small-button" id="resetCamera">Reset view</button>
</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 camera
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
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.08;
renderer.domElement.tabIndex = 0;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce5dd);
scene.fog = new THREE.Fog(0xdce5dd, 34, 68);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
120
);
const cameraState = {
target: new THREE.Vector3(0, 1.25, 0.2),
radius: 28,
theta: 0.48,
phi: 0.88
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * s * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xf5fbff, 0x766956, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d9, 3.3);
sun.position.set(-11, 18, 14);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 22;
sun.shadow.camera.bottom = -22;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 60;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8dce5, 1.25);
fill.position.set(14, 8, -12);
scene.add(fill);
// ------------------------------------------------------------
// Shared voxel construction helpers
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function standardMaterial(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
...options
});
}
function box(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(width, height, depth);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function group(parent = scene) {
const object = new THREE.Group();
parent.add(object);
return object;
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function textSprite(text, background = "#173d3a", foreground = "#fffaf0") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 96;
const context = canvas.getContext("2d");
context.fillStyle = background;
context.fillRect(0, 0, canvas.width, canvas.height);
context.fillStyle = foreground;
context.font = "700 39px monospace";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const material = new THREE.SpriteMaterial({
map: canvasTexture(canvas),
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.25, 0.42, 1);
sprite.renderOrder = 20;
return sprite;
}
// ------------------------------------------------------------
// Fixed building envelope: these objects are never animated
// ------------------------------------------------------------
const envelope = group();
envelope.name = "FIXED BUILDING ENVELOPE";
const groundMaterial = standardMaterial(0xb9c7b8);
const slabMaterial = standardMaterial(0x7d8e82);
const wallMaterial = standardMaterial(0xe7e1ce);
const wallAccentMaterial = standardMaterial(0xc9c1ad);
const capMaterial = standardMaterial(0x455d57);
const columnMaterial = standardMaterial(0x527269);
const thresholdMaterial = standardMaterial(0xe3a85d);
box(90, 0.2, 90, 0, -0.72, 0, groundMaterial, envelope, false, true);
// Interior slab and outdoor approach.
box(18.4, 0.48, 11.4, 0, -0.29, 0, slabMaterial, envelope, false, true);
box(20.2, 0.35, 9.6, 0, -0.31, 10.0, slabMaterial, envelope, false, true);
// Pixel floor tiles.
const tileMaterials = [
standardMaterial(0xd9d6c5),
standardMaterial(0xe4dfce),
standardMaterial(0xcfcbb9),
standardMaterial(0xdad5c3)
];
for (let ix = 0; ix < 18; ix++) {
for (let iz = 0; iz < 11; iz++) {
const x = -8.5 + ix;
const z = -5 + iz;
const material = tileMaterials[(ix * 3 + iz * 5) % tileMaterials.length];
box(0.96, 0.08, 0.96, x, 0, z, material, envelope, false, true);
}
}
// Outdoor approach tiles.
for (let ix = 0; ix < 12; ix++) {
for (let iz = 0; iz < 7; iz++) {
const material = tileMaterials[(ix + iz) % tileMaterials.length];
box(
0.96,
0.07,
0.96,
-5.5 + ix,
-0.095,
6 + iz,
material,
envelope,
false,
true
);
}
}
// Rear and side walls.
box(18.4, 4.6, 0.36, 0, 2.3, -5.58, wallMaterial, envelope);
box(0.36, 4.6, 11.4, -9.08, 2.3, 0, wallMaterial, envelope);
box(0.36, 4.6, 11.4, 9.08, 2.3, 0, wallMaterial, envelope);
// Front facade returns, leaving a broad central entrance.
box(5.35, 4.6, 0.42, -6.48, 2.3, 5.58, wallMaterial, envelope);
box(5.35, 4.6, 0.42, 6.48, 2.3, 5.58, wallMaterial, envelope);
// Lintel above the unchanged entrance.
box(7.75, 0.55, 0.48, 0, 4.33, 5.58, wallAccentMaterial, envelope);
// Wall caps.
box(18.65, 0.18, 0.54, 0, 4.67, -5.58, capMaterial, envelope);
box(0.54, 0.18, 11.65, -9.08, 4.67, 0, capMaterial, envelope);
box(0.54, 0.18, 11.65, 9.08, 4.67, 0, capMaterial, envelope);
box(5.55, 0.18, 0.58, -6.48, 4.67, 5.58, capMaterial, envelope);
box(5.55, 0.18, 0.58, 6.48, 4.67, 5.58, capMaterial, envelope);
// Voxel brick courses on the rear wall.
const brickMaterials = [
standardMaterial(0xddd4bd),
standardMaterial(0xe9dfc9),
standardMaterial(0xcfc5ae)
];
for (let row = 0; row < 6; row++) {
for (let column = 0; column < 19; column++) {
const offset = row % 2 === 0 ? 0 : 0.24;
const x = -8.55 + column * 0.95 + offset;
if (x > 8.75) continue;
box(
0.88,
0.62,
0.08,
x,
0.42 + row * 0.72,
-5.36,
brickMaterials[(row + column) % brickMaterials.length],
envelope,
false,
true
);
}
}
// Fixed columns framing the entrance and rear structure.
function addColumn(x, z) {
box(0.82, 0.25, 0.82, x, 0.13, z, capMaterial, envelope);
box(0.56, 4.18, 0.56, x, 2.28, z, columnMaterial, envelope);
box(0.83, 0.28, 0.83, x, 4.48, z, capMaterial, envelope);
}
addColumn(-3.66, 5.58);
addColumn(3.66, 5.58);
addColumn(-3.66, -5.22);
addColumn(3.66, -5.22);
// Clear threshold marker.
box(6.55, 0.06, 0.34, 0, 0.065, 5.58, thresholdMaterial, envelope, false, true);
// Faux storefront windows on the fixed facade.
const glassMaterial = standardMaterial(0x74aeb6, {
roughness: 0.28,
metalness: 0.05
});
box(4.0, 2.35, 0.08, -6.48, 2.25, 5.82, glassMaterial, envelope, false, false);
box(4.0, 2.35, 0.08, 6.48, 2.25, 5.82, glassMaterial, envelope, false, false);
const windowFrameMaterial = standardMaterial(0x345c5b);
for (const x of [-6.48, 6.48]) {
box(0.12, 2.55, 0.12, x, 2.25, 5.9, windowFrameMaterial, envelope);
box(4.15, 0.12, 0.12, x, 2.25, 5.9, windowFrameMaterial, envelope);
}
// Fixed shop sign.
box(7.35, 0.9, 0.18, 0, 4.64, 5.84, capMaterial, envelope);
const signCanvas = document.createElement("canvas");
signCanvas.width = 1024;
signCanvas.height = 128;
const signContext = signCanvas.getContext("2d");
signContext.fillStyle = "#173d3a";
signContext.fillRect(0, 0, 1024, 128);
signContext.fillStyle = "#fff4d8";
signContext.font = "700 54px monospace";
signContext.textAlign = "center";
signContext.textBaseline = "middle";
signContext.fillText("MORPH / WORKSPACE", 512, 68);
const signMaterial = new THREE.MeshBasicMaterial({
map: canvasTexture(signCanvas)
});
const sign = new THREE.Mesh(new THREE.PlaneGeometry(6.85, 0.62), signMaterial);
sign.position.set(0, 4.64, 5.94);
envelope.add(sign);
// ------------------------------------------------------------
// Fixed interior details
// ------------------------------------------------------------
const fixedDetails = group();
fixedDetails.name = "FIXED INTERIOR";
const darkWood = standardMaterial(0x745a43);
const lightWood = standardMaterial(0xbc9362);
const pegboard = standardMaterial(0x658a76);
const cream = standardMaterial(0xf2e8cf);
const teal = standardMaterial(0x3d7770);
// Rear service counter.
box(4.5, 1.35, 1.2, 5.65, 0.68, -4.35, darkWood, fixedDetails);
box(4.75, 0.18, 1.42, 5.65, 1.43, -4.35, lightWood, fixedDetails);
box(1.2, 0.42, 0.75, 6.35, 1.73, -4.28, teal, fixedDetails);
// Wall-mounted pegboard and small tools.
box(5.4, 2.2, 0.12, 5.55, 2.72, -5.34, pegboard, fixedDetails);
for (let i = 0; i < 7; i++) {
box(
0.14,
0.55 + (i % 3) * 0.18,
0.12,
3.55 + i * 0.67,
2.7 + (i % 2) * 0.12,
-5.21,
i % 2 === 0 ? cream : lightWood,
fixedDetails
);
}
// A small voxel plant.
box(0.68, 0.65, 0.68, 7.65, 0.33, -3.85, lightWood, fixedDetails);
box(0.14, 1.05, 0.14, 7.65, 1.1, -3.85, darkWood, fixedDetails);
box(0.8, 0.22, 0.7, 7.65, 1.52, -3.85, teal, fixedDetails);
box(0.55, 0.22, 0.52, 7.45, 1.72, -3.85, standardMaterial(0x6d9b67), fixedDetails);
// ------------------------------------------------------------
// Removable shelving
// ------------------------------------------------------------
function createShelf(label, seed = 0) {
const shelf = group();
shelf.name = "REMOVABLE SHELF";
const frame = standardMaterial(0x375d5b, {
roughness: 0.55,
metalness: 0.22
});
const boards = standardMaterial(0xbb8b5e);
const packages = [
standardMaterial(0xe47643),
standardMaterial(0xe0b858),
standardMaterial(0x5e9a8e),
standardMaterial(0x6f829d)
];
// Four uprights.
for (const x of [-1.04, 1.04]) {
for (const z of [-0.46, 0.46]) {
box(0.13, 3.05, 0.13, x, 1.57, z, frame, shelf);
}
}
// Shelf boards.
for (const y of [0.25, 1.05, 1.85, 2.65]) {
box(2.22, 0.13, 1.08, 0, y, 0, boards, shelf);
}
// Colored packages and bins.
const levels = [0.34, 1.14, 1.94];
for (let level = 0; level < levels.length; level++) {
for (let item = 0; item < 3; item++) {
const width = 0.42 + ((item + seed) % 2) * 0.08;
const height = 0.38 + ((item + level + seed) % 3) * 0.11;
const x = -0.69 + item * 0.68;
const z = ((item + seed) % 2) * 0.15 - 0.08;
box(
width,
height,
0.68,
x,
levels[level] + height / 2,
z,
packages[(item + level + seed) % packages.length],
shelf
);
box(
width * 0.52,
0.055,
0.025,
x,
levels[level] + height * 0.62,
z + 0.35,
cream,
shelf,
false,
false
);
}
}
// Top marker.
box(1.45, 0.18, 0.08, 0, 3.12, 0.42, packages[seed % packages.length], shelf);
const sprite = textSprite(label, "#a94f2f");
sprite.position.set(0, 3.65, 0);
shelf.add(sprite);
return shelf;
}
const shelfA = createShelf("REMOVE 01", 0);
const shelfB = createShelf("REMOVE 02", 2);
// ------------------------------------------------------------
// Incoming worktables
// ------------------------------------------------------------
function createWorktable(label, accentColor, seed = 0) {
const table = group();
table.name = "INCOMING WORKTABLE";
const frame = standardMaterial(0x3e5e5b, {
roughness: 0.5,
metalness: 0.28
});
const wood = standardMaterial(0xbd8e5b);
const accent = standardMaterial(accentColor);
const tool = standardMaterial(0xdbd7c6);
const dark = standardMaterial(0x394644);
// Three voxel planks form the worktop.
for (let i = -1; i <= 1; i++) {
box(0.96, 0.18, 1.68, i * 0.98, 1.42, 0, wood, table);
}
// Legs and lower braces.
for (const x of [-1.22, 1.22]) {
for (const z of [-0.58, 0.58]) {
box(0.16, 1.34, 0.16, x, 0.68, z, frame, table);
}
}
box(2.55, 0.13, 0.13, 0, 0.48, -0.58, frame, table);
box(2.55, 0.13, 0.13, 0, 0.48, 0.58, frame, table);
// Toolbox.
box(0.72, 0.34, 0.52, 0.64, 1.69, 0.25, accent, table);
box(0.36, 0.07, 0.08, 0.64, 1.91, 0.25, dark, table);
box(0.08, 0.16, 0.08, 0.48, 2.0, 0.25, dark, table);
box(0.08, 0.16, 0.08, 0.8, 2.0, 0.25, dark, table);
// Small vise and material blocks.
box(0.44, 0.26, 0.42, -0.76, 1.64, -0.3, tool, table);
box(0.13, 0.39, 0.13, -0.76, 1.78, -0.3, accent, table);
box(0.55, 0.18, 0.55, -0.2, 1.61, 0.42, accent, table);
box(0.46, 0.18, 0.46, -0.2, 1.79, 0.42, wood, table);
// Small wheel on the end.
box(0.12, 0.55, 0.12, 1.43, 0.58, 0.58, frame, table);
box(0.23, 0.38, 0.38, 1.43, 0.27, 0.58, dark, table);
const sprite = textSprite(label, "#216a7a");
sprite.position.set(0, 2.45, 0);
table.add(sprite);
return table;
}
const tableA = createWorktable("TABLE 01", 0xe8793e, 0);
const tableB = createWorktable("TABLE 02", 0x2f8798, 1);
// ------------------------------------------------------------
// Directional voxel arrows on the shared threshold
// ------------------------------------------------------------
function createArrow(x, z, direction, color) {
const arrow = group();
const material = standardMaterial(color, {
transparent: true,
opacity: 0.78,
depthWrite: false
});
box(0.2, 0.05, 1.15, 0, 0, -0.22, material, arrow, false, false);
box(1.02, 0.05, 0.22, 0, 0, 0.48, material, arrow, false, false);
box(0.68, 0.05, 0.22, 0, 0, 0.69, material, arrow, false, false);
box(0.34, 0.05, 0.22, 0, 0, 0.9, material, arrow, false, false);
arrow.position.set(x, 0.11, z);
arrow.rotation.y = direction > 0 ? 0 : Math.PI;
return arrow;
}
const outgoingArrow = createArrow(-1.35, 8.2, 1, 0xe8793e);
const incomingArrow = createArrow(1.15, 8.2, -1, 0x277d91);
// ------------------------------------------------------------
// Animation helpers
// ------------------------------------------------------------
const clamp01 = value => Math.min(1, Math.max(0, value));
function smooth01(value) {
const t = clamp01(value);
return t * t * (3 - 2 * t);
}
function lerp(a, b, t) {
return a + (b - a) * t;
}
function collectFadeMaterials(object) {
const materials = new Set();
object.traverse(child => {
if (!child.material) return;
const list = Array.isArray(child.material)
? child.material
: [child.material];
list.forEach(material => materials.add(material));
});
return [...materials].map(material => ({
material,
baseOpacity: material.opacity
}));
}
const shelfAFade = collectFadeMaterials(shelfA);
const shelfBFade = collectFadeMaterials(shelfB);
function setGroupOpacity(object, fadeEntries, opacity) {
object.visible = opacity > 0.005;
fadeEntries.forEach(entry => {
entry.material.opacity = entry.baseOpacity * opacity;
entry.material.transparent = true;
entry.material.depthWrite = opacity > 0.98;
});
}
function updateTransition(progress) {
const p = clamp01(progress);
// Shelf A: align in the aisle, then leave through the left half
// of the central storefront opening.
const shelfAPrepare = smooth01(p / 0.2);
shelfA.position.x = lerp(-5.4, -1.35, shelfAPrepare);
shelfA.position.z =
p < 0.16
? lerp(-2.8, -2.25, smooth01(p / 0.16))
: lerp(-2.25, 11.2, smooth01((p - 0.16) / 0.31));
shelfA.rotation.y = lerp(0.12, 0, shelfAPrepare);
const shelfAFadeAmount = 1 - smooth01((p - 0.48) / 0.1);
setGroupOpacity(shelfA, shelfAFade, shelfAFadeAmount);
// Shelf B follows through the same opening.
const shelfBPrepare = smooth01((p - 0.06) / 0.18);
shelfB.position.x = lerp(-2.7, -1.08, shelfBPrepare);
shelfB.position.z =
p < 0.22
? lerp(-0.25, -1.0, smooth01((p - 0.06) / 0.16))
: lerp(-1.0, 11.7, smooth01((p - 0.21) / 0.33));
shelfB.rotation.y = lerp(-0.06, 0.015, shelfBPrepare);
const shelfBFadeAmount = 1 - smooth01((p - 0.55) / 0.1);
setGroupOpacity(shelfB, shelfBFade, shelfBFadeAmount);
// Worktable A enters from outside, crosses the threshold while
// aligned with the opening, and only then fans out inside.
const tableACross = smooth01((p - 0.46) / 0.18);
const tableASettle = smooth01((p - 0.63) / 0.25);
tableA.position.x = lerp(1.15, -2.55, tableASettle);
tableA.position.z =
tableASettle > 0
? lerp(3.2, -1.9, tableASettle)
: lerp(11.5, 3.2, tableACross);
tableA.rotation.y = lerp(0, 0.035, tableASettle);
// Worktable B follows through the same central storefront.
const tableBCross = smooth01((p - 0.52) / 0.18);
const tableBSettle = smooth01((p - 0.69) / 0.26);
tableB.position.x = lerp(1.75, 2.8, tableBSettle);
tableB.position.z =
tableBSettle > 0
? lerp(3.2, -1.7, tableBSettle)
: lerp(13.8, 3.2, tableBCross);
tableB.rotation.y = lerp(0, -0.025, tableBSettle);
// Subtle threshold pulse.
const pulse = 0.58 + Math.sin(p * Math.PI * 14) * 0.14;
outgoingArrow.children.forEach(child => {
child.material.opacity = pulse;
});
incomingArrow.children.forEach(child => {
child.material.opacity = pulse;
});
}
// ------------------------------------------------------------
// Timeline UI
// ------------------------------------------------------------
const DURATION = 10;
const state = {
progress: 0,
playing: true,
lastTimestamp: performance.now()
};
const playButton = document.getElementById("play");
const progressInput = document.getElementById("progress");
const timeOutput = document.getElementById("time");
const phaseOutput = document.getElementById("phase");
const replayButton = document.getElementById("replay");
const resetCameraButton = document.getElementById("resetCamera");
function getPhase(progress) {
if (progress < 0.08) return "Existing storefront layout";
if (progress < 0.2) return "Clearing and aligning removable shelves";
if (progress < 0.46) return "Removable shelves leaving the building";
if (progress < 0.64) return "Exchanging layouts at the shared entrance";
if (progress < 0.86) return "Worktables entering the storefront";
if (progress < 0.98) return "Positioning the new worktables";
return "Transformation complete · envelope unchanged";
}
function updateUI() {
const percentage = state.progress * 100;
progressInput.value = Math.round(state.progress * 1000);
progressInput.style.setProperty("--progress", `${percentage}%`);
const seconds = state.progress * DURATION;
timeOutput.value = `00:${String(Math.floor(seconds)).padStart(2, "0")} / 00:10`;
phaseOutput.textContent = getPhase(state.progress);
}
function togglePlayback() {
if (state.progress >= 0.999) {
state.progress = 0;
state.playing = true;
} else {
state.playing = !state.playing;
}
playButton.textContent = state.playing ? "❚❚" : "▶";
playButton.setAttribute(
"aria-label",
state.playing ? "Pause animation" : "Play animation"
);
}
playButton.addEventListener("click", togglePlayback);
progressInput.addEventListener("input", event => {
state.progress = Number(event.target.value) / 1000;
state.playing = false;
playButton.textContent = "▶";
playButton.setAttribute("aria-label", "Play animation");
});
replayButton.addEventListener("click", () => {
state.progress = 0;
state.playing = true;
playButton.textContent = "❚❚";
playButton.setAttribute("aria-label", "Pause animation");
});
function resetCamera() {
cameraState.target.set(0, 1.25, 0.2);
cameraState.radius = 28;
cameraState.theta = 0.48;
cameraState.phi = 0.88;
updateCamera();
}
resetCameraButton.addEventListener("click", resetCamera);
// ------------------------------------------------------------
// Direct orbit, zoom and keyboard camera controls
// ------------------------------------------------------------
const pointer = {
active: false,
id: null,
previousX: 0,
previousY: 0
};
renderer.domElement.addEventListener("pointerdown", event => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.previousX = event.clientX;
pointer.previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const deltaX = event.clientX - pointer.previousX;
const deltaY = event.clientY - pointer.previousY;
pointer.previousX = event.clientX;
pointer.previousY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = Math.min(
1.3,
Math.max(0.3, cameraState.phi + deltaY * 0.005)
);
updateCamera();
});
function releasePointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
renderer.domElement.style.cursor = "grab";
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = Math.min(
42,
Math.max(16, cameraState.radius * Math.exp(event.deltaY * 0.001))
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", event => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.08;
break;
case "ArrowRight":
cameraState.theta -= 0.08;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.3, cameraState.phi - 0.06);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.3, cameraState.phi + 0.06);
break;
case "r":
case "R":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// ------------------------------------------------------------
// Main loop
// ------------------------------------------------------------
updateTransition(0);
updateUI();
function animate(timestamp) {
const delta = Math.min((timestamp - state.lastTimestamp) / 1000, 0.05);
state.lastTimestamp = timestamp;
if (state.playing) {
state.progress = Math.min(1, state.progress + delta / DURATION);
if (state.progress >= 1) {
state.playing = false;
playButton.textContent = "▶";
playButton.setAttribute("aria-label", "Replay animation");
}
}
updateTransition(state.progress);
updateUI();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```