Prompt specification
Build or customize the Three.js 3D scene "Original Character Proportion Mannequin" 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: Original Character Proportion Mannequin
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/original-character-proportion-mannequin-x3697
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing character body proportions and recognizable silhouettes. Model an original stylized mannequin with clearly separated head, torso, pelvis, and limbs. Show neutral proportions and readable joint locations without claiming anatomical realism. Stylized solid forms.
Working Three.js Starter (original-character-proportion-mannequin-x3697):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form 01 — Stylized Proportion Mannequin</title>
<style>
:root {
--ink: #263238;
--muted: #647177;
--paper: rgba(244, 241, 233, 0.88);
--line: rgba(38, 50, 56, 0.16);
--accent: #d47f45;
--teal: #5d8984;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8e4da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app {
position: relative;
width: 100%;
height: 100%;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: absolute;
z-index: 10;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.62);
box-shadow: 0 14px 42px rgba(46, 53, 55, 0.12);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-panel {
top: 24px;
left: 24px;
width: min(360px, calc(100vw - 48px));
padding: 18px 20px 16px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
content: "";
background: var(--accent);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.status-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 14px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.status-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(93, 137, 132, 0.13);
}
.control-panel {
top: 24px;
right: 24px;
width: 248px;
padding: 15px;
}
.control-label {
margin: 0 0 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.button-grid {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-bottom: 14px;
}
button {
min-height: 34px;
padding: 7px 8px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.52);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(38, 50, 56, 0.38);
background: rgba(255, 255, 255, 0.9);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
button.active {
border-color: var(--ink);
background: var(--ink);
color: #f7f4ec;
}
.toggle-row {
display: flex;
gap: 6px;
}
.toggle-row button {
flex: 1;
}
.control-help {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.55;
}
.legend-panel {
bottom: 24px;
left: 24px;
padding: 14px 16px;
pointer-events: none;
}
.legend-items {
display: flex;
flex-wrap: wrap;
gap: 9px 16px;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #4c595e;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
border: 1px solid rgba(38, 50, 56, 0.12);
}
.metrics-panel {
right: 24px;
bottom: 24px;
width: 248px;
padding: 15px;
pointer-events: none;
}
.metric {
display: flex;
align-items: baseline;
justify-content: space-between;
padding: 7px 0;
border-bottom: 1px solid var(--line);
}
.metric:last-child {
border-bottom: 0;
padding-bottom: 0;
}
.metric-name {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
font-size: 13px;
font-weight: 800;
}
.disclaimer {
margin: 11px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.center-hint {
position: absolute;
left: 50%;
bottom: 27px;
z-index: 5;
padding: 7px 11px;
border: 1px solid rgba(38, 50, 56, 0.11);
border-radius: 999px;
background: rgba(244, 241, 233, 0.68);
color: rgba(38, 50, 56, 0.65);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translateX(-50%);
pointer-events: none;
white-space: nowrap;
}
@media (max-width: 820px) {
.title-panel {
top: 14px;
left: 14px;
width: 260px;
padding: 14px;
}
.title-panel .subtitle {
display: none;
}
.control-panel {
top: 14px;
right: 14px;
width: 218px;
}
.metrics-panel,
.center-hint {
display: none;
}
.legend-panel {
bottom: 14px;
left: 14px;
}
}
@media (max-width: 540px) {
.title-panel {
width: calc(100vw - 28px);
}
.control-panel {
top: auto;
right: 14px;
bottom: 14px;
width: calc(100vw - 28px);
}
.legend-panel {
display: none;
}
}
</style>
</head>
<body>
<main id="app">
<header class="panel title-panel">
<div class="eyebrow">Form Study / 01</div>
<h1>Proportion<br>Mannequin</h1>
<p class="subtitle">
An original segmented figure built from simplified solid forms for
readable proportions, joint placement, and silhouette exploration.
</p>
<div class="status-row">
<span class="status-dot"></span>
<span id="view-status">Three-quarter view</span>
</div>
</header>
<aside class="panel control-panel" aria-label="Model controls">
<p class="control-label">Camera Views</p>
<div class="button-grid">
<button type="button" data-view="front">Front</button>
<button type="button" data-view="three" class="active">3/4</button>
<button type="button" data-view="side">Side</button>
<button type="button" data-view="rear">Rear</button>
</div>
<p class="control-label">Display</p>
<div class="toggle-row">
<button type="button" id="joint-toggle" aria-pressed="true">
Joints ON
</button>
<button type="button" id="guide-toggle" aria-pressed="true">
Guides ON
</button>
<button type="button" id="reset-view">Reset</button>
</div>
<p class="control-help">
Drag to orbit · Wheel or pinch to zoom<br>
Arrow keys rotate · + / − zoom · R resets
</p>
</aside>
<aside class="panel legend-panel" aria-label="Color legend">
<div class="legend-items">
<div class="legend-item">
<span class="swatch" style="background:#5d8984"></span>
Torso
</div>
<div class="legend-item">
<span class="swatch" style="background:#3c5262"></span>
Pelvis
</div>
<div class="legend-item">
<span class="swatch" style="background:#d8d1c2"></span>
Limbs
</div>
<div class="legend-item">
<span class="swatch" style="background:#efeadc"></span>
Head
</div>
<div class="legend-item">
<span class="swatch" style="background:#e39450"></span>
Joints
</div>
</div>
</aside>
<aside class="panel metrics-panel" aria-label="Model dimensions">
<p class="control-label">Design Values</p>
<div class="metric">
<span class="metric-name">Figure height</span>
<span class="metric-value">5.9 u</span>
</div>
<div class="metric">
<span class="metric-name">Head height</span>
<span class="metric-value">1.05 u</span>
</div>
<div class="metric">
<span class="metric-name">Shoulder span</span>
<span class="metric-value">2.45 u</span>
</div>
<div class="metric">
<span class="metric-name">Joint markers</span>
<span class="metric-value">12</span>
</div>
<p class="disclaimer">
Model-space design values only. This is an abstract construction,
not an anatomical or ergonomic reference.
</p>
</aside>
<div class="center-hint">Drag to inspect the silhouette</div>
</main>
<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 viewStatus = document.querySelector("#view-status");
const viewButtons = [...document.querySelectorAll("[data-view]")];
// ---------------------------------------------------------------------
// Renderer and orthographic study camera
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8e4da);
scene.fog = new THREE.Fog(0xe8e4da, 13, 26);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive stylized mannequin. Drag to rotate and use the controls to change views."
);
renderer.domElement.tabIndex = 0;
app.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-4, 4, 3.6, -3.6, 0.1, 100);
const cameraState = {
theta: 0.52,
phi: 0.12,
zoom: 1,
targetTheta: 0.52,
targetPhi: 0.12,
targetZoom: 1
};
const cameraTarget = new THREE.Vector3(0, 2.9, 0);
const cameraRadius = 12;
const viewHeight = 7.2;
function resizeRenderer() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
function shortestAngleDelta(from, to) {
let delta = (to - from + Math.PI) % (Math.PI * 2);
if (delta < 0) delta += Math.PI * 2;
return delta - Math.PI;
}
function updateCamera() {
const horizontal = cameraRadius * Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraState.theta),
cameraTarget.y + cameraRadius * Math.sin(cameraState.phi),
cameraTarget.z + horizontal * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
// ---------------------------------------------------------------------
// Lighting and ground
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfffbf2, 0x687378, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3df, 3.15);
keyLight.position.set(5, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9e0e3, 1.2);
fillLight.position.set(-5, 4, -4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffffff, 1.45);
rimLight.position.set(1, 6, -6);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d5cb,
roughness: 1,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.075;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(3.05, 3.12, 0.12, 64),
new THREE.MeshStandardMaterial({
color: 0xe4dfd4,
roughness: 0.9
})
);
platform.position.y = -0.06;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const grid = new THREE.GridHelper(14, 28, 0x768985, 0xa5aaa6);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.2;
scene.add(grid);
// ---------------------------------------------------------------------
// Stylized solid-form mannequin
// ---------------------------------------------------------------------
const body = new THREE.Group();
body.name = "Stylized proportion mannequin";
scene.add(body);
const materials = {
head: new THREE.MeshStandardMaterial({
color: 0xefeadd,
roughness: 0.7,
metalness: 0.01,
flatShading: false
}),
torso: new THREE.MeshStandardMaterial({
color: 0x5d8984,
roughness: 0.68,
metalness: 0.02,
flatShading: true
}),
pelvis: new THREE.MeshStandardMaterial({
color: 0x3c5262,
roughness: 0.72,
metalness: 0.02,
flatShading: true
}),
limb: new THREE.MeshStandardMaterial({
color: 0xd8d1c2,
roughness: 0.76,
metalness: 0.01,
flatShading: true
}),
joint: new THREE.MeshStandardMaterial({
color: 0xe39450,
emissive: 0x4d1f08,
emissiveIntensity: 0.12,
roughness: 0.56,
metalness: 0.02,
flatShading: true
}),
face: new THREE.MeshStandardMaterial({
color: 0x263238,
roughness: 0.72,
flatShading: true
})
};
const jointGroup = new THREE.Group();
jointGroup.name = "Readable joint markers";
body.add(jointGroup);
function addMesh(geometry, material, parent = body) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Creates a lofted solid from stacked rectangular/oval cross-sections.
function loftGeometry(sections, radialSegments = 16) {
const positions = [];
const indices = [];
sections.forEach((section) => {
const { y, width, depth, z = 0 } = section;
for (let i = 0; i < radialSegments; i++) {
const angle = (i / radialSegments) * Math.PI * 2;
positions.push(
Math.cos(angle) * width,
y,
z + Math.sin(angle) * depth
);
}
});
for (let ring = 0; ring < sections.length - 1; ring++) {
for (let i = 0; i < radialSegments; i++) {
const next = (i + 1) % radialSegments;
const a = ring * radialSegments + i;
const b = ring * radialSegments + next;
const c = (ring + 1) * radialSegments + next;
const d = (ring + 1) * radialSegments + i;
indices.push(a, d, b);
indices.push(b, d, c);
}
}
const bottomCenter = positions.length / 3;
positions.push(0, sections[0].y, sections[0].z || 0);
const topCenter = positions.length / 3;
const topSection = sections[sections.length - 1];
positions.push(0, topSection.y, topSection.z || 0);
for (let i = 0; i < radialSegments; i++) {
const next = (i + 1) % radialSegments;
indices.push(bottomCenter, i, next);
indices.push(
topCenter,
(sections.length - 1) * radialSegments + next,
(sections.length - 1) * radialSegments + i
);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function addSegment(start, end, radiusStart, radiusEnd, material, parent = body) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusStart,
radiusEnd,
length,
12,
1,
false
);
const mesh = addMesh(geometry, material, parent);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function addJoint(position, radius = 0.16) {
const marker = addMesh(
new THREE.SphereGeometry(radius, 14, 10),
materials.joint,
jointGroup
);
marker.position.copy(position);
return marker;
}
// Torso: broad shoulder line, tapered waist, compact chest.
const torsoGeometry = loftGeometry([
{ y: 3.13, width: 0.50, depth: 0.29 },
{ y: 3.25, width: 0.66, depth: 0.35 },
{ y: 3.62, width: 0.61, depth: 0.32 },
{ y: 4.20, width: 0.73, depth: 0.34 },
{ y: 4.58, width: 1.00, depth: 0.31 },
{ y: 4.79, width: 0.90, depth: 0.26 }
]);
addMesh(torsoGeometry, materials.torso);
// Pelvis: separate, low, trapezoid-like solid.
const pelvisGeometry = loftGeometry([
{ y: 2.42, width: 0.58, depth: 0.30 },
{ y: 2.63, width: 0.73, depth: 0.35 },
{ y: 2.87, width: 0.68, depth: 0.32 },
{ y: 3.02, width: 0.53, depth: 0.28 }
]);
addMesh(pelvisGeometry, materials.pelvis);
// Dark waist band makes the torso/pelvis segmentation explicit.
addSegment(
new THREE.Vector3(0, 2.97, 0),
new THREE.Vector3(0, 3.19, 0),
0.43,
0.43,
materials.pelvis
);
// Neck and head remain independent forms.
addSegment(
new THREE.Vector3(0, 4.72, 0),
new THREE.Vector3(0, 5.03, 0),
0.18,
0.17,
materials.pelvis
);
const head = addMesh(
new THREE.SphereGeometry(1, 28, 20),
materials.head
);
head.position.set(0, 5.37, 0);
head.scale.set(0.40, 0.52, 0.38);
// Minimal face planes preserve a readable character silhouette.
const nose = addMesh(
new THREE.ConeGeometry(0.07, 0.18, 3),
materials.head
);
nose.position.set(0, 5.37, 0.385);
nose.rotation.x = Math.PI / 2;
for (const side of [-1, 1]) {
const eye = addMesh(
new THREE.SphereGeometry(0.034, 10, 8),
materials.face
);
eye.position.set(side * 0.12, 5.47, 0.354);
eye.scale.set(1, 0.7, 0.45);
const ear = addMesh(
new THREE.SphereGeometry(1, 14, 10),
materials.head
);
ear.position.set(side * 0.39, 5.36, -0.005);
ear.scale.set(0.085, 0.13, 0.10);
}
const mouth = addMesh(
new THREE.BoxGeometry(0.11, 0.018, 0.025),
materials.face
);
mouth.position.set(0, 5.24, 0.359);
// Arms are held slightly away from the torso to preserve silhouette.
for (const side of [-1, 1]) {
const shoulder = new THREE.Vector3(side * 1.04, 4.55, 0.16);
const elbow = new THREE.Vector3(side * 1.35, 3.14, 0.08);
const wrist = new THREE.Vector3(side * 1.49, 1.84, 0.06);
addSegment(shoulder, elbow, 0.18, 0.145, materials.limb);
addSegment(elbow, wrist, 0.14, 0.105, materials.limb);
addJoint(shoulder, 0.19);
addJoint(elbow, 0.145);
addJoint(wrist, 0.105);
const handDirection = new THREE.Vector3()
.subVectors(wrist, elbow)
.normalize();
const hand = addMesh(
new THREE.SphereGeometry(1, 16, 10),
materials.limb
);
hand.position.copy(wrist).addScaledVector(handDirection, 0.16);
hand.scale.set(0.13, 0.24, 0.10);
hand.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
handDirection
);
}
// Legs use a restrained neutral stance.
for (const side of [-1, 1]) {
const hip = new THREE.Vector3(side * 0.43, 2.76, 0.18);
const knee = new THREE.Vector3(side * 0.46, 1.45, 0.08);
const ankle = new THREE.Vector3(side * 0.47, 0.28, 0.04);
addSegment(hip, knee, 0.25, 0.18, materials.limb);
addSegment(knee, ankle, 0.18, 0.12, materials.limb);
addJoint(hip, 0.18);
addJoint(knee, 0.17);
addJoint(ankle, 0.115);
const foot = addMesh(
new THREE.BoxGeometry(0.45, 0.20, 0.76),
materials.limb
);
foot.position.set(side * 0.47, 0.11, 0.18);
const sole = addMesh(
new THREE.BoxGeometry(0.47, 0.055, 0.78),
materials.pelvis
);
sole.position.set(side * 0.47, 0.025, 0.18);
}
// ---------------------------------------------------------------------
// Proportion guides
// ---------------------------------------------------------------------
const guidePositions = [];
function guideLine(x1, y1, x2, y2) {
guidePositions.push(x1, y1, 0, x2, y2, 0);
}
const guideX = -1.82;
guideLine(guideX, 0, guideX, 5.92);
guideLine(guideX, 5.92, -0.42, 5.92);
guideLine(guideX, 0, -0.66, 0);
const guideLevels = [
0.28,
1.45,
2.76,
3.10,
4.55,
4.84,
5.92
];
guideLevels.forEach((level) => {
guideLine(guideX, level, -0.62, level);
});
const guideGeometry = new THREE.BufferGeometry();
guideGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(guidePositions, 3)
);
const guides = new THREE.LineSegments(
guideGeometry,
new THREE.LineBasicMaterial({
color: 0x517b78,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
guides.name = "Proportion guide lines";
scene.add(guides);
// ---------------------------------------------------------------------
// Direct camera controls: pointer, touch, wheel, keyboard
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function clamp(value, min, max) {
return Math.max(min, Math.min(max, value));
}
function setCustomView() {
viewStatus.textContent = "Custom view";
viewButtons.forEach((button) => button.classList.remove("active"));
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= deltaX * 0.006;
cameraState.phi = clamp(
cameraState.phi + deltaY * 0.005,
0.03,
0.68
);
cameraState.targetTheta = cameraState.theta;
cameraState.targetPhi = cameraState.phi;
setCustomView();
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (
event &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.targetZoom = clamp(
cameraState.targetZoom * Math.exp(-event.deltaY * 0.001),
0.68,
2.1
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function selectView(name) {
const presets = {
front: { theta: 0, phi: 0.055, label: "Front view" },
three: { theta: 0.52, phi: 0.12, label: "Three-quarter view" },
side: { theta: Math.PI / 2, phi: 0.055, label: "Side view" },
rear: { theta: Math.PI, phi: 0.055, label: "Rear view" }
};
const preset = presets[name];
if (!preset) return;
cameraState.targetTheta = preset.theta;
cameraState.targetPhi = preset.phi;
cameraState.targetZoom = 1;
viewStatus.textContent = preset.label;
viewButtons.forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
function resetView() {
selectView("three");
}
viewButtons.forEach((button) => {
button.addEventListener("click", () => {
selectView(button.dataset.view);
});
});
document.querySelector("#reset-view").addEventListener("click", resetView);
const jointToggle = document.querySelector("#joint-toggle");
jointToggle.addEventListener("click", () => {
jointGroup.visible = !jointGroup.visible;
jointToggle.textContent = jointGroup.visible ? "Joints ON" : "Joints OFF";
jointToggle.setAttribute("aria-pressed", String(jointGroup.visible));
jointToggle.classList.toggle("active", jointGroup.visible);
});
const guideToggle = document.querySelector("#guide-toggle");
guideToggle.addEventListener("click", () => {
guides.visible = !guides.visible;
guideToggle.textContent = guides.visible ? "Guides ON" : "Guides OFF";
guideToggle.setAttribute("aria-pressed", String(guides.visible));
guideToggle.classList.toggle("active", guides.visible);
});
jointToggle.classList.add("active");
guideToggle.classList.add("active");
window.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "r") {
resetView();
} else if (key === "j") {
jointToggle.click();
} else if (key === "g") {
guideToggle.click();
} else if (key === "1") {
selectView("front");
} else if (key === "2") {
selectView("three");
} else if (key === "3") {
selectView("side");
} else if (key === "4") {
selectView("rear");
} else if (key === "arrowleft") {
event.preventDefault();
cameraState.targetTheta -= 0.12;
setCustomView();
} else if (key === "arrowright") {
event.preventDefault();
cameraState.targetTheta += 0.12;
setCustomView();
} else if (key === "arrowup") {
event.preventDefault();
cameraState.targetPhi = clamp(cameraState.targetPhi - 0.07, 0.03, 0.68);
setCustomView();
} else if (key === "arrowdown") {
event.preventDefault();
cameraState.targetPhi = clamp(cameraState.targetPhi + 0.07, 0.03, 0.68);
setCustomView();
} else if (key === "+" || key === "=") {
cameraState.targetZoom = clamp(cameraState.targetZoom + 0.08, 0.68, 2.1);
} else if (key === "-" || key === "_") {
cameraState.targetZoom = clamp(cameraState.targetZoom - 0.08, 0.68, 2.1);
}
});
// ---------------------------------------------------------------------
// Animation and resize
// ---------------------------------------------------------------------
function animate() {
cameraState.theta +=
shortestAngleDelta(cameraState.theta, cameraState.targetTheta) * 0.14;
cameraState.phi +=
(cameraState.targetPhi - cameraState.phi) * 0.14;
cameraState.zoom +=
(cameraState.targetZoom - cameraState.zoom) * 0.14;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", resizeRenderer);
resizeRenderer();
updateCamera();
animate();
</script>
</body>
</html>
```