Prompt specification
Build or customize the Three.js 3D scene "Caravan pack frame with balanced bundles" 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: Caravan pack frame with balanced bundles
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/caravan-pack-frame-with-balanced-bundles-x2617
Scene Description Prompt:
A voxel caravan pack frame supports balanced bundles on either side of a saddle; cargo is illustrative. Three.js from cdnjs, one HTML file.
Working Three.js Starter (caravan-pack-frame-with-balanced-bundles-x2617):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#b8733e" />
<title>Voxel Caravan — Balanced Pack Frame</title>
<style>
:root {
--ink: #fff8e9;
--muted: rgba(255, 248, 233, 0.68);
--panel: rgba(44, 29, 24, 0.54);
--line: rgba(255, 248, 233, 0.2);
--accent: #f3c56e;
--teal: #6db7ae;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(
circle at 72% 19%,
rgba(255, 229, 153, 0.95) 0 5.5%,
rgba(255, 215, 132, 0.25) 6%,
transparent 16%
),
linear-gradient(
180deg,
#78aeb5 0%,
#b7c1a5 29%,
#e3ac70 59%,
#bd7445 100%
);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(
180deg,
rgba(44, 29, 24, 0.16),
transparent 22%,
transparent 76%,
rgba(44, 29, 24, 0.23)
),
radial-gradient(
ellipse at center,
transparent 52%,
rgba(47, 28, 22, 0.18) 100%
);
}
.title {
position: fixed;
top: clamp(20px, 4vw, 44px);
left: clamp(20px, 4vw, 52px);
max-width: 360px;
pointer-events: none;
text-shadow: 0 2px 18px rgba(50, 29, 20, 0.28);
}
.eyebrow {
margin-bottom: 9px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 6vw, 72px);
font-weight: 500;
letter-spacing: -0.055em;
line-height: 0.92;
}
.subtitle {
max-width: 310px;
margin: 16px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.035em;
}
.load-panel {
position: fixed;
top: clamp(20px, 4vw, 44px);
right: clamp(20px, 4vw, 52px);
width: 238px;
padding: 17px 18px 15px;
border: 1px solid var(--line);
border-radius: 4px;
background: var(--panel);
box-shadow: 0 16px 45px rgba(49, 29, 20, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.load-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.load-heading strong {
color: var(--accent);
font-size: 10px;
}
.load-side {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 5px 12px;
margin-top: 11px;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.14em;
}
.load-side b {
color: var(--ink);
font-size: 11px;
letter-spacing: 0.04em;
}
.load-bar {
grid-column: 1 / -1;
height: 4px;
overflow: hidden;
border-radius: 3px;
background: rgba(255, 255, 255, 0.1);
}
.load-bar::after {
display: block;
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #b7d3a4);
content: "";
}
.load-side:last-of-type .load-bar::after {
background: linear-gradient(90deg, #df9a55, var(--accent));
}
.controls {
position: fixed;
right: clamp(20px, 4vw, 52px);
bottom: clamp(24px, 5vw, 48px);
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
button {
appearance: none;
padding: 11px 15px;
border: 1px solid var(--line);
border-radius: 3px;
color: var(--ink);
background: rgba(44, 29, 24, 0.54);
box-shadow: 0 10px 28px rgba(49, 29, 20, 0.12);
backdrop-filter: blur(10px);
cursor: pointer;
font: inherit;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover,
button.active {
border-color: rgba(255, 221, 157, 0.58);
background: rgba(73, 42, 29, 0.78);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.caption {
position: fixed;
left: clamp(20px, 4vw, 52px);
bottom: clamp(24px, 5vw, 48px);
color: rgba(255, 248, 233, 0.58);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.17em;
line-height: 1.7;
text-transform: uppercase;
pointer-events: none;
}
.hint {
position: fixed;
left: 50%;
bottom: 24px;
padding: 8px 12px;
border-radius: 3px;
color: rgba(255, 248, 233, 0.6);
background: rgba(44, 29, 24, 0.25);
font-size: 9px;
letter-spacing: 0.1em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(7px);
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
color: var(--ink);
background: #b87545;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.title {
max-width: 240px;
}
.subtitle {
display: none;
}
.load-panel {
top: auto;
right: 18px;
bottom: 88px;
width: 196px;
}
.controls {
right: 18px;
bottom: 22px;
left: 18px;
justify-content: stretch;
}
button {
flex: 1;
padding: 10px 8px;
font-size: 9px;
}
.caption,
.hint {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel caravan pack-frame scene"></main>
<div class="vignette"></div>
<header class="title">
<div class="eyebrow">Desert field study · No. 07</div>
<h1>The Last Load</h1>
<p class="subtitle">
A voxel caravan animal carrying a timber pack saddle, paired side
bundles, and a balanced illustrative cargo.
</p>
</header>
<aside class="load-panel" aria-label="Load balance">
<div class="load-heading">
<span>Pack frame balance</span>
<strong>48 kg</strong>
</div>
<div class="load-side">
<span>Port</span><b>24 kg</b>
<span class="load-bar"></span>
</div>
<div class="load-side">
<span>Starboard</span><b>24 kg</b>
<span class="load-bar"></span>
</div>
</aside>
<nav class="controls" aria-label="Camera presets">
<button class="active" data-view="overview">Overview</button>
<button data-view="cargo">Pack close-up</button>
<button data-view="opposite">Opposite side</button>
</nav>
<div class="caption">
Burlap · timber frame · woven rug · illustrative cargo
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Arrow keys to pan</div>
<div id="loading">Preparing caravan…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const loading = document.querySelector("#loading");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.9));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xdca36d, 19, 61);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
120
);
const hemisphere = new THREE.HemisphereLight(0xffdfaa, 0x684331, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffe0ac, 3.35);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.camera.left = -13;
sun.shadow.camera.right = 13;
sun.shadow.camera.top = 13;
sun.shadow.camera.bottom = -13;
sun.shadow.bias = -0.00025;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x8bc5d0, 0.72);
fill.position.set(7, 6, -9);
scene.add(fill);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
flatShading: true,
...options
});
}
const m = {
sand: material(0xd99352),
road: material(0xe3ab69),
dune: material(0xd38a4d),
duneLight: material(0xdf9a59),
rock: material(0x9f6447),
rockLight: material(0xb87950),
shrub: material(0x596743),
shrubLight: material(0x758052),
camel: material(0xb97138),
camelLight: material(0xd18a45),
camelDark: material(0x94502d),
muzzle: material(0xc98545),
hoof: material(0x3e302b),
eye: material(0x171817),
leather: material(0x63412e),
teal: material(0x397b78),
tealLight: material(0x65a49a),
rust: material(0xa95035),
cream: material(0xd7b777),
wood: material(0x765039),
woodLight: material(0x966c47),
woodDark: material(0x4b342a),
rope: material(0xb8945b),
ropeDark: material(0x785a37),
burlap: material(0xa8804f),
pottery: material(0xb7603f),
brass: material(0xb58b3f, {
metalness: 0.32,
roughness: 0.48
}),
distant: material(0xa76542),
distantDark: material(0x895036)
};
function cube(parent, mat, size, position, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(parent, mat, a, b, thickness = 0.07) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const mesh = cube(
parent,
mat,
[thickness, direction.length(), thickness],
midpoint.toArray()
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
// Seeded scenery placement.
let seed = 713;
function random() {
seed |= 0;
seed = (seed + 0x6d2b79f5) | 0;
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
}
function range(min, max) {
return min + (max - min) * random();
}
// Ground and caravan road.
cube(scene, m.sand, [70, 0.5, 60], [0, -0.25, 0], false);
for (let i = 0; i < 16; i++) {
const x = -28 + i * 3.75;
const z = Math.sin(i * 0.62) * 1.2;
cube(
scene,
m.road,
[3.95, 0.035, 2.65 + random() * 0.35],
[x, 0.018, z],
false
);
}
function dune(x, z, sx, sz, height) {
cube(scene, m.dune, [sx, height * 0.42, sz], [x, height * 0.21, z], false);
cube(
scene,
m.duneLight,
[sx * 0.77, height * 0.38, sz * 0.78],
[x + 0.7, height * 0.58, z - 0.35],
false
);
cube(
scene,
m.duneLight,
[sx * 0.48, height * 0.29, sz * 0.52],
[x + 1.1, height * 0.87, z - 0.58],
false
);
}
dune(-18, -15, 15, 8, 3.1);
dune(13, -18, 18, 9, 3.8);
dune(26, 9, 13, 7, 2.8);
dune(-25, 10, 11, 7, 2.4);
function makeRock(x, z, scale) {
const rock = new THREE.Group();
rock.position.set(x, 0, z);
rock.rotation.y = range(0, Math.PI);
cube(rock, m.rock, [scale, scale * 0.52, scale * 0.78], [0, scale * 0.26, 0]);
cube(
rock,
m.rockLight,
[scale * 0.65, scale * 0.42, scale * 0.58],
[scale * 0.13, scale * 0.65, -scale * 0.05]
);
scene.add(rock);
}
function makeShrub(x, z, scale) {
const shrub = new THREE.Group();
shrub.position.set(x, 0, z);
cube(shrub, m.woodDark, [0.09, 0.65, 0.09], [0, 0.33, 0]);
cube(shrub, m.woodDark, [0.07, 0.47, 0.07], [0.15, 0.24, 0.02]);
cube(shrub, m.shrub, [0.4, 0.27, 0.36], [0, 0.68, 0]);
cube(shrub, m.shrubLight, [0.33, 0.25, 0.3], [0.18, 0.87, -0.04]);
cube(shrub, m.shrub, [0.3, 0.22, 0.27], [-0.16, 0.78, 0.07]);
shrub.scale.setScalar(scale);
scene.add(shrub);
}
for (let i = 0; i < 35; i++) {
const x = range(-24, 24);
const z = range(-13, 13);
if (Math.abs(z) < 2.1 && x > -5 && x < 6) continue;
if (random() > 0.68) {
makeShrub(x, z, range(0.65, 1.3));
} else {
makeRock(x, z, range(0.18, 0.7));
}
}
// Distant caravan silhouettes establish scale and setting.
function makeDistantCamel(x, z, scale) {
const animal = new THREE.Group();
animal.position.set(x, 0, z);
animal.scale.setScalar(scale);
cube(animal, m.distant, [2.65, 0.95, 1.05], [0, 1.85, 0]);
cube(animal, m.distant, [1.25, 0.72, 0.88], [-0.1, 2.55, 0]);
cube(animal, m.distant, [0.72, 1.45, 0.72], [1.0, 2.7, 0]);
cube(animal, m.distant, [0.85, 0.55, 0.58], [1.45, 3.45, 0]);
cube(animal, m.distantDark, [0.56, 0.36, 0.5], [1.9, 3.37, 0]);
for (const legX of [-0.88, 0.88]) {
for (const legZ of [-0.36, 0.36]) {
cube(animal, m.distantDark, [0.25, 1.5, 0.25], [legX, 0.75, legZ]);
}
}
cube(animal, m.woodDark, [1.25, 0.12, 1.75], [-0.05, 2.72, 0]);
cube(animal, m.burlap, [0.95, 0.68, 0.58], [-0.08, 2.2, 0.68]);
cube(animal, m.rust, [0.95, 0.68, 0.58], [-0.08, 2.2, -0.68]);
scene.add(animal);
}
makeDistantCamel(-9.5, -8.8, 0.58);
makeDistantCamel(-15.5, -10.3, 0.54);
makeDistantCamel(-21.3, -9.6, 0.5);
// Main voxel caravan animal.
const camel = new THREE.Group();
scene.add(camel);
// Body and shoulder.
cube(camel, m.camel, [3.35, 1.3, 1.36], [0, 2.25, 0]);
cube(camel, m.camelLight, [0.85, 1.17, 1.42], [1.17, 2.28, 0]);
cube(camel, m.camelDark, [0.7, 1.13, 1.38], [-1.25, 2.25, 0]);
// Pixel-like coat markings.
const coatMarks = [
[-0.75, 2.53, 0.25],
[-0.28, 2.08, 0.34],
[0.2, 2.49, 0.2],
[0.62, 2.03, 0.36]
];
for (const side of [-1, 1]) {
for (let i = 0; i < coatMarks.length; i++) {
const mark = coatMarks[i];
cube(
camel,
i % 2 ? m.camelDark : m.camelLight,
[0.36, 0.27, 0.045],
[mark[0], mark[1], side * 0.702]
);
}
}
// Hump.
cube(camel, m.camel, [1.78, 0.94, 1.13], [-0.12, 3.18, 0]);
cube(camel, m.camelLight, [1.18, 0.18, 1.16], [-0.22, 3.68, 0]);
// Four blocky legs.
for (const x of [-1.18, 1.12]) {
for (const z of [-0.48, 0.48]) {
cube(camel, m.camel, [0.48, 1.28, 0.48], [x, 1.64, z]);
cube(camel, m.camelDark, [0.38, 0.73, 0.4], [x, 0.66, z]);
cube(camel, m.hoof, [0.51, 0.32, 0.53], [x, 0.16, z]);
}
}
// Long stepped neck and head.
cube(camel, m.camel, [0.92, 1.06, 0.92], [1.25, 3.05, 0]);
cube(camel, m.camelLight, [0.73, 0.86, 0.78], [1.48, 3.62, 0]);
cube(camel, m.camel, [0.66, 0.79, 0.68], [1.63, 4.14, 0]);
cube(camel, m.camelLight, [1.04, 0.7, 0.7], [2.13, 4.48, 0]);
cube(camel, m.muzzle, [0.75, 0.47, 0.58], [2.73, 4.35, 0]);
cube(camel, m.camelDark, [0.15, 0.36, 0.49], [3.09, 4.34, 0]);
// Ears, eyes, and nostrils.
for (const side of [-1, 1]) {
cube(camel, m.camelDark, [0.22, 0.37, 0.15], [1.82, 4.97, side * 0.22]);
cube(camel, m.eye, [0.11, 0.13, 0.06], [2.35, 4.56, side * 0.365]);
cube(camel, m.cream, [0.035, 0.04, 0.025], [2.375, 4.585, side * 0.401]);
cube(camel, m.hoof, [0.035, 0.07, 0.09], [3.166, 4.36, side * 0.14]);
beam(
camel,
m.leather,
[1.78, 4.72, side * 0.36],
[2.75, 4.39, side * 0.295],
0.055
);
}
beam(camel, m.leather, [2.73, 4.49, -0.29], [2.73, 4.49, 0.29], 0.065);
// Tail.
beam(camel, m.camelDark, [-1.66, 2.55, 0], [-1.94, 1.7, 0.04], 0.13);
cube(camel, m.hoof, [0.25, 0.43, 0.23], [-1.97, 1.48, 0.04]);
// Saddle blanket, draped equally over both sides.
cube(camel, m.teal, [1.66, 0.14, 1.73], [-0.08, 3.72, 0]);
for (const side of [-1, 1]) {
cube(camel, m.teal, [1.66, 0.69, 0.12], [-0.08, 3.37, side * 0.83]);
for (let i = 0; i < 7; i++) {
const x = -0.73 + i * 0.216;
cube(
camel,
m.cream,
[0.13, 0.13, 0.035],
[x, 3.36, side * 0.899]
);
cube(
camel,
i % 2 ? m.rust : m.cream,
[0.075, 0.24, 0.075],
[x, 3.0, side * 0.89]
);
}
}
// Central timber pack saddle and cross-frame.
cube(camel, m.woodDark, [1.74, 0.16, 1.22], [-0.08, 3.91, 0]);
cube(camel, m.woodLight, [1.48, 0.11, 0.96], [-0.08, 4.03, 0]);
for (const z of [-0.68, 0.68]) {
cube(camel, m.wood, [1.98, 0.16, 0.16], [-0.08, 3.98, z]);
}
for (const x of [-0.9, 0.74]) {
cube(camel, m.wood, [0.16, 0.16, 3.08], [x, 3.99, 0]);
}
cube(camel, m.brass, [0.09, 0.21, 0.26], [0.81, 4.03, 0]);
// Mirrored side bundles. Structure and mass are intentionally balanced.
for (const side of [-1, 1]) {
const bundle = new THREE.Group();
camel.add(bundle);
// Main burlap bundle.
cube(bundle, m.burlap, [1.25, 0.92, 0.68], [-0.05, 2.75, side * 1.13]);
cube(bundle, m.cream, [1.08, 0.14, 0.58], [-0.05, 3.25, side * 1.13]);
// Wooden retaining slats on the outer face.
const outerZ = side * 1.505;
for (const y of [2.47, 2.75, 3.04]) {
cube(bundle, m.woodLight, [1.35, 0.1, 0.08], [-0.05, y, outerZ]);
}
for (const x of [-0.56, 0.46]) {
cube(bundle, m.wood, [0.1, 0.95, 0.08], [x, 2.75, outerZ]);
}
// Rolled rug on top.
const rugMat = side === 1 ? m.rust : m.tealLight;
cube(bundle, rugMat, [1.16, 0.25, 0.37], [-0.05, 3.43, side * 1.12]);
for (const x of [-0.42, 0.32]) {
cube(bundle, m.ropeDark, [0.075, 0.27, 0.39], [x, 3.44, side * 1.12]);
}
// Small tied sack, equal on both sides.
cube(bundle, m.burlap, [0.38, 0.34, 0.31], [-0.31, 3.73, side * 1.1]);
cube(bundle, m.ropeDark, [0.4, 0.045, 0.33], [-0.31, 3.78, side * 1.1]);
cube(bundle, m.burlap, [0.16, 0.12, 0.15], [-0.31, 3.94, side * 1.1]);
// Rope wraps around each bundle.
for (const x of [-0.43, 0.32]) {
beam(
bundle,
m.rope,
[x, 2.31, side * 1.51],
[x, 3.34, side * 1.51],
0.055
);
beam(
bundle,
m.rope,
[x, 3.34, side * 1.51],
[x, 3.39, side * 0.79],
0.055
);
beam(
bundle,
m.rope,
[x, 3.39, side * 0.79],
[x, 2.32, side * 0.79],
0.055
);
// Suspension lines to the timber frame.
beam(
bundle,
m.ropeDark,
[x, 3.24, side * 1.2],
[x, 3.98, side * 0.68],
0.055
);
}
// Small illustrative hanging pouch.
cube(bundle, m.pottery, [0.31, 0.35, 0.18], [0.29, 2.29, side * 1.56]);
beam(
bundle,
m.ropeDark,
[0.29, 2.48, side * 1.55],
[0.29, 2.79, side * 1.49],
0.035
);
}
// Light airborne dust.
const dustGeometry = new THREE.BufferGeometry();
const dustPositions = new Float32Array(180 * 3);
for (let i = 0; i < 180; i++) {
dustPositions[i * 3] = range(-22, 22);
dustPositions[i * 3 + 1] = range(0.4, 5.5);
dustPositions[i * 3 + 2] = range(-15, 15);
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffd69a,
size: 0.045,
transparent: true,
opacity: 0.48,
depthWrite: false,
sizeAttenuation: true
})
);
scene.add(dust);
// Custom orbit camera controls.
const desired = {
theta: 0.78,
phi: 1.08,
radius: 9.2,
target: new THREE.Vector3(0, 2.45, 0)
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius,
target: desired.target.clone()
};
const pointers = new Map();
let previousPinchDistance = 0;
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
previousPinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi + dy * 0.005,
0.48,
1.43
);
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const distance = Math.hypot(a.x - b.x, a.y - b.y);
if (previousPinchDistance > 0) {
desired.radius = THREE.MathUtils.clamp(
desired.radius * (previousPinchDistance / distance),
4.6,
15
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
previousPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
4.6,
15
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = event.shiftKey ? 0.18 : 0.075;
switch (event.key) {
case "ArrowLeft":
desired.theta += step;
break;
case "ArrowRight":
desired.theta -= step;
break;
case "ArrowUp":
desired.phi = Math.max(0.48, desired.phi - step);
break;
case "ArrowDown":
desired.phi = Math.min(1.43, desired.phi + step);
break;
case "+":
case "=":
desired.radius = Math.max(4.6, desired.radius - 0.5);
break;
case "-":
case "_":
desired.radius = Math.min(15, desired.radius + 0.5);
break;
case "r":
case "R":
setView("overview");
break;
default:
return;
}
event.preventDefault();
});
function setView(view) {
document.querySelectorAll("[data-view]").forEach((button) => {
button.classList.toggle("active", button.dataset.view === view);
});
if (view === "overview") {
desired.theta = 0.78;
desired.phi = 1.08;
desired.radius = 9.2;
desired.target.set(0, 2.45, 0);
}
if (view === "cargo") {
desired.theta = 0.67;
desired.phi = 1.01;
desired.radius = 6.1;
desired.target.set(-0.05, 2.85, 0);
}
if (view === "opposite") {
desired.theta = current.theta + Math.PI;
desired.phi = 1.09;
desired.radius = 8.6;
desired.target.set(0, 2.45, 0);
}
}
document.querySelectorAll("[data-view]").forEach((button) => {
button.addEventListener("click", () => {
setView(button.dataset.view);
});
});
function dampAngle(from, to, amount) {
const difference = Math.atan2(
Math.sin(to - from),
Math.cos(to - from)
);
return from + difference * amount;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.9));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const smoothing = 1 - Math.pow(0.0008, 1 / 60);
current.theta = dampAngle(
current.theta,
desired.theta,
smoothing
);
current.phi +=
(desired.phi - current.phi) * smoothing;
current.radius +=
(desired.radius - current.radius) * smoothing;
current.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x +
current.radius * sinPhi * Math.cos(current.theta),
current.target.y + current.radius * Math.cos(current.phi),
current.target.z +
current.radius * sinPhi * Math.sin(current.theta)
);
camera.lookAt(current.target);
dust.rotation.y = elapsed * 0.006;
dust.position.y = Math.sin(elapsed * 0.22) * 0.035;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
resize();
camera.position.set(6.1, 6.8, 5.5);
camera.lookAt(current.target);
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 600);
animate();
</script>
</body>
</html>
```