Prompt specification
Build or customize the Three.js 3D scene "Pizza-sharing classroom scene" 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: Pizza-sharing classroom scene
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pizza-sharing-classroom-scene-x1695
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: pizza-sharing classroom scene. Compose identical whole pizzas divided among toy plates with fractional labels; distinguish number of slices from amount of pizza when partition sizes differ.
Working Three.js Starter (pizza-sharing-classroom-scene-x1695):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Pizza Sharing Classroom</title>
<style>
:root {
--ink: #17313b;
--cream: #fff7e8;
--yellow: #ffd166;
--coral: #ef8354;
--teal: #2a9d8f;
--blue: #277da1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eadfc9;
color: var(--ink);
font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 100;
display: grid;
place-items: center;
background: #f3e8d2;
transition: opacity 0.35s ease, visibility 0.35s ease;
}
#loading.hidden {
opacity: 0;
visibility: hidden;
}
.loader {
padding: 20px 26px;
border: 3px solid var(--ink);
border-radius: 18px;
background: var(--cream);
font-weight: 900;
letter-spacing: 0.08em;
box-shadow: 7px 7px 0 var(--ink);
}
.hud {
position: fixed;
z-index: 10;
pointer-events: none;
}
#brand {
top: 20px;
left: 20px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 16px 11px 12px;
border: 2px solid rgba(23, 49, 59, 0.18);
border-radius: 16px;
background: rgba(255, 247, 232, 0.93);
box-shadow: 0 8px 24px rgba(31, 44, 48, 0.13);
backdrop-filter: blur(8px);
}
.logo {
display: grid;
place-items: center;
width: 42px;
height: 42px;
border-radius: 12px;
background: var(--yellow);
font-size: 25px;
box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.09);
}
#brand strong {
display: block;
font-size: 14px;
letter-spacing: 0.09em;
}
#brand small {
display: block;
margin-top: 2px;
color: #587079;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.05em;
}
#lesson {
left: 20px;
bottom: 20px;
width: min(390px, calc(100vw - 40px));
padding: 17px;
border: 2px solid rgba(23, 49, 59, 0.2);
border-radius: 20px;
background: rgba(255, 247, 232, 0.95);
box-shadow: 0 12px 34px rgba(31, 44, 48, 0.16);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.eyebrow {
margin-bottom: 5px;
color: #6b7b80;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#detail-title {
margin: 0 0 7px;
font-size: 19px;
line-height: 1.15;
}
#detail-text {
margin: 0;
color: #40565e;
font-size: 13px;
font-weight: 650;
line-height: 1.45;
}
#detail-key {
margin-top: 11px;
padding: 9px 11px;
border-radius: 10px;
background: #f1e3c7;
color: #17313b;
font-size: 12px;
font-weight: 900;
text-align: center;
}
#station-buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 7px;
margin-top: 13px;
}
#station-buttons button {
min-height: 36px;
border: 0;
border-radius: 10px;
background: #dce5df;
color: #28434b;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 900;
transition: transform 0.15s ease, background 0.15s ease;
}
#station-buttons button:hover {
transform: translateY(-2px);
}
#station-buttons button.active {
color: white;
background: var(--active, var(--blue));
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
#controls {
right: 20px;
bottom: 20px;
padding: 9px 12px;
border-radius: 12px;
background: rgba(23, 49, 59, 0.86);
color: #fff9ed;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.03em;
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.16);
}
#hint {
top: 20px;
right: 20px;
max-width: 265px;
padding: 10px 13px;
border-radius: 13px;
background: rgba(255, 247, 232, 0.9);
color: #486069;
font-size: 11px;
font-weight: 750;
line-height: 1.4;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}
@media (max-width: 700px) {
#hint {
display: none;
}
#brand {
top: 12px;
left: 12px;
}
#lesson {
left: 12px;
bottom: 12px;
width: calc(100vw - 24px);
padding: 13px;
}
#controls {
display: none;
}
}
</style>
</head>
<body>
<div id="loading">
<div class="loader">BUILDING THE CLASSROOM…</div>
</div>
<div id="brand" class="hud">
<div class="logo">🍕</div>
<div>
<strong>FRACTION LAB</strong>
<small>VOXEL PIZZA-SHARING CLASSROOM</small>
</div>
</div>
<div id="hint" class="hud">
Every central pizza is the <b>same size</b>.
Count the pieces, then compare their <b>fraction labels</b>.
Click a pizza or choose a station below.
</div>
<section id="lesson" class="hud">
<div class="eyebrow">Explore the sharing table</div>
<h2 id="detail-title"></h2>
<p id="detail-text"></p>
<div id="detail-key"></div>
<div id="station-buttons">
<button type="button" data-station="0">A · 2</button>
<button type="button" data-station="1">B · 3</button>
<button type="button" data-station="2">C · 4</button>
<button type="button" data-station="3">D · 4</button>
</div>
</section>
<div id="controls" class="hud">
DRAG TO ORBIT · SCROLL TO ZOOM · R TO RESET
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and direct (non-addon) camera controls
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0e5cf);
scene.fog = new THREE.Fog(0xf0e5cf, 28, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 1.65, -0.35);
const initialView = { yaw: 0.32, pitch: 0.62, distance: 22 };
const view = { ...initialView };
function updateCamera() {
const horizontal = Math.cos(view.pitch) * view.distance;
camera.position.set(
target.x + Math.sin(view.yaw) * horizontal,
target.y + Math.sin(view.pitch) * view.distance,
target.z + Math.cos(view.yaw) * horizontal
);
camera.lookAt(target);
}
updateCamera();
let pointerDown = false;
let pointerMoved = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = false;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
if (Math.abs(dx) + Math.abs(dy) > 3) pointerMoved = true;
view.yaw -= dx * 0.005;
view.pitch = THREE.MathUtils.clamp(
view.pitch + dy * 0.004,
0.28,
1.28
);
pointerX = event.clientX;
pointerY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
pointerDown = false;
if (!pointerMoved) {
const mouse = new THREE.Vector2(
(event.clientX / window.innerWidth) * 2 - 1,
-(event.clientY / window.innerHeight) * 2 + 1
);
const raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouse, camera);
const hit = raycaster.intersectObjects(interactiveMeshes, false)[0];
if (hit && Number.isInteger(hit.object.userData.stationIndex)) {
selectStation(hit.object.userData.stationIndex);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointerDown = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.distance = THREE.MathUtils.clamp(
view.distance + event.deltaY * 0.012,
12,
31
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
view.yaw = initialView.yaw;
view.pitch = initialView.pitch;
view.distance = initialView.distance;
updateCamera();
}
if (["1", "2", "3", "4"].includes(event.key)) {
selectStation(Number(event.key) - 1);
}
});
// -------------------------------------------------------------------------
// Shared geometry, materials, and small construction helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function standardMaterial(color, roughness = 0.8, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
function addBox(
parent,
size,
position,
color,
options = {}
) {
const material =
color && color.isMaterial
? color
: standardMaterial(
color,
options.roughness ?? 0.8,
options.metalness ?? 0
);
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.scale.set(size[0], size[1], size[2]);
if (options.rotationY) {
mesh.rotation.y = options.rotationY;
}
if (options.rotationX) {
mesh.rotation.x = options.rotationX;
}
if (options.rotationZ) {
mesh.rotation.z = options.rotationZ;
}
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
return mesh;
}
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function canvasTexture(canvas) {
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
return texture;
}
function makeSprite(
parent,
canvas,
position,
width,
height,
options = {}
) {
const material = new THREE.SpriteMaterial({
map: canvasTexture(canvas),
transparent: true,
depthWrite: false,
depthTest: options.depthTest ?? true
});
const sprite = new THREE.Sprite(material);
sprite.position.set(position[0], position[1], position[2]);
sprite.scale.set(width, height, 1);
sprite.renderOrder = options.renderOrder ?? 5;
parent.add(sprite);
return sprite;
}
function makeStationSign(station) {
const canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 230;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 8, 8, 884, 214, 34);
ctx.fillStyle = station.frame;
ctx.fill();
ctx.lineWidth = 8;
ctx.strokeStyle = "rgba(23,49,59,0.75)";
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#17313b";
ctx.font = "900 58px system-ui, sans-serif";
ctx.fillText(station.signTitle, 450, 91);
ctx.font = "800 31px system-ui, sans-serif";
ctx.fillStyle = "#36515a";
ctx.fillText(station.signSubtitle, 450, 150);
ctx.fillStyle = "rgba(255,255,255,0.8)";
roundedRect(ctx, 280, 173, 340, 6, 3);
ctx.fill();
return canvas;
}
function makeFractionBadge(fraction, accent) {
const canvas = document.createElement("canvas");
canvas.width = 360;
canvas.height = 135;
const ctx = canvas.getContext("2d");
roundedRect(ctx, 7, 7, 346, 121, 25);
ctx.fillStyle = accent;
ctx.fill();
ctx.lineWidth = 7;
ctx.strokeStyle = "#17313b";
ctx.stroke();
ctx.textAlign = "center";
ctx.fillStyle = "#ffffff";
ctx.font = "900 58px system-ui, sans-serif";
ctx.fillText(fraction, 180, 74);
ctx.font = "900 20px system-ui, sans-serif";
ctx.fillStyle = "rgba(255,255,255,0.88)";
ctx.fillText("OF THE WHOLE", 180, 105);
return canvas;
}
function fractionLabel(fraction) {
const denominator = Math.round(1 / fraction);
return `${denominator === 1 ? "1" : "1"}/${denominator}`;
}
// -------------------------------------------------------------------------
// Lighting and classroom shell
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff5dc, 0x7b91a0, 2.25));
const sun = new THREE.DirectionalLight(0xfff0cf, 3.0);
sun.position.set(-7, 14, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -16;
sun.shadow.camera.right = 16;
sun.shadow.camera.top = 14;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 40;
sun.shadow.bias = -0.00035;
scene.add(sun);
const windowLight = new THREE.PointLight(0xaadfff, 1.5, 16, 2);
windowLight.position.set(10, 5.5, -5.8);
scene.add(windowLight);
const room = new THREE.Group();
scene.add(room);
// Floor base.
addBox(
room,
[27.4, 0.2, 16.8],
[0, -0.13, 0],
0xd4c7ae
);
// Voxel checkerboard floor using instancing.
const tileGeometry = new THREE.BoxGeometry(1, 1, 1);
const floorItems = [];
for (let x = 0; x < 18; x++) {
for (let z = 0; z < 11; z++) {
floorItems.push({
x: (x - 8.5) * 1.5,
z: (z - 5) * 1.5,
color: (x + z) % 2 === 0 ? 0xe8dcc4 : 0xd8c9ae
});
}
}
const floorA = new THREE.InstancedMesh(
tileGeometry,
standardMaterial(0xe8dcc4),
Math.ceil(floorItems.length / 2)
);
const floorB = new THREE.InstancedMesh(
tileGeometry,
standardMaterial(0xd8c9ae),
Math.floor(floorItems.length / 2)
);
const dummy = new THREE.Object3D();
let floorAIndex = 0;
let floorBIndex = 0;
floorItems.forEach((tile, index) => {
dummy.position.set(tile.x, -0.035, tile.z);
dummy.scale.set(1.46, 0.12, 1.46);
dummy.updateMatrix();
if (index % 2 === 0) {
floorA.setMatrixAt(floorAIndex++, dummy.matrix);
} else {
floorB.setMatrixAt(floorBIndex++, dummy.matrix);
}
});
floorA.receiveShadow = true;
floorB.receiveShadow = true;
room.add(floorA, floorB);
// Walls and baseboards.
addBox(room, [27.3, 9.6, 0.32], [0, 4.7, -8.35], 0xf2ead9);
addBox(room, [0.32, 9.6, 16.6], [-13.55, 4.7, 0], 0xe8dfcd);
addBox(room, [0.32, 9.6, 16.6], [13.55, 4.7, 0], 0xe8dfcd);
addBox(room, [27, 0.35, 0.26], [0, 0.18, -8.12], 0x9f7956);
addBox(room, [0.26, 0.35, 16.4], [-13.32, 0.18, 0], 0x9f7956);
addBox(room, [0.26, 0.35, 16.4], [13.32, 0.18, 0], 0x9f7956);
// Blackboard frame.
addBox(room, [14.5, 4.75, 0.32], [0, 5.15, -8.02], 0x9d704e);
addBox(room, [14.0, 4.25, 0.10], [0, 5.15, -7.80], 0x183f39);
// Blackboard content.
const boardCanvas = document.createElement("canvas");
boardCanvas.width = 1600;
boardCanvas.height = 520;
const boardCtx = boardCanvas.getContext("2d");
boardCtx.fillStyle = "#183f39";
boardCtx.fillRect(0, 0, 1600, 520);
boardCtx.strokeStyle = "rgba(232,245,226,0.14)";
boardCtx.lineWidth = 3;
for (let y = 20; y < 520; y += 42) {
boardCtx.beginPath();
boardCtx.moveTo(0, y);
boardCtx.lineTo(1600, y);
boardCtx.stroke();
}
boardCtx.fillStyle = "#f5f0d5";
boardCtx.font = "900 72px system-ui, sans-serif";
boardCtx.fillText("PIZZA SHARING LAB", 62, 89);
boardCtx.fillStyle = "#ffd166";
boardCtx.font = "800 31px system-ui, sans-serif";
boardCtx.fillText("Every pizza is the same whole: 1", 65, 143);
boardCtx.fillStyle = "#f5f0d5";
boardCtx.font = "900 43px system-ui, sans-serif";
boardCtx.fillText("COUNT SLICES", 70, 230);
boardCtx.fillText("COMPARE AMOUNTS", 940, 230);
boardCtx.fillStyle = "#bdd4c6";
boardCtx.font = "700 31px system-ui, sans-serif";
boardCtx.fillText("How many pieces?", 70, 278);
boardCtx.fillText("How much of the whole?", 940, 278);
boardCtx.fillStyle = "#ef8354";
boardCtx.font = "900 74px system-ui, sans-serif";
boardCtx.fillText("≠", 782, 270);
boardCtx.fillStyle = "rgba(255,255,255,0.08)";
roundedRect(boardCtx, 55, 315, 670, 88, 20);
boardCtx.fill();
roundedRect(boardCtx, 900, 315, 645, 88, 20);
boardCtx.fill();
boardCtx.fillStyle = "#ffffff";
boardCtx.font = "850 28px system-ui, sans-serif";
boardCtx.fillText("2 × 1/2 = 1 3 × 1/3 = 1", 88, 370);
boardCtx.fillText("4 × 1/4 = 1 1/2 + 1/4 + 1/8 + 1/8 = 1", 928, 370);
const boardMesh = new THREE.Mesh(
new THREE.PlaneGeometry(13.9, 4.2),
new THREE.MeshBasicMaterial({ map: canvasTexture(boardCanvas) })
);
boardMesh.position.set(0, 5.15, -7.735);
room.add(boardMesh);
// Chalk rail and eraser.
addBox(room, [14.2, 0.18, 0.38], [0, 2.73, -7.66], 0x936744);
addBox(room, [0.55, 0.2, 0.32], [5.9, 2.91, -7.60], 0x384a4e);
addBox(room, [0.36, 0.18, 0.25], [5.9, 3.03, -7.60], 0xe9e1cf);
// Voxel window.
addBox(room, [4.2, 3.8, 0.22], [10.25, 5.35, -8.02], 0x986b4d);
addBox(room, [3.72, 3.32, 0.16], [10.25, 5.35, -7.86], 0x9ed8eb);
addBox(room, [0.16, 3.35, 0.16], [10.25, 5.35, -7.72], 0xf8f0dd);
addBox(room, [3.74, 0.16, 0.16], [10.25, 5.35, -7.71], 0xf8f0dd);
addBox(room, [4.45, 0.24, 0.7], [10.25, 3.40, -7.75], 0x986b4d);
// Simple clock.
addBox(room, [1.35, 1.35, 0.18], [0, 8.3, -8.08], 0x9d704e);
addBox(room, [1.12, 1.12, 0.12], [0, 8.3, -7.95], 0xfff8e7);
addBox(room, [0.07, 0.38, 0.06], [0, 8.39, -7.87], 0x17313b);
addBox(room, [0.34, 0.07, 0.06], [0.12, 8.3, -7.87], 0x17313b);
// Bookcase.
addBox(room, [3.8, 0.25, 1.0], [-10.45, 1.25, -7.60], 0xa77c56);
addBox(room, [3.8, 0.25, 1.0], [-10.45, 3.0, -7.60], 0xa77c56);
addBox(room, [3.8, 0.25, 1.0], [-10.45, 4.75, -7.60], 0xa77c56);
addBox(room, [0.25, 4.9, 1.0], [-12.22, 3.0, -7.60], 0xa77c56);
addBox(room, [0.25, 4.9, 1.0], [-8.68, 3.0, -7.60], 0xa77c56);
const bookColors = [
0xef8354,
0x2a9d8f,
0x277da1,
0xe9c46a,
0x9b5de5
];
for (let shelf = 0; shelf < 3; shelf++) {
for (let book = 0; book < 7; book++) {
const height = 0.65 + ((book + shelf) % 3) * 0.13;
addBox(
room,
[0.30, height, 0.65],
[
-11.85 + book * 0.43,
1.38 + shelf * 1.75 + height / 2,
-7.48
],
bookColors[(book + shelf) % bookColors.length]
);
}
}
// Classroom poster.
addBox(room, [2.5, 2.1, 0.14], [-10.45, 7.0, -8.06], 0xb7794f);
addBox(room, [2.15, 1.75, 0.10], [-10.45, 7.0, -7.95], 0xf4d58d);
const posterCanvas = document.createElement("canvas");
posterCanvas.width = 500;
posterCanvas.height = 420;
const posterCtx = posterCanvas.getContext("2d");
posterCtx.fillStyle = "#f4d58d";
posterCtx.fillRect(0, 0, 500, 420);
posterCtx.textAlign = "center";
posterCtx.fillStyle = "#17313b";
posterCtx.font = "900 48px system-ui, sans-serif";
posterCtx.fillText("SHARE", 250, 92);
posterCtx.fillText("FAIRLY!", 250, 146);
posterCtx.font = "800 34px system-ui, sans-serif";
posterCtx.fillText("same whole", 250, 226);
posterCtx.fillText("different shares", 250, 270);
posterCtx.fillStyle = "#ef8354";
posterCtx.fillRect(105, 315, 290, 12);
const poster = new THREE.Mesh(
new THREE.PlaneGeometry(2.1, 1.72),
new THREE.MeshBasicMaterial({ map: canvasTexture(posterCanvas) })
);
poster.position.set(-10.45, 7.0, -7.885);
room.add(poster);
// -------------------------------------------------------------------------
// Long sharing table
// -------------------------------------------------------------------------
const table = new THREE.Group();
scene.add(table);
addBox(table, [18.7, 0.30, 6.1], [0, 1.35, 0], 0xd9a86c);
addBox(table, [18.3, 0.08, 5.75], [0, 1.54, 0], 0xe9c88e);
for (const x of [-8.35, 8.35]) {
for (const z of [-2.45, 2.45]) {
addBox(table, [0.55, 1.25, 0.55], [x, 0.65, z], 0x8b684f);
}
}
addBox(table, [16.7, 0.35, 0.4], [0, 0.38, -2.45], 0x9f7956);
addBox(table, [16.7, 0.35, 0.4], [0, 0.38, 2.45], 0x9f7956);
// -------------------------------------------------------------------------
// Voxel student figures
// -------------------------------------------------------------------------
function createStudent(x, z, shirtColor, skinColor, hairColor, rotation = 0) {
const student = new THREE.Group();
student.position.set(x, 0, z);
student.rotation.y = rotation;
scene.add(student);
addBox(student, [0.34, 0.18, 0.58], [-0.23, 0.10, 0.10], 0x263c45);
addBox(student, [0.34, 0.18, 0.58], [0.23, 0.10, 0.10], 0x263c45);
addBox(student, [0.28, 0.80, 0.32], [-0.20, 0.58, 0], 0x435c69);
addBox(student, [0.28, 0.80, 0.32], [0.20, 0.58, 0], 0x435c69);
addBox(student, [0.78, 0.82, 0.42], [0, 1.35, 0], shirtColor);
addBox(student, [0.25, 0.77, 0.28], [-0.53, 1.28, 0], shirtColor);
addBox(student, [0.25, 0.77, 0.28], [0.53, 1.28, 0], shirtColor);
addBox(student, [0.24, 0.25, 0.24], [-0.53, 0.82, 0], skinColor);
addBox(student, [0.24, 0.25, 0.24], [0.53, 0.82, 0], skinColor);
addBox(student, [0.69, 0.67, 0.64], [0, 2.05, 0], skinColor);
addBox(student, [0.74, 0.23, 0.68], [0, 2.42, -0.02], hairColor);
addBox(student, [0.18, 0.35, 0.18], [-0.39, 2.16, 0], hairColor);
addBox(student, [0.09, 0.10, 0.06], [-0.15, 2.10, 0.335], 0x17262e);
addBox(student, [0.09, 0.10, 0.06], [0.15, 2.10, 0.335], 0x17262e);
addBox(student, [0.13, 0.06, 0.06], [0, 1.93, 0.34], 0xb95c50);
return student;
}
createStudent(-8.2, -3.55, 0xef8354, 0xdca77f, 0x4b352f);
createStudent(8.2, -3.55, 0x277da1, 0x8f5f43, 0x24212a);
// Small foreground chairs.
function createChair(x, z, color) {
const chair = new THREE.Group();
chair.position.set(x, 0, z);
scene.add(chair);
addBox(chair, [1.15, 0.18, 1.0], [0, 0.95, 0], color);
addBox(chair, [1.15, 1.0, 0.16], [0, 1.48, -0.42], color);
for (const lx of [-0.43, 0.43]) {
for (const lz of [-0.34, 0.34]) {
addBox(chair, [0.13, 0.9, 0.13], [lx, 0.45, lz], 0x8c735f);
}
}
}
createChair(-7.7, 3.85, 0x2a9d8f);
createChair(7.7, 3.85, 0xef8354);
// -------------------------------------------------------------------------
// Pizza geometry
// -------------------------------------------------------------------------
function sectorGeometry(
fraction,
radius,
depth,
startAngle = -Math.PI / 2,
angularGap = 0.012
) {
const span = Math.PI * 2 * fraction;
const a0 = startAngle + angularGap;
const a1 = startAngle + span - angularGap;
const segments = Math.max(5, Math.ceil(span * 15));
const points = [new THREE.Vector2(0, 0)];
for (let i = 0; i <= segments; i++) {
const angle = a0 + (a1 - a0) * (i / segments);
points.push(
new THREE.Vector2(
Math.cos(angle) * radius,
Math.sin(angle) * radius
)
);
}
// Polygon centroid, used to center a served slice on its toy plate.
let signedArea = 0;
let centroidX = 0;
let centroidY = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const cross = a.x * b.y - b.x * a.y;
signedArea += cross;
centroidX += (a.x + b.x) * cross;
centroidY += (a.y + b.y) * cross;
}
signedArea *= 0.5;
centroidX /= 3 * signedArea;
centroidY /= 3 * signedArea;
const shape = new THREE.Shape();
shape.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i].x, points[i].y);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth,
bevelEnabled: false,
steps: 1,
curveSegments: 12
});
// Shape XY becomes world XZ.
geometry.rotateX(-Math.PI / 2);
return {
geometry,
center: {
x: centroidX,
z: -centroidY
}
};
}
let randomSeed = 7321;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const toppingColors = [0xc94b35, 0xb73e32, 0xd65b3e];
const cheeseColors = [0xffd166, 0xf6bd60, 0xffe08a, 0xf4a261];
const sauceColor = 0xb83f32;
function addToppings(parent, fraction, startAngle, colorIndex) {
const count = Math.max(1, Math.round(fraction * 20));
const span = Math.PI * 2 * fraction;
for (let i = 0; i < count; i++) {
const angle = startAngle + span * (0.08 + random() * 0.84);
const radius = 0.18 + random() * 0.57;
const x = Math.cos(angle) * radius;
const z = -Math.sin(angle) * radius;
if (random() > 0.28) {
addBox(
parent,
[0.15, 0.045, 0.15],
[x, 1.735, z],
toppingColors[(i + colorIndex) % toppingColors.length],
{ rotationY: random() * Math.PI }
);
} else {
addBox(
parent,
[0.11, 0.055, 0.11],
[x, 1.737, z],
0x4f9b55,
{ rotationY: random() * Math.PI }
);
}
}
}
function createCentralPizza(parent, station, stationIndex) {
const pizza = new THREE.Group();
pizza.position.z = -0.62;
parent.add(pizza);
addBox(pizza, [2.32, 0.06, 2.32], [0, 1.55, 0], 0x375d68);
let startAngle = -Math.PI / 2;
station.fractions.forEach((fraction, index) => {
const cheeseColor =
stationIndex === 3
? cheeseColors[index % cheeseColors.length]
: cheeseColors[stationIndex % 3];
const sauce = sectorGeometry(
fraction,
0.90,
0.075,
startAngle,
0.009
);
const sauceMesh = new THREE.Mesh(
sauce.geometry,
standardMaterial(sauceColor, 0.9)
);
sauceMesh.position.y = 1.59;
sauceMesh.castShadow = true;
sauceMesh.receiveShadow = true;
pizza.add(sauceMesh);
const cheese = sectorGeometry(
fraction,
0.85,
0.035,
startAngle,
0.017
);
const cheeseMesh = new THREE.Mesh(
cheese.geometry,
standardMaterial(cheeseColor, 0.86)
);
cheeseMesh.position.y = 1.665;
cheeseMesh.castShadow = true;
cheeseMesh.receiveShadow = true;
pizza.add(cheeseMesh);
addToppings(pizza, fraction, startAngle, index);
startAngle += Math.PI * 2 * fraction;
});
// Voxel crust ring.
const crustCount = 30;
for (let i = 0; i < crustCount; i++) {
const angle = (i / crustCount) * Math.PI * 2;
const radius = 0.94;
addBox(
pizza,
[0.225, 0.17, 0.18],
[
Math.cos(angle) * radius,
1.67,
-Math.sin(angle) * radius
],
i % 3 === 0 ? 0xd89b4d : 0xe5ad5d,
{ rotationY: Math.PI / 2 + angle }
);
}
// Dark radial cut lines.
for (let i = 0; i < station.fractions.length; i++) {
const angle = -Math.PI / 2 + (i / station.fractions.length) * Math.PI * 2;
addBox(
pizza,
[0.025, 0.035, 0.84],
[
Math.cos(angle) * 0.43,
1.718,
-Math.sin(angle) * 0.43
],
0x8f4f30,
{ rotationY: Math.PI / 2 + angle }
);
}
return pizza;
}
function createToyPlate(parent, x, fraction, sliceColor, accent, labelIndex) {
const plate = new THREE.Group();
plate.position.set(x, 0, 1.07);
parent.add(plate);
addBox(plate, [0.84, 0.08, 0.74], [0, 1.58, 0], accent);
addBox(plate, [0.67, 0.025, 0.57], [0, 1.63, 0], 0xfff9e9);
// Small raised rim corners keep the plate visibly toy-like and blocky.
addBox(plate, [0.10, 0.10, 0.68], [-0.38, 1.64, 0], accent);
addBox(plate, [0.10, 0.10, 0.68], [0.38, 1.64, 0], accent);
addBox(plate, [0.70, 0.10, 0.10], [0, 1.64, -0.32], accent);
addBox(plate, [0.70, 0.10, 0.10], [0, 1.64, 0.32], accent);
const startAngle = -Math.PI / 2;
const sauce = sectorGeometry(fraction, 0.395, 0.035, startAngle, 0.015);
const sauceMesh = new THREE.Mesh(
sauce.geometry,
standardMaterial(sauceColor, 0.9)
);
sauceMesh.position.set(sauce.center.x, 1.64, sauce.center.z);
sauceMesh.castShadow = true;
plate.add(sauceMesh);
const cheese = sectorGeometry(fraction, 0.35, 0.025, startAngle, 0.019);
const cheeseMesh = new THREE.Mesh(
cheese.geometry,
standardMaterial(sliceColor, 0.85)
);
cheeseMesh.position.set(cheese.center.x, 1.682, cheese.center.z);
cheeseMesh.castShadow = true;
plate.add(cheeseMesh);
// Crust blocks on the served slice.
const arcStart = startAngle + 0.02;
const arcSpan = Math.PI * 2 * fraction - 0.04;
const crustPieces = Math.max(2, Math.ceil(fraction * 12));
for (let i = 0; i < crustPieces; i++) {
const t = crustPieces === 1 ? 0.5 : i / (crustPieces - 1);
const angle = arcStart + arcSpan * t;
addBox(
plate,
[0.13, 0.06, 0.075],
[
cheese.center.x + Math.cos(angle) * 0.375,
1.69,
cheese.center.z - Math.sin(angle) * 0.375
],
0xd99b4d,
{ rotationY: Math.PI / 2 + angle }
);
}
// One or two voxel toppings.
const toppingCount = fraction >= 0.45 ? 2 : 1;
for (let i = 0; i < toppingCount; i++) {
const angle = arcStart + arcSpan * (0.35 + i * 0.22);
const radius = fraction > 0.45 ? 0.16 : 0.19;
addBox(
plate,
[0.12, 0.04, 0.12],
[
cheese.center.x + Math.cos(angle) * radius,
1.735,
cheese.center.z - Math.sin(angle) * radius
],
toppingColors[(labelIndex + i) % toppingColors.length],
{ rotationY: angle }
);
}
const label = makeSprite(
parent,
makeFractionBadge(fractionLabel(fraction), accent),
[x, 2.02, 1.49],
0.78,
0.29,
{ renderOrder: 8 }
);
return label;
}
// -------------------------------------------------------------------------
// Four lesson stations
// -------------------------------------------------------------------------
const stationDefinitions = [
{
id: "A",
title: "A · 2 slices — equal shares",
text:
"This whole pizza is cut into 2 pieces. Each toy plate holds 1/2 of the same whole pizza.",
key: "2 slices × 1/2 each = 1 whole",
fractions: [1 / 2, 1 / 2],
frame: "#f3b44d",
accent: "#ef8354",
signTitle: "A · 2 SLICES",
signSubtitle: "EQUAL SHARES · 1/2 + 1/2 = 1"
},
{
id: "B",
title: "B · 3 slices — equal shares",
text:
"There are more slices, so each piece is smaller. The number of pieces and the amount per piece are different ideas.",
key: "3 slices × 1/3 each = 1 whole",
fractions: [1 / 3, 1 / 3, 1 / 3],
frame: "#79c6bd",
accent: "#2a9d8f",
signTitle: "B · 3 SLICES",
signSubtitle: "EQUAL SHARES · 3 × 1/3 = 1"
},
{
id: "C",
title: "C · 4 slices — equal shares",
text:
"Four equal slices each have a 1/4 share. Compare this with station D, which also has four slices.",
key: "4 slices × 1/4 each = 1 whole",
fractions: [1 / 4, 1 / 4, 1 / 4, 1 / 4],
frame: "#91c9dc",
accent: "#277da1",
signTitle: "C · 4 SLICES",
signSubtitle: "EQUAL SHARES · 4 × 1/4 = 1"
},
{
id: "D",
title: "D · 4 slices — unequal shares",
text:
"D and C both have 4 slices, but D's pieces are unequal: 1/2, 1/4, 1/8, and 1/8. Equal slice counts do not guarantee equal amounts.",
key: "Same count as C ≠ the same amount per slice",
fractions: [1 / 2, 1 / 4, 1 / 8, 1 / 8],
frame: "#e6a5bd",
accent: "#b85f88",
signTitle: "D · 4 SLICES",
signSubtitle: "UNEVEN · 1/2 + 1/4 + 1/8 + 1/8 = 1"
}
];
const stationXs = [-6.75, -2.25, 2.25, 6.75];
const stationGroups = [];
const stationMats = [];
const stationSigns = [];
const interactiveMeshes = [];
stationDefinitions.forEach((station, index) => {
const group = new THREE.Group();
group.position.x = stationXs[index];
scene.add(group);
stationGroups.push(group);
const mat = new THREE.MeshStandardMaterial({
color: 0xfff4d9,
roughness: 0.92,
emissive: 0x000000,
emissiveIntensity: 0.25
});
stationMats.push(mat);
addBox(
group,
[3.95, 0.045, 3.75],
[0, 1.525, 0.18],
mat,
{ castShadow: false }
);
addBox(
group,
[3.98, 0.07, 0.11],
[0, 1.54, -1.69],
station.accent,
{ castShadow: false }
);
createCentralPizza(group, station, index);
const offsets =
station.fractions.length === 2
? [-0.68, 0.68]
: station.fractions.length === 3
? [-1.0, 0, 1.0]
: [-1.35, -0.45, 0.45, 1.35];
station.fractions.forEach((fraction, sliceIndex) => {
const sliceColor =
index === 3
? cheeseColors[sliceIndex % cheeseColors.length]
: cheeseColors[index % 3];
createToyPlate(
group,
offsets[sliceIndex],
fraction,
sliceColor,
station.accent,
sliceIndex
);
});
// Small sign stand.
addBox(
group,
[0.10, 1.45, 0.10],
[-1.48, 2.22, -1.45],
0x8e7157
);
const sign = makeSprite(
group,
makeStationSign(station),
[0, 3.05, -1.43],
3.45,
0.88,
{ renderOrder: 7 }
);
stationSigns.push(sign);
group.traverse((object) => {
if (object.isMesh) {
object.userData.stationIndex = index;
interactiveMeshes.push(object);
}
});
});
// -------------------------------------------------------------------------
// Decorative block plant
// -------------------------------------------------------------------------
const plant = new THREE.Group();
plant.position.set(12.1, 0, -7.15);
scene.add(plant);
addBox(plant, [1.2, 0.8, 1.2], [0, 0.4, 0], 0xc87850);
addBox(plant, [0.18, 2.2, 0.18], [0, 1.65, 0], 0x477b53);
addBox(plant, [0.75, 0.18, 0.65], [-0.36, 1.45, 0], 0x4f9761);
addBox(plant, [0.72, 0.18, 0.65], [0.38, 1.85, 0.05], 0x5aa66a);
addBox(plant, [0.70, 0.18, 0.64], [-0.25, 2.25, 0], 0x3f8756);
addBox(plant, [0.75, 0.18, 0.62], [0.35, 2.62, 0], 0x64ad72);
// -------------------------------------------------------------------------
// Lesson panel and station selection
// -------------------------------------------------------------------------
const detailTitle = document.getElementById("detail-title");
const detailText = document.getElementById("detail-text");
const detailKey = document.getElementById("detail-key");
const buttons = [...document.querySelectorAll("#station-buttons button")];
let selectedStation = 3;
function selectStation(index) {
selectedStation = index;
const station = stationDefinitions[index];
detailTitle.textContent = station.title;
detailText.textContent = station.text;
detailKey.textContent = station.key;
stationMats.forEach((material, i) => {
material.emissive.set(i === index ? station.accent : 0x000000);
material.emissiveIntensity = i === index ? 0.24 : 0;
});
stationSigns.forEach((sign, i) => {
const scale = i === index ? 1.06 : 1.0;
sign.scale.set(3.45 * scale, 0.88 * scale, 1);
});
buttons.forEach((button, i) => {
const active = i === index;
button.classList.toggle("active", active);
button.style.setProperty(
"--active",
stationDefinitions[i].accent
);
});
}
buttons.forEach((button) => {
button.addEventListener("click", () => {
selectStation(Number(button.dataset.station));
});
});
selectStation(selectedStation);
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
</script>
</body>
</html>
```