Prompt specification
Build or customize the Three.js 3D scene "Schematic Stage Separation Sequence" 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: Schematic Stage Separation Sequence
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/schematic-stage-separation-sequence-x3814
Scene Description Prompt:
Build an HTML cutaway with Three.js from cdnjs showing fictional rocket stages separating continuously along an explicitly illustrative trajectory.
Working Three.js Starter (schematic-stage-separation-sequence-x3814):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vector-7 — Illustrative Rocket Cutaway</title>
<style>
:root {
color-scheme: dark;
--bg: #06101d;
--panel: rgba(8, 19, 33, 0.82);
--panel-border: rgba(156, 214, 255, 0.18);
--text: #edf8ff;
--muted: #91a9bb;
--cyan: #67ddff;
--orange: #ff9f43;
--stage-1: #ff785a;
--stage-2: #67ddff;
--stage-3: #bd8cff;
--payload: #ffe275;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
select,
input {
font: inherit;
}
button,
select {
color: var(--text);
background: rgba(17, 38, 58, 0.82);
border: 1px solid var(--panel-border);
border-radius: 8px;
}
button {
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover,
select:hover {
background: rgba(30, 62, 86, 0.95);
border-color: rgba(103, 221, 255, 0.5);
}
button:active {
transform: translateY(1px);
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.topbar {
position: absolute;
top: 24px;
left: 28px;
right: 28px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
}
.brand {
max-width: 560px;
text-shadow: 0 2px 20px rgba(0, 0, 0, 0.7);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.5vw, 48px);
font-weight: 680;
letter-spacing: -0.035em;
line-height: 1;
}
.subtitle {
margin-top: 12px;
max-width: 520px;
color: #b5c9d8;
font-size: 13px;
line-height: 1.55;
}
.route-badge {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 16px;
padding: 8px 11px;
color: #ffd8a8;
background: rgba(81, 42, 17, 0.66);
border: 1px solid rgba(255, 159, 67, 0.34);
border-radius: 999px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.route-badge::before {
width: 7px;
height: 7px;
content: "";
background: var(--orange);
border-radius: 50%;
box-shadow: 0 0 12px var(--orange);
}
.readout {
min-width: 260px;
padding: 15px 16px;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 12px;
backdrop-filter: blur(12px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.24);
}
.readout-row {
display: flex;
justify-content: space-between;
gap: 20px;
padding: 5px 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout-row strong {
color: var(--text);
font-variant-numeric: tabular-nums;
font-weight: 650;
letter-spacing: 0.02em;
text-transform: none;
}
#status {
color: var(--cyan);
}
.left-panel {
position: absolute;
top: 50%;
left: 28px;
width: 245px;
padding: 16px;
transform: translateY(-42%);
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 12px;
backdrop-filter: blur(12px);
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.24);
}
.panel-title {
margin-bottom: 12px;
color: #a9c0d1;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.vehicle-row {
display: grid;
grid-template-columns: 9px 1fr;
gap: 10px;
align-items: center;
padding: 7px 0;
}
.vehicle-row i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--dot);
box-shadow: 0 0 12px var(--dot);
}
.vehicle-row b {
display: block;
font-size: 12px;
font-weight: 650;
}
.vehicle-row small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 10px;
}
.note {
margin-top: 14px;
padding-top: 13px;
border-top: 1px solid var(--panel-border);
color: #9eb3c3;
font-size: 10px;
line-height: 1.55;
}
.note strong {
color: #ffc98f;
}
.events {
margin: 0;
padding: 0;
list-style: none;
}
.events li {
display: grid;
grid-template-columns: 39px 1fr;
gap: 9px;
padding: 7px 0;
color: #7890a3;
font-size: 11px;
transition: color 150ms ease;
}
.events li span {
font-variant-numeric: tabular-nums;
color: #7890a3;
}
.events li.active {
color: var(--text);
}
.events li.active span {
color: var(--cyan);
}
.events li.done {
color: #a9bac6;
}
.events li.done span {
color: #76dba6;
}
.bottom-panel {
position: absolute;
right: 28px;
bottom: 24px;
left: 28px;
display: grid;
grid-template-columns: auto minmax(260px, 1fr) auto;
gap: 18px;
align-items: center;
padding: 14px 16px;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--panel-border);
border-radius: 13px;
backdrop-filter: blur(14px);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}
.controls {
display: flex;
align-items: center;
gap: 8px;
}
.controls button {
min-height: 36px;
padding: 0 12px;
font-size: 11px;
font-weight: 650;
}
#play {
min-width: 84px;
color: #06121e;
background: var(--cyan);
border-color: transparent;
}
#play:hover {
color: #06121e;
background: #9aeaff;
}
.controls select {
height: 36px;
padding: 0 9px;
font-size: 11px;
}
.timeline-wrap {
position: relative;
min-width: 0;
padding-top: 9px;
}
#timeline {
--progress: 0%;
width: 100%;
height: 5px;
margin: 0;
appearance: none;
background:
linear-gradient(
to right,
var(--cyan) 0 var(--progress),
rgba(135, 177, 204, 0.18) var(--progress) 100%
);
border-radius: 999px;
outline: none;
}
#timeline::-webkit-slider-thumb {
width: 14px;
height: 14px;
appearance: none;
background: #e9fbff;
border: 3px solid #41bde2;
border-radius: 50%;
box-shadow: 0 0 14px rgba(103, 221, 255, 0.7);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
background: #e9fbff;
border: 3px solid #41bde2;
border-radius: 50%;
}
.timeline-labels {
position: relative;
height: 25px;
margin-top: 8px;
color: #7890a3;
font-size: 9px;
letter-spacing: 0.04em;
}
.timeline-labels span {
position: absolute;
top: 0;
transform: translateX(-50%);
white-space: nowrap;
}
.timeline-labels span:first-child {
transform: none;
}
.timeline-labels span:last-child {
transform: translateX(-100%);
}
.timeline-labels b {
display: block;
color: #b7cad7;
font-weight: 650;
}
.time-box {
min-width: 135px;
text-align: right;
}
.time-box small {
display: block;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.14em;
text-transform: uppercase;
}
#time {
display: block;
margin-top: 3px;
font-size: 18px;
font-variant-numeric: tabular-nums;
font-weight: 620;
}
.callout,
.route-tag {
position: fixed;
z-index: 4;
pointer-events: none;
opacity: 0;
transition: opacity 100ms linear;
}
.callout {
padding: 7px 10px 7px 12px;
transform: translate(14px, -50%);
background: rgba(7, 17, 29, 0.83);
border-left: 2px solid var(--stage-color, var(--cyan));
border-radius: 0 6px 6px 0;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.28);
white-space: nowrap;
}
.callout::before {
position: absolute;
top: 50%;
right: 100%;
width: 14px;
height: 1px;
content: "";
background: var(--stage-color, var(--cyan));
opacity: 0.7;
}
.callout b {
display: block;
color: var(--stage-color, var(--cyan));
font-size: 10px;
font-weight: 760;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.callout small {
display: block;
margin-top: 3px;
color: #9eb2c1;
font-size: 9px;
}
.route-tag {
padding: 4px 6px;
transform: translate(-50%, -140%);
color: #ffca91;
background: rgba(34, 21, 12, 0.72);
border: 1px solid rgba(255, 159, 67, 0.25);
border-radius: 4px;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
white-space: nowrap;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: #a9c2d2;
background: #06101d;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
.corner-hint {
position: absolute;
right: 30px;
bottom: 111px;
color: rgba(173, 201, 218, 0.64);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
@media (max-width: 900px) {
.left-panel {
display: none;
}
.bottom-panel {
grid-template-columns: 1fr;
gap: 10px;
}
.controls {
justify-content: center;
}
.time-box {
display: none;
}
.topbar {
top: 18px;
right: 18px;
left: 18px;
}
.readout {
display: none;
}
.bottom-panel {
right: 14px;
bottom: 14px;
left: 14px;
}
.timeline-labels span {
font-size: 8px;
}
.callout small {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway of a fictional separating rocket"></canvas>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="eyebrow">Fictional launch systems / interactive cutaway</div>
<h1>VECTOR–7</h1>
<p class="subtitle">
A fictional three-stage launch vehicle shown in cutaway. Watch each
stage depart along an explicitly illustrative flight path.
</p>
<div class="route-badge">Illustrative trajectory · not orbital · not to scale</div>
</div>
<div class="readout">
<div class="readout-row">
<span>Flight state</span>
<strong id="status">S1 powered ascent</strong>
</div>
<div class="readout-row">
<span>Model altitude</span>
<strong id="altitude">0.0 units</strong>
</div>
<div class="readout-row">
<span>Path speed</span>
<strong id="speed">0.00 units/s</strong>
</div>
<div class="readout-row">
<span>Separation model</span>
<strong>Diagrammatic</strong>
</div>
</div>
</header>
<aside class="left-panel">
<div class="panel-title">Vehicle elements</div>
<div class="vehicle-row">
<i style="--dot: var(--stage-1)"></i>
<div>
<b>Stage 01 / Lift</b>
<small>LOX + fictional RP-1, 3 engines</small>
</div>
</div>
<div class="vehicle-row">
<i style="--dot: var(--stage-2)"></i>
<div>
<b>Stage 02 / Transfer</b>
<small>Hydrolox tanks + avionics bay</small>
</div>
</div>
<div class="vehicle-row">
<i style="--dot: var(--stage-3)"></i>
<div>
<b>Stage 03 / Insertion</b>
<small>Storable propellant + compact engine</small>
</div>
</div>
<div class="vehicle-row">
<i style="--dot: var(--payload)"></i>
<div>
<b>ARGUS–3 payload</b>
<small>Fictional satellite and deployable fairing</small>
</div>
</div>
<div class="panel-title" style="margin-top: 18px">Separation sequence</div>
<ol class="events">
<li data-event="s1"><span>09.0</span><b>S1 separation</b></li>
<li data-event="s2"><span>18.0</span><b>S2 separation</b></li>
<li data-event="s3"><span>27.0</span><b>S3 separation</b></li>
<li data-event="fairing"><span>31.0</span><b>Fairing deploy</b></li>
</ol>
<div class="note">
<strong>Diagram note.</strong> Vehicle proportions, gravity response,
separation impulse, path curvature, altitude, and timing are all
fictional. The route is a visual teaching diagram, not a trajectory
solution.
</div>
</aside>
<div class="corner-hint">Drag to orbit · wheel to zoom · space to pause</div>
<footer class="bottom-panel">
<div class="controls">
<button id="play" type="button">Pause</button>
<button id="restart" type="button">Restart</button>
<select id="speed" 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>
<button id="follow" class="active" type="button">Follow</button>
<button id="overview" type="button">Full arc</button>
</div>
<div class="timeline-wrap">
<input
id="timeline"
type="range"
min="0"
max="42"
step="0.01"
value="0"
aria-label="Flight timeline"
/>
<div class="timeline-labels">
<span style="left: 0%"><b>LIFTOFF</b>00.0</span>
<span style="left: 21.43%"><b>S1 SEP</b>09.0</span>
<span style="left: 42.86%"><b>S2 SEP</b>18.0</span>
<span style="left: 64.29%"><b>S3 SEP</b>27.0</span>
<span style="left: 73.81%"><b>DEPLOY</b>31.0</span>
<span style="left: 100%"><b>COAST</b>42.0</span>
</div>
</div>
<div class="time-box">
<small>Mission elapsed</small>
<span id="time">T+ 00:00.0</span>
</div>
</footer>
</div>
<div id="label-s1" class="callout" style="--stage-color: var(--stage-1)">
<b>Stage 01 / Lift</b>
<small>LOX tank · RP-1 tank · engine bay</small>
</div>
<div id="label-s2" class="callout" style="--stage-color: var(--stage-2)">
<b>Stage 02 / Transfer</b>
<small>Hydrolox tanks · avionics</small>
</div>
<div id="label-s3" class="callout" style="--stage-color: var(--stage-3)">
<b>Stage 03 / Insertion</b>
<small>Storable propellant · compact engine</small>
</div>
<div id="label-payload" class="callout" style="--stage-color: var(--payload)">
<b>ARGUS–3 / Payload</b>
<small>Fictional satellite · deployable fairing</small>
</div>
<div id="marker-s1" class="route-tag">S1 SEP</div>
<div id="marker-s2" class="route-tag">S2 SEP</div>
<div id="marker-s3" class="route-tag">S3 SEP</div>
<div id="loading">Initializing vector-7 cutaway…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and state
// -------------------------------------------------------------------------
const EVENTS = {
s1: 9,
s2: 18,
s3: 27,
fairing: 31
};
const DURATION = 42;
const PATH_END_TIME = EVENTS.s3;
let simulationTime = 0;
let playing = true;
let playbackSpeed = 1;
let cameraMode = "follow";
const canvas = document.querySelector("#scene");
const timeline = document.querySelector("#timeline");
const playButton = document.querySelector("#play");
const restartButton = document.querySelector("#restart");
const speedSelect = document.querySelector("#speed");
const followButton = document.querySelector("#follow");
const overviewButton = document.querySelector("#overview");
const timeReadout = document.querySelector("#time");
const statusReadout = document.querySelector("#status");
const altitudeReadout = document.querySelector("#altitude");
const speedReadout = document.querySelector("#speed");
const labels = {
s1: document.querySelector("#label-s1"),
s2: document.querySelector("#label-s2"),
s3: document.querySelector("#label-s3"),
payload: document.querySelector("#label-payload")
};
const routeLabels = {
s1: document.querySelector("#marker-s1"),
s2: document.querySelector("#marker-s2"),
s3: document.querySelector("#marker-s3")
};
// -------------------------------------------------------------------------
// Renderer, scene, camera, lights
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
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.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x06101d);
scene.fog = new THREE.FogExp2(0x06101d, 0.011);
const camera = new THREE.PerspectiveCamera(
46,
window.innerWidth / window.innerHeight,
0.1,
180
);
const hemisphere = new THREE.HemisphereLight(0x9bdcff, 0x07101a, 1.55);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.0);
keyLight.position.set(-12, 22, 17);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1536, 1536);
keyLight.shadow.camera.left = -25;
keyLight.shadow.camera.right = 25;
keyLight.shadow.camera.top = 25;
keyLight.shadow.camera.bottom = -25;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 70;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x4dbbff, 2.1);
rimLight.position.set(14, 8, -15);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9a4d, 2.0, 26, 2);
warmLight.position.set(0, 3, 5);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Illustrative environment
// -------------------------------------------------------------------------
const earth = new THREE.Mesh(
new THREE.SphereGeometry(28, 80, 50),
new THREE.MeshStandardMaterial({
color: 0x0a3850,
roughness: 0.92,
metalness: 0.04
})
);
earth.position.set(0, -28, 0);
earth.receiveShadow = true;
scene.add(earth);
const earthGrid = new THREE.Mesh(
new THREE.SphereGeometry(28.04, 36, 24),
new THREE.MeshBasicMaterial({
color: 0x4aa6c6,
wireframe: true,
transparent: true,
opacity: 0.055,
depthWrite: false
})
);
earthGrid.position.copy(earth.position);
scene.add(earthGrid);
const atmosphere = new THREE.Mesh(
new THREE.SphereGeometry(28.8, 64, 40),
new THREE.MeshBasicMaterial({
color: 0x46d8ff,
transparent: true,
opacity: 0.075,
side: THREE.BackSide,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
atmosphere.position.copy(earth.position);
scene.add(atmosphere);
const starPositions = new Float32Array(1600 * 3);
for (let i = 0; i < 1600; i++) {
const radius = 52 + Math.random() * 65;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
starPositions[i * 3] =
radius * Math.sin(phi) * Math.cos(theta);
starPositions[i * 3 + 1] =
radius * Math.cos(phi);
starPositions[i * 3 + 2] =
radius * Math.sin(phi) * Math.sin(theta);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xb9e9ff,
size: 0.075,
transparent: true,
opacity: 0.82,
depthWrite: false
})
);
scene.add(stars);
const launchPad = new THREE.Group();
const padBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.25, 1.45, 0.18, 48),
new THREE.MeshStandardMaterial({
color: 0x263746,
metalness: 0.65,
roughness: 0.5
})
);
padBase.position.set(-0.4, 0.08, 0);
padBase.receiveShadow = true;
launchPad.add(padBase);
const padRing = new THREE.Mesh(
new THREE.TorusGeometry(1.02, 0.035, 10, 64),
new THREE.MeshBasicMaterial({ color: 0x58d8ff })
);
padRing.rotation.x = Math.PI / 2;
padRing.position.set(-0.4, 0.19, 0);
launchPad.add(padRing);
const towerMaterial = new THREE.MeshStandardMaterial({
color: 0x405566,
metalness: 0.72,
roughness: 0.38
});
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2 + Math.PI / 4;
const post = new THREE.Mesh(
new THREE.BoxGeometry(0.08, 2.7, 0.08),
towerMaterial
);
post.position.set(
-0.4 + Math.cos(angle) * 1.02,
1.35,
Math.sin(angle) * 1.02
);
post.castShadow = true;
launchPad.add(post);
}
scene.add(launchPad);
// -------------------------------------------------------------------------
// Fictional illustrative trajectory
// -------------------------------------------------------------------------
const trajectory = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.4, 1.55, 0),
new THREE.Vector3(0.15, 4.0, 0.25),
new THREE.Vector3(1.25, 7.25, 0.9),
new THREE.Vector3(3.15, 10.65, 1.1),
new THREE.Vector3(6.0, 13.15, 0.35),
new THREE.Vector3(8.9, 14.25, -0.8),
new THREE.Vector3(10.5, 14.0, -2.0)
],
false,
"catmullrom",
0.5
);
const trajectoryLength = trajectory.getLength();
const pathSpeed = trajectoryLength / PATH_END_TIME;
const trajectoryEnd = trajectory.getPointAt(1);
const trajectoryEndTangent = trajectory.getTangentAt(1).normalize();
const pathPoints = [];
for (let i = 0; i <= 150; i++) {
pathPoints.push(trajectory.getPointAt(i / 150));
}
for (let i = 1; i <= 45; i++) {
pathPoints.push(
trajectoryEnd
.clone()
.addScaledVector(trajectoryEndTangent, pathSpeed * (i / 3))
);
}
const trajectoryGeometry = new THREE.BufferGeometry().setFromPoints(
pathPoints
);
const trajectoryLine = new THREE.Line(
trajectoryGeometry,
new THREE.LineDashedMaterial({
color: 0xffa24d,
dashSize: 0.28,
gapSize: 0.16,
transparent: true,
opacity: 0.78
})
);
trajectoryLine.computeLineDistances();
scene.add(trajectoryLine);
function rootPoseAt(time) {
let position;
let tangent;
if (time <= PATH_END_TIME) {
const u = THREE.MathUtils.clamp(time / PATH_END_TIME, 0, 1);
position = trajectory.getPointAt(u);
tangent = trajectory.getTangentAt(u).normalize();
} else {
position = trajectoryEnd
.clone()
.addScaledVector(
trajectoryEndTangent,
pathSpeed * (time - PATH_END_TIME)
);
tangent = trajectoryEndTangent.clone();
}
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
tangent
);
return {
position,
tangent,
quaternion,
velocity: tangent.clone().multiplyScalar(pathSpeed)
};
}
// Event markers on the nominal path.
const eventMarkerPositions = {
s1: rootPoseAt(EVENTS.s1).position,
s2: rootPoseAt(EVENTS.s2).position,
s3: rootPoseAt(EVENTS.s3).position
};
for (const [key, position] of Object.entries(eventMarkerPositions)) {
const marker = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 16, 12),
new THREE.MeshBasicMaterial({
color: key === "s1" ? 0xff785a : key === "s2" ? 0x67ddff : 0xbd8cff
})
);
marker.position.copy(position);
scene.add(marker);
}
const currentMarker = new THREE.Group();
const currentMarkerCore = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 18, 14),
new THREE.MeshBasicMaterial({ color: 0xfff0d0 })
);
const currentMarkerHalo = new THREE.Mesh(
new THREE.SphereGeometry(0.26, 18, 14),
new THREE.MeshBasicMaterial({
color: 0xffb257,
transparent: true,
opacity: 0.22,
blending: THREE.AdditiveBlending,
depthWrite: false
})
);
currentMarker.add(currentMarkerCore, currentMarkerHalo);
scene.add(currentMarker);
// -------------------------------------------------------------------------
// Rocket construction helpers
// -------------------------------------------------------------------------
const Y_AXIS = new THREE.Vector3(0, 1, 0);
const UNIT_SCALE = new THREE.Vector3(1, 1, 1);
function addMesh(group, geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
function makeTube(points, radius, material) {
const curve = new THREE.CatmullRomCurve3(points);
const geometry = new THREE.TubeGeometry(curve, 28, radius, 8, false);
return new THREE.Mesh(geometry, material);
}
function buildStage({
radius,
height,
color,
engineCount = 1,
tankMaterialColor = color
}) {
const group = new THREE.Group();
group.matrixAutoUpdate = false;
const shellMaterial = new THREE.MeshPhysicalMaterial({
color: 0xdce9ef,
metalness: 0.24,
roughness: 0.32,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide,
depthWrite: false
});
const ghostMaterial = new THREE.MeshBasicMaterial({
color,
wireframe: true,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const tankMaterial = new THREE.MeshStandardMaterial({
color: tankMaterialColor,
metalness: 0.52,
roughness: 0.3,
transparent: true,
opacity: 0.86
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x92a7b5,
metalness: 0.78,
roughness: 0.25
});
const darkMetal = new THREE.MeshStandardMaterial({
color: 0x26333d,
metalness: 0.72,
roughness: 0.32
});
const accentMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.12,
metalness: 0.42,
roughness: 0.32
});
// Full ghost silhouette.
addMesh(
group,
new THREE.CylinderGeometry(radius, radius, height, 40, 1, true),
ghostMaterial
);
// Rear half of the outer shell; the front is cut away.
const backShell = addMesh(
group,
new THREE.CylinderGeometry(
radius,
radius,
height,
48,
1,
true,
Math.PI / 2,
Math.PI
),
shellMaterial
);
backShell.castShadow = false;
// Bright longitudinal cut edges.
for (const side of [-1, 1]) {
const cutEdge = addMesh(
group,
new THREE.CylinderGeometry(0.018, 0.018, height + 0.03, 8),
accentMaterial,
new THREE.Vector3(side * radius, 0, 0)
);
cutEdge.castShadow = false;
}
// Structural rings.
for (const y of [-height / 2, height / 2]) {
const ring = addMesh(
group,
new THREE.TorusGeometry(radius * 0.98, 0.025, 8, 48),
metalMaterial,
new THREE.Vector3(0, y, 0)
);
ring.rotation.x = Math.PI / 2;
ring.castShadow = false;
}
// Main propellant tank.
const tankHeight = height * 0.57;
const tankRadius = radius * 0.59;
addMesh(
group,
new THREE.CylinderGeometry(
tankRadius,
tankRadius,
tankHeight,
36,
1,
false
),
tankMaterial
);
// Rounded tank domes.
const upperDome = addMesh(
group,
new THREE.SphereGeometry(tankRadius, 32, 20),
tankMaterial,
new THREE.Vector3(0, tankHeight / 2, 0)
);
upperDome.scale.y = 0.34;
const lowerDome = addMesh(
group,
new THREE.SphereGeometry(tankRadius, 32, 20),
tankMaterial,
new THREE.Vector3(0, -tankHeight / 2, 0)
);
lowerDome.scale.y = 0.34;
// Secondary tank / equipment volume.
const upperTankRadius = radius * 0.39;
const upperTankHeight = height * 0.23;
addMesh(
group,
new THREE.CylinderGeometry(
upperTankRadius,
upperTankRadius,
upperTankHeight,
28
),
new THREE.MeshStandardMaterial({
color: 0x9aaeba,
metalness: 0.62,
roughness: 0.34
}),
new THREE.Vector3(0, height * 0.27, -radius * 0.12)
);
// Avionics / pump module.
addMesh(
group,
new THREE.BoxGeometry(radius * 0.55, height * 0.18, radius * 0.46),
darkMetal,
new THREE.Vector3(0, -height * 0.31, radius * 0.18)
);
// Visible feed lines.
const pipeMaterial = new THREE.MeshStandardMaterial({
color: 0xc1d4dc,
metalness: 0.82,
roughness: 0.23
});
const pipeA = makeTube(
[
new THREE.Vector3(-radius * 0.62, height * 0.33, 0.08),
new THREE.Vector3(-radius * 0.45, height * 0.1, 0.18),
new THREE.Vector3(-radius * 0.5, -height * 0.18, 0.18),
new THREE.Vector3(-radius * 0.2, -height * 0.38, 0.06)
],
0.024,
pipeMaterial
);
const pipeB = makeTube(
[
new THREE.Vector3(radius * 0.6, height * 0.3, 0.02),
new THREE.Vector3(radius * 0.48, 0, 0.18),
new THREE.Vector3(radius * 0.42, -height * 0.24, 0.12),
new THREE.Vector3(radius * 0.18, -height * 0.39, 0.03)
],
0.02,
pipeMaterial
);
group.add(pipeA, pipeB);
// Engines.
const flames = [];
for (let i = 0; i < engineCount; i++) {
let engineX = 0;
let engineZ = 0;
if (engineCount === 3) {
const angle = (i / 3) * Math.PI * 2;
engineX = Math.cos(angle) * radius * 0.34;
engineZ = Math.sin(angle) * radius * 0.34;
}
const engineY = -height / 2 - 0.28;
const bell = addMesh(
group,
new THREE.CylinderGeometry(0.16, 0.35, 0.54, 28, 1, true),
darkMetal,
new THREE.Vector3(engineX, engineY, engineZ)
);
bell.castShadow = true;
const nozzle = addMesh(
group,
new THREE.CylinderGeometry(0.14, 0.14, 0.18, 20),
metalMaterial,
new THREE.Vector3(engineX, engineY + 0.34, engineZ)
);
const flameMaterial = new THREE.MeshBasicMaterial({
color: 0xff9d3d,
transparent: true,
opacity: 0.88,
blending: THREE.AdditiveBlending,
depthWrite: false
});
const flame = new THREE.Mesh(
new THREE.ConeGeometry(0.28, 1.05, 18, 1, true),
flameMaterial
);
flame.position.set(
engineX,
engineY - 0.73,
engineZ
);
flame.rotation.z = Math.PI;
flame.castShadow = false;
group.add(flame);
flames.push(flame);
}
group.userData.flames = flames;
group.userData.height = height;
return group;
}
const stage1 = buildStage({
radius: 0.78,
height: 2.5,
color: 0xff785a,
engineCount: 3
});
const stage2 = buildStage({
radius: 0.68,
height: 2.1,
color: 0x67ddff,
engineCount: 1,
tankMaterialColor: 0x4aa9c9
});
const stage3 = buildStage({
radius: 0.58,
height: 1.65,
color: 0xbd8cff,
engineCount: 1,
tankMaterialColor: 0x8c71c2
});
scene.add(stage1, stage2, stage3);
// -------------------------------------------------------------------------
// Payload and deployable fairing
// -------------------------------------------------------------------------
const payload = new THREE.Group();
payload.matrixAutoUpdate = false;
const fairingMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe5edf0,
metalness: 0.18,
roughness: 0.38,
transparent: true,
opacity: 0.65,
side: THREE.DoubleSide,
depthWrite: false
});
const goldMaterial = new THREE.MeshStandardMaterial({
color: 0xd9a62c,
metalness: 0.78,
roughness: 0.3
});
const satelliteMaterial = new THREE.MeshStandardMaterial({
color: 0xb8c6cc,
metalness: 0.68,
roughness: 0.32
});
const panelMaterial = new THREE.MeshStandardMaterial({
color: 0x153f74,
emissive: 0x0b2754,
emissiveIntensity: 0.35,
metalness: 0.4,
roughness: 0.36
});
const fairingBase = addMesh(
payload,
new THREE.CylinderGeometry(0.5, 0.5, 0.34, 36),
fairingMaterial,
new THREE.Vector3(0, 0, 0)
);
fairingBase.castShadow = false;
const fairingRight = new THREE.Mesh(
new THREE.ConeGeometry(
0.5,
1.35,
32,
1,
true,
0,
Math.PI
),
fairingMaterial
);
const fairingLeft = new THREE.Mesh(
new THREE.ConeGeometry(
0.5,
1.35,
32,
1,
true,
Math.PI,
Math.PI
),
fairingMaterial
);
fairingRight.position.y = 0.84;
fairingLeft.position.y = 0.84;
fairingRight.castShadow = false;
fairingLeft.castShadow = false;
payload.add(fairingRight, fairingLeft);
const satellite = new THREE.Group();
satellite.position.y = 0.57;
addMesh(
satellite,
new THREE.BoxGeometry(0.48, 0.52, 0.48),
goldMaterial
);
addMesh(
satellite,
new THREE.BoxGeometry(0.25, 0.18, 0.25),
satelliteMaterial,
new THREE.Vector3(0, 0.37, 0)
);
for (const side of [-1, 1]) {
addMesh(
satellite,
new THREE.BoxGeometry(0.85, 0.045, 0.42),
panelMaterial,
new THREE.Vector3(side * 0.66, 0, 0)
);
const boom = addMesh(
satellite,
new THREE.BoxGeometry(0.4, 0.025, 0.035),
satelliteMaterial,
new THREE.Vector3(side * 0.35, 0, 0)
);
boom.castShadow = false;
}
payload.add(satellite);
scene.add(payload);
// -------------------------------------------------------------------------
// Detached-stage illustrative branch trajectories
// -------------------------------------------------------------------------
function createBranch({
eventTime,
localY,
impulse,
gravity,
maxDt,
color,
spin = 0
}) {
const eventPose = rootPoseAt(eventTime);
const offset = new THREE.Vector3(0, localY, 0).applyQuaternion(
eventPose.quaternion
);
const position0 = eventPose.position.clone().add(offset);
const velocity0 = eventPose.velocity.clone().add(impulse);
const acceleration = new THREE.Vector3(0, -gravity, 0);
return {
eventTime,
localY,
position0,
velocity0,
acceleration,
eventQuaternion: eventPose.quaternion,
maxDt,
color,
spin
};
}
const branches = {
s1: createBranch({
eventTime: EVENTS.s1,
localY: 0,
impulse: new THREE.Vector3(-0.13, -0.02, 0.02),
gravity: 0.34,
maxDt: 11,
color: 0xff785a,
spin: 0.34
}),
s2: createBranch({
eventTime: EVENTS.s2,
localY: 2.55,
impulse: new THREE.Vector3(-0.025, -0.035, 0.07),
gravity: 0.025,
maxDt: 24,
color: 0x67ddff,
spin: 0.12
}),
s3: createBranch({
eventTime: EVENTS.s3,
localY: 4.45,
impulse: new THREE.Vector3(0.02, 0.012, -0.035),
gravity: 0.012,
maxDt: 15,
color: 0xbd8cff,
spin: 0.08
})
};
function branchState(branch, elapsed) {
const t = Math.max(0, elapsed);
const position = branch.position0
.clone()
.addScaledVector(branch.velocity0, t)
.addScaledVector(branch.acceleration, 0.5 * t * t);
const velocity = branch.velocity0
.clone()
.addScaledVector(branch.acceleration, t);
const direction = velocity.clone().normalize();
const alignQuaternion = new THREE.Quaternion().setFromUnitVectors(
Y_AXIS,
direction
);
const spinQuaternion = new THREE.Quaternion().setFromAxisAngle(
Y_AXIS,
branch.spin * t
);
alignQuaternion.multiply(spinQuaternion);
const blend = THREE.MathUtils.smoothstep(t, 0, 0.65);
const quaternion = branch.eventQuaternion.clone().slerp(
alignQuaternion,
blend
);
return { position, quaternion, velocity };
}
function createBranchLine(branch) {
const points = [];
for (let i = 0; i <= 100; i++) {
const elapsed = (i / 100) * branch.maxDt;
points.push(branchState(branch, elapsed).position);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(
geometry,
new THREE.LineDashedMaterial({
color: branch.color,
dashSize: 0.16,
gapSize: 0.11,
transparent: true,
opacity: 0.5
})
);
line.computeLineDistances();
line.visible = false;
scene.add(line);
return line;
}
const branchLines = {
s1: createBranchLine(branches.s1),
s2: createBranchLine(branches.s2),
s3: createBranchLine(branches.s3)
};
// -------------------------------------------------------------------------
// Matrix animation
// -------------------------------------------------------------------------
const rootMatrix = new THREE.Matrix4();
const localMatrix = new THREE.Matrix4();
const stageMatrices = {
s1: new THREE.Matrix4(),
s2: new THREE.Matrix4(),
s3: new THREE.Matrix4(),
payload: new THREE.Matrix4()
};
function setObjectMatrix(object, matrix) {
object.matrix.copy(matrix);
object.matrixWorldNeedsUpdate = true;
}
function updateRocket(time) {
const pose = rootPoseAt(time);
rootMatrix.compose(
pose.position,
pose.quaternion,
UNIT_SCALE
);
localMatrix.makeTranslation(0, 0, 0);
stageMatrices.s1.multiplyMatrices(rootMatrix, localMatrix);
localMatrix.makeTranslation(0, 2.55, 0);
stageMatrices.s2.multiplyMatrices(rootMatrix, localMatrix);
localMatrix.makeTranslation(0, 4.45, 0);
stageMatrices.s3.multiplyMatrices(rootMatrix, localMatrix);
localMatrix.makeTranslation(0, 5.95, 0);
stageMatrices.payload.multiplyMatrices(rootMatrix, localMatrix);
if (time < EVENTS.s1) {
setObjectMatrix(stage1, stageMatrices.s1);
} else {
const state = branchState(branches.s1, time - EVENTS.s1);
const matrix = new THREE.Matrix4().compose(
state.position,
state.quaternion,
UNIT_SCALE
);
setObjectMatrix(stage1, matrix);
}
if (time < EVENTS.s2) {
setObjectMatrix(stage2, stageMatrices.s2);
} else {
const state = branchState(branches.s2, time - EVENTS.s2);
const matrix = new THREE.Matrix4().compose(
state.position,
state.quaternion,
UNIT_SCALE
);
setObjectMatrix(stage2, matrix);
}
if (time < EVENTS.s3) {
setObjectMatrix(stage3, stageMatrices.s3);
} else {
const state = branchState(branches.s3, time - EVENTS.s3);
const matrix = new THREE.Matrix4().compose(
state.position,
state.quaternion,
UNIT_SCALE
);
setObjectMatrix(stage3, matrix);
}
setObjectMatrix(payload, stageMatrices.payload);
// Engine flames indicate the active stage.
stage1.userData.flames.forEach((flame) => {
flame.visible = time < EVENTS.s1;
});
stage2.userData.flames.forEach((flame) => {
flame.visible = time >= EVENTS.s1 && time < EVENTS.s2;
});
stage3.userData.flames.forEach((flame) => {
flame.visible = time >= EVENTS.s2 && time < EVENTS.s3;
});
const flamePulse = 0.88 + Math.sin(time * 31) * 0.09;
[
...stage1.userData.flames,
...stage2.userData.flames,
...stage3.userData.flames
].forEach((flame) => {
flame.scale.y = flamePulse;
flame.material.opacity = 0.76 + Math.sin(time * 23) * 0.12;
});
// Fairing deployment.
const deployment = THREE.MathUtils.clamp(
(time - EVENTS.fairing) / 3,
0,
1
);
const easedDeployment = 1 - Math.pow(1 - deployment, 3);
fairingRight.position.x = easedDeployment * 1.25;
fairingLeft.position.x = -easedDeployment * 1.25;
fairingRight.rotation.z = easedDeployment * 0.9;
fairingLeft.rotation.z = -easedDeployment * 0.9;
branchLines.s1.visible = time >= EVENTS.s1;
branchLines.s2.visible = time >= EVENTS.s2;
branchLines.s3.visible = time >= EVENTS.s3;
currentMarker.position.copy(pose.position);
scene.updateMatrixWorld(true);
}
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3();
const desiredTarget = new THREE.Vector3();
const desiredCameraPosition = new THREE.Vector3();
let cameraYaw = 0.57;
let cameraPitch = 0.19;
let cameraDistance = 12.5;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function resetCamera() {
cameraYaw = 0.57;
cameraPitch = 0.19;
cameraDistance = cameraMode === "follow" ? 12.5 : 31;
}
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
cameraYaw -= deltaX * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + deltaY * 0.005,
-0.3,
1.25
);
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = "grab";
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance * Math.exp(event.deltaY * 0.001),
4.5,
52
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.style.cursor = "grab";
function updateCamera(delta) {
const payloadWorld = new THREE.Vector3();
payload.getWorldPosition(payloadWorld);
if (cameraMode === "follow") {
desiredTarget.copy(payloadWorld);
} else {
desiredTarget
.copy(trajectory.getPointAt(0.55))
.lerp(payloadWorld, 0.48);
}
const smoothing = 1 - Math.exp(-delta * 5.5);
cameraTarget.lerp(desiredTarget, smoothing);
const horizontalDistance =
cameraDistance * Math.cos(cameraPitch);
desiredCameraPosition.set(
cameraTarget.x +
Math.sin(cameraYaw) * horizontalDistance,
cameraTarget.y +
Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z +
Math.cos(cameraYaw) * horizontalDistance
);
camera.position.lerp(
desiredCameraPosition,
1 - Math.exp(-delta * 8)
);
camera.lookAt(cameraTarget);
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
function projectToScreen(worldPosition) {
const projected = worldPosition.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible:
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1
};
}
function placeLabel(element, worldPosition, visible = true) {
const screen = projectToScreen(worldPosition);
element.style.left = `${screen.x}px`;
element.style.top = `${screen.y}px`;
element.style.opacity =
visible && screen.visible ? "1" : "0";
}
function updateLabels(time) {
const positions = {
s1: new THREE.Vector3(),
s2: new THREE.Vector3(),
s3: new THREE.Vector3(),
payload: new THREE.Vector3()
};
stage1.getWorldPosition(positions.s1);
stage2.getWorldPosition(positions.s2);
stage3.getWorldPosition(positions.s3);
payload.getWorldPosition(positions.payload);
placeLabel(labels.s1, positions.s1, time < 19);
placeLabel(labels.s2, positions.s2, true);
placeLabel(labels.s3, positions.s3, true);
placeLabel(labels.payload, positions.payload, true);
placeLabel(
routeLabels.s1,
eventMarkerPositions.s1,
cameraMode === "overview"
);
placeLabel(
routeLabels.s2,
eventMarkerPositions.s2,
cameraMode === "overview"
);
placeLabel(
routeLabels.s3,
eventMarkerPositions.s3,
cameraMode === "overview"
);
}
// -------------------------------------------------------------------------
// UI and flight-state readouts
// -------------------------------------------------------------------------
function formatTime(time) {
const minutes = Math.floor(time / 60);
const seconds = (time % 60).toFixed(1).padStart(4, "0");
return `${String(minutes).padStart(2, "0")}:${seconds}`;
}
function flightStatus(time) {
if (time < EVENTS.s1) return "S1 powered ascent";
if (time < EVENTS.s2) return "S1 separated / S2 burn";
if (time < EVENTS.s3) return "S2 separated / S3 burn";
if (time < EVENTS.fairing) return "S3 separated / payload coast";
return "Fairing deployed / payload coast";
}
function updateUI(time) {
timeline.value = String(time);
timeline.style.setProperty(
"--progress",
`${(time / DURATION) * 100}%`
);
timeReadout.textContent = `T+ ${formatTime(time)}`;
statusReadout.textContent = flightStatus(time);
const payloadWorld = new THREE.Vector3();
payload.getWorldPosition(payloadWorld);
altitudeReadout.textContent = `${payloadWorld.y.toFixed(1)} units`;
speedReadout.textContent = `${pathSpeed.toFixed(2)} units/s`;
const eventRows = document.querySelectorAll("[data-event]");
eventRows.forEach((row) => {
const eventName = row.dataset.event;
const eventTime = EVENTS[eventName];
const active =
(eventName === "s1" && time >= EVENTS.s1 && time < EVENTS.s2) ||
(eventName === "s2" && time >= EVENTS.s2 && time < EVENTS.s3) ||
(eventName === "s3" && time >= EVENTS.s3 && time < EVENTS.fairing) ||
(eventName === "fairing" && time >= EVENTS.fairing);
row.classList.toggle("active", active);
row.classList.toggle("done", time >= eventTime && !active);
});
}
playButton.addEventListener("click", () => {
playing = !playing;
playButton.textContent = playing ? "Pause" : "Play";
});
restartButton.addEventListener("click", () => {
simulationTime = 0;
playing = true;
playButton.textContent = "Pause";
});
speedSelect.addEventListener("change", () => {
playbackSpeed = Number(speedSelect.value);
});
timeline.addEventListener("input", () => {
simulationTime = Number(timeline.value);
});
followButton.addEventListener("click", () => {
cameraMode = "follow";
cameraDistance = 12.5;
followButton.classList.add("active");
overviewButton.classList.remove("active");
});
overviewButton.addEventListener("click", () => {
cameraMode = "overview";
cameraDistance = 31;
overviewButton.classList.add("active");
followButton.classList.remove("active");
});
window.addEventListener("keydown", (event) => {
const tagName = document.activeElement?.tagName;
if (tagName === "INPUT" || tagName === "SELECT") return;
if (event.code === "Space") {
event.preventDefault();
playButton.click();
}
if (event.code === "KeyR") {
restartButton.click();
}
});
// -------------------------------------------------------------------------
// Resize and animation 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();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (playing) {
simulationTime += delta * playbackSpeed;
if (simulationTime >= DURATION) {
simulationTime = 0;
}
}
updateRocket(simulationTime);
updateCamera(delta);
updateLabels(simulationTime);
updateUI(simulationTime);
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.querySelector("#loading").classList.add("hidden");
}
}
cameraTarget.copy(rootPoseAt(0).position);
updateRocket(0);
updateCamera(1);
animate();
</script>
</body>
</html>
```