Prompt specification
Build or customize the Three.js 3D scene "Block and Coarse Measurement 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: Block and Coarse Measurement Ruler
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/block-and-coarse-measurement-ruler-x2045
Scene Description Prompt:
Please make a cutaway Three.js scene in one standalone HTML file using cdnjs. Model a dimensioned block beside a ruler with deliberately coarse ticks. Show the known model length separately from the value readable at the ruler's resolution.
Working Three.js Starter (block-and-coarse-measurement-ruler-x2045):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cutaway Dimension Study</title>
<style>
:root {
color-scheme: dark;
--exact: #53d8fb;
--ruler: #ffbd59;
--panel: rgba(10, 18, 27, 0.86);
--border: rgba(148, 178, 202, 0.22);
--muted: #91a7b8;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091019;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
}
#title {
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px 17px;
border-radius: 16px;
}
.eyebrow {
margin: 0 0 7px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 3vw, 28px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: #a9bbc8;
font-size: 13px;
line-height: 1.45;
}
#readout {
left: 22px;
bottom: 22px;
width: min(390px, calc(100vw - 44px));
padding: 18px 20px;
border-radius: 16px;
}
.value-row {
display: grid;
grid-template-columns: 1fr auto;
gap: 18px;
align-items: baseline;
padding: 12px 0;
border-top: 1px solid rgba(148, 178, 202, 0.13);
}
.value-row:first-of-type {
border-top: 0;
padding-top: 2px;
}
.value-label {
color: #b7c6d1;
font-size: 12px;
line-height: 1.35;
}
.value-label small {
display: block;
margin-top: 3px;
color: #718797;
font-size: 10px;
}
.value {
font-size: 27px;
font-weight: 800;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.exact {
color: var(--exact);
}
.ruler {
color: var(--ruler);
}
.resolution-note {
margin: 8px 0 0;
padding-top: 11px;
border-top: 1px solid rgba(148, 178, 202, 0.13);
color: #8499a8;
font-size: 11px;
line-height: 1.5;
}
.resolution-note strong {
color: #d8e1e7;
font-weight: 700;
}
.legend {
display: flex;
gap: 16px;
margin-top: 13px;
color: #9aafbd;
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
}
#help {
right: 22px;
bottom: 22px;
padding: 10px 13px;
border-radius: 12px;
color: #9eb1c0;
font-size: 11px;
}
#reset {
position: fixed;
z-index: 12;
top: 22px;
right: 22px;
padding: 10px 14px;
border: 1px solid var(--border);
border-radius: 11px;
color: #dce7ee;
background: var(--panel);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(12px);
}
#reset:hover {
border-color: rgba(83, 216, 251, 0.55);
color: white;
}
#loading {
position: fixed;
inset: 0;
z-index: 30;
display: grid;
place-items: center;
color: #a9c0d1;
background: #091019;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
#title {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
#readout {
left: 14px;
bottom: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
#help {
display: none;
}
#reset {
top: auto;
right: 14px;
bottom: 205px;
}
.subtitle {
display: none;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="title" class="panel">
<p class="eyebrow">Cutaway / Scale Study</p>
<h1>Same part, two resolutions</h1>
<p class="subtitle">
The exact digital dimension is compared with a deliberately coarse,
half-metre ruler.
</p>
</section>
<section id="readout" class="panel" aria-live="polite">
<p class="eyebrow">Dimension Readout</p>
<div class="value-row">
<div class="value-label">
Known model length
<small>Exact digital dimension</small>
</div>
<div class="value exact">1.60 m</div>
</div>
<div class="value-row">
<div class="value-label">
Readable at ruler resolution
<small>Nearest labelled 0.50 m tick</small>
</div>
<div class="value ruler">1.50 m</div>
</div>
<p class="resolution-note">
The endpoint falls between <strong>1.50 m</strong> and
<strong>2.00 m</strong>. With 0.50 m ticks, the nearest readable value is
<strong>1.50 m</strong>, a difference of <strong>0.10 m</strong>.
</p>
<div class="legend">
<span><i class="dot" style="background:var(--exact)"></i>Known length</span>
<span><i class="dot" style="background:var(--ruler)"></i>Ruler readout</span>
</div>
</section>
<button id="reset" type="button">Reset view</button>
<div id="help" class="panel">Drag to orbit · Scroll to zoom</div>
<div id="loading">Loading Three.js…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const container = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091019);
scene.fog = new THREE.Fog(0x091019, 7, 13);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
50
);
const target = new THREE.Vector3(-0.08, 0.32, 0.43);
const initialOrbit = {
theta: 0.48,
phi: 1.03,
radius: 4.85
};
const orbit = {
theta: initialOrbit.theta,
phi: initialOrbit.phi,
radius: initialOrbit.radius,
goalTheta: initialOrbit.theta,
goalPhi: initialOrbit.phi,
goalRadius: initialOrbit.radius
};
function applyCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
applyCamera();
// ---------------------------------------------------------------------
// Direct camera controls: no OrbitControls or other addons.
// ---------------------------------------------------------------------
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.goalTheta -= dx * 0.006;
orbit.goalPhi = THREE.MathUtils.clamp(
orbit.goalPhi - dy * 0.005,
0.28,
1.43
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (
event &&
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener("lostpointercapture", () => {
dragging = false;
renderer.domElement.style.cursor = "grab";
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.goalRadius = THREE.MathUtils.clamp(
orbit.goalRadius * Math.exp(event.deltaY * 0.001),
3.1,
8.5
);
},
{ passive: false }
);
renderer.domElement.style.cursor = "grab";
document.querySelector("#reset").addEventListener("click", () => {
orbit.goalTheta = initialOrbit.theta;
orbit.goalPhi = initialOrbit.phi;
orbit.goalRadius = initialOrbit.radius;
});
// ---------------------------------------------------------------------
// Lighting and ground
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xb8d9ee, 0x18212c, 1.65));
const key = new THREE.DirectionalLight(0xffffff, 3.2);
key.position.set(3.5, 6, 4.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -4;
key.shadow.camera.right = 4;
key.shadow.camera.top = 4;
key.shadow.camera.bottom = -4;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 15;
key.shadow.bias = -0.0003;
scene.add(key);
const rim = new THREE.DirectionalLight(0x53d8fb, 1.7);
rim.position.set(-4, 2.5, -3);
scene.add(rim);
const warmFill = new THREE.PointLight(0xff9a52, 14, 6, 2);
warmFill.position.set(-2.5, 1.1, 2.3);
scene.add(warmFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x0c151f,
roughness: 0.92,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(12, 24, 0x375064, 0x1a2b39);
grid.position.y = -0.006;
grid.material.transparent = true;
grid.material.opacity = 0.23;
scene.add(grid);
// ---------------------------------------------------------------------
// Materials and geometry helpers
// ---------------------------------------------------------------------
const materials = {
shell: new THREE.MeshStandardMaterial({
color: 0x91a8ba,
roughness: 0.32,
metalness: 0.62
}),
darkShell: new THREE.MeshStandardMaterial({
color: 0x344653,
roughness: 0.42,
metalness: 0.7
}),
cut: new THREE.MeshStandardMaterial({
color: 0xff713d,
roughness: 0.38,
metalness: 0.2,
emissive: 0x421207,
emissiveIntensity: 0.45
}),
exact: new THREE.MeshBasicMaterial({
color: 0x53d8fb
}),
ruler: new THREE.MeshBasicMaterial({
color: 0xffbd59
}),
board: new THREE.MeshStandardMaterial({
color: 0x17675a,
roughness: 0.58,
metalness: 0.12
}),
chip: new THREE.MeshStandardMaterial({
color: 0x111b25,
roughness: 0.5,
metalness: 0.35
}),
copper: new THREE.MeshStandardMaterial({
color: 0xd97838,
roughness: 0.28,
metalness: 0.82
}),
ivory: new THREE.MeshStandardMaterial({
color: 0xf0e9d7,
roughness: 0.72,
metalness: 0.02
}),
ink: new THREE.MeshBasicMaterial({
color: 0x17212a
})
};
function addBox(width, height, depth, material, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addEdges(mesh, color = 0x263745, opacity = 0.65) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edges.renderOrder = 2;
mesh.add(edges);
return edges;
}
// ---------------------------------------------------------------------
// Canvas-texture labels; these are still rendered with Three.js core.
// ---------------------------------------------------------------------
function roundedRectPath(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
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 makeLabel(
lines,
{
width = 1.6,
color = "#53d8fb",
background = "rgba(7, 17, 27, 0.90)",
border = "rgba(83, 216, 251, 0.72)"
} = {}
) {
const textLines = Array.isArray(lines) ? lines : [lines];
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 210 + Math.max(0, textLines.length - 1) * 78;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRectPath(ctx, 5, 5, canvas.width - 10, canvas.height - 10, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = 5;
ctx.strokeStyle = border;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
textLines.forEach((line, index) => {
const isValue = index === textLines.length - 1;
const fontSize = index === 0 ? 48 : isValue ? 74 : 43;
const y = 78 + index * 78;
ctx.font = `${index === 0 ? 800 : 700} ${fontSize}px system-ui, sans-serif`;
ctx.fillStyle = index === 0 ? "#b9c8d2" : color;
ctx.fillText(line, canvas.width / 2, y, canvas.width - 60);
});
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(width, width * canvas.height / canvas.width, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeRulerNumber(text, x) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, 256, 128);
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.font = "800 72px system-ui, sans-serif";
ctx.fillStyle = "#17212a";
ctx.fillText(text, 128, 66);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(0.27, 0.135, 1);
sprite.position.set(x, 0.29, 1.43);
sprite.renderOrder = 21;
scene.add(sprite);
}
// ---------------------------------------------------------------------
// Cutaway model: 1.60 m long
// ---------------------------------------------------------------------
const model = new THREE.Group();
scene.add(model);
const modelX0 = -1.0;
const modelX1 = 0.6;
const modelCenterX = (modelX0 + modelX1) / 2;
const modelLength = modelX1 - modelX0;
// Bottom slab.
const bottom = addBox(
modelLength,
0.08,
0.74,
materials.darkShell,
modelCenterX,
0.08,
0,
model
);
addEdges(bottom);
// Rear wall.
const rear = addBox(
modelLength,
0.56,
0.07,
materials.shell,
modelCenterX,
0.36,
-0.335,
model
);
addEdges(rear);
// End walls.
const leftWall = addBox(
0.07,
0.56,
0.67,
materials.shell,
modelX0 + 0.035,
0.36,
0,
model
);
addEdges(leftWall);
const rightWall = addBox(
0.07,
0.56,
0.67,
materials.shell,
modelX1 - 0.035,
0.36,
0,
model
);
addEdges(rightWall);
// Only the rear portion of the top remains, exposing the interior.
const roof = addBox(
modelLength,
0.07,
0.27,
materials.shell,
modelCenterX,
0.62,
-0.235,
model
);
addEdges(roof);
// Orange section faces identify the cutaway surfaces.
addBox(
modelLength,
0.082,
0.012,
materials.cut,
modelCenterX,
0.08,
0.376,
model
);
addBox(
0.072,
0.56,
0.012,
materials.cut,
modelX0 + 0.035,
0.36,
0.341,
model
);
addBox(
0.072,
0.56,
0.012,
materials.cut,
modelX1 - 0.035,
0.36,
0.341,
model
);
addBox(
modelLength,
0.072,
0.012,
materials.cut,
modelCenterX,
0.62,
-0.094,
model
);
// Small section-face fasteners.
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x26333d,
roughness: 0.28,
metalness: 0.8
});
[-0.78, -0.32, 0.16, 0.48].forEach((x) => {
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.018, 0.018, 0.016, 16),
boltMaterial
);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(x, 0.53, 0.348);
bolt.castShadow = true;
model.add(bolt);
});
// ---------------------------------------------------------------------
// Visible internal components
// ---------------------------------------------------------------------
const pcb = addBox(
0.58,
0.025,
0.34,
materials.board,
-0.52,
0.145,
0.045,
model
);
addEdges(pcb, 0x64d2b8, 0.35);
addBox(
0.22,
0.06,
0.17,
materials.chip,
-0.57,
0.19,
0.035,
model
);
addBox(
0.10,
0.04,
0.10,
materials.chip,
-0.36,
0.18,
0.10,
model
);
const module = addBox(
0.42,
0.20,
0.26,
new THREE.MeshStandardMaterial({
color: 0x2787a1,
roughness: 0.32,
metalness: 0.48,
emissive: 0x082b35,
emissiveIntensity: 0.35
}),
-0.55,
0.285,
-0.025,
model
);
addEdges(module, 0x80e9ff, 0.55);
addBox(
0.035,
0.38,
0.46,
materials.darkShell,
-0.05,
0.31,
-0.01,
model
);
const heatBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.115, 0.115, 0.29, 32),
materials.copper
);
heatBase.position.set(0.16, 0.29, -0.045);
heatBase.castShadow = true;
model.add(heatBase);
const finMaterial = new THREE.MeshStandardMaterial({
color: 0xe5a052,
roughness: 0.3,
metalness: 0.76
});
for (let i = 0; i < 5; i++) {
const fin = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.012, 8, 32),
finMaterial
);
fin.rotation.x = Math.PI / 2;
fin.position.set(0.16, 0.19 + i * 0.048, -0.045);
fin.castShadow = true;
model.add(fin);
}
const battery = addBox(
0.26,
0.19,
0.22,
new THREE.MeshStandardMaterial({
color: 0xa94d2d,
roughness: 0.42,
metalness: 0.45
}),
0.35,
0.235,
0.115,
model
);
addEdges(battery, 0xf2a069, 0.5);
// Curved internal wires.
const wireMaterialA = new THREE.MeshStandardMaterial({
color: 0x53d8fb,
roughness: 0.42,
metalness: 0.12,
emissive: 0x0b3f4e,
emissiveIntensity: 0.5
});
const wireMaterialB = new THREE.MeshStandardMaterial({
color: 0xffbd59,
roughness: 0.44,
metalness: 0.12
});
function addWire(points, material, radius = 0.011) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const wire = new THREE.Mesh(
new THREE.TubeGeometry(curve, 32, radius, 8, false),
material
);
wire.castShadow = true;
model.add(wire);
}
addWire(
[
[-0.48, 0.18, 0.18],
[-0.38, 0.28, 0.24],
[-0.12, 0.31, 0.24],
[0.08, 0.35, 0.19]
],
wireMaterialA
);
addWire(
[
[-0.52, 0.18, 0.14],
[-0.40, 0.22, 0.19],
[-0.20, 0.22, 0.23],
[0.04, 0.23, 0.19],
[0.22, 0.22, 0.19]
],
wireMaterialB,
0.009
);
// ---------------------------------------------------------------------
// Coarse ruler, aligned to the model's zero point
// ---------------------------------------------------------------------
const rulerStartX = -1.0;
const rulerLength = 2.6;
const rulerCenterX = rulerStartX + rulerLength / 2;
const rulerZ = 1.23;
const rulerBase = addBox(
rulerLength,
0.09,
0.34,
materials.ivory,
rulerCenterX,
0.12,
rulerZ
);
addEdges(rulerBase, 0x9e947f, 0.65);
// Deliberately coarse ticks: every 0.50 m.
for (let i = 0; i <= 5; i++) {
const value = i * 0.5;
const x = rulerStartX + value;
addBox(
0.012,
0.018,
0.20,
materials.ink,
x,
0.174,
rulerZ - 0.015
);
makeRulerNumber(value.toFixed(1), x);
}
// ---------------------------------------------------------------------
// Exact known-length dimension line
// ---------------------------------------------------------------------
const dimensionY = 0.145;
const dimensionZ = 0.73;
addBox(
modelLength,
0.015,
0.018,
materials.exact,
modelCenterX,
dimensionY,
dimensionZ
);
// Extension lines.
addBox(
0.012,
0.012,
0.35,
materials.exact,
modelX0,
dimensionY,
0.565
);
addBox(
0.012,
0.012,
0.35,
materials.exact,
modelX1,
dimensionY,
0.565
);
// End ticks.
addBox(
0.018,
0.15,
0.018,
materials.exact,
modelX0,
dimensionY,
dimensionZ
);
addBox(
0.018,
0.15,
0.018,
materials.exact,
modelX1,
dimensionY,
dimensionZ
);
const exactLabel = makeLabel(
["KNOWN MODEL LENGTH", "1.60 m"],
{
width: 1.68,
color: "#53d8fb",
border: "rgba(83, 216, 251, 0.78)"
}
);
exactLabel.position.set(modelCenterX, 0.44, dimensionZ);
scene.add(exactLabel);
// ---------------------------------------------------------------------
// Separate coarse-ruler bracket and readout
// ---------------------------------------------------------------------
const coarseTickX = rulerStartX + 1.5;
const coarseY = 0.265;
const coarseZ = 1.055;
addBox(
1.5,
0.015,
0.018,
materials.ruler,
rulerStartX + 0.75,
coarseY,
coarseZ
);
addBox(
0.018,
0.13,
0.018,
materials.ruler,
rulerStartX,
coarseY,
coarseZ
);
addBox(
0.018,
0.13,
0.018,
materials.ruler,
coarseTickX,
coarseY,
coarseZ
);
const coarseLabel = makeLabel(
["RULER-READABLE", "1.50 m"],
{
width: 1.45,
color: "#ffbd59",
border: "rgba(255, 189, 89, 0.78)"
}
);
coarseLabel.position.set(-0.12, 0.65, 1.10);
scene.add(coarseLabel);
// ---------------------------------------------------------------------
// Animation and resize
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const damping = 1 - Math.exp(-10 * dt);
orbit.theta = THREE.MathUtils.lerp(
orbit.theta,
orbit.goalTheta,
damping
);
orbit.phi = THREE.MathUtils.lerp(
orbit.phi,
orbit.goalPhi,
damping
);
orbit.radius = THREE.MathUtils.lerp(
orbit.radius,
orbit.goalRadius,
damping
);
applyCamera();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
animate();
document.querySelector("#loading").remove();
</script>
</body>
</html>
```