Prompt specification
Build or customize the Three.js 3D scene "Mandarin segment structure" 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: Mandarin segment structure
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/mandarin-segment-structure-x0093
Scene Description Prompt:
Please use Three.js from cdnjs for a voxel scene based on this idea: mandarin segment structure. Model a peeled mandarin with one wedge removed, showing radial segments, central gap, and pith strands; all pieces must fit back into the original sphere. Return one self-contained HTML file.
Working Three.js Starter (mandarin-segment-structure-x0093):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Mandarin — Radial Segment Study</title>
<style>
:root {
color-scheme: dark;
--ink: #f4f7fb;
--muted: #9ba9bb;
--panel: rgba(11, 18, 29, 0.78);
--line: rgba(255, 255, 255, 0.12);
--orange: #ff9d28;
--pith: #eee8cf;
--cyan: #83d9ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #09111c;
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;
outline: none;
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
}
#header {
position: absolute;
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 19px 21px 18px;
border-radius: 16px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--orange);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(22px, 3vw, 34px);
font-weight: 760;
letter-spacing: -0.035em;
line-height: 1.02;
}
#header p {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
#status {
display: inline-flex;
align-items: center;
gap: 7px;
margin-top: 14px;
padding: 6px 9px;
border: 1px solid rgba(255, 157, 40, 0.25);
border-radius: 999px;
color: #ffd09a;
background: rgba(255, 157, 40, 0.08);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
#status::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 10px var(--orange);
content: "";
}
#legend {
position: absolute;
right: 24px;
top: 24px;
padding: 15px 17px;
border-radius: 14px;
color: var(--muted);
font-size: 10px;
line-height: 1.9;
}
.legend-row {
display: flex;
align-items: center;
gap: 9px;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 2px;
box-shadow: 0 0 0 1px rgba(255,255,255,0.16);
}
.swatch.flesh {
background: linear-gradient(135deg, #ffbd4d, #f27613);
}
.swatch.pith {
background: var(--pith);
}
.swatch.envelope {
border: 1px solid var(--cyan);
background: transparent;
border-radius: 50%;
}
#controls {
position: absolute;
left: 50%;
bottom: 22px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 15px;
pointer-events: auto;
transform: translateX(-50%);
}
button {
min-height: 38px;
padding: 0 14px;
border: 1px solid transparent;
border-radius: 9px;
color: #bdc7d5;
background: transparent;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
}
button:hover {
color: white;
background: rgba(255, 255, 255, 0.07);
}
button.active {
color: #ffe3c2;
border-color: rgba(255, 157, 40, 0.28);
background: rgba(255, 157, 40, 0.12);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#note {
position: absolute;
right: 24px;
bottom: 25px;
max-width: 280px;
color: #738196;
font-size: 10px;
line-height: 1.55;
text-align: right;
}
.callout {
position: absolute;
z-index: 3;
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 6px;
color: #d9e2ed;
background: rgba(8, 14, 23, 0.72);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.13em;
line-height: 1;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, calc(-100% - 20px));
transition: opacity 150ms ease;
}
.callout::after {
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 20px;
background: linear-gradient(rgba(255,255,255,0.5), transparent);
content: "";
}
#label-core {
color: #b7dff1;
}
#label-pith {
color: #fff3cd;
}
#label-piece {
color: #ffd09a;
}
#loading {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
color: var(--muted);
background: #09111c;
font-size: 11px;
letter-spacing: 0.16em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 820px) {
#header {
top: 14px;
left: 14px;
width: min(330px, calc(100vw - 28px));
padding: 15px 16px;
}
#header p,
#legend,
#note,
.callout {
display: none;
}
#status {
margin-top: 10px;
}
#controls {
right: 12px;
bottom: 12px;
left: 12px;
justify-content: center;
overflow-x: auto;
transform: none;
}
button {
padding: 0 11px;
white-space: nowrap;
}
}
</style>
</head>
<body>
<div id="loading">Constructing voxel anatomy…</div>
<div id="ui">
<section id="header" class="panel">
<div class="eyebrow">Botanical Voxel Study / 01</div>
<h1>Peeled Mandarin</h1>
<p>
Nine radial flesh sectors, cream pith membranes, and an open central axis.
One sector is detached to expose the internal construction.
</p>
<div id="status" aria-live="polite">Wedge removed</div>
</section>
<aside id="legend" class="panel">
<div class="legend-row"><span class="swatch flesh"></span>Segmented flesh</div>
<div class="legend-row"><span class="swatch pith"></span>Radial pith</div>
<div class="legend-row"><span class="swatch envelope"></span>Shared sphere envelope</div>
</aside>
<div id="controls" class="panel">
<button id="seat" type="button">Seat wedge</button>
<button id="remove" class="active" type="button">Remove wedge</button>
<button id="guide" class="active" type="button">Envelope on</button>
<button id="reset" type="button">Reset view</button>
</div>
<div id="note">
Drag to orbit · wheel or pinch to zoom<br>
Every sector is clipped from the same 32-cell spherical envelope.
</div>
<div id="label-core" class="callout">Central void</div>
<div id="label-pith" class="callout">Pith membrane</div>
<div id="label-piece" class="callout">Detached sector</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 VOXEL = 0.42;
const GRID_RADIUS = 16.2;
const SECTOR_COUNT = 9;
const SECTOR_WIDTH = (Math.PI * 2) / SECTOR_COUNT;
const REMOVED_SECTOR = 0;
const FIRST_SECTOR_ANGLE = THREE.MathUtils.degToRad(50);
const CORE_CLEARANCE = 2.65;
const PITH_CLEARANCE = 1.08;
const MAIN_CENTER = new THREE.Vector3(-3.1, 0, 0);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x09111c);
scene.fog = new THREE.FogExp2(0x09111c, 0.0125);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.18;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute("aria-label", "Interactive voxel mandarin scene");
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
150
);
const cameraTarget = new THREE.Vector3(2.1, -0.1, 0);
const cameraSpherical = new THREE.Spherical(31, 1.18, 0.89);
function updateCamera() {
camera.position.setFromSpherical(cameraSpherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xb9dcff, 0x28150c, 1.65);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xffedd4, 4.2);
key.position.set(7, 18, 11);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -28;
key.shadow.camera.right = 28;
key.shadow.camera.top = 28;
key.shadow.camera.bottom = -28;
key.shadow.camera.near = 1;
key.shadow.camera.far = 60;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0x8bbcff, 1.45);
fill.position.set(-12, 6, -10);
scene.add(fill);
const warmFill = new THREE.PointLight(0xff8b32, 8, 10, 2);
warmFill.position.set(-1.2, 0.4, 2.3);
scene.add(warmFill);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(90, 90),
new THREE.MeshStandardMaterial({
color: 0x101a27,
roughness: 0.96,
metalness: 0.02
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -7.13;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(90, 45, 0x33516a, 0x1a2d40);
grid.position.y = -7.115;
const gridMaterials = Array.isArray(grid.material) ? grid.material : [grid.material];
for (const material of gridMaterials) {
material.transparent = true;
material.opacity = 0.2;
material.depthWrite = false;
}
scene.add(grid);
const mainRoot = new THREE.Group();
mainRoot.position.copy(MAIN_CENTER);
scene.add(mainRoot);
const detachedRoot = new THREE.Group();
scene.add(detachedRoot);
const orangeGeometry = new THREE.BoxGeometry(
VOXEL * 0.91,
VOXEL * 0.91,
VOXEL * 0.91
);
const pithGeometry = new THREE.BoxGeometry(
VOXEL * 0.88,
VOXEL * 0.88,
VOXEL * 0.88
);
const orangeMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0
});
const pithMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0
});
const mainFlesh = [];
const detachedFlesh = [];
const pithVoxels = [];
const pithSeen = new Set();
function pseudoRandom(index) {
const value = Math.sin(index * 12.9898 + 78.233) * 43758.5453;
return value - Math.floor(value);
}
function positiveModulo(value, divisor) {
return ((value % divisor) + divisor) % divisor;
}
function nearestSector(theta) {
const delta = Math.atan2(
Math.sin(theta - FIRST_SECTOR_ANGLE),
Math.cos(theta - FIRST_SECTOR_ANGLE)
);
const rawIndex = Math.round(delta / SECTOR_WIDTH);
const sector = positiveModulo(rawIndex, SECTOR_COUNT);
const localDelta = delta - rawIndex * SECTOR_WIDTH;
return { sector, localDelta };
}
for (let x = -16; x <= 16; x++) {
for (let y = -16; y <= 16; y++) {
for (let z = -16; z <= 16; z++) {
const radiusSquared = x * x + y * y + z * z;
if (
radiusSquared > GRID_RADIUS * GRID_RADIUS ||
radiusSquared < CORE_CLEARANCE * CORE_CLEARANCE
) {
continue;
}
const radius = Math.sqrt(radiusSquared);
const theta = Math.atan2(z, x);
const { sector, localDelta } = nearestSector(theta);
const distanceToBoundary =
radius *
Math.sin(
Math.abs(SECTOR_WIDTH * 0.5 - Math.abs(localDelta))
);
if (distanceToBoundary < PITH_CLEARANCE) {
continue;
}
const hueOffsets = [0.0, 0.012, -0.009, 0.007, -0.014, 0.015, -0.004, 0.01, -0.011];
const hue = 0.064 + hueOffsets[sector] + (pseudoRandom(x * 97 + y * 41 + z * 13) - 0.5) * 0.014;
const lightness =
0.43 +
(radius / GRID_RADIUS) * 0.13 +
pseudoRandom(x * 31 + y * 67 + z * 89) * 0.065;
const color = new THREE.Color().setHSL(hue, 0.91, lightness);
const voxel = { x, y, z, color };
if (sector === REMOVED_SECTOR) {
detachedFlesh.push(voxel);
} else {
mainFlesh.push(voxel);
}
}
}
}
// Each membrane is a one-voxel-thick radial wall in a vertical plane.
// The walls remain on the fruit when a flesh sector is removed.
for (let boundary = 0; boundary < SECTOR_COUNT; boundary++) {
const angle =
FIRST_SECTOR_ANGLE + (boundary - 0.5) * SECTOR_WIDTH;
for (let radial = 3; radial <= 16; radial++) {
const x = Math.round(Math.cos(angle) * radial);
const z = Math.round(Math.sin(angle) * radial);
for (let y = -16; y <= 16; y++) {
if (x * x + y * y + z * z > GRID_RADIUS * GRID_RADIUS) {
continue;
}
const key = `${x},${y},${z}`;
if (pithSeen.has(key)) {
continue;
}
pithSeen.add(key);
const lightness = 0.79 + pseudoRandom(radial * 43 + y * 71 + boundary * 19) * 0.1;
const color = new THREE.Color().setHSL(0.115, 0.27, lightness);
pithVoxels.push({ x, y, z, color });
}
}
}
function createInstancedVoxels(data, geometry, material) {
const mesh = new THREE.InstancedMesh(geometry, material, data.length);
const transform = new THREE.Object3D();
for (let index = 0; index < data.length; index++) {
const voxel = data[index];
transform.position.set(
voxel.x * VOXEL,
voxel.y * VOXEL,
voxel.z * VOXEL
);
transform.updateMatrix();
mesh.setMatrixAt(index, transform.matrix);
mesh.setColorAt(index, voxel.color);
}
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) {
mesh.instanceColor.needsUpdate = true;
}
mesh.castShadow = true;
mesh.receiveShadow = true;
if (typeof mesh.computeBoundingSphere === "function") {
mesh.computeBoundingSphere();
}
return mesh;
}
const mainMesh = createInstancedVoxels(mainFlesh, orangeGeometry, orangeMaterial);
mainRoot.add(mainMesh);
const pithMesh = createInstancedVoxels(pithVoxels, pithGeometry, pithMaterial);
mainRoot.add(pithMesh);
const detachedMesh = createInstancedVoxels(detachedFlesh, orangeGeometry, orangeMaterial);
detachedRoot.add(detachedMesh);
const envelopeRadius = GRID_RADIUS * VOXEL + VOXEL * 0.49;
const envelope = new THREE.Group();
envelope.position.copy(MAIN_CENTER);
const envelopeSphere = new THREE.Mesh(
new THREE.SphereGeometry(envelopeRadius, 32, 18),
new THREE.MeshBasicMaterial({
color: 0x83d9ff,
wireframe: true,
transparent: true,
opacity: 0.075,
depthWrite: false
})
);
envelope.add(envelopeSphere);
const equatorPoints = [];
for (let index = 0; index <= 128; index++) {
const angle = (index / 128) * Math.PI * 2;
equatorPoints.push(
new THREE.Vector3(
Math.cos(angle) * envelopeRadius,
0,
Math.sin(angle) * envelopeRadius
)
);
}
const equator = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(equatorPoints),
new THREE.LineBasicMaterial({
color: 0x83d9ff,
transparent: true,
opacity: 0.28,
depthWrite: false
})
);
envelope.add(equator);
scene.add(envelope);
const separatedPosition = new THREE.Vector3(8.1, 0, 0.45);
const separatedQuaternion = new THREE.Quaternion().setFromEuler(
new THREE.Euler(0.02, -0.3, 0.1)
);
const seatedPosition = MAIN_CENTER.clone();
const seatedQuaternion = new THREE.Quaternion();
detachedRoot.position.copy(separatedPosition);
detachedRoot.quaternion.copy(separatedQuaternion);
let wedgeSeparated = true;
let envelopeVisible = true;
const seatButton = document.getElementById("seat");
const removeButton = document.getElementById("remove");
const guideButton = document.getElementById("guide");
const resetButton = document.getElementById("reset");
const status = document.getElementById("status");
const pieceLabel = document.getElementById("label-piece");
function setWedgeState(separated) {
wedgeSeparated = separated;
seatButton.classList.toggle("active", !separated);
removeButton.classList.toggle("active", separated);
status.textContent = separated ? "Wedge removed" : "Sphere assembled";
pieceLabel.textContent = separated ? "Detached sector" : "Sector seated";
}
function setEnvelopeVisible(visible) {
envelopeVisible = visible;
envelope.visible = visible;
guideButton.classList.toggle("active", visible);
guideButton.textContent = visible ? "Envelope on" : "Envelope off";
}
seatButton.addEventListener("click", () => setWedgeState(false));
removeButton.addEventListener("click", () => setWedgeState(true));
guideButton.addEventListener("click", () => setEnvelopeVisible(!envelopeVisible));
resetButton.addEventListener("click", () => {
cameraSpherical.set(31, 1.18, 0.89);
updateCamera();
});
window.addEventListener("keydown", (event) => {
if (event.code === "Space") {
event.preventDefault();
setWedgeState(!wedgeSeparated);
} else if (event.key.toLowerCase() === "g") {
setEnvelopeVisible(!envelopeVisible);
} else if (event.key.toLowerCase() === "r") {
cameraSpherical.set(31, 1.18, 0.89);
updateCamera();
}
});
// Direct camera controls; no external control addon is used.
const pointers = new Map();
let pinchDistance = 0;
let dragged = false;
renderer.domElement.addEventListener("pointerdown", (event) => {
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
dragged = true;
if (pointers.size === 2) {
const points = [...pointers.values()];
pinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
return;
}
const previous = pointers.get(event.pointerId);
const deltaX = event.clientX - previous.x;
const deltaY = event.clientY - previous.y;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraSpherical.theta -= deltaX * 0.006;
cameraSpherical.phi = THREE.MathUtils.clamp(
cameraSpherical.phi - deltaY * 0.005,
0.28,
1.48
);
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (pinchDistance > 0) {
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius * (pinchDistance / distance),
17,
49
);
}
pinchDistance = distance;
}
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (pointers.size < 2) {
pinchDistance = 0;
}
if (pointers.size === 0) {
dragged = false;
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener(
"pointerleave",
(event) => {
if (!dragged) {
releasePointer(event);
}
}
);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraSpherical.radius = THREE.MathUtils.clamp(
cameraSpherical.radius * Math.exp(event.deltaY * 0.001),
17,
49
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraSpherical.set(31, 1.18, 0.89);
updateCamera();
});
renderer.domElement.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
const coreLabel = document.getElementById("label-core");
const pithLabel = document.getElementById("label-pith");
const coreWorld = MAIN_CENTER.clone().add(
new THREE.Vector3(
Math.cos(FIRST_SECTOR_ANGLE) * 0.7,
0.25,
Math.sin(FIRST_SECTOR_ANGLE) * 0.7
)
);
const pithBoundaryAngle =
FIRST_SECTOR_ANGLE + SECTOR_WIDTH * 0.5;
const pithWorld = MAIN_CENTER.clone().add(
new THREE.Vector3(
Math.cos(pithBoundaryAngle) * 3.2,
4.85,
Math.sin(pithBoundaryAngle) * 3.2
)
);
const detachedLabelLocal = new THREE.Vector3(
Math.cos(FIRST_SECTOR_ANGLE) * 3.2,
3.7,
Math.sin(FIRST_SECTOR_ANGLE) * 3.2
);
function positionLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
element.style.opacity = visible ? "1" : "0";
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width / height < 0.8 ? 49 : 42;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.75));
}
window.addEventListener("resize", resize);
resize();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 4.5);
const targetPosition = wedgeSeparated
? separatedPosition
: seatedPosition;
const targetQuaternion = wedgeSeparated
? separatedQuaternion
: seatedQuaternion;
detachedRoot.position.lerp(targetPosition, smoothing);
detachedRoot.quaternion.slerp(targetQuaternion, smoothing);
updateCamera();
detachedRoot.updateMatrixWorld(true);
mainRoot.updateMatrixWorld(true);
positionLabel(coreLabel, coreWorld);
positionLabel(pithLabel, pithWorld);
positionLabel(
pieceLabel,
detachedRoot.localToWorld(detachedLabelLocal.clone())
);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
requestAnimationFrame(() => {
document.getElementById("loading").classList.add("hidden");
setTimeout(() => {
document.getElementById("loading").remove();
}, 450);
});
</script>
</body>
</html>
```