Prompt specification
Build or customize the Three.js 3D scene "Three Proportion Variants Share One Pose" 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: Three Proportion Variants Share One Pose
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/three-proportion-variants-share-one-pose-x3698
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts character body proportions and recognizable silhouettes. Create three original characters with different proportions using the same joint hierarchy. Preserve contact with the floor and compare silhouettes from the same camera. Voxel style.
Working Three.js Starter (three-proportion-variants-share-one-pose-x3698):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Three Rigs — Voxel Proportions</title>
<style>
:root {
--ink: #eaf7ff;
--muted: #91a9b9;
--panel: rgba(7, 18, 27, 0.78);
--line: rgba(154, 211, 235, 0.18);
--cyan: #62e7d2;
--amber: #ffd166;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07121c;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#stage canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#stage canvas {
display: block;
touch-action: none;
outline: none;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
circle at 50% 42%,
transparent 38%,
rgba(1, 7, 12, 0.18) 100%
);
}
.glass {
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: fixed;
top: 18px;
left: 18px;
z-index: 5;
padding: 13px 16px 12px;
border-radius: 14px;
pointer-events: none;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand h1 {
margin: 4px 0 3px;
font-size: 20px;
line-height: 1;
letter-spacing: -0.035em;
}
.brand p {
margin: 0;
color: var(--muted);
font-size: 11px;
}
.toolbar {
position: fixed;
top: 18px;
right: 18px;
z-index: 7;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 7px;
max-width: min(520px, calc(100vw - 36px));
padding: 8px;
border-radius: 15px;
}
button {
appearance: none;
border: 1px solid rgba(167, 218, 239, 0.16);
border-radius: 9px;
padding: 9px 11px;
background: rgba(255, 255, 255, 0.045);
color: #dff6ff;
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.02em;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(98, 231, 210, 0.1);
border-color: rgba(98, 231, 210, 0.4);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
button.active {
color: #041310;
background: var(--cyan);
border-color: var(--cyan);
}
.info {
position: fixed;
right: 18px;
top: 82px;
z-index: 5;
width: 274px;
padding: 16px;
border-radius: 15px;
pointer-events: none;
}
.info-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.camera-badge {
color: var(--cyan);
letter-spacing: 0.08em;
}
.character-row {
display: grid;
grid-template-columns: 9px 1fr auto;
align-items: center;
gap: 9px;
padding: 9px 0;
border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.swatch {
width: 8px;
height: 22px;
border-radius: 3px;
box-shadow: 0 0 15px currentColor;
}
.character-row strong {
display: block;
font-size: 12px;
letter-spacing: 0.04em;
}
.character-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.height {
color: #dff8ff;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.rig-note {
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: var(--muted);
font-size: 9px;
line-height: 1.6;
}
.rig-note strong {
color: #d9f4ff;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.world-label {
position: absolute;
min-width: 104px;
padding: 6px 9px;
border: 1px solid rgba(160, 224, 245, 0.22);
border-radius: 8px;
background: rgba(4, 14, 22, 0.76);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
text-align: center;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
}
.world-label b {
display: block;
font-size: 10px;
letter-spacing: 0.16em;
}
.world-label span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.04em;
}
.hint {
position: fixed;
left: 18px;
bottom: 18px;
z-index: 6;
padding: 10px 13px;
border-radius: 11px;
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.hint b {
color: #dff6ff;
font-weight: 700;
}
.floor-badge {
position: fixed;
right: 18px;
bottom: 18px;
z-index: 6;
padding: 10px 13px;
border-radius: 11px;
color: var(--muted);
font-size: 10px;
pointer-events: none;
}
.floor-badge b {
color: var(--cyan);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--cyan);
background: #07121c;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@media (max-width: 900px) {
.info {
display: none;
}
.toolbar {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
max-width: none;
}
.hint,
.floor-badge {
display: none;
}
}
@media (max-width: 560px) {
.brand {
top: 10px;
left: 10px;
padding: 10px 12px;
}
.brand h1 {
font-size: 17px;
}
.brand p {
font-size: 9px;
}
.toolbar {
gap: 5px;
padding: 6px;
}
button {
padding: 8px 9px;
font-size: 9px;
}
.world-label {
min-width: 78px;
padding: 5px 6px;
}
.world-label b {
font-size: 8px;
}
.world-label span {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<div class="vignette"></div>
<div id="labels">
<div class="world-label" id="label-mote">
<b>MOTE</b>
<span>slim / long-limbed</span>
</div>
<div class="world-label" id="label-rook">
<b>ROOK</b>
<span>tall / narrow</span>
</div>
<div class="world-label" id="label-bram">
<b>BRAM</b>
<span>broad / big-head</span>
</div>
</div>
<header class="brand glass">
<div class="eyebrow">Voxel proportion study</div>
<h1>ONE RIG / THREE SILHOUETTES</h1>
<p>Identical joint order. Different body proportions.</p>
</header>
<nav class="toolbar glass" aria-label="Scene controls">
<button id="silhouetteBtn" aria-pressed="false">Compare silhouettes</button>
<button id="jointsBtn" aria-pressed="false">Show joints</button>
<button data-view="front">Front</button>
<button data-view="quarter" class="active">3/4</button>
<button data-view="side">Side</button>
<button id="resetBtn">Reset</button>
</nav>
<aside class="info glass">
<div class="info-title">
<span>Proportion set</span>
<span class="camera-badge">Shared camera</span>
</div>
<div class="character-row">
<i class="swatch" style="color:#2dd4bf;background:#2dd4bf"></i>
<div>
<strong>MOTE</strong>
<small>Slim shoulders · long legs</small>
</div>
<span class="height">6.92u</span>
</div>
<div class="character-row">
<i class="swatch" style="color:#6683ff;background:#6683ff"></i>
<div>
<strong>ROOK</strong>
<small>Long torso · narrow frame</small>
</div>
<span class="height">8.01u</span>
</div>
<div class="character-row">
<i class="swatch" style="color:#ff7a45;background:#ff7a45"></i>
<div>
<strong>BRAM</strong>
<small>Wide shoulders · large head</small>
</div>
<span class="height">6.86u</span>
</div>
<div class="rig-note">
<strong>Shared hierarchy</strong><br>
root → pelvis → spine → chest → neck → head<br>
chest → shoulder → elbow → wrist<br>
pelvis → hip → knee → ankle → foot
</div>
</aside>
<div class="hint glass">
<b>Drag</b> orbit · <b>Wheel</b> zoom · <b>Shift-drag</b> pan · <b>Double-click</b> reset
</div>
<div class="floor-badge glass">
<b>FOOT LOCK</b> · both soles at y = 0.00
</div>
<div id="loading">Building voxel rigs…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel character proportion comparison"
);
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07121c);
scene.fog = new THREE.Fog(0x07121c, 27, 48);
const camera = new THREE.OrthographicCamera(
-5,
5,
5,
-5,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 3.9, 0);
let azimuth = 0.43;
let elevation = 0.23;
let zoom = 1;
const hemisphere = new THREE.HemisphereLight(
0xc8efff,
0x111a20,
2.1
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.8);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7899ff, 1.35);
fillLight.position.set(6, 5, -6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0x58f0d6, 1.15);
rimLight.position.set(-4, 4, -5);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x0d1d28,
roughness: 0.96,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(
40,
40,
0x377083,
0x193744
);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.34;
scene.add(grid);
// Faint footprints make the floor-contact relationship easy to inspect.
const contactGroup = new THREE.Group();
const contactMaterial = new THREE.MeshBasicMaterial({
color: 0x5ce8d0,
transparent: true,
opacity: 0.12,
depthWrite: false
});
scene.add(contactGroup);
const silhouetteMaterial = new THREE.MeshBasicMaterial({
color: 0x020609
});
const jointMaterial = new THREE.MeshBasicMaterial({
color: 0xffd166,
depthTest: false,
depthWrite: false
});
const jointGeometry = new THREE.BoxGeometry(0.09, 0.09, 0.09);
// -------------------------------------------------------------------------
// Character configurations
//
// Every character uses exactly the same hierarchy. Only proportions,
// segment dimensions, colors, and small stance offsets differ.
// -------------------------------------------------------------------------
const characters = [
{
id: "mote",
name: "MOTE",
trait: "slim / long-limbed",
x: -2.65,
bodyColor: 0x2dd4bf,
skinColor: 0xf0bd8e,
bootColor: 0x173e46,
accentColor: 0xe9fff9,
pelvisH: 0.64,
pelvisW: 1.03,
torsoW: 1.23,
torsoH: 1.18,
chestH: 0.78,
shoulderW: 1.62,
chestDepth: 0.70,
bodyDepth: 0.67,
thigh: 1.45,
shin: 1.35,
hipSpacing: 0.60,
footH: 0.26,
footW: 0.46,
footDepth: 0.78,
upperArm: 1.13,
forearm: 1.02,
armW: 0.30,
armTilt: 0.095,
neckH: 0.28,
headW: 0.90,
headH: 0.98,
headDepth: 0.77
},
{
id: "rook",
name: "ROOK",
trait: "tall / narrow",
x: 0,
bodyColor: 0x6683ff,
skinColor: 0xc99168,
bootColor: 0x202c58,
accentColor: 0xdce6ff,
pelvisH: 0.62,
pelvisW: 0.94,
torsoW: 1.08,
torsoH: 1.45,
chestH: 0.95,
shoulderW: 1.76,
chestDepth: 0.65,
bodyDepth: 0.63,
thigh: 1.65,
shin: 1.60,
hipSpacing: 0.52,
footH: 0.26,
footW: 0.45,
footDepth: 0.77,
upperArm: 1.25,
forearm: 1.12,
armW: 0.28,
armTilt: 0.065,
neckH: 0.32,
headW: 0.76,
headH: 1.16,
headDepth: 0.72
},
{
id: "bram",
name: "BRAM",
trait: "broad / big-head",
x: 2.65,
bodyColor: 0xff7a45,
skinColor: 0xf5c59d,
bootColor: 0x352a32,
accentColor: 0xffdfb8,
pelvisH: 0.78,
pelvisW: 1.34,
torsoW: 1.73,
torsoH: 1.10,
chestH: 1.05,
shoulderW: 2.42,
chestDepth: 0.93,
bodyDepth: 0.84,
thigh: 1.02,
shin: 0.98,
hipSpacing: 0.88,
footH: 0.30,
footW: 0.60,
footDepth: 0.88,
upperArm: 0.88,
forearm: 0.80,
armW: 0.40,
armTilt: 0.135,
neckH: 0.28,
headW: 1.58,
headH: 1.35,
headDepth: 1.08
}
];
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function standardMaterial(color) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.76,
metalness: 0.015
});
}
function addBox(
parent,
dimensions,
position,
material,
name = "",
options = {}
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(
dimensions[0],
dimensions[1],
dimensions[2]
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.name = name;
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
mesh.userData.originalMaterial = material;
parent.add(mesh);
return mesh;
}
function addSegment(
parent,
length,
width,
depth,
material,
name
) {
// Joints sit at the top of each segment.
// The segment extends down from its local origin.
return addBox(
parent,
[width, length, depth],
[0, -length / 2, 0],
material,
name
);
}
function addJointMarker(group) {
const marker = new THREE.Mesh(
jointGeometry,
jointMaterial
);
marker.name = `${group.name}-marker`;
marker.castShadow = false;
marker.receiveShadow = false;
marker.renderOrder = 10;
marker.visible = showJoints;
marker.userData.originalMaterial = jointMaterial;
marker.userData.isJointMarker = true;
group.add(marker);
return marker;
}
let showJoints = false;
const characterRoots = [];
// -------------------------------------------------------------------------
// Shared voxel rig builder
// -------------------------------------------------------------------------
function buildCharacter(config) {
const bodyMaterial = standardMaterial(config.bodyColor);
const skinMaterial = standardMaterial(config.skinColor);
const bootMaterial = standardMaterial(config.bootColor);
const accentMaterial = standardMaterial(config.accentColor);
const eyeMaterial = new THREE.MeshBasicMaterial({
color: 0x071016
});
const root = new THREE.Group();
root.name = `${config.name}-RIG`;
root.position.x = config.x;
scene.add(root);
// Root -> pelvis
const pelvis = new THREE.Group();
pelvis.name = "pelvis";
// This equation guarantees that the bottom of both feet is at y = 0:
// pelvis center - half pelvis height - thigh - shin = foot height.
pelvis.position.y =
config.pelvisH / 2 +
config.thigh +
config.shin +
config.footH;
root.add(pelvis);
addBox(
pelvis,
[
config.pelvisW,
config.pelvisH,
config.bodyDepth * 0.88
],
[0, 0, 0],
bodyMaterial,
`${config.name}-pelvis-mesh`
);
addJointMarker(pelvis);
// Pelvis -> spine
const spine = new THREE.Group();
spine.name = "spine";
spine.position.y = config.pelvisH / 2;
pelvis.add(spine);
addBox(
spine,
[
config.torsoW,
config.torsoH,
config.bodyDepth
],
[0, config.torsoH / 2, 0],
bodyMaterial,
`${config.name}-torso-mesh`
);
addJointMarker(spine);
// Spine -> chest
const chest = new THREE.Group();
chest.name = "chest";
chest.position.y = config.torsoH;
spine.add(chest);
addBox(
chest,
[
config.shoulderW,
config.chestH,
config.chestDepth
],
[0, config.chestH / 2, 0],
bodyMaterial,
`${config.name}-chest-mesh`
);
// Flat chest inset, attached directly to the chest joint.
addBox(
chest,
[config.torsoW * 0.48, 0.34, 0.035],
[0, config.chestH * 0.48, config.chestDepth / 2 + 0.018],
accentMaterial,
`${config.name}-chest-inset`,
{ castShadow: false }
);
addJointMarker(chest);
// Chest -> neck -> head
const neck = new THREE.Group();
neck.name = "neck";
neck.position.y = config.chestH;
chest.add(neck);
addBox(
neck,
[0.31, config.neckH, 0.31],
[0, config.neckH / 2, 0],
skinMaterial,
`${config.name}-neck-mesh`
);
addJointMarker(neck);
const head = new THREE.Group();
head.name = "head";
head.position.y = config.neckH;
neck.add(head);
addBox(
head,
[
config.headW,
config.headH,
config.headDepth
],
[0, config.headH / 2, 0],
skinMaterial,
`${config.name}-head-mesh`
);
const eyeY = config.headH * 0.62;
const eyeX = config.headW * 0.22;
const eyeSize = Math.min(0.13, config.headW * 0.15);
for (const side of [-1, 1]) {
addBox(
head,
[eyeSize, eyeSize * 1.12, 0.035],
[
side * eyeX,
eyeY,
config.headDepth / 2 + 0.019
],
eyeMaterial,
`${config.name}-eye`,
{ castShadow: false }
);
}
addBox(
head,
[
config.headW * 0.25,
0.055,
0.035
],
[
0,
config.headH * 0.30,
config.headDepth / 2 + 0.019
],
eyeMaterial,
`${config.name}-mouth`,
{ castShadow: false }
);
addJointMarker(head);
// Chest -> shoulder -> elbow -> wrist
for (const side of [-1, 1]) {
const suffix = side < 0 ? "L" : "R";
const shoulder = new THREE.Group();
shoulder.name = `shoulder-${suffix}`;
shoulder.position.set(
side * (config.shoulderW / 2 - config.armW / 2),
config.chestH * 0.72,
0
);
shoulder.rotation.z = side * config.armTilt;
chest.add(shoulder);
addSegment(
shoulder,
config.upperArm,
config.armW,
config.armW,
bodyMaterial,
`${config.name}-upper-arm-${suffix}`
);
addJointMarker(shoulder);
const elbow = new THREE.Group();
elbow.name = `elbow-${suffix}`;
elbow.position.y = -config.upperArm;
// Slightly relax the forearm back toward the body.
elbow.rotation.z = -side * 0.045;
shoulder.add(elbow);
addSegment(
elbow,
config.forearm,
config.armW * 0.94,
config.armW * 0.94,
skinMaterial,
`${config.name}-forearm-${suffix}`
);
addJointMarker(elbow);
const wrist = new THREE.Group();
wrist.name = `wrist-${suffix}`;
wrist.position.y = -config.forearm;
elbow.add(wrist);
const handH = config.armW * 1.16;
addBox(
wrist,
[
config.armW * 1.04,
handH,
config.armW * 1.08
],
[0, -handH / 2, 0],
skinMaterial,
`${config.name}-hand-${suffix}`
);
addJointMarker(wrist);
}
// Pelvis -> hip -> knee -> ankle -> foot
for (const side of [-1, 1]) {
const suffix = side < 0 ? "L" : "R";
const hip = new THREE.Group();
hip.name = `hip-${suffix}`;
hip.position.set(
side * config.hipSpacing / 2,
-config.pelvisH / 2,
0
);
pelvis.add(hip);
addSegment(
hip,
config.thigh,
config.armW * 1.42,
config.armW * 1.42,
bodyMaterial,
`${config.name}-thigh-${suffix}`
);
addJointMarker(hip);
const knee = new THREE.Group();
knee.name = `knee-${suffix}`;
knee.position.y = -config.thigh;
hip.add(knee);
addSegment(
knee,
config.shin,
config.armW * 1.28,
config.armW * 1.28,
bodyMaterial,
`${config.name}-shin-${suffix}`
);
addJointMarker(knee);
const ankle = new THREE.Group();
ankle.name = `ankle-${suffix}`;
ankle.position.y = -config.shin;
knee.add(ankle);
const footCenterZ = config.footDepth * 0.13;
addBox(
ankle,
[
config.footW,
config.footH,
config.footDepth
],
[
0,
-config.footH / 2,
footCenterZ
],
bootMaterial,
`${config.name}-foot-${suffix}`
);
addJointMarker(ankle);
// Separate floor marker, aligned with each sole.
const footprint = addBox(
contactGroup,
[
config.footW + 0.16,
0.012,
config.footDepth + 0.12
],
[
config.x + side * config.hipSpacing / 2,
0.007,
footCenterZ
],
contactMaterial,
`${config.name}-footprint-${suffix}`,
{
castShadow: false,
receiveShadow: false
}
);
footprint.renderOrder = 1;
}
const height =
config.pelvisH +
config.thigh +
config.shin +
config.footH +
config.torsoH +
config.chestH +
config.neckH +
config.headH;
root.userData.config = config;
root.userData.height = height;
root.userData.pelvis = pelvis;
characterRoots.push(root);
return root;
}
characters.forEach(buildCharacter);
// -------------------------------------------------------------------------
// Mode controls
// -------------------------------------------------------------------------
const silhouetteBtn = document.getElementById("silhouetteBtn");
const jointsBtn = document.getElementById("jointsBtn");
const resetBtn = document.getElementById("resetBtn");
let silhouetteMode = false;
function updateJointMarkers() {
for (const root of characterRoots) {
root.traverse((object) => {
if (object.userData.isJointMarker) {
object.visible = showJoints && !silhouetteMode;
}
});
}
}
function setSilhouette(enabled) {
silhouetteMode = enabled;
for (const root of characterRoots) {
root.traverse((object) => {
if (!object.isMesh || object.userData.isJointMarker) {
return;
}
object.material = enabled
? silhouetteMaterial
: object.userData.originalMaterial;
});
}
if (enabled) {
scene.background.set(0xe9eef1);
scene.fog.color.set(0xe9eef1);
floorMaterial.color.set(0xd5dde1);
grid.material.opacity = 0.12;
contactGroup.visible = false;
} else {
scene.background.set(0x07121c);
scene.fog.color.set(0x07121c);
floorMaterial.color.set(0x0d1d28);
grid.material.opacity = 0.34;
contactGroup.visible = true;
}
silhouetteBtn.classList.toggle("active", enabled);
silhouetteBtn.setAttribute("aria-pressed", String(enabled));
silhouetteBtn.textContent = enabled
? "Return to voxel"
: "Compare silhouettes";
updateJointMarkers();
}
function setJoints(enabled) {
showJoints = enabled;
jointsBtn.classList.toggle("active", enabled);
jointsBtn.setAttribute("aria-pressed", String(enabled));
updateJointMarkers();
}
silhouetteBtn.addEventListener("click", () => {
setSilhouette(!silhouetteMode);
});
jointsBtn.addEventListener("click", () => {
setJoints(!showJoints);
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, zoom, and presets
// -------------------------------------------------------------------------
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
// Keep all three figures inside the narrowest viewport.
const viewHeight = Math.max(8.8, 8.5 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.zoom = zoom;
camera.updateProjectionMatrix();
}
function updateCamera() {
const horizontalRadius = 18 * Math.cos(elevation);
camera.position.set(
cameraTarget.x + horizontalRadius * Math.sin(azimuth),
cameraTarget.y + 18 * Math.sin(elevation),
cameraTarget.z + horizontalRadius * Math.cos(azimuth)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
function setView(name) {
if (name === "front") {
azimuth = 0;
elevation = 0.09;
} else if (name === "side") {
azimuth = Math.PI / 2;
elevation = 0.16;
} else {
azimuth = 0.43;
elevation = 0.23;
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle(
"active",
button.dataset.view === name
);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
function resetView() {
cameraTarget.set(0, 3.9, 0);
zoom = 1;
updateProjection();
setView("quarter");
}
resetBtn.addEventListener("click", resetView);
const canvas = renderer.domElement;
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
if (event.shiftKey) {
const panScale = 0.012 / zoom;
const right = new THREE.Vector3(
Math.cos(azimuth),
0,
-Math.sin(azimuth)
);
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.y += dy * panScale;
} else {
azimuth -= dx * 0.006;
elevation = THREE.MathUtils.clamp(
elevation + dy * 0.005,
0.045,
0.90
);
}
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.style.cursor = "grab";
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoom = THREE.MathUtils.clamp(
zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.65
);
updateProjection();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "1") setView("front");
if (event.key === "2") setView("quarter");
if (event.key === "3") setView("side");
if (event.key.toLowerCase() === "s") {
setSilhouette(!silhouetteMode);
}
if (event.key.toLowerCase() === "j") {
setJoints(!showJoints);
}
});
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateProjection();
});
// -------------------------------------------------------------------------
// Project character labels using the same camera as the scene
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
for (const config of characters) {
const label = document.getElementById(`label-${config.id}`);
const root = characterRoots.find(
(character) => character.userData.config.id === config.id
);
projected.set(
config.x,
root.userData.height + 0.23,
0
);
projected.project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
Math.abs(projected.x) < 1.15 &&
Math.abs(projected.y) < 1.15;
label.style.opacity = visible ? "1" : "0";
label.style.left =
`${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
label.style.top =
`${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
updateProjection();
updateCamera();
function animate() {
requestAnimationFrame(animate);
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
animate();
document.getElementById("loading")?.remove();
</script>
</body>
</html>
```