Prompt specification
Build or customize the Three.js 3D scene "Change fiber amount and compare sheets" 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: Change fiber amount and compare sheets
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/change-fiber-amount-and-compare-sheets-x2276
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring papermaking in Han-era China. Let users vary an illustrative fiber count before lifting the screen. Show relative sheet coverage and thickness while labeling the process as a simplified teaching model. Voxel style.
Working Three.js Starter (change-fiber-amount-and-compare-sheets-x2276):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#e8dcc3">
<title>Han Paper Workshop</title>
<style>
:root {
--ink: #302a25;
--muted: #74695b;
--paper: #f5ecd9;
--paper-strong: #fffaf0;
--line: #cdbd9f;
--red: #9f3f32;
--red-dark: #7c2d24;
--indigo: #344d61;
--green: #617052;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8dcc3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
cursor: pointer;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
outline: none;
touch-action: none;
}
#hud {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.brand {
position: absolute;
top: 24px;
left: 28px;
max-width: 390px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
}
.eyebrow {
margin-bottom: 6px;
color: var(--red-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 48px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.025em;
}
.subtitle {
margin: 10px 0 0;
color: #5d5348;
font-size: 13px;
line-height: 1.5;
}
.model-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 13px;
padding: 7px 10px;
border: 1px solid rgba(93, 78, 57, 0.25);
border-radius: 999px;
background: rgba(255, 250, 240, 0.7);
color: #625547;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.model-badge::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--red);
content: "";
}
.control-card {
position: absolute;
left: 28px;
bottom: 78px;
width: min(340px, calc(100vw - 56px));
padding: 20px;
border: 1px solid rgba(101, 81, 57, 0.24);
border-radius: 18px;
background: rgba(250, 243, 226, 0.93);
box-shadow:
0 18px 48px rgba(66, 48, 28, 0.15),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
pointer-events: auto;
backdrop-filter: blur(14px);
}
.panel-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 14px;
margin-bottom: 18px;
}
.panel-kicker {
margin: 0 0 4px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.panel-title {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 500;
}
.step-number {
display: grid;
width: 34px;
height: 34px;
flex: 0 0 auto;
place-items: center;
border-radius: 50%;
background: var(--red);
color: white;
font-family: Georgia, "Times New Roman", serif;
font-size: 17px;
box-shadow: 0 5px 13px rgba(127, 45, 36, 0.25);
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 10px;
font-size: 12px;
font-weight: 750;
}
.control-label output {
color: var(--red-dark);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
appearance: none;
border-radius: 999px;
background: linear-gradient(
90deg,
var(--red) 0%,
var(--red) var(--fill, 35%),
#d9cbb3 var(--fill, 35%),
#d9cbb3 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 19px;
height: 19px;
appearance: none;
border: 3px solid var(--paper-strong);
border-radius: 50%;
background: var(--red);
box-shadow: 0 2px 8px rgba(68, 42, 30, 0.3);
}
input[type="range"]::-moz-range-thumb {
width: 14px;
height: 14px;
border: 3px solid var(--paper-strong);
border-radius: 50%;
background: var(--red);
box-shadow: 0 2px 8px rgba(68, 42, 30, 0.3);
}
input[type="range"]:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #88796a;
font-size: 10px;
}
.metrics {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 17px 0 14px;
}
.metric {
min-width: 0;
padding: 12px;
border: 1px solid rgba(101, 81, 57, 0.15);
border-radius: 12px;
background: rgba(255, 252, 244, 0.72);
}
.metric span {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
line-height: 1.25;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.metric strong {
display: block;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
font-variant-numeric: tabular-nums;
}
.metric small {
display: block;
margin-top: 2px;
color: #8c7e6d;
font-size: 9px;
}
.primary-button {
width: 100%;
min-height: 46px;
padding: 11px 16px;
border: 0;
border-radius: 12px;
background: var(--red);
color: white;
font-weight: 800;
letter-spacing: 0.01em;
box-shadow: 0 7px 16px rgba(127, 45, 36, 0.22);
transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}
.primary-button:hover:not(:disabled) {
transform: translateY(-1px);
background: var(--red-dark);
}
.primary-button:active:not(:disabled) {
transform: translateY(1px);
}
.primary-button:disabled {
cursor: wait;
opacity: 0.68;
}
.status {
min-height: 32px;
margin: 12px 2px 0;
color: #6f6254;
font-size: 11px;
line-height: 1.45;
}
.teaching-note {
margin: 13px 0 0;
padding-top: 13px;
border-top: 1px solid rgba(101, 81, 57, 0.14);
color: #7b6e5e;
font-size: 10px;
line-height: 1.45;
}
.teaching-note strong {
color: #5d5144;
}
.view-tools {
position: absolute;
top: 24px;
right: 26px;
display: flex;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.small-button {
padding: 9px 12px;
border: 1px solid rgba(101, 81, 57, 0.22);
border-radius: 10px;
background: rgba(255, 250, 240, 0.82);
color: #5e5144;
font-size: 11px;
font-weight: 750;
box-shadow: 0 5px 18px rgba(65, 47, 30, 0.08);
backdrop-filter: blur(8px);
}
.view-help {
color: rgba(66, 57, 47, 0.72);
font-size: 10px;
font-weight: 700;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.annotation {
position: absolute;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(99, 78, 55, 0.18);
border-radius: 9px;
background: rgba(255, 250, 239, 0.87);
color: #594d40;
font-size: 10px;
font-weight: 750;
white-space: nowrap;
box-shadow: 0 7px 20px rgba(57, 42, 25, 0.12);
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.annotation::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--red);
box-shadow: 0 0 0 3px rgba(159, 63, 50, 0.14);
content: "";
}
.process-strip {
position: absolute;
right: 26px;
bottom: 26px;
display: flex;
align-items: center;
gap: 8px;
padding: 10px 12px;
border: 1px solid rgba(101, 81, 57, 0.18);
border-radius: 13px;
background: rgba(250, 243, 226, 0.87);
box-shadow: 0 8px 24px rgba(66, 48, 28, 0.09);
backdrop-filter: blur(10px);
}
.process-step {
display: flex;
align-items: center;
gap: 7px;
color: #8a7d6c;
font-size: 10px;
font-weight: 750;
}
.process-step i {
display: grid;
width: 21px;
height: 21px;
place-items: center;
border-radius: 50%;
background: #ddd0b8;
color: #766956;
font-family: Georgia, serif;
font-size: 11px;
font-style: normal;
}
.process-step.active {
color: var(--red-dark);
}
.process-step.active i {
background: var(--red);
color: white;
}
.process-arrow {
color: #b0a28e;
font-size: 12px;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #e8dcc3;
color: #695b4b;
font-family: Georgia, serif;
font-size: 20px;
}
#loading.hidden {
display: none;
}
@media (max-width: 760px) {
.brand {
top: 16px;
left: 17px;
max-width: calc(100vw - 34px);
}
h1 {
font-size: 31px;
}
.subtitle {
max-width: 270px;
font-size: 11px;
}
.model-badge {
margin-top: 9px;
padding: 6px 9px;
font-size: 9px;
}
.control-card {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.panel-top {
margin-bottom: 10px;
}
.panel-title {
font-size: 19px;
}
.metrics {
margin: 11px 0;
}
.metric {
padding: 8px 10px;
}
.metric strong {
font-size: 20px;
}
.teaching-note {
display: none;
}
.status {
min-height: 26px;
margin-top: 8px;
font-size: 10px;
}
.view-tools {
top: 16px;
right: 14px;
}
.view-help {
display: none;
}
.process-strip {
display: none;
}
.annotation {
display: none;
}
}
@media (max-height: 680px) and (min-width: 761px) {
.control-card {
bottom: 18px;
padding: 14px;
}
.teaching-note {
display: none;
}
.status {
min-height: 24px;
}
.brand {
top: 16px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel-style Han dynasty papermaking workshop. Drag to orbit and scroll to zoom."
></canvas>
<div id="hud">
<header class="brand">
<div class="eyebrow">Eastern Han · Craft Laboratory</div>
<h1>Paper from the<br>Workshop</h1>
<p class="subtitle">
Prepare a symbolic bark-and-hemp pulp, then lift the bamboo mould to reveal a formed sheet.
</p>
<div class="model-badge">Simplified teaching model</div>
</header>
<section class="control-card" aria-label="Papermaking controls">
<div class="panel-top">
<div>
<p class="panel-kicker">Mould preparation</p>
<h2 class="panel-title">Choose the fiber count</h2>
</div>
<div class="step-number" id="stepNumber">1</div>
</div>
<label class="control-label" for="fiberCount">
<span>Illustrative fibers</span>
<output id="fiberOutput" for="fiberCount">40 bundles</output>
</label>
<input
id="fiberCount"
type="range"
min="12"
max="96"
step="1"
value="40"
aria-describedby="teachingNote"
>
<div class="range-ends">
<span>Lightly filled</span>
<span>Densely filled</span>
</div>
<div class="metrics">
<div class="metric">
<span>Relative coverage</span>
<strong id="coverageValue">—</strong>
<small id="coverageCaption">projected sheet area</small>
</div>
<div class="metric">
<span>Relative thickness</span>
<strong id="thicknessValue">—</strong>
<small>reference units, not millimetres</small>
</div>
</div>
<button class="primary-button" id="actionButton" type="button">
Lift the screen
</button>
<p class="status" id="status" aria-live="polite">
The mould is resting in the pulp vat. Adjust the fiber count before lifting.
</p>
<p class="teaching-note" id="teachingNote">
<strong>Simplified teaching model.</strong> Fiber count is symbolic rather than a recipe.
Coverage and thickness are relative comparisons, not measured historical or laboratory values.
</p>
</section>
<div class="view-tools">
<span class="view-help">Drag to orbit · scroll to zoom</span>
<button class="small-button" id="resetView" type="button">Reset view</button>
</div>
<div class="annotation" id="vatAnnotation">Pulp vat</div>
<div class="annotation" id="screenAnnotation">Bamboo mould</div>
<div class="process-strip" aria-label="Papermaking stages">
<div class="process-step active" id="stepOne">
<i>1</i><span>Prepare pulp</span>
</div>
<span class="process-arrow">→</span>
<div class="process-step" id="stepTwo">
<i>2</i><span>Lift mould</span>
</div>
<span class="process-arrow">→</span>
<div class="process-step" id="stepThree">
<i>3</i><span>Form sheet</span>
</div>
</div>
</div>
</div>
<div id="loading">Preparing the Han paper workshop…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// DOM and application state
// ------------------------------------------------------------
const canvas = document.querySelector("#scene");
const slider = document.querySelector("#fiberCount");
const fiberOutput = document.querySelector("#fiberOutput");
const coverageValue = document.querySelector("#coverageValue");
const thicknessValue = document.querySelector("#thicknessValue");
const coverageCaption = document.querySelector("#coverageCaption");
const actionButton = document.querySelector("#actionButton");
const statusElement = document.querySelector("#status");
const stepNumber = document.querySelector("#stepNumber");
const stepOne = document.querySelector("#stepOne");
const stepTwo = document.querySelector("#stepTwo");
const stepThree = document.querySelector("#stepThree");
const vatAnnotation = document.querySelector("#vatAnnotation");
const screenAnnotation = document.querySelector("#screenAnnotation");
const MIN_FIBERS = 12;
const MAX_FIBERS = 96;
const LIFT_START_Y = 1.36;
const LIFT_END_Y = 3.26;
const LIFT_DURATION = 2.8;
let fiberCount = Number(slider.value);
let projectedCoverage = 0;
let relativeThickness = 0;
let phase = "ready"; // ready | lifting | done
let liftTime = 0;
let liftProgress = 0;
// ------------------------------------------------------------
// Renderer, scene, camera, and lighting
// ------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8dcc3);
scene.fog = new THREE.Fog(0xe8dcc3, 21, 38);
const camera = new THREE.OrthographicCamera(-8, 8, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.35, 0);
const cameraSpherical = new THREE.Spherical(17.5, 1.03, 0.67);
let cameraAzimuth = 0.67;
let cameraPolar = 1.03;
function updateCamera() {
cameraSpherical.set(17.5, cameraPolar, cameraAzimuth);
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xfff7e3, 0x76624b, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.4);
sun.position.set(-7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -9;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb9d1db, 0.75);
fill.position.set(9, 6, -7);
scene.add(fill);
// ------------------------------------------------------------
// 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.88,
metalness: 0,
...options
})
);
}
return materialCache.get(key);
}
function box(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 seededRandom(seed) {
let value = seed >>> 0;
return () => {
value += 0x6d2b79f5;
let result = value;
result = Math.imul(result ^ (result >>> 15), result | 1);
result ^= result + Math.imul(result ^ (result >>> 7), result | 61);
return ((result ^ (result >>> 14)) >>> 0) / 4294967296;
};
}
function shuffled(array, random) {
const result = [...array];
for (let i = result.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
// ------------------------------------------------------------
// Workshop architecture and floor
// ------------------------------------------------------------
const workshop = new THREE.Group();
scene.add(workshop);
box(workshop, [14.8, 0.42, 10.1], [0, -0.28, 0], 0x78614a);
box(workshop, [14.3, 0.13, 9.7], [0, -0.02, 0], 0xa8875d);
const plankColors = [0xb49368, 0xaa8760, 0xbb9b6f, 0xa5825b, 0xb08d63];
for (let row = 0; row < 10; row++) {
const z = -4.35 + row * 0.97;
box(
workshop,
[14.05, 0.09, 0.91],
[0, 0.075, z],
plankColors[row % plankColors.length]
);
for (let joint = 0; joint < 4; joint++) {
const x = -5.2 + joint * 3.5 + (row % 2) * 0.55;
box(
workshop,
[0.025, 0.012, 0.86],
[x, 0.126, z],
0x806548
);
}
}
// Rear plaster wall, posts, and beams.
box(workshop, [13.9, 2.7, 0.22], [0, 1.45, -4.55], 0xd3c3a4);
for (let panel = 0; panel < 7; panel++) {
const x = -5.3 + panel * 1.77;
box(workshop, [1.68, 2.52, 0.05], [x, 1.44, -4.405], 0xcbbb9b);
box(workshop, [0.045, 2.55, 0.065], [x - 0.84, 1.44, -4.35], 0x795a3e);
}
for (const x of [-6.55, -3.25, 0, 3.25, 6.55]) {
box(workshop, [0.24, 4.15, 0.29], [x, 2.13, -4.35], 0x684a33);
box(workshop, [0.49, 0.22, 0.54], [x, 0.24, -4.35], 0x5c4130);
}
box(workshop, [13.9, 0.28, 0.34], [0, 4.13, -4.32], 0x62432f);
box(workshop, [13.4, 0.17, 0.25], [0, 3.65, -4.28], 0x76513a);
// Small lattice openings above the plaster.
for (let x = -5.8; x <= 5.9; x += 1.45) {
box(workshop, [0.065, 0.9, 0.09], [x, 3.08, -4.31], 0x755238);
}
for (let y = 2.8; y < 3.6; y += 0.4) {
box(workshop, [12.9, 0.065, 0.09], [0, y, -4.3], 0x755238);
}
// ------------------------------------------------------------
// Pulp vat
// ------------------------------------------------------------
const vat = new THREE.Group();
vat.position.set(-0.9, 0, 0.3);
scene.add(vat);
for (const x of [-1.45, 1.45]) {
for (const z of [-0.98, 0.98]) {
box(vat, [0.28, 0.76, 0.28], [x, 0.45, z], 0x60432e);
}
}
box(vat, [3.55, 0.22, 2.68], [0, 0.82, 0], 0x6f4c31);
box(vat, [3.68, 0.92, 0.23], [0, 1.13, 1.22], 0x805638);
box(vat, [3.68, 0.92, 0.23], [0, 1.13, -1.22], 0x765035);
box(vat, [0.23, 0.92, 2.45], [-1.73, 1.13, 0], 0x704b31);
box(vat, [0.23, 0.92, 2.45], [1.73, 1.13, 0], 0x704b31);
// Raised dark trim gives the vat a blocky, constructed silhouette.
box(vat, [3.8, 0.13, 0.31], [0, 1.61, 1.23], 0x563b2b);
box(vat, [3.8, 0.13, 0.31], [0, 1.61, -1.23], 0x563b2b);
box(vat, [0.31, 0.13, 2.5], [-1.74, 1.61, 0], 0x563b2b);
box(vat, [0.31, 0.13, 2.5], [1.74, 1.61, 0], 0x563b2b);
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x668f91,
roughness: 0.26,
metalness: 0.02,
transparent: true,
opacity: 0.76,
depthWrite: false
});
const water = new THREE.Mesh(
new THREE.BoxGeometry(3.42, 0.075, 2.35),
waterMaterial
);
water.position.set(0, 1.48, 0);
water.receiveShadow = true;
water.renderOrder = 4;
vat.add(water);
// Surface fibers in the pulp.
const pulpRandom = seededRandom(3127);
const pulpSpecs = [];
const pulpMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
material(0xd9c8a2),
34
);
pulpMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
pulpMesh.castShadow = false;
pulpMesh.receiveShadow = false;
vat.add(pulpMesh);
for (let i = 0; i < 34; i++) {
pulpSpecs.push({
x: (pulpRandom() - 0.5) * 3.1,
z: (pulpRandom() - 0.5) * 2.05,
length: 0.1 + pulpRandom() * 0.2,
width: 0.025 + pulpRandom() * 0.045,
angle: pulpRandom() * Math.PI,
phase: pulpRandom() * Math.PI * 2
});
}
// Rectangular, blocky ripples.
const rippleMaterial = new THREE.MeshBasicMaterial({
color: 0xd7e5df,
transparent: true,
opacity: 0.26,
depthWrite: false
});
const ripples = [];
for (let i = 0; i < 3; i++) {
const group = new THREE.Group();
group.position.set(-0.9, 1.527, 0.3);
const size = 0.7 + i * 0.48;
box(group, [size, 0.012, 0.025], [0, 0, -size / 2], 0xd7e5df, {
transparent: true,
opacity: 0.26,
depthWrite: false
});
box(group, [size, 0.012, 0.025], [0, 0, size / 2], 0xd7e5df, {
transparent: true,
opacity: 0.26,
depthWrite: false
});
box(group, [0.025, 0.012, size], [-size / 2, 0, 0], 0xd7e5df, {
transparent: true,
opacity: 0.26,
depthWrite: false
});
box(group, [0.025, 0.012, size], [size / 2, 0, 0], 0xd7e5df, {
transparent: true,
opacity: 0.26,
depthWrite: false
});
scene.add(group);
ripples.push(group);
}
// ------------------------------------------------------------
// Bamboo screen and forming sheet
// ------------------------------------------------------------
const screen = new THREE.Group();
screen.position.set(-0.9, LIFT_START_Y, 0.3);
scene.add(screen);
const frameColor = 0x87613b;
const bambooColor = 0xb48c50;
box(screen, [3.12, 0.13, 0.15], [0, 0, -1.12], frameColor);
box(screen, [3.12, 0.13, 0.15], [0, 0, 1.12], frameColor);
box(screen, [0.15, 0.13, 2.24], [-1.49, 0, 0], frameColor);
box(screen, [0.15, 0.13, 2.24], [1.49, 0, 0], frameColor);
// Long handles.
box(screen, [0.72, 0.115, 0.19], [-1.8, -0.005, 0], 0x68472e);
box(screen, [0.72, 0.115, 0.19], [1.8, -0.005, 0], 0x68472e);
// Bamboo lattice.
for (let i = -6; i <= 6; i++) {
box(
screen,
[0.025, 0.035, 2.08],
[i * 0.225, 0.066, 0],
bambooColor
);
}
for (let i = -4; i <= 4; i++) {
box(
screen,
[2.82, 0.03, 0.025],
[0, 0.084, i * 0.245],
bambooColor
);
}
const sheetMaterial = new THREE.MeshStandardMaterial({
color: 0xf0e4c9,
roughness: 1,
transparent: true,
opacity: 0.68,
depthWrite: false,
side: THREE.DoubleSide
});
const sheet = new THREE.Mesh(
new THREE.BoxGeometry(2.78, 0.026, 2.08),
sheetMaterial
);
sheet.position.set(0, 0.115, 0);
sheet.castShadow = true;
sheet.receiveShadow = true;
sheet.renderOrder = 3;
screen.add(sheet);
// Deterministic, shuffled fiber positions keep comparisons stable.
const fiberRandom = seededRandom(8721);
const fiberPalette = [0xdac8a3, 0xc9b58f, 0xe8d8b9, 0xbda984, 0xefe2c5];
const fiberSpecs = shuffled(
Array.from({ length: MAX_FIBERS }, () => ({
x: (fiberRandom() - 0.5) * 2.62,
z: (fiberRandom() - 0.5) * 1.91,
length: 0.09 + fiberRandom() * 0.19,
width: 0.025 + fiberRandom() * 0.05,
angle: fiberRandom() * Math.PI,
color: fiberPalette[Math.floor(fiberRandom() * fiberPalette.length)]
})),
fiberRandom
);
const fiberMesh = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1,
vertexColors: true
}),
MAX_FIBERS
);
fiberMesh.castShadow = true;
fiberMesh.receiveShadow = true;
fiberMesh.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
screen.add(fiberMesh);
const dummy = new THREE.Object3D();
function updateFibers() {
fiberMesh.count = fiberCount;
for (let i = 0; i < fiberCount; i++) {
const spec = fiberSpecs[i];
dummy.position.set(spec.x, 0.145, spec.z);
dummy.rotation.set(0, spec.angle, 0);
dummy.scale.set(spec.length, 0.022, spec.width);
dummy.updateMatrix();
fiberMesh.setMatrixAt(i, dummy.matrix);
fiberMesh.setColorAt(i, new THREE.Color(spec.color));
}
fiberMesh.instanceMatrix.needsUpdate = true;
if (fiberMesh.instanceColor) {
fiberMesh.instanceColor.needsUpdate = true;
}
}
// ------------------------------------------------------------
// Voxel workers
// ------------------------------------------------------------
function makeWorker({
x,
z,
rotation = 0,
robe = 0x3d566a,
trim = 0x8d3f34,
hat = true
}) {
const worker = new THREE.Group();
worker.position.set(x, 0.1, z);
worker.rotation.y = rotation;
scene.add(worker);
// Feet and lower legs.
box(worker, [0.28, 0.2, 0.45], [-0.2, 0.12, -0.08], 0x3f3028);
box(worker, [0.28, 0.2, 0.45], [0.2, 0.12, -0.08], 0x3f3028);
box(worker, [0.24, 0.68, 0.26], [-0.2, 0.53, 0], 0x6e4c37);
box(worker, [0.24, 0.68, 0.26], [0.2, 0.53, 0], 0x6e4c37);
// Layered robe.
box(worker, [0.82, 0.67, 0.48], [0, 0.94, 0], robe);
box(worker, [0.93, 0.36, 0.58], [0, 0.68, 0], robe);
box(worker, [0.73, 0.23, 0.53], [0, 0.45, 0], robe);
box(worker, [0.12, 0.67, 0.515], [-0.2, 1.02, 0], trim);
box(worker, [0.31, 0.08, 0.525], [0.08, 1.28, 0], trim);
// Collar.
box(worker, [0.13, 0.42, 0.535], [-0.17, 1.43, 0], 0xe7d9bc);
box(worker, [0.33, 0.09, 0.535], [0.08, 1.3, 0], 0xe7d9bc);
// Neck and head.
box(worker, [0.25, 0.16, 0.25], [0, 1.56, 0], 0xc18f69);
box(worker, [0.47, 0.47, 0.43], [0, 1.86, 0], 0xd2a078);
box(worker, [0.49, 0.16, 0.45], [0, 2.08, -0.015], 0x282521);
// Small dark eyes.
box(worker, [0.055, 0.055, 0.025], [-0.1, 1.9, -0.223], 0x332a25);
box(worker, [0.055, 0.055, 0.025], [0.1, 1.9, -0.223], 0x332a25);
if (hat) {
// Stepped, block-built conical straw hat.
box(worker, [0.91, 0.09, 0.77], [0, 2.16, 0], 0xc8a867);
box(worker, [0.7, 0.13, 0.57], [0, 2.25, 0], 0xc9aa69);
box(worker, [0.47, 0.13, 0.39], [0, 2.34, 0], 0xd2b375);
box(worker, [0.25, 0.11, 0.22], [0, 2.42, 0], 0xd7b97a);
} else {
box(worker, [0.52, 0.18, 0.48], [0, 2.09, 0], 0x272522);
}
const arms = [];
for (const side of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.48, 1.35, 0);
worker.add(pivot);
box(pivot, [0.24, 0.65, 0.27], [0, -0.27, 0], robe);
box(pivot, [0.23, 0.17, 0.25], [0, -0.65, -0.015], 0xcd9d77);
arms.push(pivot);
}
return { group: worker, arms };
}
const papermaker = makeWorker({
x: 2.25,
z: 0.3,
rotation: -Math.PI / 2,
robe: 0x3c5668,
trim: 0x873c31,
hat: true
});
papermaker.arms[0].rotation.x = -1.08;
papermaker.arms[1].rotation.x = -1.02;
const stackWorker = makeWorker({
x: 4.25,
z: 1.55,
rotation: 0,
robe: 0x7b7655,
trim: 0x5e4936,
hat: false
});
stackWorker.arms[0].rotation.x = -1.16;
stackWorker.arms[1].rotation.x = -1.12;
// ------------------------------------------------------------
// Pressing table, paper stack, and workshop supplies
// ------------------------------------------------------------
const table = new THREE.Group();
table.position.set(3.65, 0, 0.25);
scene.add(table);
for (const x of [-0.82, 0.82]) {
for (const z of [-0.55, 0.55]) {
box(table, [0.19, 1.12, 0.19], [x, 0.61, z], 0x66472f);
}
}
box(table, [2.18, 0.18, 1.55], [0, 1.2, 0], 0x8b633d);
box(table, [2.02, 0.08, 1.39], [0, 1.32, 0], 0x9d754a);
for (let i = 0; i < 9; i++) {
box(
table,
[1.58 - (i % 3) * 0.045, 0.025, 1.05 - (i % 2) * 0.04],
[0, 1.385 + i * 0.025, 0],
i % 2 ? 0xe7dcc2 : 0xf0e7d1
);
}
// Stack of bamboo strips.
for (let i = 0; i < 9; i++) {
box(
scene,
[0.15, 0.15, 3.25],
[4.0 + (i % 3) * 0.18, 0.22 + Math.floor(i / 3) * 0.15, -2.25],
i % 2 ? 0xa9844e : 0xb99258
);
}
// Bark or rag bundles.
for (let i = 0; i < 5; i++) {
const bundle = new THREE.Group();
bundle.position.set(-4.65 + i * 0.33, 0.28 + (i % 2) * 0.09, -2.45);
bundle.rotation.y = (i - 2) * 0.11;
scene.add(bundle);
box(bundle, [0.38, 0.36, 1.35], [0, 0, 0], i % 2 ? 0x8d7654 : 0x9c8460);
box(bundle, [0.4, 0.07, 0.1], [0, 0.18, 0], 0x594a3a);
}
// A ceramic vat and wooden stool.
const jar = new THREE.Group();
jar.position.set(-4.6, 0, 0.9);
scene.add(jar);
box(jar, [0.58, 0.15, 0.58], [0, 0.09, 0], 0x625044);
box(jar, [0.82, 0.77, 0.82], [0, 0.53, 0], 0x6f7566);
box(jar, [0.59, 0.17, 0.59], [0, 0.98, 0], 0x5e6558);
box(jar, [0.68, 0.06, 0.68], [0, 1.07, 0], 0x455a58);
const stool = new THREE.Group();
stool.position.set(-3.85, 0, 2.0);
scene.add(stool);
box(stool, [0.78, 0.16, 0.66], [0, 0.83, 0], 0x795336);
for (const x of [-0.25, 0.25]) {
for (const z of [-0.2, 0.2]) {
box(stool, [0.11, 0.8, 0.11], [x, 0.42, z], 0x67472f);
}
}
// ------------------------------------------------------------
// Drip animation
// ------------------------------------------------------------
const dripMaterial = new THREE.MeshBasicMaterial({
color: 0x8db2ad,
transparent: true,
opacity: 0.78
});
const drips = [];
const dripRandom = seededRandom(991);
for (let i = 0; i < 24; i++) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.095, 0.055),
dripMaterial
);
mesh.visible = false;
mesh.userData = {
x: (dripRandom() - 0.5) * 3.0,
z: (dripRandom() - 0.5) * 2.1,
offset: dripRandom(),
speed: 0.8 + dripRandom() * 0.65
};
scene.add(mesh);
drips.push(mesh);
}
// ------------------------------------------------------------
// UI calculations and interaction
// ------------------------------------------------------------
function updateReadouts() {
// Symbolic, monotonic teaching relationships.
projectedCoverage = Math.round(
12 + 84 * (1 - Math.exp(-fiberCount / 34))
);
relativeThickness = 0.45 + fiberCount / 55;
fiberOutput.textContent = `${fiberCount} bundles`;
coverageValue.textContent = `${projectedCoverage}%`;
thicknessValue.textContent = `${relativeThickness.toFixed(1)} rel.`;
const fill =
((fiberCount - MIN_FIBERS) / (MAX_FIBERS - MIN_FIBERS)) * 100;
slider.style.setProperty("--fill", `${fill}%`);
updateFibers();
const opacity = 0.27 + (projectedCoverage / 100) * 0.58;
sheetMaterial.opacity = phase === "ready" ? opacity * 0.72 : opacity;
sheet.scale.y = 0.65 + (fiberCount / MAX_FIBERS) * 1.65;
}
slider.addEventListener("input", () => {
fiberCount = Number(slider.value);
updateReadouts();
});
actionButton.addEventListener("click", () => {
if (phase === "ready") {
phase = "lifting";
liftTime = 0;
liftProgress = 0;
slider.disabled = true;
actionButton.disabled = true;
actionButton.textContent = "Lifting the mould…";
statusElement.textContent =
"Water drains through the bamboo lattice while the sheet settles on the mould.";
coverageCaption.textContent = "forming sheet area";
stepNumber.textContent = "2";
stepOne.classList.remove("active");
stepTwo.classList.add("active");
} else if (phase === "done") {
resetDemo();
}
});
function resetDemo() {
phase = "ready";
liftTime = 0;
liftProgress = 0;
screen.position.set(-0.9, LIFT_START_Y, 0.3);
screen.rotation.set(0, 0, 0);
water.position.y = 1.48;
slider.disabled = false;
actionButton.disabled = false;
actionButton.textContent = "Lift the screen";
statusElement.textContent =
"The mould is resting in the pulp vat. Adjust the fiber count before lifting.";
coverageCaption.textContent = "projected sheet area";
stepNumber.textContent = "1";
stepOne.classList.add("active");
stepTwo.classList.remove("active");
stepThree.classList.remove("active");
for (const drip of drips) {
drip.visible = false;
}
updateReadouts();
}
// ------------------------------------------------------------
// Direct camera controls — no addons
// ------------------------------------------------------------
let dragging = false;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar - dy * 0.005,
0.56,
1.34
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("pointerleave", (event) => {
if (dragging && event.buttons === 0) stopDragging();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
camera.zoom = THREE.MathUtils.clamp(
camera.zoom * (event.deltaY > 0 ? 0.91 : 1.1),
0.68,
1.7
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("keydown", (event) => {
const step = 0.08;
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraAzimuth += step;
break;
case "ArrowRight":
cameraAzimuth -= step;
break;
case "ArrowUp":
cameraPolar = Math.max(0.56, cameraPolar - step);
break;
case "ArrowDown":
cameraPolar = Math.min(1.34, cameraPolar + step);
break;
case "+":
case "=":
camera.zoom = Math.min(1.7, camera.zoom * 1.08);
break;
case "-":
camera.zoom = Math.max(0.68, camera.zoom * 0.92);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
canvas.style.cursor = "grab";
document.querySelector("#resetView").addEventListener("click", () => {
cameraAzimuth = 0.67;
cameraPolar = 1.03;
camera.zoom = 1;
updateCamera();
});
// ------------------------------------------------------------
// Resize and annotation projection
// ------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height, false);
// Keep the full workshop visible on narrow screens.
const halfHeight = Math.max(5.7, 7.3 / aspect);
camera.left = -halfHeight * aspect;
camera.right = halfHeight * aspect;
camera.top = halfHeight;
camera.bottom = -halfHeight;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
const projected = new THREE.Vector3();
function positionAnnotation(element, worldPoint, offsetX = 0, offsetY = 0) {
projected.copy(worldPoint).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.1 &&
Math.abs(projected.y) < 1.1;
element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth + offsetX;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight + offsetY;
element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
}
// ------------------------------------------------------------
// Animation
// ------------------------------------------------------------
const clock = new THREE.Clock();
const screenAnchor = new THREE.Vector3();
const vatAnchor = new THREE.Vector3(-2.7, 1.7, 1.6);
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
// Slowly float the pulp pieces.
for (let i = 0; i < pulpSpecs.length; i++) {
const spec = pulpSpecs[i];
dummy.position.set(
spec.x,
1.535 + Math.sin(elapsed * 1.1 + spec.phase) * 0.008,
spec.z
);
dummy.rotation.set(0, spec.angle, 0);
dummy.scale.set(spec.length, 0.014, spec.width);
dummy.updateMatrix();
pulpMesh.setMatrixAt(i, dummy.matrix);
}
pulpMesh.instanceMatrix.needsUpdate = true;
// Expanding rectangular surface ripples.
for (let i = 0; i < ripples.length; i++) {
const phaseValue = (elapsed * 0.24 + i / ripples.length) % 1;
const scale = 0.7 + phaseValue * 1.35;
ripples[i].scale.set(scale, 1, scale);
ripples[i].rotation.y = phaseValue * 0.08;
}
if (phase === "lifting") {
liftTime += delta;
liftProgress = Math.min(liftTime / LIFT_DURATION, 1);
const eased = 1 - Math.pow(1 - liftProgress, 3);
screen.position.y = THREE.MathUtils.lerp(
LIFT_START_Y,
LIFT_END_Y,
eased
);
screen.position.x = THREE.MathUtils.lerp(-0.9, -0.65, eased);
screen.position.z = THREE.MathUtils.lerp(0.3, 0.36, eased);
screen.rotation.x = Math.sin(liftProgress * Math.PI) * 0.055;
screen.rotation.z = -Math.sin(liftProgress * Math.PI) * 0.035;
water.position.y = 1.48 - eased * 0.07;
papermaker.arms[0].rotation.x =
-1.08 - Math.sin(liftProgress * Math.PI) * 0.24;
papermaker.arms[1].rotation.x =
-1.02 - Math.sin(liftProgress * Math.PI) * 0.19;
sheetMaterial.opacity =
0.27 + (projectedCoverage / 100) * 0.58 * (0.7 + eased * 0.3);
// Water drains from the lower edge of the raised mould.
for (const drip of drips) {
const data = drip.userData;
const fall = (liftTime * data.speed + data.offset) % 1;
drip.visible = liftProgress > 0.13 && liftProgress < 0.985;
drip.position.set(
screen.position.x + data.x,
screen.position.y - 0.1 - fall * 2.4,
screen.position.z + data.z
);
drip.scale.y = 0.75 + fall * 0.7;
}
if (liftProgress >= 1) {
phase = "done";
screen.rotation.set(0, 0, 0);
actionButton.disabled = false;
actionButton.textContent = "Reset & remix";
statusElement.textContent =
"The sheet has formed. More fibers produce greater relative coverage and thickness.";
coverageCaption.textContent = "formed sheet area";
stepNumber.textContent = "3";
stepTwo.classList.remove("active");
stepThree.classList.add("active");
for (const drip of drips) {
drip.visible = false;
}
}
}
// Projected HTML labels follow their 3D anchors.
screenAnchor.set(1.45, 0.2, 0.72);
screen.localToWorld(screenAnchor);
positionAnnotation(screenAnnotation, screenAnchor, 40, -22);
positionAnnotation(vatAnnotation, vatAnchor, -36, 8);
renderer.render(scene, camera);
}
updateReadouts();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```