Prompt specification
Build or customize the Three.js 3D scene "Avocado seed and flesh volumes" 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: Avocado seed and flesh volumes
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/avocado-seed-and-flesh-volumes-x0081
Scene Description Prompt:
I'd like to see this as a stylized Three.js scene: avocado seed and flesh volumes. Build two avocado halves with contrasting flesh, peel, and one large stone; remove the stone to expose a matching cavity and clearly readable material boundaries. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (avocado-seed-and-flesh-volumes-x0081):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Avocado Volume Study</title>
<style>
:root {
color-scheme: dark;
--ink: #eef4e9;
--muted: #9baaa0;
--accent: #c8df62;
--panel: rgba(13, 22, 20, 0.76);
--line: rgba(224, 241, 215, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #0d1514;
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;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: var(--ink);
}
.header {
position: absolute;
top: clamp(18px, 3vw, 34px);
left: clamp(18px, 3vw, 38px);
max-width: 420px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.eyebrow::before {
width: 24px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
font-size: clamp(27px, 4vw, 52px);
font-weight: 520;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 350px;
margin: 14px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.action-panel {
position: absolute;
top: clamp(18px, 3vw, 34px);
right: clamp(18px, 3vw, 38px);
display: grid;
justify-items: end;
gap: 10px;
pointer-events: auto;
}
.status {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--panel);
color: #dbe6d8;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.13em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.status-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 12px rgba(200, 223, 98, 0.8);
}
button {
appearance: none;
border: 1px solid rgba(200, 223, 98, 0.45);
border-radius: 999px;
padding: 11px 17px;
background: rgba(200, 223, 98, 0.11);
color: var(--accent);
font: inherit;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
border-color: rgba(200, 223, 98, 0.8);
background: rgba(200, 223, 98, 0.19);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.legend {
position: absolute;
bottom: clamp(18px, 3vw, 32px);
left: clamp(18px, 3vw, 38px);
display: flex;
flex-wrap: wrap;
gap: 9px 18px;
max-width: calc(100vw - 36px);
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
backdrop-filter: blur(12px);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #b8c5bb;
font-size: 10px;
letter-spacing: 0.035em;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}
.swatch.peel { background: #244f28; }
.swatch.flesh { background: #bfd35a; }
.swatch.cavity { background: #315426; }
.swatch.stone { background: #8b512b; }
.help {
position: absolute;
right: clamp(18px, 3vw, 38px);
bottom: clamp(22px, 3vw, 36px);
color: #738079;
font-size: 10px;
letter-spacing: 0.05em;
text-align: right;
}
@media (max-width: 700px) {
.header {
max-width: 245px;
}
.subtitle {
max-width: 225px;
font-size: 11px;
}
.action-panel {
justify-items: end;
}
.status {
max-width: 145px;
line-height: 1.35;
}
.help {
display: none;
}
.legend {
right: 18px;
gap: 8px 12px;
}
}
</style>
</head>
<body>
<div class="ui">
<header class="header">
<div class="eyebrow">Volume study / 01</div>
<h1>Avocado<br />anatomy</h1>
<p class="subtitle">
Two cut halves, one extracted stone, and a clearly exposed matching cavity.
</p>
</header>
<div class="action-panel">
<div class="status" aria-live="polite">
<span class="status-dot"></span>
<span id="statusText">Stone removed · cavity exposed</span>
</div>
<button id="toggleStone" type="button">Seat the stone</button>
</div>
<div class="legend" aria-label="Material legend">
<span class="legend-item"><i class="swatch peel"></i>Peel</span>
<span class="legend-item"><i class="swatch flesh"></i>Flesh</span>
<span class="legend-item"><i class="swatch cavity"></i>Cavity</span>
<span class="legend-item"><i class="swatch stone"></i>Stone</span>
</div>
<div class="help">Drag to orbit · wheel to zoom · double-click to reset</div>
</div>
<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(0x0d1514);
scene.fog = new THREE.Fog(0x0d1514, 13, 31);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe2f6df, 0x182019, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff0cc, 3.25);
keyLight.position.set(-5.5, 8.5, 7.5);
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 = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8cffb7, 1.25);
rimLight.position.set(6, 3.5, -4);
scene.add(rimLight);
const fillLight = new THREE.PointLight(0xcceeff, 20, 18, 2);
fillLight.position.set(1, 4, 8);
scene.add(fillLight);
const LENGTH = 4.6;
const HALF_LENGTH = LENGTH * 0.5;
const FLESH_FRACTION = 0.865;
const PIT_RX = 0.73;
const PIT_RY = 0.83;
const PIT_CY = -0.04;
function smoothstep(edge0, edge1, x) {
const t = THREE.MathUtils.clamp(
(x - edge0) / (edge1 - edge0),
0,
1
);
return t * t * (3 - 2 * t);
}
// A stylized pear profile: broad lower body tapering toward the stem.
function avocadoRadius(t) {
const s = Math.max(0, Math.sin(Math.PI * t));
return (
1.52 *
Math.pow(s, 0.62) *
(0.78 + 0.34 * (1 - t))
);
}
function avocadoDepth(t) {
const s = Math.max(0, Math.sin(Math.PI * t));
return 1.28 * Math.pow(s, 0.54);
}
function makePeelGeometry() {
const rows = 76;
const segments = 64;
const positions = [];
const colors = [];
const indices = [];
const dark = new THREE.Color(0x183d24);
const light = new THREE.Color(0x34713a);
const color = new THREE.Color();
for (let i = 0; i <= rows; i++) {
const t = i / rows;
const y = -HALF_LENGTH + t * LENGTH;
const radius = avocadoRadius(t);
const depth = avocadoDepth(t);
for (let j = 0; j <= segments; j++) {
const angle = Math.PI + (Math.PI * j) / segments;
const x = radius * Math.cos(angle);
const z = -depth * Math.sin(angle);
positions.push(x, y, z);
const variation =
0.5 +
0.22 * Math.sin(angle * 5.0 + y * 1.4) +
0.13 * Math.sin(angle * 9.0 - y * 0.8);
color.copy(dark).lerp(light, THREE.MathUtils.clamp(variation, 0, 1));
colors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < rows; i++) {
for (let j = 0; j < segments; j++) {
const a = i * (segments + 1) + j;
const b = a + segments + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeRimGeometry(innerFraction, outerFraction, zOffset) {
const rows = 76;
const columns = 6;
const positions = [];
const indices = [];
for (const side of [-1, 1]) {
const offset = positions.length / 3;
for (let i = 0; i <= rows; i++) {
const t = i / rows;
const y = -HALF_LENGTH + t * LENGTH;
const radius = avocadoRadius(t);
for (let j = 0; j <= columns; j++) {
const v = j / columns;
const fraction =
innerFraction + (outerFraction - innerFraction) * v;
positions.push(side * radius * fraction, y, zOffset);
}
}
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
const a = offset + i * (columns + 1) + j;
const b = a + columns + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeFleshGeometry() {
const rows = 112;
const columns = 68;
const positions = [];
const colors = [];
const indices = [];
const base = new THREE.Color(0xbfd45b);
const warm = new THREE.Color(0xd6df72);
const edge = new THREE.Color(0x769f38);
const cavity = new THREE.Color(0x294c20);
const color = new THREE.Color();
for (let i = 0; i <= rows; i++) {
const t = i / rows;
const y = -HALF_LENGTH + t * LENGTH;
const radius = avocadoRadius(t) * FLESH_FRACTION;
for (let j = 0; j <= columns; j++) {
const u = j / columns;
const x = (u * 2 - 1) * radius;
const q =
Math.pow(x / PIT_RX, 2) +
Math.pow((y - PIT_CY) / PIT_RY, 2);
let z = 0.075 + 0.008 * Math.sin(x * 4 + y * 1.8);
if (q < 1) {
z -= 0.57 * Math.sqrt(1 - q);
}
positions.push(x, y, z);
color.copy(base).lerp(warm, 0.18 * Math.sin(y * 1.4 + 1));
color.lerp(edge, smoothstep(0.72, 1, Math.abs(u * 2 - 1)) * 0.62);
if (q < 1) {
color.lerp(cavity, Math.pow(1 - q, 0.58) * 0.94);
}
colors.push(color.r, color.g, color.b);
}
}
for (let i = 0; i < rows; i++) {
for (let j = 0; j < columns; j++) {
const a = i * (columns + 1) + j;
const b = a + columns + 1;
const c = b + 1;
const d = a + 1;
indices.push(a, d, b, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("color", new THREE.Float32BufferAttribute(colors, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeCavityOutline() {
const points = [];
const segments = 128;
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
points.push(
new THREE.Vector3(
PIT_RX * 1.015 * Math.cos(angle),
PIT_CY + PIT_RY * 1.015 * Math.sin(angle),
0.088
)
);
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color: 0xe1eb8a,
transparent: true,
opacity: 0.48,
depthWrite: false
});
return new THREE.LineLoop(geometry, material);
}
const peelMaterial = new THREE.MeshPhysicalMaterial({
vertexColors: true,
roughness: 0.58,
metalness: 0,
clearcoat: 0.2,
clearcoatRoughness: 0.58,
side: THREE.DoubleSide
});
const skinMaterial = new THREE.MeshStandardMaterial({
color: 0x83aa38,
roughness: 0.74,
side: THREE.DoubleSide
});
const peelEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0x2c612c,
roughness: 0.68,
side: THREE.DoubleSide
});
const fleshMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.79,
metalness: 0,
side: THREE.DoubleSide
});
function createAvocadoHalf() {
const group = new THREE.Group();
const peel = new THREE.Mesh(makePeelGeometry(), peelMaterial);
peel.castShadow = true;
peel.receiveShadow = true;
group.add(peel);
const skinBand = new THREE.Mesh(
makeRimGeometry(FLESH_FRACTION, 0.91, 0.046),
skinMaterial
);
skinBand.castShadow = true;
skinBand.receiveShadow = true;
group.add(skinBand);
const peelBand = new THREE.Mesh(
makeRimGeometry(0.91, 0.997, 0.025),
peelEdgeMaterial
);
peelBand.castShadow = true;
peelBand.receiveShadow = true;
group.add(peelBand);
const flesh = new THREE.Mesh(makeFleshGeometry(), fleshMaterial);
flesh.castShadow = true;
flesh.receiveShadow = true;
group.add(flesh);
group.add(makeCavityOutline());
return group;
}
const leftHalf = createAvocadoHalf();
leftHalf.position.set(-2.15, -0.08, 0);
leftHalf.rotation.set(-0.015, 0.105, -0.045);
scene.add(leftHalf);
const rightHalf = createAvocadoHalf();
rightHalf.position.set(2.15, -0.08, 0);
rightHalf.rotation.set(0.02, -0.105, 0.045);
scene.add(rightHalf);
// One irregular brown stone, built entirely from core Three.js geometry.
const stoneGeometry = new THREE.SphereGeometry(1, 72, 52);
const stonePosition = stoneGeometry.getAttribute("position");
const stoneColors = [];
const stoneColor = new THREE.Color();
const stoneBase = new THREE.Color(0x86502c);
const stoneLight = new THREE.Color(0xb7783d);
const stoneDark = new THREE.Color(0x4f2e1e);
for (let i = 0; i < stonePosition.count; i++) {
const x = stonePosition.getX(i);
const y = stonePosition.getY(i);
const z = stonePosition.getZ(i);
const irregularity =
1 +
0.018 * Math.sin(x * 7.1 + y * 4.7) +
0.012 * Math.sin(z * 10.2 - x * 3.3);
stonePosition.setXYZ(
i,
x * irregularity,
y * irregularity,
z * irregularity
);
const mottling =
0.5 +
0.25 * Math.sin(x * 9.2 + y * 6.1) +
0.18 * Math.sin(z * 11.0 - y * 5.7);
stoneColor.copy(stoneBase).lerp(stoneLight, THREE.MathUtils.clamp(mottling, 0, 1));
if (y < -0.2) {
stoneColor.lerp(stoneDark, smoothstep(-0.15, -1, y) * 0.48);
}
stoneColors.push(stoneColor.r, stoneColor.g, stoneColor.b);
}
stoneGeometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(stoneColors, 3)
);
stoneGeometry.computeVertexNormals();
const stoneMaterial = new THREE.MeshPhysicalMaterial({
vertexColors: true,
roughness: 0.71,
metalness: 0,
clearcoat: 0.08,
clearcoatRoughness: 0.8
});
const stone = new THREE.Mesh(stoneGeometry, stoneMaterial);
stone.scale.set(0.73, 0.83, 0.58);
stone.castShadow = true;
stone.receiveShadow = true;
scene.add(stone);
// Display platform.
const platformMaterial = new THREE.MeshStandardMaterial({
color: 0x1d2825,
roughness: 0.92,
metalness: 0.03
});
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(6.15, 6.35, 0.28, 128),
platformMaterial
);
platform.position.y = -2.52;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x101817,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -2.67;
floor.receiveShadow = true;
scene.add(floor);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(5.35, 0.012, 8, 180),
new THREE.MeshBasicMaterial({
color: 0x9fbe51,
transparent: true,
opacity: 0.2
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = -2.365;
scene.add(platformRing);
leftHalf.updateMatrixWorld(true);
rightHalf.updateMatrixWorld(true);
const seatedPosition = leftHalf.localToWorld(
new THREE.Vector3(0, PIT_CY, -0.16)
);
const removedPosition = leftHalf.localToWorld(
new THREE.Vector3(-1.76, 1.18, 1.32)
);
const seatedQuaternion = leftHalf.quaternion.clone();
const removedQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0.28, -0.4, 0.18)
);
stone.position.copy(removedPosition);
stone.quaternion.copy(removedQuaternion);
let stoneSeated = false;
const statusText = document.getElementById("statusText");
const toggleButton = document.getElementById("toggleStone");
function setStoneState(seated) {
stoneSeated = seated;
toggleButton.textContent = seated ? "Remove the stone" : "Seat the stone";
statusText.textContent = seated
? "Stone seated · cavity concealed"
: "Stone removed · cavity exposed";
}
toggleButton.addEventListener("click", () => {
setStoneState(!stoneSeated);
});
// Custom camera controls implemented directly, without addon imports.
const controls = {
theta: 0.035,
phi: 1.235,
distance: 11.8,
target: new THREE.Vector3(0, -0.08, 0),
userAdjusted: false
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x + controls.distance * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.distance * Math.cos(controls.phi),
controls.target.z + controls.distance * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
let pointerTravel = 0;
const raycaster = new THREE.Raycaster();
const pointerNDC = new THREE.Vector2();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.58,
1.67
);
controls.userAdjusted = true;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (pointerTravel < 7) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNDC.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNDC.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNDC, camera);
const hit = raycaster.intersectObject(stone, false);
if (hit.length) setStoneState(!stoneSeated);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance * Math.exp(event.deltaY * 0.001),
7.5,
24
);
controls.userAdjusted = true;
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
controls.theta = 0.035;
controls.phi = 1.235;
controls.distance =
window.innerWidth < 700 ? 17 : window.innerWidth < 1000 ? 14 : 11.8;
controls.userAdjusted = false;
updateCamera();
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
renderer.setSize(width, height);
camera.aspect = aspect;
camera.fov = aspect < 0.85 ? 48 : 38;
camera.updateProjectionMatrix();
if (!controls.userAdjusted) {
controls.distance =
aspect < 0.85 ? 17 : aspect < 1.25 ? 14 : 11.8;
}
updateCamera();
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
const desiredPosition = stoneSeated
? seatedPosition
: removedPosition.clone().add(
new THREE.Vector3(
0,
0.045 + Math.sin(elapsed * 1.35) * 0.055,
0
)
);
const desiredQuaternion = stoneSeated
? seatedQuaternion
: removedQuaternion.clone().multiply(
new THREE.Quaternion().setFromEuler(
new THREE.Euler(
0,
Math.sin(elapsed * 0.45) * 0.08,
0
)
)
);
const positionEase = 1 - Math.exp(-delta * 5.2);
const rotationEase = 1 - Math.exp(-delta * 6.0);
stone.position.lerp(desiredPosition, positionEase);
stone.quaternion.slerp(desiredQuaternion, rotationEase);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```