Prompt specification
Build or customize the Three.js 3D scene "Root wedge and freeze-thaw analogy bench" 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: Root wedge and freeze-thaw analogy bench
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/root-wedge-and-freeze-thaw-analogy-bench-x1198
Scene Description Prompt:
Please make a stylized Three.js scene in one standalone HTML file using cdnjs. Arrange two transparent crack models showing a growing root and expanding conceptual ice wedge; label them simplified weathering mechanisms rather than exact stress calculations.
Working Three.js Starter (root-wedge-and-freeze-thaw-analogy-bench-x1198):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Fracture / Growth — Stylized Weathering Mechanisms</title>
<style>
:root {
--bg: #071018;
--panel: rgba(12, 27, 36, 0.78);
--line: rgba(185, 226, 234, 0.2);
--text: #eef8f8;
--muted: #9bb2b9;
--amber: #e9a765;
--cyan: #73dcf4;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 35%, #122936 0%, #071018 58%, #040a0f 100%);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
#vignette {
position: fixed;
inset: 0;
z-index: 1;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 38%, rgba(2, 8, 12, 0.42) 100%);
}
header {
position: fixed;
z-index: 4;
top: 28px;
left: 32px;
width: min(430px, calc(100vw - 64px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: #a8c5cb;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: var(--cyan);
box-shadow: 0 0 10px rgba(115, 220, 244, 0.65);
}
h1 {
margin: 13px 0 9px;
font-size: clamp(34px, 4.3vw, 64px);
font-weight: 520;
letter-spacing: -0.055em;
line-height: 0.96;
}
h1 span {
color: var(--cyan);
font-weight: 300;
}
header p {
max-width: 390px;
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.scale-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 17px;
padding: 7px 10px;
border: 1px solid rgba(115, 220, 244, 0.2);
border-radius: 999px;
background: rgba(14, 33, 43, 0.55);
color: #b9d7dc;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.scale-badge::before {
width: 6px;
height: 6px;
content: "";
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
}
.model-label {
position: fixed;
z-index: 3;
width: 264px;
padding: 14px 15px 13px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--panel);
box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
transform: translate(-50%, -100%);
transition: opacity 180ms ease;
}
.model-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 22px;
content: "";
background: linear-gradient(var(--line), rgba(255, 255, 255, 0.08));
}
.model-label::before {
position: absolute;
top: calc(100% + 20px);
left: calc(50% - 3px);
width: 7px;
height: 7px;
content: "";
border: 1px solid currentColor;
border-radius: 50%;
background: var(--bg);
box-shadow: 0 0 10px currentColor;
}
#label-root {
color: var(--amber);
}
#label-ice {
color: var(--cyan);
}
.label-index {
margin-bottom: 6px;
color: currentColor;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
opacity: 0.92;
}
.model-label h2 {
margin: 0 0 6px;
color: var(--text);
font-size: 17px;
font-weight: 570;
letter-spacing: -0.02em;
}
.model-label p {
margin: 0 0 10px;
color: #a8bdc3;
font-size: 11px;
line-height: 1.45;
}
.disclaimer {
display: inline-block;
padding-top: 8px;
border-top: 1px solid rgba(255, 255, 255, 0.09);
color: currentColor;
font-size: 9px;
font-weight: 650;
line-height: 1.35;
opacity: 0.84;
}
.view-help {
position: fixed;
z-index: 4;
top: 30px;
right: 32px;
display: flex;
align-items: center;
gap: 13px;
color: #8fa8b0;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
}
.view-help span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.view-help i {
display: inline-block;
width: 16px;
height: 16px;
border: 1px solid rgba(185, 226, 234, 0.28);
border-radius: 50%;
text-align: center;
font-style: normal;
line-height: 14px;
}
.legend {
position: fixed;
z-index: 4;
left: 32px;
bottom: 28px;
display: flex;
gap: 18px;
color: #8fa8b0;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.legend span {
display: flex;
align-items: center;
gap: 7px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
}
.legend .root-dot {
background: var(--amber);
box-shadow: 0 0 9px rgba(233, 167, 101, 0.7);
}
.legend .ice-dot {
background: var(--cyan);
box-shadow: 0 0 9px rgba(115, 220, 244, 0.7);
}
.controls {
position: fixed;
z-index: 5;
right: 28px;
bottom: 24px;
display: flex;
align-items: center;
gap: 9px;
padding: 9px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(8, 20, 28, 0.86);
box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
button {
min-width: 70px;
padding: 9px 12px;
border: 1px solid rgba(185, 226, 234, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.045);
color: #d7e8ea;
font: inherit;
font-size: 11px;
font-weight: 650;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
border-color: rgba(115, 220, 244, 0.48);
background: rgba(115, 220, 244, 0.09);
}
button:active {
transform: translateY(1px);
}
#play {
border-color: rgba(115, 220, 244, 0.34);
background: rgba(115, 220, 244, 0.1);
}
.timeline-wrap {
display: grid;
grid-template-columns: 120px 38px;
align-items: center;
gap: 9px;
padding: 0 4px 0 8px;
}
#timeline {
width: 120px;
height: 3px;
margin: 0;
border-radius: 10px;
appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--progress, 0%),
rgba(255, 255, 255, 0.12) var(--progress, 0%),
rgba(255, 255, 255, 0.12) 100%
);
cursor: pointer;
}
#timeline::-webkit-slider-thumb {
width: 12px;
height: 12px;
border: 2px solid #dffaff;
border-radius: 50%;
appearance: none;
background: #3abbd7;
box-shadow: 0 0 12px rgba(115, 220, 244, 0.7);
}
#timeline::-moz-range-thumb {
width: 10px;
height: 10px;
border: 2px solid #dffaff;
border-radius: 50%;
background: #3abbd7;
box-shadow: 0 0 12px rgba(115, 220, 244, 0.7);
}
#progress-text {
color: #88a2aa;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
@media (max-width: 780px) {
header {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
h1 {
font-size: 34px;
}
header p {
max-width: 310px;
font-size: 11px;
}
.scale-badge {
margin-top: 11px;
}
.view-help {
top: auto;
right: 18px;
bottom: 106px;
}
.view-help .wheel-help {
display: none;
}
.model-label {
width: 224px;
padding: 11px 12px;
}
.model-label h2 {
font-size: 15px;
}
.model-label p {
font-size: 10px;
}
.legend {
display: none;
}
.controls {
right: 50%;
bottom: 14px;
width: calc(100vw - 28px);
justify-content: center;
transform: translateX(50%);
}
.timeline-wrap {
flex: 1;
grid-template-columns: 1fr 34px;
}
#timeline {
width: 100%;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive Three.js comparison of root wedging and a conceptual freeze-thaw ice wedge"></canvas>
<div id="vignette"></div>
<header>
<div class="eyebrow">Weathering / schematic study</div>
<h1>Fracture <span>/</span><br />Growth</h1>
<p>
Two transparent fracture studies showing how biological growth and
freeze–thaw action can progressively alter a crack.
</p>
<div class="scale-badge">Schematic · not to scale</div>
</header>
<div class="view-help" aria-hidden="true">
<span><i>↔</i> Drag to orbit</span>
<span class="wheel-help"><i>⌕</i> Scroll to zoom</span>
</div>
<section id="label-root" class="model-label" aria-label="Root wedging label">
<div class="label-index">01 · Biological weathering</div>
<h2>Root wedging</h2>
<p>
A growing root follows an existing fracture and locally widens the
opening as it develops.
</p>
<div class="disclaimer">
Simplified mechanism — not an exact stress calculation.
</div>
</section>
<section id="label-ice" class="model-label" aria-label="Conceptual ice wedge label">
<div class="label-index">02 · Freeze–thaw weathering</div>
<h2>Conceptual ice wedge</h2>
<p>
Repeated freezing and growth are represented as an expanding ice body
inside a widening crack.
</p>
<div class="disclaimer">
Illustrative expansion — not a stress or pressure calculation.
</div>
</section>
<div class="legend" aria-hidden="true">
<span><i class="root-dot"></i> Root pathway</span>
<span><i class="ice-dot"></i> Ice body</span>
</div>
<div class="controls" aria-label="Animation controls">
<button id="play" type="button">Pause</button>
<button id="replay" type="button">Replay</button>
<button id="reset-view" type="button" title="Reset the camera">
View
</button>
<div class="timeline-wrap">
<input
id="timeline"
type="range"
min="0"
max="1000"
value="0"
step="1"
aria-label="Conceptual growth timeline"
/>
<span id="progress-text">0%</span>
</div>
</div>
<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 rootLabel = document.querySelector("#label-root");
const iceLabel = document.querySelector("#label-ice");
const timeline = document.querySelector("#timeline");
const progressText = document.querySelector("#progress-text");
const playButton = document.querySelector("#play");
const replayButton = document.querySelector("#replay");
const resetViewButton = document.querySelector("#reset-view");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setClearColor(0x071018, 1);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x071018, 0.034);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, -0.15, 0);
const orbitGoal = {
yaw: 0.10,
pitch: 0.22,
radius: 13.2
};
const orbitCurrent = { ...orbitGoal };
const hemisphere = new THREE.HemisphereLight(0xa7dce5, 0x10171d, 1.55);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xf2fbff, 2.15);
keyLight.position.set(4.5, 8, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
scene.add(keyLight);
const amberLight = new THREE.PointLight(0xffa55c, 14, 10, 2);
amberLight.position.set(-4, 0.5, 4);
scene.add(amberLight);
const cyanLight = new THREE.PointLight(0x50d8ff, 16, 11, 2);
cyanLight.position.set(4, 1.2, 4);
scene.add(cyanLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x08131b,
roughness: 0.93,
metalness: 0.05
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.48;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(30, 30, 0x31515d, 0x17313b);
grid.position.y = -2.465;
grid.material.transparent = true;
grid.material.opacity = 0.17;
scene.add(grid);
function createPedestal(color) {
const group = new THREE.Group();
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.95, 2.08, 0.15, 64),
new THREE.MeshStandardMaterial({
color: 0x0d1c25,
roughness: 0.7,
metalness: 0.18
})
);
base.position.y = -2.31;
base.receiveShadow = true;
group.add(base);
const ring = new THREE.Mesh(
new THREE.RingGeometry(1.67, 1.71, 96),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.32,
side: THREE.DoubleSide,
depthWrite: false
})
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = -2.225;
group.add(ring);
return group;
}
function createRockSlab(tint, strataOpacity = 0.1) {
const group = new THREE.Group();
const shape = new THREE.Shape();
shape.moveTo(-1.6, -2.05);
shape.lineTo(-1.53, 1.42);
shape.lineTo(-1.06, 2.07);
shape.lineTo(0.86, 2.18);
shape.lineTo(1.55, 1.57);
shape.lineTo(1.58, -1.38);
shape.lineTo(1.17, -2.12);
shape.lineTo(-1.02, -2.14);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 1.8,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: 0.09,
bevelThickness: 0.07,
curveSegments: 4
});
geometry.translate(0, 0, -0.9);
const material = new THREE.MeshPhysicalMaterial({
color: tint,
transparent: true,
opacity: 0.115,
roughness: 0.82,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
});
const slab = new THREE.Mesh(geometry, material);
slab.renderOrder = 1;
group.add(slab);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 22),
new THREE.LineBasicMaterial({
color: tint,
transparent: true,
opacity: 0.29,
depthWrite: false
})
);
edges.renderOrder = 2;
group.add(edges);
// Fine, irregular strata lines emphasize the transparent rock volume.
for (let row = 0; row < 8; row++) {
const y = -1.75 + row * 0.48;
const points = [];
for (let i = 0; i <= 10; i++) {
const x = -1.38 + (i / 10) * 2.76;
const wave =
Math.sin(i * 1.71 + row * 1.23) * 0.035 +
Math.cos(i * 0.74 + row) * 0.025;
points.push(new THREE.Vector3(x, y + wave, 1.018));
}
const line = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineBasicMaterial({
color: tint,
transparent: true,
opacity: strataOpacity,
depthWrite: false
})
);
group.add(line);
}
return group;
}
function createRibbonGeometry(points, widths) {
const positions = [];
const indices = [];
const normals = [];
for (let i = 0; i < points.length; i++) {
const previous = points[Math.max(0, i - 1)];
const next = points[Math.min(points.length - 1, i + 1)];
const tangent = new THREE.Vector2(
next.x - previous.x,
next.y - previous.y
).normalize();
const normal = new THREE.Vector2(-tangent.y, tangent.x);
const halfWidth = widths[i] * 0.5;
const left = new THREE.Vector3(
points[i].x + normal.x * halfWidth,
points[i].y + normal.y * halfWidth,
points[i].z
);
const right = new THREE.Vector3(
points[i].x - normal.x * halfWidth,
points[i].y - normal.y * halfWidth,
points[i].z
);
positions.push(left.x, left.y, left.z);
positions.push(right.x, right.y, right.z);
normals.push(0, 0, 1, 0, 0, 1);
if (i < points.length - 1) {
const a = i * 2;
indices.push(a, a + 1, a + 2, a + 1, a + 3, a + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
function createTaperedTube(curve, tubularSegments, radialSegments, startRadius, endRadius) {
const frames = curve.computeFrenetFrames(tubularSegments, false);
const positions = [];
const normals = [];
const uvs = [];
const indices = [];
for (let i = 0; i <= tubularSegments; i++) {
const t = i / tubularSegments;
const point = curve.getPointAt(t);
const radius = THREE.MathUtils.lerp(
startRadius,
endRadius,
Math.pow(t, 0.78)
);
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const normal = new THREE.Vector3()
.copy(frames.normals[i])
.multiplyScalar(Math.cos(angle))
.addScaledVector(frames.binormals[i], Math.sin(angle));
positions.push(
point.x + normal.x * radius,
point.y + normal.y * radius,
point.z + normal.z * radius
);
normals.push(normal.x, normal.y, normal.z);
uvs.push(t, j / radialSegments);
}
}
for (let i = 1; i <= tubularSegments; i++) {
for (let j = 1; j <= radialSegments; j++) {
const a = (radialSegments + 1) * (i - 1) + (j - 1);
const b = (radialSegments + 1) * i + (j - 1);
const c = (radialSegments + 1) * i + j;
const d = (radialSegments + 1) * (i - 1) + j;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"normal",
new THREE.Float32BufferAttribute(normals, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeBoundingSphere();
return geometry;
}
function createIcePrism(width, height, frontZ, backZ) {
const vertices = new Float32Array([
-width, height, frontZ,
width, height, frontZ,
0, -height, frontZ,
-width, height, backZ,
width, height, backZ,
0, -height, backZ
]);
const indices = [
0, 1, 2,
5, 4, 3,
0, 3, 4, 0, 4, 1,
1, 4, 5, 1, 5, 2
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(vertices, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
// ------------------------------------------------------------
// Root-wedging model
// ------------------------------------------------------------
const rootModel = new THREE.Group();
rootModel.add(createPedestal(0xe9a765));
rootModel.add(createRockSlab(0xb5cbd0, 0.1));
const rootCrackPoints = [
new THREE.Vector3(0.00, -2.10, 1.045),
new THREE.Vector3(-0.10, -1.62, 1.045),
new THREE.Vector3(0.14, -1.13, 1.045),
new THREE.Vector3(-0.04, -0.62, 1.045),
new THREE.Vector3(0.19, -0.06, 1.045),
new THREE.Vector3(-0.14, 0.53, 1.045),
new THREE.Vector3(0.11, 1.12, 1.045),
new THREE.Vector3(-0.04, 1.68, 1.045),
new THREE.Vector3(0.02, 2.10, 1.045)
];
const rootCrackMaterial = new THREE.MeshBasicMaterial({
color: 0xe69c58,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false
});
const rootCrack = new THREE.Mesh(
createRibbonGeometry(
rootCrackPoints,
[0.07, 0.12, 0.09, 0.13, 0.10, 0.14, 0.10, 0.12, 0.06]
),
rootCrackMaterial
);
rootCrack.renderOrder = 3;
rootModel.add(rootCrack);
const rootCrackLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(rootCrackPoints),
new THREE.LineBasicMaterial({
color: 0xffbd78,
transparent: true,
opacity: 0.8,
depthWrite: false
})
);
rootCrackLine.renderOrder = 4;
rootModel.add(rootCrackLine);
const rootCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.24, -2.26, 1.105),
new THREE.Vector3(-0.08, -1.75, 1.12),
new THREE.Vector3(0.10, -1.22, 1.11),
new THREE.Vector3(-0.01, -0.68, 1.13),
new THREE.Vector3(0.15, -0.10, 1.115),
new THREE.Vector3(-0.10, 0.50, 1.13),
new THREE.Vector3(0.07, 1.10, 1.115),
new THREE.Vector3(-0.02, 1.65, 1.12),
new THREE.Vector3(0.02, 2.04, 1.105)
],
false,
"centripetal"
);
const rootMaterial = new THREE.MeshStandardMaterial({
color: 0x915d38,
emissive: 0x2b1308,
emissiveIntensity: 0.18,
roughness: 0.76,
metalness: 0.01
});
const rootSegments = 120;
const rootRadialSegments = 8;
const rootGeometry = createTaperedTube(
rootCurve,
rootSegments,
rootRadialSegments,
0.135,
0.032
);
rootGeometry.setDrawRange(0, 0);
const rootMesh = new THREE.Mesh(rootGeometry, rootMaterial);
rootMesh.castShadow = true;
rootMesh.renderOrder = 5;
rootModel.add(rootMesh);
const branchCurves = [
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.01, -0.72, 1.12),
new THREE.Vector3(-0.27, -0.54, 1.125),
new THREE.Vector3(-0.49, -0.23, 1.11),
new THREE.Vector3(-0.68, 0.03, 1.09)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(0.15, -0.10, 1.12),
new THREE.Vector3(0.34, 0.05, 1.125),
new THREE.Vector3(0.51, 0.23, 1.10),
new THREE.Vector3(0.64, 0.42, 1.085)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.11, 0.50, 1.12),
new THREE.Vector3(-0.29, 0.68, 1.115),
new THREE.Vector3(-0.45, 0.87, 1.10),
new THREE.Vector3(-0.53, 1.05, 1.085)
])
];
const branchMeshes = branchCurves.map((curve) => {
const geometry = new THREE.TubeGeometry(curve, 38, 0.034, 6, false);
geometry.setDrawRange(0, 0);
const mesh = new THREE.Mesh(geometry, rootMaterial);
mesh.renderOrder = 5;
rootModel.add(mesh);
return mesh;
});
const sprout = new THREE.Group();
sprout.position.set(0.02, 2.035, 1.105);
sprout.scale.setScalar(0.001);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.033, 0.28, 8),
rootMaterial
);
stem.position.y = 0.13;
sprout.add(stem);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x799f62,
roughness: 0.8,
side: THREE.DoubleSide
});
const leafGeometry = new THREE.SphereGeometry(1, 18, 10);
const leftLeaf = new THREE.Mesh(leafGeometry, leafMaterial);
leftLeaf.scale.set(0.09, 0.22, 0.026);
leftLeaf.position.set(-0.10, 0.29, 0);
leftLeaf.rotation.z = 0.75;
sprout.add(leftLeaf);
const rightLeaf = new THREE.Mesh(leafGeometry, leafMaterial);
rightLeaf.scale.set(0.09, 0.23, 0.026);
rightLeaf.position.set(0.10, 0.30, 0.01);
rightLeaf.rotation.z = -0.75;
sprout.add(rightLeaf);
rootModel.add(sprout);
// ------------------------------------------------------------
// Conceptual ice-wedge model
// ------------------------------------------------------------
const iceModel = new THREE.Group();
iceModel.add(createPedestal(0x73dcf4));
iceModel.add(createRockSlab(0x8dc6d2, 0.085));
const iceBody = new THREE.Group();
iceModel.add(iceBody);
const iceMaterial = new THREE.MeshPhysicalMaterial({
color: 0x64d6f4,
emissive: 0x073d50,
emissiveIntensity: 0.58,
transparent: true,
opacity: 0.38,
roughness: 0.18,
metalness: 0.04,
side: THREE.DoubleSide,
depthWrite: false
});
const iceGeometry = createIcePrism(0.76, 1.92, 1.095, 0.52);
const iceMesh = new THREE.Mesh(iceGeometry, iceMaterial);
iceMesh.renderOrder = 4;
iceBody.add(iceMesh);
const iceHaloMaterial = new THREE.MeshBasicMaterial({
color: 0x6fe4ff,
transparent: true,
opacity: 0.075,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
});
const iceHalo = new THREE.Mesh(
createIcePrism(0.76, 1.92, 1.10, 0.50),
iceHaloMaterial
);
iceHalo.scale.set(1.075, 1.025, 1.03);
iceHalo.renderOrder = 3;
iceBody.add(iceHalo);
const iceEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(iceGeometry, 15),
new THREE.LineBasicMaterial({
color: 0xb5f2ff,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
iceEdges.renderOrder = 5;
iceBody.add(iceEdges);
const innerIce = new THREE.Mesh(
createIcePrism(0.53, 1.70, 1.108, 0.73),
new THREE.MeshBasicMaterial({
color: 0xc0f5ff,
transparent: true,
opacity: 0.17,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
innerIce.renderOrder = 5;
iceBody.add(innerIce);
const leftArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.78, 0.18, 1.13),
0.55,
0x75e5ff,
0.13,
0.075
);
const rightArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(0.78, 0.18, 1.13),
0.55,
0x75e5ff,
0.13,
0.075
);
for (const arrow of [leftArrow, rightArrow]) {
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.62;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.62;
iceModel.add(arrow);
}
const expansionRing = new THREE.Mesh(
new THREE.RingGeometry(0.72, 0.745, 80),
new THREE.MeshBasicMaterial({
color: 0x76e7ff,
transparent: true,
opacity: 0.12,
side: THREE.DoubleSide,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
expansionRing.position.set(0, 0.18, 1.12);
iceModel.add(expansionRing);
scene.add(rootModel, iceModel);
// Subtle atmospheric particles.
const dustPositions = [];
for (let i = 0; i < 120; i++) {
dustPositions.push(
(Math.random() - 0.5) * 18,
Math.random() * 9 - 2,
(Math.random() - 0.5) * 12 - 1
);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x8bc5d1,
size: 0.025,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
scene.add(dust);
// ------------------------------------------------------------
// Responsive scene layout
// ------------------------------------------------------------
let narrowLayout = false;
function configureLayout(resetCamera = true) {
narrowLayout = window.innerWidth < 780;
if (narrowLayout) {
rootModel.position.set(0, 2.55, 0);
iceModel.position.set(0, -2.55, 0);
floor.position.y = -5.03;
grid.position.y = -5.015;
orbitGoal.yaw = 0.035;
orbitGoal.pitch = 0.17;
orbitGoal.radius = 17.2;
cameraTarget.set(0, -0.15, 0);
} else {
rootModel.position.set(-2.58, 0, 0);
iceModel.position.set(2.58, 0, 0);
floor.position.y = -2.48;
grid.position.y = -2.465;
orbitGoal.yaw = 0.10;
orbitGoal.pitch = 0.22;
orbitGoal.radius =
window.innerWidth / window.innerHeight < 1.25 ? 15.4 : 13.2;
cameraTarget.set(0, -0.15, 0);
}
if (resetCamera) {
Object.assign(orbitCurrent, orbitGoal);
}
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
configureLayout(true);
}
window.addEventListener("resize", resize);
configureLayout(true);
resize();
// ------------------------------------------------------------
// Direct camera controls implemented without add-ons
// ------------------------------------------------------------
const pointers = new Map();
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let lastPinchDistance = 0;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size === 2) {
dragging = false;
lastPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1 && dragging) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
orbitGoal.yaw -= dx * 0.005;
orbitGoal.pitch = THREE.MathUtils.clamp(
orbitGoal.pitch + dy * 0.004,
0.04,
0.78
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
} else if (pointers.size >= 2) {
const distance = pointerDistance();
if (lastPinchDistance > 0 && distance > 0) {
orbitGoal.radius = THREE.MathUtils.clamp(
orbitGoal.radius * (lastPinchDistance / distance),
8.5,
21
);
}
lastPinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 1) {
const remaining = [...pointers.values()][0];
dragging = true;
lastPointerX = remaining.x;
lastPointerY = remaining.y;
} else {
dragging = false;
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbitGoal.radius = THREE.MathUtils.clamp(
orbitGoal.radius + event.deltaY * 0.008,
8.5,
21
);
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => configureLayout(true));
resetViewButton.addEventListener("click", () => configureLayout(true));
// ------------------------------------------------------------
// Conceptual animation timeline
// ------------------------------------------------------------
const duration = 10;
let progress = 0;
let playing = true;
let elapsed = 0;
function smooth01(value) {
const x = THREE.MathUtils.clamp(value, 0, 1);
return x * x * (3 - 2 * x);
}
function updateProgressUI() {
const percentage = Math.round(progress * 100);
timeline.value = Math.round(progress * 1000);
timeline.style.setProperty("--progress", `${percentage}%`);
progressText.textContent = `${percentage}%`;
playButton.textContent = playing
? "Pause"
: progress >= 1
? "Replay"
: "Play";
}
function applyProgress() {
const rootProgress = smooth01((progress - 0.025) / 0.49);
const branchProgress = smooth01((progress - 0.28) / 0.34);
const iceProgress = smooth01((progress - 0.08) / 0.70);
const sproutProgress = smooth01((progress - 0.68) / 0.22);
const rootIndexCount =
Math.floor(rootProgress * rootSegments) *
rootRadialSegments *
6;
rootGeometry.setDrawRange(0, rootIndexCount);
for (const mesh of branchMeshes) {
const segmentCount = Math.floor(branchProgress * 38);
mesh.geometry.setDrawRange(0, segmentCount * 6 * 6);
}
rootCrackMaterial.opacity = 0.14 + rootProgress * 0.14;
rootMaterial.emissiveIntensity = 0.15 + rootProgress * 0.12;
sprout.scale.setScalar(Math.max(0.001, sproutProgress));
sprout.visible = sproutProgress > 0.002;
const width = 0.16 + iceProgress * 0.84;
const height = 0.76 + iceProgress * 0.24;
iceBody.scale.set(width, height, 1);
iceMaterial.opacity = 0.30 + iceProgress * 0.23;
iceMaterial.emissiveIntensity = 0.42 + iceProgress * 0.34;
iceHaloMaterial.opacity = 0.04 + iceProgress * 0.075;
const arrowLength = 0.26 + iceProgress * 0.52;
leftArrow.setLength(arrowLength, 0.13, 0.075);
rightArrow.setLength(arrowLength, 0.13, 0.075);
leftArrow.line.material.opacity = 0.2 + iceProgress * 0.45;
rightArrow.line.material.opacity = 0.2 + iceProgress * 0.45;
leftArrow.cone.material.opacity = 0.2 + iceProgress * 0.45;
rightArrow.cone.material.opacity = 0.2 + iceProgress * 0.45;
expansionRing.scale.setScalar(0.72 + iceProgress * 0.55);
expansionRing.material.opacity = 0.06 + iceProgress * 0.13;
updateProgressUI();
}
function togglePlayback() {
if (progress >= 0.999) {
progress = 0;
playing = true;
} else {
playing = !playing;
}
applyProgress();
}
playButton.addEventListener("click", togglePlayback);
replayButton.addEventListener("click", () => {
progress = 0;
playing = true;
applyProgress();
});
timeline.addEventListener("input", () => {
progress = Number(timeline.value) / 1000;
playing = false;
applyProgress();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
togglePlayback();
}
if (event.key.toLowerCase() === "r") {
progress = 0;
playing = true;
applyProgress();
}
});
applyProgress();
// ------------------------------------------------------------
// Label projection and render loop
// ------------------------------------------------------------
const rootAnchor = new THREE.Vector3(0, 2.48, 0.75);
const iceAnchor = new THREE.Vector3(0, 2.48, 0.75);
function positionLabel(element, object, localAnchor) {
object.updateWorldMatrix(true, false);
const projected = object.localToWorld(localAnchor.clone());
projected.project(camera);
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const halfWidth = element.offsetWidth * 0.5;
const clampedX = THREE.MathUtils.clamp(
x,
halfWidth + 12,
window.innerWidth - halfWidth - 12
);
element.style.left = `${clampedX}px`;
element.style.top = `${Math.max(126, y + 7)}px`;
}
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (playing) {
progress = Math.min(1, progress + delta / duration);
if (progress >= 1) playing = false;
applyProgress();
}
// Smooth camera orbit.
const damping = 1 - Math.pow(0.001, delta);
orbitCurrent.yaw = THREE.MathUtils.lerp(
orbitCurrent.yaw,
orbitGoal.yaw,
damping
);
orbitCurrent.pitch = THREE.MathUtils.lerp(
orbitCurrent.pitch,
orbitGoal.pitch,
damping
);
orbitCurrent.radius = THREE.MathUtils.lerp(
orbitCurrent.radius,
orbitGoal.radius,
damping
);
const { yaw, pitch, radius } = orbitCurrent;
camera.position.set(
cameraTarget.x + radius * Math.sin(yaw) * Math.cos(pitch),
cameraTarget.y + radius * Math.sin(pitch),
cameraTarget.z + radius * Math.cos(yaw) * Math.cos(pitch)
);
camera.lookAt(cameraTarget);
dust.rotation.y = elapsed * 0.014;
dust.rotation.x = Math.sin(elapsed * 0.07) * 0.025;
expansionRing.material.opacity +=
Math.sin(elapsed * 2.1) * 0.0025;
expansionRing.material.opacity = THREE.MathUtils.clamp(
expansionRing.material.opacity,
0.035,
0.23
);
positionLabel(rootLabel, rootModel, rootAnchor);
positionLabel(iceLabel, iceModel, iceAnchor);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```