Prompt specification
Build or customize the Three.js 3D scene "Cane-detectable boundary study" 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: Cane-detectable boundary study
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cane-detectable-boundary-study-x0445
Scene Description Prompt:
Model a simplified white cane sweep beside floor-level and overhanging obstacles; expose their different heights without implying that one tool detects every possible hazard. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (cane-detectable-boundary-study-x0445):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>White Cane Sweep — Ground and Overhead Obstacles</title>
<style>
:root {
color-scheme: light;
--ink: #21343d;
--muted: #60747d;
--panel: rgba(255, 255, 255, 0.91);
--ground: #e76f51;
--overhead: #7558d6;
--sweep: #2583a3;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8f0ee;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid rgba(35, 62, 73, 0.12);
background: var(--panel);
box-shadow: 0 12px 36px rgba(41, 63, 70, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#intro {
top: 18px;
left: 18px;
width: min(430px, calc(100vw - 36px));
padding: 17px 18px 15px;
border-radius: 17px;
}
h1 {
margin: 0 0 7px;
font-size: clamp(18px, 2.2vw, 25px);
line-height: 1.12;
letter-spacing: -0.035em;
}
#intro p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 13px;
}
.legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 9px;
border-radius: 999px;
background: rgba(244, 248, 247, 0.9);
color: #40565f;
font-size: 11px;
font-weight: 650;
white-space: nowrap;
}
.dot {
width: 9px;
height: 9px;
border-radius: 50%;
}
.dot.ground {
background: var(--ground);
}
.dot.overhead {
background: var(--overhead);
}
.dot.sweep {
background: var(--sweep);
}
#notice {
position: fixed;
z-index: 5;
left: 18px;
bottom: 18px;
width: min(430px, calc(100vw - 36px));
padding: 13px 15px;
border-left: 4px solid var(--sweep);
border-radius: 12px;
background: rgba(255, 255, 255, 0.93);
color: #52666f;
font-size: 12px;
line-height: 1.45;
box-shadow: 0 9px 28px rgba(41, 63, 70, 0.1);
}
#notice strong {
color: #263c45;
}
#controls {
right: 18px;
bottom: 18px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 14px;
}
button {
appearance: none;
border: 1px solid rgba(35, 62, 73, 0.15);
border-radius: 10px;
padding: 9px 12px;
background: #f8fbfa;
color: #29414b;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #eef5f3;
border-color: rgba(35, 62, 73, 0.25);
}
button:focus-visible {
outline: 3px solid rgba(37, 131, 163, 0.28);
outline-offset: 2px;
}
#camera-hint {
position: fixed;
top: 18px;
right: 18px;
z-index: 4;
padding: 9px 12px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.76);
color: #647981;
font-size: 11px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#labels {
position: fixed;
inset: 0;
z-index: 3;
overflow: hidden;
pointer-events: none;
}
.tag {
position: absolute;
top: 0;
left: 0;
min-width: 120px;
padding: 8px 10px;
border: 1px solid rgba(35, 62, 73, 0.13);
border-left-width: 4px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.94);
box-shadow: 0 6px 18px rgba(34, 55, 63, 0.13);
color: #273d46;
font-size: 11px;
line-height: 1.25;
text-align: left;
transform: translate(-50%, -50%);
will-change: transform;
}
.tag strong {
display: block;
margin-bottom: 2px;
font-size: 11px;
}
.tag small {
color: #6a7c83;
font-size: 10px;
}
.tag.ground {
border-left-color: var(--ground);
}
.tag.overhead {
border-left-color: var(--overhead);
}
.tag.sweep {
border-left-color: var(--sweep);
}
.tag.measure {
min-width: auto;
padding: 5px 8px;
border: 0;
border-radius: 999px;
background: rgba(43, 61, 70, 0.86);
color: white;
box-shadow: none;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.03em;
}
.hidden {
display: none !important;
}
@media (max-width: 720px) {
#intro {
top: 10px;
left: 10px;
width: calc(100vw - 20px);
padding: 13px 14px;
}
#intro p {
font-size: 11px;
}
.legend {
gap: 5px;
margin-top: 9px;
}
.legend-item {
padding: 5px 7px;
font-size: 9px;
}
#camera-hint {
display: none;
}
#notice {
left: 10px;
bottom: 68px;
width: calc(100vw - 20px);
font-size: 10px;
}
#controls {
right: 10px;
bottom: 10px;
}
button {
padding: 8px 10px;
font-size: 10px;
}
.tag {
min-width: 100px;
padding: 6px 8px;
}
.tag strong {
font-size: 10px;
}
.tag small {
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Stylized scene showing a white cane sweeping beside a low ground obstacle and a separate overhanging obstacle."
></canvas>
<div id="labels"></div>
<section id="intro" class="panel">
<h1>White cane sweep: different hazard heights</h1>
<p>
The cane arc is confined to the walking surface. A separate head-height
obstacle is shown in another height band so it is not represented as
cane-detectable.
</p>
<div class="legend" aria-label="Scene legend">
<span class="legend-item">
<span class="dot ground"></span>
Ground-level obstacle
</span>
<span class="legend-item">
<span class="dot overhead"></span>
Overhanging obstacle
</span>
<span class="legend-item">
<span class="dot sweep"></span>
Surface-level sweep
</span>
</div>
</section>
<div id="camera-hint">Drag to orbit · Scroll to zoom · Space to pause</div>
<aside id="notice">
<strong>Illustration, not a detection guarantee.</strong>
A white cane may help identify some ground-level obstacles, but it cannot be
assumed to identify every low, overhead, moving, or head-height hazard.
Other awareness, aids, or assistance may be needed.
</aside>
<nav id="controls" class="panel" aria-label="Scene controls">
<button id="sweep-button" type="button">Pause sweep</button>
<button id="labels-button" type="button">Hide labels</button>
<button id="reset-button" type="button">Reset view</button>
</nav>
<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.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const sweepButton = document.querySelector("#sweep-button");
const labelsButton = document.querySelector("#labels-button");
const resetButton = document.querySelector("#reset-button");
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, false);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.setClearColor(0xe8f0ee, 1);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe8f0ee, 12, 26);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xf9fffd, 0x738b83, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff5df, 2.5);
sun.position.set(-4, 9, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 25;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0xb8d9ee, 0.85);
rimLight.position.set(5, 4, -6);
scene.add(rimLight);
const palette = {
grass: new THREE.MeshStandardMaterial({
color: 0x9eb7a3,
roughness: 0.96
}),
path: new THREE.MeshStandardMaterial({
color: 0xe9dfcb,
roughness: 0.92
}),
pathEdge: new THREE.MeshStandardMaterial({
color: 0xcfbea1,
roughness: 0.9
}),
groundHazard: new THREE.MeshStandardMaterial({
color: 0xe76f51,
roughness: 0.72
}),
groundTop: new THREE.MeshStandardMaterial({
color: 0xf49a7f,
roughness: 0.78
}),
overhead: new THREE.MeshStandardMaterial({
color: 0x7558d6,
roughness: 0.68
}),
overheadDark: new THREE.MeshStandardMaterial({
color: 0x563aa9,
roughness: 0.72
}),
sweep: new THREE.MeshStandardMaterial({
color: 0x2583a3,
roughness: 0.74
}),
shirt: new THREE.MeshStandardMaterial({
color: 0x3f7e91,
roughness: 0.8
}),
pants: new THREE.MeshStandardMaterial({
color: 0x304451,
roughness: 0.86
}),
skin: new THREE.MeshStandardMaterial({
color: 0xdca47e,
roughness: 0.82
}),
hair: new THREE.MeshStandardMaterial({
color: 0x43352f,
roughness: 0.95
}),
cane: new THREE.MeshStandardMaterial({
color: 0xf8fbfb,
roughness: 0.42
}),
red: new THREE.MeshStandardMaterial({
color: 0xd9473f,
roughness: 0.6
}),
white: new THREE.MeshStandardMaterial({
color: 0xf7f4e9,
roughness: 0.85
}),
dark: new THREE.MeshStandardMaterial({
color: 0x293940,
roughness: 0.72
}),
green: new THREE.MeshStandardMaterial({
color: 0x5e9573,
roughness: 0.95
}),
greenLight: new THREE.MeshStandardMaterial({
color: 0x78a984,
roughness: 0.95
}),
trunk: new THREE.MeshStandardMaterial({
color: 0x886b50,
roughness: 0.96
}),
buildingA: new THREE.MeshStandardMaterial({
color: 0xc7d8d5,
roughness: 0.9
}),
buildingB: new THREE.MeshStandardMaterial({
color: 0xe1c6b7,
roughness: 0.9
}),
window: new THREE.MeshStandardMaterial({
color: 0x6f99a5,
roughness: 0.45,
metalness: 0.06
})
};
function addMesh(geometry, material, position, parent = scene) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = scene) {
return addMesh(
new THREE.BoxGeometry(w, h, d),
material,
[x, y, z],
parent
);
}
function cylinderBetween(a, b, radius, material, parent = scene, segments = 12) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, segments),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Landscape and sidewalk.
const ground = addMesh(
new THREE.PlaneGeometry(28, 18),
palette.grass,
[0, -0.09, 0]
);
ground.rotation.x = -Math.PI / 2;
ground.castShadow = false;
addBox(11.5, 0.09, 3.25, palette.path, -0.15, -0.045, 0);
addBox(11.5, 0.11, 0.12, palette.pathEdge, -0.15, -0.035, 1.67);
addBox(11.5, 0.11, 0.12, palette.pathEdge, -0.15, -0.035, -1.67);
// Sparse decorative paving joints.
for (let x = -5; x <= 5; x += 1.25) {
addBox(0.018, 0.012, 3.0, palette.pathEdge, x, 0.008, 0);
}
// Background buildings.
addBox(4.0, 3.7, 1.5, palette.buildingA, -1.1, 1.82, -4.05);
addBox(3.3, 2.6, 1.4, palette.buildingB, 3.1, 1.27, -4.1);
for (let x = -2.5; x <= 0.5; x += 0.9) {
addBox(0.45, 0.65, 0.035, palette.window, x, 2.05, -3.275);
}
for (let x = 1.8; x <= 4.3; x += 0.82) {
addBox(0.42, 0.58, 0.035, palette.window, x, 1.52, -3.375);
}
// Decorative trees and shrubs outside the walking surface.
function addTree(x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
cylinderBetween(
[0, 0, 0],
[0, 1.75, 0],
0.13,
palette.trunk,
group
);
addMesh(
new THREE.SphereGeometry(0.62, 18, 14),
palette.green,
[0, 1.95, 0],
group
);
addMesh(
new THREE.SphereGeometry(0.43, 16, 12),
palette.greenLight,
[0.33, 2.22, 0.05],
group
);
}
addTree(-4.25, 2.7, 1.0);
addTree(4.35, 2.9, 0.85);
addMesh(
new THREE.SphereGeometry(0.52, 16, 12),
palette.green,
[3.2, 0.42, 2.6]
);
// A low ground-level obstacle, placed beside the cane sweep.
const step = addBox(
0.58,
0.12,
0.82,
palette.groundHazard,
0.18,
0.06,
0.39
);
addBox(
0.58,
0.025,
0.82,
palette.groundTop,
0.18,
0.132,
0.39
);
// A smaller raised surface patch gives a second ground-level example.
addBox(
0.52,
0.045,
0.42,
palette.groundHazard,
-0.08,
0.0225,
-0.48
);
// Overhanging obstacle. Its lower edge is at 1.90 m.
const overheadGroup = new THREE.Group();
overheadGroup.position.x = 1.35;
scene.add(overheadGroup);
cylinderBetween(
[0, 0, -1.48],
[0, 1.9, -1.48],
0.055,
palette.overheadDark,
overheadGroup
);
cylinderBetween(
[0, 0, 1.48],
[0, 1.9, 1.48],
0.055,
palette.overheadDark,
overheadGroup
);
addBox(
0.62,
0.22,
3.2,
palette.overhead,
0,
2.01,
0,
overheadGroup
);
// Contrasting lower edge makes the actual hazard height clear.
addBox(
0.66,
0.045,
3.2,
palette.overheadDark,
0,
1.923,
0,
overheadGroup
);
// Stylized human figure, facing +X.
const person = new THREE.Group();
person.position.set(-2.05, 0, 0);
scene.add(person);
// Legs.
cylinderBetween(
[-0.03, 0.2, -0.13],
[0, 0.79, -0.13],
0.105,
palette.pants,
person
);
cylinderBetween(
[-0.03, 0.2, 0.13],
[0, 0.79, 0.13],
0.105,
palette.pants,
person
);
addBox(0.34, 0.13, 0.19, palette.dark, 0.08, 0.075, -0.13, person);
addBox(0.34, 0.13, 0.19, palette.dark, 0.08, 0.075, 0.13, person);
// Torso.
addBox(0.38, 0.66, 0.55, palette.shirt, 0, 1.08, 0, person);
// Neck and head.
cylinderBetween(
[0, 1.37, 0],
[0, 1.49, 0],
0.075,
palette.skin,
person
);
addMesh(
new THREE.SphereGeometry(0.205, 22, 16),
palette.skin,
[0.015, 1.62, 0],
person
);
addMesh(
new THREE.SphereGeometry(0.207, 22, 16, 0, Math.PI * 2, 0, Math.PI * 0.46),
palette.hair,
[-0.025, 1.63, 0],
person
);
// Nose indicates the direction of travel.
addMesh(
new THREE.SphereGeometry(0.045, 12, 8),
palette.skin,
[0.205, 1.61, 0],
person
);
// Rear arm.
cylinderBetween(
[0.06, 1.31, -0.25],
[0.29, 0.98, -0.29],
0.065,
palette.shirt,
person
);
addMesh(
new THREE.SphereGeometry(0.073, 12, 10),
palette.skin,
[0.29, 0.96, -0.29],
person
);
// Front arm reaches the cane grip.
cylinderBetween(
[0.06, 1.31, 0.25],
[0.66, 1.15, 0.14],
0.066,
palette.shirt,
person
);
addMesh(
new THREE.SphereGeometry(0.071, 12, 10),
palette.skin,
[0.68, 1.145, 0.135],
person
);
// White cane pivot at the hand.
const canePivot = new THREE.Group();
canePivot.position.set(-1.36, 1.15, 0.135);
scene.add(canePivot);
const caneStart = new THREE.Vector3(0, 0, 0);
const caneEnd = new THREE.Vector3(0.98, -1.105, 0);
cylinderBetween(
caneStart.toArray(),
caneEnd.toArray(),
0.018,
palette.cane,
canePivot,
14
);
// Rounded white cane tip.
const caneTip = addMesh(
new THREE.SphereGeometry(0.034, 12, 8),
palette.cane,
caneEnd.toArray(),
canePivot
);
// Red reflective band near the lower end.
const bandA = caneStart.clone().lerp(caneEnd, 0.78);
const bandB = caneStart.clone().lerp(caneEnd, 0.855);
cylinderBetween(
bandA.toArray(),
bandB.toArray(),
0.024,
palette.red,
canePivot,
14
);
// Short ergonomic handle.
cylinderBetween(
[-0.13, 0.005, 0],
[0.015, 0.005, 0],
0.028,
palette.dark,
canePivot,
12
);
// Surface-level sweep trail.
const trailPoints = [];
const sweepCenter = -0.045;
const sweepAmplitude = 0.305;
for (let i = 0; i <= 64; i++) {
const t = i / 64;
const angle = sweepCenter + Math.sin((t - 0.5) * Math.PI * 2) * sweepAmplitude;
trailPoints.push(
new THREE.Vector3(
canePivot.position.x + 0.98 * Math.cos(angle),
0.018,
canePivot.position.z - 0.98 * Math.sin(angle)
)
);
}
const trailGeometry = new THREE.BufferGeometry().setFromPoints(trailPoints);
const trailMaterial = new THREE.LineDashedMaterial({
color: 0x2583a3,
dashSize: 0.09,
gapSize: 0.065,
transparent: true,
opacity: 0.86
});
const trail = new THREE.Line(trailGeometry, trailMaterial);
trail.computeLineDistances();
scene.add(trail);
// Small ground-level contact cue under the cane path.
const arcDisk = addMesh(
new THREE.CircleGeometry(0.065, 18),
new THREE.MeshBasicMaterial({
color: 0x2583a3,
transparent: true,
opacity: 0.48,
depthWrite: false
}),
[
canePivot.position.x + 0.98 * Math.cos(sweepCenter),
0.022,
canePivot.position.z - 0.98 * Math.sin(sweepCenter)
]
);
arcDisk.rotation.x = -Math.PI / 2;
arcDisk.castShadow = false;
// Height-measurement lines.
function addVerticalDimension(x, z, y0, y1, color) {
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.055,
gapSize: 0.045,
transparent: true,
opacity: 0.8
});
const points = [
new THREE.Vector3(x, y0, z),
new THREE.Vector3(x, y1, z),
new THREE.Vector3(x - 0.13, y0, z),
new THREE.Vector3(x + 0.13, y0, z),
new THREE.Vector3(x - 0.13, y1, z),
new THREE.Vector3(x + 0.13, y1, z)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lines = new THREE.LineSegments(geometry, material);
lines.computeLineDistances();
scene.add(lines);
}
addVerticalDimension(0.68, 0.72, 0, 0.12, 0xe76f51);
addVerticalDimension(1.83, 1.28, 0, 1.9, 0x7558d6);
// DOM labels projected from 3D anchors.
const labels = [];
function addLabel(title, detail, position, type = "", measurement = false) {
const element = document.createElement("div");
element.className = `tag ${type} ${measurement ? "measure" : ""}`;
element.innerHTML = measurement
? detail
: `<strong>${title}</strong><small>${detail}</small>`;
labelLayer.appendChild(element);
labels.push({
element,
position: new THREE.Vector3(...position)
});
}
addLabel(
"Ground-level obstacle",
"12 cm step · beside the sweep",
[0.18, 0.43, 0.4],
"ground"
);
addLabel(
"Overhanging obstacle",
"1.90 m lower edge · outside cane reach",
[1.35, 2.28, 0],
"overhead"
);
addLabel(
"Cane sweep",
"Surface-level arc only",
[-0.68, 0.14, 0.48],
"sweep"
);
addLabel("", "12 cm", [0.68, 0.17, 0.72], "", true);
addLabel("", "1.90 m", [1.83, 1.05, 1.28], "", true);
// Camera controls implemented directly, without an addon.
const defaultView = {
radius: 7.8,
theta: 0.73,
phi: 1.13,
target: new THREE.Vector3(-0.25, 0.83, 0)
};
const view = {
radius: defaultView.radius,
theta: defaultView.theta,
phi: defaultView.phi,
target: defaultView.target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
const cosPhi = Math.cos(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.cos(view.theta),
view.target.y + view.radius * cosPhi,
view.target.z + view.radius * sinPhi * Math.sin(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
view.radius = defaultView.radius;
view.theta = defaultView.theta;
view.phi = defaultView.phi;
view.target.copy(defaultView.target);
updateCamera();
}
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.classList.add("dragging");
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
view.theta -= dx * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + dy * 0.005,
0.38,
1.43
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.006,
4.2,
13
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
let sweepPlaying = true;
let labelsVisible = true;
function setSweepPlaying(playing) {
sweepPlaying = playing;
sweepButton.textContent = playing ? "Pause sweep" : "Play sweep";
sweepButton.setAttribute("aria-pressed", String(!playing));
}
sweepButton.addEventListener("click", () => {
setSweepPlaying(!sweepPlaying);
});
labelsButton.addEventListener("click", () => {
labelsVisible = !labelsVisible;
labelLayer.classList.toggle("hidden", !labelsVisible);
labelsButton.textContent = labelsVisible ? "Hide labels" : "Show labels";
});
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.code === "Space" && event.target === document.body) {
event.preventDefault();
setSweepPlaying(!sweepPlaying);
}
if (event.key.toLowerCase() === "r") {
resetView();
}
});
const projected = new THREE.Vector3();
function updateLabels() {
if (!labelsVisible) return;
for (const label of labels) {
projected.copy(label.position).project(camera);
const inFront = projected.z > -1 && projected.z < 1;
const onScreen =
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.display = inFront && onScreen ? "block" : "none";
if (!inFront || !onScreen) continue;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height, false);
}
window.addEventListener("resize", resize);
updateCamera();
resize();
const clock = new THREE.Clock();
function render() {
requestAnimationFrame(render);
const elapsed = clock.getElapsedTime();
if (sweepPlaying) {
const angle = sweepCenter + Math.sin(elapsed * 2.15) * sweepAmplitude;
canePivot.rotation.y = angle;
const tipX = canePivot.position.x + 0.98 * Math.cos(angle);
const tipZ = canePivot.position.z - 0.98 * Math.sin(angle);
arcDisk.position.x = tipX;
arcDisk.position.z = tipZ;
// Very small body movement suggests walking without distracting
// from the simplified cane demonstration.
person.position.y = 0.007 * Math.sin(elapsed * 4.3);
}
updateLabels();
renderer.render(scene, camera);
}
render();
</script>
</body>
</html>
```