Prompt specification
Build or customize the Three.js 3D scene "Two Red Cups and One Tall Cup" 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: Two Red Cups and One Tall Cup
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-red-cups-and-one-tall-cup-x3409
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring references to objects in context. Display cups differing in height, color, and handle shape. Show that a short description may identify one object, several objects, or no object. Stylized solid forms.
Working Three.js Starter (two-red-cups-and-one-tall-cup-x3409):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Objects in Context — Reference Resolver</title>
<style>
:root {
--ink: #292722;
--muted: #756f65;
--paper: rgba(250, 247, 240, 0.92);
--line: rgba(54, 48, 40, 0.14);
--accent: #dc6b4d;
--green: #397963;
--blue: #476fb5;
--red: #b64e40;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background: #e9e4da;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 5;
top: 28px;
left: 30px;
max-width: 460px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: #615b52;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 2px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4vw, 58px);
font-weight: 500;
line-height: 0.96;
letter-spacing: -0.045em;
}
.intro {
max-width: 430px;
margin: 13px 0 0;
color: #665f55;
font-size: 14px;
line-height: 1.55;
}
.panel {
position: fixed;
z-index: 10;
top: 24px;
right: 24px;
width: min(365px, calc(100vw - 48px));
padding: 22px;
border: 1px solid rgba(71, 62, 51, 0.13);
border-radius: 22px;
background: var(--paper);
box-shadow:
0 24px 60px rgba(53, 45, 35, 0.15),
inset 0 1px rgba(255, 255, 255, 0.8);
backdrop-filter: blur(18px);
}
.panel-kicker {
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 0 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 27px;
font-weight: 500;
letter-spacing: -0.025em;
}
.panel-copy {
margin: 0 0 17px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.input-shell {
position: relative;
display: flex;
align-items: center;
}
#description {
width: 100%;
height: 48px;
padding: 0 44px 0 14px;
border: 1px solid rgba(64, 56, 46, 0.18);
border-radius: 13px;
outline: none;
color: var(--ink);
background: rgba(255, 255, 255, 0.74);
font-size: 14px;
transition:
border-color 160ms ease,
box-shadow 160ms ease;
}
#description:focus {
border-color: rgba(220, 107, 77, 0.7);
box-shadow: 0 0 0 4px rgba(220, 107, 77, 0.1);
}
#clear {
position: absolute;
right: 8px;
display: grid;
width: 29px;
height: 29px;
padding: 0;
place-items: center;
border: 0;
border-radius: 50%;
color: #766f65;
background: transparent;
cursor: pointer;
}
#clear:hover {
background: rgba(40, 35, 30, 0.07);
}
.examples-label {
margin: 15px 0 8px;
color: #81796e;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.examples {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.example {
padding: 7px 10px;
border: 1px solid rgba(64, 56, 46, 0.13);
border-radius: 999px;
color: #5f584f;
background: rgba(255, 255, 255, 0.5);
font-size: 11px;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.example:hover {
transform: translateY(-1px);
border-color: rgba(220, 107, 77, 0.4);
background: white;
}
.example.active {
border-color: var(--accent);
color: #a34934;
background: rgba(220, 107, 77, 0.09);
}
.result {
margin-top: 18px;
padding: 15px;
border: 1px solid rgba(57, 121, 99, 0.18);
border-radius: 15px;
background: rgba(57, 121, 99, 0.075);
transition:
border-color 180ms ease,
background 180ms ease;
}
.result[data-mode="several"] {
border-color: rgba(71, 111, 181, 0.2);
background: rgba(71, 111, 181, 0.075);
}
.result[data-mode="none"] {
border-color: rgba(182, 78, 64, 0.2);
background: rgba(182, 78, 64, 0.07);
}
.result[data-mode="idle"] {
border-color: var(--line);
background: rgba(255, 255, 255, 0.38);
}
.result-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
#result-label {
color: var(--green);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.result[data-mode="several"] #result-label {
color: var(--blue);
}
.result[data-mode="none"] #result-label {
color: var(--red);
}
.result[data-mode="idle"] #result-label {
color: var(--muted);
}
#result-count {
display: grid;
width: 30px;
height: 30px;
place-items: center;
border-radius: 50%;
color: white;
background: var(--green);
font-size: 12px;
font-weight: 800;
}
.result[data-mode="several"] #result-count {
background: var(--blue);
}
.result[data-mode="none"] #result-count {
background: var(--red);
}
.result[data-mode="idle"] #result-count {
color: #81796e;
background: #e8e2d8;
}
#result-text {
margin: 10px 0 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 16px;
line-height: 1.35;
}
#result-names,
#criteria {
display: flex;
flex-wrap: wrap;
gap: 5px;
margin-top: 10px;
}
.name-pill,
.criteria-pill {
padding: 5px 8px;
border-radius: 999px;
font-size: 10px;
line-height: 1.1;
}
.name-pill {
color: #365f50;
background: rgba(57, 121, 99, 0.1);
}
.criteria-pill {
color: #726a60;
background: rgba(48, 42, 35, 0.07);
}
.panel-note {
margin: 15px 0 0;
color: #8a8277;
font-size: 11px;
line-height: 1.5;
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.object-label {
position: absolute;
min-width: 112px;
padding: 8px 10px;
border: 1px solid rgba(48, 42, 35, 0.12);
border-radius: 11px;
color: #4b453d;
background: rgba(250, 248, 242, 0.86);
box-shadow: 0 7px 18px rgba(44, 37, 29, 0.08);
text-align: left;
opacity: 0.72;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
transition:
opacity 180ms ease,
border-color 180ms ease,
box-shadow 180ms ease,
background 180ms ease;
backdrop-filter: blur(8px);
}
.object-label:hover {
opacity: 1;
}
.object-label.is-match {
border-color: rgba(220, 107, 77, 0.65);
background: rgba(255, 252, 246, 0.96);
box-shadow: 0 9px 24px rgba(91, 60, 39, 0.15);
opacity: 1;
}
.label-line {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.label-line strong {
font-size: 10px;
font-weight: 800;
}
.label-meta {
display: block;
margin-top: 4px;
color: #8a8175;
font-size: 9px;
letter-spacing: 0.03em;
}
.hint {
position: fixed;
z-index: 5;
bottom: 24px;
left: 28px;
display: flex;
align-items: center;
gap: 10px;
color: rgba(60, 54, 47, 0.64);
font-size: 11px;
pointer-events: none;
}
.hint-icon {
display: grid;
width: 29px;
height: 29px;
place-items: center;
border: 1px solid rgba(55, 49, 42, 0.14);
border-radius: 50%;
background: rgba(250, 247, 240, 0.55);
}
#loading {
position: fixed;
z-index: 30;
inset: 0;
display: grid;
place-items: center;
color: #685f54;
background: #e9e4da;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 820px) {
.topbar {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
h1 {
font-size: 37px;
}
.intro {
display: none;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 16px;
border-radius: 18px;
}
.panel-copy,
.panel-note,
.examples-label {
display: none;
}
.panel h2 {
margin-bottom: 12px;
font-size: 22px;
}
.examples {
margin-top: 9px;
}
.result {
margin-top: 11px;
padding: 11px;
}
#result-text {
font-size: 14px;
}
.hint {
display: none;
}
.object-label {
min-width: 96px;
padding: 6px 8px;
}
.label-meta {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">Loading scene…</div>
<main id="scene" aria-label="Interactive 3D cup scene"></main>
<header class="topbar">
<div class="eyebrow">Reference study / 01</div>
<h1>Objects in context</h1>
<p class="intro">
A short description can point to one cup, a group of cups, or nothing
at all. Try a color, height, handle shape, or position.
</p>
</header>
<aside class="panel" aria-label="Description resolver">
<div class="panel-kicker">Live reference resolver</div>
<h2>Which cup did you mean?</h2>
<p class="panel-copy">
Enter a short description. Matching cups will brighten and receive a
colored ring.
</p>
<div class="input-shell">
<input
id="description"
type="text"
value="coral cup"
placeholder="e.g. tall cups with square handles"
autocomplete="off"
aria-label="Object description"
/>
<button id="clear" type="button" aria-label="Clear description">×</button>
</div>
<div class="examples-label">Try an example</div>
<div class="examples">
<button class="example active" data-query="coral cup">One object</button>
<button class="example" data-query="tall cups">Several objects</button>
<button class="example" data-query="purple teapot">No object</button>
<button class="example" data-query="coral cup on the left">In context</button>
</div>
<section id="result" class="result" data-mode="one" aria-live="polite">
<div class="result-top">
<span id="result-label">One object</span>
<span id="result-count">1</span>
</div>
<p id="result-text"></p>
<div id="criteria"></div>
<div id="result-names"></div>
</section>
<p class="panel-note">
Click a cup or its label to create a referring expression.
</p>
</aside>
<div id="labels"></div>
<div class="hint">
<span class="hint-icon">↔</span>
<span>Drag to orbit · Scroll to zoom · Click a cup</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneRoot = document.getElementById("scene");
const labelsRoot = document.getElementById("labels");
const input = document.getElementById("description");
const clearButton = document.getElementById("clear");
const result = document.getElementById("result");
const resultLabel = document.getElementById("result-label");
const resultCount = document.getElementById("result-count");
const resultText = document.getElementById("result-text");
const resultNames = document.getElementById("result-names");
const criteriaRoot = document.getElementById("criteria");
const exampleButtons = [...document.querySelectorAll(".example")];
// ------------------------------------------------------------
// Renderer, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
sceneRoot.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
scene.fog = new THREE.Fog(0xe9e4da, 10, 23);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const orbit = {
target: new THREE.Vector3(-0.65, 0.72, 0.05),
yaw: -0.05,
pitch: 0.47,
distance: 8.4
};
function updateCamera() {
const horizontal = orbit.distance * Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + horizontal * Math.sin(orbit.yaw),
orbit.target.y + orbit.distance * Math.sin(orbit.pitch),
orbit.target.z + horizontal * Math.cos(orbit.yaw)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(
0xfff8eb,
0x777269,
1.8
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d8, 3.1);
keyLight.position.set(-3.8, 8.5, 5.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -7;
keyLight.shadow.camera.right = 7;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbfd3e6, 0.85);
fillLight.position.set(5, 4, 1);
scene.add(fillLight);
// ------------------------------------------------------------
// Context: floor, wall, table, and solid decorative forms
// ------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xded8cd,
roughness: 0.94
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.76;
floor.receiveShadow = true;
scene.add(floor);
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(30, 12),
new THREE.MeshStandardMaterial({
color: 0xeee9df,
roughness: 1
})
);
wall.position.set(0, 3.2, -4.25);
wall.receiveShadow = true;
scene.add(wall);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(1.25, 64),
new THREE.MeshBasicMaterial({ color: 0xe5b49a })
);
sun.position.set(-3.0, 2.3, -4.12);
scene.add(sun);
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0xd5cec1,
roughness: 0.95
});
const panelA = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 3.8, 0.18),
panelMaterial
);
panelA.position.set(-0.75, 1.2, -3.95);
panelA.castShadow = true;
scene.add(panelA);
const panelB = new THREE.Mesh(
new THREE.BoxGeometry(1.35, 3.8, 0.18),
new THREE.MeshStandardMaterial({
color: 0xc8d0c5,
roughness: 0.95
})
);
panelB.position.set(0.65, 1.2, -3.95);
panelB.castShadow = true;
scene.add(panelB);
const tableTop = new THREE.Mesh(
new THREE.BoxGeometry(7.6, 0.28, 4.4),
new THREE.MeshStandardMaterial({
color: 0xbba58b,
roughness: 0.76
})
);
tableTop.position.y = 0;
tableTop.castShadow = true;
tableTop.receiveShadow = true;
scene.add(tableTop);
const tableEdge = new THREE.Mesh(
new THREE.BoxGeometry(7.74, 0.12, 4.54),
new THREE.MeshStandardMaterial({
color: 0x8f7963,
roughness: 0.8
})
);
tableEdge.position.y = -0.18;
tableEdge.castShadow = true;
scene.add(tableEdge);
const legMaterial = new THREE.MeshStandardMaterial({
color: 0x776653,
roughness: 0.9
});
for (const x of [-3.15, 3.15]) {
for (const z of [-1.55, 1.55]) {
const leg = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.62, 0.24),
legMaterial
);
leg.position.set(x, -0.53, z);
leg.castShadow = true;
scene.add(leg);
}
}
// Context objects: folded napkin and a closed book.
const napkin = new THREE.Mesh(
new THREE.BoxGeometry(1.15, 0.045, 0.72),
new THREE.MeshStandardMaterial({
color: 0xd7b4a0,
roughness: 0.9
})
);
napkin.position.set(2.85, 0.17, 1.35);
napkin.rotation.y = 0.18;
napkin.castShadow = true;
scene.add(napkin);
const book = new THREE.Mesh(
new THREE.BoxGeometry(1.25, 0.14, 0.82),
new THREE.MeshStandardMaterial({
color: 0x758a91,
roughness: 0.78
})
);
book.position.set(-2.9, 0.2, 1.48);
book.rotation.y = -0.12;
book.castShadow = true;
scene.add(book);
const bookPages = new THREE.Mesh(
new THREE.BoxGeometry(1.16, 0.08, 0.74),
new THREE.MeshStandardMaterial({
color: 0xe7dfd0,
roughness: 1
})
);
bookPages.position.set(-2.9, 0.205, 1.48);
bookPages.rotation.y = -0.12;
scene.add(bookPages);
// ------------------------------------------------------------
// Cups
// ------------------------------------------------------------
const cupDefinitions = [
{
id: "coral",
name: "Coral short cup",
color: 0xe37658,
colorWord: "coral",
height: 0.72,
radius: 0.34,
handle: "round",
type: "cup",
position: [-2.55, 0.15, 0.72]
},
{
id: "cobalt",
name: "Cobalt tall mug",
color: 0x4776d0,
colorWord: "cobalt",
height: 1.42,
radius: 0.36,
handle: "square",
type: "mug",
position: [-0.88, 0.15, -0.58]
},
{
id: "ochre",
name: "Ochre medium cup",
color: 0xdda83b,
colorWord: "ochre",
height: 1.02,
radius: 0.38,
handle: "oval",
type: "cup",
position: [0.9, 0.15, 0.72]
},
{
id: "mint",
name: "Mint tall cup",
color: 0x69b69a,
colorWord: "mint",
height: 1.30,
radius: 0.34,
handle: "triangular",
type: "cup",
position: [2.48, 0.15, -0.55]
},
{
id: "ink",
name: "Ink medium tumbler",
color: 0x344b63,
colorWord: "ink",
height: 1.04,
radius: 0.31,
handle: "none",
type: "tumbler",
position: [-0.78, 0.15, 1.48]
},
{
id: "pink",
name: "Pink short cup",
color: 0xc96d88,
colorWord: "pink",
height: 0.78,
radius: 0.36,
handle: "loop",
type: "cup",
position: [0.88, 0.15, 1.48]
}
];
const cups = [];
const cupRoots = [];
function createHandle(handleType, radius, height, material) {
const group = new THREE.Group();
if (handleType === "round") {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(0.17, 0.055, 12, 42),
material
);
mesh.position.set(radius + 0.055, height * 0.53, 0);
group.add(mesh);
}
if (handleType === "oval") {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(0.19, 0.055, 12, 42),
material
);
mesh.scale.set(0.82, 1.22, 1);
mesh.position.set(radius + 0.04, height * 0.53, 0);
group.add(mesh);
}
if (handleType === "loop") {
const mesh = new THREE.Mesh(
new THREE.TorusGeometry(0.22, 0.052, 12, 48),
material
);
mesh.scale.set(0.82, 1.08, 1);
mesh.position.set(radius + 0.055, height * 0.53, 0);
group.add(mesh);
}
if (handleType === "square") {
const points = [
new THREE.Vector3(radius * 0.98, height * 0.73, 0),
new THREE.Vector3(radius + 0.28, height * 0.73, 0),
new THREE.Vector3(radius + 0.31, height * 0.67, 0),
new THREE.Vector3(radius + 0.31, height * 0.33, 0),
new THREE.Vector3(radius + 0.28, height * 0.27, 0),
new THREE.Vector3(radius * 0.98, height * 0.27, 0)
];
const curve = new THREE.CatmullRomCurve3(
points,
true,
"catmullrom",
0.0
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 64, 0.052, 9, true),
material
);
group.add(mesh);
}
if (handleType === "triangular") {
const points = [
new THREE.Vector3(radius * 0.98, height * 0.73, 0),
new THREE.Vector3(radius + 0.31, height * 0.36, 0),
new THREE.Vector3(radius * 0.98, height * 0.27, 0)
];
const curve = new THREE.CatmullRomCurve3(
points,
true,
"catmullrom",
0.0
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 56, 0.055, 9, true),
material
);
group.add(mesh);
}
return group;
}
for (const definition of cupDefinitions) {
const root = new THREE.Group();
root.position.fromArray(definition.position);
root.userData.cupId = definition.id;
const bodyMaterial = new THREE.MeshStandardMaterial({
color: definition.color,
roughness: 0.48,
metalness: 0.02
});
const profile = [
new THREE.Vector2(0, 0),
new THREE.Vector2(definition.radius * 0.78, 0),
new THREE.Vector2(definition.radius * 0.94, 0.055),
new THREE.Vector2(definition.radius, definition.height - 0.04),
new THREE.Vector2(definition.radius, definition.height),
new THREE.Vector2(definition.radius - 0.075, definition.height),
new THREE.Vector2(
definition.radius - 0.095,
definition.height - 0.08
),
new THREE.Vector2(definition.radius - 0.095, 0.105),
new THREE.Vector2(0, 0.105)
];
const body = new THREE.Mesh(
new THREE.LatheGeometry(profile, 48),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
root.add(body);
const coffeeMaterial = new THREE.MeshStandardMaterial({
color: 0x493027,
roughness: 0.3,
metalness: 0.04
});
const coffee = new THREE.Mesh(
new THREE.CylinderGeometry(
definition.radius - 0.105,
definition.radius - 0.105,
0.018,
40
),
coffeeMaterial
);
coffee.position.y = definition.height * 0.79;
root.add(coffee);
const handleColor = new THREE.Color(definition.color).multiplyScalar(0.9);
const handleMaterial = new THREE.MeshStandardMaterial({
color: handleColor,
roughness: 0.5
});
if (definition.handle !== "none") {
const handle = createHandle(
definition.handle,
definition.radius,
definition.height,
handleMaterial
);
handle.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
root.add(handle);
}
const ring = new THREE.Mesh(
new THREE.RingGeometry(
definition.radius * 0.98,
definition.radius * 1.19,
56
),
new THREE.MeshBasicMaterial({
color: definition.color,
transparent: true,
opacity: 0.55,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = 0.018;
ring.visible = false;
root.add(ring);
const cup = {
...definition,
root,
bodyMaterial,
handleMaterial,
ring,
baseColor: new THREE.Color(definition.color),
label: null
};
root.userData.cup = cup;
cups.push(cup);
cupRoots.push(root);
scene.add(root);
const heightLabel =
definition.height < 0.85
? "short"
: definition.height > 1.15
? "tall"
: "medium";
const handleLabel =
definition.handle === "none"
? "no handle"
: `${definition.handle} handle`;
const label = document.createElement("button");
label.type = "button";
label.className = "object-label";
label.setAttribute(
"aria-label",
`Refer to ${definition.name}, ${heightLabel}, ${handleLabel}`
);
label.innerHTML = `
<span class="label-line">
<i class="swatch" style="background:#${definition.color
.toString(16)
.padStart(6, "0")}"></i>
<strong>${definition.name}</strong>
</span>
<span class="label-meta">${heightLabel} · ${handleLabel}</span>
`;
label.addEventListener("click", () => {
input.value = `${definition.colorWord} cup`;
updateResolver();
input.focus();
});
labelsRoot.appendChild(label);
cup.label = label;
}
// ------------------------------------------------------------
// Description resolver
// ------------------------------------------------------------
const colorSynonyms = {
coral: "coral",
red: "coral",
tomato: "coral",
blue: "cobalt",
cobalt: "cobalt",
yellow: "ochre",
gold: "ochre",
golden: "ochre",
ochre: "ochre",
mint: "mint",
green: "mint",
ink: "ink",
navy: "ink",
pink: "pink",
rose: "pink"
};
const knownColorWords = new Set([
"coral",
"red",
"tomato",
"blue",
"cobalt",
"yellow",
"gold",
"golden",
"ochre",
"mint",
"green",
"ink",
"navy",
"pink",
"rose",
"purple",
"violet",
"orange",
"white",
"black",
"brown",
"gray",
"grey",
"silver",
"teal"
]);
const unsupportedObjectWords = /\b(teapot|kettle|bowl|bottle|plate|spoon|fork|glass|glasses|pan|jar)\b/;
function resolveDescription(rawDescription) {
const description = rawDescription
.trim()
.toLowerCase()
.replace(/[-–—]/g, " ")
.replace(/[^\p{L}\p{N}\s]/gu, " ");
const tokens = description.split(/\s+/).filter(Boolean);
const criteria = [];
if (!description) {
return { matches: [], criteria, empty: true };
}
if (unsupportedObjectWords.test(description)) {
return { matches: [], criteria, unsupported: true };
}
const filters = [];
let color = null;
let height = null;
let handle = null;
let hasHandle = null;
let position = null;
let objectType = null;
for (const token of tokens) {
if (colorSynonyms[token]) {
color = colorSynonyms[token];
}
if (["short", "small", "low"].includes(token)) {
height = "short";
}
if (["tall", "large", "high", "big"].includes(token)) {
height = "tall";
}
if (["medium", "mid", "middle"].includes(token)) {
height = "medium";
}
const handleSynonyms = {
round: "round",
circular: "round",
square: "square",
angular: "square",
rectangular: "square",
oval: "oval",
elliptical: "oval",
triangle: "triangular",
triangular: "triangular",
loop: "loop"
};
if (handleSynonyms[token]) {
handle = handleSynonyms[token];
}
if (["left", "right", "front", "back", "middle"].includes(token)) {
position = token;
}
}
if (
/\b(handleless|no handle|without (?:a |any )?handle)\b/.test(
description
)
) {
handle = "none";
hasHandle = false;
} else if (
/\bhandles?\b/.test(description) &&
!handle
) {
hasHandle = true;
}
if (/\bmugs?\b/.test(description)) {
objectType = "mug";
}
if (/\btumblers?\b/.test(description)) {
objectType = "tumbler";
}
const unknownColor = tokens.some(
(token) => knownColorWords.has(token) && !colorSynonyms[token]
);
if (unknownColor) {
return { matches: [], criteria, unknownColor: true };
}
if (color) {
filters.push((cup) => cup.colorWord === color);
criteria.push(`color: ${color}`);
}
if (height) {
filters.push((cup) => {
const cupHeight =
cup.height < 0.85
? "short"
: cup.height > 1.15
? "tall"
: "medium";
return cupHeight === height;
});
criteria.push(`height: ${height}`);
}
if (handle) {
filters.push((cup) => cup.handle === handle);
criteria.push(`handle: ${handle}`);
} else if (hasHandle !== null) {
filters.push((cup) =>
hasHandle ? cup.handle !== "none" : cup.handle === "none"
);
criteria.push(hasHandle ? "has a handle" : "has no handle");
}
if (position) {
filters.push((cup) => {
if (position === "left") return cup.position[0] < -0.4;
if (position === "right") return cup.position[0] > 0.4;
if (position === "front") return cup.position[2] > 0.3;
if (position === "back") return cup.position[2] < -0.2;
return Math.abs(cup.position[0]) < 1.4;
});
criteria.push(`position: ${position}`);
}
if (objectType) {
filters.push((cup) => cup.type === objectType);
criteria.push(`object: ${objectType}`);
}
const mentionsCup = /\b(cups?|mugs?|tumblers?)\b/.test(description);
if (!mentionsCup && filters.length === 0) {
return { matches: [], criteria, unsupported: true };
}
const matches = cups.filter((cup) =>
filters.every((filter) => filter(cup))
);
return { matches, criteria };
}
function updateResolver() {
const description = input.value;
const resolution = resolveDescription(description);
const matches = resolution.matches;
const matchedIds = new Set(matches.map((cup) => cup.id));
for (const cup of cups) {
const isMatch = matchedIds.has(cup.id);
cup.bodyMaterial.color
.copy(cup.baseColor)
.lerp(new THREE.Color(0xd7d1c7), isMatch ? 0 : 0.46);
cup.handleMaterial.color
.copy(cup.baseColor)
.multiplyScalar(0.9)
.lerp(new THREE.Color(0xd7d1c7), isMatch ? 0 : 0.46);
cup.bodyMaterial.emissive.copy(cup.baseColor);
cup.bodyMaterial.emissiveIntensity = isMatch ? 0.2 : 0;
cup.handleMaterial.emissive.copy(cup.baseColor);
cup.handleMaterial.emissiveIntensity = isMatch ? 0.16 : 0;
cup.ring.visible = isMatch;
cup.label.classList.toggle("is-match", isMatch);
cup.label.style.opacity = isMatch
? "1"
: resolution.matches.length === 0 && description
? "0.5"
: "0.72";
}
criteriaRoot.replaceChildren();
resultNames.replaceChildren();
for (const criterion of resolution.criteria) {
const pill = document.createElement("span");
pill.className = "criteria-pill";
pill.textContent = criterion;
criteriaRoot.appendChild(pill);
}
if (resolution.empty) {
result.dataset.mode = "idle";
resultLabel.textContent = "Ready";
resultCount.textContent = "—";
resultText.textContent = "Type a color, height, handle shape, or position.";
} else if (matches.length === 0) {
result.dataset.mode = "none";
resultLabel.textContent = "No object";
resultCount.textContent = "0";
resultText.textContent = `No object in the scene matches “${description.trim()}”.`;
} else if (matches.length === 1) {
result.dataset.mode = "one";
resultLabel.textContent = "One object";
resultCount.textContent = "1";
resultText.textContent = `The description resolves to ${matches[0].name}.`;
} else {
result.dataset.mode = "several";
resultLabel.textContent = "Several objects";
resultCount.textContent = String(matches.length);
resultText.textContent = `${matches.length} objects satisfy this description.`;
}
for (const cup of matches) {
const pill = document.createElement("span");
pill.className = "name-pill";
pill.textContent = cup.name;
resultNames.appendChild(pill);
}
for (const button of exampleButtons) {
button.classList.toggle(
"active",
button.dataset.query.toLowerCase() === description.trim().toLowerCase()
);
}
}
input.addEventListener("input", updateResolver);
clearButton.addEventListener("click", () => {
input.value = "";
updateResolver();
input.focus();
});
for (const button of exampleButtons) {
button.addEventListener("click", () => {
input.value = button.dataset.query;
updateResolver();
});
}
// ------------------------------------------------------------
// Custom camera controls — no external controls addon
// ------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const canvas = renderer.domElement;
let dragging = false;
let moved = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
dragging = true;
moved = false;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
if (Math.abs(deltaX) + Math.abs(deltaY) > 2) {
moved = true;
}
orbit.yaw -= deltaX * 0.005;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + deltaY * 0.004,
0.22,
1.08
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
if (moved) return;
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 intersections = raycaster.intersectObjects(cupRoots, true);
if (intersections.length > 0) {
let object = intersections[0].object;
while (object && !object.userData.cup) {
object = object.parent;
}
if (object?.userData.cup) {
const cup = object.userData.cup;
input.value = `${cup.colorWord} cup`;
updateResolver();
}
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.distance = THREE.MathUtils.clamp(
orbit.distance + event.deltaY * 0.006,
5.7,
13
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
// ------------------------------------------------------------
// Labels, resize, and animation
// ------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
for (const cup of cups) {
projected.set(
cup.root.position.x,
cup.root.position.y + cup.height + 0.31,
cup.root.position.z
);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
cup.label.style.display = visible ? "block" : "none";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
cup.label.style.left = `${x}px`;
cup.label.style.top = `${y}px`;
}
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
});
function animate(time) {
requestAnimationFrame(animate);
for (const cup of cups) {
if (!cup.ring.visible) continue;
const pulse = 1 + Math.sin(time * 0.0035 + cup.position[0]) * 0.035;
cup.ring.scale.set(pulse, pulse, 1);
cup.ring.material.opacity =
0.43 + Math.sin(time * 0.0035 + cup.position[0]) * 0.12;
}
updateLabels();
renderer.render(scene, camera);
}
updateResolver();
updateLabels();
document.getElementById("loading").style.display = "none";
requestAnimationFrame(animate);
</script>
</body>
</html>
```