Prompt specification
Build or customize the Three.js 3D scene "Cabinet glass edge study" 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: Cabinet glass edge study
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cabinet-glass-edge-study-x0189
Scene Description Prompt:
Make a stylized Three.js scene in a self-contained HTML file using cdnjs: cabinet glass edge study. Model a glass display door with visible edge thickness, hinges, and a specimen behind it; use restrained reflections so transparency and physical boundary are both readable.
Working Three.js Starter (cabinet-glass-edge-study-x0189):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cabinet Glass Edge Study</title>
<style>
:root {
color-scheme: light;
--ink: #222824;
--muted: #646b64;
--paper: #d8d2c6;
--accent: #8b6c45;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 2;
}
.title-block {
position: absolute;
top: 30px;
left: 34px;
max-width: 340px;
}
.eyebrow {
margin: 0 0 10px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.24em;
text-transform: uppercase;
color: var(--accent);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 4vw, 48px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 285px;
margin: 15px 0 0;
font-size: 12px;
line-height: 1.6;
color: var(--muted);
}
#controls {
position: absolute;
top: 30px;
right: 30px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 8px;
pointer-events: auto;
}
button {
min-width: 132px;
padding: 11px 13px;
border: 1px solid rgba(34, 40, 36, 0.3);
border-radius: 2px;
background: rgba(235, 231, 222, 0.72);
color: var(--ink);
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.13em;
text-align: left;
backdrop-filter: blur(8px);
cursor: pointer;
transition:
background 180ms ease,
border-color 180ms ease,
transform 180ms ease;
}
button:hover {
background: rgba(248, 245, 237, 0.95);
border-color: rgba(34, 40, 36, 0.6);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
button span {
display: block;
}
button small {
display: block;
margin-top: 4px;
font-size: 8px;
font-weight: 500;
letter-spacing: 0.15em;
color: var(--muted);
}
.legend {
position: absolute;
right: 30px;
bottom: 27px;
display: flex;
gap: 18px;
align-items: center;
font-size: 9px;
font-weight: 650;
letter-spacing: 0.13em;
text-transform: uppercase;
color: rgba(34, 40, 36, 0.62);
}
.legend::before {
content: "";
width: 32px;
height: 1px;
background: rgba(34, 40, 36, 0.35);
}
#loading {
position: fixed;
inset: 0;
z-index: 5;
display: grid;
place-items: center;
background: var(--paper);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.22em;
text-transform: uppercase;
transition: opacity 500ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 650px) {
.title-block {
top: 20px;
left: 20px;
}
.subtitle {
display: none;
}
#controls {
top: 20px;
right: 20px;
}
.legend {
right: 20px;
bottom: 20px;
}
}
</style>
</head>
<body>
<div id="loading">Preparing glass study</div>
<div id="ui">
<div class="title-block">
<p class="eyebrow">Material Study / 04</p>
<h1>Cabinet<br />Glass Edge</h1>
<p class="subtitle">
A restrained study in transparency, edge thickness, reflected light,
and the physical boundary of a specimen cabinet.
</p>
</div>
<div id="controls">
<button id="doorButton" type="button">
<span id="doorLabel">OPEN DOOR</span>
<small id="doorDetail">HINGE TEST · 22°</small>
</button>
<button id="resetButton" type="button">
<span>RESET VIEW</span>
<small>RETURN TO THREE-QUARTER</small>
</button>
</div>
<div class="legend">Drag to orbit · Scroll to inspect</div>
</div>
<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,
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional glass specimen cabinet"
);
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d2c6);
scene.fog = new THREE.Fog(0xd8d2c6, 11, 23);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const controls = {
target: new THREE.Vector3(0, 1.62, 0),
radius: 6.35,
phi: 1.22,
theta: 0.54
};
const defaultControls = {
radius: controls.radius,
phi: controls.phi,
theta: controls.theta
};
// A procedural equirectangular environment gives the glass restrained,
// readable softbox reflections without importing any external assets.
function createEnvironment() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
const base = ctx.createLinearGradient(0, 0, 0, 512);
base.addColorStop(0, "#b9b4aa");
base.addColorStop(0.44, "#777b74");
base.addColorStop(0.72, "#3d4641");
base.addColorStop(1, "#a49b8c");
ctx.fillStyle = base;
ctx.fillRect(0, 0, 1024, 512);
ctx.filter = "blur(22px)";
ctx.fillStyle = "rgba(255,250,232,0.95)";
ctx.fillRect(115, 70, 150, 260);
ctx.fillRect(680, 90, 95, 210);
ctx.fillStyle = "rgba(218,235,227,0.72)";
ctx.fillRect(400, 45, 220, 145);
ctx.filter = "none";
const lower = ctx.createLinearGradient(0, 300, 0, 512);
lower.addColorStop(0, "rgba(20,30,26,0)");
lower.addColorStop(1, "rgba(20,30,26,0.42)");
ctx.fillStyle = lower;
ctx.fillRect(0, 300, 1024, 212);
const texture = new THREE.CanvasTexture(canvas);
texture.mapping = THREE.EquirectangularReflectionMapping;
texture.colorSpace = THREE.SRGBColorSpace;
scene.environment = texture;
}
createEnvironment();
// -------------------------------------------------------------------------
// Materials
// -------------------------------------------------------------------------
const cabinetMetal = new THREE.MeshStandardMaterial({
color: 0x252c28,
roughness: 0.34,
metalness: 0.66
});
const cabinetInset = new THREE.MeshStandardMaterial({
color: 0x34413b,
roughness: 0.76,
metalness: 0.08
});
const darkGasket = new THREE.MeshStandardMaterial({
color: 0x111713,
roughness: 0.88,
metalness: 0.05
});
const bronze = new THREE.MeshStandardMaterial({
color: 0x9d7b4d,
roughness: 0.29,
metalness: 0.78
});
const darkBronze = new THREE.MeshStandardMaterial({
color: 0x5f4a32,
roughness: 0.36,
metalness: 0.7
});
const ceramic = new THREE.MeshPhysicalMaterial({
color: 0xb77750,
roughness: 0.32,
metalness: 0.02,
clearcoat: 0.28,
clearcoatRoughness: 0.4
});
const stone = new THREE.MeshStandardMaterial({
color: 0xaaa497,
roughness: 0.78,
metalness: 0.02
});
const branchMaterial = new THREE.MeshStandardMaterial({
color: 0x57402d,
roughness: 0.9
});
const leafMaterials = [
new THREE.MeshStandardMaterial({
color: 0x747d5c,
roughness: 0.85,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x9a7650,
roughness: 0.88,
side: THREE.DoubleSide
}),
new THREE.MeshStandardMaterial({
color: 0x596b56,
roughness: 0.8,
side: THREE.DoubleSide
})
];
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xd8f2ec,
metalness: 0,
roughness: 0.075,
transmission: 0.88,
thickness: 0.11,
ior: 1.48,
attenuationColor: 0x8fc8bd,
attenuationDistance: 1.15,
clearcoat: 0.8,
clearcoatRoughness: 0.09,
specularIntensity: 0.72,
transparent: true,
opacity: 0.96,
depthWrite: false,
envMapIntensity: 0.62
});
const glassEdgeMaterial = new THREE.MeshPhysicalMaterial({
color: 0x6fa99e,
roughness: 0.16,
metalness: 0,
transmission: 0.22,
thickness: 0.12,
ior: 1.48,
transparent: true,
opacity: 0.68,
depthWrite: false,
envMapIntensity: 0.72
});
// -------------------------------------------------------------------------
// Utility helpers
// -------------------------------------------------------------------------
function addBox(size, position, material, parent = scene, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
radius,
height,
position,
material,
parent = scene,
radialSegments = 32
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
height,
radialSegments
),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
renderer.capabilities.getMaxAnisotropy(),
8
);
return texture;
}
// -------------------------------------------------------------------------
// Studio floor and background
// -------------------------------------------------------------------------
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xb8b1a5,
roughness: 0.96,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const backdrop = new THREE.Mesh(
new THREE.PlaneGeometry(30, 18),
new THREE.MeshStandardMaterial({
color: 0xc9c3b8,
roughness: 1
})
);
backdrop.position.set(0, 7, -7);
backdrop.receiveShadow = true;
scene.add(backdrop);
// -------------------------------------------------------------------------
// Cabinet carcass
// -------------------------------------------------------------------------
addBox([2.34, 0.10, 1.06], [0, 0.055, 0.02], cabinetMetal);
addBox([2.58, 0.36, 1.22], [0, 0.27, 0], cabinetMetal);
addBox([2.58, 0.16, 1.20], [0, 3.20, 0], cabinetMetal);
addBox(
[0.16, 2.68, 1.10],
[-1.21, 1.73, 0],
cabinetMetal
);
addBox(
[0.16, 2.68, 1.10],
[1.21, 1.73, 0],
cabinetMetal
);
addBox([2.36, 2.64, 0.08], [0, 1.73, -0.50], cabinetMetal);
addBox([2.22, 2.55, 0.035], [0, 1.73, -0.44], cabinetInset);
addBox([2.30, 0.08, 1.02], [0, 0.52, 0.01], cabinetInset);
// Fixed dark reveal around the door opening.
addBox([0.075, 2.69, 0.035], [-1.13, 1.74, 0.56], darkGasket);
addBox([0.075, 2.69, 0.035], [1.13, 1.74, 0.56], darkGasket);
addBox([2.33, 0.075, 0.035], [0, 0.43, 0.56], darkGasket);
addBox([2.33, 0.075, 0.035], [0, 3.055, 0.56], darkGasket);
// Small interior light detail.
const lightStripMaterial = new THREE.MeshStandardMaterial({
color: 0xf1dfb7,
emissive: 0xe5c68d,
emissiveIntensity: 1.25,
roughness: 0.5
});
addBox(
[1.48, 0.026, 0.075],
[0, 3.095, 0.22],
lightStripMaterial,
scene,
false
);
// -------------------------------------------------------------------------
// Door and hinge assembly
// -------------------------------------------------------------------------
const door = new THREE.Group();
door.position.set(1.15, 0, 0.64);
scene.add(door);
const doorCenterX = -1.125;
const doorCenterY = 1.74;
const pane = new THREE.Mesh(
new THREE.BoxGeometry(2.18, 2.55, 0.085),
glassMaterial
);
pane.position.set(doorCenterX, doorCenterY, 0);
pane.renderOrder = 5;
door.add(pane);
// Tinted perimeter geometry makes the physical glass thickness explicit.
const edgeDepth = 0.105;
const edgeWidth = 0.052;
addBox(
[edgeWidth, 2.55, edgeDepth],
[doorCenterX - 1.064, doorCenterY, 0],
glassEdgeMaterial,
door,
false
).renderOrder = 6;
addBox(
[edgeWidth, 2.55, edgeDepth],
[doorCenterX + 1.064, doorCenterY, 0],
glassEdgeMaterial,
door,
false
).renderOrder = 6;
addBox(
[2.18, edgeWidth, edgeDepth],
[doorCenterX, doorCenterY - 1.249, 0],
glassEdgeMaterial,
door,
false
).renderOrder = 6;
addBox(
[2.18, edgeWidth, edgeDepth],
[doorCenterX, doorCenterY + 1.249, 0],
glassEdgeMaterial,
door,
false
).renderOrder = 6;
// Slim frame that stays visually secondary to the glass.
addBox(
[0.065, 2.68, 0.075],
[0, 1.74, 0.025],
darkBronze,
door
);
addBox(
[0.065, 2.68, 0.075],
[-2.25, 1.74, 0.025],
darkBronze,
door
);
addBox(
[2.315, 0.065, 0.075],
[doorCenterX, 0.435, 0.025],
darkBronze,
door
);
addBox(
[2.315, 0.065, 0.075],
[doorCenterX, 3.045, 0.025],
darkBronze,
door
);
// Vertical pull handle.
addCylinder(
0.026,
0.48,
[-2.00, 1.70, 0.15],
bronze,
door
);
for (const y of [1.49, 1.91]) {
const mount = addCylinder(
0.025,
0.105,
[-2.00, y, 0.095],
bronze,
door
);
mount.rotation.x = Math.PI / 2;
}
// Hinge barrels and fixed leaves.
for (const y of [0.76, 1.73, 2.70]) {
addCylinder(
0.057,
0.28,
[1.18, y, 0.64],
bronze,
scene
);
const pin = addCylinder(
0.018,
0.31,
[1.18, y, 0.64],
darkBronze,
scene,
20
);
pin.castShadow = false;
for (const offset of [-0.105, 0.105]) {
const collar = new THREE.Mesh(
new THREE.TorusGeometry(0.058, 0.008, 8, 32),
darkBronze
);
collar.rotation.x = Math.PI / 2;
collar.position.set(1.18, y + offset, 0.64);
collar.castShadow = true;
scene.add(collar);
}
addBox(
[0.14, 0.15, 0.045],
[1.275, y, 0.61],
darkBronze,
scene
);
addBox(
[0.16, 0.15, 0.04],
[-0.08, y, -0.015],
darkBronze,
door
);
const screw = addCylinder(
0.011,
0.012,
[-0.08, y, 0.012],
bronze,
door,
18
);
screw.rotation.x = Math.PI / 2;
}
// -------------------------------------------------------------------------
// Restrained surface reflections
// -------------------------------------------------------------------------
const reflectionTexture = makeCanvasTexture(512, 1024, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
const broad = ctx.createLinearGradient(0, 0, w, 0);
broad.addColorStop(0, "rgba(255,255,255,0)");
broad.addColorStop(0.18, "rgba(235,255,248,0.14)");
broad.addColorStop(0.32, "rgba(255,255,255,0.02)");
broad.addColorStop(1, "rgba(255,255,255,0)");
ctx.fillStyle = broad;
ctx.fillRect(0, 0, w, h);
ctx.save();
ctx.translate(120, 0);
ctx.rotate(-0.14);
ctx.filter = "blur(15px)";
ctx.fillStyle = "rgba(255,255,255,0.24)";
ctx.fillRect(-22, -160, 34, 1350);
ctx.restore();
ctx.save();
ctx.translate(350, 0);
ctx.rotate(-0.14);
ctx.filter = "blur(5px)";
ctx.fillStyle = "rgba(255,255,255,0.12)";
ctx.fillRect(-5, -120, 9, 1250);
ctx.restore();
});
const reflection = new THREE.Mesh(
new THREE.PlaneGeometry(2.12, 2.50),
new THREE.MeshBasicMaterial({
map: reflectionTexture,
transparent: true,
opacity: 0.30,
depthWrite: false,
blending: THREE.AdditiveBlending,
side: THREE.DoubleSide
})
);
reflection.position.set(doorCenterX, doorCenterY, 0.049);
reflection.renderOrder = 12;
door.add(reflection);
// A small etched collection mark near the bottom of the pane.
const etchingTexture = makeCanvasTexture(512, 128, (ctx, w, h) => {
ctx.clearRect(0, 0, w, h);
ctx.fillStyle = "rgba(241,255,249,0.85)";
ctx.font = "600 23px Arial";
ctx.letterSpacing = "5px";
ctx.textAlign = "center";
ctx.fillText("FIELD COLLECTION / 07", w / 2, 52);
ctx.fillStyle = "rgba(241,255,249,0.55)";
ctx.fillRect(155, 76, 202, 2);
});
const etching = new THREE.Mesh(
new THREE.PlaneGeometry(0.68, 0.17),
new THREE.MeshBasicMaterial({
map: etchingTexture,
transparent: true,
opacity: 0.32,
depthWrite: false
})
);
etching.position.set(-0.66, 0.59, 0.052);
etching.renderOrder = 13;
door.add(etching);
// -------------------------------------------------------------------------
// Specimen: stylized dried botanical in a ceramic vessel
// -------------------------------------------------------------------------
addBox(
[0.94, 0.10, 0.70],
[0.02, 0.59, 0.01],
stone
);
const vaseProfile = [
new THREE.Vector2(0.00, 0.00),
new THREE.Vector2(0.19, 0.015),
new THREE.Vector2(0.235, 0.10),
new THREE.Vector2(0.225, 0.24),
new THREE.Vector2(0.175, 0.39),
new THREE.Vector2(0.105, 0.48),
new THREE.Vector2(0.10, 0.58),
new THREE.Vector2(0.135, 0.62),
new THREE.Vector2(0.115, 0.64),
new THREE.Vector2(0.00, 0.64)
];
const vase = new THREE.Mesh(
new THREE.LatheGeometry(vaseProfile, 48),
ceramic
);
vase.position.set(0.02, 0.64, 0.02);
vase.castShadow = true;
vase.receiveShadow = true;
scene.add(vase);
const neck = new THREE.Mesh(
new THREE.CircleGeometry(0.108, 40),
new THREE.MeshStandardMaterial({
color: 0x3b2c21,
roughness: 0.92
})
);
neck.rotation.x = -Math.PI / 2;
neck.position.set(0.02, 1.279, 0.02);
scene.add(neck);
function addBranch(points, radius = 0.014) {
const curve = new THREE.CatmullRomCurve3(
points.map((p) => new THREE.Vector3(...p))
);
const mesh = new THREE.Mesh(
new THREE.TubeGeometry(curve, 28, radius, 8, false),
branchMaterial
);
mesh.castShadow = true;
scene.add(mesh);
return curve;
}
const mainBranch = addBranch(
[
[0.02, 1.24, 0.02],
[0.10, 1.58, 0.00],
[-0.04, 1.91, 0.03],
[0.10, 2.24, -0.01],
[0.04, 2.55, 0.02],
[0.13, 2.79, 0.00]
],
0.025
);
addBranch([
[0.06, 1.47, 0.01],
[-0.15, 1.61, 0.02],
[-0.37, 1.74, 0.00]
]);
addBranch([
[0.04, 1.67, 0.01],
[0.24, 1.78, -0.02],
[0.42, 1.91, 0.01]
]);
addBranch([
[-0.02, 1.86, 0.02],
[-0.25, 1.99, -0.01],
[-0.40, 2.15, 0.02]
]);
addBranch([
[0.06, 2.05, 0.00],
[0.29, 2.17, 0.03],
[0.43, 2.33, 0.01]
]);
addBranch([
[0.08, 2.29, 0.01],
[-0.12, 2.40, -0.01],
[-0.26, 2.53, 0.01]
]);
addBranch([
[0.10, 2.52, 0.01],
[0.27, 2.63, 0.02],
[0.35, 2.74, 0.00]
], 0.011);
const leafShape = new THREE.Shape();
leafShape.moveTo(0, 0);
leafShape.bezierCurveTo(0.09, 0.07, 0.17, 0.22, 0, 0.39);
leafShape.bezierCurveTo(-0.13, 0.23, -0.08, 0.07, 0, 0);
const leafGeometry = new THREE.ShapeGeometry(leafShape, 8);
function addLeaf(position, rotation, scale, materialIndex) {
const leaf = new THREE.Mesh(
leafGeometry,
leafMaterials[materialIndex % leafMaterials.length]
);
leaf.position.set(...position);
leaf.rotation.z = rotation;
leaf.rotation.y = (position[1] - 1.5) * 0.12;
leaf.scale.setScalar(scale);
leaf.castShadow = true;
leaf.receiveShadow = true;
scene.add(leaf);
}
const leafData = [
[[0.06, 1.42, 0.03], -1.05, 0.85, 0],
[[0.08, 1.54, 0.01], 1.05, 0.80, 1],
[[-0.18, 1.62, 0.03], -0.92, 0.74, 2],
[[-0.37, 1.74, 0.01], -0.55, 0.83, 0],
[[0.24, 1.78, 0.00], 0.95, 0.86, 1],
[[0.42, 1.91, 0.02], 0.48, 0.76, 2],
[[-0.25, 1.99, 0.00], -0.88, 0.83, 1],
[[-0.40, 2.15, 0.03], -0.43, 0.72, 0],
[[0.28, 2.17, 0.04], 0.93, 0.77, 2],
[[0.43, 2.33, 0.02], 0.48, 0.73, 0],
[[-0.12, 2.40, 0.00], -0.93, 0.75, 1],
[[-0.26, 2.53, 0.02], -0.50, 0.68, 2],
[[0.27, 2.63, 0.03], 0.87, 0.68, 0],
[[0.35, 2.74, 0.01], 0.42, 0.62, 1]
];
leafData.forEach((data, index) => {
addLeaf(data[0], data[1], data[2], index);
});
const podMaterial = new THREE.MeshStandardMaterial({
color: 0x93613e,
roughness: 0.86
});
[
[-0.39, 2.14, 0.03, 0.025],
[0.43, 2.32, 0.02, 0.022],
[-0.26, 2.52, 0.03, 0.019]
].forEach(([x, y, z, scale]) => {
const pod = new THREE.Mesh(
new THREE.SphereGeometry(scale, 14, 10),
podMaterial
);
pod.position.set(x, y, z);
pod.scale.set(0.7, 1.45, 0.72);
pod.castShadow = true;
scene.add(pod);
});
// Museum specimen label.
const labelTexture = makeCanvasTexture(1024, 420, (ctx, w, h) => {
ctx.fillStyle = "#d2c7ad";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#6e5c43";
ctx.lineWidth = 5;
ctx.strokeRect(18, 18, w - 36, h - 36);
ctx.fillStyle = "#3c3328";
ctx.font = "600 34px Arial";
ctx.letterSpacing = "4px";
ctx.fillText("HERBARIUM / SPECIMEN 07", 62, 92);
ctx.font = "italic 57px Georgia";
ctx.letterSpacing = "0px";
ctx.fillText("Ficus aurea", 62, 190);
ctx.font = "27px Arial";
ctx.fillText("DRIED BRANCH · FIELD STUDY", 62, 252);
ctx.strokeStyle = "rgba(61,51,40,0.35)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(62, 292);
ctx.lineTo(w - 62, 292);
ctx.stroke();
ctx.font = "24px Arial";
ctx.fillText("CABINET STUDY — SERIES IV", 62, 348);
});
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.69, 0.285),
new THREE.MeshStandardMaterial({
map: labelTexture,
roughness: 0.8,
metalness: 0
})
);
label.position.set(0.70, 0.73, 0.43);
label.rotation.x = -0.14;
label.receiveShadow = true;
scene.add(label);
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
scene.add(
new THREE.HemisphereLight(0xfff4df, 0x424840, 1.85)
);
const keyLight = new THREE.DirectionalLight(0xfff0d3, 3.35);
keyLight.position.set(-3.8, 7.2, 5.6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xd8eee7, 1.3);
fillLight.position.set(4.5, 3.6, 4.0);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xd8e9df, 2.25);
rimLight.position.set(-4.5, 4.5, -3.5);
scene.add(rimLight);
const interiorLight = new THREE.SpotLight(
0xffdfaa,
24,
5.5,
0.72,
0.92,
2
);
interiorLight.position.set(0, 3.01, 0.22);
interiorLight.target.position.set(0, 0.75, 0);
scene.add(interiorLight, interiorLight.target);
// -------------------------------------------------------------------------
// Direct camera controls, implemented without addons
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let previousX = 0;
let previousY = 0;
let activePointerId = null;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
activePointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== activePointerId) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.theta -= dx * 0.005;
controls.phi = THREE.MathUtils.clamp(
controls.phi + dy * 0.0045,
0.78,
1.47
);
controls.theta = THREE.MathUtils.clamp(
controls.theta,
-0.95,
1.18
);
});
function endDrag(event) {
if (event.pointerId !== activePointerId) return;
dragging = false;
activePointerId = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius + event.deltaY * 0.0035,
4.45,
9.2
);
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
updateCamera();
const resetButton = document.getElementById("resetButton");
resetButton.addEventListener("click", () => {
controls.radius = defaultControls.radius;
controls.phi = defaultControls.phi;
controls.theta = defaultControls.theta;
});
// -------------------------------------------------------------------------
// Door interaction
// -------------------------------------------------------------------------
const doorButton = document.getElementById("doorButton");
const doorLabel = document.getElementById("doorLabel");
const doorDetail = document.getElementById("doorDetail");
const maxDoorAngle = THREE.MathUtils.degToRad(22);
let doorTarget = 0;
let doorAngle = 0;
function updateDoorButton() {
if (doorTarget > 0) {
doorLabel.textContent = "CLOSE DOOR";
doorDetail.textContent = "HINGE TEST · 22°";
} else {
doorLabel.textContent = "OPEN DOOR";
doorDetail.textContent = "HINGE TEST · 22°";
}
}
doorButton.addEventListener("click", () => {
doorTarget = doorTarget > 0 ? 0 : maxDoorAngle;
updateDoorButton();
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 5.5);
doorAngle = THREE.MathUtils.lerp(doorAngle, doorTarget, smoothing);
door.rotation.y = doorAngle;
updateCamera();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
});
}
}
animate();
</script>
</body>
</html>
```