Prompt specification
Build or customize the Three.js 3D scene "Cup Inside Box Beside Sphere" 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: Cup Inside Box Beside Sphere
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cup-inside-box-beside-sphere-x3413
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows spatial containment and adjacency. Arrange a cup inside an open box and a sphere beside it. Provide distinct object silhouettes and enough clearance to distinguish inside, beside, and overlapping. Stylized solid forms.
Working Three.js Starter (cup-inside-box-beside-sphere-x3413):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spatial Containment and Adjacency</title>
<style>
:root {
--ink: #24333a;
--muted: #6f7c80;
--paper: #f3efe8;
--teal: #168f88;
--gold: #e8a82f;
--coral: #d66e52;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.header {
position: fixed;
top: clamp(20px, 4vw, 42px);
left: clamp(20px, 4vw, 48px);
z-index: 5;
max-width: min(480px, calc(100vw - 120px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 3px;
border-radius: 99px;
background: var(--teal);
content: "";
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 430px;
margin: 14px 0 0;
color: var(--muted);
font-size: clamp(13px, 1.4vw, 16px);
line-height: 1.55;
}
#reset-view {
position: fixed;
top: clamp(20px, 4vw, 42px);
right: clamp(20px, 4vw, 48px);
z-index: 10;
padding: 10px 14px;
border: 1px solid rgba(36, 51, 58, 0.16);
border-radius: 999px;
background: rgba(255, 255, 255, 0.64);
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
background 160ms ease;
}
#reset-view:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.9);
}
.anchor-label {
position: fixed;
top: 0;
left: 0;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid rgba(36, 51, 58, 0.12);
border-radius: 999px;
background: rgba(255, 255, 255, 0.86);
box-shadow: 0 8px 24px rgba(62, 55, 45, 0.1);
color: var(--ink);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.04em;
white-space: nowrap;
pointer-events: none;
backdrop-filter: blur(10px);
}
.anchor-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: linear-gradient(rgba(36, 51, 58, 0.32), transparent);
content: "";
}
.anchor-label .dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 143, 136, 0.12);
}
#sphere-label .dot {
background: var(--gold);
box-shadow: 0 0 0 4px rgba(232, 168, 47, 0.15);
}
.legend {
position: fixed;
left: clamp(20px, 4vw, 48px);
bottom: clamp(20px, 4vw, 42px);
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 9px;
max-width: calc(100vw - 40px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(36, 51, 58, 0.1);
border-radius: 12px;
background: rgba(255, 255, 255, 0.72);
color: var(--muted);
font-size: 11px;
font-weight: 650;
backdrop-filter: blur(12px);
}
.legend-item strong {
color: var(--ink);
font-weight: 800;
}
.legend-icon {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 7px;
background: rgba(22, 143, 136, 0.12);
color: var(--teal);
font-size: 13px;
font-weight: 900;
}
.legend-item:last-child .legend-icon {
background: rgba(232, 168, 47, 0.15);
color: #b9780b;
}
.hint {
position: fixed;
right: clamp(20px, 4vw, 48px);
bottom: clamp(20px, 4vw, 42px);
z-index: 5;
color: rgba(36, 51, 58, 0.56);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 720px) {
.header {
max-width: calc(100vw - 40px);
}
.subtitle {
max-width: 310px;
}
.legend {
right: 20px;
}
.legend-item {
padding: 8px 10px;
}
.hint {
display: none;
}
#reset-view {
top: auto;
right: 20px;
bottom: 104px;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="A cup contained inside an open box, with a sphere beside it"></main>
<header class="header">
<div class="eyebrow">Spatial relationships</div>
<h1>Inside &<br />Beside</h1>
<p class="subtitle">
A teal cup is contained by the open box. The golden sphere remains
separate and adjacent, with a visible gap between the silhouettes.
</p>
</header>
<button id="reset-view" type="button">Reset view</button>
<div id="cup-label" class="anchor-label">
<span class="dot"></span>
CONTAINED
</div>
<div id="sphere-label" class="anchor-label">
<span class="dot"></span>
ADJACENT
</div>
<section class="legend" aria-label="Relationship legend">
<div class="legend-item">
<span class="legend-icon">∈</span>
<span><strong>Cup</strong> inside the box</span>
</div>
<div class="legend-item">
<span class="legend-icon">↔</span>
<span><strong>Sphere</strong> beside, without overlap</span>
</div>
</section>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3efe8);
scene.fog = new THREE.Fog(0xf3efe8, 14, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
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.setAttribute(
"aria-label",
"Interactive 3D scene showing a cup inside a box and a sphere beside the box"
);
sceneHost.appendChild(renderer.domElement);
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8ec, 0x8a8178, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff4dc, 4.2);
keyLight.position.set(-4.5, 9, 6.5);
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 = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9dcff, 1.1);
fillLight.position.set(6, 4, -5);
scene.add(fillLight);
// Materials
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e3da,
roughness: 0.96,
metalness: 0
});
const boxMaterial = new THREE.MeshStandardMaterial({
color: 0xd66e52,
roughness: 0.72,
metalness: 0
});
const boxEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xee9a78,
roughness: 0.7,
metalness: 0
});
const boxInteriorMaterial = new THREE.MeshStandardMaterial({
color: 0x86483d,
roughness: 0.9,
metalness: 0
});
const cupMaterial = new THREE.MeshStandardMaterial({
color: 0x168f88,
roughness: 0.58,
metalness: 0.02,
side: THREE.DoubleSide
});
const cupRimMaterial = new THREE.MeshStandardMaterial({
color: 0x56c8b9,
roughness: 0.48,
metalness: 0.02
});
const cupInsideMaterial = new THREE.MeshStandardMaterial({
color: 0x0a4b4c,
roughness: 0.85,
metalness: 0,
side: THREE.DoubleSide
});
const sphereMaterial = new THREE.MeshStandardMaterial({
color: 0xe8a82f,
roughness: 0.48,
metalness: 0.02
});
// Ground
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Open box, with a lower front wall to keep the cup readable.
const box = new THREE.Group();
box.position.set(-1.25, 0, 0);
scene.add(box);
addBox(box, [4.2, 0.36, 3.4], [0, 0.18, 0], boxMaterial);
const innerFloor = new THREE.Mesh(
new THREE.PlaneGeometry(3.78, 2.98),
boxInteriorMaterial
);
innerFloor.rotation.x = -Math.PI / 2;
innerFloor.position.y = 0.375;
innerFloor.receiveShadow = true;
box.add(innerFloor);
// Side and back walls
addBox(box, [0.22, 1.5, 3.4], [-1.99, 1.11, 0], boxMaterial);
addBox(box, [0.22, 1.5, 3.4], [1.99, 1.11, 0], boxMaterial);
addBox(box, [4.2, 1.5, 0.22], [0, 1.11, -1.59], boxMaterial);
// Lower front wall
addBox(box, [4.2, 0.82, 0.22], [0, 0.77, 1.59], boxMaterial);
// Bright top rims clarify the open-box silhouette.
addBox(box, [0.28, 0.1, 3.46], [-1.99, 1.91, 0], boxEdgeMaterial);
addBox(box, [0.28, 0.1, 3.46], [1.99, 1.91, 0], boxEdgeMaterial);
addBox(box, [4.26, 0.1, 0.28], [0, 1.91, -1.59], boxEdgeMaterial);
addBox(box, [4.26, 0.1, 0.28], [0, 1.23, 1.59], boxEdgeMaterial);
// Dark inner wall panels
addBox(
box,
[0.035, 1.38, 2.98],
[-1.865, 1.1, 0],
boxInteriorMaterial,
false
);
addBox(
box,
[0.035, 1.38, 2.98],
[1.865, 1.1, 0],
boxInteriorMaterial,
false
);
addBox(
box,
[3.76, 1.38, 0.035],
[0, 1.1, -1.465],
boxInteriorMaterial,
false
);
// Cup
const cup = new THREE.Group();
cup.position.set(-1.25, 0, 0.05);
scene.add(cup);
const cupBottom = new THREE.Mesh(
new THREE.CylinderGeometry(0.56, 0.56, 0.12, 48),
cupMaterial
);
cupBottom.position.y = 0.44;
cupBottom.castShadow = true;
cupBottom.receiveShadow = true;
cup.add(cupBottom);
const cupBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.64, 0.56, 1.48, 48, 1, true),
cupMaterial
);
cupBody.position.y = 1.14;
cupBody.castShadow = true;
cupBody.receiveShadow = true;
cup.add(cupBody);
const cupOpening = new THREE.Mesh(
new THREE.CircleGeometry(0.555, 48),
cupInsideMaterial
);
cupOpening.rotation.x = -Math.PI / 2;
cupOpening.position.y = 1.855;
cup.add(cupOpening);
const cupRim = new THREE.Mesh(
new THREE.TorusGeometry(0.6, 0.055, 14, 56),
cupRimMaterial
);
cupRim.rotation.x = -Math.PI / 2;
cupRim.position.y = 1.88;
cupRim.castShadow = true;
cup.add(cupRim);
// The full circular handle is partially hidden by the cup body,
// leaving a clear and recognizable handle silhouette.
const cupHandle = new THREE.Mesh(
new THREE.TorusGeometry(0.4, 0.105, 14, 48),
cupMaterial
);
cupHandle.position.set(0.64, 1.2, 0.015);
cupHandle.castShadow = true;
cup.add(cupHandle);
// Separate sphere beside the box
const sphere = new THREE.Mesh(
new THREE.SphereGeometry(0.82, 48, 32),
sphereMaterial
);
sphere.position.set(2.8, 0.82, 0.12);
sphere.castShadow = true;
sphere.receiveShadow = true;
scene.add(sphere);
// A subtle dashed floor marker emphasizes the adjacency gap.
const gapLineGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0.92, 0.018, 0.12),
new THREE.Vector3(1.91, 0.018, 0.12)
]);
const gapLine = new THREE.Line(
gapLineGeometry,
new THREE.LineDashedMaterial({
color: 0xb9aa98,
dashSize: 0.11,
gapSize: 0.08,
transparent: true,
opacity: 0.65
})
);
gapLine.computeLineDistances();
scene.add(gapLine);
// Camera orbit state
const target = new THREE.Vector3(0.15, 0.82, 0);
const orbit = {
theta: 0.3,
phi: 0.86,
radius: 10.7
};
function responsiveRadius() {
const aspect = window.innerWidth / window.innerHeight;
if (aspect < 0.72) return 16;
if (aspect < 1) return 13.6;
if (window.innerWidth < 900) return 11.7;
return 10.7;
}
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
function resetCamera() {
orbit.theta = 0.3;
orbit.phi = 0.86;
orbit.radius = responsiveRadius();
updateCamera();
}
resetCamera();
// Direct camera controls: no addon imports.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
orbit.theta -= deltaX * 0.005;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + deltaY * 0.004,
0.48,
1.3
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
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 + event.deltaY * 0.008,
7.5,
20
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset-view").addEventListener("click", resetCamera);
// Project labels from their 3D anchors.
const cupLabel = document.getElementById("cup-label");
const sphereLabel = document.getElementById("sphere-label");
const cupAnchor = new THREE.Vector3(-1.25, 2.34, 0.05);
const sphereAnchor = new THREE.Vector3(2.8, 1.83, 0.12);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
renderer.setAnimationLoop(() => {
positionLabel(cupLabel, cupAnchor);
positionLabel(sphereLabel, sphereAnchor);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```