Prompt specification
Build or customize the Three.js 3D scene "Corner fruit stall transaction" 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: Corner fruit stall transaction
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/corner-fruit-stall-transaction-x0559
Scene Description Prompt:
Use Three.js from cdnjs in standalone HTML to animate a stylized fruit purchase, selecting, weighing, and bagging the same pieces.
Working Three.js Starter (corner-fruit-stall-transaction-x0559):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>The Good Fruit Co. — Fruit Purchase</title>
<style>
:root {
--ink: #243b39;
--muted: #71817d;
--cream: #f7f0e6;
--green: #4f8f78;
--orange: #f28a3a;
--line: rgba(36, 59, 57, 0.12);
--shadow: 0 16px 50px rgba(45, 64, 58, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee5d9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.glass {
background: rgba(255, 252, 246, 0.82);
border: 1px solid rgba(255, 255, 255, 0.75);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 46px;
height: 46px;
border-radius: 15px;
display: grid;
place-items: center;
background: var(--green);
box-shadow: 0 10px 28px rgba(55, 104, 87, 0.26);
}
.brand-mark svg {
width: 28px;
height: 28px;
}
.brand h1 {
margin: 0;
font-size: 17px;
line-height: 1.1;
letter-spacing: -0.02em;
}
.brand p {
margin: 5px 0 0;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.weight-card {
position: absolute;
top: 22px;
left: 50%;
width: 190px;
padding: 14px 18px;
border-radius: 20px;
transform: translateX(-50%);
text-align: center;
}
.weight-card .eyebrow {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
#weight-value {
display: block;
margin: 3px 0 1px;
font-size: 30px;
font-weight: 800;
letter-spacing: -0.05em;
font-variant-numeric: tabular-nums;
}
#weight-note {
color: var(--muted);
font-size: 11px;
}
.basket {
position: absolute;
top: 108px;
right: 26px;
width: 254px;
padding: 18px;
border-radius: 22px;
}
.basket-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.basket-heading strong {
font-size: 14px;
}
#basket-count {
display: inline-grid;
min-width: 25px;
height: 25px;
padding: 0 7px;
place-items: center;
border-radius: 999px;
background: rgba(79, 143, 120, 0.12);
color: var(--green);
font-size: 11px;
font-weight: 800;
}
.basket-item {
display: grid;
grid-template-columns: 11px 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 0;
border-top: 1px solid var(--line);
opacity: 0.58;
transition: opacity 0.25s ease, transform 0.25s ease;
}
.basket-item.chosen {
opacity: 1;
transform: translateX(2px);
}
.fruit-dot {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 -2px 2px rgba(0, 0, 0, 0.1);
}
.fruit-name {
font-size: 12px;
font-weight: 750;
}
.fruit-meta {
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.item-status {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.basket-item.chosen .item-status {
color: var(--green);
}
.basket-total {
display: flex;
align-items: flex-end;
justify-content: space-between;
margin-top: 9px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.basket-total span {
color: var(--muted);
font-size: 11px;
}
.basket-total strong {
font-size: 18px;
letter-spacing: -0.03em;
}
.story {
position: absolute;
left: 26px;
bottom: 128px;
width: min(340px, calc(100vw - 52px));
padding: 15px 17px;
border-radius: 18px;
}
#story-kicker {
color: var(--orange);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#story-text {
margin-top: 5px;
font-size: 13px;
line-height: 1.45;
}
.journey {
position: absolute;
right: 26px;
bottom: 28px;
left: 26px;
padding: 13px 16px 12px;
border-radius: 22px;
pointer-events: auto;
}
.journey-top {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 9px;
}
#progress {
position: relative;
height: 5px;
flex: 1;
overflow: hidden;
border-radius: 99px;
background: rgba(36, 59, 57, 0.1);
}
#progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #f3a13d, #62a486);
}
#replay {
min-width: 72px;
padding: 7px 12px;
border: 0;
border-radius: 11px;
background: var(--ink);
color: white;
cursor: pointer;
font-size: 11px;
font-weight: 800;
transition: transform 0.2s ease, background 0.2s ease;
}
#replay:hover {
transform: translateY(-1px);
background: var(--green);
}
.steps {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 8px;
}
.step {
position: relative;
padding: 8px 10px;
border: 0;
border-radius: 12px;
background: transparent;
color: var(--muted);
text-align: left;
cursor: pointer;
transition: background 0.2s ease, color 0.2s ease;
}
.step:hover {
background: rgba(79, 143, 120, 0.07);
}
.step.active {
background: rgba(79, 143, 120, 0.12);
color: var(--green);
}
.step.complete {
color: var(--ink);
}
.step-index {
display: block;
margin-bottom: 2px;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.step-name {
font-size: 12px;
font-weight: 800;
}
.help {
position: absolute;
left: 27px;
bottom: 30px;
color: rgba(36, 59, 57, 0.58);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
#toast {
position: absolute;
top: 104px;
left: 50%;
padding: 10px 15px;
border-radius: 999px;
background: rgba(36, 59, 57, 0.92);
color: white;
font-size: 12px;
font-weight: 750;
opacity: 0;
transform: translate(-50%, -8px);
transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #f4ecdf;
transition: opacity 0.6s ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.loader {
display: flex;
align-items: center;
gap: 12px;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loader-dot {
width: 15px;
height: 15px;
border: 3px solid rgba(79, 143, 120, 0.18);
border-top-color: var(--green);
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
@media (max-width: 850px) {
.basket {
top: 94px;
right: 16px;
width: 220px;
padding: 14px;
}
.brand {
top: 16px;
left: 16px;
}
.weight-card {
top: 16px;
right: 16px;
left: auto;
width: 160px;
transform: none;
}
.story {
left: 16px;
bottom: 116px;
}
.journey {
right: 16px;
bottom: 16px;
left: 16px;
}
.help {
display: none;
}
}
@media (max-width: 620px) {
.brand p,
.basket,
.story,
.step-index {
display: none;
}
.brand {
top: 14px;
left: 14px;
}
.brand h1 {
font-size: 13px;
}
.weight-card {
top: 14px;
right: 14px;
width: 140px;
padding: 10px 12px;
}
#weight-value {
font-size: 24px;
}
.journey {
right: 10px;
bottom: 10px;
left: 10px;
padding: 10px;
}
.steps {
gap: 2px;
}
.step {
padding: 7px 4px;
text-align: center;
}
.step-name {
font-size: 10px;
}
#replay {
min-width: 58px;
padding: 7px 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated fruit market purchase"></canvas>
<div class="ui">
<div class="brand">
<div class="brand-mark">
<svg viewBox="0 0 32 32" aria-hidden="true">
<circle cx="16" cy="18" r="10" fill="#f49a42" />
<path d="M16 9c1-4 4-6 8-6-1 4-3 6-8 6Z" fill="#7eb17d" />
<path d="M16 9c0-3 1-5 3-7" fill="none" stroke="#744c30" stroke-width="2" />
</svg>
</div>
<div>
<h1>The Good Fruit Co.</h1>
<p>A tiny market trip</p>
</div>
</div>
<div class="weight-card glass">
<div class="eyebrow">Scale total</div>
<strong id="weight-value">—</strong>
<div id="weight-note">Waiting for selection</div>
</div>
<aside class="basket glass">
<div class="basket-heading">
<strong>Your basket</strong>
<span id="basket-count">0 / 4</span>
</div>
<div id="basket-items"></div>
<div class="basket-total">
<span>4 pieces · one purchase</span>
<strong id="basket-total">1.19 kg</strong>
</div>
</aside>
<div class="story glass">
<div id="story-kicker">Freshly picked</div>
<div id="story-text">The same fruit pieces will move from the display to the scale and into your bag.</div>
</div>
<div class="journey glass">
<div class="journey-top">
<div id="progress"><div id="progress-fill"></div></div>
<button id="replay" type="button">Replay</button>
</div>
<div class="steps">
<button class="step" data-jump="0.25" type="button">
<span class="step-index">Step 01</span>
<span class="step-name">Arrive</span>
</button>
<button class="step" data-jump="1.1" type="button">
<span class="step-index">Step 02</span>
<span class="step-name">Pick</span>
</button>
<button class="step" data-jump="5.25" type="button">
<span class="step-index">Step 03</span>
<span class="step-name">Weigh</span>
</button>
<button class="step" data-jump="8.1" type="button">
<span class="step-index">Step 04</span>
<span class="step-name">Bag</span>
</button>
<button class="step" data-jump="12.8" type="button">
<span class="step-index">Step 05</span>
<span class="step-name">Paid</span>
</button>
</div>
</div>
<div class="help">Drag to orbit · scroll to zoom · click a fruit</div>
<div id="toast" role="status" aria-live="polite"></div>
</div>
<div id="loading">
<div class="loader"><span class="loader-dot"></span> Opening 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";
const canvas = document.getElementById("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(0xeee5d9);
scene.fog = new THREE.Fog(0xeee5d9, 18, 31);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom orbit camera, implemented without addons.
const orbit = {
target: new THREE.Vector3(0, 1.05, 0),
theta: 0.48,
elevation: 0.52,
radius: 14.3,
desiredTheta: 0.48,
desiredElevation: 0.52,
desiredRadius: 14.3
};
function updateCamera(dt) {
const damping = 1 - Math.exp(-dt * 8);
orbit.theta += (orbit.desiredTheta - orbit.theta) * damping;
orbit.elevation += (orbit.desiredElevation - orbit.elevation) * damping;
orbit.radius += (orbit.desiredRadius - orbit.radius) * damping;
const horizontal = Math.cos(orbit.elevation) * orbit.radius;
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.theta),
orbit.target.y + Math.sin(orbit.elevation) * orbit.radius,
orbit.target.z + horizontal * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera(1);
const hemisphere = new THREE.HemisphereLight(0xfff8ed, 0x78958a, 2.4);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0d9, 3.2);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xb7d8cf, 1.35);
rimLight.position.set(8, 5, -5);
scene.add(rimLight);
const surfaceY = 0.83;
const palette = {
cream: 0xf7f0e6,
wall: 0xf1e4d2,
counter: 0x5f8f82,
wood: 0xd4a46e,
darkWood: 0xa96d3e,
dark: 0x314c49,
scale: 0xece9df,
paper: 0xd0a16a,
paperDark: 0x9d6d42
};
function standard(color, roughness = 0.75, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function roundedRectPath(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + w - r, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + r);
ctx.lineTo(x + w, y + h - r);
ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
ctx.lineTo(x + r, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function canvasTexture(width, height, draw) {
const c = document.createElement("canvas");
c.width = width;
c.height = height;
const ctx = c.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return { canvas: c, ctx, texture };
}
function makeSignTexture(title, subtitle, accent = "#5f8f82") {
return canvasTexture(1024, 320, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRectPath(ctx, 8, 8, w - 16, h - 16, 38);
ctx.fillStyle = "#fbf6ec";
ctx.fill();
ctx.strokeStyle = "rgba(49,76,73,.16)";
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = accent;
ctx.fillRect(62, 61, 12, 198);
ctx.fillStyle = "#2e4844";
ctx.font = "800 72px system-ui, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(title, 110, 121);
ctx.fillStyle = "#75847f";
ctx.font = "700 31px system-ui, sans-serif";
ctx.fillText(subtitle, 112, 207);
}).texture;
}
function makeBadgeTexture(number, color) {
return canvasTexture(160, 100, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
roundedRectPath(ctx, 6, 6, w - 12, h - 12, 30);
ctx.fillStyle = "rgba(255,252,244,.95)";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.stroke();
ctx.fillStyle = "#304a46";
ctx.font = "900 48px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(number, w / 2, h / 2 + 2);
}).texture;
}
function makeSprite(texture, width, height) {
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, height, 1);
return sprite;
}
function box(w, h, d, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Market room and counter.
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
standard(0xe8dfd2, 0.95)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.02;
ground.receiveShadow = true;
scene.add(ground);
box(
16,
6.6,
0.25,
standard(palette.wall, 0.95),
0,
3.25,
-3.62
);
for (let i = 0; i < 12; i++) {
const x = -7.2 + i * 1.3;
box(
0.035,
5.8,
0.035,
standard(0xe4d4c0, 1),
x,
3.1,
-3.475
);
}
const mainSign = new THREE.Mesh(
new THREE.PlaneGeometry(6.5, 2.03),
new THREE.MeshBasicMaterial({
map: makeSignTexture(
"THE GOOD FRUIT CO.",
"FRESH PICKS • FAIR WEIGHTS • PAPER BAGS",
"#ef9a43"
),
transparent: true,
toneMapped: false
})
);
mainSign.position.set(0, 4.55, -3.46);
scene.add(mainSign);
box(
13,
0.65,
6.5,
standard(palette.counter, 0.68),
0,
0.325,
0
);
box(
13.3,
0.18,
6.8,
standard(palette.wood, 0.66),
0,
0.74,
0
);
const frontInset = new THREE.Mesh(
new THREE.PlaneGeometry(5.4, 0.47),
new THREE.MeshBasicMaterial({
map: makeSignTexture(
"GOOD FOOD, FAIR WEIGHT",
"A SMALL MARKET IN THE BIG CITY",
"#f4a14d"
),
transparent: true,
toneMapped: false
})
);
frontInset.position.set(0, 0.33, 3.255);
scene.add(frontInset);
// Display crate.
const crate = new THREE.Group();
crate.position.set(-3.35, 0, 0.25);
scene.add(crate);
box(3.25, 0.12, 2.65, standard(palette.darkWood), 0, 0.89, 0, crate);
box(3.25, 0.32, 0.12, standard(palette.darkWood), 0, 1.05, -1.32, crate);
box(3.25, 0.32, 0.12, standard(palette.darkWood), 0, 1.05, 1.32, crate);
box(0.12, 0.32, 2.65, standard(palette.darkWood), -1.62, 1.05, 0, crate);
box(0.12, 0.32, 2.65, standard(palette.darkWood), 1.62, 1.05, 0, crate);
// Scale.
const scale = new THREE.Group();
scale.position.set(0.65, 0, 0);
scene.add(scale);
const scaleBody = box(
1.68,
0.22,
1.48,
standard(palette.dark, 0.58),
0,
0.94,
0,
scale
);
const scalePan = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.08, 0.1, 64),
standard(palette.scale, 0.48, 0.12)
);
scalePan.position.y = 1.1;
scalePan.castShadow = true;
scalePan.receiveShadow = true;
scale.add(scalePan);
const scaleHaloMaterial = new THREE.MeshBasicMaterial({
color: 0x78b394,
transparent: true,
opacity: 0,
depthWrite: false
});
const scaleHalo = new THREE.Mesh(
new THREE.TorusGeometry(1.075, 0.025, 10, 80),
scaleHaloMaterial
);
scaleHalo.rotation.x = Math.PI / 2;
scaleHalo.position.y = 1.16;
scale.add(scaleHalo);
const scaleDisplay = canvasTexture(640, 280, () => {});
const scaleDisplayMesh = new THREE.Mesh(
new THREE.PlaneGeometry(1.17, 0.48),
new THREE.MeshBasicMaterial({
map: scaleDisplay.texture,
toneMapped: false
})
);
scaleDisplayMesh.position.set(0, 0.94, 0.748);
scale.add(scaleDisplayMesh);
let lastScaleText = "";
function drawScaleDisplay(text) {
if (text === lastScaleText) return;
lastScaleText = text;
const { ctx, canvas: c, texture } = scaleDisplay;
ctx.clearRect(0, 0, c.width, c.height);
roundedRectPath(ctx, 12, 12, c.width - 24, c.height - 24, 34);
ctx.fillStyle = "#263b39";
ctx.fill();
ctx.fillStyle = "#bde4b5";
ctx.font = "800 106px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 3);
texture.needsUpdate = true;
}
// Paper shopping bag.
const bag = new THREE.Group();
bag.position.set(4.0, surfaceY, 0);
scene.add(bag);
const bagMaterial = standard(palette.paper, 0.92);
const bagSideMaterial = standard(0xc5935d, 0.95);
const bagBottom = box(1.4, 0.06, 1.35, bagMaterial, 0, 0.03, 0, bag);
const bagBack = box(1.4, 1.65, 0.06, bagMaterial, 0, 0.825, -0.67, bag);
const bagFront = box(1.4, 0.9, 0.06, bagMaterial, 0, 0.45, 0.67, bag);
const bagLeft = box(0.06, 1.62, 1.35, bagSideMaterial, -0.67, 0.81, 0, bag);
const bagRight = box(0.06, 1.62, 1.35, bagSideMaterial, 0.67, 0.81, 0, bag);
const handleMaterial = standard(palette.paperDark, 0.9);
for (const z of [-0.43, 0.43]) {
const handle = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.038, 8, 28, Math.PI),
handleMaterial
);
handle.position.set(0, 1.5, z);
handle.castShadow = true;
bag.add(handle);
}
const bagLogo = new THREE.Mesh(
new THREE.PlaneGeometry(0.87, 0.32),
new THREE.MeshBasicMaterial({
map: makeSignTexture("FRESH", "GOODNESS TO GO", "#df9949"),
transparent: true,
toneMapped: false
})
);
bagLogo.position.set(0, 0.49, 0.705);
bag.add(bagLogo);
// Payment terminal and receipt.
const terminal = new THREE.Group();
terminal.position.set(5.55, surfaceY, 0.38);
scene.add(terminal);
box(0.76, 0.25, 0.92, standard(0x2c4240, 0.5), 0, 0.125, 0, terminal);
const terminalTextures = {
ready: makeSignTexture("TAP", "READY TO PAY", "#ef9a43"),
paid: makeSignTexture("PAID", "THANK YOU!", "#68a987")
};
const terminalMaterial = new THREE.MeshBasicMaterial({
map: terminalTextures.ready,
transparent: true,
toneMapped: false
});
const terminalScreen = new THREE.Mesh(
new THREE.PlaneGeometry(0.62, 0.4),
terminalMaterial
);
terminalScreen.position.set(0, 0.39, 0.02);
terminalScreen.rotation.x = -0.25;
terminal.add(terminalScreen);
const receiptMaterial = new THREE.MeshStandardMaterial({
color: 0xfffdf6,
roughness: 0.95,
transparent: true,
opacity: 0
});
const receipt = box(
0.35,
0.72,
0.025,
receiptMaterial,
5.55,
1.0,
1.23
);
receipt.visible = false;
// Station signs.
const stationData = [
[-3.35, "01", "PICK", "#ef9a43"],
[0.65, "02", "WEIGH", "#5f8f82"],
[4.0, "03", "BAG", "#a06f9a"]
];
for (const [x, number, title, color] of stationData) {
const stationSprite = makeSprite(
makeSignTexture(`${number} ${title}`, "THE GOOD FRUIT CO.", color),
1.95,
0.61
);
stationSprite.position.set(x, 3.05, -1.62);
scene.add(stationSprite);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 1.35, 8),
standard(0xb18456, 0.8)
);
pole.position.set(x, 2.03, -1.62);
pole.castShadow = true;
scene.add(pole);
}
// Fruit construction helpers.
function addStem(group, height = 0.42, x = 0) {
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.055, 0.14, 8),
standard(0x68452e, 0.9)
);
stem.position.set(x, height, 0);
stem.castShadow = true;
group.add(stem);
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(1, 14, 8),
standard(0x6fa363, 0.88)
);
leaf.scale.set(0.15, 0.027, 0.075);
leaf.position.set(x + 0.1, height + 0.04, 0);
leaf.rotation.z = -0.35;
leaf.castShadow = true;
group.add(leaf);
}
function createOrange() {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.42, 40, 28),
standard(0xf28a34, 0.68)
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const poreMaterial = standard(0xd96d24, 0.9);
for (let i = 0; i < 18; i++) {
const y = 1 - (i / 17) * 2;
const radius = Math.sqrt(1 - y * y);
const angle = i * 2.39996;
const pore = new THREE.Mesh(
new THREE.SphereGeometry(0.018, 6, 5),
poreMaterial
);
pore.position.set(
Math.cos(angle) * radius * 0.417,
y * 0.417,
Math.sin(angle) * radius * 0.417
);
group.add(pore);
}
addStem(group, 0.43);
return group;
}
function createApple() {
const group = new THREE.Group();
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.43, 36, 24),
standard(0xdf4e54, 0.58)
);
body.scale.set(1, 0.9, 0.98);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const blush = new THREE.Mesh(
new THREE.SphereGeometry(0.24, 24, 16),
standard(0xf06b66, 0.7)
);
blush.scale.set(1, 0.55, 0.22);
blush.position.set(0.22, 0.02, 0.29);
group.add(blush);
addStem(group, 0.42);
return group;
}
function createPear() {
const group = new THREE.Group();
const profile = [
new THREE.Vector2(0.0, -0.39),
new THREE.Vector2(0.16, -0.37),
new THREE.Vector2(0.27, -0.24),
new THREE.Vector2(0.31, -0.04),
new THREE.Vector2(0.27, 0.17),
new THREE.Vector2(0.18, 0.34),
new THREE.Vector2(0.09, 0.46),
new THREE.Vector2(0.0, 0.5)
];
const body = new THREE.Mesh(
new THREE.LatheGeometry(profile, 32),
standard(0xb8c94d, 0.7)
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
addStem(group, 0.54);
return group;
}
function createBanana() {
const group = new THREE.Group();
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.46, -0.18, 0),
new THREE.Vector3(-0.28, 0.19, 0),
new THREE.Vector3(0.02, 0.31, 0),
new THREE.Vector3(0.35, 0.18, 0),
new THREE.Vector3(0.48, -0.04, 0),
new THREE.Vector3(0.38, -0.2, 0)
]);
const body = new THREE.Mesh(
new THREE.TubeGeometry(curve, 40, 0.12, 12, false),
standard(0xf0c83d, 0.62)
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const tipMaterial = standard(0x8b6731, 0.9);
for (const point of [curve.getPoint(0), curve.getPoint(1)]) {
const tip = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 12, 8),
tipMaterial
);
tip.position.copy(point);
tip.scale.set(0.8, 1.1, 0.8);
group.add(tip);
}
return group;
}
const fruitDefinitions = [
{
name: "Sun orange",
weight: 0.42,
color: "#f28a34",
cssColor: "#f28a34",
create: createOrange,
home: new THREE.Vector3(-4.15, 1.36, 0.9),
pan: new THREE.Vector3(0.35, 1.57, 0.27),
packed: new THREE.Vector3(3.78, 1.28, 0.2)
},
{
name: "Ruby apple",
weight: 0.28,
color: "#df4e54",
cssColor: "#df4e54",
create: createApple,
home: new THREE.Vector3(-3.05, 1.34, 1.02),
pan: new THREE.Vector3(0.98, 1.57, 0.27),
packed: new THREE.Vector3(4.22, 1.3, 0.18)
},
{
name: "Green pear",
weight: 0.31,
color: "#b8c94d",
cssColor: "#b8c94d",
create: createPear,
home: new THREE.Vector3(-4.02, 1.39, -0.5),
pan: new THREE.Vector3(0.31, 1.58, -0.3),
packed: new THREE.Vector3(3.83, 1.38, -0.18)
},
{
name: "Yellow banana",
weight: 0.18,
color: "#f0c83d",
cssColor: "#f0c83d",
create: createBanana,
home: new THREE.Vector3(-2.62, 1.32, -0.52),
pan: new THREE.Vector3(1.02, 1.55, -0.31),
packed: new THREE.Vector3(4.2, 1.36, -0.2)
}
];
const fruits = [];
const pickMeshes = [];
fruitDefinitions.forEach((definition, index) => {
const group = definition.create();
group.position.copy(definition.home);
group.rotation.y = index * 0.35 - 0.35;
scene.add(group);
const badge = makeSprite(
makeBadgeTexture(String(index + 1).padStart(2, "0"), definition.color),
0.46,
0.29
);
badge.position.set(0, 0.87, 0);
group.add(badge);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xfff5d5,
transparent: true,
opacity: 0.2,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.022, 8, 48),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.47;
group.add(ring);
const fruit = {
...definition,
group,
badge,
ring,
ringMaterial,
homeQ: group.quaternion.clone(),
panQ: group.quaternion.clone().multiply(
new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, 0.35 + index * 0.3, index % 2 ? 0.12 : -0.1)
)
),
bagQ: new THREE.Quaternion().setFromEuler(
new THREE.Euler(
index * 0.16,
index * 0.72 + 0.3,
index % 2 ? 0.28 : -0.2
)
),
selectStart: 0.9 + index * 0.72,
selectDuration: 0.9,
bagStart: 7.35 + index * 0.78,
bagDuration: 1.15,
glow: 0,
hover: 0
};
group.traverse((child) => {
if (child.isMesh) {
child.userData.fruit = fruit;
pickMeshes.push(child);
}
});
fruits.push(fruit);
});
const totalWeight = fruits.reduce((sum, fruit) => sum + fruit.weight, 0);
// Basket UI.
const basketItems = document.getElementById("basket-items");
const basketCount = document.getElementById("basket-count");
const basketTotal = document.getElementById("basket-total");
const weightValue = document.getElementById("weight-value");
const weightNote = document.getElementById("weight-note");
const storyKicker = document.getElementById("story-kicker");
const storyText = document.getElementById("story-text");
const progressFill = document.getElementById("progress-fill");
const toast = document.getElementById("toast");
const steps = [...document.querySelectorAll(".step")];
const itemElements = fruits.map((fruit, index) => {
const element = document.createElement("div");
element.className = "basket-item";
element.innerHTML = `
<span class="fruit-dot" style="background:${fruit.cssColor}"></span>
<div>
<div class="fruit-name">${fruit.name}</div>
<div class="fruit-meta">${fruit.weight.toFixed(2)} kg · #${String(index + 1).padStart(2, "0")}</div>
</div>
<span class="item-status">Waiting</span>
`;
basketItems.appendChild(element);
return element;
});
basketTotal.textContent = `${totalWeight.toFixed(2)} kg`;
const stageInfo = [
{
id: "intro",
start: 0,
end: 0.9,
kicker: "Freshly picked",
text: "The same fruit pieces will move from the display to the scale and into your bag."
},
{
id: "pick",
start: 0.9,
end: 4.8,
kicker: "Choosing the pieces",
text: "Four marked pieces are selected one by one from the fresh produce display."
},
{
id: "weigh",
start: 4.8,
end: 7.35,
kicker: "Checking the weight",
text: "Every selected piece is checked together on the market scale."
},
{
id: "bag",
start: 7.35,
end: 12,
kicker: "Packing the purchase",
text: "Those same four pieces travel from the scale into the paper shopping bag."
},
{
id: "done",
start: 12,
end: 14,
kicker: "Paid and packed",
text: "The receipt is printed and the fruit is ready to enjoy."
}
];
function clamp01(value) {
return Math.max(0, Math.min(1, value));
}
function smooth(value) {
value = clamp01(value);
return value * value * (3 - 2 * value);
}
function cubicBezier(p0, p1, p2, p3, t, target) {
const u = 1 - t;
const a = u * u * u;
const b = 3 * u * u * t;
const c = 3 * u * t * t;
const d = t * t * t;
target.set(
a * p0.x + b * p1.x + c * p2.x + d * p3.x,
a * p0.y + b * p1.y + c * p2.y + d * p3.y,
a * p0.z + b * p1.z + c * p2.z + d * p3.z
);
return target;
}
const pathA = new THREE.Vector3();
const pathB = new THREE.Vector3();
const pathC = new THREE.Vector3();
function updateFruit(fruit, time, index) {
const group = fruit.group;
if (time < fruit.selectStart) {
group.position.copy(fruit.home);
group.position.y += Math.sin(time * 2.2 + index) * 0.025;
group.quaternion.copy(fruit.homeQ);
fruit.ringMaterial.opacity = 0.15;
fruit.badge.material.opacity = 1;
return;
}
if (time < fruit.bagStart) {
const p = smooth(
(time - fruit.selectStart) / fruit.selectDuration
);
pathA.copy(fruit.home).add(new THREE.Vector3(0, 1.45, 0));
pathB.copy(fruit.pan).add(new THREE.Vector3(0, 1.45, 0));
cubicBezier(
fruit.home,
pathA,
pathB,
fruit.pan,
p,
group.position
);
group.quaternion.copy(fruit.homeQ).slerp(fruit.panQ, p);
fruit.ringMaterial.opacity = 0.42 * Math.sin(Math.PI * p) + 0.15;
fruit.badge.material.opacity = 1;
return;
}
const p = smooth((time - fruit.bagStart) / fruit.bagDuration);
pathA.copy(fruit.pan).add(new THREE.Vector3(0.85, 1.55, 0));
pathB.copy(fruit.packed).add(new THREE.Vector3(0, 1.48, 0));
cubicBezier(
fruit.pan,
pathA,
pathB,
fruit.packed,
p,
group.position
);
group.quaternion.copy(fruit.panQ).slerp(fruit.bagQ, p);
fruit.ringMaterial.opacity = 0.15 * (1 - p);
fruit.badge.material.opacity = 1 - p * 0.88;
}
let elapsed = 0;
let playing = true;
let lastTime = performance.now();
let toastTimer;
function showToast(message) {
toast.textContent = message;
toast.classList.add("visible");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("visible"), 1800);
}
function setTerminalPaid(paid) {
const nextMap = paid ? terminalTextures.paid : terminalTextures.ready;
if (terminalMaterial.map !== nextMap) {
terminalMaterial.map = nextMap;
terminalMaterial.needsUpdate = true;
}
}
function updateUI(time) {
let activeStage = stageInfo[0];
for (const stage of stageInfo) {
if (time >= stage.start) activeStage = stage;
}
storyKicker.textContent = activeStage.kicker;
storyText.textContent = activeStage.text;
steps.forEach((step, index) => {
step.classList.toggle("active", index === stageInfo.indexOf(activeStage));
step.classList.toggle(
"complete",
time >= stageInfo[index].end
);
});
progressFill.style.width = `${clamp01(time / 13.5) * 100}%`;
let chosen = 0;
fruits.forEach((fruit, index) => {
let status = "Waiting";
let isChosen = false;
if (time >= fruit.selectStart) {
isChosen = true;
chosen++;
if (time < fruit.selectStart + fruit.selectDuration) {
status = "Picking";
} else if (time < fruit.bagStart) {
status = "On scale";
} else if (time < fruit.bagStart + fruit.bagDuration) {
status = "Packing";
} else {
status = "Bagged";
}
}
const element = itemElements[index];
element.classList.toggle("chosen", isChosen);
element.querySelector(".item-status").textContent = status;
});
basketCount.textContent = `${chosen} / ${fruits.length}`;
const weighProgress = clamp01((time - 4.95) / 1.5);
const displayedWeight = totalWeight * weighProgress;
if (time < 4.8) {
weightValue.textContent = "—";
weightNote.textContent =
time < 3.9 ? "Selection in progress" : "Ready to weigh";
drawScaleDisplay("0.00 kg");
} else {
weightValue.textContent = `${displayedWeight.toFixed(2)} kg`;
weightNote.textContent =
time < 6.45
? "Verifying selected fruit"
: time < 12
? "4 pieces · verified"
: "4 pieces · packed";
drawScaleDisplay(`${displayedWeight.toFixed(2)} kg`);
}
}
function resetAnimation() {
elapsed = 0;
playing = true;
lastTime = performance.now();
setTerminalPaid(false);
receipt.visible = false;
receiptMaterial.opacity = 0;
}
document.getElementById("replay").addEventListener("click", resetAnimation);
for (const step of steps) {
step.addEventListener("click", () => {
elapsed = Number(step.dataset.jump);
playing = true;
lastTime = performance.now();
});
}
// Pointer picking and custom orbit controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const pointerDown = new THREE.Vector2();
let pointerIsDown = false;
let pointerMoved = false;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickFruit(event) {
setPointer(event);
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickMeshes, false)[0];
if (hit?.object.userData.fruit) {
const fruit = hit.object.userData.fruit;
fruit.glow = 1;
showToast(`${fruit.name} · ${fruit.weight.toFixed(2)} kg`);
}
}
canvas.addEventListener("pointerdown", (event) => {
pointerIsDown = true;
pointerMoved = false;
pointerDown.set(event.clientX, event.clientY);
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
setPointer(event);
if (pointerIsDown) {
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.abs(dx) + Math.abs(dy) > 4) pointerMoved = true;
if (pointerMoved) {
orbit.desiredTheta -= dx * 0.005;
orbit.desiredElevation = THREE.MathUtils.clamp(
orbit.desiredElevation + dy * 0.004,
0.28,
1.02
);
pointerDown.set(event.clientX, event.clientY);
}
return;
}
scene.updateMatrixWorld(true);
raycaster.setFromCamera(pointer, camera);
const hit = raycaster.intersectObjects(pickMeshes, false)[0];
for (const fruit of fruits) fruit.hover = 0;
if (hit?.object.userData.fruit) {
hit.object.userData.fruit.hover = 1;
canvas.style.cursor = "pointer";
} else {
canvas.style.cursor = "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
if (pointerIsDown && !pointerMoved) pickFruit(event);
pointerIsDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("pointercancel", () => {
pointerIsDown = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius * Math.exp(event.deltaY * 0.001),
8.5,
19
);
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate(now) {
const dt = Math.min((now - lastTime) / 1000, 0.05);
lastTime = now;
if (playing) {
elapsed = Math.min(elapsed + dt, 13.5);
if (elapsed >= 13.5) playing = false;
}
updateCamera(dt);
fruits.forEach((fruit, index) => {
updateFruit(fruit, elapsed, index);
fruit.glow = Math.max(
fruit.hover,
fruit.glow - dt * 1.35
);
fruit.ringMaterial.opacity = Math.max(
fruit.ringMaterial.opacity,
fruit.glow * 0.7
);
});
const weighing = elapsed >= 4.8 && elapsed < 7.35;
const pulse = weighing
? 1 + Math.sin((elapsed - 4.8) * 7) * 0.012
: 1;
scalePan.scale.set(pulse, 1, pulse);
scaleHaloMaterial.opacity = weighing
? 0.35 + Math.sin((elapsed - 4.8) * 7) * 0.18
: 0;
const bagActivity = elapsed >= 7.35 && elapsed < 11.2;
bag.rotation.z = bagActivity
? Math.sin(elapsed * 13) * 0.008
: Math.sin(elapsed * 1.8) * 0.001;
const paid = elapsed >= 12;
setTerminalPaid(paid);
if (paid) {
const reveal = smooth((elapsed - 12) / 0.7);
receipt.visible = true;
receiptMaterial.opacity = reveal;
receipt.position.y = 1.02 + reveal * 0.62;
}
updateUI(elapsed);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
setTimeout(() => {
document.getElementById("loading").classList.add("hidden");
}, 450);
</script>
</body>
</html>
```