Prompt specification
Build or customize the Three.js 3D scene "Two Characters Around an Opaque Screen" 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: Two Characters Around an Opaque Screen
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-characters-around-an-opaque-screen-x3749
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Model two characters and an object hidden from only one viewpoint. Display each view separately and distinguish occlusion from absence of the object.
Working Three.js Starter (two-characters-around-an-opaque-screen-x3749):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Hidden Crystal — Two Views</title>
<style>
:root {
--ink: #24313b;
--muted: #687681;
--paper: #f5f1e9;
--panel: #fffdf8;
--line: #ddd8ce;
--gold: #e5a934;
--green: #2f8f68;
--red: #c9574f;
--blue: #357d8d;
--coral: #d96d57;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background:
radial-gradient(circle at 15% 0%, #fffdf8 0, transparent 35%),
var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
padding: clamp(18px, 3vw, 42px);
}
header {
max-width: 1440px;
margin: 0 auto 24px;
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 24px;
align-items: end;
}
.eyebrow {
margin: 0 0 8px;
color: var(--muted);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(2rem, 5vw, 4.6rem);
line-height: 0.96;
letter-spacing: -0.055em;
}
.intro {
max-width: 670px;
margin: 14px 0 0;
color: var(--muted);
font-size: clamp(0.94rem, 1.5vw, 1.08rem);
line-height: 1.6;
}
.inventory {
min-width: 250px;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(255, 253, 248, 0.8);
box-shadow: 0 12px 35px rgba(36, 49, 59, 0.06);
}
.inventory-title {
display: flex;
align-items: center;
gap: 9px;
font-size: 0.82rem;
font-weight: 800;
}
.inventory-dot {
width: 13px;
height: 13px;
flex: 0 0 auto;
border-radius: 4px;
background: var(--gold);
box-shadow:
inset 2px 2px 0 rgba(255, 255, 255, 0.35),
0 0 0 3px rgba(229, 169, 52, 0.16);
transform: rotate(15deg);
}
.inventory p {
margin: 8px 0 0;
color: var(--muted);
font-size: 0.76rem;
line-height: 1.45;
}
main {
max-width: 1440px;
margin: 0 auto;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
}
.view {
overflow: hidden;
border: 1px solid var(--line);
border-radius: 22px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(36, 49, 59, 0.08),
0 2px 6px rgba(36, 49, 59, 0.03);
}
.view-header {
min-height: 74px;
padding: 16px 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
border-bottom: 1px solid var(--line);
}
.view-heading {
display: flex;
align-items: center;
gap: 12px;
}
.view-number {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border-radius: 11px;
background: var(--ink);
color: white;
font-size: 0.72rem;
font-weight: 900;
letter-spacing: 0.06em;
}
.view-title {
display: block;
font-size: 0.83rem;
font-weight: 900;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.view-subtitle {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 0.72rem;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border-radius: 999px;
background: #ece8df;
color: #59636b;
font-size: 0.66rem;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.status::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: currentColor;
content: "";
}
.status.visible {
background: rgba(47, 143, 104, 0.13);
color: var(--green);
}
.status.occluded {
background: rgba(229, 169, 52, 0.17);
color: #9a6810;
}
.status.outside {
background: #ece8df;
color: #68727a;
}
.status.absent {
background: rgba(201, 87, 79, 0.13);
color: var(--red);
}
.stage {
position: relative;
height: clamp(360px, 54vh, 650px);
overflow: hidden;
background: #eee8dd;
}
.stage canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
.stage canvas:active {
cursor: grabbing;
}
.stage canvas:focus-visible {
outline: 3px solid var(--gold);
outline-offset: -3px;
}
.view-footer {
padding: 15px 18px 17px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
.explanation {
margin: 0;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.5;
}
.explanation strong {
color: var(--ink);
}
.reset {
flex: 0 0 auto;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: white;
color: var(--ink);
font: inherit;
font-size: 0.72rem;
font-weight: 800;
cursor: pointer;
}
.reset:hover {
border-color: #bdb6aa;
background: #faf7f1;
}
.controls {
max-width: 1440px;
margin: 17px auto 0;
color: var(--muted);
text-align: center;
font-size: 0.74rem;
letter-spacing: 0.02em;
}
.controls span {
margin: 0 7px;
opacity: 0.45;
}
@media (max-width: 850px) {
header {
grid-template-columns: 1fr;
}
.inventory {
min-width: 0;
}
main {
grid-template-columns: 1fr;
}
.stage {
height: min(62vh, 520px);
min-height: 360px;
}
}
@media (max-width: 480px) {
body {
padding: 12px;
}
.view-header,
.view-footer {
align-items: flex-start;
flex-direction: column;
}
.status {
align-self: flex-start;
}
}
</style>
</head>
<body>
<header>
<div>
<p class="eyebrow">One scene · two viewpoints · one hidden object</p>
<h1>The Hidden Crystal</h1>
<p class="intro">
Ari stands directly in front of the gold crystal in the frontal view.
Move to the second camera and the crystal appears. Its pixels change;
the object never leaves the scene.
</p>
</div>
<aside class="inventory" aria-label="Scene object inventory">
<div class="inventory-title">
<span class="inventory-dot" aria-hidden="true"></span>
Gold crystal · present
</div>
<p>
The same crystal is rendered by both cameras. “Occluded” means hidden
by another object, not absent from the world.
</p>
</aside>
</header>
<main>
<section class="view" aria-labelledby="view-a-title">
<div class="view-header">
<div class="view-heading">
<span class="view-number">01</span>
<div>
<span class="view-title" id="view-a-title">Frontal axis</span>
<span class="view-subtitle">Ari is aligned with the crystal</span>
</div>
</div>
<span class="status occluded" data-status aria-live="polite">
Object occluded
</span>
</div>
<div class="stage" data-stage="a"></div>
<div class="view-footer">
<p class="explanation" data-explanation>
<strong>Present, not missing:</strong> Ari blocks the crystal from this
camera.
</p>
<button class="reset" type="button" data-reset="a">Reset camera</button>
</div>
</section>
<section class="view" aria-labelledby="view-b-title">
<div class="view-header">
<div class="view-heading">
<span class="view-number">02</span>
<div>
<span class="view-title" id="view-b-title">Three-quarter view</span>
<span class="view-subtitle">The camera clears Ari’s silhouette</span>
</div>
</div>
<span class="status visible" data-status aria-live="polite">
Object visible
</span>
</div>
<div class="stage" data-stage="b"></div>
<div class="view-footer">
<p class="explanation" data-explanation>
<strong>Same object:</strong> the gold crystal is clearly visible
beyond Ari.
</p>
<button class="reset" type="button" data-reset="b">Reset camera</button>
</div>
</section>
</main>
<p class="controls">
Drag to orbit <span>•</span> Scroll to zoom <span>•</span>
Double-click or press R to reset
</p>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2ede4);
scene.fog = new THREE.Fog(0xf2ede4, 12, 24);
const hemisphere = new THREE.HemisphereLight(
0xfff9ed,
0x81929a,
2.15
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d9, 3.1);
sun.position.set(-4.5, 8, 5.5);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xa8d8ef, 1.1);
rim.position.set(6, 4, -5);
scene.add(rim);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe7e0d5,
roughness: 0.96
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0xf8f4ec,
roughness: 0.82
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(5, 5.15, 0.24, 64),
platformMaterial
);
platform.position.y = -0.12;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0xd9d0c2,
roughness: 0.9
});
const floorRing = new THREE.Mesh(
new THREE.TorusGeometry(3.85, 0.025, 8, 96),
ringMaterial
);
floorRing.rotation.x = Math.PI / 2;
floorRing.position.y = 0.012;
scene.add(floorRing);
// Small platform markers add scale and graphic structure.
const markerColors = [0x6b9eaa, 0xe4ad55, 0xd77b65, 0x8d9e8a];
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const marker = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.075, 0.035, 16),
new THREE.MeshStandardMaterial({
color: markerColors[i % markerColors.length],
roughness: 0.7
})
);
marker.position.set(
Math.cos(angle) * 4.35,
0.025,
Math.sin(angle) * 4.35
);
marker.receiveShadow = true;
scene.add(marker);
}
// -------------------------------------------------------------------------
// Characters
// -------------------------------------------------------------------------
function createCharacter({
name,
coatColor,
accentColor,
hairColor,
position
}) {
const root = new THREE.Group();
root.position.copy(position);
root.userData.isCharacter = true;
root.userData.name = name;
const coat = new THREE.MeshStandardMaterial({
color: coatColor,
roughness: 0.72,
metalness: 0.02
});
const accent = new THREE.MeshStandardMaterial({
color: accentColor,
roughness: 0.65
});
const hair = new THREE.MeshStandardMaterial({
color: hairColor,
roughness: 0.85
});
const skin = new THREE.MeshStandardMaterial({
color: 0xf1c7a5,
roughness: 0.9
});
const dark = new THREE.MeshStandardMaterial({
color: 0x25313a,
roughness: 0.75
});
const white = new THREE.MeshStandardMaterial({
color: 0xfffdf7,
roughness: 0.8
});
function addMesh(geometry, material, x, y, z) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
root.add(mesh);
return mesh;
}
// Legs and boots.
const legGeometry = new THREE.CapsuleGeometry(0.17, 0.45, 5, 10);
const leftLeg = addMesh(legGeometry, dark, -0.27, 0.42, 0);
const rightLeg = addMesh(legGeometry, dark, 0.27, 0.42, 0);
leftLeg.rotation.z = -0.025;
rightLeg.rotation.z = 0.025;
const bootGeometry = new THREE.SphereGeometry(0.24, 16, 10);
const leftBoot = addMesh(bootGeometry, accent, -0.27, 0.08, 0.13);
const rightBoot = addMesh(bootGeometry, accent, 0.27, 0.08, 0.13);
leftBoot.scale.set(1.05, 0.58, 1.5);
rightBoot.scale.set(1.05, 0.58, 1.5);
// Broad torso: this is the principal occluder in View 01.
const torso = addMesh(
new THREE.CapsuleGeometry(0.52, 0.72, 7, 16),
coat,
0,
1.11,
0
);
torso.scale.z = 0.77;
const belt = addMesh(
new THREE.TorusGeometry(0.49, 0.055, 8, 32),
accent,
0,
0.78,
0.02
);
belt.rotation.x = Math.PI / 2;
belt.scale.z = 0.82;
// Arms.
const armGeometry = new THREE.CapsuleGeometry(0.145, 0.58, 5, 10);
const handGeometry = new THREE.SphereGeometry(0.16, 14, 10);
const leftArm = addMesh(armGeometry, coat, -0.66, 1.13, 0.02);
const rightArm = addMesh(armGeometry, coat, 0.66, 1.13, 0.02);
leftArm.rotation.z = -0.18;
rightArm.rotation.z = 0.18;
addMesh(handGeometry, skin, -0.76, 0.73, 0.06);
addMesh(handGeometry, skin, 0.76, 0.73, 0.06);
// Neck and head.
addMesh(
new THREE.CylinderGeometry(0.15, 0.17, 0.18, 16),
skin,
0,
1.94,
0
);
addMesh(
new THREE.SphereGeometry(0.43, 24, 16),
skin,
0,
2.23,
0
);
// Rounded top hemisphere as stylized hair.
addMesh(
new THREE.SphereGeometry(
0.445,
24,
12,
0,
Math.PI * 2,
0,
Math.PI / 2
),
hair,
0,
2.225,
-0.015
);
// Face.
const eyeGeometry = new THREE.SphereGeometry(0.055, 12, 8);
addMesh(eyeGeometry, dark, -0.14, 2.26, 0.405);
addMesh(eyeGeometry, dark, 0.14, 2.26, 0.405);
const eyeGlintGeometry = new THREE.SphereGeometry(0.016, 8, 6);
addMesh(
eyeGlintGeometry,
white,
-0.128,
2.277,
0.455
);
addMesh(
eyeGlintGeometry,
white,
0.152,
2.277,
0.455
);
const mouth = addMesh(
new THREE.BoxGeometry(0.13, 0.026, 0.018),
dark,
0,
2.055,
0.39
);
mouth.rotation.z = 0.02;
// Small chest badge.
const badge = addMesh(
new THREE.CylinderGeometry(0.12, 0.12, 0.026, 20),
accent,
0,
1.42,
0.405
);
badge.rotation.x = Math.PI / 2;
scene.add(root);
return root;
}
const ari = createCharacter({
name: "Ari",
coatColor: 0x357d8d,
accentColor: 0xf2b84b,
hairColor: 0x293845,
position: new THREE.Vector3(0, 0, 0.75)
});
const nora = createCharacter({
name: "Nora",
coatColor: 0xd96d57,
accentColor: 0x694f58,
hairColor: 0x533f3a,
position: new THREE.Vector3(-2.65, 0, -0.55)
});
nora.rotation.y = -0.12;
// -------------------------------------------------------------------------
// The object: always present, sometimes hidden
// -------------------------------------------------------------------------
const crystal = new THREE.Group();
crystal.name = "Gold crystal";
crystal.position.set(0, 1.28, -1.75);
const crystalMaterial = new THREE.MeshStandardMaterial({
color: 0xe7ad35,
emissive: 0x7d3f05,
emissiveIntensity: 0.34,
metalness: 0.48,
roughness: 0.23,
flatShading: true
});
const crystalMesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.39, 0),
crystalMaterial
);
crystalMesh.castShadow = true;
crystalMesh.receiveShadow = true;
crystal.add(crystalMesh);
const crystalGlow = new THREE.PointLight(0xffb638, 0.8, 2.2, 2);
crystal.add(crystalGlow);
scene.add(crystal);
// -------------------------------------------------------------------------
// Independent cameras and direct camera controls
// -------------------------------------------------------------------------
const characterRoots = [ari, nora];
const raycaster = new THREE.Raycaster();
const frustum = new THREE.Frustum();
const projectionMatrix = new THREE.Matrix4();
function createView({
stage,
statusElement,
explanationElement,
initialPosition,
initialTarget
}) {
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"Interactive 3D view. Drag to orbit, scroll to zoom, and press R to reset."
);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 50);
const target = initialTarget.clone();
const resetPosition = initialPosition.clone();
const resetTarget = initialTarget.clone();
const spherical = new THREE.Spherical();
function applyCamera() {
spherical.setFromVector3(camera.position.clone().sub(target));
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
camera.updateMatrixWorld();
}
function reset() {
target.copy(resetTarget);
camera.position.copy(resetPosition);
applyCamera();
}
reset();
function resize() {
const width = Math.max(1, stage.clientWidth);
const height = Math.max(1, stage.clientHeight);
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
spherical.setFromVector3(camera.position.clone().sub(target));
spherical.theta -= deltaX * 0.006;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - deltaY * 0.006,
0.35,
Math.PI - 0.35
);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
spherical.setFromVector3(camera.position.clone().sub(target));
spherical.radius = THREE.MathUtils.clamp(
spherical.radius * Math.exp(event.deltaY * 0.001),
4.3,
13
);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
},
{ passive: false }
);
canvas.addEventListener("dblclick", reset);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key.toLowerCase()) {
case "arrowleft":
spherical.theta -= 0.08;
break;
case "arrowright":
spherical.theta += 0.08;
break;
case "arrowup":
spherical.phi = Math.max(0.35, spherical.phi - 0.08);
break;
case "arrowdown":
spherical.phi = Math.min(Math.PI - 0.35, spherical.phi + 0.08);
break;
case "+":
case "=":
spherical.radius = Math.max(4.3, spherical.radius - 0.4);
break;
case "-":
spherical.radius = Math.min(13, spherical.radius + 0.4);
break;
case "r":
reset();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
}
});
function updateStatus() {
const objectPosition = new THREE.Vector3();
crystal.getWorldPosition(objectPosition);
if (!crystal.visible) {
statusElement.className = "status absent";
statusElement.textContent = "Object absent";
explanationElement.innerHTML =
"<strong>Absent:</strong> the crystal is not present in the scene.";
return;
}
camera.updateMatrixWorld();
projectionMatrix.multiplyMatrices(
camera.projectionMatrix,
camera.matrixWorldInverse
);
frustum.setFromProjectionMatrix(projectionMatrix);
const inFrustum = frustum.containsPoint(objectPosition);
const direction = objectPosition.clone().sub(camera.position);
const objectDistance = direction.length();
raycaster.set(camera.position, direction.normalize());
raycaster.near = 0;
raycaster.far = objectDistance;
const hits = raycaster.intersectObjects(characterRoots, true);
const blockingHit = hits.find(
(hit) => hit.distance < objectDistance - 0.025
);
if (inFrustum && blockingHit) {
let owner = blockingHit.object;
while (owner && !owner.userData.isCharacter) {
owner = owner.parent;
}
const ownerName = owner?.userData.name ?? "a character";
statusElement.className = "status occluded";
statusElement.textContent = "Object occluded";
explanationElement.innerHTML =
`<strong>Present, not missing:</strong> ` +
`${ownerName} blocks the crystal from this camera.`;
} else if (inFrustum) {
statusElement.className = "status visible";
statusElement.textContent = "Object visible";
explanationElement.innerHTML =
"<strong>Same object:</strong> the gold crystal is visible in this view.";
} else {
statusElement.className = "status outside";
statusElement.textContent = "Outside frame";
explanationElement.innerHTML =
"<strong>Still present:</strong> the crystal is outside this camera’s frame.";
}
}
return {
renderer,
camera,
reset,
updateStatus
};
}
const viewA = createView({
stage: document.querySelector('[data-stage="a"]'),
statusElement: document.querySelector(
'[data-stage="a"]'
).closest(".view").querySelector("[data-status]"),
explanationElement: document.querySelector(
'[data-stage="a"]'
).closest(".view").querySelector("[data-explanation]"),
initialPosition: new THREE.Vector3(0, 2.1, 8.5),
initialTarget: new THREE.Vector3(0, 1.05, -0.55)
});
const viewB = createView({
stage: document.querySelector('[data-stage="b"]'),
statusElement: document.querySelector(
'[data-stage="b"]'
).closest(".view").querySelector("[data-status]"),
explanationElement: document.querySelector(
'[data-stage="b"]'
).closest(".view").querySelector("[data-explanation]"),
initialPosition: new THREE.Vector3(5.5, 3.0, 7.2),
initialTarget: new THREE.Vector3(-0.45, 1.0, -0.65)
});
document.querySelectorAll("[data-reset]").forEach((button) => {
button.addEventListener("click", () => {
const id = button.dataset.reset;
if (id === "a") viewA.reset();
if (id === "b") viewB.reset();
});
});
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
crystal.rotation.y = elapsed * 0.55;
crystal.rotation.x = Math.sin(elapsed * 0.7) * 0.12;
crystal.position.y = 1.28 + Math.sin(elapsed * 1.6) * 0.035;
crystalMaterial.emissiveIntensity =
0.3 + Math.sin(elapsed * 2.2) * 0.07;
viewA.updateStatus();
viewB.updateStatus();
viewA.renderer.render(scene, viewA.camera);
viewB.renderer.render(scene, viewB.camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```