Prompt specification
Build or customize the Three.js 3D scene "Pet-space preparation object set" 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: Pet-space preparation object set
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pet-space-preparation-object-set-x3841
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Arrange a water bowl, resting mat, toy, and carrier beside a simple room plan; show their intended locations through matching symbols rather than written instructions alone.
Working Three.js Starter (pet-space-preparation-object-set-x3841):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Paws & Plan — Stylized Pet Corner</title>
<style>
:root {
--ink: #253744;
--muted: #6c7c85;
--panel: rgba(255, 255, 255, 0.82);
--border: rgba(49, 73, 86, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8eb;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}
#app,
#stage {
width: 100%;
height: 100%;
}
#stage {
display: block;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow:
0 14px 40px rgba(46, 70, 82, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.75);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.heading {
top: 22px;
left: 22px;
padding: 16px 19px 15px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 4px;
color: #6b8792;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(22px, 3vw, 31px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin-top: 7px;
color: var(--muted);
font-size: 12px;
}
.controls {
top: 22px;
right: 22px;
padding: 11px 14px;
border-radius: 16px;
color: #647983;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.025em;
pointer-events: none;
}
.controls span {
color: #2d4854;
}
.legend {
bottom: 22px;
left: 22px;
padding: 12px;
border-radius: 21px;
}
.legend-title {
padding: 1px 5px 9px;
color: #71828a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: flex;
gap: 8px;
}
.item-button {
display: flex;
align-items: center;
gap: 8px;
min-width: 112px;
padding: 8px 11px 8px 8px;
border: 1px solid transparent;
border-radius: 14px;
background: rgba(255, 255, 255, 0.62);
color: #405661;
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
transform 160ms ease,
border-color 160ms ease,
background 160ms ease,
box-shadow 160ms ease;
}
.item-button:hover {
transform: translateY(-2px);
background: white;
}
.item-button.active {
border-color: var(--accent);
background: white;
box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}
.item-button img {
width: 34px;
height: 34px;
flex: 0 0 auto;
user-select: none;
}
#status {
position: fixed;
right: 22px;
bottom: 22px;
z-index: 10;
max-width: 240px;
padding: 10px 13px;
border-radius: 14px;
color: #6d7e86;
font-size: 11px;
line-height: 1.4;
pointer-events: none;
}
@media (max-width: 760px) {
.heading {
top: 12px;
left: 12px;
padding: 13px 15px;
}
.subtitle {
display: none;
}
.controls {
top: 12px;
right: 12px;
padding: 9px 11px;
font-size: 9px;
}
.legend {
right: 10px;
bottom: 10px;
left: 10px;
overflow-x: auto;
padding: 9px;
}
.legend-title {
padding-left: 3px;
}
.legend-row {
width: max-content;
}
.item-button {
min-width: auto;
padding-right: 10px;
}
#status {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="panel heading">
<div class="eyebrow">Stylized pet setup</div>
<h1>Paws & Plan</h1>
<div class="subtitle">A room corner and its matching location map.</div>
</header>
<div class="panel controls">
<span>Drag</span> to orbit · <span>Scroll</span> to zoom · <span>Select</span> an item
</div>
<nav class="panel legend" aria-label="Pet corner items">
<div class="legend-title">Match the symbols</div>
<div class="legend-row">
<button class="item-button" data-item="bowl" style="--accent:#4ea8de">
<span>Water bowl</span>
</button>
<button class="item-button" data-item="mat" style="--accent:#ef9368">
<span>Resting mat</span>
</button>
<button class="item-button" data-item="toy" style="--accent:#e6b83f">
<span>Toy</span>
</button>
<button class="item-button" data-item="carrier" style="--accent:#8c78d2">
<span>Carrier</span>
</button>
</div>
</nav>
<div class="panel" id="status" aria-live="polite">
Select an object to highlight its matching spot on the plan.
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.domElement.id = "stage";
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.12;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce8eb");
scene.fog = new THREE.Fog("#dce8eb", 19, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(0.2, 1.15, -0.1),
radius: window.innerWidth < 760 ? 18 : 15.5,
yaw: 0.38,
pitch: 0.52,
wantedRadius: window.innerWidth < 760 ? 18 : 15.5,
wantedYaw: 0.38,
wantedPitch: 0.52
};
function updateCamera() {
orbit.yaw += (orbit.wantedYaw - orbit.yaw) * 0.09;
orbit.pitch += (orbit.wantedPitch - orbit.pitch) * 0.09;
orbit.radius += (orbit.wantedRadius - orbit.radius) * 0.09;
const cp = Math.cos(orbit.pitch);
camera.position.set(
orbit.target.x + orbit.radius * Math.sin(orbit.yaw) * cp,
orbit.target.y + orbit.radius * Math.sin(orbit.pitch),
orbit.target.z + orbit.radius * Math.cos(orbit.yaw) * cp
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight("#ffffff", "#a7b9bd", 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff5db", 3.5);
sun.position.set(-5, 11, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fill = new THREE.DirectionalLight("#b9dcff", 1.25);
fill.position.set(8, 5, -6);
scene.add(fill);
const itemData = {
bowl: {
name: "Water bowl",
color: "#4ea8de",
radius: 0.72
},
mat: {
name: "Resting mat",
color: "#ef9368",
radius: 1.28
},
toy: {
name: "Toy",
color: "#e6b83f",
radius: 0.52
},
carrier: {
name: "Carrier",
color: "#8c78d2",
radius: 1.04
}
};
const pickables = [];
const itemMarkers = {
bowl: [],
mat: [],
toy: [],
carrier: []
};
const selectedRing = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.027, 8, 64),
new THREE.MeshBasicMaterial({
color: "#4ea8de",
transparent: true,
opacity: 0.72,
depthWrite: false
})
);
selectedRing.rotation.x = Math.PI / 2;
selectedRing.position.y = 0.225;
selectedRing.renderOrder = 4;
scene.add(selectedRing);
function roundedRectPath(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 roundedRectShape(width, height, radius) {
const shape = new THREE.Shape();
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
shape.moveTo(x + r, y);
shape.lineTo(x + width - r, y);
shape.quadraticCurveTo(x + width, y, x + width, y + r);
shape.lineTo(x + width, y + height - r);
shape.quadraticCurveTo(x + width, y + height, x + width - r, y + height);
shape.lineTo(x + r, y + height);
shape.quadraticCurveTo(x, y + height, x, y + height - r);
shape.lineTo(x, y + r);
shape.quadraticCurveTo(x, y, x + r, y);
return shape;
}
function extrudedShape(shape, depth, bevel = 0.025) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
steps: 1,
bevelEnabled: bevel > 0,
bevelSize: bevel,
bevelThickness: bevel,
bevelSegments: 3,
curveSegments: 16
});
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
return geometry;
}
function standard(color, roughness = 0.72, metalness = 0) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness
});
}
function addMesh(group, geometry, material, position, rotation) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function drawIcon(ctx, kind, color, centerX, centerY, scale) {
ctx.save();
ctx.translate(centerX, centerY);
ctx.scale(scale, scale);
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.lineWidth = 7;
ctx.lineCap = "round";
ctx.lineJoin = "round";
if (kind === "bowl") {
ctx.beginPath();
ctx.moveTo(-34, -11);
ctx.lineTo(34, -11);
ctx.quadraticCurveTo(29, 27, 0, 27);
ctx.quadraticCurveTo(-29, 27, -34, -11);
ctx.closePath();
ctx.fillStyle = color + "30";
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-25, -18);
ctx.quadraticCurveTo(-15, -25, -5, -18);
ctx.quadraticCurveTo(5, -11, 15, -18);
ctx.quadraticCurveTo(23, -23, 29, -18);
ctx.stroke();
}
if (kind === "mat") {
ctx.beginPath();
ctx.ellipse(0, 1, 39, 27, 0, 0, Math.PI * 2);
ctx.fillStyle = color + "28";
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-21, 6);
ctx.quadraticCurveTo(0, -17, 21, 6);
ctx.stroke();
}
if (kind === "toy") {
ctx.beginPath();
ctx.arc(0, 0, 29, 0, Math.PI * 2);
ctx.fillStyle = color + "35";
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-27, -8);
ctx.quadraticCurveTo(0, 8, 27, -8);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-7, -28);
ctx.quadraticCurveTo(7, 0, -7, 28);
ctx.stroke();
}
if (kind === "carrier") {
ctx.beginPath();
ctx.moveTo(-31, 28);
ctx.lineTo(-31, -5);
ctx.quadraticCurveTo(-31, -32, 0, -32);
ctx.quadraticCurveTo(31, -32, 31, -5);
ctx.lineTo(31, 28);
ctx.closePath();
ctx.fillStyle = color + "25";
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-10, 28);
ctx.lineTo(-10, 3);
ctx.quadraticCurveTo(0, -9, 10, 3);
ctx.lineTo(10, 28);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(-13, -30);
ctx.quadraticCurveTo(-13, -47, 0, -47);
ctx.quadraticCurveTo(13, -47, 13, -30);
ctx.stroke();
}
ctx.restore();
}
function makeTokenCanvas(kind, color) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 260;
const ctx = canvas.getContext("2d");
ctx.shadowColor = "rgba(35, 53, 63, 0.18)";
ctx.shadowBlur = 13;
ctx.shadowOffsetY = 6;
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo(105, 157);
ctx.lineTo(151, 157);
ctx.lineTo(128, 224);
ctx.closePath();
ctx.fill();
ctx.shadowColor = "transparent";
ctx.beginPath();
ctx.arc(128, 102, 77, 0, Math.PI * 2);
ctx.fillStyle = "#ffffff";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 11;
ctx.stroke();
drawIcon(ctx, kind, color, 128, 99, 1.12);
return canvas;
}
function makeLegendIcon(kind, color) {
const canvas = document.createElement("canvas");
canvas.width = 72;
canvas.height = 72;
const ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(36, 36, 31, 0, Math.PI * 2);
ctx.fillStyle = "#ffffff";
ctx.fill();
ctx.strokeStyle = color;
ctx.lineWidth = 5;
ctx.stroke();
drawIcon(ctx, kind, color, 36, 36, 0.73);
return canvas.toDataURL();
}
function createToken(kind, color, scale = 0.68) {
const texture = new THREE.CanvasTexture(makeTokenCanvas(kind, color));
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.center.set(0.5, 0);
sprite.scale.set(scale, scale * 1.04, 1);
sprite.renderOrder = 20;
sprite.userData.baseScale = scale;
return sprite;
}
document.querySelectorAll(".item-button").forEach((button) => {
const key = button.dataset.item;
const icon = document.createElement("img");
icon.alt = "";
icon.src = makeLegendIcon(key, itemData[key].color);
button.prepend(icon);
});
// Ground and room shell.
const ground = addMesh(
scene,
new THREE.PlaneGeometry(50, 50),
standard("#d6e3e5", 0.95),
[0, -0.04, 0],
[-Math.PI / 2, 0, 0]
);
ground.castShadow = false;
const floorShape = roundedRectShape(8.45, 6.3, 0.38);
const floor = addMesh(
scene,
extrudedShape(floorShape, 0.18, 0.035),
standard("#eee4d2", 0.86),
[-2.7, 0.09, 0],
[-Math.PI / 2, 0, 0]
);
const floorInset = addMesh(
scene,
extrudedShape(roundedRectShape(8.05, 5.9, 0.3), 0.025, 0.01),
standard("#f7efdf", 0.95),
[-2.7, 0.192, 0],
[-Math.PI / 2, 0, 0]
);
floorInset.castShadow = false;
// Subtle floor seams.
const seamPoints = [];
for (let x = -6.2; x <= 0.8; x += 0.72) {
seamPoints.push(new THREE.Vector3(x, 0.208, -2.75));
seamPoints.push(new THREE.Vector3(x, 0.208, 2.75));
}
for (let z = -2.35; z <= 2.4; z += 0.68) {
seamPoints.push(new THREE.Vector3(-6.55, 0.208, z));
seamPoints.push(new THREE.Vector3(1.15, 0.208, z));
}
const seams = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(seamPoints),
new THREE.LineBasicMaterial({
color: "#d4c8b8",
transparent: true,
opacity: 0.38
})
);
scene.add(seams);
const wallMaterial = standard("#f4f0e8", 0.88);
const trimMaterial = standard("#b8cbd0", 0.75);
addMesh(
scene,
new THREE.BoxGeometry(8.45, 2.75, 0.18),
wallMaterial,
[-2.7, 1.565, -3.08]
);
addMesh(
scene,
new THREE.BoxGeometry(0.18, 2.75, 6.28),
wallMaterial,
[-6.82, 1.565, 0]
);
addMesh(
scene,
new THREE.BoxGeometry(8.2, 0.15, 0.08),
trimMaterial,
[-2.7, 0.27, -2.96]
);
addMesh(
scene,
new THREE.BoxGeometry(0.08, 0.15, 6.05),
trimMaterial,
[-6.69, 0.27, 0]
);
// Stylized window.
const windowGroup = new THREE.Group();
windowGroup.position.set(-2.65, 1.75, -2.95);
scene.add(windowGroup);
addMesh(
windowGroup,
new THREE.BoxGeometry(2.45, 1.35, 0.1),
standard("#ffffff", 0.65),
[0, 0, 0]
);
addMesh(
windowGroup,
new THREE.BoxGeometry(2.19, 1.09, 0.05),
standard("#9fd3e6", 0.48),
[0, 0, 0.07]
);
addMesh(
windowGroup,
new THREE.BoxGeometry(0.07, 1.13, 0.09),
standard("#ffffff", 0.65),
[0, 0, 0.12]
);
addMesh(
windowGroup,
new THREE.BoxGeometry(2.22, 0.07, 0.09),
standard("#ffffff", 0.65),
[0, 0, 0.12]
);
// Paw-print wall decoration.
const paw = new THREE.Group();
paw.position.set(-5.35, 1.72, -2.955);
scene.add(paw);
const pawMaterial = standard("#e8b49c", 0.9);
addMesh(paw, new THREE.SphereGeometry(0.18, 20, 12), pawMaterial, [0, -0.07, 0], [0, 0, 0]);
[
[-0.28, 0.12, -0.04],
[-0.1, 0.24, 0],
[0.11, 0.24, 0],
[0.28, 0.12, -0.04]
].forEach(([x, y, z]) => {
const toe = addMesh(
paw,
new THREE.SphereGeometry(0.085, 16, 10),
pawMaterial,
[x, y, z]
);
toe.scale.set(1, 1.2, 0.45);
});
// Soft patch of sunlight on the floor.
const sunlight = addMesh(
scene,
new THREE.PlaneGeometry(3.1, 1.55),
new THREE.MeshBasicMaterial({
color: "#fff1ad",
transparent: true,
opacity: 0.15,
depthWrite: false
}),
[-3.35, 0.211, 0.9],
[-Math.PI / 2, 0, -0.13]
);
sunlight.castShadow = false;
// Water bowl.
const bowl = new THREE.Group();
bowl.position.set(-1.2, 0.205, 1.25);
scene.add(bowl);
const bowlBody = addMesh(
bowl,
new THREE.CylinderGeometry(0.55, 0.44, 0.28, 48),
standard("#4aa5d2", 0.42),
[0, 0.14, 0]
);
addMesh(
bowl,
new THREE.CylinderGeometry(0.455, 0.455, 0.028, 48),
standard("#71c9ec", 0.2),
[0, 0.291, 0]
);
addMesh(
bowl,
new THREE.TorusGeometry(0.49, 0.045, 12, 48),
standard("#2f8fbe", 0.38),
[0, 0.30, 0],
[Math.PI / 2, 0, 0]
);
// Resting mat.
const mat = new THREE.Group();
mat.position.set(-3.75, 0.205, 0.85);
mat.rotation.y = -0.12;
scene.add(mat);
addMesh(
mat,
extrudedShape(roundedRectShape(2.25, 1.52, 0.32), 0.085, 0.025),
standard("#e98d63", 0.92),
[0, 0.015, 0],
[-Math.PI / 2, 0, 0]
);
const matInset = addMesh(
mat,
extrudedShape(roundedRectShape(1.95, 1.23, 0.25), 0.028, 0.012),
standard("#f5b28c", 0.96),
[0, 0.072, 0],
[-Math.PI / 2, 0, 0]
);
matInset.castShadow = false;
// Toy ball.
const toy = new THREE.Group();
toy.position.set(0.05, 0.205, -1.2);
scene.add(toy);
addMesh(
toy,
new THREE.SphereGeometry(0.33, 32, 24),
standard("#edbd3f", 0.58),
[0, 0.34, 0]
);
addMesh(
toy,
new THREE.TorusGeometry(0.329, 0.027, 10, 48),
standard("#ef865f", 0.55),
[0, 0.34, 0]
);
addMesh(
toy,
new THREE.TorusGeometry(0.329, 0.027, 10, 48),
standard("#ef865f", 0.55),
[0, 0.34, 0],
[0, Math.PI / 2, 0]
);
// Carrier.
const carrier = new THREE.Group();
carrier.position.set(-5.05, 0.205, -1.45);
carrier.rotation.y = 0.08;
scene.add(carrier);
const carrierShape = new THREE.Shape();
carrierShape.moveTo(-0.72, 0);
carrierShape.lineTo(0.72, 0);
carrierShape.lineTo(0.72, 0.92);
carrierShape.quadraticCurveTo(0.72, 1.34, 0.48, 1.49);
carrierShape.quadraticCurveTo(0, 1.67, -0.48, 1.49);
carrierShape.quadraticCurveTo(-0.72, 1.34, -0.72, 0.92);
carrierShape.closePath();
addMesh(
carrier,
extrudedShape(carrierShape, 0.84, 0.045),
standard("#8872cf", 0.63),
[0, 0, 0]
);
addMesh(
carrier,
new THREE.ShapeGeometry(roundedRectShape(1.08, 0.78, 0.17)),
standard("#a692df", 0.6),
[0, 0.44, 0.455]
);
addMesh(
carrier,
new THREE.ShapeGeometry(roundedRectShape(0.58, 0.58, 0.13)),
standard("#4d4969", 0.7),
[0, 0.4, 0.47]
);
[-0.16, 0, 0.16].forEach((x) => {
addMesh(
carrier,
new THREE.BoxGeometry(0.035, 0.48, 0.04),
standard("#c2b3ec", 0.6),
[x, 0.42, 0.495]
);
});
addMesh(
carrier,
new THREE.TorusGeometry(0.22, 0.045, 10, 32, Math.PI),
standard("#6f59bb", 0.6),
[0, 1.55, 0]
);
// Register object meshes for selection.
function registerGroup(group, key) {
group.traverse((child) => {
if (child.isMesh) {
child.userData.itemKey = key;
pickables.push(child);
}
});
}
registerGroup(bowl, "bowl");
registerGroup(mat, "mat");
registerGroup(toy, "toy");
registerGroup(carrier, "carrier");
// Floating symbols over the real objects.
function addObjectMarker(group, key, y) {
const token = createToken(key, itemData[key].color, 0.67);
token.position.set(0, y, 0);
token.userData.itemKey = key;
token.userData.baseY = y;
token.userData.float = true;
group.add(token);
pickables.push(token);
itemMarkers[key].push(token);
const stemGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, Math.max(0.05, y - 0.14), 0),
new THREE.Vector3(0, y, 0)
]);
const stem = new THREE.Line(
stemGeometry,
new THREE.LineBasicMaterial({
color: itemData[key].color,
transparent: true,
opacity: 0.65
})
);
group.add(stem);
}
addObjectMarker(bowl, "bowl", 0.62);
addObjectMarker(mat, "mat", 0.36);
addObjectMarker(toy, "toy", 0.91);
addObjectMarker(carrier, "carrier", 1.93);
// Standing room-plan board.
const board = new THREE.Group();
board.position.set(4.75, 2.7, -0.42);
board.rotation.y = -0.12;
scene.add(board);
addMesh(
board,
extrudedShape(roundedRectShape(4.85, 3.75, 0.28), 0.2, 0.045),
standard("#405866", 0.72),
[0, 0, 0]
);
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1024;
boardCanvas.height = 768;
const bctx = boardCanvas.getContext("2d");
bctx.fillStyle = "#f7f3e9";
bctx.fillRect(0, 0, 1024, 768);
bctx.fillStyle = "#29414d";
bctx.font = "800 47px system-ui, sans-serif";
bctx.fillText("ROOM PLAN", 100, 86);
bctx.fillStyle = "#809098";
bctx.font = "700 22px system-ui, sans-serif";
bctx.fillText("SYMBOL LOCATIONS", 102, 128);
roundedRectPath(bctx, 112, 177, 800, 467, 31);
bctx.fillStyle = "#fffdf8";
bctx.fill();
bctx.strokeStyle = "#8b9ca3";
bctx.lineWidth = 7;
bctx.stroke();
// Door opening and swing.
bctx.strokeStyle = "#fffdf8";
bctx.lineWidth = 12;
bctx.beginPath();
bctx.moveTo(190, 644);
bctx.lineTo(294, 644);
bctx.stroke();
bctx.strokeStyle = "#8b9ca3";
bctx.lineWidth = 5;
bctx.beginPath();
bctx.moveTo(190, 644);
bctx.lineTo(190, 548);
bctx.stroke();
bctx.beginPath();
bctx.arc(190, 644, 96, -Math.PI / 2, 0);
bctx.stroke();
// A small wall/fixed-feature detail.
bctx.strokeStyle = "#c7d1d3";
bctx.lineWidth = 4;
bctx.beginPath();
bctx.moveTo(745, 184);
bctx.lineTo(745, 346);
bctx.stroke();
const boardTexture = new THREE.CanvasTexture(boardCanvas);
boardTexture.colorSpace = THREE.SRGBColorSpace;
boardTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const boardFace = addMesh(
board,
new THREE.PlaneGeometry(4.55, 3.41),
new THREE.MeshStandardMaterial({
map: boardTexture,
roughness: 0.88
}),
[0, 0, 0.115]
);
boardFace.castShadow = false;
// Board legs and feet.
[3.45, 6.05].forEach((x) => {
addMesh(
scene,
new THREE.BoxGeometry(0.15, 1.62, 0.18),
standard("#506773", 0.72),
[x, 0.82, -0.42]
);
addMesh(
scene,
new THREE.BoxGeometry(0.72, 0.12, 0.55),
standard("#506773", 0.72),
[x, 0.08, -0.42]
);
});
// Exact symbol positions on the plan, matching the room arrangement.
const planLocations = {
carrier: [-1.35, 0.52],
mat: [-0.72, -0.50],
bowl: [0.55, -0.56],
toy: [1.28, 0.52]
};
Object.entries(planLocations).forEach(([key, [x, y]]) => {
const token = createToken(key, itemData[key].color, 0.56);
token.position.set(x, y, 0.19);
token.userData.itemKey = key;
board.add(token);
pickables.push(token);
itemMarkers[key].push(token);
});
// Small colored disks beneath the items reinforce the color mapping.
const locations = {
bowl: new THREE.Vector3(-1.2, 0.215, 1.25),
mat: new THREE.Vector3(-3.75, 0.215, 0.85),
toy: new THREE.Vector3(0.05, 0.215, -1.2),
carrier: new THREE.Vector3(-5.05, 0.215, -1.45)
};
Object.entries(locations).forEach(([key, position]) => {
const disk = addMesh(
scene,
new THREE.CircleGeometry(itemData[key].radius * 0.82, 48),
new THREE.MeshBasicMaterial({
color: itemData[key].color,
transparent: true,
opacity: 0.09,
depthWrite: false
}),
[position.x, position.y, position.z],
[-Math.PI / 2, 0, 0]
);
disk.castShadow = false;
disk.renderOrder = 1;
});
let selected = "bowl";
function selectItem(key) {
if (!itemData[key]) return;
selected = key;
const data = itemData[key];
const position = locations[key];
selectedRing.position.set(position.x, 0.23, position.z);
selectedRing.scale.setScalar(data.radius);
selectedRing.material.color.set(data.color);
document.querySelectorAll(".item-button").forEach((button) => {
button.classList.toggle("active", button.dataset.item === key);
});
document.querySelector("#status").textContent =
`${data.name} selected — its matching symbol is highlighted in both places.`;
}
document.querySelectorAll(".item-button").forEach((button) => {
button.addEventListener("click", () => selectItem(button.dataset.item));
});
selectItem("bowl");
// Direct camera controls: drag to orbit and wheel/pinch to zoom.
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
const canvas = renderer.domElement;
let dragging = false;
let moved = 0;
let lastX = 0;
let lastY = 0;
function setPointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pick(event) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, false);
return hits.length ? hits[0].object.userData.itemKey : null;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
moved = 0;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
moved += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
orbit.wantedYaw = THREE.MathUtils.clamp(
orbit.wantedYaw - dx * 0.005,
-0.65,
1.12
);
orbit.wantedPitch = THREE.MathUtils.clamp(
orbit.wantedPitch + dy * 0.004,
0.3,
1.03
);
} else {
const key = pick(event);
canvas.style.cursor = key ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
canvas.style.cursor = "grab";
if (moved < 7) {
const key = pick(event);
if (key) selectItem(key);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.wantedRadius = THREE.MathUtils.clamp(
orbit.wantedRadius + event.deltaY * 0.008,
10.5,
21
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
orbit.wantedYaw = 0.38;
orbit.wantedPitch = 0.52;
orbit.wantedRadius = window.innerWidth < 760 ? 18 : 15.5;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
updateCamera();
Object.entries(itemMarkers).forEach(([key, markers]) => {
markers.forEach((marker, index) => {
const base = marker.userData.baseScale;
const selectedScale = key === selected ? 1.18 : 1;
const pulse =
key === selected ? 1 + Math.sin(elapsed * 4.5) * 0.045 : 1;
const extra = index === 0 ? 1 : 0.9;
marker.scale.set(
base * selectedScale * pulse,
base * 1.04 * selectedScale * pulse,
1
);
if (marker.userData.float) {
marker.position.y =
marker.userData.baseY + Math.sin(elapsed * 2.1 + key.length) * 0.035;
}
});
});
const selectedScale = 1 + Math.sin(elapsed * 3.8) * 0.025;
selectedRing.scale.setScalar(itemData[selected].radius * selectedScale);
selectedRing.material.opacity = 0.58 + Math.sin(elapsed * 3.8) * 0.12;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```