Prompt specification
Build or customize the Three.js 3D scene "Juice yield exploration stand" 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: Juice yield exploration stand
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/juice-yield-exploration-stand-x0096
Scene Description Prompt:
Use Three.js from cdnjs to create a market demonstration with different-sized citrus models and a symbolic press; let users compare equal fruit counts and equal fruit volumes using explicitly illustrative yield bars. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (juice-yield-exploration-stand-x0096):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Citrus Press Lab — Voxel Market Demonstration</title>
<style>
:root {
--ink: #20352b;
--paper: #f6eedc;
--paper-deep: #eadfc6;
--orange: #ed7628;
--orange-light: #f5a33c;
--green: #4e7658;
--green-light: #dce7d4;
--red: #b94d3d;
--shadow: rgba(32, 53, 43, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
height: 100vh;
overflow: hidden;
}
button {
font: inherit;
}
.app-header {
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
padding: 0 24px;
color: #fff9e9;
background: var(--ink);
border-bottom: 4px solid var(--orange);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 0;
}
.voxel-mark {
position: relative;
width: 34px;
height: 34px;
flex: 0 0 auto;
}
.voxel-mark span {
position: absolute;
width: 15px;
height: 15px;
background: var(--orange-light);
box-shadow: inset -3px -3px 0 rgba(32, 53, 43, 0.18);
}
.voxel-mark span:nth-child(1) {
left: 0;
top: 0;
}
.voxel-mark span:nth-child(2) {
left: 17px;
top: 0;
background: #ffd36e;
}
.voxel-mark span:nth-child(3) {
left: 8px;
top: 17px;
background: #f28b2f;
}
.brand-copy {
min-width: 0;
}
.brand-copy strong {
display: block;
font-size: 16px;
line-height: 1.1;
letter-spacing: 0.08em;
white-space: nowrap;
}
.brand-copy small {
display: block;
margin-top: 4px;
color: #d6dfd1;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.illustrative-badge {
flex: 0 0 auto;
padding: 8px 11px;
color: #ffe3a8;
border: 1px solid rgba(255, 227, 168, 0.42);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
main {
display: grid;
grid-template-columns: minmax(0, 1fr) 390px;
height: calc(100vh - 72px);
}
#viewport {
position: relative;
min-width: 0;
overflow: hidden;
isolation: isolate;
background: #e9dfca;
}
#viewport canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
cursor: grab;
}
#viewport canvas:active {
cursor: grabbing;
}
.scene-copy {
position: absolute;
z-index: 3;
top: 24px;
left: 24px;
max-width: min(470px, calc(100% - 48px));
pointer-events: none;
}
.scene-kicker {
display: inline-block;
margin-bottom: 9px;
padding: 6px 9px;
color: var(--ink);
background: #f9d37e;
box-shadow: 4px 4px 0 rgba(32, 53, 43, 0.2);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-copy h1 {
max-width: 470px;
margin: 0;
font-size: clamp(28px, 3.4vw, 49px);
line-height: 0.96;
letter-spacing: -0.055em;
text-transform: uppercase;
}
.scene-copy p {
max-width: 420px;
margin: 13px 0 0;
color: #405348;
font-size: 13px;
line-height: 1.5;
}
.view-tools {
position: absolute;
z-index: 5;
right: 18px;
top: 18px;
display: flex;
gap: 8px;
}
.tool-button {
padding: 9px 11px;
color: var(--ink);
background: rgba(255, 250, 237, 0.94);
border: 2px solid var(--ink);
box-shadow: 3px 3px 0 rgba(32, 53, 43, 0.22);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.03em;
}
.tool-button:hover {
background: #fff;
transform: translateY(-1px);
}
.tool-button:active {
box-shadow: 1px 1px 0 rgba(32, 53, 43, 0.22);
transform: translate(1px, 1px);
}
.scene-help {
position: absolute;
z-index: 4;
left: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px 11px;
color: #f8f1df;
background: rgba(32, 53, 43, 0.9);
border: 1px solid rgba(255, 255, 255, 0.16);
font-size: 11px;
pointer-events: none;
}
.scene-help b {
color: #ffd36e;
}
.world-label {
position: absolute;
z-index: 2;
min-width: 116px;
padding: 7px 9px;
color: var(--ink);
background: rgba(255, 250, 237, 0.93);
border: 2px solid var(--ink);
box-shadow: 4px 4px 0 rgba(32, 53, 43, 0.2);
pointer-events: none;
text-align: center;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.world-label strong,
.world-label small {
display: block;
}
.world-label strong {
font-size: 11px;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.world-label small {
margin-top: 2px;
color: #68796d;
font-size: 9px;
}
.world-label.press-label {
color: #fff9e9;
background: rgba(32, 53, 43, 0.93);
border-color: #f5b347;
}
.world-label.press-label small {
color: #f9d37e;
}
.panel {
position: relative;
z-index: 6;
overflow-y: auto;
padding: 25px 24px 28px;
background:
linear-gradient(rgba(32, 53, 43, 0.035) 1px, transparent 1px),
linear-gradient(90deg, rgba(32, 53, 43, 0.035) 1px, transparent 1px),
var(--paper);
background-size: 20px 20px;
border-left: 4px solid var(--ink);
}
.panel-kicker {
color: var(--orange);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.panel h2 {
margin: 8px 0 8px;
font-size: 29px;
line-height: 1.02;
letter-spacing: -0.04em;
}
.panel-intro {
margin: 0 0 19px;
color: #536459;
font-size: 13px;
line-height: 1.5;
}
.mode-switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 5px;
margin-bottom: 15px;
background: #ded2b8;
border: 2px solid var(--ink);
}
.mode-button {
min-height: 44px;
padding: 9px 7px;
color: var(--ink);
background: transparent;
border: 0;
cursor: pointer;
font-size: 11px;
font-weight: 850;
line-height: 1.2;
text-transform: uppercase;
}
.mode-button[aria-pressed="true"] {
color: #fff9e9;
background: var(--ink);
box-shadow: 3px 3px 0 rgba(32, 53, 43, 0.2);
}
.scenario-note {
display: flex;
gap: 10px;
margin-bottom: 15px;
padding: 11px 12px;
color: #415449;
background: var(--green-light);
border-left: 4px solid var(--green);
font-size: 12px;
line-height: 1.45;
}
.scenario-note .note-icon {
flex: 0 0 auto;
color: var(--green);
font-size: 17px;
font-weight: 900;
}
.comparison-card {
margin-bottom: 13px;
padding: 15px;
background: rgba(255, 252, 243, 0.94);
border: 2px solid var(--ink);
box-shadow: 5px 5px 0 rgba(32, 53, 43, 0.12);
}
.comparison-card.card-b {
border-color: #ba7620;
box-shadow: 5px 5px 0 rgba(186, 118, 32, 0.14);
}
.card-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 10px;
}
.card-name {
display: flex;
align-items: center;
gap: 9px;
}
.fruit-swatch {
width: 25px;
height: 25px;
flex: 0 0 auto;
background:
linear-gradient(135deg, transparent 42%, rgba(255, 255, 255, 0.35) 43% 54%, transparent 55%),
var(--orange);
border: 3px solid #b74d21;
box-shadow: 3px 3px 0 rgba(32, 53, 43, 0.16);
transform: rotate(8deg);
}
.card-b .fruit-swatch {
background:
linear-gradient(135deg, transparent 42%, rgba(255, 255, 255, 0.4) 43% 54%, transparent 55%),
var(--orange-light);
border-color: #bf7a19;
}
.card-name h3 {
margin: 0;
font-size: 14px;
line-height: 1.05;
}
.card-name p {
margin: 4px 0 0;
color: #718077;
font-size: 10px;
}
.count-pill {
flex: 0 0 auto;
padding: 5px 7px;
color: var(--ink);
background: #eee2c8;
border: 1px solid #b9aa8c;
font-size: 10px;
font-weight: 850;
white-space: nowrap;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 13px 0;
}
.metric {
padding: 8px 9px;
background: #f1e8d5;
border: 1px solid #d3c4a7;
}
.metric span,
.metric strong {
display: block;
}
.metric span {
color: #738076;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.metric strong {
margin-top: 3px;
font-size: 15px;
}
.yield-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 8px;
margin-bottom: 7px;
}
.yield-heading span {
color: #65766b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.yield-heading strong {
font-size: 12px;
}
.yield-bar {
position: relative;
height: 18px;
overflow: hidden;
background:
repeating-linear-gradient(
90deg,
transparent 0,
transparent calc(10% - 1px),
rgba(32, 53, 43, 0.12) calc(10% - 1px),
rgba(32, 53, 43, 0.12) 10%
),
#ddd1b8;
border: 2px solid var(--ink);
}
.yield-fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
background:
repeating-linear-gradient(
90deg,
rgba(255, 255, 255, 0.18) 0 7px,
transparent 7px 10px
),
var(--orange);
transition: width 550ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.card-b .yield-fill {
background:
repeating-linear-gradient(
90deg,
rgba(255, 255, 255, 0.22) 0 7px,
transparent 7px 10px
),
var(--orange-light);
}
.scale-note {
margin: -3px 0 17px;
color: #7a867d;
font-size: 9px;
text-align: right;
}
.method-card {
padding: 14px;
color: #f8f0df;
background: var(--ink);
border-bottom: 4px solid var(--orange);
}
.method-card h3 {
margin: 0 0 7px;
color: #ffd36e;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.method-card p {
margin: 0;
color: #dce3d9;
font-size: 11px;
line-height: 1.55;
}
.formula {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-top: 11px;
}
.formula span {
padding: 5px 7px;
color: #fff9e9;
background: rgba(255, 255, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.18);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.press-button {
width: 100%;
min-height: 48px;
margin-top: 13px;
color: #fff9e9;
background: var(--orange);
border: 2px solid var(--ink);
box-shadow: 4px 4px 0 rgba(32, 53, 43, 0.24);
cursor: pointer;
font-size: 12px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.press-button:hover {
background: #f28431;
transform: translateY(-1px);
}
.press-button:active {
box-shadow: 1px 1px 0 rgba(32, 53, 43, 0.24);
transform: translate(2px, 2px);
}
.press-button:disabled {
cursor: wait;
opacity: 0.72;
}
.panel-footer {
margin: 14px 0 0;
color: #718077;
font-size: 10px;
line-height: 1.45;
}
@media (max-width: 900px) {
body {
height: auto;
overflow: auto;
}
.app-header {
height: 66px;
padding: 0 15px;
}
.brand-copy small {
display: none;
}
.illustrative-badge {
max-width: 130px;
font-size: 8px;
text-align: center;
}
main {
display: block;
height: auto;
}
#viewport {
height: 62vh;
min-height: 460px;
}
.panel {
overflow: visible;
padding: 23px 18px 30px;
border-top: 4px solid var(--ink);
border-left: 0;
}
.scene-copy {
top: 18px;
left: 18px;
}
.scene-copy h1 {
max-width: 330px;
font-size: 31px;
}
.scene-copy p {
display: none;
}
.view-tools {
top: auto;
right: 14px;
bottom: 56px;
}
.world-label {
min-width: 92px;
padding: 5px 7px;
}
.world-label strong {
font-size: 9px;
}
.world-label small {
font-size: 8px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<header class="app-header">
<div class="brand">
<div class="voxel-mark" aria-hidden="true">
<span></span><span></span><span></span>
</div>
<div class="brand-copy">
<strong>CITRUS PRESS LAB</strong>
<small>Voxel market demonstration</small>
</div>
</div>
<div class="illustrative-badge">All numbers illustrative</div>
</header>
<main>
<section id="viewport" aria-label="Interactive voxel market scene">
<div class="scene-copy">
<div class="scene-kicker">Market demo / live comparison</div>
<h1 id="scene-title">Equal count.<br />Unequal bulk.</h1>
<p id="scene-description">
Two voxel citrus models share the same fruit count. Compare their
modeled volume with a deliberately illustrative yield proxy.
</p>
</div>
<div class="view-tools">
<button class="tool-button" id="reset-view" type="button">Reset view</button>
</div>
<div class="world-label" id="label-a">
<strong id="world-a-title">8 standard</strong>
<small>1.0 modeled unit each</small>
</div>
<div class="world-label" id="label-b">
<strong id="world-b-title">8 jumbo</strong>
<small>2.5 modeled units each</small>
</div>
<div class="world-label press-label" id="label-press">
<strong>Symbolic press</strong>
<small>Block-by-block mechanism</small>
</div>
<div class="scene-help">
<b>DRAG</b><span>orbit</span>
<b>•</b>
<b>SCROLL</b><span>zoom</span>
</div>
</section>
<aside class="panel" aria-label="Comparison controls and illustrative yield bars">
<div class="panel-kicker">Choose the comparison</div>
<h2>Same fruit.<br />Different questions.</h2>
<p class="panel-intro">
Switch between matching fruit counts and matching modeled fruit volumes.
The bars make the resulting yield proxy easy to compare.
</p>
<div class="mode-switch" role="group" aria-label="Comparison mode">
<button
class="mode-button"
id="mode-count"
type="button"
aria-pressed="true"
>
Equal fruit<br />count
</button>
<button
class="mode-button"
id="mode-volume"
type="button"
aria-pressed="false"
>
Equal fruit<br />volume
</button>
</div>
<div class="scenario-note" id="scenario-note" aria-live="polite">
<span class="note-icon">→</span>
<span id="scenario-text">
Equal counts favor the jumbo model: it carries 2.5× the modeled volume.
</span>
</div>
<article class="comparison-card card-a">
<div class="card-heading">
<div class="card-name">
<span class="fruit-swatch" aria-hidden="true"></span>
<div>
<h3>Standard orange</h3>
<p>1.0 modeled volume unit per fruit</p>
</div>
</div>
<span class="count-pill" id="count-a">8 fruit</span>
</div>
<div class="metrics">
<div class="metric">
<span>Modeled volume</span>
<strong id="volume-a">8.0 units</strong>
</div>
<div class="metric">
<span>Yield proxy</span>
<strong id="proxy-a">6.4 units</strong>
</div>
</div>
<div class="yield-heading">
<span>Illustrative juice-yield proxy</span>
<strong id="yield-a">6.4</strong>
</div>
<div
class="yield-bar"
id="bar-a"
role="img"
aria-label="Standard orange illustrative yield: 6.4 proxy units"
>
<div class="yield-fill" id="fill-a"></div>
</div>
</article>
<article class="comparison-card card-b">
<div class="card-heading">
<div class="card-name">
<span class="fruit-swatch" aria-hidden="true"></span>
<div>
<h3>Jumbo orange</h3>
<p>2.5 modeled volume units per fruit</p>
</div>
</div>
<span class="count-pill" id="count-b">8 fruit</span>
</div>
<div class="metrics">
<div class="metric">
<span>Modeled volume</span>
<strong id="volume-b">20.0 units</strong>
</div>
<div class="metric">
<span>Yield proxy</span>
<strong id="proxy-b">16.0 units</strong>
</div>
</div>
<div class="yield-heading">
<span>Illustrative juice-yield proxy</span>
<strong id="yield-b">16.0</strong>
</div>
<div
class="yield-bar"
id="bar-b"
role="img"
aria-label="Jumbo orange illustrative yield: 16 proxy units"
>
<div class="yield-fill" id="fill-b"></div>
</div>
</article>
<div class="scale-note">Shared illustrative scale: 0–20 proxy units</div>
<section class="method-card">
<h3>How the teaching model works</h3>
<p>
Standard fruit is assigned 1 modeled volume unit and jumbo fruit is
assigned 2.5. Each bar uses an arbitrary 80% conversion to represent
a juice-yield proxy.
</p>
<div class="formula" aria-label="Illustrative calculation formula">
<span>yield proxy = modeled volume × 0.8</span>
</div>
</section>
<button class="press-button" id="run-press" type="button">
Run symbolic press cycle
</button>
<p class="panel-footer">
Teaching visualization only. The yield values are not measured juice,
nutrition, price, agricultural yield, or commercial performance.
</p>
</aside>
</main>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.querySelector("#viewport");
const reducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// -------------------------------------------------------------------------
// Renderer, camera, lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9dfca);
scene.fog = new THREE.Fog(0xe9dfca, 19, 34);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel citrus market. Drag to orbit and scroll to zoom."
);
viewport.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff6df, 0x65705d, 2.0);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe6b8, 3.4);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
scene.add(sun.target);
const fill = new THREE.DirectionalLight(0xb8d7ff, 0.8);
fill.position.set(8, 6, -6);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and reusable geometry helpers
// -------------------------------------------------------------------------
const materials = {
wood: new THREE.MeshStandardMaterial({ color: 0x9a6137, roughness: 0.85 }),
darkWood: new THREE.MeshStandardMaterial({ color: 0x67422d, roughness: 0.9 }),
paleWood: new THREE.MeshStandardMaterial({ color: 0xc58d53, roughness: 0.82 }),
cream: new THREE.MeshStandardMaterial({ color: 0xf6e8c9, roughness: 0.75 }),
red: new THREE.MeshStandardMaterial({ color: 0xb84d3e, roughness: 0.72 }),
steel: new THREE.MeshStandardMaterial({
color: 0x596360,
roughness: 0.5,
metalness: 0.45
}),
darkSteel: new THREE.MeshStandardMaterial({
color: 0x303a38,
roughness: 0.4,
metalness: 0.55
}),
green: new THREE.MeshStandardMaterial({ color: 0x4d7448, roughness: 0.85 }),
juice: new THREE.MeshStandardMaterial({
color: 0xf49b2c,
roughness: 0.35,
emissive: 0x6b2700,
emissiveIntensity: 0.08
})
};
function addBox(
width,
height,
depth,
material,
x,
y,
z,
parent = scene,
castShadow = true,
receiveShadow = true
) {
const geometry = new THREE.BoxGeometry(width, height, depth);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function disposeGroup(group) {
while (group.children.length) {
const child = group.children.pop();
child.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material.dispose();
}
}
});
}
}
// -------------------------------------------------------------------------
// Voxel ground
// -------------------------------------------------------------------------
const tileGeometry = new THREE.BoxGeometry(0.96, 0.18, 0.96);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96
});
const tileCount = 20 * 16;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const tileColors = [
new THREE.Color(0xd9c9a8),
new THREE.Color(0xe3d4b6),
new THREE.Color(0xcdbc9a),
new THREE.Color(0xdfd0b0)
];
const matrix = new THREE.Matrix4();
let tileIndex = 0;
for (let x = 0; x < 20; x++) {
for (let z = 0; z < 16; z++) {
const worldX = x - 10;
const worldZ = z - 8;
matrix.makeTranslation(worldX, -0.10, worldZ);
tiles.setMatrixAt(tileIndex, matrix);
tiles.setColorAt(
tileIndex,
tileColors[(x * 7 + z * 3 + (x + z) % 4) % tileColors.length]
);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// -------------------------------------------------------------------------
// Market stall and voxel sign
// -------------------------------------------------------------------------
function buildStall() {
const stall = new THREE.Group();
addBox(0.34, 5.0, 0.34, materials.darkWood, -6.4, 2.4, -4.9, stall);
addBox(0.34, 5.0, 0.34, materials.darkWood, 6.4, 2.4, -4.9, stall);
addBox(13.1, 0.32, 0.38, materials.darkWood, 0, 4.85, -4.9, stall);
// Awning made from alternating block panels.
for (let i = 0; i < 15; i++) {
const material = i % 2 === 0 ? materials.red : materials.cream;
addBox(
0.88,
0.18,
1.65,
material,
-6.16 + i * 0.88,
5.08,
-4.7,
stall
);
}
// Back shelf.
addBox(12.4, 0.22, 0.9, materials.wood, 0, 1.2, -5.25, stall);
addBox(0.25, 1.3, 0.25, materials.darkWood, -5.8, 0.55, -5.25, stall);
addBox(0.25, 1.3, 0.25, materials.darkWood, 5.8, 0.55, -5.25, stall);
// Small block-built crates on the back shelf.
for (const x of [-5.35, -4.35, 4.25, 5.25]) {
addBox(0.82, 0.16, 0.7, materials.darkWood, x, 1.39, -5.2, stall);
addBox(0.08, 0.48, 0.7, materials.wood, x - 0.36, 1.58, -5.2, stall);
addBox(0.08, 0.48, 0.7, materials.wood, x + 0.36, 1.58, -5.2, stall);
addBox(0.82, 0.48, 0.08, materials.wood, x, 1.58, -4.89, stall);
}
// Sign board.
addBox(3.65, 1.05, 0.18, materials.darkWood, 0, 4.28, -4.28, stall);
const patterns = {
C: ["11111", "10000", "10000", "10000", "10000", "10000", "11111"],
I: ["11111", "00100", "00100", "00100", "00100", "00100", "11111"],
T: ["11111", "00100", "00100", "00100", "00100", "00100", "00100"],
R: ["11110", "10001", "10001", "11110", "10100", "10010", "10001"],
U: ["10001", "10001", "10001", "10001", "10001", "10001", "01110"],
S: ["11111", "10000", "10000", "11111", "00001", "00001", "11111"]
};
const word = "CITRUS";
const pixel = 0.072;
const letterSpacing = 0.17;
[...word].forEach((letter, letterIndex) => {
const pattern = patterns[letter];
pattern.forEach((row, y) => {
[...row].forEach((cell, x) => {
if (cell !== "1") return;
const worldX =
(letterIndex * 6 + x) * pixel -
(word.length * 6 * pixel) / 2 +
pixel / 2;
const worldY = 4.61 - y * pixel;
addBox(
pixel * 0.88,
pixel * 0.88,
0.09,
materials.cream,
worldX,
worldY,
-4.15,
stall,
false,
false
);
});
});
});
scene.add(stall);
}
buildStall();
// -------------------------------------------------------------------------
// Comparison tables and crates
// -------------------------------------------------------------------------
const tableAX = -3.85;
const tableBX = 3.85;
const tableZ = 0.8;
function buildTable(x, crateMaterial) {
const table = new THREE.Group();
addBox(3.8, 0.22, 2.35, materials.paleWood, x, 0.84, tableZ, table);
addBox(3.45, 0.08, 2.05, materials.darkWood, x, 1.01, tableZ, table);
for (const dx of [-1.55, 1.55]) {
for (const dz of [-0.84, 0.84]) {
addBox(
0.26,
0.75,
0.26,
materials.wood,
x + dx,
0.38,
tableZ + dz,
table
);
}
}
addBox(
3.55,
0.16,
0.13,
crateMaterial,
x,
1.11,
tableZ - 0.98,
table
);
addBox(
3.55,
0.16,
0.13,
crateMaterial,
x,
1.11,
tableZ + 0.98,
table
);
addBox(
0.13,
0.16,
1.95,
crateMaterial,
x - 1.72,
1.11,
tableZ,
table
);
addBox(
0.13,
0.16,
1.95,
crateMaterial,
x + 1.72,
1.11,
tableZ,
table
);
scene.add(table);
}
buildTable(tableAX, materials.wood);
buildTable(tableBX, materials.darkWood);
// -------------------------------------------------------------------------
// Symbolic voxel press
// -------------------------------------------------------------------------
const press = new THREE.Group();
press.position.z = -3.0;
scene.add(press);
addBox(3.2, 0.28, 2.25, materials.darkWood, 0, 0.14, 0, press);
addBox(0.34, 3.55, 0.42, materials.steel, -1.12, 2.05, -0.1, press);
addBox(0.34, 3.55, 0.42, materials.steel, 1.12, 2.05, -0.1, press);
addBox(2.7, 0.34, 0.48, materials.darkSteel, 0, 3.9, -0.1, press);
// Screw made from visible stacked blocks.
for (let i = 0; i < 8; i++) {
addBox(
0.46 - i * 0.012,
0.12,
0.46 - i * 0.012,
i % 2 === 0 ? materials.steel : materials.darkSteel,
0,
3.43 - i * 0.14,
-0.1,
press
);
}
const pressHead = addBox(
1.35,
0.3,
1.08,
materials.red,
0,
2.56,
-0.08,
press
);
addBox(2.15, 0.18, 1.55, materials.steel, 0, 1.45, 0.05, press);
addBox(1.45, 0.16, 0.92, materials.darkWood, 0, 1.61, 0.05, press);
// A voxel orange on the press tray.
for (let x = -2; x <= 2; x++) {
for (let y = -2; y <= 2; y++) {
for (let z = -2; z <= 2; z++) {
if (x * x + y * y + z * z > 5) continue;
addBox(
0.12,
0.12,
0.12,
materials.juice,
x * 0.12,
1.78 + y * 0.12,
0.05 + z * 0.12,
press
);
}
}
}
// Lever pivots around the press head.
const lever = new THREE.Group();
lever.position.set(0, 2.74, 0.46);
press.add(lever);
addBox(2.7, 0.22, 0.24, materials.steel, 1.18, 0, 0, lever);
addBox(0.72, 0.28, 0.32, materials.red, 2.55, 0, 0, lever);
addBox(0.36, 0.36, 0.36, materials.darkSteel, 0, 0, 0, lever);
// Catch bucket under the spout.
addBox(0.95, 0.12, 0.95, materials.darkSteel, 0, 0.32, 1.0, press);
addBox(0.10, 0.65, 0.95, materials.steel, -0.42, 0.60, 1.0, press);
addBox(0.10, 0.65, 0.95, materials.steel, 0.42, 0.60, 1.0, press);
addBox(0.95, 0.65, 0.10, materials.steel, 0, 0.60, 0.56, press);
addBox(0.95, 0.65, 0.10, materials.steel, 0, 0.60, 1.44, press);
addBox(0.73, 0.10, 0.73, materials.juice, 0, 0.83, 1.0, press);
// Falling juice voxels.
const juiceDrops = [];
for (let i = 0; i < 7; i++) {
const drop = addBox(
0.095,
0.095,
0.095,
materials.juice,
(i % 2 ? 0.04 : -0.04),
1.45 - i * 0.14,
0.95,
press,
false,
false
);
juiceDrops.push(drop);
}
// -------------------------------------------------------------------------
// Voxel fruit generation
// -------------------------------------------------------------------------
const produceGroup = new THREE.Group();
scene.add(produceGroup);
const blockGeometry = new THREE.BoxGeometry(0.105, 0.105, 0.105);
const fruitMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.7,
metalness: 0
});
const fruitDefinitions = {
standard: {
gridSize: 5,
spacing: 0.115,
baseColor: new THREE.Color(0xed7628),
seed: 11
},
jumbo: {
gridSize: 7,
spacing: 0.115,
baseColor: new THREE.Color(0xf4a52d),
seed: 29
}
};
function hashNoise(x, y, z, seed) {
const value = Math.sin(
x * 127.1 + y * 311.7 + z * 74.7 + seed * 19.19
) * 43758.5453;
return value - Math.floor(value);
}
function addFruitBlocks(instanceData, centerX, centerY, centerZ, type) {
const definition = fruitDefinitions[type];
const half = Math.floor(definition.gridSize / 2);
const { spacing, baseColor, seed } = definition;
for (let x = -half; x <= half; x++) {
for (let y = -half; y <= half; y++) {
for (let z = -half; z <= half; z++) {
const distance =
(x * x + y * y + z * z) / (half * half);
if (distance > 1.04) continue;
const noise = hashNoise(x + centerX, y, z + centerZ, seed);
const color = baseColor.clone();
color.offsetHSL(
(noise - 0.5) * 0.025,
(noise - 0.5) * 0.08,
(noise - 0.5) * 0.11
);
instanceData.push({
x: centerX + x * spacing,
y: centerY + y * spacing,
z: centerZ + z * spacing,
color
});
}
}
}
// A chunky green leaf makes each fruit read clearly at a distance.
instanceData.push({
x: centerX + 0.035,
y: centerY + (half + 0.42) * spacing,
z: centerZ,
color: new THREE.Color(0x4e7848)
});
}
function layoutFor(type, count) {
const isStandard = type === "standard";
if (isStandard && count === 8) {
return {
columns: 4,
xPositions: [-1.2, -0.4, 0.4, 1.2],
zPositions: [-0.42, 0.42]
};
}
if (!isStandard && count === 8) {
return {
columns: 4,
xPositions: [-1.35, -0.45, 0.45, 1.35],
zPositions: [-0.49, 0.49]
};
}
if (isStandard && count === 10) {
return {
columns: 5,
xPositions: [-1.44, -0.72, 0, 0.72, 1.44],
zPositions: [-0.42, 0.42]
};
}
return {
columns: 2,
xPositions: [-0.58, 0.58],
zPositions: [-0.49, 0.49]
};
}
function rebuildProduce(mode) {
disposeGroup(produceGroup);
const instanceData = [];
const standardCount = mode === "count" ? 8 : 10;
const jumboCount = mode === "count" ? 8 : 4;
const standardLayout = layoutFor("standard", standardCount);
const jumboLayout = layoutFor("jumbo", jumboCount);
function placeGroup(type, count, tableX, layout) {
const definition = fruitDefinitions[type];
const extent = (definition.gridSize * definition.spacing) / 2;
const centerY = 1.12 + extent + 0.025;
for (let index = 0; index < count; index++) {
const column = index % layout.columns;
const row = Math.floor(index / layout.columns);
addFruitBlocks(
instanceData,
tableX + layout.xPositions[column],
centerY,
tableZ + layout.zPositions[row],
type
);
}
}
placeGroup("standard", standardCount, tableAX, standardLayout);
placeGroup("jumbo", jumboCount, tableBX, jumboLayout);
const fruitMesh = new THREE.InstancedMesh(
blockGeometry,
fruitMaterial,
instanceData.length
);
const localMatrix = new THREE.Matrix4();
instanceData.forEach((block, index) => {
localMatrix.makeTranslation(block.x, block.y, block.z);
fruitMesh.setMatrixAt(index, localMatrix);
fruitMesh.setColorAt(index, block.color);
});
fruitMesh.instanceMatrix.needsUpdate = true;
fruitMesh.instanceColor.needsUpdate = true;
fruitMesh.castShadow = true;
fruitMesh.receiveShadow = true;
fruitMesh.computeBoundingSphere();
produceGroup.add(fruitMesh);
}
// -------------------------------------------------------------------------
// Comparison data and UI
// -------------------------------------------------------------------------
const comparisons = {
count: {
a: { count: 8, volume: 8.0, yield: 6.4 },
b: { count: 8, volume: 20.0, yield: 16.0 },
title: "Equal count.<br />Unequal bulk.",
description:
"Two voxel citrus models share the same fruit count. Compare their modeled volume with a deliberately illustrative yield proxy.",
note:
"Equal counts favor the jumbo model: it carries 2.5× the modeled volume.",
worldA: "8 standard",
worldB: "8 jumbo"
},
volume: {
a: { count: 10, volume: 10.0, yield: 8.0 },
b: { count: 4, volume: 10.0, yield: 8.0 },
title: "Equal volume.<br />Unequal count.",
description:
"Ten standard fruit and four jumbo fruit carry the same modeled volume. Their illustrative yield bars therefore match.",
note:
"Equal modeled volume needs 10 standard fruit or 4 jumbo fruit; both yield proxies match.",
worldA: "10 standard",
worldB: "4 jumbo"
}
};
const maxYieldScale = 20;
let currentMode = "count";
function setText(id, value) {
document.querySelector(`#${id}`).textContent = value;
}
function applyMode(mode) {
currentMode = mode;
const data = comparisons[mode];
document.querySelector("#mode-count").setAttribute(
"aria-pressed",
String(mode === "count")
);
document.querySelector("#mode-volume").setAttribute(
"aria-pressed",
String(mode === "volume")
);
document.querySelector("#scene-title").innerHTML = data.title;
setText("scene-description", data.description);
setText("scenario-text", data.note);
setText("world-a-title", data.worldA);
setText("world-b-title", data.worldB);
setText("count-a", `${data.a.count} fruit`);
setText("count-b", `${data.b.count} fruit`);
setText("volume-a", `${data.a.volume.toFixed(1)} units`);
setText("volume-b", `${data.b.volume.toFixed(1)} units`);
setText("proxy-a", `${data.a.yield.toFixed(1)} units`);
setText("proxy-b", `${data.b.yield.toFixed(1)} units`);
setText("yield-a", data.a.yield.toFixed(1));
setText("yield-b", data.b.yield.toFixed(1));
document.querySelector("#fill-a").style.width =
`${(data.a.yield / maxYieldScale) * 100}%`;
document.querySelector("#fill-b").style.width =
`${(data.b.yield / maxYieldScale) * 100}%`;
document.querySelector("#bar-a").setAttribute(
"aria-label",
`Standard orange illustrative yield: ${data.a.yield} proxy units`
);
document.querySelector("#bar-b").setAttribute(
"aria-label",
`Jumbo orange illustrative yield: ${data.b.yield} proxy units`
);
rebuildProduce(mode);
}
document.querySelector("#mode-count").addEventListener("click", () => {
applyMode("count");
});
document.querySelector("#mode-volume").addEventListener("click", () => {
applyMode("volume");
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom, keyboard, double-click reset
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.45, -0.65);
const defaultCamera = {
radius: 15.8,
theta: 0.42,
phi: 1.02
};
const orbit = { ...defaultCamera };
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
cameraTarget.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
cameraTarget.y + orbit.radius * Math.cos(orbit.phi),
cameraTarget.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
orbit.radius = defaultCamera.radius;
orbit.theta = defaultCamera.theta;
orbit.phi = defaultCamera.phi;
cameraTarget.set(0, 1.45, -0.65);
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
orbit.theta -= deltaX * 0.005;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.45,
1.42
);
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();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
9,
24
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
const step = 0.08;
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta += step;
break;
case "ArrowRight":
orbit.theta -= step;
break;
case "ArrowUp":
orbit.phi = Math.max(0.45, orbit.phi - step);
break;
case "ArrowDown":
orbit.phi = Math.min(1.42, orbit.phi + step);
break;
case "+":
case "=":
orbit.radius = Math.max(9, orbit.radius - 0.8);
break;
case "-":
orbit.radius = Math.min(24, orbit.radius + 0.8);
break;
case "0":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
document.querySelector("#reset-view").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Symbolic press animation
// -------------------------------------------------------------------------
let pressTime = 0;
const pressButton = document.querySelector("#run-press");
pressButton.addEventListener("click", () => {
pressTime = 1.25;
pressButton.disabled = true;
pressButton.textContent = "Pressing…";
});
function updatePress(delta) {
if (pressTime <= 0) {
pressHead.position.y = 2.56;
lever.rotation.z = 0;
juiceDrops.forEach((drop) => {
drop.visible = false;
});
return;
}
pressTime = Math.max(0, pressTime - delta);
const progress = 1 - pressTime / 1.25;
const power = Math.sin(progress * Math.PI);
pressHead.position.y = 2.56 - power * 0.33;
lever.rotation.z = -power * 0.17;
juiceDrops.forEach((drop, index) => {
drop.visible = power > 0.12;
const cycle = (performance.now() * 0.0017 + index * 0.14) % 1;
drop.position.y = 1.45 - cycle * 0.72;
drop.position.x = (index % 2 ? 1 : -1) * 0.035;
});
if (pressTime === 0) {
pressButton.disabled = false;
pressButton.textContent = "Run symbolic press cycle";
}
}
// -------------------------------------------------------------------------
// Project HTML labels into the Three.js scene
// -------------------------------------------------------------------------
const labelDefinitions = [
{
element: document.querySelector("#label-a"),
position: new THREE.Vector3(tableAX, 2.48, tableZ)
},
{
element: document.querySelector("#label-b"),
position: new THREE.Vector3(tableBX, 2.48, tableZ)
},
{
element: document.querySelector("#label-press"),
position: new THREE.Vector3(0, 4.43, -3.0)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
labelDefinitions.forEach((label) => {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
label.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.opacity = "1";
});
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
applyMode("count");
resetCamera();
resize();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
updatePress(delta);
updateLabels();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```