Prompt specification
Build or customize the Three.js 3D scene "Single-leg and two-leg stance comparison" 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: Single-leg and two-leg stance comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/single-leg-and-two-leg-stance-comparison-x0998
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing human stance and hip balance. Place matched stylized figures in two stances and show their support polygons; distinguish static geometry from the active muscular control required in living balance. A 3D cutaway view.
Working Three.js Starter (single-leg-and-two-leg-stance-comparison-x0998):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Human Stance & Hip Balance — 3D Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: rgba(10, 20, 31, 0.86);
--line: rgba(174, 220, 239, 0.16);
--text: #edf7fb;
--muted: #91a8b5;
--cyan: #69dcff;
--coral: #ff6f73;
--amber: #ffd166;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active { cursor: grabbing; }
.topbar {
position: fixed;
inset: 0 0 auto 0;
z-index: 5;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 22px;
padding: 24px 28px;
pointer-events: none;
background: linear-gradient(180deg, rgba(4, 10, 17, .92), transparent);
}
.brand {
max-width: 590px;
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: .18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(105, 220, 255, .7);
}
h1 {
margin: 0;
font-size: clamp(26px, 3vw, 45px);
line-height: 1.02;
letter-spacing: -.045em;
font-weight: 690;
}
.intro {
max-width: 550px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
background: var(--panel);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
box-shadow: 0 18px 60px rgba(0, 0, 0, .22);
}
.control-panel {
width: 292px;
flex: 0 0 auto;
border-radius: 14px;
padding: 13px;
pointer-events: auto;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
}
.control-title {
color: #d9e8ee;
font-size: 10px;
font-weight: 750;
letter-spacing: .14em;
text-transform: uppercase;
}
.views {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 11px;
}
.view-button, .toggle {
border: 1px solid rgba(164, 214, 234, .16);
border-radius: 8px;
color: #b9cbd3;
background: rgba(255, 255, 255, .035);
cursor: pointer;
transition: .18s ease;
}
.view-button {
min-height: 30px;
padding: 6px 7px;
font-size: 10px;
font-weight: 650;
}
.view-button:hover,
.toggle:hover {
color: white;
border-color: rgba(105, 220, 255, .42);
background: rgba(105, 220, 255, .08);
}
.toggles {
display: grid;
gap: 7px;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
padding: 7px 9px;
font-size: 11px;
}
.toggle-label {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px currentColor;
}
.swatch.coral { background: var(--coral); }
.swatch.amber { background: var(--amber); }
.check {
width: 14px;
height: 14px;
accent-color: var(--cyan);
}
.legend {
position: fixed;
z-index: 4;
top: 174px;
left: 28px;
display: grid;
gap: 8px;
padding: 11px 13px;
border-radius: 11px;
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #b9cbd3;
font-size: 10px;
white-space: nowrap;
}
.legend-row strong {
color: #eff9fc;
font-weight: 650;
}
.floating-label {
position: fixed;
z-index: 3;
width: 190px;
padding: 10px 12px;
border-radius: 10px;
transform: translate(-50%, -50%);
pointer-events: none;
opacity: 0;
transition: opacity .15s ease;
}
.floating-label.visible { opacity: 1; }
.floating-label .kicker {
display: block;
margin-bottom: 4px;
color: var(--cyan);
font-size: 8px;
font-weight: 800;
letter-spacing: .15em;
text-transform: uppercase;
}
.floating-label strong {
display: block;
font-size: 13px;
letter-spacing: -.01em;
}
.floating-label small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.callout {
position: fixed;
z-index: 3;
transform: translate(-50%, -50%);
padding: 6px 9px;
border: 1px solid currentColor;
border-radius: 999px;
background: rgba(7, 16, 25, .78);
color: var(--cyan);
font-size: 8px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
opacity: 0;
}
.callout.visible { opacity: 1; }
.callout.active { color: var(--coral); }
.summary {
position: fixed;
z-index: 5;
left: 28px;
right: 28px;
bottom: 22px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
max-width: 760px;
margin: 0 auto;
pointer-events: none;
}
.summary article {
min-height: 92px;
padding: 13px 15px;
border-radius: 13px;
}
.summary .number {
float: left;
margin-right: 12px;
color: var(--cyan);
font-size: 24px;
font-weight: 300;
line-height: 1;
}
.summary article:nth-child(2) .number { color: var(--coral); }
.summary h2 {
margin: 0 0 4px;
font-size: 13px;
font-weight: 700;
}
.summary p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.view-hint {
position: fixed;
z-index: 4;
right: 29px;
bottom: 28px;
color: rgba(183, 210, 220, .63);
font-size: 9px;
letter-spacing: .06em;
pointer-events: none;
}
.view-hint span {
color: var(--cyan);
margin-right: 5px;
}
@media (max-width: 900px) {
.control-panel { width: 250px; }
.legend { top: 166px; }
.view-hint { display: none; }
}
@media (max-width: 700px) {
.topbar {
padding: 17px;
display: block;
}
.intro { display: none; }
h1 { max-width: 320px; font-size: 28px; }
.control-panel {
position: fixed;
top: 108px;
right: 13px;
width: 218px;
padding: 9px;
}
.control-head { margin-bottom: 7px; }
.views { margin-bottom: 7px; }
.toggle { padding: 5px 7px; font-size: 9px; }
.legend, .floating-label, .callout { display: none; }
.summary {
left: 13px;
right: 13px;
bottom: 13px;
gap: 7px;
}
.summary article {
min-height: 82px;
padding: 10px;
}
.summary .number {
font-size: 19px;
margin-right: 8px;
}
.summary h2 { font-size: 11px; }
.summary p { font-size: 8px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D comparison of bilateral and single-leg human balance"></canvas>
<header class="topbar">
<div class="brand">
<div class="eyebrow">3D anatomical cutaway · biomechanics</div>
<h1>Static geometry. Living control.</h1>
<p class="intro">
Matched figures reveal how the support area sets the mechanical limit,
while sensory feedback and active muscle torque keep the body balanced.
</p>
</div>
<div class="control-panel panel">
<div class="control-head">
<span class="control-title">View & layers</span>
<span class="control-title" style="color:var(--muted)">Drag to rotate</span>
</div>
<div class="views">
<button class="view-button" data-view="front">Front</button>
<button class="view-button" data-view="oblique">3/4</button>
<button class="view-button" data-view="pelvis">Pelvis</button>
</div>
<div class="toggles">
<label class="toggle">
<span class="toggle-label">
<i class="swatch"></i> Support geometry
</span>
<input id="supportToggle" class="check" type="checkbox" checked />
</label>
<label class="toggle">
<span class="toggle-label">
<i class="swatch coral"></i> Muscle control
</span>
<input id="muscleToggle" class="check" type="checkbox" checked />
</label>
<label class="toggle">
<span class="toggle-label">
<i class="swatch amber"></i> COM & gravity
</span>
<input id="gravityToggle" class="check" type="checkbox" checked />
</label>
</div>
</div>
</header>
<aside class="legend panel">
<div class="legend-row">
<i class="swatch"></i>
<span><strong>Static geometry</strong> · skeleton + support polygon</span>
</div>
<div class="legend-row">
<i class="swatch coral"></i>
<span><strong>Active control</strong> · muscle torque + motor signal</span>
</div>
<div class="legend-row">
<i class="swatch amber"></i>
<span><strong>Balance reference</strong> · COM + gravity projection</span>
</div>
</aside>
<div id="bilateralLabel" class="floating-label panel">
<span class="kicker">Static geometry / bilateral</span>
<strong>Wide support base</strong>
<small>Both feet share the load, increasing the available margin of stability.</small>
</div>
<div id="singleLabel" class="floating-label panel">
<span class="kicker" style="color:var(--coral)">Living control / single-leg</span>
<strong>Reduced support base</strong>
<small>Hip and ankle muscles continuously correct body sway.</small>
</div>
<div id="supportCallout" class="callout">Support polygon</div>
<div id="muscleCallout" class="callout active">Active stabilization</div>
<section class="summary">
<article class="panel">
<div class="number">01</div>
<h2>Bilateral stance</h2>
<p>
The rigid foot geometry creates a broad support polygon. A larger base
tolerates more center-of-mass displacement before loss of balance.
</p>
</article>
<article class="panel">
<div class="number">02</div>
<h2>Single-leg stance</h2>
<p>
The support area collapses to one foot. Gluteal, hip, and ankle muscles
must generate changing torque to keep the gravity projection inside it.
</p>
</article>
</section>
<div class="view-hint"><span>↔</span> Drag to orbit · Scroll to zoom · 1 / 2 / 3 for views</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 canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071019);
scene.fog = new THREE.Fog(0x071019, 12, 28);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xbadfff, 0x18202a, 2.0);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xe7f8ff, 3.2);
key.position.set(-4, 8, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 8;
key.shadow.camera.bottom = -2;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 22;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x49cfff, 2.2);
rim.position.set(5, 4, -5);
scene.add(rim);
const coralLight = new THREE.PointLight(0xff505f, 7, 8, 2);
coralLight.position.set(3.2, 2.3, 2.7);
scene.add(coralLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(32, 32),
new THREE.MeshStandardMaterial({
color: 0x09131d,
roughness: 0.91,
metalness: 0.05
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(24, 48, 0x284757, 0x142b39);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
// -------------------------------------------------------------------------
// Shared materials
// -------------------------------------------------------------------------
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xbcecff,
roughness: 0.38,
metalness: 0.10,
emissive: 0x123746,
emissiveIntensity: 0.30
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xe7fbff,
roughness: 0.25,
metalness: 0.14,
emissive: 0x285b6b,
emissiveIntensity: 0.32
});
const headMaterial = new THREE.MeshStandardMaterial({
color: 0xd9e4e8,
roughness: 0.74,
metalness: 0.0,
emissive: 0x16252c,
emissiveIntensity: 0.12
});
const shellMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd6a896,
roughness: 0.72,
metalness: 0,
transparent: true,
opacity: 0.105,
side: THREE.DoubleSide,
depthWrite: false
});
const muscleCalmMaterial = new THREE.MeshStandardMaterial({
color: 0xd64f61,
roughness: 0.52,
metalness: 0.02,
emissive: 0x5c0712,
emissiveIntensity: 0.32,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const muscleActiveMaterial = new THREE.MeshStandardMaterial({
color: 0xff5664,
roughness: 0.42,
metalness: 0.02,
emissive: 0xa40d23,
emissiveIntensity: 0.95,
transparent: true,
opacity: 0.90,
depthWrite: false
});
const supportFillMaterial = new THREE.MeshStandardMaterial({
color: 0x48cfff,
emissive: 0x0b5a78,
emissiveIntensity: 0.55,
transparent: true,
opacity: 0.16,
side: THREE.DoubleSide,
depthWrite: false
});
const supportLineMaterial = new THREE.LineBasicMaterial({
color: 0x72e3ff,
transparent: true,
opacity: 0.95
});
const controlMaterial = new THREE.MeshBasicMaterial({
color: 0xff6470,
transparent: true,
opacity: 0.78,
depthWrite: false
});
const signalMaterial = new THREE.MeshBasicMaterial({
color: 0xffe0d6,
transparent: true,
opacity: 0.95
});
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function cylinderBetween(start, end, radius, material, parent, radialSegments = 12) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments, 1),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(radius, material, parent, position, scale = null) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 18, 14),
material
);
mesh.position.copy(position);
if (scale) mesh.scale.copy(scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function tubeFromPoints(points, radius, material, parent, segments = 28) {
const curve = new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, segments, radius, 8, false),
material
);
mesh.castShadow = true;
parent.add(mesh);
return { curve, mesh };
}
function addMuscle(parent, points, radius, material, withSignal = false) {
const result = tubeFromPoints(points, radius, material, parent, 34);
result.mesh.castShadow = false;
if (withSignal) {
for (let i = 0; i < 2; i++) {
const signal = sphere(0.028, signalMaterial, parent, new THREE.Vector3());
signal.userData.phase = i * 0.5;
result.mesh.userData.signals ??= [];
result.mesh.userData.signals.push(signal);
}
}
return result;
}
function createSupportPolygon(parent, points) {
const shape = new THREE.Shape(
points.map(([x, z]) => new THREE.Vector2(x, z))
);
const fill = new THREE.Mesh(
new THREE.ShapeGeometry(shape),
supportFillMaterial
);
fill.rotation.x = -Math.PI / 2;
fill.position.y = 0.012;
parent.add(fill);
const outlinePoints = points.map(
([x, z]) => new THREE.Vector3(x, 0.019, z)
);
outlinePoints.push(outlinePoints[0].clone());
const outline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(outlinePoints),
supportLineMaterial
);
parent.add(outline);
return { fill, outline };
}
function createFoot(parent, x, y, z, lift = false) {
const material = new THREE.MeshStandardMaterial({
color: 0x163747,
roughness: 0.58,
metalness: 0.08,
emissive: 0x09202b,
emissiveIntensity: 0.28
});
const foot = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.13, 0.52, 2, 1, 3),
material
);
foot.position.set(x, y, z);
foot.castShadow = true;
foot.receiveShadow = true;
if (lift) {
foot.rotation.z = -0.15;
foot.rotation.x = -0.10;
}
parent.add(foot);
return foot;
}
// -------------------------------------------------------------------------
// Anatomical figure construction
// -------------------------------------------------------------------------
function createFigure({ x, singleLeg = false }) {
const root = new THREE.Group();
root.position.x = x;
scene.add(root);
const supportGroup = new THREE.Group();
const muscleGroup = new THREE.Group();
const balanceGroup = new THREE.Group();
const activeControlGroup = new THREE.Group();
root.add(supportGroup, muscleGroup, balanceGroup, activeControlGroup);
const supportX = singleLeg ? 0.18 : 0;
const bilateralPolygon = [
[-0.72, -0.22],
[ 0.72, -0.22],
[ 0.72, 0.34],
[ 0.18, 0.40],
[-0.18, 0.40],
[-0.72, 0.34]
];
const singlePolygon = [
[0.05, -0.20],
[0.31, -0.20],
[0.31, 0.36],
[0.14, 0.41],
[0.05, 0.36]
];
const polygon = createSupportPolygon(
supportGroup,
singleLeg ? singlePolygon : bilateralPolygon
);
// Leg definitions
const leftLeg = singleLeg
? {
hip: new THREE.Vector3(-0.20, 1.58, 0),
knee: new THREE.Vector3(-0.40, 0.91, -0.10),
ankle: new THREE.Vector3(-0.55, 0.34, -0.24),
lifted: true
}
: {
hip: new THREE.Vector3(-0.20, 1.58, 0),
knee: new THREE.Vector3(-0.47, 0.88, 0),
ankle: new THREE.Vector3(-0.58, 0.16, 0),
lifted: false
};
const rightLeg = singleLeg
? {
hip: new THREE.Vector3(0.20, 1.58, 0),
knee: new THREE.Vector3(0.20, 0.88, 0),
ankle: new THREE.Vector3(0.18, 0.16, 0),
lifted: false
}
: {
hip: new THREE.Vector3(0.20, 1.58, 0),
knee: new THREE.Vector3(0.47, 0.88, 0),
ankle: new THREE.Vector3(0.58, 0.16, 0),
lifted: false
};
function buildLeg(leg, side) {
cylinderBetween(leg.hip, leg.knee, 0.095, boneMaterial, root);
cylinderBetween(leg.knee, leg.ankle, 0.071, boneMaterial, root);
sphere(0.118, jointMaterial, root, leg.hip);
sphere(0.105, jointMaterial, root, leg.knee);
sphere(0.081, jointMaterial, root, leg.ankle);
createFoot(
root,
leg.ankle.x,
leg.lifted ? leg.ankle.y : 0.07,
leg.lifted ? leg.ankle.z + 0.10 : 0.08,
leg.lifted
);
const sideSign = side === "left" ? -1 : 1;
// Quadriceps and hamstring give each leg a recognizable muscular contour.
addMuscle(
muscleGroup,
[
[leg.hip.x + sideSign * 0.02, 1.57, 0.115],
[leg.knee.x * 0.92, 1.22, 0.15],
[leg.knee.x, 0.91, 0.115]
],
singleLeg && !leg.lifted ? 0.064 : 0.048,
singleLeg && !leg.lifted ? muscleActiveMaterial : muscleCalmMaterial,
singleLeg && !leg.lifted
);
addMuscle(
muscleGroup,
[
[leg.hip.x, 1.54, -0.12],
[leg.knee.x * 0.94, 1.20, -0.14],
[leg.knee.x, 0.91, -0.09]
],
singleLeg && !leg.lifted ? 0.055 : 0.042,
singleLeg && !leg.lifted ? muscleActiveMaterial : muscleCalmMaterial,
singleLeg && !leg.lifted
);
// Gluteus medius / hip abductor path.
addMuscle(
muscleGroup,
[
[leg.hip.x + sideSign * 0.04, 1.84, 0.015],
[leg.hip.x + sideSign * 0.15, 1.62, 0.04],
[leg.knee.x * 0.85, 1.33, 0.05]
],
singleLeg && !leg.lifted ? 0.070 : 0.052,
singleLeg && !leg.lifted ? muscleActiveMaterial : muscleCalmMaterial,
singleLeg && !leg.lifted
);
// Ankle stabilizers are emphasized in the loaded single-leg figure.
if (!leg.lifted) {
addMuscle(
muscleGroup,
[
[leg.ankle.x, 0.43, 0.105],
[leg.ankle.x, 0.20, 0.12],
[leg.ankle.x, 0.11, 0.23]
],
singleLeg ? 0.046 : 0.031,
singleLeg ? muscleActiveMaterial : muscleCalmMaterial,
singleLeg
);
}
}
buildLeg(leftLeg, "left");
buildLeg(rightLeg, "right");
// Static pelvis
sphere(0.14, boneMaterial, root, new THREE.Vector3(0, 1.61, -0.02));
sphere(
0.26, boneMaterial, root,
new THREE.Vector3(-0.18, 1.68, 0),
new THREE.Vector3(0.64, 0.90, 0.34)
);
sphere(
0.26, boneMaterial, root,
new THREE.Vector3(0.18, 1.68, 0),
new THREE.Vector3(0.64, 0.90, 0.34)
);
cylinderBetween(
new THREE.Vector3(-0.20, 1.61, 0),
new THREE.Vector3(0.20, 1.61, 0),
0.055,
boneMaterial,
root
);
// Upper anatomy pivots subtly at the pelvis in the single-leg figure.
const upper = new THREE.Group();
upper.position.y = 1.62;
root.add(upper);
cylinderBetween(
new THREE.Vector3(0, 0, -0.075),
new THREE.Vector3(0, 1.08, -0.06),
0.052,
boneMaterial,
upper
);
// Rib cage: exposed through an open-front torso shell.
for (let i = 0; i < 5; i++) {
const width = 0.34 - i * 0.023;
const y = 0.21 + i * 0.115;
const points = [];
for (let j = 0; j <= 16; j++) {
const t = -1 + (j / 16) * 2;
points.push([
t * width,
y - 0.045 * (1 - t * t),
0.035 + 0.13 * (1 - t * t)
]);
}
tubeFromPoints(points, 0.018, boneMaterial, upper, 28);
}
// Partial cylinder leaves a frontal anatomical window.
const shell = new THREE.Mesh(
new THREE.CylinderGeometry(
0.39, 0.31, 0.90, 32, 1, true,
0.67, Math.PI * 2 - 1.34
),
shellMaterial
);
shell.position.y = 0.52;
shell.castShadow = false;
upper.add(shell);
// Shoulder girdle and clavicles
cylinderBetween(
new THREE.Vector3(-0.38, 0.91, -0.025),
new THREE.Vector3(0.38, 0.91, -0.025),
0.040,
boneMaterial,
upper
);
cylinderBetween(
new THREE.Vector3(0, 0.94, -0.07),
new THREE.Vector3(0, 1.15, -0.02),
0.065,
boneMaterial,
upper
);
// Stylized head
const head = sphere(0.235, headMaterial, upper, new THREE.Vector3(0, 1.39, 0));
head.scale.set(0.86, 1.12, 0.91);
const jaw = sphere(
0.16, headMaterial, upper,
new THREE.Vector3(0, 1.29, 0.055),
new THREE.Vector3(0.78, 0.58, 0.82)
);
jaw.castShadow = true;
// Arms
const arms = [
{
shoulder: new THREE.Vector3(-0.38, 0.91, 0),
elbow: new THREE.Vector3(-0.49, 0.55, 0.015),
wrist: new THREE.Vector3(-0.54, 0.20, 0.075)
},
{
shoulder: new THREE.Vector3(0.38, 0.91, 0),
elbow: new THREE.Vector3(0.49, 0.55, 0.015),
wrist: new THREE.Vector3(0.54, 0.20, 0.075)
}
];
for (const arm of arms) {
cylinderBetween(arm.shoulder, arm.elbow, 0.053, boneMaterial, upper);
cylinderBetween(arm.elbow, arm.wrist, 0.043, boneMaterial, upper);
sphere(0.072, jointMaterial, upper, arm.elbow);
sphere(0.057, jointMaterial, upper, arm.wrist);
sphere(0.074, headMaterial, upper, arm.wrist.clone().add(new THREE.Vector3(0, -0.08, 0.01)));
}
// Center of mass and gravity projection
const com = sphere(
0.055,
new THREE.MeshBasicMaterial({ color: 0xffd166 }),
balanceGroup,
new THREE.Vector3(supportX, 1.72, 0.075)
);
const gravityGeometry = new THREE.BufferGeometry();
gravityGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(6), 3)
);
const gravityLine = new THREE.Line(
gravityGeometry,
new THREE.LineDashedMaterial({
color: 0xffd166,
dashSize: 0.065,
gapSize: 0.045,
transparent: true,
opacity: 0.85
})
);
balanceGroup.add(gravityLine);
const groundMarker = new THREE.Mesh(
new THREE.RingGeometry(0.065, 0.090, 28),
new THREE.MeshBasicMaterial({
color: 0xffd166,
side: THREE.DoubleSide,
transparent: true,
opacity: 0.95
})
);
groundMarker.rotation.x = -Math.PI / 2;
groundMarker.position.set(supportX, 0.025, 0.075);
balanceGroup.add(groundMarker);
// Small sway trajectory under the single-leg figure.
const swayPoints = [];
for (let i = 0; i <= 64; i++) {
const a = (i / 64) * Math.PI * 2;
swayPoints.push(
new THREE.Vector3(
supportX + Math.cos(a) * 0.115,
0.024,
0.075 + Math.sin(a) * 0.19
)
);
}
const swayEllipse = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(swayPoints),
new THREE.LineDashedMaterial({
color: 0xff6671,
dashSize: 0.025,
gapSize: 0.035,
transparent: true,
opacity: 0.8
})
);
swayEllipse.computeLineDistances();
balanceGroup.add(swayEllipse);
// Pelvic control arcs indicate active coordination.
if (singleLeg) {
for (let i = 0; i < 2; i++) {
const arc = new THREE.Mesh(
new THREE.TorusGeometry(
0.39 + i * 0.075,
0.012,
6,
52,
Math.PI * 1.48
),
controlMaterial
);
arc.position.set(0, 1.66, 0.05);
arc.rotation.z = 0.25 + i * 0.12;
activeControlGroup.add(arc);
}
const correctionArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(supportX, 1.73, 0.08),
0.30,
0xff6972,
0.075,
0.045
);
correctionArrow.line.material.transparent = true;
correctionArrow.line.material.opacity = 0.88;
correctionArrow.cone.material.transparent = true;
correctionArrow.cone.material.opacity = 0.88;
activeControlGroup.add(correctionArrow);
root.userData.correctionArrow = correctionArrow;
}
const figure = {
root,
upper,
supportGroup,
muscleGroup,
balanceGroup,
activeControlGroup,
com,
gravityLine,
groundMarker,
swayEllipse,
polygon,
supportX,
singleLeg,
correctionArrow: root.userData.correctionArrow
};
// Track animated motor signals.
figure.muscleGroup.traverse(object => {
if (object.userData.signals) {
figure.signals ??= [];
figure.signals.push({
curve: object.userData.curve,
signals: object.userData.signals
});
}
});
// The signal metadata is attached to the mesh itself.
figure.signals = [];
muscleGroup.traverse(object => {
if (object.userData.signals) {
const parentCurve = object.userData.curve;
if (parentCurve) {
figure.signals.push({
curve: parentCurve,
signals: object.userData.signals
});
}
}
});
return figure;
}
const bilateral = createFigure({ x: -2.15, singleLeg: false });
const single = createFigure({ x: 2.15, singleLeg: true });
// -------------------------------------------------------------------------
// Labels and projected anchors
// -------------------------------------------------------------------------
const labelElements = [
{
element: document.querySelector("#bilateralLabel"),
anchor: new THREE.Vector3(-2.15, 3.62, 0)
},
{
element: document.querySelector("#singleLabel"),
anchor: new THREE.Vector3(2.15, 3.62, 0)
},
{
element: document.querySelector("#supportCallout"),
anchor: new THREE.Vector3(-1.53, 0.28, 0.22)
},
{
element: document.querySelector("#muscleCallout"),
anchor: new THREE.Vector3(2.68, 1.77, 0.18)
}
];
function updateProjectedLabels() {
for (const item of labelElements) {
const p = item.anchor.clone().project(camera);
const visible = p.z > -1 && p.z < 1;
item.element.style.left = `${(p.x * 0.5 + 0.5) * window.innerWidth}px`;
item.element.style.top = `${(-p.y * 0.5 + 0.5) * window.innerHeight}px`;
item.element.classList.toggle("visible", visible);
}
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons
// -------------------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 1.68, 0),
radius: window.innerWidth < 700 ? 13.0 : 9.7,
azimuth: 0.0,
polar: 1.34
};
function updateCamera() {
const sinPolar = Math.sin(cameraState.polar);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPolar * Math.sin(cameraState.azimuth),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.polar),
cameraState.target.z +
cameraState.radius * sinPolar * Math.cos(cameraState.azimuth)
);
camera.lookAt(cameraState.target);
}
function setView(name) {
if (name === "front") {
cameraState.azimuth = 0;
cameraState.polar = 1.34;
cameraState.radius = window.innerWidth < 700 ? 13.0 : 9.7;
cameraState.target.set(0, 1.68, 0);
} else if (name === "oblique") {
cameraState.azimuth = 0.56;
cameraState.polar = 1.30;
cameraState.radius = window.innerWidth < 700 ? 13.0 : 9.5;
cameraState.target.set(0, 1.68, 0);
} else if (name === "pelvis") {
cameraState.azimuth = 0.34;
cameraState.polar = 1.43;
cameraState.radius = 5.6;
cameraState.target.set(1.75, 1.45, 0);
}
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
cameraState.azimuth -= dx * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar - dy * 0.005,
0.58,
1.49
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
4.7,
16
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", () => setView("front"));
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => setView(button.dataset.view));
});
window.addEventListener("keydown", event => {
if (event.key === "1") setView("front");
if (event.key === "2") setView("oblique");
if (event.key === "3") setView("pelvis");
if (event.key === "ArrowLeft") {
cameraState.azimuth -= 0.12;
updateCamera();
}
if (event.key === "ArrowRight") {
cameraState.azimuth += 0.12;
updateCamera();
}
});
// Layer controls
const supportToggle = document.querySelector("#supportToggle");
const muscleToggle = document.querySelector("#muscleToggle");
const gravityToggle = document.querySelector("#gravityToggle");
supportToggle.addEventListener("change", () => {
bilateral.supportGroup.visible = supportToggle.checked;
single.supportGroup.visible = supportToggle.checked;
});
muscleToggle.addEventListener("change", () => {
bilateral.muscleGroup.visible = muscleToggle.checked;
single.muscleGroup.visible = muscleToggle.checked;
bilateral.activeControlGroup.visible = muscleToggle.checked;
single.activeControlGroup.visible = muscleToggle.checked;
});
gravityToggle.addEventListener("change", () => {
bilateral.balanceGroup.visible = gravityToggle.checked;
single.balanceGroup.visible = gravityToggle.checked;
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function updateBalanceFigure(figure, time) {
if (!figure.singleLeg) {
figure.com.position.x = 0;
figure.groundMarker.position.x = 0;
figure.com.position.z = 0.075;
} else {
const sway = Math.sin(time * 1.05) * 0.050;
const x = figure.supportX + sway;
figure.upper.rotation.z = -Math.sin(time * 1.05) * 0.033;
figure.com.position.x = x;
figure.groundMarker.position.x = x;
figure.com.position.z = 0.075;
if (figure.correctionArrow) {
const direction = new THREE.Vector3(
sway >= 0 ? -1 : 1,
0,
0
);
figure.correctionArrow.setDirection(direction.normalize());
figure.correctionArrow.position.set(x, 1.73, 0.08);
}
}
const position = figure.gravityLine.geometry.attributes.position;
const comX = figure.com.position.x;
const comZ = figure.com.position.z;
position.setXYZ(0, comX, figure.com.position.y, comZ);
position.setXYZ(1, comX, 0.026, comZ);
position.needsUpdate = true;
figure.gravityLine.computeLineDistances();
// Moving points communicate motor commands traveling through the muscle.
for (const signalSet of figure.signals) {
signalSet.signals.forEach((signal, index) => {
const t = (
time * (figure.singleLeg ? 0.24 : 0.15) +
signal.userData.phase +
index * 0.11
) % 1;
signal.position.copy(signalSet.curve.getPointAt(t));
signal.scale.setScalar(0.85 + Math.sin(time * 8 + index) * 0.15);
});
}
}
function animate() {
const time = clock.getElapsedTime();
updateBalanceFigure(bilateral, time);
updateBalanceFigure(single, time);
muscleActiveMaterial.emissiveIntensity =
0.82 + Math.sin(time * 2.8) * 0.24;
muscleActiveMaterial.opacity =
0.82 + Math.sin(time * 2.8) * 0.08;
controlMaterial.opacity =
0.60 + Math.sin(time * 2.5) * 0.20;
single.swayEllipse.rotation.y = Math.sin(time * 0.45) * 0.035;
renderer.render(scene, camera);
updateProjectedLabels();
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
animate();
</script>
</body>
</html>
```