Prompt specification
Build or customize the Three.js 3D scene "Elephant foot and water-edge scale" 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: Elephant foot and water-edge scale
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/elephant-foot-and-water-edge-scale-x0677
Scene Description Prompt:
Elephant foot and water-edge scale. Show an adult and calf elephant beside a shallow water-edge model; compare their leg lengths and reach while keeping the same ground and water reference planes. Please build this with Three.js from cdnjs in one self-contained HTML file, using visible voxel blocks.
Working Three.js Starter (elephant-foot-and-water-edge-scale-x0677):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Elephant Foot and Water-Edge Scale</title>
<style>
:root {
--ink: #24312e;
--muted: #68736f;
--paper: rgba(255, 255, 255, 0.91);
--adult: #247d73;
--calf: #c85f50;
--leg: #d99a2b;
--reach: #258e9d;
--water: #3f91ad;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8ede9;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#labels {
position: fixed;
inset: 0;
}
#app canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#app canvas:active {
cursor: grabbing;
}
#labels {
pointer-events: none;
overflow: hidden;
z-index: 3;
}
.panel {
position: fixed;
z-index: 5;
background: var(--paper);
border: 1px solid rgba(36, 49, 46, 0.12);
box-shadow: 0 12px 35px rgba(34, 47, 43, 0.12);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#title-card {
top: 20px;
left: 20px;
width: min(430px, calc(100vw - 40px));
padding: 17px 19px 15px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(21px, 2.6vw, 30px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 8px 0 13px;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
padding-top: 11px;
border-top: 1px solid rgba(36, 49, 46, 0.11);
color: #56625e;
font-size: 11px;
font-weight: 650;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.swatch.adult { background: var(--adult); }
.swatch.calf { background: var(--calf); }
.swatch.leg { background: var(--leg); }
.swatch.reach { background: var(--reach); }
#stats-card {
right: 20px;
bottom: 20px;
width: min(390px, calc(100vw - 40px));
padding: 15px 17px 14px;
border-radius: 16px;
}
.stats-heading {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 14px;
margin-bottom: 9px;
}
.stats-heading strong {
font-size: 13px;
}
.stats-heading span {
color: var(--muted);
font-size: 10px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 11px;
}
th,
td {
padding: 8px 6px;
border-bottom: 1px solid rgba(36, 49, 46, 0.09);
text-align: right;
white-space: nowrap;
}
th:first-child,
td:first-child {
padding-left: 0;
text-align: left;
}
thead th {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.09em;
text-transform: uppercase;
}
tbody td:first-child {
color: #56625e;
}
.value {
font-variant-numeric: tabular-nums;
font-weight: 800;
}
.species {
display: inline-flex;
align-items: center;
gap: 5px;
}
.species::before {
content: "";
width: 7px;
height: 7px;
border-radius: 2px;
background: currentColor;
}
.species.adult { color: var(--adult); }
.species.calf { color: var(--calf); }
.stats-note {
margin-top: 10px;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
#controls-hint {
left: 20px;
bottom: 20px;
padding: 9px 12px;
border-radius: 11px;
color: #5b6763;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
padding: 5px 8px;
border: 1px solid rgba(36, 49, 46, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.91);
box-shadow: 0 4px 15px rgba(34, 47, 43, 0.11);
color: #33413d;
font-size: 10px;
font-weight: 800;
line-height: 1;
letter-spacing: 0.015em;
white-space: nowrap;
}
.world-label.adult {
border-color: rgba(36, 125, 115, 0.42);
color: var(--adult);
}
.world-label.calf {
border-color: rgba(200, 95, 80, 0.42);
color: var(--calf);
}
.world-label.measure {
padding: 4px 7px;
background: rgba(255, 255, 255, 0.94);
font-variant-numeric: tabular-nums;
}
.world-label.datum {
background: rgba(255, 255, 255, 0.88);
color: #665d4c;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.world-label.water {
color: #267d99;
}
@media (max-width: 760px) {
#title-card {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.subtitle {
margin-bottom: 9px;
}
.legend {
gap: 6px 10px;
}
#stats-card {
right: 12px;
bottom: 12px;
width: calc(100vw - 24px);
}
#controls-hint {
display: none;
}
.world-label {
font-size: 9px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div id="labels"></div>
<section id="title-card" class="panel">
<div class="eyebrow">Shared-scale voxel study</div>
<h1>Elephant foot & water-edge scale</h1>
<p class="subtitle">
Adult and calf share the same ground datum and shallow-water plane.
Gold bars compare leg length; blue bars compare forward trunk reach.
</p>
<div class="legend">
<span><i class="swatch adult"></i>Adult</span>
<span><i class="swatch calf"></i>Calf</span>
<span><i class="swatch leg"></i>Leg length</span>
<span><i class="swatch reach"></i>Forward reach</span>
</div>
</section>
<section id="stats-card" class="panel">
<div class="stats-heading">
<strong>Shared-scale measurements</strong>
<span>metres</span>
</div>
<table>
<thead>
<tr>
<th>Reference</th>
<th><span class="species adult">Adult</span></th>
<th><span class="species calf">Calf</span></th>
</tr>
</thead>
<tbody>
<tr>
<td>Ground → shoulder</td>
<td class="value">2.40 m</td>
<td class="value">1.34 m</td>
</tr>
<tr>
<td>Shoulder → trunk tip</td>
<td class="value">2.70 m</td>
<td class="value">1.51 m</td>
</tr>
<tr>
<td>Overall height</td>
<td class="value">4.05 m</td>
<td class="value">2.27 m</td>
</tr>
<tr>
<td>Adult ÷ calf</td>
<td class="value" colspan="2">1.79× scale</td>
</tr>
<tr>
<td>Water surface below ground</td>
<td class="value" colspan="2">0.18 m</td>
</tr>
</tbody>
</table>
<div class="stats-note">
Reach begins at the shoulder projection on the ground-referenced x-axis
and ends at the forward-most trunk block. Both animals use identical
world units and reference planes.
</div>
</section>
<div id="controls-hint" class="panel">
Drag: orbit · Shift-drag: pan · Wheel: zoom · Double-click: reset
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------
// Renderer, scene, and camera
// ------------------------------------------------------------
const app = document.getElementById("app");
const labelLayer = document.getElementById("labels");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive voxel elephant and water-edge scale model"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8ede9);
scene.fog = new THREE.Fog(0xe8ede9, 24, 43);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const controls = {
target: new THREE.Vector3(0, 1.65, -0.35),
theta: 0,
phi: 1.08,
distance: 18,
zoom: 1
};
const baseWidth = 17.5;
const baseHeight = 10.5;
function updateProjection() {
const aspect = window.innerWidth / window.innerHeight;
const height = Math.max(baseHeight, baseWidth / aspect) / controls.zoom;
const width = height * aspect;
camera.left = -width / 2;
camera.right = width / 2;
camera.top = height / 2;
camera.bottom = -height / 2;
camera.updateProjectionMatrix();
}
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.distance * cosPhi,
controls.target.z +
controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
camera.updateMatrixWorld();
updateProjection();
}
updateCamera();
// ------------------------------------------------------------
// Lighting
// ------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xffffff,
0x66706b,
2.05
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff6df, 3.15);
keyLight.position.set(-7, 13, 9);
keyLight.target.position.set(0, 1.3, 0);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight, keyLight.target);
const rimLight = new THREE.DirectionalLight(0xcce8ed, 1.25);
rimLight.position.set(8, 6, -8);
scene.add(rimLight);
// ------------------------------------------------------------
// Shared materials and primitive geometry
// ------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const materials = {
adultBody: new THREE.MeshStandardMaterial({
color: 0x87928e,
roughness: 0.92,
metalness: 0
}),
adultLight: new THREE.MeshStandardMaterial({
color: 0x9ca5a1,
roughness: 0.92
}),
adultDark: new THREE.MeshStandardMaterial({
color: 0x707c78,
roughness: 0.95
}),
adultFoot: new THREE.MeshStandardMaterial({
color: 0x68736f,
roughness: 0.98
}),
calfBody: new THREE.MeshStandardMaterial({
color: 0x9b958a,
roughness: 0.93
}),
calfLight: new THREE.MeshStandardMaterial({
color: 0xada69a,
roughness: 0.93
}),
calfDark: new THREE.MeshStandardMaterial({
color: 0x847d73,
roughness: 0.95
}),
calfFoot: new THREE.MeshStandardMaterial({
color: 0x756f67,
roughness: 0.98
}),
eye: new THREE.MeshStandardMaterial({
color: 0x151b19,
roughness: 0.48
}),
ivory: new THREE.MeshStandardMaterial({
color: 0xf1e4c5,
roughness: 0.76
})
};
// ------------------------------------------------------------
// Instanced voxel batching
// ------------------------------------------------------------
class VoxelBatch {
constructor(parent, materialMap) {
this.parent = parent;
this.materialMap = materialMap;
this.entries = new Map();
this.matrix = new THREE.Matrix4();
this.position = new THREE.Vector3();
this.quaternion = new THREE.Quaternion();
this.scale = new THREE.Vector3();
}
add(materialKey, x, y, z, sx, sy, sz) {
if (!this.entries.has(materialKey)) {
this.entries.set(materialKey, []);
}
this.position.set(x, y, z);
this.scale.set(sx, sy, sz);
this.matrix.compose(
this.position,
this.quaternion,
this.scale
);
this.entries.get(materialKey).push(this.matrix.clone());
}
ellipsoid(
materialKey,
center,
radii,
step,
minimumNormalizedRadiusSquared = 0
) {
const nx = Math.ceil(radii[0] / step);
const ny = Math.ceil(radii[1] / step);
const nz = Math.ceil(radii[2] / step);
for (let ix = -nx; ix <= nx; ix++) {
for (let iy = -ny; iy <= ny; iy++) {
for (let iz = -nz; iz <= nz; iz++) {
const dx = (ix * step) / radii[0];
const dy = (iy * step) / radii[1];
const dz = (iz * step) / radii[2];
const q = dx * dx + dy * dy + dz * dz;
if (
q <= 1 &&
q >= minimumNormalizedRadiusSquared
) {
this.add(
materialKey,
center[0] + ix * step,
center[1] + iy * step,
center[2] + iz * step,
step * 0.94,
step * 0.94,
step * 0.94
);
}
}
}
}
}
flush() {
for (const [materialKey, matrices] of this.entries) {
const mesh = new THREE.InstancedMesh(
unitBox,
this.materialMap[materialKey],
matrices.length
);
matrices.forEach((matrix, index) => {
mesh.setMatrixAt(index, matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
this.parent.add(mesh);
}
}
}
// ------------------------------------------------------------
// Voxel elephant
//
// Local adult dimensions:
// leg length: 2.40 m
// shoulder datum x: 0.75 m
// forward trunk tip: x = 3.45 m
// forward reach: 2.70 m
// ------------------------------------------------------------
function makeElephant({
x,
z,
scale,
bodyKey,
lightKey,
darkKey,
footKey
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
group.scale.setScalar(scale);
scene.add(group);
const batch = new VoxelBatch(group, materials);
// Four block-built legs. Their upper surfaces align with y = 2.40.
const legX = [-0.85, 0.85];
const legZ = [-0.56, 0.56];
for (const lx of legX) {
for (const lz of legZ) {
for (let level = 0; level < 5; level++) {
const width = 0.48 + level * 0.025;
batch.add(
level === 0 ? footKey : bodyKey,
lx,
0.24 + level * 0.48,
lz,
width,
0.46,
width
);
}
// Small ivory toenail blocks on the forward-facing foot edge.
for (const toeOffset of [-0.13, 0.13]) {
batch.add(
"ivory",
lx + 0.31,
0.12,
lz + toeOffset,
0.10,
0.14,
0.11
);
}
}
}
// Main torso, head, and ears.
batch.ellipsoid(bodyKey, [0, 3.05, 0], [1.40, 1.00, 0.85], 0.29);
batch.ellipsoid(lightKey, [1.30, 3.05, 0], [0.72, 0.86, 0.70], 0.27);
batch.ellipsoid(darkKey, [0.84, 3.16, 0.76], [0.75, 0.98, 0.24], 0.22);
batch.ellipsoid(darkKey, [0.84, 3.16, -0.76], [0.75, 0.98, 0.24], 0.22);
// Pixel-like ear highlights.
batch.ellipsoid(lightKey, [0.86, 3.17, 0.91], [0.54, 0.70, 0.12], 0.18);
batch.ellipsoid(lightKey, [0.86, 3.17, -0.91], [0.54, 0.70, 0.12], 0.18);
// Trunk: a descending, forward-curving chain of visible cube blocks.
const trunkPath = [
[1.68, 3.35],
[1.98, 3.02],
[2.16, 2.68],
[2.29, 2.32],
[2.39, 1.97],
[2.57, 1.69],
[2.80, 1.55],
[3.03, 1.57],
[3.24, 1.72]
];
for (const [tx, ty] of trunkPath) {
batch.add(darkKey, tx, ty, 0, 0.40, 0.40, 0.40);
}
// Tusks, constructed from small ivory blocks.
for (const tuskZ of [-0.29, 0.29]) {
batch.add("ivory", 1.84, 2.79, tuskZ, 0.22, 0.22, 0.22);
batch.add("ivory", 2.06, 2.66, tuskZ, 0.22, 0.22, 0.22);
batch.add("ivory", 2.28, 2.53, tuskZ, 0.22, 0.22, 0.22);
}
// Eyes on both visible head sides.
batch.add("eye", 1.55, 3.43, 0.59, 0.16, 0.16, 0.13);
batch.add("eye", 1.55, 3.43, -0.59, 0.16, 0.16, 0.13);
// Tail.
const tailPath = [
[-1.34, 3.00],
[-1.43, 2.78],
[-1.46, 2.55],
[-1.42, 2.31],
[-1.50, 2.10]
];
for (const [tailX, tailY] of tailPath) {
batch.add(darkKey, tailX, tailY, 0, 0.19, 0.19, 0.19);
}
batch.flush();
return group;
}
const ADULT_X = -3.40;
const CALF_X = 2.20;
const ELEPHANT_Z = -0.78;
const CALF_SCALE = 0.56;
makeElephant({
x: ADULT_X,
z: ELEPHANT_Z,
scale: 1,
bodyKey: "adultBody",
lightKey: "adultLight",
darkKey: "adultDark",
footKey: "adultFoot"
});
makeElephant({
x: CALF_X,
z: ELEPHANT_Z,
scale: CALF_SCALE,
bodyKey: "calfBody",
lightKey: "calfLight",
darkKey: "calfDark",
footKey: "calfFoot"
});
// ------------------------------------------------------------
// Voxel land and shallow water
// ------------------------------------------------------------
const landMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.98,
metalness: 0
});
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.22,
metalness: 0.03,
transparent: true,
opacity: 0.76,
depthWrite: false
});
const landCount = 16 * 8;
const land = new THREE.InstancedMesh(
unitBox,
landMaterial,
landCount
);
const terrainMatrix = new THREE.Matrix4();
const terrainPosition = new THREE.Vector3();
const terrainScale = new THREE.Vector3();
const terrainQuaternion = new THREE.Quaternion();
const terrainColor = new THREE.Color();
let terrainIndex = 0;
for (let ix = 0; ix < 16; ix++) {
for (let iz = 0; iz < 8; iz++) {
terrainPosition.set(-7.5 + ix, -0.18, -5.5 + iz);
terrainScale.set(0.94, 0.36, 0.94);
terrainMatrix.compose(
terrainPosition,
terrainQuaternion,
terrainScale
);
land.setMatrixAt(terrainIndex, terrainMatrix);
terrainColor.setHSL(
0.105 + Math.sin(ix * 1.73 + iz * 0.91) * 0.006,
0.25,
0.57 + Math.sin(ix * 2.1 + iz * 1.4) * 0.035
);
land.setColorAt(terrainIndex, terrainColor);
terrainIndex++;
}
}
land.instanceMatrix.needsUpdate = true;
land.instanceColor.needsUpdate = true;
land.castShadow = true;
land.receiveShadow = true;
scene.add(land);
const waterCount = 16 * 4;
const water = new THREE.InstancedMesh(
unitBox,
waterMaterial,
waterCount
);
terrainIndex = 0;
for (let ix = 0; ix < 16; ix++) {
for (let iz = 0; iz < 4; iz++) {
terrainPosition.set(-7.5 + ix, -0.27, 2.5 + iz);
terrainScale.set(0.94, 0.18, 0.94);
terrainMatrix.compose(
terrainPosition,
terrainQuaternion,
terrainScale
);
water.setMatrixAt(terrainIndex, terrainMatrix);
terrainColor.setHSL(
0.525 + Math.sin(ix * 1.4 + iz * 0.8) * 0.009,
0.34,
0.58 + Math.sin(ix * 1.9 + iz * 1.7) * 0.045
);
water.setColorAt(terrainIndex, terrainColor);
terrainIndex++;
}
}
water.instanceMatrix.needsUpdate = true;
water.instanceColor.needsUpdate = true;
water.receiveShadow = true;
scene.add(water);
// ------------------------------------------------------------
// Shared datum planes, outlines, and grids
// ------------------------------------------------------------
function addReferencePlane(
width,
depth,
centerZ,
y,
color,
opacity
) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity,
side: THREE.DoubleSide,
depthWrite: false
});
const plane = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
material
);
plane.rotation.x = -Math.PI / 2;
plane.position.set(0, y, centerZ);
plane.renderOrder = 2;
scene.add(plane);
}
addReferencePlane(16, 8, -2, 0.008, 0xc59b61, 0.065);
addReferencePlane(16, 4, 4, -0.172, 0x3f9ab7, 0.14);
function addGrid(width, minZ, maxZ, y, color, opacity) {
const points = [];
for (let x = -width / 2; x <= width / 2; x++) {
points.push(
new THREE.Vector3(x, y, minZ),
new THREE.Vector3(x, y, maxZ)
);
}
for (let z = minZ; z <= maxZ; z++) {
points.push(
new THREE.Vector3(-width / 2, y, z),
new THREE.Vector3(width / 2, y, z)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const grid = new THREE.LineSegments(geometry, material);
grid.renderOrder = 3;
scene.add(grid);
}
addGrid(16, -6, 2, 0.014, 0x806c50, 0.22);
addGrid(16, 2, 6, -0.168, 0x287d9c, 0.24);
function addPlaneOutline(
width,
minZ,
maxZ,
y,
color,
opacity
) {
const points = [
new THREE.Vector3(-width / 2, y, minZ),
new THREE.Vector3(width / 2, y, minZ),
new THREE.Vector3(width / 2, y, maxZ),
new THREE.Vector3(-width / 2, y, maxZ),
new THREE.Vector3(-width / 2, y, minZ)
];
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineDashedMaterial({
color,
dashSize: 0.32,
gapSize: 0.16,
transparent: true,
opacity,
depthWrite: false
});
const outline = new THREE.Line(geometry, material);
outline.computeLineDistances();
outline.renderOrder = 4;
scene.add(outline);
}
addPlaneOutline(16, -6, 2, 0.019, 0x826b45, 0.65);
addPlaneOutline(16, 2, 6, -0.164, 0x237c9a, 0.75);
// ------------------------------------------------------------
// Small voxel reeds to identify the shoreline
// ------------------------------------------------------------
const reedMaterial = new THREE.MeshStandardMaterial({
color: 0x66865b,
roughness: 0.9
});
const reedLightMaterial = new THREE.MeshStandardMaterial({
color: 0x91a76f,
roughness: 0.9
});
function addReedCluster(x, z, count) {
for (let i = 0; i < count; i++) {
const stem = new THREE.Mesh(unitBox, reedMaterial);
const height = 0.48 + (i % 3) * 0.15;
stem.position.set(
x + (i % 2) * 0.12,
height / 2,
z + Math.floor(i / 2) * 0.08
);
stem.scale.set(0.075, height, 0.075);
stem.castShadow = true;
scene.add(stem);
const leaf = new THREE.Mesh(unitBox, reedLightMaterial);
leaf.position.set(
stem.position.x + 0.07,
height * 0.66,
stem.position.z
);
leaf.scale.set(0.28, 0.07, 0.09);
leaf.castShadow = true;
scene.add(leaf);
}
}
addReedCluster(-6.3, 1.94, 5);
addReedCluster(-4.9, 1.92, 3);
addReedCluster(6.1, 1.94, 4);
// ------------------------------------------------------------
// Measurement bars
// ------------------------------------------------------------
const legMeasureMaterial = new THREE.MeshBasicMaterial({
color: 0xd99a2b,
depthTest: false
});
const reachMeasureMaterial = new THREE.MeshBasicMaterial({
color: 0x258e9d,
depthTest: false
});
function addBox(
material,
x,
y,
z,
width,
height,
depth
) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
mesh.renderOrder = 10;
scene.add(mesh);
return mesh;
}
function addVerticalMeasure(x, z, length, material) {
addBox(material, x, length / 2, z, 0.045, length, 0.045);
addBox(material, x, 0.018, z, 0.34, 0.045, 0.045);
addBox(material, x, length, z, 0.34, 0.045, 0.045);
}
function addHorizontalMeasure(
startX,
endX,
y,
z,
material
) {
const length = endX - startX;
const middleX = (startX + endX) / 2;
addBox(material, middleX, y, z, length, 0.045, 0.045);
addBox(material, startX, y, z, 0.045, 0.28, 0.045);
addBox(material, endX, y, z, 0.045, 0.28, 0.045);
}
const adultLegLength = 2.40;
const adultReach = 2.70;
const calfLegLength = adultLegLength * CALF_SCALE;
const calfReach = adultReach * CALF_SCALE;
const adultShoulderX = ADULT_X + 0.75;
const adultTrunkTipX = ADULT_X + 3.45;
const calfShoulderX = CALF_X + 0.75 * CALF_SCALE;
const calfTrunkTipX = CALF_X + 3.45 * CALF_SCALE;
addVerticalMeasure(-5.25, 0.28, adultLegLength, legMeasureMaterial);
addVerticalMeasure(0.95, 0.28, calfLegLength, legMeasureMaterial);
addHorizontalMeasure(
adultShoulderX,
adultTrunkTipX,
2.62,
0.62,
reachMeasureMaterial
);
addHorizontalMeasure(
calfShoulderX,
calfTrunkTipX,
2.62 * CALF_SCALE,
0.58,
reachMeasureMaterial
);
// Water-edge step marker.
addVerticalMeasure(-7.40, 2.00, 0.18, reachMeasureMaterial);
// ------------------------------------------------------------
// Screen-space labels anchored to world positions
// ------------------------------------------------------------
const labels = [];
function addLabel(
text,
position,
className = "",
offsetX = 0,
offsetY = 0
) {
const element = document.createElement("div");
element.className = `world-label ${className}`.trim();
element.textContent = text;
labelLayer.appendChild(element);
labels.push({
element,
position: position.clone(),
offsetX,
offsetY
});
}
addLabel(
"ADULT · 2.40 m LEG",
new THREE.Vector3(ADULT_X, 4.48, ELEPHANT_Z),
"adult",
0,
-8
);
addLabel(
"CALF · 1.34 m LEG",
new THREE.Vector3(CALF_X, 2.72, ELEPHANT_Z),
"calf",
0,
-8
);
addLabel(
"LEG 2.40 m",
new THREE.Vector3(-5.25, 2.58, 0.28),
"measure",
-34,
-8
);
addLabel(
"LEG 1.34 m",
new THREE.Vector3(0.95, 1.54, 0.28),
"measure",
-31,
-8
);
addLabel(
"REACH 2.70 m",
new THREE.Vector3(
(adultShoulderX + adultTrunkTipX) / 2,
2.86,
0.62
),
"measure",
0,
-10
);
addLabel(
"REACH 1.51 m",
new THREE.Vector3(
(calfShoulderX + calfTrunkTipX) / 2,
1.61,
0.58
),
"measure",
0,
-10
);
addLabel(
"SHARED GROUND · 0.00 m",
new THREE.Vector3(-6.65, 0.08, 0.65),
"datum",
0,
-5
);
addLabel(
"SHARED WATER PLANE · −0.18 m",
new THREE.Vector3(-6.55, -0.10, 4.05),
"datum water",
0,
-5
);
addLabel(
"0.18 m STEP",
new THREE.Vector3(-7.40, 0.28, 2.00),
"measure",
-37,
-4
);
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.position).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.left = `${x + label.offsetX}px`;
label.element.style.top = `${y + label.offsetY}px`;
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
x > -100 &&
x < width + 100 &&
y > -80 &&
y < height + 80;
label.element.style.opacity = visible ? "1" : "0";
}
}
// ------------------------------------------------------------
// Direct camera controls — no addons
// ------------------------------------------------------------
const pointer = {
active: false,
id: null,
lastX: 0,
lastY: 0,
pan: false
};
renderer.domElement.addEventListener("pointerdown", (event) => {
pointer.active = true;
pointer.id = event.pointerId;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
pointer.pan = event.button === 2 || event.shiftKey;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointer.active || event.pointerId !== pointer.id) {
return;
}
const dx = event.clientX - pointer.lastX;
const dy = event.clientY - pointer.lastY;
pointer.lastX = event.clientX;
pointer.lastY = event.clientY;
if (pointer.pan) {
const worldPerPixel =
(baseHeight / controls.zoom) / window.innerHeight;
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
controls.target.addScaledVector(right, -dx * worldPerPixel);
controls.target.addScaledVector(up, dy * worldPerPixel);
} else {
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.38,
1.46
);
}
updateCamera();
});
function endPointer(event) {
if (event.pointerId !== pointer.id) {
return;
}
pointer.active = false;
pointer.id = null;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.65,
2.40
);
updateProjection();
},
{ passive: false }
);
function resetCamera() {
controls.target.set(0, 1.65, -0.35);
controls.theta = 0;
controls.phi = 1.08;
controls.distance = 18;
controls.zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateProjection();
});
// ------------------------------------------------------------
// Render loop
// ------------------------------------------------------------
renderer.setAnimationLoop(() => {
updateCamera();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```