Prompt specification
Build or customize the Three.js 3D scene "Arrival-to-classroom orientation" 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: Arrival-to-classroom orientation
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/arrival-to-classroom-orientation-x3862
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: arrival-to-classroom orientation. Animate a student meeting a teacher, finding the matching cubby, and reaching a desk; each landmark becomes visible before the student follows it. Return one self-contained HTML file.
Working Three.js Starter (arrival-to-classroom-orientation-x3862):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Arrival to Classroom — Voxel Orientation</title>
<style>
:root {
--ink: #19373e;
--muted: #60777c;
--paper: rgba(255, 255, 255, 0.9);
--mint: #58c7b1;
--coral: #f48370;
--gold: #f3bd52;
--line: rgba(25, 55, 62, 0.12);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dcebed;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 3;
}
.brand {
position: absolute;
top: 24px;
left: 26px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 15px 11px 11px;
border: 1px solid rgba(255,255,255,.75);
border-radius: 16px;
background: rgba(255,255,255,.72);
box-shadow: 0 10px 30px rgba(30, 65, 72, .08);
backdrop-filter: blur(12px);
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 7px);
grid-template-rows: repeat(2, 7px);
gap: 3px;
padding: 8px;
border-radius: 11px;
background: var(--ink);
}
.brand-mark i {
display: block;
border-radius: 2px;
background: var(--mint);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(3) {
background: var(--gold);
}
.brand-title {
font-size: 13px;
font-weight: 800;
letter-spacing: .12em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
letter-spacing: .04em;
}
.actions {
position: absolute;
top: 24px;
right: 26px;
display: flex;
gap: 9px;
pointer-events: auto;
}
button {
border: 1px solid rgba(25, 55, 62, .12);
border-radius: 13px;
padding: 11px 14px;
color: var(--ink);
background: rgba(255,255,255,.84);
box-shadow: 0 8px 24px rgba(30, 65, 72, .08);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform .18s ease, background .18s ease;
}
button:hover {
transform: translateY(-2px);
background: #fff;
}
button span {
margin-right: 6px;
font-size: 15px;
}
.story {
position: absolute;
left: 26px;
bottom: 27px;
width: min(410px, calc(100vw - 52px));
padding: 20px 22px 18px;
overflow: hidden;
border: 1px solid rgba(255,255,255,.86);
border-radius: 22px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(30, 65, 72, .13);
backdrop-filter: blur(16px);
}
.story::before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
width: 5px;
background: var(--mint);
transition: background .3s ease;
}
.story-top {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 9px;
}
#step {
color: var(--mint);
font-size: 11px;
font-weight: 850;
letter-spacing: .14em;
text-transform: uppercase;
}
.mode {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border-radius: 999px;
color: var(--muted);
background: #eef4f2;
font-size: 10px;
font-weight: 800;
letter-spacing: .1em;
text-transform: uppercase;
}
.mode::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 4px rgba(243,189,82,.18);
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 31px);
line-height: 1.08;
letter-spacing: -.035em;
}
#copy {
min-height: 46px;
margin: 10px 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.progress-wrap {
height: 5px;
overflow: hidden;
border-radius: 999px;
background: #e5ece9;
}
#progress {
width: 0%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--mint), var(--gold));
transition: width .1s linear;
}
.legend {
position: absolute;
right: 26px;
bottom: 27px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 14px;
border: 1px solid rgba(255,255,255,.75);
border-radius: 14px;
color: var(--muted);
background: rgba(255,255,255,.68);
box-shadow: 0 10px 30px rgba(30,65,72,.08);
backdrop-filter: blur(12px);
font-size: 11px;
font-weight: 700;
}
.legend span {
display: flex;
align-items: center;
gap: 6px;
}
.legend b {
width: 8px;
height: 8px;
border-radius: 3px;
background: var(--gold);
}
.legend span:nth-child(2) b { background: var(--coral); }
.legend span:nth-child(3) b { background: var(--mint); }
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #dcebed;
transition: opacity .45s ease, visibility .45s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader-card {
display: flex;
align-items: center;
gap: 14px;
padding: 17px 20px;
border-radius: 17px;
color: var(--ink);
background: rgba(255,255,255,.86);
box-shadow: 0 16px 50px rgba(30,65,72,.12);
font-size: 13px;
font-weight: 750;
}
.spinner {
width: 24px;
height: 24px;
border: 4px solid #dce8e5;
border-top-color: var(--mint);
border-radius: 50%;
animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (max-width: 720px) {
.brand { top: 15px; left: 15px; }
.brand-subtitle { display: none; }
.actions { top: 15px; right: 15px; }
button { padding: 10px; }
button .button-label { display: none; }
.story {
left: 15px;
bottom: 15px;
width: calc(100vw - 30px);
padding: 17px 18px 16px;
}
.legend { display: none; }
#copy { min-height: 0; }
}
</style>
</head>
<body>
<div id="loading">
<div class="loader-card">
<div class="spinner"></div>
<span id="loading-text">Building the classroom…</span>
</div>
</div>
<div id="hud">
<div class="brand">
<div class="brand-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></div>
<div>
<div class="brand-title">Arrival Lab</div>
<div class="brand-subtitle">Voxel classroom orientation · Room 204</div>
</div>
</div>
<div class="actions">
<button id="camera-reset" title="Reset camera" aria-label="Reset camera">
<span>⌖</span><span class="button-label">Reset view</span>
</button>
<button id="replay" title="Replay the orientation" aria-label="Replay the orientation">
<span>↻</span><span class="button-label">Replay</span>
</button>
</div>
<section class="story" aria-live="polite">
<div class="story-top">
<div id="step">01 / ARRIVAL</div>
<div class="mode" id="mode">Look</div>
</div>
<h1 id="title">Start with a visible landmark</h1>
<p id="copy">The entry beacon appears first. Its floor dots will guide the student into the classroom.</p>
<div class="progress-wrap"><div id="progress"></div></div>
</section>
<div class="legend" aria-hidden="true">
<span><b></b> Look</span>
<span><b></b> Follow</span>
<span><b></b> Arrive</span>
<span>·</span>
<span>Drag to orbit · Wheel to zoom</span>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const loading = document.querySelector("#loading");
const loadingText = document.querySelector("#loading-text");
const stepEl = document.querySelector("#step");
const titleEl = document.querySelector("#title");
const copyEl = document.querySelector("#copy");
const modeEl = document.querySelector("#mode");
const progressEl = document.querySelector("#progress");
let renderer;
try {
renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
} catch (error) {
loadingText.textContent = "WebGL is required to view this classroom.";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.04;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#dcebed");
scene.fog = new THREE.Fog("#dcebed", 34, 62);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemi = new THREE.HemisphereLight(0xffffff, 0x7e9a9b, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3d9, 3.25);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 42;
sun.shadow.bias = -0.0004;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xccecff, 1.05);
fill.position.set(11, 8, -7);
scene.add(fill);
const materialCache = new Map();
function standardMaterial(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02
})
);
}
return materialCache.get(color);
}
function box(w, h, d, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
typeof color === "object" ? color : standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, w, h, r) {
r = Math.min(r, w / 2, h / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + w, y, x + w, y + h, r);
ctx.arcTo(x + w, y + h, x, y + h, r);
ctx.arcTo(x, y + h, x, y, r);
ctx.arcTo(x, y, x + w, y, r);
ctx.closePath();
}
function textTexture(
text,
{
width = 512,
height = 128,
bg = "#ffffff",
fg = "#19373e",
fontSize = 58,
radius = 25,
padding = 28
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
if (bg !== "transparent") {
roundedRect(ctx, 3, 3, width - 6, height - 6, radius);
ctx.fillStyle = bg;
ctx.fill();
}
let size = fontSize;
ctx.font = `800 ${size}px system-ui, sans-serif`;
while (ctx.measureText(text).width > width - padding * 2 && size > 20) {
size -= 2;
ctx.font = `800 ${size}px system-ui, sans-serif`;
}
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = fg;
ctx.fillText(text, width / 2, height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function labelSprite(text, options = {}) {
const {
bg = "#ffffff",
fg = "#19373e",
scale = [3, 0.75],
depthTest = true,
fontSize = 58
} = options;
const texture = textTexture(text, { bg, fg, fontSize });
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(scale[0], scale[1], 1);
return sprite;
}
// Room shell and tiled floor.
box(23.2, 0.45, 15.6, 0xb7c9c8, -0.1, -0.25, 0.55);
const floorColors = [0xe9efea, 0xf1eee5, 0xdeebe7, 0xe4ece8];
for (let x = 0; x < 12; x++) {
for (let z = 0; z < 8; z++) {
const color = floorColors[(x * 3 + z * 5) % floorColors.length];
box(1.94, 0.09, 1.84, color, -11 + x * 2, 0.015, -6 + z * 1.9);
}
}
box(23.2, 5.4, 0.35, 0xf3ecdf, -0.1, 2.7, -7.02);
box(0.35, 2.4, 9.8, 0xe8e3d8, -11.62, 1.2, -1.75);
box(0.35, 1.05, 13.4, 0xe8e3d8, 11.62, 0.52, 0.2);
// Soft ground shadow below the diorama.
const shadowPlane = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.ShadowMaterial({ opacity: 0.13 })
);
shadowPlane.rotation.x = -Math.PI / 2;
shadowPlane.position.y = -0.49;
shadowPlane.receiveShadow = true;
scene.add(shadowPlane);
// Entrance portal.
box(0.22, 3.2, 0.28, 0x4f777b, -10.05, 1.6, 6.78);
box(0.22, 3.2, 0.28, 0x4f777b, -7.95, 1.6, 6.78);
box(2.32, 0.24, 0.28, 0x58c7b1, -9, 3.18, 6.78);
const entrySign = labelSprite("ENTRY", {
bg: "#58c7b1",
fg: "#ffffff",
scale: [1.45, 0.42],
fontSize: 58
});
entrySign.position.set(-9, 3.57, 6.8);
scene.add(entrySign);
// Teacher board and room identity.
box(5.05, 2.18, 0.17, 0x38545b, -8.25, 3.15, -6.78);
box(4.72, 1.86, 0.12, 0x6f9f91, -8.25, 3.15, -6.66);
const paperColors = [0xf5ca62, 0xf58d7a, 0xdcecf1, 0xf5eee0];
const paperPositions = [
[-9.6, 3.55], [-8.65, 3.55], [-7.65, 3.55],
[-9.55, 2.75], [-8.55, 2.75], [-7.55, 2.75]
];
paperPositions.forEach((p, i) => {
box(0.65, 0.48, 0.035, paperColors[i % paperColors.length], p[0], p[1], -6.56);
});
const roomSign = labelSprite("ROOM 204", {
bg: "#38545b",
fg: "#ffffff",
scale: [2.7, 0.62],
fontSize: 62
});
roomSign.position.set(-8.2, 4.72, -6.58);
scene.add(roomSign);
// Window.
box(5.5, 2.55, 0.16, 0xbadbe2, 6.65, 3.18, -6.79);
box(5.72, 0.16, 0.21, 0xffffff, 6.65, 4.48, -6.69);
box(5.72, 0.16, 0.21, 0xffffff, 6.65, 1.88, -6.69);
box(0.16, 2.55, 0.21, 0xffffff, 3.88, 3.18, -6.69);
box(0.16, 2.55, 0.21, 0xffffff, 9.42, 3.18, -6.69);
box(0.12, 2.55, 0.22, 0xffffff, 6.65, 3.18, -6.68);
box(5.55, 0.13, 0.23, 0xffffff, 6.65, 3.18, -6.67);
// Voxel clock.
const clockGroup = new THREE.Group();
clockGroup.position.set(3.15, 4.08, -6.62);
scene.add(clockGroup);
box(1.22, 1.22, 0.15, 0x38545b, 0, 0, 0, clockGroup);
box(1.02, 1.02, 0.17, 0xf8f1e3, 0, 0, 0.02, clockGroup);
box(0.08, 0.34, 0.05, 0x38545b, 0, 0.16, 0.13, clockGroup);
const clockHand = box(0.28, 0.07, 0.05, 0xf48370, 0.11, 0.02, 0.14, clockGroup);
clockHand.rotation.z = -0.75;
// Cubby bank, 12 open cells. Matching cubby 07 is highlighted.
const cubbyCenterX = -1;
const cellW = 1.2;
const cubbyZ = -6.13;
box(7.3, 2.55, 0.18, 0x57777b, cubbyCenterX, 1.34, -6.65);
box(7.5, 0.16, 1.12, 0xbe865c, cubbyCenterX, 0.14, cubbyZ);
box(7.5, 0.16, 1.12, 0xbe865c, cubbyCenterX, 1.34, cubbyZ);
box(7.5, 0.16, 1.12, 0xbe865c, cubbyCenterX, 2.54, cubbyZ);
for (let c = 0; c <= 6; c++) {
const x = cubbyCenterX - 3.6 + c * cellW;
box(0.12, 2.42, 1.12, 0xbe865c, x, 1.34, cubbyZ);
}
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 6; col++) {
const number = row * 6 + col + 1;
const x = cubbyCenterX + (col - 2.5) * cellW;
const y = row === 0 ? 0.72 : 1.93;
const isTarget = number === 7;
if (isTarget) {
box(1.08, 0.08, 0.08, 0xf3bd52, x, 1.43, -5.53);
box(1.08, 0.08, 0.08, 0xf3bd52, x, 2.43, -5.53);
box(0.08, 1.0, 0.08, 0xf3bd52, x - 0.54, 1.93, -5.53);
box(0.08, 1.0, 0.08, 0xf3bd52, x + 0.54, 1.93, -5.53);
box(0.55, 0.46, 0.34, 0x58c7b1, x, 1.72, -5.93);
box(0.32, 0.16, 0.12, 0x386c67, x, 2.01, -5.92);
}
const numberSprite = labelSprite(String(number).padStart(2, "0"), {
bg: isTarget ? "#f3bd52" : "#f8f2e7",
fg: isTarget ? "#19373e" : "#527078",
scale: [0.42, 0.42],
fontSize: 76
});
numberSprite.position.set(x, y, -5.51);
scene.add(numberSprite);
if (!isTarget && (col + row * 2) % 3 === 0) {
box(0.19, 0.52, 0.38, col % 2 ? 0xf48370 : 0x6ea9c6, x - 0.2, y - 0.08, -5.95);
box(0.16, 0.42, 0.34, 0xf3bd52, x + 0.05, y - 0.13, -5.96);
}
}
}
const cubbiesSign = labelSprite("CUBBIES", {
bg: "#f8f2e7",
fg: "#38545b",
scale: [2.15, 0.52]
});
cubbiesSign.position.set(-1, 3.12, -6.55);
scene.add(cubbiesSign);
// Teacher welcome area.
box(3.8, 0.035, 2.7, 0xb9dcd5, -6.5, 0.09, 2.1);
box(3.05, 0.18, 1.35, 0xd39b68, -6.5, 1.25, 1.02);
box(0.22, 1.17, 1.02, 0x8e684f, -7.7, 0.65, 1.02);
box(0.22, 1.17, 1.02, 0x8e684f, -5.3, 0.65, 1.02);
const helloSign = labelSprite("HELLO", {
bg: "#f48370",
fg: "#ffffff",
scale: [1.55, 0.4],
fontSize: 62
});
helloSign.position.set(-6.5, 0.92, 1.72);
scene.add(helloSign);
box(0.38, 0.08, 0.55, 0x38545b, -6.35, 1.39, 0.9);
box(0.3, 0.03, 0.42, 0xdcebed, -6.35, 1.44, 0.9);
// Desks and chairs.
function makeDesk(x, z, number, target = false) {
const topColor = target ? 0x72cdb9 : 0xd5a16f;
box(2.55, 0.17, 1.28, topColor, x, 1.28, z);
box(0.17, 1.2, 0.17, 0x806657, x - 0.95, 0.66, z - 0.43);
box(0.17, 1.2, 0.17, 0x806657, x + 0.95, 0.66, z - 0.43);
box(0.17, 1.2, 0.17, 0x806657, x - 0.95, 0.66, z + 0.43);
box(0.17, 1.2, 0.17, 0x806657, x + 0.95, 0.66, z + 0.43);
box(0.92, 0.14, 0.88, target ? 0x58c7b1 : 0x6fa0a7, x, 0.68, z + 1.15);
box(0.92, 0.84, 0.14, target ? 0x58c7b1 : 0x6fa0a7, x, 1.12, z + 1.55);
box(0.12, 0.58, 0.12, 0x506d72, x - 0.34, 0.37, z + 1.15);
box(0.12, 0.58, 0.12, 0x506d72, x + 0.34, 0.37, z + 1.15);
const plate = labelSprite(String(number), {
bg: target ? "#f3bd52" : "#f6efe2",
fg: target ? "#19373e" : "#506d72",
scale: [0.72, 0.36],
fontSize: 74
});
plate.position.set(x, 0.99, z + 0.66);
scene.add(plate);
box(0.55, 0.09, 0.48, number % 2 ? 0xf48370 : 0x6ea9c6, x - 0.54, 1.42, z - 0.08);
box(0.1, 0.1, 0.58, 0xf3bd52, x + 0.45, 1.43, z - 0.12);
}
makeDesk(2.0, -1.55, 12);
makeDesk(5.5, -1.55, 14, true);
makeDesk(9.0, -1.55, 16);
const desksSign = labelSprite("TODAY'S SEATS", {
bg: "#f8f2e7",
fg: "#38545b",
scale: [2.6, 0.56]
});
desksSign.position.set(5.5, 4.76, -6.58);
scene.add(desksSign);
// Water fountain and a blocky plant.
box(0.82, 1.25, 0.68, 0x7eb6c1, -10.45, 0.67, 3.25);
box(0.9, 0.14, 0.72, 0xd7eef0, -10.45, 1.35, 3.25);
box(0.16, 0.25, 0.16, 0x38545b, -10.45, 1.5, 3.05);
box(0.82, 0.72, 0.82, 0xd88964, 10.25, 0.4, 4.9);
box(0.18, 1.25, 0.18, 0x806657, 10.25, 1.18, 4.9);
box(0.9, 0.58, 0.55, 0x68ae78, 10.25, 1.8, 4.9);
box(0.58, 0.55, 0.9, 0x79bf86, 10.25, 2.1, 4.9);
box(0.75, 0.38, 0.68, 0x5b9e6f, 10.25, 2.48, 4.9);
// Voxel people.
function makePerson({
skin = 0xd89b73,
hair = 0x253f49,
shirt = 0xf3bd52,
pants = 0x36596a,
backpack = false
} = {}) {
const root = new THREE.Group();
const torso = box(0.72, 0.82, 0.44, shirt, 0, 1.25, 0, root);
box(0.64, 0.62, 0.61, skin, 0, 1.96, 0.015, root);
box(0.69, 0.18, 0.66, hair, 0, 2.28, -0.015, root);
box(0.69, 0.35, 0.18, hair, 0, 2.04, -0.24, root);
box(0.085, 0.085, 0.035, 0x26383c, -0.14, 2.01, 0.326, root);
box(0.085, 0.085, 0.035, 0x26383c, 0.14, 2.01, 0.326, root);
box(0.11, 0.045, 0.035, 0xb16f59, 0, 1.86, 0.327, root);
const leftLeg = new THREE.Group();
const rightLeg = new THREE.Group();
leftLeg.position.set(-0.2, 0.86, 0);
rightLeg.position.set(0.2, 0.86, 0);
root.add(leftLeg, rightLeg);
box(0.25, 0.7, 0.27, pants, 0, -0.36, 0, leftLeg);
box(0.25, 0.7, 0.27, pants, 0, -0.36, 0, rightLeg);
box(0.29, 0.18, 0.43, 0x26383c, 0, -0.69, 0.07, leftLeg);
box(0.29, 0.18, 0.43, 0x26383c, 0, -0.69, 0.07, rightLeg);
const leftArm = new THREE.Group();
const rightArm = new THREE.Group();
leftArm.position.set(-0.49, 1.58, 0);
rightArm.position.set(0.49, 1.58, 0);
root.add(leftArm, rightArm);
box(0.22, 0.67, 0.25, shirt, 0, -0.34, 0, leftArm);
box(0.22, 0.67, 0.25, shirt, 0, -0.34, 0, rightArm);
box(0.22, 0.2, 0.24, skin, 0, -0.72, 0, leftArm);
box(0.22, 0.2, 0.24, skin, 0, -0.72, 0, rightArm);
if (backpack) {
box(0.65, 0.76, 0.28, 0x58c7b1, 0, 1.32, -0.36, root);
box(0.48, 0.28, 0.08, 0xf3bd52, 0, 1.39, -0.54, root);
box(0.09, 0.7, 0.07, 0x327d75, -0.22, 1.45, 0.25, root);
box(0.09, 0.7, 0.07, 0x327d75, 0.22, 1.45, 0.25, root);
const badgeTexture = textTexture("07", {
width: 128,
height: 128,
bg: "#fff3d4",
fg: "#38545b",
fontSize: 72,
radius: 18,
padding: 8
});
const badge = new THREE.Mesh(
new THREE.PlaneGeometry(0.3, 0.3),
new THREE.MeshBasicMaterial({
map: badgeTexture,
transparent: true,
toneMapped: false
})
);
badge.position.set(0.13, 1.31, 0.226);
root.add(badge);
}
return { root, torso, leftLeg, rightLeg, leftArm, rightArm };
}
const teacher = makePerson({
skin: 0x9f664d,
hair: 0x51343a,
shirt: 0xf48370,
pants: 0x3d5364
});
teacher.root.position.set(-6.5, 0.07, 0.12);
teacher.root.rotation.y = 0;
scene.add(teacher.root);
const student = makePerson({
skin: 0xe1aa7e,
hair: 0x263b45,
shirt: 0xf3bd52,
pants: 0x385f73,
backpack: true
});
student.root.position.set(-9, 0.07, 7.05);
scene.add(student.root);
// Landmark beacons.
function makeLandmark(text, color, x, z) {
const group = new THREE.Group();
group.position.set(x, 0.09, z);
const ringMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.48,
roughness: 0.55,
transparent: true,
opacity: 0
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.63, 0.055, 8, 40),
ringMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.08;
group.add(ring);
const beamMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
const beam = new THREE.Mesh(
new THREE.CylinderGeometry(0.5, 0.5, 3.1, 8, 1, true),
beamMaterial
);
beam.position.y = 1.55;
group.add(beam);
const cubeMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.35,
transparent: true,
opacity: 0
});
const cube = box(0.26, 0.26, 0.26, cubeMaterial, 0, 3.18, 0, group);
const label = labelSprite(text, {
bg: `#${new THREE.Color(color).getHexString()}`,
fg: "#ffffff",
scale: [3.05, 0.66],
depthTest: false,
fontSize: 56
});
label.position.set(0, 3.62, 0);
group.add(label);
group.visible = false;
scene.add(group);
return {
group,
ring,
beam,
cube,
label,
materials: [ringMaterial, beamMaterial, cubeMaterial, label.material],
labelBaseY: label.position.y
};
}
const landmarks = {
entry: makeLandmark("ENTRY", 0x58c7b1, -9, 6.45),
teacher: makeLandmark("TEACHER · WELCOME", 0xf48370, -6.5, 2.55),
cubby: makeLandmark("CUBBY 07", 0xf3bd52, -4, -4.2),
desk: makeLandmark("DESK 14", 0x58c7b1, 5.5, -0.1)
};
// Speech bubbles.
const teacherBubble = labelSprite("Welcome, Maya!", {
bg: "#f48370",
fg: "#ffffff",
scale: [3.25, 0.78],
depthTest: false,
fontSize: 58
});
teacherBubble.position.set(-6.3, 3.35, 0.18);
teacherBubble.visible = false;
scene.add(teacherBubble);
const finalBubble = labelSprite("You’re ready — seat 14!", {
bg: "#58c7b1",
fg: "#ffffff",
scale: [3.6, 0.82],
depthTest: false,
fontSize: 56
});
finalBubble.position.set(5.5, 3.45, -0.05);
finalBubble.visible = false;
scene.add(finalBubble);
// Routes: every route starts only after its destination beacon is visible.
const routes = [
{
start: 1.0,
end: 3.8,
points: [[-9, 7.05], [-9, 6.3], [-8.8, 5.25], [-8.4, 4.6]],
color: 0x58c7b1
},
{
start: 4.8,
end: 7.2,
points: [[-8.4, 4.6], [-7.8, 4.1], [-7.0, 3.6], [-6.5, 2.6]],
color: 0xf48370
},
{
start: 10.0,
end: 12.7,
points: [[-6.5, 2.6], [-6.0, 1.5], [-5.2, -0.5], [-4.6, -2.7], [-4.0, -4.2]],
color: 0xf3bd52
},
{
start: 14.5,
end: 17.2,
points: [[-4.0, -4.2], [-2.8, -3.0], [-1.0, -1.6], [1.0, -0.8], [4.8, 0.8], [5.5, 0.35], [5.5, -0.1]],
color: 0x58c7b1
}
];
function pathMetrics(points) {
const segments = [];
let total = 0;
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const dx = b[0] - a[0];
const dz = b[1] - a[1];
const length = Math.hypot(dx, dz);
segments.push({ a, b, dx, dz, length, start: total });
total += length;
}
return { segments, total };
}
function samplePath(points, u, metrics = pathMetrics(points)) {
const distance = THREE.MathUtils.clamp(u, 0, 1) * metrics.total;
let segment = metrics.segments[metrics.segments.length - 1];
for (const candidate of metrics.segments) {
if (distance <= candidate.start + candidate.length) {
segment = candidate;
break;
}
}
const local = segment.length === 0 ? 0 : (distance - segment.start) / segment.length;
return {
x: THREE.MathUtils.lerp(segment.a[0], segment.b[0], local),
z: THREE.MathUtils.lerp(segment.a[1], segment.b[1], local),
angle: Math.atan2(segment.dx, segment.dz)
};
}
const routeDots = [];
routes.forEach((route, routeIndex) => {
const metrics = pathMetrics(route.points);
const count = Math.max(5, Math.ceil(metrics.total / 0.72));
for (let i = 0; i <= count; i++) {
const u = i / count;
const p = samplePath(route.points, u, metrics);
const dot = box(
0.15,
0.055,
0.15,
route.color,
p.x,
0.105,
p.z
);
dot.rotation.y = Math.PI / 4;
dot.visible = false;
routeDots.push({
dot,
born: route.start + u * (route.end - route.start),
routeIndex
});
}
});
// Small deterministic success confetti.
const confetti = [];
const confettiColors = [0xf48370, 0xf3bd52, 0x58c7b1, 0x6ea9c6, 0xffffff];
for (let i = 0; i < 28; i++) {
const angle = (i / 28) * Math.PI * 2;
const radius = 0.6 + (i % 5) * 0.16;
const piece = box(
0.12 + (i % 3) * 0.025,
0.18,
0.08,
confettiColors[i % confettiColors.length],
5.5 + Math.cos(angle) * radius,
2.8 + (i % 6) * 0.18,
-0.1 + Math.sin(angle) * radius
);
piece.visible = false;
confetti.push({
piece,
offset: new THREE.Vector3(Math.cos(angle) * radius, (i % 6) * 0.18, Math.sin(angle) * radius),
phase: i * 0.71
});
}
// Camera controls implemented directly without addons.
const orbit = {
targetYaw: 0.58,
targetPitch: 0.56,
targetRadius: 29.5,
yaw: 0.58,
pitch: 0.56,
radius: 29.5,
dragging: false,
lastX: 0,
lastY: 0
};
function resetCamera() {
orbit.targetYaw = 0.58;
orbit.targetPitch = 0.56;
orbit.targetRadius = 29.5;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
orbit.dragging = true;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!orbit.dragging) return;
const dx = event.clientX - orbit.lastX;
const dy = event.clientY - orbit.lastY;
orbit.lastX = event.clientX;
orbit.lastY = event.clientY;
orbit.targetYaw -= dx * 0.005;
orbit.targetPitch = THREE.MathUtils.clamp(orbit.targetPitch + dy * 0.004, 0.28, 1.05);
});
function endDrag(event) {
orbit.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius * Math.exp(event.deltaY * 0.001),
18,
40
);
},
{ passive: false }
);
document.querySelector("#camera-reset").addEventListener("click", resetCamera);
let elapsed = 0;
document.querySelector("#replay").addEventListener("click", () => {
elapsed = 0;
});
const phaseData = [
{
end: 4,
step: "01 / ARRIVAL",
mode: "Look",
title: "Start with a visible landmark",
copy: "The entry beacon appears first. Its floor dots will guide the student into the classroom."
},
{
end: 9.2,
step: "02 / TEACHER CHECK-IN",
mode: "Follow",
title: "See the teacher, then follow",
copy: "The teacher’s coral beacon is revealed before the student follows the route to a welcoming check-in."
},
{
end: 13.7,
step: "03 / MATCHING CUBBY",
mode: "Follow",
title: "Your number reveals the cubby",
copy: "Cubby 07 lights up first. The student follows the gold dots to the one place that matches the badge."
},
{
end: 17.2,
step: "04 / REACHING YOUR DESK",
mode: "Follow",
title: "The last beacon points home",
copy: "Desk 14 becomes visible before the route appears, giving the student one clear final destination."
},
{
end: Infinity,
step: "05 / ORIENTATION COMPLETE",
mode: "Arrive",
title: "Welcome to Room 204",
copy: "Teacher, cubby 07, and desk 14 are now connected in one clear, repeatable arrival journey."
}
];
let currentPhase = -1;
function updatePhaseUI(time) {
let index = phaseData.findIndex((phase) => time < phase.end);
if (index < 0) index = phaseData.length - 1;
if (index !== currentPhase) {
currentPhase = index;
const phase = phaseData[index];
stepEl.textContent = phase.step;
modeEl.textContent = phase.mode;
titleEl.textContent = phase.title;
copyEl.textContent = phase.copy;
}
progressEl.style.width = `${Math.min(time / 17.2, 1) * 100}%`;
}
function updateLandmark(marker, reveal, end, time) {
if (time < reveal) {
marker.group.visible = false;
return;
}
const fadeIn = Math.min(1, (time - reveal) / 0.32);
const fadeOut = time > end ? Math.max(0, 1 - (time - end) / 0.45) : 1;
const opacity = fadeIn * fadeOut;
marker.group.visible = opacity > 0.001;
marker.group.scale.setScalar(Math.max(0.001, opacity));
marker.ring.material.opacity = 0.95 * opacity;
marker.beam.material.opacity = 0.085 * opacity;
marker.cube.material.opacity = 0.95 * opacity;
marker.label.material.opacity = opacity;
const pulse = 1 + Math.sin(time * 4.2) * 0.075;
marker.ring.scale.set(pulse, pulse, pulse);
marker.cube.rotation.y = time * 1.4;
marker.cube.position.y = 3.18 + Math.sin(time * 3.1) * 0.1;
marker.label.position.y = marker.labelBaseY + Math.sin(time * 2.5) * 0.075;
}
function lerpAngle(a, b, t) {
const delta = Math.atan2(Math.sin(b - a), Math.cos(b - a));
return a + delta * t;
}
function animatePerson(person, time, moving, wave = false) {
const stride = Math.sin(time * 10.5);
const amount = moving ? 1 : 0;
person.leftLeg.rotation.x = stride * 0.58 * amount;
person.rightLeg.rotation.x = -stride * 0.58 * amount;
person.leftArm.rotation.x = -stride * 0.44 * amount;
person.rightArm.rotation.x = stride * 0.44 * amount;
person.leftArm.rotation.z = THREE.MathUtils.lerp(person.leftArm.rotation.z, 0, 0.2);
person.rightArm.rotation.z = THREE.MathUtils.lerp(person.rightArm.rotation.z, 0, 0.2);
person.torso.position.y = 1.25 + Math.sin(time * 2.2) * 0.018;
if (wave) {
person.rightArm.rotation.z = 2.25 + Math.sin(time * 8) * 0.14;
person.rightArm.rotation.x = -0.18;
}
}
const cameraKeys = [
{ t: 0, p: new THREE.Vector3(-3.8, 0.4, 3.2) },
{ t: 4, p: new THREE.Vector3(-6.4, 0.5, 1.6) },
{ t: 9.2, p: new THREE.Vector3(-4.0, 0.4, -3.6) },
{ t: 13.7, p: new THREE.Vector3(5.2, 0.4, -1.2) },
{ t: 17.2, p: new THREE.Vector3(4.6, 0.6, -0.8) },
{ t: 22, p: new THREE.Vector3(3.7, 0.8, -0.4) }
];
const focusGoal = new THREE.Vector3(-2, 0.5, 1);
const currentFocus = new THREE.Vector3(-2, 0.5, 1);
function updateCameraFocus(time) {
for (let i = 0; i < cameraKeys.length - 1; i++) {
const a = cameraKeys[i];
const b = cameraKeys[i + 1];
if (time >= a.t && time <= b.t) {
let u = (time - a.t) / (b.t - a.t);
u = u * u * (3 - 2 * u);
focusGoal.lerpVectors(a.p, b.p, u);
return;
}
}
focusGoal.copy(cameraKeys[cameraKeys.length - 1].p);
}
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
elapsed += dt;
updatePhaseUI(elapsed);
// Each beacon appears before its corresponding movement segment begins.
updateLandmark(landmarks.entry, 0, 4.0, elapsed);
updateLandmark(landmarks.teacher, 4.0, 9.2, elapsed);
updateLandmark(landmarks.cubby, 9.2, 13.7, elapsed);
updateLandmark(landmarks.desk, 13.7, 18.0, elapsed);
// Teacher and student greeting.
const teacherWave = elapsed >= 4.7 && elapsed < 9.15;
const studentWave = (elapsed >= 7.15 && elapsed < 8.9) || elapsed >= 17.25;
teacherBubble.visible = elapsed >= 7.05 && elapsed < 9.15;
if (teacherBubble.visible) {
const inAmount = Math.min(1, (elapsed - 7.05) / 0.3);
const outAmount = elapsed > 8.85 ? Math.max(0, 1 - (elapsed - 8.85) / 0.3) : 1;
teacherBubble.material.opacity = inAmount * outAmount;
teacherBubble.scale.set(3.25 * inAmount * outAmount, 0.78 * inAmount * outAmount, 1);
teacherBubble.position.y = 3.35 + Math.sin(elapsed * 3) * 0.06;
}
finalBubble.visible = elapsed >= 17.25;
if (finalBubble.visible) {
const amount = Math.min(1, (elapsed - 17.25) / 0.45);
finalBubble.material.opacity = amount;
finalBubble.scale.set(3.6 * amount, 0.82 * amount, 1);
finalBubble.position.y = 3.45 + Math.sin(elapsed * 3) * 0.07;
}
// Route dots appear progressively after their landmark is visible.
routeDots.forEach(({ dot, born }) => {
const appear = Math.min(1, Math.max(0, (elapsed - born) / 0.18));
dot.visible = appear > 0;
dot.scale.setScalar(appear);
});
// Student route and orientation.
let studentX = routes[0].points[0][0];
let studentZ = routes[0].points[0][1];
let targetAngle = Math.PI;
let moving = false;
for (const route of routes) {
if (elapsed < route.start) break;
const u = THREE.MathUtils.clamp((elapsed - route.start) / (route.end - route.start), 0, 1);
const p = samplePath(route.points, u);
studentX = p.x;
studentZ = p.z;
targetAngle = p.angle;
moving = elapsed < route.end;
if (u >= 1 && routeIndexIsTeacher(route)) targetAngle = Math.PI;
if (u >= 1 && routeIndexIsCubby(route)) targetAngle = Math.PI;
if (u >= 1 && routeIndexIsDesk(route)) targetAngle = Math.PI;
}
function routeIndexIsTeacher(route) { return route === routes[1]; }
function routeIndexIsCubby(route) { return route === routes[2]; }
function routeIndexIsDesk(route) { return route === routes[3]; }
const angleBlend = 1 - Math.exp(-dt * 9);
student.root.rotation.y = lerpAngle(student.root.rotation.y, targetAngle, angleBlend);
student.root.position.x = studentX;
student.root.position.z = studentZ;
student.root.position.y = 0.07 + (moving ? Math.abs(Math.sin(elapsed * 10.5)) * 0.055 : 0);
animatePerson(student, elapsed, moving, studentWave);
animatePerson(teacher, elapsed, false, teacherWave);
// Success confetti.
confetti.forEach(({ piece, offset, phase }) => {
const age = elapsed - 17.25;
piece.visible = age >= 0 && age < 4.2;
if (piece.visible) {
piece.position.set(
5.5 + offset.x + Math.sin(age * 3 + phase) * 0.22,
2.9 + offset.y + age * 0.25 - age * age * 0.13,
-0.1 + offset.z + Math.cos(age * 2.6 + phase) * 0.18
);
piece.rotation.x = age * 4 + phase;
piece.rotation.y = age * 3.2 + phase;
piece.rotation.z = age * 2.4;
}
});
// Smooth scripted focus plus direct user orbit/zoom controls.
updateCameraFocus(elapsed);
currentFocus.lerp(focusGoal, 1 - Math.exp(-dt * 1.65));
orbit.yaw = lerpAngle(orbit.yaw, orbit.targetYaw, 1 - Math.exp(-dt * 9));
orbit.pitch = THREE.MathUtils.lerp(orbit.pitch, orbit.targetPitch, 1 - Math.exp(-dt * 9));
orbit.radius = THREE.MathUtils.lerp(orbit.radius, orbit.targetRadius, 1 - Math.exp(-dt * 8));
const horizontal = Math.cos(orbit.pitch) * orbit.radius;
camera.position.set(
currentFocus.x + Math.sin(orbit.yaw) * horizontal,
currentFocus.y + Math.sin(orbit.pitch) * orbit.radius,
currentFocus.z + Math.cos(orbit.yaw) * horizontal
);
camera.lookAt(currentFocus);
renderer.render(scene, camera);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
requestAnimationFrame(() => {
loading.classList.add("hidden");
});
</script>
</body>
</html>
```