Prompt specification
Build or customize the Three.js 3D scene "Kaleidoscope mirror wedge section" 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: Kaleidoscope mirror wedge section
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kaleidoscope-mirror-wedge-section-x0345
Scene Description Prompt:
Create a stylized kaleidoscope cutaway with three angled mirrors, colored beads, and an open viewing end. One HTML file using Three.js from cdnjs.
Working Three.js Starter (kaleidoscope-mirror-wedge-section-x0345):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Prism No. 7 — Kaleidoscope Cutaway</title>
<style>
:root {
color-scheme: dark;
--cyan: #72f4ff;
--pink: #ff62ca;
--gold: #ffd58a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 65% 35%, #202044 0%, #101329 32%, #070913 72%),
#070913;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: clamp(24px, 5vw, 58px);
left: clamp(24px, 5vw, 64px);
width: min(310px, 72vw);
pointer-events: none;
color: #f6f4ff;
text-shadow: 0 2px 24px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 14px;
color: var(--cyan);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 28px;
height: 1px;
background: currentColor;
box-shadow: 0 0 10px currentColor;
}
h1 {
margin: 0;
font-size: clamp(48px, 7vw, 86px);
font-weight: 300;
line-height: 0.88;
letter-spacing: -0.065em;
}
h1 span {
display: block;
color: transparent;
-webkit-text-stroke: 1px rgba(255, 255, 255, 0.75);
}
.subtitle {
max-width: 250px;
margin: 22px 0 0;
color: rgba(239, 238, 255, 0.62);
font-size: 13px;
line-height: 1.65;
letter-spacing: 0.025em;
}
.specs {
position: fixed;
top: clamp(24px, 5vw, 54px);
right: clamp(24px, 5vw, 58px);
display: grid;
gap: 9px;
justify-items: end;
pointer-events: none;
color: rgba(255, 255, 255, 0.48);
font-size: 10px;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.specs strong {
color: var(--gold);
font-weight: 600;
}
.instructions {
position: fixed;
left: 50%;
bottom: 26px;
display: flex;
align-items: center;
gap: 12px;
transform: translateX(-50%);
padding: 11px 16px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 999px;
background: rgba(8, 9, 18, 0.58);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(14px);
pointer-events: none;
color: rgba(255, 255, 255, 0.58);
font-size: 10px;
letter-spacing: 0.14em;
text-transform: uppercase;
white-space: nowrap;
}
.instructions i {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--pink);
box-shadow: 0 0 12px var(--pink);
}
@media (max-width: 700px) {
.title-card {
top: 24px;
left: 24px;
}
.subtitle {
display: none;
}
.specs {
display: none;
}
.instructions {
bottom: 18px;
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-card">
<div class="eyebrow">Optical study · 03</div>
<h1>Prism <span>No. 7</span></h1>
<p class="subtitle">
A cutaway study of three angled mirrors, luminous beads,
and the infinite chamber they create.
</p>
</header>
<aside class="specs">
<span>Mirror array <strong>3 × 120°</strong></span>
<span>Viewing end <strong>Open</strong></span>
<span>Optic <strong>Prismatic</strong></span>
</aside>
<div class="instructions">
<i></i>
Drag to orbit · Scroll to zoom · Double-click 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 and scene
// -------------------------------------------------------------------------
const stage = document.querySelector("#stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x070913, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x090b18, 0.022);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, -0.05, 0);
const spherical = new THREE.Spherical(12.2, 1.08, 0.62);
const initialSpherical = spherical.clone();
// -------------------------------------------------------------------------
// Procedural environment map for the reflective surfaces
// -------------------------------------------------------------------------
function createEnvironmentTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const base = ctx.createLinearGradient(0, 0, 0, canvas.height);
base.addColorStop(0, "#24254a");
base.addColorStop(0.45, "#11182d");
base.addColorStop(1, "#050811");
ctx.fillStyle = base;
ctx.fillRect(0, 0, canvas.width, canvas.height);
const lights = [
[170, 120, 210, "#64eaff"],
[620, 100, 260, "#ff5cc8"],
[840, 260, 180, "#ffd27b"],
[410, 330, 300, "#6a80ff"]
];
for (const [x, y, radius, color] of lights) {
const glow = ctx.createRadialGradient(x, y, 0, x, y, radius);
glow.addColorStop(0, color);
glow.addColorStop(0.28, color + "88");
glow.addColorStop(1, color + "00");
ctx.fillStyle = glow;
ctx.fillRect(x - radius, y - radius, radius * 2, radius * 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
scene.environment = createEnvironmentTexture();
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb8eaff, 0x180a2b, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x50eaff, 28, 14, 2);
cyanLight.position.set(-4, 2.5, 3.5);
scene.add(cyanLight);
const pinkLight = new THREE.PointLight(0xff45bf, 24, 12, 2);
pinkLight.position.set(4.5, -1.5, -1.5);
scene.add(pinkLight);
const rearLight = new THREE.PointLight(0xffcc78, 18, 9, 2);
rearLight.position.set(0, 0.7, -4.2);
scene.add(rearLight);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const shellMaterial = new THREE.MeshPhysicalMaterial({
color: 0x44317e,
metalness: 0.48,
roughness: 0.24,
clearcoat: 0.9,
clearcoatRoughness: 0.18,
iridescence: 0.65,
iridescenceIOR: 1.3,
envMapIntensity: 1.25,
side: THREE.FrontSide
});
const innerShellMaterial = new THREE.MeshStandardMaterial({
color: 0x17162c,
metalness: 0.32,
roughness: 0.42,
envMapIntensity: 0.65,
side: THREE.BackSide
});
const goldMaterial = new THREE.MeshStandardMaterial({
color: 0xd7a95b,
metalness: 0.9,
roughness: 0.19,
envMapIntensity: 1.8
});
const paleGoldMaterial = new THREE.MeshStandardMaterial({
color: 0xffdf9b,
metalness: 0.72,
roughness: 0.22,
envMapIntensity: 1.5
});
const cyanMaterial = new THREE.MeshStandardMaterial({
color: 0x79efff,
emissive: 0x1bc8e6,
emissiveIntensity: 1.3,
metalness: 0.35,
roughness: 0.2
});
const mirrorMaterial = new THREE.MeshPhysicalMaterial({
color: 0xc7e9f2,
metalness: 0.88,
roughness: 0.075,
clearcoat: 1,
clearcoatRoughness: 0.06,
emissive: 0x0b2632,
emissiveIntensity: 0.22,
envMapIntensity: 2.2
});
const mirrorEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x7864bc,
metalness: 0.8,
roughness: 0.22,
envMapIntensity: 1.5
});
const beadColors = [
0xff4fba,
0x54e9ff,
0xffd35a,
0x9e72ff,
0x67f2a1,
0xff815e
];
const beadMaterials = beadColors.map((color) =>
new THREE.MeshPhysicalMaterial({
color,
metalness: 0.02,
roughness: 0.13,
clearcoat: 1,
clearcoatRoughness: 0.08,
transmission: 0.12,
thickness: 0.5,
emissive: color,
emissiveIntensity: 0.12,
envMapIntensity: 1.4
})
);
// -------------------------------------------------------------------------
// Kaleidoscope body
// -------------------------------------------------------------------------
const kaleidoscope = new THREE.Group();
scene.add(kaleidoscope);
const bodyLength = 7.4;
const backRadius = 1.68;
const frontRadius = 1.92;
// The retained shell covers approximately 273 degrees, leaving a
// camera-facing wedge open to expose the mirror chamber.
const shellArcLength = 4.77;
const shellThetaStart = 3.05;
const retainedStartAngle = shellThetaStart - Math.PI / 2;
function createShellGeometry(front, back) {
const geometry = new THREE.CylinderGeometry(
front,
back,
bodyLength,
96,
1,
true,
shellThetaStart,
shellArcLength
);
geometry.rotateX(Math.PI / 2);
return geometry;
}
const shell = new THREE.Mesh(
createShellGeometry(frontRadius, backRadius),
shellMaterial
);
shell.castShadow = true;
shell.receiveShadow = true;
kaleidoscope.add(shell);
const innerShell = new THREE.Mesh(
createShellGeometry(frontRadius - 0.17, backRadius - 0.14),
innerShellMaterial
);
innerShell.receiveShadow = true;
kaleidoscope.add(innerShell);
function radiusAtZ(z) {
const t = (z + bodyLength / 2) / bodyLength;
return backRadius + (frontRadius - backRadius) * t;
}
// Decorative partial hoops.
for (const z of [-2.65, -0.7, 1.35]) {
const hoop = new THREE.Mesh(
new THREE.TorusGeometry(
radiusAtZ(z) + 0.012,
0.035,
8,
96,
shellArcLength
),
goldMaterial
);
hoop.rotation.z = retainedStartAngle;
hoop.position.z = z;
hoop.castShadow = true;
kaleidoscope.add(hoop);
}
// Gold rails tracing the two longitudinal cut edges.
function createCutRail(angle) {
const points = [];
for (const z of [-3.7, -1.25, 1.25, 3.7]) {
const radius = radiusAtZ(z) + 0.025;
points.push(
new THREE.Vector3(
radius * Math.cos(angle),
radius * Math.sin(angle),
z
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const rail = new THREE.Mesh(
new THREE.TubeGeometry(curve, 40, 0.038, 8, false),
paleGoldMaterial
);
rail.castShadow = true;
kaleidoscope.add(rail);
}
createCutRail(retainedStartAngle);
createCutRail(retainedStartAngle + shellArcLength - Math.PI * 2);
// -------------------------------------------------------------------------
// Three long mirrors arranged as a triangular optical chamber
// -------------------------------------------------------------------------
const mirrorGroup = new THREE.Group();
kaleidoscope.add(mirrorGroup);
const mirrorAngles = [0, (Math.PI * 2) / 3, (Math.PI * 4) / 3];
const mirrorApothem = 0.79;
const mirrorWidth = 2.64;
const mirrorDepth = 6.52;
mirrorAngles.forEach((angle, index) => {
const assembly = new THREE.Group();
assembly.position.set(
mirrorApothem * Math.cos(angle),
mirrorApothem * Math.sin(angle),
-0.08
);
assembly.rotation.z = angle + Math.PI / 2;
const panel = new THREE.Mesh(
new THREE.BoxGeometry(mirrorWidth, 0.055, mirrorDepth),
mirrorMaterial
);
panel.castShadow = true;
panel.receiveShadow = true;
assembly.add(panel);
// Dark beveled frame.
for (const x of [-mirrorWidth / 2, mirrorWidth / 2]) {
const frame = new THREE.Mesh(
new THREE.BoxGeometry(0.055, 0.095, mirrorDepth + 0.08),
mirrorEdgeMaterial
);
frame.position.x = x;
frame.castShadow = true;
assembly.add(frame);
}
// Thin colored reflection streaks.
const streakColors = [0x58eaff, 0xff5cc5, 0xffd56d];
for (let s = 0; s < 3; s++) {
const geometry = new THREE.PlaneGeometry(0.045, 5.9);
geometry.rotateX(-Math.PI / 2);
const streak = new THREE.Mesh(
geometry,
new THREE.MeshBasicMaterial({
color: streakColors[(s + index) % streakColors.length],
transparent: true,
opacity: 0.1,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide
})
);
streak.position.set(-0.65 + s * 0.62, 0.034, -0.15);
streak.rotation.y = (s - 1) * 0.12;
assembly.add(streak);
}
// Small colored forms on the mirror suggest reflected beads.
for (let r = 0; r < 8; r++) {
const reflection = new THREE.Mesh(
new THREE.SphereGeometry(1, 12, 8),
new THREE.MeshBasicMaterial({
color: beadColors[(r + index * 2) % beadColors.length],
transparent: true,
opacity: 0.58,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
reflection.position.set(
-1.05 + (r / 7) * 2.1,
0.046,
-2.65 + ((r * 0.73 + index * 0.37) % 1) * 5.4
);
reflection.scale.set(0.045, 0.012, 0.045);
assembly.add(reflection);
}
mirrorGroup.add(assembly);
});
// -------------------------------------------------------------------------
// Colored beads
// -------------------------------------------------------------------------
let seed = 718203;
function random() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
const beadGeometry = new THREE.SphereGeometry(1, 20, 14);
const animatedBeads = [];
for (let i = 0; i < 58; i++) {
const radius = 0.065 + random() * 0.105;
const radial = Math.sqrt(random()) * 0.55;
const angle = random() * Math.PI * 2;
const z = -2.85 + random() * 4.95;
const bead = new THREE.Mesh(
beadGeometry,
beadMaterials[Math.floor(random() * beadMaterials.length)]
);
bead.position.set(
radial * Math.cos(angle),
radial * Math.sin(angle),
z
);
bead.scale.setScalar(radius);
bead.castShadow = true;
bead.receiveShadow = true;
kaleidoscope.add(bead);
animatedBeads.push({
mesh: bead,
base: bead.position.clone(),
phase: random() * Math.PI * 2,
amount: 0.008 + random() * 0.014
});
}
// A few larger foreground beads.
for (let i = 0; i < 7; i++) {
const bead = new THREE.Mesh(
beadGeometry,
beadMaterials[(i + 2) % beadMaterials.length]
);
const angle = i * 0.9;
bead.position.set(
Math.cos(angle) * 0.35,
Math.sin(angle) * 0.35,
1.15 + i * 0.15
);
bead.scale.setScalar(0.16 + (i % 3) * 0.025);
bead.castShadow = true;
kaleidoscope.add(bead);
}
// -------------------------------------------------------------------------
// Luminous closed back and kaleidoscope rosette
// -------------------------------------------------------------------------
const backDisc = new THREE.Mesh(
new THREE.CircleGeometry(1.55, 96),
new THREE.MeshStandardMaterial({
color: 0x130f2d,
emissive: 0x4a126c,
emissiveIntensity: 0.9,
metalness: 0.4,
roughness: 0.3
})
);
backDisc.position.z = -3.69;
kaleidoscope.add(backDisc);
const pattern = new THREE.Group();
pattern.position.z = -3.60;
kaleidoscope.add(pattern);
const patternRingMaterial = new THREE.MeshStandardMaterial({
color: 0x80ecff,
emissive: 0x2ac9e9,
emissiveIntensity: 1.15,
metalness: 0.55,
roughness: 0.2
});
for (const radius of [0.28, 0.62, 1.02, 1.39]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(radius, 0.021, 8, 80),
patternRingMaterial
);
pattern.add(ring);
}
const up = new THREE.Vector3(0, 1, 0);
function makeSpoke(angle, length, radius, material) {
const start = new THREE.Vector3(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0
);
const end = new THREE.Vector3(
Math.cos(angle) * 1.38,
Math.sin(angle) * 1.38,
0
);
const direction = end.clone().sub(start);
const spoke = new THREE.Mesh(
new THREE.CylinderGeometry(0.014, 0.014, direction.length(), 6),
material
);
spoke.position.copy(start).add(end).multiplyScalar(0.5);
spoke.quaternion.setFromUnitVectors(up, direction.normalize());
pattern.add(spoke);
}
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
makeSpoke(
angle,
1.2,
i % 2 === 0 ? 0.25 : 0.58,
i % 3 === 0 ? paleGoldMaterial : patternRingMaterial
);
}
const centerGem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.18, 0),
new THREE.MeshPhysicalMaterial({
color: 0xff73cc,
emissive: 0xdb287f,
emissiveIntensity: 1.2,
metalness: 0.35,
roughness: 0.12,
clearcoat: 1
})
);
centerGem.position.z = 0.03;
pattern.add(centerGem);
// Small points around the rosette.
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const radius = i % 2 === 0 ? 1.22 : 0.87;
const point = new THREE.Mesh(
new THREE.SphereGeometry(0.035, 10, 8),
beadMaterials[i % beadMaterials.length]
);
point.position.set(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0.045
);
pattern.add(point);
}
// Soft glow behind the beads.
function createGlowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
const gradient = ctx.createRadialGradient(128, 128, 0, 128, 128, 128);
gradient.addColorStop(0, "rgba(255,120,220,0.85)");
gradient.addColorStop(0.2, "rgba(111,90,255,0.34)");
gradient.addColorStop(1, "rgba(0,0,0,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, 256, 256);
return new THREE.CanvasTexture(canvas);
}
const glow = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createGlowTexture(),
color: 0xff8de0,
transparent: true,
opacity: 0.46,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
glow.position.set(0, 0, -3.42);
glow.scale.set(4.4, 4.4, 1);
kaleidoscope.add(glow);
// -------------------------------------------------------------------------
// Open viewing end
// -------------------------------------------------------------------------
const frontAnnulus = new THREE.Mesh(
new THREE.RingGeometry(1.59, 2.035, 96),
new THREE.MeshPhysicalMaterial({
color: 0x6850a8,
metalness: 0.72,
roughness: 0.2,
clearcoat: 0.8,
envMapIntensity: 1.65,
side: THREE.DoubleSide
})
);
frontAnnulus.position.z = 3.72;
frontAnnulus.castShadow = true;
kaleidoscope.add(frontAnnulus);
const frontRim = new THREE.Mesh(
new THREE.TorusGeometry(1.91, 0.115, 12, 96),
goldMaterial
);
frontRim.position.z = 3.77;
frontRim.castShadow = true;
kaleidoscope.add(frontRim);
const innerRim = new THREE.Mesh(
new THREE.TorusGeometry(1.60, 0.033, 8, 96),
cyanMaterial
);
innerRim.position.z = 3.78;
kaleidoscope.add(innerRim);
const rearRim = new THREE.Mesh(
new THREE.TorusGeometry(1.68, 0.085, 10, 96),
goldMaterial
);
rearRim.position.z = -3.72;
rearRim.castShadow = true;
kaleidoscope.add(rearRim);
// Decorative studs around the open rim.
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2;
const stud = new THREE.Mesh(
new THREE.SphereGeometry(0.043, 12, 8),
i % 4 === 0 ? cyanMaterial : paleGoldMaterial
);
stud.position.set(
1.81 * Math.cos(angle),
1.81 * Math.sin(angle),
3.86
);
stud.castShadow = true;
kaleidoscope.add(stud);
}
// -------------------------------------------------------------------------
// Ground and subtle platform reflection
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x090b15,
metalness: 0.08,
roughness: 0.86
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.91;
floor.receiveShadow = true;
scene.add(floor);
const halo = new THREE.Mesh(
new THREE.CircleGeometry(4.4, 80),
new THREE.MeshBasicMaterial({
color: 0x312866,
transparent: true,
opacity: 0.11,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = -1.9;
scene.add(halo);
// -------------------------------------------------------------------------
// Direct camera controls
// -------------------------------------------------------------------------
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;
spherical.theta -= dx * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi + dy * 0.005,
0.34,
1.48
);
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
8.1,
18
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
spherical.copy(initialSpherical);
});
function updateCamera() {
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
for (const item of animatedBeads) {
item.mesh.position.x =
item.base.x + Math.sin(elapsed * 0.8 + item.phase) * item.amount;
item.mesh.position.y =
item.base.y + Math.cos(elapsed * 0.65 + item.phase) * item.amount;
item.mesh.position.z =
item.base.z + Math.sin(elapsed * 0.45 + item.phase) * 0.014;
item.mesh.rotation.y += 0.003;
}
pattern.rotation.z = elapsed * 0.075;
centerGem.rotation.x = elapsed * 0.45;
centerGem.rotation.y = elapsed * 0.7;
mirrorMaterial.emissiveIntensity =
0.2 + Math.sin(elapsed * 0.65) * 0.035;
cyanMaterial.emissiveIntensity =
1.2 + Math.sin(elapsed * 1.2) * 0.16;
glow.material.opacity = 0.4 + Math.sin(elapsed * 0.9) * 0.055;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateCamera();
animate();
</script>
</body>
</html>
```