Prompt specification
Build or customize the Three.js 3D scene "Classroom pattern discovery table" 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: Classroom pattern discovery table
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/classroom-pattern-discovery-table-x0347
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a kaleidoscope. Arrange mirror wedges, beads, and symmetry cards; users change the wedge angle and inspect the number of repeated sectors in an explicitly idealized reflection model. Stylized solid forms.
Working Three.js Starter (classroom-pattern-discovery-table-x0347):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Kaleido Fold Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #080d19;
--panel: rgba(15, 23, 42, 0.84);
--panel-edge: rgba(174, 225, 255, 0.16);
--text: #edf7ff;
--muted: #91a4bc;
--cyan: #70e7f2;
--gold: #ffd166;
--coral: #ff7f91;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 70% 20%, #192845 0%, transparent 38%),
linear-gradient(145deg, #080d19, #10192c 55%, #080d19);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.brand {
position: fixed;
top: 25px;
right: 30px;
z-index: 3;
pointer-events: none;
text-align: right;
}
.brand strong {
display: block;
font-size: 0.82rem;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.brand span {
color: var(--muted);
font-size: 0.72rem;
letter-spacing: 0.08em;
}
.panel {
position: fixed;
z-index: 4;
top: 18px;
left: 18px;
width: min(365px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow: auto;
padding: 20px;
border: 1px solid var(--panel-edge);
border-radius: 22px;
background:
linear-gradient(150deg, rgba(28, 43, 69, 0.88), rgba(10, 17, 32, 0.9));
box-shadow:
0 24px 70px rgba(0, 0, 0, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.05);
backdrop-filter: blur(18px) saturate(130%);
scrollbar-width: thin;
scrollbar-color: rgba(112, 231, 242, 0.3) transparent;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--cyan);
font-size: 0.68rem;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 15px var(--cyan);
content: "";
}
h1 {
margin: 0;
font-size: clamp(1.75rem, 4vw, 2.35rem);
line-height: 0.98;
letter-spacing: -0.045em;
}
.intro {
margin: 11px 0 20px;
color: var(--muted);
font-size: 0.88rem;
line-height: 1.55;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.control-head label {
font-size: 0.82rem;
font-weight: 700;
}
#angleValue {
color: var(--gold);
font-size: 1.35rem;
font-weight: 760;
font-variant-numeric: tabular-nums;
}
#angle {
width: 100%;
height: 7px;
margin: 0;
border-radius: 999px;
appearance: none;
background: rgba(255, 255, 255, 0.12);
cursor: pointer;
}
#angle::-webkit-slider-thumb {
width: 20px;
height: 20px;
border: 3px solid #172238;
border-radius: 50%;
appearance: none;
background: var(--gold);
box-shadow: 0 0 0 1px var(--gold), 0 0 18px rgba(255, 209, 102, 0.35);
}
#angle::-moz-range-thumb {
width: 15px;
height: 15px;
border: 3px solid #172238;
border-radius: 50%;
background: var(--gold);
box-shadow: 0 0 0 1px var(--gold);
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: #71839a;
font-size: 0.65rem;
font-variant-numeric: tabular-nums;
}
.stats {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin: 18px 0 12px;
}
.stat {
min-width: 0;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.07);
border-radius: 14px;
background: rgba(255, 255, 255, 0.035);
}
.stat span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 0.64rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong {
font-size: 1.5rem;
font-variant-numeric: tabular-nums;
}
.stat small {
margin-left: 4px;
color: var(--muted);
font-size: 0.68rem;
}
.model-summary {
display: grid;
grid-template-columns: 112px 1fr;
align-items: center;
gap: 13px;
margin: 14px 0;
padding: 12px;
border: 1px solid rgba(112, 231, 242, 0.12);
border-radius: 16px;
background: rgba(7, 15, 29, 0.42);
}
#modelRose {
width: 112px;
height: 112px;
overflow: visible;
filter: drop-shadow(0 0 12px rgba(112, 231, 242, 0.12));
}
.formula {
margin: 0 0 8px;
color: var(--text);
font-size: 0.86rem;
font-weight: 700;
}
.formula code {
color: var(--cyan);
font-family: inherit;
}
#modelDescription {
margin: 0;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.5;
}
.sector-nav {
display: flex;
align-items: center;
gap: 9px;
margin: 12px 0;
}
.sector-nav button,
.reset-button {
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 11px;
background: rgba(255, 255, 255, 0.05);
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.sector-nav button {
width: 39px;
height: 37px;
font-size: 1rem;
}
.sector-nav button:hover,
.reset-button:hover {
border-color: rgba(112, 231, 242, 0.5);
background: rgba(112, 231, 242, 0.1);
}
.sector-nav button:active,
.reset-button:active {
transform: scale(0.96);
}
#sectorLabel {
flex: 1;
color: var(--muted);
font-size: 0.75rem;
text-align: center;
font-variant-numeric: tabular-nums;
}
.toggle {
display: flex;
align-items: center;
justify-content: space-between;
gap: 15px;
margin: 15px 0;
padding: 11px 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.035);
cursor: pointer;
}
.toggle strong {
display: block;
font-size: 0.76rem;
}
.toggle small {
color: var(--muted);
font-size: 0.66rem;
}
.toggle input {
position: relative;
width: 40px;
height: 22px;
flex: 0 0 auto;
margin: 0;
border-radius: 999px;
appearance: none;
background: #28364c;
cursor: pointer;
transition: background 160ms ease;
}
.toggle input::after {
position: absolute;
top: 3px;
left: 3px;
width: 16px;
height: 16px;
border-radius: 50%;
background: #d6e4ef;
transition: transform 160ms ease;
content: "";
}
.toggle input:checked {
background: #398b93;
}
.toggle input:checked::after {
transform: translateX(18px);
background: var(--cyan);
}
details {
border-top: 1px solid rgba(255, 255, 255, 0.08);
padding-top: 13px;
}
summary {
color: var(--muted);
font-size: 0.72rem;
cursor: pointer;
}
details p {
margin: 10px 0 0;
color: #8296ad;
font-size: 0.7rem;
line-height: 1.55;
}
.model-badge {
display: inline-flex;
align-items: center;
gap: 5px;
margin-bottom: 8px;
padding: 5px 8px;
border: 1px solid rgba(255, 209, 102, 0.24);
border-radius: 999px;
color: var(--gold);
font-size: 0.6rem;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.hint {
position: fixed;
z-index: 2;
right: 24px;
bottom: 20px;
padding: 9px 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(7, 13, 25, 0.56);
color: #8295aa;
font-size: 0.67rem;
pointer-events: none;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #080d19;
color: var(--cyan);
font-size: 0.75rem;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.brand {
display: none;
}
.panel {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: calc(100vh - 20px);
padding: 16px;
border-radius: 18px;
}
.hint {
display: none;
}
.intro {
margin-bottom: 14px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional kaleidoscope with mirror wedges, beads, and symmetry cards"
></canvas>
<div class="brand" aria-hidden="true">
<strong>Fold Lab / 01</strong>
<span>Solid-form symmetry study</span>
</div>
<aside class="panel">
<div class="eyebrow">Kaleidoscope laboratory</div>
<h1>Shape the<br>fold.</h1>
<p class="intro">
Rotate the mirror aperture, inspect its repeated sectors, and select any
folded card or bead to follow its place in the pattern.
</p>
<div class="control-head">
<label for="angle">Mirror wedge angle</label>
<output id="angleValue" for="angle">36°</output>
</div>
<input
id="angle"
type="range"
min="15"
max="90"
step="1"
value="36"
aria-label="Mirror wedge angle in degrees"
>
<div class="range-labels">
<span>15° / dense</span>
<span>90° / fourfold</span>
</div>
<div class="stats">
<div class="stat">
<span>Repeated sectors</span>
<strong id="sectorValue">10</strong>
<small>copies</small>
</div>
<div class="stat">
<span>Angular remainder</span>
<strong id="remainderValue">0°</strong>
<small>open</small>
</div>
</div>
<div class="model-summary">
<svg
id="modelRose"
viewBox="-52 -52 104 104"
role="img"
aria-label="Planar diagram of repeated sectors"
></svg>
<div>
<p class="formula">
<code>N = ⌊360° / θ⌋</code>
</p>
<p id="modelDescription">
Ten equal reflected copies fill the complete 360° turn.
</p>
</div>
</div>
<div class="sector-nav">
<button id="previousSector" type="button" aria-label="Inspect previous sector">
‹
</button>
<span id="sectorLabel" aria-live="polite">Inspecting sector 01 / 10</span>
<button id="nextSector" type="button" aria-label="Inspect next sector">
›
</button>
</div>
<label class="toggle">
<span>
<strong>Explode the folds</strong>
<small>Separate repeated wedge assemblies</small>
</span>
<input id="explode" type="checkbox">
</label>
<details open>
<summary>Idealized reflection model</summary>
<p>
The wedge aperture is θ. Each planar reflected copy advances by θ,
giving the largest non-overlapping set
<strong>N = floor(360° / θ)</strong>. Any remainder is intentionally
left open. This is a geometric idealization—not a ray-traced optical
simulation. Refraction, finite mirror thickness, seam overlap,
multiple reflection paths, and path-dependent brightness are ignored.
</p>
</details>
</aside>
<div class="hint">Drag to orbit · Wheel to zoom · Click a sector to inspect</div>
<div id="loading">Building symmetry…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const angleInput = document.querySelector("#angle");
const angleValue = document.querySelector("#angleValue");
const sectorValue = document.querySelector("#sectorValue");
const remainderValue = document.querySelector("#remainderValue");
const modelDescription = document.querySelector("#modelDescription");
const modelRose = document.querySelector("#modelRose");
const sectorLabel = document.querySelector("#sectorLabel");
const explodeInput = document.querySelector("#explode");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d19);
scene.fog = new THREE.Fog(0x080d19, 17, 39);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraState = {
radius: 13.7,
phi: 0.68,
theta: 0.68,
target: new THREE.Vector3(0, 0.52, 0)
};
function updateCamera() {
const { radius, phi, theta, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xc7efff, 0x251a39, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.4);
keyLight.position.set(7, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 32;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x50e5ff, 24, 18, 2);
cyanLight.position.set(-4, 5, 3);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff5d93, 19, 16, 2);
pinkLight.position.set(5, 3, -4);
scene.add(pinkLight);
// Shared materials
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0x0a1120,
roughness: 0.96,
metalness: 0.02
}),
base: new THREE.MeshStandardMaterial({
color: 0x17243a,
roughness: 0.38,
metalness: 0.68
}),
baseEdge: new THREE.MeshStandardMaterial({
color: 0x263c57,
roughness: 0.25,
metalness: 0.78
}),
well: new THREE.MeshStandardMaterial({
color: 0x091322,
roughness: 0.32,
metalness: 0.6
}),
mirror: new THREE.MeshStandardMaterial({
color: 0xc6e8ed,
roughness: 0.19,
metalness: 0.82
}),
mirrorBlue: new THREE.MeshStandardMaterial({
color: 0x9ccbd8,
roughness: 0.24,
metalness: 0.76
}),
dark: new THREE.MeshStandardMaterial({
color: 0x101a2a,
roughness: 0.46,
metalness: 0.46
}),
cyanTrim: new THREE.MeshStandardMaterial({
color: 0x4bdce9,
emissive: 0x145a63,
emissiveIntensity: 0.55,
roughness: 0.26,
metalness: 0.55
}),
gold: new THREE.MeshStandardMaterial({
color: 0xffcf70,
emissive: 0x6f3c08,
emissiveIntensity: 0.42,
roughness: 0.26,
metalness: 0.66
}),
ray: new THREE.LineBasicMaterial({
color: 0x72e9f4,
transparent: true,
opacity: 0.24
}),
seam: new THREE.LineBasicMaterial({
color: 0x07101e,
transparent: true,
opacity: 0.9
}),
selection: new THREE.LineBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.95
}),
selectionFill: new THREE.MeshBasicMaterial({
color: 0xffd166,
transparent: true,
opacity: 0.54,
side: THREE.DoubleSide
})
};
const cardMaterials = [
0xff7f91,
0x6de4da,
0xffcf70,
0xa897ff
].map(
color =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.34,
metalness: 0.12,
side: THREE.DoubleSide
})
);
const beadMaterials = [
0x64e8f2,
0xff7696,
0xffd166,
0xf0f7ff
].map(
color =>
new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.09,
roughness: 0.25,
metalness: 0.18
})
);
// Ground and instrument base
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
materials.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.28;
ground.receiveShadow = true;
scene.add(ground);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(4.9, 5.12, 0.52, 96),
materials.base
);
base.position.y = 0;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const lowerRim = new THREE.Mesh(
new THREE.TorusGeometry(4.96, 0.12, 12, 128),
materials.baseEdge
);
lowerRim.rotation.x = Math.PI / 2;
lowerRim.position.y = 0.16;
lowerRim.castShadow = true;
scene.add(lowerRim);
const well = new THREE.Mesh(
new THREE.CylinderGeometry(4.35, 4.35, 0.18, 128),
materials.well
);
well.position.y = 0.32;
well.receiveShadow = true;
scene.add(well);
const outerRing = new THREE.Mesh(
new THREE.TorusGeometry(4.58, 0.075, 10, 128),
materials.cyanTrim
);
outerRing.rotation.x = Math.PI / 2;
outerRing.position.y = 0.48;
outerRing.castShadow = true;
scene.add(outerRing);
const tickGeometry = new THREE.BoxGeometry(0.035, 0.07, 0.19);
for (let i = 0; i < 48; i++) {
const a = (i / 48) * Math.PI * 2;
const tick = new THREE.Mesh(tickGeometry, i % 4 === 0
? materials.gold
: materials.baseEdge
);
tick.position.set(
Math.cos(a) * 4.56,
0.5,
Math.sin(a) * 4.56
);
tick.rotation.y = Math.PI / 2 - a;
scene.add(tick);
}
// Central solid-form jewel
const centralGroup = new THREE.Group();
scene.add(centralGroup);
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.7, 0.82, 0.38, 48),
materials.baseEdge
);
hub.position.y = 0.69;
hub.castShadow = true;
centralGroup.add(hub);
const hubRing = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.065, 10, 64),
materials.cyanTrim
);
hubRing.rotation.x = Math.PI / 2;
hubRing.position.y = 0.88;
centralGroup.add(hubRing);
const crystal = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.43, 0),
materials.gold
);
crystal.position.y = 1.2;
crystal.castShadow = true;
centralGroup.add(crystal);
// Ambient background solids
const backgroundSolids = [];
const backgroundColors = [0x1b3550, 0x342342, 0x173a43];
for (let i = 0; i < 12; i++) {
const a = (i / 12) * Math.PI * 2 + 0.23;
const r = 10 + (i % 3) * 1.8;
const size = 0.38 + (i % 4) * 0.19;
const solid = new THREE.Mesh(
new THREE.IcosahedronGeometry(size, 0),
new THREE.MeshStandardMaterial({
color: backgroundColors[i % backgroundColors.length],
roughness: 0.72,
metalness: 0.14,
transparent: true,
opacity: 0.68
})
);
solid.position.set(
Math.cos(a) * r,
1.1 + (i % 5) * 0.55,
Math.sin(a) * r
);
solid.rotation.set(i * 0.31, i * 0.47, i * 0.19);
scene.add(solid);
backgroundSolids.push(solid);
}
/*
Creates a closed annular prism centered on the local +X axis.
The geometry is converted to non-indexed geometry so its top,
bottom, and side faces retain distinct solid-form normals.
*/
function createAnnularWedge(
innerRadius,
outerRadius,
angle,
height,
segments = 24
) {
const positions = [];
const indices = [];
const half = height / 2;
for (let i = 0; i <= segments; i++) {
const a = -angle / 2 + (i / segments) * angle;
const c = Math.cos(a);
const s = Math.sin(a);
positions.push(
c * innerRadius, half, s * innerRadius,
c * outerRadius, half, s * outerRadius,
c * innerRadius, -half, s * innerRadius,
c * outerRadius, -half, s * outerRadius
);
}
for (let i = 0; i < segments; i++) {
const a = i * 4;
const b = (i + 1) * 4;
// Top
indices.push(a, b, a + 1);
indices.push(a + 1, b, b + 1);
// Bottom
indices.push(a + 2, a + 3, b + 2);
indices.push(a + 3, b + 3, b + 2);
// Outer wall
indices.push(a + 1, b + 1, a + 3);
indices.push(a + 3, b + 1, b + 3);
// Inner wall
indices.push(a + 2, b, a);
indices.push(a, a + 2, b);
}
const start = 0;
indices.push(start, start + 1, start + 2);
indices.push(start + 1, start + 3, start + 2);
const end = segments * 4;
indices.push(end, end + 2, end + 1);
indices.push(end + 1, end + 2, end + 3);
let geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry = geometry.toNonIndexed();
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function createRadialLine(angle, innerRadius, outerRadius, y) {
const c = Math.cos(angle);
const s = Math.sin(angle);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(c * innerRadius, y, s * innerRadius),
new THREE.Vector3(c * outerRadius, y, s * outerRadius)
]);
return new THREE.Line(geometry, materials.seam);
}
let sectorRoot = null;
let selectionMarker = null;
let sectorRecords = [];
let selectableObjects = [];
let sectorCount = 10;
let currentTheta = 36;
let selectedSector = 0;
let rebuildQueued = false;
function disposeObjectGeometry(object) {
const geometries = new Set();
object.traverse(child => {
if (child.geometry) geometries.add(child.geometry);
});
geometries.forEach(geometry => geometry.dispose());
}
function tagSelectable(object, index) {
object.userData.sectorIndex = index;
selectableObjects.push(object);
return object;
}
function buildSector(thetaDegrees, count) {
if (sectorRoot) {
scene.remove(sectorRoot);
disposeObjectGeometry(sectorRoot);
}
sectorRoot = new THREE.Group();
scene.add(sectorRoot);
sectorRecords = [];
selectableObjects = [];
const theta = THREE.MathUtils.degToRad(thetaDegrees);
const half = theta / 2;
for (let i = 0; i < count; i++) {
const centerAngle = (i + 0.5) * theta;
const sectorGroup = new THREE.Group();
// Local +X points along the sector's radial center.
sectorGroup.rotation.y = -centerAngle;
sectorRoot.add(sectorGroup);
const wedge = new THREE.Mesh(
createAnnularWedge(0.91, 4.28, theta, 0.18, 32),
i % 2 === 0 ? materials.mirror : materials.mirrorBlue
);
wedge.position.y = 0.57;
wedge.castShadow = true;
wedge.receiveShadow = true;
tagSelectable(wedge, i);
sectorGroup.add(wedge);
// A faint radial construction line.
const rayGeometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0.77, 0.79, 0),
new THREE.Vector3(3.28, 0.79, 0)
]);
const ray = new THREE.Line(rayGeometry, materials.ray);
sectorGroup.add(ray);
// Start boundary of this repeated wedge.
sectorGroup.add(createRadialLine(-half, 0.78, 4.28, 0.72));
// Three beads whose offsets shrink with the wedge angle.
const beadRadii = [1.48, 2.04, 2.65];
const beadSides = [-1, 1, -1];
beadRadii.forEach((radius, j) => {
const bead = new THREE.Mesh(
new THREE.SphereGeometry(0.145, 18, 14),
beadMaterials[(i + j) % beadMaterials.length]
);
const tangentOffset =
beadSides[j] * radius * Math.tan(half) * 0.42;
bead.position.set(radius, 0.88, tangentOffset);
bead.castShadow = true;
tagSelectable(bead, i);
sectorGroup.add(bead);
});
// Upright symmetry card, facing inward.
const cardAssembly = new THREE.Group();
cardAssembly.position.set(3.62, 1.28, 0);
cardAssembly.rotation.y = -Math.PI / 2;
sectorGroup.add(cardAssembly);
const cardBody = new THREE.Mesh(
new THREE.BoxGeometry(0.78, 1.1, 0.13),
cardMaterials[i % cardMaterials.length]
);
cardBody.castShadow = true;
cardBody.receiveShadow = true;
tagSelectable(cardBody, i);
cardAssembly.add(cardBody);
// Emblems are placed on both sides so the card remains legible
// while the camera orbits around the instrument.
for (const side of [-1, 1]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.225, 0.035, 8, 32),
materials.gold
);
ring.position.z = side * 0.09;
cardAssembly.add(ring);
const diamond = new THREE.Mesh(
new THREE.OctahedronGeometry(0.105, 0),
materials.gold
);
diamond.position.z = side * 0.145;
cardAssembly.add(diamond);
}
sectorRecords.push({
group: sectorGroup,
cardAssembly,
centerAngle
});
}
// The open remainder boundary.
if (360 - count * thetaDegrees > 0) {
const remainderAngle = count * theta;
const c = Math.cos(remainderAngle);
const s = Math.sin(remainderAngle);
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(c * 0.8, 0.72, s * 0.8),
new THREE.Vector3(c * 4.28, 0.72, s * 4.28)
]);
sectorRoot.add(new THREE.Line(geometry, materials.seam));
}
selectedSector = Math.min(selectedSector, count - 1);
applyExplodedState();
buildSelectionMarker();
updateSectorVisuals();
}
function applyExplodedState() {
const offset = explodeInput.checked ? 0.56 : 0;
sectorRecords.forEach(record => {
record.group.position.x = offset;
});
}
function buildSelectionMarker() {
if (selectionMarker) {
scene.remove(selectionMarker);
disposeObjectGeometry(selectionMarker);
}
const theta = THREE.MathUtils.degToRad(currentTheta);
const half = theta / 2;
const centerAngle = (selectedSector + 0.5) * theta;
const offset = explodeInput.checked ? 0.56 : 0;
selectionMarker = new THREE.Group();
selectionMarker.position.set(
Math.cos(centerAngle) * offset,
0,
Math.sin(centerAngle) * offset
);
selectionMarker.rotation.y = -centerAngle;
const edge = new THREE.Mesh(
createAnnularWedge(4.27, 4.39, theta, 0.027, 40),
materials.selectionFill
);
edge.position.y = 0.76;
selectionMarker.add(edge);
const points = [];
for (const a of [-half, half]) {
const c = Math.cos(a);
const s = Math.sin(a);
points.push(
new THREE.Vector3(c * 0.8, 0.79, s * 0.8),
new THREE.Vector3(c * 4.38, 0.79, s * 4.38)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
selectionMarker.add(new THREE.LineSegments(geometry, materials.selection));
scene.add(selectionMarker);
}
function updateSectorVisuals() {
sectorRecords.forEach((record, index) => {
const scale = index === selectedSector ? 1.13 : 1;
record.cardAssembly.scale.setScalar(scale);
});
sectorLabel.textContent =
`Inspecting sector ${String(selectedSector + 1).padStart(2, "0")}` +
` / ${String(sectorCount).padStart(2, "0")}`;
updateModelRose();
}
function selectSector(index) {
selectedSector = (index + sectorCount) % sectorCount;
buildSelectionMarker();
updateSectorVisuals();
}
function polar(angle, radius) {
const a = THREE.MathUtils.degToRad(angle - 90);
return {
x: Math.cos(a) * radius,
y: Math.sin(a) * radius
};
}
function updateModelRose() {
const theta = currentTheta;
const count = sectorCount;
let markup = "";
for (let i = 0; i < count; i++) {
const a0 = polar(i * theta, 48);
const a1 = polar((i + 1) * theta, 48);
const selected = i === selectedSector;
const fill = selected
? "#ffd166"
: i % 2 === 0
? "rgba(112,231,242,.27)"
: "rgba(168,151,255,.24)";
const opacity = selected ? 0.9 : 0.72;
markup += `
<path
d="M 0 0 L ${a0.x.toFixed(3)} ${a0.y.toFixed(3)}
A 48 48 0 0 1 ${a1.x.toFixed(3)} ${a1.y.toFixed(3)} Z"
fill="${fill}"
fill-opacity="${opacity}"
stroke="#9adfe9"
stroke-opacity="${selected ? 0.9 : 0.24}"
stroke-width="${selected ? 1.8 : 0.8}"
/>
`;
}
markup += `
<circle r="48" fill="none" stroke="#70e7f2" stroke-opacity=".45"/>
<circle r="13" fill="#101a2d" stroke="#ffd166" stroke-opacity=".8"/>
<text y="4" text-anchor="middle" fill="#edf7ff"
font-size="11" font-family="system-ui" font-weight="700">${count}</text>
`;
modelRose.innerHTML = markup;
}
function updateReadouts() {
currentTheta = Number(angleInput.value);
sectorCount = Math.floor(360 / currentTheta);
const remainder = 360 - sectorCount * currentTheta;
const coverage = sectorCount * currentTheta;
angleValue.textContent = `${currentTheta}°`;
sectorValue.textContent = sectorCount;
remainderValue.textContent = `${remainder}°`;
const progress =
((currentTheta - Number(angleInput.min)) /
(Number(angleInput.max) - Number(angleInput.min))) *
100;
angleInput.style.background =
`linear-gradient(90deg, #70e7f2 0%, #70e7f2 ${progress}%,` +
` rgba(255,255,255,.12) ${progress}%, rgba(255,255,255,.12) 100%)`;
if (remainder === 0) {
modelDescription.textContent =
`${sectorCount} equal reflected copies fill the complete 360° turn.`;
} else {
modelDescription.textContent =
`${sectorCount} copies occupy ${coverage}°. ` +
`The final ${remainder}° remainder stays open.`;
}
}
function scheduleRebuild() {
if (rebuildQueued) return;
rebuildQueued = true;
requestAnimationFrame(() => {
rebuildQueued = false;
buildSector(currentTheta, sectorCount);
updateModelRose();
});
}
angleInput.addEventListener("input", () => {
updateReadouts();
scheduleRebuild();
});
explodeInput.addEventListener("change", () => {
applyExplodedState();
buildSelectionMarker();
});
document.querySelector("#previousSector").addEventListener(
"click",
() => selectSector(selectedSector - 1)
);
document.querySelector("#nextSector").addEventListener(
"click",
() => selectSector(selectedSector + 1)
);
// Custom camera controls: orbit, pan, wheel zoom, and touch pinch.
const pointers = new Map();
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
let gestureMoved = false;
let pinchDistance = null;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY,
button: event.button,
moved: false
});
gestureMoved = false;
if (pointers.size === 2) pinchDistance = null;
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", event => {
const pointer = pointers.get(event.pointerId);
if (!pointer) {
if (event.pointerType === "mouse") updateHover(event);
return;
}
const dx = event.clientX - pointer.x;
const dy = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (Math.abs(dx) + Math.abs(dy) > 0.5) {
pointer.moved = true;
gestureMoved = true;
}
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (pinchDistance / distance),
7.5,
24
);
}
pinchDistance = distance;
updateCamera();
return;
}
if (pointer.button === 2 || event.shiftKey) {
const scale = cameraState.radius * 0.0013;
const right = new THREE.Vector3().setFromMatrixColumn(
camera.matrix,
0
);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.y = THREE.MathUtils.clamp(
cameraState.target.y,
-1,
4
);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.25,
1.32
);
}
updateCamera();
});
function endPointer(event) {
const pointer = pointers.get(event.pointerId);
const wasClick =
pointer &&
pointer.button === 0 &&
!pointer.moved &&
!gestureMoved;
pointers.delete(event.pointerId);
if (wasClick) pickSector(event);
if (pointers.size === 0) {
gestureMoved = false;
pinchDistance = null;
canvas.classList.remove("dragging");
} else if (pointers.size === 1) {
pinchDistance = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
7.5,
24
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.radius = 13.7;
cameraState.phi = 0.68;
cameraState.theta = 0.68;
cameraState.target.set(0, 0.52, 0);
updateCamera();
});
function setPointerFromEvent(event) {
const rect = canvas.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickSector(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointerNDC, camera);
const intersections = raycaster.intersectObjects(
selectableObjects,
false
);
if (intersections.length) {
const index = intersections[0].object.userData.sectorIndex;
if (Number.isInteger(index)) selectSector(index);
}
}
function updateHover(event) {
setPointerFromEvent(event);
raycaster.setFromCamera(pointerNDC, camera);
const intersections = raycaster.intersectObjects(
selectableObjects,
false
);
canvas.style.cursor = intersections.length ? "pointer" : "grab";
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
updateReadouts();
buildSector(currentTheta, sectorCount);
updateSectorVisuals();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
crystal.rotation.y = elapsed * 0.34;
crystal.rotation.x = Math.sin(elapsed * 0.42) * 0.16;
hubRing.rotation.z = elapsed * 0.08;
backgroundSolids.forEach((solid, index) => {
solid.rotation.y += 0.001 + (index % 3) * 0.0003;
solid.position.y += Math.sin(elapsed * 0.45 + index) * 0.0007;
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```