Prompt specification
Build or customize the Three.js 3D scene "Joint-constraint animation sandbox" 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: Joint-constraint animation sandbox
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/joint-constraint-animation-sandbox-x1008
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Allow limited knee flexion and camera inspection of bone alignment in a simplified rig; make the approximation explicit and prevent arbitrary impossible rotations or severe mesh collisions.
Working Three.js Starter (joint-constraint-animation-sandbox-x1008):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Low-Poly Knee Alignment Inspector</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(16, 24, 35, 0.9);
--panel-border: rgba(255, 255, 255, 0.13);
--text: #edf4ff;
--muted: #aab8ca;
--accent: #58c7ff;
--safe: #66e3a6;
--warn: #ffcc66;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0c1420;
color: var(--text);
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(370px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 18px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
}
h1 {
margin: 0;
font-size: 1.18rem;
letter-spacing: 0.01em;
}
.subtitle {
margin: 5px 0 16px;
color: var(--muted);
font-size: 0.83rem;
line-height: 1.4;
}
.angle-box {
display: flex;
align-items: baseline;
justify-content: space-between;
margin: 10px 0 6px;
}
.angle {
color: var(--accent);
font-size: 2rem;
font-weight: 750;
font-variant-numeric: tabular-nums;
}
.requested {
color: var(--muted);
font-size: 0.78rem;
}
input[type="range"] {
width: 100%;
margin: 8px 0 4px;
accent-color: var(--accent);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
color: var(--muted);
font-size: 0.7rem;
}
.status {
margin-top: 12px;
padding: 10px 11px;
border: 1px solid rgba(102, 227, 166, 0.25);
border-radius: 10px;
background: rgba(102, 227, 166, 0.08);
color: var(--safe);
font-size: 0.78rem;
line-height: 1.45;
}
.status.warning {
border-color: rgba(255, 204, 102, 0.32);
background: rgba(255, 204, 102, 0.09);
color: var(--warn);
}
.status strong {
display: block;
margin-bottom: 2px;
}
.section-label {
margin: 16px 0 8px;
color: var(--muted);
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.button-row {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
button {
padding: 8px 10px;
border: 1px solid var(--panel-border);
border-radius: 8px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 0.77rem;
cursor: pointer;
}
button:hover {
background: rgba(88, 199, 255, 0.14);
border-color: rgba(88, 199, 255, 0.4);
}
.check-row {
display: flex;
align-items: center;
gap: 8px;
margin-top: 11px;
color: #d8e4f4;
font-size: 0.8rem;
cursor: pointer;
}
.check-row input {
accent-color: var(--accent);
}
.legend {
display: flex;
gap: 15px;
margin-top: 13px;
color: var(--muted);
font-size: 0.74rem;
}
.swatch {
display: inline-block;
width: 10px;
height: 10px;
margin-right: 5px;
border-radius: 3px;
vertical-align: -1px;
}
.femur-swatch {
background: #d9c8a4;
}
.tibia-swatch {
background: #b9d9ef;
}
.guide-swatch {
background: #58c7ff;
}
.note {
margin: 15px 0 0;
padding-top: 13px;
border-top: 1px solid var(--panel-border);
color: var(--muted);
font-size: 0.72rem;
line-height: 1.5;
}
.note strong {
color: #dce8f8;
}
.help {
margin-top: 11px;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.45;
}
@media (max-width: 640px) {
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 58vh;
padding: 14px;
}
h1 {
font-size: 1rem;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly knee rig"></canvas>
<section class="panel" aria-label="Knee rig controls">
<h1>Low-Poly Knee Alignment Inspector</h1>
<p class="subtitle">
Fixed-axis sagittal hinge with conservative shaft-clearance checking.
Camera motion never changes the rig pose.
</p>
<div class="angle-box">
<span class="angle" id="angleReadout">0.0°</span>
<span class="requested" id="requestedReadout">Requested 0°</span>
</div>
<label for="flexSlider" class="section-label">Knee flexion</label>
<input
id="flexSlider"
type="range"
min="0"
max="125"
step="1"
value="0"
aria-label="Requested knee flexion angle"
>
<div class="range-labels">
<span>0° extended</span>
<span>125° requested maximum</span>
</div>
<div class="status" id="safetyStatus" role="status" aria-live="polite">
<strong>Clearance OK</strong>
The conservative shaft proxies remain separated.
</div>
<div class="section-label">Camera views</div>
<div class="button-row">
<button type="button" data-view="side">Side</button>
<button type="button" data-view="front">Front</button>
<button type="button" data-view="oblique">3/4</button>
<button type="button" id="resetView">Reset camera</button>
</div>
<div class="section-label">Rig</div>
<div class="button-row">
<button type="button" id="resetPose">Reset pose</button>
<button type="button" id="safeLimit">Use safe limit</button>
</div>
<label class="check-row">
<input id="showGuides" type="checkbox" checked>
Show alignment guides and hinge axis
</label>
<div class="legend">
<span><i class="swatch femur-swatch"></i>Femur</span>
<span><i class="swatch tibia-swatch"></i>Tibia</span>
<span><i class="swatch guide-swatch"></i>Guides</span>
</div>
<p class="note">
<strong>Approximation:</strong> this is an educational geometric hinge,
not an anatomical or biomechanical simulation. It omits axial
“screw-home” rotation, translation, ligament constraints, patellar
glide, and patient-specific bone surfaces.
</p>
<p class="note">
The faceted joint hub is intentionally overlapping and is excluded from
collision checks. The two tapered shaft proxies include a safety
clearance so severe femur–tibia interpenetration is prevented. The
displayed safe limit is a property of this simplified model, not a
clinical range-of-motion recommendation.
</p>
<p class="help">
Drag to orbit, scroll or pinch to zoom, and use the view buttons for
alignment inspection. The flexion slider is the only control that
changes the model.
</p>
</section>
<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 ui = {
slider: document.querySelector("#flexSlider"),
angle: document.querySelector("#angleReadout"),
requested: document.querySelector("#requestedReadout"),
status: document.querySelector("#safetyStatus"),
guides: document.querySelector("#showGuides"),
resetView: document.querySelector("#resetView"),
resetPose: document.querySelector("#resetPose"),
safeLimit: document.querySelector("#safeLimit")
};
const DEG = Math.PI / 180;
const MAX_REQUESTED = 125;
const KNEE_HEIGHT = 1.35;
// Scene ---------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0c1420);
scene.fog = new THREE.Fog(0x0c1420, 7, 16);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
50
);
const cameraTarget = new THREE.Vector3(0, KNEE_HEIGHT, 0);
const desiredOrbit = {
theta: 0.68,
phi: 1.20,
radius: 4.5
};
const currentOrbit = {
theta: desiredOrbit.theta,
phi: desiredOrbit.phi,
radius: desiredOrbit.radius
};
function updateCamera() {
const { theta, phi, radius } = currentOrbit;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xcbe7ff, 0x263343, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d8, 3.4);
keyLight.position.set(3.5, 6.5, 4.0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 15;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5abfff, 1.8);
rimLight.position.set(-4, 3, -3);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(14, 14),
new THREE.MeshStandardMaterial({
color: 0x142131,
roughness: 0.95,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = 0;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(10, 20, 0x42627e, 0x263c51);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// Materials -----------------------------------------------------------
const boneMaterial = new THREE.MeshStandardMaterial({
color: 0xd9c8a4,
roughness: 0.82,
metalness: 0.02,
flatShading: true
});
const tibiaMaterial = new THREE.MeshStandardMaterial({
color: 0xb9d9ef,
roughness: 0.8,
metalness: 0.03,
flatShading: true
});
const jointMaterial = new THREE.MeshStandardMaterial({
color: 0xf0b85f,
roughness: 0.5,
metalness: 0.08,
flatShading: true
});
const footMaterial = new THREE.MeshStandardMaterial({
color: 0x34475d,
roughness: 0.9,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x4b5360,
transparent: true,
opacity: 0.58
});
function addEdges(mesh) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry, 15),
edgeMaterial
);
mesh.add(edges);
return mesh;
}
// Simplified rig ------------------------------------------------------
const knee = new THREE.Group();
knee.position.set(0, KNEE_HEIGHT, 0);
scene.add(knee);
const tibiaPivot = new THREE.Group();
knee.add(tibiaPivot);
// Femur: tapered six-sided shaft.
const femur = addEdges(
new THREE.Mesh(
new THREE.CylinderGeometry(0.145, 0.095, 1.0, 6, 1, false),
boneMaterial
)
);
femur.position.y = 0.68;
femur.castShadow = true;
femur.receiveShadow = true;
knee.add(femur);
// Stylized hip endpoint.
const hip = addEdges(
new THREE.Mesh(
new THREE.DodecahedronGeometry(0.19, 0),
boneMaterial
)
);
hip.position.y = 1.22;
hip.scale.set(1.05, 0.9, 1.05);
hip.castShadow = true;
knee.add(hip);
// Tibia: tapered six-sided shaft, rotating only around local Z.
const tibia = addEdges(
new THREE.Mesh(
new THREE.CylinderGeometry(0.095, 0.12, 1.0, 6, 1, false),
tibiaMaterial
)
);
tibia.position.y = -0.67;
tibia.castShadow = true;
tibia.receiveShadow = true;
tibiaPivot.add(tibia);
// Intentionally overlapping joint housing, excluded from collision proxy.
const jointHub = addEdges(
new THREE.Mesh(
new THREE.IcosahedronGeometry(0.17, 1),
jointMaterial
)
);
jointHub.scale.set(1.08, 0.96, 1.22);
jointHub.castShadow = true;
knee.add(jointHub);
// Stylized ankle and foot.
const ankle = addEdges(
new THREE.Mesh(
new THREE.DodecahedronGeometry(0.105, 0),
tibiaMaterial
)
);
ankle.position.y = -1.17;
ankle.castShadow = true;
tibiaPivot.add(ankle);
const foot = addEdges(
new THREE.Mesh(
new THREE.BoxGeometry(0.36, 0.13, 0.21),
footMaterial
)
);
foot.position.set(0.11, -1.25, 0);
foot.castShadow = true;
foot.receiveShadow = true;
tibiaPivot.add(foot);
// Alignment guides ----------------------------------------------------
const guideGroup = new THREE.Group();
guideGroup.position.copy(knee.position);
scene.add(guideGroup);
function dashedLine(color, points) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.045,
gapSize: 0.025,
transparent: true,
opacity: 0.9,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 20;
return line;
}
const referenceLine = dashedLine(
0x8aa0b6,
[
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, -0.78, 0)
]
);
guideGroup.add(referenceLine);
const currentAxisLine = dashedLine(
0x58c7ff,
[
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, -0.78, 0)
]
);
guideGroup.add(currentAxisLine);
const femurAxisLine = dashedLine(
0xd9c8a4,
[
new THREE.Vector3(0, 0.12, 0),
new THREE.Vector3(0, 1.29, 0)
]
);
guideGroup.add(femurAxisLine);
const arcGeometry = new THREE.BufferGeometry();
const arcPositions = new Float32Array(65 * 3);
arcGeometry.setAttribute(
"position",
new THREE.BufferAttribute(arcPositions, 3)
);
const arc = new THREE.Line(
arcGeometry,
new THREE.LineBasicMaterial({
color: 0x58c7ff,
transparent: true,
opacity: 0.95,
depthTest: false
})
);
arc.renderOrder = 21;
guideGroup.add(arc);
// Fixed hinge-axis pin, aligned with local Z.
const axisPin = new THREE.Mesh(
new THREE.CylinderGeometry(0.014, 0.014, 0.56, 8),
new THREE.MeshBasicMaterial({
color: 0x58c7ff,
transparent: true,
opacity: 0.75,
depthTest: false
})
);
axisPin.rotation.x = Math.PI / 2;
axisPin.renderOrder = 22;
guideGroup.add(axisPin);
function updateGuides(angleDegrees) {
const angle = angleDegrees * DEG;
const direction = new THREE.Vector3(
Math.sin(angle),
-Math.cos(angle),
0
);
currentAxisLine.geometry.setFromPoints([
new THREE.Vector3(0, 0, 0),
direction.clone().multiplyScalar(0.78)
]);
currentAxisLine.computeLineDistances();
const steps = 64;
for (let i = 0; i <= steps; i++) {
const a = -Math.PI / 2 + angle * (i / steps);
arcPositions[i * 3] = Math.cos(a) * 0.52;
arcPositions[i * 3 + 1] = Math.sin(a) * 0.52;
arcPositions[i * 3 + 2] = 0;
}
arcGeometry.attributes.position.needsUpdate = true;
arcGeometry.setDrawRange(0, steps + 1);
arcGeometry.computeBoundingSphere();
}
// Collision proxy -----------------------------------------------------
/*
Conservative tapered capsule proxies around the two shaft axes.
Radii match the visible shaft radii at their endpoints and are
interpolated between endpoints. A 0.018 scene-unit separation is
additionally required. The intentionally overlapping joint housing
and endpoint ornaments are not part of the rigid-shaft collision model.
*/
const CLEARANCE = 0.018;
const FEMUR_A = new THREE.Vector3(0, KNEE_HEIGHT + 0.18, 0);
const FEMUR_B = new THREE.Vector3(0, KNEE_HEIGHT + 1.18, 0);
const FEMUR_RA = 0.095;
const FEMUR_RB = 0.145;
const TIBIA_A_LOCAL = new THREE.Vector3(0, -0.17, 0);
const TIBIA_B_LOCAL = new THREE.Vector3(0, -1.17, 0);
const TIBIA_RA = 0.095;
const TIBIA_RB = 0.12;
function closestPointOnSegment(point, a, b, result) {
const ab = b.clone().sub(a);
const lengthSq = ab.lengthSq();
if (lengthSq < 1e-12) {
result.copy(a);
return 0;
}
const t = THREE.MathUtils.clamp(
point.clone().sub(a).dot(ab) / lengthSq,
0,
1
);
result.copy(a).addScaledVector(ab, t);
return t;
}
function minimumClearance(angleDegrees) {
const angle = angleDegrees * DEG;
const c = Math.cos(angle);
const s = Math.sin(angle);
// Rotation about the fixed mediolateral Z axis.
const tibiaA = new THREE.Vector3(
-TIBIA_A_LOCAL.y * s,
KNEE_HEIGHT + TIBIA_A_LOCAL.y * c,
0
);
const tibiaB = new THREE.Vector3(
-TIBIA_B_LOCAL.y * s,
KNEE_HEIGHT + TIBIA_B_LOCAL.y * c,
0
);
let minimumMargin = Infinity;
const samples = 96;
const closest = new THREE.Vector3();
// Sample the femur axis and project onto the tibia axis.
for (let i = 0; i <= samples; i++) {
const u = i / samples;
const p = FEMUR_A.clone().lerp(FEMUR_B, u);
const t = closestPointOnSegment(p, tibiaA, tibiaB, closest);
const femurRadius = THREE.MathUtils.lerp(
FEMUR_RA,
FEMUR_RB,
u
);
const tibiaRadius = THREE.MathUtils.lerp(
TIBIA_RA,
TIBIA_RB,
t
);
const margin =
p.distanceTo(closest) -
femurRadius -
tibiaRadius -
CLEARANCE;
minimumMargin = Math.min(minimumMargin, margin);
}
// Sample in the opposite direction to avoid missing an interior pair.
for (let i = 0; i <= samples; i++) {
const u = i / samples;
const p = tibiaA.clone().lerp(tibiaB, u);
const t = closestPointOnSegment(p, FEMUR_A, FEMUR_B, closest);
const tibiaRadius = THREE.MathUtils.lerp(
TIBIA_RA,
TIBIA_RB,
u
);
const femurRadius = THREE.MathUtils.lerp(
FEMUR_RA,
FEMUR_RB,
t
);
const margin =
p.distanceTo(closest) -
femurRadius -
tibiaRadius -
CLEARANCE;
minimumMargin = Math.min(minimumMargin, margin);
}
return minimumMargin;
}
// Find the first unsafe angle. The rig cannot sweep through it.
let safeLimit = 0;
for (let angle = 0; angle <= MAX_REQUESTED; angle += 0.5) {
if (minimumClearance(angle) < 0) {
break;
}
safeLimit = angle;
}
// Pose and status ------------------------------------------------------
function applyPose() {
const requested = Number(ui.slider.value);
const limited = requested > safeLimit + 0.001;
const applied = limited ? safeLimit : requested;
tibiaPivot.rotation.z = applied * DEG;
updateGuides(applied);
const margin = minimumClearance(applied);
ui.angle.textContent = `${applied.toFixed(1)}°`;
ui.requested.textContent =
`Requested ${requested.toFixed(0)}°`;
if (limited) {
ui.status.classList.add("warning");
ui.status.innerHTML = `
<strong>Request limited by model clearance</strong>
Applied ${applied.toFixed(1)}° instead of ${requested.toFixed(0)}°.
This model's conservative safe limit is ${safeLimit.toFixed(1)}°.
`;
} else {
ui.status.classList.remove("warning");
ui.status.innerHTML = `
<strong>Clearance OK</strong>
The conservative shaft proxies remain separated.
Proxy margin: ${margin.toFixed(3)} scene units.
`;
}
}
ui.slider.addEventListener("input", applyPose);
ui.safeLimit.addEventListener("click", () => {
ui.slider.value = String(safeLimit);
applyPose();
});
ui.resetPose.addEventListener("click", () => {
ui.slider.value = "0";
applyPose();
});
ui.guides.addEventListener("change", () => {
guideGroup.visible = ui.guides.checked;
});
// Direct camera controls, implemented without Three.js addons ----------
let dragging = false;
let lastX = 0;
let lastY = 0;
let activePointer = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointer = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointer) {
return;
}
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desiredOrbit.theta -= dx * 0.008;
desiredOrbit.phi = THREE.MathUtils.clamp(
desiredOrbit.phi - dy * 0.006,
0.18,
Math.PI - 0.18
);
});
function endDrag(event) {
if (!dragging || event.pointerId !== activePointer) {
return;
}
dragging = false;
activePointer = null;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredOrbit.radius = THREE.MathUtils.clamp(
desiredOrbit.radius * Math.exp(event.deltaY * 0.001),
1.8,
7.5
);
},
{ passive: false }
);
function setView(name) {
if (name === "side") {
desiredOrbit.theta = 0;
desiredOrbit.phi = Math.PI / 2;
desiredOrbit.radius = 3.8;
} else if (name === "front") {
desiredOrbit.theta = Math.PI / 2;
desiredOrbit.phi = Math.PI / 2;
desiredOrbit.radius = 3.8;
} else {
desiredOrbit.theta = 0.68;
desiredOrbit.phi = 1.20;
desiredOrbit.radius = 4.5;
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
ui.resetView.addEventListener("click", () => {
setView("oblique");
});
// Resize and render loop -----------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate() {
requestAnimationFrame(animate);
const smoothing = 0.12;
currentOrbit.theta +=
(desiredOrbit.theta - currentOrbit.theta) * smoothing;
currentOrbit.phi +=
(desiredOrbit.phi - currentOrbit.phi) * smoothing;
currentOrbit.radius +=
(desiredOrbit.radius - currentOrbit.radius) * smoothing;
updateCamera();
renderer.render(scene, camera);
}
applyPose();
animate();
</script>
</body>
</html>
```