Prompt specification
Build or customize the Three.js 3D scene "Clove branch beside dried spice buds" 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: Clove branch beside dried spice buds
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/clove-branch-beside-dried-spice-buds-x2621
Scene Description Prompt:
A voxel clove branch sits beside dried spice buds, showing their botanical connection. Make one HTML scene using Three.js from cdnjs.
Working Three.js Starter (clove-branch-beside-dried-spice-buds-x2621):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Clove — From Flower to Spice</title>
<style>
:root {
--ink: #29251f;
--muted: #6e6458;
--paper: rgba(248, 243, 233, 0.88);
--line: rgba(73, 58, 40, 0.18);
--pink: #cf6576;
--brown: #74452d;
--green: #3d6748;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8dfd0;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.heading {
position: fixed;
z-index: 5;
top: 28px;
left: 32px;
width: min(420px, calc(100vw - 64px));
pointer-events: none;
}
.kicker {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 8px;
color: #78513b;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.kicker::before {
width: 28px;
height: 2px;
background: #a96c48;
content: "";
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(34px, 5vw, 62px);
font-weight: 500;
line-height: 0.92;
letter-spacing: -0.045em;
}
.heading p {
max-width: 350px;
margin: 15px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
z-index: 5;
top: 30px;
right: 32px;
display: grid;
gap: 9px;
padding: 14px 16px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--paper);
box-shadow: 0 12px 35px rgba(68, 46, 28, 0.08);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
color: #62584d;
font-size: 11px;
white-space: nowrap;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.swatch.fresh {
background: var(--pink);
}
.swatch.dried {
background: var(--brown);
}
.swatch.leaf {
background: var(--green);
}
.info-card {
position: fixed;
z-index: 6;
left: 32px;
bottom: 30px;
width: min(390px, calc(100vw - 64px));
padding: 18px 20px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--paper);
box-shadow: 0 16px 45px rgba(68, 46, 28, 0.11);
backdrop-filter: blur(14px);
pointer-events: none;
}
.info-card .eyebrow {
color: #9b6847;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.info-card h2 {
margin: 6px 0 7px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 500;
letter-spacing: -0.02em;
}
.info-card p {
margin: 0;
color: #655c51;
font-size: 12px;
line-height: 1.55;
}
.hint {
position: fixed;
z-index: 5;
right: 32px;
bottom: 31px;
color: rgba(64, 52, 40, 0.62);
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
}
.scene-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
color: #4b4034;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -100%);
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 25px;
background: rgba(80, 62, 43, 0.35);
content: "";
}
.scene-label .dot {
width: 7px;
height: 7px;
border: 2px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
background: var(--pink);
box-shadow: 0 0 0 1px rgba(56, 42, 28, 0.25);
}
.scene-label.dried .dot {
background: var(--brown);
}
@media (max-width: 720px) {
.heading {
top: 20px;
left: 20px;
}
.heading p {
display: none;
}
.legend {
top: auto;
right: 20px;
bottom: 112px;
}
.info-card {
left: 20px;
bottom: 20px;
width: calc(100vw - 40px);
}
.hint {
display: none;
}
.scene-label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="heading">
<div class="kicker">Botanical study · 01</div>
<h1>Clove,<br />before & after.</h1>
<p>
A living clove inflorescence beside its sun-dried spice form.
Drag to orbit, scroll to zoom, or select a plant part.
</p>
</div>
<div class="legend">
<div class="legend-row">
<span class="swatch fresh"></span>
Fresh flower buds
</div>
<div class="legend-row">
<span class="swatch dried"></span>
Dried spice buds
</div>
<div class="legend-row">
<span class="swatch leaf"></span>
Clove leaves
</div>
</div>
<div class="info-card" id="infoCard">
<div class="eyebrow" id="infoEyebrow">Botanical field note</div>
<h2 id="infoTitle">One bud, two moments</h2>
<p id="infoText">
Clove flowers begin as clustered pink buds. Harvested before opening and
sun-dried, they become the familiar brown, nail-shaped spice.
</p>
</div>
<div class="hint">Drag · rotate Scroll · zoom Click · inspect</div>
<div class="scene-label" id="freshLabel">
<span class="dot"></span>
Fresh inflorescence
</div>
<div class="scene-label dried" id="driedLabel">
<span class="dot"></span>
Dried cloves
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ------------------------------------------------------------------
// Scene setup
// ------------------------------------------------------------------
const container = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe8dfd0);
scene.fog = new THREE.Fog(0xe8dfd0, 13, 27);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
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 display of a clove branch and dried clove buds"
);
renderer.domElement.tabIndex = 0;
container.appendChild(renderer.domElement);
// Deterministic randomness keeps the arrangement stable between loads.
let seed = 9137;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const materialCache = new Map();
function material(color, roughness = 0.82, metalness = 0) {
const key = `${color}-${roughness}-${metalness}`;
if (!materialCache.has(key)) {
materialCache.set(
key,
new THREE.MeshStandardMaterial({
color,
roughness,
metalness
})
);
}
return materialCache.get(key);
}
const barkMats = [
material(0x68452f),
material(0x795239),
material(0x543722),
material(0x8a6040)
];
const leafMats = [
material(0x315c3e),
material(0x3d6947),
material(0x496f4c),
material(0x2d5438),
material(0x547957)
];
const pinkMats = [
material(0xc95c70),
material(0xdb7181),
material(0xb94b60),
material(0xe1848d)
];
const driedMats = [
material(0x70432c),
material(0x825237),
material(0x5c3826),
material(0x946442)
];
function block(parent, size, position, mat, rotation = null) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size.x, size.y, size.z),
mat
);
mesh.position.copy(position);
if (rotation) mesh.rotation.set(rotation.x, rotation.y, rotation.z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function beam(parent, from, to, width, depth, mat) {
const direction = new THREE.Vector3().subVectors(to, from);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(from, to)
.multiplyScalar(0.5);
const mesh = block(
parent,
new THREE.Vector3(width, length, depth),
midpoint,
mat
);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.clone().normalize()
);
return mesh;
}
// ------------------------------------------------------------------
// Lighting and stage
// ------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff8e9, 0x8b7963, 2.0));
const keyLight = new THREE.DirectionalLight(0xfff1d2, 3.4);
keyLight.position.set(-4.5, 8.5, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc8dded, 1.25);
fillLight.position.set(6, 4, -5);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffc38e, 18, 12, 2);
warmLight.position.set(3.5, 5, 3);
scene.add(warmLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
material(0xd9cdb8, 0.96)
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.035;
ground.receiveShadow = true;
scene.add(ground);
// A small voxel support beneath the cut branch.
const support = new THREE.Group();
support.position.set(-3.75, 0.12, 0.16);
scene.add(support);
block(support, new THREE.Vector3(1.0, 0.22, 0.86), new THREE.Vector3(0, 0.08, 0), material(0xc9bba4));
block(support, new THREE.Vector3(0.72, 0.12, 0.64), new THREE.Vector3(0, 0.25, 0), material(0xe0d3bd));
// ------------------------------------------------------------------
// Voxel branch
// ------------------------------------------------------------------
const branch = new THREE.Group();
scene.add(branch);
const points = {
a: new THREE.Vector3(-4.15, 0.43, 0.18),
b: new THREE.Vector3(-3.55, 0.76, 0.08),
c: new THREE.Vector3(-2.90, 1.22, -0.02),
d: new THREE.Vector3(-2.18, 1.72, 0.03),
e: new THREE.Vector3(-1.40, 2.17, 0.12),
f: new THREE.Vector3(-0.78, 2.63, 0.15)
};
const trunkPairs = [
[points.a, points.b, 0.43],
[points.b, points.c, 0.38],
[points.c, points.d, 0.31],
[points.d, points.e, 0.25],
[points.e, points.f, 0.20]
];
trunkPairs.forEach(([from, to, width], index) => {
beam(branch, from, to, width, width * 0.88, barkMats[index % 3]);
});
const twigA = new THREE.Vector3(-3.00, 1.22, -0.02);
const twigAEnd = new THREE.Vector3(-3.38, 1.82, -0.18);
const twigB = new THREE.Vector3(-2.20, 1.70, 0.03);
const twigBEnd = new THREE.Vector3(-1.25, 1.95, -0.48);
const twigC = new THREE.Vector3(-1.48, 2.12, 0.10);
const twigCEnd = new THREE.Vector3(-0.77, 2.58, 0.46);
beam(branch, twigA, twigAEnd, 0.19, 0.17, barkMats[1]);
beam(branch, twigB, twigBEnd, 0.17, 0.15, barkMats[3]);
beam(branch, twigC, twigCEnd, 0.14, 0.13, barkMats[0]);
// Blocky bark knots and highlights.
for (let i = 0; i < 26; i++) {
const pair = trunkPairs[Math.floor(random() * trunkPairs.length)];
const t = random();
const p = new THREE.Vector3().lerpVectors(pair[0], pair[1], t);
p.x += (random() - 0.5) * 0.28;
p.z += (random() - 0.5) * 0.28;
p.y += (random() - 0.5) * 0.12;
block(
branch,
new THREE.Vector3(
0.09 + random() * 0.11,
0.07 + random() * 0.10,
0.08 + random() * 0.08
),
p,
barkMats[Math.floor(random() * barkMats.length)],
new THREE.Euler(random(), random(), random())
);
}
// ------------------------------------------------------------------
// Voxel leaves
// ------------------------------------------------------------------
function makeLeaf(anchor, direction, length = 1.55, width = 0.54, colorIndex = 0) {
const leaf = new THREE.Group();
leaf.position.copy(anchor);
branch.add(leaf);
const forward = direction.clone().normalize();
const side = new THREE.Vector3().crossVectors(
new THREE.Vector3(0, 1, 0),
forward
).normalize();
const normal = new THREE.Vector3().crossVectors(side, forward).normalize();
const basis = new THREE.Matrix4().makeBasis(forward, normal, side);
leaf.quaternion.setFromRotationMatrix(basis);
const slices = 9;
const sliceLength = length / slices;
for (let i = 0; i < slices; i++) {
const t = (i + 0.5) / slices;
const profile = Math.sin(Math.PI * Math.pow(t, 0.88));
const sliceWidth = Math.max(0.12, width * profile);
const mat = leafMats[(colorIndex + i + (i % 2)) % leafMats.length];
block(
leaf,
new THREE.Vector3(sliceLength * 0.94, 0.09, sliceWidth),
new THREE.Vector3((i + 0.5) * sliceLength, 0, 0),
mat
);
}
// Thin stepped central vein.
for (let i = 1; i < slices - 1; i++) {
block(
leaf,
new THREE.Vector3(sliceLength * 0.76, 0.025, 0.035),
new THREE.Vector3((i + 0.5) * sliceLength, 0.065, 0),
material(0x78916a)
);
}
block(
leaf,
new THREE.Vector3(0.32, 0.07, 0.075),
new THREE.Vector3(-0.06, 0, 0),
material(0x5b6940)
);
leaf.traverse((object) => {
if (object.isMesh) object.userData.category = "leaf";
});
return leaf;
}
makeLeaf(points.b.clone().add(new THREE.Vector3(0, 0.04, 0)), new THREE.Vector3(-0.85, 0.15, 0.85), 1.65, 0.58, 0);
makeLeaf(points.b.clone().add(new THREE.Vector3(0, 0.12, 0)), new THREE.Vector3(0.35, 0.18, -1.0), 1.43, 0.50, 1);
makeLeaf(points.c.clone().add(new THREE.Vector3(0, 0.03, 0)), new THREE.Vector3(-0.9, 0.15, 0.6), 1.72, 0.61, 2);
makeLeaf(points.c.clone().add(new THREE.Vector3(0, 0.10, 0)), new THREE.Vector3(0.65, 0.16, -0.9), 1.36, 0.48, 3);
makeLeaf(points.d.clone().add(new THREE.Vector3(0, 0.02, 0)), new THREE.Vector3(-0.7, 0.15, -0.85), 1.42, 0.51, 4);
makeLeaf(points.d.clone().add(new THREE.Vector3(0, 0.10, 0)), new THREE.Vector3(0.8, 0.18, 0.65), 1.54, 0.55, 1);
makeLeaf(twigAEnd.clone().add(new THREE.Vector3(0, 0.03, 0)), new THREE.Vector3(-0.5, 0.1, 0.9), 1.25, 0.43, 2);
makeLeaf(twigAEnd.clone().add(new THREE.Vector3(0, 0.08, 0)), new THREE.Vector3(0.25, 0.1, -1.0), 1.14, 0.40, 4);
makeLeaf(twigBEnd.clone().add(new THREE.Vector3(0, 0.02, 0)), new THREE.Vector3(0.8, 0.12, 0.5), 1.28, 0.46, 0);
makeLeaf(twigBEnd.clone().add(new THREE.Vector3(0, 0.08, 0)), new THREE.Vector3(-0.6, 0.16, -0.7), 1.22, 0.42, 3);
makeLeaf(twigCEnd.clone().add(new THREE.Vector3(0, 0.03, 0)), new THREE.Vector3(0.25, 0.1, 1.0), 1.30, 0.45, 2);
makeLeaf(twigCEnd.clone().add(new THREE.Vector3(0, 0.08, 0)), new THREE.Vector3(-0.85, 0.14, 0.4), 1.20, 0.43, 1);
// ------------------------------------------------------------------
// Flower buds
// ------------------------------------------------------------------
function makeBud(parent, position, axis, scale, fresh = true, category = "fresh") {
const bud = new THREE.Group();
bud.position.copy(position);
bud.scale.setScalar(scale);
parent.add(bud);
bud.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
axis.clone().normalize()
);
const bodyMats = fresh ? pinkMats : driedMats;
const petalMats = fresh
? [material(0xe27b89), material(0xd96879), material(0xc94f66)]
: [material(0x5f3927), material(0x75442d), material(0x4d3023)];
block(
bud,
new THREE.Vector3(0.065, 0.18, 0.065),
new THREE.Vector3(0, -0.31, 0),
fresh ? material(0x667447) : material(0x59402c)
);
block(
bud,
new THREE.Vector3(0.16, 0.27, 0.16),
new THREE.Vector3(0, -0.11, 0),
bodyMats[0]
);
block(
bud,
new THREE.Vector3(0.135, 0.19, 0.135),
new THREE.Vector3(0, 0.10, 0),
bodyMats[1]
);
// Four narrow petals suggest the unopened calyx of a clove flower.
for (let i = 0; i < 4; i++) {
const angle = (i / 4) * Math.PI * 2;
const offset = new THREE.Vector3(
Math.cos(angle) * 0.055,
0.24,
Math.sin(angle) * 0.055
);
const petal = block(
bud,
new THREE.Vector3(0.065, fresh ? 0.16 : 0.12, 0.095),
offset,
petalMats[i % petalMats.length]
);
petal.rotation.y = -angle;
}
bud.traverse((object) => {
if (object.isMesh) object.userData.category = category;
});
return bud;
}
function makeFreshCluster(anchor, count, spread, category = "fresh") {
const cluster = new THREE.Group();
cluster.position.copy(anchor);
scene.add(cluster);
for (let i = 0; i < count; i++) {
const angle = (i / count) * Math.PI * 2 + random() * 0.5;
const radial = spread * (0.35 + random() * 0.65);
const position = new THREE.Vector3(
Math.cos(angle) * radial,
random() * spread * 0.65,
Math.sin(angle) * radial
);
const axis = new THREE.Vector3(
Math.cos(angle) * 0.62,
0.72 + random() * 0.45,
Math.sin(angle) * 0.62
);
beam(
cluster,
new THREE.Vector3(0, -0.12, 0),
position.clone().add(new THREE.Vector3(0, -0.25, 0)),
0.06,
0.06,
material(0x64764a)
);
makeBud(
cluster,
position,
axis,
0.72 + random() * 0.25,
true,
category
);
}
return cluster;
}
const freshCluster = makeFreshCluster(
new THREE.Vector3(-0.70, 2.83, 0.18),
11,
0.68,
"fresh"
);
makeFreshCluster(
new THREE.Vector3(0.02, 2.55, 0.45),
5,
0.34,
"fresh"
);
// ------------------------------------------------------------------
// Dried spice display
// ------------------------------------------------------------------
const tray = new THREE.Group();
tray.position.set(2.35, 0.06, 0.25);
scene.add(tray);
block(
tray,
new THREE.Vector3(3.65, 0.20, 2.75),
new THREE.Vector3(0, 0.10, 0),
material(0xa89577)
);
block(
tray,
new THREE.Vector3(3.36, 0.08, 2.46),
new THREE.Vector3(0, 0.23, 0),
material(0xe7dcc5)
);
const trayTop = 0.29;
// Low block rim.
block(tray, new THREE.Vector3(3.65, 0.15, 0.14), new THREE.Vector3(0, 0.31, -1.30), material(0xb9a585));
block(tray, new THREE.Vector3(3.65, 0.15, 0.14), new THREE.Vector3(0, 0.31, 1.30), material(0xb9a585));
block(tray, new THREE.Vector3(0.14, 0.15, 2.45), new THREE.Vector3(-1.76, 0.31, 0), material(0xb9a585));
block(tray, new THREE.Vector3(0.14, 0.15, 2.45), new THREE.Vector3(1.76, 0.31, 0), material(0xb9a585));
const driedGroup = new THREE.Group();
driedGroup.position.set(2.35, trayTop, 0.25);
scene.add(driedGroup);
for (let i = 0; i < 16; i++) {
const x = (random() - 0.5) * 2.55;
const z = (random() - 0.5) * 1.85;
// Keep the central label area slightly less crowded.
if (Math.abs(x) < 0.45 && Math.abs(z) < 0.25 && i % 2 === 0) {
z += 0.55;
}
const axis = new THREE.Vector3(
random() - 0.5,
0.10 + random() * 0.30,
random() - 0.5
);
makeBud(
driedGroup,
new THREE.Vector3(x, 0.10 + random() * 0.05, z),
axis,
0.85 + random() * 0.42,
false,
"dried"
);
}
// A few detached petals and coarse spice fragments.
for (let i = 0; i < 22; i++) {
const size = 0.04 + random() * 0.055;
block(
driedGroup,
new THREE.Vector3(size * 1.9, size * 0.55, size),
new THREE.Vector3(
(random() - 0.5) * 3.0,
0.025,
(random() - 0.5) * 2.1
),
driedMats[Math.floor(random() * driedMats.length)],
new THREE.Euler(0, random() * Math.PI, random() * 0.35)
);
}
// ------------------------------------------------------------------
// Dotted botanical relationship line
// ------------------------------------------------------------------
const connectionMaterial = new THREE.MeshStandardMaterial({
color: 0xb67a36,
roughness: 0.68,
metalness: 0.08,
emissive: 0x5a3212,
emissiveIntensity: 0.12
});
const connectionCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.15, 3.02, 0.35),
new THREE.Vector3(0.50, 3.08, 0.48),
new THREE.Vector3(1.08, 2.45, 0.56),
new THREE.Vector3(1.46, 1.42, 0.60),
new THREE.Vector3(1.82, 0.52, 0.42)
]);
const connectionGroup = new THREE.Group();
scene.add(connectionGroup);
for (let i = 0; i <= 30; i++) {
if (i % 2 !== 0) continue;
const p = connectionCurve.getPoint(i / 30);
const dot = block(
connectionGroup,
new THREE.Vector3(0.055, 0.055, 0.055),
p,
connectionMaterial
);
dot.rotation.set(i * 0.19, i * 0.31, i * 0.13);
}
// Small voxel arrowhead near the dried display.
const arrow = block(
connectionGroup,
new THREE.Vector3(0.15, 0.15, 0.15),
new THREE.Vector3(1.86, 0.43, 0.39),
connectionMaterial,
new THREE.Euler(0.25, 0.6, 0.15)
);
// Floating dust motes add depth without distracting from the specimen.
const dust = new THREE.Group();
scene.add(dust);
const dustMaterial = new THREE.MeshBasicMaterial({
color: 0xfff4d9,
transparent: true,
opacity: 0.42
});
for (let i = 0; i < 34; i++) {
const size = 0.015 + random() * 0.025;
const mote = new THREE.Mesh(
new THREE.BoxGeometry(size, size, size),
dustMaterial
);
mote.position.set(
-6 + random() * 12,
0.6 + random() * 5.2,
-3 + random() * 7
);
mote.rotation.set(random() * 3, random() * 3, random() * 3);
dust.add(mote);
}
// ------------------------------------------------------------------
// Camera controls implemented directly
// ------------------------------------------------------------------
const target = new THREE.Vector3(-0.05, 1.35, 0.12);
const orbit = {
radius: 10.6,
theta: 0.60,
phi: 1.08
};
const defaultOrbit = { ...orbit };
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
target.y + orbit.radius * Math.cos(orbit.phi),
target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(target);
}
updateCamera();
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let pointerDown = null;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = {
x: event.clientX,
y: event.clientY,
lastX: event.clientX,
lastY: event.clientY,
moved: false
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - pointerDown.lastX;
const dy = event.clientY - pointerDown.lastY;
if (
Math.abs(event.clientX - pointerDown.x) +
Math.abs(event.clientY - pointerDown.y) > 4
) {
pointerDown.moved = true;
}
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.005,
0.45,
1.42
);
pointerDown.lastX = event.clientX;
pointerDown.lastY = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (pointerDown && !pointerDown.moved) {
inspectAt(event.clientX, event.clientY);
}
pointerDown = null;
});
canvas.addEventListener("pointercancel", () => {
pointerDown = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
6.7,
15.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
Object.assign(orbit, defaultOrbit);
updateCamera();
});
canvas.addEventListener("keydown", (event) => {
const key = event.key.toLowerCase();
if (key === "arrowleft") orbit.theta += 0.08;
else if (key === "arrowright") orbit.theta -= 0.08;
else if (key === "arrowup") orbit.phi = Math.max(0.45, orbit.phi - 0.06);
else if (key === "arrowdown") orbit.phi = Math.min(1.42, orbit.phi + 0.06);
else if (key === "+" || key === "=") orbit.radius = Math.max(6.7, orbit.radius - 0.5);
else if (key === "-") orbit.radius = Math.min(15.5, orbit.radius + 0.5);
else if (key === "r") Object.assign(orbit, defaultOrbit);
else return;
event.preventDefault();
updateCamera();
});
// ------------------------------------------------------------------
// Inspection labels and information card
// ------------------------------------------------------------------
const infoEyebrow = document.getElementById("infoEyebrow");
const infoTitle = document.getElementById("infoTitle");
const infoText = document.getElementById("infoText");
const freshLabel = document.getElementById("freshLabel");
const driedLabel = document.getElementById("driedLabel");
const content = {
fresh: {
eyebrow: "Living clove flower",
title: "Unopened inflorescence",
text:
"Clove flowers grow in small clusters. These pink, tightly closed buds contain the oils that later become concentrated in the dried spice."
},
dried: {
eyebrow: "Harvested & sun-dried",
title: "The familiar clove nail",
text:
"Each dried clove retains the narrow flower tube and four-petalled crown. Drying deepens its color and intensifies its warm, sweet aroma."
},
leaf: {
eyebrow: "Syzygium aromaticum",
title: "Glossy clove leaves",
text:
"The evergreen leaves are opposite, oval, and pointed. Their aromatic oil is distinct from the floral oil found in the spice buds."
}
};
function inspectAt(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
for (const hit of hits) {
const category = hit.object.userData.category;
if (category && content[category]) {
const data = content[category];
infoEyebrow.textContent = data.eyebrow;
infoTitle.textContent = data.title;
infoText.textContent = data.text;
return;
}
}
}
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.display = visible ? "flex" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const freshAnchor = new THREE.Vector3(-0.48, 3.62, 0.25);
const driedAnchor = new THREE.Vector3(2.55, 0.98, 0.30);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
// ------------------------------------------------------------------
// Render loop
// ------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
dust.children.forEach((mote, index) => {
mote.position.y += Math.sin(time * 0.35 + index) * 0.0008;
mote.rotation.x += 0.0015;
mote.rotation.y += 0.001;
});
placeLabel(freshLabel, freshAnchor);
placeLabel(driedLabel, driedAnchor);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```