Prompt specification
Build or customize the Three.js 3D scene "Layered snowpack cutaway 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: Layered snowpack cutaway tile
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/layered-snowpack-cutaway-tile-x1249
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Build a sloping snow block with distinct layers, embedded markers, and an exposed face; label it as a simplified structure rather than an avalanche assessment.
Working Three.js Starter (layered-snowpack-cutaway-tile-x1249):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Simplified Snow Structure</title>
<style>
:root {
color-scheme: dark;
--ink: #eff8ff;
--muted: #9fb5c5;
--panel: rgba(12, 28, 43, 0.78);
--border: rgba(181, 220, 239, 0.17);
--orange: #ff9d66;
--teal: #59d2c5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #091522;
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;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 43%, transparent 32%, rgba(3, 10, 17, 0.24) 76%),
linear-gradient(180deg, rgba(4, 12, 21, 0.12), transparent 36%);
}
.header {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(430px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin-bottom: 9px;
color: var(--teal);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(28px, 4vw, 48px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 0.98;
}
.subtitle {
max-width: 390px;
margin: 14px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 8px 11px;
border: 1px solid rgba(255, 157, 102, 0.34);
border-radius: 999px;
background: rgba(255, 157, 102, 0.09);
color: #ffc19a;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.badge::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 12px rgba(255, 157, 102, 0.8);
content: "";
}
.legend {
position: fixed;
top: 28px;
right: 28px;
z-index: 5;
width: 218px;
padding: 17px;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
box-shadow: 0 18px 55px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-title {
margin-bottom: 13px;
color: #dcebf3;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 22px 1fr;
align-items: center;
gap: 10px;
margin: 9px 0;
color: #b9cbd7;
font-size: 12px;
}
.swatch {
width: 22px;
height: 8px;
border: 1px solid rgba(255, 255, 255, 0.22);
border-radius: 2px;
}
.marker-key {
display: flex;
gap: 14px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--border);
color: #91a9b9;
font-size: 10px;
}
.marker-key span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.marker-dot {
width: 7px;
height: 7px;
border-radius: 50%;
}
.notice {
position: fixed;
left: 28px;
bottom: 26px;
z-index: 5;
max-width: 520px;
padding: 13px 15px;
border: 1px solid var(--border);
border-left: 3px solid var(--orange);
border-radius: 8px;
background: rgba(9, 23, 36, 0.82);
color: #bacbd5;
font-size: 11px;
line-height: 1.5;
pointer-events: none;
backdrop-filter: blur(12px);
}
.notice strong {
color: #f0f7fb;
}
.controls {
position: fixed;
right: 28px;
bottom: 28px;
z-index: 6;
display: flex;
align-items: center;
gap: 10px;
color: #8fa7b7;
font-size: 10px;
letter-spacing: 0.03em;
pointer-events: none;
}
button {
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 8px;
background: rgba(15, 33, 49, 0.85);
color: #d9e8f1;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.05em;
cursor: pointer;
pointer-events: auto;
}
button:hover {
border-color: rgba(89, 210, 197, 0.45);
color: white;
}
#face-callout {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
pointer-events: none;
opacity: 0;
transition: opacity 160ms ease;
}
#face-callout .anchor {
position: absolute;
left: -4px;
width: 8px;
height: 8px;
border: 2px solid #ffc19a;
border-radius: 50%;
background: rgba(255, 157, 102, 0.35);
box-shadow: 0 0 16px rgba(255, 157, 102, 0.55);
}
#face-callout .line {
width: 42px;
height: 1px;
margin-left: 3px;
background: linear-gradient(90deg, #ffad78, rgba(255, 173, 120, 0.25));
}
#face-callout .label {
margin-left: 7px;
padding: 6px 8px;
border: 1px solid rgba(255, 173, 120, 0.3);
border-radius: 5px;
background: rgba(10, 25, 39, 0.83);
color: #ffc19a;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
white-space: nowrap;
}
@media (max-width: 760px) {
.header {
top: 20px;
left: 20px;
width: calc(100vw - 40px);
}
.subtitle {
max-width: 310px;
font-size: 12px;
}
.legend {
display: none;
}
.notice {
right: 20px;
bottom: 20px;
left: 20px;
max-width: none;
}
.controls {
top: 20px;
right: 20px;
bottom: auto;
}
.controls .hint {
display: none;
}
}
</style>
</head>
<body>
<div id="vignette"></div>
<header class="header">
<div class="eyebrow">Geometric study / 01</div>
<h1>Simplified<br />Snow Structure</h1>
<p class="subtitle">
A faceted snow block with schematic layers, embedded markers, and a visible
cut face for spatial reference.
</p>
<div class="badge">Simplified structure — not an assessment</div>
</header>
<aside class="legend" aria-label="Scene legend">
<div class="legend-title">Illustrative layers</div>
<div class="legend-row">
<span class="swatch" style="background:#fffaf2"></span>
<span>Surface band</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#e9f3f7"></span>
<span>Upper band</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#d4e6ed"></span>
<span>Middle band</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#b5ceda"></span>
<span>Lower band</span>
</div>
<div class="legend-row">
<span class="swatch" style="background:#91b2c2"></span>
<span>Base band</span>
</div>
<div class="marker-key">
<span>
<i class="marker-dot" style="background:#ff9d66"></i>
Stake
</span>
<span>
<i class="marker-dot" style="background:#59d2c5"></i>
Embedded sensor
</span>
</div>
</aside>
<div id="face-callout">
<span class="anchor"></span>
<span class="line"></span>
<span class="label">EXPOSED FACE</span>
</div>
<div class="notice">
<strong>Schematic visualization only.</strong>
This simplified structure does not represent an avalanche assessment,
stability analysis, or field guidance.
</div>
<div class="controls">
<span class="hint">Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button">RESET VIEW</button>
</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 renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.domElement.id = "scene-canvas";
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly model of a simplified sloping snow structure"
);
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.12;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091522);
scene.fog = new THREE.FogExp2(0x091522, 0.027);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
// Direct camera controls; no examples/addons modules are used.
const controls = {
target: new THREE.Vector3(0, 1.35, 0),
radius: 14.2,
theta: 0.56,
phi: 1.02,
dragging: false,
pointerX: 0,
pointerY: 0
};
function updateCamera() {
const { target, radius, theta, phi } = controls;
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
function resetCamera() {
controls.target.set(0, 1.35, 0);
controls.radius = 14.2;
controls.theta = 0.56;
controls.phi = 1.02;
updateCamera();
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.48,
1.38
);
updateCamera();
});
function endDrag(event) {
controls.dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("contextmenu", (event) => event.preventDefault());
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
9,
22
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
document.getElementById("reset-view").addEventListener("click", resetCamera);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xc6e8ff, 0x152436, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.1);
keyLight.position.set(6, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x78bfff, 1.05);
fillLight.position.set(-8, 5, -5);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0x59d2c5, 14, 22, 2);
rimLight.position.set(-5, 3, -5);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Ground and faceted display plinth
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(70, 70),
new THREE.MeshStandardMaterial({
color: 0x08131f,
roughness: 0.96,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.5;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(40, 40, 0x315066, 0x193246);
grid.position.y = -0.485;
grid.material.transparent = true;
grid.material.opacity = 0.18;
scene.add(grid);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(8.7, 9.15, 0.5, 8, 1, false),
new THREE.MeshStandardMaterial({
color: 0x152b3d,
roughness: 0.78,
metalness: 0.08,
flatShading: true
})
);
plinth.position.y = -0.22;
plinth.receiveShadow = true;
plinth.castShadow = true;
scene.add(plinth);
const plinthEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(plinth.geometry, 20),
new THREE.LineBasicMaterial({
color: 0x53758a,
transparent: true,
opacity: 0.38
})
);
plinthEdges.position.copy(plinth.position);
scene.add(plinthEdges);
// -------------------------------------------------------------------------
// Snow block profile and distinct schematic layers
// -------------------------------------------------------------------------
const BASE = 0.04;
const BLOCK_DEPTH = 4.3;
// Piecewise-linear top profile: tall on the left, low on the right.
const topProfile = [
[-5.0, 3.55],
[-2.4, 3.25],
[-0.2, 2.55],
[1.6, 1.72],
[3.2, 1.08],
[5.0, 0.72]
];
function topAt(x) {
if (x <= topProfile[0][0]) return topProfile[0][1];
for (let i = 0; i < topProfile.length - 1; i++) {
const [x0, y0] = topProfile[i];
const [x1, y1] = topProfile[i + 1];
if (x <= x1) {
const t = (x - x0) / (x1 - x0);
return THREE.MathUtils.lerp(y0, y1, t);
}
}
return topProfile[topProfile.length - 1][1];
}
const layerDefinitions = [
{
name: "Base band",
low: 0,
high: 0.16,
cap: 0x91b2c2,
side: 0x7296a9
},
{
name: "Lower band",
low: 0.16,
high: 0.36,
cap: 0xb5ceda,
side: 0x91afc0
},
{
name: "Middle band",
low: 0.36,
high: 0.57,
cap: 0xd4e6ed,
side: 0xaec8d5
},
{
name: "Upper band",
low: 0.57,
high: 0.79,
cap: 0xe9f3f7,
side: 0xc3dbe5
},
{
name: "Surface band",
low: 0.79,
high: 1,
cap: 0xfffaf2,
side: 0xdde9ed
}
];
function profilePoints(fraction) {
return topProfile.map(([x, y]) => [
x,
BASE + (y - BASE) * fraction
]);
}
layerDefinitions.forEach((layer) => {
const lower = profilePoints(layer.low);
const upper = profilePoints(layer.high);
const shape = new THREE.Shape();
shape.moveTo(lower[0][0], lower[0][1]);
lower.slice(1).forEach(([x, y]) => shape.lineTo(x, y));
upper
.slice()
.reverse()
.forEach(([x, y]) => shape.lineTo(x, y));
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: BLOCK_DEPTH,
steps: 1,
bevelEnabled: false,
curveSegments: 1
});
const capMaterial = new THREE.MeshStandardMaterial({
color: layer.cap,
roughness: 0.93,
metalness: 0,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: layer.side,
roughness: 0.96,
metalness: 0,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, [capMaterial, sideMaterial]);
mesh.position.z = -BLOCK_DEPTH / 2;
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
});
// -------------------------------------------------------------------------
// Faceted upper snow surface
// -------------------------------------------------------------------------
const topPositions = [];
const topColors = [];
const xDivisions = 12;
const zDivisions = 4;
const xMin = -5;
const xMax = 5;
const zMin = -BLOCK_DEPTH / 2;
const zMax = BLOCK_DEPTH / 2;
const facetPalette = [
new THREE.Color(0xf8fcff),
new THREE.Color(0xffffff),
new THREE.Color(0xeaf5fa),
new THREE.Color(0xf3f9fc),
new THREE.Color(0xdfeef5)
];
let randomSeed = 7381;
function random() {
randomSeed = (randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
function addTopTriangle(a, b, c) {
const color = facetPalette[Math.floor(random() * facetPalette.length)];
[a, b, c].forEach((point) => {
topPositions.push(
point[0],
topAt(point[0]) + 0.045,
point[2]
);
topColors.push(color.r, color.g, color.b);
});
}
for (let ix = 0; ix < xDivisions; ix++) {
const x0 = THREE.MathUtils.lerp(xMin, xMax, ix / xDivisions);
const x1 = THREE.MathUtils.lerp(xMin, xMax, (ix + 1) / xDivisions);
for (let iz = 0; iz < zDivisions; iz++) {
const z0 = THREE.MathUtils.lerp(zMin, zMax, iz / zDivisions);
const z1 = THREE.MathUtils.lerp(zMin, zMax, (iz + 1) / zDivisions);
const a = [x0, 0, z0];
const b = [x1, 0, z0];
const c = [x1, 0, z1];
const d = [x0, 0, z1];
if ((ix + iz) % 2 === 0) {
addTopTriangle(a, c, b);
addTopTriangle(b, c, d);
} else {
addTopTriangle(a, d, c);
addTopTriangle(a, b, d);
}
}
}
const topGeometry = new THREE.BufferGeometry();
topGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(topPositions, 3)
);
topGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(topColors, 3)
);
topGeometry.computeVertexNormals();
const topSurface = new THREE.Mesh(
topGeometry,
new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.88,
metalness: 0,
flatShading: true,
side: THREE.DoubleSide
})
);
topSurface.castShadow = true;
topSurface.receiveShadow = true;
scene.add(topSurface);
// -------------------------------------------------------------------------
// Exposed-face outline, layer boundaries, and small measurement ticks
// -------------------------------------------------------------------------
const frontZ = BLOCK_DEPTH / 2 + 0.012;
const framePoints = [];
const lowerFrame = profilePoints(0);
const upperFrame = profilePoints(1);
lowerFrame.forEach(([x, y]) => framePoints.push(new THREE.Vector3(x, y, frontZ)));
upperFrame
.slice()
.reverse()
.forEach(([x, y]) => framePoints.push(new THREE.Vector3(x, y, frontZ)));
const frameGeometry = new THREE.BufferGeometry().setFromPoints(framePoints);
const frame = new THREE.LineLoop(
frameGeometry,
new THREE.LineBasicMaterial({
color: 0x476b80,
transparent: true,
opacity: 0.85
})
);
scene.add(frame);
[0.16, 0.36, 0.57, 0.79].forEach((fraction) => {
const points = profilePoints(fraction).map(
([x, y]) => new THREE.Vector3(x, y, frontZ + 0.004)
);
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: 0x668fa4,
transparent: true,
opacity: 0.55
})
);
scene.add(line);
});
const tickPoints = [];
const scaleX = -4.66;
for (let y = 0.5; y <= 3.01; y += 0.5) {
tickPoints.push(
new THREE.Vector3(scaleX - 0.09, y, frontZ),
new THREE.Vector3(scaleX + 0.09, y, frontZ)
);
}
const scaleGeometry = new THREE.BufferGeometry().setFromPoints(tickPoints);
const scaleTicks = new THREE.LineSegments(
scaleGeometry,
new THREE.LineBasicMaterial({
color: 0x496d81,
transparent: true,
opacity: 0.85
})
);
scene.add(scaleTicks);
// -------------------------------------------------------------------------
// Canvas-generated scene labels
// -------------------------------------------------------------------------
function roundedRect(context, x, y, width, height, radius) {
context.beginPath();
context.moveTo(x + radius, y);
context.lineTo(x + width - radius, y);
context.quadraticCurveTo(x + width, y, x + width, y + radius);
context.lineTo(x + width, y + height - radius);
context.quadraticCurveTo(
x + width,
y + height,
x + width - radius,
y + height
);
context.lineTo(x + radius, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - radius);
context.lineTo(x, y + radius);
context.quadraticCurveTo(x, y, x + radius, y);
context.closePath();
}
function createLabel(text, accent = "#ff9d66", scale = 1) {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 12, 18, 232, 60, 15);
context.fillStyle = "rgba(10, 25, 39, 0.92)";
context.fill();
context.strokeStyle = accent;
context.lineWidth = 4;
context.stroke();
context.fillStyle = accent;
context.beginPath();
context.arc(38, 48, 8, 0, Math.PI * 2);
context.fill();
context.font = "800 34px system-ui, sans-serif";
context.textAlign = "left";
context.textBaseline = "middle";
context.fillStyle = "#eef8ff";
context.fillText(text, 60, 49);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.0 * scale, 0.375 * scale, 1);
sprite.renderOrder = 10;
return sprite;
}
// -------------------------------------------------------------------------
// Embedded vertical stakes
// -------------------------------------------------------------------------
const stakeMaterial = new THREE.MeshStandardMaterial({
color: 0x314b5b,
roughness: 0.55,
metalness: 0.12,
flatShading: true
});
const stakeData = [
{ x: -3.75, z: -0.7, color: 0xff9d66, text: "P1" },
{ x: -1.85, z: 0.45, color: 0x59d2c5, text: "P2" },
{ x: 0.75, z: -0.75, color: 0xffcf66, text: "P3" },
{ x: 3.15, z: 0.55, color: 0xff9d66, text: "P4" }
];
stakeData.forEach((stake) => {
const snowY = topAt(stake.x) + 0.045;
const accent = new THREE.MeshStandardMaterial({
color: stake.color,
roughness: 0.48,
metalness: 0.08,
flatShading: true
});
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.055, 1.22, 6),
stakeMaterial
);
rod.position.set(stake.x, snowY + 0.26, stake.z);
rod.castShadow = true;
scene.add(rod);
const surfaceRing = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.025, 5, 12),
accent
);
surfaceRing.rotation.x = Math.PI / 2;
surfaceRing.position.set(stake.x, snowY + 0.06, stake.z);
scene.add(surfaceRing);
const cap = new THREE.Mesh(
new THREE.SphereGeometry(0.115, 7, 5),
accent
);
cap.position.set(stake.x, snowY + 0.88, stake.z);
cap.castShadow = true;
scene.add(cap);
const flag = new THREE.Mesh(
new THREE.BoxGeometry(0.34, 0.17, 0.035),
accent
);
flag.position.set(stake.x + 0.16, snowY + 0.71, stake.z);
flag.castShadow = true;
scene.add(flag);
const label = createLabel(stake.text, `#${stake.color.toString(16).padStart(6, "0")}`, 0.8);
label.position.set(stake.x + 0.35, snowY + 1.22, stake.z);
scene.add(label);
});
// -------------------------------------------------------------------------
// Sensor pucks embedded into the exposed face
// -------------------------------------------------------------------------
const faceSensors = [
{ x: -2.75, fraction: 0.48, color: 0x59d2c5, text: "M1" },
{ x: 0.05, fraction: 0.67, color: 0xff9d66, text: "M2" },
{ x: 2.75, fraction: 0.4, color: 0xffcf66, text: "M3" }
];
faceSensors.forEach((sensor) => {
const y = BASE + (topAt(sensor.x) - BASE) * sensor.fraction;
const color = new THREE.MeshStandardMaterial({
color: sensor.color,
roughness: 0.46,
metalness: 0.15,
flatShading: true
});
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.3, 6),
stakeMaterial
);
rod.rotation.x = Math.PI / 2;
rod.position.set(sensor.x, y, frontZ - 0.03);
scene.add(rod);
const puck = new THREE.Mesh(
new THREE.CylinderGeometry(0.17, 0.17, 0.1, 10),
color
);
puck.rotation.x = Math.PI / 2;
puck.position.set(sensor.x, y, frontZ + 0.13);
puck.castShadow = true;
scene.add(puck);
const center = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.115, 8),
new THREE.MeshStandardMaterial({
color: 0x183042,
roughness: 0.5,
metalness: 0.2
})
);
center.rotation.x = Math.PI / 2;
center.position.set(sensor.x, y, frontZ + 0.14);
scene.add(center);
const label = createLabel(sensor.text, `#${sensor.color.toString(16).padStart(6, "0")}`, 0.58);
label.position.set(sensor.x + 0.32, y + 0.25, frontZ + 0.2);
scene.add(label);
});
// -------------------------------------------------------------------------
// Small angular ice fragments around the base
// -------------------------------------------------------------------------
const chipGeometry = new THREE.TetrahedronGeometry(0.16, 0);
const chipMaterials = [
new THREE.MeshStandardMaterial({
color: 0xdceef5,
roughness: 0.85,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xb8d5e1,
roughness: 0.9,
flatShading: true
})
];
const chipPositions = [
[-5.45, 0.12, 1.65, 0.3],
[-4.55, 0.08, -2.65, 0.8],
[-2.9, 0.1, 2.65, 0.5],
[-0.65, 0.08, -2.7, 1.2],
[1.45, 0.1, 2.55, 0.25],
[3.8, 0.08, 2.4, 0.65],
[5.3, 0.08, -1.4, 0.95]
];
chipPositions.forEach(([x, y, z, rotation], index) => {
const chip = new THREE.Mesh(
chipGeometry,
chipMaterials[index % chipMaterials.length]
);
chip.position.set(x, y, z);
chip.rotation.set(rotation, rotation * 0.7, rotation * 0.4);
chip.scale.set(
0.8 + random() * 0.8,
0.65 + random() * 0.6,
0.75 + random() * 0.8
);
chip.castShadow = true;
chip.receiveShadow = true;
scene.add(chip);
});
// -------------------------------------------------------------------------
// Projected HTML callout for the exposed face
// -------------------------------------------------------------------------
const faceCallout = document.getElementById("face-callout");
const calloutAnchor = new THREE.Vector3(2.65, 1.55, frontZ + 0.04);
const projected = new THREE.Vector3();
function updateCallout() {
projected.copy(calloutAnchor).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
faceCallout.style.opacity = visible ? "1" : "0";
if (visible) {
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
faceCallout.style.left = `${x}px`;
faceCallout.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateCallout();
}
animate();
</script>
</body>
</html>
```