Prompt specification
Build or customize the Three.js 3D scene "Three rock textures on specimen plinths" 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: Three rock textures on specimen plinths
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/three-rock-textures-on-specimen-plinths-x1177
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts recognizable schematic igneous, sedimentary, and metamorphic sample blocks using geometry and color bands; keep each sample separate and label representation as simplified. Low-poly.
Working Three.js Starter (three-rock-textures-on-specimen-plinths-x1177):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Schematic Igneous, Sedimentary & Metamorphic Samples</title>
<style>
:root {
--bg: #081018;
--panel: rgba(12, 22, 30, 0.82);
--line: rgba(205, 226, 235, 0.18);
--text: #edf4f5;
--muted: #9fb1b8;
--igneous: #d69b7c;
--sedimentary: #d7b45f;
--metamorphic: #8db2a2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
canvas.grabbing {
cursor: grabbing;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
max-width: 480px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 8px;
color: #89a2ad;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(24px, 3vw, 42px);
font-weight: 650;
line-height: 1.05;
letter-spacing: -0.035em;
}
header p {
max-width: 430px;
margin: 12px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.sample-label {
position: absolute;
width: 190px;
padding: 10px 12px 11px;
overflow: hidden;
border: 1px solid var(--label-color);
border-radius: 9px;
background: var(--panel);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.28);
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
backdrop-filter: blur(10px);
}
.sample-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 23px;
background: linear-gradient(var(--label-color), transparent);
content: "";
}
.sample-label.visible {
opacity: 1;
}
.label-heading {
display: flex;
align-items: center;
gap: 8px;
}
.label-number {
color: var(--label-color);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.label-heading strong {
font-size: 13px;
letter-spacing: 0.08em;
}
.simplified {
display: inline-block;
margin-top: 7px;
padding: 3px 5px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 3px;
color: #b8c6ca;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.13em;
}
.sample-label p {
margin: 6px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
#legend {
position: fixed;
bottom: 28px;
left: 32px;
z-index: 5;
max-width: 430px;
color: #91a4ab;
font-size: 11px;
line-height: 1.55;
pointer-events: none;
}
#legend strong {
color: #d7e2e5;
font-weight: 650;
}
#controls {
position: fixed;
right: 28px;
bottom: 26px;
z-index: 8;
display: flex;
gap: 8px;
}
button {
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(12, 22, 30, 0.84);
color: #c9d6da;
font: inherit;
font-size: 11px;
cursor: pointer;
backdrop-filter: blur(8px);
}
button:hover,
button:focus-visible {
border-color: #78909a;
color: white;
outline: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: var(--bg);
color: #91a4ab;
font-size: 12px;
letter-spacing: 0.15em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
header {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
header p {
max-width: 320px;
font-size: 11px;
}
.sample-label {
width: 142px;
padding: 8px 9px;
}
.sample-label p {
display: none;
}
.simplified {
margin-top: 5px;
font-size: 7px;
}
#legend {
display: none;
}
#controls {
right: 16px;
bottom: 16px;
}
button {
padding: 8px 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header>
<div class="eyebrow">Geology / Visual taxonomy</div>
<h1>Three ways rock records its story</h1>
<p>
Separated low-poly teaching specimens showing crystal grains,
sedimentary bedding, and metamorphic foliation.
</p>
</header>
<div id="labels" aria-hidden="true">
<div
class="sample-label"
id="label-igneous"
style="--label-color: var(--igneous)"
>
<div class="label-heading">
<span class="label-number">01</span>
<strong>IGNEOUS</strong>
</div>
<span class="simplified">SIMPLIFIED REPRESENTATION</span>
<p>Interlocking, coarse crystal mosaic</p>
</div>
<div
class="sample-label"
id="label-sedimentary"
style="--label-color: var(--sedimentary)"
>
<div class="label-heading">
<span class="label-number">02</span>
<strong>SEDIMENTARY</strong>
</div>
<span class="simplified">SIMPLIFIED REPRESENTATION</span>
<p>Horizontal bedding and clastic grains</p>
</div>
<div
class="sample-label"
id="label-metamorphic"
style="--label-color: var(--metamorphic)"
>
<div class="label-heading">
<span class="label-number">03</span>
<strong>METAMORPHIC</strong>
</div>
<span class="simplified">SIMPLIFIED REPRESENTATION</span>
<p>Wavy, directional mineral bands</p>
</div>
</div>
<aside id="legend">
<strong>Schematic teaching specimens — not to scale.</strong>
Colors and structures are intentionally exaggerated for recognition.
Drag to orbit, scroll or pinch to zoom, and double-click to reset.
</aside>
<div id="controls">
<button id="reset" type="button">Reset view</button>
<button id="spin" type="button" aria-pressed="false">Auto orbit: off</button>
</div>
<div id="loading">Loading schematic specimens</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Scene setup
// -------------------------------------------------------------------------
const container = document.querySelector("#scene");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x081018);
scene.fog = new THREE.Fog(0x081018, 19, 38);
const camera = new THREE.PerspectiveCamera(
38,
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional schematic rock samples"
);
container.appendChild(renderer.domElement);
const hemiLight = new THREE.HemisphereLight(0xc5e1f2, 0x242018, 2.0);
scene.add(hemiLight);
const keyLight = new THREE.DirectionalLight(0xfff0da, 3.6);
keyLight.position.set(7, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x82b8d5, 2.0);
rimLight.position.set(-8, 5, -7);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xd7aa88, 22, 20, 2);
fillLight.position.set(0, 4, 5);
scene.add(fillLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
new THREE.MeshStandardMaterial({
color: 0x0c151c,
roughness: 0.96,
metalness: 0.04
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.02;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(36, 36, 0x35505d, 0x20343e);
grid.position.y = 0.002;
grid.material.transparent = true;
grid.material.opacity = 0.22;
grid.material.depthWrite = false;
scene.add(grid);
// -------------------------------------------------------------------------
// Utilities
// -------------------------------------------------------------------------
function seededRandom(seed) {
return function () {
let t = seed += 0x6d2b79f5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const random = seededRandom(1847);
function choose(list) {
return list[Math.floor(random() * list.length)];
}
function addTriangleColor(colors, color) {
colors.push(color.r, color.g, color.b);
}
function createPedestal(accentColor) {
const pedestal = new THREE.Group();
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.66, 1.78, 0.24, 12),
new THREE.MeshStandardMaterial({
color: 0x17242c,
roughness: 0.67,
metalness: 0.28,
flatShading: true
})
);
base.position.y = 0.12;
base.castShadow = true;
base.receiveShadow = true;
pedestal.add(base);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.58, 0.025, 4, 48),
new THREE.MeshBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.72
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.255;
pedestal.add(ring);
return pedestal;
}
// -------------------------------------------------------------------------
// Igneous sample: crystalline, interlocking-facet mosaic
// -------------------------------------------------------------------------
function createIgneousSample() {
const group = new THREE.Group();
const width = 2.65;
const height = 2.58;
const depth = 2.3;
group.add(createPedestal(0xd69b7c));
const specimen = new THREE.Group();
specimen.position.y = 0.27;
group.add(specimen);
const holder = new THREE.Group();
holder.position.y = height / 2;
specimen.add(holder);
const indexed = new THREE.BoxGeometry(width, height, depth, 3, 3, 3);
const geometry = indexed.toNonIndexed();
indexed.dispose();
const positions = geometry.attributes.position;
// Slightly taper and skew the block so it reads as a cut hand specimen.
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const normalizedY = y / height;
const taper = 0.98 - normalizedY * 0.045;
positions.setX(i, x * taper + normalizedY * 0.075);
positions.setY(i, y);
positions.setZ(i, z * (0.99 - normalizedY * 0.035));
}
positions.needsUpdate = true;
const granitePalette = [
0x9c9992,
0xb97f79,
0xd2c2a6,
0x38434b,
0x69757b,
0xe0d5bf
].map((hex) => new THREE.Color(hex));
const colors = [];
for (let i = 0; i < positions.count; i += 3) {
const value = random();
let color;
if (value < 0.25) {
color = granitePalette[0];
} else if (value < 0.43) {
color = granitePalette[1];
} else if (value < 0.62) {
color = granitePalette[2];
} else if (value < 0.77) {
color = granitePalette[3];
} else if (value < 0.90) {
color = granitePalette[4];
} else {
color = granitePalette[5];
}
addTriangleColor(colors, color);
addTriangleColor(colors, color);
addTriangleColor(colors, color);
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const block = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.88,
metalness: 0.035,
flatShading: true
})
);
block.castShadow = true;
block.receiveShadow = true;
holder.add(block);
// A few protruding crystal grains help suggest coarse granite.
const crystalGeometry = new THREE.OctahedronGeometry(0.12, 0);
const crystalColors = [
0xd5c0a4,
0xb87972,
0x707a7d,
0xe1d6c3
];
const crystalLocations = [
[-0.86, 0.60, 1.13],
[-0.42, 0.79, 1.14],
[0.16, 0.54, 1.14],
[0.76, 0.67, 1.13],
[-0.93, -0.28, 1.14],
[-0.26, -0.51, 1.14],
[0.46, -0.18, 1.14],
[0.92, -0.48, 1.12],
[-0.07, 0.03, 1.15],
[0.64, 0.12, 1.15]
];
for (const [x, y, z] of crystalLocations) {
const grain = new THREE.Mesh(
crystalGeometry,
new THREE.MeshStandardMaterial({
color: choose(crystalColors),
roughness: 0.7,
flatShading: true
})
);
grain.position.set(x, y, z);
grain.rotation.set(random() * Math.PI, random() * Math.PI, 0);
grain.scale.set(
0.8 + random() * 0.65,
0.8 + random() * 0.65,
0.45 + random() * 0.35
);
grain.castShadow = true;
holder.add(grain);
}
return { group, height };
}
// -------------------------------------------------------------------------
// Sedimentary sample: stacked beds with visible clasts
// -------------------------------------------------------------------------
function createSedimentarySample() {
const group = new THREE.Group();
const height = 2.55;
group.add(createPedestal(0xd7b45f));
const specimen = new THREE.Group();
specimen.position.y = 0.27;
group.add(specimen);
const layerColors = [
0x8c6842,
0xc6a46d,
0xe0c997,
0x745a3e,
0xb88b54,
0xd4b47a,
0x96704a,
0xc49b65
];
const layerRecords = [];
const layerCount = 8;
let currentY = 0;
for (let i = 0; i < layerCount; i++) {
const baseHeight = height / layerCount;
const layerHeight = baseHeight * (0.88 + random() * 0.22);
const layerWidth = 2.55 + random() * 0.18;
const layerDepth = 2.18 + random() * 0.17;
const xOffset = (random() - 0.5) * 0.10;
const zOffset = (random() - 0.5) * 0.09;
const layer = new THREE.Mesh(
new THREE.BoxGeometry(layerWidth, layerHeight, layerDepth),
new THREE.MeshStandardMaterial({
color: layerColors[i],
roughness: 0.94,
metalness: 0,
flatShading: true
})
);
layer.position.set(xOffset, currentY + layerHeight / 2, zOffset);
layer.rotation.z = (random() - 0.5) * 0.018;
layer.rotation.x = (random() - 0.5) * 0.012;
layer.castShadow = true;
layer.receiveShadow = true;
specimen.add(layer);
layerRecords.push({
layer,
xOffset,
zOffset,
y: currentY + layerHeight / 2,
height: layerHeight,
depth: layerDepth
});
currentY += layerHeight * 0.96;
}
// Rounded clasts embedded in the exposed face.
const pebbleGeometry = new THREE.IcosahedronGeometry(1, 0);
const pebbleColors = [0x5b5650, 0x857663, 0xa5967d, 0x6f6256];
for (let i = 0; i < 18; i++) {
const record = choose(layerRecords);
const radius = 0.055 + random() * 0.065;
const pebble = new THREE.Mesh(
pebbleGeometry,
new THREE.MeshStandardMaterial({
color: choose(pebbleColors),
roughness: 1,
flatShading: true
})
);
pebble.position.set(
record.xOffset + (random() - 0.5) * 2.05,
record.y + (random() - 0.5) * record.height * 0.55,
record.zOffset + record.depth / 2 + radius * 0.2
);
pebble.scale.set(
radius * (0.8 + random() * 0.6),
radius * (0.55 + random() * 0.4),
radius * 0.5
);
pebble.rotation.set(random() * Math.PI, random() * Math.PI, 0);
pebble.castShadow = true;
specimen.add(pebble);
}
return { group, height };
}
// -------------------------------------------------------------------------
// Metamorphic sample: wavy, directional mineral banding
// -------------------------------------------------------------------------
function createMetamorphicSample() {
const group = new THREE.Group();
const width = 2.62;
const height = 2.66;
const depth = 2.28;
group.add(createPedestal(0x8db2a2));
const specimen = new THREE.Group();
specimen.position.y = 0.27;
group.add(specimen);
const holder = new THREE.Group();
holder.position.y = height / 2;
specimen.add(holder);
const indexed = new THREE.BoxGeometry(width, height, depth, 5, 5, 5);
const geometry = indexed.toNonIndexed();
indexed.dispose();
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const normalizedY = y / height;
positions.setX(i, x * (0.98 - normalizedY * 0.035) - normalizedY * 0.05);
positions.setZ(i, z * (0.99 - normalizedY * 0.03));
}
positions.needsUpdate = true;
const bandPalette = [
new THREE.Color(0x303940),
new THREE.Color(0xd7d2c3),
new THREE.Color(0x758579),
new THREE.Color(0x9f6d64),
new THREE.Color(0x4b5559)
];
const colors = [];
for (let i = 0; i < positions.count; i += 3) {
const x =
(positions.getX(i) +
positions.getX(i + 1) +
positions.getX(i + 2)) / 3;
const y =
(positions.getY(i) +
positions.getY(i + 1) +
positions.getY(i + 2)) / 3;
const z =
(positions.getZ(i) +
positions.getZ(i + 1) +
positions.getZ(i + 2)) / 3;
// A scalar field creates coherent diagonal and wavy bands.
const field =
1.08 * x +
2.75 * y +
0.48 * z +
0.62 * Math.sin(2.45 * y + 1.35 * x) +
0.18 * Math.sin(4.2 * z);
const index = Math.floor(field + 10);
const bandIndex = ((index % bandPalette.length) + bandPalette.length) %
bandPalette.length;
const color = bandPalette[bandIndex];
addTriangleColor(colors, color);
addTriangleColor(colors, color);
addTriangleColor(colors, color);
}
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const block = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.84,
metalness: 0.055,
flatShading: true
})
);
block.castShadow = true;
block.receiveShadow = true;
holder.add(block);
// Raised, narrow seams reinforce the directional foliation.
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0x293239,
roughness: 0.9,
flatShading: true
});
for (const baseY of [-0.78, -0.18, 0.48, 0.98]) {
const points = [];
for (let i = 0; i <= 12; i++) {
const x = -1.27 + (i / 12) * 2.54;
const y =
baseY -
x * 0.24 +
Math.sin(x * 2.15 + baseY) * 0.13 +
Math.sin(x * 4.8) * 0.035;
points.push(new THREE.Vector3(x, y, depth / 2 + 0.018));
}
const curve = new THREE.CatmullRomCurve3(points);
const seam = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, 0.021, 3, false),
seamMaterial
);
seam.castShadow = true;
holder.add(seam);
}
return { group, height };
}
// -------------------------------------------------------------------------
// Sample assembly and responsive layout
// -------------------------------------------------------------------------
const samples = [
{
...createIgneousSample(),
label: document.querySelector("#label-igneous")
},
{
...createSedimentarySample(),
label: document.querySelector("#label-sedimentary")
},
{
...createMetamorphicSample(),
label: document.querySelector("#label-metamorphic")
}
];
samples.forEach((sample) => {
scene.add(sample.group);
sample.anchor = new THREE.Object3D();
sample.anchor.position.y = sample.height + 0.64;
sample.group.add(sample.anchor);
});
function layoutSamples() {
const portrait = window.innerWidth / window.innerHeight < 0.9;
const positions = portrait
? [[0, -5], [0, 0], [0, 5]]
: [[-4.15, 0], [0, 0], [4.15, 0]];
samples.forEach((sample, index) => {
sample.group.position.set(
positions[index][0],
0,
positions[index][1]
);
});
return portrait;
}
// -------------------------------------------------------------------------
// Direct camera controls — no OrbitControls or addons
// -------------------------------------------------------------------------
const view = {
theta: 0.67,
phi: 1.12,
radius: 15.4,
target: new THREE.Vector3(0, 1.15, 0),
autoOrbit: false
};
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
view.target.x + view.radius * sinPhi * Math.sin(view.theta),
view.target.y + view.radius * Math.cos(view.phi),
view.target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(view.target);
}
function resetView() {
const portrait = layoutSamples();
view.theta = portrait ? 0.95 : 0.67;
view.phi = portrait ? 1.10 : 1.12;
view.radius = portrait ? 19.5 : 15.4;
view.target.set(0, 1.15, 0);
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
let pointerId = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.classList.add("grabbing");
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.theta -= deltaX * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi - deltaY * 0.005,
0.45,
1.45
);
});
function endDrag(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
canvas.classList.remove("grabbing");
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius * Math.exp(event.deltaY * 0.001),
10,
27
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
const spinButton = document.querySelector("#spin");
spinButton.addEventListener("click", () => {
view.autoOrbit = !view.autoOrbit;
spinButton.textContent = `Auto orbit: ${view.autoOrbit ? "on" : "off"}`;
spinButton.setAttribute("aria-pressed", String(view.autoOrbit));
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const sample of samples) {
sample.anchor.getWorldPosition(projected);
projected.project(camera);
const visible = projected.z > -1 && projected.z < 1;
if (!visible) {
sample.label.classList.remove("visible");
continue;
}
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
sample.label.style.left = `${x}px`;
sample.label.style.top = `${y}px`;
sample.label.classList.add("visible");
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
const portrait = window.innerWidth / window.innerHeight < 0.9;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
layoutSamples();
if (!dragging) {
view.radius = portrait ? 19.5 : 15.4;
}
}
window.addEventListener("resize", onResize);
resetView();
function animate() {
requestAnimationFrame(animate);
if (view.autoOrbit && !dragging) {
view.theta += 0.0026;
}
updateCamera();
renderer.render(scene, camera);
updateLabels();
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```