Prompt specification
Build or customize the Three.js 3D scene "Two markers and a straight ruler" 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 markers and a straight ruler
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/two-markers-and-a-straight-ruler-x1297
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts straight-line and obstacle-avoiding route distances. Place two destination markers on opposite sides of a curved wall. Draw a direct distance ruler and a separate valid walking path around the obstacle. Stylized solid forms.
Working Three.js Starter (two-markers-and-a-straight-ruler-x1297):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Straight-Line vs. Obstacle-Avoiding Route</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9ede7;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
outline: none;
}
.legend {
position: fixed;
top: 24px;
left: 24px;
width: min(330px, calc(100vw - 48px));
padding: 18px 20px;
border: 1px solid rgba(38, 53, 48, 0.08);
border-radius: 18px;
background: rgba(255, 255, 255, 0.9);
box-shadow: 0 12px 38px rgba(42, 56, 50, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
z-index: 10;
}
.eyebrow {
margin-bottom: 7px;
color: #77817c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.title {
margin-bottom: 15px;
color: #24312d;
font-size: 20px;
font-weight: 750;
line-height: 1.2;
}
.legend-row {
display: grid;
grid-template-columns: 28px 1fr auto;
align-items: center;
gap: 9px;
margin-top: 9px;
color: #43514c;
font-size: 13px;
}
.legend-row strong {
color: #24312d;
font-size: 13px;
}
.swatch {
display: block;
width: 27px;
height: 0;
border-top: 4px solid;
}
.swatch.direct {
border-color: #f05d4f;
border-top-style: dashed;
}
.swatch.walk {
border-color: #0b9f89;
}
.summary {
display: flex;
justify-content: space-between;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid #e5e9e4;
color: #68746f;
font-size: 12px;
}
.summary strong {
color: #f05d4f;
}
.controls {
position: fixed;
right: 22px;
bottom: 20px;
padding: 9px 13px;
border-radius: 999px;
color: #53615c;
background: rgba(255, 255, 255, 0.86);
box-shadow: 0 6px 20px rgba(42, 56, 50, 0.1);
font-size: 11px;
pointer-events: none;
z-index: 10;
}
.scene-label {
position: fixed;
left: 0;
top: 0;
transform: translate(-50%, -50%);
padding: 7px 11px;
border: 1px solid rgba(36, 49, 45, 0.08);
border-radius: 999px;
color: #26332f;
background: rgba(255, 255, 255, 0.93);
box-shadow: 0 6px 20px rgba(42, 56, 50, 0.13);
font-size: 11px;
font-weight: 750;
letter-spacing: 0.02em;
white-space: nowrap;
pointer-events: none;
z-index: 8;
}
.scene-label.direct {
border-left: 4px solid #f05d4f;
}
.scene-label.walk {
border-left: 4px solid #0b9f89;
}
.scene-label.wall {
color: #7c582f;
background: rgba(255, 248, 235, 0.94);
}
.pin-label {
display: grid;
width: 30px;
height: 30px;
place-items: center;
padding: 0;
border-radius: 50%;
color: white;
font-size: 13px;
font-weight: 850;
}
#label-a {
background: #f05d4f;
}
#label-b {
background: #416fe8;
}
@media (max-width: 640px) {
.legend {
top: 14px;
left: 14px;
padding: 14px 16px;
}
.title {
font-size: 17px;
}
.controls {
right: 14px;
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section class="legend">
<div class="eyebrow">Route comparison</div>
<div class="title">Same destination, two possible routes</div>
<div class="legend-row">
<span class="swatch direct"></span>
<span>Straight-line ruler</span>
<strong id="direct-value">—</strong>
</div>
<div class="legend-row">
<span class="swatch walk"></span>
<span>Valid walking path</span>
<strong id="walk-value">—</strong>
</div>
<div class="summary">
<span>Extra distance from the wall</span>
<strong id="detour-value">—</strong>
</div>
</section>
<div class="controls">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div id="label-direct" class="scene-label direct">DIRECT</div>
<div id="label-walk" class="scene-label walk">WALK AROUND</div>
<div id="label-wall" class="scene-label wall">CURVED WALL</div>
<div id="label-a" class="scene-label pin-label">A</div>
<div id="label-b" class="scene-label pin-label">B</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9ede7);
scene.fog = new THREE.Fog(0xe9ede7, 28, 52);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
container.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of a direct route and an obstacle-avoiding walking path"
);
// Lighting
scene.add(new THREE.HemisphereLight(0xf8fbff, 0xb6b0a1, 2.25));
const keyLight = new THREE.DirectionalLight(0xfff5e8, 3.4);
keyLight.position.set(6, 13, -9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -16;
keyLight.shadow.camera.right = 16;
keyLight.shadow.camera.top = 16;
keyLight.shadow.camera.bottom = -16;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d8ff, 1.15);
fillLight.position.set(-9, 7, 10);
scene.add(fillLight);
// Stylized platform
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xf1efe7,
roughness: 0.93,
metalness: 0
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(11.45, 11.45, 0.34, 96),
floorMaterial
);
platform.position.y = -0.17;
platform.receiveShadow = true;
scene.add(platform);
const platformBase = new THREE.Mesh(
new THREE.CylinderGeometry(11.7, 11.8, 0.18, 96),
new THREE.MeshStandardMaterial({
color: 0xd6dbd2,
roughness: 0.9
})
);
platformBase.position.y = -0.39;
platformBase.receiveShadow = true;
scene.add(platformBase);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe9ede7,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.5;
ground.receiveShadow = true;
scene.add(ground);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(10.75, 0.025, 8, 128),
new THREE.MeshStandardMaterial({
color: 0xd3d8ce,
roughness: 0.8
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = 0.018;
scene.add(platformRing);
// Destination positions, on opposite sides of the curved wall.
const pointA = new THREE.Vector3(0, 0.16, -4.65);
const pointB = new THREE.Vector3(0, 0.16, 6.25);
// Curved annular-sector wall.
// Shape coordinates are rotated so the wall stands upright in world space.
const outerRadius = 5.15;
const innerRadius = 4.35;
const wallHeight = 3.2;
const startShapeAngle = THREE.MathUtils.degToRad(-140);
const endShapeAngle = THREE.MathUtils.degToRad(-40);
const wallShape = new THREE.Shape();
wallShape.absarc(
0,
0,
outerRadius,
startShapeAngle,
endShapeAngle,
false
);
wallShape.lineTo(
Math.cos(endShapeAngle) * innerRadius,
Math.sin(endShapeAngle) * innerRadius
);
wallShape.absarc(
0,
0,
innerRadius,
endShapeAngle,
startShapeAngle,
true
);
wallShape.closePath();
const wallGeometry = new THREE.ExtrudeGeometry(wallShape, {
depth: wallHeight,
bevelEnabled: true,
bevelThickness: 0.1,
bevelSize: 0.1,
bevelSegments: 3,
curveSegments: 96
});
wallGeometry.rotateX(-Math.PI / 2);
const wall = new THREE.Mesh(
wallGeometry,
new THREE.MeshStandardMaterial({
color: 0xd89252,
roughness: 0.72,
metalness: 0
})
);
wall.castShadow = true;
wall.receiveShadow = true;
scene.add(wall);
// Thin trim along the outer top edge.
const topTrimPoints = [];
for (let angle = 40; angle <= 140; angle += 2) {
const radians = THREE.MathUtils.degToRad(angle);
topTrimPoints.push(
new THREE.Vector3(
Math.cos(radians) * outerRadius,
wallHeight + 0.06,
Math.sin(radians) * outerRadius
)
);
}
const topTrim = new THREE.Mesh(
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(topTrimPoints),
160,
0.045,
8,
false
),
new THREE.MeshStandardMaterial({
color: 0xb86f35,
roughness: 0.65
})
);
topTrim.castShadow = true;
scene.add(topTrim);
// Destination marker construction
const markerHalos = [];
function createMarker(position, color, phase) {
const group = new THREE.Group();
group.position.copy(position);
group.position.y = 0;
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.48,
metalness: 0.03
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.46, 0.5, 0.14, 36),
material
);
base.position.y = 0.09;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.075, 0.09, 1.35, 20),
material
);
stem.position.y = 0.82;
stem.castShadow = true;
group.add(stem);
const top = new THREE.Mesh(
new THREE.SphereGeometry(0.23, 28, 20),
material
);
top.position.y = 1.59;
top.castShadow = true;
group.add(top);
const haloMaterial = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.42,
depthWrite: false
});
const halo = new THREE.Mesh(
new THREE.RingGeometry(0.57, 0.63, 64),
haloMaterial
);
halo.rotation.x = -Math.PI / 2;
halo.position.y = 0.025;
group.add(halo);
markerHalos.push({ mesh: halo, phase });
scene.add(group);
}
createMarker(pointA, 0xf05d4f, 0);
createMarker(pointB, 0x416fe8, Math.PI);
// Straight-line ruler
const directDirection = pointB.clone().sub(pointA).normalize();
const directLength = pointA.distanceTo(pointB);
const directMaterial = new THREE.MeshBasicMaterial({
color: 0xf05d4f,
depthTest: false,
depthWrite: false
});
const directLineGeometry = new THREE.BufferGeometry().setFromPoints([
pointA,
pointB
]);
const directLine = new THREE.Line(
directLineGeometry,
new THREE.LineDashedMaterial({
color: 0xf05d4f,
dashSize: 0.28,
gapSize: 0.18,
transparent: true,
opacity: 0.88,
depthTest: false,
depthWrite: false
})
);
directLine.computeLineDistances();
directLine.renderOrder = 20;
scene.add(directLine);
function cylinderBetween(start, end, radius, material) {
const midpoint = start.clone().add(end).multiplyScalar(0.5);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 10),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.renderOrder = 20;
return mesh;
}
// Ruler ticks, perpendicular to the direct line.
const perpendicular = new THREE.Vector3(
-directDirection.z,
0,
directDirection.x
).normalize();
for (let distance = 1; distance < directLength; distance += 1) {
const center = pointA.clone().addScaledVector(directDirection, distance);
const halfTick = perpendicular.clone().multiplyScalar(0.22);
const tick = cylinderBetween(
center.clone().sub(halfTick),
center.clone().add(halfTick),
0.025,
directMaterial
);
scene.add(tick);
}
for (const endpoint of [pointA, pointB]) {
const halfCap = perpendicular.clone().multiplyScalar(0.32);
const cap = cylinderBetween(
endpoint.clone().sub(halfCap),
endpoint.clone().add(halfCap),
0.035,
directMaterial
);
scene.add(cap);
}
function createArrow(position, direction, color, size = 1) {
const arrow = new THREE.Mesh(
new THREE.ConeGeometry(0.16 * size, 0.42 * size, 18),
new THREE.MeshStandardMaterial({
color,
roughness: 0.48
})
);
arrow.position.copy(position);
arrow.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
arrow.castShadow = true;
scene.add(arrow);
return arrow;
}
createArrow(
pointA.clone().addScaledVector(directDirection, 0.52),
directDirection,
0xf05d4f,
0.9
);
createArrow(
pointB.clone().addScaledVector(directDirection, -0.52),
directDirection.clone().negate(),
0xf05d4f,
0.9
);
// Valid path: from A, around the left end of the wall, then to B.
const routeRadius = 5.8;
const routeControlPoints = [
new THREE.Vector3(0, 0.13, -4.65),
new THREE.Vector3(-5.9, 0.13, -1.2),
new THREE.Vector3(-5.6, 0.13, 1.8)
];
for (let angle = 140; angle >= 90; angle -= 5) {
const radians = THREE.MathUtils.degToRad(angle);
routeControlPoints.push(
new THREE.Vector3(
Math.cos(radians) * routeRadius,
0.13,
Math.sin(radians) * routeRadius
)
);
}
routeControlPoints.push(new THREE.Vector3(0, 0.13, 6.25));
// Round polyline corners with quadratic Bézier sections.
function roundPolyline(points, trimDistance = 0.38, segments = 10) {
const result = [points[0].clone()];
for (let i = 1; i < points.length - 1; i++) {
const previous = points[i - 1];
const current = points[i];
const next = points[i + 1];
const incoming = current.clone().sub(previous);
const outgoing = next.clone().sub(current);
const incomingLength = incoming.length();
const outgoingLength = outgoing.length();
const trim = Math.min(
trimDistance,
incomingLength * 0.35,
outgoingLength * 0.35
);
const incomingDirection = incoming.normalize();
const outgoingDirection = outgoing.normalize();
const entry = current.clone().addScaledVector(incomingDirection, -trim);
const exit = current.clone().addScaledVector(outgoingDirection, trim);
result.push(entry);
for (let step = 1; step <= segments; step++) {
const t = step / segments;
const inverse = 1 - t;
const point =
entry.clone().multiplyScalar(inverse * inverse)
.addScaledVector(current, 2 * inverse * t)
.addScaledVector(exit, t * t);
result.push(point);
}
}
result.push(points[points.length - 1].clone());
return result;
}
const roundedRoutePoints = roundPolyline(routeControlPoints);
const routeCurve = new THREE.CatmullRomCurve3(
roundedRoutePoints,
false,
"centripetal",
0.5
);
const routeLength = routeCurve.getLength();
// Pale border underneath the teal route.
const routeBorder = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 360, 0.2, 10, false),
new THREE.MeshStandardMaterial({
color: 0xf8f5eb,
roughness: 0.8
})
);
routeBorder.receiveShadow = true;
scene.add(routeBorder);
const route = new THREE.Mesh(
new THREE.TubeGeometry(routeCurve, 360, 0.115, 10, false),
new THREE.MeshStandardMaterial({
color: 0x0b9f89,
roughness: 0.5
})
);
route.castShadow = true;
scene.add(route);
// Direction arrows along the valid route.
for (const fraction of [0.18, 0.36, 0.54, 0.72, 0.9]) {
const position = routeCurve.getPointAt(fraction);
const tangent = routeCurve.getTangentAt(fraction);
position.y = 0.19;
createArrow(position, tangent, 0xf9fff9, 0.86);
}
// DOM labels projected from 3D positions.
const labelDirect = document.getElementById("label-direct");
const labelWalk = document.getElementById("label-walk");
const labelWall = document.getElementById("label-wall");
const labelA = document.getElementById("label-a");
const labelB = document.getElementById("label-b");
labelDirect.textContent = `DIRECT · ${directLength.toFixed(1)} m`;
labelWalk.textContent = `WALK AROUND · ${routeLength.toFixed(1)} m`;
document.getElementById("direct-value").textContent =
`${directLength.toFixed(1)} m`;
document.getElementById("walk-value").textContent =
`${routeLength.toFixed(1)} m`;
document.getElementById("detour-value").textContent =
`+${(routeLength - directLength).toFixed(1)} m`;
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.opacity = visible ? "1" : "0";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
// Direct camera controls, implemented without external control addons.
const orbit = {
theta: 2.48,
phi: 1.14,
radius: 21,
target: new THREE.Vector3(0, 1, 0)
};
const initialOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x +
orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z +
orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetCamera() {
orbit.theta = initialOrbit.theta;
orbit.phi = initialOrbit.phi;
orbit.radius = initialOrbit.radius;
orbit.target.copy(initialOrbit.target);
}
const pointer = {
active: false,
id: null,
lastX: 0,
lastY: 0,
mode: "orbit"
};
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.mode =
event.button === 2 || event.shiftKey ? "pan" : "orbit";
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) return;
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
if (pointer.mode === "pan") {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.setY(0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1)
.setY(0)
.normalize();
const panScale = orbit.radius * 0.0014;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(up, dy * panScale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi -= dy * 0.005;
orbit.phi = THREE.MathUtils.clamp(orbit.phi, 0.36, 1.46);
}
});
function endPointer(event) {
if (event.pointerId !== pointer.id) return;
pointer.active = false;
pointer.id = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius *= Math.exp(event.deltaY * 0.001);
orbit.radius = THREE.MathUtils.clamp(orbit.radius, 10, 34);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
for (const halo of markerHalos) {
const pulse = 1 + Math.sin(elapsed * 2.4 + halo.phase) * 0.07;
halo.mesh.scale.setScalar(pulse);
halo.mesh.material.opacity = 0.34 + Math.sin(elapsed * 2.4 + halo.phase) * 0.1;
}
updateCamera();
positionLabel(
labelDirect,
new THREE.Vector3(1.55, 0.45, -2.65)
);
positionLabel(
labelWalk,
new THREE.Vector3(-6.15, 0.48, 0.25)
);
positionLabel(
labelWall,
new THREE.Vector3(0.15, 3.75, 4.75)
);
positionLabel(
labelA,
new THREE.Vector3(0, 2.05, -4.65)
);
positionLabel(
labelB,
new THREE.Vector3(0, 2.05, 6.25)
);
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```