Prompt specification
Build or customize the Three.js 3D scene "Fruit size grading apertures" 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: Fruit size grading apertures
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/fruit-size-grading-apertures-x1093
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts produce grading. Display several fruit models beside circular grading openings of different diameters; make size the only active criterion so the classification rule is directly observable. Stylized solid forms.
Working Three.js Starter (fruit-size-grading-apertures-x1093):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Produce Size Grading</title>
<style>
:root {
--ink: #18342f;
--muted: #66746f;
--paper: #f5f2e9;
--panel: rgba(250, 248, 241, 0.92);
--green: #287a63;
--green-soft: #dcebe4;
--coral: #d85d47;
--coral-soft: #f4dfd8;
--line: rgba(24, 52, 47, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eae6dc;
color: var(--ink);
font-family:
Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.brand {
position: absolute;
top: 30px;
left: 34px;
max-width: 440px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
content: "";
background: var(--green);
}
h1 {
margin: 0;
font-size: clamp(34px, 4vw, 58px);
font-weight: 750;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
letter-spacing: 0.01em;
}
.rule-panel {
position: absolute;
top: 28px;
right: 28px;
width: 310px;
padding: 19px;
overflow: hidden;
border: 1px solid rgba(255, 255, 255, 0.78);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 18px 55px rgba(42, 56, 49, 0.11),
inset 0 0 0 1px rgba(24, 52, 47, 0.04);
backdrop-filter: blur(14px);
pointer-events: none;
}
.panel-heading {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--green);
}
.live-dot::before {
width: 7px;
height: 7px;
content: "";
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(40, 122, 99, 0.12);
}
.criteria {
display: grid;
gap: 7px;
}
.criterion {
display: flex;
align-items: center;
justify-content: space-between;
min-height: 43px;
padding: 0 13px;
border: 1px solid var(--line);
border-radius: 12px;
color: #89918d;
background: rgba(255, 255, 255, 0.32);
font-size: 13px;
font-weight: 700;
}
.criterion.active {
color: var(--ink);
border-color: rgba(40, 122, 99, 0.24);
background: var(--green-soft);
}
.criterion span {
display: flex;
align-items: center;
gap: 10px;
}
.criterion.active span::before {
width: 8px;
height: 8px;
content: "";
border-radius: 3px;
background: var(--green);
}
.criterion b {
font-size: 10px;
letter-spacing: 0.12em;
}
.criterion.active b {
color: var(--green);
}
.rule {
display: grid;
grid-template-columns: 38px 1fr;
gap: 12px;
align-items: center;
margin-top: 14px;
padding: 14px;
border-radius: 14px;
color: #f8f5eb;
background: var(--ink);
}
.rule-number {
display: grid;
width: 38px;
height: 38px;
place-items: center;
border-radius: 11px;
color: var(--ink);
background: #d7e8df;
font-size: 12px;
font-weight: 900;
}
.rule strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
}
.rule span {
display: block;
color: #bfcac5;
font-size: 12px;
line-height: 1.35;
}
.summary {
position: absolute;
bottom: 27px;
left: 50%;
display: flex;
gap: 25px;
align-items: center;
padding: 12px 20px;
transform: translateX(-50%);
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 999px;
background: rgba(250, 248, 241, 0.82);
box-shadow: 0 8px 28px rgba(39, 52, 45, 0.08);
backdrop-filter: blur(12px);
white-space: nowrap;
}
.summary-item {
display: flex;
gap: 7px;
align-items: baseline;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.summary-item strong {
color: var(--ink);
font-size: 15px;
}
.summary-divider {
width: 1px;
height: 20px;
background: var(--line);
}
.reset {
position: absolute;
right: 28px;
bottom: 28px;
display: flex;
gap: 8px;
align-items: center;
padding: 11px 15px;
border: 1px solid rgba(24, 52, 47, 0.14);
border-radius: 999px;
color: var(--ink);
background: rgba(250, 248, 241, 0.86);
box-shadow: 0 8px 28px rgba(39, 52, 45, 0.08);
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
pointer-events: auto;
transition:
transform 160ms ease,
background 160ms ease;
}
.reset:hover {
transform: translateY(-2px);
background: #fffdf7;
}
.reset svg {
width: 14px;
height: 14px;
}
.loader {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--ink);
background: #eae6dc;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
.loader.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 850px) {
.brand {
top: 20px;
left: 20px;
}
h1 {
font-size: 38px;
}
.subtitle {
display: none;
}
.rule-panel {
top: auto;
right: 16px;
bottom: 72px;
width: 270px;
padding: 14px;
border-radius: 18px;
}
.criteria {
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.criterion {
min-height: 37px;
padding: 0 7px;
font-size: 10px;
}
.criterion span {
gap: 0;
}
.criterion.active span::before {
display: none;
}
.criterion b {
display: none;
}
.rule {
margin-top: 9px;
padding: 10px;
}
.summary {
left: 16px;
bottom: 20px;
transform: none;
gap: 12px;
padding: 10px 14px;
}
.summary-item:nth-of-type(4),
.summary-item:nth-of-type(5),
.summary-divider:last-of-type {
display: none;
}
.reset {
right: 16px;
bottom: 20px;
}
}
@media (max-width: 560px) {
.brand {
top: 16px;
left: 16px;
}
h1 {
font-size: 31px;
}
.eyebrow {
font-size: 9px;
}
.rule-panel {
right: 12px;
bottom: 66px;
width: calc(100% - 24px);
}
.summary {
display: none;
}
.reset {
right: 12px;
bottom: 16px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D produce size-grading scene. Drag to orbit and scroll to zoom."
></canvas>
<div class="hud">
<header class="brand">
<div class="eyebrow">Produce line / inspection 03</div>
<h1>Size grading</h1>
<p class="subtitle">One active rule. Every fruit has a place.</p>
</header>
<aside class="rule-panel" aria-label="Active grading criteria">
<div class="panel-heading">
<span>Active criteria</span>
<span class="live-dot">Running</span>
</div>
<div class="criteria">
<div class="criterion active">
<span>Size</span>
<b>On</b>
</div>
<div class="criterion">
<span>Shape</span>
<b>Off</b>
</div>
<div class="criterion">
<span>Color</span>
<b>Off</b>
</div>
<div class="criterion">
<span>Defects</span>
<b>Off</b>
</div>
</div>
<div class="rule">
<div class="rule-number">01</div>
<div>
<strong>Pass when fruit width ≤ opening</strong>
<span>Larger fruit is held as “too large.”</span>
</div>
</div>
</aside>
<div class="summary" aria-live="polite">
<div class="summary-item"><strong>6</strong> samples</div>
<div class="summary-divider"></div>
<div class="summary-item"><strong>3</strong> size gates</div>
<div class="summary-divider"></div>
<div class="summary-item"><strong>1</strong> active rule</div>
</div>
<button class="reset" id="reset" type="button">
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path
d="M4 8V4m0 0h4M4 4l4.2 4.2a7 7 0 1 1-1 7.8"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
Reset view
</button>
</div>
<div class="loader" id="loader">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";
const canvas = document.querySelector("#scene");
const loader = document.querySelector("#loader");
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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#eae6dc");
scene.fog = new THREE.Fog("#eae6dc", 18, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 0.8, 0);
const defaultCamera = {
yaw: 0.18,
pitch: 0.64,
radius: 13.6
};
const cameraState = { ...defaultCamera };
function updateCamera() {
const { yaw, pitch, radius } = cameraState;
camera.position.set(
target.x + radius * Math.sin(yaw) * Math.cos(pitch),
target.y + radius * Math.sin(pitch),
target.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#fffdf5", "#777b70", 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight("#fff8e9", 4.2);
keyLight.position.set(-4.5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#c7e5df", 1.55);
fillLight.position.set(8, 5, -5);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight("#ffd3a8", 1.1);
rimLight.position.set(-7, 4, -8);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: "#d9d5ca",
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const inkMaterial = new THREE.MeshStandardMaterial({
color: "#18342f",
roughness: 0.72,
metalness: 0.08
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: "#294a43",
roughness: 0.68,
metalness: 0.12
});
const topMaterial = new THREE.MeshStandardMaterial({
color: "#f0ecdf",
roughness: 0.78,
metalness: 0.02
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: "#172724",
roughness: 0.85,
metalness: 0.04
});
function roundedRectShape(width, height, radius) {
const shape = new THREE.Shape();
const left = -width / 2;
const right = width / 2;
const bottom = -height / 2;
const top = height / 2;
shape.moveTo(left + radius, bottom);
shape.lineTo(right - radius, bottom);
shape.absarc(right - radius, bottom + radius, radius, -Math.PI / 2, 0, false);
shape.lineTo(right, top - radius);
shape.absarc(right - radius, top - radius, radius, 0, Math.PI / 2, false);
shape.lineTo(left + radius, top);
shape.absarc(left + radius, top - radius, radius, Math.PI / 2, Math.PI, false);
shape.lineTo(left, bottom + radius);
shape.absarc(left + radius, bottom + radius, radius, Math.PI, Math.PI * 1.5, false);
shape.closePath();
return shape;
}
const TABLE_TOP_Y = 0.94;
const gateDefinitions = [
{ x: -3.55, radius: 0.42, millimeters: 70, label: "GATE 01" },
{ x: 0, radius: 0.60, millimeters: 100, label: "GATE 02" },
{ x: 3.55, radius: 0.78, millimeters: 130, label: "GATE 03" }
];
// The slab contains three real circular openings.
const slabShape = roundedRectShape(11.2, 5.4, 0.34);
for (const gate of gateDefinitions) {
const hole = new THREE.Path();
hole.absarc(gate.x, 0.42, gate.radius, 0, Math.PI * 2, true);
slabShape.holes.push(hole);
}
const slabGeometry = new THREE.ExtrudeGeometry(slabShape, {
depth: 0.22,
bevelEnabled: true,
bevelThickness: 0.035,
bevelSize: 0.035,
bevelSegments: 2,
curveSegments: 48
});
slabGeometry.computeVertexNormals();
const slab = new THREE.Mesh(slabGeometry, topMaterial);
slab.rotation.x = -Math.PI / 2;
slab.position.y = 0.67;
slab.castShadow = true;
slab.receiveShadow = true;
scene.add(slab);
const underframe = new THREE.Mesh(
new THREE.BoxGeometry(10.9, 0.22, 5.05),
frameMaterial
);
underframe.position.set(0, 0.57, 0);
underframe.castShadow = true;
underframe.receiveShadow = true;
scene.add(underframe);
const frontFascia = new THREE.Mesh(
new THREE.BoxGeometry(10.95, 0.43, 0.16),
frameMaterial
);
frontFascia.position.set(0, 0.66, 2.76);
frontFascia.castShadow = true;
scene.add(frontFascia);
for (const x of [-5.0, 5.0]) {
for (const z of [-2.15, 2.15]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.68, 0.22),
inkMaterial
);
leg.position.set(x, 0.27, z);
leg.castShadow = true;
scene.add(leg);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.18, 0.18, 0.07, 24),
darkMaterial
);
foot.position.set(x, 0.035, z);
foot.castShadow = true;
scene.add(foot);
}
}
// Recessed opening wells and dimensional graphics.
const apertureRings = [];
const scanDots = [];
function makeDiameterGraphic(radius, color, dashed = true) {
const group = new THREE.Group();
const lineMaterial = dashed
? new THREE.LineDashedMaterial({
color,
dashSize: 0.075,
gapSize: 0.045,
transparent: true,
opacity: 0.9,
depthTest: false,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.96,
depthTest: false,
depthWrite: false
});
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-radius, 0, 0),
new THREE.Vector3(radius, 0, 0)
]),
lineMaterial
);
if (dashed) line.computeLineDistances();
line.renderOrder = 8;
group.add(line);
const tickGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-radius, -0.07, 0),
new THREE.Vector3(-radius, 0.07, 0),
new THREE.Vector3(radius, -0.07, 0),
new THREE.Vector3(radius, 0.07, 0)
]);
const ticks = new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
})
);
ticks.renderOrder = 8;
group.add(ticks);
return group;
}
for (const gate of gateDefinitions) {
const wellBottom = new THREE.Mesh(
new THREE.CylinderGeometry(
gate.radius * 0.985,
gate.radius * 0.985,
0.07,
48
),
darkMaterial
);
wellBottom.position.set(gate.x, 0.7, -0.42);
wellBottom.receiveShadow = true;
scene.add(wellBottom);
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(
gate.radius * 0.985,
gate.radius * 0.985,
0.22,
48,
1,
true
),
new THREE.MeshStandardMaterial({
color: "#445b54",
roughness: 0.75,
metalness: 0.18,
side: THREE.DoubleSide
})
);
wall.position.set(gate.x, 0.79, -0.42);
scene.add(wall);
const ringMaterial = new THREE.MeshStandardMaterial({
color: "#287a63",
emissive: "#174c3f",
emissiveIntensity: 0.09,
roughness: 0.48,
metalness: 0.16
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(gate.radius + 0.035, 0.045, 16, 72),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.set(gate.x, TABLE_TOP_Y + 0.025, -0.42);
ring.castShadow = true;
scene.add(ring);
apertureRings.push(ring);
const apertureGraphic = makeDiameterGraphic(
gate.radius,
"#3b806d",
true
);
apertureGraphic.position.set(gate.x, TABLE_TOP_Y + 0.035, -0.42);
scene.add(apertureGraphic);
const scanDot = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 16, 12),
new THREE.MeshBasicMaterial({ color: "#d4f1df" })
);
scanDot.position.set(gate.x, TABLE_TOP_Y + 0.05, -0.42);
scanDot.renderOrder = 9;
scene.add(scanDot);
scanDots.push({ mesh: scanDot, gate });
}
function roundedCanvasRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function createBadge(mainText, subText, accent, dark = false) {
const badgeCanvas = document.createElement("canvas");
badgeCanvas.width = 1024;
badgeCanvas.height = 280;
const ctx = badgeCanvas.getContext("2d");
const background = dark ? "rgba(24,52,47,0.96)" : "rgba(250,248,241,0.96)";
const primary = dark ? "#f9f5e9" : "#18342f";
const secondary = dark ? "#bdcbc5" : "#66746f";
roundedCanvasRect(ctx, 8, 8, 1008, 264, 38);
ctx.fillStyle = background;
ctx.fill();
roundedCanvasRect(ctx, 27, 27, 13, 226, 6);
ctx.fillStyle = accent;
ctx.fill();
ctx.fillStyle = primary;
ctx.font = "800 70px Arial, sans-serif";
ctx.textBaseline = "middle";
ctx.fillText(mainText, 68, 101);
ctx.fillStyle = secondary;
ctx.font = "600 39px Arial, sans-serif";
ctx.fillText(subText, 70, 190);
const texture = new THREE.CanvasTexture(badgeCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.05, 0.56, 1);
sprite.renderOrder = 20;
return sprite;
}
for (const gate of gateDefinitions) {
const badge = createBadge(
gate.label,
`OPENING Ø ${gate.millimeters} mm`,
"#287a63"
);
badge.position.set(gate.x, 1.56, -2.38);
badge.scale.set(2.15, 0.59, 1);
scene.add(badge);
}
// A second explanatory label on the machine itself.
const fasciaCanvas = document.createElement("canvas");
fasciaCanvas.width = 1536;
fasciaCanvas.height = 150;
const fasciaCtx = fasciaCanvas.getContext("2d");
fasciaCtx.clearRect(0, 0, fasciaCanvas.width, fasciaCanvas.height);
fasciaCtx.fillStyle = "#dcebe4";
fasciaCtx.font = "800 52px Arial, sans-serif";
fasciaCtx.textAlign = "center";
fasciaCtx.textBaseline = "middle";
fasciaCtx.fillText(
"SIZE ONLY / PASS IF FRUIT WIDTH ≤ OPENING",
768,
75
);
const fasciaTexture = new THREE.CanvasTexture(fasciaCanvas);
fasciaTexture.colorSpace = THREE.SRGBColorSpace;
const fasciaLabel = new THREE.Mesh(
new THREE.PlaneGeometry(6.4, 0.63),
new THREE.MeshBasicMaterial({
map: fasciaTexture,
transparent: true,
toneMapped: false
})
);
fasciaLabel.position.set(0, 0.68, 2.845);
scene.add(fasciaLabel);
function makeFruit(kind, diameterWorld) {
const group = new THREE.Group();
const palettes = {
lime: {
body: "#7fbf35",
stem: "#5d3c24",
leaf: "#3f7c32"
},
plum: {
body: "#684069",
stem: "#65452d",
leaf: "#4d7f3e"
},
orange: {
body: "#ef8d28",
stem: "#75502d",
leaf: "#377a42"
},
apple: {
body: "#cf4438",
stem: "#65432b",
leaf: "#4c843b"
},
grapefruit: {
body: "#b9c84c",
stem: "#725333",
leaf: "#3c7d43"
},
melon: {
body: "#39785b",
stem: "#715332",
leaf: "#397842"
}
};
const palette = palettes[kind];
const bodyMaterial = new THREE.MeshStandardMaterial({
color: palette.body,
roughness: kind === "orange" ? 0.88 : 0.7,
metalness: 0
});
const body = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 36, 24),
bodyMaterial
);
body.position.y = 0.5;
if (kind === "apple") body.scale.set(1, 0.9, 0.95);
if (kind === "plum") body.scale.set(1, 1.06, 0.93);
if (kind === "grapefruit") body.scale.set(1, 0.97, 1);
if (kind === "melon") body.scale.set(1, 0.97, 1.08);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const stemMaterial = new THREE.MeshStandardMaterial({
color: palette.stem,
roughness: 0.9
});
const leafMaterial = new THREE.MeshStandardMaterial({
color: palette.leaf,
roughness: 0.85
});
function addStem(height = 0.18, leaf = true) {
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.04, height, 12),
stemMaterial
);
stem.position.set(0, 0.96 + height * 0.35, 0);
stem.rotation.z = kind === "apple" ? -0.16 : 0.08;
stem.castShadow = true;
group.add(stem);
if (leaf) {
const leaf = new THREE.Mesh(
new THREE.SphereGeometry(0.13, 18, 10),
leafMaterial
);
leaf.scale.set(1.55, 0.22, 0.72);
leaf.position.set(
kind === "apple" ? 0.13 : 0.1,
1.0 + height * 0.5,
0
);
leaf.rotation.z = kind === "apple" ? -0.34 : 0.25;
leaf.castShadow = true;
group.add(leaf);
}
}
if (kind === "apple" || kind === "plum") {
addStem(0.18, true);
} else if (kind === "orange" || kind === "grapefruit") {
addStem(0.1, true);
const dimple = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.02, 0.025, 16),
new THREE.MeshStandardMaterial({
color: kind === "orange" ? "#b75e24" : "#819132",
roughness: 1
})
);
dimple.position.set(0.06, 0.984, 0);
group.add(dimple);
} else if (kind === "lime") {
const nub = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 14, 10),
stemMaterial
);
nub.scale.set(1, 0.6, 1);
nub.position.y = 0.985;
group.add(nub);
} else {
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.05, 0.08, 12),
stemMaterial
);
stem.position.y = 0.995;
group.add(stem);
}
// Rounded, solid color ribs give the melon a stylized form.
if (kind === "melon") {
const ribMaterial = new THREE.MeshStandardMaterial({
color: "#2b644c",
roughness: 0.78
});
for (let i = 0; i < 4; i++) {
const rib = new THREE.Mesh(
new THREE.TorusGeometry(0.485, 0.012, 8, 48, Math.PI),
ribMaterial
);
rib.rotation.y = (i / 4) * Math.PI;
rib.position.y = 0.5;
group.add(rib);
}
}
group.scale.setScalar(diameterWorld);
return group;
}
const passColor = "#287a63";
const failColor = "#d85d47";
function addStatusGraphics(group, statusColor) {
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.58, 0.018, 10, 64),
new THREE.MeshBasicMaterial({
color: statusColor,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
})
);
halo.rotation.x = Math.PI / 2;
halo.position.y = 0.012;
halo.renderOrder = 9;
group.add(halo);
// The colored caliper line directly indicates measured fruit width.
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.5, 0.5, 0.515),
new THREE.Vector3(0.5, 0.5, 0.515)
]),
new THREE.LineBasicMaterial({
color: statusColor,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
})
);
line.renderOrder = 12;
group.add(line);
const ticks = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.5, 0.43, 0.515),
new THREE.Vector3(-0.5, 0.57, 0.515),
new THREE.Vector3(0.5, 0.43, 0.515),
new THREE.Vector3(0.5, 0.57, 0.515)
]),
new THREE.LineBasicMaterial({
color: statusColor,
transparent: true,
opacity: 0.98,
depthTest: false,
depthWrite: false
})
);
ticks.renderOrder = 12;
group.add(ticks);
}
const samples = [
{
kind: "lime",
x: -4.27,
z: 0.98,
millimeters: 56,
gate: 70,
pass: true
},
{
kind: "plum",
x: -2.82,
z: 1.67,
millimeters: 80,
gate: 70,
pass: false
},
{
kind: "orange",
x: -0.72,
z: 0.98,
millimeters: 94,
gate: 100,
pass: true
},
{
kind: "apple",
x: 0.73,
z: 1.67,
millimeters: 108,
gate: 100,
pass: false
},
{
kind: "grapefruit",
x: 2.83,
z: 0.98,
millimeters: 126,
gate: 130,
pass: true
},
{
kind: "melon",
x: 4.28,
z: 1.67,
millimeters: 144,
gate: 130,
pass: false
}
];
// One world unit equals 12 millimeters.
const millimetersToWorld = 0.012;
for (const sample of samples) {
const diameterWorld = sample.millimeters * millimetersToWorld;
const fruit = makeFruit(sample.kind, diameterWorld);
fruit.position.set(sample.x, TABLE_TOP_Y, sample.z);
fruit.userData.baseY = TABLE_TOP_Y;
addStatusGraphics(fruit, sample.pass ? passColor : failColor);
scene.add(fruit);
const main = sample.pass ? "PASS" : "TOO LARGE";
const comparison = sample.pass ? "≤" : ">";
const sub = `${sample.millimeters} mm ${comparison} ${sample.gate} mm`;
const badge = createBadge(
main,
sub,
sample.pass ? passColor : failColor,
!sample.pass
);
badge.position.set(
sample.x,
TABLE_TOP_Y + diameterWorld * 1.02 + 0.48,
sample.z
);
badge.scale.set(1.83, 0.5, 1);
scene.add(badge);
}
// Small decorative fasteners reinforce the industrial product design.
const fastenerMaterial = new THREE.MeshStandardMaterial({
color: "#b9c4bd",
roughness: 0.35,
metalness: 0.7
});
for (const x of [-5.25, -2.95, -0.35, 2.25, 4.85]) {
for (const z of [-2.45, 2.42]) {
const fastener = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.025, 16),
fastenerMaterial
);
fastener.position.set(x, TABLE_TOP_Y + 0.005, z);
scene.add(fastener);
}
}
// Direct camera controls implemented without addons.
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= deltaX * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.005,
0.28,
1.12
);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
9,
18
);
updateCamera();
},
{ passive: false }
);
function resetView() {
Object.assign(cameraState, defaultCamera);
updateCamera();
}
document.querySelector("#reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
canvas.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") cameraState.yaw += 0.08;
else if (event.key === "ArrowRight") cameraState.yaw -= 0.08;
else if (event.key === "ArrowUp") cameraState.pitch += 0.06;
else if (event.key === "ArrowDown") cameraState.pitch -= 0.06;
else if (event.key.toLowerCase() === "r") {
resetView();
return;
} else {
return;
}
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch,
0.28,
1.12
);
updateCamera();
event.preventDefault();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
apertureRings.forEach((ring, index) => {
ring.material.emissiveIntensity =
0.08 + (Math.sin(elapsed * 2.2 - index * 0.8) * 0.5 + 0.5) * 0.12;
});
scanDots.forEach(({ mesh, gate }, index) => {
const progress = (elapsed * 0.31 + index * 0.23) % 1;
mesh.position.x = gate.x - gate.radius + progress * gate.radius * 2;
mesh.position.z = -0.42 + Math.sin(progress * Math.PI) * 0.015;
mesh.material.opacity = 0.65 + Math.sin(progress * Math.PI) * 0.35;
});
renderer.render(scene, camera);
}
animate();
loader.classList.add("hidden");
window.setTimeout(() => loader.remove(), 350);
</script>
</body>
</html>
```