Prompt specification
Build or customize the Three.js 3D scene "Pelvis and support-leg balance model" 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: Pelvis and support-leg balance model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pelvis-and-support-leg-balance-model-x0997
Scene Description Prompt:
A simplified pelvis-and-support-leg cutaway showing center of mass, gravity line, and support footprint. Three.js from cdnjs, one HTML file.
Working Three.js Starter (pelvis-and-support-leg-balance-model-x0997):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pelvis & Support-Leg Cutaway</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 23, 31, 0.82);
--border: rgba(154, 213, 220, 0.18);
--text: #eaf6f6;
--muted: #91a9af;
--cyan: #67e7e8;
--gold: #ffd166;
--green: #77e3a1;
}
* { box-sizing: border-box; }
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background:
radial-gradient(circle at 48% 30%, #173441 0%, #0b1b24 43%, #061017 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
outline: none;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.28);
}
.title-panel {
top: 22px;
left: 22px;
width: min(360px, calc(100vw - 44px));
padding: 18px 20px 16px;
border-radius: 16px;
}
.eyebrow {
color: var(--cyan);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 7px;
font-size: clamp(21px, 2.3vw, 29px);
line-height: 1.12;
letter-spacing: -0.035em;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.legend {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.legend-item {
color: #c6d5d8;
font-size: 10px;
line-height: 1.3;
}
.legend-item span {
display: block;
width: 9px;
height: 9px;
margin-bottom: 6px;
border-radius: 50%;
box-shadow: 0 0 12px currentColor;
}
.legend-item.com span { color: var(--gold); background: var(--gold); }
.legend-item.gravity span { color: var(--cyan); background: var(--cyan); }
.legend-item.support span { color: var(--green); background: var(--green); }
.view-panel {
right: 22px;
top: 22px;
padding: 7px;
border-radius: 13px;
display: flex;
gap: 4px;
}
button {
border: 0;
border-radius: 9px;
padding: 9px 11px;
color: #b9cbcf;
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition: color 160ms ease, background 160ms ease;
}
button:hover,
button.active {
color: #efffff;
background: rgba(103, 231, 232, 0.13);
}
.readout {
right: 22px;
bottom: 22px;
width: 265px;
padding: 15px 16px;
border-radius: 14px;
}
.readout-title {
display: flex;
align-items: center;
gap: 8px;
color: #dff8ee;
font-size: 12px;
font-weight: 750;
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 13px rgba(119, 227, 161, 0.9);
}
.readout p {
margin: 8px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.readout b { color: var(--green); }
.hint {
left: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 11px;
color: #91a8ad;
font-size: 10px;
letter-spacing: 0.02em;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
overflow: hidden;
}
.callout {
position: absolute;
display: flex;
align-items: flex-start;
gap: 8px;
width: max-content;
max-width: 205px;
padding: 9px 11px;
transform: translate(-50%, -115%);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 10px;
background: rgba(7, 18, 25, 0.88);
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(10px);
opacity: 0;
transition: opacity 180ms ease;
}
.callout.visible { opacity: 1; }
.callout .dot {
flex: 0 0 auto;
width: 8px;
height: 8px;
margin-top: 3px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
.callout strong {
display: block;
color: #edf9f9;
font-size: 11px;
line-height: 1.25;
}
.callout small {
display: block;
margin-top: 3px;
color: #91a6ab;
font-size: 9px;
line-height: 1.3;
}
.callout.com { color: var(--gold); }
.callout.gravity { color: var(--cyan); }
.callout.support { color: var(--green); }
.callout.cutaway { color: #e5b3a1; }
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
color: var(--muted);
background: #07131b;
font-size: 12px;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px 15px;
}
.legend { display: none; }
.view-panel { top: auto; right: 12px; bottom: 55px; }
.readout { display: none; }
.hint { left: 12px; bottom: 12px; }
.callout { max-width: 160px; }
.callout small { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional pelvis and support-leg biomechanics cutaway"></canvas>
<div id="labels">
<div class="callout com" id="label-com">
<span class="dot"></span>
<div><strong>Center of mass</strong><small>Combined body-mass centroid</small></div>
</div>
<div class="callout gravity" id="label-gravity">
<span class="dot"></span>
<div><strong>Gravity line</strong><small>Vertical force direction</small></div>
</div>
<div class="callout support" id="label-support">
<span class="dot"></span>
<div><strong>Support footprint</strong><small>Base of support</small></div>
</div>
<div class="callout cutaway" id="label-cutaway">
<span class="dot"></span>
<div><strong>Bone cutaway</strong><small>Exposed marrow cavity</small></div>
</div>
</div>
<section class="panel title-panel">
<div class="eyebrow">Biomechanics · Single-Leg Stance</div>
<h1>Pelvis & Support-Leg Cutaway</h1>
<p class="subtitle">
A simplified anatomical model showing how gravity projects through the
center of mass and relates to the planted foot.
</p>
<div class="legend">
<div class="legend-item com"><span></span>Center of mass</div>
<div class="legend-item gravity"><span></span>Gravity line</div>
<div class="legend-item support"><span></span>Support area</div>
</div>
</section>
<nav class="panel view-panel" aria-label="Camera views">
<button class="active" data-view="oblique">Oblique</button>
<button data-view="front">Front</button>
<button data-view="side">Side</button>
</nav>
<aside class="panel readout">
<div class="readout-title"><span class="status-dot"></span>Projection inside support</div>
<p>
The vertical gravity line falls within the <b>support footprint</b>,
indicating a statically balanced alignment in this simplified pose.
</p>
</aside>
<div class="panel hint">Drag to orbit · Scroll to zoom</div>
<div id="loading">Loading anatomy model…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: 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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.localClippingEnabled = true;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x081720, 0.035);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
50
);
const model = new THREE.Group();
scene.add(model);
const controls = {
yaw: 0.46,
pitch: 0.08,
distance: 7.15,
target: new THREE.Vector3(0.08, 1.83, 0.08),
desiredYaw: 0.46,
desiredPitch: 0.08,
desiredDistance: 7.15
};
// ---------------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xbfefff, 0x172029, 1.65));
const key = new THREE.DirectionalLight(0xfff3d7, 3.2);
key.position.set(4.5, 7, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -3;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 18;
key.shadow.bias = -0.0004;
scene.add(key);
const rim = new THREE.DirectionalLight(0x58dce3, 2.3);
rim.position.set(-5, 3.5, -4);
scene.add(rim);
const warmFill = new THREE.PointLight(0xffbd76, 15, 8, 2);
warmFill.position.set(2.2, 2.6, 3.1);
scene.add(warmFill);
// ---------------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------------
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xe9dfc4,
roughness: 0.64,
metalness: 0.02
});
const boneFaceMaterial = new THREE.MeshStandardMaterial({
color: 0xd4c39f,
roughness: 0.72,
side: THREE.DoubleSide
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xf4ead0,
roughness: 0.78,
side: THREE.DoubleSide
});
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x9e8969,
roughness: 0.8
});
const jointMaterial = new THREE.MeshPhysicalMaterial({
color: 0xb8d8d7,
roughness: 0.25,
clearcoat: 0.45,
transparent: true,
opacity: 0.75
});
const marrowMaterial = new THREE.MeshStandardMaterial({
color: 0xc85f61,
roughness: 0.88
});
const tissueMaterial = new THREE.MeshStandardMaterial({
color: 0xb94f68,
roughness: 0.76,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false
});
const footTissueMaterial = new THREE.MeshStandardMaterial({
color: 0xc87584,
roughness: 0.72,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false
});
const cyanMaterial = new THREE.MeshBasicMaterial({
color: 0x67e7e8,
transparent: true,
opacity: 0.92,
depthTest: false
});
const goldMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0xffa62e,
emissiveIntensity: 1.15,
roughness: 0.28
});
// ---------------------------------------------------------------------------
// Geometry helpers
// ---------------------------------------------------------------------------
function addMesh(geometry, material, parent = model) {
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = !material.transparent;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addTube(points, radius, material, parent = model, tubularSegments = 48) {
const curve = new THREE.CatmullRomCurve3(
points.map(p => new THREE.Vector3(...p))
);
const geometry = new THREE.TubeGeometry(
curve,
tubularSegments,
radius,
10,
false
);
return addMesh(geometry, material, parent);
}
function addSegment(a, b, radius, material, parent = model, radialSegments = 12) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, length, radialSegments),
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 addEllipsoid(position, scale, material, parent = model) {
const mesh = addMesh(new THREE.SphereGeometry(1, 28, 20), material, parent);
mesh.position.set(...position);
mesh.scale.set(...scale);
return mesh;
}
/**
* Creates an anteriorly opened shaft. The missing sector faces +Z so the
* internal marrow column and pale cut faces remain visible.
*/
function addCutShaft({
x,
z,
top,
bottom,
rTop,
rBottom,
parent = model,
tissue = null
}) {
const height = top - bottom;
const centerY = (top + bottom) / 2;
const thetaStart = 0.38;
const thetaLength = Math.PI * 1.60;
const outer = addMesh(
new THREE.CylinderGeometry(
rTop,
rBottom,
height,
40,
1,
false,
thetaStart,
thetaLength
),
boneMaterial,
parent
);
outer.position.set(x, centerY, z);
const marrow = addMesh(
new THREE.CylinderGeometry(
rTop * 0.34,
rBottom * 0.30,
height * 0.88,
24
),
marrowMaterial,
parent
);
marrow.position.set(x, centerY, z);
// Pale planar surfaces at both sides of the cutaway.
for (const theta of [thetaStart, thetaStart + thetaLength]) {
const s = Math.sin(theta);
const c = Math.cos(theta);
const vertices = new Float32Array([
x + s * rBottom, bottom, z + c * rBottom,
x + s * rTop, top, z + c * rTop,
x + s * rBottom * 0.34, bottom, z + c * rBottom * 0.34,
x + s * rTop * 0.34, top, z + c * rTop * 0.34
]);
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex([0, 1, 2, 0, 2, 3]);
geometry.computeVertexNormals();
addMesh(geometry, cutMaterial, parent);
}
if (tissue) {
const shell = addMesh(
new THREE.CylinderGeometry(
rTop * 1.36,
rBottom * 1.30,
height * 0.93,
36,
1,
true,
thetaStart + 0.05,
thetaLength - 0.10
),
tissue,
parent
);
shell.position.set(x, centerY, z);
shell.castShadow = false;
}
}
// ---------------------------------------------------------------------------
// Pelvis
// ---------------------------------------------------------------------------
function makeIliacWing(sign) {
const points = [
[0.10, 2.43],
[0.54, 2.34],
[0.96, 2.48],
[1.17, 2.96],
[1.03, 3.48],
[0.72, 3.79],
[0.36, 3.62],
[0.10, 3.29]
];
const shape = new THREE.Shape();
shape.moveTo(points[0][0] * sign, points[0][1]);
shape.quadraticCurveTo(
0.72 * sign, 2.27,
0.98 * sign, 2.48
);
shape.quadraticCurveTo(
1.24 * sign, 3.05,
1.03 * sign, 3.48
);
shape.quadraticCurveTo(
0.80 * sign, 3.89,
0.36 * sign, 3.62
);
shape.lineTo(points[7][0] * sign, points[7][1]);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.28,
bevelEnabled: true,
bevelSegments: 3,
steps: 1,
bevelSize: 0.045,
bevelThickness: 0.045,
curveSegments: 18
});
geometry.translate(0, 0, -0.14);
const wing = addMesh(geometry, boneMaterial);
// Shallow iliac surface line.
addTube([
[0.31 * sign, 2.56, 0.16],
[0.70 * sign, 2.57, 0.17],
[0.95 * sign, 2.89, 0.17],
[0.87 * sign, 3.32, 0.17],
[0.60 * sign, 3.54, 0.16]
], 0.014, grooveMaterial);
return wing;
}
makeIliacWing(1);
makeIliacWing(-1);
// Sacrum.
const sacrumShape = new THREE.Shape();
sacrumShape.moveTo(-0.23, 3.56);
sacrumShape.lineTo(0.23, 3.56);
sacrumShape.quadraticCurveTo(0.28, 3.10, 0.22, 2.76);
sacrumShape.quadraticCurveTo(0.12, 2.53, 0, 2.46);
sacrumShape.quadraticCurveTo(-0.12, 2.53, -0.22, 2.76);
sacrumShape.quadraticCurveTo(-0.28, 3.10, -0.23, 3.56);
const sacrumGeometry = new THREE.ExtrudeGeometry(sacrumShape, {
depth: 0.34,
bevelEnabled: true,
bevelSize: 0.035,
bevelThickness: 0.035,
bevelSegments: 3,
curveSegments: 16
});
sacrumGeometry.translate(0, 0, -0.17);
addMesh(sacrumGeometry, boneMaterial);
// Sacral foramina.
for (const y of [3.34, 3.13, 2.92]) {
for (const x of [-0.095, 0.095]) {
addEllipsoid([x, y, 0.19], [0.038, 0.048, 0.022], grooveMaterial);
}
}
// Pelvic brim and pubic arch.
addTube([
[-0.79, 3.02, 0.03],
[-0.46, 2.82, 0.07],
[-0.18, 2.69, 0.08],
[0, 2.65, 0.08],
[0.18, 2.69, 0.08],
[0.46, 2.82, 0.07],
[0.79, 3.02, 0.03]
], 0.075, boneMaterial);
addTube([
[-0.48, 2.60, 0.06],
[-0.31, 2.34, 0.08],
[0, 2.24, 0.10],
[0.31, 2.34, 0.08],
[0.48, 2.60, 0.06]
], 0.095, boneMaterial);
// Obturator rings.
for (const x of [-0.31, 0.31]) {
const ring = addMesh(
new THREE.TorusGeometry(0.19, 0.068, 12, 42),
boneMaterial
);
ring.position.set(x, 2.38, 0.04);
ring.scale.set(1.0, 1.26, 1);
}
// Acetabulum of support hip.
const acetabulum = addMesh(
new THREE.TorusGeometry(0.225, 0.052, 14, 48),
boneMaterial
);
acetabulum.position.set(0.38, 2.60, 0.015);
const acetabularCup = addMesh(
new THREE.SphereGeometry(0.19, 24, 16),
jointMaterial
);
acetabularCup.position.set(0.38, 2.60, -0.01);
acetabularCup.scale.set(1, 1, 0.52);
// ---------------------------------------------------------------------------
// Support femur
// ---------------------------------------------------------------------------
const supportX = 0.38;
const supportZ = 0.015;
addEllipsoid(
[supportX, 2.61, supportZ],
[0.145, 0.145, 0.125],
jointMaterial
);
addSegment(
[supportX, 2.57, supportZ],
[0.48, 2.72, supportZ],
0.115,
boneMaterial
);
addEllipsoid(
[0.56, 2.58, supportZ],
[0.13, 0.20, 0.16],
boneMaterial
);
addCutShaft({
x: 0.40,
z: supportZ,
top: 2.62,
bottom: 1.27,
rTop: 0.165,
rBottom: 0.205,
tissue: tissueMaterial
});
// Femoral condyles and patella.
addEllipsoid([0.29, 1.25, 0.055], [0.14, 0.17, 0.15], boneMaterial);
addEllipsoid([0.49, 1.25, 0.055], [0.14, 0.17, 0.15], boneMaterial);
addEllipsoid([0.39, 1.27, 0.19], [0.13, 0.15, 0.07], boneFaceMaterial);
// ---------------------------------------------------------------------------
// Support tibia, fibula, and foot
// ---------------------------------------------------------------------------
const plateau = addMesh(
new THREE.BoxGeometry(0.43, 0.14, 0.31),
boneMaterial
);
plateau.position.set(0.38, 1.12, 0.01);
addCutShaft({
x: 0.38,
z: supportZ,
top: 1.08,
bottom: 0.25,
rTop: 0.145,
rBottom: 0.105,
tissue: tissueMaterial
});
// Fibula.
addSegment(
[0.15, 1.04, -0.015],
[0.17, 0.28, -0.015],
0.066,
boneMaterial,
model,
16
);
addEllipsoid([0.17, 1.03, -0.01], [0.09, 0.13, 0.09], boneMaterial);
addEllipsoid([0.17, 0.28, -0.01], [0.08, 0.10, 0.08], boneMaterial);
// Achilles tendon.
addTube([
[0.25, 0.47, -0.13],
[0.30, 0.27, -0.19],
[0.36, 0.14, -0.22]
], 0.035, new THREE.MeshStandardMaterial({
color: 0xe4d4aa,
roughness: 0.62
}));
// Foot tissue envelope.
const footEnvelope = addEllipsoid(
[0.38, 0.115, 0.41],
[0.245, 0.13, 0.69],
footTissueMaterial
);
footEnvelope.castShadow = false;
// Calcaneus and talus.
addEllipsoid([0.38, 0.105, -0.19], [0.17, 0.11, 0.25], boneMaterial);
addEllipsoid([0.38, 0.17, 0.015], [0.13, 0.11, 0.13], boneMaterial);
addEllipsoid([0.38, 0.14, 0.18], [0.105, 0.075, 0.11], boneMaterial);
// Metatarsals and phalanges.
const toeOffsets = [-0.125, -0.065, 0, 0.065, 0.125];
const toeLengths = [0.28, 0.37, 0.40, 0.35, 0.27];
for (let i = 0; i < 5; i++) {
const x = 0.38 + toeOffsets[i];
const startZ = 0.22;
const endZ = 0.63 + (0.40 - toeLengths[i]);
const midZ = (startZ + endZ) / 2;
addSegment(
[x, 0.105, startZ],
[x, 0.095, midZ],
0.027,
boneMaterial,
model,
10
);
addSegment(
[x, 0.095, midZ],
[x, 0.09, endZ],
0.022,
boneMaterial,
model,
10
);
addSegment(
[x, 0.09, endZ],
[x, 0.08, endZ + toeLengths[i] * 0.48],
0.017,
boneMaterial,
model,
10
);
addSegment(
[x, 0.08, endZ + toeLengths[i] * 0.48],
[x, 0.075, endZ + toeLengths[i]],
0.014,
boneMaterial,
model,
10
);
}
// ---------------------------------------------------------------------------
// Ground, footprint, and gravity construction
// ---------------------------------------------------------------------------
const ground = addMesh(
new THREE.PlaneGeometry(14, 14),
new THREE.MeshStandardMaterial({
color: 0x0b2028,
roughness: 0.96,
metalness: 0.02
}),
scene
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.012;
ground.receiveShadow = true;
const grid = new THREE.GridHelper(12, 24, 0x315c65, 0x193740);
grid.position.y = -0.005;
const gridMaterials = Array.isArray(grid.material) ? grid.material : [grid.material];
gridMaterials.forEach(material => {
material.transparent = true;
material.opacity = 0.24;
});
scene.add(grid);
// Soft contact shadow.
const shadowCanvas = document.createElement("canvas");
shadowCanvas.width = shadowCanvas.height = 256;
const shadowContext = shadowCanvas.getContext("2d");
const gradient = shadowContext.createRadialGradient(128, 128, 4, 128, 128, 125);
gradient.addColorStop(0, "rgba(0,0,0,0.52)");
gradient.addColorStop(0.45, "rgba(0,0,0,0.25)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
shadowContext.fillStyle = gradient;
shadowContext.fillRect(0, 0, 256, 256);
const contactShadow = new THREE.Mesh(
new THREE.PlaneGeometry(1.8, 2.5),
new THREE.MeshBasicMaterial({
map: new THREE.CanvasTexture(shadowCanvas),
transparent: true,
depthWrite: false,
opacity: 0.75
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.set(0.38, 0.002, 0.40);
scene.add(contactShadow);
// Convex support footprint around the planted foot.
const footprintVertices = [
[0.02, -0.40],
[0.67, -0.36],
[0.78, 0.72],
[0.56, 1.17],
[0.17, 1.19],
[-0.03, 0.72]
];
const footprintCenter = footprintVertices.reduce(
(sum, point) => [sum[0] + point[0] / footprintVertices.length,
sum[1] + point[1] / footprintVertices.length],
[0, 0]
);
const footprintPositions = [];
const footprintIndices = [];
footprintPositions.push(
footprintCenter[0], 0.012, footprintCenter[1]
);
for (const [x, z] of footprintVertices) {
footprintPositions.push(x, 0.012, z);
}
for (let i = 0; i < footprintVertices.length; i++) {
footprintIndices.push(
0,
i + 1,
(i + 1) % footprintVertices.length + 1
);
}
const footprintGeometry = new THREE.BufferGeometry();
footprintGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(footprintPositions, 3)
);
footprintGeometry.setIndex(footprintIndices);
footprintGeometry.computeVertexNormals();
const footprint = new THREE.Mesh(
footprintGeometry,
new THREE.MeshBasicMaterial({
color: 0x77e3a1,
transparent: true,
opacity: 0.11,
side: THREE.DoubleSide,
depthWrite: false
})
);
footprint.renderOrder = 2;
scene.add(footprint);
const footprintOutline = new THREE.LineLoop(
new THREE.BufferGeometry().setFromPoints(
footprintVertices.map(([x, z]) => new THREE.Vector3(x, 0.025, z))
),
new THREE.LineBasicMaterial({
color: 0x77e3a1,
transparent: true,
opacity: 0.9
})
);
footprintOutline.renderOrder = 3;
scene.add(footprintOutline);
// Center of mass.
const comPosition = new THREE.Vector3(0.22, 3.12, 0.16);
const comMarker = new THREE.Group();
comMarker.position.copy(comPosition);
scene.add(comMarker);
const comSphere = new THREE.Mesh(
new THREE.SphereGeometry(0.095, 24, 16),
goldMaterial
);
comMarker.add(comSphere);
const ringGeometry = new THREE.TorusGeometry(0.145, 0.008, 8, 48);
for (let i = 0; i < 3; i++) {
const ring = new THREE.Mesh(ringGeometry, cyanMaterial.clone());
ring.material.color.set(0xffd166);
ring.material.opacity = 0.88;
if (i === 1) ring.rotation.x = Math.PI / 2;
if (i === 2) ring.rotation.y = Math.PI / 2;
ring.renderOrder = 10;
comMarker.add(ring);
}
// Dashed vertical gravity line.
const gravityGeometry = new THREE.BufferGeometry().setFromPoints([
comPosition.clone(),
new THREE.Vector3(comPosition.x, 0.04, comPosition.z)
]);
const gravityLine = new THREE.Line(
gravityGeometry,
new THREE.LineDashedMaterial({
color: 0x67e7e8,
dashSize: 0.095,
gapSize: 0.055,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
gravityLine.computeLineDistances();
gravityLine.renderOrder = 11;
scene.add(gravityLine);
// Downward arrow at the support surface.
const gravityArrow = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.17, 16),
cyanMaterial
);
gravityArrow.position.set(comPosition.x, 0.105, comPosition.z);
gravityArrow.rotation.z = Math.PI;
gravityArrow.renderOrder = 12;
scene.add(gravityArrow);
// Ground projection marker.
const projectionRing = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.013, 8, 44),
cyanMaterial
);
projectionRing.position.set(comPosition.x, 0.032, comPosition.z);
projectionRing.rotation.x = Math.PI / 2;
projectionRing.renderOrder = 12;
scene.add(projectionRing);
const projectionDot = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 16, 10),
cyanMaterial
);
projectionDot.position.set(comPosition.x, 0.034, comPosition.z);
projectionDot.renderOrder = 12;
scene.add(projectionDot);
// ---------------------------------------------------------------------------
// DOM labels projected from Three.js coordinates
// ---------------------------------------------------------------------------
const labels = [
{
element: document.querySelector("#label-com"),
position: comPosition.clone().add(new THREE.Vector3(0, 0.13, 0)),
offset: [0, 0]
},
{
element: document.querySelector("#label-gravity"),
position: new THREE.Vector3(comPosition.x + 0.10, 1.83, comPosition.z),
offset: [44, 0]
},
{
element: document.querySelector("#label-support"),
position: new THREE.Vector3(0.48, 0.10, 0.82),
offset: [0, 8]
},
{
element: document.querySelector("#label-cutaway"),
position: new THREE.Vector3(0.53, 1.92, 0.18),
offset: [38, -3]
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width + label.offset[0]}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height + label.offset[1]}px`;
label.element.classList.toggle("visible", visible);
}
}
// ---------------------------------------------------------------------------
// Direct camera controls: no addon modules
// ---------------------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
canvas.addEventListener("pointerdown", event => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging || event.pointerId !== pointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.desiredYaw -= dx * 0.006;
controls.desiredPitch = THREE.MathUtils.clamp(
controls.desiredPitch + dy * 0.005,
-0.18,
0.75
);
});
function endDrag(event) {
if (!dragging) return;
dragging = false;
if (pointerId !== null && canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
canvas.style.cursor = "grab";
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
controls.desiredDistance = THREE.MathUtils.clamp(
controls.desiredDistance + event.deltaY * 0.006,
4.8,
10.5
);
}, { passive: false });
canvas.style.cursor = "grab";
const viewPresets = {
oblique: { yaw: 0.46, pitch: 0.08, distance: 7.15 },
front: { yaw: 0.00, pitch: 0.05, distance: 7.25 },
side: { yaw: 1.36, pitch: 0.06, distance: 7.20 }
};
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
const preset = viewPresets[button.dataset.view];
controls.desiredYaw = preset.yaw;
controls.desiredPitch = preset.pitch;
controls.desiredDistance = preset.distance;
document.querySelectorAll("[data-view]").forEach(item => {
item.classList.toggle("active", item === button);
});
});
});
// ---------------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.pow(0.0008, delta);
controls.yaw += (controls.desiredYaw - controls.yaw) * damping;
controls.pitch += (controls.desiredPitch - controls.pitch) * damping;
controls.distance += (controls.desiredDistance - controls.distance) * damping;
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
const pulse = 1 + Math.sin(clock.elapsedTime * 2.2) * 0.055;
comSphere.scale.setScalar(pulse);
comMarker.children.slice(1).forEach((ring, index) => {
ring.rotation.z += delta * (index % 2 === 0 ? 0.42 : -0.34);
});
updateLabels();
renderer.render(scene, camera);
}
renderer.compile(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```