Prompt specification
Build or customize the Three.js 3D scene "Shapes That Are Not Cylinders" 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: Shapes That Are Not Cylinders
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shapes-that-are-not-cylinders-x3397
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Arrange mixed solids on a tray and separate those satisfying a negative shape constraint. Include several valid alternatives so negation is not mistaken for one opposite category.
Working Three.js Starter (shapes-that-are-not-cylinders-x3397):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Negative Shape Sorting</title>
<style>
:root {
--paper: #f2eee5;
--ink: #26332f;
--muted: #6f7771;
--line: #d8d2c6;
--green: #347d6d;
--green-light: #dcebe4;
--coral: #df765d;
--coral-light: #f5dfd7;
--panel: #faf8f2;
}
* {
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;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-columns: 320px minmax(0, 1fr);
height: 100vh;
min-height: 650px;
}
aside {
position: relative;
z-index: 2;
padding: 28px 24px;
overflow-y: auto;
background: var(--panel);
border-right: 1px solid var(--line);
box-shadow: 8px 0 30px rgb(45 55 48 / 5%);
}
.eyebrow {
margin: 0 0 12px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 3vw, 42px);
line-height: 1.03;
letter-spacing: -0.045em;
}
.intro {
margin: 16px 0 22px;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.rule-card {
padding: 17px;
border: 1px solid #e8c7bb;
border-radius: 15px;
background: var(--coral-light);
}
.rule-label {
margin-bottom: 9px;
color: #995543;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.rule {
display: flex;
align-items: center;
gap: 10px;
font-size: 18px;
font-weight: 750;
}
.not-symbol {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: 2px solid var(--coral);
border-radius: 50%;
color: var(--coral);
font-size: 22px;
line-height: 1;
}
.rule-code {
margin: 11px 0 0;
color: #805647;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 12px;
}
.section-title {
margin: 23px 0 10px;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title.accepted {
color: var(--green);
}
.section-title.rejected {
color: #b65350;
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.chip {
padding: 7px 9px;
border: 1px solid #cbded5;
border-radius: 999px;
background: var(--green-light);
color: #2e685b;
font-size: 11px;
font-weight: 700;
}
.chip.rejected {
border-color: #ecc6c4;
background: #f8e5e4;
color: #a14c4a;
}
.explanation {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.counter {
float: right;
padding: 3px 7px;
border-radius: 999px;
background: #d6e9e0;
color: var(--green);
font-size: 10px;
letter-spacing: 0;
}
.actions {
display: grid;
gap: 9px;
margin-top: 25px;
}
.primary,
.secondary {
min-height: 43px;
padding: 10px 14px;
border-radius: 11px;
font-size: 13px;
font-weight: 800;
cursor: pointer;
transition:
transform 150ms ease,
box-shadow 150ms ease,
background 150ms ease;
}
.primary {
border: 1px solid var(--green);
background: var(--green);
color: white;
box-shadow: 0 6px 15px rgb(52 125 109 / 18%);
}
.secondary {
border: 1px solid var(--line);
background: transparent;
color: var(--ink);
}
.primary:hover:not(:disabled),
.secondary:hover:not(:disabled) {
transform: translateY(-1px);
}
.primary:disabled,
.secondary:disabled {
cursor: not-allowed;
opacity: 0.48;
}
.controls-note {
margin: 22px 0 0;
padding-top: 16px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #eee9df;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.scene-note {
position: absolute;
top: 18px;
right: 18px;
z-index: 3;
padding: 9px 12px;
border: 1px solid rgb(255 255 255 / 65%);
border-radius: 999px;
background: rgb(255 255 255 / 66%);
box-shadow: 0 7px 22px rgb(43 52 46 / 8%);
color: #53615b;
font-size: 11px;
font-weight: 700;
backdrop-filter: blur(8px);
pointer-events: none;
}
.status {
position: absolute;
bottom: 20px;
left: 50%;
z-index: 3;
min-width: 270px;
padding: 11px 18px;
transform: translateX(-50%);
border: 1px solid rgb(255 255 255 / 70%);
border-radius: 999px;
background: rgb(255 255 255 / 82%);
box-shadow: 0 10px 30px rgb(43 52 46 / 12%);
color: #46544e;
font-size: 12px;
font-weight: 750;
text-align: center;
backdrop-filter: blur(9px);
pointer-events: none;
}
.inspect {
position: absolute;
bottom: 20px;
left: 18px;
z-index: 3;
max-width: 300px;
padding: 10px 13px;
border: 1px solid #c9ddd4;
border-radius: 11px;
background: rgb(239 248 243 / 92%);
color: #356659;
font-size: 11px;
line-height: 1.45;
box-shadow: 0 8px 25px rgb(43 52 46 / 9%);
pointer-events: none;
}
.inspect.excluded {
border-color: #e6c1bf;
background: rgb(252 238 237 / 94%);
color: #9b4c49;
}
@media (max-width: 820px) {
.app {
grid-template-columns: 1fr;
grid-template-rows: minmax(520px, 68vh) auto;
height: auto;
min-height: 100vh;
}
#viewport {
grid-row: 1;
min-height: 520px;
}
aside {
grid-row: 2;
overflow: visible;
border-top: 1px solid var(--line);
border-right: 0;
}
.inspect {
bottom: 66px;
}
}
@media (max-width: 520px) {
.scene-note {
top: 12px;
right: 12px;
font-size: 10px;
}
.status {
bottom: 12px;
min-width: 0;
width: calc(100% - 24px);
}
}
</style>
</head>
<body>
<div class="app">
<aside>
<p class="eyebrow">Logical sorting / negation</p>
<h1>Keep what is not a sphere.</h1>
<p class="intro">
The negative constraint matches the complement of one category.
Every non-spherical solid qualifies—not just a single “opposite” shape.
</p>
<section class="rule-card" aria-label="Negative shape constraint">
<div class="rule-label">Negative shape constraint</div>
<div class="rule">
<span class="not-symbol" aria-hidden="true">¬</span>
<span>shape ≠ sphere</span>
</div>
<p class="rule-code">MATCH(S) := shape IS NOT sphere</p>
</section>
<h2 class="section-title accepted">
Accepted <span class="counter" id="matchCount">0 / 6</span>
</h2>
<div class="chips" aria-label="Accepted shape alternatives">
<span class="chip">Cube</span>
<span class="chip">Hex cylinder</span>
<span class="chip">Cone</span>
<span class="chip">Pyramid</span>
<span class="chip">Triangular prism</span>
<span class="chip">Ring solid</span>
</div>
<p class="explanation">
Six different categories satisfy the same negative rule.
</p>
<h2 class="section-title rejected">Rejected</h2>
<div class="chips">
<span class="chip rejected">Sphere only</span>
</div>
<div class="actions">
<button class="primary" id="separateButton" type="button">
Separate matches
</button>
<button class="secondary" id="resetButton" type="button" disabled>
Reset mixed tray
</button>
</div>
<p class="controls-note">
Drag the scene to orbit. Scroll or pinch to zoom.
Click any solid to inspect its match result.
</p>
</aside>
<main id="viewport" aria-label="Interactive low-poly shape sorting scene">
<div class="scene-note">6 valid alternatives · 1 excluded sphere</div>
<div class="status" id="status" role="status" aria-live="polite">
Preparing mixed tray…
</div>
<div class="inspect" id="inspect" hidden></div>
</main>
</div>
<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.getElementById("viewport");
const separateButton = document.getElementById("separateButton");
const resetButton = document.getElementById("resetButton");
const statusElement = document.getElementById("status");
const matchCountElement = document.getElementById("matchCount");
const inspectElement = document.getElementById("inspect");
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lights
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 16, 29);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Low-poly scene containing mixed solids on two trays"
);
viewport.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.05, 0);
let cameraYaw = 0.015;
let cameraPitch = 0.61;
let cameraZoom = 1;
function updateCamera() {
const radius = 15;
camera.position.set(
cameraTarget.x +
Math.sin(cameraYaw) * Math.cos(cameraPitch) * radius,
cameraTarget.y + Math.sin(cameraPitch) * radius,
cameraTarget.z +
Math.cos(cameraYaw) * Math.cos(cameraPitch) * radius
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x8b7665, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff8e9, 3.4);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.normalBias = 0.035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xbdd9ff, 1.2);
rimLight.position.set(7, 5, -8);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Materials and reusable helpers
// -------------------------------------------------------------------------
function standardMaterial(color, extra = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.72,
metalness: 0.02,
flatShading: true,
...extra
});
}
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x25312e,
transparent: true,
opacity: 0.32,
depthWrite: false
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
standardMaterial(0xeee9df, { roughness: 1 })
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.76;
floor.receiveShadow = true;
scene.add(floor);
const table = new THREE.Mesh(
new THREE.CylinderGeometry(8.4, 8.7, 0.35, 8),
standardMaterial(0xd9cdbb, { roughness: 0.92 })
);
table.position.y = -0.56;
table.receiveShadow = true;
table.castShadow = true;
scene.add(table);
function makeTray(x, baseColor, rimColor) {
const group = new THREE.Group();
group.position.x = x;
const width = 4.4;
const depth = 2.8;
const baseMaterial = standardMaterial(baseColor, { roughness: 0.86 });
const rimMaterial = standardMaterial(rimColor, { roughness: 0.8 });
const base = new THREE.Mesh(
new THREE.BoxGeometry(width, 0.17, depth),
baseMaterial
);
base.position.y = -0.285;
base.receiveShadow = true;
base.castShadow = true;
group.add(base);
const wallHeight = 0.32;
const wallThickness = 0.13;
const left = new THREE.Mesh(
new THREE.BoxGeometry(wallThickness, wallHeight, depth + 0.12),
rimMaterial
);
left.position.set(-width / 2 + wallThickness / 2, -0.04, 0);
const right = left.clone();
right.position.x = width / 2 - wallThickness / 2;
const front = new THREE.Mesh(
new THREE.BoxGeometry(width + 0.12, wallHeight, wallThickness),
rimMaterial
);
front.position.set(0, -0.04, depth / 2 - wallThickness / 2);
const back = front.clone();
back.position.z = -depth / 2 + wallThickness / 2;
for (const wall of [left, right, front, back]) {
wall.castShadow = true;
wall.receiveShadow = true;
group.add(wall);
}
scene.add(group);
return group;
}
makeTray(-3.2, 0xd9d1c3, 0xb4aa9b);
makeTray(3.2, 0xcfe2d7, 0x82ad9b);
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function makeLabel(text, accent, width) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 220;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(ctx, 8, 8, 1008, 204, 42);
ctx.fillStyle = "rgba(255,255,255,0.91)";
ctx.fill();
ctx.lineWidth = 7;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = accent;
ctx.font = "800 56px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 111);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * 220 / 1024, 1);
sprite.renderOrder = 20;
return sprite;
}
const sourceLabel = makeLabel("MIXED TRAY · 7 SOLIDS", "#52615b", 3.55);
sourceLabel.position.set(-3.2, 1.55, 0);
scene.add(sourceLabel);
const matchLabel = makeLabel("MATCHES · NOT A SPHERE", "#347d6d", 4.25);
matchLabel.position.set(3.2, 1.55, 0);
scene.add(matchLabel);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.55, -0.19, 0),
1.1,
0x6e8e81,
0.25,
0.16
);
scene.add(arrow);
// -------------------------------------------------------------------------
// Low-poly solids
// -------------------------------------------------------------------------
const items = [];
const clickableMeshes = [];
const trayTop = -0.20;
function geometryFor(type) {
switch (type) {
case "cube":
return new THREE.BoxGeometry(0.72, 0.72, 0.72);
case "cylinder":
return new THREE.CylinderGeometry(0.38, 0.38, 0.72, 6, 1, false);
case "cone":
return new THREE.ConeGeometry(0.46, 0.82, 6, 1, false);
case "pyramid":
return new THREE.ConeGeometry(0.50, 0.82, 4, 1, false);
case "prism":
return new THREE.CylinderGeometry(0.46, 0.46, 0.68, 3, 1, false);
case "ring":
return new THREE.TorusGeometry(0.32, 0.14, 6, 10);
case "sphere":
return new THREE.IcosahedronGeometry(0.43, 1);
default:
throw new Error(`Unknown shape type: ${type}`);
}
}
function centerHeightFor(type) {
switch (type) {
case "cube":
case "cylinder":
return 0.36;
case "cone":
case "pyramid":
return 0.41;
case "prism":
return 0.34;
case "ring":
return 0.46;
case "sphere":
return 0.43;
default:
return 0.4;
}
}
function createItem({
type,
label,
color,
startX,
startZ,
endX,
endZ,
eligible,
startRotation,
endRotation
}) {
const group = new THREE.Group();
const geometry = geometryFor(type);
const material = standardMaterial(color);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 12),
edgeMaterial
);
edges.renderOrder = 2;
group.add(mesh, edges);
const start = new THREE.Vector3(
startX,
trayTop + centerHeightFor(type),
startZ
);
const end = new THREE.Vector3(
endX,
trayTop + centerHeightFor(type),
endZ
);
group.position.copy(start);
group.rotation.set(...startRotation);
const item = {
type,
label,
eligible,
group,
mesh,
start,
end,
startRotation: new THREE.Euler(...startRotation),
endRotation: new THREE.Euler(...endRotation),
delay: 0
};
mesh.userData.item = item;
clickableMeshes.push(mesh);
scene.add(group);
items.push(item);
return item;
}
const eligibleSpecs = [
{
type: "cube",
label: "Cube",
color: 0xe76f51,
startX: -4.85,
startZ: -0.64,
endX: 1.48,
endZ: -0.64,
startRotation: [0.12, 0.46, 0],
endRotation: [0.02, 0.72, 0]
},
{
type: "prism",
label: "Triangular prism",
color: 0x8d6cc7,
startX: -3.72,
startZ: 0.62,
endX: 2.58,
endZ: 0.62,
startRotation: [0, 0.22, 0],
endRotation: [0, -0.42, 0]
},
{
type: "cylinder",
label: "Hexagonal cylinder",
color: 0xe9b949,
startX: -3.72,
startZ: -0.64,
endX: 2.58,
endZ: -0.64,
startRotation: [0, 0.18, 0],
endRotation: [0, 0.65, 0]
},
{
type: "ring",
label: "Ring solid",
color: 0xd98ead,
startX: -2.60,
startZ: 0.62,
endX: 3.68,
endZ: 0.62,
startRotation: [0, 0.25, 0],
endRotation: [0, -0.38, 0]
},
{
type: "cone",
label: "Six-sided cone",
color: 0x2a9d8f,
startX: -2.60,
startZ: -0.64,
endX: 3.68,
endZ: -0.64,
startRotation: [0, 0.18, 0],
endRotation: [0, 0.62, 0]
},
{
type: "pyramid",
label: "Square pyramid",
color: 0x4c78d0,
startX: -1.48,
startZ: 0.62,
endX: 4.83,
endZ: 0.62,
startRotation: [0, Math.PI / 4, 0],
endRotation: [0, -Math.PI / 5, 0]
}
];
eligibleSpecs.forEach((spec, index) => {
createItem({
...spec,
eligible: true
});
items[index].delay = index * 115;
});
// The only rejected object. It remains in the mixed tray.
createItem({
type: "sphere",
label: "Faceted sphere",
color: 0xe94b60,
startX: -1.48,
startZ: -0.64,
endX: -1.48,
endZ: -0.64,
eligible: false,
startRotation: [0.1, 0.22, 0.08],
endRotation: [0.1, 0.22, 0.08]
});
// -------------------------------------------------------------------------
// Sorting animation
// -------------------------------------------------------------------------
let mode = "ready";
let animationStart = 0;
const animationDuration = 1150;
function resetPositions() {
for (const item of items) {
item.group.position.copy(item.start);
item.group.rotation.copy(item.startRotation);
}
}
function startSeparation() {
if (mode === "sorting") return;
resetPositions();
mode = "sorting";
animationStart = performance.now();
separateButton.disabled = true;
separateButton.textContent = "Separating…";
resetButton.disabled = false;
statusElement.textContent =
"Moving all six non-spherical solids to the matching tray…";
matchCountElement.textContent = "0 / 6";
inspectElement.hidden = true;
}
function resetScene() {
mode = "ready";
resetPositions();
separateButton.disabled = false;
separateButton.textContent = "Separate matches";
resetButton.disabled = true;
statusElement.textContent =
"Mixed tray restored · six objects satisfy “not sphere”";
matchCountElement.textContent = "0 / 6";
inspectElement.hidden = true;
}
separateButton.addEventListener("click", startSeparation);
resetButton.addEventListener("click", resetScene);
function updateSorting(now) {
if (mode !== "sorting") return;
const elapsed = now - animationStart;
let finished = true;
for (const item of items) {
if (!item.eligible) continue;
const rawT = THREE.MathUtils.clamp(
(elapsed - item.delay) / animationDuration,
0,
1
);
if (rawT < 1) finished = false;
const t = rawT * rawT * (3 - 2 * rawT);
item.group.position.lerpVectors(item.start, item.end, t);
item.group.position.y += Math.sin(Math.PI * t) * 1.08;
item.group.rotation.x = THREE.MathUtils.lerp(
item.startRotation.x,
item.endRotation.x,
t
);
item.group.rotation.y = THREE.MathUtils.lerp(
item.startRotation.y,
item.endRotation.y,
t
) + Math.sin(Math.PI * t) * Math.PI * 0.7;
item.group.rotation.z = THREE.MathUtils.lerp(
item.startRotation.z,
item.endRotation.z,
t
);
}
if (finished) {
mode = "sorted";
separateButton.disabled = false;
separateButton.textContent = "Replay separation";
resetButton.disabled = false;
statusElement.textContent =
"6 matches separated · 1 sphere correctly rejected";
matchCountElement.textContent = "6 / 6";
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit by dragging and zoom with the wheel
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = null;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
pointerId: event.pointerId,
moved: false
};
canvas.setPointerCapture(event.pointerId);
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown || pointerDown.pointerId !== event.pointerId) return;
const dx = event.clientX - pointerDown.x;
const dy = event.clientY - pointerDown.y;
if (Math.hypot(dx, dy) > 4) pointerDown.moved = true;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.004,
0.34,
1.16
);
pointerDown.x = event.clientX;
pointerDown.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
const wasClick = pointerDown && !pointerDown.moved;
if (pointerDown) {
if (canvas.hasPointerCapture(pointerDown.pointerId)) {
canvas.releasePointerCapture(pointerDown.pointerId);
}
}
pointerDown = null;
canvas.classList.remove("dragging");
if (wasClick) inspectObject(event);
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.5
);
updateCamera();
},
{ passive: false }
);
function inspectObject(event) {
const bounds = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - bounds.left) / bounds.width) * 2 - 1;
pointer.y =
-((event.clientY - bounds.top) / bounds.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickableMeshes, false);
if (!hits.length) {
inspectElement.hidden = true;
return;
}
const item = hits[0].object.userData.item;
inspectElement.hidden = false;
inspectElement.classList.toggle("excluded", !item.eligible);
if (item.eligible) {
inspectElement.innerHTML =
`<strong>MATCH</strong> · ${item.label}<br>` +
"This shape is not a sphere, so it satisfies the constraint.";
} else {
inspectElement.innerHTML =
`<strong>REJECTED</strong> · ${item.label}<br>` +
"This is the one excluded category.";
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function resize() {
const width = Math.max(1, viewport.clientWidth);
const height = Math.max(1, viewport.clientHeight);
const aspect = width / height;
// Keep both trays visible, including on narrow viewports.
const viewHeight = Math.max(7.2, 12.8 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
new ResizeObserver(resize).observe(viewport);
resize();
function animate(now) {
requestAnimationFrame(animate);
updateSorting(now);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
// Begin with the mixed tray, then demonstrate the separation automatically.
window.setTimeout(() => {
if (mode === "ready") startSeparation();
}, 900);
</script>
</body>
</html>
```