Prompt specification
Build or customize the Three.js 3D scene "Barrel vault cross-section slice" 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: Barrel vault cross-section slice
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/barrel-vault-cross-section-slice-x2233
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a short barrel-vault segment with a removable end slice. Make the continuous curved surface and two supporting wall lines visible from inside and above. Voxel style.
Working Three.js Starter (barrel-vault-cross-section-slice-x2233):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Barrel Vault</title>
<style>
:root {
--ink: #edf6f3;
--muted: #99aaa9;
--panel: rgba(13, 22, 27, 0.88);
--border: rgba(190, 224, 218, 0.16);
--mint: #68e3ca;
--orange: #ef9468;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0d151b;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.title-block {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
pointer-events: none;
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--mint);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
width: 25px;
height: 2px;
content: "";
background: var(--mint);
box-shadow: 0 0 12px rgba(104, 227, 202, 0.55);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 48px);
font-weight: 720;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 390px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: fixed;
top: 26px;
right: 26px;
z-index: 10;
width: 246px;
padding: 16px;
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
}
.control-label {
margin-bottom: 9px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.view-buttons {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-bottom: 13px;
}
.view-buttons button,
.secondary {
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.035);
color: #bdcbc9;
cursor: pointer;
transition:
color 150ms ease,
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.view-buttons button {
min-height: 34px;
padding: 7px 5px;
font-size: 11px;
font-weight: 650;
}
.view-buttons button:hover,
.secondary:hover {
border-color: rgba(104, 227, 202, 0.4);
color: var(--ink);
background: rgba(104, 227, 202, 0.08);
}
.view-buttons button.active {
border-color: rgba(104, 227, 202, 0.48);
background: rgba(104, 227, 202, 0.13);
color: var(--mint);
}
.primary,
.secondary {
width: 100%;
min-height: 42px;
padding: 10px 12px;
font-size: 12px;
font-weight: 720;
}
.primary {
border: 1px solid rgba(239, 148, 104, 0.48);
border-radius: 10px;
background: rgba(239, 148, 104, 0.14);
color: #ffc3a4;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
.primary:hover {
background: rgba(239, 148, 104, 0.22);
}
.primary:active,
.secondary:active {
transform: translateY(1px);
}
.secondary {
margin-top: 7px;
}
.status {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
padding-top: 12px;
border-top: 1px solid var(--border);
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.status-dot {
width: 7px;
height: 7px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 10px rgba(239, 148, 104, 0.55);
}
.legend {
position: fixed;
bottom: 25px;
left: 29px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 17px;
max-width: calc(100vw - 58px);
padding: 11px 14px;
border: 1px solid var(--border);
border-radius: 12px;
background: rgba(13, 22, 27, 0.76);
color: var(--muted);
font-size: 10px;
pointer-events: none;
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
background: #c9b99f;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.swatch.support {
background: var(--mint);
box-shadow: 0 0 8px rgba(104, 227, 202, 0.45);
}
.swatch.slice {
background: var(--orange);
box-shadow: 0 0 8px rgba(239, 148, 104, 0.35);
}
.hint {
position: fixed;
right: 28px;
bottom: 27px;
z-index: 5;
color: rgba(205, 219, 216, 0.58);
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 5px 7px;
border: 1px solid rgba(104, 227, 202, 0.22);
border-radius: 6px;
background: rgba(8, 17, 21, 0.75);
color: var(--mint);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 120ms ease;
backdrop-filter: blur(8px);
}
.world-label::before {
width: 5px;
height: 5px;
content: "";
border-radius: 50%;
background: var(--mint);
box-shadow: 0 0 8px var(--mint);
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
background: #0d151b;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 450ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.title-block {
top: 20px;
left: 19px;
max-width: calc(100vw - 38px);
}
h1 {
font-size: 30px;
}
.subtitle {
display: none;
}
.controls {
top: auto;
right: 14px;
bottom: 67px;
width: 220px;
padding: 12px;
}
.legend {
bottom: 15px;
left: 14px;
gap: 11px;
padding: 9px 11px;
}
.hint {
display: none;
}
.world-label {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="title-block">
<div class="eyebrow">Exploded architecture study</div>
<h1>Voxel Barrel Vault</h1>
<p class="subtitle">
A short masonry vault with a detachable end slice. The inner curved
surface and both supporting springing lines remain readable from the
interior and elevated views.
</p>
</header>
<aside class="controls" aria-label="Vault controls">
<div class="control-label">Camera</div>
<div class="view-buttons">
<button type="button" data-view="overview" class="active">
Overview
</button>
<button type="button" data-view="interior">
Inside
</button>
<button type="button" data-view="above">
Above
</button>
</div>
<button type="button" id="sliceToggle" class="primary" aria-pressed="true">
Restore end slice
</button>
<button type="button" id="resetView" class="secondary">
Reset view
</button>
<div class="status">
<span class="status-dot"></span>
<span id="statusText">End slice detached · opening exposed</span>
</div>
</aside>
<div class="world-label" id="labelA">Support A</div>
<div class="world-label" id="labelB">Support B</div>
<div class="legend" aria-label="Model legend">
<div class="legend-item">
<span class="swatch"></span>
Continuous voxel shell
</div>
<div class="legend-item">
<span class="swatch support"></span>
Supporting wall lines
</div>
<div class="legend-item">
<span class="swatch slice"></span>
Removable end slice
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Space to remove / restore</div>
<div id="loading">Loading Three.js module…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const stage = document.getElementById("stage");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0d151b);
scene.fog = new THREE.Fog(0x0d151b, 18, 38);
const camera = new THREE.PerspectiveCamera(
48,
window.innerWidth / window.innerHeight,
0.05,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D voxel barrel vault"
);
stage.appendChild(renderer.domElement);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xd9f1ff, 0x172028, 2.15));
const sun = new THREE.DirectionalLight(0xffe0b8, 3.1);
sun.position.set(7, 13, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x8dcfff, 1.35);
rimLight.position.set(-8, 6, -9);
scene.add(rimLight);
const interiorLightA = new THREE.PointLight(0x8bffe3, 22, 11, 2);
interiorLightA.position.set(0, 2.8, -1.8);
scene.add(interiorLightA);
const interiorLightB = new THREE.PointLight(0xffc48b, 17, 10, 2);
interiorLightB.position.set(0, 2.4, 3.5);
scene.add(interiorLightB);
// -------------------------------------------------------------------------
// Ground and grid
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x111c22,
roughness: 0.96,
metalness: 0.02
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(
30,
30,
0x42636a,
0x203139
);
grid.position.y = -0.015;
grid.material.transparent = true;
grid.material.opacity = 0.48;
scene.add(grid);
// -------------------------------------------------------------------------
// Barrel-vault dimensions
//
// The vault axis runs along Z.
// The semicircular cross-section occupies the XY plane.
// -------------------------------------------------------------------------
const RADIUS = 4.0;
const BASE_Y = 0.65;
const DEPTH = 0.50;
const LENGTH = 11.84;
const ARC_STEPS = 24;
const Z_BANDS = 16;
const REMOVABLE_BANDS = 2;
const Z_STEP = LENGTH / Z_BANDS;
const HALF_LENGTH = LENGTH / 2;
const CUT_Z = -HALF_LENGTH + (Z_BANDS - REMOVABLE_BANDS) * Z_STEP;
const SLICE_END_Z = HALF_LENGTH;
const mainPalette = [
0xc9b99f,
0xd7c9ae,
0xbda78d,
0xe1d5bd,
0xb39a7f,
0xcdbca2
];
const slicePalette = [
0xe58a61,
0xf0a276,
0xd97855,
0xe89a73,
0xc96f50
];
const stoneMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0.02,
flatShading: true
});
const sliceMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0.025,
flatShading: true
});
const arcStep = Math.PI / ARC_STEPS;
const tangentLength =
2 * (RADIUS + DEPTH * 0.5) * Math.sin(arcStep * 0.5) * 1.045;
const blockGeometry = new THREE.BoxGeometry(
tangentLength,
DEPTH,
Z_STEP * 1.018
);
const mainEntries = [];
const sliceEntries = [];
for (let band = 0; band < Z_BANDS; band++) {
const z = -HALF_LENGTH + (band + 0.5) * Z_STEP;
for (let step = 0; step < ARC_STEPS; step++) {
const theta = (step + 0.5) * arcStep;
const radial = RADIUS + DEPTH * 0.5;
const position = new THREE.Vector3(
Math.cos(theta) * radial,
BASE_Y + Math.sin(theta) * radial,
z
);
const quaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0, 0, theta - Math.PI / 2)
);
const matrix = new THREE.Matrix4().compose(
position,
quaternion,
new THREE.Vector3(1, 1, 1)
);
const entry = {
matrix,
color:
band < Z_BANDS - REMOVABLE_BANDS
? mainPalette[
(step * 3 + band * 5 + ((step * band) % 3)) %
mainPalette.length
]
: slicePalette[
(step * 2 + band) % slicePalette.length
]
};
if (band < Z_BANDS - REMOVABLE_BANDS) {
mainEntries.push(entry);
} else {
sliceEntries.push(entry);
}
}
}
function createBlockMesh(entries, material) {
const mesh = new THREE.InstancedMesh(
blockGeometry,
material,
entries.length
);
entries.forEach((entry, index) => {
mesh.setMatrixAt(index, entry.matrix);
mesh.setColorAt(index, new THREE.Color(entry.color));
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
const mainShell = createBlockMesh(mainEntries, stoneMaterial);
scene.add(mainShell);
const sliceGroup = new THREE.Group();
sliceGroup.name = "Removable end slice";
scene.add(sliceGroup);
const removableShell = createBlockMesh(sliceEntries, sliceMaterial);
sliceGroup.add(removableShell);
// -------------------------------------------------------------------------
// Continuous section lines
// -------------------------------------------------------------------------
function createArcLine(z, color, opacity, parent = scene) {
const points = [];
for (let i = 0; i <= 72; i++) {
const theta = (i / 72) * Math.PI;
points.push(
new THREE.Vector3(
Math.cos(theta) * (RADIUS - 0.025),
BASE_Y + Math.sin(theta) * (RADIUS - 0.025),
z
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
});
const line = new THREE.Line(geometry, material);
parent.add(line);
return line;
}
createArcLine(-HALF_LENGTH + 0.015, 0x78dfd1, 0.42);
createArcLine(CUT_Z - 0.018, 0xf1a174, 0.68);
createArcLine(CUT_Z + 0.015, 0xf1a174, 0.72, sliceGroup);
createArcLine(SLICE_END_Z - 0.015, 0x78dfd1, 0.52, sliceGroup);
// -------------------------------------------------------------------------
// Two continuous supporting wall lines
// -------------------------------------------------------------------------
const foundationMaterial = new THREE.MeshStandardMaterial({
color: 0x30434a,
roughness: 0.9,
metalness: 0.05
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x68e3ca,
emissive: 0x24b99c,
emissiveIntensity: 1.85,
roughness: 0.34,
metalness: 0.15
});
function addBox(parent, width, height, depth, x, y, z, material) {
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;
}
for (const side of [-1, 1]) {
const x = side * RADIUS;
// Continuous foundation and highlighted supporting line.
addBox(
scene,
0.62,
0.30,
LENGTH + 0.45,
x,
0.15,
0,
foundationMaterial
);
addBox(
scene,
0.085,
0.085,
LENGTH + 0.30,
x,
0.43,
0,
supportMaterial
);
// Voxel footings emphasize the two straight wall lines.
for (let band = 0; band < Z_BANDS; band++) {
const z = -HALF_LENGTH + (band + 0.5) * Z_STEP;
addBox(
scene,
0.72,
0.34,
Z_STEP * 0.84,
x,
0.17,
z,
foundationMaterial
);
}
}
// -------------------------------------------------------------------------
// Dashed extraction guides for the removable slice
// -------------------------------------------------------------------------
const connectorMaterial = new THREE.LineDashedMaterial({
color: 0x83dfd3,
transparent: true,
opacity: 0,
dashSize: 0.14,
gapSize: 0.10
});
const connectors = [];
for (const side of [-1, 1]) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(6), 3)
);
const line = new THREE.Line(geometry, connectorMaterial);
line.frustumCulled = false;
scene.add(line);
connectors.push({ line, side });
}
// -------------------------------------------------------------------------
// Camera presets
// -------------------------------------------------------------------------
const presets = {
overview: {
position: new THREE.Vector3(0, 4.1, 13.2),
target: new THREE.Vector3(0, 2.15, -0.4)
},
interior: {
position: new THREE.Vector3(0, 3.15, -5.55),
target: new THREE.Vector3(0, 2.45, 4.65)
},
above: {
position: new THREE.Vector3(10.5, 11.8, 12.8),
target: new THREE.Vector3(0, 1.65, 0)
}
};
const currentTarget = presets.overview.target.clone();
const desiredTarget = currentTarget.clone();
camera.position.copy(presets.overview.position);
camera.lookAt(currentTarget);
const currentSpherical = new THREE.Spherical().setFromVector3(
camera.position.clone().sub(currentTarget)
);
const desiredSpherical = currentSpherical.clone();
const cameraOffset = new THREE.Vector3();
function setView(name) {
const preset = presets[name];
if (!preset) return;
desiredTarget.copy(preset.target);
desiredSpherical.setFromVector3(
preset.position.clone().sub(desiredTarget)
);
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === name);
});
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
document.getElementById("resetView").addEventListener("click", () => {
setView("overview");
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, zoom and touch drag
// -------------------------------------------------------------------------
let pointerActive = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointerActive = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.focus();
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointerActive) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
desiredSpherical.theta -= deltaX * 0.006;
desiredSpherical.phi = THREE.MathUtils.clamp(
desiredSpherical.phi - deltaY * 0.006,
0.12,
Math.PI - 0.12
);
});
function endPointer(event) {
pointerActive = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredSpherical.radius = THREE.MathUtils.clamp(
desiredSpherical.radius * Math.exp(event.deltaY * 0.001),
4.5,
28
);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Removable end slice
// -------------------------------------------------------------------------
const sliceToggle = document.getElementById("sliceToggle");
const statusText = document.getElementById("statusText");
let sliceRemoved = true;
let slicePositionTarget = new THREE.Vector3();
let sliceRotationTarget = 0;
const detachedPosition = new THREE.Vector3(5.2, 3.6, 0.8);
const detachedRotation = -0.22;
function updateSliceState(removed, immediate = false) {
sliceRemoved = removed;
if (removed) {
slicePositionTarget.copy(detachedPosition);
sliceRotationTarget = detachedRotation;
sliceToggle.textContent = "Restore end slice";
sliceToggle.setAttribute("aria-pressed", "true");
statusText.textContent = "End slice detached · opening exposed";
} else {
slicePositionTarget.set(0, 0, 0);
sliceRotationTarget = 0;
sliceToggle.textContent = "Remove end slice";
sliceToggle.setAttribute("aria-pressed", "false");
statusText.textContent = "End slice installed · continuous vault";
}
if (immediate) {
sliceGroup.position.copy(slicePositionTarget);
sliceGroup.rotation.y = sliceRotationTarget;
}
}
sliceToggle.addEventListener("click", () => {
updateSliceState(!sliceRemoved);
});
updateSliceState(true, true);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
updateSliceState(!sliceRemoved);
}
if (event.key === "1") setView("overview");
if (event.key === "2") setView("interior");
if (event.key === "3") setView("above");
});
// -------------------------------------------------------------------------
// Screen-space labels for the two supporting lines
// -------------------------------------------------------------------------
const labelA = document.getElementById("labelA");
const labelB = document.getElementById("labelB");
const labelAnchors = [
{
element: labelA,
point: new THREE.Vector3(RADIUS, 0.56, 2.35)
},
{
element: labelB,
point: new THREE.Vector3(-RADIUS, 0.56, 2.35)
}
];
function updateWorldLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelAnchors) {
const projected = label.point.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 0.92 &&
Math.abs(projected.y) < 0.88;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left = `${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top = `${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
const connectorDestination = new THREE.Vector3();
const connectorOrigin = new THREE.Vector3();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 6.5);
// Smooth camera movement.
currentTarget.lerp(desiredTarget, smoothing);
const thetaDelta = Math.atan2(
Math.sin(desiredSpherical.theta - currentSpherical.theta),
Math.cos(desiredSpherical.theta - currentSpherical.theta)
);
currentSpherical.theta += thetaDelta * smoothing;
currentSpherical.phi +=
(desiredSpherical.phi - currentSpherical.phi) * smoothing;
currentSpherical.radius +=
(desiredSpherical.radius - currentSpherical.radius) * smoothing;
cameraOffset.setFromSpherical(currentSpherical);
camera.position.copy(currentTarget).add(cameraOffset);
camera.lookAt(currentTarget);
// Animate the exploded/removable slice.
sliceGroup.position.lerp(slicePositionTarget, smoothing);
sliceGroup.rotation.y +=
(sliceRotationTarget - sliceGroup.rotation.y) * smoothing;
sliceGroup.updateMatrixWorld(true);
// Update the dashed extraction guides.
connectorMaterial.opacity = sliceRemoved ? 0.48 : 0;
if (sliceRemoved) {
for (const connector of connectors) {
connectorOrigin.set(
connector.side * RADIUS,
BASE_Y,
CUT_Z
);
connectorDestination.set(
connector.side * RADIUS,
BASE_Y,
SLICE_END_Z - 0.02
);
sliceGroup.localToWorld(connectorDestination);
const positions = connector.line.geometry.attributes.position;
positions.setXYZ(0, connectorOrigin.x, connectorOrigin.y, connectorOrigin.z);
positions.setXYZ(
1,
connectorDestination.x,
connectorDestination.y,
connectorDestination.z
);
positions.needsUpdate = true;
connector.line.geometry.computeBoundingSphere();
connector.line.computeLineDistances();
}
}
updateWorldLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
renderer.render(scene, camera);
loading.classList.add("hidden");
</script>
</body>
</html>
```