Prompt specification
Build or customize the Three.js 3D scene "Same Task Different Character Designs" 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: Same Task Different Character Designs
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/same-task-different-character-designs-x3748
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring character roles defined by tools and activities. Create several original characters performing the same simple assembly action. Preserve task constraints while adapting reach and pose to their different geometric proportions. Voxel style.
Working Three.js Starter (same-task-different-character-designs-x3748):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Common Craft — Voxel Assembly Cell</title>
<style>
:root {
--ink: #14282b;
--panel: rgba(17, 36, 39, 0.91);
--paper: #f4f0df;
--muted: #aebfba;
--gold: #f2bd55;
--cyan: #64d7d2;
--orange: #f27b4d;
--line: rgba(244, 240, 223, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #aebbb7;
color: var(--paper);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#stage canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
background: var(--panel);
border: 1px solid var(--line);
box-shadow: 0 12px 35px rgba(9, 25, 27, 0.24);
backdrop-filter: blur(12px);
}
#brief {
top: 20px;
left: 20px;
width: min(390px, calc(100vw - 40px));
padding: 20px 22px 18px;
clip-path: polygon(0 0, calc(100% - 14px) 0, 100% 14px, 100% 100%, 0 100%);
}
.kicker {
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 8px 0 8px;
font-size: clamp(27px, 3vw, 43px);
line-height: 0.95;
letter-spacing: -0.06em;
}
h1 span {
color: var(--cyan);
}
#brief p {
margin: 0 0 15px;
max-width: 330px;
color: var(--muted);
font-size: 11px;
line-height: 1.6;
}
.constraint {
display: flex;
align-items: center;
gap: 9px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #d6dfd7;
font-size: 10px;
line-height: 1.4;
}
.constraint i {
display: grid;
flex: 0 0 auto;
place-items: center;
width: 21px;
height: 21px;
color: var(--ink);
background: var(--gold);
font-style: normal;
font-weight: 900;
}
.constraint b {
color: var(--gold);
}
#status {
top: 20px;
right: 20px;
min-width: 190px;
padding: 13px 16px;
}
#status-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 22px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#live-dot {
width: 7px;
height: 7px;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
#phase {
margin-top: 8px;
color: var(--gold);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
}
#progress-track {
height: 4px;
margin-top: 11px;
overflow: hidden;
background: rgba(255, 255, 255, 0.12);
}
#progress-fill {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--cyan), var(--gold));
}
#roles {
left: 20px;
bottom: 20px;
width: 350px;
padding: 13px;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin: 0 3px 9px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.role {
display: grid;
grid-template-columns: 8px 1fr auto;
align-items: center;
gap: 11px;
width: 100%;
min-height: 49px;
margin-top: 6px;
padding: 8px 10px;
color: var(--paper);
text-align: left;
background: rgba(255, 255, 255, 0.035);
border: 1px solid transparent;
cursor: pointer;
transition: 160ms ease;
}
.role:hover,
.role.selected {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(244, 240, 223, 0.25);
transform: translateX(2px);
}
.role-swatch {
width: 7px;
height: 29px;
}
.role-name {
display: grid;
gap: 3px;
}
.role-name b {
font-size: 11px;
letter-spacing: 0.08em;
}
.role-name small {
color: var(--muted);
font-size: 9px;
}
.role-state {
min-width: 46px;
color: var(--gold);
font-size: 8px;
font-weight: 800;
text-align: right;
letter-spacing: 0.08em;
}
#transport {
left: 50%;
bottom: 20px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
transform: translateX(-50%);
}
.control {
height: 34px;
padding: 0 12px;
color: var(--paper);
background: transparent;
border: 1px solid var(--line);
cursor: pointer;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.control:hover,
.control.active {
color: var(--ink);
background: var(--gold);
border-color: var(--gold);
}
#play {
min-width: 74px;
color: var(--ink);
background: var(--paper);
border-color: var(--paper);
}
#help {
right: 20px;
bottom: 20px;
padding: 12px 15px;
color: var(--muted);
font-size: 9px;
line-height: 1.7;
}
#help b {
color: var(--paper);
}
#loader {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
color: var(--ink);
background: #b8c5c0;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.15em;
transition: opacity 350ms ease;
}
#loader.hidden {
pointer-events: none;
opacity: 0;
}
@media (max-width: 900px) {
#brief {
width: 320px;
}
#roles {
width: 300px;
}
#help {
display: none;
}
#transport {
left: auto;
right: 20px;
transform: none;
}
}
@media (max-width: 620px) {
#brief {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 14px 16px;
}
#brief p,
.constraint {
display: none;
}
#status {
top: 123px;
right: 10px;
min-width: 156px;
}
#roles {
left: 10px;
bottom: 10px;
width: calc(100vw - 20px);
padding: 8px;
}
.role {
min-height: 39px;
padding: 5px 8px;
}
.role-name small {
display: none;
}
#transport {
right: 10px;
bottom: 190px;
flex-direction: column;
align-items: stretch;
}
.control {
height: 30px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel assembly workshop"></main>
<section id="brief" class="panel">
<div class="kicker">Assembly Cell 03 / Parallel Practice</div>
<h1>COMMON <span>CRAFT</span></h1>
<p>
Three original crafters, three tools, one identical task.
Each body adapts its stance, lean, and reach without changing the required order.
</p>
<div class="constraint">
<i>1</i>
Lift the cobalt housing
<b>→</b>
seat it on the keyed socket
<b>→</b>
secure the top fastener
</div>
</section>
<section id="status" class="panel">
<div id="status-top">
<span>Shared protocol</span>
<span id="live-dot"></span>
</div>
<div id="phase">01 / READY</div>
<div id="progress-track"><div id="progress-fill"></div></div>
</section>
<section id="roles" class="panel">
<div class="panel-heading">
<span>Craft roles</span>
<span>Select to inspect</span>
</div>
<button class="role" data-focus="0">
<span class="role-swatch" style="background:#f27b4d"></span>
<span class="role-name">
<b>POCK</b>
<small>SPARKWRIGHT / cordless driver</small>
</span>
<span class="role-state">READY</span>
</button>
<button class="role" data-focus="1">
<span class="role-swatch" style="background:#70d4cd"></span>
<span class="role-name">
<b>BRAMBLE</b>
<small>PIPE MENDER / adjustable wrench</small>
</span>
<span class="role-state">READY</span>
</button>
<button class="role" data-focus="2">
<span class="role-swatch" style="background:#e9bd55"></span>
<span class="role-name">
<b>MICA</b>
<small>PANEL JOINER / joiner's mallet</small>
</span>
<span class="role-state">READY</span>
</button>
</section>
<section id="transport" class="panel">
<button id="play" class="control">Pause</button>
<button id="replay" class="control">Replay</button>
<button id="all" class="control active">All cells</button>
</section>
<section id="help" class="panel">
<b>DRAG</b> orbit <b>SCROLL</b> zoom<br>
<b>DOUBLE-CLICK</b> reset camera
</section>
<div id="loader">BUILDING ASSEMBLY CELL…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.6));
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.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaebbb7);
scene.fog = new THREE.Fog(0xaebbb7, 31, 58);
const camera = new THREE.OrthographicCamera(-10, 10, 7, -7, 0.1, 100);
const cameraState = {
yaw: 0.52,
pitch: 0.50,
radius: 24,
zoom: 1,
zoomGoal: 1,
target: new THREE.Vector3(0, 1.35, 1.7),
targetGoal: new THREE.Vector3(0, 1.35, 1.7)
};
const hemi = new THREE.HemisphereLight(0xe9f4e8, 0x50645f, 2.0);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd1, 3.1);
sun.position.set(-8, 15, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x93c8ff, 1.15);
fill.position.set(11, 7, -7);
scene.add(fill);
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const yAxis = new THREE.Vector3(0, 1, 0);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0,
flatShading: true,
...options
});
}
const MAT = {
floorA: material(0x9faeaa),
floorB: material(0xa9b6b1),
floorEdge: material(0x6f817e),
wall: material(0x526d69),
wallDark: material(0x3d5654),
wallTrim: material(0x78918b),
navy: material(0x233b40),
ink: material(0x14282b),
steel: material(0xaab8b5, { metalness: 0.48, roughness: 0.5 }),
darkSteel: material(0x536864, { metalness: 0.42, roughness: 0.62 }),
wood: material(0xb98b60),
woodLight: material(0xd0a676),
cream: material(0xf0ead6),
gold: material(0xf0b94e, { metalness: 0.15, roughness: 0.58 }),
cobalt: material(0x3e78dc),
cobaltDark: material(0x2857a5),
cyan: material(0x69d7d1),
orange: material(0xf27b4d),
red: material(0xc94e47),
white: material(0xf3f1df)
};
function box(w, h, d, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(unitBox, mat);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function setSegment(mesh, start, end, width, depth) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.scale.set(width, length, depth);
}
function clamp01(v) {
return Math.min(1, Math.max(0, v));
}
function smooth(a, b, value) {
const x = clamp01((value - a) / (b - a));
return x * x * (3 - 2 * x);
}
function mix(a, b, t) {
return a + (b - a) * t;
}
function solveJoint(start, end, upperLength, lowerLength, pole) {
const direction = new THREE.Vector3().subVectors(end, start);
const actualDistance = Math.max(direction.length(), 0.0001);
const directionUnit = direction.clone().normalize();
const distance = THREE.MathUtils.clamp(
actualDistance,
Math.abs(upperLength - lowerLength) + 0.0001,
upperLength + lowerLength - 0.0001
);
const along =
(upperLength * upperLength -
lowerLength * lowerLength +
distance * distance) /
(2 * distance);
const height = Math.sqrt(
Math.max(0, upperLength * upperLength - along * along)
);
let poleDirection = pole
.clone()
.addScaledVector(directionUnit, -pole.dot(directionUnit));
if (poleDirection.lengthSq() < 0.00001) {
poleDirection = new THREE.Vector3(1, 0, 0);
}
poleDirection.normalize();
const joint = start
.clone()
.addScaledVector(directionUnit, along)
.addScaledVector(poleDirection, height);
return joint;
}
function makeTextSprite(title, subtitle, accent, width = 2.7) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 190;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#14282b";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 12, canvas.height);
ctx.fillRect(0, 0, canvas.width, 7);
ctx.fillStyle = "#f4f0df";
ctx.font = "900 54px monospace";
ctx.fillText(title, 34, 76);
ctx.fillStyle = accent;
ctx.font = "700 25px monospace";
ctx.fillText(subtitle, 36, 126);
ctx.fillStyle = "rgba(244,240,223,0.5)";
ctx.fillRect(36, 151, 555, 3);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
})
);
sprite.scale.set(width, width * 190 / 640, 1);
return sprite;
}
// -------------------------------------------------------------------------
// Workshop set
// -------------------------------------------------------------------------
const floor = box(
22,
0.6,
16,
MAT.floorEdge,
0,
-0.38,
2
);
floor.receiveShadow = true;
for (let xIndex = 0; xIndex < 11; xIndex++) {
for (let zIndex = 0; zIndex < 8; zIndex++) {
const tile = box(
1.96,
0.08,
1.96,
(xIndex + zIndex) % 2 === 0 ? MAT.floorA : MAT.floorB,
-10 + xIndex * 2,
-0.035,
-5 + zIndex * 2
);
tile.receiveShadow = true;
}
}
box(22, 5.5, 0.35, MAT.wall, 0, 2.35, -5.65);
box(22, 0.30, 0.55, MAT.wallTrim, 0, 0.15, -5.55);
box(22, 0.30, 0.55, MAT.wallDark, 0, 4.95, -5.55);
for (let x = -10; x <= 10; x += 2.5) {
box(0.15, 4.7, 0.18, MAT.wallDark, x, 2.4, -5.40);
}
// Back-wall pegboard and storage.
box(7.6, 2.1, 0.18, MAT.wallDark, -4.4, 2.75, -5.30);
for (let x = -7.8; x <= -1; x += 0.42) {
for (let y = 1.9; y <= 3.55; y += 0.42) {
box(0.07, 0.07, 0.05, MAT.ink, x, y, -5.18);
}
}
box(7.9, 0.16, 0.95, MAT.wood, -4.4, 1.38, -5.05);
box(7.9, 0.16, 0.95, MAT.wood, -4.4, 3.85, -5.05);
for (let i = 0; i < 8; i++) {
const crate = box(
0.72,
0.62,
0.72,
i % 2 ? MAT.cyan : MAT.gold,
-7.7 + i * 0.92,
1.78,
-5.00
);
box(0.08, 0.67, 0.76, MAT.ink, crate.position.x, 1.78, -5.00);
}
for (let i = 0; i < 5; i++) {
box(0.62, 0.78, 0.62, i % 2 ? MAT.red : MAT.orange, 6.0 + i * 0.83, 1.87, -5.0);
}
// A large workshop sign.
const workshopSign = makeTextSprite(
"COMMON CRAFT",
"PARALLEL ASSEMBLY CELL / 03",
"#f2bd55",
5.4
);
workshopSign.position.set(0.4, 4.35, -5.0);
scene.add(workshopSign);
// Cabinet and spare voxel parts.
box(2.0, 2.2, 1.3, MAT.navy, -9.2, 1.1, -0.4);
for (let i = 0; i < 4; i++) {
box(1.75, 0.38, 0.10, MAT.wallTrim, -9.2, 0.35 + i * 0.53, 0.30);
box(0.40, 0.06, 0.07, MAT.gold, -9.2, 0.35 + i * 0.53, 0.38);
}
for (let i = 0; i < 7; i++) {
box(
0.48,
0.48,
0.48,
[MAT.cobalt, MAT.gold, MAT.cyan, MAT.orange][i % 4],
8.3 + (i % 3) * 0.62,
0.25 + Math.floor(i / 3) * 0.49,
-1.8 + Math.floor(i / 3) * 0.75
);
}
// -------------------------------------------------------------------------
// Character and tool construction
// -------------------------------------------------------------------------
function makeTool(type, accent) {
const anchor = new THREE.Group();
scene.add(anchor);
const group = new THREE.Group();
anchor.add(group);
let spinningBit = null;
if (type === "drill") {
box(0.48, 0.25, 0.28, MAT.orange, 0, -0.11, 0, group);
box(0.14, 0.44, 0.20, MAT.ink, -0.08, -0.38, 0, group);
box(0.33, 0.13, 0.29, MAT.cyan, -0.08, -0.60, 0, group);
spinningBit = box(0.065, 0.34, 0.065, MAT.steel, 0.12, -0.39, 0, group);
box(0.12, 0.08, 0.08, accent, 0.12, -0.58, 0, group);
} else if (type === "wrench") {
box(0.13, 0.49, 0.13, MAT.steel, 0, -0.24, 0, group);
box(0.34, 0.12, 0.14, MAT.steel, 0, -0.47, 0, group);
box(0.10, 0.23, 0.14, MAT.steel, -0.11, -0.56, 0, group);
box(0.10, 0.23, 0.14, MAT.steel, 0.11, -0.56, 0, group);
box(0.19, 0.12, 0.15, MAT.cobalt, 0, -0.04, 0, group);
} else {
box(0.105, 0.53, 0.105, MAT.woodLight, 0, -0.25, 0, group);
box(0.48, 0.20, 0.22, MAT.red, 0, -0.48, 0, group);
box(0.18, 0.16, 0.19, MAT.gold, 0, -0.04, 0, group);
}
return {
anchor,
group,
spinningBit,
workLength: type === "drill" ? 0.62 : type === "wrench" ? 0.68 : 0.60
};
}
function createCharacter(config) {
config = {
...config, torsoWidth: config.torsoW, torsoDepth: config.torsoD,
shirt: material(config.shirt), pants: material(config.pants),
skin: material(config.skin), accent: material(config.accent)
};
const root = new THREE.Group();
root.position.set(config.x, 0, 2.95);
scene.add(root);
const torso = new THREE.Group();
torso.position.y = config.hipY;
root.add(torso);
box(
config.hipWidth * 1.18,
0.24,
config.torsoDepth * 0.96,
MAT.navy,
0,
-0.02,
0,
torso
);
box(
config.torsoWidth,
config.torsoH,
config.torsoDepth,
config.shirt,
0,
config.torsoH / 2,
0,
torso
);
// Overall bib and straps.
box(
config.torsoWidth * 0.64,
config.torsoH * 0.50,
0.045,
config.pants,
0,
config.torsoH * 0.25,
config.torsoDepth / 2 + 0.025,
torso
);
for (const side of [-1, 1]) {
box(
0.10,
config.torsoH * 0.73,
0.05,
config.pants,
side * config.torsoWidth * 0.25,
config.torsoH * 0.57,
config.torsoDepth / 2 + 0.028,
torso
);
}
// Head.
const head = new THREE.Group();
head.position.y = config.torsoH + config.headSize / 2;
torso.add(head);
box(
config.headSize,
config.headSize,
config.headSize,
config.skin,
0,
0,
0,
head
);
box(
config.headSize * 0.16,
config.headSize * 0.16,
0.035,
MAT.ink,
-config.headSize * 0.20,
config.headSize * 0.08,
config.headSize / 2 + 0.018,
head
);
box(
config.headSize * 0.16,
config.headSize * 0.16,
0.035,
MAT.ink,
config.headSize * 0.20,
config.headSize * 0.08,
config.headSize / 2 + 0.018,
head
);
box(
config.headSize * 0.28,
0.05,
0.04,
config.skin,
0,
-config.headSize * 0.13,
config.headSize / 2 + 0.022,
head
);
// Distinct role-defining headwear.
if (config.type === "drill") {
box(
config.headSize * 1.08,
config.headSize * 0.24,
config.headSize * 1.03,
config.accent,
0,
config.headSize * 0.54,
0,
head
);
box(
config.headSize * 1.20,
config.headSize * 0.10,
config.headSize * 0.48,
config.accent,
0,
config.headSize * 0.43,
config.headSize * 0.67,
head
);
} else if (config.type === "wrench") {
box(
config.headSize * 0.95,
config.headSize * 0.28,
config.headSize * 0.94,
config.accent,
0,
config.headSize * 0.49,
-0.03,
head
);
box(
config.headSize * 1.16,
config.headSize * 0.08,
config.headSize * 0.44,
MAT.navy,
0,
config.headSize * 0.43,
config.headSize * 0.62,
head
);
} else {
box(
config.headSize * 1.04,
config.headSize * 0.34,
config.headSize * 1.01,
config.accent,
0,
config.headSize * 0.48,
0,
head
);
box(
config.headSize * 1.05,
config.headSize * 0.12,
config.headSize * 1.03,
MAT.cream,
0,
config.headSize * 0.37,
0,
head
);
}
// Backpack/tool pouch.
box(
config.torsoWidth * 0.68,
config.torsoH * 0.48,
0.20,
config.accent,
0,
config.torsoH * 0.40,
-config.torsoDepth / 2 - 0.11,
torso
);
const arms = {};
const legs = {};
for (const side of [-1, 1]) {
const sideName = side > 0 ? "right" : "left";
arms[sideName] = {
upper: new THREE.Mesh(unitBox, config.shirt),
lower: new THREE.Mesh(unitBox, config.skin),
hand: new THREE.Group()
};
arms[sideName].upper.castShadow = true;
arms[sideName].lower.castShadow = true;
scene.add(arms[sideName].upper);
scene.add(arms[sideName].lower);
scene.add(arms[sideName].hand);
box(
0.19,
0.17,
0.18,
config.skin,
0,
0,
0,
arms[sideName].hand
);
legs[sideName] = {
upper: new THREE.Mesh(unitBox, config.pants),
lower: new THREE.Mesh(unitBox, config.pants),
foot: box(
0.32,
0.22,
0.47,
MAT.ink,
side * config.footX,
0.12,
0.12,
root
)
};
legs[sideName].upper.castShadow = true;
legs[sideName].lower.castShadow = true;
root.add(legs[sideName].upper);
root.add(legs[sideName].lower);
}
const tool = makeTool(config.type, config.accent);
return {
config,
root,
torso,
head,
arms,
legs,
tool
};
}
// -------------------------------------------------------------------------
// Assembly stations
// -------------------------------------------------------------------------
const BENCH_TOP = 1.05;
const BENCH_Z = 4.0;
const CUBE_SIZE = 0.50;
const CUBE_Y = BENCH_TOP + 0.29;
const characterConfigs = [
{
name: "POCK",
role: "SPARKWRIGHT",
type: "drill",
x: -6,
accent: 0xf27b4d,
shirt: 0xe8a04f,
pants: 0x2c6e70,
skin: 0x9b6045,
hipY: 0.98,
torsoH: 0.76,
torsoW: 0.91,
torsoD: 0.55,
headSize: 0.58,
shoulderX: 0.45,
hipWidth: 0.27,
footX: 0.29,
armUpper: 0.64,
armLower: 0.60,
legUpper: 0.48,
legLower: 0.48,
lean: 0.43,
offset: 0
},
{
name: "BRAMBLE",
role: "PIPE MENDER",
type: "wrench",
x: 0,
accent: 0x70d4cd,
shirt: 0x7fb9ad,
pants: 0x244b58,
skin: 0xc98761,
hipY: 1.28,
torsoH: 1.02,
torsoW: 0.61,
torsoD: 0.45,
headSize: 0.56,
shoulderX: 0.33,
hipWidth: 0.21,
footX: 0.24,
armUpper: 0.86,
armLower: 0.82,
legUpper: 0.67,
legLower: 0.64,
lean: 0.14,
offset: 0.035
},
{
name: "MICA",
role: "PANEL JOINER",
type: "mallet",
x: 6,
accent: 0xe9bd55,
shirt: 0xd16d58,
pants: 0x725a3c,
skin: 0x754a38,
hipY: 1.05,
torsoH: 0.88,
torsoW: 0.73,
torsoD: 0.49,
headSize: 0.60,
shoulderX: 0.39,
hipWidth: 0.25,
footX: 0.28,
armUpper: 0.72,
armLower: 0.70,
legUpper: 0.56,
legLower: 0.54,
lean: 0.28,
offset: 0.07
}
];
function makeHousing() {
const group = new THREE.Group();
box(
CUBE_SIZE,
CUBE_SIZE,
CUBE_SIZE,
MAT.cobalt,
0,
0,
0,
group
);
box(
CUBE_SIZE * 0.54,
CUBE_SIZE * 0.20,
0.045,
MAT.gold,
0,
-0.08,
CUBE_SIZE / 2 + 0.023,
group
);
box(
0.13,
0.13,
0.06,
MAT.cream,
0,
CUBE_SIZE / 2 + 0.03,
0,
group
);
box(
CUBE_SIZE + 0.025,
0.045,
CUBE_SIZE + 0.025,
MAT.cobaltDark,
0,
CUBE_SIZE / 2 - 0.045,
0,
group
);
return group;
}
const stations = [];
for (const config of characterConfigs) {
// Workbench.
box(3.25, 0.18, 1.45, MAT.woodLight, config.x, BENCH_TOP - 0.09, BENCH_Z);
box(3.05, 0.37, 0.13, MAT.navy, config.x, 0.77, BENCH_Z + 0.64);
for (const dx of [-1.28, 1.28]) {
for (const dz of [-0.53, 0.53]) {
box(
0.18,
BENCH_TOP - 0.18,
0.18,
MAT.darkSteel,
config.x + dx,
(BENCH_TOP - 0.18) / 2,
BENCH_Z + dz
);
}
}
// Colored station tab.
box(0.72, 0.19, 0.05, material(config.accent), config.x, 0.83, BENCH_Z + 0.72);
// Safety outline on the floor.
const tapeMat = material(config.accent, {
transparent: true,
opacity: 0.55
});
box(3.65, 0.025, 0.045, tapeMat, config.x, 0.035, BENCH_Z - 1.05);
box(0.045, 0.025, 2.35, tapeMat, config.x - 1.80, 0.035, BENCH_Z);
box(0.045, 0.025, 2.35, tapeMat, config.x + 1.80, 0.035, BENCH_Z);
const sourceX = config.x + 0.75;
const targetX = config.x - 0.72;
// Source tray.
box(0.82, 0.06, 0.78, MAT.darkSteel, sourceX, BENCH_TOP + 0.03, BENCH_Z);
box(0.82, 0.13, 0.055, MAT.steel, sourceX, BENCH_TOP + 0.10, BENCH_Z - 0.36);
box(0.82, 0.13, 0.055, MAT.steel, sourceX, BENCH_TOP + 0.10, BENCH_Z + 0.36);
box(0.055, 0.13, 0.78, MAT.steel, sourceX - 0.38, BENCH_TOP + 0.10, BENCH_Z);
box(0.055, 0.13, 0.78, MAT.steel, sourceX + 0.38, BENCH_TOP + 0.10, BENCH_Z);
// Keyed socket and corner alignment marks.
box(0.70, 0.065, 0.70, MAT.navy, targetX, BENCH_TOP + 0.035, BENCH_Z);
box(0.15, 0.35, 0.15, MAT.gold, targetX, BENCH_TOP + 0.19, BENCH_Z);
const marker = material(config.accent, {
emissive: config.accent,
emissiveIntensity: 0.16
});
for (const dx of [-0.32, 0.32]) {
for (const dz of [-0.32, 0.32]) {
box(0.18, 0.035, 0.05, marker, targetX + dx, BENCH_TOP + 0.085, BENCH_Z + dz);
box(0.05, 0.035, 0.18, marker, targetX + dx, BENCH_TOP + 0.085, BENCH_Z + dz);
}
}
// Transparent target volume makes the constraint legible.
const targetGeometry = new THREE.BoxGeometry(CUBE_SIZE, CUBE_SIZE, CUBE_SIZE);
const targetEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(targetGeometry),
new THREE.LineBasicMaterial({
color: config.accent,
transparent: true,
opacity: 0.65
})
);
targetEdges.position.set(targetX, CUBE_Y, BENCH_Z);
scene.add(targetEdges);
targetGeometry.dispose();
const housing = makeHousing();
housing.position.set(sourceX, CUBE_Y, BENCH_Z);
scene.add(housing);
const sign = makeTextSprite(
config.name,
config.role,
`#${new THREE.Color(config.accent).getHexString()}`,
2.7
);
sign.position.set(config.x, 3.18, 0.35);
scene.add(sign);
const character = createCharacter(config);
stations.push({
config,
character,
housing,
targetEdges,
source: new THREE.Vector3(sourceX, CUBE_Y, BENCH_Z),
target: new THREE.Vector3(targetX, CUBE_Y, BENCH_Z)
});
}
// -------------------------------------------------------------------------
// Animation: the same constrained task, adapted to different proportions
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
const duration = 10;
let elapsed = 0;
let playing = true;
let globalTime = 0;
function updateArm(character, sideName, shoulder, handPosition) {
const arm = character.arms[sideName];
const side = sideName === "right" ? 1 : -1;
const joint = solveJoint(
shoulder,
handPosition,
character.config.armUpper,
character.config.armLower,
new THREE.Vector3(side * 0.8, -0.72, 0.18)
);
setSegment(
arm.upper,
shoulder,
joint,
character.config.torsoW * 0.24,
character.config.torsoD * 0.82
);
setSegment(
arm.lower,
joint,
handPosition,
character.config.torsoW * 0.18,
character.config.torsoD * 0.72
);
arm.hand.position.copy(handPosition);
}
function updateLeg(character, sideName, hipY, focus) {
const leg = character.legs[sideName];
const side = sideName === "right" ? 1 : -1;
const hip = new THREE.Vector3(
side * character.config.hipWidth,
hipY,
0
);
const foot = new THREE.Vector3(
side * character.config.footX,
0.13,
0.12 + focus * 0.10
);
const knee = solveJoint(
hip,
foot,
character.config.legUpper,
character.config.legLower,
new THREE.Vector3(0, 0.08, 1)
);
setSegment(
leg.upper,
hip,
knee,
character.config.torsoW * 0.27,
character.config.torsoD * 0.85
);
setSegment(
leg.lower,
knee,
foot,
character.config.torsoW * 0.23,
character.config.torsoD * 0.75
);
leg.foot.position.copy(foot);
leg.foot.position.y = 0.12;
}
function updateStation(station, time) {
const { config, character, housing, source, target } = station;
const t = (time / duration + config.offset) % 1;
const pick = smooth(0.10, 0.28, t);
const carry = smooth(0.28, 0.58, t);
const place = smooth(0.44, 0.62, t);
const release = smooth(0.60, 0.70, t);
const toolAmount = smooth(0.70, 0.81, t);
let workFocus = 0;
if (t >= 0.10 && t < 0.78) {
workFocus = smooth(0.10, 0.19, t);
} else if (t >= 0.78) {
workFocus = 1;
}
// Short workers crouch and lean more; tall workers make smaller corrections.
const crouch = workFocus * (config.type === "drill" ? 0.075 : 0.035);
const lean = config.lean * workFocus;
character.root.position.z = 2.95 + workFocus * 0.08;
character.torso.position.y = config.hipY - crouch;
character.torso.rotation.x = lean;
character.head.rotation.x = -lean * 0.24;
updateLeg(character, "right", config.hipY - crouch, workFocus);
updateLeg(character, "left", config.hipY - crouch, workFocus);
const shoulderLocalY = config.torsoH * 0.76;
const rightShoulder = new THREE.Vector3(
config.shoulderX,
shoulderLocalY,
0
)
.applyEuler(character.torso.rotation)
.add(character.torso.position)
.add(character.root.position);
const leftShoulder = new THREE.Vector3(
-config.shoulderX,
shoulderLocalY,
0
)
.applyEuler(character.torso.rotation)
.add(character.torso.position)
.add(character.root.position);
const rightRest = new THREE.Vector3(
config.shoulderX * 0.94,
config.hipY + config.torsoH * 0.22,
0.13
).add(character.root.position);
const leftRest = new THREE.Vector3(
-config.shoulderX * 0.94,
config.hipY + config.torsoH * 0.22,
0.13
).add(character.root.position);
const sourceGrip = source.clone().add(new THREE.Vector3(0, 0.23, 0));
const targetGrip = target.clone().add(new THREE.Vector3(0, 0.23, 0));
const rightHand = new THREE.Vector3();
if (t < 0.30) {
rightHand.lerpVectors(rightRest, sourceGrip, pick);
} else if (t < 0.58) {
rightHand.lerpVectors(sourceGrip, targetGrip, carry);
rightHand.y += Math.sin(carry * Math.PI) * 0.34;
} else if (t < 0.70) {
rightHand.lerpVectors(targetGrip, rightRest, release);
} else {
rightHand.copy(rightRest);
}
// The housing follows the working hand only until it is seated.
if (t < 0.30) {
housing.position.copy(source);
housing.rotation.y = 0;
} else if (t < 0.58) {
housing.position.copy(rightHand).add(new THREE.Vector3(0, -0.23, 0));
housing.rotation.y = Math.sin(carry * Math.PI) * 0.38;
} else {
housing.position.copy(target);
housing.rotation.y = 0;
}
// Tool hand transitions to the top fastener only after seating is complete.
const workPosition = target.clone();
workPosition.y = target.y + CUBE_SIZE / 2 + character.tool.workLength;
const leftHand = leftRest.clone().lerp(workPosition, toolAmount);
if (config.type === "drill") {
leftHand.y += Math.sin(globalTime * 24) * 0.018 * toolAmount;
character.tool.anchor.rotation.set(
0,
Math.sin(globalTime * 5) * 0.07 * toolAmount,
0
);
if (character.tool.spinningBit) {
character.tool.spinningBit.rotation.y = globalTime * 28;
}
} else if (config.type === "wrench") {
const turn = Math.sin(globalTime * 7.5) * 0.20 * toolAmount;
leftHand.x += turn;
leftHand.z += (1 - Math.cos(globalTime * 7.5)) * 0.055 * toolAmount;
character.tool.anchor.rotation.set(0, globalTime * 5.5, 0);
} else {
const swingPhase = clamp01((t - 0.81) / 0.19);
const strike = Math.max(0, Math.sin(swingPhase * Math.PI * 4));
leftHand.x += (1 - strike) * 0.24 * toolAmount;
leftHand.y += strike * 0.10 * toolAmount;
character.tool.anchor.rotation.set(
0,
0,
-0.12 + (1 - strike) * 0.58 * toolAmount
);
}
character.tool.anchor.position.copy(leftHand);
updateArm(character, "right", rightShoulder, rightHand);
updateArm(character, "left", leftShoulder, leftHand);
station.targetEdges.material.opacity =
0.28 + 0.38 * (1 - smooth(0.62, 0.76, t));
return t;
}
// -------------------------------------------------------------------------
// Direct camera controls: no addons or OrbitControls
// -------------------------------------------------------------------------
const pointer = {
active: false,
x: 0,
y: 0
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.x = event.clientX;
pointer.y = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active) return;
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.22,
0.95
);
});
function stopPointer() {
pointer.active = false;
}
renderer.domElement.addEventListener("pointerup", stopPointer);
renderer.domElement.addEventListener("pointercancel", stopPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoomGoal = THREE.MathUtils.clamp(
cameraState.zoomGoal * Math.exp(-event.deltaY * 0.001),
0.72,
1.85
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraState.yaw = 0.52;
cameraState.pitch = 0.50;
cameraState.zoomGoal = 1;
cameraState.targetGoal.set(0, 1.35, 1.7);
selectRole(-1);
});
function updateCamera(dt) {
const blend = 1 - Math.exp(-dt * 5);
cameraState.target.lerp(cameraState.targetGoal, blend);
cameraState.zoom = THREE.MathUtils.lerp(
cameraState.zoom,
cameraState.zoomGoal,
blend
);
const horizontal = Math.cos(cameraState.pitch) * cameraState.radius;
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * horizontal,
cameraState.target.y + Math.sin(cameraState.pitch) * cameraState.radius,
cameraState.target.z + Math.cos(cameraState.yaw) * horizontal
);
camera.lookAt(cameraState.target);
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
const viewHeight = aspect < 1 ? 24 / aspect : 14;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
const roleButtons = [...document.querySelectorAll(".role")];
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const allButton = document.querySelector("#all");
const phaseElement = document.querySelector("#phase");
const progressFill = document.querySelector("#progress-fill");
function selectRole(index) {
roleButtons.forEach((button, buttonIndex) => {
button.classList.toggle("selected", buttonIndex === index);
});
allButton.classList.toggle("active", index < 0);
if (index < 0) {
cameraState.targetGoal.set(0, 1.35, 1.7);
cameraState.zoomGoal = 1;
} else {
const config = characterConfigs[index];
cameraState.targetGoal.set(config.x, 1.35, 2.85);
cameraState.zoomGoal = 1.38;
}
}
roleButtons.forEach((button) => {
button.addEventListener("click", () => {
selectRole(Number(button.dataset.focus));
});
});
allButton.addEventListener("click", () => selectRole(-1));
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
playButton.classList.toggle("active", !playing);
});
replayButton.addEventListener("click", () => {
elapsed = 0;
playing = true;
playButton.textContent = "Pause";
playButton.classList.remove("active");
});
function phaseName(t) {
if (t < 0.10) return "01 / READY";
if (t < 0.30) return "02 / LIFT";
if (t < 0.58) return "03 / CARRY";
if (t < 0.70) return "04 / SEAT";
return "05 / SECURE";
}
function characterState(t) {
if (t < 0.10) return "READY";
if (t < 0.30) return "LIFT";
if (t < 0.58) return "CARRY";
if (t < 0.70) return "SEAT";
return "LOCK";
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
globalTime += dt;
if (playing) {
elapsed = (elapsed + dt) % duration;
}
for (let i = 0; i < stations.length; i++) {
const station = stations[i];
const localTime = updateStation(station, elapsed);
const state = roleButtons[i].querySelector(".role-state");
state.textContent = characterState(localTime);
}
updateCamera(dt);
const normalized = elapsed / duration;
progressFill.style.width = `${normalized * 100}%`;
phaseElement.textContent = phaseName(normalized);
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loader").classList.add("hidden");
});
</script>
</body>
</html>
```