Prompt specification
Build or customize the Three.js 3D scene "Flipbook frame stack" 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: Flipbook frame stack
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/flipbook-frame-stack-x0333
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a flipbook. Display a small book with successive ball positions drawn as raised simple shapes on separated pages; the ordered changes should remain visible along the fanned edge. Voxel style.
Technical checks: Show the changing ball positions at frame selections 1, 6, and 11. Keep the intermediate positions visible along the fanned edge without pages hiding the sequence.
Return one complete HTML document that works with the cdnjs Three.js r160 module inside a sandbox with scripts allowed. Make the requested subject visible at the default camera. Use procedural assets and local button handlers. Do not use native form submission, pointer lock, external assets or runtime requests other than Three.js.
Working Three.js Starter (flipbook-frame-stack-x0333):
```html
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flipbook Voxel — Sequência da Bola</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(9, 19, 33, 0.88);
--line: rgba(148, 210, 255, 0.22);
--text: #eaf6ff;
--muted: #92abc0;
--accent: #55e6c1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091321;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage,
#labels {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#labels {
pointer-events: none;
z-index: 3;
overflow: hidden;
}
.step-label {
position: absolute;
min-width: 24px;
padding: 2px 5px;
border: 1px solid rgba(255, 255, 255, 0.28);
border-radius: 3px;
background: rgba(6, 15, 27, 0.84);
color: white;
font: 700 10px/1.15 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: center;
transform: translate(-50%, -100%);
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
will-change: left, top;
}
.step-label.active {
color: #07121d;
border-color: white;
background: white;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--line);
border-radius: 8px;
background: var(--panel);
color: var(--text);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
}
#intro {
top: 18px;
left: 18px;
width: min(390px, calc(100vw - 36px));
padding: 15px 17px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--accent);
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.17em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(19px, 3vw, 27px);
line-height: 1.08;
letter-spacing: -0.035em;
}
#intro p {
margin: 9px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
#statusPanel {
top: 18px;
right: 18px;
width: min(295px, calc(100vw - 36px));
padding: 12px 14px;
font: 600 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#status {
color: var(--accent);
}
#statusDetail {
margin-top: 4px;
color: var(--muted);
font-size: 10px;
font-weight: 500;
}
#controls {
right: 18px;
bottom: 18px;
left: 18px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 12px 14px;
overflow: auto;
}
.control-group {
display: flex;
align-items: center;
gap: 7px;
flex: 0 0 auto;
}
.control-label {
margin-right: 3px;
color: var(--muted);
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
button {
min-width: 36px;
height: 34px;
padding: 0 10px;
border: 1px solid rgba(160, 213, 255, 0.25);
border-radius: 4px;
background: rgba(29, 51, 73, 0.88);
color: var(--text);
font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
cursor: pointer;
transition: background 120ms ease, border-color 120ms ease, transform 120ms ease;
}
button:hover {
border-color: var(--accent);
background: rgba(42, 83, 101, 0.95);
}
button:active {
transform: translateY(1px);
}
button.active {
border-color: white;
background: white;
color: #081421;
}
#play {
min-width: 112px;
border-color: rgba(85, 230, 193, 0.6);
color: var(--accent);
}
.frame-buttons {
display: flex;
gap: 5px;
}
.frame-buttons button {
min-width: 38px;
padding: 0 7px;
}
.fan-control {
display: flex;
align-items: center;
gap: 9px;
min-width: 235px;
}
input[type="range"] {
width: 145px;
accent-color: var(--accent);
cursor: pointer;
}
#fanValue {
min-width: 42px;
color: var(--accent);
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
#legend {
display: flex;
align-items: center;
gap: 3px;
flex: 0 0 auto;
}
.swatch {
width: 12px;
height: 22px;
border-radius: 2px;
box-shadow: inset 0 -3px rgba(0, 0, 0, 0.16);
}
#help {
position: fixed;
right: 20px;
bottom: 107px;
z-index: 9;
color: rgba(215, 235, 248, 0.66);
font: 500 10px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-align: right;
pointer-events: none;
text-shadow: 0 2px 6px #000;
}
@media (max-width: 820px) {
#intro {
width: calc(100vw - 36px);
}
#intro p {
display: none;
}
#statusPanel {
top: 112px;
left: 18px;
right: auto;
width: calc(100vw - 36px);
}
#controls {
gap: 11px;
flex-wrap: wrap;
justify-content: flex-start;
}
.fan-control {
min-width: 210px;
}
#help {
display: none;
}
}
@media (max-width: 480px) {
#statusPanel {
top: 104px;
}
#controls {
right: 10px;
bottom: 10px;
left: 10px;
}
.control-label {
display: none;
}
.fan-control {
width: 100%;
}
input[type="range"] {
flex: 1;
}
#legend {
display: none;
}
}
</style>
</head>
<body>
<div id="stage" aria-label="Cena 3D interativa de um flipbook voxel"></div>
<div id="labels" aria-hidden="true"></div>
<section id="intro" class="panel">
<div class="eyebrow">Laboratório de movimento</div>
<h1>Flipbook da Bola Voxel</h1>
<p>
Os 12 quadros permanecem Simultaneamente visíveis. Cada bola é uma peça
elevada no margen exterior das folhas, evitando que a dobra ou páginas
vizinhas escondam a sequência.
</p>
</section>
<aside id="statusPanel" class="panel" aria-live="polite">
<div id="status">12/12 passos no quadro</div>
<div id="statusDetail">12/12 fora da área da dobra</div>
</aside>
<footer id="controls" class="panel">
<div class="control-group">
<span class="control-label">Quadro</span>
<button id="previous" type="button" title="Quadro anterior">‹</button>
<button id="play" type="button">▶ Reproduzir</button>
<button id="next" type="button" title="Próximo quadro">›</button>
</div>
<div class="control-group frame-buttons" aria-label="Quadros selecionados">
<button type="button" data-frame="0">01</button>
<button type="button" data-frame="5">06</button>
<button type="button" data-frame="10">11</button>
</div>
<div class="control-group fan-control">
<label class="control-label" for="fan">Leque</label>
<input id="fan" type="range" min="85" max="125" step="1" value="105"
aria-label="Abertura do leque em graus">
<output id="fanValue" for="fan">105°</output>
</div>
<div class="control-group">
<span class="control-label">Ordem</span>
<div id="legend" aria-label="Legenda de cores em ordem"></div>
</div>
<div class="control-group">
<button id="resetView" type="button">Reenquadrar</button>
</div>
</footer>
<div id="help">
Arraste para orbitar · roda para zoom<br>
duplo clique para reenquadrar
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const FRAME_COUNT = 12;
const PAGE_WIDTH = 2.15;
const PAGE_DEPTH = 1.25;
const HINGE_X = -1.18;
const PAGE_THICKNESS = 0.052;
const stage = document.getElementById("stage");
const labelsLayer = document.getElementById("labels");
const statusElement = document.getElementById("status");
const statusDetail = document.getElementById("statusDetail");
const fanInput = document.getElementById("fan");
const fanValue = document.getElementById("fanValue");
const playButton = document.getElementById("play");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091321);
scene.fog = new THREE.Fog(0x091321, 13, 28);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("tabindex", "0");
renderer.domElement.setAttribute(
"aria-label",
"Arraste para orbitar o flipbook. Use os botões para selecionar quadros."
);
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc8e7ff, 0x172238, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff2d9, 3.1);
keyLight.position.set(4.5, 8, 3.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x58d8ff, 1.4);
rimLight.position.set(-5, 3.5, -4);
scene.add(rimLight);
const book = new THREE.Group();
scene.add(book);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x0a1726,
roughness: 0.96,
metalness: 0.02
});
const ground = new THREE.Mesh(
new THREE.BoxGeometry(10, 0.18, 7),
groundMaterial
);
ground.position.set(0, -0.38, 0);
ground.receiveShadow = true;
scene.add(ground);
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x10283a,
roughness: 0.78,
metalness: 0.08
});
const platform = new THREE.Mesh(
new THREE.BoxGeometry(3.75, 0.18, 3.15),
platformMaterial
);
platform.position.set(-0.08, -0.19, 0);
platform.receiveShadow = true;
book.add(platform);
const coverMaterial = new THREE.MeshStandardMaterial({
color: 0x164b5c,
roughness: 0.72,
metalness: 0.08
});
const cover = new THREE.Mesh(
new THREE.BoxGeometry(PAGE_WIDTH + 0.42, 0.14, PAGE_DEPTH + 0.46),
coverMaterial
);
cover.position.set(HINGE_X + PAGE_WIDTH * 0.5, 0.005, 0);
cover.castShadow = true;
cover.receiveShadow = true;
book.add(cover);
const coverEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x0c2939,
roughness: 0.8
});
const coverLip = new THREE.Mesh(
new THREE.BoxGeometry(PAGE_WIDTH + 0.48, 0.07, PAGE_DEPTH + 0.52),
coverEdgeMaterial
);
coverLip.position.set(
HINGE_X + PAGE_WIDTH * 0.5,
-0.045,
0
);
coverLip.castShadow = true;
book.add(coverLip);
const spineMaterial = new THREE.MeshStandardMaterial({
color: 0x0b2d3d,
roughness: 0.8
});
const spineGeometry = new THREE.BoxGeometry(0.23, 0.22, 0.23);
for (let i = 0; i < 6; i++) {
const spineBlock = new THREE.Mesh(spineGeometry, spineMaterial);
spineBlock.position.set(
HINGE_X - 0.12,
0.105,
(i - 2.5) * 0.245
);
spineBlock.castShadow = true;
book.add(spineBlock);
}
const sharedPageGeometry = new THREE.BoxGeometry(
PAGE_WIDTH,
PAGE_THICKNESS,
PAGE_DEPTH
);
const sharedRuleGeometry = new THREE.BoxGeometry(0.34, 0.012, 0.035);
const sharedEdgeGeometry = new THREE.BoxGeometry(0.065, 0.075, PAGE_DEPTH * 0.84);
const sharedShelfGeometry = new THREE.BoxGeometry(0.42, 0.07, 0.36);
const sharedStemGeometry = new THREE.BoxGeometry(0.045, 0.35, 0.045);
const sharedVoxelGeometry = new THREE.BoxGeometry(0.052, 0.052, 0.052);
const voxelOffsets = [];
for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
for (let z = -1; z <= 1; z++) {
if (x * x + y * y + z * z <= 2) {
voxelOffsets.push(new THREE.Vector3(x, y, z));
}
}
}
}
const markerBalls = [];
const markerGroups = [];
const pagePivots = [];
const pageMaterials = [];
const markerMaterials = [];
const frameColors = [];
for (let frame = 0; frame < FRAME_COUNT; frame++) {
const t = frame / (FRAME_COUNT - 1);
const color = new THREE.Color().setHSL(
0.12 + t * 0.39,
0.86,
0.59
);
frameColors.push(color);
const pivot = new THREE.Group();
pivot.position.set(HINGE_X, 0.115 + frame * 0.007, 0);
book.add(pivot);
pagePivots.push(pivot);
const pageMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL(
0.105,
0.22,
0.80 + (frame % 2) * 0.025
),
roughness: 0.9,
metalness: 0,
emissive: 0x000000,
emissiveIntensity: 0
});
pageMaterials.push(pageMaterial);
const page = new THREE.Mesh(sharedPageGeometry, pageMaterial);
page.position.set(PAGE_WIDTH * 0.5, 0, 0);
page.castShadow = true;
page.receiveShadow = true;
page.userData.frame = frame;
pivot.add(page);
const ruleMaterial = new THREE.MeshStandardMaterial({
color: 0x9ea99e,
roughness: 1,
transparent: true,
opacity: 0.52
});
for (let line = 0; line < 3; line++) {
const rule = new THREE.Mesh(sharedRuleGeometry, ruleMaterial);
rule.position.set(
0.50 + line * 0.43,
PAGE_THICKNESS * 0.5 + 0.008,
0.34
);
pivot.add(rule);
}
const edgeMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.62,
emissive: color.clone().multiplyScalar(0.12),
emissiveIntensity: 0.3
});
const edge = new THREE.Mesh(sharedEdgeGeometry, edgeMaterial);
edge.position.set(PAGE_WIDTH - 0.005, 0.042, 0);
edge.castShadow = true;
pivot.add(edge);
const shelf = new THREE.Mesh(sharedShelfGeometry, edgeMaterial);
shelf.position.set(PAGE_WIDTH + 0.14, 0.045, 0);
shelf.castShadow = true;
pivot.add(shelf);
const marker = new THREE.Group();
// A geometria real fica inteiramente fora da área da folha.
// O deslocamento radial growing mantém os passos separados no arco.
marker.position.set(
PAGE_WIDTH + 0.18 + frame * 0.012,
0.43,
0
);
pivot.add(marker);
markerGroups.push(marker);
const stem = new THREE.Mesh(
sharedStemGeometry,
new THREE.MeshStandardMaterial({
color: 0x28495a,
roughness: 0.78
})
);
stem.position.y = -0.18;
stem.castShadow = true;
marker.add(stem);
const markerMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
metalness: 0.05,
emissive: color.clone().multiplyScalar(0.08),
emissiveIntensity: 0.18,
depthTest: false,
depthWrite: false
});
markerMaterials.push(markerMaterial);
const ball = new THREE.InstancedMesh(
sharedVoxelGeometry,
markerMaterial,
voxelOffsets.length
);
const transform = new THREE.Object3D();
voxelOffsets.forEach((offset, index) => {
transform.position.copy(offset).multiplyScalar(0.052);
transform.updateMatrix();
ball.setMatrixAt(index, transform.matrix);
});
ball.instanceMatrix.needsUpdate = true;
ball.userData.frame = frame;
ball.renderOrder = 40 + frame;
marker.add(ball);
markerBalls.push(ball);
const crownMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.95,
depthTest: false,
depthWrite: false
});
const crown = new THREE.Group();
crown.position.y = 0.115;
crown.renderOrder = 70;
const horizontalBracket = new THREE.BoxGeometry(0.065, 0.022, 0.022);
const verticalBracket = new THREE.BoxGeometry(0.022, 0.022, 0.065);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const h = new THREE.Mesh(horizontalBracket, crownMaterial);
h.position.set(sx * 0.14, 0, sz * 0.14);
h.renderOrder = 70;
crown.add(h);
const v = new THREE.Mesh(verticalBracket, crownMaterial);
v.position.set(sx * 0.14, 0, sz * 0.14);
v.renderOrder = 70;
crown.add(v);
}
}
crown.visible = false;
marker.add(crown);
marker.userData.crown = crown;
}
// Trilha pontilhada voxel, sempre apoiada no bordo externo do leque.
const railMaterial = new THREE.MeshBasicMaterial({
color: 0x2cc8ad,
transparent: true,
opacity: 0.76,
depthTest: false,
depthWrite: false
});
const railGeometry = new THREE.BoxGeometry(0.052, 0.038, 0.052);
const railBlocks = [];
const RAIL_BLOCK_COUNT = 39;
for (let i = 0; i < RAIL_BLOCK_COUNT; i++) {
const block = new THREE.Mesh(railGeometry, railMaterial);
block.renderOrder = 30;
book.add(block);
railBlocks.push(block);
}
const labels = [];
const legend = document.getElementById("legend");
for (let frame = 0; frame < FRAME_COUNT; frame++) {
const label = document.createElement("div");
label.className = "step-label";
label.textContent = String(frame + 1).padStart(2, "0");
labelsLayer.appendChild(label);
labels.push(label);
const swatch = document.createElement("span");
swatch.className = "swatch";
swatch.style.background = `#${frameColors[frame].getHexString()}`;
swatch.title = `Quadro ${frame + 1}`;
legend.appendChild(swatch);
}
const state = {
selected: 5,
playing: false,
fanDegrees: Number(fanInput.value),
yaw: 1.34,
pitch: 0.72,
radius: window.innerWidth < 700 ? 9.8 : 8.25,
target: new THREE.Vector3(0.06, 0.27, 0),
userZoomed: false
};
const clock = new THREE.Clock();
const projected = new THREE.Vector3();
const worldPosition = new THREE.Vector3();
const cameraDirection = new THREE.Vector3();
function updateFan(degrees) {
state.fanDegrees = degrees;
const halfAngle = THREE.MathUtils.degToRad(degrees * 0.5);
const step = (halfAngle * 2) / (FRAME_COUNT - 1);
pagePivots.forEach((pivot, frame) => {
pivot.rotation.y = -halfAngle + frame * step;
});
const railRadius = HINGE_X + PAGE_WIDTH + 0.095;
railBlocks.forEach((block, index) => {
const angle = -halfAngle + (index / (RAIL_BLOCK_COUNT - 1)) * halfAngle * 2;
block.position.set(
railRadius * Math.cos(angle),
0.215,
-railRadius * Math.sin(angle)
);
});
fanValue.value = `${Math.round(degrees)}°`;
fanValue.textContent = `${Math.round(degrees)}°`;
}
function updateCamera() {
const horizontalRadius = Math.sin(state.pitch) * state.radius;
camera.position.set(
state.target.x + horizontalRadius * Math.sin(state.yaw),
state.target.y + Math.cos(state.pitch) * state.radius,
state.target.z + horizontalRadius * Math.cos(state.yaw)
);
camera.lookAt(state.target);
camera.updateMatrixWorld();
}
function resetView() {
state.yaw = 1.34;
state.pitch = 0.72;
state.radius = window.innerWidth < 700 ? 9.8 : 8.25;
state.userZoomed = false;
updateCamera();
}
function selectFrame(frame, userInitiated = true) {
state.selected = (frame + FRAME_COUNT) % FRAME_COUNT;
document.querySelectorAll("button[data-frame]").forEach(button => {
const buttonFrame = Number(button.dataset.frame);
button.classList.toggle("active", buttonFrame === state.selected);
});
labels.forEach((label, index) => {
label.classList.toggle("active", index === state.selected);
});
if (userInitiated) {
state.playing = false;
playButton.textContent = "▶ Reproduzir";
playButton.setAttribute("aria-pressed", "false");
}
}
function setPlaying(playing) {
state.playing = playing;
playButton.textContent = playing ? "❚❚ Pausar" : "▶ Reproduzir";
playButton.setAttribute("aria-pressed", String(playing));
}
function auditGeometry() {
scene.updateMatrixWorld(true);
let visibleCount = 0;
let outsideCount = 0;
const screenPoints = [];
markerGroups.forEach((marker, index) => {
// Teste da geometria real: a peça deve estar além da borda da folha.
if (marker.position.x > PAGE_WIDTH + 0.14) {
outsideCount++;
}
marker.getWorldPosition(worldPosition);
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.04 &&
projected.x < 1.04 &&
projected.y > -1.04 &&
projected.y < 1.04;
if (visible) {
visibleCount++;
screenPoints.push({
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
});
}
if (index === state.selected) {
// Mantém o teste de seleção honesto: o quadro selecionado também
// precisa continuar dentro do enquadramento.
markerGroups[index].getWorldPosition(worldPosition);
}
});
let minimumGap = Infinity;
for (let i = 1; i < screenPoints.length; i++) {
const dx = screenPoints[i].x - screenPoints[i - 1].x;
const dy = screenPoints[i].y - screenPoints[i - 1].y;
minimumGap = Math.min(minimumGap, Math.hypot(dx, dy));
}
statusElement.textContent = `${visibleCount}/${FRAME_COUNT} passos no quadro`;
statusDetail.textContent =
`${outsideCount}/${FRAME_COUNT} fora da área da dobra` +
(Number.isFinite(minimumGap)
? ` · separação mínima ${Math.round(minimumGap)} px`
: "");
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
markerGroups.forEach((marker, index) => {
marker.getWorldPosition(worldPosition);
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
const label = labels[index];
label.style.display = visible ? "block" : "none";
if (visible) {
label.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.style.top = `${(-projected.y * 0.5 + 0.5) * height - 17}px`;
}
});
}
fanInput.addEventListener("input", () => {
updateFan(Number(fanInput.value));
});
document.querySelectorAll("button[data-frame]").forEach(button => {
button.addEventListener("click", () => {
selectFrame(Number(button.dataset.frame));
});
});
document.getElementById("previous").addEventListener("click", () => {
selectFrame(state.selected - 1);
});
document.getElementById("next").addEventListener("click", () => {
selectFrame(state.selected + 1);
});
playButton.addEventListener("click", () => {
setPlaying(!state.playing);
});
document.getElementById("resetView").addEventListener("click", resetView);
window.addEventListener("keydown", event => {
const tag = event.target.tagName;
if (tag === "INPUT" || tag === "BUTTON") return;
if (event.key === "ArrowRight") {
selectFrame(state.selected + 1);
} else if (event.key === "ArrowLeft") {
selectFrame(state.selected - 1);
} else if (event.code === "Space") {
event.preventDefault();
setPlaying(!state.playing);
} else if (event.key.toLowerCase() === "r") {
resetView();
}
});
// Câmera orbital implementado diretamente, sem addons.
const pointer = {
down: false,
id: null,
x: 0,
y: 0,
moved: false
};
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", event => {
if (event.button !== 0) return;
pointer.down = true;
pointer.id = event.pointerId;
pointer.x = event.clientX;
pointer.y = event.clientY;
pointer.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!pointer.down || event.pointerId !== pointer.id) 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) > 2) {
pointer.moved = true;
}
state.yaw -= dx * 0.006;
state.pitch = THREE.MathUtils.clamp(
state.pitch + dy * 0.005,
0.34,
1.08
);
});
renderer.domElement.addEventListener("pointerup", event => {
if (!pointer.down || event.pointerId !== pointer.id) return;
if (!pointer.moved) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hits = raycaster.intersectObjects(markerBalls, false);
if (hits.length) {
selectFrame(hits[0].object.userData.frame);
}
}
pointer.down = false;
pointer.id = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
pointer.down = false;
pointer.id = null;
});
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
state.radius = THREE.MathUtils.clamp(
state.radius * Math.exp(event.deltaY * 0.001),
4.7,
14
);
state.userZoomed = true;
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!state.userZoomed) {
state.radius = window.innerWidth < 700 ? 9.8 : 8.25;
}
updateCamera();
});
updateFan(state.fanDegrees);
selectFrame(state.selected, false);
setPlaying(false);
resetView();
let elapsedTime = 0;
let frameCounter = 0;
let lastPlayAdvance = performance.now();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
elapsedTime += delta;
frameCounter++;
if (state.playing) {
const now = performance.now();
if (now - lastPlayAdvance > 820) {
selectFrame(state.selected + 1, false);
lastPlayAdvance = now;
}
}
updateCamera();
const smoothing = 1 - Math.exp(-delta * 9);
pagePivots.forEach((pivot, index) => {
const targetY =
0.115 +
index * 0.007 +
(index === state.selected ? 0.065 : 0);
pivot.position.y = THREE.MathUtils.lerp(
pivot.position.y,
targetY,
smoothing
);
const selected = index === state.selected;
pageMaterials[index].emissive.setHex(selected ? 0x3a2b12 : 0x000000);
pageMaterials[index].emissiveIntensity = selected ? 0.42 : 0;
markerMaterials[index].emissive.copy(frameColors[index]);
markerMaterials[index].emissiveIntensity = selected ? 0.72 : 0.12;
const pulse = selected
? 1.17 + Math.sin(elapsedTime * 6.5) * 0.035
: 1;
const currentScale = markerBalls[index].scale.x;
const nextScale = THREE.MathUtils.lerp(
currentScale,
pulse,
smoothing
);
markerBalls[index].scale.setScalar(nextScale);
markerGroups[index].userData.crown.visible = selected;
markerGroups[index].userData.crown.rotation.y += delta * 0.55;
});
scene.updateMatrixWorld(true);
updateLabels();
if (frameCounter % 8 === 0) {
auditGeometry();
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```