Prompt specification
Build or customize the Three.js 3D scene "First-day classroom welcome" 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: First-day classroom welcome
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/first-day-classroom-welcome-x3863
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: first-day classroom welcome. Compose school entrance, corridor, classroom, and coat area in a compact cutaway; several students find their places while teachers guide through clear shared paths. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (first-day-classroom-welcome-x3863):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>First Day, First Hello — Classroom Cutaway</title>
<style>
:root {
--ink: #233746;
--muted: #657783;
--paper: rgba(255, 252, 245, 0.92);
--teal: #238f8a;
--amber: #e49a3b;
--coral: #df7258;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4d8;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.header {
position: fixed;
top: 24px;
left: 28px;
z-index: 5;
max-width: min(460px, calc(100vw - 56px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 7px 11px;
border-radius: 999px;
background: var(--paper);
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: .14em;
text-transform: uppercase;
box-shadow: 0 8px 24px rgba(35, 55, 70, .09);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 4px rgba(223, 114, 88, .13);
}
h1 {
margin: 0;
font-size: clamp(29px, 4vw, 52px);
line-height: .98;
letter-spacing: -.045em;
font-weight: 850;
text-wrap: balance;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
font-weight: 600;
}
.controls {
position: fixed;
top: 24px;
right: 24px;
z-index: 8;
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(35, 55, 70, .12);
backdrop-filter: blur(12px);
}
.controls button {
min-height: 38px;
padding: 0 13px;
border: 0;
border-radius: 11px;
background: transparent;
color: var(--ink);
font: inherit;
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition: background .2s ease, transform .2s ease;
}
.controls button:hover {
background: #edf0e9;
transform: translateY(-1px);
}
.controls button.primary {
background: var(--ink);
color: white;
}
.legend {
position: fixed;
left: 28px;
bottom: 24px;
z-index: 6;
display: flex;
flex-wrap: wrap;
gap: 8px 18px;
max-width: calc(100vw - 56px);
padding: 12px 15px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 16px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(35, 55, 70, .1);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
color: #53636f;
font-size: 11px;
font-weight: 750;
white-space: nowrap;
}
.swatch {
width: 18px;
height: 6px;
border-radius: 99px;
background: var(--teal);
}
.swatch.amber { background: var(--amber); }
.swatch.coral { background: var(--coral); }
.hint {
position: fixed;
right: 25px;
bottom: 25px;
z-index: 5;
color: rgba(35, 55, 70, .6);
font-size: 11px;
font-weight: 650;
pointer-events: none;
}
.room-label {
position: fixed;
z-index: 4;
padding: 7px 11px;
border: 1px solid rgba(255,255,255,.86);
border-radius: 11px;
background: rgba(255, 252, 245, .88);
box-shadow: 0 8px 22px rgba(35, 55, 70, .11);
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: .1em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(8px);
}
.room-label::after {
content: "";
position: absolute;
left: 50%;
bottom: -5px;
width: 8px;
height: 8px;
border-right: 1px solid rgba(255,255,255,.86);
border-bottom: 1px solid rgba(255,255,255,.86);
background: rgba(255, 252, 245, .88);
transform: translateX(-50%) rotate(45deg);
}
.room-label.teal { border-bottom: 3px solid var(--teal); }
.room-label.amber { border-bottom: 3px solid var(--amber); }
.room-label.coral { border-bottom: 3px solid var(--coral); }
.loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #e9e4d8;
color: var(--ink);
transition: opacity .6s ease, visibility .6s ease;
}
.loading.hidden {
opacity: 0;
visibility: hidden;
}
.loading-card {
text-align: center;
font-size: 13px;
font-weight: 750;
letter-spacing: .04em;
}
.loading-card span {
display: block;
width: 42px;
height: 5px;
margin: 13px auto 0;
overflow: hidden;
border-radius: 9px;
background: rgba(35,55,70,.12);
}
.loading-card span::after {
content: "";
display: block;
width: 55%;
height: 100%;
border-radius: inherit;
background: var(--teal);
animation: load 1s ease-in-out infinite alternate;
}
@keyframes load { to { transform: translateX(82%); } }
@media (max-width: 700px) {
.header { top: 18px; left: 18px; }
.subtitle { display: none; }
.controls { top: 16px; right: 16px; }
.controls button { padding: 0 10px; }
.legend { left: 16px; bottom: 16px; gap: 7px 12px; }
.hint { display: none; }
.room-label { font-size: 8px; padding: 5px 8px; }
}
</style>
</head>
<body>
<div class="loading" id="loading">
<div class="loading-card">
Preparing the first day…
<span></span>
</div>
</div>
<header class="header">
<div class="eyebrow">Day 1 · 08:30</div>
<h1>First Day,<br />First Hello.</h1>
<p class="subtitle">A compact cutaway of welcome, discovery, and shared paths.</p>
</header>
<div class="controls" aria-label="Scene controls">
<button class="primary" id="pause">Pause</button>
<button id="reset">Reset view</button>
</div>
<div class="legend">
<div class="legend-item"><span class="swatch"></span>To Room 2B</div>
<div class="legend-item"><span class="swatch amber"></span>To Coat Check</div>
<div class="legend-item"><span class="swatch coral"></span>Teacher guidance</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="room-label teal" id="label-class">Room 2B</div>
<div class="room-label amber" id="label-coat">Coat Area</div>
<div class="room-label coral" id="label-entrance">School Entrance</div>
<div class="room-label teal" id="label-corridor">Shared Corridor</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4d8);
scene.fog = new THREE.Fog(0xe9e4d8, 32, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
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.16;
renderer.domElement.setAttribute("aria-label", "Interactive stylized school cutaway");
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 8, -8, 0.1, 100);
const controls = {
target: new THREE.Vector3(0, 0.35, 0.1),
theta: 0.67,
phi: 0.78,
zoom: 1,
dragging: false,
lastX: 0,
lastY: 0
};
const clock = new THREE.Clock();
let paused = false;
let elapsed = 0;
const palette = {
ink: 0x233746,
cream: 0xf7efe1,
base: 0xbcae97,
baseEdge: 0x9e927f,
lobby: 0xf0cda8,
corridor: 0xefdda8,
classroom: 0xe8dfcc,
coat: 0xd6e5db,
teal: 0x238f8a,
amber: 0xe49a3b,
coral: 0xdf7258,
purple: 0x7c6aa6,
blue: 0x4e7894,
wood: 0xb9794f,
paleWood: 0xd7a66e,
darkWood: 0x79503e,
green: 0x679c72,
board: 0x315f59
};
const material = (color, roughness = 0.82, extra = {}) =>
new THREE.MeshStandardMaterial({ color, roughness, ...extra });
const M = {
base: material(palette.base),
baseEdge: material(palette.baseEdge),
lobby: material(palette.lobby),
corridor: material(palette.corridor),
classroom: material(palette.classroom),
coat: material(palette.coat),
cream: material(palette.cream),
teal: material(palette.teal),
amber: material(palette.amber),
coral: material(palette.coral),
purple: material(palette.purple),
blue: material(palette.blue),
wood: material(palette.wood),
paleWood: material(palette.paleWood),
darkWood: material(palette.darkWood),
green: material(palette.green),
dark: material(0x35444d),
black: material(0x28343a),
white: material(0xfffdf7),
board: material(palette.board),
glass: material(0x8ec7c5, 0.2, { transparent: true, opacity: 0.28 })
};
function addMesh(geometry, mat, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(geometry, mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function box(w, h, d, x, y, z, mat, parent = scene) {
return addMesh(new THREE.BoxGeometry(w, h, d), mat, x, y, z, parent);
}
function cylinder(rt, rb, h, x, y, z, mat, parent = scene, segments = 16) {
return addMesh(new THREE.CylinderGeometry(rt, rb, h, segments), mat, x, y, z, parent);
}
function sphere(r, x, y, z, mat, parent = scene, segments = 16) {
return addMesh(new THREE.SphereGeometry(r, segments, Math.max(8, segments / 2)), mat, x, y, z, parent);
}
function groupAt(x = 0, y = 0, z = 0, parent = scene) {
const g = new THREE.Group();
g.position.set(x, y, z);
parent.add(g);
return g;
}
function panelTexture(title, subtitle = "", bg = "#315f59", fg = "#fff9e9", accent = "#e49a3b") {
const canvas = document.createElement("canvas");
canvas.width = 768;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = bg;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = accent;
ctx.fillRect(0, 0, 18, canvas.height);
ctx.fillRect(42, 218, 180, 8);
ctx.textAlign = "center";
ctx.fillStyle = fg;
ctx.font = "800 58px system-ui, sans-serif";
ctx.fillText(title, canvas.width / 2 + 8, subtitle ? 112 : 142);
if (subtitle) {
ctx.globalAlpha = 0.82;
ctx.font = "600 27px system-ui, sans-serif";
ctx.fillText(subtitle, canvas.width / 2 + 8, 174);
ctx.globalAlpha = 1;
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function signPanel(title, subtitle, w, h, x, y, z, bg, fg, accent, parent = scene) {
const texture = panelTexture(title, subtitle, bg, fg, accent);
const panel = addMesh(
new THREE.PlaneGeometry(w, h),
new THREE.MeshBasicMaterial({ map: texture, side: THREE.DoubleSide }),
x, y, z, parent
);
panel.castShadow = false;
panel.receiveShadow = false;
return panel;
}
function makeArrowGeometry() {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute([
-0.22, 0, -0.28,
0.22, 0, -0.28,
0.00, 0, 0.34
], 3));
geometry.setIndex([0, 1, 2]);
geometry.computeVertexNormals();
return geometry;
}
const arrowGeometry = makeArrowGeometry();
function floorArrow(x, z, yaw, mat = M.white) {
const arrow = addMesh(arrowGeometry, mat, x, 0.072, z);
arrow.rotation.y = yaw;
arrow.castShadow = false;
arrow.receiveShadow = false;
}
function pathStrip(w, d, x, z, mat) {
const strip = box(w, 0.025, d, x, 0.045, z, mat);
strip.castShadow = false;
return strip;
}
// Lighting
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x78808a, 2.15));
const sun = new THREE.DirectionalLight(0xfff2d6, 3.4);
sun.position.set(9, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad8e4, 1.15);
fill.position.set(-10, 8, -7);
scene.add(fill);
// Presentation base
box(17.7, 0.52, 10.65, 0, -0.43, 0, M.baseEdge);
box(17.4, 0.18, 10.35, 0, -0.12, 0, M.base);
const ground = addMesh(
new THREE.PlaneGeometry(200, 200),
material(0xe9e4d8),
0, -0.71, 0
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
// Room floors
box(3.05, 0.15, 2.35, -1.5, -0.015, 4.35, M.lobby);
box(3.05, 0.15, 7.35, -1.5, -0.015, 0.25, M.corridor);
box(7.55, 0.15, 7.55, 3.85, -0.015, 0, M.classroom);
box(4.75, 0.15, 4.05, -5.4, -0.015, -2.1, M.coat);
// Floor tile seams
for (let z = -3.2; z < 4.3; z += 1.05) {
box(2.9, 0.008, 0.018, -1.5, 0.066, z, M.paleWood).castShadow = false;
}
for (let x = 1.2; x < 7.5; x += 1.25) {
box(0.018, 0.008, 7.35, x, 0.066, 0, M.paleWood).castShadow = false;
}
// Classroom walls: tall on the far sides, low cutaway edges near the viewer.
box(7.75, 2.55, 0.16, 3.85, 1.275, -3.86, M.cream);
box(0.16, 2.55, 3.88, 0.03, 1.275, -1.92, M.cream);
box(0.16, 2.55, 2.57, 0.03, 1.275, 2.58, M.cream);
box(0.16, 0.38, 7.75, 7.68, 0.19, 0, M.cream);
box(7.75, 0.38, 0.16, 3.85, 0.19, 3.86, M.cream);
// Doorway trim
box(0.2, 2.38, 0.2, 0.03, 1.19, 0.08, M.darkWood);
box(0.2, 2.38, 0.2, 0.03, 1.19, 1.27, M.darkWood);
box(0.22, 0.18, 1.42, 0.03, 2.34, 0.67, M.darkWood);
// Coat room walls
box(4.95, 2.25, 0.15, -5.4, 1.125, -4.13, M.cream);
box(0.15, 2.25, 4.2, -7.85, 1.125, -2.1, M.cream);
box(0.15, 0.38, 4.2, -3.0, 0.19, -2.1, M.cream);
box(4.95, 0.38, 0.15, -5.4, 0.19, -0.08, M.cream);
// Entrance frame and welcome canopy
box(0.18, 2.55, 0.22, -2.83, 1.275, 5.16, M.darkWood);
box(0.18, 2.55, 0.22, -0.17, 1.275, 5.16, M.darkWood);
box(2.85, 0.22, 0.22, -1.5, 2.5, 5.16, M.darkWood);
for (let i = 0; i < 6; i++) {
const awningMat = i % 2 === 0 ? M.coral : M.cream;
const strip = box(0.49, 0.09, 1.1, -2.68 + i * 0.49, 2.68, 5.05, awningMat);
strip.rotation.x = -0.12;
}
signPanel("WELCOME!", "LET'S FIND OUR PLACES", 2.45, 0.72, -1.5, 2.47, 5.29, "#315f59", "#fff9e9", "#df7258");
box(1.72, 0.035, 0.72, -1.5, 0.075, 4.54, M.teal).castShadow = false;
// Open entrance doors
const doorLeft = groupAt(-2.73, 0, 5.14);
const doorRight = groupAt(-0.27, 0, 5.14);
const glassLeft = box(0.92, 1.88, 0.055, 0.43, 1.02, 0, M.glass, doorLeft);
const glassRight = box(0.92, 1.88, 0.055, -0.43, 1.02, 0, M.glass, doorRight);
doorLeft.rotation.y = -0.72;
doorRight.rotation.y = 0.72;
// Hallway and classroom guidance signs
signPanel("ROOM 2B", "FOLLOW THE TEAL PATH", 1.15, 0.4, 0.72, 1.47, 0.92, "#238f8a", "#ffffff", "#f7efe1");
box(0.055, 1.05, 0.055, 0.72, 0.52, 0.92, M.dark);
signPanel("COAT CHECK", "← FOLLOW THE AMBER PATH", 1.15, 0.4, -3.0, 1.47, -2.1, "#e49a3b", "#233746", "#ffffff");
box(0.055, 1.05, 0.055, -3.0, 0.52, -2.1, M.dark);
// Shared route strips
pathStrip(0.42, 3.56, -1.12, 2.77, M.teal);
pathStrip(2.82, 0.42, 0.29, 1.0, M.teal);
pathStrip(0.42, 6.2, -1.88, 1.24, M.amber);
pathStrip(3.0, 0.42, -3.38, -2.1, M.amber);
// Direction arrows
floorArrow(-1.12, 3.6, Math.PI);
floorArrow(-1.12, 2.15, Math.PI);
floorArrow(0.2, 1.0, Math.PI / 2);
floorArrow(-1.88, 3.5, Math.PI);
floorArrow(-1.88, 1.8, Math.PI);
floorArrow(-1.88, -0.4, Math.PI);
floorArrow(-2.8, -2.1, -Math.PI / 2);
floorArrow(-4.2, -2.1, -Math.PI / 2);
// Small route dots make the shared circulation legible.
for (let z = -1.85; z < 3.85; z += 0.62) {
cylinder(0.038, 0.038, 0.012, -1.12, 0.07, z, M.white, scene, 10).castShadow = false;
cylinder(0.038, 0.038, 0.012, -1.88, 0.07, z, M.white, scene, 10).castShadow = false;
}
// Classroom board
box(3.7, 1.65, 0.12, 3.45, 1.47, -3.73, M.wood);
signPanel("HELLO, ROOM 2B!", "TODAY: FIND YOUR FRIENDS & YOUR SEAT", 3.5, 1.45, 3.45, 1.47, -3.655, "#315f59", "#fff9e9", "#e49a3b");
// Classroom clock
const clockRim = addMesh(new THREE.TorusGeometry(0.31, 0.055, 10, 32), M.darkWood, 6.75, 1.88, -3.71);
clockRim.rotation.x = 0;
const clockFace = cylinder(0.28, 0.28, 0.055, 6.75, 1.88, -3.67, M.white);
clockFace.rotation.x = Math.PI / 2;
box(0.035, 0.2, 0.025, 6.75, 1.93, -3.625, M.dark);
box(0.15, 0.03, 0.025, 6.80, 1.88, -3.625, M.dark);
// Reading rug
const rug = cylinder(1.25, 1.25, 0.025, 3.75, 0.035, 2.8, M.teal, scene, 48);
rug.scale.z = 0.62;
rug.castShadow = false;
// Desks and chairs
function makeDesk(x, z, topMat) {
box(1.38, 0.12, 0.62, x, 0.72, z, topMat);
box(0.085, 0.66, 0.085, x - 0.52, 0.34, z - 0.2, M.darkWood);
box(0.085, 0.66, 0.085, x + 0.52, 0.34, z - 0.2, M.darkWood);
box(0.085, 0.66, 0.085, x - 0.52, 0.34, z + 0.2, M.darkWood);
box(0.085, 0.66, 0.085, x + 0.52, 0.34, z + 0.2, M.darkWood);
box(0.58, 0.035, 0.4, x - 0.22, 0.802, z + 0.01, M.white);
box(0.44, 0.055, 0.28, x + 0.3, 0.81, z - 0.03, M.paleWood);
}
function makeChair(x, z) {
box(0.58, 0.09, 0.54, x, 0.42, z, M.blue);
box(0.58, 0.56, 0.08, x, 0.68, z + 0.24, M.blue);
box(0.07, 0.4, 0.07, x - 0.21, 0.2, z - 0.18, M.dark);
box(0.07, 0.4, 0.07, x + 0.21, 0.2, z - 0.18, M.dark);
}
const deskXs = [1.55, 3.72, 5.88];
const deskZs = [-1.82, 0.08, 2.0];
const deskColors = [M.paleWood, M.cream, M.paleWood];
deskZs.forEach((z, row) => {
deskXs.forEach((x, col) => {
makeDesk(x, z, deskColors[(row + col) % deskColors.length]);
makeChair(x, z + 0.66);
});
});
// Small classroom storage
box(1.1, 1.15, 0.42, 6.92, 0.575, -2.85, M.wood);
for (let row = 0; row < 2; row++) {
for (let col = 0; col < 3; col++) {
box(0.25, 0.3, 0.025, 6.53 + col * 0.31, 0.34 + row * 0.48, -2.625, [M.coral, M.teal, M.amber][col]);
}
}
// Teacher desk
box(1.7, 0.14, 0.72, 6.23, 0.82, -2.65, M.wood);
box(0.1, 0.75, 0.1, 5.55, 0.4, -2.9, M.darkWood);
box(0.1, 0.75, 0.1, 6.9, 0.4, -2.9, M.darkWood);
box(0.45, 0.06, 0.32, 6.25, 0.92, -2.63, M.white);
cylinder(0.11, 0.13, 0.25, 6.75, 1.0, -2.65, M.coral);
// Coat hooks and hanging bags
box(3.55, 0.12, 0.12, -5.4, 1.55, -3.96, M.darkWood);
box(0.12, 1.55, 0.12, -7.15, 0.78, -3.96, M.darkWood);
box(0.12, 1.55, 0.12, -3.65, 0.78, -3.96, M.darkWood);
for (let i = 0; i < 6; i++) {
const x = -6.82 + i * 0.57;
const hook = cylinder(0.035, 0.035, 0.22, x, 1.43, -3.87, M.dark);
hook.rotation.x = Math.PI / 2;
if (i !== 2 && i !== 4) {
const bagMat = [M.purple, M.coral, M.blue, M.teal][i % 4];
box(0.39, 0.55, 0.2, x, 1.05, -3.72, bagMat);
box(0.23, 0.12, 0.07, x, 1.37, -3.66, bagMat);
}
}
// Bench in coat area
box(2.9, 0.13, 0.58, -5.35, 0.46, -0.72, M.wood);
box(0.12, 0.43, 0.12, -6.55, 0.22, -0.72, M.darkWood);
box(0.12, 0.43, 0.12, -4.15, 0.22, -0.72, M.darkWood);
// Entrance side table and bell
box(0.85, 0.12, 0.5, -0.32, 0.63, 4.35, M.wood);
box(0.1, 0.6, 0.1, -0.32, 0.3, 4.35, M.darkWood);
cylinder(0.13, 0.16, 0.12, -0.32, 0.76, 4.35, M.amber);
sphere(0.045, -0.32, 0.85, 4.35, M.darkWood);
// Planters and small trees
function planter(x, z) {
cylinder(0.45, 0.34, 0.45, x, 0.12, z, M.coral, scene, 12);
cylinder(0.1, 0.12, 1.05, x, 0.76, z, M.darkWood);
sphere(0.48, x, 1.35, z, M.green, scene, 12).scale.set(1, 0.92, 1);
sphere(0.35, x - 0.28, 1.12, z + 0.1, M.green, scene, 12);
sphere(0.32, x + 0.28, 1.18, z - 0.05, M.green, scene, 12);
}
planter(5.7, 4.67);
planter(-7.0, 4.65);
// Character construction
function makePerson({
shirt = M.teal,
pants = M.blue,
skin = 0xdca27d,
hair = 0x47332a,
scale = 0.86,
backpack = false,
teacher = false
} = {}) {
const g = new THREE.Group();
const skinMat = material(skin);
const hairMat = material(hair);
const shirtMat = teacher ? material(0x6b78a7) : shirt;
const pantsMat = teacher ? material(0x354b5c) : pants;
const body = addMesh(new THREE.CapsuleGeometry(0.22, 0.48, 5, 10), shirtMat, 0, 0.98, 0, g);
body.scale.z = 0.84;
const head = sphere(0.245, 0, 1.49, 0, skinMat, g);
const hairCap = addMesh(
new THREE.SphereGeometry(0.255, 14, 8, 0, Math.PI * 2, 0, Math.PI / 2),
hairMat, 0, 1.51, -0.015, g
);
hairCap.scale.z = 0.95;
sphere(0.045, 0, 1.47, 0.245, skinMat, g, 10);
sphere(0.022, -0.075, 1.54, 0.224, M.black, g, 8);
sphere(0.022, 0.075, 1.54, 0.224, M.black, g, 8);
const leftLeg = groupAt(-0.115, 0.68, 0, g);
const rightLeg = groupAt(0.115, 0.68, 0, g);
cylinder(0.075, 0.085, 0.52, 0, -0.25, 0, pantsMat, leftLeg, 10);
cylinder(0.075, 0.085, 0.52, 0, -0.25, 0, pantsMat, rightLeg, 10);
box(0.16, 0.1, 0.26, 0, -0.54, 0.055, M.dark, leftLeg);
box(0.16, 0.1, 0.26, 0, -0.54, 0.055, M.dark, rightLeg);
const leftArm = groupAt(-0.29, 1.16, 0, g);
const rightArm = groupAt(0.29, 1.16, 0, g);
cylinder(0.055, 0.07, 0.48, 0, -0.23, 0, shirtMat, leftArm, 10);
cylinder(0.055, 0.07, 0.48, 0, -0.23, 0, shirtMat, rightArm, 10);
sphere(0.075, 0, -0.49, 0, skinMat, leftArm, 10);
sphere(0.075, 0, -0.49, 0, skinMat, rightArm, 10);
let bag = null;
if (backpack) {
bag = box(0.38, 0.46, 0.2, 0, 1.0, -0.265, M.coral, g);
box(0.24, 0.12, 0.08, 0, 1.16, -0.385, M.coral, g);
}
if (teacher) {
box(0.045, 0.47, 0.025, -0.08, 1.03, 0.205, M.amber, g);
box(0.045, 0.47, 0.025, 0.08, 1.03, 0.205, M.amber, g);
box(0.12, 0.09, 0.035, 0, 0.82, 0.215, M.white, g);
}
g.scale.setScalar(scale);
g.userData = { leftLeg, rightLeg, leftArm, rightArm, backpack: bag, phase: Math.random() * 6 };
return g;
}
function makeSeatedStudent(shirt, skin, hair, scale = 0.78) {
const g = new THREE.Group();
const shirtMat = material(shirt);
const skinMat = material(skin);
const hairMat = material(hair);
const body = addMesh(new THREE.CapsuleGeometry(0.19, 0.37, 4, 9), shirtMat, 0, 0.82, 0, g);
body.scale.z = 0.85;
sphere(0.225, 0, 1.27, 0, skinMat, g);
addMesh(
new THREE.SphereGeometry(0.235, 12, 7, 0, Math.PI * 2, 0, Math.PI / 2),
hairMat, 0, 1.29, -0.01, g
);
sphere(0.04, 0, 1.25, 0.22, skinMat, g, 10);
box(0.14, 0.14, 0.46, -0.105, 0.42, 0.12, M.blue, g);
box(0.14, 0.14, 0.46, 0.105, 0.42, 0.12, M.blue, g);
box(0.14, 0.1, 0.22, -0.105, 0.37, 0.4, M.dark, g);
box(0.14, 0.1, 0.22, 0.105, 0.37, 0.4, M.dark, g);
g.scale.setScalar(scale);
return g;
}
// Seated students already settling in
const seatedA = makeSeatedStudent(0xdf7258, 0x8b583e, 0x2f2927);
seatedA.position.set(3.72, 0, 0.74);
seatedA.rotation.y = Math.PI;
scene.add(seatedA);
const seatedB = makeSeatedStudent(0x7c6aa6, 0xe5b38c, 0x6a4931);
seatedB.position.set(5.88, 0, -1.16);
seatedB.rotation.y = Math.PI;
scene.add(seatedB);
const seatedC = makeSeatedStudent(0x4e7894, 0xc9815d, 0x392b28);
seatedC.position.set(3.72, 0, -1.16);
seatedC.rotation.y = Math.PI;
scene.add(seatedC);
// The student arriving at the front-left desk.
const arrivingSeated = makeSeatedStudent(0x238f8a, 0xe2aa83, 0x4d3329);
arrivingSeated.position.set(1.55, 0, 0.74);
arrivingSeated.rotation.y = Math.PI;
arrivingSeated.visible = false;
scene.add(arrivingSeated);
// Teacher at the front of the classroom
const classTeacher = makePerson({
shirt: M.purple,
pants: M.blue,
skin: 0xc88965,
hair: 0x302c2b,
scale: 1.04,
teacher: true
});
classTeacher.position.set(6.23, 0, -3.18);
classTeacher.rotation.y = 0;
classTeacher.userData.rightArm.rotation.z = -0.75;
classTeacher.userData.rightArm.rotation.x = -0.55;
scene.add(classTeacher);
// Teacher at the coat-area junction
const coatGuide = makePerson({
shirt: M.amber,
pants: M.blue,
skin: 0xe0aa80,
hair: 0x664637,
scale: 1.02,
teacher: true
});
coatGuide.position.set(-2.5, 0, -1.65);
coatGuide.rotation.y = -Math.PI / 2;
coatGuide.userData.rightArm.rotation.z = -0.7;
coatGuide.userData.rightArm.rotation.x = -0.5;
const coatGuideSign = signPanel("← COATS", "", 0.82, 0.36, 0.46, 0.83, 0.22, "#e49a3b", "#233746", "#ffffff", coatGuide);
scene.add(coatGuide);
// A bag appears on the hook when the student reaches the coat area.
const hungStudentBag = box(0.42, 0.52, 0.21, -5.91, 1.04, -3.69, M.coral);
hungStudentBag.visible = false;
// Walking route system
function createWalker(route, options = {}) {
const person = makePerson(options);
const points = route.map(([x, z]) => ({ x, z }));
let length = 0;
for (let i = 0; i < points.length - 1; i++) {
length += Math.hypot(points[i + 1].x - points[i].x, points[i + 1].z - points[i].z);
}
person.userData.route = {
points,
length,
progress: options.progress ?? 0,
speed: options.speed ?? 0.72,
direction: 1,
oneShot: options.oneShot ?? false,
pingPong: options.pingPong ?? false,
arrived: false
};
scene.add(person);
return person;
}
function sampleRoute(routeData, distance) {
let remaining = distance;
for (let i = 0; i < routeData.points.length - 1; i++) {
const a = routeData.points[i];
const b = routeData.points[i + 1];
const segment = Math.hypot(b.x - a.x, b.z - a.z);
if (remaining <= segment || i === routeData.points.length - 2) {
const t = segment === 0 ? 0 : Math.min(1, Math.max(0, remaining / segment));
return {
x: THREE.MathUtils.lerp(a.x, b.x, t),
z: THREE.MathUtils.lerp(a.z, b.z, t),
dx: b.x - a.x,
dz: b.z - a.z
};
}
remaining -= segment;
}
}
const classStudent = createWalker([
[-1.12, 4.5],
[-1.12, 1.0],
[1.55, 1.0],
[1.55, 0.74]
], {
shirt: M.teal,
pants: M.purple,
skin: 0xe2aa83,
hair: 0x4d3329,
backpack: true,
scale: 0.82,
speed: 0.65,
progress: 0.11,
oneShot: true
});
const coatStudent = createWalker([
[-1.88, 4.48],
[-1.88, -2.1],
[-5.91, -2.1],
[-5.91, -2.7]
], {
shirt: M.coral,
pants: M.blue,
skin: 0x9a6043,
hair: 0x2f2927,
backpack: true,
scale: 0.79,
speed: 0.58,
progress: 0.06,
oneShot: true
});
const hallStudent = createWalker([
[-2.55, 4.45],
[-2.55, 2.15],
[-1.12, 1.0],
[3.72, 1.0]
], {
shirt: M.purple,
pants: M.teal,
skin: 0xf0c39d,
hair: 0x8c5a37,
backpack: true,
scale: 0.75,
speed: 0.54,
progress: 0.22,
oneShot: true
});
const guideTeacher = createWalker([
[-0.35, 4.45],
[-0.88, 3.2],
[-0.88, 1.05],
[0.8, 1.05],
[2.3, 1.05]
], {
shirt: M.purple,
pants: M.blue,
skin: 0xdca27d,
hair: 0x3a302c,
scale: 1.03,
teacher: true,
speed: 0.48,
progress: 0.38,
pingPong: true
});
guideTeacher.userData.rightArm.rotation.z = -0.58;
guideTeacher.userData.rightArm.rotation.x = -0.55;
const guideSign = signPanel("2B →", "", 0.72, 0.34, -0.45, 0.88, 0.23, "#238f8a", "#ffffff", "#f7efe1", guideTeacher);
guideSign.rotation.y = Math.PI;
function updateWalker(person, dt) {
const data = person.userData.route;
if (!data) return;
if (data.oneShot && data.arrived) return;
if (data.oneShot) {
data.progress = Math.min(1, data.progress + data.speed * dt / data.length);
} else {
data.progress += data.direction * data.speed * dt / data.length;
if (data.progress >= 1) {
if (data.pingPong) {
data.progress = 1;
data.direction = -1;
} else {
data.progress = 1;
}
} else if (data.progress <= 0 && data.pingPong) {
data.progress = 0;
data.direction = 1;
}
}
const sample = sampleRoute(data, data.progress * data.length);
person.position.x = sample.x;
person.position.z = sample.z;
person.rotation.y = Math.atan2(sample.dx, sample.dz);
const moving = !data.oneShot || data.progress < 0.995;
const phase = elapsed * (data.oneShot ? 8 : 7) + person.userData.phase;
const swing = moving ? Math.sin(phase) * 0.45 : 0;
person.userData.leftLeg.rotation.x = swing;
person.userData.rightLeg.rotation.x = -swing;
person.userData.leftArm.rotation.x = -swing * 0.75;
person.userData.rightArm.rotation.x = swing * 0.75;
person.position.y = moving ? 0.035 + Math.abs(Math.sin(phase)) * 0.025 : 0.035;
if (data.oneShot && data.progress >= 1 && !data.arrived) {
data.arrived = true;
if (person === classStudent) {
person.visible = false;
arrivingSeated.visible = true;
}
if (person === coatStudent) {
person.userData.backpack.visible = false;
hungStudentBag.visible = true;
person.rotation.y = Math.PI;
person.userData.rightArm.rotation.x = -0.75;
}
if (person === hallStudent) {
person.visible = false;
}
}
}
const walkers = [classStudent, coatStudent, hallStudent, guideTeacher];
// Camera controls implemented directly without external examples.
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + 28 * sinPhi * Math.sin(controls.theta),
controls.target.y + 28 * Math.cos(controls.phi),
controls.target.z + 28 * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
const viewHeight = Math.max(12.8, 19.5 / aspect);
camera.left = -viewHeight * aspect / 2 / controls.zoom;
camera.right = viewHeight * aspect / 2 / controls.zoom;
camera.top = viewHeight / 2 / controls.zoom;
camera.bottom = -viewHeight / 2 / controls.zoom;
camera.updateProjectionMatrix();
updateCamera();
}
function resetCamera() {
controls.theta = 0.67;
controls.phi = 0.78;
controls.zoom = 1;
resize();
}
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(controls.phi - dy * 0.005, 0.42, 1.18);
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture?.(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(controls.zoom * Math.exp(-event.deltaY * 0.001), 0.67, 1.8);
resize();
}, { passive: false });
canvas.addEventListener("dblclick", resetCamera);
document.getElementById("reset").addEventListener("click", resetCamera);
document.getElementById("pause").addEventListener("click", (event) => {
paused = !paused;
event.currentTarget.textContent = paused ? "Play" : "Pause";
});
window.addEventListener("resize", resize);
// Floating room labels remain attached to the cutaway while orbiting.
const labels = [
{ element: document.getElementById("label-class"), point: new THREE.Vector3(4.0, 2.35, -0.2) },
{ element: document.getElementById("label-coat"), point: new THREE.Vector3(-5.45, 1.75, -2.1) },
{ element: document.getElementById("label-entrance"), point: new THREE.Vector3(-1.5, 2.95, 4.65) },
{ element: document.getElementById("label-corridor"), point: new THREE.Vector3(-1.45, 0.95, 0.05) }
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labels.forEach(({ element, point }) => {
const projected = point.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1 &&
projected.x > -1.05 && projected.x < 1.05 &&
projected.y > -1.05 && projected.y < 1.05;
element.style.display = visible ? "block" : "none";
element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
});
}
resize();
updateCamera();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed += dt;
walkers.forEach(walker => updateWalker(walker, dt));
}
// A subtle, welcoming wave from the classroom teacher.
classTeacher.userData.rightArm.rotation.x = -0.55 + Math.sin(elapsed * 2.1) * 0.16;
coatGuide.userData.rightArm.rotation.x = -0.5 + Math.sin(elapsed * 1.7 + 1) * 0.1;
renderer.render(scene, camera);
updateLabels();
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("hidden");
}
}
animate();
</script>
</body>
</html>
```