Prompt specification
Build or customize the Three.js 3D scene "Snow cover and bare ground comparison" 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: Snow cover and bare ground comparison
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/snow-cover-and-bare-ground-comparison-x1202
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring surface albedo. Arrange two miniature slopes with matching sun angle but different surface cover; illustrate contrasting reflected fractions without assuming color alone fully determines real thermal behavior. Stylized solid forms.
Working Three.js Starter (snow-cover-and-bare-ground-comparison-x1202):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Surface Albedo — Same Sun, Different Cover</title>
<style>
:root {
--ink: #183236;
--muted: #617275;
--paper: #f6f2e9;
--glass: rgba(250, 248, 241, 0.9);
--line: rgba(24, 50, 54, 0.14);
--gold: #e9a52f;
--cyan: #198e8a;
--warm: #d96f4c;
--green: #52705a;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
background:
radial-gradient(circle at 70% 12%, rgba(255, 246, 215, 0.8), transparent 35%),
linear-gradient(145deg, #ece8dd 0%, #ddd9cd 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#scene,
#scene canvas {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
#scene canvas {
display: block;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.ui {
position: absolute;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 26px;
left: 30px;
width: min(460px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
margin: 0 0 9px;
color: var(--green);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.brand h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 4.2vw, 62px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.035em;
}
.brand p {
max-width: 410px;
margin: 13px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--line);
border-radius: 18px;
background: var(--glass);
box-shadow:
0 16px 45px rgba(49, 55, 47, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.65);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.controls {
position: absolute;
top: 24px;
right: 24px;
width: 274px;
padding: 17px 18px 15px;
pointer-events: auto;
}
.controls-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 15px;
}
.controls-title strong {
font-size: 12px;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.same-badge {
padding: 5px 8px;
border-radius: 999px;
color: #315f52;
background: rgba(82, 112, 90, 0.12);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.control-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 10px;
font-size: 12px;
font-weight: 700;
}
output {
color: var(--gold);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
margin: 9px 0 2px;
accent-color: var(--gold);
cursor: pointer;
}
.control-actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
cursor: pointer;
}
.toggle input {
width: 15px;
height: 15px;
accent-color: var(--cyan);
}
.reset {
padding: 7px 10px;
border: 1px solid var(--line);
border-radius: 9px;
color: var(--ink);
background: rgba(255, 255, 255, 0.65);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
cursor: pointer;
}
.reset:hover {
background: white;
}
.model-label {
position: absolute;
width: 218px;
padding: 14px 15px 13px;
border: 1px solid rgba(24, 50, 54, 0.13);
border-radius: 15px;
background: rgba(250, 248, 241, 0.94);
box-shadow: 0 13px 32px rgba(46, 55, 48, 0.13);
transform: translate(-50%, -100%);
pointer-events: none;
backdrop-filter: blur(10px);
}
.model-label::after {
position: absolute;
bottom: -16px;
left: 50%;
width: 1px;
height: 16px;
background: rgba(24, 50, 54, 0.25);
content: "";
}
.label-top {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
}
.cover-name {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 20px;
font-weight: 500;
}
.angle-badge {
flex: 0 0 auto;
padding: 4px 7px;
border-radius: 999px;
color: var(--muted);
background: rgba(24, 50, 54, 0.07);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
}
.albedo-line {
display: flex;
align-items: baseline;
justify-content: space-between;
margin-top: 9px;
}
.albedo-line span {
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.albedo-line strong {
color: var(--cyan);
font-size: 23px;
font-variant-numeric: tabular-nums;
}
.fraction-bar {
display: flex;
height: 8px;
margin-top: 7px;
overflow: hidden;
border-radius: 999px;
background: var(--warm);
}
.fraction-bar .reflected {
background: var(--cyan);
}
.fraction-key {
display: flex;
justify-content: space-between;
margin-top: 7px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.legend {
position: absolute;
bottom: 24px;
left: 24px;
width: 260px;
padding: 14px 16px;
}
.legend-title {
margin-bottom: 10px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
margin-top: 7px;
color: var(--muted);
font-size: 11px;
}
.swatch {
width: 22px;
height: 3px;
border-radius: 99px;
background: var(--gold);
}
.swatch.cyan {
background: var(--cyan);
}
.swatch.warm {
background: var(--warm);
}
.legend-note {
margin-top: 11px;
padding-top: 10px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
line-height: 1.45;
}
.insight {
position: absolute;
right: 24px;
bottom: 24px;
width: 365px;
padding: 18px 19px 17px;
}
.insight h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 24px;
font-weight: 500;
line-height: 1.08;
}
.insight p {
margin: 10px 0 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.insight ul {
display: grid;
gap: 6px;
margin: 12px 0 0;
padding: 0;
list-style: none;
}
.insight li {
position: relative;
padding-left: 14px;
color: #41585a;
font-size: 10px;
line-height: 1.45;
}
.insight li::before {
position: absolute;
top: 5px;
left: 0;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--green);
content: "";
}
.hint {
position: absolute;
bottom: 25px;
left: 50%;
padding: 7px 11px;
border-radius: 999px;
color: rgba(24, 50, 54, 0.58);
background: rgba(250, 248, 241, 0.55);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
transform: translateX(-50%);
}
@media (max-width: 900px) {
.brand {
top: 18px;
left: 18px;
}
.brand h1 {
font-size: 38px;
}
.brand p {
max-width: 330px;
font-size: 12px;
}
.controls {
top: 18px;
right: 18px;
width: 235px;
}
.legend {
bottom: 18px;
left: 18px;
width: 225px;
}
.insight {
right: 18px;
bottom: 18px;
width: 320px;
}
.hint {
display: none;
}
}
@media (max-width: 650px) {
.brand {
width: calc(100vw - 36px);
}
.brand h1 {
max-width: 260px;
font-size: 34px;
}
.brand p {
display: none;
}
.controls {
top: 110px;
left: 18px;
right: 18px;
width: auto;
padding: 12px 14px;
}
.controls-title {
margin-bottom: 8px;
}
.model-label {
width: 176px;
padding: 10px 11px;
}
.cover-name {
font-size: 16px;
}
.albedo-line strong {
font-size: 19px;
}
.legend {
display: none;
}
.insight {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 34vh;
overflow: auto;
padding: 14px 15px;
}
.insight h2 {
font-size: 20px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="brand">
<p class="eyebrow">Surface energy comparison</p>
<h1>Same sun.<br />Different cover.</h1>
<p>
Two miniature slopes share the same inclination and receive parallel
sunlight. Compare how surface cover changes the reflected fraction.
</p>
</header>
<section class="controls panel" aria-label="Scene controls">
<div class="controls-title">
<strong>Shared sun geometry</strong>
<span class="same-badge">Both slopes</span>
</div>
<div class="control-row">
<label for="sunElevation">Sun elevation</label>
<output id="sunValue" for="sunElevation">52°</output>
</div>
<input
id="sunElevation"
type="range"
min="25"
max="70"
step="1"
value="52"
/>
<div class="control-actions">
<label class="toggle">
<input id="showArrows" type="checkbox" checked />
Energy arrows
</label>
<button id="resetView" class="reset" type="button">Reset view</button>
</div>
</section>
<div id="snowLabel" class="model-label" aria-label="Snow surface albedo">
<div class="label-top">
<p class="cover-name">Fresh snow</p>
<span class="angle-badge">20° slope</span>
</div>
<div class="albedo-line">
<span>Surface albedo</span>
<strong>0.72</strong>
</div>
<div class="fraction-bar">
<div class="reflected" style="width: 72%"></div>
</div>
<div class="fraction-key">
<span>72% reflected</span>
<span>28% other pathways</span>
</div>
</div>
<div id="forestLabel" class="model-label" aria-label="Forest surface albedo">
<div class="label-top">
<p class="cover-name">Dense vegetation</p>
<span class="angle-badge">20° slope</span>
</div>
<div class="albedo-line">
<span>Surface albedo</span>
<strong>0.16</strong>
</div>
<div class="fraction-bar">
<div class="reflected" style="width: 16%"></div>
</div>
<div class="fraction-key">
<span>16% reflected</span>
<span>84% other pathways</span>
</div>
</div>
<section class="legend panel" aria-label="Energy diagram legend">
<div class="legend-title">Energy key</div>
<div class="legend-row">
<span class="swatch"></span>
<span>Incoming sunlight</span>
</div>
<div class="legend-row">
<span class="swatch cyan"></span>
<span>Reflected fraction</span>
</div>
<div class="legend-row">
<span class="swatch warm"></span>
<span>Absorbed or transmitted</span>
</div>
<div class="legend-note">
Values and arrow lengths are illustrative, not measurements of a
particular snowfield or forest.
</div>
</section>
<aside class="insight panel">
<p class="eyebrow">Read the model, not just the color</p>
<h2>Albedo is a starting point.</h2>
<p>
Albedo describes reflected shortwave energy; it does not by itself
determine real surface temperature.
</p>
<ul>
<li>Moisture, snow depth, and phase changes alter energy balance.</li>
<li>Canopy gaps and roughness change interception and shadowing.</li>
<li>Wind, humidity, evapotranspiration, and longwave exchange matter.</li>
</ul>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</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 sceneRoot = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
sceneRoot.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of snow and forest surfaces under the same sun angle"
);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5da);
scene.fog = new THREE.Fog(0xe9e5da, 19, 32);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
70
);
// ------------------------------------------------------------
// Custom camera controls — no examples/addons are imported.
// ------------------------------------------------------------
const cameraState = {
target: new THREE.Vector3(0, 0.42, 0),
radius: 14.4,
theta: 0.58,
phi: 1.03,
desiredRadius: 14.4,
desiredTheta: 0.58,
desiredPhi: 1.03
};
function updateCamera(instant = false) {
const damping = instant ? 1 : 0.085;
cameraState.radius +=
(cameraState.desiredRadius - cameraState.radius) * damping;
cameraState.theta +=
(cameraState.desiredTheta - cameraState.theta) * damping;
cameraState.phi +=
(cameraState.desiredPhi - cameraState.phi) * damping;
const sinPhi = Math.sin(cameraState.phi);
const cosPhi = Math.cos(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * cosPhi,
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function resetCamera() {
cameraState.desiredRadius = 14.4;
cameraState.desiredTheta = 0.58;
cameraState.desiredPhi = 1.03;
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.desiredTheta -= deltaX * 0.005;
cameraState.desiredPhi = THREE.MathUtils.clamp(
cameraState.desiredPhi - deltaY * 0.005,
0.35,
1.38
);
});
function stopDragging(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.desiredRadius = THREE.MathUtils.clamp(
cameraState.desiredRadius * Math.exp(event.deltaY * 0.001),
8.5,
20
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement) return;
if (event.key === "ArrowLeft") cameraState.desiredTheta += 0.08;
if (event.key === "ArrowRight") cameraState.desiredTheta -= 0.08;
if (event.key === "ArrowUp") cameraState.desiredPhi -= 0.06;
if (event.key === "ArrowDown") cameraState.desiredPhi += 0.06;
if (event.key === "+" || event.key === "=") {
cameraState.desiredRadius = Math.max(
8.5,
cameraState.desiredRadius - 0.7
);
}
if (event.key === "-" || event.key === "_") {
cameraState.desiredRadius = Math.min(
20,
cameraState.desiredRadius + 0.7
);
}
if (event.key.toLowerCase() === "r") resetCamera();
});
// ------------------------------------------------------------
// Lighting and ground
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xeaf4ff,
0x8a735c,
2.05
);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xfff1c7, 3.1);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -11;
sunLight.shadow.camera.right = 11;
sunLight.shadow.camera.top = 11;
sunLight.shadow.camera.bottom = -11;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 35;
sunLight.shadow.bias = -0.00035;
sunLight.shadow.normalBias = 0.025;
scene.add(sunLight);
scene.add(sunLight.target);
const softFill = new THREE.DirectionalLight(0xb7d8e8, 0.55);
softFill.position.set(8, 5, -8);
scene.add(softFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(32, 24),
new THREE.MeshStandardMaterial({
color: 0xded9cc,
roughness: 0.94,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.56;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(22, 22, 0xbeb8aa, 0xd0cabf);
grid.position.y = -0.552;
grid.material.transparent = true;
grid.material.opacity = 0.28;
scene.add(grid);
// ------------------------------------------------------------
// Stylized model geometry
// ------------------------------------------------------------
const modelWidth = 4.55;
const modelDepth = 3.7;
const modelHeight = 1.35;
const modelBottom = -0.3;
const snowCenter = -3.0;
const forestCenter = 3.0;
function createWedgeGeometry(width, depth, height, bottom) {
const w = width / 2;
const d = depth / 2;
const positions = [
-w, height, -d,
w, height, -d,
w, 0, d,
-w, 0, d,
-w, bottom, -d,
w, bottom, -d,
w, bottom, d,
-w, bottom, d
];
const indices = [
0, 2, 1, 0, 3, 2, // top
3, 2, 6, 3, 6, 7, // front
1, 2, 6, 1, 6, 5, // right
0, 5, 4, 0, 1, 5, // back
0, 4, 7, 0, 7, 3, // left
4, 6, 7, 4, 5, 6 // bottom
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createModel(centerX, surfaceMaterial, sideMaterial, plinthMaterial) {
const group = new THREE.Group();
group.position.x = centerX;
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(5.15, 0.2, 4.35),
plinthMaterial
);
plinth.position.y = -0.42;
plinth.castShadow = true;
plinth.receiveShadow = true;
group.add(plinth);
const body = new THREE.Mesh(
createWedgeGeometry(
modelWidth,
modelDepth,
modelHeight,
modelBottom
),
sideMaterial
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const slopeLength = Math.hypot(modelDepth, modelHeight);
const surface = new THREE.Mesh(
new THREE.PlaneGeometry(modelWidth, slopeLength),
surfaceMaterial
);
// This orientation places the surface exactly between the wedge's
// high rear edge and low front edge.
surface.rotation.x = -Math.atan2(modelDepth, modelHeight);
surface.position.set(0, modelHeight / 2, 0);
surface.position.addScaledVector(
new THREE.Vector3(0, 1, modelHeight / modelDepth).normalize(),
0.008
);
surface.castShadow = true;
surface.receiveShadow = true;
group.add(surface);
scene.add(group);
return group;
}
const snowModel = createModel(
snowCenter,
new THREE.MeshStandardMaterial({
color: 0xf4fbff,
roughness: 0.93,
metalness: 0
}),
new THREE.MeshStandardMaterial({
color: 0x78939b,
roughness: 0.9,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xc8c4b9,
roughness: 0.88
})
);
const forestModel = createModel(
forestCenter,
new THREE.MeshStandardMaterial({
color: 0x63875e,
roughness: 0.98,
metalness: 0
}),
new THREE.MeshStandardMaterial({
color: 0x706653,
roughness: 0.94,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0xc7bbaa,
roughness: 0.9
})
);
function surfaceHeight(localZ) {
return (
modelHeight *
(modelDepth / 2 - localZ) /
modelDepth
);
}
// Snow drifts and a few exposed icy rocks.
const snowMoundMaterial = new THREE.MeshStandardMaterial({
color: 0xf8fdff,
roughness: 1
});
[
[-1.3, 0.3, 0.85, 0.13, 0.42],
[0.6, -0.65, 0.65, 0.11, 0.34],
[1.4, 0.85, 0.5, 0.09, 0.3]
].forEach(([x, z, sx, sy, sz]) => {
const mound = new THREE.Mesh(
new THREE.SphereGeometry(0.5, 14, 8),
snowMoundMaterial
);
mound.position.set(x, surfaceHeight(z) + 0.015, z);
mound.scale.set(sx, sy, sz);
mound.castShadow = true;
mound.receiveShadow = true;
snowModel.add(mound);
});
const iceRockMaterial = new THREE.MeshStandardMaterial({
color: 0xaec4ca,
roughness: 0.86,
flatShading: true
});
[
[-0.25, 0.85, 0.25],
[1.55, -0.35, 0.2]
].forEach(([x, z, size]) => {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
iceRockMaterial
);
rock.position.set(x, surfaceHeight(z) + size * 0.7, z);
rock.rotation.set(0.25, x, 0.2);
rock.castShadow = true;
rock.receiveShadow = true;
snowModel.add(rock);
});
// Stylized conifer cover.
const trunkMaterial = new THREE.MeshStandardMaterial({
color: 0x6a4d37,
roughness: 1
});
const foliageMaterials = [
new THREE.MeshStandardMaterial({
color: 0x294f43,
roughness: 1,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x3f6b4e,
roughness: 1,
flatShading: true
})
];
function createTree(scale, materialIndex) {
const tree = new THREE.Group();
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.065, 0.3, 6),
trunkMaterial
);
trunk.position.y = 0.15;
trunk.castShadow = true;
tree.add(trunk);
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.27, 0.68, 7),
foliageMaterials[materialIndex]
);
lower.position.y = 0.48;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.5, 7),
foliageMaterials[materialIndex]
);
upper.position.y = 0.78;
upper.castShadow = true;
tree.add(upper);
tree.scale.setScalar(scale);
return tree;
}
const treePositions = [
[-1.55, -0.75, 0.86, 0],
[-0.65, -1.12, 1.0, 1],
[0.25, -1.25, 0.78, 0],
[1.3, -0.72, 0.9, 1],
[-1.65, 0.42, 0.68, 1],
[-0.92, -0.02, 0.76, 0],
[0.68, 0.62, 0.7, 1],
[1.55, 0.68, 0.62, 0]
];
treePositions.forEach(([x, z, scale, materialIndex]) => {
const tree = createTree(scale, materialIndex);
tree.position.set(x, surfaceHeight(z), z);
tree.rotation.y = (x + z) * 1.7;
forestModel.add(tree);
});
const shrubMaterial = new THREE.MeshStandardMaterial({
color: 0x789566,
roughness: 1,
flatShading: true
});
[
[-0.2, 0.8, 0.28],
[1.0, -0.15, 0.23],
[-1.15, 0.95, 0.22]
].forEach(([x, z, size]) => {
const shrub = new THREE.Mesh(
new THREE.DodecahedronGeometry(size, 0),
shrubMaterial
);
shrub.position.set(x, surfaceHeight(z) + size * 0.6, z);
shrub.scale.y = 0.7;
shrub.castShadow = true;
forestModel.add(shrub);
});
// ------------------------------------------------------------
// Sun marker and parallel energy arrows
// ------------------------------------------------------------
function createSunTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
64,
64,
4,
64,
64,
64
);
gradient.addColorStop(0, "rgba(255,248,203,1)");
gradient.addColorStop(0.3, "rgba(255,218,107,0.9)");
gradient.addColorStop(0.58, "rgba(244,177,52,0.38)");
gradient.addColorStop(1, "rgba(244,177,52,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
return new THREE.CanvasTexture(canvas);
}
const sunSprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: createSunTexture(),
transparent: true,
depthWrite: false,
toneMapped: false
})
);
sunSprite.scale.set(2.7, 2.7, 1);
scene.add(sunSprite);
const energyGroup = new THREE.Group();
scene.add(energyGroup);
const incomingColor = new THREE.Color(0xe6a128);
const reflectedColor = new THREE.Color(0x168d89);
function createEnergyModel(centerX, albedo) {
const target = new THREE.Vector3(
centerX - 1.05,
surfaceHeight(0.35),
0.35
);
const incoming = new THREE.ArrowHelper(
new THREE.Vector3(0, -1, 0),
target,
1,
incomingColor,
0.35,
0.19
);
const reflected = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
target,
1,
reflectedColor,
0.25,
0.15
);
incoming.line.material.transparent = true;
incoming.line.material.opacity = 0.92;
incoming.cone.material.transparent = true;
incoming.cone.material.opacity = 0.95;
reflected.line.material.transparent = true;
reflected.line.material.opacity = 0.95;
reflected.cone.material.transparent = true;
reflected.cone.material.opacity = 0.98;
energyGroup.add(incoming);
energyGroup.add(reflected);
return { target, incoming, reflected, albedo };
}
const energyModels = [
createEnergyModel(snowCenter, 0.72),
createEnergyModel(forestCenter, 0.16)
];
let rayDirection = new THREE.Vector3(0.4, -0.8, -0.4).normalize();
function updateSun() {
const elevation = Number(
document.getElementById("sunElevation").value
);
document.getElementById("sunValue").value = `${elevation}°`;
const elevationRadians = THREE.MathUtils.degToRad(elevation);
const sourceRadius = 11;
const horizontalRadius = Math.cos(elevationRadians) * sourceRadius;
// Both models use this same parallel ray direction.
const sourceOffset = new THREE.Vector3(
-0.62 * horizontalRadius,
Math.sin(elevationRadians) * sourceRadius,
0.68 * horizontalRadius
);
rayDirection = sourceOffset.clone().normalize().negate();
sunLight.position.copy(sourceOffset).multiplyScalar(1.35);
sunLight.target.position.set(0, 0.2, 0);
sunLight.target.updateMatrixWorld();
sunSprite.position.copy(sourceOffset).multiplyScalar(1.2);
const reflectedDirection = new THREE.Vector3(
-rayDirection.x * 0.18,
1,
-rayDirection.z * 0.18
).normalize();
const surfaceNormal = new THREE.Vector3(
0,
1,
modelHeight / modelDepth
).normalize();
energyModels.forEach((model) => {
const incomingStart = model.target
.clone()
.addScaledVector(rayDirection, 3.05);
model.incoming.position.copy(incomingStart);
model.incoming.setDirection(rayDirection);
model.incoming.setLength(2.9, 0.34, 0.18);
model.reflected.position
.copy(model.target)
.addScaledVector(surfaceNormal, 0.1);
model.reflected.setDirection(reflectedDirection);
model.reflected.setLength(
0.35 + model.albedo * 2.55,
0.25,
0.14
);
});
}
document
.getElementById("sunElevation")
.addEventListener("input", updateSun);
document
.getElementById("showArrows")
.addEventListener("change", (event) => {
energyGroup.visible = event.target.checked;
});
document
.getElementById("resetView")
.addEventListener("click", resetCamera);
updateSun();
updateCamera(true);
// ------------------------------------------------------------
// Project the two HTML callouts into the 3D scene.
// ------------------------------------------------------------
const snowLabel = document.getElementById("snowLabel");
const forestLabel = document.getElementById("forestLabel");
const snowLabelPosition = new THREE.Vector3(
snowCenter,
2.48,
0.25
);
const forestLabelPosition = new THREE.Vector3(
forestCenter,
2.48,
0.25
);
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "block" : "none";
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
renderer.setAnimationLoop(() => {
updateCamera();
positionLabel(snowLabel, snowLabelPosition);
positionLabel(forestLabel, forestLabelPosition);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```