Prompt specification
Build or customize the Three.js 3D scene "Replace-or-repair narrative comparison" 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: Replace-or-repair narrative comparison
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/replace-or-repair-narrative-comparison-x3904
Scene Description Prompt:
Replace-or-repair narrative comparison. Create two branches from the same broken keepsake: repair retains original parts, replacement introduces a new object; track identity and material flows without prescribing a single emotional response. Please build this with Three.js from cdnjs in one self-contained HTML file, using low-poly forms.
Working Three.js Starter (replace-or-repair-narrative-comparison-x3904):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>After the Break — Replace or Repair</title>
<style>
:root {
--paper: #f3f0e8;
--ink: #242724;
--muted: #6d716b;
--line: rgba(36, 39, 36, 0.18);
--panel: rgba(248, 246, 240, 0.86);
--original: #d49a4e;
--original-dark: #865b31;
--repair: #2498a8;
--replacement: #7967c7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
position: relative;
}
#scene {
position: fixed;
inset: 0;
z-index: 0;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.masthead {
position: fixed;
z-index: 5;
top: 20px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 30px;
pointer-events: none;
}
.kicker {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3vw, 44px);
font-weight: 500;
letter-spacing: -0.04em;
line-height: 0.95;
}
.subtitle {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.origin-note {
max-width: 390px;
padding: 12px 14px;
border: 1px solid var(--line);
background: rgba(248, 246, 240, 0.78);
backdrop-filter: blur(10px);
pointer-events: auto;
}
.origin-note strong {
display: block;
margin-bottom: 4px;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.origin-note span {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.comparison {
position: fixed;
z-index: 3;
top: 124px;
left: 24px;
right: 24px;
bottom: 170px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px;
pointer-events: none;
}
.branch-panel {
position: relative;
min-width: 0;
overflow: hidden;
border: 1px solid var(--line);
background: transparent;
}
.branch-copy {
position: absolute;
z-index: 4;
top: 18px;
left: 18px;
max-width: min(390px, calc(100% - 36px));
padding: 11px 13px;
border-left: 3px solid var(--branch-color);
background: var(--panel);
backdrop-filter: blur(9px);
}
.branch-meta {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
margin-bottom: 7px;
}
.branch-label {
color: var(--branch-color);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.stage-badge {
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.branch-copy h2 {
margin: 0 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 23px;
font-weight: 500;
letter-spacing: -0.025em;
}
.branch-copy p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.metrics {
position: absolute;
z-index: 4;
right: 14px;
bottom: 14px;
left: 14px;
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1px;
overflow: hidden;
border: 1px solid var(--line);
background: var(--line);
backdrop-filter: blur(9px);
}
.metric {
min-height: 52px;
padding: 8px 10px;
background: rgba(248, 246, 240, 0.9);
}
.metric-label {
display: block;
margin-bottom: 4px;
color: var(--muted);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.metric-value {
display: block;
font-size: 10px;
font-weight: 700;
line-height: 1.25;
}
.annotation {
position: absolute;
z-index: 3;
padding: 5px 7px;
border: 1px solid rgba(36, 39, 36, 0.16);
background: rgba(248, 246, 240, 0.9);
color: var(--ink);
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
}
.annotation::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
background: rgba(36, 39, 36, 0.3);
content: "";
}
.annotation.original {
border-bottom: 2px solid var(--original);
}
.annotation.added {
border-bottom: 2px solid var(--branch-color);
}
.control-dock {
position: fixed;
z-index: 6;
right: 24px;
bottom: 18px;
left: 24px;
display: grid;
grid-template-columns: minmax(330px, 1.35fr) minmax(250px, 1fr) minmax(190px, 0.7fr);
gap: 20px;
min-height: 126px;
padding: 15px 18px;
border: 1px solid var(--line);
background: rgba(248, 246, 240, 0.93);
backdrop-filter: blur(16px);
box-shadow: 0 12px 30px rgba(36, 39, 36, 0.05);
}
.sequence {
min-width: 0;
}
.sequence-top {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
}
.section-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.small-button {
padding: 5px 10px;
border: 1px solid var(--line);
background: transparent;
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 700;
cursor: pointer;
}
.small-button:hover,
.small-button:focus-visible {
background: #fff;
outline: none;
}
.stage-track {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 6px;
}
.stage-button {
position: relative;
min-width: 0;
padding: 9px 8px 8px;
border: 1px solid var(--line);
background: transparent;
color: var(--muted);
font: inherit;
text-align: left;
cursor: pointer;
}
.stage-button::before {
position: absolute;
top: -1px;
right: -1px;
left: -1px;
height: 2px;
background: transparent;
content: "";
}
.stage-button span {
display: block;
margin-bottom: 3px;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.08em;
}
.stage-button small {
display: block;
overflow: hidden;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.stage-button:hover,
.stage-button:focus-visible {
border-color: rgba(36, 39, 36, 0.4);
outline: none;
}
.stage-button.active {
border-color: rgba(36, 39, 36, 0.45);
background: #fff;
color: var(--ink);
}
.stage-button.active::before {
background: var(--ink);
}
.legend {
border-left: 1px solid var(--line);
padding-left: 18px;
}
.legend-items {
display: grid;
gap: 9px;
margin-top: 14px;
}
.legend-item {
display: grid;
grid-template-columns: 9px 1fr;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 10px;
line-height: 1.3;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
.legend-note {
margin: 11px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.4;
}
.view-tools {
border-left: 1px solid var(--line);
padding-left: 18px;
}
.tool-row {
display: flex;
align-items: center;
gap: 7px;
margin-top: 12px;
color: var(--muted);
font-size: 10px;
cursor: pointer;
}
.tool-row input {
accent-color: var(--ink);
}
.interaction-note {
margin: 13px 0 0;
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.hide-annotations .annotation {
opacity: 0 !important;
}
@media (max-width: 900px) {
.masthead {
top: 15px;
left: 17px;
right: 17px;
}
.origin-note {
max-width: 280px;
}
.comparison {
top: 112px;
left: 14px;
right: 14px;
bottom: 178px;
gap: 12px;
}
.branch-copy {
top: 12px;
left: 12px;
max-width: calc(100% - 24px);
padding: 9px 10px;
}
.branch-copy h2 {
font-size: 19px;
}
.branch-copy p {
display: none;
}
.metric {
min-height: 45px;
padding: 7px;
}
.metric-value {
font-size: 9px;
}
.control-dock {
right: 14px;
bottom: 14px;
left: 14px;
grid-template-columns: 1.3fr 1fr;
gap: 14px;
min-height: 140px;
padding: 13px;
}
.view-tools {
display: none;
}
.legend {
padding-left: 14px;
}
}
@media (max-width: 680px) {
.masthead {
gap: 12px;
}
.subtitle {
display: none;
}
.origin-note {
max-width: 220px;
padding: 9px 10px;
}
.origin-note span {
font-size: 9px;
}
.comparison {
top: 91px;
bottom: 202px;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr;
gap: 9px;
}
.branch-copy {
top: 8px;
left: 8px;
}
.branch-copy h2 {
margin-bottom: 0;
font-size: 16px;
}
.branch-meta {
margin-bottom: 4px;
}
.metrics {
right: 8px;
bottom: 8px;
left: 8px;
}
.metric {
min-height: 38px;
padding: 5px 6px;
}
.metric-label {
margin-bottom: 2px;
font-size: 7px;
}
.metric-value {
font-size: 8px;
}
.annotation {
display: none;
}
.control-dock {
grid-template-columns: 1fr;
gap: 10px;
min-height: 190px;
}
.legend {
display: none;
}
.stage-button {
padding: 8px 5px;
}
.stage-button span {
font-size: 8px;
}
.stage-button small {
font-size: 8px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
role="img"
aria-label="Interactive low-poly comparison of repairing or replacing the same broken keepsake"
></canvas>
<header class="masthead">
<div>
<span class="kicker">Object study / material continuity</span>
<h1>After the break</h1>
<p class="subtitle">
One broken keepsake. Two branching continuations.
</p>
</div>
<div class="origin-note">
<strong>Shared origin</strong>
<span>
The same two-piece object enters both branches. The comparison reports
composition and continuity; it does not rank either endpoint.
</span>
</div>
</header>
<main class="comparison" id="comparison">
<section
class="branch-panel"
id="panel-repair"
style="--branch-color: var(--repair)"
>
<div class="branch-copy">
<div class="branch-meta">
<span class="branch-label">Branch A / Repair</span>
<span class="stage-badge" id="repair-stage-badge">Result</span>
</div>
<h2 id="repair-title">Retains the original</h2>
<p id="repair-description">
The repaired object retains both original fragments and a visible added seam.
</p>
</div>
<div class="annotation original" id="repair-original-label">
Original / 2 fragments
</div>
<div class="annotation added" id="repair-seam-label">
Introduced / seam material
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Active object</span>
<span class="metric-value" id="repair-active">Repaired original</span>
</div>
<div class="metric">
<span class="metric-label">Original parts</span>
<span class="metric-value" id="repair-parts">2 / 2 retained</span>
</div>
<div class="metric">
<span class="metric-label">Added material</span>
<span class="metric-value" id="repair-added">Localized seam</span>
</div>
</div>
</section>
<section
class="branch-panel"
id="panel-replacement"
style="--branch-color: var(--replacement)"
>
<div class="branch-copy">
<div class="branch-meta">
<span class="branch-label">Branch B / Replace</span>
<span class="stage-badge" id="replacement-stage-badge">Result</span>
</div>
<h2 id="replacement-title">Introduces a new object</h2>
<p id="replacement-description">
The new object is complete; both original fragments remain set aside.
</p>
</div>
<div class="annotation original" id="replacement-original-label">
Original / set aside
</div>
<div class="annotation added" id="replacement-new-label">
New object / introduced material
</div>
<div class="metrics">
<div class="metric">
<span class="metric-label">Active object</span>
<span class="metric-value" id="replacement-active">New object</span>
</div>
<div class="metric">
<span class="metric-label">Original parts</span>
<span class="metric-value" id="replacement-parts">0 / 2 in active object</span>
</div>
<div class="metric">
<span class="metric-label">Added material</span>
<span class="metric-value" id="replacement-added">Full new object</span>
</div>
</div>
</section>
</main>
<footer class="control-dock">
<section class="sequence">
<div class="sequence-top">
<span class="section-label">Shared process / select a stage</span>
<button class="small-button" id="play-button" type="button">Play sequence</button>
</div>
<div class="stage-track" aria-label="Comparison stages">
<button class="stage-button" data-stage="0" type="button">
<span>01</span><small>Broken</small>
</button>
<button class="stage-button" data-stage="1" type="button">
<span>02</span><small>Route</small>
</button>
<button class="stage-button" data-stage="2" type="button">
<span>03</span><small>Form</small>
</button>
<button class="stage-button active" data-stage="3" type="button">
<span>04</span><small>Result</small>
</button>
</div>
</section>
<section class="legend" aria-label="Material legend">
<span class="section-label">Material key</span>
<div class="legend-items">
<div class="legend-item">
<span class="swatch" style="background: var(--original)"></span>
<span>Original material and original fragments</span>
</div>
<div class="legend-item">
<span class="swatch" style="background: var(--repair)"></span>
<span>Introduced seam material in the repair branch</span>
</div>
<div class="legend-item">
<span class="swatch" style="background: var(--replacement)"></span>
<span>Introduced material in the replacement branch</span>
</div>
</div>
<p class="legend-note">
Moving points indicate material routing, not emotional change.
</p>
</section>
<section class="view-tools">
<span class="section-label">Display / camera</span>
<label class="tool-row">
<input id="toggle-labels" type="checkbox" checked />
Object labels
</label>
<label class="tool-row">
<input id="toggle-flows" type="checkbox" checked />
Material flows
</label>
<button class="small-button" id="reset-view" type="button">Reset view</button>
<p class="interaction-note">
Drag either scene to rotate both views. Scroll or pinch to zoom.
Arrow keys move through stages.
</p>
</section>
</footer>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and shared camera controls
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const colors = {
paper: new THREE.Color(0xf3f0e8),
repairScene: new THREE.Color(0xf0eee7),
replacementScene: new THREE.Color(0xf0edf0),
original: new THREE.Color(0xd49a4e),
originalSide: new THREE.Color(0x865b31),
repair: new THREE.Color(0x2498a8),
replacement: new THREE.Color(0x7967c7)
};
function makeCamera() {
const camera = new THREE.PerspectiveCamera(
35,
1,
0.1,
100
);
camera.position.set(0, 0.5, 6.2);
camera.lookAt(0, -0.03, 0);
return camera;
}
function addLighting(scene) {
const hemisphere = new THREE.HemisphereLight(
0xfffcf4,
0x8c918d,
2.1
);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff5df, 3.2);
key.position.set(-3.5, 5.5, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -5;
key.shadow.camera.right = 5;
key.shadow.camera.top = 5;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.1;
key.shadow.camera.far = 15;
key.shadow.bias = -0.0008;
scene.add(key);
const rim = new THREE.DirectionalLight(0xb9d9e4, 1.3);
rim.position.set(4, 2, -4);
scene.add(rim);
}
function makeGround(scene, color = 0xdedbd2) {
const ground = new THREE.Mesh(
new THREE.CircleGeometry(3.4, 32),
new THREE.MeshStandardMaterial({
color,
roughness: 1,
metalness: 0,
flatShading: true
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.06;
ground.receiveShadow = true;
scene.add(ground);
return ground;
}
// -------------------------------------------------------------------------
// Low-poly keepsake geometry
// -------------------------------------------------------------------------
const leftOutline = [
[-0.12, 0.72],
[-0.52, 0.78],
[-0.90, 0.48],
[-0.95, 0.04],
[-0.78, -0.45],
[-0.45, -0.72],
[0.05, -0.68],
[-0.06, -0.22],
[0.08, 0.02],
[-0.04, 0.30]
];
const rightOutline = [
[-0.12, 0.72],
[-0.04, 0.30],
[0.08, 0.02],
[-0.06, -0.22],
[0.05, -0.68],
[0.55, -0.73],
[0.88, -0.45],
[0.96, 0.02],
[0.72, 0.62],
[0.25, 0.77]
];
function makeFragmentGeometry(points) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], points[i][1]);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.18,
bevelEnabled: true,
bevelSegments: 1,
steps: 1,
bevelSize: 0.035,
bevelThickness: 0.025,
curveSegments: 1
});
geometry.translate(0, 0, -0.09);
geometry.computeVertexNormals();
return geometry;
}
const leftGeometry = makeFragmentGeometry(leftOutline);
const rightGeometry = makeFragmentGeometry(rightOutline);
const originalMaterials = [
new THREE.MeshStandardMaterial({
color: colors.original,
roughness: 0.78,
metalness: 0.06,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: colors.originalSide,
roughness: 0.9,
metalness: 0.02,
flatShading: true
})
];
function makeFragment(geometry, markPosition) {
const group = new THREE.Group();
const fragment = new THREE.Mesh(
geometry,
originalMaterials
);
fragment.castShadow = true;
fragment.receiveShadow = true;
group.add(fragment);
// A small maker's mark helps establish identity across both branches.
const mark = new THREE.Mesh(
new THREE.ConeGeometry(0.065, 0.035, 3),
new THREE.MeshStandardMaterial({
color: 0x563d29,
roughness: 0.9,
flatShading: true
})
);
mark.position.set(markPosition[0], markPosition[1], 0.125);
mark.rotation.x = Math.PI / 2;
mark.rotation.z = Math.PI / 6;
mark.castShadow = true;
group.add(mark);
return group;
}
function makeOriginalPair() {
const pair = new THREE.Group();
const left = makeFragment(leftGeometry, [-0.55, 0.18]);
const right = makeFragment(rightGeometry, [0.50, 0.22]);
pair.add(left, right);
pair.userData.left = left;
pair.userData.right = right;
return pair;
}
function makeRepairSeam() {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color: colors.repair,
roughness: 0.62,
metalness: 0.12,
flatShading: true
});
const positions = [
[-0.015, 0.52, 0.13, -0.08],
[0.035, 0.25, 0.12, 0.12],
[-0.035, -0.02, 0.13, -0.05],
[0.025, -0.30, 0.12, 0.10],
[-0.005, -0.54, 0.13, -0.06]
];
group.userData.chips = [];
for (const [x, y, z, rotation] of positions) {
const chip = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.115, 0),
material
);
chip.position.set(x, y, z);
chip.scale.set(0.48, 1.35, 0.72);
chip.rotation.z = rotation;
chip.castShadow = true;
group.add(chip);
group.userData.chips.push(chip);
}
return group;
}
function makeReplacementObject() {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: colors.replacement,
roughness: 0.66,
metalness: 0.1,
flatShading: true
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x4d417f,
roughness: 0.75,
metalness: 0.08,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.62, 0),
bodyMaterial
);
body.scale.set(0.86, 1.18, 0.72);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const band = new THREE.Mesh(
new THREE.TorusGeometry(0.47, 0.035, 4, 8),
darkMaterial
);
band.scale.set(0.9, 1.15, 1);
band.castShadow = true;
group.add(band);
const cap = new THREE.Mesh(
new THREE.ConeGeometry(0.14, 0.25, 5),
darkMaterial
);
cap.position.y = 0.72;
cap.castShadow = true;
group.add(cap);
return group;
}
// -------------------------------------------------------------------------
// Material-flow paths and moving points
// -------------------------------------------------------------------------
function makeFlow(scene, points, color, particleCount = 11) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const lineGeometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(64)
);
const lineMaterial = new THREE.LineDashedMaterial({
color,
dashSize: 0.075,
gapSize: 0.055,
transparent: true,
opacity: 0
});
const line = new THREE.Line(lineGeometry, lineMaterial);
line.computeLineDistances();
scene.add(line);
const particleMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.9
});
const particles = [];
for (let i = 0; i < particleCount; i++) {
const particle = new THREE.Mesh(
new THREE.TetrahedronGeometry(0.035, 0),
particleMaterial
);
particle.rotation.set(i * 0.7, i * 0.3, i * 0.5);
scene.add(particle);
particles.push(particle);
}
return {
curve,
line,
lineMaterial,
particleMaterial,
particles
};
}
function updateFlow(flow, strength, elapsed, speed = 0.17) {
const s = THREE.MathUtils.clamp(strength, 0, 1);
flow.lineMaterial.opacity = 0.48 * s;
flow.particleMaterial.opacity = 0.9 * s;
flow.particles.forEach((particle, index) => {
const t = (elapsed * speed + index / flow.particles.length) % 1;
const point = flow.curve.getPoint(t);
particle.position.copy(point);
particle.scale.setScalar(0.65 + Math.sin(t * Math.PI) * 0.65);
particle.visible = s > 0.015;
});
}
// -------------------------------------------------------------------------
// Repair branch
// -------------------------------------------------------------------------
function createRepairBranch() {
const scene = new THREE.Scene();
scene.background = colors.repairScene;
addLighting(scene);
makeGround(scene, 0xdedbd2);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(1.3, 1.44, 0.16, 8),
new THREE.MeshStandardMaterial({
color: 0xcfd0c9,
roughness: 0.95,
flatShading: true
})
);
pedestal.position.y = -0.94;
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const original = makeOriginalPair();
original.position.y = 0.02;
scene.add(original);
const seam = makeRepairSeam();
seam.position.y = 0.02;
seam.scale.setScalar(0.001);
scene.add(seam);
const originalMarker = new THREE.Object3D();
originalMarker.position.set(-0.48, 0.28, 0.18);
original.userData.left.add(originalMarker);
const seamMarker = new THREE.Object3D();
seamMarker.position.set(0.02, 0.32, 0.2);
seam.add(seamMarker);
const originalFlow = makeFlow(
scene,
[
[-1.7, -1.28, 0.3],
[-1.05, -0.78, 0.22],
[-0.63, -0.22, 0.18],
[-0.48, 0.16, 0.2]
],
colors.original
);
const repairFlow = makeFlow(
scene,
[
[0.02, -1.35, 0.28],
[0.18, -0.78, 0.25],
[0.08, -0.28, 0.22],
[0.02, 0.38, 0.22]
],
colors.repair
);
return {
scene,
camera: makeCamera(),
original,
seam,
originalMarker,
seamMarker,
originalFlow,
repairFlow
};
}
// -------------------------------------------------------------------------
// Replacement branch
// -------------------------------------------------------------------------
function createReplacementBranch() {
const scene = new THREE.Scene();
scene.background = colors.replacementScene;
addLighting(scene);
makeGround(scene, 0xded9df);
const archivePlatform = new THREE.Mesh(
new THREE.BoxGeometry(1.45, 0.14, 0.72),
new THREE.MeshStandardMaterial({
color: 0xcfcacd,
roughness: 0.95,
transparent: true,
opacity: 1,
flatShading: true
})
);
archivePlatform.position.set(-1.17, -0.84, -0.08);
archivePlatform.castShadow = true;
archivePlatform.receiveShadow = true;
scene.add(archivePlatform);
const newPlatform = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 1.0, 0.16, 8),
new THREE.MeshStandardMaterial({
color: 0xd2ccd8,
roughness: 0.95,
flatShading: true
})
);
newPlatform.position.set(0.62, -0.94, 0);
newPlatform.castShadow = true;
newPlatform.receiveShadow = true;
scene.add(newPlatform);
const original = makeOriginalPair();
original.position.y = 0.02;
scene.add(original);
const newObject = makeReplacementObject();
newObject.position.set(0.62, 0.02, 0);
newObject.scale.setScalar(0.001);
scene.add(newObject);
const originalMarker = new THREE.Object3D();
originalMarker.position.set(-0.42, 0.28, 0.18);
original.userData.left.add(originalMarker);
const newMarker = new THREE.Object3D();
newMarker.position.set(0, 0.94, 0.1);
newObject.add(newMarker);
const originalFlow = makeFlow(
scene,
[
[0.02, -1.32, 0.3],
[-0.28, -0.92, 0.22],
[-0.74, -0.63, 0.18],
[-1.17, -0.34, 0.18]
],
colors.original
);
const replacementFlow = makeFlow(
scene,
[
[0.62, -1.38, 0.3],
[0.68, -0.82, 0.25],
[0.60, -0.31, 0.2],
[0.62, 0.15, 0.15]
],
colors.replacement
);
return {
scene,
camera: makeCamera(),
original,
newObject,
archivePlatform,
originalMarker,
newMarker,
originalFlow,
replacementFlow
};
}
const repair = createRepairBranch();
const replacement = createReplacementBranch();
// -------------------------------------------------------------------------
// Stage state and narratives
// -------------------------------------------------------------------------
let targetStage = 3;
let currentStage = 3;
let playing = false;
let playTimer = null;
const repairNarratives = [
{
badge: "Broken",
title: "One object in two pieces",
description:
"Both branches begin with the same two original fragments and the same material history.",
active: "Broken original",
parts: "2 / 2 present",
added: "None"
},
{
badge: "Route / repair",
title: "Original pieces are aligned",
description:
"The original fragments are brought into a shared alignment without changing their material identity.",
active: "Original in alignment",
parts: "2 / 2 retained",
added: "Not yet introduced"
},
{
badge: "Route / form",
title: "A localized material is introduced",
description:
"A limited quantity of contrasting material is applied only along the original break.",
active: "Original with added seam",
parts: "2 / 2 retained",
added: "Localized seam"
},
{
badge: "Result",
title: "Retains the original",
description:
"The repaired object retains both original fragments and a visible added seam.",
active: "Repaired original",
parts: "2 / 2 retained",
added: "Localized seam"
}
];
const replacementNarratives = [
{
badge: "Broken",
title: "One object in two pieces",
description:
"Both branches begin with the same two original fragments and the same material history.",
active: "Broken original",
parts: "2 / 2 present",
added: "None"
},
{
badge: "Route / separate",
title: "Original pieces are set aside",
description:
"The original fragments remain present as a record but are separated from the active object.",
active: "No active object yet",
parts: "0 / 2 in active object",
added: "Not yet introduced"
},
{
badge: "Route / form",
title: "A different object is assembled",
description:
"A new material stream assembles a geometric object with no original fragments inside it.",
active: "New object forming",
parts: "0 / 2 in active object",
added: "Full new object"
},
{
badge: "Result",
title: "Introduces a new object",
description:
"The new object is complete; both original fragments remain set aside.",
active: "New object",
parts: "0 / 2 in active object",
added: "Full new object"
}
];
function setStage(stage) {
targetStage = THREE.MathUtils.clamp(Math.round(stage), 0, 3);
document.querySelectorAll(".stage-button").forEach((button) => {
button.classList.toggle(
"active",
Number(button.dataset.stage) === targetStage
);
});
const repairData = repairNarratives[targetStage];
const replacementData = replacementNarratives[targetStage];
document.querySelector("#repair-stage-badge").textContent = repairData.badge;
document.querySelector("#replacement-stage-badge").textContent =
replacementData.badge;
document.querySelector("#repair-title").textContent = repairData.title;
document.querySelector("#replacement-title").textContent =
replacementData.title;
document.querySelector("#repair-description").textContent =
repairData.description;
document.querySelector("#replacement-description").textContent =
replacementData.description;
document.querySelector("#repair-active").textContent = repairData.active;
document.querySelector("#repair-parts").textContent = repairData.parts;
document.querySelector("#repair-added").textContent = repairData.added;
document.querySelector("#replacement-active").textContent =
replacementData.active;
document.querySelector("#replacement-parts").textContent =
replacementData.parts;
document.querySelector("#replacement-added").textContent =
replacementData.added;
}
document.querySelectorAll(".stage-button").forEach((button) => {
button.addEventListener("click", () => {
setStage(Number(button.dataset.stage));
});
});
function stopPlayback() {
playing = false;
clearInterval(playTimer);
playTimer = null;
document.querySelector("#play-button").textContent = "Play sequence";
}
document.querySelector("#play-button").addEventListener("click", () => {
if (playing) {
stopPlayback();
return;
}
if (targetStage >= 3) {
setStage(0);
}
playing = true;
document.querySelector("#play-button").textContent = "Pause";
playTimer = setInterval(() => {
setStage((targetStage + 1) % 4);
}, 1700);
});
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
setStage(targetStage - 1);
}
if (event.key === "ArrowRight") {
setStage(targetStage + 1);
}
});
// -------------------------------------------------------------------------
// Direct camera controls
// -------------------------------------------------------------------------
const cameraState = {
yaw: 0,
pitch: 0.08,
distance: 6.2,
target: new THREE.Vector3(0, -0.03, 0)
};
let dragging = false;
let dragX = 0;
let dragY = 0;
let activePointerId = null;
function pointInPanel(x, y, rect) {
return (
x >= rect.left &&
x <= rect.right &&
y >= rect.top &&
y <= rect.bottom
);
}
canvas.addEventListener("pointerdown", (event) => {
const panels = [
document.querySelector("#panel-repair"),
document.querySelector("#panel-replacement")
];
const overPanel = panels.some((panel) =>
pointInPanel(
event.clientX,
event.clientY,
panel.getBoundingClientRect()
)
);
if (!overPanel) return;
dragging = true;
activePointerId = event.pointerId;
dragX = event.clientX;
dragY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - dragX;
const dy = event.clientY - dragY;
dragX = event.clientX;
dragY = event.clientY;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.0045,
-0.55,
0.7
);
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.003,
4.2,
9
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset-view").addEventListener("click", resetView);
function resetView() {
cameraState.yaw = 0;
cameraState.pitch = 0.08;
cameraState.distance = 6.2;
}
function updateCamera(camera) {
const { yaw, pitch, distance, target } = cameraState;
camera.position.set(
target.x + distance * Math.sin(yaw) * Math.cos(pitch),
target.y + distance * Math.sin(pitch),
target.z + distance * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(target);
camera.updateMatrixWorld();
}
// -------------------------------------------------------------------------
// Display toggles
// -------------------------------------------------------------------------
let labelsVisible = true;
let flowsVisible = true;
document
.querySelector("#toggle-labels")
.addEventListener("change", (event) => {
labelsVisible = event.target.checked;
document.body.classList.toggle("hide-annotations", !labelsVisible);
});
document
.querySelector("#toggle-flows")
.addEventListener("change", (event) => {
flowsVisible = event.target.checked;
});
// -------------------------------------------------------------------------
// Stage interpolation and animation
// -------------------------------------------------------------------------
function smoothstep(edge0, edge1, value) {
const t = THREE.MathUtils.clamp(
(value - edge0) / (edge1 - edge0),
0,
1
);
return t * t * (3 - 2 * t);
}
function updateRepair(stage, elapsed) {
const left = repair.original.userData.left;
const right = repair.original.userData.right;
const align = smoothstep(0, 1, stage);
const close = smoothstep(1, 2, stage);
const seamAmount = smoothstep(1.05, 1.95, stage);
let separation = THREE.MathUtils.lerp(0.27, 0.065, align);
separation = THREE.MathUtils.lerp(separation, 0.008, close);
left.position.x = -separation;
right.position.x = separation;
left.position.y = THREE.MathUtils.lerp(-0.045, 0.015, align);
right.position.y = THREE.MathUtils.lerp(0.035, 0.015, align);
left.rotation.z = THREE.MathUtils.lerp(0.045, 0.008, align);
right.rotation.z = THREE.MathUtils.lerp(-0.035, -0.008, align);
repair.seam.visible = seamAmount > 0.01;
repair.seam.scale.setScalar(Math.max(0.001, seamAmount));
repair.seam.userData.chips.forEach((chip, index) => {
chip.rotation.y = elapsed * (index % 2 ? -0.22 : 0.22);
});
updateFlow(
repair.originalFlow,
flowsVisible ? 0.28 + align * 0.55 : 0,
elapsed,
0.13
);
updateFlow(
repair.repairFlow,
flowsVisible ? seamAmount : 0,
elapsed,
0.19
);
}
function updateReplacement(stage, elapsed) {
const left = replacement.original.userData.left;
const right = replacement.original.userData.right;
const setAside = smoothstep(0.55, 1.45, stage);
const form = smoothstep(1.45, 2.4, stage);
const separation = THREE.MathUtils.lerp(0.27, 0.14, setAside);
const archiveX = -1.18 * setAside;
const archiveY = -0.34 * setAside;
left.position.x = archiveX - separation;
right.position.x = archiveX + separation;
left.position.y = archiveY;
right.position.y = archiveY;
left.rotation.z = THREE.MathUtils.lerp(0.045, -0.23, setAside);
right.rotation.z = THREE.MathUtils.lerp(-0.035, 0.2, setAside);
left.rotation.y = THREE.MathUtils.lerp(0, -0.28, setAside);
right.rotation.y = THREE.MathUtils.lerp(0, 0.25, setAside);
replacement.archivePlatform.material.opacity = 0.35 + setAside * 0.65;
replacement.newObject.visible = form > 0.005;
replacement.newObject.scale.setScalar(Math.max(0.001, form * 0.96));
replacement.newObject.rotation.y =
Math.sin(elapsed * 0.42) * 0.1 + form * 0.16;
replacement.newObject.rotation.z =
Math.sin(elapsed * 0.31) * 0.025;
updateFlow(
replacement.originalFlow,
flowsVisible ? setAside * 0.85 : 0,
elapsed,
0.15
);
updateFlow(
replacement.replacementFlow,
flowsVisible ? form : 0,
elapsed,
0.2
);
}
// -------------------------------------------------------------------------
// DOM annotations projected from scene coordinates
// -------------------------------------------------------------------------
function positionAnnotation(element, object, camera, panel) {
const world = new THREE.Vector3();
object.getWorldPosition(world);
world.project(camera);
const x = (world.x * 0.5 + 0.5) * panel.clientWidth;
const y = (-world.y * 0.5 + 0.5) * panel.clientHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function updateAnnotations() {
const repairPanel = document.querySelector("#panel-repair");
const replacementPanel = document.querySelector("#panel-replacement");
const repairOriginal = document.querySelector(
"#repair-original-label"
);
const repairSeam = document.querySelector("#repair-seam-label");
const replacementOriginal = document.querySelector(
"#replacement-original-label"
);
const replacementNew = document.querySelector(
"#replacement-new-label"
);
if (labelsVisible) {
positionAnnotation(
repairOriginal,
repair.originalMarker,
repair.camera,
repairPanel
);
positionAnnotation(
repairSeam,
repair.seamMarker,
repair.camera,
repairPanel
);
positionAnnotation(
replacementOriginal,
replacement.originalMarker,
replacement.camera,
replacementPanel
);
positionAnnotation(
replacementNew,
replacement.newMarker,
replacement.camera,
replacementPanel
);
}
repairSeam.style.opacity =
currentStage > 1.2 ? String(smoothstep(1.2, 1.8, currentStage)) : "0";
replacementOriginal.style.opacity = String(
0.45 + smoothstep(0.7, 1.4, currentStage) * 0.55
);
replacementNew.style.opacity = String(
smoothstep(1.5, 2.1, currentStage)
);
}
// -------------------------------------------------------------------------
// Scissor rendering for the two comparison views
// -------------------------------------------------------------------------
function resizeRenderer() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resizeRenderer);
function renderBranch(branch, panel) {
const rect = panel.getBoundingClientRect();
const x = Math.round(rect.left);
const y = Math.round(window.innerHeight - rect.bottom);
const width = Math.round(rect.width);
const height = Math.round(rect.height);
renderer.setViewport(x, y, width, height);
renderer.setScissor(x, y, width, height);
branch.camera.aspect = width / Math.max(height, 1);
branch.camera.updateProjectionMatrix();
updateCamera(branch.camera);
renderer.render(branch.scene, branch.camera);
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
currentStage += (targetStage - currentStage) * 0.075;
if (Math.abs(targetStage - currentStage) < 0.0005) {
currentStage = targetStage;
}
updateRepair(currentStage, elapsed);
updateReplacement(currentStage, elapsed);
renderer.setScissorTest(false);
renderer.setViewport(0, 0, window.innerWidth, window.innerHeight);
renderer.setClearColor(colors.paper, 1);
renderer.clear();
renderer.setScissorTest(true);
renderBranch(repair, document.querySelector("#panel-repair"));
renderBranch(
replacement,
document.querySelector("#panel-replacement")
);
renderer.setScissorTest(false);
updateAnnotations();
}
setStage(3);
animate();
</script>
</body>
</html>
```