Prompt specification
Build or customize the Three.js 3D scene "Two Crossing Vehicle Paths" 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: Two Crossing Vehicle Paths
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-crossing-vehicle-paths-x2105
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this voxel scene: Model a small intersection tile with two perpendicular vehicle paths and a highlighted conflict area. Show the physical crossing region independently of any traffic-control rule.
Working Three.js Starter (two-crossing-vehicle-paths-x2105):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Intersection — Physical Conflict Area</title>
<style>
:root {
--ink: #172328;
--muted: #56666b;
--panel: rgba(247, 250, 249, 0.9);
--line: rgba(23, 35, 40, 0.12);
--path-a: #21c7d5;
--path-b: #b26cff;
--conflict: #ffad24;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce6e5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#app,
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
}
#scene {
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
top: 22px;
left: 22px;
width: min(370px, calc(100vw - 44px));
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 18px;
background: var(--panel);
box-shadow:
0 18px 45px rgba(30, 48, 54, 0.14),
inset 0 0 0 1px rgba(255, 255, 255, 0.45);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
user-select: none;
}
.eyebrow {
margin-bottom: 9px;
color: #708084;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
max-width: 310px;
font-size: clamp(25px, 3vw, 34px);
font-weight: 760;
line-height: 1.02;
letter-spacing: -0.04em;
}
.subtitle {
margin: 10px 0 14px;
color: var(--muted);
font-size: 14px;
line-height: 1.45;
}
.rule-badge {
display: inline-flex;
align-items: center;
gap: 7px;
margin-bottom: 12px;
padding: 7px 10px;
border: 1px solid rgba(255, 173, 36, 0.42);
border-radius: 999px;
background: rgba(255, 173, 36, 0.12);
color: #8a5100;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.12em;
}
.rule-badge::before {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--conflict);
box-shadow: 0 0 0 3px rgba(255, 173, 36, 0.18);
content: "";
}
.explanation {
padding: 12px 13px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.5);
color: #4e5d62;
font-size: 12px;
line-height: 1.55;
}
.explanation strong {
color: var(--ink);
}
.legend {
display: grid;
gap: 9px;
margin-top: 15px;
}
.legend-item {
display: flex;
align-items: center;
gap: 10px;
color: #3c4b50;
font-size: 12px;
}
.swatch {
width: 22px;
height: 8px;
flex: 0 0 auto;
border-radius: 2px;
}
.swatch.a {
background: var(--path-a);
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.07);
}
.swatch.b {
background: var(--path-b);
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.07);
}
.swatch.conflict {
border: 2px solid #f39a0c;
background: rgba(255, 173, 36, 0.35);
}
.controls {
position: fixed;
right: 20px;
bottom: 18px;
display: flex;
align-items: center;
gap: 10px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 12px;
background: rgba(247, 250, 249, 0.82);
box-shadow: 0 10px 25px rgba(30, 48, 54, 0.1);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
color: #58686d;
font-size: 11px;
pointer-events: none;
}
#reset {
pointer-events: auto;
padding: 6px 9px;
border: 1px solid rgba(23, 35, 40, 0.13);
border-radius: 8px;
background: white;
color: var(--ink);
font: inherit;
font-weight: 700;
cursor: pointer;
}
#reset:hover {
background: #f0f4f3;
}
.corner-note {
position: fixed;
right: 22px;
top: 22px;
max-width: 230px;
padding: 10px 12px;
border-right: 3px solid var(--conflict);
background: rgba(247, 250, 249, 0.72);
color: #607075;
font-size: 10px;
line-height: 1.45;
letter-spacing: 0.03em;
text-transform: uppercase;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
display: grid;
place-items: center;
background: #dce6e5;
color: #526469;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 700px) {
.panel {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 15px;
}
.explanation,
.corner-note {
display: none;
}
.controls {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="app">
<canvas
id="scene"
aria-label="Interactive voxel intersection showing two perpendicular vehicle paths and their physical conflict area"
></canvas>
</div>
<section class="panel">
<div class="eyebrow">Urban mobility / geometry study</div>
<h1>Intersection conflict tile</h1>
<p class="subtitle">
Two perpendicular vehicle paths crossing through one physical overlap.
</p>
<div class="rule-badge">Rule-independent</div>
<div class="explanation">
The amber square marks <strong>only the physical crossing footprint</strong>
of the two road corridors. It does not encode signal state, priority,
right-of-way, or any other traffic-control rule.
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch a"></span>
<span>Path A — west to east</span>
</div>
<div class="legend-item">
<span class="swatch b"></span>
<span>Path B — south to north</span>
</div>
<div class="legend-item">
<span class="swatch conflict"></span>
<span>Physical conflict region</span>
</div>
</div>
</section>
<aside class="corner-note">
Geometry-defined conflict region<br />
No traffic-control assumptions
</aside>
<div class="controls">
<span>Drag to orbit · Scroll to zoom</span>
<button id="reset" type="button">Reset</button>
</div>
<div id="loading">Loading intersection tile…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const loading = document.getElementById("loading");
const resetButton = document.getElementById("reset");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce6e5);
scene.fog = new THREE.Fog(0xdce6e5, 58, 100);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
150
);
const target = new THREE.Vector3(0, 0.2, 0);
// Direct camera controls: no addons or OrbitControls are used.
const defaultView = {
azimuth: 0.72,
polar: 0.76,
radius: 44
};
const view = {
azimuth: defaultView.azimuth,
polar: defaultView.polar,
radius: defaultView.radius,
targetAzimuth: defaultView.azimuth,
targetPolar: defaultView.polar,
targetRadius: defaultView.radius
};
function updateCamera() {
const sinPolar = Math.sin(view.polar);
camera.position.set(
target.x + view.radius * sinPolar * Math.sin(view.azimuth),
target.y + view.radius * Math.cos(view.polar),
target.z + view.radius * sinPolar * Math.cos(view.azimuth)
);
camera.lookAt(target);
}
updateCamera();
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf4fbff, 0x77847f, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff4df, 3.2);
sun.position.set(-14, 26, 18);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 65;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xb8e7ff, 0.8);
fill.position.set(20, 12, -18);
scene.add(fill);
// Surrounding ground and subtle grid
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xcbd6d4,
roughness: 1
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.68;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(80, 40, 0x9eaeac, 0xb9c6c3);
grid.position.y = -0.665;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// Raised voxel base
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xaebbb8,
roughness: 0.92
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(30, 0.65, 30),
baseMaterial
);
base.position.y = -0.325;
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const lowerBase = new THREE.Mesh(
new THREE.BoxGeometry(30.25, 0.12, 30.25),
new THREE.MeshStandardMaterial({
color: 0x758481,
roughness: 0.9
})
);
lowerBase.position.y = -0.63;
lowerBase.receiveShadow = true;
scene.add(lowerBase);
// Cross-shaped asphalt surface
const roadHalfWidth = 4.2;
const roadHalfLength = 15;
const roadShape = new THREE.Shape();
roadShape.moveTo(-roadHalfLength, -roadHalfWidth);
roadShape.lineTo(-roadHalfWidth, -roadHalfWidth);
roadShape.lineTo(-roadHalfWidth, -roadHalfLength);
roadShape.lineTo(roadHalfWidth, -roadHalfLength);
roadShape.lineTo(roadHalfWidth, -roadHalfWidth);
roadShape.lineTo(roadHalfLength, -roadHalfWidth);
roadShape.lineTo(roadHalfLength, roadHalfWidth);
roadShape.lineTo(roadHalfWidth, roadHalfWidth);
roadShape.lineTo(roadHalfWidth, roadHalfLength);
roadShape.lineTo(-roadHalfWidth, roadHalfLength);
roadShape.lineTo(-roadHalfWidth, roadHalfWidth);
roadShape.lineTo(-roadHalfLength, roadHalfWidth);
roadShape.closePath();
const roadGeometry = new THREE.ShapeGeometry(roadShape);
roadGeometry.rotateX(-Math.PI / 2);
const road = new THREE.Mesh(
roadGeometry,
new THREE.MeshStandardMaterial({
color: 0x293338,
roughness: 0.96,
metalness: 0.02
})
);
road.position.y = 0.055;
road.receiveShadow = true;
scene.add(road);
// Voxel sidewalk tiles in the four corners
const sidewalkMaterials = [
new THREE.MeshStandardMaterial({
color: 0xcbd4d0,
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
color: 0xd4dcd8,
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
color: 0xc3ceca,
roughness: 0.9
})
];
const sidewalkStart = 4.27;
const sidewalkSize = 10.45;
const tileCount = 5;
const tilePitch = sidewalkSize / tileCount;
const tileSize = tilePitch - 0.055;
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
for (let ix = 0; ix < tileCount; ix++) {
for (let iz = 0; iz < tileCount; iz++) {
const x =
sx * (sidewalkStart + tilePitch * (ix + 0.5));
const z =
sz * (sidewalkStart + tilePitch * (iz + 0.5));
const materialIndex =
(ix * 3 + iz * 5 + (sx + 1) * 2 + (sz + 1)) % 3;
const tile = new THREE.Mesh(
new THREE.BoxGeometry(tileSize, 0.17, tileSize),
sidewalkMaterials[materialIndex]
);
tile.position.set(x, 0.085, z);
tile.castShadow = true;
tile.receiveShadow = true;
scene.add(tile);
}
}
}
}
// Raised curb segments
const curbMaterial = new THREE.MeshStandardMaterial({
color: 0xe0e6e2,
roughness: 0.85
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const horizontalCurb = new THREE.Mesh(
new THREE.BoxGeometry(10.45, 0.27, 0.18),
curbMaterial
);
horizontalCurb.position.set(
sx * (sidewalkStart + sidewalkSize * 0.5),
0.145,
sz * 4.31
);
horizontalCurb.castShadow = true;
horizontalCurb.receiveShadow = true;
scene.add(horizontalCurb);
const verticalCurb = new THREE.Mesh(
new THREE.BoxGeometry(0.18, 0.27, 10.45),
curbMaterial
);
verticalCurb.position.set(
sx * 4.31,
0.145,
sz * (sidewalkStart + sidewalkSize * 0.5)
);
verticalCurb.castShadow = true;
verticalCurb.receiveShadow = true;
scene.add(verticalCurb);
}
}
// Pale road-edge markings, avoiding the physical conflict region
const markingMaterial = new THREE.MeshStandardMaterial({
color: 0xe8eee9,
roughness: 0.85,
emissive: 0x53605c,
emissiveIntensity: 0.06
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const horizontalLine = new THREE.Mesh(
new THREE.BoxGeometry(10.1, 0.025, 0.1),
markingMaterial
);
horizontalLine.position.set(
sx * 9.55,
0.082,
sz * 3.82
);
scene.add(horizontalLine);
const verticalLine = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.025, 10.1),
markingMaterial
);
verticalLine.position.set(
sx * 3.82,
0.082,
sz * 9.55
);
scene.add(verticalLine);
}
}
// The physical conflict region is the full overlap of the two corridors.
// Its geometry is independent of any signal, priority, or right-of-way rule.
const conflictSize = 8.4;
const conflictBase = new THREE.Mesh(
new THREE.BoxGeometry(conflictSize, 0.055, conflictSize),
new THREE.MeshBasicMaterial({
color: 0xffa515,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
conflictBase.position.y = 0.095;
scene.add(conflictBase);
const conflictMaterials = [
new THREE.MeshStandardMaterial({
color: 0xffa515,
emissive: 0xff8b00,
emissiveIntensity: 0.2,
transparent: true,
opacity: 0.4,
roughness: 0.52,
depthWrite: false
}),
new THREE.MeshStandardMaterial({
color: 0xffc044,
emissive: 0xff9500,
emissiveIntensity: 0.18,
transparent: true,
opacity: 0.34,
roughness: 0.55,
depthWrite: false
})
];
const conflictPitch = conflictSize / 4;
const conflictTileSize = conflictPitch - 0.055;
for (let x = 0; x < 4; x++) {
for (let z = 0; z < 4; z++) {
const tile = new THREE.Mesh(
new THREE.BoxGeometry(conflictTileSize, 0.1, conflictTileSize),
conflictMaterials[(x + z) % 2]
);
tile.position.set(
-conflictSize * 0.5 + conflictPitch * (x + 0.5),
0.145,
-conflictSize * 0.5 + conflictPitch * (z + 0.5)
);
scene.add(tile);
}
}
const conflictEdgeMaterial = new THREE.MeshBasicMaterial({
color: 0xffa000,
toneMapped: false
});
const horizontalEdge = new THREE.Mesh(
new THREE.BoxGeometry(conflictSize + 0.12, 0.07, 0.11),
conflictEdgeMaterial
);
horizontalEdge.position.y = 0.23;
scene.add(horizontalEdge);
const verticalEdge = new THREE.Mesh(
new THREE.BoxGeometry(0.11, 0.07, conflictSize + 0.12),
conflictEdgeMaterial
);
verticalEdge.position.y = 0.23;
scene.add(verticalEdge);
// Voxel corner markers
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.24, 0.35, 0.24),
conflictEdgeMaterial
);
marker.position.set(
sx * conflictSize * 0.5,
0.28,
sz * conflictSize * 0.5
);
marker.castShadow = true;
scene.add(marker);
}
}
// Vehicle paths
const pathAColor = 0x21c7d5;
const pathBColor = 0xb26cff;
function createPathTube(color, start, end) {
const curve = new THREE.LineCurve3(start, end);
const geometry = new THREE.TubeGeometry(curve, 2, 0.075, 8, false);
const material = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.55,
roughness: 0.45,
toneMapped: false
});
const tube = new THREE.Mesh(geometry, material);
scene.add(tube);
}
createPathTube(
pathAColor,
new THREE.Vector3(-14.35, 0.245, 0),
new THREE.Vector3(14.35, 0.245, 0)
);
createPathTube(
pathBColor,
new THREE.Vector3(0, 0.245, -14.35),
new THREE.Vector3(0, 0.245, 14.35)
);
// Flat directional arrows
const arrowShape = new THREE.Shape();
arrowShape.moveTo(-0.75, -0.17);
arrowShape.lineTo(0.12, -0.17);
arrowShape.lineTo(0.12, -0.42);
arrowShape.lineTo(0.82, 0);
arrowShape.lineTo(0.12, 0.42);
arrowShape.lineTo(0.12, 0.17);
arrowShape.lineTo(-0.75, 0.17);
arrowShape.closePath();
const arrowGeometry = new THREE.ShapeGeometry(arrowShape);
arrowGeometry.rotateX(-Math.PI / 2);
function addArrow(color, x, z, rotationY) {
const arrow = new THREE.Mesh(
arrowGeometry,
new THREE.MeshBasicMaterial({
color,
side: THREE.DoubleSide,
toneMapped: false
})
);
arrow.position.set(x, 0.31, z);
arrow.rotation.y = rotationY;
scene.add(arrow);
}
// Path A travels toward +X.
addArrow(pathAColor, -5.55, 0, 0);
addArrow(pathAColor, 8.0, 0, 0);
// Path B travels toward -Z.
addArrow(pathBColor, 0, 5.65, Math.PI / 2);
addArrow(pathBColor, 0, -8.4, Math.PI / 2);
// Small voxel vehicles, one on each approach.
function createVehicle(color) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color,
roughness: 0.4,
metalness: 0.12
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x142126,
roughness: 0.48
});
const glassMaterial = new THREE.MeshStandardMaterial({
color: 0x8bc3d2,
roughness: 0.2,
metalness: 0.25,
emissive: 0x183c48,
emissiveIntensity: 0.16
});
const lampMaterial = new THREE.MeshStandardMaterial({
color: 0xfff2b2,
emissive: 0xffdd77,
emissiveIntensity: 0.7
});
const tailMaterial = new THREE.MeshStandardMaterial({
color: 0xff5147,
emissive: 0x9e1008,
emissiveIntensity: 0.45
});
function addBox(size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
material
);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
group.add(mesh);
return mesh;
}
addBox(
new THREE.Vector3(2.7, 0.5, 1.32),
new THREE.Vector3(0, 0.46, 0),
bodyMaterial
);
addBox(
new THREE.Vector3(1.28, 0.54, 1.08),
new THREE.Vector3(-0.16, 0.96, 0),
bodyMaterial
);
addBox(
new THREE.Vector3(0.025, 0.28, 0.91),
new THREE.Vector3(0.495, 0.99, 0),
glassMaterial,
false
);
for (const z of [-0.551, 0.551]) {
addBox(
new THREE.Vector3(0.93, 0.27, 0.025),
new THREE.Vector3(-0.17, 1.0, z),
glassMaterial,
false
);
}
for (const x of [-0.86, 0.86]) {
for (const z of [-0.69, 0.69]) {
addBox(
new THREE.Vector3(0.54, 0.4, 0.25),
new THREE.Vector3(x, 0.2, z),
darkMaterial
);
}
}
for (const z of [-0.43, 0.43]) {
addBox(
new THREE.Vector3(0.06, 0.17, 0.2),
new THREE.Vector3(1.37, 0.48, z),
lampMaterial,
false
);
addBox(
new THREE.Vector3(0.06, 0.15, 0.2),
new THREE.Vector3(-1.37, 0.46, z),
tailMaterial,
false
);
}
return group;
}
const vehicleA = createVehicle(pathAColor);
vehicleA.position.set(-9.7, 0.06, 0);
scene.add(vehicleA);
const vehicleB = createVehicle(pathBColor);
vehicleB.position.set(0, 0.06, 9.7);
vehicleB.rotation.y = Math.PI / 2;
scene.add(vehicleB);
// Billboard labels made with CanvasTexture.
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width * 0.5, height * 0.5);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function createLabel(text, accent, width = 560) {
const height = 128;
const labelCanvas = document.createElement("canvas");
labelCanvas.width = width;
labelCanvas.height = height;
const ctx = labelCanvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRectPath(ctx, 5, 5, width - 10, height - 10, 25);
ctx.fillStyle = "rgba(17, 28, 33, 0.91)";
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.fillStyle = "#ffffff";
ctx.font = "800 36px Inter, Arial, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width * 0.5, height * 0.52);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
})
);
sprite.scale.set(5.6, 1.28, 1);
sprite.renderOrder = 20;
return sprite;
}
const labelA = createLabel("PATH A · WEST → EAST", "#21c7d5");
labelA.position.set(-10.3, 1.65, 3.45);
scene.add(labelA);
const labelB = createLabel("PATH B · SOUTH → NORTH", "#b26cff");
labelB.position.set(3.45, 1.65, -10.3);
scene.add(labelB);
const conflictLabel = createLabel(
"PHYSICAL CONFLICT AREA",
"#ffad24",
620
);
conflictLabel.scale.set(6.3, 1.3, 1);
conflictLabel.position.set(4.75, 1.35, 4.75);
scene.add(conflictLabel);
// Pointer and keyboard camera controls
const pointers = new Map();
let rotating = false;
let previousX = 0;
let previousY = 0;
let previousPinchDistance = 0;
function pointerDistance() {
const points = [...pointers.values()];
if (points.length < 2) return 0;
return Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
rotating = true;
previousX = event.clientX;
previousY = event.clientY;
canvas.classList.add("dragging");
} else if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && rotating) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
view.targetAzimuth -= dx * 0.006;
view.targetPolar = THREE.MathUtils.clamp(
view.targetPolar + dy * 0.005,
0.34,
1.35
);
previousX = event.clientX;
previousY = event.clientY;
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
view.targetRadius = THREE.MathUtils.clamp(
view.targetRadius * (previousPinchDistance / distance),
25,
65
);
}
previousPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
rotating = false;
canvas.classList.remove("dragging");
}
if (pointers.size < 2) {
previousPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.targetRadius = THREE.MathUtils.clamp(
view.targetRadius * Math.exp(event.deltaY * 0.001),
25,
65
);
},
{ passive: false }
);
function resetView() {
view.targetAzimuth = defaultView.azimuth;
view.targetPolar = defaultView.polar;
view.targetRadius = defaultView.radius;
}
resetButton.addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
view.targetAzimuth -= 0.12;
} else if (event.key === "ArrowRight") {
view.targetAzimuth += 0.12;
} else if (event.key === "ArrowUp") {
view.targetPolar = THREE.MathUtils.clamp(
view.targetPolar - 0.08,
0.34,
1.35
);
} else if (event.key === "ArrowDown") {
view.targetPolar = THREE.MathUtils.clamp(
view.targetPolar + 0.08,
0.34,
1.35
);
} else if (event.key === "+" || event.key === "=") {
view.targetRadius = Math.max(25, view.targetRadius - 3);
} else if (event.key === "-" || event.key === "_") {
view.targetRadius = Math.min(65, view.targetRadius + 3);
} else if (event.key.toLowerCase() === "r") {
resetView();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
function animate() {
const easing = 0.12;
view.azimuth +=
(view.targetAzimuth - view.azimuth) * easing;
view.polar +=
(view.targetPolar - view.polar) * easing;
view.radius +=
(view.targetRadius - view.radius) * easing;
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
loading.classList.add("hidden");
</script>
</body>
</html>
```