Prompt specification
Build or customize the Three.js 3D scene "Mosaic classroom floor model" 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: Mosaic classroom floor model
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mosaic-classroom-floor-model-x0363
Scene Description Prompt:
Stylized students extend a geometric tile border around classroom activity zones, maintaining corner spacing. Three.js from cdnjs, one HTML file.
Working Three.js Starter (mosaic-classroom-floor-model-x0363):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tile by Tile — Classroom Activity Zones</title>
<style>
:root {
--ink: #243247;
--muted: #64748b;
--paper: rgba(255, 255, 255, 0.84);
--line: rgba(255, 255, 255, 0.65);
--accent: #ff7867;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 28px;
left: 30px;
width: min(430px, calc(100vw - 60px));
padding: 20px 22px 19px;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--paper);
box-shadow: 0 18px 50px rgba(38, 50, 72, 0.12);
backdrop-filter: blur(14px);
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: #e76555;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(255, 120, 103, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 43px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.title-card p {
max-width: 360px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: absolute;
top: 30px;
right: 30px;
display: flex;
flex-direction: column;
gap: 10px;
width: 205px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 38px rgba(38, 50, 72, 0.1);
backdrop-filter: blur(14px);
}
.legend-row {
display: flex;
align-items: center;
gap: 10px;
color: #526075;
font-size: 11px;
font-weight: 700;
line-height: 1.3;
}
.swatch {
width: 18px;
height: 18px;
flex: 0 0 auto;
border-radius: 5px;
background: #4fb6ac;
box-shadow: inset 0 0 0 2px rgba(255,255,255,.55);
}
.swatch.gap {
position: relative;
border: 1px dashed #f0a643;
background: rgba(255,255,255,.5);
}
.swatch.gap::after {
position: absolute;
inset: 5px;
border-radius: 2px;
background: #f0a643;
content: "";
}
.bottom-bar {
position: absolute;
right: 30px;
bottom: 28px;
left: 30px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
}
.progress-card {
width: min(330px, calc(100vw - 60px));
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 14px 38px rgba(38, 50, 72, 0.1);
backdrop-filter: blur(14px);
}
.progress-head {
display: flex;
justify-content: space-between;
margin-bottom: 9px;
color: #526075;
font-size: 11px;
font-weight: 800;
letter-spacing: .04em;
text-transform: uppercase;
}
.track {
height: 7px;
overflow: hidden;
border-radius: 99px;
background: #e6e9ed;
}
#progress-fill {
width: 42%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #4fb6ac, #65c9b4, #f0a643);
transition: width .2s linear;
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
min-height: 42px;
padding: 0 15px;
border: 1px solid rgba(255,255,255,.72);
border-radius: 13px;
color: var(--ink);
background: rgba(255,255,255,.88);
box-shadow: 0 10px 28px rgba(38,50,72,.1);
font: inherit;
font-size: 12px;
font-weight: 800;
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform .15s ease, background .15s ease;
}
button:hover {
transform: translateY(-2px);
background: #fff;
}
.hint {
position: absolute;
right: 31px;
bottom: 88px;
color: rgba(36,50,71,.56);
font-size: 10px;
font-weight: 750;
letter-spacing: .04em;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
background: #eee9df;
color: #45556b;
font-size: 13px;
font-weight: 800;
letter-spacing: .08em;
text-transform: uppercase;
transition: opacity .4s ease, visibility .4s ease;
}
#loading.hide {
visibility: hidden;
opacity: 0;
}
@media (max-width: 720px) {
.title-card {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px 18px;
}
.title-card p { display: none; }
.legend {
top: auto;
right: 14px;
bottom: 96px;
width: 175px;
}
.bottom-bar {
right: 14px;
bottom: 14px;
left: 14px;
}
.progress-card {
width: min(260px, calc(100vw - 160px));
}
.controls { gap: 5px; }
button { padding: 0 11px; }
.hint { display: none; }
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<section class="title-card">
<div class="eyebrow">Live classroom project</div>
<h1>Tile by tile.</h1>
<p>
Students are extending colorful geometric borders around their activity
zones, keeping an equal-sized opening at every corner.
</p>
</section>
<aside class="legend" aria-label="Scene legend">
<div class="legend-row">
<span class="swatch"></span>
<span>Shared geometric tile border</span>
</div>
<div class="legend-row">
<span class="swatch gap"></span>
<span>Equal corner spacing</span>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<div class="bottom-bar">
<div class="progress-card">
<div class="progress-head">
<span>Border installation</span>
<span id="progress-value">42%</span>
</div>
<div class="track"><div id="progress-fill"></div></div>
</div>
<div class="controls">
<button id="pause" type="button">Pause</button>
<button id="reset" type="button">Reset view</button>
</div>
</div>
</div>
<div id="loading">Preparing the classroom…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const pauseButton = document.querySelector("#pause");
const resetButton = document.querySelector("#reset");
const progressFill = document.querySelector("#progress-fill");
const progressValue = document.querySelector("#progress-value");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 24, 43);
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.06;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional classroom with students placing tiles around activity zones"
);
sceneHost.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 6, -6, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.55, 0);
const view = { theta: 0.72, phi: 0.86, zoom: 1 };
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const visibleHeight = Math.max(11.8, 20.2 / aspect);
camera.left = -visibleHeight * aspect / 2;
camera.right = visibleHeight * aspect / 2;
camera.top = visibleHeight / 2;
camera.bottom = -visibleHeight / 2;
camera.zoom = view.zoom;
const radius = 20;
const sinPhi = Math.sin(view.phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(view.theta),
cameraTarget.y + radius * Math.cos(view.phi),
cameraTarget.z + radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
}
function resetView() {
view.theta = 0.72;
view.phi = 0.86;
view.zoom = 1;
updateCamera();
}
window.addEventListener("resize", updateCamera);
updateCamera();
// Direct camera controls, without importing any external addon.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(view.phi + dy * 0.004, 0.43, 1.25);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("dblclick", resetView);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.zoom = THREE.MathUtils.clamp(view.zoom - event.deltaY * 0.001, 0.68, 1.5);
updateCamera();
},
{ passive: false }
);
resetButton.addEventListener("click", resetView);
const hemi = new THREE.HemisphereLight(0xfff8eb, 0x9bb1c4, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4dc, 3.35);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbdd9ff, 0.85);
fill.position.set(8, 6, -5);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0,
flatShading: options.flatShading ?? false,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
side: options.side ?? THREE.FrontSide
});
}
const mats = {
floor: material(0xf8f4ea),
floorEdge: material(0xd8d0c2),
wall: material(0xe8eef0),
wallTrim: material(0xc9d6d8),
wood: material(0xc99468),
woodLight: material(0xe2b98a),
dark: material(0x344457),
chair: material(0x6ba9b4),
metal: material(0x738291),
white: material(0xfffdf8),
navy: material(0x34445c),
cream: material(0xfff8e9),
coral: material(0xf27f6d),
teal: material(0x51b7aa),
yellow: material(0xf2bd55),
blue: material(0x5f9fd2),
purple: material(0xa68ac8),
orange: material(0xee9b50)
};
function box(parent, w, h, d, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(w, h, d), mat);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinder(parent, rTop, rBottom, h, mat, x = 0, y = 0, z = 0, segments = 24) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(rTop, rBottom, h, segments),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function sphere(parent, radius, mat, x = 0, y = 0, z = 0, segments = 16) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, segments, Math.max(10, segments / 2)),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function textPlane(text, width, height, color = "#304156") {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = color;
ctx.font = "800 72px Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, 512, 134);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
}
// Classroom shell.
const room = new THREE.Group();
scene.add(room);
box(room, 16.7, 0.38, 12.7, mats.floorEdge, 0, -0.22, 0);
box(room, 16.45, 0.08, 12.45, mats.floor, 0, -0.015, 0);
box(room, 16.55, 5.15, 0.22, mats.wall, 0, 2.5, -6.28);
box(room, 16.6, 0.16, 0.3, mats.wallTrim, 0, 0.06, -6.1);
const gridVertices = [];
for (let x = -8; x <= 8; x += 1) {
gridVertices.push(x, 0.031, -6.1, x, 0.031, 6.1);
}
for (let z = -6; z <= 6; z += 1) {
gridVertices.push(-8.1, 0.031, z, 8.1, 0.031, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute("position", new THREE.Float32BufferAttribute(gridVertices, 3));
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({ color: 0x9ba6ad, transparent: true, opacity: 0.12 })
);
room.add(grid);
// Whiteboard and geometric lesson pieces.
const boardGroup = new THREE.Group();
boardGroup.position.set(0.1, 2.65, -6.09);
room.add(boardGroup);
box(boardGroup, 6.45, 2.28, 0.12, mats.metal);
box(boardGroup, 6.22, 2.05, 0.07, mats.white, 0, 0, 0.08);
const boardTitle = textPlane("GEOMETRIC GARDEN", 3.8, 0.62, "#304156");
boardTitle.position.set(0, 0.59, 0.125);
boardGroup.add(boardTitle);
const boardShapes = new THREE.Group();
boardShapes.position.z = 0.14;
boardGroup.add(boardShapes);
const boardCircle = new THREE.Mesh(new THREE.CircleGeometry(0.22, 24), mats.coral);
boardCircle.position.set(-2.1, -0.28, 0);
boardShapes.add(boardCircle);
const triangleShape = new THREE.Shape();
triangleShape.moveTo(0, 0.26);
triangleShape.lineTo(-0.25, -0.19);
triangleShape.lineTo(0.25, -0.19);
triangleShape.closePath();
const triangle = new THREE.Mesh(new THREE.ShapeGeometry(triangleShape), mats.yellow);
triangle.position.set(-1.28, -0.25, 0);
boardShapes.add(triangle);
box(boardShapes, 0.38, 0.38, 0.025, mats.teal, -0.38, -0.28, 0);
box(boardShapes, 0.38, 0.38, 0.025, mats.blue, 0.38, -0.28, 0);
for (let i = 0; i < 4; i++) {
box(boardShapes, 0.13, 0.13, 0.025, [mats.coral, mats.teal, mats.yellow, mats.purple][i],
1.18 + i * 0.28, -0.29, 0);
}
// Window.
const windowGroup = new THREE.Group();
windowGroup.position.set(6.0, 3.0, -6.1);
room.add(windowGroup);
box(windowGroup, 2.5, 1.72, 0.1, mats.white);
box(windowGroup, 2.23, 1.45, 0.07, material(0x91c8dc), 0, 0, 0.07);
box(windowGroup, 0.08, 1.47, 0.09, mats.white, 0, 0, 0.11);
box(windowGroup, 2.25, 0.08, 0.09, mats.white, 0, 0, 0.11);
box(windowGroup, 2.75, 0.13, 0.32, mats.woodLight, 0, -0.89, 0.13);
// Wall clock.
const clock = cylinder(room, 0.38, 0.38, 0.09, mats.white, 4.05, 3.78, -6.05, 32);
clock.rotation.x = Math.PI / 2;
box(room, 0.055, 0.27, 0.05, mats.dark, 4.05, 3.86, -5.98);
box(room, 0.23, 0.055, 0.05, mats.dark, 4.12, 3.77, -5.97);
// Bookshelf.
const shelf = new THREE.Group();
shelf.position.set(-6.85, 0, -5.7);
room.add(shelf);
box(shelf, 2.25, 2.8, 0.58, mats.wood);
box(shelf, 1.95, 0.14, 0.15, mats.woodLight, 0, -1.1, 0.31);
box(shelf, 1.95, 0.14, 0.15, mats.woodLight, 0, -0.22, 0.31);
box(shelf, 1.95, 0.14, 0.15, mats.woodLight, 0, 0.66, 0.31);
const bookColors = [mats.coral, mats.teal, mats.yellow, mats.blue, mats.purple, mats.orange];
for (let row = 0; row < 3; row++) {
for (let i = 0; i < 6; i++) {
const book = box(
shelf,
0.18 + (i % 2) * 0.035,
0.48 + (i % 3) * 0.06,
0.34,
bookColors[(row * 2 + i) % bookColors.length],
-0.76 + i * 0.29,
-0.83 + row * 0.88,
0.36
);
book.rotation.z = (i % 2 ? 1 : -1) * 0.035;
}
}
// Classroom desks and chairs.
function createDesk(x, z, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.rotation.y = rotation;
room.add(group);
box(group, 1.35, 0.13, 0.87, mats.woodLight, 0, 1.1, 0);
box(group, 1.08, 0.11, 0.62, mats.cream, 0, 1.18, 0.03);
for (const lx of [-0.52, 0.52]) {
for (const lz of [-0.28, 0.28]) {
box(group, 0.07, 1.02, 0.07, mats.metal, lx, 0.52, lz);
}
}
box(group, 0.7, 0.12, 0.68, mats.chair, 0, 0.58, -0.78);
box(group, 0.7, 0.72, 0.1, mats.chair, 0, 0.98, -1.05);
for (const lx of [-0.25, 0.25]) {
for (const lz of [-1.0, -0.56]) {
box(group, 0.055, 0.55, 0.055, mats.metal, lx, 0.28, lz);
}
}
box(group, 0.42, 0.045, 0.31, mats.blue, -0.28, 1.26, 0.05).rotation.y = -0.12;
box(group, 0.31, 0.045, 0.26, mats.yellow, 0.3, 1.26, 0.08).rotation.y = 0.16;
return group;
}
createDesk(-5.6, -3.7, 0);
createDesk(-3.65, -3.85, 0.04);
createDesk(-1.7, -3.75, -0.04);
createDesk(5.45, -3.65, 0.02);
createDesk(7.0, -0.85, Math.PI / 2);
// Activity zones.
const leftRug = cylinder(room, 1, 1, 0.055, material(0xf3c2b5), -3.65, 0.04, 0.9, 64);
leftRug.scale.set(2.55, 1, 1.58);
box(room, 4.78, 0.055, 3.38, material(0xc8e2d8), 3.65, 0.035, 0.9);
const readLabel = textPlane("READ • REFLECT", 2.45, 0.44, "#8f554f");
readLabel.rotation.x = -Math.PI / 2;
readLabel.position.set(-3.65, 0.075, 2.06);
room.add(readLabel);
const makeLabel = textPlane("MAKE • TEST", 2.25, 0.43, "#39756d");
makeLabel.rotation.x = -Math.PI / 2;
makeLabel.position.set(3.65, 0.072, 2.12);
room.add(makeLabel);
// Reading-zone cushions and books.
const cushionGeometry = new THREE.CylinderGeometry(0.42, 0.42, 0.18, 24);
const cushion1 = new THREE.Mesh(cushionGeometry, mats.yellow);
cushion1.position.set(-4.7, 0.17, 0.95);
cushion1.scale.z = 0.8;
cushion1.castShadow = true;
room.add(cushion1);
const cushion2 = new THREE.Mesh(cushionGeometry, mats.blue);
cushion2.position.set(-2.65, 0.17, 1.15);
cushion2.scale.z = 0.8;
cushion2.castShadow = true;
room.add(cushion2);
const openBook = new THREE.Group();
openBook.position.set(-3.65, 0.16, 0.95);
openBook.rotation.y = -0.18;
room.add(openBook);
box(openBook, 0.56, 0.055, 0.42, mats.cream);
box(openBook, 0.018, 0.06, 0.42, mats.wood, 0, 0.01, 0);
// Low maker table and blocks.
const makerTable = new THREE.Group();
makerTable.position.set(3.65, 0, 0.95);
room.add(makerTable);
box(makerTable, 1.55, 0.12, 0.92, mats.woodLight, 0, 0.72, 0);
for (const x of [-0.62, 0.62]) {
for (const z of [-0.32, 0.32]) {
box(makerTable, 0.08, 0.68, 0.08, mats.wood, x, 0.35, z);
}
}
box(makerTable, 0.42, 0.42, 0.42, mats.coral, -0.3, 1.0, -0.05).rotation.y = 0.15;
box(makerTable, 0.31, 0.31, 0.31, mats.teal, 0.18, 0.94, 0.12).rotation.y = -0.22;
const triangleBlock = new THREE.Mesh(
new THREE.CylinderGeometry(0.26, 0.26, 0.32, 3),
mats.yellow
);
triangleBlock.position.set(0.34, 0.97, -0.19);
triangleBlock.rotation.y = 0.2;
triangleBlock.castShadow = true;
makerTable.add(triangleBlock);
const TILE_SIZE = 0.34;
// A small supply stack near the reading border.
for (let i = 0; i < 5; i++) {
const tile = makeTile(bookColors[i % bookColors.length]);
tile.position.set(-7.1 + (i % 2) * 0.09, i * 0.085, 2.6);
tile.rotation.y = (i % 3) * 0.13;
room.add(tile);
}
// Plant.
const plant = new THREE.Group();
plant.position.set(7.25, 0, -5.35);
room.add(plant);
cylinder(plant, 0.37, 0.28, 0.55, mats.coral, 0, 0.28, 0);
cylinder(plant, 0.06, 0.08, 1.65, material(0x567d58), 0, 1.15, 0, 12);
const leafMaterial = material(0x70a873);
for (let i = 0; i < 7; i++) {
const leaf = sphere(plant, 0.42, leafMaterial,
Math.sin(i * 2.4) * 0.42,
1.25 + (i % 3) * 0.34,
Math.cos(i * 2.4) * 0.38,
14
);
leaf.scale.set(0.45, 1.35, 0.24);
leaf.rotation.z = Math.sin(i * 2.1) * 0.75;
leaf.rotation.x = Math.cos(i * 1.7) * 0.55;
}
// Geometric border construction.
const TILE_SEAM = 0.08;
const CORNER_GAP = 0.58;
const tilePalette = [0x4fb6ac, 0xf07d6d, 0xf1bd55, 0x639fd0, 0xa68bc7, 0xed9c50];
function makeTile(color) {
const group = new THREE.Group();
const baseMaterial = material(color, { roughness: 0.68 });
const base = box(group, TILE_SIZE, 0.075, TILE_SIZE, baseMaterial, 0, 0.046, 0);
const accent = box(
group,
0.135,
0.012,
0.135,
material(0xfff7e7, { roughness: 0.55 }),
0,
0.091,
0
);
accent.rotation.y = Math.PI / 4;
accent.castShadow = false;
group.userData.baseMaterial = baseMaterial;
return group;
}
function sidePositions(length) {
const usable = length - CORNER_GAP * 2;
const count = Math.max(1, Math.floor(usable / (TILE_SIZE + TILE_SEAM)) + 1);
const result = [];
for (let i = 0; i < count; i++) {
result.push(-length / 2 + CORNER_GAP + i * (TILE_SIZE + TILE_SEAM));
}
return result;
}
function createBorder(cx, cz, innerWidth, innerDepth) {
const borderWidth = innerWidth + 0.86;
const borderDepth = innerDepth + 0.86;
const group = new THREE.Group();
scene.add(group);
const sequence = [];
const xPositions = sidePositions(borderWidth);
const zPositions = sidePositions(borderDepth);
let colorIndex = 0;
function addTile(x, z, normalX, normalZ, tangentX, tangentZ) {
const color = tilePalette[colorIndex % tilePalette.length];
colorIndex++;
const tile = makeTile(color);
tile.position.set(x, 0, z);
group.add(tile);
sequence.push({
tile,
position: new THREE.Vector3(x, 0, z),
normal: new THREE.Vector3(normalX, 0, normalZ),
tangent: new THREE.Vector3(tangentX, 0, tangentZ),
color
});
}
xPositions.forEach((x) => addTile(cx + x, cz - borderDepth / 2, 0, -1, 1, 0));
zPositions.forEach((z) => addTile(cx + borderWidth / 2, cz + z, 1, 0, 0, 1));
[...xPositions].reverse().forEach((x) => addTile(cx + x, cz + borderDepth / 2, 0, 1, -1, 0));
[...zPositions].reverse().forEach((z) => addTile(cx - borderWidth / 2, cz + z, -1, 0, 0, -1));
return { group, sequence };
}
const leftBorder = createBorder(-3.65, 0.9, 5.1, 3.1);
const activeBorder = createBorder(3.65, 0.9, 4.78, 3.38);
// The reading border is already complete.
leftBorder.sequence.forEach(({ tile }) => tile.scale.setScalar(1));
// The maker border is partially complete and then grows as students place tiles.
const initialTileCount = 16;
activeBorder.sequence.forEach(({ tile }, index) => {
tile.scale.setScalar(index < initialTileCount ? 1 : 0.001);
});
// Low-poly students.
const skinMaterials = [
material(0xf2c7a5),
material(0xd99b73),
material(0x9f6549),
material(0x754936),
material(0xe5b18e),
material(0xc88965)
];
const hairMaterials = [
material(0x2f2830),
material(0x56392c),
material(0x8b5839),
material(0x252b35),
material(0xc28b4d),
material(0x40302c)
];
function createStudent(shirtColor, skinColor, hairColor, options = {}) {
const root = new THREE.Group();
scene.add(root);
const shirt = material(shirtColor, { roughness: 0.82 });
const skin = material(skinColor, { roughness: 0.88 });
const hair = material(hairColor, { roughness: 0.94 });
const trousers = material(0x3b4b63, { roughness: 0.9 });
const upper = new THREE.Group();
upper.position.y = 0.67;
root.add(upper);
const torso = sphere(upper, 0.43, shirt, 0, 0.4, 0, 16);
torso.scale.set(0.9, 1.05, 0.7);
cylinder(upper, 0.11, 0.12, 0.16, skin, 0, 0.79, 0, 12);
const head = sphere(upper, 0.3, skin, 0, 1.04, 0, 20);
head.scale.y = 1.08;
const hairCap = new THREE.Mesh(
new THREE.SphereGeometry(0.315, 18, 10, 0, Math.PI * 2, 0, Math.PI / 2),
hair
);
hairCap.position.set(0, 1.075, -0.012);
hairCap.scale.set(1.02, 0.58, 1.02);
hairCap.castShadow = true;
upper.add(hairCap);
const eyeMaterial = material(0x29313c);
sphere(upper, 0.025, eyeMaterial, -0.105, 1.065, 0.276, 10);
sphere(upper, 0.025, eyeMaterial, 0.105, 1.065, 0.276, 10);
box(upper, 0.065, 0.012, 0.014, eyeMaterial, 0, 0.945, 0.286);
function createArm(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.38, 0.62, 0);
upper.add(pivot);
cylinder(pivot, 0.07, 0.085, 0.52, shirt, 0, -0.25, 0, 12);
sphere(pivot, 0.085, skin, 0, -0.56, 0, 12);
return pivot;
}
const leftArm = createArm(-1);
const rightArm = createArm(1);
function createLeg(side) {
const pivot = new THREE.Group();
pivot.position.set(side * 0.18, 0.64, 0);
root.add(pivot);
cylinder(pivot, 0.09, 0.105, 0.55, trousers, 0, -0.27, 0, 12);
const shoe = box(pivot, 0.2, 0.13, 0.34, mats.dark, 0, -0.57, 0.08);
shoe.castShadow = true;
return pivot;
}
const leftLeg = createLeg(-1);
const rightLeg = createLeg(1);
if (options.backpack) {
const backpack = box(upper, 0.48, 0.58, 0.24, options.backpack, 0, 0.43, -0.35);
backpack.rotation.x = -0.05;
}
root.userData = {
upper,
leftArm,
rightArm,
leftLeg,
rightLeg,
phase: options.phase ?? 0
};
return root;
}
// Students already working in the activity areas.
const staticStudents = [];
const reader = createStudent(0x9b83c5, 0xf1c19d, 0x4b3028, {
backpack: 0xe58a65,
phase: 0.4
});
reader.position.set(-4.0, 0.05, 0.95);
reader.rotation.y = -0.65;
const readerBook = box(reader, 0.38, 0.055, 0.32, mats.blue, -0.28, 1.1, 0.3);
readerBook.rotation.z = 0.12;
staticStudents.push(reader);
const maker = createStudent(0xef9861, 0x9f6549, 0x292830, {
backpack: 0x55aaa2,
phase: 2.1
});
maker.position.set(4.55, 0.06, 1.15);
maker.rotation.y = 2.4;
staticStudents.push(maker);
// Six students carry and place the missing tiles.
const workerCount = 6;
const workers = [];
const shirtColors = [0xef7867, 0x50afa7, 0xe9b84f, 0x639bc8, 0x9c83c1, 0xdd9255];
for (let i = 0; i < workerCount; i++) {
const root = createStudent(
shirtColors[i],
skinMaterials[i % skinMaterials.length],
hairMaterials[i % hairMaterials.length],
{
backpack: i % 2 === 0 ? 0xf0c64f : 0x5b92c7,
phase: i * 0.8
}
);
const carried = makeTile(tilePalette[i % tilePalette.length]);
carried.scale.setScalar(0.9);
carried.position.set(0, 0.62, 0.62);
root.userData.upper.add(carried);
workers.push({
root,
carried,
jobs: [],
phase: i * 0.9
});
}
const missingTiles = activeBorder.sequence.slice(initialTileCount);
missingTiles.forEach((entry, index) => {
const workerIndex = index % workerCount;
const placement = 1.4 + index * 0.26;
const sideOffset = (workerIndex % 2 ? 1 : -1) * 0.1;
const stand = entry.position.clone()
.addScaledVector(entry.normal, 0.55)
.addScaledVector(entry.tangent, sideOffset);
workers[workerIndex].jobs.push({
tile: entry.tile,
color: entry.color,
normal: entry.normal,
tangent: entry.tangent,
placement,
stand,
from: stand.clone(),
start: 0,
revealed: false
});
});
workers.forEach((worker, workerIndex) => {
worker.jobs.forEach((job, jobIndex) => {
const previous = worker.jobs[jobIndex - 1];
if (previous) {
job.from.copy(previous.stand);
job.start = previous.placement + 0.22;
} else {
job.from.copy(job.stand)
.addScaledVector(job.tangent, workerIndex % 2 ? 0.5 : -0.5)
.addScaledVector(job.normal, 0.22);
job.start = Math.max(0.12, job.placement - 1.25);
}
});
const firstJob = worker.jobs[0];
worker.root.position.copy(firstJob.from);
});
function smoothStep(t) {
return t * t * (3 - 2 * t);
}
function easeOutBack(t) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(t - 1, 3) + c1 * Math.pow(t - 1, 2);
}
function updateWorker(worker, time) {
const { root, carried } = worker;
const upper = root.userData.upper;
const leftArm = root.userData.leftArm;
const rightArm = root.userData.rightArm;
const leftLeg = root.userData.leftLeg;
const rightLeg = root.userData.rightLeg;
let current = null;
let previous = null;
for (let i = 0; i < worker.jobs.length; i++) {
if (time <= worker.jobs[i].placement + 0.28) {
current = worker.jobs[i];
previous = i > 0 ? worker.jobs[i - 1] : null;
break;
}
}
let walking = false;
let placing = false;
let direction = new THREE.Vector3(0, 0, -1);
if (current && time >= current.start) {
carried.visible = true;
carried.userData.baseMaterial.color.set(current.color);
if (time <= current.placement) {
const progress = THREE.MathUtils.clamp(
(time - current.start) / Math.max(0.001, current.placement - current.start),
0,
1
);
const eased = smoothStep(progress);
root.position.lerpVectors(current.from, current.stand, eased);
direction.subVectors(current.stand, current.from);
walking = direction.lengthSq() > 0.0001;
} else {
root.position.copy(current.stand);
direction.set(-current.normal.x, 0, -current.normal.z);
placing = true;
}
} else {
carried.visible = false;
if (previous) {
root.position.copy(previous.stand);
direction.set(-previous.normal.x, 0, -previous.normal.z);
} else if (current) {
root.position.copy(current.from);
}
}
if (direction.lengthSq() > 0.0001) {
root.rotation.y = Math.atan2(direction.x, direction.z);
}
const walkPhase = time * 10 + worker.phase;
const swing = walking ? Math.sin(walkPhase) * 0.5 : 0;
leftLeg.rotation.x = swing;
rightLeg.rotation.x = -swing;
const carryAmount = carried.visible ? 1 : 0;
leftArm.rotation.x = THREE.MathUtils.lerp(0.08, -1.08, carryAmount);
rightArm.rotation.x = THREE.MathUtils.lerp(0.08, -1.08, carryAmount);
leftArm.rotation.z = carried.visible ? 0.18 : -0.03;
rightArm.rotation.z = carried.visible ? -0.18 : 0.03;
upper.rotation.x = placing ? 0.16 : walking ? 0.035 : 0;
upper.position.y = 0.67 + (walking ? Math.abs(Math.sin(walkPhase)) * 0.025 : 0);
}
// Keep the loading veil until the first frame is ready.
let firstFrame = true;
let animationTime = 0;
let previousTime = performance.now();
let paused = false;
let progressTimer = 0;
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
});
function animate(now) {
const delta = Math.min(0.05, Math.max(0, (now - previousTime) / 1000));
previousTime = now;
if (!paused) animationTime += delta;
workers.forEach((worker) => updateWorker(worker, animationTime));
staticStudents.forEach((student, index) => {
const phase = student.userData.phase;
student.position.y = 0.05 + Math.sin(animationTime * 1.5 + phase) * 0.012;
student.userData.upper.rotation.y = Math.sin(animationTime * 0.75 + phase) * 0.035;
student.userData.rightArm.rotation.x = -0.22 + Math.sin(animationTime + phase) * 0.025;
student.userData.leftArm.rotation.x = -0.18 - Math.sin(animationTime + phase) * 0.025;
});
let completed = initialTileCount;
activeBorder.sequence.forEach((entry) => {
const job = workers.flatMap(worker => worker.jobs).find(candidate => candidate.tile === entry.tile);
if (!job) return;
if (!job.revealed && animationTime >= job.placement) {
job.revealed = true;
job.tile.userData.revealStart = animationTime;
}
if (job.revealed) {
const revealProgress = THREE.MathUtils.clamp(
(animationTime - job.tile.userData.revealStart) / 0.3,
0,
1
);
job.tile.scale.setScalar(Math.max(0.001, easeOutBack(revealProgress)));
if (revealProgress >= 1) completed++;
}
});
progressTimer += delta;
if (progressTimer > 0.08) {
progressTimer = 0;
const percent = Math.round((completed / activeBorder.sequence.length) * 100);
progressValue.textContent = `${percent}%`;
progressFill.style.width = `${percent}%`;
}
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
loading.classList.add("hide");
}
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```