Prompt specification
Build or customize the Three.js 3D scene "Student schoolbag preparation" 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: Student schoolbag preparation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/student-schoolbag-preparation-x0563
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: student schoolbag preparation. Compose a desk, backpack, books, lunchbox, and water bottle; a student packs according to a visible timetable while often-needed items stay in accessible compartments.
Working Three.js Starter (student-schoolbag-preparation-x0563):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Schoolbag — Packing by Timetable</title>
<style>
:root {
--ink: #24313d;
--muted: #667784;
--paper: rgba(255, 255, 255, 0.92);
--teal: #188b83;
--teal-dark: #106d68;
--gold: #f3bd45;
--coral: #ed765f;
--purple: #7567c8;
--shadow: 0 14px 36px rgba(37, 55, 68, 0.17);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e8;
color: var(--ink);
font-family: Inter, ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}
#viewport {
position: fixed;
inset: 0;
touch-action: none;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255, 255, 255, 0.88);
box-shadow: var(--shadow);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: min(340px, calc(100vw - 44px));
padding: 18px 20px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--teal-dark);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
border-radius: 3px;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(24, 139, 131, 0.12);
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.04;
letter-spacing: -0.045em;
}
.brand p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.timetable {
position: absolute;
top: 22px;
right: 22px;
width: 310px;
padding: 16px;
border-radius: 18px;
}
.timetable-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.timetable-header strong {
font-size: 14px;
letter-spacing: 0.02em;
}
.live-badge {
padding: 5px 8px;
border-radius: 999px;
color: white;
background: var(--coral);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.schedule-row {
display: grid;
grid-template-columns: 53px 1fr auto;
align-items: center;
gap: 8px;
min-height: 43px;
padding: 7px 8px;
border-radius: 10px;
border: 1px solid transparent;
cursor: pointer;
transition: background 160ms ease, transform 160ms ease, border-color 160ms ease;
}
.schedule-row:hover {
background: #eef6f5;
transform: translateX(-2px);
}
.schedule-row.active {
color: white;
background: var(--teal);
border-color: var(--teal-dark);
box-shadow: 0 7px 16px rgba(24, 139, 131, 0.23);
}
.schedule-row.done {
background: #edf8f2;
}
.schedule-row.done.active {
background: var(--teal);
}
.schedule-time {
font-size: 10px;
font-weight: 900;
opacity: 0.76;
}
.schedule-subject {
font-size: 12px;
font-weight: 800;
}
.schedule-place {
max-width: 76px;
font-size: 9px;
font-weight: 800;
text-align: right;
opacity: 0.76;
}
.status {
position: absolute;
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 15px 17px;
border-radius: 18px;
}
.status-top {
display: flex;
align-items: center;
gap: 10px;
}
.status-icon {
display: grid;
flex: 0 0 38px;
height: 38px;
place-items: center;
border-radius: 11px;
background: #e5f5f3;
color: var(--teal-dark);
font-size: 18px;
}
#statusTitle {
margin: 0;
font-size: 15px;
font-weight: 900;
}
#statusDetail {
margin: 3px 0 0;
color: var(--muted);
font-size: 11px;
}
.progress-track {
height: 7px;
margin: 13px 0 9px;
overflow: hidden;
border-radius: 999px;
background: #e6ecee;
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #47b8a9);
transition: width 80ms linear;
}
.access-key {
display: flex;
flex-wrap: wrap;
gap: 6px 12px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
}
.key-item {
display: flex;
align-items: center;
gap: 5px;
}
.key-dot {
width: 8px;
height: 8px;
border-radius: 2px;
}
.controls {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
align-items: center;
gap: 8px;
padding: 8px;
border-radius: 16px;
transform: translateX(-50%);
}
button {
height: 38px;
border: 0;
border-radius: 10px;
color: var(--ink);
background: #edf2f3;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 900;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-2px);
background: #e3ebed;
}
button:active {
transform: translateY(0);
}
#playButton {
min-width: 88px;
color: white;
background: var(--teal);
}
#playButton:hover {
background: var(--teal-dark);
}
.control-divider {
width: 1px;
height: 24px;
background: #dce4e6;
}
.camera-hint {
position: absolute;
left: 50%;
bottom: 83px;
padding: 6px 10px;
border-radius: 999px;
color: rgba(36, 49, 61, 0.7);
background: rgba(255, 255, 255, 0.72);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.04em;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
@media (max-width: 780px) {
.brand {
top: 12px;
left: 12px;
width: 240px;
padding: 13px 15px;
}
.brand p {
display: none;
}
.timetable {
top: 12px;
right: 12px;
width: 225px;
padding: 11px;
}
.schedule-row {
grid-template-columns: 45px 1fr;
min-height: 35px;
padding: 5px 7px;
}
.schedule-place {
display: none;
}
.status {
left: 12px;
bottom: 75px;
width: 250px;
padding: 11px 13px;
}
.access-key {
display: none;
}
.controls {
bottom: 12px;
}
.camera-hint {
display: none;
}
}
@media (max-width: 540px) {
.brand {
width: calc(100vw - 24px);
}
.timetable {
top: 92px;
width: calc(100vw - 24px);
}
.schedule-row {
grid-template-columns: 50px 1fr 70px;
min-height: 31px;
}
.schedule-place {
display: block;
}
.status {
display: none;
}
.controls {
width: calc(100vw - 24px);
justify-content: center;
}
#speedButton {
display: none;
}
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="ui">
<section class="brand panel">
<div class="eyebrow">Packing lab · Voxel classroom</div>
<h1>Ready for school?</h1>
<p>
Watch the student follow today’s timetable. Books go in the main
compartment, while lunch and hydration stay easy to reach.
</p>
</section>
<aside class="timetable panel">
<div class="timetable-header">
<strong>Today’s timetable</strong>
<span class="live-badge">Live packing</span>
</div>
<div id="schedule"></div>
</aside>
<section class="status panel">
<div class="status-top">
<div class="status-icon" id="statusIcon">✦</div>
<div>
<p id="statusTitle">Reading the timetable…</p>
<p id="statusDetail">The student is preparing each school item.</p>
</div>
</div>
<div class="progress-track">
<div id="progress"></div>
</div>
<div class="access-key">
<span class="key-item">
<i class="key-dot" style="background:#7567c8"></i>
Books · main
</span>
<span class="key-item">
<i class="key-dot" style="background:#ed765f"></i>
Lunch · side
</span>
<span class="key-item">
<i class="key-dot" style="background:#2589ca"></i>
Drink · side
</span>
<span class="key-item">
<i class="key-dot" style="background:#e2aa2e"></i>
Pencils · front
</span>
</div>
</section>
<div class="camera-hint">Drag to orbit · Scroll or pinch to zoom · Click a timetable row to seek</div>
<nav class="controls panel" aria-label="Scene controls">
<button id="playButton" type="button">❚❚ Pause</button>
<button id="restartButton" type="button">↺ Restart</button>
<div class="control-divider"></div>
<button id="speedButton" type="button">1× Speed</button>
<button id="cameraButton" type="button">⌂ Camera</button>
</nav>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Core scene
// -------------------------------------------------------------------------
const viewport = document.getElementById("viewport");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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.05;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dce8e8");
scene.fog = new THREE.Fog("#dce8e8", 18, 35);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight("#e8fbff", "#8d7560", 2.25);
scene.add(hemisphere);
const sunlight = new THREE.DirectionalLight("#fff1cf", 3.2);
sunlight.position.set(-7, 12, 8);
sunlight.castShadow = true;
sunlight.shadow.mapSize.set(2048, 2048);
sunlight.shadow.camera.left = -13;
sunlight.shadow.camera.right = 13;
sunlight.shadow.camera.top = 13;
sunlight.shadow.camera.bottom = -13;
sunlight.shadow.camera.near = 1;
sunlight.shadow.camera.far = 35;
sunlight.shadow.bias = -0.00035;
scene.add(sunlight);
const fillLight = new THREE.DirectionalLight("#b9e5ff", 1.25);
fillLight.position.set(9, 6, -5);
scene.add(fillLight);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(
width,
height,
depth,
color,
parent = scene,
x = 0,
y = 0,
z = 0,
castShadow = true,
receiveShadow = true
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function addLabel(parent, text, color = "#ffffff", width = 1.2) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.fillRect(5, 7, 502, 114);
ctx.strokeStyle = "rgba(255,255,255,0.65)";
ctx.lineWidth = 7;
ctx.strokeRect(12, 14, 488, 94);
ctx.fillStyle = "#26333e";
ctx.font = "900 42px Trebuchet MS, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
parent.add(sprite);
return sprite;
}
function makeWorldLabel(text, x, y, z, color, width = 1.6) {
const label = addLabel(scene, text, color, width);
label.position.set(x, y, z);
return label;
}
// -------------------------------------------------------------------------
// Voxel classroom
// -------------------------------------------------------------------------
box(40, 0.25, 40, "#b8c9c6", scene, 0, -0.18, 0, false, true);
const tileColors = ["#d7dfda", "#dce5df", "#cfd9d5", "#e0e7e1"];
const tileSize = 1.5;
for (let x = -6; x <= 6; x++) {
for (let z = -6; z <= 6; z++) {
const color = tileColors[Math.abs(x * 3 + z * 5) % tileColors.length];
box(
tileSize - 0.035,
0.08,
tileSize - 0.035,
color,
scene,
x * tileSize,
-0.02,
z * tileSize,
false,
true
);
}
}
box(28, 11, 0.3, "#e9eee8", scene, 0, 5.3, -7.35, false, true);
box(28, 0.3, 0.45, "#b4c4c0", scene, 0, 0.15, -7.2, false, true);
// Window
box(5.3, 4.1, 0.22, "#7eaaa9", scene, -4.3, 5.45, -7.05, false, true);
box(4.75, 3.55, 0.18, "#bfe8ef", scene, -4.3, 5.45, -6.88, false, true);
box(0.18, 3.7, 0.22, "#f7f4e9", scene, -4.3, 5.45, -6.7, false, true);
box(4.9, 0.18, 0.22, "#f7f4e9", scene, -4.3, 5.45, -6.7, false, true);
box(5.7, 0.25, 0.48, "#f7f4e9", scene, -4.3, 3.32, -6.7, false, true);
box(4.5, 0.22, 0.35, "#9f7653", scene, -4.3, 3.08, -6.5, false, true);
// Voxel clouds
box(1.2, 0.42, 0.12, "#ffffff", scene, -5.5, 6.25, -6.73, false, false);
box(0.65, 0.65, 0.12, "#ffffff", scene, -4.9, 6.4, -6.72, false, false);
box(1.25, 0.4, 0.12, "#ffffff", scene, -3.6, 6.18, -6.72, false, false);
// Wall clock, deliberately voxel-shaped
box(1.45, 1.45, 0.24, "#f4c85f", scene, -0.2, 7.35, -7.0, false, true);
box(1.08, 1.08, 0.12, "#fff8df", scene, -0.2, 7.35, -6.83, false, true);
box(0.12, 0.65, 0.1, "#354451", scene, -0.2, 7.52, -6.71, false, false);
box(0.43, 0.1, 0.1, "#354451", scene, -0.02, 7.35, -6.7, false, false);
// -------------------------------------------------------------------------
// Classroom timetable board
// -------------------------------------------------------------------------
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1024;
boardCanvas.height = 640;
const boardContext = boardCanvas.getContext("2d");
const boardTexture = new THREE.CanvasTexture(boardCanvas);
boardTexture.colorSpace = THREE.SRGBColorSpace;
boardTexture.anisotropy = Math.min(
4,
renderer.capabilities.getMaxAnisotropy()
);
const board = new THREE.Mesh(
new THREE.PlaneGeometry(5.6, 3.5),
new THREE.MeshBasicMaterial({ map: boardTexture })
);
board.position.set(3.15, 5.25, -7.02);
scene.add(board);
box(5.95, 0.22, 0.25, "#9b6946", scene, 3.15, 7.08, -7.02, false, true);
box(5.95, 0.22, 0.25, "#9b6946", scene, 3.15, 3.42, -7.02, false, true);
box(0.22, 3.82, 0.25, "#9b6946", scene, 0.25, 5.25, -7.02, false, true);
box(0.22, 3.82, 0.25, "#9b6946", scene, 6.05, 5.25, -7.02, false, true);
// -------------------------------------------------------------------------
// Desk
// -------------------------------------------------------------------------
const desk = new THREE.Group();
scene.add(desk);
box(8.1, 0.34, 3.5, "#d99f64", desk, 0, 2.38, 0);
box(8.2, 0.16, 3.6, "#b87947", desk, 0, 2.16, 0);
box(0.42, 2.18, 0.42, "#596b70", desk, -3.25, 1.05, -1.22);
box(0.42, 2.18, 0.42, "#596b70", desk, 3.25, 1.05, -1.22);
box(0.42, 2.18, 0.42, "#596b70", desk, -3.25, 1.05, 1.22);
box(0.42, 2.18, 0.42, "#596b70", desk, 3.25, 1.05, 1.22);
box(7.15, 0.22, 0.25, "#52666b", desk, 0, 0.65, -1.22);
box(7.15, 0.22, 0.25, "#52666b", desk, 0, 0.65, 1.22);
// Drawer unit
box(1.65, 1.48, 2.55, "#d8a069", desk, 2.55, 1.55, 0);
box(1.42, 0.6, 0.14, "#efbd82", desk, 2.55, 1.95, 1.32);
box(1.42, 0.6, 0.14, "#efbd82", desk, 2.55, 1.2, 1.32);
box(0.42, 0.1, 0.16, "#7b5a42", desk, 2.55, 1.95, 1.44);
box(0.42, 0.1, 0.16, "#7b5a42", desk, 2.55, 1.2, 1.44);
// Pencil cup
box(0.6, 0.75, 0.6, "#4c91a2", desk, -3.05, 2.92, -0.82);
box(0.08, 0.8, 0.08, "#e75e55", desk, -3.16, 3.57, -0.82);
box(0.08, 0.95, 0.08, "#f0bd38", desk, -3.01, 3.62, -0.84);
box(0.08, 0.85, 0.08, "#7567c8", desk, -2.9, 3.57, -0.79);
// -------------------------------------------------------------------------
// Voxel backpack with open main compartment and accessible pockets
// -------------------------------------------------------------------------
const bag = new THREE.Group();
bag.position.set(0.6, 2.57, 0.12);
bag.rotation.y = -0.06;
scene.add(bag);
const bagColor = "#238f88";
const bagDark = "#176a68";
const bagTrim = "#f0bc45";
// Open body: back, side walls, base, and lower front panel
box(3.0, 2.55, 0.25, bagDark, bag, 0, 1.32, -0.68);
box(0.27, 2.55, 1.45, bagDark, bag, -1.36, 1.32, 0);
box(0.27, 2.55, 1.45, bagDark, bag, 1.36, 1.32, 0);
box(3.0, 0.27, 1.45, bagDark, bag, 0, 0.15, 0);
box(3.0, 1.0, 0.26, bagColor, bag, 0, 0.72, 0.68);
// Front rim and zipper
box(3.04, 0.15, 0.34, bagTrim, bag, 0, 1.22, 0.69);
box(2.6, 0.08, 0.13, "#f8e6a1", bag, 0, 1.2, 0.89);
// Open top flap, folded backward
const flap = new THREE.Group();
flap.position.set(0, 2.62, -0.58);
flap.rotation.x = -0.24;
bag.add(flap);
box(3.05, 0.3, 1.48, bagColor, flap, 0, 0, 0);
box(2.5, 0.08, 0.13, bagTrim, flap, 0, -0.15, 0.76);
box(0.24, 0.26, 0.18, "#f8e6a1", flap, 0, -0.16, 0.83);
// Quick-access front pocket
box(2.05, 0.82, 0.48, bagDark, bag, 0, 0.73, 0.93);
box(1.82, 0.55, 0.18, bagColor, bag, 0, 0.73, 1.22);
box(1.52, 0.065, 0.1, bagTrim, bag, 0, 0.96, 1.34);
box(0.22, 0.18, 0.15, "#f8e6a1", bag, 0.62, 0.96, 1.4);
// Side pockets, open at the top
box(0.48, 0.28, 1.15, bagDark, bag, -1.58, 0.62, 0.02);
box(0.12, 0.86, 1.15, bagColor, bag, -1.83, 0.9, 0.02);
box(0.12, 0.86, 1.15, bagColor, bag, -1.32, 0.9, 0.02);
box(0.48, 0.28, 1.15, bagDark, bag, 1.58, 0.62, 0.02);
box(0.12, 0.86, 1.15, bagColor, bag, 1.83, 0.9, 0.02);
box(0.12, 0.86, 1.15, bagColor, bag, 1.32, 0.9, 0.02);
// Back straps and buckles
box(0.34, 2.15, 0.22, "#4d4b72", bag, -0.92, 1.4, -0.91);
box(0.34, 2.15, 0.22, "#4d4b72", bag, 0.92, 1.4, -0.91);
box(0.48, 0.36, 0.27, bagTrim, bag, -0.92, 0.68, -0.92);
box(0.48, 0.36, 0.27, bagTrim, bag, 0.92, 0.68, -0.92);
// Carry handle
box(0.18, 0.54, 0.2, bagDark, bag, -0.48, 2.86, -0.48);
box(0.18, 0.54, 0.2, bagDark, bag, 0.48, 2.86, -0.48);
box(1.12, 0.18, 0.2, bagDark, bag, 0, 3.08, -0.48);
// Front patch
box(0.82, 0.4, 0.08, "#f0bc45", bag, -0.72, 0.77, 1.35);
box(0.5, 0.09, 0.09, "#385257", bag, -0.72, 0.77, 1.41);
makeWorldLabel("MAIN COMPARTMENT", -0.45, 5.28, -0.1, "#f0bc45", 2.45);
makeWorldLabel("QUICK ACCESS", -0.85, 3.42, 1.48, "#f6df91", 1.75);
makeWorldLabel("SIDE POCKET", 2.62, 3.8, 0.18, "#a8e2d8", 1.65);
// -------------------------------------------------------------------------
// Packable items
// -------------------------------------------------------------------------
function makeBook(cover, title, titleColor = "#ffffff") {
const group = new THREE.Group();
const width = 0.77;
const height = 1.04;
const depth = 0.2;
box(width, height, 0.15, "#f7f0da", group, 0, 0, 0);
box(width + 0.06, height + 0.06, 0.045, cover, group, 0, 0, 0.09);
box(width + 0.06, height + 0.06, 0.045, cover, group, 0, 0, -0.09);
box(width + 0.06, 0.15, 0.225, cover, group, 0, -height * 0.42, 0);
const label = addLabel(group, title, titleColor, 0.58);
label.position.set(0, 0.12, 0.125);
label.scale.set(0.58, 0.145, 1);
return group;
}
function makeLunchbox() {
const group = new THREE.Group();
box(1.12, 0.62, 0.74, "#ed765f", group, 0, 0, 0);
box(1.16, 0.13, 0.77, "#f39a72", group, 0, 0.28, 0);
box(0.23, 0.18, 0.13, "#f8d264", group, 0, 0.15, 0.42);
box(0.58, 0.15, 0.14, "#394f59", group, 0, 0.53, 0);
box(0.12, 0.32, 0.15, "#394f59", group, -0.22, 0.4, 0);
box(0.12, 0.32, 0.15, "#394f59", group, 0.22, 0.4, 0);
return group;
}
function makeBottle() {
const group = new THREE.Group();
box(0.48, 0.95, 0.48, "#278bc8", group, 0, -0.08, 0);
box(0.52, 0.2, 0.52, "#57b8e7", group, 0, 0.4, 0);
box(0.3, 0.22, 0.3, "#205b77", group, 0, 0.6, 0);
box(0.34, 0.08, 0.34, "#173f54", group, 0, 0.74, 0);
box(0.5, 0.24, 0.5, "#eaf7fb", group, 0, 0.04, 0);
return group;
}
function makePencilCase() {
const group = new THREE.Group();
box(1.18, 0.34, 0.55, "#e2aa2e", group, 0, 0, 0);
box(1.05, 0.07, 0.58, "#f5ca53", group, 0, 0.18, 0);
box(0.84, 0.045, 0.07, "#5a4a32", group, 0, 0.23, 0);
box(0.18, 0.12, 0.12, "#f7e19a", group, 0.47, 0.23, 0);
return group;
}
const mathBook = makeBook("#7567c8", "MATH");
const englishBook = makeBook("#e36c72", "READ");
const scienceBook = makeBook("#3f9b78", "SCIENCE");
const lunchbox = makeLunchbox();
const bottle = makeBottle();
const pencilCase = makePencilCase();
scene.add(mathBook, englishBook, scienceBook, lunchbox, bottle, pencilCase);
const deskTop = 2.56;
const schedule = [
{
time: "08:15",
subject: "Mathematics",
item: "Math book",
place: "Main",
color: "#7567c8",
group: mathBook,
source: new THREE.Vector3(-2.62, deskTop + 0.54, -0.22),
targetLocal: new THREE.Vector3(-0.93, 1.28, -0.02),
targetRotation: new THREE.Euler(0, -0.05, 0)
},
{
time: "09:30",
subject: "English",
item: "Reader",
place: "Main",
color: "#e36c72",
group: englishBook,
source: new THREE.Vector3(-1.92, deskTop + 0.54, 0.48),
targetLocal: new THREE.Vector3(0, 1.26, -0.01),
targetRotation: new THREE.Euler(0, 0.02, 0)
},
{
time: "11:00",
subject: "Science",
item: "Lab book",
place: "Main",
color: "#3f9b78",
group: scienceBook,
source: new THREE.Vector3(-3.25, deskTop + 0.54, 0.68),
targetLocal: new THREE.Vector3(0.91, 1.26, -0.03),
targetRotation: new THREE.Euler(0, 0.07, 0)
},
{
time: "12:30",
subject: "Lunch",
item: "Lunchbox",
place: "Side",
color: "#ed765f",
group: lunchbox,
source: new THREE.Vector3(2.85, deskTop + 0.33, 0.25),
targetLocal: new THREE.Vector3(1.63, 1.08, 0.02),
targetRotation: new THREE.Euler(0, 0.08, 0)
},
{
time: "13:10",
subject: "Hydration",
item: "Water bottle",
place: "Side",
color: "#2589ca",
group: bottle,
source: new THREE.Vector3(3.42, deskTop + 0.63, -0.66),
targetLocal: new THREE.Vector3(-1.66, 1.18, -0.02),
targetRotation: new THREE.Euler(0, -0.04, 0)
},
{
time: "14:00",
subject: "Art",
item: "Pencil case",
place: "Front",
color: "#e2aa2e",
group: pencilCase,
source: new THREE.Vector3(-1.23, deskTop + 0.19, 1.05),
targetLocal: new THREE.Vector3(0, 1.35, 0.96),
targetRotation: new THREE.Euler(0, 0, 0)
}
];
bag.updateMatrixWorld(true);
for (const entry of schedule) {
entry.sourceQuaternion = entry.group.quaternion.clone();
entry.target = bag.localToWorld(entry.targetLocal.clone());
entry.targetQuaternion = new THREE.Quaternion().setFromEuler(
entry.targetRotation
);
}
// A tiny stack of loose paper on the desk.
for (let i = 0; i < 4; i++) {
const sheet = box(
0.64,
0.035,
0.48,
i % 2 ? "#f7f0da" : "#fffdf4",
scene,
1.78 + i * 0.025,
deskTop + 0.02 + i * 0.038,
1.05,
true,
true
);
sheet.rotation.y = 0.1 * i;
}
// -------------------------------------------------------------------------
// Voxel student
// -------------------------------------------------------------------------
const student = new THREE.Group();
student.position.set(-2.4, 0, -2.04);
scene.add(student);
const shirt = "#7464c9";
const pants = "#34465c";
const skin = "#e8a273";
const hair = "#3b302d";
// Shoes and legs
box(0.48, 0.24, 0.72, "#26323b", student, -0.3, 0.16, 0.12);
box(0.48, 0.24, 0.72, "#26323b", student, 0.3, 0.16, 0.12);
box(0.42, 1.2, 0.45, pants, student, -0.3, 0.78, 0);
box(0.42, 1.2, 0.45, pants, student, 0.3, 0.78, 0);
// Torso and hoodie details
box(1.15, 1.4, 0.7, shirt, student, 0, 2.05, 0);
box(0.54, 0.35, 0.1, "#6558ad", student, 0, 2.35, 0.39);
box(0.52, 0.12, 0.11, "#f1c45d", student, 0, 1.55, 0.4);
box(0.1, 0.25, 0.1, "#f1c45d", student, -0.18, 2.2, 0.42);
box(0.1, 0.25, 0.1, "#f1c45d", student, 0.18, 2.2, 0.42);
// Head
box(0.9, 0.88, 0.8, skin, student, 0, 3.2, 0.02);
box(0.98, 0.25, 0.86, hair, student, 0, 3.68, 0.01);
box(0.22, 0.46, 0.18, hair, student, -0.43, 3.46, 0);
box(0.22, 0.46, 0.18, hair, student, 0.43, 3.46, 0);
box(0.1, 0.12, 0.08, "#29313a", student, -0.2, 3.25, 0.44);
box(0.1, 0.12, 0.08, "#29313a", student, 0.2, 3.25, 0.44);
box(0.23, 0.07, 0.08, "#a85d52", student, 0, 3.04, 0.44);
box(0.16, 0.2, 0.2, skin, student, -0.47, 3.2, 0);
box(0.16, 0.2, 0.2, skin, student, 0.47, 3.2, 0);
// Left arm hangs by the side.
box(0.3, 1.03, 0.34, shirt, student, -0.75, 2.13, 0);
box(0.32, 0.3, 0.36, skin, student, -0.75, 1.5, 0);
// Animated right arm.
const rightArm = new THREE.Group();
rightArm.position.set(0.7, 2.67, 0.02);
student.add(rightArm);
box(0.3, 1, 0.34, shirt, rightArm, 0, -0.5, 0);
const rightHand = box(0.34, 0.3, 0.36, skin, scene);
// -------------------------------------------------------------------------
// DOM timetable
// -------------------------------------------------------------------------
const scheduleElement = document.getElementById("schedule");
const rowElements = [];
schedule.forEach((entry, index) => {
const row = document.createElement("div");
row.className = "schedule-row";
row.setAttribute("role", "button");
row.setAttribute("tabindex", "0");
row.innerHTML = `
<span class="schedule-time">${entry.time}</span>
<span class="schedule-subject">${entry.subject}</span>
<span class="schedule-place">${entry.place}</span>
`;
const seek = () => {
elapsed = index * STEP + 0.08;
playing = true;
updatePlayButton();
refreshTimeline();
};
row.addEventListener("click", seek);
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
seek();
}
});
scheduleElement.appendChild(row);
rowElements.push(row);
});
function drawBoard(activeIndex) {
const ctx = boardContext;
const W = boardCanvas.width;
const H = boardCanvas.height;
ctx.fillStyle = "#f9f5e8";
ctx.fillRect(0, 0, W, H);
ctx.fillStyle = "#188b83";
ctx.fillRect(0, 0, W, 108);
ctx.fillStyle = "#ffffff";
ctx.font = "900 47px Trebuchet MS, sans-serif";
ctx.textAlign = "left";
ctx.textBaseline = "middle";
ctx.fillText("TODAY'S TIMETABLE", 42, 55);
ctx.font = "700 20px Trebuchet MS, sans-serif";
ctx.fillText("PACK TO PLAN • REACH WITHOUT DIGGING", 690, 58);
schedule.forEach((entry, index) => {
const y = 120 + index * 70;
const active = index === activeIndex;
ctx.fillStyle = active
? "#188b83"
: index % 2
? "#eef1e8"
: "#ffffff";
ctx.fillRect(30, y, W - 60, 58);
if (active) {
ctx.fillStyle = "#f3bd45";
ctx.fillRect(30, y, 13, 58);
}
ctx.fillStyle = active ? "#ffffff" : "#31434d";
ctx.font = "900 24px Trebuchet MS, sans-serif";
ctx.fillText(entry.time, 58, y + 30);
ctx.font = "800 25px Trebuchet MS, sans-serif";
ctx.fillText(entry.subject, 170, y + 30);
ctx.textAlign = "right";
ctx.font = "700 21px Trebuchet MS, sans-serif";
ctx.fillStyle = active ? "#eafbf8" : "#6b7c83";
ctx.fillText(`${entry.item} → ${entry.place}`, W - 56, y + 30);
ctx.textAlign = "left";
});
ctx.fillStyle = "#dcefe9";
ctx.fillRect(30, 550, W - 60, 62);
ctx.fillStyle = "#176d68";
ctx.font = "900 22px Trebuchet MS, sans-serif";
ctx.fillText("ACCESS RULE: BOOKS IN MAIN • LUNCH + DRINK IN SIDE", 52, 581);
boardTexture.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Timeline and animation
// -------------------------------------------------------------------------
const STEP = 3.05;
const DURATION = 2.58;
const TOTAL = schedule.length * STEP;
let elapsed = 0;
let playing = true;
let speed = 1;
let activeIndex = -2;
let previousTime = performance.now();
const statusTitle = document.getElementById("statusTitle");
const statusDetail = document.getElementById("statusDetail");
const statusIcon = document.getElementById("statusIcon");
const progressElement = document.getElementById("progress");
const playButton = document.getElementById("playButton");
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updatePlayButton() {
playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
playButton.setAttribute("aria-label", playing ? "Pause packing" : "Play packing");
}
function refreshTimeline() {
const completed = elapsed >= TOTAL;
const index = completed ? -1 : Math.min(schedule.length - 1, Math.floor(elapsed / STEP));
if (index !== activeIndex) {
activeIndex = index;
rowElements.forEach((row, rowIndex) => {
row.classList.toggle("active", rowIndex === index);
row.classList.toggle("done", elapsed >= (rowIndex + 1) * STEP);
});
drawBoard(index);
if (completed) {
statusTitle.textContent = "Bag packed — ready for school!";
statusDetail.textContent =
"All six timetable items are packed, with daily essentials kept accessible.";
statusIcon.textContent = "✓";
} else if (index >= 0) {
const entry = schedule[index];
statusTitle.textContent = `${entry.subject} · ${entry.item}`;
statusDetail.textContent = `Packing into the ${entry.place.toLowerCase()} compartment.`;
statusIcon.textContent = "✦";
}
}
progressElement.style.width = `${Math.min(100, (elapsed / TOTAL) * 100)}%`;
}
const temporaryPosition = new THREE.Vector3();
const temporaryQuaternion = new THREE.Quaternion();
const restHand = new THREE.Vector3();
const shoulderWorld = new THREE.Vector3();
const armDirection = new THREE.Vector3();
const downDirection = new THREE.Vector3(0, -1, 0);
function updateItems(time) {
let activeItem = null;
let localProgress = 0;
for (let index = 0; index < schedule.length; index++) {
const entry = schedule[index];
const start = index * STEP;
const p = (time - start) / DURATION;
if (p < 0) {
entry.group.position.copy(entry.source);
entry.group.quaternion.copy(entry.sourceQuaternion);
continue;
}
if (p >= 1) {
entry.group.position.copy(entry.target);
entry.group.quaternion.copy(entry.targetQuaternion);
continue;
}
activeItem = entry;
localProgress = p;
if (p < 0.16) {
entry.group.position.copy(entry.source);
entry.group.quaternion.copy(entry.sourceQuaternion);
} else if (p < 0.3) {
const q = smoothstep((p - 0.16) / 0.14);
entry.group.position.lerpVectors(entry.source, entry.target, q * 0.08);
entry.group.position.y += Math.sin(q * Math.PI) * 0.18;
entry.group.quaternion.slerpQuaternions(
entry.sourceQuaternion,
entry.targetQuaternion,
q * 0.12
);
} else if (p < 0.72) {
const q = smoothstep((p - 0.3) / 0.42);
temporaryPosition.lerpVectors(entry.source, entry.target, q);
temporaryPosition.y += Math.sin(q * Math.PI) * 0.85;
entry.group.position.copy(temporaryPosition);
temporaryQuaternion.slerpQuaternions(
entry.sourceQuaternion,
entry.targetQuaternion,
q
);
entry.group.quaternion.copy(temporaryQuaternion);
} else {
const q = smoothstep((p - 0.72) / 0.28);
entry.group.position.copy(entry.target);
temporaryQuaternion.slerpQuaternions(
entry.targetQuaternion,
entry.targetQuaternion,
q
);
entry.group.quaternion.copy(temporaryQuaternion);
}
}
// Move the student toward the item being packed.
if (activeItem) {
let travel = 0;
if (localProgress < 0.3) {
travel = 0;
} else if (localProgress < 0.72) {
travel = smoothstep((localProgress - 0.3) / 0.42);
} else {
travel = 1;
}
const startX = activeItem.source.x - 1.02;
const endX = activeItem.target.x - 1.48;
student.position.x = THREE.MathUtils.lerp(startX, endX, travel);
student.position.z = -2.04;
student.position.y =
activeItem && localProgress > 0.3 && localProgress < 0.72
? Math.sin(time * 7) * 0.025
: 0;
} else {
student.position.x = THREE.MathUtils.lerp(
student.position.x,
-2.4,
0.08
);
student.position.z = -2.04;
student.position.y = 0;
}
student.updateMatrixWorld(true);
// Choose the animated hand target.
let handTarget;
if (activeItem && localProgress < 0.72) {
handTarget = activeItem.group.position.clone();
if (localProgress < 0.16) {
const reach = smoothstep(localProgress / 0.16);
restHand.set(0.93, 2.28, 0.12);
student.localToWorld(restHand);
handTarget.lerpVectors(restHand, handTarget, reach);
}
} else {
restHand.set(0.93, 2.28, 0.12);
student.localToWorld(restHand);
handTarget = restHand.clone();
if (activeItem) {
const returnAmount = smoothstep((localProgress - 0.72) / 0.28);
handTarget.lerp(activeItem.target, 1 - returnAmount);
}
}
rightHand.position.copy(handTarget);
shoulderWorld.set(0.7, 2.67, 0.02);
student.localToWorld(shoulderWorld);
armDirection.copy(handTarget).sub(shoulderWorld);
const armLength = Math.max(0.35, armDirection.length());
rightArm.quaternion.setFromUnitVectors(
downDirection,
armDirection.normalize()
);
rightArm.scale.set(1, armLength, 1);
}
// -------------------------------------------------------------------------
// Custom camera controls: orbit, wheel zoom, touch pinch
// -------------------------------------------------------------------------
const cameraState = {
radius: 13.6,
phi: 1.14,
theta: 0.72,
target: new THREE.Vector3(0, 2.45, -0.1)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.radius = 13.6;
cameraState.phi = 1.14;
cameraState.theta = 0.72;
cameraState.target.set(0, 2.45, -0.1);
updateCamera();
}
const pointers = new Map();
let previousPointerX = 0;
let previousPointerY = 0;
let pinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
previousPointerX = event.clientX;
previousPointerY = event.clientY;
if (pointers.size === 2) {
const values = [...pointers.values()];
pinchDistance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previousPointerX;
const dy = event.clientY - previousPointerY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.48,
1.43
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
} else if (pointers.size === 2) {
const values = [...pointers.values()];
const distance = Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
if (pinchDistance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + (pinchDistance - distance) * 0.018,
8.2,
19
);
}
pinchDistance = distance;
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
pinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", removePointer);
renderer.domElement.addEventListener("pointercancel", removePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.01,
8.2,
19
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI controls and keyboard shortcuts
// -------------------------------------------------------------------------
document.getElementById("playButton").addEventListener("click", () => {
if (elapsed >= TOTAL) elapsed = 0;
playing = !playing;
updatePlayButton();
});
document.getElementById("restartButton").addEventListener("click", () => {
elapsed = 0;
playing = true;
activeIndex = -2;
updatePlayButton();
refreshTimeline();
});
document.getElementById("speedButton").addEventListener("click", (event) => {
speed = speed === 1 ? 2 : 1;
event.currentTarget.textContent = `${speed}× Speed`;
});
document.getElementById("cameraButton").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
if (elapsed >= TOTAL) elapsed = 0;
playing = !playing;
updatePlayButton();
}
if (event.key.toLowerCase() === "r") {
elapsed = 0;
playing = true;
activeIndex = -2;
updatePlayButton();
refreshTimeline();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate(now) {
const delta = Math.min(0.05, (now - previousTime) / 1000);
previousTime = now;
if (playing) {
elapsed = Math.min(TOTAL, elapsed + delta * speed);
}
refreshTimeline();
updateItems(elapsed);
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resetCamera();
updatePlayButton();
refreshTimeline();
requestAnimationFrame(animate);
</script>
</body>
</html>
```