Prompt specification
Build or customize the Three.js 3D scene "Convergent desert plant exhibit" 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: Convergent desert plant exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/convergent-desert-plant-exhibit-x0895
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts convergent evolution. Compose unrelated succulent-like plant forms with water-storage features beside a simplified relationship tree; state that similar appearance can emerge independently under comparable pressures. Voxel style.
Working Three.js Starter (convergent-desert-plant-exhibit-x0895):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Convergent Evolution — Voxel Field Study</title>
<style>
:root {
--ink: #26352f;
--paper: #f5f0e4;
--green: #397f68;
--plum: #87536f;
--gold: #d58a35;
--water: #258ca2;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
color: var(--ink);
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;
}
.panel {
position: fixed;
z-index: 10;
pointer-events: none;
}
#intro {
top: 24px;
left: 28px;
max-width: 440px;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
padding: 6px 10px;
border: 1px solid rgba(38, 53, 47, 0.18);
border-radius: 999px;
background: rgba(255, 252, 244, 0.82);
color: #52665c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.eyebrow::before {
width: 7px;
height: 7px;
content: "";
background: var(--gold);
box-shadow: 0 0 0 3px rgba(213, 138, 53, 0.16);
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 850;
letter-spacing: -0.055em;
line-height: 0.96;
}
#intro p {
max-width: 370px;
margin: 13px 0 0;
color: #617068;
font-size: 13px;
line-height: 1.55;
}
#key {
top: 25px;
right: 26px;
display: grid;
gap: 9px;
min-width: 215px;
padding: 14px 16px;
border: 1px solid rgba(38, 53, 47, 0.14);
border-radius: 12px;
background: rgba(255, 252, 244, 0.88);
box-shadow: 0 12px 30px rgba(49, 57, 46, 0.08);
backdrop-filter: blur(10px);
}
.key-row {
display: flex;
align-items: center;
gap: 9px;
color: #53645b;
font-size: 11px;
line-height: 1.35;
}
.swatch {
flex: 0 0 auto;
width: 12px;
height: 12px;
border-radius: 3px;
box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}
.swatch.a {
background: var(--green);
}
.swatch.b {
background: var(--plum);
}
.swatch.tree {
background: #a77b4f;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.tag {
position: absolute;
min-width: 108px;
padding: 8px 10px;
border: 1px solid rgba(38, 53, 47, 0.15);
border-left: 4px solid var(--accent, #738179);
border-radius: 7px;
background: rgba(255, 253, 247, 0.91);
box-shadow: 0 8px 20px rgba(42, 54, 47, 0.1);
color: #34463e;
font-size: 10px;
font-weight: 760;
letter-spacing: 0.035em;
line-height: 1.25;
text-align: left;
white-space: nowrap;
transform: translate(-50%, -50%);
transition: opacity 120ms linear;
backdrop-filter: blur(6px);
}
.tag small {
display: block;
margin-top: 3px;
color: #748078;
font-size: 9px;
font-weight: 550;
letter-spacing: 0.025em;
}
.tag.water {
min-width: 90px;
color: #176d80;
font-size: 9px;
}
.tag.pressure {
color: #86501e;
}
#statement {
right: 24px;
bottom: 22px;
left: 24px;
display: flex;
align-items: center;
justify-content: center;
gap: 18px;
padding: 14px 18px;
border: 1px solid rgba(38, 53, 47, 0.14);
border-radius: 12px;
background: rgba(255, 252, 244, 0.92);
box-shadow: 0 15px 40px rgba(44, 55, 46, 0.12);
backdrop-filter: blur(12px);
}
#statement .symbol {
display: grid;
flex: 0 0 38px;
width: 38px;
height: 38px;
place-items: center;
border-radius: 9px;
background: #e7ead8;
color: #63704c;
font-size: 22px;
font-weight: 800;
}
#statement strong {
display: block;
font-size: clamp(13px, 1.4vw, 17px);
line-height: 1.3;
}
#statement small {
display: block;
margin-top: 3px;
color: #718078;
font-size: 10px;
line-height: 1.35;
}
#controls {
position: fixed;
right: 27px;
bottom: 106px;
z-index: 12;
display: flex;
align-items: center;
gap: 10px;
color: #627068;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.06em;
}
#reset {
padding: 8px 11px;
border: 1px solid rgba(38, 53, 47, 0.16);
border-radius: 8px;
background: rgba(255, 252, 244, 0.9);
color: #52635a;
font: inherit;
font-size: 10px;
font-weight: 750;
cursor: pointer;
box-shadow: 0 7px 18px rgba(42, 54, 47, 0.08);
}
#reset:hover {
background: white;
color: #25372f;
}
@media (max-width: 760px) {
#intro {
top: 18px;
left: 18px;
max-width: 290px;
}
#intro p,
#key,
.minor {
display: none;
}
#statement {
right: 12px;
bottom: 12px;
left: 12px;
gap: 11px;
padding: 11px 13px;
}
#statement .symbol {
flex-basis: 30px;
width: 30px;
height: 30px;
}
#controls {
right: 15px;
bottom: 92px;
}
.control-copy {
display: none;
}
.tag {
padding: 6px 7px;
font-size: 8px;
}
.tag small {
font-size: 7px;
}
}
</style>
</head>
<body>
<header id="intro" class="panel">
<div class="eyebrow">Voxel field study · biology</div>
<h1>Convergent<br>Evolution</h1>
<p>
Two distant plant lineages independently evolve compact, water-storing
forms under the same environmental pressures.
</p>
</header>
<aside id="key" class="panel" aria-label="Color key">
<div class="key-row">
<span class="swatch a"></span>
<span>Lineage A: cactus-like growth form</span>
</div>
<div class="key-row">
<span class="swatch b"></span>
<span>Lineage B: rosette succulent form</span>
</div>
<div class="key-row">
<span class="swatch tree"></span>
<span>Brown trunk: shared ancient ancestry</span>
</div>
</aside>
<div id="labels" aria-hidden="true">
<div id="tag-tree" class="tag" style="--accent:#a77b4f">
SIMPLIFIED RELATIONSHIP TREE
<small>shared root · distinct branches</small>
</div>
<div id="tag-a" class="tag" style="--accent:#397f68">
CACTUS-LIKE
<small>distant lineage A</small>
</div>
<div id="tag-b" class="tag" style="--accent:#87536f">
ALOE-LIKE
<small>distant lineage B</small>
</div>
<div id="tag-water-a" class="tag water minor" style="--accent:#258ca2">
WATER-STORE
<small>thick internal tissue</small>
</div>
<div id="tag-water-b" class="tag water minor" style="--accent:#258ca2">
WATER-STORE
<small>thick internal tissue</small>
</div>
<div id="tag-pressure" class="tag pressure" style="--accent:#d58a35">
COMPARABLE PRESSURES
<small>high heat · scarce water</small>
</div>
</div>
<div id="controls">
<span class="control-copy">DRAG TO ORBIT · SCROLL TO ZOOM</span>
<button id="reset" type="button">Reset view</button>
</div>
<section id="statement" class="panel">
<div class="symbol">↗</div>
<div>
<strong>
Similar appearance can emerge independently under comparable pressures.
</strong>
<small>
The shared succulent form is a solution to similar problems—not evidence
of a close relationship.
</small>
</div>
</section>
<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.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 scene showing two unrelated succulent plant forms and a relationship tree."
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf0ebdc);
scene.fog = new THREE.Fog(0xf0ebdc, 30, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const target = new THREE.Vector3(0, 2.0, -0.2);
const cameraState = {
theta: 0.43,
phi: 1.03,
radius: 20.5,
goalTheta: 0.43,
goalPhi: 1.03,
goalRadius: 20.5
};
function updateCamera(immediate = false) {
const s = cameraState;
if (immediate) {
s.theta = s.goalTheta;
s.phi = s.goalPhi;
s.radius = s.goalRadius;
}
const sinPhi = Math.sin(s.phi);
camera.position.set(
target.x + s.radius * sinPhi * Math.sin(s.theta),
target.y + s.radius * Math.cos(s.phi),
target.z + s.radius * sinPhi * Math.cos(s.theta)
);
camera.lookAt(target);
}
updateCamera(true);
// -------------------------------------------------------------------------
// Lights
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0xfff8df, 0x78917f, 2.2);
scene.add(hemisphere);
const sunLight = new THREE.DirectionalLight(0xffe4aa, 3.6);
sunLight.position.set(-8, 16, 11);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -18;
sunLight.shadow.camera.right = 18;
sunLight.shadow.camera.top = 16;
sunLight.shadow.camera.bottom = -14;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 45;
sunLight.shadow.normalBias = 0.035;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0xbad7d8, 1.15);
fillLight.position.set(11, 7, -9);
scene.add(fillLight);
// -------------------------------------------------------------------------
// Shared voxel geometry and materials
// -------------------------------------------------------------------------
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const material = {
groundBase: new THREE.MeshStandardMaterial({
color: 0xbca77f,
roughness: 1
}),
soil: new THREE.MeshStandardMaterial({
color: 0xc9b58c,
roughness: 1
}),
cactus: new THREE.MeshStandardMaterial({
color: 0x397f68,
roughness: 0.92
}),
cactusLight: new THREE.MeshStandardMaterial({
color: 0x5b9876,
roughness: 0.92
}),
cactusDark: new THREE.MeshStandardMaterial({
color: 0x2c6757,
roughness: 0.95
}),
succulent: new THREE.MeshStandardMaterial({
color: 0x718a67,
roughness: 0.9
}),
succulentLight: new THREE.MeshStandardMaterial({
color: 0x91a47a,
roughness: 0.9
}),
plum: new THREE.MeshStandardMaterial({
color: 0x87536f,
roughness: 0.9
}),
plumLight: new THREE.MeshStandardMaterial({
color: 0xa66e86,
roughness: 0.9
}),
bark: new THREE.MeshStandardMaterial({
color: 0x92704b,
roughness: 1
}),
barkDark: new THREE.MeshStandardMaterial({
color: 0x6f5339,
roughness: 1
}),
branchA: new THREE.MeshStandardMaterial({
color: 0x397f68,
roughness: 0.95
}),
branchB: new THREE.MeshStandardMaterial({
color: 0x87536f,
roughness: 0.95
}),
water: new THREE.MeshStandardMaterial({
color: 0x2b9db4,
roughness: 0.22,
metalness: 0.04,
transparent: true,
opacity: 0.76,
depthWrite: false
}),
bubble: new THREE.MeshBasicMaterial({
color: 0xbaf4f2,
transparent: true,
opacity: 0.9
}),
amber: new THREE.MeshStandardMaterial({
color: 0xd58a35,
roughness: 0.8
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xf1bf52,
roughness: 0.75
}),
rock: new THREE.MeshStandardMaterial({
color: 0x9e947d,
roughness: 1
}),
cloud: new THREE.MeshStandardMaterial({
color: 0xfffaf0,
roughness: 1
}),
mesa: new THREE.MeshStandardMaterial({
color: 0xcbb68d,
roughness: 1
})
};
function addBox(
parent,
x,
y,
z,
sx,
sy,
sz,
mat,
rotationY = 0
) {
const mesh = new THREE.Mesh(cubeGeometry, mat);
mesh.position.set(x, y, z);
mesh.scale.set(sx, sy, sz);
mesh.rotation.y = rotationY;
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Voxel terrain
// -------------------------------------------------------------------------
addBox(scene, 0, -0.18, 0, 29, 0.45, 19, material.groundBase);
const tileGeometry = new THREE.BoxGeometry(1, 1, 1);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 1
});
const tileCount = 27 * 17;
const tiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tileCount
);
tiles.receiveShadow = true;
tiles.castShadow = false;
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let z = -8; z <= 8; z++) {
for (let x = -13; x <= 13; x++) {
dummy.position.set(x, 0.14, z);
dummy.scale.set(0.965, 0.14, 0.965);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
tiles.setMatrixAt(tileIndex, dummy.matrix);
const variation =
Math.sin(x * 12.9898 + z * 78.233) * 43758.5453;
const n = variation - Math.floor(variation);
tileColor.setHSL(0.105, 0.27, 0.65 + n * 0.085);
tiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Sparse rocks and dry soil fragments.
const rockPositions = [
[-10.2, 0.42, 2.5, 0.55],
[-8.9, 0.35, 4.1, 0.35],
[9.7, 0.45, -2.1, 0.62],
[11.1, 0.34, 3.4, 0.4],
[-3.9, 0.3, -5.8, 0.32],
[4.5, 0.28, -6.5, 0.36]
];
for (const [x, y, z, s] of rockPositions) {
addBox(scene, x, y, z, s, s * 0.72, s * 0.85, material.rock, x * 0.4);
}
// Distant block mesas.
for (let i = 0; i < 10; i++) {
const x = -13 + i * 2.8;
const height = 0.7 + ((i * 7) % 4) * 0.28;
addBox(
scene,
x,
0.35 + height * 0.5,
-8.1,
2.25,
height,
1.25,
material.mesa,
((i % 3) - 1) * 0.08
);
}
// Voxel clouds.
function addCloud(x, y, z, scale = 1) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
addBox(cloud, 0, 0, 0, 2.3, 0.65, 0.75, material.cloud);
addBox(cloud, -1.25, -0.12, 0, 1.25, 0.5, 0.65, material.cloud);
addBox(cloud, 1.25, -0.08, 0, 1.35, 0.52, 0.68, material.cloud);
addBox(cloud, 0.1, 0.45, 0, 1.05, 0.7, 0.7, material.cloud);
scene.add(cloud);
}
addCloud(-8.8, 7.8, -8.5, 1.05);
addCloud(8.8, 6.8, -9.5, 0.82);
// -------------------------------------------------------------------------
// Lineage A: voxel cactus-like plant with a visible water reservoir
// -------------------------------------------------------------------------
const plantA = new THREE.Group();
plantA.position.set(-6.45, 0.25, 0.65);
scene.add(plantA);
const stepA = 0.36;
for (let y = 0; y < 10; y++) {
for (let gx = -1; gx <= 1; gx++) {
for (let gz = -1; gz <= 1; gz++) {
// Open a front-facing cutaway so the water storage is visible.
if (gx === 0 && gz === 1 && y >= 1 && y <= 8) continue;
let mat = material.cactus;
if ((gx + gz + y) % 4 === 0) mat = material.cactusLight;
if (Math.abs(gx) === 1 && gz === -1) mat = material.cactusDark;
addBox(
plantA,
gx * stepA,
y * stepA + stepA * 0.5,
gz * stepA,
stepA * 0.98,
stepA * 0.98,
stepA * 0.98,
mat
);
}
}
}
// Left and right cactus arms.
for (const x of [-0.74, -1.1, -1.46, -1.82, -2.18]) {
addBox(
plantA,
x,
1.62,
0,
stepA,
stepA,
stepA,
x < -1.5 ? material.cactusLight : material.cactus
);
}
for (let i = 0; i < 5; i++) {
addBox(
plantA,
-2.18,
1.8 + i * stepA,
0,
stepA,
stepA,
stepA,
i % 2 ? material.cactus : material.cactusLight
);
}
for (const x of [0.74, 1.1, 1.46, 1.82, 2.18]) {
addBox(
plantA,
x,
2.48,
0,
stepA,
stepA,
stepA,
x > 1.5 ? material.cactusLight : material.cactus
);
}
for (let i = 0; i < 4; i++) {
addBox(
plantA,
2.18,
2.65 + i * stepA,
0,
stepA,
stepA,
stepA,
i % 2 ? material.cactus : material.cactusLight
);
}
const reservoirA = addBox(
plantA,
0,
1.72,
0.39,
0.25,
2.45,
0.25,
material.water
);
reservoirA.castShadow = false;
// Small pale cubes suggest stored water moving within the tissue.
const bubbleGroups = [];
function addWaterBubbles(parent, x, y, z, width, height) {
const group = [];
for (let i = 0; i < 4; i++) {
const bubble = addBox(
parent,
x + (i % 2 ? 0.055 : -0.055),
y,
z,
0.065,
0.065,
0.065,
material.bubble
);
bubble.castShadow = false;
group.push({
mesh: bubble,
baseY: y - height * 0.38,
height,
offset: i * 0.19,
speed: 0.22 + i * 0.025
});
}
bubbleGroups.push(...group);
}
addWaterBubbles(plantA, 0, 1.1, 0.56, 0.18, 2.0);
// -------------------------------------------------------------------------
// Lineage B: unrelated rosette succulent with a different palette and form
// -------------------------------------------------------------------------
const plantB = new THREE.Group();
plantB.position.set(6.55, 0.25, 0.45);
scene.add(plantB);
const stepB = 0.34;
// Compact central body. A front voxel is omitted for the water cutaway.
for (let y = 0; y < 3; y++) {
for (let gx = -1; gx <= 1; gx++) {
for (let gz = -1; gz <= 1; gz++) {
if (gx === 0 && gz === 1 && y > 0) continue;
addBox(
plantB,
gx * stepB,
0.25 + y * stepB,
gz * stepB,
stepB * 0.98,
stepB * 0.98,
stepB * 0.98,
y === 2 ? material.succulentLight : material.succulent
);
}
}
}
// Eight thick leaves assembled from shrinking voxel chains.
const leafAngles = Array.from(
{ length: 8 },
(_, index) => index * (Math.PI / 4)
);
for (const angle of leafAngles) {
for (let i = 0; i < 5; i++) {
const radius = 0.38 + i * 0.39;
const size = 0.58 - i * 0.075;
const y =
0.32 +
Math.sin(i * 0.9) * 0.14 +
Math.max(0, 0.2 - Math.abs(i - 2) * 0.075);
const mat =
i >= 3
? material.plumLight
: i === 1
? material.succulentLight
: material.succulent;
addBox(
plantB,
Math.cos(angle) * radius,
y,
Math.sin(angle) * radius,
size,
size * 0.82,
size,
mat,
angle
);
}
}
// Plum-colored outer body accents.
for (const angle of [0, Math.PI, Math.PI / 2, -Math.PI / 2]) {
addBox(
plantB,
Math.cos(angle) * 0.43,
0.55,
Math.sin(angle) * 0.43,
0.35,
0.28,
0.35,
material.plum,
angle
);
}
const reservoirB = addBox(
plantB,
0,
0.62,
0.38,
0.27,
0.82,
0.26,
material.water
);
reservoirB.castShadow = false;
addWaterBubbles(plantB, 0, 0.5, 0.54, 0.16, 0.62);
// -------------------------------------------------------------------------
// Simplified relationship tree
// -------------------------------------------------------------------------
const tree = new THREE.Group();
tree.position.set(0, 0.2, -4.75);
scene.add(tree);
const branchStep = 0.42;
// Shared trunk and roots.
for (let i = 0; i < 8; i++) {
const width = i < 2 ? 0.62 : 0.48;
addBox(
tree,
0,
0.2 + i * branchStep,
0,
width,
branchStep * 0.97,
width,
i % 3 === 0 ? material.barkDark : material.bark
);
}
for (let i = 0; i < 5; i++) {
addBox(
tree,
(i - 2) * 0.3,
0.12,
0.45,
0.28,
0.25,
0.9,
material.barkDark
);
}
// Distinct colored branches: same ancient root, separate tips.
for (let i = 1; i <= 7; i++) {
addBox(
tree,
-i * 0.43,
3.12,
0,
0.42,
0.42,
0.42,
i > 4 ? material.branchA : material.bark,
Math.PI / 4
);
addBox(
tree,
i * 0.43,
3.12,
0,
0.42,
0.42,
0.42,
i > 4 ? material.branchB : material.bark,
Math.PI / 4
);
}
for (let i = 0; i < 5; i++) {
addBox(
tree,
-3.0,
3.36 + i * branchStep,
0,
0.41,
0.41,
0.41,
material.branchA
);
addBox(
tree,
3.0,
3.36 + i * branchStep,
0,
0.41,
0.41,
0.41,
material.branchB
);
}
// Extra lateral twigs clarify the tree silhouette.
for (let i = 1; i <= 3; i++) {
addBox(
tree,
-3.0 - i * 0.35,
4.85,
0,
0.35,
0.35,
0.35,
material.branchA
);
addBox(
tree,
3.0 + i * 0.35,
4.85,
0,
0.35,
0.35,
0.35,
material.branchB
);
}
// -------------------------------------------------------------------------
// Comparable-pressure icon: heat, sunlight, and scarce water
// -------------------------------------------------------------------------
const pressureGroup = new THREE.Group();
pressureGroup.position.set(0, 0.2, 4.25);
scene.add(pressureGroup);
const sunGroup = new THREE.Group();
sunGroup.position.set(0, 2.75, 0);
pressureGroup.add(sunGroup);
addBox(sunGroup, 0, 0, 0, 0.72, 0.72, 0.72, material.yellow);
const rayOffsets = [
[-0.73, 0],
[0.73, 0],
[0, 0.73],
[0, -0.73],
[-0.62, 0.62],
[0.62, 0.62],
[-0.62, -0.62],
[0.62, -0.62]
];
for (const [x, y] of rayOffsets) {
addBox(sunGroup, x, y, 0, 0.31, 0.31, 0.31, material.amber);
}
// A tiny water supply emphasizes scarcity.
addBox(pressureGroup, 0, 0.42, 0.22, 0.3, 0.3, 0.3, material.water);
addBox(pressureGroup, 0, 0.68, 0.22, 0.19, 0.19, 0.19, material.water);
// Sparse amber voxel traces point toward both similarly pressured habitats.
for (const side of [-1, 1]) {
for (let i = 0; i < 8; i++) {
addBox(
pressureGroup,
side * (1.25 + i * 0.48),
0.29,
-0.12 - i * 0.14,
0.09,
0.07,
0.09,
material.amber
);
}
}
// A few dry, cracked-looking blocks around the lineage bases.
for (const side of [-1, 1]) {
addBox(
scene,
side * 5.25,
0.31,
1.85,
0.58,
0.1,
0.12,
material.barkDark,
side * 0.35
);
addBox(
scene,
side * 5.55,
0.31,
2.08,
0.13,
0.1,
0.47,
material.barkDark,
side * 0.35
);
}
// -------------------------------------------------------------------------
// Screen-space labels
// -------------------------------------------------------------------------
const labelAnchors = [
{
element: document.getElementById("tag-tree"),
position: new THREE.Vector3(0, 6.15, -4.75),
offsetY: -12
},
{
element: document.getElementById("tag-a"),
position: new THREE.Vector3(-6.45, 3.95, 0.65),
offsetY: -15
},
{
element: document.getElementById("tag-b"),
position: new THREE.Vector3(6.55, 2.35, 0.45),
offsetY: -15
},
{
element: document.getElementById("tag-water-a"),
position: new THREE.Vector3(-6.45, 1.9, 1.15),
offsetX: 65,
offsetY: 20
},
{
element: document.getElementById("tag-water-b"),
position: new THREE.Vector3(6.55, 1.0, 1.0),
offsetX: 62,
offsetY: 30
},
{
element: document.getElementById("tag-pressure"),
position: new THREE.Vector3(0, 4.25, 4.25),
offsetY: -25
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelAnchors) {
projected.copy(label.position).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.25 &&
Math.abs(projected.y) < 1.25;
label.element.style.opacity = visible ? "1" : "0";
const x = (projected.x * 0.5 + 0.5) * width + (label.offsetX || 0);
const y = (-projected.y * 0.5 + 0.5) * height + (label.offsetY || 0);
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
}
}
// -------------------------------------------------------------------------
// Direct camera controls: orbit, wheel zoom, touch pinch
// -------------------------------------------------------------------------
const pointers = new Map();
let previousPinchDistance = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
renderer.domElement.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
previousPinchDistance = pinchDistance();
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const current = {
x: event.clientX,
y: event.clientY
};
pointers.set(event.pointerId, current);
if (pointers.size === 1) {
const dx = current.x - previous.x;
const dy = current.y - previous.y;
cameraState.goalTheta -= dx * 0.006;
cameraState.goalPhi = THREE.MathUtils.clamp(
cameraState.goalPhi - dy * 0.005,
0.42,
1.43
);
} else if (pointers.size === 2) {
const distance = pinchDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius *
(previousPinchDistance / distance),
12,
29
);
}
previousPinchDistance = distance;
}
});
function pinchDistance() {
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
);
}
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pinchDistance() : 0;
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener("lostpointercapture", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.goalRadius = THREE.MathUtils.clamp(
cameraState.goalRadius + event.deltaY * 0.012,
12,
29
);
},
{ passive: false }
);
function resetCamera() {
cameraState.goalTheta = 0.43;
cameraState.goalPhi = 1.03;
cameraState.goalRadius = 20.5;
}
document.getElementById("reset").addEventListener("click", resetCamera);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
// Damped camera motion.
cameraState.theta = THREE.MathUtils.lerp(
cameraState.theta,
cameraState.goalTheta,
0.09
);
cameraState.phi = THREE.MathUtils.lerp(
cameraState.phi,
cameraState.goalPhi,
0.09
);
cameraState.radius = THREE.MathUtils.lerp(
cameraState.radius,
cameraState.goalRadius,
0.09
);
updateCamera();
// Water cubes gently circulate inside the reservoirs.
for (const bubble of bubbleGroups) {
const progress = (elapsed * bubble.speed + bubble.offset) % 1;
bubble.mesh.position.y =
bubble.baseY + progress * bubble.height;
}
// Subtle pulse for the pressure/heat icon.
const pulse = 1 + Math.sin(elapsed * 1.5) * 0.025;
sunGroup.scale.setScalar(pulse);
sunGroup.rotation.y = Math.sin(elapsed * 0.3) * 0.07;
renderer.render(scene, camera);
updateLabels();
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```