Prompt specification
Build or customize the Three.js 3D scene "Farm packing-house workcell" 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: Farm packing-house workcell
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/farm-packing-house-workcell-x1095
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring produce grading. Compose receiving crates, inspection table, grading station, and packed boxes; workers move produce through distinct stages while rejected-for-size items remain visible in a separate use bin. Stylized solid forms.
Working Three.js Starter (farm-packing-house-workcell-x1095):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Produce Grading Line</title>
<style>
:root {
--ink: #18343b;
--muted: #60747a;
--paper: rgba(255, 255, 255, 0.9);
--teal: #2f8f84;
--gold: #e9a63a;
--coral: #df654e;
--blue: #4d79a5;
--purple: #7b6aa7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #cbd8d5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(24, 52, 59, 0.12);
box-shadow: 0 12px 32px rgba(34, 55, 56, 0.14);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 20px;
left: 20px;
width: 320px;
padding: 18px 19px 16px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.live-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #44b887;
box-shadow: 0 0 0 4px rgba(68, 184, 135, 0.14);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
50% {
box-shadow: 0 0 0 7px rgba(68, 184, 135, 0);
}
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1.12;
letter-spacing: -0.03em;
}
.subtitle {
margin: 8px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.stages {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.stage {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 9px;
border: 1px solid rgba(24, 52, 59, 0.08);
border-radius: 10px;
background: rgba(255, 255, 255, 0.6);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.stage span:last-child {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.swatch {
flex: 0 0 auto;
width: 9px;
height: 9px;
border-radius: 3px;
}
.controls {
right: 20px;
bottom: 20px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px;
border-radius: 14px;
}
button {
height: 36px;
padding: 0 13px;
border: 0;
border-radius: 9px;
background: var(--ink);
color: white;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: transform 0.15s ease, background 0.15s ease;
}
button:hover {
transform: translateY(-1px);
background: #28515a;
}
button.secondary {
background: #e9efed;
color: var(--ink);
}
.control-hint {
padding: 0 8px 0 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.3;
}
.reject-note {
position: fixed;
z-index: 9;
right: 20px;
top: 20px;
display: flex;
align-items: center;
gap: 10px;
max-width: 265px;
padding: 12px 14px;
border: 1px solid rgba(223, 101, 78, 0.22);
border-radius: 14px;
background: rgba(255, 244, 239, 0.92);
box-shadow: 0 10px 26px rgba(93, 55, 46, 0.1);
color: #734034;
font-size: 12px;
font-weight: 650;
line-height: 1.35;
}
.reject-icon {
display: grid;
flex: 0 0 31px;
height: 31px;
place-items: center;
border-radius: 9px;
background: var(--coral);
color: white;
font-size: 16px;
font-weight: 900;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #d7e1de;
color: var(--ink);
font-size: 14px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 0.4s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: min(290px, calc(100vw - 24px));
padding: 14px;
}
h1 {
font-size: 21px;
}
.subtitle,
.stages {
display: none;
}
.reject-note {
top: auto;
right: 12px;
bottom: 69px;
max-width: 230px;
padding: 9px 11px;
}
.controls {
right: 12px;
bottom: 12px;
}
.control-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="panel title-panel">
<div class="eyebrow">
<span class="live-dot"></span>
Live processing line
</div>
<h1>Produce Grading</h1>
<p class="subtitle">
Workers move harvested produce through receiving, inspection, grading,
and packing. Oversized items are retained in the separate use bin.
</p>
<div class="stages">
<div class="stage">
<span class="swatch" style="background:#e9a63a"></span>
<span>01 Receive</span>
</div>
<div class="stage">
<span class="swatch" style="background:#2f8f84"></span>
<span>02 Inspect</span>
</div>
<div class="stage">
<span class="swatch" style="background:#4d79a5"></span>
<span>03 Grade</span>
</div>
<div class="stage">
<span class="swatch" style="background:#7b6aa7"></span>
<span>04 Pack</span>
</div>
</div>
</section>
<div class="reject-note">
<span class="reject-icon">!</span>
<span>Oversized produce stays visible in the dedicated size-reject use bin.</span>
</div>
<div class="panel controls">
<button id="pause" type="button">Pause</button>
<button id="reset" class="secondary" type="button">Reset view</button>
<span class="control-hint">Drag to orbit · Scroll to zoom</span>
</div>
<div id="loading">Loading grading line…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
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.setAttribute("aria-label", "Animated produce grading facility");
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#cbd8d5");
scene.fog = new THREE.Fog("#cbd8d5", 20, 36);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight("#f7fffc", "#756958", 2.35);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff0d4", 3.1);
sun.position.set(-5, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.0003;
scene.add(sun);
const fillLight = new THREE.DirectionalLight("#b9dcff", 0.8);
fillLight.position.set(9, 5, -4);
scene.add(fillLight);
const materials = new Map();
function material(color) {
if (color && color.isMaterial) return color;
const key = String(color);
if (!materials.has(key)) {
materials.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.02
})
);
}
return materials.get(key);
}
function box(parent, w, h, d, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(
parent,
radiusTop,
radiusBottom,
height,
color,
x = 0,
y = 0,
z = 0,
segments = 16
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
segments
),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function ball(parent, radius, color, x = 0, y = 0, z = 0, segments = 16) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, Math.max(10, segments / 2)),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function textSprite(text, background = "#18343b", foreground = "#ffffff", width = 2.2) {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 160;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 752, 144, 26);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = "rgba(255,255,255,0.7)";
ctx.stroke();
ctx.fillStyle = foreground;
ctx.font = "800 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 384, 83, 710);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.needsUpdate = true;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * (160 / 768), 1);
sprite.renderOrder = 20;
return sprite;
}
function addSign(text, x, y, z, background, width = 2.2) {
const sign = textSprite(text, background, "#ffffff", width);
sign.position.set(x, y, z);
scene.add(sign);
return sign;
}
function floorPad(x, z, w, d, color, opacity = 0.16) {
const mat = new THREE.MeshStandardMaterial({
color,
roughness: 0.95,
transparent: true,
opacity,
depthWrite: false
});
return box(scene, w, 0.025, d, mat, x, 0.005, z);
}
function floorArrow(x, z, color, angle = 0, scale = 1) {
const shape = new THREE.Shape();
shape.moveTo(-0.26, -0.14);
shape.lineTo(0.04, -0.14);
shape.lineTo(0.04, -0.31);
shape.lineTo(0.32, 0);
shape.lineTo(0.04, 0.31);
shape.lineTo(0.04, 0.14);
shape.lineTo(-0.26, 0.14);
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
const mesh = new THREE.Mesh(geometry, material(color));
mesh.rotation.x = -Math.PI / 2;
mesh.rotateOnWorldAxis(new THREE.Vector3(0, 1, 0), angle);
mesh.scale.setScalar(scale);
mesh.position.set(x, 0.025, z);
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Building shell and floor zones
// -------------------------------------------------------------------------
box(scene, 16.5, 0.28, 9.4, "#c9c0ae", 0, -0.17, 0.35);
box(scene, 16.5, 4.2, 0.22, "#e7e2d6", 0, 2.03, -3.86);
box(scene, 0.22, 4.2, 9.2, "#ded9cd", -8.18, 2.03, 0.3);
box(scene, 16.4, 0.18, 0.12, "#b8ad9a", 0, 0.12, -3.72);
for (const x of [-7.7, -5.2, -2.7, -0.2, 2.3, 4.8, 7.3]) {
box(scene, 0.16, 4.0, 0.13, "#b8c4bf", x, 2.0, -3.7);
}
for (const x of [-5.4, -1.7, 1.8, 5.2]) {
box(scene, 1.7, 1.0, 0.08, "#a9c3c3", x, 2.55, -3.72);
box(scene, 0.08, 1.0, 0.1, "#dfe6df", x, 2.55, -3.65);
}
floorPad(-5.75, -0.85, 3.65, 3.25, "#e9a63a", 0.18);
floorPad(-2.65, -0.5, 3.65, 2.35, "#2f8f84", 0.13);
floorPad(0.75, -0.5, 2.9, 2.35, "#4d79a5", 0.13);
floorPad(4.4, -0.5, 3.55, 2.35, "#7b6aa7", 0.13);
floorPad(2.75, 2.7, 2.5, 1.9, "#df654e", 0.18);
// Main production flow.
[-4.65, -0.15, 2.55].forEach((x, index) => {
floorArrow(x, 0.68, index === 2 ? "#397f78" : "#70a39c", 0, 0.8);
});
// Reject flow.
for (let i = 0; i < 5; i++) {
const dash = box(
scene,
0.28,
0.035,
0.10,
"#df654e",
1.65 + i * 0.25,
0.03,
1.15 + i * 0.25
);
dash.rotation.y = -0.85;
}
floorArrow(2.65, 1.98, "#df654e", -0.35, 0.8);
// -------------------------------------------------------------------------
// Produce, crates, cartons, and pallets
// -------------------------------------------------------------------------
const produceColors = ["#d95343", "#eea13c", "#77a94b", "#e1c743", "#b95878"];
function createFruit(parent, color, size = 0.14, x = 0, y = 0, z = 0, stem = true) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const fruit = ball(group, size, color, 0, 0, 0, 14);
fruit.scale.y = 0.94;
if (stem) {
cylinder(group, 0.018, 0.025, 0.085, "#6c4b2e", 0, size * 0.91, 0, 8);
const leaf = ball(group, size * 0.32, "#4f8c45", size * 0.26, size * 0.91, 0, 10);
leaf.scale.set(1.45, 0.22, 0.72);
leaf.rotation.z = 0.3;
}
return group;
}
function createCrate(parent, x, y, z, fill = true, accent = "#2f8f84") {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const w = 1.35;
const d = 1.05;
const h = 0.75;
const wood = "#b77b43";
box(group, w, 0.12, d, wood, 0, 0.08, 0);
for (const sy of [0.31, 0.62]) {
box(group, w, 0.16, 0.09, wood, 0, sy, d / 2);
box(group, w, 0.16, 0.09, wood, 0, sy, -d / 2);
box(group, 0.09, 0.16, d, wood, w / 2, sy, 0);
box(group, 0.09, 0.16, d, wood, -w / 2, sy, 0);
}
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
box(group, 0.12, h, 0.12, "#8e5d32", sx * (w / 2 - 0.05), h / 2, sz * (d / 2 - 0.05));
}
}
box(group, w * 0.7, 0.09, 0.035, accent, 0, 0.47, d / 2 + 0.052);
if (fill) {
const positions = [
[-0.39, 0.43, -0.25],
[0.00, 0.45, -0.27],
[0.39, 0.42, -0.22],
[-0.32, 0.43, 0.23],
[0.10, 0.44, 0.23],
[0.43, 0.44, 0.25]
];
positions.forEach((p, i) => {
createFruit(group, produceColors[i % produceColors.length], 0.16, ...p);
});
}
return group;
}
function createPallet(parent, x, y, z, w = 1.75, d = 1.35) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
for (const sx of [-0.55, 0, 0.55]) {
box(group, 0.22, 0.16, d, "#91613d", sx * w * 0.55, 0.09, 0);
}
for (let i = 0; i < 5; i++) {
box(group, w, 0.08, 0.16, "#c18850", 0, 0.21, -d / 2 + 0.13 + i * ((d - 0.26) / 4));
}
return group;
}
function createCarton(parent, x, y, z, w = 0.8, h = 0.58, d = 0.65, open = false) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
const cardboard = "#c89256";
if (!open) {
box(group, w, h, d, cardboard, 0, h / 2, 0);
box(group, 0.09, 0.012, d + 0.012, "#ead7a6", 0, h + 0.006, 0);
box(group, 0.09, h + 0.012, d + 0.014, "#ead7a6", 0, h / 2, 0);
box(group, w * 0.35, h * 0.31, 0.015, "#f3ead8", -w * 0.18, h * 0.54, d / 2 + 0.01);
} else {
box(group, w, 0.08, d, cardboard, 0, 0.04, 0);
box(group, 0.07, h, d, cardboard, -w / 2 + 0.035, h / 2, 0);
box(group, 0.07, h, d, cardboard, w / 2 - 0.035, h / 2, 0);
box(group, w, h, 0.07, cardboard, 0, h / 2, -d / 2 + 0.035);
box(group, w, h, 0.07, cardboard, 0, h / 2, d / 2 - 0.035);
const backFlap = box(group, w, 0.055, d * 0.48, cardboard, 0, h, -d * 0.24);
backFlap.rotation.x = -0.75;
const leftFlap = box(group, w * 0.46, 0.055, d, cardboard, -w * 0.25, h, 0);
leftFlap.rotation.z = 0.55;
const rightFlap = box(group, w * 0.46, 0.055, d, cardboard, w * 0.25, h, 0);
rightFlap.rotation.z = -0.55;
createFruit(group, "#d95343", 0.15, -0.18, 0.18, -0.1);
createFruit(group, "#eea13c", 0.15, 0.14, 0.18, 0.08);
}
return group;
}
// -------------------------------------------------------------------------
// 01 Receiving area
// -------------------------------------------------------------------------
createPallet(scene, -6.1, 0, -2.0, 1.8, 1.35);
createCrate(scene, -6.1, 0.26, -2.0, true, "#e9a63a");
createCrate(scene, -6.1, 1.05, -2.0, false, "#e9a63a");
createCrate(scene, -5.8, 0, -0.12, true, "#e9a63a");
// Receiving clipboard on a small stand.
cylinder(scene, 0.055, 0.07, 0.9, "#49636a", -4.85, 0.45, -0.5, 10);
box(scene, 0.62, 0.08, 0.48, "#58747a", -4.85, 0.92, -0.5);
box(scene, 0.48, 0.035, 0.34, "#f4efe2", -4.85, 0.98, -0.5);
addSign("01 RECEIVE", -5.65, 2.82, -0.2, "#d7922d", 2.25);
// -------------------------------------------------------------------------
// 02 Inspection table
// -------------------------------------------------------------------------
const inspection = new THREE.Group();
inspection.position.set(-2.65, 0, -0.55);
scene.add(inspection);
box(inspection, 3.35, 0.16, 1.35, "#d9e2dc", 0, 1.18, 0);
box(inspection, 3.05, 0.07, 1.15, "#f2f4ea", 0, 1.29, 0);
for (const sx of [-1.42, 1.42]) {
for (const sz of [-0.48, 0.48]) {
box(inspection, 0.13, 1.06, 0.13, "#627b7d", sx, 0.54, sz);
}
}
box(inspection, 2.95, 0.10, 0.95, "#a9bbb5", 0, 0.35, 0);
[
[-1.05, 1.48, -0.24],
[-0.72, 1.48, 0.18],
[-0.38, 1.48, -0.19],
[0.24, 1.48, 0.12],
[0.54, 1.48, -0.18]
].forEach((p, i) => {
createFruit(inspection, produceColors[i % produceColors.length], 0.16, ...p);
});
// Scale and inspection display.
box(inspection, 0.75, 0.12, 0.62, "#2f8f84", 1.03, 1.42, 0);
cylinder(inspection, 0.035, 0.035, 0.55, "#425d62", 1.32, 1.68, -0.18, 10);
box(inspection, 0.68, 0.38, 0.1, "#37565b", 1.32, 2.05, -0.18);
box(inspection, 0.5, 0.23, 0.025, "#b9e1bf", 1.32, 2.05, -0.117);
addSign("02 INSPECT", -2.65, 2.75, -0.48, "#287b73", 2.25);
// -------------------------------------------------------------------------
// 03 Grading station
// -------------------------------------------------------------------------
const grading = new THREE.Group();
grading.position.set(0.75, 0, -0.6);
scene.add(grading);
box(grading, 2.45, 0.18, 1.18, "#3f5b62", 0, 0.93, 0);
box(grading, 2.2, 0.09, 0.95, "#243f46", 0, 1.04, 0);
for (let i = 0; i < 9; i++) {
const roller = cylinder(
grading,
0.105,
0.105,
0.92,
i % 2 ? "#aeb9b2" : "#d6ddd5",
-0.96 + i * 0.24,
1.13,
0,
14
);
roller.rotation.x = Math.PI / 2;
}
for (const sx of [-1.05, 1.05]) {
box(grading, 0.16, 1.05, 0.16, "#55747a", sx, 0.5, 0);
box(grading, 0.2, 2.45, 0.24, "#e6aa42", sx, 1.3, -0.13);
}
box(grading, 2.3, 0.25, 0.38, "#e6aa42", 0, 2.57, -0.13);
box(grading, 0.68, 0.38, 0.55, "#335961", 0, 2.28, 0.02);
box(grading, 0.48, 0.22, 0.025, "#aee1d4", 0, 2.3, 0.305);
ball(grading, 0.075, "#4bc487", 0.82, 2.45, 0.08, 12);
ball(grading, 0.075, "#e25d4b", 1.02, 2.45, 0.08, 12);
createFruit(grading, "#d95343", 0.16, -0.35, 1.33, 0.05);
createFruit(grading, "#eea13c", 0.16, 0.35, 1.33, -0.02);
createFruit(grading, "#77a94b", 0.16, 0.72, 1.33, 0.05);
// Small collection trays beneath the sorter.
box(grading, 0.62, 0.12, 0.72, "#2f8f84", -1.28, 0.65, 0.05);
box(grading, 0.62, 0.12, 0.72, "#d97844", 1.28, 0.65, 0.05);
addSign("03 GRADE", 0.75, 3.2, -0.55, "#426f99", 2.1);
// -------------------------------------------------------------------------
// 04 Packing table and finished boxes
// -------------------------------------------------------------------------
const packing = new THREE.Group();
packing.position.set(4.35, 0, -0.55);
scene.add(packing);
box(packing, 3.15, 0.16, 1.38, "#b8a487", 0, 1.17, 0);
box(packing, 2.95, 0.09, 1.18, "#d8c3a3", 0, 1.29, 0);
for (const sx of [-1.32, 1.32]) {
for (const sz of [-0.5, 0.5]) {
box(packing, 0.14, 1.04, 0.14, "#647d7d", sx, 0.53, sz);
}
}
box(packing, 2.85, 0.1, 1.05, "#9d866d", 0, 0.33, 0);
createCarton(packing, -0.72, 1.35, 0.05, 0.95, 0.62, 0.8, true);
createCarton(packing, 0.64, 1.35, -0.1, 0.84, 0.58, 0.68, false);
// Tape dispenser.
box(packing, 0.38, 0.18, 0.25, "#384e54", 1.18, 1.48, 0.42);
const tapeRoll = cylinder(packing, 0.14, 0.14, 0.11, "#e8d6a1", 1.18, 1.66, 0.42, 20);
tapeRoll.rotation.x = Math.PI / 2;
createPallet(scene, 6.25, 0, 1.78, 1.95, 1.45);
createCarton(scene, 5.78, 0.26, 1.58, 0.9, 0.62, 0.7, false);
createCarton(scene, 6.67, 0.26, 1.57, 0.9, 0.62, 0.7, false);
createCarton(scene, 5.78, 0.9, 1.58, 0.9, 0.62, 0.7, false);
createCarton(scene, 6.67, 0.9, 1.57, 0.9, 0.62, 0.7, false);
createCarton(scene, 6.23, 1.54, 1.58, 0.88, 0.6, 0.7, false);
addSign("04 PACK", 4.35, 2.78, -0.42, "#6e5d98", 2.05);
// -------------------------------------------------------------------------
// Separate size-reject use bin
// -------------------------------------------------------------------------
const rejectBin = new THREE.Group();
rejectBin.position.set(2.75, 0, 2.7);
scene.add(rejectBin);
box(rejectBin, 1.95, 0.13, 1.5, "#b94d3d", 0, 0.08, 0);
box(rejectBin, 1.95, 1.25, 0.13, "#df654e", 0, 0.64, -0.69);
box(rejectBin, 0.13, 1.25, 1.5, "#df654e", -0.91, 0.64, 0);
box(rejectBin, 0.13, 1.25, 1.5, "#df654e", 0.91, 0.64, 0);
box(rejectBin, 1.95, 0.64, 0.13, "#c95140", 0, 0.35, 0.69);
// These oversized items remain visible in the bin throughout the scene.
const oversized = [
["#78a94d", 0.34, -0.36, 0.75, -0.18],
["#df654e", 0.30, 0.28, 0.66, 0.19],
["#e5a53b", 0.29, 0.46, 0.61, -0.23],
["#b85f7e", 0.27, -0.35, 0.59, 0.29]
];
oversized.forEach(([color, size, x, y, z]) => {
const fruit = createFruit(rejectBin, color, size, x, y, z);
fruit.rotation.z = (x > 0 ? 1 : -1) * 0.17;
});
// Safety border.
for (let i = 0; i < 8; i++) {
const stripe = box(
scene,
0.31,
0.035,
0.11,
i % 2 ? "#f0d79b" : "#df654e",
1.55 + i * 0.34,
0.035,
3.58
);
stripe.rotation.y = -0.22;
}
// Size gauge beside the use bin.
cylinder(scene, 0.055, 0.07, 1.65, "#5c6260", 3.85, 0.83, 2.72, 10);
box(scene, 0.52, 1.35, 0.11, "#495b5d", 3.85, 1.13, 2.72);
for (let i = 0; i < 6; i++) {
box(
scene,
i % 2 ? 0.31 : 0.42,
0.045,
0.025,
"#f0d79b",
3.88,
0.63 + i * 0.19,
2.65
);
}
addSign("SIZE REJECT • USE BIN", 2.75, 2.18, 2.72, "#b84f3e", 2.85);
// -------------------------------------------------------------------------
// Stylized workers
// -------------------------------------------------------------------------
function createCarry(type) {
const carry = new THREE.Group();
if (type === "box") {
createCarton(carry, 0, 0.02, 0, 0.62, 0.5, 0.5, false);
} else if (type === "melon") {
const melon = createFruit(carry, "#719b45", 0.32, 0, 0.1, 0);
melon.rotation.z = 0.18;
} else {
box(carry, 0.66, 0.07, 0.43, "#44666c", 0, 0, 0);
box(carry, 0.66, 0.1, 0.055, "#315158", 0, 0.055, 0.205);
box(carry, 0.66, 0.1, 0.055, "#315158", 0, 0.055, -0.205);
const count = type === "single" ? 1 : 3;
for (let i = 0; i < count; i++) {
createFruit(
carry,
produceColors[(i + 1) % produceColors.length],
type === "single" ? 0.18 : 0.14,
count === 1 ? 0 : -0.19 + i * 0.19,
0.12,
count === 1 ? 0 : (i % 2 ? 0.09 : -0.08)
);
}
}
return carry;
}
function createWorker({
color,
skin = "#d69a72",
hat = "#f3bd45",
points,
speed,
offset,
carryType
}) {
const root = new THREE.Group();
scene.add(root);
// Legs.
const legs = [];
for (const sx of [-0.15, 0.15]) {
const pivot = new THREE.Group();
pivot.position.set(sx, 0.77, 0);
root.add(pivot);
cylinder(pivot, 0.105, 0.09, 0.58, "#40545c", 0, -0.29, 0, 12);
box(pivot, 0.19, 0.13, 0.31, "#293d43", 0, -0.63, 0.06);
legs.push(pivot);
}
// Torso and vest.
box(root, 0.48, 0.64, 0.32, "#e5e2d6", 0, 1.12, 0);
box(root, 0.53, 0.49, 0.36, color, 0, 1.15, 0);
box(root, 0.53, 0.065, 0.375, "#edf1e8", 0, 0.95, 0);
box(root, 0.17, 0.12, 0.025, "#ffffff", 0, 1.28, 0.19);
// Head and hard hat.
cylinder(root, 0.11, 0.13, 0.16, skin, 0, 1.51, 0, 12);
ball(root, 0.2, skin, 0, 1.7, 0, 16);
ball(root, 0.055, skin, 0, 1.67, 0.19, 10);
ball(root, 0.225, hat, 0, 1.84, 0, 16).scale.y = 0.58;
cylinder(root, 0.25, 0.25, 0.045, hat, 0, 1.77, 0, 16);
// Arms.
const arms = [];
for (const sx of [-0.35, 0.35]) {
const pivot = new THREE.Group();
pivot.position.set(sx, 1.39, 0);
root.add(pivot);
cylinder(pivot, 0.075, 0.065, 0.5, color, 0, -0.25, 0, 10);
ball(pivot, 0.075, skin, 0, -0.52, 0, 10);
arms.push(pivot);
}
const carry = createCarry(carryType);
carry.position.set(0, 0.93, 0.58);
root.add(carry);
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p)),
false,
"catmullrom",
0.08
);
return {
root,
legs,
arms,
carry,
curve,
speed,
offset,
angle: 0,
initialized: false
};
}
const workers = [
createWorker({
color: "#e9a63a",
skin: "#c9855f",
hat: "#f2bd43",
points: [
[-6.15, 0, 0.76],
[-5.2, 0, 0.68],
[-3.35, 0, 0.68]
],
speed: 0.085,
offset: 0.02,
carryType: "tray"
}),
createWorker({
color: "#2f8f84",
skin: "#e1aa80",
hat: "#f1c34e",
points: [
[-3.35, 0, 0.68],
[-1.55, 0, 0.68],
[0.12, 0, 0.68]
],
speed: 0.094,
offset: 0.16,
carryType: "single"
}),
createWorker({
color: "#4d79a5",
skin: "#9d654b",
hat: "#eebd43",
points: [
[0.12, 0, 0.68],
[1.7, 0, 0.68],
[3.48, 0, 0.68]
],
speed: 0.09,
offset: 0.29,
carryType: "tray"
}),
createWorker({
color: "#7b6aa7",
skin: "#d89a72",
hat: "#efc04b",
points: [
[3.55, 0, 0.68],
[5.0, 0, 0.9],
[6.18, 0, 1.55]
],
speed: 0.086,
offset: 0.08,
carryType: "box"
}),
createWorker({
color: "#df654e",
skin: "#b97856",
hat: "#f2c14e",
points: [
[1.55, 0, -1.52],
[1.82, 0, 0.15],
[2.3, 0, 1.62],
[2.7, 0, 2.22]
],
speed: 0.11,
offset: 0.05,
carryType: "melon"
})
];
function sampleWorkerCycle(cycle) {
if (cycle < 0.1) {
return { u: 0, moving: false, direction: -1 };
}
if (cycle < 0.39) {
return {
u: (cycle - 0.1) / 0.29,
moving: true,
direction: 1
};
}
if (cycle < 0.61) {
return { u: 1, moving: false, direction: -1 };
}
if (cycle < 0.9) {
return {
u: 1 - (cycle - 0.61) / 0.29,
moving: true,
direction: -1
};
}
return { u: 0, moving: false, direction: 1 };
}
function updateWorkers(elapsed) {
workers.forEach((worker, index) => {
const cycle = (elapsed * worker.speed + worker.offset) % 1;
const state = sampleWorkerCycle(cycle);
const position = worker.curve.getPointAt(state.u);
const tangent = worker.curve.getTangentAt(Math.min(0.999, state.u));
if (state.direction < 0) tangent.negate();
const desiredAngle = Math.atan2(tangent.x, tangent.z);
if (!worker.initialized) {
worker.angle = desiredAngle;
worker.initialized = true;
} else {
const difference = Math.atan2(
Math.sin(desiredAngle - worker.angle),
Math.cos(desiredAngle - worker.angle)
);
worker.angle += difference * 0.12;
}
worker.root.rotation.y = worker.angle;
worker.root.position.set(position.x, 0, position.z);
const carrying = cycle > 0.1 && cycle < 0.39;
worker.carry.visible = carrying;
const stride = state.moving ? Math.sin(elapsed * 10 + index * 1.7) : 0;
worker.legs[0].rotation.x = stride * 0.58;
worker.legs[1].rotation.x = -stride * 0.58;
const targetArm = carrying ? -1.08 : stride * 0.48;
worker.arms[0].rotation.x += (targetArm - worker.arms[0].rotation.x) * 0.18;
worker.arms[1].rotation.x += (targetArm - worker.arms[1].rotation.x) * 0.18;
const bob = state.moving ? Math.abs(Math.sin(elapsed * 10 + index)) * 0.035 : 0;
worker.root.position.y = bob;
});
}
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.7, 0.15),
radius: 15.6,
phi: 0.86,
theta: 0.59
};
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(
new THREE.Vector3().setFromSpherical(spherical)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.target.set(0, 0.7, 0.15);
cameraState.radius = 15.6;
cameraState.phi = 0.86;
cameraState.theta = 0.59;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.004,
0.42,
1.38
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
9.5,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
let paused = false;
const pauseButton = document.getElementById("pause");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
pauseButton.click();
}
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
resetCamera();
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
if (!paused) {
elapsed += clock.getDelta();
updateWorkers(elapsed);
} else {
clock.getDelta();
}
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```