Prompt specification
Build or customize the Three.js 3D scene "Community Workshop With Shared Roles" 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: Community Workshop With Shared Roles
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-workshop-with-shared-roles-x3747
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring character roles defined by tools and activities. Build an original neighborhood workshop where varied characters exchange tasks and tools. Make roles legible through current actions rather than fixed costumes or demographic stereotypes. Voxel style.
Working Three.js Starter (community-workshop-with-shared-roles-x3747):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Common Ground — A Neighborhood Workshop</title>
<style>
:root {
--ink: #27312e;
--muted: #69736d;
--paper: rgba(250, 247, 238, 0.91);
--paper-solid: #faf7ee;
--line: rgba(39, 49, 46, 0.15);
--accent: #db704e;
--green: #477b62;
--shadow: 0 14px 38px rgba(43, 47, 40, 0.13);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e1d1;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
button {
font: inherit;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255,255,255,0.72);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.brand {
position: absolute;
top: 24px;
left: 24px;
width: min(380px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 18px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--accent);
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 38px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.brand-copy {
max-width: 330px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.rota {
position: absolute;
top: 174px;
left: 24px;
width: 278px;
padding: 16px;
border-radius: 17px;
}
.section-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.section-head h2 {
margin: 0;
font-size: 12px;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.live-dot::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: #5d9d77;
box-shadow: 0 0 0 4px rgba(93,157,119,0.14);
content: "";
}
#rota-list {
display: grid;
gap: 6px;
}
.rota-row {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
width: 100%;
padding: 9px 10px;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(255,255,255,0.42);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: 160ms ease;
}
.rota-row:hover,
.rota-row.selected {
border-color: rgba(219,112,78,0.38);
background: rgba(255,255,255,0.85);
transform: translateX(2px);
}
.rota-task {
display: block;
font-size: 12px;
font-weight: 800;
}
.rota-tool {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.rota-holder {
font-size: 10px;
font-weight: 800;
color: var(--accent);
}
.rotating-note {
margin: 11px 2px 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.detail {
position: absolute;
right: 24px;
bottom: 24px;
width: min(330px, calc(100vw - 48px));
padding: 18px;
border-radius: 18px;
}
.detail-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.detail h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.04em;
}
.detail-role {
margin: 3px 0 0;
color: var(--accent);
font-size: 12px;
font-weight: 800;
}
.tool-badge {
flex: 0 0 auto;
padding: 7px 9px;
border-radius: 9px;
background: #eee6d6;
color: #5d554a;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.detail p {
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.52;
}
.controls {
position: absolute;
left: 50%;
bottom: 24px;
display: flex;
gap: 8px;
padding: 7px;
border-radius: 15px;
transform: translateX(-50%);
}
.control-button {
min-height: 40px;
padding: 0 14px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--ink);
font-size: 12px;
font-weight: 800;
cursor: pointer;
transition: 150ms ease;
}
.control-button:hover {
background: rgba(39,49,46,0.08);
}
.control-button.primary {
background: var(--ink);
color: #fffdf7;
}
.control-button.primary:hover {
background: #3a4944;
}
.hint {
position: absolute;
right: 25px;
top: 24px;
padding: 10px 13px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
line-height: 1.45;
text-align: right;
}
.hint strong {
color: var(--ink);
}
.character-label {
position: absolute;
left: 0;
top: 0;
min-width: 116px;
padding: 7px 9px;
border: 1px solid rgba(255,255,255,0.85);
border-radius: 10px;
background: rgba(250,247,238,0.91);
box-shadow: 0 8px 20px rgba(43,47,40,0.13);
color: var(--ink);
text-align: center;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
white-space: nowrap;
}
.character-label::after {
position: absolute;
left: 50%;
bottom: -5px;
width: 9px;
height: 9px;
background: rgba(250,247,238,0.91);
transform: translateX(-50%) rotate(45deg);
content: "";
}
.character-label strong,
.character-label span {
display: block;
}
.character-label strong {
font-size: 11px;
}
.character-label span {
margin-top: 2px;
color: var(--accent);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.035em;
text-transform: uppercase;
}
.character-label.selected {
border-color: rgba(219,112,78,0.75);
box-shadow: 0 8px 26px rgba(219,112,78,0.2);
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #e9e1d1;
color: var(--ink);
font-size: 13px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
z-index: 20;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.brand {
top: 14px;
left: 14px;
width: 290px;
padding: 14px 16px;
}
.brand-copy { display: none; }
.rota { display: none; }
.detail {
right: 14px;
bottom: 76px;
width: 280px;
}
.controls {
bottom: 14px;
width: calc(100vw - 28px);
justify-content: center;
}
.hint { display: none; }
}
@media (max-width: 560px) {
.brand {
width: calc(100vw - 28px);
}
.brand h1 { font-size: 27px; }
.detail {
right: 14px;
bottom: 74px;
width: calc(100vw - 28px);
padding: 14px;
}
.detail p { display: none; }
.control-button {
padding: 0 10px;
font-size: 11px;
}
.character-label {
min-width: 92px;
padding: 5px 7px;
}
.character-label strong { font-size: 9px; }
.character-label span { font-size: 7px; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="An animated voxel neighborhood workshop where residents exchange tools and tasks"></canvas>
<div class="hud">
<header class="brand panel">
<p class="eyebrow">A living neighborhood workshop</p>
<h1>Common Ground</h1>
<p class="brand-copy">
Everyone shares the tools, and everyone changes jobs.
Watch the workshop rota turn five temporary roles into five new ones.
</p>
</header>
<aside class="rota panel" aria-label="Live workshop rota">
<div class="section-head">
<h2>Live skill rota</h2>
<span class="live-dot">Rotating</span>
</div>
<div id="rota-list"></div>
<p class="rotating-note">
Roles describe what someone is doing now—not who they are.
Clothes and hair are simply part of the scene.
</p>
</aside>
<aside class="detail panel" aria-live="polite">
<div class="detail-top">
<div>
<h2 id="detail-name">Mika</h2>
<p class="detail-role" id="detail-role">Calibrating a print bed</p>
</div>
<span class="tool-badge" id="detail-tool">Caliper</span>
</div>
<p id="detail-copy"></p>
</aside>
<div class="hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br />
<strong>Click</strong> a person to inspect · <strong>Space</strong> to swap
</div>
<nav class="controls panel" aria-label="Scene controls">
<button class="control-button primary" id="swap-button">Call a tool swap</button>
<button class="control-button" id="pause-button">Pause</button>
<button class="control-button" id="reset-button">Reset view</button>
</nav>
</div>
<div id="loading">Building the neighborhood…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and camera
// -------------------------------------------------------------------------
const canvas = document.querySelector("#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("#e9e1d1");
scene.fog = new THREE.Fog("#e9e1d1", 19, 34);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 80);
const cameraState = {
yaw: 0.66,
pitch: 0.72,
zoom: 1,
target: new THREE.Vector3(0, 1.05, 0)
};
const hemisphere = new THREE.HemisphereLight("#fff6de", "#817d72", 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight("#fff2d6", 3.2);
sun.position.set(-6, 12, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0007;
scene.add(sun);
const fill = new THREE.DirectionalLight("#bdd7d1", 1.1);
fill.position.set(8, 7, -5);
scene.add(fill);
// -------------------------------------------------------------------------
// Small voxel construction helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function standardMaterial(color) {
if (color?.isMaterial) return color;
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(w, h, d, x, y, z, color, parent = scene, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function groupAt(x, y, z, parent = scene) {
const group = new THREE.Group();
group.position.set(x, y, z);
parent.add(group);
return group;
}
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
const random = seededRandom(8182);
function makeTextTexture(lines, options = {}) {
const {
width = 768,
height = 192,
background = "#f6edda",
foreground = "#27312e",
accent = "#db704e",
border = true
} = options;
const textCanvas = document.createElement("canvas");
textCanvas.width = width;
textCanvas.height = height;
const ctx = textCanvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
if (background) {
ctx.fillStyle = background;
ctx.fillRect(0, 0, width, height);
}
if (border) {
ctx.strokeStyle = accent;
ctx.lineWidth = 12;
ctx.strokeRect(8, 8, width - 16, height - 16);
}
const arranged = Array.isArray(lines) ? lines : [lines];
const mainSize = options.mainSize || 62;
const subSize = options.subSize || 26;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = foreground;
ctx.font = `800 ${mainSize}px system-ui, sans-serif`;
ctx.fillText(arranged[0], width / 2, arranged.length === 1 ? height / 2 : height * 0.42);
if (arranged.length > 1) {
ctx.fillStyle = accent;
ctx.font = `800 ${subSize}px system-ui, sans-serif`;
ctx.fillText(arranged[1], width / 2, height * 0.73);
}
const texture = new THREE.CanvasTexture(textCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function textPanel(
lines,
width,
height,
position,
options = {},
parent = scene
) {
const texture = makeTextTexture(lines, options);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.position.copy(position);
parent.add(mesh);
return mesh;
}
function table(x, z, width = 2.1, depth = 1.15, topColor = "#9b7655") {
const group = groupAt(x, 0, z);
box(width, 0.16, depth, 0, 1.04, 0, topColor, group);
box(0.16, 0.95, 0.16, -width / 2 + 0.16, 0.5, -depth / 2 + 0.14, "#68584c", group);
box(0.16, 0.95, 0.16, width / 2 - 0.16, 0.5, -depth / 2 + 0.14, "#68584c", group);
box(0.16, 0.95, 0.16, -width / 2 + 0.16, 0.5, depth / 2 - 0.14, "#68584c", group);
box(0.16, 0.95, 0.16, width / 2 - 0.16, 0.5, depth / 2 - 0.14, "#68584c", group);
box(width - 0.1, 0.1, 0.12, 0, 0.42, -depth / 2 + 0.14, "#776657", group);
return group;
}
// -------------------------------------------------------------------------
// Workshop environment
// -------------------------------------------------------------------------
box(200, 0.2, 200, 0, -0.62, 0, "#d7d0c2", scene, false);
box(13.4, 0.46, 10.9, 0, -0.27, 0, "#7d796f");
const paverColors = ["#c8bda8", "#d2c8b5", "#bdb5a4", "#d8cdb8", "#c4baa8"];
for (let x = 0; x < 14; x++) {
for (let z = 0; z < 11; z++) {
const px = (x - 6.5) * 0.88;
const pz = (z - 5) * 0.88;
const offset = random() * 0.08;
box(
0.82,
0.13,
0.82,
px,
0.015 + offset * 0.02,
pz,
paverColors[Math.floor(random() * paverColors.length)],
scene,
false
);
}
}
// Back wall and side return.
box(12.8, 3.7, 0.32, 0, 1.85, -5.15, "#d8c9ad");
box(12.95, 0.2, 0.46, 0, 3.72, -5.13, "#b79c79");
box(0.3, 2.7, 3.2, -6.2, 1.35, -3.8, "#cdbfa6");
box(0.3, 1.4, 2.2, 6.2, 0.7, -4.05, "#c5b79f");
// Background neighborhood.
const neighborColors = ["#b8b6a8", "#c7a58e", "#9eaaa0", "#d0bd94", "#a9b3ad"];
for (let i = 0; i < 7; i++) {
const x = -6 + i * 2;
const h = 3.6 + random() * 2.7;
box(1.75, h, 1.7, x, h / 2 - 0.05, -7.2, neighborColors[i % neighborColors.length]);
box(1.9, 0.16, 1.85, x, h, -7.2, "#817c70");
for (let row = 0; row < 2; row++) {
box(
0.55,
0.65,
0.04,
x - 0.35,
1.5 + row * 1.65,
-6.33,
"#d9dfcf"
);
box(
0.55,
0.65,
0.04,
x + 0.35,
1.5 + row * 1.65,
-6.33,
"#d9dfcf"
);
}
}
// Main wall sign.
textPanel(
["COMMON GROUND", "NEIGHBORHOOD TOOL LIBRARY · OPEN TO ALL"],
4.35,
1.05,
new THREE.Vector3(0, 3.04, -4.96),
{
background: "#f2e7ce",
foreground: "#28322f",
accent: "#c65f43",
mainSize: 61,
subSize: 22
}
);
// Two windows and a shelf.
for (const x of [-2.55, 2.55]) {
box(1.45, 1.3, 0.12, x, 2.05, -4.9, "#c7aa7f");
box(1.2, 1.05, 0.06, x, 2.05, -4.8, "#91b8b4");
box(0.08, 1.05, 0.08, x, 2.05, -4.74, "#efe2c8");
box(1.2, 0.08, 0.08, x, 2.05, -4.74, "#efe2c8");
}
box(3.0, 0.12, 0.55, 0, 1.48, -4.7, "#8a694c");
box(3.0, 0.12, 0.55, 0, 2.42, -4.7, "#8a694c");
for (let i = 0; i < 8; i++) {
const colors = ["#d67951", "#71977c", "#d6a85c", "#6e8f9b"];
box(
0.28,
0.35 + random() * 0.22,
0.28,
-1.2 + i * 0.34,
1.72,
-4.69,
colors[i % colors.length]
);
}
// Central tool exchange plinth.
const exchange = groupAt(0, 0, 0);
box(1.05, 0.68, 1.05, 0, 0.38, 0, "#778274", exchange);
box(1.22, 0.14, 1.22, 0, 0.79, 0, "#d7b56d", exchange);
box(0.68, 0.1, 0.68, 0, 0.91, 0, "#475b52", exchange);
for (let i = 0; i < 20; i++) {
const a = (i / 20) * Math.PI * 2;
box(
0.16,
0.04,
0.16,
Math.sin(a) * 1.55,
0.12,
Math.cos(a) * 1.55,
i % 2 ? "#d9c998" : "#bfb79c",
scene,
false
);
}
textPanel(
["TOOL SWAP"],
0.95,
0.28,
new THREE.Vector3(0, 0.73, 0.635),
{
background: "#475b52",
foreground: "#fff8e8",
accent: "#fff8e8",
border: false,
mainSize: 54
}
);
// -------------------------------------------------------------------------
// Workstations
// -------------------------------------------------------------------------
const tasks = [
{
name: "Print check",
verb: "Calibrating a print bed",
tool: "caliper",
station: new THREE.Vector3(-4.2, 0, -2.35),
stand: new THREE.Vector3(-4.2, 0, -1.02),
color: "#df7653"
},
{
name: "Radio repair",
verb: "Tuning a shared radio",
tool: "wrench",
station: new THREE.Vector3(4.2, 0, -2.35),
stand: new THREE.Vector3(4.2, 0, -1.02),
color: "#5f8790"
},
{
name: "Plant care",
verb: "Potting a seedling",
tool: "trowel",
station: new THREE.Vector3(4.2, 0, 2.28),
stand: new THREE.Vector3(4.2, 0, 1.25),
color: "#668b63"
},
{
name: "Stool assembly",
verb: "Balancing a stool joint",
tool: "hammer",
station: new THREE.Vector3(-4.2, 0, 2.28),
stand: new THREE.Vector3(-4.2, 0, 1.25),
color: "#bb8b55"
},
{
name: "Pantry prep",
verb: "Scooping shared supplies",
tool: "scoop",
station: new THREE.Vector3(0, 0, -3.72),
stand: new THREE.Vector3(0, 0, -2.55),
color: "#9a6c82"
}
];
const stationAnimations = {};
// Print station.
{
const g = table(tasks[0].station.x, tasks[0].station.z, 2.05, 1.28, "#6f7772");
box(0.9, 0.08, 0.75, 0, 1.16, 0, "#374743", g);
box(0.12, 1.12, 0.12, -0.53, 1.71, -0.36, "#34423e", g);
box(0.12, 1.12, 0.12, 0.53, 1.71, -0.36, "#34423e", g);
box(0.12, 1.12, 0.12, -0.53, 1.71, 0.36, "#34423e", g);
box(0.12, 1.12, 0.12, 0.53, 1.71, 0.36, "#34423e", g);
box(1.22, 0.13, 0.92, 0, 2.33, 0, "#465650", g);
const head = box(0.26, 0.23, 0.23, 0, 1.86, 0.12, "#e29a5c", g);
stationAnimations.printHead = head;
box(0.42, 0.3, 0.05, -0.28, 2.2, 0.48, "#9ed6cf", g);
box(0.32, 0.22, 0.32, 0.53, 1.27, 0.38, "#db7654", g);
textPanel(
["PRINT CHECK"],
1.12,
0.3,
new THREE.Vector3(-4.2, 1.64, -1.69),
{
background: "#e6ded0",
foreground: "#33413c",
accent: "#d86d4a",
mainSize: 52
}
);
}
// Repair station and pegboard.
{
const g = table(tasks[1].station.x, tasks[1].station.z, 2.05, 1.28, "#856951");
box(0.88, 0.6, 0.52, 0, 1.45, -0.08, "#c2ad83", g);
box(0.58, 0.25, 0.03, -0.12, 1.52, 0.19, "#40534c", g);
for (let i = 0; i < 4; i++) {
box(0.05, 0.19, 0.03, -0.32 + i * 0.14, 1.52, 0.21, "#b9d1c6", g);
}
const knob = box(0.13, 0.13, 0.08, 0.29, 1.43, 0.21, "#d9714d", g);
stationAnimations.radioKnob = knob;
box(0.04, 0.62, 0.04, 0.25, 1.95, -0.09, "#4e554e", g);
box(2.0, 1.45, 0.1, 4.2, 2.08, -3.03, "#ae8b67");
for (let x = 0; x < 8; x++) {
for (let y = 0; y < 4; y++) {
box(
0.06,
0.06,
0.03,
3.38 + x * 0.235,
1.56 + y * 0.29,
-2.965,
"#6d5947",
scene,
false
);
}
}
box(0.12, 0.67, 0.08, 3.58, 2.05, -2.91, "#607f87");
box(0.28, 0.12, 0.08, 3.58, 2.34, -2.91, "#607f87");
box(0.1, 0.56, 0.08, 4.16, 2.02, -2.91, "#d67551");
box(0.32, 0.12, 0.08, 4.16, 2.28, -2.91, "#d67551");
textPanel(
["RADIO REPAIR"],
1.15,
0.3,
new THREE.Vector3(4.2, 1.63, -1.69),
{
background: "#e6ded0",
foreground: "#33413c",
accent: "#5f8790",
mainSize: 48
}
);
}
// Plant station.
{
const g = table(tasks[2].station.x, tasks[2].station.z, 2.05, 1.3, "#8c7557");
box(1.25, 0.15, 0.7, -0.25, 1.19, 0, "#654d3e", g);
box(1.1, 0.06, 0.55, -0.25, 1.3, 0, "#503d32", g);
const seedling = groupAt(0.55, 1.2, 0, g);
box(0.42, 0.42, 0.42, 0, 0.2, 0, "#b76f4e", seedling);
box(0.08, 0.45, 0.08, 0, 0.56, 0, "#668958", seedling);
box(0.34, 0.1, 0.19, 0.13, 0.68, 0, "#769c62", seedling);
box(0.29, 0.1, 0.18, -0.14, 0.57, 0, "#587d50", seedling);
stationAnimations.seedling = seedling;
box(0.38, 0.34, 0.38, -0.85, 1.27, -0.3, "#b16e50", g);
box(0.07, 0.34, 0.07, -0.85, 1.55, -0.3, "#5c8253", g);
box(0.25, 0.09, 0.16, -0.73, 1.66, -0.3, "#789b63", g);
textPanel(
["PLANT CARE"],
1.05,
0.3,
new THREE.Vector3(4.2, 1.64, 2.94),
{
background: "#e6ded0",
foreground: "#33413c",
accent: "#668b63",
mainSize: 52
}
);
}
// Build station.
{
const g = table(tasks[3].station.x, tasks[3].station.z, 2.08, 1.3, "#a07850");
box(1.32, 0.11, 0.22, -0.24, 1.17, -0.23, "#c6925a", g);
box(1.32, 0.11, 0.22, -0.24, 1.17, 0.03, "#d1a365", g);
const plank = box(1.28, 0.11, 0.22, -0.24, 1.31, 0.29, "#d9ac70", g);
stationAnimations.plank = plank;
box(0.65, 0.14, 0.65, 0.62, 1.2, 0.1, "#b98551", g);
box(0.13, 0.52, 0.13, 0.37, 0.9, -0.12, "#8a603e", g);
box(0.13, 0.52, 0.13, 0.86, 0.9, -0.12, "#8a603e", g);
box(0.13, 0.52, 0.13, 0.37, 0.9, 0.31, "#8a603e", g);
box(0.13, 0.52, 0.13, 0.86, 0.9, 0.31, "#8a603e", g);
textPanel(
["STOOL ASSEMBLY"],
1.34,
0.3,
new THREE.Vector3(-4.2, 1.64, 2.94),
{
background: "#e6ded0",
foreground: "#33413c",
accent: "#bb8b55",
mainSize: 47
}
);
}
// Pantry station.
{
const g = table(tasks[4].station.x, tasks[4].station.z, 2.25, 1.2, "#8b7056");
box(0.75, 0.43, 0.63, -0.62, 1.33, 0, "#a8794d", g);
box(0.75, 0.43, 0.63, 0.55, 1.33, 0, "#a8794d", g);
const produceColors = ["#d87945", "#d3aa4f", "#76945c", "#b95e54"];
for (let crate = 0; crate < 2; crate++) {
for (let i = 0; i < 6; i++) {
const x = -0.84 + (i % 3) * 0.22 + crate * 1.17;
const z = -0.14 + Math.floor(i / 3) * 0.28;
box(
0.17,
0.17,
0.17,
x,
1.62,
z,
produceColors[(i + crate) % produceColors.length],
g
);
}
}
textPanel(
["PANTRY PREP"],
1.13,
0.3,
new THREE.Vector3(0, 1.64, -3.08),
{
background: "#e6ded0",
foreground: "#33413c",
accent: "#9a6c82",
mainSize: 50
}
);
}
// -------------------------------------------------------------------------
// Extra neighborhood details
// -------------------------------------------------------------------------
// Blocky trees and planters.
function tree(x, z, scale = 1) {
const g = groupAt(x, 0, z);
box(0.32 * scale, 1.65 * scale, 0.32 * scale, 0, 0.82 * scale, 0, "#77583e", g);
box(1.05 * scale, 0.82 * scale, 1.0 * scale, 0, 1.75 * scale, 0, "#69805d", g);
box(0.85 * scale, 0.75 * scale, 0.9 * scale, -0.52 * scale, 1.52 * scale, 0.12 * scale, "#82946a", g);
box(0.78 * scale, 0.7 * scale, 0.8 * scale, 0.48 * scale, 1.55 * scale, -0.05 * scale, "#577357", g);
box(1.22 * scale, 0.34 * scale, 1.18 * scale, 0, 0.15 * scale, 0, "#987253", g);
return g;
}
tree(-5.25, 3.65, 0.82);
tree(5.3, 3.55, 0.75);
// Bench and stacked crates.
const bench = groupAt(-0.15, 0, 4.1);
box(2.0, 0.16, 0.58, 0, 0.65, 0, "#a77a50", bench);
box(2.0, 0.55, 0.14, 0, 1.05, -0.25, "#a77a50", bench);
box(0.16, 0.55, 0.48, -0.78, 0.3, 0, "#655647", bench);
box(0.16, 0.55, 0.48, 0.78, 0.3, 0, "#655647", bench);
for (let i = 0; i < 3; i++) {
box(0.7, 0.36, 0.65, -5.1, 0.28 + i * 0.38, 3.15, i % 2 ? "#aa7b4e" : "#bd905e");
}
// String of little square lights.
const lightPoints = [];
for (let i = 0; i <= 24; i++) {
const t = i / 24;
lightPoints.push(
new THREE.Vector3(
-5.75 + t * 11.5,
3.55 - Math.sin(t * Math.PI) * 0.42,
-3.62
)
);
}
const lightLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(lightPoints),
new THREE.LineBasicMaterial({ color: "#655f52" })
);
scene.add(lightLine);
for (let i = 1; i < 24; i += 3) {
const p = lightPoints[i];
box(
0.12,
0.16,
0.12,
p.x,
p.y - 0.1,
p.z,
new THREE.MeshStandardMaterial({
color: "#f5c96e",
emissive: "#e7a83e",
emissiveIntensity: 0.7
})
);
}
// -------------------------------------------------------------------------
// Voxel characters
// -------------------------------------------------------------------------
const pickMeshes = [];
const characterLabels = [];
function createCharacter(config, index) {
const root = new THREE.Group();
root.scale.setScalar(config.scale);
scene.add(root);
const skin = config.skin;
const shirt = config.shirt;
const trousers = config.trousers;
box(0.48, 0.2, 0.31, 0, 0.65, 0, trousers, root);
box(config.torsoWidth, 0.66, 0.36, 0, 1.05, 0, shirt, root);
box(0.2, 0.12, 0.2, 0, 1.43, 0, skin, root);
box(0.47, 0.46, 0.45, 0, 1.68, 0, skin, root);
// Hair is deliberately just one visual variation, not a role marker.
box(0.49, 0.12, 0.47, 0, 1.93, -0.01, config.hair, root);
box(0.11, 0.27, 0.47, -0.19, 1.82, -0.01, config.hair, root);
if (config.hairStyle === 2) {
box(0.49, 0.24, 0.11, 0, 1.83, -0.18, config.hair, root);
} else if (config.hairStyle === 3) {
box(0.48, 0.09, 0.48, 0, 1.98, 0, config.hair, root);
}
box(0.055, 0.065, 0.035, -0.105, 1.72, 0.237, "#303632", root);
box(0.055, 0.065, 0.035, 0.105, 1.72, 0.237, "#303632", root);
box(0.12, 0.035, 0.04, 0, 1.57, 0.241, "#a36c5d", root);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-config.torsoWidth / 2 - 0.08, 1.31, 0);
rightArm.position.set(config.torsoWidth / 2 + 0.08, 1.31, 0);
root.add(leftArm, rightArm);
box(0.17, 0.52, 0.18, 0, -0.25, 0, shirt, leftArm);
box(0.17, 0.52, 0.18, 0, -0.25, 0, shirt, rightArm);
box(0.17, 0.16, 0.18, 0, -0.56, 0, skin, leftArm);
box(0.17, 0.16, 0.18, 0, -0.56, 0, skin, rightArm);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.14, 0.61, 0);
rightLeg.position.set(0.14, 0.61, 0);
root.add(leftLeg, rightLeg);
box(0.19, 0.5, 0.2, 0, -0.23, 0, trousers, leftLeg);
box(0.19, 0.5, 0.2, 0, -0.23, 0, trousers, rightLeg);
box(0.21, 0.12, 0.3, 0, -0.53, 0.045, "#41443f", leftLeg);
box(0.21, 0.12, 0.3, 0, -0.53, 0.045, "#41443f", rightLeg);
const toolAnchor = new THREE.Group();
toolAnchor.position.set(0, -0.65, 0.04);
rightArm.add(toolAnchor);
const headAnchor = new THREE.Object3D();
headAnchor.position.set(0, 2.18, 0);
root.add(headAnchor);
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false
});
const hit = new THREE.Mesh(
new THREE.BoxGeometry(0.95 * config.scale, 2.18 * config.scale, 0.72 * config.scale),
hitMaterial
);
hit.position.y = 1.06 * config.scale;
hit.userData.characterIndex = index;
root.add(hit);
pickMeshes.push(hit);
const label = document.createElement("div");
label.className = "character-label";
label.innerHTML = `<strong>${config.name}</strong><span></span>`;
document.querySelector(".hud").appendChild(label);
characterLabels.push(label);
return {
...config,
index,
root,
leftArm,
rightArm,
leftLeg,
rightLeg,
toolAnchor,
headAnchor,
label,
task: index,
from: new THREE.Vector3(),
destination: new THREE.Vector3(),
exchangeSlot: new THREE.Vector3(),
facing: 0
};
}
const characters = [
createCharacter({
name: "Mika",
skin: "#b87954",
shirt: "#d66f4d",
trousers: "#405a62",
hair: "#342b28",
hairStyle: 0,
scale: 1.04,
torsoWidth: 0.58
}, 0),
createCharacter({
name: "Bo",
skin: "#e0aa7c",
shirt: "#6b9097",
trousers: "#596454",
hair: "#69513b",
hairStyle: 1,
scale: 0.94,
torsoWidth: 0.54
}, 1),
createCharacter({
name: "Ada",
skin: "#8d5d43",
shirt: "#708b63",
trousers: "#5a5148",
hair: "#292827",
hairStyle: 2,
scale: 1.0,
torsoWidth: 0.56
}, 2),
createCharacter({
name: "Cielo",
skin: "#d49670",
shirt: "#c39a58",
trousers: "#4d6572",
hair: "#4e392c",
hairStyle: 3,
scale: 0.9,
torsoWidth: 0.52
}, 3),
createCharacter({
name: "Dev",
skin: "#c88e63",
shirt: "#9b7088",
trousers: "#465c52",
hair: "#252a29",
hairStyle: 1,
scale: 1.08,
torsoWidth: 0.61
}, 4)
];
characters.forEach((character, index) => {
character.root.position.copy(tasks[index].stand);
const target = tasks[index].station.clone().sub(tasks[index].stand);
character.facing = Math.atan2(target.x, target.z);
character.root.rotation.y = character.facing;
});
// -------------------------------------------------------------------------
// Tools
// -------------------------------------------------------------------------
function makeTool(type) {
const g = new THREE.Group();
if (type === "caliper") {
box(0.075, 0.62, 0.075, 0, 0.29, 0, "#d68a49", g);
box(0.42, 0.075, 0.075, -0.13, 0.58, 0, "#e3b467", g);
box(0.13, 0.28, 0.075, 0.07, 0.48, 0, "#e3b467", g);
box(0.13, 0.28, 0.075, -0.33, 0.48, 0, "#e3b467", g);
}
if (type === "wrench") {
box(0.085, 0.7, 0.085, 0, 0.32, 0, "#67858b", g);
box(0.3, 0.12, 0.1, 0, 0.69, 0, "#799da1", g);
box(0.11, 0.25, 0.1, -0.13, 0.78, 0, "#799da1", g);
box(0.11, 0.25, 0.1, 0.13, 0.78, 0, "#799da1", g);
}
if (type === "trowel") {
box(0.085, 0.62, 0.085, 0, 0.3, 0, "#a76542", g);
box(0.29, 0.42, 0.08, 0, 0.02, 0, "#829293", g);
box(0.2, 0.08, 0.085, 0, -0.18, 0, "#829293", g);
}
if (type === "hammer") {
box(0.08, 0.78, 0.08, 0, 0.34, 0, "#a96f43", g);
box(0.4, 0.16, 0.17, 0, 0.74, 0, "#6d7774", g);
}
if (type === "scoop") {
box(0.075, 0.62, 0.075, 0, 0.31, 0, "#8f6581", g);
box(0.34, 0.22, 0.34, 0, 0.0, 0, "#a98399", g);
box(0.23, 0.08, 0.23, 0, 0.14, 0, "#624d5d", g);
}
g.traverse((child) => {
if (child.isMesh) {
child.castShadow = true;
child.receiveShadow = true;
}
});
scene.add(g);
return g;
}
const tools = tasks.map((task, index) => ({
type: task.tool,
group: makeTool(task.tool),
holder: index,
destination: index,
source: index,
transfer: false
}));
// -------------------------------------------------------------------------
// Selection marker
// -------------------------------------------------------------------------
const selectionRing = new THREE.Group();
const selectionMaterial = new THREE.MeshStandardMaterial({
color: "#df704c",
emissive: "#b84d31",
emissiveIntensity: 0.24,
roughness: 0.7
});
box(0.66, 0.045, 0.08, 0, 0, 0.42, selectionMaterial, selectionRing, false);
box(0.66, 0.045, 0.08, 0, 0, -0.42, selectionMaterial, selectionRing, false);
box(0.08, 0.045, 0.66, 0.42, 0, 0, selectionMaterial, selectionRing, false);
box(0.08, 0.045, 0.66, -0.42, 0, 0, selectionMaterial, selectionRing, false);
scene.add(selectionRing);
let selectedIndex = 0;
// -------------------------------------------------------------------------
// Live rota and detail UI
// -------------------------------------------------------------------------
const rotaList = document.querySelector("#rota-list");
const detailName = document.querySelector("#detail-name");
const detailRole = document.querySelector("#detail-role");
const detailTool = document.querySelector("#detail-tool");
const detailCopy = document.querySelector("#detail-copy");
const swapButton = document.querySelector("#swap-button");
const pauseButton = document.querySelector("#pause-button");
const resetButton = document.querySelector("#reset-button");
function findCharacterByTask(task) {
return characters.find((character) => character.task === task);
}
function refreshRota() {
rotaList.innerHTML = "";
tasks.forEach((task, taskIndex) => {
const holder = findCharacterByTask(taskIndex);
const row = document.createElement("button");
row.type = "button";
row.className = `rota-row${holder.index === selectedIndex ? " selected" : ""}`;
row.innerHTML = `
<span>
<span class="rota-task">${task.name}</span>
<span class="rota-tool">${task.tool}</span>
</span>
<span class="rota-holder">${holder.name}</span>
`;
row.addEventListener("click", () => selectCharacter(holder.index));
rotaList.appendChild(row);
});
characters.forEach((character) => {
const task = tasks[character.task];
character.label.querySelector("span").textContent = `${task.name} · ${task.tool}`;
character.label.classList.toggle("selected", character.index === selectedIndex);
});
const character = characters[selectedIndex];
const task = tasks[character.task];
const nextTask = tasks[(character.task + 1) % tasks.length];
detailName.textContent = character.name;
detailRole.textContent = task.verb;
detailTool.textContent = task.tool;
detailCopy.textContent =
`${character.name} is currently using the ${task.tool} for ${task.name.toLowerCase()}. ` +
`This is a temporary workshop role. At the next handoff, the ${task.tool} moves to ` +
`someone doing ${nextTask.name.toLowerCase()}.`;
}
function selectCharacter(index) {
selectedIndex = index;
refreshRota();
}
// -------------------------------------------------------------------------
// Rotation cycle
// -------------------------------------------------------------------------
const WORK_SECONDS = 10;
const EXCHANGE_SLOTS = tasks.map((_, index) => {
const angle = (index / tasks.length) * Math.PI * 2 + 0.25;
return new THREE.Vector3(
Math.sin(angle) * 1.52,
0,
Math.cos(angle) * 1.52
);
});
const rotation = {
phase: "work",
time: 0,
paused: false
};
function beginTravelToExchange() {
characters.forEach((character) => {
character.from.copy(character.root.position);
character.exchangeSlot.copy(EXCHANGE_SLOTS[character.task]);
});
rotation.phase = "travelToExchange";
rotation.time = 0;
}
function beginExchange() {
tools.forEach((tool, taskIndex) => {
tool.source = tool.holder;
tool.destination = characters.find(
(character) => character.task === (taskIndex - 1 + tasks.length) % tasks.length
).index;
tool.transfer = false;
});
rotation.phase = "exchange";
rotation.time = 0;
}
function beginTravelToStation() {
characters.forEach((character) => {
character.from.copy(character.root.position);
character.destination.copy(tasks[character.task].stand);
});
rotation.phase = "travelToStation";
rotation.time = 0;
}
function beginWork() {
rotation.phase = "work";
rotation.time = 0;
refreshRota();
}
function requestSwap() {
if (rotation.phase === "work") {
rotation.time = WORK_SECONDS;
}
}
swapButton.addEventListener("click", requestSwap);
pauseButton.addEventListener("click", () => {
rotation.paused = !rotation.paused;
pauseButton.textContent = rotation.paused ? "Resume" : "Pause";
});
resetButton.addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Custom camera controls: orbit, zoom, pan, and keyboard
// -------------------------------------------------------------------------
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragMoved = 0;
let previousPointer = { x: 0, y: 0 };
let pointerButton = 0;
function resetCamera() {
cameraState.yaw = 0.66;
cameraState.pitch = 0.72;
cameraState.zoom = 1;
cameraState.target.set(0, 1.05, 0);
}
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const viewSize = aspect < 1 ? 14 : 11;
camera.left = -viewSize * aspect / 2;
camera.right = viewSize * aspect / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.zoom = cameraState.zoom;
camera.updateProjectionMatrix();
const radius = 17;
const sinPitch = Math.sin(cameraState.pitch);
camera.position.set(
cameraState.target.x + radius * sinPitch * Math.sin(cameraState.yaw),
cameraState.target.y + radius * Math.cos(cameraState.pitch),
cameraState.target.z + radius * sinPitch * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraState.target);
}
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function characterUnderPointer() {
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickMeshes, false);
return hits.length ? hits[0].object.userData.characterIndex : null;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = 0;
pointerButton = event.button;
previousPointer = { x: event.clientX, y: event.clientY };
canvas.setPointerCapture(event.pointerId);
updatePointer(event);
});
canvas.addEventListener("pointermove", (event) => {
updatePointer(event);
if (!dragging) {
canvas.style.cursor = characterUnderPointer() !== null ? "pointer" : "grab";
return;
}
const dx = event.clientX - previousPointer.x;
const dy = event.clientY - previousPointer.y;
dragMoved += Math.abs(dx) + Math.abs(dy);
previousPointer = { x: event.clientX, y: event.clientY };
if (event.shiftKey || pointerButton === 2) {
const right = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, new THREE.Vector3(), new THREE.Vector3());
right.y = 0;
right.normalize();
cameraState.target.addScaledVector(right, -dx * 0.008);
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
cameraState.target.addScaledVector(forward, -dy * 0.008);
} else {
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.004,
0.35,
1.22
);
}
});
canvas.addEventListener("pointerup", (event) => {
dragging = false;
updatePointer(event);
if (dragMoved < 7) {
const index = characterUnderPointer();
if (index !== null) selectCharacter(index);
}
});
canvas.addEventListener("pointercancel", () => {
dragging = false;
});
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.72,
2.25
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
requestSwap();
}
if (event.code === "KeyR") resetCamera();
if (event.code === "KeyP") pauseButton.click();
if (event.code === "ArrowLeft") cameraState.yaw -= 0.09;
if (event.code === "ArrowRight") cameraState.yaw += 0.09;
if (event.code === "ArrowUp") {
cameraState.pitch = Math.max(0.35, cameraState.pitch - 0.06);
}
if (event.code === "ArrowDown") {
cameraState.pitch = Math.min(1.22, cameraState.pitch + 0.06);
}
});
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const tempPosition = new THREE.Vector3();
const tempPositionB = new THREE.Vector3();
const tempQuaternion = new THREE.Quaternion();
const tempQuaternionB = new THREE.Quaternion();
const tempQuaternionC = new THREE.Quaternion();
const worldPosition = new THREE.Vector3();
function lerpAngle(a, b, t) {
let delta = ((b - a + Math.PI) % (Math.PI * 2)) - Math.PI;
if (delta < -Math.PI) delta += Math.PI * 2;
return a + delta * t;
}
function faceMovement(character, target, dt) {
const dx = target.x - character.root.position.x;
const dz = target.z - character.root.position.z;
if (Math.abs(dx) + Math.abs(dz) < 0.001) return;
const desired = Math.atan2(dx, dz);
character.root.rotation.y = lerpAngle(
character.root.rotation.y,
desired,
Math.min(1, dt * 8)
);
}
function animateWork(character, time) {
const index = character.index;
let right = -0.72;
let left = -0.15;
if (character.task === 0) {
right = -0.92 + Math.sin(time * 2.1 + index) * 0.18;
left = -0.5;
} else if (character.task === 1) {
right = -1.05 + Math.sin(time * 2.7 + index * 0.7) * 0.3;
left = -0.7;
} else if (character.task === 2) {
right = -0.55 + Math.sin(time * 1.6 + index) * 0.17;
left = -0.35;
} else if (character.task === 3) {
const strike = Math.pow(Math.max(0, Math.sin(time * 3.1 + index)), 9);
right = -0.72 - strike * 0.65;
left = -0.8;
} else if (character.task === 4) {
right = -0.66 + Math.sin(time * 2.2 + index) * 0.26;
left = -0.4;
}
character.rightArm.rotation.x = THREE.MathUtils.lerp(
character.rightArm.rotation.x,
right,
0.12
);
character.leftArm.rotation.x = THREE.MathUtils.lerp(
character.leftArm.rotation.x,
left,
0.12
);
character.root.position.y = Math.sin(time * 2 + index) * 0.018;
}
function animateWalk(character, time) {
const stride = Math.sin(time * 9 + character.index * 1.7);
character.leftLeg.rotation.x = stride * 0.47;
character.rightLeg.rotation.x = -stride * 0.47;
character.leftArm.rotation.x = -stride * 0.28 - 0.12;
character.rightArm.rotation.x = stride * 0.28 - 0.35;
character.root.position.y = Math.abs(Math.sin(time * 9 + character.index)) * 0.045;
}
function updateTools(time, dt) {
scene.updateMatrixWorld(true);
tools.forEach((tool) => {
if (rotation.phase === "exchange") {
const p = THREE.MathUtils.clamp(rotation.time / 2.5, 0, 1);
const transferProgress = THREE.MathUtils.clamp((p - 0.17) / 0.83, 0, 1);
const source = characters[tool.source];
const destination = characters[tool.destination];
source.toolAnchor.getWorldPosition(tempPosition);
destination.toolAnchor.getWorldPosition(tempPositionB);
if (transferProgress <= 0) {
tool.group.position.copy(tempPosition);
source.toolAnchor.getWorldQuaternion(tempQuaternion);
tool.group.quaternion.copy(tempQuaternion);
} else {
const smooth = THREE.MathUtils.smoothstep(transferProgress, 0, 1);
tool.group.position.lerpVectors(tempPosition, tempPositionB, smooth);
tool.group.position.y += Math.sin(transferProgress * Math.PI) * 1.25;
source.toolAnchor.getWorldQuaternion(tempQuaternion);
destination.toolAnchor.getWorldQuaternion(tempQuaternionB);
tool.group.quaternion.copy(tempQuaternion).slerp(tempQuaternionB, smooth);
tempQuaternionC.setFromAxisAngle(
new THREE.Vector3(0, 1, 0),
(1 - transferProgress) * Math.PI * 1.5
);
tool.group.quaternion.multiply(tempQuaternionC);
}
} else {
const holder = characters[tool.holder];
holder.toolAnchor.getWorldPosition(worldPosition);
tool.group.position.copy(worldPosition);
holder.toolAnchor.getWorldQuaternion(tempQuaternion);
tool.group.quaternion.slerp(tempQuaternion, Math.min(1, dt * 14));
}
});
}
function updateStationProps(time) {
if (stationAnimations.printHead) {
stationAnimations.printHead.position.x = Math.sin(time * 1.65) * 0.27;
stationAnimations.printHead.position.y = 1.87 + Math.sin(time * 3.3) * 0.025;
}
if (stationAnimations.radioKnob) {
stationAnimations.radioKnob.rotation.y = Math.sin(time * 1.2) * 0.32;
}
if (stationAnimations.seedling) {
stationAnimations.seedling.rotation.z = Math.sin(time * 1.55) * 0.025;
stationAnimations.seedling.scale.y = 1 + Math.sin(time * 2.1) * 0.025;
}
if (stationAnimations.plank) {
stationAnimations.plank.position.y =
1.31 + Math.pow(Math.max(0, Math.sin(time * 3.1)), 10) * 0.055;
}
}
function updateCharacterLabels() {
characters.forEach((character) => {
character.headAnchor.getWorldPosition(worldPosition);
worldPosition.project(camera);
const visible =
worldPosition.z > -1 &&
worldPosition.z < 1 &&
Math.abs(worldPosition.x) < 1.15 &&
Math.abs(worldPosition.y) < 1.15;
character.label.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (worldPosition.x * 0.5 + 0.5) * window.innerWidth;
const y = (-worldPosition.y * 0.5 + 0.5) * window.innerHeight;
character.label.style.left = `${x}px`;
character.label.style.top = `${y}px`;
});
}
function updateRotation(dt) {
rotation.time += dt;
if (rotation.phase === "work" && rotation.time >= WORK_SECONDS) {
beginTravelToExchange();
return;
}
if (rotation.phase === "travelToExchange") {
const duration = 2.7;
const p = THREE.MathUtils.clamp(rotation.time / duration, 0, 1);
const eased = THREE.MathUtils.smoothstep(p, 0, 1);
characters.forEach((character) => {
character.root.position.lerpVectors(
character.from,
character.exchangeSlot,
eased
);
faceMovement(character, character.exchangeSlot, dt);
animateWalk(character, rotation.time);
});
if (p >= 1) beginExchange();
} else if (rotation.phase === "exchange") {
characters.forEach((character) => {
const target = new THREE.Vector3(0, 0, 0);
faceMovement(character, target, dt);
character.root.position.y = Math.sin(rotation.time * 2 + character.index) * 0.018;
character.rightArm.rotation.x = THREE.MathUtils.lerp(
character.rightArm.rotation.x,
-0.65,
0.1
);
character.leftArm.rotation.x = THREE.MathUtils.lerp(
character.leftArm.rotation.x,
-0.65,
0.1
);
});
if (rotation.time >= 2.5) {
characters.forEach((character) => {
character.task = (character.task + 1) % tasks.length;
});
tools.forEach((tool) => {
tool.holder = tool.destination;
});
refreshRota();
beginTravelToStation();
}
} else if (rotation.phase === "travelToStation") {
const duration = 3.1;
const p = THREE.MathUtils.clamp(rotation.time / duration, 0, 1);
const eased = THREE.MathUtils.smoothstep(p, 0, 1);
characters.forEach((character) => {
character.root.position.lerpVectors(
character.from,
character.destination,
eased
);
faceMovement(character, character.destination, dt);
animateWalk(character, rotation.time);
});
if (p >= 1) {
characters.forEach((character) => {
character.root.position.copy(tasks[character.task].stand);
const target = tasks[character.task].station.clone().sub(character.root.position);
character.facing = Math.atan2(target.x, target.z);
});
beginWork();
}
}
}
// -------------------------------------------------------------------------
// Main loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let elapsed = 0;
function animate() {
requestAnimationFrame(animate);
const rawDt = Math.min(clock.getDelta(), 0.05);
const dt = rotation.paused ? 0 : rawDt;
elapsed += dt;
updateRotation(dt);
updateStationProps(elapsed);
if (rotation.phase === "work") {
characters.forEach((character) => animateWork(character, elapsed));
}
updateTools(elapsed, rawDt);
updateCamera();
updateCharacterLabels();
const selected = characters[selectedIndex];
selectionRing.position.set(
selected.root.position.x,
0.13,
selected.root.position.z
);
selectionRing.rotation.y = elapsed * 0.28;
selectionRing.visible = rotation.phase !== "travelToStation" || rotation.time > 1.8;
renderer.render(scene, camera);
}
function resize() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
refreshRota();
updateCamera();
updateTools(0, 1);
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```