Prompt specification
Build or customize the Three.js 3D scene "Voxel Market Cast and 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: Voxel Market Cast and Roles
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/voxel-market-cast-and-roles-x3755
Scene Description Prompt:
An original low-poly market cast, with block-built characters distinguished by silhouettes, carried objects, and tasks. Three.js from cdnjs, one HTML file.
Working Three.js Starter (voxel-market-cast-and-roles-x3755):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Morning Market — A Low-Poly Cast</title>
<style>
:root {
color-scheme: light;
--ink: #352d2a;
--paper: #fff8e9;
--accent: #d86f4f;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #efd3b8;
color: var(--ink);
font-family: Inter, ui-rounded, "Avenir Next", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.brand {
position: fixed;
z-index: 3;
top: 28px;
left: 30px;
max-width: 370px;
pointer-events: none;
text-shadow: 0 1px 0 rgba(255,255,255,.45);
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 25px;
height: 3px;
border-radius: 99px;
background: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 5.2vw, 68px);
font-weight: 600;
line-height: .91;
letter-spacing: -.045em;
}
.brand p {
margin: 12px 0 0;
max-width: 300px;
font-size: 13px;
line-height: 1.5;
color: rgba(53,45,42,.72);
}
.controls {
position: fixed;
z-index: 4;
top: 28px;
right: 28px;
display: flex;
align-items: center;
gap: 8px;
}
.control {
border: 1px solid rgba(72,54,44,.15);
border-radius: 12px;
padding: 10px 13px;
color: var(--ink);
background: rgba(255,248,233,.76);
box-shadow: 0 8px 30px rgba(91,61,38,.08);
backdrop-filter: blur(12px);
font: 700 11px/1 system-ui, sans-serif;
letter-spacing: .02em;
cursor: pointer;
transition: transform .18s ease, background .18s ease;
}
.control:hover {
transform: translateY(-2px);
background: rgba(255,252,244,.96);
}
.hint {
position: fixed;
z-index: 3;
right: 30px;
bottom: 154px;
padding: 8px 11px;
border-radius: 10px;
background: rgba(255,248,233,.68);
color: rgba(53,45,42,.62);
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 700;
letter-spacing: .04em;
pointer-events: none;
}
.cast-panel {
position: fixed;
z-index: 4;
left: 50%;
bottom: 22px;
width: min(860px, calc(100vw - 44px));
transform: translateX(-50%);
padding: 13px;
border: 1px solid rgba(72,54,44,.13);
border-radius: 20px;
background: rgba(255,248,233,.84);
box-shadow: 0 18px 60px rgba(74,47,31,.15);
backdrop-filter: blur(16px);
}
.cast-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 0 3px 10px;
}
.cast-heading strong {
font-family: Georgia, serif;
font-size: 17px;
font-weight: 600;
}
#status {
color: rgba(53,45,42,.62);
font-size: 11px;
text-align: right;
}
#cards {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 8px;
}
.cast-card {
position: relative;
min-width: 0;
padding: 12px 12px 11px;
overflow: hidden;
border: 1px solid rgba(67,47,37,.11);
border-radius: 13px;
background: rgba(255,255,255,.5);
color: var(--ink);
text-align: left;
cursor: pointer;
transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.cast-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 4px;
background: var(--accent);
}
.cast-card:hover,
.cast-card.active {
transform: translateY(-3px);
border-color: color-mix(in srgb, var(--accent), transparent 50%);
background: #fffdf7;
}
.cast-card .number {
display: block;
margin-bottom: 7px;
color: var(--accent);
font-size: 9px;
font-weight: 900;
letter-spacing: .12em;
}
.cast-card strong {
display: block;
overflow: hidden;
font-family: Georgia, serif;
font-size: 16px;
font-weight: 600;
text-overflow: ellipsis;
white-space: nowrap;
}
.cast-card small {
display: block;
margin-top: 3px;
overflow: hidden;
color: rgba(53,45,42,.54);
font-size: 9px;
font-weight: 800;
letter-spacing: .08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.cast-card p {
min-height: 25px;
margin: 8px 0 0;
color: rgba(53,45,42,.68);
font-size: 10px;
line-height: 1.25;
}
#loading {
position: fixed;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #efd3b8;
color: #59473e;
font-family: Georgia, serif;
font-size: 22px;
transition: opacity .45s ease;
}
#loading.done {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.brand {
top: 18px;
left: 18px;
}
.brand p { display: none; }
.controls {
top: 18px;
right: 18px;
}
#reset { display: none; }
.hint { display: none; }
.cast-panel {
bottom: 12px;
width: calc(100vw - 24px);
padding: 10px;
}
.cast-heading { padding-bottom: 8px; }
#status {
max-width: 190px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
#cards {
display: flex;
overflow-x: auto;
padding-bottom: 3px;
scroll-snap-type: x proximity;
}
.cast-card {
flex: 0 0 142px;
scroll-snap-align: start;
}
.cast-card p { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="An interactive low-poly morning market scene"></canvas>
<header class="brand">
<div class="eyebrow">A pocket-sized portrait</div>
<h1>Morning<br>Market</h1>
<p>Five locals, five very different jobs, and one square that never quite quiets down.</p>
</header>
<div class="controls">
<button class="control" id="pause" type="button">Pause</button>
<button class="control" id="reset" type="button">Reset view</button>
</div>
<div class="hint">DRAG TO ORBIT · SHIFT-DRAG TO PAN · SCROLL TO ZOOM</div>
<section class="cast-panel" aria-label="Meet the market cast">
<div class="cast-heading">
<strong>Meet the regulars</strong>
<div id="status" aria-live="polite">Choose a character to take a closer look.</div>
</div>
<div id="cards"></div>
</section>
<div id="loading">Setting out the stalls…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xefd3b8);
scene.fog = new THREE.Fog(0xefd3b8, 18, 42);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemi = new THREE.HemisphereLight(0xffe8c8, 0x8b796d, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff0cf, 4.2);
sun.position.set(8, 13, 9);
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 = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.normalBias = 0.025;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xa8c4d5, 0.8);
fill.position.set(-9, 6, 4);
scene.add(fill);
// -------------------------------------------------------------------------
// Small procedural geometry helpers
// -------------------------------------------------------------------------
const materialCache = new Map();
function material(color, options = {}) {
const key = `${color}-${JSON.stringify(options)}`;
if (!materialCache.has(key)) {
materialCache.set(key, new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
}));
}
return materialCache.get(key);
}
function addBox(parent, size, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(parent, top, bottom, height, segments, position, color, options = {}) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(top, bottom, height, segments),
material(color, options)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addPoly(parent, radius, position, color, scale = [1, 1, 1], detail = 0) {
const mesh = new THREE.Mesh(
new THREE.DodecahedronGeometry(radius, detail),
material(color)
);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(scale[0], scale[1], scale[2]);
mesh.rotation.set(
Math.random() * 0.4,
Math.random() * Math.PI,
Math.random() * 0.3
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addLeaf(parent, position, color, scale = [1, 1, 1], rotation = [0, 0, 0]) {
const leaf = addBox(
parent,
[0.18 * scale[0], 0.08 * scale[1], 0.38 * scale[2]],
position,
color
);
leaf.rotation.set(rotation[0], rotation[1], rotation[2]);
return leaf;
}
function seededRandom(seed) {
return function () {
seed |= 0;
seed = seed + 0x6D2B79F5 | 0;
let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
const random = seededRandom(78421);
// -------------------------------------------------------------------------
// Cobbled square
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 40),
new THREE.MeshStandardMaterial({
color: 0xcbb49b,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.08;
ground.receiveShadow = true;
scene.add(ground);
const tileGeometry = new THREE.BoxGeometry(1.04, 0.08, 1.04);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
flatShading: true
});
const tileCount = 15 * 11;
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, tileCount);
tiles.receiveShadow = true;
const tileMatrix = new THREE.Matrix4();
const tileColors = [0xd9c4a9, 0xe0ccb2, 0xcbb69e, 0xe8d4b9, 0xd0baa1];
for (let i = 0; i < tileCount; i++) {
const col = i % 15;
const row = Math.floor(i / 15);
const x = (col - 7) * 1.08;
const z = (row - 5) * 1.08 - 0.1;
const jitterX = (random() - 0.5) * 0.035;
const jitterZ = (random() - 0.5) * 0.035;
tileMatrix.makeTranslation(x + jitterX, -0.025, z + jitterZ);
tiles.setMatrixAt(i, tileMatrix);
const c = new THREE.Color(tileColors[Math.floor(random() * tileColors.length)]);
c.offsetHSL(0, 0, (random() - 0.5) * 0.035);
tiles.setColorAt(i, c);
}
tiles.instanceMatrix.needsUpdate = true;
tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// A warm central runner under the characters.
addBox(scene, [16, 0.035, 4.6], [0.65, 0.025, 1.65], 0xe7cfad);
// -------------------------------------------------------------------------
// Market stalls
// -------------------------------------------------------------------------
function signTexture(text, background = "#49352d", foreground = "#fff4d8") {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = foreground;
ctx.lineWidth = 5;
ctx.strokeRect(10, 10, c.width - 20, c.height - 20);
ctx.fillStyle = foreground;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "700 47px Georgia";
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
function addFlower(parent, x, y, z, color, height = 0.6) {
const stem = addBox(parent, [0.035, height, 0.035], [x, y + height / 2, z], 0x477b4c);
const bloom = addPoly(parent, 0.12, [x, y + height, z], color, [1, 0.65, 1]);
bloom.rotation.set(0, 0, 0);
addLeaf(parent, [x + 0.1, y + height * 0.48, z], 0x67985a, [1, 1, 1], [0, 0, -0.5]);
return stem;
}
function addProduce(parent, type, count = 12) {
const colors = {
fruit: [0xe79a3b, 0xe56f43, 0xd8b63e],
greens: [0x6d9e5c, 0x4d8251, 0x91ae63],
roots: [0xe47a48, 0xd7623c, 0xf0a052]
};
for (let i = 0; i < count; i++) {
const x = -1.95 + random() * 3.9;
const z = -0.35 + random() * 0.9;
const palette = colors[type] || colors.fruit;
if (type === "greens") {
addLeaf(parent, [x, 1.98, z], palette[i % palette.length], [1.8, 2, 1.5], [0.25, 0, 0.4]);
} else {
addPoly(
parent,
type === "roots" ? 0.15 : 0.19,
[x, 2.02, z],
palette[i % palette.length],
[1, type === "roots" ? 1.5 : 0.85, 1]
);
}
}
}
function createStall(x, z, stripeA, stripeB, label, productType) {
const stall = new THREE.Group();
stall.position.set(x, 0, z);
stall.rotation.y = (random() - 0.5) * 0.08;
scene.add(stall);
const wood = 0x8c5c3e;
const darkWood = 0x634535;
// Counter and shelf.
addBox(stall, [4.8, 0.95, 1.15], [0, 1.1, 0.2], wood);
addBox(stall, [5.05, 0.16, 1.38], [0, 1.66, 0.2], 0xb98252);
addBox(stall, [4.3, 0.13, 0.75], [0, 1.75, -0.8], darkWood);
addBox(stall, [4.7, 0.12, 0.1], [0, 0.62, 0.81], darkWood);
// Counter planks.
for (let i = -2; i <= 2; i++) {
addBox(stall, [0.035, 0.83, 0.025], [i * 0.86, 1.1, 0.79], darkWood);
}
// Frame.
for (const px of [-2.3, 2.3]) {
for (const pz of [-0.78, 0.86]) {
addBox(stall, [0.12, 3.25, 0.12], [px, 1.6, pz], darkWood);
}
}
// Striped canopy.
const panelCount = 10;
for (let i = 0; i < panelCount; i++) {
const px = -2.42 + i * 0.535;
const panel = addBox(
stall,
[0.54, 0.14, 2.22],
[px, 3.25, 0.02],
i % 2 === 0 ? stripeA : stripeB
);
panel.rotation.z = i % 2 === 0 ? 0.025 : -0.025;
}
addBox(stall, [5.15, 0.12, 0.12], [0, 3.03, 1.12], darkWood);
addBox(stall, [5.15, 0.42, 0.1], [0, 2.82, 1.12], stripeA);
// Hanging sign.
const sign = new THREE.Mesh(
new THREE.PlaneGeometry(3.25, 0.81),
new THREE.MeshBasicMaterial({
map: signTexture(label),
transparent: true,
depthWrite: false
})
);
sign.position.set(0, 3.77, -0.7);
stall.add(sign);
// Baskets and produce.
for (let i = 0; i < 3; i++) {
const bx = -1.55 + i * 1.55;
addBox(stall, [1.05, 0.32, 0.78], [bx, 1.9, 0.25], 0x9a6945);
addBox(stall, [1.12, 0.08, 0.84], [bx, 2.08, 0.25], 0xb58150);
}
addProduce(stall, productType, 13);
// Crates under the counter.
addBox(stall, [0.8, 0.5, 0.65], [-1.75, 0.25, 0.3], 0x9a6945);
addBox(stall, [0.72, 0.4, 0.62], [-1.7, 0.72, 0.3], 0xb17b4c);
addBox(stall, [0.85, 0.48, 0.65], [1.65, 0.24, 0.35], 0x9a6945);
return stall;
}
createStall(-6.2, -5.3, 0xb85843, 0xf0d3a2, "ORCHARD", "fruit");
createStall(0.0, -5.65, 0x487d69, 0xf1d6a7, "MORNING MARKET", "greens");
createStall(6.1, -5.2, 0x577b9d, 0xf2d9ad, "FRESH DAILY", "roots");
// -------------------------------------------------------------------------
// Background buildings, crates, and string lights
// -------------------------------------------------------------------------
const buildingColors = [0xc98462, 0xd8a06f, 0xb87862, 0xc79576, 0xb87964];
for (let i = 0; i < 9; i++) {
const x = -11 + i * 2.75;
const height = 3.4 + random() * 2.2;
const width = 2.25 + random() * 0.45;
const z = -10.5 - random() * 0.8;
const building = addBox(
scene,
[width, height, 2.6],
[x, height / 2, z],
buildingColors[i % buildingColors.length]
);
building.rotation.y = (random() - 0.5) * 0.03;
const roof = addBox(
scene,
[width + 0.25, 0.22, 2.85],
[x, height + 0.05, z],
i % 2 ? 0x745146 : 0x8c5d49
);
roof.rotation.z = (random() - 0.5) * 0.025;
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 2; col++) {
addBox(
scene,
[0.43, 0.55, 0.055],
[x + (col - 0.5) * 0.75, 1.6 + row * 1.25, z + 1.33],
0xf1cf87,
{ emissive: 0x7b4825, emissiveIntensity: 0.12 }
);
addBox(
scene,
[0.5, 0.08, 0.08],
[x + (col - 0.5) * 0.75, 1.6 + row * 1.25, z + 1.37],
0x74574a
);
}
}
}
function createStringLights() {
const poleXs = [-9, -3, 3, 9];
const poleZ = -3.85;
poleXs.forEach((x) => {
addCylinder(scene, 0.055, 0.075, 5.25, 7, [x, 2.62, poleZ], 0x665043);
addPoly(scene, 0.12, [x, 5.24, poleZ], 0x665043, [1, 1, 1]);
});
for (let i = 0; i < poleXs.length - 1; i++) {
const x1 = poleXs[i];
const x2 = poleXs[i + 1];
const points = [];
for (let j = 0; j <= 12; j++) {
const t = j / 12;
const x = THREE.MathUtils.lerp(x1, x2, t);
const y = 5.18 - Math.sin(t * Math.PI) * 0.8;
points.push(new THREE.Vector3(x, y, poleZ));
}
const curve = new THREE.CatmullRomCurve3(points);
const cable = new THREE.Mesh(
new THREE.TubeGeometry(curve, 30, 0.022, 5, false),
material(0x4f4039)
);
scene.add(cable);
for (let j = 1; j < 8; j++) {
const p = curve.getPoint(j / 8);
addPoly(
scene,
0.09,
[p.x, p.y - 0.12, p.z],
0xffd276,
[1, 1.25, 1]
);
}
}
}
createStringLights();
// Foreground baskets and barrels.
function createBarrel(x, z, color = 0x9a6945) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addCylinder(group, 0.42, 0.36, 0.9, 8, [0, 0.45, 0], color);
addCylinder(group, 0.44, 0.44, 0.07, 8, [0, 0.18, 0], 0x62483a);
addCylinder(group, 0.44, 0.44, 0.07, 8, [0, 0.7, 0], 0x62483a);
}
createBarrel(-8.2, 1.4, 0x9a6945);
createBarrel(8.1, -0.3, 0xa9794e);
createBarrel(7.4, 3.8, 0x8d6044);
for (let i = 0; i < 4; i++) {
addBox(scene, [0.85, 0.45, 0.72], [-8.4 + i * 0.13, 0.23 + i * 0.46, 2.7], i % 2 ? 0xa16d46 : 0xb47c4e);
}
// -------------------------------------------------------------------------
// Block-built character system
// -------------------------------------------------------------------------
function createCharacter(spec) {
const group = new THREE.Group();
group.position.set(spec.position[0], 0, spec.position[1]);
group.rotation.y = spec.rotation || 0;
group.scale.set(...spec.scale);
scene.add(group);
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.68, 20),
new THREE.MeshBasicMaterial({
color: 0x49342c,
transparent: true,
opacity: 0.11,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = 0.035;
group.add(shadow);
const rig = {
group,
head: new THREE.Group(),
leftArm: new THREE.Group(),
rightArm: new THREE.Group(),
leftLeg: new THREE.Group(),
rightLeg: new THREE.Group(),
leftHand: new THREE.Group(),
rightHand: new THREE.Group(),
type: spec.type,
phase: random() * Math.PI * 2
};
// Torso, hips, and legs.
addBox(group, [spec.width * 0.78, 0.3, 0.46], [0, 1.13, 0], spec.trousers);
addBox(group, [spec.width, 1.02, 0.5], [0, 1.77, 0], spec.shirt);
addBox(group, [0.26, 0.18, 0.26], [0, 2.36, 0], spec.skin);
rig.leftLeg.position.set(-0.25, 1.06, 0);
rig.rightLeg.position.set(0.25, 1.06, 0);
group.add(rig.leftLeg, rig.rightLeg);
for (const leg of [rig.leftLeg, rig.rightLeg]) {
addBox(leg, [0.29, 0.88, 0.31], [0, -0.43, 0], spec.trousers);
addBox(leg, [0.34, 0.2, 0.48], [0, -0.9, 0.1], spec.shoes);
}
// Head and face.
rig.head.position.set(0, 2.73, 0);
group.add(rig.head);
addBox(rig.head, [0.65, 0.68, 0.59], [0, 0, 0], spec.skin);
addBox(rig.head, [0.065, 0.07, 0.035], [-0.14, 0.06, 0.312], 0x332824);
addBox(rig.head, [0.065, 0.07, 0.035], [0.14, 0.06, 0.312], 0x332824);
addBox(rig.head, [0.11, 0.12, 0.12], [0, -0.055, 0.335], spec.skin);
addBox(rig.head, [0.13, 0.025, 0.025], [0, -0.19, 0.31], 0x754d43);
// Arms and hands.
rig.leftArm.position.set(-(spec.width / 2 + 0.15), 2.2, 0);
rig.rightArm.position.set(spec.width / 2 + 0.15, 2.2, 0);
group.add(rig.leftArm, rig.rightArm);
for (const arm of [rig.leftArm, rig.rightArm]) {
addBox(arm, [0.24, 0.61, 0.27], [0, -0.29, 0], spec.shirt);
addBox(arm, [0.22, 0.16, 0.24], [0, -0.62, 0], spec.skin);
}
rig.leftHand.position.set(0, -0.66, 0);
rig.rightHand.position.set(0, -0.66, 0);
rig.leftArm.add(rig.leftHand);
rig.rightArm.add(rig.rightHand);
// Distinct hairstyles and headwear.
if (spec.hair === "bun") {
addBox(rig.head, [0.7, 0.19, 0.63], [0, 0.37, -0.015], spec.hairColor);
addBox(rig.head, [0.12, 0.43, 0.13], [-0.31, 0.12, -0.01], spec.hairColor);
addBox(rig.head, [0.12, 0.43, 0.13], [0.31, 0.12, -0.01], spec.hairColor);
addPoly(rig.head, 0.19, [0, 0.5, -0.14], spec.hairColor, [1, 0.9, 1]);
}
if (spec.hair === "scarf") {
addBox(rig.head, [0.72, 0.2, 0.66], [0, 0.37, -0.01], spec.hairColor);
addBox(rig.head, [0.13, 0.5, 0.18], [-0.31, 0.12, -0.08], spec.hairColor);
addBox(rig.head, [0.13, 0.5, 0.18], [0.31, 0.12, -0.08], spec.hairColor);
addBox(rig.head, [0.18, 0.44, 0.08], [0, 0.11, -0.34], spec.hairColor);
}
if (spec.hair === "beard") {
addBox(rig.head, [0.69, 0.17, 0.62], [0, 0.36, -0.02], spec.hairColor);
addBox(rig.head, [0.59, 0.34, 0.18], [0, -0.22, 0.25], spec.hairColor);
addBox(rig.head, [0.24, 0.13, 0.4], [0, 0.31, 0.05], spec.hairColor);
}
if (spec.hair === "wideHat") {
addBox(rig.head, [0.68, 0.16, 0.61], [0, 0.36, 0], spec.hairColor);
addCylinder(rig.head, 0.73, 0.73, 0.09, 10, [0, 0.48, 0], 0xc99b52);
addCylinder(rig.head, 0.34, 0.39, 0.36, 8, [0, 0.68, 0], 0xd7aa5f);
addCylinder(rig.head, 0.36, 0.36, 0.08, 8, [0, 0.57, 0], 0x6e7d50);
}
if (spec.hair === "curls") {
addBox(rig.head, [0.68, 0.19, 0.62], [0, 0.37, 0], spec.hairColor);
for (const x of [-0.28, -0.15, 0, 0.15, 0.28]) {
addPoly(rig.head, 0.11, [x, 0.43, -0.04], spec.hairColor, [1, 0.8, 1]);
}
addCylinder(rig.head, 0.37, 0.4, 0.17, 8, [0, 0.48, 0], spec.hairColor);
addBox(rig.head, [0.51, 0.07, 0.16], [0, 0.47, 0.27], spec.accent);
}
// Clothing details.
if (spec.type === "mara") {
addBox(rig.head, [0.5, 0.42, 0.06], [0, 0.04, 0.315], 0xf5e8d2);
addBox(rig.head, [0.52, 0.035, 0.025], [0, 0.2, 0.355], 0xd55f48);
}
if (spec.type === "oona") {
addBox(group, [1.08, 0.42, 0.57], [0, 1.15, 0], spec.shirt);
addBox(rig.head, [0.47, 0.32, 0.045], [0, 0.02, 0.32], 0xf0dfc4);
}
if (spec.type === "bram") {
addBox(group, [0.82, 0.72, 0.055], [0, 1.58, 0.285], 0x466b83);
addBox(group, [0.13, 0.72, 0.07], [-0.27, 1.91, 0.3], 0x466b83);
addBox(group, [0.13, 0.72, 0.07], [0.27, 1.91, 0.3], 0x466b83);
addBox(rig.head, [0.72, 0.13, 0.66], [0, 0.46, 0], 0x42657a);
addBox(rig.head, [0.48, 0.07, 0.22], [0, 0.42, 0.39], 0x42657a);
}
if (spec.type === "fen") {
addBox(group, [0.76, 0.68, 0.055], [0, 1.59, 0.285], 0x66724c);
addBox(group, [0.12, 0.63, 0.065], [-0.25, 1.92, 0.3], 0x66724c);
addBox(group, [0.12, 0.63, 0.065], [0.25, 1.92, 0.3], 0x66724c);
}
if (spec.type === "lio") {
addBox(group, [0.7, 0.51, 0.055], [0, 1.6, 0.285], 0x667d9b);
addBox(group, [0.11, 0.56, 0.07], [-0.21, 1.85, 0.31], 0x667d9b);
addBox(group, [0.11, 0.56, 0.07], [0.21, 1.85, 0.31], 0x667d9b);
}
// Task-specific props.
if (spec.type === "mara") {
// Apron.
addBox(group, [spec.width * 0.73, 0.78, 0.055], [0, 1.62, 0.285], 0xf3dfbb);
addBox(group, [0.12, 0.6, 0.065], [-0.24, 2.03, 0.31], 0xf3dfbb);
addBox(group, [0.12, 0.6, 0.065], [0.24, 2.03, 0.31], 0xf3dfbb);
// A tray of bread, carried horizontally in front.
const tray = new THREE.Group();
tray.position.set(-0.46, 0, 0);
tray.rotation.x = 1.45;
rig.rightHand.add(tray);
addBox(tray, [1.45, 0.1, 0.68], [0, 0, 0], 0x8a5b3e);
addBox(tray, [1.26, 0.05, 0.52], [0, 0.07, 0], 0xb57d4e);
addBox(tray, [0.39, 0.18, 0.26], [-0.36, 0.16, 0.08], 0xdca55c);
addBox(tray, [0.42, 0.19, 0.27], [0.02, 0.16, -0.08], 0xe3b06a);
addBox(tray, [0.36, 0.17, 0.25], [0.35, 0.15, 0.07], 0xd89d51);
rig.leftArm.rotation.x = -1.45;
rig.rightArm.rotation.x = -1.45;
rig.leftArm.rotation.z = -0.12;
rig.rightArm.rotation.z = 0.12;
}
if (spec.type === "oona") {
const crate = new THREE.Group();
crate.position.set(0, 0.06, 0);
rig.rightHand.add(crate);
addBox(crate, [0.88, 0.38, 0.65], [0, 0, 0], 0x9b6a45);
addBox(crate, [0.96, 0.08, 0.7], [0, 0.22, 0], 0xb47e4d);
const fishColors = [0xb8c7c4, 0x91abae, 0xd7d4bd];
for (let i = 0; i < 3; i++) {
const fish = addBox(
crate,
[0.35, 0.1, 0.13],
[-0.23 + i * 0.23, 0.31, -0.13 + (i % 2) * 0.18],
fishColors[i]
);
fish.rotation.y = (i - 1) * 0.35;
const tail = new THREE.Mesh(
new THREE.ConeGeometry(0.1, 0.18, 3),
material(fishColors[i])
);
tail.position.set(0.22, 0, 0);
tail.rotation.z = Math.PI / 2;
fish.add(tail);
}
rig.leftArm.rotation.x = -0.55;
rig.leftArm.rotation.z = -0.65;
rig.rightArm.rotation.z = 0.08;
}
if (spec.type === "bram") {
// A precarious stack that defines the silhouette.
addBox(group, [1.18, 0.52, 0.82], [0, 3.25, 0], 0xa46c43);
addBox(group, [1.24, 0.09, 0.87], [0, 3.53, 0], 0xbd8350);
addBox(group, [0.88, 0.45, 0.7], [0.05, 3.77, -0.02], 0x93613f);
addBox(group, [0.94, 0.08, 0.75], [0.05, 4.01, -0.02], 0xb77b4c);
rig.leftArm.rotation.z = -2.55;
rig.rightArm.rotation.z = 2.55;
}
if (spec.type === "fen") {
const plant = new THREE.Group();
plant.position.set(0, -0.02, 0);
rig.leftHand.add(plant);
addCylinder(plant, 0.3, 0.22, 0.38, 7, [0, 0, 0], 0xb56d45);
addCylinder(plant, 0.31, 0.31, 0.07, 7, [0, 0.2, 0], 0x7b4935);
addBox(plant, [0.05, 0.72, 0.05], [0, 0.54, 0], 0x49784a);
addLeaf(plant, [-0.15, 0.62, 0], 0x5e9354, [1.8, 1.1, 1.6], [0.1, 0.2, 0.45]);
addLeaf(plant, [0.16, 0.77, 0], 0x6c9e59, [1.8, 1.1, 1.6], [-0.1, 0.2, -0.5]);
addLeaf(plant, [0, 0.91, 0], 0x83aa62, [1.7, 1.1, 1.6], [0, 0.4, 0.1]);
rig.leftArm.rotation.z = -0.12;
rig.rightArm.rotation.z = 0.55;
rig.rightArm.rotation.x = -0.2;
}
if (spec.type === "lio") {
const bucket = new THREE.Group();
bucket.position.set(0, 0.05, 0);
rig.leftHand.add(bucket);
addCylinder(bucket, 0.24, 0.2, 0.37, 8, [0, 0, 0], 0x7f9d9b);
addCylinder(bucket, 0.25, 0.25, 0.05, 8, [0, 0.19, 0], 0xaac0b4);
addFlower(bucket, -0.1, 0.16, 0, 0xe36f64, 0.6);
addFlower(bucket, 0.08, 0.16, 0.03, 0xf0b55c, 0.68);
addFlower(bucket, 0, 0.16, -0.1, 0xd985a1, 0.55);
rig.rightArm.rotation.z = 0.75;
rig.rightArm.rotation.x = -0.2;
}
group.userData.character = spec;
return rig;
}
const characters = [
createCharacter({
type: "mara",
name: "Mara",
role: "Baker",
task: "Balances a warm bread tray.",
accent: "#d7654d",
position: [-4.3, 2.1],
rotation: 0.06,
scale: [1.08, 0.94, 1.08],
width: 1.04,
shirt: 0xd7684e,
trousers: 0x5c6e6a,
shoes: 0x4b3730,
skin: 0xb96f4f,
hair: "bun",
hairColor: 0x733f31
}),
createCharacter({
type: "oona",
name: "Oona",
role: "Fishmonger",
task: "Carries the morning catch.",
accent: "#4c8e89",
position: [-1.55, 3.0],
rotation: -0.13,
scale: [0.98, 0.79, 0.98],
width: 0.96,
shirt: 0x4f8e89,
trousers: 0x365b58,
shoes: 0x493a35,
skin: 0xe2ad82,
hair: "scarf",
hairColor: 0x3f716c
}),
createCharacter({
type: "bram",
name: "Bram",
role: "Porter",
task: "Keeps a heavy stack steady.",
accent: "#547a93",
position: [1.25, 1.7],
rotation: 0.08,
scale: [1.13, 1.08, 1.08],
width: 1.18,
shirt: 0xb86740,
trousers: 0x3e596a,
shoes: 0x3e302c,
skin: 0x8d573d,
hair: "beard",
hairColor: 0x4a332b
}),
createCharacter({
type: "fen",
name: "Fen",
role: "Gardener",
task: "Brings a young plant to market.",
accent: "#789050",
position: [4.05, 2.75],
rotation: -0.18,
scale: [0.86, 1.17, 0.86],
width: 0.83,
shirt: 0x6f8c50,
trousers: 0x88714b,
shoes: 0x574339,
skin: 0xe7b88b,
hair: "wideHat",
hairColor: 0x78553c
}),
createCharacter({
type: "lio",
name: "Lio",
role: "Flower seller",
task: "Sells bunches by the stem.",
accent: "#d98a62",
position: [6.2, 1.1],
rotation: 0.28,
scale: [0.83, 0.67, 0.83],
width: 0.82,
shirt: 0xe1a74e,
trousers: 0x657d9a,
shoes: 0x473832,
skin: 0xca895f,
hair: "curls",
hairColor: 0x4c3028
})
];
const castSpecs = [
["Mara", "Baker", "Balances a warm bread tray.", "#d7654d"],
["Oona", "Fishmonger", "Carries the morning catch.", "#4c8e89"],
["Bram", "Porter", "Keeps a heavy stack steady.", "#547a93"],
["Fen", "Gardener", "Brings a young plant to market.", "#789050"],
["Lio", "Flower seller", "Sells bunches by the stem.", "#d98a62"]
];
// -------------------------------------------------------------------------
// UI and camera focus
// -------------------------------------------------------------------------
const cardsContainer = document.querySelector("#cards");
const status = document.querySelector("#status");
const resetButton = document.querySelector("#reset");
const pauseButton = document.querySelector("#pause");
const cameraNow = {
target: new THREE.Vector3(0.55, 1.5, 0.3),
yaw: 0.12,
pitch: 0.31,
distance: 16
};
const cameraGoal = {
target: cameraNow.target.clone(),
yaw: cameraNow.yaw,
pitch: cameraNow.pitch,
distance: cameraNow.distance
};
let selectedIndex = -1;
let paused = false;
function focusCharacter(index) {
const character = characters[index];
const spec = castSpecs[index];
selectedIndex = index;
cameraGoal.target.set(
character.group.position.x,
1.55 * character.group.scale.y,
character.group.position.z
);
cameraGoal.distance = 6.3;
cameraGoal.pitch = 0.18;
cameraGoal.yaw = 0.08;
status.textContent = `${spec[0]} — ${spec[2]}`;
document.querySelectorAll(".cast-card").forEach((card, i) => {
card.classList.toggle("active", i === index);
});
}
function resetView() {
selectedIndex = -1;
cameraGoal.target.set(0.55, 1.5, 0.3);
cameraGoal.yaw = 0.12;
cameraGoal.pitch = 0.31;
cameraGoal.distance = 16;
status.textContent = "Choose a character to take a closer look.";
document.querySelectorAll(".cast-card").forEach(card => card.classList.remove("active"));
}
castSpecs.forEach((spec, index) => {
const button = document.createElement("button");
button.className = "cast-card";
button.type = "button";
button.style.setProperty("--accent", spec[3]);
button.innerHTML = `
<span class="number">0${index + 1}</span>
<strong>${spec[0]}</strong>
<small>${spec[1]}</small>
<p>${spec[2]}</p>
`;
button.addEventListener("click", () => focusCharacter(index));
cardsContainer.appendChild(button);
});
resetButton.addEventListener("click", resetView);
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
});
window.addEventListener("keydown", (event) => {
if (event.key >= "1" && event.key <= "5") {
focusCharacter(Number(event.key) - 1);
}
if (event.key.toLowerCase() === "r") {
resetView();
}
if (event.code === "Space") {
event.preventDefault();
paused = !paused;
pauseButton.textContent = paused ? "Play" : "Pause";
}
});
// -------------------------------------------------------------------------
// Direct orbit, pan, and zoom controls — no external control add-ons
// -------------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey || event.buttons === 4) {
const right = new THREE.Vector3(
Math.cos(cameraGoal.yaw),
0,
-Math.sin(cameraGoal.yaw)
);
const forward = new THREE.Vector3(
-Math.sin(cameraGoal.yaw),
0,
-Math.cos(cameraGoal.yaw)
);
const panScale = cameraGoal.distance * 0.00125;
cameraGoal.target.addScaledVector(right, -dx * panScale);
cameraGoal.target.addScaledVector(forward, -dy * panScale);
} else {
cameraGoal.yaw -= dx * 0.006;
cameraGoal.pitch = THREE.MathUtils.clamp(
cameraGoal.pitch + dy * 0.005,
0.08,
1.05
);
}
});
function endDrag(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
cameraGoal.distance = THREE.MathUtils.clamp(
cameraGoal.distance * Math.exp(event.deltaY * 0.001),
5.4,
25
);
}, { passive: false });
function updateCamera() {
const smoothing = 0.085;
cameraNow.target.lerp(cameraGoal.target, smoothing);
cameraNow.yaw = THREE.MathUtils.lerp(cameraNow.yaw, cameraGoal.yaw, smoothing);
cameraNow.pitch = THREE.MathUtils.lerp(cameraNow.pitch, cameraGoal.pitch, smoothing);
cameraNow.distance = THREE.MathUtils.lerp(
cameraNow.distance,
cameraGoal.distance,
smoothing
);
const cp = Math.cos(cameraNow.pitch);
const sp = Math.sin(cameraNow.pitch);
camera.position.set(
cameraNow.target.x + cameraNow.distance * cp * Math.sin(cameraNow.yaw),
cameraNow.target.y + cameraNow.distance * sp,
cameraNow.target.z + cameraNow.distance * cp * Math.cos(cameraNow.yaw)
);
camera.lookAt(cameraNow.target);
}
// -------------------------------------------------------------------------
// Character animation
// -------------------------------------------------------------------------
function animateCharacters(time) {
characters.forEach((rig, index) => {
const phase = rig.phase;
const bobSpeed = 1.6 + index * 0.12;
const bobAmount = rig.type === "bram" ? 0.018 : 0.028;
rig.group.position.y = Math.sin(time * bobSpeed + phase) * bobAmount;
rig.head.rotation.y = Math.sin(time * 0.65 + phase) * 0.09;
rig.head.rotation.z = Math.sin(time * 0.43 + phase) * 0.025;
rig.leftLeg.rotation.x = Math.sin(time * 0.72 + phase) * 0.025;
rig.rightLeg.rotation.x = -Math.sin(time * 0.72 + phase) * 0.025;
if (rig.type === "mara") {
rig.rightArm.rotation.x = -1.45 + Math.sin(time * 1.4 + phase) * 0.035;
rig.leftArm.rotation.x = -1.45 - Math.sin(time * 1.4 + phase) * 0.025;
rig.rightArm.rotation.z = 0.12;
rig.leftArm.rotation.z = -0.12;
}
if (rig.type === "oona") {
rig.leftArm.rotation.x = -0.55 + Math.sin(time * 1.6 + phase) * 0.16;
rig.leftArm.rotation.z = -0.65 + Math.sin(time * 1.6 + phase) * 0.12;
rig.rightArm.rotation.z = 0.08;
rig.rightArm.rotation.x = Math.sin(time * 1.2 + phase) * 0.035;
}
if (rig.type === "bram") {
const balance = Math.sin(time * 1.05 + phase) * 0.045;
rig.leftArm.rotation.z = -2.55 + balance;
rig.rightArm.rotation.z = 2.55 - balance;
rig.head.rotation.z += Math.sin(time * 0.8 + phase) * 0.025;
}
if (rig.type === "fen") {
rig.rightArm.rotation.z = 0.55 + Math.sin(time * 1.5 + phase) * 0.25;
rig.rightArm.rotation.x = -0.2 + Math.cos(time * 1.5 + phase) * 0.08;
rig.leftArm.rotation.z = -0.12;
}
if (rig.type === "lio") {
rig.rightArm.rotation.z = 0.75 + Math.sin(time * 2.3 + phase) * 0.36;
rig.rightArm.rotation.x = -0.2 + Math.cos(time * 2.3 + phase) * 0.08;
rig.leftArm.rotation.z = -0.06;
}
});
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
let animationTime = 0;
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) animationTime += dt;
updateCamera();
animateCharacters(animationTime);
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("done");
setTimeout(() => document.querySelector("#loading").remove(), 500);
});
</script>
</body>
</html>
```