Prompt specification
Build or customize the Three.js 3D scene "Bag Blocking a Shared Bench Seat" 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: Bag Blocking a Shared Bench Seat
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bag-blocking-a-shared-bench-seat-x3269
Scene Description Prompt:
Show a stylized three-seat bench with a person occupying one seat and a bag blocking another. One HTML file using Three.js from cdnjs.
Working Three.js Starter (bag-blocking-a-shared-bench-seat-x3269):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Three-Seat Bench</title>
<style>
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: #dce8e5;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #203a3b;
}
#app {
position: relative;
width: 100%;
height: 100%;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging { cursor: grabbing; }
.panel {
position: absolute;
z-index: 2;
border: 1px solid rgba(255, 255, 255, 0.65);
background: rgba(250, 249, 244, 0.84);
box-shadow: 0 14px 40px rgba(35, 65, 64, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
top: 24px;
left: 24px;
max-width: 330px;
padding: 18px 20px 17px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: #58817d;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 8px;
height: 8px;
border-radius: 50%;
background: #f28b68;
box-shadow: 0 0 0 4px rgba(242, 139, 104, 0.14);
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 36px);
line-height: 1.05;
letter-spacing: -0.045em;
}
.intro p {
margin: 9px 0 0;
color: #5d7473;
font-size: 13px;
line-height: 1.45;
}
.legend {
left: 50%;
bottom: 24px;
display: flex;
gap: 20px;
align-items: center;
padding: 12px 16px;
border-radius: 16px;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #536a69;
font-size: 12px;
font-weight: 700;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
background: #a6b3b0;
}
.dot.occupied { background: #3f8da0; }
.dot.blocked { background: #ef8465; }
.dot.open { background: #77b985; }
.hint {
right: 24px;
bottom: 24px;
padding: 11px 14px;
border-radius: 14px;
color: #617775;
font-size: 11px;
font-weight: 700;
pointer-events: none;
}
#reset {
position: absolute;
z-index: 3;
top: 24px;
right: 24px;
width: 44px;
height: 44px;
border: 1px solid rgba(255, 255, 255, 0.75);
border-radius: 50%;
background: rgba(250, 249, 244, 0.88);
color: #385958;
box-shadow: 0 12px 30px rgba(35, 65, 64, 0.13);
cursor: pointer;
font-size: 20px;
transition: transform 160ms ease, background 160ms ease;
}
#reset:hover {
transform: rotate(-20deg) scale(1.05);
background: #fffdf7;
}
@media (max-width: 760px) {
.intro {
top: 14px;
left: 14px;
max-width: 255px;
padding: 14px 16px;
}
.intro p { display: none; }
.legend {
bottom: 14px;
gap: 11px;
padding: 10px 12px;
}
.legend-item { font-size: 10px; }
.hint { display: none; }
#reset { top: 14px; right: 14px; }
}
</style>
</head>
<body>
<div id="app">
<div class="panel intro">
<div class="eyebrow">Everyday scenes</div>
<h1>Three seats,<br />two occupied.</h1>
<p>A small study in space, patience, and one very assertive bag.</p>
</div>
<button id="reset" aria-label="Reset camera view" title="Reset view">↺</button>
<div class="panel legend" aria-hidden="true">
<div class="legend-item"><span class="dot occupied"></span>Person</div>
<div class="legend-item"><span class="dot open"></span>Open seat</div>
<div class="legend-item"><span class="dot blocked"></span>Bag</div>
</div>
<div class="panel hint">Drag to orbit · Scroll to zoom</div>
</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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e5);
scene.fog = new THREE.Fog(0xdce8e5, 13, 24);
const camera = new THREE.PerspectiveCamera(
35,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"A stylized three-seat bench with a seated person, one empty seat, and a bag occupying another seat."
);
app.prepend(renderer.domElement);
// ---------- Materials ----------
const mat = {
wood: new THREE.MeshStandardMaterial({
color: 0xc88755,
roughness: 0.72,
metalness: 0.02
}),
woodLight: new THREE.MeshStandardMaterial({
color: 0xd89b65,
roughness: 0.75
}),
woodDark: new THREE.MeshStandardMaterial({
color: 0x9d603d,
roughness: 0.8
}),
frame: new THREE.MeshStandardMaterial({
color: 0x294749,
roughness: 0.38,
metalness: 0.62
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x3e879b,
roughness: 0.8
}),
pants: new THREE.MeshStandardMaterial({
color: 0x293c53,
roughness: 0.9
}),
skin: new THREE.MeshStandardMaterial({
color: 0xe7ad84,
roughness: 0.82
}),
hair: new THREE.MeshStandardMaterial({
color: 0x3b2928,
roughness: 0.95
}),
shoe: new THREE.MeshStandardMaterial({
color: 0xf3eee2,
roughness: 0.8
}),
bag: new THREE.MeshStandardMaterial({
color: 0xeb765a,
roughness: 0.68
}),
bagDark: new THREE.MeshStandardMaterial({
color: 0xb94d3f,
roughness: 0.72
}),
bagLight: new THREE.MeshStandardMaterial({
color: 0xf3a17d,
roughness: 0.72
}),
cream: new THREE.MeshStandardMaterial({
color: 0xf8f0df,
roughness: 0.8
}),
floor: new THREE.MeshStandardMaterial({
color: 0xece7dc,
roughness: 0.96
}),
platform: new THREE.MeshStandardMaterial({
color: 0xf5f0e6,
roughness: 0.92
}),
pot: new THREE.MeshStandardMaterial({
color: 0xbd7259,
roughness: 0.86
}),
leaf: new THREE.MeshStandardMaterial({
color: 0x547f68,
roughness: 0.9
}),
leafLight: new THREE.MeshStandardMaterial({
color: 0x78a47e,
roughness: 0.9
})
};
// ---------- Geometry helpers ----------
function roundedRectangleShape(width, height, radius) {
const x = -width / 2;
const y = -height / 2;
const r = Math.min(radius, width / 2, height / 2);
const shape = new THREE.Shape();
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 roundedBox(width, height, depth, radius, material) {
const bevel = Math.min(radius, width / 4, height / 4, depth / 4);
const shape = roundedRectangleShape(
width - bevel * 2,
height - bevel * 2,
bevel
);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: depth - bevel * 2,
bevelEnabled: true,
bevelThickness: bevel,
bevelSize: bevel,
bevelSegments: 4,
curveSegments: 10
});
geometry.translate(0, 0, -(depth - bevel * 2) / 2);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function box(width, height, depth, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function sphere(radius, material, widthSegments = 24) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, widthSegments, 16),
material
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function cylinderBetween(a, b, radius, material, radialSegments = 14) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
material
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function makeNumberTexture(number) {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 128, 128);
ctx.fillStyle = "#f8f0df";
ctx.beginPath();
ctx.arc(64, 64, 54, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#d5bd91";
ctx.lineWidth = 6;
ctx.stroke();
ctx.fillStyle = "#35504f";
ctx.font = "700 62px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(String(number), 64, 67);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// ---------- Environment ----------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
mat.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.08;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5.25, 5.35, 0.16, 64),
mat.platform
);
platform.position.y = 0.0;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const sun = new THREE.Mesh(
new THREE.CircleGeometry(1.12, 48),
new THREE.MeshBasicMaterial({ color: 0xf2c36f })
);
sun.position.set(3.25, 3.55, -3.8);
scene.add(sun);
const halo = new THREE.Mesh(
new THREE.RingGeometry(1.3, 1.43, 48),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.38,
side: THREE.DoubleSide
})
);
halo.position.copy(sun.position);
halo.position.z += 0.01;
scene.add(halo);
// Small stylized plant for depth.
const plant = new THREE.Group();
plant.position.set(-3.85, 0.08, -1.35);
plant.rotation.y = 0.25;
const pot = new THREE.Mesh(
new THREE.CylinderGeometry(0.38, 0.28, 0.72, 20),
mat.pot
);
pot.position.y = 0.36;
pot.castShadow = true;
pot.receiveShadow = true;
plant.add(pot);
const stemMaterial = new THREE.MeshStandardMaterial({
color: 0x466b58,
roughness: 0.9
});
const leafPositions = [
[-0.24, 1.16, 0.02, -0.5],
[0.18, 1.35, -0.03, 0.55],
[-0.10, 1.58, 0.01, -0.2],
[0.25, 1.72, 0.02, 0.6],
[-0.22, 1.84, -0.02, -0.55]
];
leafPositions.forEach((data, index) => {
const [x, y, z, rz] = data;
const stemTop = new THREE.Vector3(x * 0.35, 0.72, z);
const leafBase = new THREE.Vector3(x, y - 0.26, z);
plant.add(cylinderBetween(stemTop, leafBase, 0.022, stemMaterial, 8));
const leaf = sphere(0.25, index % 2 ? mat.leaf : mat.leafLight);
leaf.position.set(x, y, z);
leaf.scale.set(0.66, 1.32, 0.34);
leaf.rotation.z = rz;
plant.add(leaf);
});
scene.add(plant);
// ---------- Bench ----------
const bench = new THREE.Group();
scene.add(bench);
const seatXs = [-1.55, 0, 1.55];
// Three visibly separate seat panels.
seatXs.forEach((x, index) => {
const seat = roundedBox(
1.48,
0.22,
1.02,
0.09,
index === 1 ? mat.woodLight : mat.wood
);
seat.position.set(x, 1.46, 0);
bench.add(seat);
// Subtle wood grain.
[-0.28, 0, 0.28].forEach((z, lineIndex) => {
const grain = box(
1.19 - lineIndex * 0.08,
0.008,
0.012,
mat.woodDark
);
grain.position.set(x + (lineIndex - 1) * 0.035, 1.575, z);
grain.castShadow = false;
bench.add(grain);
});
// Numbered enamel badge on the front edge.
const badge = new THREE.Mesh(
new THREE.PlaneGeometry(0.19, 0.19),
new THREE.MeshBasicMaterial({
map: makeNumberTexture(index + 1),
transparent: true,
depthWrite: false
})
);
badge.position.set(x, 1.45, 0.519);
bench.add(badge);
});
// Horizontal backrest slats.
[1.98, 2.35, 2.72].forEach((y, index) => {
const slat = roundedBox(
4.86,
0.24,
0.15,
0.06,
index === 1 ? mat.woodLight : mat.wood
);
slat.position.set(0, y, -0.48);
bench.add(slat);
});
// Back supports.
[-2.22, 0, 2.22].forEach((x) => {
const post = box(0.11, 1.5, 0.11, mat.frame);
post.position.set(x, 2.03, -0.54);
bench.add(post);
});
// Under-seat rails.
[-0.31, 0.31].forEach((z) => {
const rail = roundedBox(4.75, 0.13, 0.13, 0.045, mat.frame);
rail.position.set(0, 1.27, z);
bench.add(rail);
});
// Six legs.
[-2.08, 0, 2.08].forEach((x) => {
[-0.35, 0.35].forEach((z) => {
const leg = cylinderBetween(
new THREE.Vector3(x, 0.09, z),
new THREE.Vector3(x, 1.29, z),
0.065,
mat.frame
);
bench.add(leg);
const foot = sphere(0.082, mat.frame, 16);
foot.position.set(x, 0.10, z);
foot.scale.y = 0.45;
bench.add(foot);
});
});
// Outer armrests.
[-2.52, 2.52].forEach((x) => {
const arm = roundedBox(0.14, 0.14, 1.03, 0.055, mat.frame);
arm.position.set(x, 2.04, -0.02);
bench.add(arm);
const support = cylinderBetween(
new THREE.Vector3(x, 1.39, -0.36),
new THREE.Vector3(x, 2.02, -0.36),
0.055,
mat.frame
);
bench.add(support);
});
// ---------- Person on the left seat ----------
const person = new THREE.Group();
person.position.x = -1.55;
scene.add(person);
// Hips.
const hips = roundedBox(0.69, 0.34, 0.48, 0.16, mat.pants);
hips.position.set(0, 1.72, -0.02);
person.add(hips);
// Shirt torso.
const torso = new THREE.Mesh(
new THREE.CapsuleGeometry(0.35, 0.56, 8, 20),
mat.shirt
);
torso.position.set(0, 2.30, -0.03);
torso.scale.set(1.06, 1, 0.73);
torso.castShadow = true;
torso.receiveShadow = true;
person.add(torso);
// Neck.
const neck = new THREE.Mesh(
new THREE.CylinderGeometry(0.12, 0.14, 0.25, 16),
mat.skin
);
neck.position.set(0, 2.91, -0.02);
neck.castShadow = true;
person.add(neck);
// Head and hair.
const head = sphere(0.34, mat.skin, 32);
head.position.set(0, 3.23, 0);
head.scale.set(0.94, 1.08, 0.93);
person.add(head);
const hair = sphere(0.35, mat.hair, 32);
hair.position.set(0, 3.36, -0.055);
hair.scale.set(1.02, 0.74, 0.90);
person.add(hair);
[-1, 1].forEach((side) => {
const ear = sphere(0.075, mat.skin, 16);
ear.position.set(side * 0.315, 3.21, 0.0);
ear.scale.set(0.62, 1, 0.82);
person.add(ear);
const eye = sphere(0.026, mat.hair, 12);
eye.position.set(side * 0.105, 3.265, 0.302);
eye.scale.z = 0.55;
person.add(eye);
});
const nose = sphere(0.047, mat.skin, 16);
nose.position.set(0, 3.18, 0.335);
nose.scale.set(0.8, 0.8, 1.1);
person.add(nose);
const mouth = roundedBox(0.085, 0.018, 0.018, 0.008, mat.hair);
mouth.position.set(0, 3.075, 0.318);
person.add(mouth);
// Legs.
[-0.19, 0.19].forEach((x, index) => {
const hipPoint = new THREE.Vector3(x, 1.73, 0.03);
const kneePoint = new THREE.Vector3(x, 1.59, 0.67);
const anklePoint = new THREE.Vector3(x, 0.30, 0.70);
person.add(cylinderBetween(hipPoint, kneePoint, 0.18, mat.pants, 18));
const knee = sphere(0.18, mat.pants, 18);
knee.position.copy(kneePoint);
person.add(knee);
person.add(cylinderBetween(kneePoint, anklePoint, 0.135, mat.pants, 18));
const shoe = roundedBox(0.31, 0.19, 0.54, 0.085, mat.shoe);
shoe.position.set(x, 0.22, 0.81);
shoe.rotation.y = index ? -0.035 : 0.035;
person.add(shoe);
const sole = roundedBox(0.32, 0.055, 0.55, 0.025, mat.cream);
sole.position.set(x, 0.13, 0.815);
sole.rotation.y = index ? -0.035 : 0.035;
person.add(sole);
});
// Arms resting in the lap.
[-1, 1].forEach((side) => {
const shoulder = new THREE.Vector3(side * 0.34, 2.66, -0.02);
const elbow = new THREE.Vector3(side * 0.49, 2.18, 0.16);
const wrist = new THREE.Vector3(side * 0.32, 1.83, 0.50);
person.add(cylinderBetween(shoulder, elbow, 0.115, mat.shirt, 16));
person.add(cylinderBetween(elbow, wrist, 0.09, mat.skin, 16));
const elbowJoint = sphere(0.115, mat.shirt, 16);
elbowJoint.position.copy(elbow);
person.add(elbowJoint);
const hand = sphere(0.105, mat.skin, 16);
hand.position.copy(wrist);
hand.scale.set(0.8, 1.15, 0.7);
person.add(hand);
});
// ---------- Bag occupying the right seat ----------
const bag = new THREE.Group();
bag.position.set(1.55, 0, 0);
bag.rotation.y = -0.10;
scene.add(bag);
const bagBody = roundedBox(1.25, 0.69, 0.77, 0.19, mat.bag);
bagBody.position.set(0, 1.93, -0.01);
bag.add(bagBody);
// Side end panels.
[-0.59, 0.59].forEach((x) => {
const end = roundedBox(0.10, 0.53, 0.60, 0.09, mat.bagDark);
end.position.set(x, 1.92, -0.01);
bag.add(end);
});
// Front pocket.
const pocket = roundedBox(0.74, 0.39, 0.12, 0.075, mat.bagLight);
pocket.position.set(0.04, 1.88, 0.42);
bag.add(pocket);
// Zipper.
const zipper = roundedBox(0.91, 0.028, 0.035, 0.012, mat.bagDark);
zipper.position.set(0, 2.205, 0.23);
bag.add(zipper);
const zipperPull = roundedBox(0.06, 0.13, 0.04, 0.018, mat.cream);
zipperPull.position.set(0.30, 2.17, 0.26);
bag.add(zipperPull);
// Tubular handles.
const handleCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.30, 2.20, 0.03),
new THREE.Vector3(-0.31, 2.47, 0.03),
new THREE.Vector3(-0.14, 2.62, 0.03),
new THREE.Vector3(0.14, 2.62, 0.03),
new THREE.Vector3(0.31, 2.47, 0.03),
new THREE.Vector3(0.30, 2.20, 0.03)
]);
const handle = new THREE.Mesh(
new THREE.TubeGeometry(handleCurve, 30, 0.047, 9, false),
mat.bagDark
);
handle.castShadow = true;
bag.add(handle);
// Small luggage tag.
const tag = roundedBox(0.19, 0.27, 0.055, 0.035, mat.cream);
tag.position.set(0.40, 2.08, 0.47);
tag.rotation.z = -0.12;
bag.add(tag);
const tagLine = roundedBox(0.095, 0.018, 0.012, 0.006, mat.bagDark);
tagLine.position.set(0.40, 2.11, 0.502);
tagLine.rotation.z = -0.12;
bag.add(tagLine);
// ---------- Lighting ----------
const hemisphere = new THREE.HemisphereLight(0xf8fbff, 0x8d7965, 2.1);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xfff1d4, 3.4);
sunLight.position.set(-4.5, 8.5, 6);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -7;
sunLight.shadow.camera.right = 7;
sunLight.shadow.camera.top = 7;
sunLight.shadow.camera.bottom = -7;
sunLight.shadow.camera.near = 0.5;
sunLight.shadow.camera.far = 22;
sunLight.shadow.bias = -0.0004;
scene.add(sunLight);
const fill = new THREE.DirectionalLight(0xbad9e5, 1.2);
fill.position.set(5, 4, -4);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb98e, 0.8);
rim.position.set(-5, 3, -5);
scene.add(rim);
// ---------- Custom camera controls ----------
const target = new THREE.Vector3(0, 1.62, 0);
const spherical = new THREE.Spherical(9.35, 1.22, 0.48);
const initialSpherical = spherical.clone();
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
spherical.phi = THREE.MathUtils.clamp(spherical.phi, 0.62, 1.43);
spherical.radius = THREE.MathUtils.clamp(spherical.radius, 6.4, 13.5);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.theta -= dx * 0.006;
spherical.phi -= dy * 0.005;
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (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();
spherical.radius *= Math.exp(event.deltaY * 0.001);
updateCamera();
},
{ passive: false }
);
document.querySelector("#reset").addEventListener("click", () => {
spherical.copy(initialSpherical);
updateCamera();
});
addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```