Prompt specification
Build or customize the Three.js 3D scene "Spinning and winding work corner" 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: Spinning and winding work corner
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/spinning-and-winding-work-corner-x2250
Scene Description Prompt:
Animate an ancient voxel textile corner with a suspended spindle twisting and winding a continuous thread. Three.js from cdnjs, one HTML file.
Working Three.js Starter (spinning-and-winding-work-corner-x2250):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Woven Corner — Voxel Spindle</title>
<style>
:root {
color-scheme: dark;
--ivory: #e7d7b5;
--muted: #aa9270;
--gold: #d59a4b;
--line: rgba(226, 191, 133, 0.25);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #100b09;
}
body {
font-family: Georgia, "Times New Roman", serif;
color: var(--ivory);
}
#viewport {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#viewport:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.title-card {
position: absolute;
top: clamp(24px, 4vw, 54px);
left: clamp(24px, 4vw, 58px);
max-width: 390px;
padding-left: 19px;
border-left: 1px solid var(--line);
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.75);
}
.eyebrow {
margin: 0 0 10px;
color: var(--gold);
font-family: Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.28em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 13px 0 0;
max-width: 310px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
line-height: 1.65;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.status {
position: absolute;
right: clamp(22px, 4vw, 52px);
bottom: clamp(24px, 4vw, 44px);
display: flex;
align-items: center;
gap: 10px;
color: var(--muted);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #e4a64f;
box-shadow: 0 0 12px #e4a64f;
animation: breathe 1.5s ease-in-out infinite;
}
@keyframes breathe {
0%, 100% { opacity: 0.45; transform: scale(0.8); }
50% { opacity: 1; transform: scale(1.15); }
}
.controls {
position: absolute;
left: clamp(24px, 4vw, 58px);
bottom: clamp(24px, 4vw, 44px);
display: flex;
align-items: center;
gap: 16px;
color: rgba(212, 190, 153, 0.66);
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
font-weight: 600;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.controls span {
white-space: nowrap;
}
button {
pointer-events: auto;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 0;
background: rgba(20, 13, 10, 0.62);
color: var(--ivory);
font: inherit;
font-size: 9px;
letter-spacing: 0.15em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
button:hover {
color: #fff0c8;
border-color: rgba(226, 191, 133, 0.65);
background: rgba(78, 47, 24, 0.72);
}
@media (max-width: 640px) {
.title-card {
max-width: 280px;
}
.subtitle {
display: none;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<section class="title-card">
<p class="eyebrow">Spindle study · 480 BCE</p>
<h1>The Woven<br>Corner</h1>
<p class="subtitle">
An ancient chamber of dyed wool, suspended wood, and one continuous golden thread.
</p>
</section>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button">Reset view</button>
</div>
<div class="status">
<span class="status-dot"></span>
<span>Continuous thread · winding</span>
</div>
</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 scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const viewport = renderer.domElement;
viewport.id = "viewport";
viewport.setAttribute("aria-label", "Interactive ancient voxel textile corner");
document.body.prepend(viewport);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x120c09);
scene.fog = new THREE.Fog(0x120c09, 13, 30);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Custom camera controls: no addons or examples modules.
const orbit = {
target: new THREE.Vector3(-0.35, 2.75, 0.05),
desiredTarget: new THREE.Vector3(-0.35, 2.75, 0.05),
theta: 0.67,
phi: 1.25,
radius: 16.7,
desiredTheta: 0.67,
desiredPhi: 1.25,
desiredRadius: 16.7
};
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
function resetView() {
orbit.desiredTheta = 0.67;
orbit.desiredPhi = 1.25;
orbit.desiredRadius = 16.7;
orbit.desiredTarget.set(-0.35, 2.75, 0.05);
}
document.getElementById("reset-view").addEventListener("click", resetView);
let dragging = false;
let pointerX = 0;
let pointerY = 0;
viewport.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
viewport.setPointerCapture(event.pointerId);
});
viewport.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.desiredTheta -= dx * 0.005;
orbit.desiredPhi = THREE.MathUtils.clamp(
orbit.desiredPhi - dy * 0.0045,
0.55,
1.49
);
});
function endDrag(event) {
dragging = false;
if (viewport.hasPointerCapture(event.pointerId)) {
viewport.releasePointerCapture(event.pointerId);
}
}
viewport.addEventListener("pointerup", endDrag);
viewport.addEventListener("pointercancel", endDrag);
viewport.addEventListener("contextmenu", (event) => event.preventDefault());
viewport.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.desiredRadius = THREE.MathUtils.clamp(
orbit.desiredRadius * Math.exp(event.deltaY * 0.001),
9,
24
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0x9bb2c0, 0x27140c, 1.5));
const keyLight = new THREE.DirectionalLight(0xffd3a0, 3.1);
keyLight.position.set(5, 10, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const coolFill = new THREE.DirectionalLight(0x7899b0, 0.9);
coolFill.position.set(-7, 5, 2);
scene.add(coolFill);
// -------------------------------------------------------------------------
// Shared helpers
// -------------------------------------------------------------------------
const dummy = new THREE.Object3D();
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const X_AXIS = new THREE.Vector3(1, 0, 0);
const Z_AXIS = new THREE.Vector3(0, 0, 1);
let seed = 1847;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
function hash(x, y = 0) {
const value = Math.sin(x * 127.1 + y * 311.7) * 43758.5453123;
return value - Math.floor(value);
}
function setInstance(mesh, index, position, scale, quaternion, color) {
dummy.position.copy(position);
dummy.quaternion.copy(quaternion || new THREE.Quaternion());
dummy.scale.copy(scale || new THREE.Vector3(1, 1, 1));
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
if (color) {
mesh.setColorAt(index, color);
}
}
function box(
width,
height,
depth,
material,
position,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
scene.add(mesh);
return mesh;
}
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.97,
metalness: 0
});
const darkStoneMaterial = new THREE.MeshStandardMaterial({
color: 0x2c211b,
roughness: 1
});
const woodMaterial = new THREE.MeshStandardMaterial({
color: 0x3c2418,
roughness: 0.82,
metalness: 0.03
});
const darkWoodMaterial = new THREE.MeshStandardMaterial({
color: 0x21150f,
roughness: 0.92
});
const bronzeMaterial = new THREE.MeshStandardMaterial({
color: 0xa56b32,
roughness: 0.48,
metalness: 0.5
});
// -------------------------------------------------------------------------
// Stone floor
// -------------------------------------------------------------------------
const floorBase = box(
16,
0.26,
13,
darkStoneMaterial,
new THREE.Vector3(0, -0.22, 0),
false,
true
);
const floorGeometry = new THREE.BoxGeometry(0.92, 0.14, 0.92);
const floorTiles = new THREE.InstancedMesh(
floorGeometry,
stoneMaterial,
13 * 11
);
floorTiles.castShadow = true;
floorTiles.receiveShadow = true;
const floorColors = [
new THREE.Color(0x49372c),
new THREE.Color(0x594033),
new THREE.Color(0x3e3029),
new THREE.Color(0x69503d),
new THREE.Color(0x514238)
];
let floorIndex = 0;
for (let iz = 0; iz < 11; iz++) {
for (let ix = 0; ix < 13; ix++) {
const x = -6 + ix;
const z = -4.5 + iz;
const y = -0.04 + random() * 0.035;
setInstance(
floorTiles,
floorIndex,
new THREE.Vector3(x, y, z),
new THREE.Vector3(1, 0.9 + random() * 0.22, 1),
null,
floorColors[Math.floor(random() * floorColors.length)]
);
floorIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
scene.add(floorTiles);
// -------------------------------------------------------------------------
// Ancient masonry walls
// -------------------------------------------------------------------------
const stoneColors = [
new THREE.Color(0x57483a),
new THREE.Color(0x685342),
new THREE.Color(0x493c32),
new THREE.Color(0x77604a),
new THREE.Color(0x51443a),
new THREE.Color(0x3f352e)
];
const backWallCount = 11 * 11;
const backWall = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.96, 0.52, 0.58),
stoneMaterial,
backWallCount
);
backWall.castShadow = true;
backWall.receiveShadow = true;
let wallIndex = 0;
for (let row = 0; row < 11; row++) {
for (let col = 0; col < 11; col++) {
const stagger = row % 2 === 0 ? 0 : 0.025;
const x = -5 + col + stagger;
const y = 0.28 + row * 0.56;
const z = -4.02 + (random() - 0.5) * 0.035;
setInstance(
backWall,
wallIndex,
new THREE.Vector3(x, y, z),
new THREE.Vector3(
0.97 + random() * 0.025,
0.94 + random() * 0.06,
1
),
null,
stoneColors[Math.floor(random() * stoneColors.length)]
);
wallIndex++;
}
}
backWall.instanceMatrix.needsUpdate = true;
backWall.instanceColor.needsUpdate = true;
scene.add(backWall);
const sideWallCount = 11 * 14;
const sideWall = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.58, 0.52, 0.96),
stoneMaterial,
sideWallCount
);
sideWall.castShadow = true;
sideWall.receiveShadow = true;
wallIndex = 0;
for (let row = 0; row < 11; row++) {
for (let col = 0; col < 14; col++) {
const stagger = row % 2 === 0 ? 0 : 0.025;
const z = -4 + col * 0.62 + stagger;
const y = 0.28 + row * 0.56;
const x = -5.02 + (random() - 0.5) * 0.035;
setInstance(
sideWall,
wallIndex,
new THREE.Vector3(x, y, z),
new THREE.Vector3(
1,
0.94 + random() * 0.06,
0.97 + random() * 0.025
),
null,
stoneColors[Math.floor(random() * stoneColors.length)]
);
wallIndex++;
}
}
sideWall.instanceMatrix.needsUpdate = true;
sideWall.instanceColor.needsUpdate = true;
scene.add(sideWall);
// -------------------------------------------------------------------------
// Textile palettes and pattern functions
// -------------------------------------------------------------------------
const textilePalette = [
new THREE.Color(0x76272c), // burgundy
new THREE.Color(0x3d2732), // dark plum
new THREE.Color(0x273d50), // indigo
new THREE.Color(0xc78036), // ochre
new THREE.Color(0xd8b67a), // ivory
new THREE.Color(0x9b402b), // rust
new THREE.Color(0x596052) // faded sage
];
function backTextilePattern(u, v) {
const edge = Math.min(u, 1 - u, v, 1 - v);
if (edge < 0.035) return 2;
if (edge < 0.075) {
return Math.floor(v * 28) % 2 === 0 ? 4 : 0;
}
const dx = Math.abs(u - 0.52) / 0.34;
const dy = Math.abs(v - 0.53) / 0.39;
const diamond = dx + dy;
if (diamond < 0.22) return 4;
if (diamond < 0.88) return 3;
if (diamond < 1.03) return 2;
if (
(u > 0.16 && u < 0.23) ||
(u > 0.77 && u < 0.84)
) {
const zigzag = Math.abs(((v * 7) % 1) - 0.5);
if (zigzag < 0.12) return 3;
}
if (v > 0.14 && v < 0.22 && Math.floor(u * 17) % 2 === 0) {
return 4;
}
const field = hash(Math.floor(u * 20), Math.floor(v * 24));
if (field > 0.86) return 5;
if (field < 0.12) return 1;
return 0;
}
function sideTextilePattern(u, v) {
const edge = Math.min(u, 1 - u, v, 1 - v);
if (edge < 0.035) return 2;
if (edge < 0.075) {
return Math.floor(u * 30) % 2 === 0 ? 4 : 0;
}
const cellU = (u * 5) % 1;
const cellV = (v * 6) % 1;
const diamond =
Math.abs(cellU - 0.5) + Math.abs(cellV - 0.5);
if (diamond < 0.18) return 4;
if (diamond < 0.42) return 3;
if (diamond < 0.49) return 2;
if (v > 0.46 && v < 0.54 && Math.floor(u * 24) % 2 === 0) {
return 4;
}
const field = hash(Math.floor(u * 22), Math.floor(v * 24) + 12);
if (field > 0.88) return 5;
if (field < 0.13) return 1;
return 0;
}
const textileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.93,
metalness: 0
});
// -------------------------------------------------------------------------
// Back textile: individual voxel fibers
// -------------------------------------------------------------------------
const backTextileWidth = 6.2;
const backTextileHeight = 4.5;
const backCols = 34;
const backRows = 24;
const backLeft = -2.75;
const backBottom = 0.77;
box(
backTextileWidth + 0.1,
backTextileHeight + 0.08,
0.08,
darkWoodMaterial,
new THREE.Vector3(backLeft + backTextileWidth / 2, 3.02, -3.67)
);
const backTextile = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.181, 0.181, 0.11),
textileMaterial,
backCols * backRows
);
backTextile.castShadow = true;
backTextile.receiveShadow = true;
let textileIndex = 0;
for (let row = 0; row < backRows; row++) {
for (let col = 0; col < backCols; col++) {
const u = col / (backCols - 1);
const v = row / (backRows - 1);
const x = backLeft + u * backTextileWidth;
const y = backBottom + v * backTextileHeight;
const z = -3.55 + ((row + col) % 2 === 0 ? 0.008 : -0.008);
const color = textilePalette[backTextilePattern(u, v)];
setInstance(
backTextile,
textileIndex,
new THREE.Vector3(x, y, z),
new THREE.Vector3(
0.97,
0.97,
(row + col) % 2 === 0 ? 1.12 : 0.78
),
null,
color
);
textileIndex++;
}
}
backTextile.instanceMatrix.needsUpdate = true;
backTextile.instanceColor.needsUpdate = true;
scene.add(backTextile);
// -------------------------------------------------------------------------
// Side textile: perpendicular woven wall
// -------------------------------------------------------------------------
const sideTextileWidth = 5.8;
const sideTextileHeight = 4.5;
const sideCols = 32;
const sideRows = 24;
const sideStart = -3.5;
box(
0.08,
sideTextileHeight + 0.08,
sideTextileWidth + 0.1,
darkWoodMaterial,
new THREE.Vector3(-4.67, 3.02, sideStart + sideTextileWidth / 2)
);
const sideTextile = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.181, 0.181, 0.11),
textileMaterial,
sideCols * sideRows
);
sideTextile.castShadow = true;
sideTextile.receiveShadow = true;
const sideQuaternion = new THREE.Quaternion().setFromAxisAngle(
Y_AXIS,
Math.PI / 2
);
textileIndex = 0;
for (let row = 0; row < sideRows; row++) {
for (let col = 0; col < sideCols; col++) {
const u = col / (sideCols - 1);
const v = row / (sideRows - 1);
const z = sideStart + u * sideTextileWidth;
const y = backBottom + v * sideTextileHeight;
const x = -4.55 + ((row + col) % 2 === 0 ? 0.008 : -0.008);
const color = textilePalette[sideTextilePattern(u, v)];
setInstance(
sideTextile,
textileIndex,
new THREE.Vector3(x, y, z),
new THREE.Vector3(
0.97,
0.97,
(row + col) % 2 === 0 ? 1.12 : 0.78
),
sideQuaternion,
color
);
textileIndex++;
}
}
sideTextile.instanceMatrix.needsUpdate = true;
sideTextile.instanceColor.needsUpdate = true;
scene.add(sideTextile);
// Hanging rods.
box(
6.55,
0.11,
0.13,
woodMaterial,
new THREE.Vector3(backLeft + backTextileWidth / 2, 5.32, -3.49)
);
box(
0.13,
0.11,
6.15,
woodMaterial,
new THREE.Vector3(-4.49, 5.32, sideStart + sideTextileWidth / 2)
);
// -------------------------------------------------------------------------
// Fringes
// -------------------------------------------------------------------------
const fringeMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 1
});
const backFringe = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.032, 0.44, 0.032),
fringeMaterial,
30
);
backFringe.castShadow = true;
for (let i = 0; i < 30; i++) {
const x = backLeft + 0.08 + (i / 29) * (backTextileWidth - 0.16);
const length = 0.72 + random() * 0.45;
const q = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, 0, (random() - 0.5) * 0.16)
);
setInstance(
backFringe,
i,
new THREE.Vector3(x, 0.56 - length * 0.11, -3.48),
new THREE.Vector3(1, length, 1),
q,
i % 5 === 0 ? textilePalette[4] : textilePalette[i % 2 ? 1 : 0]
);
}
backFringe.instanceMatrix.needsUpdate = true;
backFringe.instanceColor.needsUpdate = true;
scene.add(backFringe);
const sideFringe = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.032, 0.44, 0.032),
fringeMaterial,
27
);
sideFringe.castShadow = true;
for (let i = 0; i < 27; i++) {
const z = sideStart + 0.08 + (i / 26) * (sideTextileWidth - 0.16);
const length = 0.72 + random() * 0.45;
setInstance(
sideFringe,
i,
new THREE.Vector3(-4.48, 0.56 - length * 0.11, z),
new THREE.Vector3(1, length, 1),
null,
i % 6 === 0 ? textilePalette[3] : textilePalette[i % 2 ? 1 : 0]
);
}
sideFringe.instanceMatrix.needsUpdate = true;
sideFringe.instanceColor.needsUpdate = true;
scene.add(sideFringe);
// -------------------------------------------------------------------------
// Wooden gallows and suspension rope
// -------------------------------------------------------------------------
box(
8.1,
0.27,
0.34,
woodMaterial,
new THREE.Vector3(-0.72, 6.83, 0.8)
);
box(
0.38,
0.62,
0.45,
darkWoodMaterial,
new THREE.Vector3(-4.55, 6.58, 0.8)
);
// Short voxel wood grain blocks.
for (let i = 0; i < 12; i++) {
box(
0.025,
0.16 + random() * 0.09,
0.355,
darkWoodMaterial,
new THREE.Vector3(-4.3 + i * 0.64, 6.85, 0.8)
);
}
const SPINDLE_POSITION = new THREE.Vector3(0.55, 4.18, 0.8);
const ropeMaterial = new THREE.MeshStandardMaterial({
color: 0xb99b64,
roughness: 0.96
});
const ropeSegmentGeometry = new THREE.CylinderGeometry(
0.024,
0.024,
0.085,
6
);
for (let i = 0; i < 17; i++) {
const rope = new THREE.Mesh(ropeSegmentGeometry, ropeMaterial);
rope.position.set(
SPINDLE_POSITION.x + Math.sin(i * 1.3) * 0.012,
5.26 + i * 0.085,
SPINDLE_POSITION.z + Math.cos(i * 1.3) * 0.012
);
rope.rotation.y = i * 0.72;
rope.castShadow = true;
scene.add(rope);
}
// -------------------------------------------------------------------------
// Voxel drop spindle
// -------------------------------------------------------------------------
const spindle = new THREE.Group();
spindle.position.copy(SPINDLE_POSITION);
scene.add(spindle);
const spindleShaft = new THREE.Mesh(
new THREE.BoxGeometry(0.13, 1.78, 0.13),
woodMaterial
);
spindleShaft.castShadow = true;
spindle.add(spindleShaft);
const spindleStripe = new THREE.Mesh(
new THREE.BoxGeometry(0.035, 0.64, 0.035),
bronzeMaterial
);
spindleStripe.position.set(0.078, 0.13, 0.018);
spindleStripe.castShadow = true;
spindle.add(spindleStripe);
// Stepped, pointed ends.
const tipPieces = [
[-0.96, 0.12, 0.17],
[-1.06, 0.085, 0.12],
[-1.145, 0.048, 0.075],
[0.96, 0.12, 0.17],
[1.06, 0.085, 0.12],
[1.145, 0.048, 0.075]
];
for (const [y, width, height] of tipPieces) {
const tip = new THREE.Mesh(
new THREE.BoxGeometry(width, height, width),
darkWoodMaterial
);
tip.position.y = y;
tip.castShadow = true;
spindle.add(tip);
}
// Whorl built from stacked square blocks.
const whorlLayers = [
[-0.58, 0.50, 0.115],
[-0.47, 0.66, 0.115],
[-0.35, 0.72, 0.125],
[-0.23, 0.62, 0.115],
[-0.11, 0.43, 0.105]
];
for (const [y, width, height] of whorlLayers) {
const layer = new THREE.Mesh(
new THREE.BoxGeometry(width, height, width),
y === -0.35 ? bronzeMaterial : darkWoodMaterial
);
layer.position.y = y;
layer.castShadow = true;
layer.receiveShadow = true;
spindle.add(layer);
}
// Asymmetric inlays make the rotation legible.
const whorlInlay = new THREE.Mesh(
new THREE.BoxGeometry(0.12, 0.09, 0.035),
new THREE.MeshStandardMaterial({
color: 0xd0a451,
roughness: 0.5,
metalness: 0.25
})
);
whorlInlay.position.set(0, -0.47, 0.345);
spindle.add(whorlInlay);
const spindleNotch = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.16, 0.055),
new THREE.MeshStandardMaterial({
color: 0x8b3028,
roughness: 0.9
})
);
spindleNotch.position.set(0, -0.35, 0.375);
spindle.add(spindleNotch);
// -------------------------------------------------------------------------
// Dynamic tube geometry for the continuous thread
// -------------------------------------------------------------------------
class DynamicTube {
constructor(segments, radialSegments, radius, material) {
this.segments = segments;
this.radialSegments = radialSegments;
this.radius = radius;
const vertexCount = (segments + 1) * radialSegments;
this.positions = new Float32Array(vertexCount * 3);
this.normals = new Float32Array(vertexCount * 3);
const indices = [];
for (let i = 0; i < segments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * radialSegments + j;
const b = i * radialSegments + ((j + 1) % radialSegments);
const c = (i + 1) * radialSegments + j;
const d = (i + 1) * radialSegments + ((j + 1) % radialSegments);
indices.push(a, c, b, b, c, d);
}
}
this.geometry = new THREE.BufferGeometry();
this.geometry.setAttribute(
"position",
new THREE.BufferAttribute(this.positions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
this.geometry.setAttribute(
"normal",
new THREE.BufferAttribute(this.normals, 3).setUsage(
THREE.DynamicDrawUsage
)
);
this.geometry.setIndex(indices);
this.mesh = new THREE.Mesh(this.geometry, material);
this.mesh.castShadow = true;
this.mesh.frustumCulled = false;
scene.add(this.mesh);
this.tangents = Array.from(
{ length: segments + 1 },
() => new THREE.Vector3()
);
this.frames = Array.from(
{ length: segments + 1 },
() => new THREE.Vector3()
);
this.binormals = Array.from(
{ length: segments + 1 },
() => new THREE.Vector3()
);
this.rotation = new THREE.Quaternion();
}
update(points) {
const count = this.segments + 1;
for (let i = 0; i < count; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(count - 1, i + 1)];
this.tangents[i].subVectors(next, previous).normalize();
}
for (let i = 0; i < count; i++) {
const tangent = this.tangents[i];
const normal = this.frames[i];
if (i === 0) {
normal.crossVectors(tangent, Z_AXIS);
if (normal.lengthSq() < 0.00001) {
normal.crossVectors(tangent, X_AXIS);
}
normal.normalize();
} else {
this.rotation.setFromUnitVectors(
this.tangents[i - 1],
tangent
);
normal.copy(this.frames[i - 1]).applyQuaternion(this.rotation);
normal.addScaledVector(tangent, -normal.dot(tangent)).normalize();
}
const binormal = this.binormals[i];
binormal.crossVectors(tangent, normal).normalize();
for (let j = 0; j < this.radialSegments; j++) {
const angle = (j / this.radialSegments) * Math.PI * 2;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const nx = normal.x * cos + binormal.x * sin;
const ny = normal.y * cos + binormal.y * sin;
const nz = normal.z * cos + binormal.z * sin;
const vertex = i * this.radialSegments + j;
const offset = vertex * 3;
this.positions[offset] = points[i].x + nx * this.radius;
this.positions[offset + 1] = points[i].y + ny * this.radius;
this.positions[offset + 2] = points[i].z + nz * this.radius;
this.normals[offset] = nx;
this.normals[offset + 1] = ny;
this.normals[offset + 2] = nz;
}
}
this.geometry.attributes.position.needsUpdate = true;
this.geometry.attributes.normal.needsUpdate = true;
}
}
const threadMaterial = new THREE.MeshStandardMaterial({
color: 0xe0a84e,
roughness: 0.5,
metalness: 0.12,
emissive: 0x4c2706,
emissiveIntensity: 0.45
});
const thread = new DynamicTube(220, 6, 0.027, threadMaterial);
const twistMaterial = new THREE.MeshStandardMaterial({
color: 0xf3cf7b,
roughness: 0.62,
emissive: 0x3a1d03,
emissiveIntensity: 0.25
});
const twistAccent = new DynamicTube(120, 4, 0.0085, twistMaterial);
const anchorMaterial = new THREE.MeshStandardMaterial({
color: 0xe9bd64,
roughness: 0.45,
emissive: 0x5a2e05,
emissiveIntensity: 0.6
});
const threadAnchor = new THREE.Mesh(
new THREE.BoxGeometry(0.09, 0.09, 0.09),
anchorMaterial
);
threadAnchor.position.set(3.15, 1.17, -3.43);
threadAnchor.castShadow = true;
scene.add(threadAnchor);
// -------------------------------------------------------------------------
// Moving winding glints
// -------------------------------------------------------------------------
const glintMaterial = new THREE.MeshStandardMaterial({
color: 0xffe3a0,
emissive: 0xffa62e,
emissiveIntensity: 2.4,
roughness: 0.35
});
const glintCount = 18;
const glints = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.052, 0.052, 0.052),
glintMaterial,
glintCount
);
glints.frustumCulled = false;
scene.add(glints);
// -------------------------------------------------------------------------
// Brazier and flickering voxel flame
// -------------------------------------------------------------------------
const brazier = new THREE.Group();
brazier.position.set(4.05, 0, 2.6);
scene.add(brazier);
const brazierMaterial = new THREE.MeshStandardMaterial({
color: 0x3b332c,
roughness: 0.92
});
const brazierPieces = [
[0.78, 0.16, 0.78, 0, 0.12],
[0.61, 0.13, 0.61, 0, 0.27],
[0.76, 0.13, 0.76, 0, 0.40],
[0.92, 0.13, 0.92, 0, 0.53]
];
for (const [w, h, d, x, y] of brazierPieces) {
const piece = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
brazierMaterial
);
piece.position.set(x, y, 0);
piece.castShadow = true;
piece.receiveShadow = true;
brazier.add(piece);
}
const flameMaterial = new THREE.MeshStandardMaterial({
color: 0xffb03d,
emissive: 0xff6b16,
emissiveIntensity: 2.8,
roughness: 0.55,
transparent: true,
opacity: 0.9
});
const flameCount = 9;
const flames = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.15, 0.28, 0.15),
flameMaterial,
flameCount
);
flames.frustumCulled = false;
brazier.add(flames);
const brazierLight = new THREE.PointLight(0xff7b28, 17, 7, 2);
brazierLight.position.set(4.05, 1.1, 2.6);
scene.add(brazierLight);
// -------------------------------------------------------------------------
// Floating dust
// -------------------------------------------------------------------------
const dustCount = 150;
const dustPositions = new Float32Array(dustCount * 3);
const dustSpeeds = new Float32Array(dustCount);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = -5 + random() * 10;
dustPositions[i * 3 + 1] = 0.3 + random() * 7;
dustPositions[i * 3 + 2] = -3.5 + random() * 7;
dustSpeeds[i] = 0.025 + random() * 0.055;
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xd9bc83,
size: 0.027,
transparent: true,
opacity: 0.42,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Thread construction
// -------------------------------------------------------------------------
const threadPoints = Array.from(
{ length: 221 },
() => new THREE.Vector3()
);
const accentPoints = Array.from(
{ length: 121 },
() => new THREE.Vector3()
);
const coilRadius = 0.225;
const coilTurns = 16;
const coilBottom = 3.88;
const coilTop = 4.76;
const spoolRotationSpeed = 2.35;
const helixPoint = new THREE.Vector3();
const helixTangent = new THREE.Vector3();
const curveTangent = new THREE.Vector3();
const curveNormal = new THREE.Vector3();
const curveBinormal = new THREE.Vector3();
const rawPoint = new THREE.Vector3();
function buildThread(time) {
const spindlePhase = time * spoolRotationSpeed;
const baseAngle = 0.18;
// The world angle follows the spindle's local rotation.
const startAngle = baseAngle - spindlePhase;
const endpoint = new THREE.Vector3(
SPINDLE_POSITION.x + Math.cos(startAngle) * coilRadius,
coilBottom,
SPINDLE_POSITION.z + Math.sin(startAngle) * coilRadius
);
const helixDirection = new THREE.Vector3(
-Math.sin(startAngle),
0,
Math.cos(startAngle)
).normalize();
const approach = endpoint.clone().addScaledVector(
helixDirection,
-0.48
);
const feedCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(3.15, 1.17, -3.43),
new THREE.Vector3(3.36, 1.54, -2.85),
new THREE.Vector3(3.02, 2.22, -1.72),
new THREE.Vector3(2.15, 2.72, -0.57),
new THREE.Vector3(1.32, 3.02, 0.36),
approach,
endpoint
],
false,
"centripetal",
0.5
);
const feedSamples = feedCurve.getPoints(80);
for (let i = 0; i < feedSamples.length; i++) {
threadPoints[i].copy(feedSamples[i]);
}
for (let i = 0; i < 140; i++) {
const t = i / 139;
const angle = startAngle + t * coilTurns * Math.PI * 2;
threadPoints[80 + i].set(
SPINDLE_POSITION.x + Math.cos(angle) * coilRadius,
coilBottom + t * (coilTop - coilBottom),
SPINDLE_POSITION.z + Math.sin(angle) * coilRadius
);
}
thread.update(threadPoints);
// A narrow helical ridge makes the feed strand visibly twist.
const rawFeed = feedCurve.getPoints(120);
for (let i = 0; i < rawFeed.length; i++) {
rawPoint.copy(rawFeed[i]);
const previous = rawFeed[Math.max(0, i - 1)];
const next = rawFeed[Math.min(rawFeed.length - 1, i + 1)];
curveTangent.subVectors(next, previous).normalize();
curveNormal.crossVectors(curveTangent, Z_AXIS);
if (curveNormal.lengthSq() < 0.00001) {
curveNormal.crossVectors(curveTangent, X_AXIS);
}
curveNormal.normalize();
curveBinormal.crossVectors(curveTangent, curveNormal).normalize();
const angle = i * 0.72;
const ridge = 0.027;
accentPoints[i]
.copy(rawPoint)
.addScaledVector(curveNormal, Math.cos(angle) * ridge)
.addScaledVector(curveBinormal, Math.sin(angle) * ridge);
}
twistAccent.update(accentPoints);
// Glints travel upward around the rotating shaft.
for (let i = 0; i < glintCount; i++) {
const t = (i / glintCount + time * 0.13) % 1;
const angle = baseAngle + t * coilTurns * Math.PI * 2 - spindlePhase;
const pulse = 0.75 + Math.sin(time * 7 + i * 1.9) * 0.25;
helixPoint.set(
SPINDLE_POSITION.x + Math.cos(angle) * coilRadius,
coilBottom + t * (coilTop - coilBottom),
SPINDLE_POSITION.z + Math.sin(angle) * coilRadius
);
setInstance(
glints,
i,
helixPoint,
new THREE.Vector3(pulse, pulse, pulse),
null,
null
);
}
glints.instanceMatrix.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
// Damped camera movement.
const damping = 1 - Math.exp(-8 * dt);
orbit.theta += (orbit.desiredTheta - orbit.theta) * damping;
orbit.phi += (orbit.desiredPhi - orbit.phi) * damping;
orbit.radius += (orbit.desiredRadius - orbit.radius) * damping;
orbit.target.lerp(orbit.desiredTarget, damping);
spherical.set(orbit.radius, orbit.phi, orbit.theta);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(orbit.target).add(cameraOffset);
camera.lookAt(orbit.target);
// The spindle twists continuously around its suspended axis.
spindle.rotation.y = time * spoolRotationSpeed;
buildThread(time);
// Pulsing thread anchor.
const anchorScale = 0.9 + Math.sin(time * 4.2) * 0.14;
threadAnchor.scale.setScalar(anchorScale);
// Voxel flame movement.
for (let i = 0; i < flameCount; i++) {
const phase = time * 6.2 + i * 1.73;
const spread = ((i % 3) - 1) * 0.12;
const height = 0.55 + (i % 4) * 0.1;
const flicker = 0.72 + Math.sin(phase) * 0.22;
dummy.position.set(
spread + Math.sin(phase * 0.7) * 0.035,
height + Math.sin(phase * 0.8) * 0.05,
Math.cos(phase * 0.6) * 0.035
);
dummy.quaternion.identity();
dummy.scale.set(
0.6 + flicker * 0.45,
0.75 + flicker * 0.8,
0.6 + flicker * 0.45
);
dummy.updateMatrix();
flames.setMatrixAt(i, dummy.matrix);
}
flames.instanceMatrix.needsUpdate = true;
brazierLight.intensity =
15.5 + Math.sin(time * 8.1) * 1.5 + Math.sin(time * 13.7) * 0.7;
// Dust drifts upward through the warm light.
const dustAttribute = dustGeometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
dustAttribute.array[i * 3] +=
Math.sin(time * 0.32 + i) * dt * 0.012;
dustAttribute.array[i * 3 + 1] += dustSpeeds[i] * dt;
dustAttribute.array[i * 3 + 2] +=
Math.cos(time * 0.25 + i * 0.7) * dt * 0.009;
if (dustAttribute.array[i * 3 + 1] > 7.3) {
dustAttribute.array[i * 3 + 1] = 0.35;
}
}
dustAttribute.needsUpdate = true;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```