Prompt specification
Build or customize the Three.js 3D scene "Raised-floor-plan legend tile" 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: Raised-floor-plan legend tile
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/raised-floor-plan-legend-tile-x0473
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: raised-floor-plan legend tile. Model a small tactile map with raised walls, a start marker, and distinct route textures; place matching legend samples beside it for direct comparison.
Working Three.js Starter (raised-floor-plan-legend-tile-x0473):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tactile Floor Plan — Route Legend</title>
<style>
:root {
color-scheme: light;
--ink: #20332f;
--muted: #687772;
--paper: #f4f1e8;
--accent: #ef704c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dfe6df;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.brand {
position: fixed;
top: 26px;
left: 30px;
z-index: 2;
max-width: min(420px, calc(100vw - 60px));
pointer-events: none;
color: var(--ink);
}
.eyebrow {
display: block;
margin-bottom: 7px;
color: var(--accent);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 46px);
font-weight: 750;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.reset {
position: fixed;
top: 25px;
right: 26px;
z-index: 3;
border: 1px solid rgba(32, 51, 47, 0.16);
border-radius: 999px;
padding: 10px 16px;
background: rgba(248, 246, 238, 0.78);
color: var(--ink);
box-shadow: 0 8px 30px rgba(31, 52, 47, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
font: 700 11px/1 inherit;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: transform 150ms ease, background 150ms ease;
}
.reset:hover {
transform: translateY(-1px);
background: rgba(255, 253, 246, 0.96);
}
.hint {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 2;
transform: translateX(-50%);
border: 1px solid rgba(32, 51, 47, 0.12);
border-radius: 999px;
padding: 10px 16px;
background: rgba(248, 246, 238, 0.76);
color: #50615d;
box-shadow: 0 8px 30px rgba(31, 52, 47, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
white-space: nowrap;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.035em;
}
.hint span {
color: #a2aaa6;
margin: 0 7px;
}
#fallback {
position: fixed;
inset: 0;
z-index: 10;
display: none;
place-items: center;
padding: 30px;
background: #dfe6df;
color: var(--ink);
text-align: center;
}
@media (max-width: 700px) {
.brand {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.reset {
top: 17px;
right: 16px;
padding: 9px 12px;
}
.hint {
bottom: 14px;
max-width: calc(100vw - 24px);
overflow: hidden;
text-overflow: ellipsis;
}
}
</style>
</head>
<body>
<div class="brand">
<span class="eyebrow">Wayfinding Study / 02</span>
<h1>Raised plan.<br />Distinct routes.</h1>
<p class="subtitle">
A tactile wayfinding tile with raised walls, route textures, and
full-size matching legend samples.
</p>
</div>
<button class="reset" id="reset" type="button">Reset view</button>
<div class="hint">
Drag to orbit <span>•</span> Shift/right-drag to pan
<span>•</span> Scroll to zoom
</div>
<div id="fallback">
This scene requires a browser with WebGL enabled.
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, camera, and lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe6df);
scene.fog = new THREE.Fog(0xdfe6df, 18, 34);
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
document.getElementById("fallback").style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional tactile floor plan and matching route legend"
);
document.body.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-7, 7, 4, -4, 0.1, 60);
const cameraTarget = new THREE.Vector3(-0.1, 0.1, 0);
scene.add(new THREE.HemisphereLight(0xf8fbf4, 0x68766e, 2.05));
const keyLight = new THREE.DirectionalLight(0xfff4dd, 3.2);
keyLight.position.set(-5, 11, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.bias = -0.00035;
keyLight.shadow.normalBias = 0.02;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8e8e0, 1.25);
fillLight.position.set(8, 5, -6);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0xdfe6df,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.075;
ground.receiveShadow = true;
scene.add(ground);
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const materials = {
backing: new THREE.MeshStandardMaterial({
color: 0x344943,
roughness: 0.74,
metalness: 0.02
}),
insert: new THREE.MeshStandardMaterial({
color: 0xf3efe4,
roughness: 0.86
}),
floor: new THREE.MeshStandardMaterial({
color: 0xd9ded5,
roughness: 0.92
}),
card: new THREE.MeshStandardMaterial({
color: 0xfaf7ee,
roughness: 0.82
}),
wall: new THREE.MeshStandardMaterial({
color: 0xc7bca8,
roughness: 0.8
}),
wallCap: new THREE.MeshStandardMaterial({
color: 0xf0e5d2,
roughness: 0.68
}),
wallGroove: new THREE.MeshStandardMaterial({
color: 0x837969,
roughness: 0.9
}),
dark: new THREE.MeshStandardMaterial({
color: 0x28423b,
roughness: 0.78
}),
orange: new THREE.MeshStandardMaterial({
color: 0xf16f49,
roughness: 0.46
}),
orangeLight: new THREE.MeshStandardMaterial({
color: 0xffc09f,
roughness: 0.48
}),
furniture: new THREE.MeshStandardMaterial({
color: 0xc66d54,
roughness: 0.76
}),
furnitureLight: new THREE.MeshStandardMaterial({
color: 0xe0a58d,
roughness: 0.75
}),
elevator: new THREE.MeshStandardMaterial({
color: 0x708c84,
roughness: 0.68
})
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function roundedRectShape(width, depth, radius) {
const x = -width / 2;
const y = -depth / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + depth - radius);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - radius,
y + depth
);
shape.lineTo(x + radius, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function roundedSlab(width, depth, height, radius, material, y = 0) {
const shape = roundedRectShape(width, depth, radius);
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: height,
steps: 1,
bevelEnabled: true,
bevelSegments: 3,
bevelSize: Math.min(0.035, height * 0.18),
bevelThickness: Math.min(0.035, height * 0.18),
curveSegments: 10
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.position.y = y;
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function box(width, height, depth, material, x, y, z) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addTextPlane(text, width, depth, x, y, z, options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
const lines = text.split("\n");
const maxChars = Math.max(...lines.map((line) => line.length));
const fontSize = Math.min(
options.fontSize || 76,
Math.floor(820 / Math.max(1, maxChars * 0.57))
);
ctx.font = `${options.weight || 800} ${fontSize}px Arial, sans-serif`;
ctx.fillStyle = options.color || "#30443e";
const lineHeight = fontSize * 1.12;
const startY = canvas.height / 2 - ((lines.length - 1) * lineHeight) / 2;
lines.forEach((line, index) => {
ctx.fillText(line, canvas.width / 2, startY + index * lineHeight);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: -2,
toneMapped: false
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Procedural tactile route textures
// -------------------------------------------------------------------------
function createRouteTexture(kind) {
const canvas = document.createElement("canvas");
const bumpCanvas = document.createElement("canvas");
canvas.width = bumpCanvas.width = 256;
canvas.height = bumpCanvas.height = 64;
const ctx = canvas.getContext("2d");
const bump = bumpCanvas.getContext("2d");
if (kind === "ribbed") {
ctx.fillStyle = "#21877e";
ctx.fillRect(0, 0, 256, 64);
bump.fillStyle = "#d2d2d2";
bump.fillRect(0, 0, 256, 64);
for (let x = -20; x < 280; x += 32) {
ctx.strokeStyle = "#b8e2d7";
ctx.lineWidth = 8;
ctx.beginPath();
ctx.moveTo(x, 64);
ctx.lineTo(x + 24, 0);
ctx.stroke();
bump.strokeStyle = "#3b3b3b";
bump.lineWidth = 9;
bump.beginPath();
bump.moveTo(x, 64);
bump.lineTo(x + 24, 0);
bump.stroke();
}
} else if (kind === "dotted") {
ctx.fillStyle = "#d89632";
ctx.fillRect(0, 0, 256, 64);
bump.fillStyle = "#d8d8d8";
bump.fillRect(0, 0, 256, 64);
for (let x = 16; x < 256; x += 32) {
ctx.fillStyle = "#ffe2a5";
ctx.beginPath();
ctx.arc(x, 32, 9, 0, Math.PI * 2);
ctx.fill();
ctx.fillStyle = "#f8bd66";
ctx.beginPath();
ctx.arc(x, 32, 3, 0, Math.PI * 2);
ctx.fill();
bump.fillStyle = "#343434";
bump.beginPath();
bump.arc(x, 32, 9, 0, Math.PI * 2);
bump.fill();
}
} else {
ctx.fillStyle = "#77576f";
ctx.fillRect(0, 0, 256, 64);
bump.fillStyle = "#d6d6d6";
bump.fillRect(0, 0, 256, 64);
for (let x = 0; x <= 256; x += 32) {
ctx.strokeStyle = "#dbc8d5";
ctx.lineWidth = 6;
ctx.beginPath();
ctx.moveTo(x, 0);
ctx.lineTo(x, 64);
ctx.stroke();
bump.strokeStyle = "#383838";
bump.lineWidth = 7;
bump.beginPath();
bump.moveTo(x, 0);
bump.lineTo(x, 64);
bump.stroke();
}
ctx.strokeStyle = "#dbc8d5";
ctx.lineWidth = 5;
ctx.beginPath();
ctx.moveTo(0, 32);
ctx.lineTo(256, 32);
ctx.stroke();
bump.strokeStyle = "#383838";
bump.lineWidth = 6;
bump.beginPath();
bump.moveTo(0, 32);
bump.lineTo(256, 32);
bump.stroke();
}
const map = new THREE.CanvasTexture(canvas);
map.colorSpace = THREE.SRGBColorSpace;
map.wrapS = map.wrapT = THREE.RepeatWrapping;
map.repeat.set(0.72, 1);
map.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const bumpMap = new THREE.CanvasTexture(bumpCanvas);
bumpMap.wrapS = bumpMap.wrapT = THREE.RepeatWrapping;
bumpMap.repeat.copy(map.repeat);
return new THREE.MeshStandardMaterial({
map,
bumpMap,
bumpScale: 0.065,
roughness: 0.76,
metalness: 0,
side: THREE.DoubleSide
});
}
const routeMaterials = {
ribbed: createRouteTexture("ribbed"),
dotted: createRouteTexture("dotted"),
grid: createRouteTexture("grid")
};
// A flat ribbon following a polyline. UVs use accumulated world distance,
// so the tactile pattern remains consistent between map and legend.
function addRibbon(points, width, material, y) {
const positions = [];
const uvs = [];
const indices = [];
let distance = 0;
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const before = new THREE.Vector2(
points[i].x - previous.x,
points[i].z - previous.z
);
const after = new THREE.Vector2(
next.x - points[i].x,
next.z - points[i].z
);
if (before.lengthSq() < 0.000001) before.copy(after);
if (after.lengthSq() < 0.000001) after.copy(before);
before.normalize();
after.normalize();
const tangent = before.add(after).normalize();
const normal = new THREE.Vector2(-tangent.y, tangent.x);
if (i > 0) {
distance += Math.hypot(
points[i].x - points[i - 1].x,
points[i].z - points[i - 1].z
);
}
const left = {
x: points[i].x + normal.x * width / 2,
z: points[i].z + normal.y * width / 2
};
const right = {
x: points[i].x - normal.x * width / 2,
z: points[i].z - normal.y * width / 2
};
positions.push(left.x, y, left.z, right.x, y, right.z);
uvs.push(distance, 0, distance, 1);
if (i < points.length - 1) {
const base = i * 2;
indices.push(base, base + 1, base + 2);
indices.push(base + 1, base + 3, base + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Raised architectural elements
// -------------------------------------------------------------------------
function addWall(x, z, length, alongX = true, height = 0.38) {
const floorY = 0.305;
const thickness = 0.13;
const body = box(
alongX ? length : thickness,
height,
alongX ? thickness : length,
materials.wall,
x,
floorY + height / 2,
z
);
scene.add(body);
const cap = box(
alongX ? length + 0.012 : thickness + 0.012,
0.035,
alongX ? thickness + 0.012 : length + 0.012,
materials.wallCap,
x,
floorY + height + 0.014,
z
);
scene.add(cap);
const grooveCount = Math.max(2, Math.floor(length / 0.27));
for (let i = 0; i < grooveCount; i++) {
const t = (i + 0.5) / grooveCount - 0.5;
const gx = alongX ? x + t * length : x;
const gz = alongX ? z : z + t * length;
const groove = box(
alongX ? 0.025 : thickness * 0.65,
0.009,
alongX ? thickness * 0.65 : 0.025,
materials.wallGroove,
gx,
floorY + height + 0.034,
gz
);
scene.add(groove);
}
}
function addMiniWall(x, z, length) {
const body = box(
length,
0.12,
0.09,
materials.wall,
x,
0.405,
z
);
scene.add(body);
const cap = box(
length + 0.01,
0.022,
0.1,
materials.wallCap,
x,
0.476,
z
);
scene.add(cap);
}
// -------------------------------------------------------------------------
// Main map tile
// -------------------------------------------------------------------------
const mapX = -2.25;
const mapZ = 0;
scene.add(
roundedSlab(5.9, 4.8, 0.2, 0.24, materials.backing, 0)
);
scene.add(
roundedSlab(5.72, 4.62, 0.075, 0.2, materials.insert, 0.17)
);
scene.add(
roundedSlab(5.2, 3.48, 0.06, 0.12, materials.floor, 0.245)
);
addTextPlane(
"LEVEL 02 / TOUCH MAP",
4.25,
0.34,
mapX,
0.265,
-2.02,
{ fontSize: 67 }
);
// Perimeter walls with deliberate doorway gaps.
addWall(mapX - 1.88, -1.48, 1.05, true);
addWall(mapX - 0.08, -1.48, 1.35, true);
addWall(mapX + 1.75, -1.48, 1.30, true);
addWall(mapX - 1.53, 1.78, 1.75, true);
addWall(mapX + 1.28, 1.78, 2.25, true);
addWall(mapX - 2.48, -0.89, 1.07, false);
addWall(mapX - 2.48, 0.99, 1.47, false);
addWall(mapX + 2.48, -0.61, 1.62, false);
addWall(mapX + 2.48, 1.24, 0.97, false);
// Interior partitions.
addWall(mapX - 1.62, -0.50, 0.47, true);
addWall(mapX - 0.72, -0.50, 0.10, true);
addWall(mapX - 0.55, -1.17, 0.43, false);
addWall(mapX - 0.55, 0.97, 1.43, false);
addWall(mapX + 0.85, -0.94, 0.12, false);
addWall(mapX + 0.85, 0.29, 0.87, false);
addWall(mapX + 1.67, 0.68, 1.45, true);
addWall(mapX + 1.22, -0.52, 2.35, true);
// Low tactile furniture and room elements.
scene.add(
roundedSlab(
1.35,
0.55,
0.17,
0.09,
materials.furniture,
0.305
).translateX(mapX + 1.20).translateZ(0.83)
);
scene.add(
roundedSlab(
1.18,
0.55,
0.13,
0.09,
materials.furnitureLight,
0.305
).translateX(mapX + 1.48).translateZ(-0.43)
);
scene.add(
roundedSlab(
0.58,
0.58,
0.26,
0.08,
materials.elevator,
0.305
).translateX(mapX + 0.66).translateZ(0.98)
);
scene.add(
roundedSlab(
0.52,
0.68,
0.10,
0.08,
materials.furnitureLight,
0.305
).translateX(mapX - 1.43).translateZ(0.58)
);
// Route paths.
const mainRoute = [
{ x: mapX - 2.05, z: -1.02 },
{ x: mapX - 1.10, z: -1.02 },
{ x: mapX - 1.10, z: -0.20 },
{ x: mapX + 0.25, z: -0.20 },
{ x: mapX + 0.25, z: 1.25 },
{ x: mapX + 1.65, z: 1.25 }
];
const accessRoute = [
{ x: mapX - 2.05, z: -1.02 },
{ x: mapX - 2.05, z: 0.35 },
{ x: mapX - 1.78, z: 0.35 },
{ x: mapX - 1.78, z: 1.25 },
{ x: mapX - 0.10, z: 1.25 }
];
const serviceRoute = [
{ x: mapX - 2.05, z: -1.02 },
{ x: mapX - 1.75, z: -0.75 },
{ x: mapX + 1.35, z: -0.75 },
{ x: mapX + 1.35, z: -0.92 }
];
addRibbon(mainRoute, 0.18, routeMaterials.ribbed, 0.321);
addRibbon(accessRoute, 0.16, routeMaterials.dotted, 0.332);
addRibbon(serviceRoute, 0.15, routeMaterials.grid, 0.343);
// Start marker: an orange tactile beacon.
const startX = mapX - 2.05;
const startZ = -1.02;
const markerBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.235, 0.255, 0.08, 32),
materials.orange
);
markerBase.position.set(startX, 0.35, startZ);
markerBase.castShadow = true;
scene.add(markerBase);
const markerCone = new THREE.Mesh(
new THREE.ConeGeometry(0.165, 0.31, 28),
materials.orange
);
markerCone.position.set(startX, 0.535, startZ);
markerCone.castShadow = true;
scene.add(markerCone);
const markerTip = new THREE.Mesh(
new THREE.SphereGeometry(0.092, 24, 16),
materials.orangeLight
);
markerTip.position.set(startX, 0.69, startZ);
markerTip.castShadow = true;
scene.add(markerTip);
// Main map room labels.
addTextPlane("ENTRY", 0.66, 0.20, startX + 0.05, 0.312, -1.36, {
fontSize: 54,
color: "#61726c"
});
addTextPlane("LOBBY", 0.90, 0.23, mapX - 1.58, 0.312, 0.05, {
fontSize: 55,
color: "#66756f"
});
addTextPlane("MEET", 0.85, 0.22, mapX + 1.55, 0.312, -0.24, {
fontSize: 55,
color: "#66756f"
});
addTextPlane("HALL", 0.75, 0.22, mapX + 1.66, 0.312, 1.48, {
fontSize: 55,
color: "#66756f"
});
// Small registration dots at the corners of the map field.
[-2.47, 2.47].forEach((localX) => {
[-1.38, 1.69].forEach((z) => {
const dot = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 0.012, 16),
materials.dark
);
dot.position.set(mapX + localX, 0.313, z);
scene.add(dot);
});
});
// -------------------------------------------------------------------------
// Matching legend tile
// -------------------------------------------------------------------------
const legendX = 3.45;
scene.add(
roundedSlab(3.55, 4.8, 0.2, 0.24, materials.backing, 0)
);
scene.add(
roundedSlab(3.38, 4.62, 0.075, 0.2, materials.insert, 0.17)
);
addTextPlane("ROUTE LEGEND", 2.30, 0.32, legendX + 0.32, 0.265, -1.85, {
fontSize: 67
});
const legendMarker = new THREE.Mesh(
new THREE.ConeGeometry(0.13, 0.25, 24),
materials.orange
);
legendMarker.position.set(legendX - 1.36, 0.39, -1.86);
legendMarker.castShadow = true;
scene.add(legendMarker);
addTextPlane("START", 0.62, 0.19, legendX - 0.91, 0.265, -1.86, {
fontSize: 47,
color: "#61726c"
});
const legendItems = [
{
z: -0.93,
material: routeMaterials.ribbed,
label: "RIBBED\nMAIN ROUTE"
},
{
z: 0.27,
material: routeMaterials.dotted,
label: "DOTTED\nACCESS"
},
{
z: 1.47,
material: routeMaterials.grid,
label: "GRID / SERVICE"
}
];
legendItems.forEach((item) => {
const card = roundedSlab(
3.02,
0.83,
0.08,
0.13,
materials.card,
0.245
);
card.position.x = legendX;
card.position.z = item.z;
scene.add(card);
// A miniature raised wall creates a tactile sample rather than a flat icon.
addMiniWall(legendX - 0.72, item.z - 0.23, 1.25);
const samplePath = [
{ x: legendX - 1.42, z: item.z - 0.06 },
{ x: legendX - 0.78, z: item.z - 0.06 },
{ x: legendX - 0.78, z: item.z + 0.15 },
{ x: legendX - 0.10, z: item.z + 0.15 }
];
addRibbon(samplePath, 0.145, item.material, 0.346);
addTextPlane(
item.label,
1.32,
0.42,
legendX + 0.72,
0.347,
item.z,
{
fontSize: item.label.includes("GRID") ? 50 : 55,
color: "#344943"
}
);
});
// -------------------------------------------------------------------------
// Custom camera controls — no addons
// -------------------------------------------------------------------------
const desired = {
theta: 0.24,
phi: 0.86,
zoom: 1,
target: cameraTarget.clone()
};
const current = {
theta: desired.theta,
phi: desired.phi,
zoom: desired.zoom,
target: desired.target.clone()
};
const initialView = {
theta: desired.theta,
phi: desired.phi,
zoom: desired.zoom,
target: desired.target.clone()
};
let viewHeight = 8;
function updateCameraProjection() {
const aspect = window.innerWidth / window.innerHeight;
viewHeight = Math.max(7.9, 12.6 / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
function positionCamera() {
const radius = 14;
const sinPhi = Math.sin(current.phi);
camera.position.set(
current.target.x + radius * sinPhi * Math.sin(current.theta),
current.target.y + radius * Math.cos(current.phi),
current.target.z + radius * sinPhi * Math.cos(current.theta)
);
camera.zoom = current.zoom;
camera.updateProjectionMatrix();
camera.lookAt(current.target);
}
function resetView() {
desired.theta = initialView.theta;
desired.phi = initialView.phi;
desired.zoom = initialView.zoom;
desired.target.copy(initialView.target);
}
const pointers = new Map();
let dragMode = "orbit";
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragMode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
} else if (pointers.size === 2) {
lastPinchDistance = pointerDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
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 >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * (distance / lastPinchDistance),
0.65,
2.35
);
}
lastPinchDistance = distance;
return;
}
if (dragMode === "orbit") {
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.34,
1.28
);
} else {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3(
-forward.z,
0,
forward.x
);
const panScale = (viewHeight / desired.zoom) * 0.00135;
desired.target.addScaledVector(right, -dx * panScale);
desired.target.addScaledVector(forward, -dy * panScale);
desired.target.x = THREE.MathUtils.clamp(
desired.target.x,
-4,
4
);
desired.target.z = THREE.MathUtils.clamp(
desired.target.z,
-3,
3
);
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.zoom = THREE.MathUtils.clamp(
desired.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.35
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
const step = 0.08;
if (event.key === "ArrowLeft") desired.theta += step;
if (event.key === "ArrowRight") desired.theta -= step;
if (event.key === "ArrowUp") {
desired.phi = Math.max(0.34, desired.phi - step);
}
if (event.key === "ArrowDown") {
desired.phi = Math.min(1.28, desired.phi + step);
}
if (event.key === "+" || event.key === "=") {
desired.zoom = Math.min(2.35, desired.zoom * 1.08);
}
if (event.key === "-" || event.key === "_") {
desired.zoom = Math.max(0.65, desired.zoom / 1.08);
}
if (event.key.toLowerCase() === "r") resetView();
});
document.getElementById("reset").addEventListener("click", resetView);
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCameraProjection();
});
updateCameraProjection();
positionCamera();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
const damping = 0.12;
current.theta += (desired.theta - current.theta) * damping;
current.phi += (desired.phi - current.phi) * damping;
current.zoom += (desired.zoom - current.zoom) * damping;
current.target.lerp(desired.target, damping);
positionCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```