Prompt specification
Build or customize the Three.js 3D scene "Seedling nursery greenhouse aisle" 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: Seedling nursery greenhouse aisle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/seedling-nursery-greenhouse-aisle-x1071
Scene Description Prompt:
Build an HTML scene with Three.js from cdnjs featuring a voxel greenhouse, tray-carrying workers, changing sunlight, roof vents, and a clear aisle.
Working Three.js Starter (seedling-nursery-greenhouse-aisle-x1071):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Voxel Greenhouse</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(17, 38, 31, 0.82);
--panel-border: rgba(211, 242, 219, 0.18);
--text: #eef9ef;
--muted: #a9c3b1;
--accent: #b8e36d;
--warm: #ffc56d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #9fcddd;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 42%, transparent 45%, rgba(12, 29, 24, 0.2)),
linear-gradient(to bottom, rgba(16, 38, 31, 0.04), rgba(10, 25, 20, 0.18));
z-index: 2;
}
.ui {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.title-block {
position: absolute;
top: 24px;
left: 24px;
max-width: min(430px, calc(100vw - 48px));
padding: 17px 20px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 16px;
box-shadow: 0 14px 45px rgba(13, 35, 27, 0.22);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
background: var(--accent);
border-radius: 2px;
box-shadow: 0 0 13px rgba(184, 227, 109, 0.7);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
line-height: 1;
letter-spacing: -0.045em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.badges {
display: flex;
flex-wrap: wrap;
gap: 7px;
margin-top: 14px;
}
.badge {
padding: 6px 9px;
color: #d8ecd9;
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 7px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
width: 286px;
padding: 16px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 16px;
box-shadow: 0 14px 45px rgba(13, 35, 27, 0.22);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.control-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
display: inline-block;
width: 7px;
height: 7px;
margin-right: 7px;
background: var(--accent);
border-radius: 50%;
animation: pulse 1.8s infinite;
}
@keyframes pulse {
50% {
opacity: 0.35;
}
}
.control-row {
margin-top: 15px;
}
.control-label {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 8px;
color: #dceadd;
font-size: 12px;
font-weight: 650;
}
.value {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
background: rgba(255, 255, 255, 0.14);
border-radius: 99px;
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
background: var(--accent);
border: 3px solid #eef9ef;
border-radius: 50%;
box-shadow: 0 2px 9px rgba(0, 0, 0, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
background: var(--accent);
border: 3px solid #eef9ef;
border-radius: 50%;
box-shadow: 0 2px 9px rgba(0, 0, 0, 0.3);
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
button {
min-height: 38px;
padding: 8px 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.07);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 9px;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
transform: translateY(-1px);
}
button[aria-pressed="true"] {
color: #18261c;
background: var(--accent);
border-color: var(--accent);
}
.hint {
position: absolute;
left: 24px;
bottom: 24px;
display: flex;
align-items: center;
gap: 10px;
padding: 10px 13px;
color: #e7f4e7;
background: rgba(17, 38, 31, 0.75);
border: 1px solid var(--panel-border);
border-radius: 10px;
backdrop-filter: blur(12px);
font-size: 11px;
font-weight: 650;
}
.mouse-icon {
position: relative;
width: 15px;
height: 21px;
border: 1.5px solid var(--accent);
border-radius: 8px;
}
.mouse-icon::after {
content: "";
position: absolute;
top: 4px;
left: 5px;
width: 2px;
height: 5px;
background: var(--accent);
border-radius: 2px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: #eaf7e9;
background: #173429;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-block {
top: 12px;
left: 12px;
right: 12px;
max-width: none;
padding: 14px 16px;
}
.subtitle,
.badges {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
width: min(286px, calc(100vw - 24px));
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel greenhouse"></canvas>
<div class="vignette"></div>
<div class="ui">
<section class="title-block">
<div class="eyebrow">Living systems lab</div>
<h1>Solstice House</h1>
<p class="subtitle">
A working voxel greenhouse with crop beds, tray-carrying growers,
articulated roof vents, and a continuously changing sun.
</p>
<div class="badges">
<span class="badge">3 growers</span>
<span class="badge">12 crop beds</span>
<span class="badge">Clear central aisle</span>
</div>
</section>
<section class="controls" aria-label="Scene controls">
<div class="control-heading">
<span><span class="live-dot"></span>Environment</span>
<span id="timeReadout">10:00</span>
</div>
<div class="control-row">
<label class="control-label" for="sunSlider">
<span>Sun elevation</span>
<span class="value" id="sunValue">42°</span>
</label>
<input
id="sunSlider"
type="range"
min="10"
max="80"
value="42"
step="1"
/>
</div>
<div class="control-row">
<label class="control-label" for="ventSlider">
<span>Roof vents</span>
<span class="value" id="ventValue">38%</span>
</label>
<input
id="ventSlider"
type="range"
min="0"
max="100"
value="38"
step="1"
/>
</div>
<div class="button-row">
<button id="cycleButton" type="button" aria-pressed="true">
Cycle daylight
</button>
<button id="resetButton" type="button">Reset camera</button>
</div>
</section>
<div class="hint">
<span class="mouse-icon"></span>
<span>Drag to orbit · Scroll or pinch to zoom</span>
</div>
</div>
<div id="loading">Growing the greenhouse…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const sunSlider = document.querySelector("#sunSlider");
const ventSlider = document.querySelector("#ventSlider");
const sunValue = document.querySelector("#sunValue");
const ventValue = document.querySelector("#ventValue");
const timeReadout = document.querySelector("#timeReadout");
const cycleButton = document.querySelector("#cycleButton");
const resetButton = document.querySelector("#resetButton");
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
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.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xa9d6e2);
scene.fog = new THREE.Fog(0xa9d6e2, 52, 100);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
180
);
const clock = new THREE.Clock();
// Shared geometry keeps the voxel construction inexpensive.
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function getMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBeam(parent, start, end, thickness, material) {
const a = new THREE.Vector3(...start);
const b = new THREE.Vector3(...end);
const direction = b.clone().sub(a);
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const beam = new THREE.Mesh(unitBox, material);
beam.scale.set(thickness, thickness, direction.length());
beam.position.copy(midpoint);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
direction.clone().normalize()
);
beam.castShadow = true;
beam.receiveShadow = true;
parent.add(beam);
return beam;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xe9f8ff, 0x526440, 1.25);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xfff2d2, 3.1);
sunLight.position.set(-25, 35, 22);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -20;
sunLight.shadow.camera.right = 20;
sunLight.shadow.camera.top = 20;
sunLight.shadow.camera.bottom = -20;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 100;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.035;
scene.add(sunLight);
scene.add(sunLight.target);
const sunMesh = new THREE.Mesh(
new THREE.BoxGeometry(3.5, 3.5, 3.5),
new THREE.MeshBasicMaterial({
color: 0xffdf78,
fog: false
})
);
scene.add(sunMesh);
// -------------------------------------------------------------------------
// Ground, aisle, and crop beds
// -------------------------------------------------------------------------
const concreteMat = getMaterial(0x8e9b8f);
const groundMat = getMaterial(0x789070);
const pathMat = getMaterial(0xb6b7a8);
const pathEdgeMat = getMaterial(0x56785d);
const benchMat = getMaterial(0x556f58);
const soilMat = getMaterial(0x4e382a);
const pipeMat = getMaterial(0x334b40);
const frameMat = getMaterial(0x2b5a43);
const frameHighlightMat = getMaterial(0x4d8060);
addBox(scene, [70, 0.5, 70], [0, -0.72, 0], groundMat, false);
addBox(scene, [18.7, 0.48, 27], [0, -0.31, 0], concreteMat, false);
// A broad, obstacle-free central aisle.
addBox(scene, [4.4, 0.11, 24.3], [0, 0.005, 0], pathMat, false);
for (const x of [-2.12, 2.12]) {
addBox(scene, [0.1, 0.08, 24.1], [x, 0.09, 0], pathEdgeMat, false);
}
// Subtle paving seams help communicate the aisle's direction.
for (let z = -11; z <= 11; z += 2) {
addBox(scene, [4.12, 0.025, 0.045], [0, 0.075, z], concreteMat, false);
}
const plantRecords = [];
let randomSeed = 431;
function random() {
randomSeed = (randomSeed * 16807) % 2147483647;
return (randomSeed - 1) / 2147483646;
}
const bedCenters = [];
for (const side of [-1, 1]) {
for (let row = 0; row < 6; row++) {
const z = -9 + row * 3.6;
const x = side * 5.15;
bedCenters.push([x, z]);
addBox(scene, [4.8, 0.5, 3], [x, 0.38, z], benchMat);
addBox(scene, [4.5, 0.12, 2.72], [x, 0.68, z], soilMat);
for (const dx of [-1.85, 1.85]) {
for (const dz of [-1.12, 1.12]) {
addBox(
scene,
[0.22, 0.28, 0.22],
[x + dx, 0.16, z + dz],
frameMat
);
}
}
// Voxel irrigation pipe.
addBox(scene, [0.08, 0.08, 2.65], [x - 1.95, 0.83, z], pipeMat);
for (const dx of [-1.45, 0, 1.45]) {
for (const dz of [-0.68, 0.68]) {
plantRecords.push({
x: x + dx + (random() - 0.5) * 0.08,
z: z + dz + (random() - 0.5) * 0.08,
hue: random(),
fruit: random() > 0.78
});
}
}
}
}
// Instanced voxel foliage: one stem and two leaf blocks per plant.
const plantMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9
});
const plantMesh = new THREE.InstancedMesh(
unitBox,
plantMaterial,
plantRecords.length * 3
);
plantMesh.castShadow = true;
plantMesh.receiveShadow = true;
const dummy = new THREE.Object3D();
const greenA = new THREE.Color(0x3f8f45);
const greenB = new THREE.Color(0x67ad4e);
const greenC = new THREE.Color(0x94c957);
const fruitColor = new THREE.Color(0xf3a33d);
let instanceIndex = 0;
for (const plant of plantRecords) {
dummy.position.set(plant.x, 1.09, plant.z);
dummy.scale.set(0.13, 0.72, 0.13);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
plantMesh.setMatrixAt(instanceIndex, dummy.matrix);
plantMesh.setColorAt(instanceIndex, greenA);
instanceIndex++;
const leafColor = plant.hue > 0.62 ? greenC : greenB;
dummy.position.set(plant.x - 0.23, 1.29, plant.z);
dummy.scale.set(0.5, 0.31, 0.49);
dummy.rotation.y = plant.hue * 1.8;
dummy.updateMatrix();
plantMesh.setMatrixAt(instanceIndex, dummy.matrix);
plantMesh.setColorAt(instanceIndex, leafColor);
instanceIndex++;
if (plant.fruit) {
dummy.position.set(plant.x + 0.23, 1.25, plant.z + 0.08);
dummy.scale.set(0.25, 0.25, 0.25);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
plantMesh.setMatrixAt(instanceIndex, dummy.matrix);
plantMesh.setColorAt(instanceIndex, fruitColor);
} else {
dummy.position.set(plant.x + 0.23, 1.29, plant.z);
dummy.scale.set(0.5, 0.31, 0.49);
dummy.rotation.y = plant.hue * 2.2 + 0.4;
dummy.updateMatrix();
plantMesh.setMatrixAt(instanceIndex, dummy.matrix);
plantMesh.setColorAt(instanceIndex, leafColor);
}
instanceIndex++;
}
plantMesh.instanceMatrix.needsUpdate = true;
if (plantMesh.instanceColor) {
plantMesh.instanceColor.needsUpdate = true;
}
scene.add(plantMesh);
// -------------------------------------------------------------------------
// Greenhouse structure and glass
// -------------------------------------------------------------------------
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0xc6edf0,
transparent: true,
opacity: 0.13,
roughness: 0.18,
metalness: 0.02,
depthWrite: false,
side: THREE.DoubleSide
});
const HALF_WIDTH = 8;
const HALF_LENGTH = 12;
const EAVE_HEIGHT = 6.4;
const RIDGE_HEIGHT = 9;
const ROOF_ANGLE = Math.atan2(
RIDGE_HEIGHT - EAVE_HEIGHT,
HALF_WIDTH
);
const postPositions = [-12, -8, -4, 0, 4, 8, 12];
for (const z of postPositions) {
for (const side of [-1, 1]) {
addBox(
scene,
[0.23, EAVE_HEIGHT, 0.23],
[side * HALF_WIDTH, EAVE_HEIGHT / 2, z],
frameMat
);
}
// Gabled rafters.
addBeam(
scene,
[-HALF_WIDTH, EAVE_HEIGHT, z],
[0, RIDGE_HEIGHT, z],
0.22,
frameMat
);
addBeam(
scene,
[0, RIDGE_HEIGHT, z],
[HALF_WIDTH, EAVE_HEIGHT, z],
0.22,
frameMat
);
}
// Side rails.
for (const side of [-1, 1]) {
for (const y of [0.2, 3.2, EAVE_HEIGHT]) {
addBox(
scene,
[0.2, 0.2, 24.25],
[side * HALF_WIDTH, y, 0],
frameMat
);
}
}
// Long roof purlins.
for (const x of [-8, -4, 0, 4, 8]) {
const roofY = RIDGE_HEIGHT - Math.abs(x) * Math.tan(ROOF_ANGLE);
addBox(
scene,
[0.15, 0.15, 24.3],
[x, roofY, 0],
x === 0 ? frameHighlightMat : frameMat
);
}
// Side glass panels.
for (const side of [-1, 1]) {
for (let i = 0; i < 6; i++) {
const z = -10 + i * 4;
addBox(
scene,
[0.055, 6.15, 3.84],
[side * HALF_WIDTH, 3.2, z],
glassMaterial,
false
);
}
}
// Roof glass panels.
for (const side of [-1, 1]) {
for (let i = 0; i < 6; i++) {
const z = -10 + i * 4;
const panel = addBox(
scene,
[8.3, 0.055, 3.84],
[side * 4, 7.7, z],
glassMaterial,
false
);
panel.rotation.z = -side * ROOF_ANGLE;
}
}
// End walls, with a clear central doorway in the front.
for (const z of [-HALF_LENGTH, HALF_LENGTH]) {
for (const side of [-1, 1]) {
addBox(
scene,
[5.85, 6.15, 0.055],
[side * 5, 3.2, z],
glassMaterial,
false
);
addBox(
scene,
[0.22, EAVE_HEIGHT, 0.24],
[side * 2.08, EAVE_HEIGHT / 2, z],
frameMat
);
}
addBox(scene, [16, 0.22, 0.24], [0, EAVE_HEIGHT, z], frameMat);
addBox(
scene,
[14.2, 1.15, 0.055],
[0, 7.03, z],
glassMaterial,
false
);
// Small voxel braces.
addBeam(
scene,
[-7.8, 0.3, z],
[-2.2, 6.2, z],
0.11,
frameHighlightMat
);
addBeam(
scene,
[7.8, 0.3, z],
[2.2, 6.2, z],
0.11,
frameHighlightMat
);
}
// Entrance header.
addBox(scene, [4.4, 0.24, 0.28], [0, 4.25, 12], frameHighlightMat);
// Open glass door, rotated away from the entrance.
const doorPivot = new THREE.Group();
doorPivot.position.set(-2.05, 0, 12);
doorPivot.rotation.y = -0.72;
scene.add(doorPivot);
addBox(
doorPivot,
[3.8, 4.1, 0.055],
[1.9, 2.05, 0],
glassMaterial,
false
);
addBox(doorPivot, [0.16, 4.2, 0.18], [0, 2.1, 0], frameMat);
addBox(doorPivot, [3.9, 0.16, 0.18], [1.9, 4.15, 0], frameMat);
addBox(doorPivot, [3.9, 0.16, 0.18], [1.9, 0.05, 0], frameMat);
addBox(doorPivot, [0.16, 4.2, 0.18], [3.8, 2.1, 0], frameMat);
// -------------------------------------------------------------------------
// Articulated roof vents
// -------------------------------------------------------------------------
const vents = [];
const ventFrameMat = getMaterial(0x73926f);
const ventGlassMaterial = new THREE.MeshStandardMaterial({
color: 0xe4ffff,
transparent: true,
opacity: 0.24,
roughness: 0.12,
depthWrite: false,
side: THREE.DoubleSide
});
for (const side of [-1, 1]) {
for (const z of [-6, 6]) {
const pivot = new THREE.Group();
pivot.position.set(0, RIDGE_HEIGHT, z);
scene.add(pivot);
const body = new THREE.Group();
body.position.x = side * 1.55;
pivot.add(body);
addBox(
body,
[2.9, 0.055, 3.2],
[0, 0, 0],
ventGlassMaterial,
false
);
addBox(body, [3.08, 0.14, 0.12], [0, 0, -1.6], ventFrameMat);
addBox(body, [3.08, 0.14, 0.12], [0, 0, 1.6], ventFrameMat);
addBox(body, [0.12, 0.14, 3.2], [-1.48, 0, 0], ventFrameMat);
addBox(body, [0.12, 0.14, 3.2], [1.48, 0, 0], ventFrameMat);
const baseAngle = -side * ROOF_ANGLE;
pivot.rotation.z = baseAngle;
vents.push({
pivot,
side,
baseAngle
});
}
}
// -------------------------------------------------------------------------
// Tray-carrying voxel workers
// -------------------------------------------------------------------------
const workers = [];
const skinMaterials = [0xd79b71, 0xa96845, 0xe4b38c];
const shirtMaterials = [0xe9a743, 0x4f91a1, 0xd46c54];
const trouserMaterials = [0x33485c, 0x48516a, 0x3b574e];
function makeWorker(index) {
const group = new THREE.Group();
const shirt = getMaterial(shirtMaterials[index]);
const trousers = getMaterial(trouserMaterials[index]);
const skin = getMaterial(skinMaterials[index]);
const boot = getMaterial(0x27312d);
const hat = getMaterial(0xf2c84c);
const trayMat = getMaterial(0x9a6c43);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.19, 0.75, 0);
rightLeg.position.set(0.19, 0.75, 0);
group.add(leftLeg, rightLeg);
addBox(leftLeg, [0.23, 0.48, 0.24], [0, -0.22, 0], trousers);
addBox(rightLeg, [0.23, 0.48, 0.24], [0, -0.22, 0], trousers);
addBox(leftLeg, [0.27, 0.18, 0.38], [0, -0.49, 0.07], boot);
addBox(rightLeg, [0.27, 0.18, 0.38], [0, -0.49, 0.07], boot);
addBox(group, [0.72, 0.72, 0.43], [0, 1.17, 0], shirt);
addBox(group, [0.76, 0.08, 0.47], [0, 1.14, 0], hat);
addBox(group, [0.43, 0.43, 0.42], [0, 1.82, 0], skin);
addBox(group, [0.55, 0.2, 0.49], [0, 2.07, 0], hat);
addBox(group, [0.64, 0.07, 0.58], [0, 1.99, 0.02], hat);
// Tiny face and reflective vest stripe.
addBox(group, [0.05, 0.05, 0.035], [-0.1, 1.86, 0.225], getMaterial(0x25302c));
addBox(group, [0.05, 0.05, 0.035], [0.1, 1.86, 0.225], getMaterial(0x25302c));
addBox(group, [0.1, 0.46, 0.025], [0, 1.2, 0.225], getMaterial(0xece6a7));
// Arms reach forward to the carried tray.
addBeam(
group,
[-0.43, 1.47, 0.04],
[-0.3, 1.14, 0.58],
0.14,
shirt
);
addBeam(
group,
[0.43, 1.47, 0.04],
[0.3, 1.14, 0.58],
0.14,
shirt
);
const tray = new THREE.Group();
tray.position.set(0, 1.12, 0.7);
group.add(tray);
addBox(tray, [1.48, 0.1, 0.9], [0, 0, 0], trayMat);
addBox(tray, [1.5, 0.16, 0.08], [0, 0.08, -0.44], trayMat);
addBox(tray, [1.5, 0.16, 0.08], [0, 0.08, 0.44], trayMat);
for (const x of [-0.48, 0, 0.48]) {
for (const z of [-0.2, 0.2]) {
addBox(tray, [0.08, 0.29, 0.08], [x, 0.19, z], getMaterial(0x4c7138));
addBox(
tray,
[0.3, 0.18, 0.3],
[x, 0.34, z],
getMaterial(x === 0 ? 0x76b84e : 0x4f9945)
);
}
}
scene.add(group);
const worker = {
group,
leftLeg,
rightLeg,
direction: index === 1 ? -1 : 1,
speed: 0.72 + index * 0.11,
phase: index * 2.1
};
group.position.z = [-7.3, 0.8, 7.2][index];
group.rotation.y = worker.direction > 0 ? 0 : Math.PI;
workers.push(worker);
}
makeWorker(0);
makeWorker(1);
makeWorker(2);
// -------------------------------------------------------------------------
// Voxel clouds
// -------------------------------------------------------------------------
const clouds = [];
const cloudMaterial = new THREE.MeshStandardMaterial({
color: 0xf4f6e8,
roughness: 1,
transparent: true,
opacity: 0.82,
depthWrite: false
});
const cloudData = [
[-28, 19, -12, 1.2],
[22, 23, -25, 0.9],
[30, 17, 18, 1.1],
[-18, 24, 29, 0.8],
[3, 27, -38, 1.25],
[-39, 18, 8, 0.75]
];
for (const [x, y, z, scale] of cloudData) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addBox(cloud, [3.4, 1, 1.5], [0, 0, 0], cloudMaterial, false);
addBox(cloud, [1.8, 1.5, 1.6], [-1.2, 0.4, 0], cloudMaterial, false);
addBox(cloud, [2, 1.8, 1.5], [0.3, 0.55, 0], cloudMaterial, false);
addBox(cloud, [1.4, 1.1, 1.4], [1.7, 0.1, 0], cloudMaterial, false);
scene.add(cloud);
clouds.push(cloud);
}
// -------------------------------------------------------------------------
// Environment controls
// -------------------------------------------------------------------------
let autoSun = true;
let manualSunElevation = Number(sunSlider.value);
let ventTarget = Number(ventSlider.value) / 100;
let ventPosition = ventTarget;
let sunAzimuth = -0.72;
const daySky = new THREE.Color(0xa8d9e7);
const sunsetSky = new THREE.Color(0xefa07d);
const daySun = new THREE.Color(0xfff3d1);
const sunsetSun = new THREE.Color(0xff9f55);
const skyColor = new THREE.Color();
function updateDaylight(elevation, azimuth = sunAzimuth) {
const elevationRadians = THREE.MathUtils.degToRad(elevation);
const dayAmount = THREE.MathUtils.smoothstep(elevation, 10, 65);
skyColor.copy(sunsetSky).lerp(daySky, dayAmount);
scene.background.copy(skyColor);
scene.fog.color.copy(skyColor);
sunLight.color.copy(sunsetSun).lerp(daySun, dayAmount);
sunLight.intensity = 0.7 + dayAmount * 2.5;
const horizontalDistance = Math.cos(elevationRadians) * 42;
const verticalDistance = Math.sin(elevationRadians) * 42;
sunLight.position.set(
Math.cos(azimuth) * horizontalDistance,
verticalDistance,
Math.sin(azimuth) * horizontalDistance
);
sunLight.target.position.set(0, 2, 0);
sunMesh.position.copy(sunLight.position).normalize().multiplyScalar(64);
sunMesh.material.color.copy(sunsetSun).lerp(daySun, dayAmount);
hemisphere.intensity = 0.65 + dayAmount * 0.75;
const totalMinutes = Math.round(
6 * 60 + ((elevation - 10) / 70) * 12 * 60
);
const hours = Math.floor(totalMinutes / 60) % 24;
const minutes = totalMinutes % 60;
timeReadout.textContent =
`${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
sunValue.textContent = `${Math.round(elevation)}°`;
sunSlider.value = Math.round(elevation);
}
sunSlider.addEventListener("input", () => {
autoSun = false;
manualSunElevation = Number(sunSlider.value);
cycleButton.setAttribute("aria-pressed", "false");
cycleButton.textContent = "Cycle daylight";
updateDaylight(manualSunElevation);
});
cycleButton.addEventListener("click", () => {
autoSun = !autoSun;
cycleButton.setAttribute("aria-pressed", String(autoSun));
cycleButton.textContent = autoSun ? "Cycle daylight" : "Sunlight paused";
});
ventSlider.addEventListener("input", () => {
ventTarget = Number(ventSlider.value) / 100;
ventValue.textContent = `${ventSlider.value}%`;
});
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 2.4, 0),
yaw: 0.69,
pitch: 0.43,
distance: 31
};
const defaultCamera = {
yaw: cameraState.yaw,
pitch: cameraState.pitch,
distance: cameraState.distance,
target: cameraState.target.clone()
};
function updateCamera() {
const horizontal = Math.cos(cameraState.pitch) * cameraState.distance;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.distance,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.yaw = defaultCamera.yaw;
cameraState.pitch = defaultCamera.pitch;
cameraState.distance = defaultCamera.distance;
cameraState.target.copy(defaultCamera.target);
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
const pointers = new Map();
let previousPinchDistance = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const values = [...pointers.values()];
previousPinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
0.12,
1.12
);
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (previousPinchDistance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance *
(previousPinchDistance / Math.max(pinchDistance, 1)),
13,
57
);
}
previousPinchDistance = pinchDistance;
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
13,
57
);
updateCamera();
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (autoSun) {
const elevation = 45 + 35 * Math.sin(elapsed * 0.13 - 1.15);
sunAzimuth = -0.72 + elapsed * 0.025;
updateDaylight(elevation, sunAzimuth);
}
// Smoothly open or close the roof vents.
ventPosition +=
(ventTarget - ventPosition) * (1 - Math.exp(-delta * 5.2));
for (const vent of vents) {
vent.pivot.rotation.z =
vent.baseAngle + vent.side * ventPosition * 0.58;
}
// Workers walk along the unobstructed center aisle.
for (const worker of workers) {
worker.group.position.z +=
worker.direction * worker.speed * delta;
worker.phase += delta * worker.speed * 6;
if (worker.group.position.z > 10.7) {
worker.group.position.z = 10.7;
worker.direction = -1;
worker.group.rotation.y = Math.PI;
} else if (worker.group.position.z < -10.7) {
worker.group.position.z = -10.7;
worker.direction = 1;
worker.group.rotation.y = 0;
}
const stride = Math.sin(worker.phase) * 0.48;
worker.leftLeg.rotation.x = stride;
worker.rightLeg.rotation.x = -stride;
worker.group.position.y =
0.08 + Math.abs(Math.sin(worker.phase * 2)) * 0.035;
}
// Clouds drift slowly across the sky.
for (let i = 0; i < clouds.length; i++) {
const cloud = clouds[i];
cloud.position.x += delta * (0.16 + i * 0.018);
if (cloud.position.x > 48) cloud.position.x = -48;
}
updateCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateDaylight(manualSunElevation);
updateCamera();
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```