Prompt specification
Build or customize the Three.js 3D scene "Walking Character With a Hinged Cape" 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: Walking Character With a Hinged Cape
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/walking-character-with-a-hinged-cape-x3706
Scene Description Prompt:
Animate an original stylized walking character with a cape of hinged panels and bounded secondary motion. Build one HTML file using Three.js from cdnjs.
Working Three.js Starter (walking-character-with-a-hinged-cape-x3706):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#101820" />
<title>The Lantern Courier — Three.js</title>
<style>
:root {
color-scheme: dark;
--ink: #eef4ec;
--muted: #a8bbb5;
--accent: #ffb35c;
--accent-2: #73d6c6;
--panel: rgba(15, 25, 31, 0.78);
--line: rgba(210, 236, 225, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101820;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 42%, rgba(4, 9, 13, 0.34) 100%),
linear-gradient(180deg, rgba(4, 10, 14, 0.22), transparent 28%);
}
.header {
position: fixed;
top: 30px;
left: 34px;
width: min(440px, calc(100vw - 68px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--accent-2);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: currentColor;
box-shadow: 0 0 12px currentColor;
}
h1 {
max-width: 410px;
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 70px);
font-weight: 500;
line-height: 0.88;
letter-spacing: -0.055em;
text-wrap: balance;
text-shadow: 0 4px 28px rgba(0, 0, 0, 0.35);
}
.description {
max-width: 370px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.spec {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 16px;
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(13, 23, 29, 0.38);
color: #c7d8d2;
font-size: 10px;
letter-spacing: 0.11em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.spec i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 10px var(--accent);
}
.controls {
position: fixed;
right: 26px;
bottom: 24px;
display: grid;
grid-template-columns: auto auto;
gap: 15px 18px;
min-width: 330px;
padding: 17px 18px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(18px) saturate(130%);
}
.control {
display: flex;
flex-direction: column;
gap: 7px;
}
.control-label {
display: flex;
justify-content: space-between;
color: #c2d2cd;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.control-label output {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 5px 0;
appearance: none;
border-radius: 999px;
outline: none;
background: #35454a;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
appearance: none;
border: 3px solid #142229;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 1px rgba(255, 179, 92, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid #142229;
border-radius: 50%;
background: var(--accent);
}
.button-row {
display: flex;
align-items: center;
gap: 8px;
}
button {
min-height: 34px;
padding: 0 12px;
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
background: rgba(255, 255, 255, 0.045);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(255, 179, 92, 0.46);
background: rgba(255, 179, 92, 0.1);
}
button:active {
transform: translateY(1px);
}
.check {
display: flex;
align-items: center;
gap: 7px;
margin-left: auto;
color: var(--muted);
font-size: 11px;
cursor: pointer;
user-select: none;
}
.check input {
width: 14px;
height: 14px;
accent-color: var(--accent);
}
.hint {
position: fixed;
bottom: 28px;
left: 34px;
color: rgba(212, 228, 222, 0.58);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.hint span {
color: var(--accent);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
z-index: 20;
background: #101820;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.header {
top: 22px;
left: 22px;
}
.description,
.spec {
display: none;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
min-width: 0;
grid-template-columns: 1fr 1fr;
}
.hint {
display: none;
}
}
@media (max-width: 480px) {
.controls {
gap: 13px;
padding: 14px;
}
.button-row {
grid-column: 1 / -1;
}
.check {
margin-left: 0;
}
h1 {
font-size: 42px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Kinetic study · 01</div>
<h1>The Lantern Courier</h1>
<p class="description">
A stylized walking figure with a segmented, hinge-driven cape. Each panel
follows the stride through a constrained spring, producing small,
believable secondary motion without losing the original silhouette.
</p>
<div class="spec"><i></i> 40 hinged panels · bounded spring motion</div>
</header>
<section class="controls" aria-label="Animation controls">
<div class="control">
<label class="control-label" for="motion">
Cape follow-through
<output id="motionValue">100%</output>
</label>
<input id="motion" type="range" min="0.25" max="1.35" step="0.01" value="1" />
</div>
<div class="control">
<label class="control-label" for="speed">
Walking pace
<output id="speedValue">1.0×</output>
</label>
<input id="speed" type="range" min="0.35" max="1.65" step="0.01" value="1" />
</div>
<div class="button-row">
<button id="pause" type="button" aria-pressed="false">Pause</button>
<button id="resetCamera" type="button">Reset view</button>
<label class="check">
<input id="autoOrbit" type="checkbox" checked />
Auto orbit
</label>
</div>
</section>
<div class="hint"><span>Drag</span> to orbit · <span>Scroll / pinch</span> to zoom</div>
<div id="loading">Preparing the courier…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D scene of a stylized walking character"
);
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x101820);
scene.fog = new THREE.FogExp2(0x101820, 0.031);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
// ---------------------------------------------------------------------
// Camera controls — implemented directly, without imported add-ons.
// ---------------------------------------------------------------------
const orbit = {
azimuth: 0.48,
polar: 1.18,
radius: 7.35,
target: new THREE.Vector3(0, 1.42, 0),
auto: true
};
const initialCamera = {
azimuth: orbit.azimuth,
polar: orbit.polar,
radius: orbit.radius
};
const pointers = new Map();
let dragging = false;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
dragging = true;
orbit.auto = false;
document.querySelector("#autoOrbit").checked = false;
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = [...pointers.values()];
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size === 1 && previous.length === 1) {
const dx = current.x - previous[0].x;
const dy = current.y - previous[0].y;
orbit.azimuth -= dx * 0.006;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar - dy * 0.005,
0.48,
1.48
);
} else if (pointers.size === 2 && previous.length === 2) {
const oldDistance = Math.hypot(
previous[0].x - previous[1].x,
previous[0].y - previous[1].y
);
const newDistance = Math.hypot(
current.x - pointers.values().next().value.x,
current.y - pointers.values().next().value.y
);
if (oldDistance > 0 && newDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (oldDistance / newDistance),
4.2,
12
);
}
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
dragging = pointers.size > 0;
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
4.2,
12
);
},
{ passive: false }
);
function updateCamera(delta) {
if (orbit.auto && !dragging) {
orbit.azimuth += delta * 0.075;
}
const sinPolar = Math.sin(orbit.polar);
camera.position.set(
orbit.target.x + orbit.radius * sinPolar * Math.sin(orbit.azimuth),
orbit.target.y + orbit.radius * Math.cos(orbit.polar),
orbit.target.z + orbit.radius * sinPolar * Math.cos(orbit.azimuth)
);
camera.lookAt(orbit.target);
}
// ---------------------------------------------------------------------
// Lighting and environment.
// ---------------------------------------------------------------------
const hemi = new THREE.HemisphereLight(0xa7e3e2, 0x25191a, 2.0);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffedd0, 3.4);
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 = 20;
key.shadow.bias = -0.0005;
scene.add(key);
const rim = new THREE.PointLight(0xff7a51, 18, 12, 2);
rim.position.set(3.5, 3.8, -3.6);
scene.add(rim);
const moonLight = new THREE.PointLight(0x79d9d0, 6, 16, 2);
moonLight.position.set(-3.5, 4.2, -4.0);
scene.add(moonLight);
const material = {
teal: new THREE.MeshStandardMaterial({
color: 0x286269,
roughness: 0.73,
metalness: 0.06,
flatShading: true
}),
tealDark: new THREE.MeshStandardMaterial({
color: 0x153b43,
roughness: 0.82,
metalness: 0.04,
flatShading: true
}),
navy: new THREE.MeshStandardMaterial({
color: 0x17252e,
roughness: 0.78,
metalness: 0.08,
flatShading: true
}),
skin: new THREE.MeshStandardMaterial({
color: 0xdca77d,
roughness: 0.82,
flatShading: true
}),
mask: new THREE.MeshStandardMaterial({
color: 0x26363d,
roughness: 0.58,
metalness: 0.18,
flatShading: true
}),
brass: new THREE.MeshStandardMaterial({
color: 0xd69b45,
roughness: 0.36,
metalness: 0.66,
flatShading: true
}),
boot: new THREE.MeshStandardMaterial({
color: 0x26343a,
roughness: 0.92,
flatShading: true
}),
eye: new THREE.MeshStandardMaterial({
color: 0xffc76d,
emissive: 0xff8b37,
emissiveIntensity: 2.5,
roughness: 0.35
}),
glow: new THREE.MeshStandardMaterial({
color: 0xffd58a,
emissive: 0xff8b32,
emissiveIntensity: 4,
roughness: 0.25
}),
ground: new THREE.MeshStandardMaterial({
color: 0x142229,
roughness: 0.96,
metalness: 0
}),
platform: new THREE.MeshStandardMaterial({
color: 0x1b3036,
roughness: 0.84,
metalness: 0.08,
flatShading: true
})
};
function mesh(
geometry,
mat,
parent,
position = [0, 0, 0],
rotation = [0, 0, 0],
scale = [1, 1, 1]
) {
const object = new THREE.Mesh(geometry, mat);
object.position.set(...position);
object.rotation.set(...rotation);
object.scale.set(...scale);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
const floor = mesh(
new THREE.PlaneGeometry(50, 50),
material.ground,
scene,
[0, -0.25, 0],
[-Math.PI / 2, 0, 0]
);
floor.castShadow = false;
const platform = mesh(
new THREE.CylinderGeometry(2.55, 2.7, 0.23, 48),
material.platform,
scene,
[0, -0.12, 0]
);
mesh(
new THREE.TorusGeometry(2.51, 0.025, 6, 80),
material.brass,
scene,
[0, 0.012, 0],
[Math.PI / 2, 0, 0]
);
for (let i = 0; i < 16; i += 1) {
const angle = (i / 16) * Math.PI * 2;
const radius = 2.27;
mesh(
new THREE.BoxGeometry(0.055, 0.018, 0.22),
i % 4 === 0 ? material.brass : material.tealDark,
scene,
[
Math.sin(angle) * radius,
0.012,
Math.cos(angle) * radius
],
[0, angle, 0]
);
}
// A simple faceted moon and distant terrain.
mesh(
new THREE.IcosahedronGeometry(1.05, 2),
new THREE.MeshBasicMaterial({ color: 0xb4d9d0 }),
scene,
[-4.3, 5.0, -10]
);
const mountainMat = new THREE.MeshStandardMaterial({
color: 0x17272e,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 13; i += 1) {
const angle = -2.75 + i * 0.43;
const radius = 12 + (i % 3) * 1.8;
const height = 2.6 + (i % 4) * 0.75;
mesh(
new THREE.ConeGeometry(1.6 + (i % 2) * 0.55, height, 5),
mountainMat,
scene,
[
Math.sin(angle) * radius,
height * 0.5 - 0.2,
-Math.cos(angle) * radius - 2
],
[0, angle * 0.6, 0]
);
}
// Deterministic decorative stones and reeds.
let randomSeed = 8137;
function random() {
randomSeed |= 0;
randomSeed = (randomSeed + 0x6d2b79f5) | 0;
let value = Math.imul(randomSeed ^ (randomSeed >>> 15), 1 | randomSeed);
value = (value + Math.imul(value ^ (value >>> 7), 61 | value)) ^ value;
return ((value ^ (value >>> 14)) >>> 0) / 4294967296;
}
const stoneMat = new THREE.MeshStandardMaterial({
color: 0x26383d,
roughness: 1,
flatShading: true
});
for (let i = 0; i < 22; i += 1) {
const angle = random() * Math.PI * 2;
const radius = 3.0 + random() * 6.5;
const size = 0.12 + random() * 0.3;
mesh(
new THREE.DodecahedronGeometry(size, 0),
stoneMat,
scene,
[
Math.sin(angle) * radius,
-0.14 + size * 0.45,
Math.cos(angle) * radius
],
[random(), random() * Math.PI, random()],
[1, 0.65 + random() * 0.5, 1]
);
}
const reedMat = new THREE.MeshStandardMaterial({
color: 0x446e63,
roughness: 0.95,
flatShading: true
});
for (let i = 0; i < 10; i += 1) {
const angle = random() * Math.PI * 2;
const radius = 4.0 + random() * 5.0;
const group = new THREE.Group();
group.position.set(
Math.sin(angle) * radius,
0,
Math.cos(angle) * radius
);
group.rotation.z = (random() - 0.5) * 0.25;
scene.add(group);
mesh(
new THREE.CylinderGeometry(0.018, 0.028, 0.7 + random() * 0.7, 5),
reedMat,
group,
[0, 0.35, 0]
);
const leaf = mesh(
new THREE.ConeGeometry(0.07, 0.32, 4),
reedMat,
group,
[0.08, 0.63, 0],
[0, 0, -1.15]
);
leaf.scale.x = 0.55;
}
// ---------------------------------------------------------------------
// Character construction.
// ---------------------------------------------------------------------
const walker = new THREE.Group();
walker.rotation.order = "YXZ";
scene.add(walker);
const pelvis = mesh(
new THREE.IcosahedronGeometry(0.43, 1),
material.navy,
walker,
[0, 1.18, 0],
[0, 0, 0],
[1.05, 0.72, 0.83]
);
const torso = mesh(
new THREE.CylinderGeometry(0.42, 0.49, 0.82, 8),
material.teal,
walker,
[0, 1.65, 0]
);
torso.scale.z = 0.82;
mesh(
new THREE.OctahedronGeometry(0.3, 0),
material.tealDark,
walker,
[0, 1.72, 0.31],
[0, Math.PI / 4, 0],
[1, 1.08, 0.35]
);
mesh(
new THREE.TorusGeometry(0.445, 0.055, 6, 18),
material.brass,
walker,
[0, 1.29, 0],
[Math.PI / 2, 0, 0],
[1, 1, 0.86]
);
const beltClasp = mesh(
new THREE.OctahedronGeometry(0.105, 0),
material.brass,
walker,
[0, 1.29, 0.42],
[0, Math.PI / 4, 0],
[1, 1.2, 0.45]
);
// Collar and neck.
mesh(
new THREE.TorusGeometry(0.31, 0.105, 6, 18),
material.brass,
walker,
[0, 2.06, 0.015],
[Math.PI / 2, 0, 0],
[1.1, 1, 0.86]
);
mesh(
new THREE.CylinderGeometry(0.13, 0.15, 0.18, 8),
material.skin,
walker,
[0, 2.14, 0]
);
// Head, mask, hood, and small leaf ornament.
const head = new THREE.Group();
head.position.set(0, 2.42, 0.015);
walker.add(head);
mesh(
new THREE.IcosahedronGeometry(0.35, 1),
material.skin,
head,
[0, 0, 0],
[0, 0, 0],
[0.91, 1.05, 0.88]
);
mesh(
new THREE.IcosahedronGeometry(0.30, 1),
material.mask,
head,
[0, -0.035, 0.235],
[0, 0, 0],
[0.92, 0.69, 0.28]
);
mesh(
new THREE.SphereGeometry(0.375, 10, 5, 0, Math.PI * 2, 0, Math.PI / 2),
material.tealDark,
head,
[0, 0.095, -0.015],
[0, 0, 0],
[1, 0.78, 0.92]
);
mesh(
new THREE.SphereGeometry(0.045, 8, 6),
material.eye,
head,
[-0.105, 0.01, 0.325]
);
mesh(
new THREE.SphereGeometry(0.045, 8, 6),
material.eye,
head,
[0.105, 0.01, 0.325]
);
mesh(
new THREE.ConeGeometry(0.075, 0.32, 5),
material.brass,
head,
[0.17, 0.37, -0.05],
[0, 0, -0.48]
);
// Legs.
function createLeg(side) {
const hip = new THREE.Group();
hip.position.set(side * 0.18, 1.17, 0);
walker.add(hip);
mesh(
new THREE.SphereGeometry(0.15, 8, 6),
material.navy,
hip
);
mesh(
new THREE.CylinderGeometry(0.135, 0.15, 0.52, 7),
material.navy,
hip,
[0, -0.26, 0]
);
const knee = new THREE.Group();
knee.position.set(0, -0.52, 0);
hip.add(knee);
mesh(
new THREE.SphereGeometry(0.13, 8, 6),
material.boot,
knee
);
mesh(
new THREE.CylinderGeometry(0.105, 0.125, 0.50, 7),
material.boot,
knee,
[0, -0.25, 0]
);
const foot = new THREE.Group();
foot.position.set(0, -0.50, 0);
knee.add(foot);
mesh(
new THREE.BoxGeometry(0.29, 0.18, 0.49),
material.boot,
foot,
[0, -0.085, 0.115],
[0, 0, 0],
[1, 1, 1]
);
mesh(
new THREE.BoxGeometry(0.30, 0.055, 0.50),
material.brass,
foot,
[0, -0.16, 0.115]
);
return { hip, knee, foot };
}
const leftLeg = createLeg(-1);
const rightLeg = createLeg(1);
// Arms and hands.
function createArm(side) {
const shoulder = new THREE.Group();
shoulder.position.set(side * 0.49, 1.94, 0.005);
walker.add(shoulder);
mesh(
new THREE.SphereGeometry(0.13, 8, 6),
material.teal,
shoulder
);
mesh(
new THREE.CylinderGeometry(0.10, 0.115, 0.43, 7),
material.teal,
shoulder,
[0, -0.215, 0]
);
const elbow = new THREE.Group();
elbow.position.set(0, -0.43, 0);
shoulder.add(elbow);
mesh(
new THREE.SphereGeometry(0.105, 8, 6),
material.brass,
elbow
);
mesh(
new THREE.CylinderGeometry(0.085, 0.10, 0.40, 7),
material.skin,
elbow,
[0, -0.20, 0]
);
const hand = new THREE.Group();
hand.position.set(0, -0.42, 0);
elbow.add(hand);
mesh(
new THREE.IcosahedronGeometry(0.115, 1),
material.skin,
hand,
[0, -0.02, 0],
[0, 0, 0],
[0.82, 1.1, 0.8]
);
return { shoulder, elbow, hand };
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
// A small lantern carried by the left hand.
const lanternSwing = new THREE.Group();
lanternSwing.position.set(0, -0.09, 0.08);
leftArm.hand.add(lanternSwing);
mesh(
new THREE.TorusGeometry(0.055, 0.012, 5, 10),
material.brass,
lanternSwing,
[0, 0.01, 0],
[Math.PI / 2, 0, 0]
);
mesh(
new THREE.CylinderGeometry(0.09, 0.10, 0.17, 8, 1, true),
material.brass,
lanternSwing,
[0, -0.105, 0]
);
mesh(
new THREE.SphereGeometry(0.067, 10, 8),
material.glow,
lanternSwing,
[0, -0.10, 0]
);
mesh(
new THREE.CylinderGeometry(0.115, 0.09, 0.05, 8),
material.brass,
lanternSwing,
[0, -0.21, 0]
);
const lanternLight = new THREE.PointLight(0xff9b42, 1.4, 3.2, 2);
lanternLight.position.set(0, -0.1, 0);
lanternSwing.add(lanternLight);
// A small messenger bag.
const satchel = new THREE.Group();
satchel.position.set(0.47, 1.31, -0.03);
satchel.rotation.z = -0.13;
walker.add(satchel);
mesh(
new THREE.BoxGeometry(0.32, 0.37, 0.22),
material.boot,
satchel
);
mesh(
new THREE.BoxGeometry(0.34, 0.13, 0.235),
material.brass,
satchel,
[0, 0.085, 0.006]
);
// ---------------------------------------------------------------------
// Hinged cape.
//
// Five columns and eight rows form forty tapered panels. Each row is
// attached to the row above at a local pivot. Spring dynamics update
// only the hinge angles, and every angle is explicitly clamped.
// ---------------------------------------------------------------------
const capeAnchor = new THREE.Group();
capeAnchor.position.set(0, 2.08, -0.39);
walker.add(capeAnchor);
const capeRows = 8;
const capeColumns = 5;
const panelHeight = 0.235;
const hinges = [];
const capePalette = [
0xc4513f,
0xd05a42,
0xb9473b,
0xd66747,
0xc95740
];
function createPanelGeometry(
topLeft,
topRight,
bottomLeft,
bottomRight,
height,
thickness
) {
const front = thickness * 0.5;
const back = -thickness * 0.5;
const positions = [
topLeft, 0, front,
topRight, 0, front,
bottomRight, -height, front,
bottomLeft, -height, front,
topLeft, 0, back,
topRight, 0, back,
bottomRight, -height, back,
bottomLeft, -height, back
];
const indices = [
0, 1, 2, 0, 2, 3,
4, 6, 5, 4, 7, 6,
0, 4, 5, 0, 5, 1,
1, 5, 6, 1, 6, 2,
3, 2, 6, 3, 6, 7,
0, 3, 7, 0, 7, 4
];
let geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
const nonIndexed = geometry.toNonIndexed();
nonIndexed.computeVertexNormals();
geometry.dispose();
return nonIndexed;
}
function widthAt(row) {
return THREE.MathUtils.lerp(0.30, 0.42, row / capeRows);
}
for (let column = 0; column < capeColumns; column += 1) {
const topWidth = widthAt(0);
const topCenter = (column - (capeColumns - 1) / 2) * topWidth;
let chain = new THREE.Group();
chain.position.set(topCenter, 0, 0);
capeAnchor.add(chain);
for (let row = 0; row < capeRows; row += 1) {
const currentWidth = widthAt(row);
const nextWidth = widthAt(row + 1);
const currentCenter =
(column - (capeColumns - 1) / 2) * currentWidth;
const nextCenter =
(column - (capeColumns - 1) / 2) * nextWidth;
const topLeft = currentCenter - currentWidth * 0.5;
const topRight = currentCenter + currentWidth * 0.5;
const bottomLeft = nextCenter - nextWidth * 0.5;
const bottomRight = nextCenter + nextWidth * 0.5;
const geometry = createPanelGeometry(
topLeft - currentCenter,
topRight - currentCenter,
bottomLeft - currentCenter,
bottomRight - currentCenter,
panelHeight,
0.055
);
const color = new THREE.Color(capePalette[column]);
color.offsetHSL(
0,
row % 2 === 0 ? 0 : -0.035,
(row - capeRows * 0.5) * 0.012
);
const panelMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02,
flatShading: true
});
const panel = mesh(geometry, panelMaterial, chain);
panel.position.z = -row * 0.007;
// Visible hinge pin.
mesh(
new THREE.CylinderGeometry(
0.019,
0.019,
currentWidth * 0.88,
6
),
material.brass,
chain,
[0, 0, 0.035],
[0, 0, Math.PI / 2]
);
// Thin lower edge, making the panel construction readable.
mesh(
new THREE.BoxGeometry(
nextWidth * 0.96,
0.025,
0.068
),
row % 2 === 0 ? material.brass : material.tealDark,
chain,
[
nextCenter - currentCenter,
-panelHeight,
-row * 0.007
]
);
const hinge = {
group: chain,
row,
column,
sign: column < capeColumns / 2 ? -1 : 1,
x: 0,
y: 0,
z: 0,
vx: 0,
vy: 0,
vz: 0
};
hinges.push(hinge);
if (row < capeRows - 1) {
const nextHinge = new THREE.Group();
nextHinge.position.set(
nextCenter - currentCenter,
-panelHeight,
-0.007
);
chain.add(nextHinge);
chain = nextHinge;
}
}
}
// Decorative clasp at the top of the cape.
mesh(
new THREE.OctahedronGeometry(0.11, 0),
material.brass,
capeAnchor,
[0, -0.015, 0.08],
[0, Math.PI / 4, 0],
[1, 1.25, 0.45]
);
// ---------------------------------------------------------------------
// Fireflies.
// ---------------------------------------------------------------------
const fireflyCount = 34;
const fireflyPositions = new Float32Array(fireflyCount * 3);
const fireflyBase = [];
for (let i = 0; i < fireflyCount; i += 1) {
const angle = random() * Math.PI * 2;
const radius = 2.2 + random() * 5.5;
const base = [
Math.sin(angle) * radius,
0.35 + random() * 3.8,
Math.cos(angle) * radius
];
fireflyBase.push(base);
fireflyPositions.set(base, i * 3);
}
const fireflyGeometry = new THREE.BufferGeometry();
fireflyGeometry.setAttribute(
"position",
new THREE.BufferAttribute(fireflyPositions, 3)
);
const fireflies = new THREE.Points(
fireflyGeometry,
new THREE.PointsMaterial({
color: 0xffca78,
size: 0.055,
transparent: true,
opacity: 0.85,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
scene.add(fireflies);
// ---------------------------------------------------------------------
// UI and animation.
// ---------------------------------------------------------------------
const motionInput = document.querySelector("#motion");
const speedInput = document.querySelector("#speed");
const motionValue = document.querySelector("#motionValue");
const speedValue = document.querySelector("#speedValue");
const pauseButton = document.querySelector("#pause");
const autoOrbitInput = document.querySelector("#autoOrbit");
let motionAmount = Number(motionInput.value);
let walkingSpeed = Number(speedInput.value);
let paused = false;
let simulationTime = 0;
motionInput.addEventListener("input", () => {
motionAmount = Number(motionInput.value);
motionValue.value = `${Math.round(motionAmount * 100)}%`;
});
speedInput.addEventListener("input", () => {
walkingSpeed = Number(speedInput.value);
speedValue.value = `${walkingSpeed.toFixed(1)}×`;
});
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.setAttribute("aria-pressed", String(paused));
});
autoOrbitInput.addEventListener("change", () => {
orbit.auto = autoOrbitInput.checked;
});
document.querySelector("#resetCamera").addEventListener("click", () => {
orbit.azimuth = initialCamera.azimuth;
orbit.polar = initialCamera.polar;
orbit.radius = initialCamera.radius;
orbit.target.set(0, 1.42, 0);
});
function updateSpringAxis(hinge, axis, velocityAxis, target, limit, delta) {
const stiffness = 48;
const damping = 10.5;
hinge[velocityAxis] +=
((target - hinge[axis]) * stiffness -
hinge[velocityAxis] * damping) *
delta;
hinge[axis] += hinge[velocityAxis] * delta;
if (Math.abs(hinge[axis]) > limit) {
hinge[axis] = THREE.MathUtils.clamp(hinge[axis], -limit, limit);
hinge[velocityAxis] *= -0.12;
}
}
function animateCharacter(phase, delta) {
const bob = Math.abs(Math.sin(phase)) * 0.038;
walker.position.y = 0.025 + bob;
walker.rotation.z = Math.sin(phase) * 0.014;
walker.rotation.y = Math.sin(phase * 0.5) * 0.022;
// Legs use opposite phases. Knees only bend, never invert.
const leftPhase = phase;
const rightPhase = phase + Math.PI;
leftLeg.hip.rotation.x = -Math.sin(leftPhase) * 0.49;
rightLeg.hip.rotation.x = -Math.sin(rightPhase) * 0.49;
leftLeg.knee.rotation.x =
Math.max(0, Math.sin(leftPhase + 0.9)) * 0.78;
rightLeg.knee.rotation.x =
Math.max(0, Math.sin(rightPhase + 0.9)) * 0.78;
leftLeg.foot.rotation.x =
-leftLeg.hip.rotation.x * 0.24 -
leftLeg.knee.rotation.x * 0.20;
rightLeg.foot.rotation.x =
-rightLeg.hip.rotation.x * 0.24 -
rightLeg.knee.rotation.x * 0.20;
// Arms counter the legs.
leftArm.shoulder.rotation.x =
Math.sin(leftPhase + Math.PI) * 0.43 - 0.06;
rightArm.shoulder.rotation.x =
Math.sin(rightPhase + Math.PI) * 0.43 - 0.06;
leftArm.elbow.rotation.x = -0.18;
rightArm.elbow.rotation.x = -0.18;
leftArm.shoulder.rotation.z = -0.08;
rightArm.shoulder.rotation.z = 0.08;
lanternSwing.rotation.z =
Math.sin(phase + 0.55) * 0.16 * motionAmount;
lanternSwing.rotation.x =
Math.sin(phase + 0.8) * 0.08 * motionAmount;
head.rotation.y = Math.sin(phase * 0.5) * 0.045;
head.rotation.z = Math.sin(phase + 0.4) * 0.018;
head.position.y = 2.42 + bob * 0.22;
satchel.rotation.x = Math.sin(phase + 0.3) * 0.035;
// Cape anchor motion is intentionally small.
capeAnchor.rotation.x =
Math.sin(phase + 0.25) * 0.024 * motionAmount;
capeAnchor.rotation.y =
Math.sin(phase * 0.5 - 0.2) * 0.045 * motionAmount;
capeAnchor.rotation.z =
Math.sin(phase + 0.7) * 0.018 * motionAmount;
for (const hinge of hinges) {
const rowDelay = hinge.row * 0.31;
const columnDelay = (hinge.column - 2) * 0.13;
const targetX =
Math.sin(phase - rowDelay + columnDelay) *
(0.018 + hinge.row * 0.0025) *
motionAmount;
const targetY =
Math.sin(phase * 0.55 - rowDelay * 1.4 + columnDelay) *
0.016 *
motionAmount;
const targetZ =
hinge.sign *
(0.0035 + hinge.row * 0.00115) *
motionAmount +
Math.sin(phase * 0.72 - rowDelay + columnDelay) *
0.0065 *
motionAmount;
updateSpringAxis(
hinge,
"x",
"vx",
targetX,
0.075 + hinge.row * 0.004,
delta
);
updateSpringAxis(
hinge,
"y",
"vy",
targetY,
0.034,
delta
);
updateSpringAxis(
hinge,
"z",
"vz",
targetZ,
0.042,
delta
);
hinge.group.rotation.set(hinge.x, hinge.y, hinge.z);
}
}
const clock = new THREE.Clock();
function render() {
requestAnimationFrame(render);
const delta = Math.min(clock.getDelta(), 0.04);
if (!paused) {
simulationTime += delta * walkingSpeed;
}
const phase = simulationTime * 4.4;
animateCharacter(phase, paused ? 0 : delta);
updateCamera(delta);
// Gentle firefly drift.
const positions = fireflyGeometry.attributes.position.array;
for (let i = 0; i < fireflyCount; i += 1) {
const base = fireflyBase[i];
const seed = i * 1.73;
positions[i * 3] =
base[0] + Math.sin(simulationTime * 0.43 + seed) * 0.17;
positions[i * 3 + 1] =
base[1] + Math.sin(simulationTime * 0.67 + seed * 1.4) * 0.22;
positions[i * 3 + 2] =
base[2] + Math.cos(simulationTime * 0.38 + seed) * 0.14;
}
fireflyGeometry.attributes.position.needsUpdate = true;
fireflies.material.opacity = 0.7 + Math.sin(simulationTime * 1.8) * 0.12;
renderer.render(scene, camera);
}
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(0);
render();
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```