Prompt specification
Build or customize the Three.js 3D scene "Toy and last-seen location card" 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: Toy and last-seen location card
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/toy-and-last-seen-location-card-x3873
Scene Description Prompt:
Show a distinctive toy beside three location cards and one matching play-area symbol; the toy's identifying shape should remain recognizable even without its color. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (toy-and-last-seen-location-card-x3873):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Location Guide</title>
<style>
:root {
--ink: #26323a;
--muted: #687279;
--paper: #fffaf0;
--mint: #4f9b8c;
--mint-dark: #287267;
--line: rgba(38, 50, 58, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 18% 12%, #fffaf2 0, transparent 36%),
linear-gradient(145deg, #eee7da, #dfd6c8);
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
z-index: 3;
top: 30px;
left: 34px;
width: min(420px, calc(100vw - 68px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--mint-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 3px;
background: var(--mint);
content: "";
}
h1 {
max-width: 390px;
margin: 0;
font-size: clamp(34px, 4.2vw, 64px);
font-weight: 850;
line-height: 0.96;
letter-spacing: -0.055em;
}
.intro p {
max-width: 345px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.controls {
position: fixed;
z-index: 4;
top: 30px;
right: 32px;
display: flex;
gap: 8px;
}
button {
border: 1px solid rgba(38, 50, 58, 0.12);
border-radius: 999px;
padding: 10px 15px;
background: rgba(255, 250, 240, 0.88);
color: var(--ink);
box-shadow: 0 8px 25px rgba(38, 50, 58, 0.08);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 750;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-2px);
border-color: rgba(40, 114, 103, 0.35);
}
button[aria-pressed="true"] {
border-color: var(--mint-dark);
background: var(--mint-dark);
color: white;
}
.legend {
position: fixed;
z-index: 3;
right: 32px;
bottom: 24px;
display: flex;
align-items: center;
gap: 15px;
border: 1px solid rgba(38, 50, 58, 0.1);
border-radius: 999px;
padding: 10px 15px;
background: rgba(255, 250, 240, 0.76);
color: var(--muted);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--mint);
}
.dot.coral {
background: #d85e54;
}
.dot.gold {
background: #d8a24f;
}
.hint {
position: fixed;
z-index: 3;
left: 34px;
bottom: 29px;
color: rgba(38, 50, 58, 0.58);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.intro p {
display: none;
}
h1 {
max-width: 270px;
font-size: 38px;
}
.controls {
top: auto;
right: 16px;
bottom: 65px;
}
button {
padding: 9px 12px;
font-size: 11px;
}
.legend {
display: none;
}
.hint {
left: 20px;
bottom: 20px;
max-width: 180px;
line-height: 1.45;
}
}
</style>
</head>
<body>
<header class="intro">
<div class="eyebrow">Voxel location guide</div>
<h1>One rocker.<br>Three possible homes.</h1>
<p>
A shape-first toy stands beside three destination cards and a matching
rocking-horse play-area symbol.
</p>
</header>
<nav class="controls" aria-label="Scene controls">
<button id="shape-toggle" type="button" aria-pressed="false">
Shape only
</button>
<button id="reset-view" type="button">Reset view</button>
</nav>
<div class="legend" aria-hidden="true">
<span><i class="dot coral"></i> toy</span>
<span><i class="dot gold"></i> locations</span>
<span><i class="dot"></i> play area</span>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xe9e2d6, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe9e2d6, 19, 34);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const target = new THREE.Vector3(0, 1.35, 0);
const initialView = {
yaw: 0.26,
pitch: 0.39,
radius: 15.8
};
const view = { ...initialView };
function updateCamera() {
const horizontalRadius = view.radius * Math.cos(view.pitch);
camera.position.set(
target.x + Math.sin(view.yaw) * horizontalRadius,
target.y + Math.sin(view.pitch) * view.radius,
target.z + Math.cos(view.yaw) * horizontalRadius
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0xfff6e7, 0x8a8175, 2.15));
const sun = new THREE.DirectionalLight(0xfff2d5, 3.4);
sun.position.set(-5, 10, 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.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8d7d3, 1.05);
fill.position.set(7, 5, -7);
scene.add(fill);
// ------------------------------------------------------------------
// Helpers
// ------------------------------------------------------------------
const geometryCache = new Map();
function boxGeometry(width, height, depth) {
const key = `${width}/${height}/${depth}`;
if (!geometryCache.has(key)) {
geometryCache.set(
key,
new THREE.BoxGeometry(width, height, depth)
);
}
return geometryCache.get(key);
}
function box(
width,
height,
depth,
x,
y,
z,
material,
parent = scene,
castShadow = true
) {
const mesh = new THREE.Mesh(
boxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function standardMaterial(color, roughness = 0.78) {
return new THREE.MeshStandardMaterial({
color,
roughness,
metalness: 0.02,
flatShading: true
});
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
// ------------------------------------------------------------------
// Voxel floor
// ------------------------------------------------------------------
const floorBase = standardMaterial(0xcfc3b0);
box(19, 0.42, 13.5, 0, -0.27, 0, floorBase, scene, false);
const tileColors = [
0xe9dfcd,
0xe3d8c6,
0xeee5d6,
0xdfd3bf,
0xe8decb
];
const tileGeometry = boxGeometry(1.91, 0.07, 1.72);
for (let row = 0; row < 7; row++) {
for (let column = 0; column < 10; column++) {
const material = standardMaterial(
tileColors[(row * 3 + column * 2) % tileColors.length]
);
const tile = new THREE.Mesh(tileGeometry, material);
tile.position.set(
-8.55 + column * 1.9,
-0.015,
-5.15 + row * 1.7
);
tile.receiveShadow = true;
scene.add(tile);
}
}
// ------------------------------------------------------------------
// Distinctive voxel rocking-horse toy
// ------------------------------------------------------------------
const toy = new THREE.Group();
toy.position.set(-3.45, 0.02, 0.35);
scene.add(toy);
const toyMaterials = {
wood: standardMaterial(0xc98b4c),
woodLight: standardMaterial(0xe0ad69),
coral: standardMaterial(0xd85c53),
teal: standardMaterial(0x4d9588),
ink: standardMaterial(0x27343b),
cream: standardMaterial(0xf7e8c9)
};
const toyMaterialList = Object.values(toyMaterials);
const originalToyColors = toyMaterialList.map(
(material) => material.color.clone()
);
// Two stepped rockers establish the unmistakable silhouette.
for (const z of [-0.39, 0.39]) {
for (let i = 0; i < 15; i++) {
const x = -1.3 + (i / 14) * 2.6;
const arch = 0.075 + 0.39 * Math.pow(x / 1.3, 2);
box(
0.205,
0.14,
0.16,
x,
arch,
z,
toyMaterials.teal,
toy
);
}
}
// Cross braces between the rockers.
for (const x of [-0.57, 0.52]) {
box(
0.17,
0.15,
0.68,
x,
0.39,
0,
toyMaterials.wood,
toy
);
}
// Four legs, ending at the curved rocker line.
for (const x of [-0.57, 0.52]) {
const railY = 0.075 + 0.39 * Math.pow(x / 1.3, 2);
const bottom = railY + 0.09;
const top = 1.42;
const legHeight = top - bottom;
for (const z of [-0.39, 0.39]) {
box(
0.145,
legHeight,
0.145,
x,
bottom + legHeight / 2,
z,
toyMaterials.wood,
toy
);
box(
0.19,
0.12,
0.18,
x,
bottom - 0.015,
z,
toyMaterials.ink,
toy
);
}
}
// Block-built torso.
for (let i = 0; i < 8; i++) {
const x = -0.76 + i * 0.2;
box(
0.19,
0.44,
0.49,
x,
1.61,
0,
i === 2 || i === 6 ? toyMaterials.woodLight : toyMaterials.wood,
toy
);
}
// Rounded-looking rump made from stepped blocks.
box(0.25, 0.38, 0.52, -0.89, 1.62, 0, toyMaterials.woodLight, toy);
box(0.28, 0.25, 0.47, -0.95, 1.85, 0, toyMaterials.wood, toy);
// Upright neck.
box(0.3, 0.34, 0.38, 0.66, 1.91, 0, toyMaterials.wood, toy);
box(0.29, 0.34, 0.36, 0.72, 2.13, 0, toyMaterials.woodLight, toy);
box(0.29, 0.3, 0.34, 0.79, 2.35, 0, toyMaterials.wood, toy);
// Head and muzzle.
box(0.43, 0.31, 0.36, 0.98, 2.43, 0, toyMaterials.woodLight, toy);
box(0.35, 0.2, 0.28, 1.28, 2.35, 0, toyMaterials.wood, toy);
// Ears.
box(0.12, 0.27, 0.13, 0.82, 2.68, -0.07, toyMaterials.wood, toy);
box(0.12, 0.27, 0.13, 1.07, 2.68, 0.07, toyMaterials.wood, toy);
// Mane.
box(0.15, 0.26, 0.42, 0.49, 1.95, 0, toyMaterials.coral, toy);
box(0.15, 0.25, 0.4, 0.56, 2.18, 0, toyMaterials.coral, toy);
box(0.16, 0.23, 0.38, 0.64, 2.39, 0, toyMaterials.coral, toy);
// Tail.
box(0.2, 0.19, 0.28, -1.12, 1.72, 0, toyMaterials.coral, toy);
box(0.19, 0.18, 0.25, -1.3, 1.57, 0, toyMaterials.coral, toy);
box(0.18, 0.16, 0.22, -1.45, 1.43, 0, toyMaterials.coral, toy);
// Saddle and blanket.
box(0.54, 0.13, 0.53, -0.16, 1.88, 0, toyMaterials.coral, toy);
box(0.39, 0.08, 0.56, -0.16, 1.97, 0, toyMaterials.cream, toy);
// Bridle and visible eye.
box(0.055, 0.31, 0.39, 0.81, 2.39, 0, toyMaterials.ink, toy);
box(0.29, 0.045, 0.39, 1.03, 2.38, 0, toyMaterials.ink, toy);
box(0.065, 0.065, 0.035, 1.0, 2.48, 0.192, toyMaterials.ink, toy);
box(0.045, 0.045, 0.035, 1.36, 2.36, 0.151, toyMaterials.ink, toy);
// ------------------------------------------------------------------
// Three location cards
// ------------------------------------------------------------------
function drawNurseryIcon(ctx, color) {
ctx.save();
ctx.translate(256, 365);
ctx.fillStyle = color;
// Crescent moon.
ctx.beginPath();
ctx.arc(0, 0, 70, 0, Math.PI * 2);
ctx.fill();
ctx.globalCompositeOperation = "destination-out";
ctx.beginPath();
ctx.arc(28, -25, 66, 0, Math.PI * 2);
ctx.fill();
ctx.globalCompositeOperation = "source-over";
// Small stars.
for (const [x, y, size] of [
[-100, -48, 8],
[92, 32, 7],
[80, -65, 5]
]) {
ctx.fillRect(x - size / 2, y - size / 2, size, size);
ctx.fillRect(x - size / 4, y - size, size / 2, size * 3);
}
ctx.restore();
}
function drawWorkshopIcon(ctx, color) {
ctx.save();
ctx.translate(256, 365);
ctx.fillStyle = color;
// Hammer head.
ctx.fillRect(-15, -80, 120, 30);
ctx.fillRect(-20, -85, 30, 40);
// Handle.
ctx.save();
ctx.translate(42, 24);
ctx.rotate(-0.66);
ctx.fillRect(-14, -12, 28, 125);
ctx.restore();
// Ruler.
ctx.save();
ctx.translate(-70, 48);
ctx.rotate(0.25);
ctx.fillRect(-12, -10, 24, 115);
for (let i = 0; i < 5; i++) {
ctx.fillRect(0, -8 + i * 22, 15, 5);
}
ctx.restore();
ctx.restore();
}
function drawPlayroomIcon(ctx, color) {
ctx.save();
ctx.translate(256, 360);
ctx.fillStyle = color;
const block = (x, y, size, alpha = 1) => {
ctx.globalAlpha = alpha;
ctx.fillRect(x, y, size, size);
ctx.globalAlpha = 1;
};
block(-95, 10, 80);
block(-5, 10, 80);
block(-50, -80, 80);
block(-50, -80, 80, 0.35);
block(65, -55, 55);
// Small arch drawn from blocks.
block(-115, 82, 30);
block(-50, 82, 30);
block(45, 82, 30);
block(80, 82, 30);
ctx.restore();
}
function makeCardTexture(index, title, accent, iconType) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 768;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#fffaf0";
ctx.fillRect(0, 0, 512, 768);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 512, 18);
ctx.fillRect(0, 690, 512, 78);
ctx.fillStyle = "#788078";
ctx.font = "700 22px Arial";
ctx.letterSpacing = "4px";
ctx.fillText(`LOCATION 0${index}`, 42, 82);
ctx.fillStyle = "#26323a";
ctx.textAlign = "center";
ctx.font = "800 65px Arial";
ctx.fillText(title, 256, 188);
ctx.fillStyle = accent;
roundedRect(ctx, 211, 220, 90, 10, 5);
ctx.fill();
if (iconType === "nursery") drawNurseryIcon(ctx, accent);
if (iconType === "workshop") drawWorkshopIcon(ctx, accent);
if (iconType === "playroom") drawPlayroomIcon(ctx, accent);
ctx.fillStyle = "#fffaf0";
ctx.font = "700 20px Arial";
ctx.fillText("A PLACE FOR EVERYTHING", 256, 737);
return canvasTexture(canvas);
}
function createCard({
index,
title,
accent,
iconType,
x,
z,
rotation = 0
}) {
const group = new THREE.Group();
group.position.set(x, 1.3, z);
group.rotation.y = rotation;
scene.add(group);
const edge = standardMaterial(accent);
const cream = standardMaterial(0xfffaf0);
box(1.69, 2.53, 0.24, 0, 0, 0, edge, group);
box(1.53, 2.37, 0.035, 0, 0, 0.137, cream, group, false);
box(0.72, 0.17, 0.26, 0, 1.31, 0, edge, group);
const faceMaterial = new THREE.MeshBasicMaterial({
map: makeCardTexture(index, title, accent, iconType)
});
const face = new THREE.Mesh(
new THREE.PlaneGeometry(1.52, 2.35),
faceMaterial
);
face.position.set(0, 0, 0.158);
group.add(face);
// Two small voxel feet.
box(0.28, 0.1, 0.52, -0.52, -1.3, 0.08, edge, group);
box(0.28, 0.1, 0.52, 0.52, -1.3, 0.08, edge, group);
}
createCard({
index: 1,
title: "NURSERY",
accent: "#df9a8d",
iconType: "nursery",
x: 0.15,
z: -1.25,
rotation: -0.075
});
createCard({
index: 2,
title: "WORKSHOP",
accent: "#d7a24f",
iconType: "workshop",
x: 2.15,
z: -1.43,
rotation: 0.035
});
createCard({
index: 3,
title: "PLAYROOM",
accent: "#4f9b8c",
iconType: "playroom",
x: 4.15,
z: -1.18,
rotation: -0.055
});
// ------------------------------------------------------------------
// One matching play-area symbol: a rocking-horse floor plaque
// ------------------------------------------------------------------
function createPlayAreaTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 600;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
const teal = "#327d72";
const coral = "#d85c53";
const paper = "#fffaf0";
// Pixelated rocking-horse pictogram.
ctx.fillStyle = teal;
// Tail.
ctx.fillRect(125, 225, 95, 30);
ctx.fillRect(105, 255, 55, 28);
// Body.
ctx.fillRect(195, 205, 280, 55);
ctx.fillRect(225, 175, 185, 45);
ctx.fillRect(205, 250, 235, 48);
// Stepped neck.
ctx.fillRect(425, 150, 70, 90);
ctx.fillRect(460, 95, 70, 115);
// Head and muzzle.
ctx.fillRect(505, 85, 155, 68);
ctx.fillRect(630, 105, 82, 48);
// Legs.
ctx.fillRect(235, 290, 45, 145);
ctx.fillRect(315, 290, 42, 120);
ctx.fillRect(415, 290, 43, 145);
ctx.fillRect(515, 285, 44, 116);
// Pixel-step rocker.
for (let x = 120; x <= 745; x += 18) {
const normalized = (x - 432.5) / 312.5;
const y = 444 + 58 * normalized * normalized;
ctx.fillRect(x, y, 21, 18);
}
// Mane.
ctx.fillStyle = coral;
ctx.fillRect(445, 125, 38, 120);
ctx.fillRect(480, 90, 38, 82);
// Eyes.
ctx.fillStyle = paper;
ctx.fillRect(550, 101, 15, 15);
// Label plate.
ctx.fillStyle = "rgba(255,250,240,0.95)";
roundedRect(ctx, 170, 487, 684, 91, 22);
ctx.fill();
ctx.textAlign = "center";
ctx.fillStyle = "#327d72";
ctx.font = "800 52px Arial";
ctx.fillText("ROCKING HORSE", 512, 535);
ctx.fillStyle = "#5f6b6c";
ctx.font = "700 19px Arial";
ctx.fillText("MATCHING PLAY-AREA SYMBOL", 512, 563);
return canvasTexture(canvas);
}
const playArea = new THREE.Group();
playArea.position.set(2.25, 0, 2.55);
playArea.rotation.y = -0.035;
scene.add(playArea);
const playBorder = standardMaterial(0x4f9b8c);
const playPaper = standardMaterial(0xfffaf0);
box(3.48, 0.13, 2.08, 0, 0.085, 0, playBorder, playArea);
box(3.26, 0.035, 1.87, 0, 0.165, 0, playPaper, playArea, false);
const playFace = new THREE.Mesh(
new THREE.PlaneGeometry(3.22, 1.83),
new THREE.MeshBasicMaterial({
map: createPlayAreaTexture(),
transparent: true
})
);
playFace.rotation.x = -Math.PI / 2;
playFace.position.y = 0.187;
playArea.add(playFace);
// Small corner blocks emphasize the plaque's voxel construction.
for (const x of [-1.65, 1.65]) {
for (const z of [-0.94, 0.94]) {
box(
0.18,
0.17,
0.18,
x,
0.17,
z,
playBorder,
playArea
);
}
}
// ------------------------------------------------------------------
// Direct camera controls: drag, wheel, touch, keyboard, and reset
// ------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
view.yaw -= dx * 0.006;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.005,
0.18,
1.02
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
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();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.012,
10.5,
22
);
updateCamera();
},
{ passive: false }
);
function resetView() {
view.yaw = initialView.yaw;
view.pitch = initialView.pitch;
view.radius = initialView.radius;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetView);
document.getElementById("reset-view").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") view.yaw += step;
if (event.key === "ArrowRight") view.yaw -= step;
if (event.key === "ArrowUp") {
view.pitch = Math.min(1.02, view.pitch + 0.05);
}
if (event.key === "ArrowDown") {
view.pitch = Math.max(0.18, view.pitch - 0.05);
}
if (event.key === "+" || event.key === "=") {
view.radius = Math.max(10.5, view.radius - 0.7);
}
if (event.key === "-" || event.key === "_") {
view.radius = Math.min(22, view.radius + 0.7);
}
if (event.key === "Escape") resetView();
updateCamera();
});
// ------------------------------------------------------------------
// Grayscale shape demonstration
// ------------------------------------------------------------------
const shapeToggle = document.getElementById("shape-toggle");
let shapeOnly = false;
shapeToggle.addEventListener("click", () => {
shapeOnly = !shapeOnly;
shapeToggle.setAttribute("aria-pressed", String(shapeOnly));
shapeToggle.textContent = shapeOnly ? "Show color" : "Shape only";
toyMaterialList.forEach((material, index) => {
if (shapeOnly) {
const hsl = {};
material.color.getHSL(hsl);
material.color.setHSL(0, 0, hsl.l);
} else {
material.color.copy(originalToyColors[index]);
}
});
});
// ------------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```