Prompt specification
Build or customize the Three.js 3D scene "Deciduous leaf attachment and scar" 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: Deciduous leaf attachment and scar
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/deciduous-leaf-attachment-and-scar-x0777
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a voxel study of a deciduous twig. Show one attached leaf on a short petiole, one exposed leaf scar lower on the stem, and a small bud at a distinct nearby position. Use a close, slightly diagonal view so these features do not overlap. Construct the twig from irregular brown blocks, the leaf from a thin stepped surface, and the bud from tightly grouped smaller cubes. A few unobtrusive markers may identify the three structures. Keep the scene static and compact, with a plain background that makes the attachment points and relative positions clear.
Working Three.js Starter (deciduous-leaf-attachment-and-scar-x0777):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Study of a Deciduous Twig</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5dc;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
position: absolute;
inset: 0;
z-index: 1;
display: block;
}
#annotations {
position: absolute;
inset: 0;
z-index: 2;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
.annotation-line {
stroke: #666a63;
stroke-width: 1;
stroke-opacity: 0.65;
vector-effect: non-scaling-stroke;
}
.annotation-dot {
fill: #e9e5dc;
stroke: #666a63;
stroke-width: 1.2;
vector-effect: non-scaling-stroke;
}
.annotation-text {
fill: #50534e;
font-size: 11px;
font-weight: 500;
letter-spacing: 0.02em;
paint-order: stroke;
stroke: #e9e5dc;
stroke-width: 3px;
stroke-linejoin: round;
}
</style>
</head>
<body>
<main
id="scene"
role="img"
aria-label="A voxel-style deciduous twig with an attached leaf, a lower leaf scar, and a nearby bud."
></main>
<svg id="annotations" aria-hidden="true">
<g id="label-leaf">
<line class="annotation-line"></line>
<circle class="annotation-dot" r="3"></circle>
<text class="annotation-text">attached leaf</text>
</g>
<g id="label-scar">
<line class="annotation-line"></line>
<circle class="annotation-dot" r="3"></circle>
<text class="annotation-text">leaf scar</text>
</g>
<g id="label-bud">
<line class="annotation-line"></line>
<circle class="annotation-dot" r="3"></circle>
<text class="annotation-text">bud</text>
</g>
</svg>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5dc);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
document.querySelector("#scene").appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera(31, 1, 0.1, 50);
const cameraTarget = new THREE.Vector3(0.38, -0.02, 0);
const cameraDirection = new THREE.Vector3(3.35, 2.2, 6.6).normalize();
scene.add(new THREE.HemisphereLight(0xfffdf7, 0x807568, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff4df, 3.2);
keyLight.position.set(4.5, 6.5, 7.5);
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9ddeb, 1.05);
fillLight.position.set(-4, 1.5, 5);
scene.add(fillLight);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.9,
metalness: 0
})
);
}
return materialCache.get(color);
}
function addBlock(x, y, z, width, height, depth, color) {
const mesh = new THREE.Mesh(cubeGeometry, material(color));
mesh.position.set(x, y, z);
mesh.scale.set(width, height, depth);
scene.add(mesh);
return mesh;
}
// Irregular, axis-aligned brown blocks form the main twig.
const twigBlocks = [
[-0.03, -1.39, 0.00, 0.29, 0.31, 0.30, 0x75503a],
[ 0.02, -1.08, 0.01, 0.31, 0.31, 0.31, 0x80583d],
[-0.02, -0.77, -0.01, 0.31, 0.31, 0.30, 0x714b37],
[ 0.01, -0.46, 0.00, 0.33, 0.32, 0.32, 0x835a3f],
[-0.01, -0.15, 0.01, 0.31, 0.31, 0.30, 0x76503a],
[ 0.02, 0.16, 0.00, 0.32, 0.31, 0.31, 0x80583f],
[-0.01, 0.47, 0.01, 0.30, 0.30, 0.30, 0x6e4936],
[ 0.02, 0.77, 0.00, 0.31, 0.31, 0.30, 0x7d543b],
[ 0.00, 1.06, -0.01, 0.27, 0.28, 0.27, 0x8a6043]
];
for (const block of twigBlocks) {
addBlock(...block);
}
// A few subtle side-facing bark voxels.
addBlock(0.174, 0.42, 0.02, 0.018, 0.12, 0.055, 0x563d31);
addBlock(0.169, -0.79, -0.015, 0.018, 0.09, 0.045, 0x5d4132);
addBlock(-0.151, 0.97, -0.01, 0.018, 0.07, 0.04, 0x604332);
// Short petiole: three small brown segments attached to the upper node.
addBlock(0.16, 0.81, 0.04, 0.18, 0.085, 0.085, 0x6d5135);
addBlock(0.31, 0.835, 0.045, 0.16, 0.08, 0.08, 0x79603a);
addBlock(0.45, 0.845, 0.05, 0.15, 0.075, 0.075, 0x886740);
// Thin, stepped voxel leaf. Each row is a blocky cross-section.
const leafRows = [
[4],
[3, 4, 5],
[2, 3, 4, 5, 6],
[1, 2, 3, 4, 5, 6, 7],
[1, 2, 3, 4, 5, 6, 7],
[2, 3, 4, 5, 6],
[3, 4, 5],
[4]
];
const leafGreen = [0x3e7138, 0x4b813d, 0x356a34, 0x5b8e43];
const leafMidrib = 0x86a75a;
const cellSize = 0.135;
const leafBaseX = 0.565;
const leafCenterY = 0.845;
leafRows.forEach((columns, row) => {
columns.forEach((column) => {
const isEdge =
column === Math.min(...columns) ||
column === Math.max(...columns);
const color =
column === 4
? leafMidrib
: leafGreen[(row + column * 2) % leafGreen.length];
const x = leafBaseX + row * cellSize;
const y = leafCenterY + (column - 4) * cellSize;
const z = 0.055 + Math.sin(row * 0.85) * 0.009;
addBlock(
x,
y,
z,
cellSize * 0.98,
cellSize * 0.98,
isEdge ? 0.048 : 0.042,
color
);
});
});
// Exposed leaf scar on the front of a lower stem block.
const scarColors = [0xc69a71, 0xd0a77d, 0xbd8c65, 0xd8b087];
const scarPixels = [
[ 0.000, 0.000],
[-0.052, 0.025],
[ 0.052, 0.025],
[-0.052, -0.052],
[ 0.052, -0.052],
[ 0.000, -0.115],
[ 0.000, 0.092]
];
scarPixels.forEach(([x, y], index) => {
addBlock(
x,
-0.51 + y,
0.177,
0.071,
0.071,
0.025,
scarColors[index % scarColors.length]
);
});
// Small lateral twig supporting the bud.
addBlock(-0.20, 0.09, 0.035, 0.18, 0.085, 0.085, 0x765239);
addBlock(-0.35, 0.105, 0.065, 0.16, 0.08, 0.08, 0x805b3e);
addBlock(-0.46, 0.115, 0.09, 0.13, 0.075, 0.075, 0x8b6242);
// Bud made from tightly grouped, smaller cubes.
const budX = -0.535;
const budY = 0.12;
const budZ = 0.105;
const budCube = 0.075;
const budPixels = [
[ 0, 0, 0],
[-0.075, 0, 0],
[ 0.075, 0, 0],
[ 0, 0, -0.075],
[ 0, 0, 0.075],
[ 0, 0.075, 0],
[-0.075, 0.075, 0],
[ 0.075, 0.075, 0],
[ 0, 0.075, -0.075],
[ 0, 0.075, 0.075],
[-0.075, 0.15, 0],
[ 0.075, 0.15, 0],
[ 0, 0.15, -0.075],
[ 0, 0.15, 0.075],
[ 0, 0.225, 0],
[ 0, 0.30, 0]
];
const budColors = [0x704258, 0x82506a, 0x965b75, 0x684052];
budPixels.forEach(([x, y, z], index) => {
const color = budColors[(index + Math.floor(index / 5)) % budColors.length];
addBlock(
budX + x,
budY + y,
budZ + z,
budCube,
budCube,
budCube,
color
);
});
// Annotation anchors and label offsets.
const annotations = [
{
id: "label-leaf",
anchor: new THREE.Vector3(1.42, 0.92, 0.07),
offset: [42, -54]
},
{
id: "label-scar",
anchor: new THREE.Vector3(0.0, -0.51, 0.195),
offset: [-70, 55]
},
{
id: "label-bud",
anchor: new THREE.Vector3(-0.535, 0.31, 0.105),
offset: [-66, -36]
}
];
function projectPoint(point) {
const projected = point.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
};
}
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotations) {
const group = document.getElementById(annotation.id);
const point = projectPoint(annotation.anchor);
let endX = point.x + annotation.offset[0];
let endY = point.y + annotation.offset[1];
endX = THREE.MathUtils.clamp(endX, 12, width - 12);
endY = THREE.MathUtils.clamp(endY, 18, height - 12);
const line = group.querySelector("line");
const dot = group.querySelector("circle");
const text = group.querySelector("text");
line.setAttribute("x1", point.x);
line.setAttribute("y1", point.y);
line.setAttribute("x2", endX);
line.setAttribute("y2", endY);
dot.setAttribute("cx", point.x);
dot.setAttribute("cy", point.y);
const labelOnLeft = endX < point.x;
text.setAttribute(
"x",
labelOnLeft ? endX - 6 : endX + 6
);
text.setAttribute("y", endY + 4);
text.setAttribute(
"text-anchor",
labelOnLeft ? "end" : "start"
);
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
camera.aspect = aspect;
// Keep the study compact while fitting narrow portrait screens.
const fovRadians = THREE.MathUtils.degToRad(camera.fov);
const desiredHeight = 3.7;
const desiredWidth = 3.25;
const distance = Math.max(
desiredHeight / (2 * Math.tan(fovRadians / 2)),
desiredWidth / (2 * Math.tan(fovRadians / 2) * aspect)
);
camera.position.copy(cameraTarget).addScaledVector(
cameraDirection,
distance
);
camera.lookAt(cameraTarget);
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.render(scene, camera);
updateAnnotations();
}
window.addEventListener("resize", resize);
resize();
</script>
</body>
</html>
```