Prompt specification
Build or customize the Three.js 3D scene "Animation workshop desk" 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: Animation workshop desk
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/animation-workshop-desk-x0335
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a flipbook. Compose paper frames, pencil, camera stand, and screen; a simple character arranges drawings before the screen plays their sequence as a short coherent action. Stylized solid forms.
Working Three.js Starter (animation-workshop-desk-x0335):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Flipbook Studio — A Little Thing Grows</title>
<style>
:root {
--ink: #20343a;
--cream: #f5eddd;
--paper: #fffaf0;
--coral: #ed795f;
--teal: #2e7776;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #ded3c2;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.title {
position: absolute;
top: 28px;
left: 30px;
max-width: 360px;
text-shadow: 0 1px rgba(255, 255, 255, 0.5);
}
.eyebrow {
margin-bottom: 7px;
color: var(--coral);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(30px, 4vw, 54px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
margin: 12px 0 0;
max-width: 280px;
font-size: 13px;
font-weight: 650;
line-height: 1.45;
opacity: 0.72;
}
.badge {
position: absolute;
top: 30px;
right: 30px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(32, 52, 58, 0.16);
border-radius: 999px;
background: rgba(255, 250, 240, 0.68);
backdrop-filter: blur(10px);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 4px rgba(237, 121, 95, 0.16);
}
.bottom {
position: absolute;
bottom: 24px;
left: 50%;
width: min(620px, calc(100% - 32px));
transform: translateX(-50%);
padding: 14px 16px;
border: 1px solid rgba(32, 52, 58, 0.15);
border-radius: 18px;
background: rgba(255, 250, 240, 0.82);
box-shadow: 0 16px 45px rgba(51, 41, 32, 0.13);
backdrop-filter: blur(12px);
pointer-events: auto;
}
.timeline-row {
display: flex;
align-items: center;
gap: 13px;
}
.status {
min-width: 122px;
color: var(--teal);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.track {
position: relative;
flex: 1;
height: 5px;
overflow: hidden;
border-radius: 99px;
background: rgba(32, 52, 58, 0.12);
}
.fill {
position: absolute;
inset: 0 auto 0 0;
width: 0;
border-radius: inherit;
background: var(--coral);
}
.buttons {
display: flex;
gap: 7px;
}
button {
border: 0;
border-radius: 10px;
padding: 9px 12px;
background: var(--ink);
color: var(--cream);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: var(--teal);
}
button:focus-visible {
outline: 3px solid rgba(237, 121, 95, 0.45);
outline-offset: 2px;
}
.help {
position: absolute;
right: 30px;
bottom: 30px;
color: rgba(32, 52, 58, 0.58);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.title {
top: 20px;
left: 20px;
}
.badge {
top: 20px;
right: 20px;
}
.subtitle,
.help {
display: none;
}
.bottom {
bottom: 14px;
}
.status {
min-width: 92px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="hud">
<div class="title">
<div class="eyebrow">Flipbook Studio · Study 04</div>
<h1>A little thing grows</h1>
<p class="subtitle">
Four hand-drawn frames become one tiny story.
</p>
</div>
<div class="badge">
<span class="dot"></span>
<span id="sceneBadge">In production</span>
</div>
<div class="bottom">
<div class="timeline-row">
<div id="status" class="status">Arranging pages</div>
<div class="track"><div id="fill" class="fill"></div></div>
<div class="buttons">
<button id="replay" type="button">Replay</button>
<button id="resetView" type="button">View</button>
</div>
</div>
</div>
<div class="help">Drag to orbit · Scroll to zoom</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const statusEl = document.querySelector("#status");
const fillEl = document.querySelector("#fill");
const badgeEl = document.querySelector("#sceneBadge");
// -------------------------------------------------------------------------
// Renderer and 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.08;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#ded3c2");
scene.fog = new THREE.Fog("#ded3c2", 15, 29);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const view = {
target: new THREE.Vector3(-0.15, 1.75, 0),
theta: 0.38,
phi: 1.03,
radius: 12.8
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
updateCamera();
// -------------------------------------------------------------------------
// Materials and geometry helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.82, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const M = {
wall: material("#ded3c2"),
floor: material("#c8b69d"),
rug: material("#b7a991"),
wood: material("#b9794e"),
woodDark: material("#805039"),
teal: material("#2e7776"),
tealDark: material("#214f52"),
cream: material("#fff4de"),
paper: material("#f6ead1"),
coral: material("#ed795f"),
coralDark: material("#c85f4d"),
yellow: material("#efbd59"),
navy: material("#263b4a"),
black: material("#20292d", 0.48),
metal: material("#879293", 0.36, 0.62),
glass: new THREE.MeshStandardMaterial({
color: "#79aeb8",
roughness: 0.16,
metalness: 0.25
}),
skin: material("#e5a77e"),
hair: material("#3b2928"),
shirt: material("#e5a83c"),
pants: material("#365266"),
redButton: material("#e65f4d", 0.48),
soil: material("#80573f")
};
function mesh(geometry, mat, position, parent = scene) {
const object = new THREE.Mesh(geometry, mat);
object.position.copy(position);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function box(width, height, depth, mat, position, parent = scene) {
return mesh(
new THREE.BoxGeometry(width, height, depth),
mat,
position,
parent
);
}
function sphere(radius, mat, position, parent = scene, widthSegments = 20) {
return mesh(
new THREE.SphereGeometry(radius, widthSegments, 14),
mat,
position,
parent
);
}
const UP = new THREE.Vector3(0, 1, 0);
function setSegment(object, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
object.position.copy(a).add(b).multiplyScalar(0.5);
object.scale.set(1, length, 1);
object.quaternion.setFromUnitVectors(UP, direction.normalize());
}
function cylinderBetween(a, b, radius, mat, parent = scene, segments = 12) {
const object = mesh(
new THREE.CylinderGeometry(radius, radius, 1, segments),
mat,
new THREE.Vector3(),
parent
);
setSegment(object, a, b);
return object;
}
// -------------------------------------------------------------------------
// Lighting and environment
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight("#fff3dd", "#786d67", 2.25));
const keyLight = new THREE.DirectionalLight("#fff0d7", 3.25);
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 = 9;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight("#b5d9dc", 1.1);
fillLight.position.set(7, 5, -4);
scene.add(fillLight);
const floor = mesh(
new THREE.PlaneGeometry(30, 30),
M.floor,
new THREE.Vector3(0, -0.015, 0)
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
box(18, 7.5, 0.25, M.wall, new THREE.Vector3(0, 3.6, -4.15));
const rug = mesh(
new THREE.CircleGeometry(5.9, 72),
M.rug,
new THREE.Vector3(-0.25, 0.005, 0.35)
);
rug.rotation.x = -Math.PI / 2;
rug.scale.set(1.15, 0.68, 1);
rug.castShadow = false;
const wallCircle = mesh(
new THREE.CircleGeometry(0.9, 48),
M.coral,
new THREE.Vector3(-4.75, 4.45, -3.99)
);
wallCircle.castShadow = false;
box(2.55, 0.12, 0.5, M.woodDark, new THREE.Vector3(-4.15, 2.5, -3.65));
box(0.28, 1.05, 0.32, M.yellow, new THREE.Vector3(-4.95, 3.02, -3.67));
box(0.22, 0.82, 0.32, M.teal, new THREE.Vector3(-4.58, 2.95, -3.67));
box(0.34, 0.67, 0.32, M.coral, new THREE.Vector3(-4.25, 2.84, -3.67));
// -------------------------------------------------------------------------
// Drawing artwork
// -------------------------------------------------------------------------
function drawIllustration(ctx, stage) {
ctx.save();
ctx.lineCap = "round";
ctx.lineJoin = "round";
// A tiny sun, present throughout the sequence.
ctx.strokeStyle = "#d69a36";
ctx.fillStyle = "#efbd59";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.arc(405, 82, 31, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
ctx.beginPath();
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
ctx.moveTo(405 + Math.cos(angle) * 42, 82 + Math.sin(angle) * 42);
ctx.lineTo(405 + Math.cos(angle) * 56, 82 + Math.sin(angle) * 56);
}
ctx.stroke();
// Soil.
ctx.fillStyle = "#8a6047";
ctx.beginPath();
ctx.ellipse(256, 394, 155, 42, 0, 0, Math.PI * 2);
ctx.fill();
ctx.strokeStyle = "#684635";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(105, 394);
ctx.bezierCurveTo(145, 379, 195, 382, 230, 392);
ctx.moveTo(270, 391);
ctx.bezierCurveTo(325, 374, 380, 382, 408, 396);
ctx.stroke();
if (stage === 0) {
// Seed.
ctx.fillStyle = "#594538";
ctx.strokeStyle = "#352d29";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.ellipse(257, 365, 20, 29, -0.25, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(260, 349);
ctx.bezierCurveTo(271, 332, 263, 317, 249, 304);
ctx.stroke();
ctx.strokeStyle = "#77a9a2";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(233, 243);
ctx.bezierCurveTo(218, 259, 223, 275, 241, 282);
ctx.bezierCurveTo(258, 269, 251, 251, 233, 243);
ctx.stroke();
} else if (stage === 1) {
// First shoot.
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 10;
ctx.beginPath();
ctx.moveTo(256, 386);
ctx.bezierCurveTo(253, 349, 257, 320, 265, 286);
ctx.stroke();
ctx.fillStyle = "#72a85f";
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(261, 324);
ctx.bezierCurveTo(224, 326, 203, 304, 207, 281);
ctx.bezierCurveTo(238, 278, 259, 292, 261, 324);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(264, 306);
ctx.bezierCurveTo(293, 299, 308, 277, 300, 258);
ctx.bezierCurveTo(276, 264, 263, 280, 264, 306);
ctx.fill();
ctx.stroke();
} else if (stage === 2) {
// Taller stem and unfolding leaves.
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 10;
ctx.beginPath();
ctx.moveTo(256, 388);
ctx.bezierCurveTo(253, 336, 259, 274, 261, 218);
ctx.stroke();
ctx.fillStyle = "#72a85f";
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(258, 333);
ctx.bezierCurveTo(211, 332, 181, 302, 190, 270);
ctx.bezierCurveOutput;
ctx.bezierCurveTo(229, 266, 254, 290, 258, 333);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(260, 287);
ctx.bezierCurveTo(301, 280, 328, 249, 319, 218);
ctx.bezierCurveTo(284, 220, 264, 247, 260, 287);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(261, 244);
ctx.bezierCurveTo(225, 233, 217, 206, 232, 186);
ctx.bezierCurveTo(254, 196, 264, 217, 261, 244);
ctx.fill();
ctx.stroke();
} else {
// Open flower.
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 10;
ctx.beginPath();
ctx.moveTo(256, 390);
ctx.bezierCurveTo(254, 326, 258, 263, 258, 213);
ctx.stroke();
ctx.fillStyle = "#72a85f";
ctx.strokeStyle = "#386f4e";
ctx.lineWidth = 7;
ctx.beginPath();
ctx.moveTo(256, 340);
ctx.bezierCurveTo(211, 335, 186, 305, 194, 278);
ctx.bezierCurveOutput;
ctx.bezierCurveTo(230, 275, 252, 300, 256, 340);
ctx.fill();
ctx.stroke();
ctx.beginPath();
ctx.moveTo(258, 300);
ctx.bezierCurveTo(299, 292, 324, 264, 315, 236);
ctx.bezierCurveOutput;
ctx.bezierCurveTo(281, 239, 262, 263, 258, 300);
ctx.fill();
ctx.stroke();
const flowerX = 258;
const flowerY = 188;
ctx.fillStyle = "#e97d86";
ctx.strokeStyle = "#bf596d";
ctx.lineWidth = 6;
for (let i = 0; i < 8; i++) {
const angle = (i / 8) * Math.PI * 2;
const x = flowerX + Math.cos(angle) * 37;
const y = flowerY + Math.sin(angle) * 37;
ctx.beginPath();
ctx.ellipse(x, y, 27, 18, angle, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
}
ctx.fillStyle = "#efbd59";
ctx.strokeStyle = "#b9872e";
ctx.lineWidth = 6;
ctx.beginPath();
ctx.arc(flowerX, flowerY, 25, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
}
// Tiny pencil hatching on the soil.
ctx.strokeStyle = "rgba(72, 48, 38, 0.55)";
ctx.lineWidth = 3;
for (let i = 0; i < 11; i++) {
const x = 125 + i * 24;
ctx.beginPath();
ctx.moveTo(x, 401);
ctx.lineTo(x + 8, 411);
ctx.stroke();
}
ctx.restore();
}
function drawPaperArt(ctx, stage) {
ctx.fillStyle = "#f7edda";
ctx.fillRect(0, 0, 512, 512);
// Light, deterministic paper flecks.
ctx.fillStyle = "rgba(94, 72, 48, 0.12)";
for (let i = 0; i < 65; i++) {
const x = (i * 83 + 29) % 512;
const y = (i * 47 + 71) % 512;
ctx.fillRect(x, y, 2, 2);
}
ctx.save();
ctx.translate(18, 12);
ctx.scale(0.93, 0.93);
drawIllustration(ctx, stage);
ctx.restore();
ctx.strokeStyle = "rgba(59, 46, 37, 0.28)";
ctx.lineWidth = 3;
ctx.strokeRect(13, 13, 486, 486);
ctx.fillStyle = "rgba(32, 52, 58, 0.62)";
ctx.font = "700 18px system-ui";
ctx.fillText(`FRAME ${String(stage + 1).padStart(2, "0")}`, 27, 482);
}
function createDrawingTexture(stage) {
const artCanvas = document.createElement("canvas");
artCanvas.width = 512;
artCanvas.height = 512;
const ctx = artCanvas.getContext("2d");
drawPaperArt(ctx, stage);
const texture = new THREE.CanvasTexture(artCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
// -------------------------------------------------------------------------
// Screen and its animated playback canvas
// -------------------------------------------------------------------------
const screenCanvas = document.createElement("canvas");
screenCanvas.width = 1024;
screenCanvas.height = 640;
const screenCtx = screenCanvas.getContext("2d");
const screenTexture = new THREE.CanvasTexture(screenCanvas);
screenTexture.colorSpace = THREE.SRGBColorSpace;
const captions = [
"A seed waits in the soil.",
"A green shoot reaches up.",
"Leaves unfold toward the sun.",
"And a flower opens."
];
function drawScreen(stage, ended = false) {
const ctx = screenCtx;
ctx.fillStyle = "#19373c";
ctx.fillRect(0, 0, 1024, 640);
ctx.fillStyle = "#f2c46c";
ctx.font = "800 23px system-ui";
ctx.fillText("THE TINY GARDEN", 58, 52);
ctx.fillStyle = "rgba(255,255,255,0.55)";
ctx.font = "600 15px system-ui";
ctx.fillText("A FLIPBOOK IN FOUR FRAMES", 58, 78);
ctx.fillStyle = "#f6ecd7";
ctx.fillRect(54, 101, 525, 510);
ctx.save();
ctx.translate(66, 113);
ctx.scale(0.98, 0.98);
drawIllustration(ctx, Math.max(stage, 0));
ctx.restore();
ctx.strokeStyle = "rgba(242,196,108,0.32)";
ctx.lineWidth = 2;
ctx.strokeRect(54, 101, 525, 510);
const displayStage = Math.max(stage, 0);
ctx.fillStyle = "#ed795f";
ctx.font = "700 112px Georgia";
ctx.fillText(String(displayStage + 1).padStart(2, "0"), 630, 240);
ctx.fillStyle = "#f7eddb";
ctx.font = "600 30px Georgia";
ctx.fillText(ended ? "THE END" : "FRAME " + (displayStage + 1), 634, 291);
ctx.fillStyle = "rgba(255,255,255,0.74)";
ctx.font = "500 23px system-ui";
const words = ended
? "One small story, made by hand."
: captions[displayStage];
const maxWidth = 300;
const wordsArray = words.split(" ");
let line = "";
let lineY = 340;
for (const word of wordsArray) {
const testLine = line ? `${line} ${word}` : word;
if (ctx.measureText(testLine).width > maxWidth && line) {
ctx.fillText(line, 634, lineY);
line = word;
lineY += 34;
} else {
line = testLine;
}
}
ctx.fillText(line, 634, lineY);
ctx.fillStyle = "rgba(255,255,255,0.16)";
ctx.fillRect(634, 535, 300, 5);
ctx.fillStyle = "#ed795f";
const progress = ended ? 1 : (displayStage + 1) / 4;
ctx.fillRect(634, 535, 300 * progress, 5);
for (let i = 0; i < 4; i++) {
ctx.beginPath();
ctx.arc(652 + i * 35, 574, 7, 0, Math.PI * 2);
ctx.fillStyle = i <= displayStage ? "#ed795f" : "rgba(255,255,255,0.22)";
ctx.fill();
}
screenTexture.needsUpdate = true;
}
drawScreen(-1, false);
// -------------------------------------------------------------------------
// Screen housing and stand
// -------------------------------------------------------------------------
const screenGroup = new THREE.Group();
screenGroup.position.set(3.15, 3.22, -2.0);
scene.add(screenGroup);
box(4.15, 2.62, 0.34, M.tealDark, new THREE.Vector3(), screenGroup);
box(3.86, 2.31, 0.09, M.black, new THREE.Vector3(0, 0, 0.2), screenGroup);
const screenMesh = mesh(
new THREE.PlaneGeometry(3.72, 2.17),
new THREE.MeshBasicMaterial({
map: screenTexture,
toneMapped: false
}),
new THREE.Vector3(0, 0, 0.255),
screenGroup
);
screenMesh.castShadow = false;
sphere(0.055, M.redButton, new THREE.Vector3(1.72, -1.13, 0.24), screenGroup);
cylinderBetween(
new THREE.Vector3(3.15, 0.13, -2.0),
new THREE.Vector3(3.15, 2.04, -2.0),
0.11,
M.metal
);
box(1.45, 0.13, 0.7, M.tealDark, new THREE.Vector3(3.15, 0.1, -2.0));
// -------------------------------------------------------------------------
// Work table
// -------------------------------------------------------------------------
box(5.55, 0.22, 1.82, M.wood, new THREE.Vector3(-0.55, 1.42, 0.45));
box(5.42, 0.07, 1.69, M.woodDark, new THREE.Vector3(-0.55, 1.285, 0.45));
const tableLegPositions = [
[-2.83, 0.65, -0.13],
[1.73, 0.65, -0.13],
[-2.83, 0.65, 1.03],
[1.73, 0.65, 1.03]
];
for (const [x, y, z] of tableLegPositions) {
box(0.18, 1.3, 0.18, M.woodDark, new THREE.Vector3(x, y, z));
}
box(4.45, 0.13, 0.13, M.woodDark, new THREE.Vector3(-0.55, 0.42, 1.03));
box(4.45, 0.13, 0.13, M.woodDark, new THREE.Vector3(-0.55, 0.42, -0.13));
// -------------------------------------------------------------------------
// Physical flipbook with binding rings
// -------------------------------------------------------------------------
const flipbook = new THREE.Group();
flipbook.position.set(-2.53, 1.55, 0.47);
scene.add(flipbook);
box(1.22, 0.12, 1.35, M.tealDark, new THREE.Vector3(0, 0, 0), flipbook);
for (let i = 0; i < 7; i++) {
box(
1.08,
0.018,
1.22,
i % 2 ? M.paper : M.cream,
new THREE.Vector3(0.03, 0.075 + i * 0.02, 0),
flipbook
);
}
for (let i = 0; i < 3; i++) {
const ring = mesh(
new THREE.TorusGeometry(0.13, 0.022, 8, 28),
M.metal,
new THREE.Vector3(-0.59, 0.13, -0.39 + i * 0.39),
flipbook
);
ring.rotation.y = Math.PI / 2;
}
// -------------------------------------------------------------------------
// Four removable paper frames
// -------------------------------------------------------------------------
const slots = [
new THREE.Vector3(-1.25, 1.565, 0.48),
new THREE.Vector3(-0.42, 1.565, 0.48),
new THREE.Vector3(0.41, 1.565, 0.48),
new THREE.Vector3(1.24, 1.565, 0.48)
];
const cards = [];
const paperEdge = material("#d9c7a7", 0.95);
for (let i = 0; i < 4; i++) {
const group = new THREE.Group();
const texture = createDrawingTexture(i);
const frontMaterial = new THREE.MeshStandardMaterial({
map: texture,
roughness: 0.94,
side: THREE.FrontSide
});
const cardMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.72, 0.035, 0.72),
[
paperEdge,
paperEdge,
frontMaterial,
paperEdge,
paperEdge,
paperEdge
]
);
cardMesh.castShadow = true;
cardMesh.receiveShadow = true;
group.add(cardMesh);
scene.add(group);
cards.push({
group,
mesh: cardMesh,
stackPosition: new THREE.Vector3(
-2.48 + (i % 2) * 0.012,
1.73 - i * 0.015,
0.47 + i * 0.012
),
stackRotation: (i - 1.5) * 0.025
});
}
// -------------------------------------------------------------------------
// Pencil
// -------------------------------------------------------------------------
const pencilGroup = new THREE.Group();
pencilGroup.position.set(0.05, 1.59, 1.03);
pencilGroup.rotation.y = -0.36;
scene.add(pencilGroup);
const pencilBody = mesh(
new THREE.CylinderGeometry(0.065, 0.065, 1.25, 6),
M.yellow,
new THREE.Vector3(),
pencilGroup
);
pencilBody.rotation.z = Math.PI / 2;
const pencilTip = mesh(
new THREE.ConeGeometry(0.065, 0.22, 6),
M.wood,
new THREE.Vector3(0.735, 0, 0),
pencilGroup
);
pencilTip.rotation.z = -Math.PI / 2;
const graphite = mesh(
new THREE.ConeGeometry(0.023, 0.1, 6),
M.black,
new THREE.Vector3(0.89, 0, 0),
pencilGroup
);
graphite.rotation.z = -Math.PI / 2;
const eraser = mesh(
new THREE.CylinderGeometry(0.067, 0.067, 0.18, 12),
M.coral,
new THREE.Vector3(-0.71, 0, 0),
pencilGroup
);
eraser.rotation.z = Math.PI / 2;
// -------------------------------------------------------------------------
// Projector and play button
// -------------------------------------------------------------------------
box(0.76, 0.3, 0.65, M.tealDark, new THREE.Vector3(1.95, 1.68, 0.43));
box(0.62, 0.08, 0.5, M.cream, new THREE.Vector3(1.95, 1.84, 0.43));
const button = mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.085, 24),
M.redButton,
new THREE.Vector3(1.95, 1.91, 0.43)
);
const projectorLens = mesh(
new THREE.CylinderGeometry(0.105, 0.105, 0.25, 24),
M.black,
new THREE.Vector3(2.4, 1.7, 0.38)
);
projectorLens.rotation.x = Math.PI / 2;
const cableCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(2.1, 1.64, 0.73),
new THREE.Vector3(2.7, 0.25, 0.85),
new THREE.Vector3(3.3, 0.2, -0.75),
new THREE.Vector3(3.15, 1.1, -1.92)
]);
mesh(
new THREE.TubeGeometry(cableCurve, 40, 0.025, 7, false),
M.black,
new THREE.Vector3()
);
// -------------------------------------------------------------------------
// Camera on a tripod, aimed toward the screen
// -------------------------------------------------------------------------
const tripodX = 0.72;
const tripodZ = 1.72;
const hub = new THREE.Vector3(tripodX, 1.02, tripodZ);
cylinderBetween(
new THREE.Vector3(tripodX, 0.08, tripodZ),
new THREE.Vector3(tripodX, 2.52, tripodZ),
0.055,
M.metal
);
const legEnds = [
new THREE.Vector3(tripodX - 0.9, 0.06, tripodZ + 0.15),
new THREE.Vector3(tripodX + 0.75, 0.06, tripodZ + 0.26),
new THREE.Vector3(tripodX + 0.05, 0.06, tripodZ + 0.88)
];
for (const end of legEnds) {
cylinderBetween(hub, end, 0.045, M.metal);
}
sphere(0.12, M.black, hub);
const cameraModel = new THREE.Group();
cameraModel.position.set(tripodX, 2.67, tripodZ);
const directionToScreen = new THREE.Vector3(3.15, 0, -2.0).sub(
new THREE.Vector3(tripodX, 0, tripodZ)
);
cameraModel.rotation.y = Math.atan2(-directionToScreen.x, -directionToScreen.z);
scene.add(cameraModel);
box(0.9, 0.53, 0.48, M.black, new THREE.Vector3(), cameraModel);
box(0.31, 0.19, 0.25, M.black, new THREE.Vector3(-0.13, 0.36, 0.01), cameraModel);
box(0.53, 0.07, 0.5, M.navy, new THREE.Vector3(0, 0.27, 0), cameraModel);
const lens = mesh(
new THREE.CylinderGeometry(0.19, 0.19, 0.38, 28),
M.black,
new THREE.Vector3(0, 0, -0.38),
cameraModel
);
lens.rotation.x = Math.PI / 2;
const lensGlass = mesh(
new THREE.CircleGeometry(0.145, 28),
M.glass,
new THREE.Vector3(0, 0, -0.579),
cameraModel
);
lensGlass.rotation.y = Math.PI;
sphere(0.045, M.redButton, new THREE.Vector3(0.28, 0.19, 0.25), cameraModel);
// -------------------------------------------------------------------------
// Stylized character
// -------------------------------------------------------------------------
const character = new THREE.Group();
character.position.set(-1.8, 0, -0.72);
scene.add(character);
// Legs and shoes.
cylinderBetween(
new THREE.Vector3(-0.19, 0.18, 0),
new THREE.Vector3(-0.16, 0.94, 0),
0.135,
M.pants,
character
);
cylinderBetween(
new THREE.Vector3(0.19, 0.18, 0),
new THREE.Vector3(0.17, 0.94, 0),
0.135,
M.pants,
character
);
const leftShoe = box(
0.31, 0.18, 0.48, M.black,
new THREE.Vector3(-0.2, 0.12, 0.11),
character
);
const rightShoe = box(
0.31, 0.18, 0.48, M.black,
new THREE.Vector3(0.2, 0.12, 0.11),
character
);
leftShoe.castShadow = true;
rightShoe.castShadow = true;
const torso = mesh(
new THREE.CylinderGeometry(0.36, 0.44, 0.86, 20),
M.shirt,
new THREE.Vector3(0, 1.37, 0),
character
);
mesh(
new THREE.CylinderGeometry(0.115, 0.12, 0.22, 16),
M.skin,
new THREE.Vector3(0, 1.91, 0),
character
);
const head = new THREE.Group();
head.position.set(0, 2.19, 0);
character.add(head);
sphere(0.38, M.skin, new THREE.Vector3(), head, 28);
const hair = mesh(
new THREE.SphereGeometry(
0.395,
24,
14,
0,
Math.PI * 2,
0,
Math.PI / 2
),
M.hair,
new THREE.Vector3(0, 0.025, -0.015),
head
);
hair.castShadow = true;
sphere(0.044, M.black, new THREE.Vector3(-0.125, 0.025, 0.345), head, 12);
sphere(0.044, M.black, new THREE.Vector3(0.125, 0.025, 0.345), head, 12);
const nose = mesh(
new THREE.ConeGeometry(0.055, 0.12, 12),
M.skin,
new THREE.Vector3(0, -0.035, 0.395),
head
);
nose.rotation.x = Math.PI / 2;
const smile = mesh(
new THREE.TorusGeometry(0.082, 0.012, 6, 18, Math.PI),
M.coralDark,
new THREE.Vector3(0, -0.125, 0.354),
head
);
smile.rotation.z = Math.PI;
// Right arm is animated toward the pages and play button.
const upperArm = mesh(
new THREE.CylinderGeometry(0.105, 0.11, 1, 12),
M.shirt,
new THREE.Vector3(),
character
);
const lowerArm = mesh(
new THREE.CylinderGeometry(0.09, 0.095, 1, 12),
M.skin,
new THREE.Vector3(),
character
);
const hand = sphere(0.115, M.skin, new THREE.Vector3(), character, 16);
const leftUpperArm = mesh(
new THREE.CylinderGeometry(0.105, 0.11, 1, 12),
M.shirt,
new THREE.Vector3(),
character
);
const leftLowerArm = mesh(
new THREE.CylinderGeometry(0.09, 0.095, 1, 12),
M.skin,
new THREE.Vector3(),
character
);
const leftHand = sphere(0.115, M.skin, new THREE.Vector3(), character, 16);
// -------------------------------------------------------------------------
// Animation helpers
// -------------------------------------------------------------------------
const clamp01 = value => Math.min(1, Math.max(0, value));
const smooth = value => {
const t = clamp01(value);
return t * t * (3 - 2 * t);
};
const arrangementStarts = [0.9, 2.05, 3.2, 4.35];
const playbackStart = 6.55;
const frameDuration = 1.05;
const totalDuration = 10.85;
let elapsed = 0;
let lastFrameTime = performance.now();
let previousScreenKey = "";
function updateCards(time) {
for (let i = 0; i < cards.length; i++) {
const card = cards[i];
const start = arrangementStarts[i];
const movementStart = start + 0.2;
const movementEnd = start + 0.76;
const progress = smooth((time - movementStart) / (movementEnd - movementStart));
if (time < movementStart) {
card.group.position.copy(card.stackPosition);
card.group.rotation.y = card.stackRotation;
} else if (time < movementEnd) {
card.group.position.lerpVectors(card.stackPosition, slots[i], progress);
card.group.position.y += Math.sin(progress * Math.PI) * 0.34;
card.group.rotation.y = THREE.MathUtils.lerp(
card.stackRotation,
(i - 1.5) * 0.025,
progress
);
} else {
card.group.position.copy(slots[i]);
card.group.rotation.y = (i - 1.5) * 0.025;
}
}
}
function currentArrangementIndex(time) {
let index = -1;
for (let i = 0; i < arrangementStarts.length; i++) {
if (time >= arrangementStarts[i]) index = i;
}
return index;
}
function updateCharacter(time) {
const activeIndex = currentArrangementIndex(time);
let characterX = -1.8;
if (time >= 0.9 && time < 5.08) {
const previousX =
activeIndex === 0
? -1.8
: slots[activeIndex - 1].x - 0.72;
const targetX = slots[activeIndex].x - 0.72;
const walkProgress = smooth(
(time - arrangementStarts[activeIndex]) / 0.34
);
characterX = THREE.MathUtils.lerp(previousX, targetX, walkProgress);
} else if (time >= 5.08 && time < 5.85) {
characterX = THREE.MathUtils.lerp(
slots[3].x - 0.72,
1.1,
smooth((time - 5.08) / 0.77)
);
} else if (time >= 5.85 && time < 6.48) {
characterX = 1.1;
} else if (time >= 6.48) {
characterX = THREE.MathUtils.lerp(
1.1,
-0.28,
smooth((time - 6.48) / 0.8)
);
}
const walking = time > 0.7 && time < 5.1 ? 1 : 0;
character.position.x = characterX;
character.position.y = Math.sin(time * 8) * 0.012 * walking;
character.rotation.z = Math.sin(time * 4.1) * 0.012 * walking;
// The character turns to watch the screen.
const watching = time >= playbackStart;
head.rotation.y = THREE.MathUtils.lerp(
head.rotation.y,
watching ? 0.43 : 0.035,
0.08
);
head.rotation.x = THREE.MathUtils.lerp(
head.rotation.x,
watching ? -0.035 : 0.02,
0.08
);
character.updateMatrixWorld(true);
const shoulder = new THREE.Vector3(0.39, 1.67, 0.03);
let handWorld = new THREE.Vector3(0.44, 1.23, 0.18);
if (time >= 5.12 && time < 6.5) {
handWorld = new THREE.Vector3(1.95, 1.98, 0.43);
} else if (activeIndex >= 0 && time < 5.12) {
const card = cards[activeIndex];
handWorld = card.group.position.clone().add(new THREE.Vector3(0, 0.15, 0));
}
const handLocal = character.worldToLocal(handWorld.clone());
const elbow = shoulder.clone().lerp(handLocal, 0.51);
elbow.x += 0.17;
elbow.y += 0.08;
elbow.z -= 0.07;
setSegment(upperArm, shoulder, elbow);
setSegment(lowerArm, elbow, handLocal);
hand.position.copy(handLocal);
const leftShoulder = new THREE.Vector3(-0.39, 1.67, 0.02);
const leftHandLocal = new THREE.Vector3(-0.43, 1.2, 0.18);
const leftElbow = leftShoulder.clone().lerp(leftHandLocal, 0.5);
leftElbow.x -= 0.12;
leftElbow.y += 0.08;
setSegment(leftUpperArm, leftShoulder, leftElbow);
setSegment(leftLowerArm, leftElbow, leftHandLocal);
leftHand.position.copy(leftHandLocal);
// Button press.
const pressing = time > 5.9 && time < 6.32
? Math.sin(((time - 5.9) / 0.42) * Math.PI)
: 0;
button.position.y = 1.91 - pressing * 0.055;
}
function updateScreen(time) {
let stage = -1;
let ended = false;
if (time >= playbackStart) {
const playbackTime = time - playbackStart;
stage = Math.min(3, Math.floor(playbackTime / frameDuration));
ended = playbackTime >= frameDuration * 4;
}
const screenKey = `${stage}-${ended}`;
if (screenKey !== previousScreenKey) {
drawScreen(stage, ended);
previousScreenKey = screenKey;
}
// Very subtle screen pulse at each new frame.
const framePhase = time >= playbackStart
? ((time - playbackStart) % frameDuration) / frameDuration
: 1;
const pulse = time >= playbackStart
? 1 + Math.exp(-framePhase * 12) * 0.008
: 1;
screenMesh.scale.set(pulse, pulse, 1);
}
function updateHUD(time) {
let label = "Arranging pages";
let badge = "In production";
if (time >= 5.08 && time < playbackStart) {
label = "Pressing play";
badge = "Ready";
} else if (time >= playbackStart && time < totalDuration) {
label = "Screen play";
badge = "Rolling";
} else if (time >= totalDuration) {
label = "Story complete";
badge = "The end";
}
statusEl.textContent = label;
badgeEl.textContent = badge;
fillEl.style.width = `${clamp01(time / totalDuration) * 100}%`;
}
function animate(now) {
const delta = Math.min((now - lastFrameTime) / 1000, 0.05);
lastFrameTime = now;
elapsed += delta;
updateCards(elapsed);
updateCharacter(elapsed);
updateScreen(elapsed);
updateHUD(elapsed);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
// -------------------------------------------------------------------------
// Direct camera controls — no addons or examples
// -------------------------------------------------------------------------
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
view.theta -= deltaX * 0.005;
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.004,
0.56,
1.34
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("pointerleave", event => {
if (dragging) endDrag(event);
});
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
7.5,
17.5
);
updateCamera();
},
{ passive: false }
);
canvas.style.cursor = "grab";
document.querySelector("#replay").addEventListener("click", () => {
elapsed = 0;
previousScreenKey = "";
lastFrameTime = performance.now();
});
document.querySelector("#resetView").addEventListener("click", () => {
view.theta = 0.38;
view.phi = 1.03;
view.radius = window.innerWidth < 720 ? 14.6 : 12.8;
view.target.set(-0.15, 1.75, 0);
updateCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (window.innerWidth < 720) {
view.radius = Math.max(view.radius, 14.2);
}
updateCamera();
}
window.addEventListener("resize", resize);
</script>
</body>
</html>
```