Prompt specification
Build or customize the Three.js 3D scene "Tree rotation equivalence display" 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: Tree rotation equivalence display
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tree-rotation-equivalence-display-x0946
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing phylogenetic trees. Place two differently arranged trees describing the same fictional relationships side by side; highlight matching clades to show that left-to-right order is not evolutionary rank. Stylized solid forms.
Working Three.js Starter (tree-rotation-equivalence-display-x0946):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Same Branches, Different Order</title>
<style>
:root {
color-scheme: dark;
--background: #080d18;
--text: #eef4ff;
--muted: #93a4c0;
--border: rgba(156, 181, 220, 0.2);
--ab: #ffc857;
--cd: #4ecdc4;
--ef: #ff6b6b;
--gh: #a78bfa;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--background);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas.dragging {
cursor: grabbing;
}
.intro {
position: fixed;
z-index: 5;
top: 18px;
left: 50%;
width: min(760px, calc(100% - 36px));
transform: translateX(-50%);
text-align: center;
pointer-events: none;
}
.eyebrow {
margin-bottom: 6px;
color: #75d9d1;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 40px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.intro p {
max-width: 680px;
margin: 9px auto 0;
color: var(--muted);
font-size: clamp(12px, 1.25vw, 15px);
line-height: 1.5;
}
.legend {
position: fixed;
z-index: 5;
left: 50%;
bottom: 18px;
width: min(1120px, calc(100% - 36px));
transform: translateX(-50%);
padding: 13px 16px;
border: 1px solid var(--border);
border-radius: 16px;
background: rgba(13, 21, 37, 0.84);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 18px;
flex-wrap: wrap;
}
.legend-heading {
min-width: 126px;
color: #dce7f8;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.clades {
display: flex;
gap: 8px;
flex: 1;
flex-wrap: wrap;
}
.clade {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #cbd7e9;
font-size: 11px;
white-space: nowrap;
}
.dot {
width: 8px;
height: 8px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: 0 0 11px currentColor;
}
.takeaway {
margin-top: 10px;
padding-top: 9px;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--muted);
font-size: 12px;
line-height: 1.45;
}
.takeaway strong {
color: #f5f8ff;
}
.controls {
position: fixed;
z-index: 6;
top: 18px;
right: 18px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
background: rgba(13, 21, 37, 0.7);
color: #8193b1;
font-size: 10px;
letter-spacing: 0.04em;
pointer-events: none;
backdrop-filter: blur(10px);
}
#loading {
position: fixed;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: var(--background);
color: #aab9cf;
font-size: 12px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 250ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 12px;
}
.intro p {
max-width: 520px;
}
.controls {
display: none;
}
.legend {
bottom: 10px;
width: calc(100% - 20px);
padding: 10px;
}
.legend-heading {
width: 100%;
}
.clade {
padding: 5px 7px;
font-size: 10px;
}
.takeaway {
font-size: 11px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="intro">
<div class="eyebrow">Fictional lineages / topology study</div>
<h1>Same branches. Different order.</h1>
<p>
Both drawings encode identical relationships. Moving a tip left, right,
or around a circle changes the layout—not the organism’s evolutionary rank.
</p>
</header>
<div class="controls">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<section class="legend">
<div class="legend-row">
<div class="legend-heading">Matching clades</div>
<div class="clades">
<div class="clade">
<span class="dot" style="color:#ffc857;background:#ffc857"></span>
Mireling + Cinderfin
</div>
<div class="clade">
<span class="dot" style="color:#4ecdc4;background:#4ecdc4"></span>
Glasscap + Duskwing
</div>
<div class="clade">
<span class="dot" style="color:#ff6b6b;background:#ff6b6b"></span>
Emberback + Frostmaw
</div>
<div class="clade">
<span class="dot" style="color:#a78bfa;background:#a78bfa"></span>
Goldenvine + Hollowhorn
</div>
</div>
</div>
<div class="takeaway">
<strong>Read the forks, not the row.</strong>
Colors identify the same sister groups in both trees. No tip is
“more evolved” because it appears farther right.
</div>
</section>
<div id="loading">Building the trees…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.getElementById("app");
const loading = document.getElementById("loading");
// ---------------------------------------------------------------------
// Renderer, scene, and camera
// ---------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Two stylized phylogenetic trees showing the same fictional relationships"
);
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xd8ebff, 0x111522, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(-4, 7, 9);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -7;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x76a8ff, 1.25);
fillLight.position.set(7, -1, 5);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xff7ca8, 0.75);
rimLight.position.set(-7, 2, -4);
scene.add(rimLight);
const palette = {
AB: 0xffc857,
CD: 0x4ecdc4,
EF: 0xff6b6b,
GH: 0xa78bfa,
neutral: 0x687996,
panel: 0x111a2d,
panelEdge: 0x2a3a58,
text: 0xeef4ff,
muted: 0x8295b7
};
const branchMaterialCache = new Map();
const nodeMaterialCache = new Map();
const cladeRings = [];
function getBranchMaterial(color) {
if (!branchMaterialCache.has(color)) {
branchMaterialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.4,
metalness: 0.12,
emissive: color,
emissiveIntensity: 0.12
})
);
}
return branchMaterialCache.get(color);
}
function getNodeMaterial(color) {
if (!nodeMaterialCache.has(color)) {
nodeMaterialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.28,
metalness: 0.18,
emissive: color,
emissiveIntensity: 0.16,
flatShading: true
})
);
}
return nodeMaterialCache.get(color);
}
// ---------------------------------------------------------------------
// Typography rendered into Three.js sprites
// ---------------------------------------------------------------------
function makeTextSprite(
text,
{
height = 0.24,
color = "#eef4ff",
fontSize = 52,
weight = 600,
anchor = "center"
} = {}
) {
const probe = document.createElement("canvas").getContext("2d");
const font = `${weight} ${fontSize}px Inter, system-ui, sans-serif`;
probe.font = font;
const measured = probe.measureText(text);
const canvas = document.createElement("canvas");
canvas.width = Math.ceil(measured.width + 28);
canvas.height = 96;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
context.font = font;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = color;
context.fillText(text, canvas.width / 2, canvas.height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
const aspect = canvas.width / canvas.height;
sprite.scale.set(height * aspect, height, 1);
sprite.center.set(
anchor === "left" ? 0 : anchor === "right" ? 1 : 0.5,
0.5
);
sprite.renderOrder = 30;
return sprite;
}
function makePanelTitle(title, subtitle) {
const probe = document.createElement("canvas").getContext("2d");
const titleFont = "700 52px Inter, system-ui, sans-serif";
const subtitleFont = "500 29px Inter, system-ui, sans-serif";
probe.font = titleFont;
const titleWidth = probe.measureText(title).width;
probe.font = subtitleFont;
const subtitleWidth = probe.measureText(subtitle).width;
const canvas = document.createElement("canvas");
canvas.width = Math.ceil(Math.max(titleWidth, subtitleWidth) + 50);
canvas.height = 180;
const context = canvas.getContext("2d");
context.textAlign = "center";
context.textBaseline = "middle";
context.font = titleFont;
context.fillStyle = "#eef4ff";
context.fillText(title, canvas.width / 2, 54);
context.font = subtitleFont;
context.fillStyle = "#8295b7";
context.fillText(subtitle, canvas.width / 2, 122);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
toneMapped: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(0.69 * (canvas.width / canvas.height), 0.69, 1);
sprite.renderOrder = 31;
return sprite;
}
// ---------------------------------------------------------------------
// Shared topology:
// (((A,B),(C,D)),((E,F),(G,H)))
// ---------------------------------------------------------------------
const nodes = new Map();
function addNode(node) {
nodes.set(node.id, node);
return node;
}
addNode({
id: "A",
name: "Mireling",
clade: "AB"
});
addNode({
id: "B",
name: "Cinderfin",
clade: "AB"
});
addNode({
id: "C",
name: "Glasscap",
clade: "CD"
});
addNode({
id: "D",
name: "Duskwing",
clade: "CD"
});
addNode({
id: "E",
name: "Emberback",
clade: "EF"
});
addNode({
id: "F",
name: "Frostmaw",
clade: "EF"
});
addNode({
id: "G",
name: "Goldenvine",
clade: "GH"
});
addNode({
id: "H",
name: "Hollowhorn",
clade: "GH"
});
addNode({
id: "AB",
clade: "AB",
children: ["A", "B"]
});
addNode({
id: "CD",
clade: "CD",
children: ["C", "D"]
});
addNode({
id: "EF",
clade: "EF",
children: ["E", "F"]
});
addNode({
id: "GH",
clade: "GH",
children: ["G", "H"]
});
addNode({
id: "L",
children: ["AB", "CD"]
});
addNode({
id: "R",
children: ["EF", "GH"]
});
addNode({
id: "root",
children: ["L", "R"]
});
// Child order changes the visual ordering, not the topology.
const leftOrder = {
root: ["L", "R"],
L: ["AB", "CD"],
R: ["EF", "GH"],
AB: ["A", "B"],
CD: ["C", "D"],
EF: ["E", "F"],
GH: ["G", "H"]
};
const rightOrder = {
root: ["R", "L"],
R: ["GH", "EF"],
L: ["CD", "AB"],
AB: ["B", "A"],
CD: ["D", "C"],
EF: ["F", "E"],
GH: ["H", "G"]
};
function getNode(id) {
return nodes.get(id);
}
function orderedChildren(node, orderMap) {
const ids = orderMap[node.id] || node.children;
return ids.map(getNode);
}
function countLeaves(node) {
if (!node.children) return 1;
return node.children.reduce(
(total, childId) => total + countLeaves(getNode(childId)),
0
);
}
// ---------------------------------------------------------------------
// Stylized solid forms
// ---------------------------------------------------------------------
const leafGeometries = [
new THREE.IcosahedronGeometry(0.17, 0),
new THREE.OctahedronGeometry(0.175, 0),
new THREE.TetrahedronGeometry(0.19, 0),
new THREE.DodecahedronGeometry(0.155, 0)
];
function addLeaf(group, node, position, index) {
const material = getNodeMaterial(palette[node.clade]);
const mesh = new THREE.Mesh(
leafGeometries[index % leafGeometries.length],
material
);
mesh.position.copy(position);
mesh.position.z = 0.075;
mesh.rotation.set(
0.25 + index * 0.37,
0.45 + index * 0.51,
index * 0.29
);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
function addInternalNode(group, node, position) {
const color = node.clade ? palette[node.clade] : palette.neutral;
const radius = node.id === "root" ? 0.13 : node.clade ? 0.095 : 0.11;
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, node.clade ? 0 : 1),
getNodeMaterial(color)
);
mesh.position.copy(position);
mesh.position.z = 0.075;
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
if (node.clade) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.018, 8, 32),
getNodeMaterial(color)
);
ring.position.copy(position);
ring.position.z = 0.11;
ring.rotation.z = Math.random() * Math.PI;
ring.castShadow = true;
ring.userData.phase = Math.random() * Math.PI * 2;
ring.userData.baseScale = 1;
group.add(ring);
cladeRings.push(ring);
}
}
const upAxis = new THREE.Vector3(0, 1, 0);
function addBranch(group, start, end, color, radius) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
if (length < 0.0001) return;
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
10,
1,
false
);
const mesh = new THREE.Mesh(geometry, getBranchMaterial(color));
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(upAxis, direction.normalize());
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
}
function branchRadiusFor(child) {
if (!child.children) return 0.022;
if (child.clade) return 0.034;
return 0.043;
}
// ---------------------------------------------------------------------
// Panels
// ---------------------------------------------------------------------
function createPanel(x, title, subtitle) {
const group = new THREE.Group();
group.position.x = x;
const panelMaterial = new THREE.MeshStandardMaterial({
color: palette.panel,
roughness: 0.88,
metalness: 0.06
});
const panel = new THREE.Mesh(
new THREE.BoxGeometry(7, 6.2, 0.16),
panelMaterial
);
panel.position.z = -0.62;
panel.receiveShadow = true;
group.add(panel);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(panel.geometry),
new THREE.LineBasicMaterial({
color: palette.panelEdge,
transparent: true,
opacity: 0.82
})
);
edges.position.copy(panel.position);
group.add(edges);
const heading = makePanelTitle(title, subtitle);
heading.position.set(0, 2.57, 0.08);
group.add(heading);
const accent = new THREE.Mesh(
new THREE.BoxGeometry(2.15, 0.025, 0.025),
new THREE.MeshBasicMaterial({
color: 0x415879,
transparent: true,
opacity: 0.72
})
);
accent.position.set(0, 2.18, 0.02);
group.add(accent);
const rankNote = makeTextSprite("TIP POSITION ≠ RANK", {
height: 0.2,
color: "#7184a4",
fontSize: 46,
weight: 700
});
rankNote.position.set(0, -2.69, 0.06);
group.add(rankNote);
scene.add(group);
return group;
}
const leftPanel = createPanel(
-4.35,
"ORDER I · LADDER",
"a chosen left-to-right sequence"
);
const rightPanel = createPanel(
4.35,
"ORDER II · RADIAL",
"the same clades around a crown"
);
// ---------------------------------------------------------------------
// Left tree: conventional upward ladder
// ---------------------------------------------------------------------
function buildLeftTree(group) {
const positions = new Map();
const leaves = [];
function collectLeaves(node) {
if (!node.children) {
leaves.push(node);
return;
}
orderedChildren(node, leftOrder).forEach(collectLeaves);
}
collectLeaves(getNode("root"));
const span = 5.6;
const step = span / (leaves.length - 1);
leaves.forEach((leaf, index) => {
positions.set(
leaf.id,
new THREE.Vector3(-span / 2 + index * step, 1.62, 0)
);
});
const depthY = [-1.72, -0.72, 0.46, 1.62];
function place(node, depth) {
if (!node.children) return positions.get(node.id);
const children = orderedChildren(node, leftOrder);
children.forEach((child) => place(child, depth + 1));
const x =
children.reduce(
(sum, child) => sum + positions.get(child.id).x,
0
) / children.length;
positions.set(
node.id,
new THREE.Vector3(x, depthY[depth], 0)
);
}
place(getNode("root"), 0);
function drawNode(node, depth) {
if (!node.children) {
const index = "ABCDEFGH".indexOf(node.id);
const position = positions.get(node.id);
addLeaf(group, node, position, index);
const label = makeTextSprite(node.name, {
height: 0.24,
color: "#e7eef9",
fontSize: 50,
weight: 600
});
label.position.set(position.x, position.y + 0.31, 0.18);
group.add(label);
return;
}
const position = positions.get(node.id);
addInternalNode(group, node, position);
const children = orderedChildren(node, leftOrder);
for (const child of children) {
const childPosition = positions.get(child.id);
const color = child.clade ? palette[child.clade] : palette.neutral;
addBranch(
group,
position,
childPosition,
color,
branchRadiusFor(child)
);
drawNode(child, depth + 1);
}
}
drawNode(getNode("root"), 0);
}
buildLeftTree(leftPanel);
// ---------------------------------------------------------------------
// Right tree: radial crown with independently rotated child groups
// ---------------------------------------------------------------------
function buildRightTree(group) {
const positions = new Map();
const radiusByDepth = [0, 0.58, 1.1, 1.62];
function placeRadial(node, startAngle, endAngle, depth) {
const midpoint = (startAngle + endAngle) / 2;
if (!node.children) {
const radius = radiusByDepth[depth];
positions.set(
node.id,
new THREE.Vector3(
Math.cos(midpoint) * radius,
Math.sin(midpoint) * radius,
0
)
);
return;
}
if (depth === 0) {
positions.set(node.id, new THREE.Vector3(0, 0, 0));
} else {
const radius = radiusByDepth[depth];
positions.set(
node.id,
new THREE.Vector3(
Math.cos(midpoint) * radius,
Math.sin(midpoint) * radius,
0
)
);
}
const children = orderedChildren(node, rightOrder);
const totalLeaves = children.reduce(
(sum, child) => sum + countLeaves(child),
0
);
let cursor = startAngle;
const interval = endAngle - startAngle;
for (const child of children) {
const childLeaves = countLeaves(child);
const childEnd = cursor + interval * (childLeaves / totalLeaves);
placeRadial(child, cursor, childEnd, depth + 1);
cursor = childEnd;
}
}
placeRadial(getNode("root"), 0, Math.PI * 2, 0);
function drawNode(node, depth) {
if (!node.children) {
const index = "ABCDEFGH".indexOf(node.id);
const position = positions.get(node.id);
addLeaf(group, node, position, index);
const angle = Math.atan2(position.y, position.x);
const outward = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
0
);
const label = makeTextSprite(node.name, {
height: 0.24,
color: "#e7eef9",
fontSize: 50,
weight: 600,
anchor:
Math.cos(angle) > 0.2
? "left"
: Math.cos(angle) < -0.2
? "right"
: "center"
});
label.position.copy(position).addScaledVector(outward, 0.16);
label.position.z = 0.18;
group.add(label);
return;
}
const position = positions.get(node.id);
addInternalNode(group, node, position);
const children = orderedChildren(node, rightOrder);
for (const child of children) {
const childPosition = positions.get(child.id);
const color = child.clade ? palette[child.clade] : palette.neutral;
addBranch(
group,
position,
childPosition,
color,
branchRadiusFor(child)
);
drawNode(child, depth + 1);
}
}
drawNode(getNode("root"), 0);
}
buildRightTree(rightPanel);
// ---------------------------------------------------------------------
// Center equality badge
// ---------------------------------------------------------------------
const badge = new THREE.Group();
badge.position.set(0, -0.12, 0.04);
const badgeDisc = new THREE.Mesh(
new THREE.CylinderGeometry(0.27, 0.27, 0.08, 36),
new THREE.MeshStandardMaterial({
color: 0x1b2b44,
roughness: 0.42,
metalness: 0.35,
emissive: 0x14263b,
emissiveIntensity: 0.2
})
);
badgeDisc.rotation.x = Math.PI / 2;
badgeDisc.castShadow = true;
badge.add(badgeDisc);
const badgeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.27, 0.018, 8, 40),
new THREE.MeshBasicMaterial({
color: 0x75d9d1,
transparent: true,
opacity: 0.82
})
);
badgeRing.position.z = 0.05;
badge.add(badgeRing);
const equals = makeTextSprite("=", {
height: 0.34,
color: "#eafcfa",
fontSize: 68,
weight: 700
});
equals.position.z = 0.12;
badge.add(equals);
const sameLabel = makeTextSprite("SAME", {
height: 0.17,
color: "#75d9d1",
fontSize: 43,
weight: 800
});
sameLabel.position.set(0, -0.5, 0.08);
badge.add(sameLabel);
scene.add(badge);
// ---------------------------------------------------------------------
// Direct camera controls: no external controls addon
// ---------------------------------------------------------------------
const controls = {
yaw: 0,
pitch: 0.035,
zoom: 1,
dragging: false,
lastX: 0,
lastY: 0,
pinchDistance: 0,
pinchZoom: 1
};
const pointers = new Map();
function fitDistance() {
const verticalHalfSize = 3.65;
const horizontalHalfSize = 8.35;
const tangent = Math.tan(THREE.MathUtils.degToRad(camera.fov / 2));
return Math.max(
verticalHalfSize / tangent,
horizontalHalfSize / (tangent * camera.aspect)
);
}
function updateCamera() {
const distance = fitDistance() / controls.zoom;
camera.position.set(
Math.sin(controls.yaw) * Math.cos(controls.pitch) * distance,
Math.sin(controls.pitch) * distance,
Math.cos(controls.yaw) * Math.cos(controls.pitch) * distance
);
camera.lookAt(0, 0, 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
);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 1) {
controls.dragging = true;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
renderer.domElement.classList.add("dragging");
} else if (pointers.size === 2) {
controls.dragging = false;
controls.pinchDistance = pointerDistance();
controls.pinchZoom = controls.zoom;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 2) {
const distance = pointerDistance();
if (controls.pinchDistance > 0) {
controls.zoom = THREE.MathUtils.clamp(
controls.pinchZoom * (distance / controls.pinchDistance),
0.82,
1.38
);
updateCamera();
}
return;
}
if (!controls.dragging) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.yaw = THREE.MathUtils.clamp(
controls.yaw + dx * 0.0035,
-0.55,
0.55
);
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0025,
-0.22,
0.22
);
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (pointers.size === 0) {
controls.dragging = false;
renderer.domElement.classList.remove("dragging");
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.82,
1.38
);
updateCamera();
},
{ passive: false }
);
function resetCamera() {
controls.yaw = 0;
controls.pitch = 0.035;
controls.zoom = 1;
updateCamera();
}
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") resetCamera();
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
updateCamera();
}
window.addEventListener("resize", resize);
updateCamera();
resize();
// ---------------------------------------------------------------------
// Render loop
// ---------------------------------------------------------------------
const reduceMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (!reduceMotion) {
for (const ring of cladeRings) {
const pulse = 1 + Math.sin(elapsed * 1.7 + ring.userData.phase) * 0.045;
ring.scale.setScalar(pulse);
}
}
renderer.render(scene, camera);
}
renderer.render(scene, camera);
loading.classList.add("hidden");
animate();
</script>
</body>
</html>
```