Prompt specification
Build or customize the Three.js 3D scene "Missing-frame storytelling puzzle" 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: Missing-frame storytelling puzzle
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/missing-frame-storytelling-puzzle-x0336
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a flipbook. Create a tabletop animation board with gaps in a character's action; users insert candidate frames and observe whether position and pose transitions remain temporally consistent. Voxel style.
Working Three.js Starter (missing-frame-storytelling-puzzle-x0336):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Flip Lab — Voxel Continuity Bench</title>
<style>
:root {
--ink: #172733;
--muted: #6e7d83;
--paper: #f5efe3;
--panel: rgba(247, 242, 232, 0.92);
--line: rgba(23, 39, 51, 0.13);
--teal: #218f86;
--teal-dark: #17645f;
--amber: #e4a83c;
--coral: #df654f;
--navy: #203743;
--shadow: 0 18px 50px rgba(37, 45, 48, 0.13);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d1c3;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.topbar {
position: fixed;
z-index: 20;
top: 0;
left: 0;
right: 0;
height: 68px;
padding: 0 22px;
display: flex;
align-items: center;
justify-content: space-between;
background: rgba(244, 239, 228, 0.94);
border-bottom: 1px solid var(--line);
backdrop-filter: blur(16px);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
width: 34px;
height: 34px;
position: relative;
border: 3px solid var(--ink);
background: var(--amber);
box-shadow:
6px -6px 0 var(--teal),
6px 6px 0 var(--ink);
transform: translate(-3px, 3px);
}
.brand-mark::after {
content: "";
position: absolute;
width: 8px;
height: 8px;
left: 6px;
top: 6px;
background: var(--ink);
box-shadow: 11px 11px 0 var(--ink);
}
.brand h1 {
margin: 0;
font-size: 16px;
line-height: 1;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.brand p {
margin: 5px 0 0;
font-size: 11px;
color: var(--muted);
letter-spacing: 0.09em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
}
.live-pill {
display: flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(33, 143, 134, 0.25);
border-radius: 999px;
color: var(--teal-dark);
background: rgba(33, 143, 134, 0.08);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(33, 143, 134, 0.13);
}
.icon-button,
.small-button,
.primary-button {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.64);
border-radius: 8px;
cursor: pointer;
transition:
transform 140ms ease,
background 140ms ease,
border-color 140ms ease;
}
.icon-button:hover,
.small-button:hover,
.primary-button:hover {
transform: translateY(-1px);
border-color: rgba(33, 143, 134, 0.4);
}
.icon-button {
width: 34px;
height: 34px;
font-size: 16px;
}
.small-button {
padding: 8px 11px;
font-size: 11px;
font-weight: 700;
}
.primary-button {
padding: 11px 14px;
color: white;
background: var(--teal);
border-color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.04em;
}
.primary-button:disabled {
cursor: not-allowed;
opacity: 0.42;
transform: none;
}
.panel {
position: fixed;
z-index: 15;
top: 88px;
width: 250px;
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.56);
border-radius: 14px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel.left {
left: 20px;
max-height: calc(100vh - 258px);
overflow: auto;
}
.panel.right {
right: 20px;
width: 286px;
}
.eyebrow {
margin: 0 0 6px;
color: var(--teal-dark);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.panel h2 {
margin: 0;
font-size: 18px;
letter-spacing: -0.025em;
}
.panel-subtitle {
margin: 7px 0 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.divider {
height: 1px;
margin: 14px 0;
background: var(--line);
}
.candidate-list {
display: grid;
gap: 8px;
}
.candidate-card {
width: 100%;
padding: 8px;
display: grid;
grid-template-columns: 88px 1fr;
align-items: center;
gap: 10px;
text-align: left;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.5);
cursor: pointer;
transition:
border-color 140ms ease,
background 140ms ease,
transform 140ms ease;
}
.candidate-card:hover {
transform: translateX(2px);
border-color: rgba(33, 143, 134, 0.38);
}
.candidate-card.selected {
border-color: var(--teal);
background: rgba(33, 143, 134, 0.09);
box-shadow: inset 3px 0 0 var(--teal);
}
.candidate-card canvas {
display: block;
width: 88px;
height: 49px;
border-radius: 5px;
background: #e8e1d3;
}
.candidate-name {
display: block;
margin-bottom: 4px;
font-size: 11px;
font-weight: 800;
}
.candidate-meta {
display: block;
color: var(--muted);
font-size: 9px;
line-height: 1.35;
}
.candidate-risk {
display: inline-block;
margin-top: 5px;
color: var(--teal-dark);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.candidate-actions {
display: grid;
grid-template-columns: 1fr auto;
gap: 7px;
margin-top: 12px;
}
.clear-button {
padding: 0 10px;
border: 1px solid var(--line);
border-radius: 8px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 10px;
}
.scene-hud {
position: fixed;
z-index: 12;
top: 86px;
left: 50%;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 8px;
}
.scene-badge {
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 999px;
background: rgba(247, 242, 232, 0.84);
box-shadow: 0 8px 25px rgba(37, 45, 48, 0.09);
backdrop-filter: blur(12px);
color: var(--ink);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.09em;
text-transform: uppercase;
white-space: nowrap;
}
.view-controls {
position: fixed;
z-index: 12;
top: 130px;
right: 326px;
display: flex;
gap: 5px;
}
.view-controls .icon-button {
background: rgba(247, 242, 232, 0.82);
box-shadow: 0 6px 18px rgba(37, 45, 48, 0.08);
}
.score-layout {
display: grid;
grid-template-columns: 92px 1fr;
gap: 14px;
align-items: center;
margin-top: 14px;
}
.score-ring {
--score-color: var(--teal);
position: relative;
width: 88px;
height: 88px;
display: grid;
place-items: center;
border-radius: 50%;
background: conic-gradient(var(--score-color) 0%, #d7d4cb 0%);
}
.score-ring::before {
content: "";
position: absolute;
inset: 8px;
border-radius: 50%;
background: #f3eee4;
}
.score-value {
position: relative;
font-size: 24px;
font-weight: 900;
letter-spacing: -0.05em;
}
.score-value small {
color: var(--muted);
font-size: 10px;
}
.score-copy strong {
display: block;
margin-bottom: 5px;
font-size: 13px;
}
.score-copy span {
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.metric {
margin-top: 12px;
}
.metric-label {
display: flex;
justify-content: space-between;
margin-bottom: 6px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.metric-label span:last-child {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.metric-track {
height: 6px;
overflow: hidden;
border-radius: 999px;
background: rgba(23, 39, 51, 0.09);
}
.metric-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--teal);
transition: width 240ms ease;
}
.delta-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 14px;
}
.delta-card {
padding: 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.42);
}
.delta-card span {
display: block;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.delta-card strong {
display: block;
margin-top: 4px;
font-size: 13px;
font-variant-numeric: tabular-nums;
}
.verdict {
margin-top: 13px;
padding: 10px;
border-left: 3px solid var(--teal);
border-radius: 0 7px 7px 0;
background: rgba(33, 143, 134, 0.08);
font-size: 10px;
line-height: 1.45;
}
.summary-list {
display: grid;
gap: 7px;
margin-top: 12px;
}
.summary-row {
width: 100%;
display: grid;
grid-template-columns: 38px 1fr auto;
gap: 8px;
align-items: center;
padding: 9px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.45);
cursor: pointer;
text-align: left;
}
.summary-row strong {
font-size: 10px;
}
.summary-row span {
color: var(--muted);
font-size: 9px;
}
.summary-score {
font-size: 11px;
font-weight: 900;
}
.timeline-panel {
position: fixed;
z-index: 15;
left: 286px;
right: 322px;
bottom: 18px;
height: 151px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.58);
border-radius: 14px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.transport {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 10px;
}
.transport-left,
.transport-right {
display: flex;
align-items: center;
gap: 7px;
}
.transport-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.play-button {
min-width: 76px;
color: white;
background: var(--navy);
border-color: var(--navy);
}
.speed-select {
padding: 8px 7px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
font-size: 10px;
}
.loop-button.active {
color: var(--teal-dark);
border-color: rgba(33, 143, 134, 0.4);
background: rgba(33, 143, 134, 0.09);
}
.timeline {
display: grid;
grid-template-columns: repeat(8, minmax(68px, 1fr));
gap: 6px;
overflow-x: auto;
padding-bottom: 2px;
}
.frame-slot {
position: relative;
min-width: 68px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(255, 255, 255, 0.45);
cursor: pointer;
transition:
border-color 140ms ease,
transform 140ms ease,
background 140ms ease;
}
.frame-slot:hover {
transform: translateY(-2px);
border-color: rgba(33, 143, 134, 0.42);
}
.frame-slot.active {
border-color: var(--teal);
background: rgba(33, 143, 134, 0.09);
box-shadow: inset 0 -3px 0 var(--teal);
}
.frame-slot.editing {
outline: 2px solid rgba(228, 168, 60, 0.6);
outline-offset: 1px;
}
.slot-number {
position: absolute;
z-index: 2;
top: 8px;
left: 8px;
padding: 2px 4px;
border-radius: 3px;
background: rgba(23, 39, 51, 0.75);
color: white;
font-size: 8px;
font-weight: 900;
}
.frame-slot canvas {
display: block;
width: 100%;
height: 55px;
border-radius: 5px;
}
.slot-state {
display: block;
overflow: hidden;
margin-top: 4px;
color: var(--muted);
font-size: 7px;
font-weight: 900;
letter-spacing: 0.08em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.frame-slot.gap .slot-state {
color: #a86f16;
}
.frame-slot.inserted .slot-state {
color: var(--teal-dark);
}
.toast {
position: fixed;
z-index: 40;
left: 50%;
bottom: 184px;
transform: translate(-50%, 14px);
padding: 10px 15px;
border-radius: 9px;
background: var(--navy);
color: white;
box-shadow: var(--shadow);
font-size: 11px;
font-weight: 700;
opacity: 0;
pointer-events: none;
transition:
opacity 180ms ease,
transform 180ms ease;
}
.toast.visible {
opacity: 1;
transform: translate(-50%, 0);
}
.control-hint {
position: fixed;
z-index: 10;
left: 50%;
bottom: 181px;
transform: translateX(-50%);
color: rgba(23, 39, 51, 0.62);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
pointer-events: none;
}
@media (max-width: 1120px) {
.panel.left {
width: 224px;
}
.panel.right {
width: 252px;
}
.timeline-panel {
left: 258px;
right: 286px;
}
.view-controls {
right: 286px;
}
.frame-slot canvas {
height: 49px;
}
.timeline-panel {
height: 145px;
}
}
@media (max-width: 900px) {
.panel.right {
display: none;
}
.timeline-panel {
right: 18px;
}
.view-controls {
right: 18px;
}
}
@media (max-width: 620px) {
.topbar {
height: 58px;
padding: 0 12px;
}
.brand p,
.live-pill,
.top-actions .small-button {
display: none;
}
.panel {
top: 69px;
}
.panel.left {
left: 10px;
width: 204px;
max-height: calc(100vh - 232px);
padding: 12px;
}
.candidate-card {
grid-template-columns: 68px 1fr;
}
.candidate-card canvas {
width: 68px;
}
.timeline-panel {
left: 8px;
right: 8px;
bottom: 8px;
height: 139px;
}
.scene-hud {
top: 70px;
}
.scene-badge {
max-width: 220px;
overflow: hidden;
text-overflow: ellipsis;
}
.view-controls {
top: 108px;
right: 10px;
}
.transport-label,
.control-hint {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel animation board"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<h1>Flip Lab</h1>
<p>Voxel continuity bench</p>
</div>
</div>
<div class="top-actions">
<div class="live-pill"><span class="live-dot"></span>Live analysis</div>
<button class="small-button" id="resetButton">Reset bench</button>
<button class="icon-button" id="helpButton" title="Controls">?</button>
</div>
</header>
<aside class="panel left">
<p class="eyebrow">Candidate bin</p>
<h2 id="candidateTitle">Frame 03</h2>
<p class="panel-subtitle" id="candidateHint">
Choose a candidate, then insert it into the highlighted gap.
</p>
<div id="candidateList" class="candidate-list"></div>
<div class="candidate-actions">
<button class="primary-button" id="insertButton">Insert candidate</button>
<button class="clear-button" id="clearButton">Clear</button>
</div>
<div class="divider"></div>
<p class="eyebrow">Reading the bench</p>
<p class="panel-subtitle" style="margin-bottom: 0">
Teal ghosts show earlier poses. The dashed route is the inferred beat;
the solid route is the sequence as currently assembled.
</p>
</aside>
<div class="scene-hud">
<div class="scene-badge" id="sceneBadge">Frame 03 · Gap open</div>
</div>
<div class="view-controls" aria-label="Camera views">
<button class="icon-button" data-view="front" title="Front view">▣</button>
<button class="icon-button" data-view="angle" title="Angle view">◈</button>
<button class="icon-button" data-view="top" title="Top view">▤</button>
</div>
<aside class="panel right">
<p class="eyebrow">Temporal check</p>
<h2 id="analysisTitle">Frame 03</h2>
<p class="panel-subtitle" id="analysisSubtitle">
Position and pose are evaluated against the surrounding anchors.
</p>
<div class="score-layout">
<div class="score-ring" id="scoreRing">
<div class="score-value"><span id="scoreValue">0</span><small>%</small></div>
</div>
<div class="score-copy">
<strong id="verdictTitle">Awaiting frame</strong>
<span id="verdictSummary">Insert a candidate to test the transition.</span>
</div>
</div>
<div id="metrics">
<div class="metric">
<div class="metric-label"><span>Position continuity</span><span id="positionScoreText">0%</span></div>
<div class="metric-track"><div class="metric-fill" id="positionScore"></div></div>
</div>
<div class="metric">
<div class="metric-label"><span>Pose continuity</span><span id="poseScoreText">0%</span></div>
<div class="metric-track"><div class="metric-fill" id="poseScore"></div></div>
</div>
<div class="metric">
<div class="metric-label"><span>Transition balance</span><span id="transitionScoreText">0%</span></div>
<div class="metric-track"><div class="metric-fill" id="transitionScore"></div></div>
</div>
</div>
<div class="delta-grid">
<div class="delta-card">
<span>Position delta</span>
<strong id="positionDelta">—</strong>
</div>
<div class="delta-card">
<span>Pose delta</span>
<strong id="poseDelta">—</strong>
</div>
</div>
<div class="verdict" id="verdictNote">
A frame can match the inferred position and still break the action through
a limb or timing snap.
</div>
<div class="divider"></div>
<button class="primary-button" id="analyzeButton" style="width: 100%">
Analyze entire sequence
</button>
<div id="summaryList" class="summary-list" hidden></div>
</aside>
<section class="timeline-panel" aria-label="Flipbook timeline">
<div class="transport">
<div class="transport-left">
<span class="transport-label">Flipbook</span>
<button class="small-button icon-button" id="previousButton" title="Previous frame">‹</button>
<button class="small-button play-button" id="playButton">▶ Play</button>
<button class="small-button icon-button" id="nextButton" title="Next frame">›</button>
<button class="small-button loop-button active" id="loopButton">Loop</button>
</div>
<div class="transport-right">
<span class="transport-label">Speed</span>
<select class="speed-select" id="speedSelect" aria-label="Playback speed">
<option value="0.5">0.5×</option>
<option value="1" selected>1×</option>
<option value="1.5">1.5×</option>
<option value="2">2×</option>
</select>
</div>
</div>
<div class="timeline" id="timeline"></div>
</section>
<div class="control-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="toast" id="toast"></div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Data model
// -------------------------------------------------------------------------
const GAP_INDICES = new Set([2, 4, 6]);
const TARGETS = [
{ x: -3.80, y: 0.00, pose: 0.02 },
{ x: -2.70, y: 0.16, pose: 0.20 },
{ x: -1.55, y: 0.50, pose: 0.47 },
{ x: -0.35, y: 0.82, pose: 0.65 },
{ x: 0.85, y: 0.50, pose: 0.47 },
{ x: 2.05, y: 0.16, pose: 0.20 },
{ x: 2.90, y: 0.05, pose: 0.08 },
{ x: 3.80, y: 0.00, pose: 0.00 }
];
const CANDIDATES = [
{
id: "match",
name: "Matched beat",
meta: "Centered on the inferred pose and path.",
risk: "Recommended",
dx: 0,
dy: 0,
dp: 0
},
{
id: "float",
name: "Floating drift",
meta: "Arrives late and slightly above the beat.",
risk: "Position risk",
dx: 0.52,
dy: 0.14,
dp: -0.08
},
{
id: "snap",
name: "Limb snap",
meta: "Correct placement, abrupt arm and leg timing.",
risk: "Pose risk",
dx: 0,
dy: 0,
dp: 0.27
},
{
id: "near",
name: "Near match",
meta: "Small position and phase discrepancy.",
risk: "Minor drift",
dx: -0.14,
dy: 0.03,
dp: 0.06
}
];
const FRAME_NAMES = [
"Contact",
"Anticipate",
"Missing rise",
"Apex",
"Missing descent",
"Approach",
"Missing plant",
"Settle"
];
let frames = TARGETS.map((target, index) =>
GAP_INDICES.has(index)
? null
: {
...target,
source: true,
candidateId: "source",
name: FRAME_NAMES[index]
}
);
let currentIndex = 2;
let selectedGap = 2;
let selectedCandidate = 0;
let playing = false;
let looping = true;
let playbackSpeed = 1;
let playbackAccumulator = 0;
let analysisMode = false;
// -------------------------------------------------------------------------
// DOM references
// -------------------------------------------------------------------------
const sceneElement = document.querySelector("#scene");
const timelineElement = document.querySelector("#timeline");
const candidateListElement = document.querySelector("#candidateList");
const candidateTitleElement = document.querySelector("#candidateTitle");
const candidateHintElement = document.querySelector("#candidateHint");
const insertButton = document.querySelector("#insertButton");
const clearButton = document.querySelector("#clearButton");
const playButton = document.querySelector("#playButton");
const previousButton = document.querySelector("#previousButton");
const nextButton = document.querySelector("#nextButton");
const loopButton = document.querySelector("#loopButton");
const speedSelect = document.querySelector("#speedSelect");
const sceneBadge = document.querySelector("#sceneBadge");
const toastElement = document.querySelector("#toast");
const scoreRing = document.querySelector("#scoreRing");
const scoreValue = document.querySelector("#scoreValue");
const analysisTitle = document.querySelector("#analysisTitle");
const analysisSubtitle = document.querySelector("#analysisSubtitle");
const verdictTitle = document.querySelector("#verdictTitle");
const verdictSummary = document.querySelector("#verdictSummary");
const verdictNote = document.querySelector("#verdictNote");
const positionScore = document.querySelector("#positionScore");
const poseScore = document.querySelector("#poseScore");
const transitionScore = document.querySelector("#transitionScore");
const positionScoreText = document.querySelector("#positionScoreText");
const poseScoreText = document.querySelector("#poseScoreText");
const transitionScoreText = document.querySelector("#transitionScoreText");
const positionDelta = document.querySelector("#positionDelta");
const poseDelta = document.querySelector("#poseDelta");
const metricsElement = document.querySelector("#metrics");
const summaryList = document.querySelector("#summaryList");
// -------------------------------------------------------------------------
// Three.js setup
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d1c3);
scene.fog = new THREE.Fog(0xd8d1c3, 24, 46);
const camera = new THREE.PerspectiveCamera(
38,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
sceneElement.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xfff8e9, 0x6b7680, 2.15);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff2d6, 3.1);
keyLight.position.set(-8, 13, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8ecac5, 1.25);
rimLight.position.set(10, 6, -9);
scene.add(rimLight);
const materials = {
floor: new THREE.MeshStandardMaterial({ color: 0xc9c2b5, roughness: 1 }),
table: new THREE.MeshStandardMaterial({ color: 0x8a6850, roughness: 0.88 }),
tableEdge: new THREE.MeshStandardMaterial({ color: 0x5e493c, roughness: 0.95 }),
board: new THREE.MeshStandardMaterial({ color: 0x263e49, roughness: 0.82 }),
paper: new THREE.MeshStandardMaterial({ color: 0xeee7d9, roughness: 0.95 }),
paperBlue: new THREE.MeshStandardMaterial({ color: 0xdce6df, roughness: 0.95 }),
gridA: new THREE.MeshStandardMaterial({ color: 0xe8e1d4, roughness: 0.95 }),
gridB: new THREE.MeshStandardMaterial({ color: 0xddd6c9, roughness: 0.95 }),
teal: new THREE.MeshStandardMaterial({ color: 0x218f86, roughness: 0.72 }),
amber: new THREE.MeshStandardMaterial({ color: 0xe4a83c, roughness: 0.75 }),
coral: new THREE.MeshStandardMaterial({ color: 0xdf654f, roughness: 0.75 }),
skin: new THREE.MeshStandardMaterial({ color: 0xf2bd83, roughness: 0.82 }),
hair: new THREE.MeshStandardMaterial({ color: 0x31313a, roughness: 0.9 }),
shirt: new THREE.MeshStandardMaterial({ color: 0xe7a33b, roughness: 0.82 }),
overalls: new THREE.MeshStandardMaterial({ color: 0x267d82, roughness: 0.8 }),
shoes: new THREE.MeshStandardMaterial({ color: 0x263640, roughness: 0.9 }),
white: new THREE.MeshStandardMaterial({ color: 0xf9f4e9, roughness: 0.75 }),
eye: new THREE.MeshStandardMaterial({ color: 0x15222a, roughness: 0.65 })
};
function addBox(parent, width, height, depth, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeLabel(text, options = {}) {
const {
width = 1024,
height = 128,
background = "transparent",
color = "#f8f1e4",
fontSize = 54,
align = "center"
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
if (background !== "transparent") {
context.fillStyle = background;
context.fillRect(0, 0, width, height);
}
context.fillStyle = color;
context.font = `800 ${fontSize}px ui-sans-serif, system-ui, sans-serif`;
context.textAlign = align;
context.textBaseline = "middle";
const x = align === "left" ? 20 : width / 2;
context.fillText(text, x, height / 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
return texture;
}
function makeLabelPlane(text, width, height, options = {}) {
const texture = makeLabel(text, options);
const material = new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(new THREE.PlaneGeometry(width, height), material);
mesh.renderOrder = 3;
return mesh;
}
// Floor and tabletop.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.64;
floor.receiveShadow = true;
scene.add(floor);
addBox(scene, 15.1, 0.48, 8.8, materials.tableEdge, 0, -0.38, 0);
addBox(scene, 14.7, 0.28, 8.45, materials.table, 0, -0.18, 0);
// Board and paper.
addBox(scene, 13.05, 0.24, 6.65, materials.board, 0, 0.08, 0);
addBox(scene, 12.65, 0.11, 6.25, materials.paper, 0, 0.255, 0);
// Stage grid.
const gridGroup = new THREE.Group();
scene.add(gridGroup);
for (let row = 0; row < 4; row++) {
for (let col = 0; col < 13; col++) {
const material = (row + col) % 2 === 0 ? materials.gridA : materials.gridB;
addBox(
gridGroup,
0.69,
0.028,
0.62,
material,
-4.62 + col * 0.77,
0.327,
-1.43 + row * 0.73
);
}
}
// Raised title plate.
const titlePlate = addBox(
scene,
8.4,
0.62,
0.09,
materials.board,
0,
0.59,
-2.72
);
titlePlate.rotation.x = -0.08;
const titleLabel = makeLabelPlane(
"FRAME LAB / VOXEL HOP",
7.4,
0.43,
{
color: "#f4eee2",
fontSize: 52
}
);
titleLabel.position.set(0, 0.61, -2.66);
titleLabel.rotation.x = -0.08;
scene.add(titleLabel);
// Binder clips made from blocks.
for (const x of [-5.25, 5.25]) {
addBox(scene, 0.42, 0.16, 0.42, materials.amber, x, 0.43, -2.73);
addBox(scene, 0.25, 0.12, 0.52, materials.board, x, 0.52, -2.69);
}
// Small production notes on the physical board.
addBox(scene, 0.72, 0.025, 0.72, materials.amber, -5.7, 0.35, -1.65);
addBox(scene, 0.72, 0.025, 0.72, materials.paperBlue, -5.68, 0.38, -1.6);
addBox(scene, 0.1, 0.1, 1.4, materials.coral, 5.75, 0.38, -0.7);
addBox(scene, 0.12, 0.12, 0.22, materials.board, 5.75, 0.38, -0.08);
// -------------------------------------------------------------------------
// Voxel character rig
// -------------------------------------------------------------------------
function createVoxelCharacter(options = {}) {
const { ghost = false, ghostOpacity = 0.15 } = options;
function characterMaterial(baseMaterial, ghostColor = 0x55b7ad) {
if (!ghost) return baseMaterial;
return new THREE.MeshStandardMaterial({
color: ghostColor,
transparent: true,
opacity: ghostOpacity,
roughness: 0.85,
depthWrite: false
});
}
const root = new THREE.Group();
const skin = characterMaterial(materials.skin);
const hair = characterMaterial(materials.hair);
const shirt = characterMaterial(materials.shirt);
const overalls = characterMaterial(materials.overalls);
const shoes = characterMaterial(materials.shoes);
const white = characterMaterial(materials.white);
const eye = characterMaterial(materials.eye);
const body = new THREE.Group();
root.add(body);
addBox(body, 0.62, 0.69, 0.42, shirt, 0, 1.05, 0);
addBox(body, 0.49, 0.26, 0.44, overalls, 0, 0.82, 0.015);
addBox(body, 0.12, 0.32, 0.025, overalls, -0.16, 1.09, 0.222);
addBox(body, 0.12, 0.32, 0.025, overalls, 0.16, 1.09, 0.222);
const head = new THREE.Group();
head.position.y = 1.67;
body.add(head);
addBox(head, 0.64, 0.59, 0.58, skin, 0, 0, 0);
addBox(head, 0.68, 0.18, 0.62, hair, 0, 0.30, -0.015);
addBox(head, 0.14, 0.19, 0.16, hair, -0.27, 0.12, -0.05);
addBox(head, 0.09, 0.09, 0.035, eye, -0.14, 0.02, 0.302);
addBox(head, 0.09, 0.09, 0.035, eye, 0.14, 0.02, 0.302);
addBox(head, 0.11, 0.11, 0.12, skin, 0.34, -0.03, 0.08);
const legLeft = new THREE.Group();
const legRight = new THREE.Group();
legLeft.position.set(-0.17, 0.70, 0);
legRight.position.set(0.17, 0.70, 0);
body.add(legLeft, legRight);
addBox(legLeft, 0.23, 0.58, 0.25, overalls, 0, -0.28, 0);
addBox(legLeft, 0.27, 0.16, 0.38, shoes, 0, -0.62, 0.055);
addBox(legRight, 0.23, 0.58, 0.25, overalls, 0, -0.28, 0);
addBox(legRight, 0.27, 0.16, 0.38, shoes, 0, -0.62, 0.055);
const armLeft = new THREE.Group();
const armRight = new THREE.Group();
armLeft.position.set(-0.39, 1.34, 0);
armRight.position.set(0.39, 1.34, 0);
body.add(armLeft, armRight);
addBox(armLeft, 0.20, 0.58, 0.24, shirt, 0, -0.27, 0);
addBox(armLeft, 0.20, 0.18, 0.21, skin, 0, -0.62, 0);
addBox(armRight, 0.20, 0.58, 0.24, shirt, 0, -0.27, 0);
addBox(armRight, 0.20, 0.18, 0.21, skin, 0, -0.62, 0);
function applyPose(pose) {
const p = THREE.MathUtils.clamp(pose, 0, 1);
legLeft.rotation.x = -0.16 + p * 0.92;
legRight.rotation.x = 0.24 - p * 1.05;
legLeft.rotation.z = -0.02 - p * 0.08;
legRight.rotation.z = 0.02 + p * 0.08;
armLeft.rotation.z = -0.12 - p * 1.62;
armRight.rotation.z = 0.12 + p * 1.62;
armLeft.rotation.x = -0.08 + p * 0.32;
armRight.rotation.x = 0.08 - p * 0.32;
body.rotation.z = Math.sin(p * Math.PI) * 0.055;
body.position.y = Math.sin(p * Math.PI) * 0.055;
head.rotation.z = -Math.sin(p * Math.PI) * 0.045;
}
return {
root,
body,
head,
legLeft,
legRight,
armLeft,
armRight,
applyPose
};
}
const mainCharacter = createVoxelCharacter();
scene.add(mainCharacter.root);
const ghostCharacters = Array.from({ length: 3 }, (_, index) => {
const character = createVoxelCharacter({
ghost: true,
ghostOpacity: 0.18 - index * 0.035
});
scene.add(character.root);
return character;
});
// Main-stage marker.
const stageMarkerMaterial = new THREE.MeshStandardMaterial({
color: 0x218f86,
emissive: 0x123d39,
emissiveIntensity: 0.45,
roughness: 0.65
});
const stageMarker = addBox(
scene,
0.88,
0.035,
0.72,
stageMarkerMaterial,
0,
0.355,
-0.42
);
// Missing-frame wireframe.
const missingMarker = new THREE.Group();
const missingEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.82, 1.70, 0.72)),
new THREE.LineBasicMaterial({
color: 0xe4a83c,
transparent: true,
opacity: 0.8
})
);
missingMarker.add(missingEdges);
const missingLabel = makeLabelPlane("?", 0.42, 0.42, {
width: 256,
height: 256,
color: "#e4a83c",
fontSize: 170
});
missingLabel.position.set(0, 0.03, 0.37);
missingMarker.add(missingLabel);
scene.add(missingMarker);
// -------------------------------------------------------------------------
// Physical timeline slots
// -------------------------------------------------------------------------
const physicalSlots = [];
for (let index = 0; index < 8; index++) {
const x = -4.55 + index * 1.30;
const group = new THREE.Group();
group.position.x = x;
scene.add(group);
addBox(group, 1.06, 0.10, 0.80, materials.board, 0, 0.36, 2.05);
const insetMaterial = new THREE.MeshStandardMaterial({
color: GAP_INDICES.has(index) ? 0xe7c481 : 0xf0eadf,
emissive: 0x000000,
emissiveIntensity: 0,
roughness: 0.88
});
const inset = addBox(
group,
0.92,
0.04,
0.66,
insetMaterial,
0,
0.425,
2.05
);
const mini = createVoxelCharacter();
mini.root.scale.setScalar(0.18);
mini.root.position.set(0, 0.45, 2.03);
group.add(mini.root);
const placeholder = makeLabelPlane("?", 0.46, 0.46, {
width: 256,
height: 256,
color: "#a76c17",
fontSize: 180
});
placeholder.rotation.x = -Math.PI / 2;
placeholder.position.set(0, 0.456, 2.05);
group.add(placeholder);
const number = makeLabelPlane(String(index + 1).padStart(2, "0"), 0.34, 0.17, {
width: 256,
height: 128,
color: "#e8e0d2",
fontSize: 76
});
number.rotation.x = -Math.PI / 2;
number.position.set(-0.33, 0.455, 2.30);
group.add(number);
physicalSlots.push({
group,
inset,
insetMaterial,
mini,
placeholder
});
}
// Inferred path.
const idealPathGeometry = new THREE.BufferGeometry().setFromPoints(
TARGETS.map(target =>
new THREE.Vector3(target.x, 0.43 + target.y, -0.42)
)
);
const idealPath = new THREE.Line(
idealPathGeometry,
new THREE.LineDashedMaterial({
color: 0x218f86,
dashSize: 0.17,
gapSize: 0.12,
transparent: true,
opacity: 0.72
})
);
idealPath.computeLineDistances();
scene.add(idealPath);
// Assembled path.
const actualPathMaterial = new THREE.LineBasicMaterial({
color: 0xe4a83c,
transparent: true,
opacity: 0.9
});
const actualPath = new THREE.LineSegments(
new THREE.BufferGeometry(),
actualPathMaterial
);
scene.add(actualPath);
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const cameraState = {
theta: 0.57,
phi: 0.86,
radius: 17.7,
target: new THREE.Vector3(0, 0.6, 0)
};
const desiredCamera = {
theta: cameraState.theta,
phi: cameraState.phi,
radius: cameraState.radius,
target: cameraState.target.clone()
};
let dragging = false;
let panning = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
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;
if (panning) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
desiredCamera.target.addScaledVector(right, -dx * desiredCamera.radius * 0.0013);
desiredCamera.target.addScaledVector(up, dy * desiredCamera.radius * 0.0013);
} else {
desiredCamera.theta -= dx * 0.006;
desiredCamera.phi = THREE.MathUtils.clamp(
desiredCamera.phi - dy * 0.005,
0.16,
1.36
);
}
});
function stopDragging() {
dragging = false;
panning = false;
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
desiredCamera.radius = THREE.MathUtils.clamp(
desiredCamera.radius * Math.exp(event.deltaY * 0.001),
9,
28
);
},
{ passive: false }
);
function updateCamera() {
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
desiredCamera.theta,
0.12
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
desiredCamera.phi,
0.12
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
desiredCamera.radius,
0.12
);
cameraState.target.lerp(desiredCamera.target, 0.12);
const offset = new THREE.Vector3().setFromSphericalCoords(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.copy(cameraState.target).add(offset);
camera.lookAt(cameraState.target);
}
document.querySelectorAll("[data-view]").forEach(button => {
button.addEventListener("click", () => {
desiredCamera.target.set(0, 0.6, 0);
if (button.dataset.view === "front") {
desiredCamera.theta = 0;
desiredCamera.phi = 0.90;
desiredCamera.radius = 17.2;
} else if (button.dataset.view === "top") {
desiredCamera.theta = 0.01;
desiredCamera.phi = 0.18;
desiredCamera.radius = 16.6;
} else {
desiredCamera.theta = 0.57;
desiredCamera.phi = 0.86;
desiredCamera.radius = 17.7;
}
});
});
// -------------------------------------------------------------------------
// Continuity scoring
// -------------------------------------------------------------------------
function clampScore(value) {
return THREE.MathUtils.clamp(Math.round(value), 0, 100);
}
function scoreColor(score) {
if (score >= 85) return "#218f86";
if (score >= 65) return "#d49329";
return "#df654f";
}
function continuityFor(index) {
const frame = frames[index];
if (!frame) {
return {
index,
missing: true,
total: 0,
position: 0,
pose: 0,
transition: 0,
positionError: 0,
poseError: 0
};
}
const target = TARGETS[index];
const positionError = Math.hypot(
frame.x - target.x,
frame.y - target.y
);
const poseError = Math.abs(frame.pose - target.pose);
const positionScore = clampScore(100 - (positionError / 0.70) * 100);
const poseScore = clampScore(100 - (poseError / 0.38) * 100);
let transitionScore = 100;
if (GAP_INDICES.has(index)) {
const previous = frames[index - 1];
const next = frames[index + 1];
if (previous && next) {
const actualIncoming = new THREE.Vector2(
frame.x - previous.x,
frame.y - previous.y
);
const actualOutgoing = new THREE.Vector2(
next.x - frame.x,
next.y - frame.y
);
const expectedIncoming = new THREE.Vector2(
target.x - previous.x,
target.y - previous.y
);
const expectedOutgoing = new THREE.Vector2(
next.x - target.x,
next.y - target.y
);
const velocityError =
(actualIncoming.distanceTo(expectedIncoming) +
actualOutgoing.distanceTo(expectedOutgoing)) /
2;
transitionScore = clampScore(
100 - (velocityError / 0.55) * 100
);
}
}
const total = clampScore(
positionScore * 0.45 +
poseScore * 0.35 +
transitionScore * 0.20
);
return {
index,
missing: false,
total,
position: positionScore,
pose: poseScore,
transition: transitionScore,
positionError,
poseError
};
}
// -------------------------------------------------------------------------
// 2D voxel thumbnails
// -------------------------------------------------------------------------
function drawThumbnail(canvas, frame, options = {}) {
const { missing = false, candidateColor = null } = options;
const context = canvas.getContext("2d");
const width = canvas.width;
const height = canvas.height;
context.clearRect(0, 0, width, height);
context.fillStyle = missing ? "#e8dfcc" : "#eae3d6";
context.fillRect(0, 0, width, height);
context.strokeStyle = "rgba(23,39,51,0.07)";
context.lineWidth = 1;
for (let x = 0; x <= width; x += 15) {
context.beginPath();
context.moveTo(x, 0);
context.lineTo(x, height);
context.stroke();
}
for (let y = 0; y <= height; y += 15) {
context.beginPath();
context.moveTo(0, y);
context.lineTo(width, y);
context.stroke();
}
if (missing) {
context.save();
context.setLineDash([5, 4]);
context.strokeStyle = "#b47821";
context.lineWidth = 2;
context.strokeRect(5, 5, width - 10, height - 10);
context.restore();
context.fillStyle = "#b47821";
context.font = "900 30px system-ui";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("?", width / 2, height / 2 + 1);
return;
}
const pose = frame.pose;
const centerX = width * 0.5;
const groundY = height * 0.79;
const scale = Math.min(width / 120, height / 76);
context.save();
context.translate(centerX, groundY);
context.scale(scale, scale);
context.fillStyle = "rgba(23,39,51,0.14)";
context.fillRect(-23, -3, 46, 5);
const swing = Math.sin(pose * Math.PI);
const shirtColor = candidateColor || "#e7a33b";
// Legs.
context.save();
context.translate(-8, -20);
context.rotate(-0.22 + pose * 0.62);
context.fillStyle = "#267d82";
context.fillRect(-5, 0, 10, 20);
context.fillStyle = "#263640";
context.fillRect(-6, 18, 13, 5);
context.restore();
context.save();
context.translate(8, -20);
context.rotate(0.22 - pose * 0.70);
context.fillStyle = "#267d82";
context.fillRect(-5, 0, 10, 20);
context.fillStyle = "#263640";
context.fillRect(-7, 18, 13, 5);
context.restore();
// Torso.
context.fillStyle = shirtColor;
context.fillRect(-13, -43, 26, 25);
context.fillStyle = "#267d82";
context.fillRect(-10, -25, 20, 7);
// Arms.
context.save();
context.translate(-13, -40);
context.rotate(-0.12 - pose * 0.95);
context.fillStyle = shirtColor;
context.fillRect(-4, 0, 8, 19);
context.fillStyle = "#f2bd83";
context.fillRect(-4, 17, 8, 6);
context.restore();
context.save();
context.translate(13, -40);
context.rotate(0.12 + pose * 0.95);
context.fillStyle = shirtColor;
context.fillRect(-4, 0, 8, 19);
context.fillStyle = "#f2bd83";
context.fillRect(-4, 17, 8, 6);
context.restore();
// Head.
context.fillStyle = "#f2bd83";
context.fillRect(-13, -66, 26, 23);
context.fillStyle = "#31313a";
context.fillRect(-14, -69, 28, 8);
context.fillRect(-14, -64, 5, 11);
context.fillStyle = "#15222a";
context.fillRect(-8, -57, 3, 4);
context.fillRect(5, -57, 3, 4);
context.fillStyle = "#f2bd83";
context.fillRect(12, -55, 5, 6);
context.restore();
}
// -------------------------------------------------------------------------
// UI rendering
// -------------------------------------------------------------------------
function renderTimeline() {
timelineElement.innerHTML = "";
for (let index = 0; index < 8; index++) {
const frame = frames[index];
const button = document.createElement("button");
button.className = "frame-slot";
if (index === currentIndex) button.classList.add("active");
if (index === selectedGap) button.classList.add("editing");
if (!frame) button.classList.add("gap");
if (frame?.inserted) button.classList.add("inserted");
const number = document.createElement("span");
number.className = "slot-number";
number.textContent = String(index + 1).padStart(2, "0");
const canvas = document.createElement("canvas");
canvas.width = 150;
canvas.height = 76;
drawThumbnail(canvas, frame, { missing: !frame });
const state = document.createElement("span");
state.className = "slot-state";
state.textContent = frame
? frame.inserted
? "Inserted"
: "Source"
: "Gap open";
button.append(number, canvas, state);
button.addEventListener("click", () => {
analysisMode = false;
setCurrentFrame(index);
if (GAP_INDICES.has(index)) {
selectedGap = index;
} else {
selectedGap = null;
}
renderAll();
});
timelineElement.appendChild(button);
}
}
function renderCandidates() {
const canEdit = selectedGap !== null;
const target = canEdit ? TARGETS[selectedGap] : null;
candidateTitleElement.textContent = canEdit
? `Frame ${String(selectedGap + 1).padStart(2, "0")}`
: "Select a gap";
candidateHintElement.textContent = canEdit
? `Choose a candidate, then insert it into frame ${String(
selectedGap + 1
).padStart(2, "0")}.`
: "Select an open frame in the timeline to prepare an insertion.";
candidateListElement.innerHTML = "";
CANDIDATES.forEach((candidate, index) => {
const button = document.createElement("button");
button.className = "candidate-card";
if (index === selectedCandidate && canEdit) {
button.classList.add("selected");
}
const canvas = document.createElement("canvas");
canvas.width = 176;
canvas.height = 98;
if (target) {
drawThumbnail(
canvas,
{
x: target.x + candidate.dx,
y: target.y + candidate.dy,
pose: target.pose + candidate.dp
},
{ candidateColor: candidate.id === "match" ? "#e7a33b" : "#d99636" }
);
} else {
drawThumbnail(canvas, TARGETS[0], {});
}
const details = document.createElement("span");
const name = document.createElement("span");
name.className = "candidate-name";
name.textContent = candidate.name;
const meta = document.createElement("span");
meta.className = "candidate-meta";
meta.textContent = candidate.meta;
const risk = document.createElement("span");
risk.className = "candidate-risk";
risk.textContent = candidate.risk;
details.append(name, meta, risk);
button.append(canvas, details);
button.addEventListener("click", () => {
if (!canEdit) {
showToast("Select a highlighted gap first.");
return;
}
selectedCandidate = index;
renderCandidates();
});
candidateListElement.appendChild(button);
});
insertButton.disabled = !canEdit;
insertButton.textContent = canEdit
? `Insert into frame ${String(selectedGap + 1).padStart(2, "0")}`
: "Insert candidate";
clearButton.disabled = !canEdit || !frames[selectedGap]?.inserted;
}
function setMetric(element, textElement, value) {
element.style.width = `${value}%`;
element.style.background = scoreColor(value);
textElement.textContent = `${value}%`;
}
function updateAnalysis() {
if (analysisMode) {
renderSummary();
return;
}
summaryList.hidden = true;
metricsElement.hidden = false;
const result = continuityFor(currentIndex);
const color = scoreColor(result.total);
scoreRing.style.setProperty("--score-color", color);
scoreRing.style.background = `conic-gradient(${color} ${result.total}%, #d7d4cb ${result.total}%)`;
scoreValue.textContent = result.total;
analysisTitle.textContent = `Frame ${String(currentIndex + 1).padStart(2, "0")}`;
analysisSubtitle.textContent = frames[currentIndex]
? frames[currentIndex].inserted
? "Candidate inserted. Compare both sides of the action."
: "Source anchor. The inferred motion is constrained by this pose."
: "The action is missing at this beat.";
setMetric(positionScore, positionScoreText, result.position);
setMetric(poseScore, poseScoreText, result.pose);
setMetric(transitionScore, transitionScoreText, result.transition);
if (result.missing) {
verdictTitle.textContent = "Awaiting frame";
verdictSummary.textContent =
"Insert a candidate to test the transition.";
positionDelta.textContent = "—";
poseDelta.textContent = "—";
verdictNote.textContent =
"The missing frame breaks the spatial and temporal chain. Choose a candidate from the bin.";
} else if (GAP_INDICES.has(currentIndex)) {
verdictTitle.textContent =
result.total >= 85
? "Continuity holds"
: result.total >= 65
? "Minor timing break"
: "Transition breaks";
verdictSummary.textContent =
result.total >= 85
? "Position, pose, and motion vectors agree with the surrounding anchors."
: result.total >= 65
? "The beat is close, but one transition still shows a visible discrepancy."
: "The candidate creates a noticeable spatial or pose discontinuity.";
positionDelta.textContent = `${result.positionError.toFixed(2)} u`;
poseDelta.textContent = `${Math.round(result.poseError * 90)}°`;
verdictNote.textContent =
result.position >= 85 && result.pose >= 85
? "Both placement and articulation remain temporally consistent."
: result.position < 65
? "Position continuity is the main failure. The character arrives too late, early, or off path."
: "Placement is plausible, but the limb phase snaps against the neighboring poses.";
} else {
verdictTitle.textContent = "Stable source anchor";
verdictSummary.textContent =
"This frame supplies a reliable reference for the neighboring candidate.";
positionDelta.textContent = "0.00 u";
poseDelta.textContent = "0°";
verdictNote.textContent =
"Use the teal ghosts and motion path while playing to inspect how the inserted frame meets this anchor.";
}
}
function renderSummary() {
metricsElement.hidden = true;
summaryList.hidden = false;
const inserted = [...GAP_INDICES]
.map(index => continuityFor(index))
.filter(result => !result.missing);
const average = inserted.length
? Math.round(
inserted.reduce((sum, result) => sum + result.total, 0) /
inserted.length
)
: 0;
const color = scoreColor(average);
scoreRing.style.setProperty("--score-color", color);
scoreRing.style.background = `conic-gradient(${color} ${average}%, #d7d4cb ${average}%)`;
scoreValue.textContent = average;
analysisTitle.textContent = "Sequence report";
analysisSubtitle.textContent = `${inserted.length} of 3 gaps have candidate frames.`;
verdictTitle.textContent =
average >= 85
? "Sequence is coherent"
: average >= 65
? "Sequence needs refinement"
: "Sequence breaks continuity";
verdictSummary.textContent =
average >= 85
? "Every inserted beat maintains a believable chain of position and pose."
: "Replace weak candidates and compare the affected transition.";
positionDelta.textContent = `${inserted.length}/3`;
poseDelta.textContent = `${average}%`;
verdictNote.textContent =
"The report averages each inserted gap separately; source anchors are treated as reliable.";
summaryList.innerHTML = "";
for (const index of GAP_INDICES) {
const result = continuityFor(index);
const row = document.createElement("button");
row.className = "summary-row";
const number = document.createElement("strong");
number.textContent = `F${String(index + 1).padStart(2, "0")}`;
const description = document.createElement("span");
description.textContent = result.missing
? "No candidate"
: `${result.position} pos · ${result.pose} pose`;
const score = document.createElement("span");
score.className = "summary-score";
score.style.color = scoreColor(result.total);
score.textContent = result.missing ? "—" : `${result.total}%`;
row.append(number, description, score);
row.addEventListener("click", () => {
analysisMode = false;
selectedGap = index;
setCurrentFrame(index);
renderAll();
});
summaryList.appendChild(row);
}
}
// -------------------------------------------------------------------------
// Scene synchronization
// -------------------------------------------------------------------------
function updateActualPath() {
const points = [];
for (let index = 0; index < frames.length - 1; index++) {
const frame = frames[index];
const next = frames[index + 1];
if (!frame || !next) continue;
points.push(
new THREE.Vector3(frame.x, 0.43 + frame.y, -0.42),
new THREE.Vector3(next.x, 0.43 + next.y, -0.42)
);
}
actualPath.geometry.dispose();
actualPath.geometry = new THREE.BufferGeometry().setFromPoints(points);
const averageScore =
[...GAP_INDICES]
.map(index => continuityFor(index))
.filter(result => !result.missing)
.reduce((sum, result, _, array) => {
return sum + result.total / Math.max(array.length, 1);
}, 0);
actualPathMaterial.color.set(
averageScore >= 85
? 0x218f86
: averageScore >= 65
? 0xe4a83c
: 0xdf654f
);
}
function updateScene() {
const currentFrame = frames[currentIndex];
// Physical slots.
physicalSlots.forEach((slot, index) => {
const frame = frames[index];
slot.mini.root.visible = Boolean(frame);
slot.placeholder.visible = !frame;
slot.insetMaterial.color.set(
frame?.inserted ? 0xd8e8df : frame ? 0xf0eadf : 0xe7c481
);
if (frame) {
slot.mini.applyPose(frame.pose);
}
slot.insetMaterial.emissive.set(
index === currentIndex ? 0x184e49 : 0x000000
);
slot.insetMaterial.emissiveIntensity =
index === currentIndex ? 0.3 : 0;
});
// Main character.
mainCharacter.root.visible = Boolean(currentFrame);
missingMarker.visible = !currentFrame;
if (currentFrame) {
mainCharacter.root.position.set(
currentFrame.x,
0.34 + currentFrame.y,
-0.42
);
mainCharacter.applyPose(currentFrame.pose);
stageMarker.position.x = currentFrame.x;
stageMarkerMaterial.color.set(
scoreColor(continuityFor(currentIndex).total)
);
stageMarkerMaterial.emissive.set(
scoreColor(continuityFor(currentIndex).total)
);
} else {
const target = TARGETS[currentIndex];
missingMarker.position.set(target.x, 1.2 + target.y, -0.42);
stageMarker.position.x = target.x;
stageMarkerMaterial.color.set(0xe4a83c);
stageMarkerMaterial.emissive.set(0x6d4812);
}
// Previous-frame ghosts.
const previousFrames = [];
for (let offset = 1; offset <= 3; offset++) {
const index = currentIndex - offset;
if (index >= 0 && frames[index]) previousFrames.push(frames[index]);
}
ghostCharacters.forEach((character, index) => {
const frame = previousFrames[index];
character.root.visible = Boolean(frame);
if (frame) {
character.root.position.set(frame.x, 0.35 + frame.y, -0.42);
character.applyPose(frame.pose);
}
});
updateActualPath();
const frame = frames[currentIndex];
sceneBadge.textContent = frame
? `Frame ${String(currentIndex + 1).padStart(2, "0")} · ${
frame.inserted ? "Candidate inserted" : "Source anchor"
}`
: `Frame ${String(currentIndex + 1).padStart(2, "0")} · Gap open`;
}
function renderAll() {
renderTimeline();
renderCandidates();
updateAnalysis();
updateScene();
}
// -------------------------------------------------------------------------
// Interactions
// -------------------------------------------------------------------------
function setCurrentFrame(index) {
currentIndex = (index + frames.length) % frames.length;
playbackAccumulator = 0;
if (GAP_INDICES.has(currentIndex) && !frames[currentIndex]) {
selectedGap = currentIndex;
}
}
function showToast(message) {
toastElement.textContent = message;
toastElement.classList.add("visible");
clearTimeout(showToast.timeout);
showToast.timeout = setTimeout(() => {
toastElement.classList.remove("visible");
}, 2100);
}
insertButton.addEventListener("click", () => {
if (selectedGap === null) return;
const candidate = CANDIDATES[selectedCandidate];
const target = TARGETS[selectedGap];
frames[selectedGap] = {
x: target.x + candidate.dx,
y: target.y + candidate.dy,
pose: target.pose + candidate.dp,
inserted: true,
candidateId: candidate.id,
name: candidate.name
};
currentIndex = selectedGap;
analysisMode = false;
renderAll();
showToast(`${candidate.name} inserted into frame ${selectedGap + 1}.`);
});
clearButton.addEventListener("click", () => {
if (selectedGap === null || !frames[selectedGap]?.inserted) return;
frames[selectedGap] = null;
currentIndex = selectedGap;
analysisMode = false;
renderAll();
showToast(`Frame ${selectedGap + 1} is open again.`);
});
playButton.addEventListener("click", () => {
playing = !playing;
playbackAccumulator = 0;
playButton.textContent = playing ? "❚❚ Pause" : "▶ Play";
});
previousButton.addEventListener("click", () => {
analysisMode = false;
setCurrentFrame(currentIndex - 1);
selectedGap = GAP_INDICES.has(currentIndex) ? currentIndex : null;
renderAll();
});
nextButton.addEventListener("click", () => {
analysisMode = false;
setCurrentFrame(currentIndex + 1);
selectedGap = GAP_INDICES.has(currentIndex) ? currentIndex : null;
renderAll();
});
loopButton.addEventListener("click", () => {
looping = !looping;
loopButton.classList.toggle("active", looping);
});
speedSelect.addEventListener("change", () => {
playbackSpeed = Number(speedSelect.value);
});
document.querySelector("#analyzeButton").addEventListener("click", () => {
analysisMode = !analysisMode;
if (analysisMode && ![...GAP_INDICES].some(index => frames[index])) {
showToast("Insert at least one candidate before analyzing.");
analysisMode = false;
return;
}
updateAnalysis();
});
document.querySelector("#resetButton").addEventListener("click", () => {
frames = TARGETS.map((target, index) =>
GAP_INDICES.has(index)
? null
: {
...target,
source: true,
candidateId: "source",
name: FRAME_NAMES[index]
}
);
currentIndex = 2;
selectedGap = 2;
selectedCandidate = 0;
analysisMode = false;
playing = false;
playbackAccumulator = 0;
playButton.textContent = "▶ Play";
renderAll();
showToast("Bench reset to the original three-gap sequence.");
});
document.querySelector("#helpButton").addEventListener("click", () => {
showToast(
"Space: play/pause · ←/→: step · drag: orbit · Shift-drag: pan · wheel: zoom"
);
});
window.addEventListener("keydown", event => {
if (
event.target instanceof HTMLInputElement ||
event.target instanceof HTMLSelectElement
) {
return;
}
if (event.code === "Space") {
event.preventDefault();
playButton.click();
} else if (event.code === "ArrowLeft") {
previousButton.click();
} else if (event.code === "ArrowRight") {
nextButton.click();
}
});
// -------------------------------------------------------------------------
// Animation loop
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
playbackAccumulator += delta * playbackSpeed * 2.6;
if (playbackAccumulator >= 1) {
playbackAccumulator -= 1;
if (currentIndex === frames.length - 1 && !looping) {
playing = false;
playButton.textContent = "▶ Play";
} else {
setCurrentFrame(currentIndex + 1);
selectedGap =
GAP_INDICES.has(currentIndex) && !frames[currentIndex]
? currentIndex
: selectedGap;
renderAll();
}
}
}
if (missingMarker.visible) {
const pulse = 1 + Math.sin(performance.now() * 0.004) * 0.035;
missingMarker.scale.setScalar(pulse);
}
updateCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
renderAll();
updateCamera();
animate();
</script>
</body>
</html>
```