Prompt specification
Build or customize the Three.js 3D scene "Skateboard Deck and Support Footprint" 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: Skateboard Deck and Support Footprint
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/skateboard-deck-and-support-footprint-x3653
Scene Description Prompt:
I'd like to see this as a low-poly Three.js scene: skateboard deck and support footprint. Model a skateboard and two foot markers with a schematic combined mass center. Show the support area and label the balance visualization as simplified. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (skateboard-deck-and-support-footprint-x3653):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Skateboard Balance Study</title>
<style>
:root {
--ink: #25313a;
--muted: #68747a;
--paper: rgba(248, 245, 236, 0.88);
--line: rgba(37, 49, 58, 0.16);
--cyan: #26b8aa;
--amber: #e8aa3b;
--coral: #e7623e;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e3d7;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
background: var(--paper);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
box-shadow: 0 14px 45px rgba(48, 54, 55, 0.10);
}
#intro {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 8px;
color: var(--coral);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 42px);
line-height: 0.98;
letter-spacing: -0.055em;
text-transform: uppercase;
}
#intro p {
margin: 12px 0 16px;
max-width: 330px;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.simplified {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 8px 10px;
border: 1px solid rgba(232, 170, 59, 0.42);
border-radius: 999px;
background: rgba(232, 170, 59, 0.12);
color: #8a5d12;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.simplified::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--amber);
content: "";
box-shadow: 0 0 0 4px rgba(232, 170, 59, 0.13);
}
#legend {
right: 24px;
bottom: 24px;
width: 245px;
padding: 16px;
border-radius: 16px;
}
.legend-title {
margin: 0 0 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 22px 1fr;
align-items: center;
gap: 9px;
margin-top: 10px;
font-size: 12px;
}
.swatch {
display: block;
width: 18px;
height: 10px;
border-radius: 4px;
}
.swatch.support {
border: 1px solid rgba(38, 184, 170, 0.65);
background: rgba(38, 184, 170, 0.22);
}
.swatch.center {
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 4px rgba(232, 170, 59, 0.14);
}
.swatch.foot-a {
background: #35c7b4;
}
.swatch.foot-b {
background: #f2bd4e;
}
.legend-note {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#controls {
position: fixed;
right: 24px;
top: 24px;
z-index: 6;
display: flex;
gap: 7px;
}
button {
border: 1px solid var(--line);
border-radius: 10px;
padding: 9px 11px;
background: rgba(248, 245, 236, 0.90);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
color 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fffdf7;
}
button.active {
border-color: var(--ink);
background: var(--ink);
color: #fffaf0;
}
#hint {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 9px;
color: rgba(37, 49, 58, 0.66);
font-size: 11px;
letter-spacing: 0.02em;
pointer-events: none;
}
#hint span {
width: 25px;
height: 25px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 50%;
background: rgba(248, 245, 236, 0.62);
font-size: 13px;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.world-label {
position: absolute;
white-space: nowrap;
opacity: 0;
transition: opacity 120ms ease;
}
.world-label.visible {
opacity: 1;
}
.world-label b {
display: block;
font-size: 10px;
letter-spacing: 0.10em;
text-transform: uppercase;
}
.world-label small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.02em;
}
#support-label {
padding: 7px 9px;
border-left: 2px solid var(--cyan);
border-radius: 0 8px 8px 0;
background: rgba(248, 245, 236, 0.80);
transform: translate(18px, -50%);
box-shadow: 0 6px 18px rgba(37, 49, 58, 0.07);
}
#support-label::before {
position: absolute;
top: 50%;
right: 100%;
width: 16px;
height: 1px;
background: var(--cyan);
content: "";
}
#center-label {
padding: 8px 10px;
border: 1px solid rgba(232, 170, 59, 0.42);
border-radius: 9px;
background: rgba(248, 245, 236, 0.88);
transform: translate(-50%, calc(-100% - 22px));
box-shadow: 0 8px 22px rgba(37, 49, 58, 0.08);
}
#center-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 20px;
background: var(--amber);
content: "";
}
@media (max-width: 700px) {
#intro {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 15px 17px;
}
#intro p {
display: none;
}
h1 {
font-size: 28px;
}
#legend {
right: 14px;
bottom: 14px;
width: 205px;
padding: 13px;
}
#controls {
top: 128px;
right: 14px;
}
#hint {
left: 14px;
bottom: 16px;
max-width: 120px;
align-items: flex-start;
line-height: 1.35;
}
.world-label small {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section id="intro" class="panel">
<p class="eyebrow">Low-poly mechanics study</p>
<h1>Skate / Balance</h1>
<p>
A schematic rider-and-board model showing two foot inputs, the combined
mass center, and the wheel-contact support footprint.
</p>
<div class="simplified">Simplified balance visualization</div>
</section>
<div id="controls" aria-label="Camera views">
<button id="view-3d" class="active" type="button">3/4 View</button>
<button id="view-top" type="button">Top</button>
<button id="reset" type="button">Reset</button>
</div>
<section id="legend" class="panel" aria-label="Scene legend">
<p class="legend-title">Visual Key</p>
<div class="legend-row">
<span class="swatch support"></span>
<span>Support area / footprint</span>
</div>
<div class="legend-row">
<span class="swatch center"></span>
<span>Combined mass center</span>
</div>
<div class="legend-row">
<span class="swatch foot-a"></span>
<span>Rear foot input</span>
</div>
<div class="legend-row">
<span class="swatch foot-b"></span>
<span>Front foot input</span>
</div>
<p class="legend-note">
Positions and masses are diagrammatic, not a biomechanical or structural
simulation.
</p>
</section>
<div id="hint"><span>↔</span> Drag to orbit · scroll to zoom</div>
<div id="labels">
<div id="support-label" class="world-label">
<b>Support area / footprint</b>
<small>Wheel-contact envelope</small>
</div>
<div id="center-label" class="world-label">
<b>Combined mass center</b>
<small>Deck + equal foot inputs · schematic</small>
</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 stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e3d7);
scene.fog = new THREE.Fog(0xe8e3d7, 12, 25);
const camera = new THREE.PerspectiveCamera(
36,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xfff7e8, 0x66717a, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d8, 3.15);
sun.position.set(-4.5, 8, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -7;
sun.shadow.camera.right = 7;
sun.shadow.camera.top = 7;
sun.shadow.camera.bottom = -7;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 20;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xa8d9e7, 1.25);
rim.position.set(5, 4, -5);
scene.add(rim);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xded8ca,
roughness: 0.96,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(28, 28),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(20, 20, 0xbdb5a5, 0xcfc8b9);
grid.position.y = 0.008;
grid.material.transparent = true;
grid.material.opacity = 0.26;
scene.add(grid);
const skateboard = new THREE.Group();
scene.add(skateboard);
const coralMaterial = new THREE.MeshStandardMaterial({
color: 0xe7623e,
roughness: 0.62,
metalness: 0.04,
flatShading: true
});
const gripMaterial = new THREE.MeshStandardMaterial({
color: 0x27343d,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0xaab2b3,
roughness: 0.36,
metalness: 0.72,
flatShading: true
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x536069,
roughness: 0.45,
metalness: 0.58,
flatShading: true
});
const wheelMaterial = new THREE.MeshStandardMaterial({
color: 0xf0c76b,
roughness: 0.72,
metalness: 0.02,
flatShading: true
});
function createDeckShape(lengthScale = 1, widthScale = 1) {
const points = [
[-2.42, 0.00],
[-2.28, 0.34],
[-1.88, 0.58],
[-1.38, 0.68],
[0.85, 0.67],
[1.34, 0.57],
[1.82, 0.43],
[2.27, 0.28],
[2.42, 0.00],
[2.27, -0.28],
[1.82, -0.43],
[1.34, -0.57],
[0.85, -0.67],
[-1.38, -0.68],
[-1.88, -0.58],
[-2.28, -0.34]
];
const shape = new THREE.Shape();
points.forEach(([x, y], index) => {
const px = x * lengthScale;
const py = y * widthScale;
if (index === 0) shape.moveTo(px, py);
else shape.lineTo(px, py);
});
shape.closePath();
return shape;
}
function bendEnds(geometry) {
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const x = position.getX(i);
const amount = Math.max(0, Math.abs(x) - 1.42);
position.setY(i, position.getY(i) + amount * amount * 0.13);
}
position.needsUpdate = true;
geometry.computeVertexNormals();
}
const deckGeometry = new THREE.ExtrudeGeometry(createDeckShape(), {
depth: 0.13,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.04,
bevelThickness: 0.04,
curveSegments: 1
});
deckGeometry.rotateX(-Math.PI / 2);
bendEnds(deckGeometry);
const deck = new THREE.Mesh(deckGeometry, coralMaterial);
deck.position.y = 0.89;
deck.castShadow = true;
deck.receiveShadow = true;
skateboard.add(deck);
const gripGeometry = new THREE.ExtrudeGeometry(
createDeckShape(0.93, 0.90),
{
depth: 0.018,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.012,
bevelThickness: 0.012,
curveSegments: 1
}
);
gripGeometry.rotateX(-Math.PI / 2);
bendEnds(gripGeometry);
const grip = new THREE.Mesh(gripGeometry, gripMaterial);
grip.position.y = 1.055;
grip.castShadow = true;
grip.receiveShadow = true;
skateboard.add(grip);
// Truck bases, hangers, axles, and low-poly wheels.
const truckXs = [-1.48, 1.48];
const wheelXs = [-1.5, 1.5];
const wheelZs = [-0.78, 0.78];
for (const x of truckXs) {
const base = new THREE.Mesh(
new THREE.BoxGeometry(0.42, 0.11, 1.04),
darkMetalMaterial
);
base.position.set(x, 0.79, 0);
base.castShadow = true;
skateboard.add(base);
const hanger = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.18, 0.52),
metalMaterial
);
hanger.position.set(x, 0.53, 0);
hanger.castShadow = true;
skateboard.add(hanger);
const kingpin = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.34, 8),
darkMetalMaterial
);
kingpin.position.set(x, 0.69, 0);
kingpin.castShadow = true;
skateboard.add(kingpin);
const axle = new THREE.Mesh(
new THREE.CylinderGeometry(0.043, 0.043, 1.73, 8),
metalMaterial
);
axle.rotation.x = Math.PI / 2;
axle.position.set(x, 0.22, 0);
axle.castShadow = true;
skateboard.add(axle);
}
for (const x of wheelXs) {
for (const z of wheelZs) {
const wheel = new THREE.Mesh(
new THREE.CylinderGeometry(0.22, 0.22, 0.23, 10),
wheelMaterial
);
wheel.rotation.x = Math.PI / 2;
wheel.position.set(x, 0.22, z);
wheel.castShadow = true;
wheel.receiveShadow = true;
skateboard.add(wheel);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.082, 0.082, 0.245, 10),
darkMetalMaterial
);
hub.rotation.x = Math.PI / 2;
hub.position.set(x, 0.22, z);
hub.castShadow = true;
skateboard.add(hub);
}
}
// Eight visible mounting bolts.
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0xbdc4c3,
roughness: 0.32,
metalness: 0.78,
flatShading: true
});
for (const x of truckXs) {
for (const z of [-0.34, 0.34]) {
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.025, 8),
boltMaterial
);
bolt.position.set(x, 1.115, z);
skateboard.add(bolt);
}
}
function createFootGeometry() {
const shape = new THREE.Shape();
const points = [
[-0.36, -0.12],
[-0.40, -0.08],
[-0.37, 0.10],
[-0.23, 0.15],
[-0.02, 0.15],
[0.17, 0.19],
[0.34, 0.18],
[0.43, 0.10],
[0.39, -0.04],
[0.22, -0.12],
[-0.10, -0.14]
];
points.forEach(([x, y], index) => {
if (index === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.055,
steps: 1,
bevelEnabled: true,
bevelSegments: 1,
bevelSize: 0.014,
bevelThickness: 0.014,
curveSegments: 1
});
geometry.rotateX(-Math.PI / 2);
return geometry;
}
const footGeometry = createFootGeometry();
const rearFootMaterial = new THREE.MeshStandardMaterial({
color: 0x35c7b4,
roughness: 0.72,
metalness: 0,
flatShading: true
});
const frontFootMaterial = new THREE.MeshStandardMaterial({
color: 0xf2bd4e,
roughness: 0.72,
metalness: 0,
flatShading: true
});
const ridgeMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f0dc,
roughness: 0.9,
flatShading: true
});
function addFoot(x, z, angle, material) {
const foot = new THREE.Group();
foot.position.set(x, 1.105, z);
foot.rotation.y = angle;
const sole = new THREE.Mesh(footGeometry, material);
sole.castShadow = true;
sole.receiveShadow = true;
foot.add(sole);
for (const ridgeX of [0.16, 0.25, 0.33]) {
const ridge = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.018, 0.24),
ridgeMaterial
);
ridge.position.set(ridgeX, 0.079, -0.015);
foot.add(ridge);
}
skateboard.add(foot);
}
addFoot(-0.72, -0.085, 0.08, rearFootMaterial);
addFoot(0.48, 0.085, -0.07, frontFootMaterial);
// The support footprint is the quadrilateral joining wheel contact points.
const supportShape = new THREE.Shape();
supportShape.moveTo(-1.5, -0.78);
supportShape.lineTo(1.5, -0.78);
supportShape.lineTo(1.5, 0.78);
supportShape.lineTo(-1.5, 0.78);
supportShape.closePath();
const supportGeometry = new THREE.ShapeGeometry(supportShape);
supportGeometry.rotateX(-Math.PI / 2);
const supportFill = new THREE.Mesh(
supportGeometry,
new THREE.MeshBasicMaterial({
color: 0x26b8aa,
transparent: true,
opacity: 0.17,
depthWrite: false,
side: THREE.DoubleSide,
polygonOffset: true,
polygonOffsetFactor: -1
})
);
supportFill.position.y = 0.027;
scene.add(supportFill);
const footprintOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-1.5, 0.034, -0.78),
new THREE.Vector3(1.5, 0.034, -0.78),
new THREE.Vector3(1.5, 0.034, 0.78),
new THREE.Vector3(-1.5, 0.034, 0.78)
]),
new THREE.LineBasicMaterial({
color: 0x1aa99c,
transparent: true,
opacity: 0.95
})
);
scene.add(footprintOutline);
const hatchPoints = [];
for (let x = -1.45; x <= 0.01; x += 0.25) {
hatchPoints.push(
new THREE.Vector3(x, 0.035, -0.76),
new THREE.Vector3(x + 1.5, 0.035, 0.76)
);
}
const hatch = new THREE.LineSegments(
new THREE.BufferGeometry().setFromPoints(hatchPoints),
new THREE.LineBasicMaterial({
color: 0x219f94,
transparent: true,
opacity: 0.27
})
);
scene.add(hatch);
// Schematic aggregate center of mass.
// Deck center is x=0; equal foot inputs are placed at x=-0.72 and x=0.48.
const combinedCenterX = (-0.72 + 0.48) / 2;
const combinedCenter = new THREE.Vector3(combinedCenterX, 2.38, 0);
const comMaterial = new THREE.MeshStandardMaterial({
color: 0xe8aa3b,
emissive: 0x5d3900,
emissiveIntensity: 0.28,
roughness: 0.32,
metalness: 0.18,
flatShading: true
});
const comMarker = new THREE.Group();
comMarker.position.copy(combinedCenter);
scene.add(comMarker);
const comCore = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 0),
comMaterial
);
comCore.castShadow = true;
comMarker.add(comCore);
const comRing = new THREE.Mesh(
new THREE.TorusGeometry(0.29, 0.018, 6, 18),
new THREE.MeshBasicMaterial({ color: 0xe8aa3b })
);
comRing.rotation.x = Math.PI / 2;
comMarker.add(comRing);
const crossMaterial = new THREE.LineBasicMaterial({
color: 0x9e6c16,
transparent: true,
opacity: 0.8
});
const crossGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(-0.34, 0, 0),
new THREE.Vector3(0.34, 0, 0),
new THREE.Vector3(0, 0, -0.34),
new THREE.Vector3(0, 0, 0.34)
]);
const comCross = new THREE.LineSegments(crossGeometry, crossMaterial);
comMarker.add(comCross);
const plumbLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(combinedCenterX, 0.045, 0),
new THREE.Vector3(combinedCenterX, 2.22, 0)
]),
new THREE.LineDashedMaterial({
color: 0xe0a038,
dashSize: 0.09,
gapSize: 0.065,
transparent: true,
opacity: 0.88
})
);
plumbLine.computeLineDistances();
scene.add(plumbLine);
const groundProjection = new THREE.Mesh(
new THREE.RingGeometry(0.11, 0.16, 18),
new THREE.MeshBasicMaterial({
color: 0xe8aa3b,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide
})
);
groundProjection.rotation.x = -Math.PI / 2;
groundProjection.position.set(combinedCenterX, 0.042, 0);
scene.add(groundProjection);
const deckProjection = new THREE.Mesh(
new THREE.RingGeometry(0.09, 0.13, 16),
new THREE.MeshBasicMaterial({
color: 0xe8aa3b,
transparent: true,
opacity: 0.9,
side: THREE.DoubleSide
})
);
deckProjection.rotation.x = -Math.PI / 2;
deckProjection.position.set(combinedCenterX, 1.126, 0);
scene.add(deckProjection);
// Direct camera controls: orbit, zoom, and preset views.
const target = new THREE.Vector3(0, 0.86, 0);
const desired = {
theta: 0.72,
phi: 1.03,
radius: 8.35
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
const view3dButton = document.querySelector("#view-3d");
const viewTopButton = document.querySelector("#view-top");
const resetButton = document.querySelector("#reset");
function setView(view) {
if (view === "top") {
desired.theta = 0;
desired.phi = 0.08;
desired.radius = 8.2;
viewTopButton.classList.add("active");
view3dButton.classList.remove("active");
} else {
desired.theta = 0.72;
desired.phi = 1.03;
desired.radius = 8.35;
view3dButton.classList.add("active");
viewTopButton.classList.remove("active");
}
}
view3dButton.addEventListener("click", () => setView("3d"));
viewTopButton.addEventListener("click", () => setView("top"));
resetButton.addEventListener("click", () => setView("3d"));
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= dx * 0.007;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.006,
0.08,
1.44
);
});
function stopDragging(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", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
4.7,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => setView("3d"));
const supportLabel = document.querySelector("#support-label");
const centerLabel = document.querySelector("#center-label");
const supportAnchor = new THREE.Vector3(1.48, 0.06, 0.83);
const centerAnchor = combinedCenter.clone().add(new THREE.Vector3(0, 0.26, 0));
function updateLabel(element, anchor) {
const projected = anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.classList.toggle("visible", visible);
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const spherical = new THREE.Spherical();
function animate() {
requestAnimationFrame(animate);
current.theta = THREE.MathUtils.lerp(current.theta, desired.theta, 0.10);
current.phi = THREE.MathUtils.lerp(current.phi, desired.phi, 0.10);
current.radius = THREE.MathUtils.lerp(current.radius, desired.radius, 0.10);
spherical.set(current.radius, current.phi, current.theta);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
updateLabel(supportLabel, supportAnchor);
updateLabel(centerLabel, centerAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```