Prompt specification
Build or customize the Three.js 3D scene "Planet comparison interior gallery" 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: Planet comparison interior gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/planet-comparison-interior-gallery-x1139
Scene Description Prompt:
Create a standalone voxel scene in one HTML file using Three.js from cdnjs. Arrange Earth and two generic rocky planetary models with differing layer proportions; label invented comparison models clearly and avoid assigning unsupported real planetary interior details.
Working Three.js Starter (planet-comparison-interior-gallery-x1139):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Planetary Comparison</title>
<style>
:root {
color-scheme: dark;
--ink: #eef5ff;
--muted: #9caec8;
--line: rgba(151, 188, 255, 0.22);
--panel: rgba(7, 14, 30, 0.78);
--cyan: #58d9ff;
--orange: #ffb45e;
--shell: #87909b;
--middle: #c5654c;
--core: #f0b84b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 32%, #142342 0%, #090f21 43%, #02040b 100%);
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 5;
border: 1px solid var(--line);
border-radius: 16px;
background: var(--panel);
box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
pointer-events: none;
}
.title-panel {
top: 20px;
left: 20px;
width: min(440px, calc(100vw - 40px));
padding: 18px 20px;
}
.eyebrow {
display: block;
margin-bottom: 7px;
color: var(--cyan);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.035em;
}
.title-panel p {
margin: 10px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.info-panel {
top: 20px;
right: 20px;
width: 285px;
padding: 16px 17px;
}
.info-panel h2 {
margin: 0 0 9px;
font-size: 12px;
letter-spacing: 0.04em;
}
.info-panel p {
margin: 0 0 9px;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.info-panel p:last-child {
margin-bottom: 0;
}
.info-panel strong {
color: var(--ink);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
overflow: hidden;
pointer-events: none;
}
.planet-label {
position: absolute;
width: 224px;
padding: 11px 13px;
transform: translate(-50%, -50%);
border: 1px solid rgba(92, 218, 255, 0.3);
border-radius: 12px;
background: rgba(5, 12, 27, 0.83);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
transition: opacity 120ms linear;
}
.planet-label::before {
content: "";
position: absolute;
top: -22px;
left: 50%;
height: 21px;
border-left: 1px solid rgba(151, 188, 255, 0.42);
}
.planet-label.invented {
border-color: rgba(255, 180, 94, 0.38);
}
.planet-label.invented::before {
border-color: rgba(255, 180, 94, 0.45);
}
.planet-label.side::before {
display: none;
}
.label-status {
display: inline-flex;
margin-bottom: 6px;
padding: 3px 6px;
border-radius: 999px;
background: rgba(88, 217, 255, 0.11);
color: var(--cyan);
font-size: 8px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.invented .label-status {
background: rgba(255, 180, 94, 0.12);
color: var(--orange);
}
.planet-label strong {
display: block;
font-size: 14px;
line-height: 1.2;
}
.label-detail {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.layer-legend {
display: flex;
flex-wrap: wrap;
gap: 6px 10px;
margin-top: 9px;
color: #cbd7e9;
font-size: 9px;
}
.layer-legend span {
display: inline-flex;
align-items: center;
gap: 4px;
white-space: nowrap;
}
.swatch {
width: 7px;
height: 7px;
border-radius: 2px;
background: var(--shell);
}
.swatch.middle {
background: var(--middle);
}
.swatch.core {
background: var(--core);
}
.toolbar {
position: fixed;
z-index: 10;
bottom: 20px;
left: 50%;
display: flex;
gap: 8px;
padding: 7px;
transform: translateX(-50%);
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(7, 14, 30, 0.82);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
button {
appearance: none;
border: 1px solid rgba(151, 188, 255, 0.18);
border-radius: 9px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.055);
color: var(--ink);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease;
}
button:hover {
border-color: rgba(88, 217, 255, 0.48);
background: rgba(88, 217, 255, 0.1);
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
.hint {
position: fixed;
z-index: 5;
right: 20px;
bottom: 22px;
color: rgba(190, 207, 230, 0.65);
font-size: 10px;
pointer-events: none;
}
@media (max-width: 900px) {
.info-panel {
width: 245px;
}
.hint {
display: none;
}
}
@media (max-width: 700px) {
.title-panel {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 13px 15px;
}
.title-panel p {
max-width: 92%;
font-size: 10px;
}
.info-panel {
top: auto;
right: 12px;
bottom: 70px;
width: 205px;
padding: 11px 13px;
}
.info-panel p {
font-size: 9px;
}
.planet-label {
width: 148px;
padding: 9px 10px;
}
.planet-label strong {
font-size: 11px;
}
.label-detail {
display: none;
}
.layer-legend {
gap: 4px 7px;
font-size: 8px;
}
.toolbar {
bottom: 12px;
}
button {
padding: 8px 10px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive voxel planetary comparison scene"></div>
<header class="panel title-panel">
<span class="eyebrow">Interactive voxel study</span>
<h1>Surface, shell, middle, core.</h1>
<p>
Earth is a stylized exterior reference. Models A and B are explicitly
invented comparison bodies—not reconstructions of any real planet.
</p>
</header>
<aside class="panel info-panel">
<h2>Reading the scene</h2>
<p>
<strong>Earth:</strong> exterior voxels only. Its real interior is not
depicted or inferred here.
</p>
<p>
<strong>Models A and B:</strong> fictional teaching examples. Their
layer percentages are invented illustrative volume shares, not
measurements of a real body.
</p>
</aside>
<div id="labels">
<div class="planet-label" id="label-earth">
<span class="label-status">Real body · surface only</span>
<strong>Earth</strong>
<span class="label-detail">
Stylized ocean, land and ice voxels. No interior is shown.
</span>
</div>
<div class="planet-label invented" id="label-a">
<span class="label-status">Invented comparison model</span>
<strong>Generic Rocky Model A</strong>
<span class="label-detail">
Not based on a real planetary body.
</span>
<div class="layer-legend">
<span><i class="swatch"></i>Shell 14%</span>
<span><i class="swatch middle"></i>Middle 58%</span>
<span><i class="swatch core"></i>Core 28%</span>
</div>
</div>
<div class="planet-label invented" id="label-b">
<span class="label-status">Invented comparison model</span>
<strong>Generic Rocky Model B</strong>
<span class="label-detail">
Not based on a real planetary body.
</span>
<div class="layer-legend">
<span><i class="swatch"></i>Shell 22%</span>
<span><i class="swatch middle"></i>Middle 33%</span>
<span><i class="swatch core"></i>Core 45%</span>
</div>
</div>
</div>
<nav class="toolbar" aria-label="Scene controls">
<button id="drift-button" type="button" aria-pressed="false">Drift: off</button>
<button id="reset-button" type="button">Reset view</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
150
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x000000, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
sceneHost.appendChild(renderer.domElement);
// Lighting is deliberately soft so the voxel faces remain readable.
scene.add(new THREE.HemisphereLight(0xb8d8ff, 0x241326, 1.55));
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(-8, 12, 14);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x66cfff, 2.2);
rimLight.position.set(10, 4, -9);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff9b5f, 22, 35, 2);
warmLight.position.set(1, -3, 8);
scene.add(warmLight);
// Distant point stars.
const starCount = 1300;
const starPositions = new Float32Array(starCount * 3);
for (let i = 0; i < starCount; i++) {
const radius = 32 + Math.random() * 65;
const theta = Math.random() * Math.PI * 2;
const phi = Math.acos(2 * Math.random() - 1);
starPositions[i * 3] =
radius * Math.sin(phi) * Math.cos(theta);
starPositions[i * 3 + 1] =
radius * Math.cos(phi);
starPositions[i * 3 + 2] =
radius * Math.sin(phi) * Math.sin(theta);
}
const starGeometry = new THREE.BufferGeometry();
starGeometry.setAttribute(
"position",
new THREE.BufferAttribute(starPositions, 3)
);
const stars = new THREE.Points(
starGeometry,
new THREE.PointsMaterial({
color: 0xbcd7ff,
size: 0.065,
transparent: true,
opacity: 0.72,
sizeAttenuation: true,
depthWrite: false
})
);
scene.add(stars);
// A subtle voxel-display floor.
const grid = new THREE.GridHelper(44, 44, 0x31517d, 0x182a48);
grid.position.y = -3.58;
grid.material.transparent = true;
grid.material.opacity = 0.22;
grid.material.depthWrite = false;
scene.add(grid);
const VOXEL_SIZE = 0.43;
const VOXEL_STEP = 0.45;
const cubeGeometry = new THREE.BoxGeometry(
VOXEL_SIZE,
VOXEL_SIZE,
VOXEL_SIZE
);
const dummy = new THREE.Object3D();
const workingColor = new THREE.Color();
function makeInstancedLayer(cells, baseHex, variation, parent) {
if (!cells.length) return null;
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.84,
metalness: 0.015
});
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
cells.length
);
cells.forEach((cell, index) => {
dummy.position.set(cell.x, cell.y, cell.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.setScalar(1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
workingColor.set(baseHex);
const amount = (Math.random() - 0.5) * variation;
workingColor.offsetHSL(
amount * 0.025,
amount * 0.055,
amount
);
mesh.setColorAt(index, workingColor);
});
mesh.instanceMatrix.needsUpdate = true;
if (mesh.instanceColor) mesh.instanceColor.needsUpdate = true;
parent.add(mesh);
return mesh;
}
// A procedural, stylized Earth exterior. This function intentionally
// makes no claim about Earth's internal structure.
function continentalScore(x, y, z) {
const blobs = [
{ center: [0.10, 0.17, 0.98], width: 0.23 },
{ center: [-0.86, 0.04, 0.50], width: 0.19 },
{ center: [0.58, -0.55, 0.60], width: 0.14 },
{ center: [-0.22, 0.78, 0.58], width: 0.12 },
{ center: [0.82, 0.33, 0.46], width: 0.12 }
];
let score = 0;
for (const blob of blobs) {
const length =
Math.hypot(
blob.center[0],
blob.center[1],
blob.center[2]
);
const dot =
(
x * blob.center[0] +
y * blob.center[1] +
z * blob.center[2]
) / length;
const angularDistance = 1 - dot;
const contribution = Math.exp(
-angularDistance *
angularDistance /
(2 * blob.width * blob.width)
);
score = Math.max(score, contribution);
}
const grain =
Math.sin(x * 8.1 + y * 3.7) *
Math.cos(z * 6.3 - x * 2.2) +
0.45 * Math.sin((x + z) * 11.7);
return score + grain * 0.075;
}
const earthGroup = new THREE.Group();
scene.add(earthGroup);
{
const radius = 3.05;
const limit = Math.ceil(radius / VOXEL_STEP);
const oceanDark = [];
const oceanBright = [];
const landGreen = [];
const landTan = [];
const ice = [];
for (let ix = -limit; ix <= limit; ix++) {
for (let iy = -limit; iy <= limit; iy++) {
for (let iz = -limit; iz <= limit; iz++) {
const x = ix * VOXEL_STEP;
const y = iy * VOXEL_STEP;
const z = iz * VOXEL_STEP;
const distance = Math.hypot(x, y, z);
// Retain only the exterior shell.
if (
distance > radius + 0.09 ||
distance < radius - VOXEL_STEP * 0.62
) {
continue;
}
const nx = x / radius;
const ny = y / radius;
const nz = z / radius;
const normalLength = Math.hypot(nx, ny, nz);
const dx = nx / normalLength;
const dy = ny / normalLength;
const dz = nz / normalLength;
const cell = { x, y, z };
if (Math.abs(dy) > 0.86) {
ice.push(cell);
continue;
}
const land = continentalScore(dx, dy, dz) > 0.57;
if (land) {
const desert =
Math.abs(dy) < 0.25 &&
Math.sin(dx * 13 + dz * 7) > -0.12;
if (desert) {
landTan.push(cell);
} else {
landGreen.push(cell);
}
} else {
const variation =
0.5 +
0.5 *
Math.sin(dx * 5.2 + dz * 4.1 + dy * 3.3);
if (variation > 0.54) {
oceanBright.push(cell);
} else {
oceanDark.push(cell);
}
}
}
}
}
makeInstancedLayer(oceanDark, 0x1766a6, 0.25, earthGroup);
makeInstancedLayer(oceanBright, 0x258bc0, 0.22, earthGroup);
makeInstancedLayer(landGreen, 0x4f9856, 0.30, earthGroup);
makeInstancedLayer(landTan, 0xbea05e, 0.22, earthGroup);
makeInstancedLayer(ice, 0xe8f5ff, 0.08, earthGroup);
}
function makeRockyModel(proportions) {
const group = new THREE.Group();
const radius = 3.05;
const limit = Math.ceil(radius / VOXEL_STEP);
const coreFraction = proportions.core;
const middleFraction = proportions.middle;
const coreRadius =
radius * Math.cbrt(coreFraction);
const middleRadius =
radius * Math.cbrt(coreFraction + middleFraction);
const shellCells = [];
const middleCells = [];
const coreCells = [];
for (let ix = -limit; ix <= limit; ix++) {
for (let iy = -limit; iy <= limit; iy++) {
for (let iz = -limit; iz <= limit; iz++) {
const x = ix * VOXEL_STEP;
const y = iy * VOXEL_STEP;
const z = iz * VOXEL_STEP;
const distance = Math.hypot(x, y, z);
if (distance > radius + 0.1) continue;
// Remove the front-right quadrant to expose a stepped cutaway.
if (ix > 0 && iz > 0) continue;
const cell = { x, y, z };
if (distance <= coreRadius) {
coreCells.push(cell);
} else if (distance <= middleRadius) {
middleCells.push(cell);
} else {
shellCells.push(cell);
}
}
}
}
makeInstancedLayer(shellCells, 0x7f858b, 0.30, group);
makeInstancedLayer(middleCells, 0xb95643, 0.24, group);
makeInstancedLayer(coreCells, 0xe8a83d, 0.20, group);
scene.add(group);
return group;
}
// The two layer sets are fictional examples with intentionally
// different proportions.
const modelA = makeRockyModel({
shell: 0.14,
middle: 0.58,
core: 0.28
});
const modelB = makeRockyModel({
shell: 0.22,
middle: 0.33,
core: 0.45
});
const labelEarth = document.querySelector("#label-earth");
const labelA = document.querySelector("#label-a");
const labelB = document.querySelector("#label-b");
const labels = [
{
element: labelEarth,
anchor: new THREE.Vector3()
},
{
element: labelA,
anchor: new THREE.Vector3()
},
{
element: labelB,
anchor: new THREE.Vector3()
}
];
const controls = {
userAzimuth: 0.12,
cameraAzimuth: 0.12,
elevation: 0.22,
distance: 24
};
const target = new THREE.Vector3(0, 0, 0);
let narrowLayout = false;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
let driftEnabled = false;
let elapsed = 0;
function updateLayout() {
narrowLayout = window.innerWidth < 700;
if (narrowLayout) {
earthGroup.position.set(0, 4.45, 0);
modelA.position.set(0, 0, 0);
modelB.position.set(0, -4.45, 0);
labels[0].anchor.set(-4.15, 4.45, 0);
labels[1].anchor.set(4.15, 0, 0);
labels[2].anchor.set(-4.15, -4.45, 0);
controls.distance = 27;
} else {
earthGroup.position.set(-7.2, 0, 0);
modelA.position.set(0, 0, 0);
modelB.position.set(7.2, 0, 0);
labels[0].anchor.set(-7.2, -4.12, 0);
labels[1].anchor.set(0, -4.12, 0);
labels[2].anchor.set(7.2, -4.12, 0);
controls.distance = 24;
}
labels.forEach(({ element }) => {
element.classList.toggle("side", narrowLayout);
});
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateLayout();
}
window.addEventListener("resize", resize);
resize();
function resetView() {
controls.userAzimuth = 0.12;
controls.cameraAzimuth = 0.12;
controls.elevation = 0.22;
controls.distance = narrowLayout ? 27 : 24;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.classList.add("dragging");
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - lastPointerX;
const deltaY = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
controls.userAzimuth -= deltaX * 0.005;
controls.userAzimuth = THREE.MathUtils.clamp(
controls.userAzimuth,
-0.58,
0.58
);
controls.elevation = THREE.MathUtils.clamp(
controls.elevation + deltaY * 0.004,
0.05,
0.62
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.012,
18,
36
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
const driftButton = document.querySelector("#drift-button");
const resetButton = document.querySelector("#reset-button");
driftButton.addEventListener("click", () => {
driftEnabled = !driftEnabled;
driftButton.textContent = `Drift: ${driftEnabled ? "on" : "off"}`;
driftButton.setAttribute("aria-pressed", String(driftEnabled));
});
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
controls.userAzimuth -= 0.06;
} else if (event.key === "ArrowRight") {
controls.userAzimuth += 0.06;
} else if (event.key === "ArrowUp") {
controls.elevation = Math.min(0.62, controls.elevation + 0.04);
} else if (event.key === "ArrowDown") {
controls.elevation = Math.max(0.05, controls.elevation - 0.04);
} else if (event.key.toLowerCase() === "r") {
resetView();
} else {
return;
}
event.preventDefault();
controls.userAzimuth = THREE.MathUtils.clamp(
controls.userAzimuth,
-0.58,
0.58
);
});
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labels) {
projected.copy(label.anchor).project(camera);
const visible =
projected.z >= -1 &&
projected.z <= 1 &&
Math.abs(projected.x) < 1.35 &&
Math.abs(projected.y) < 1.35;
label.element.style.opacity = visible ? "1" : "0";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height}px`;
}
}
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
elapsed += delta;
if (driftEnabled && !dragging) {
controls.cameraAzimuth =
controls.userAzimuth + Math.sin(elapsed * 0.42) * 0.085;
} else {
controls.cameraAzimuth = THREE.MathUtils.lerp(
controls.cameraAzimuth,
controls.userAzimuth,
Math.min(1, delta * 7)
);
}
earthGroup.rotation.y = 0.28 + elapsed * 0.025;
const horizontalDistance =
controls.distance * Math.cos(controls.elevation);
camera.position.set(
target.x +
Math.sin(controls.cameraAzimuth) * horizontalDistance,
target.y +
Math.sin(controls.elevation) * controls.distance,
target.z +
Math.cos(controls.cameraAzimuth) * horizontalDistance
);
camera.lookAt(target);
camera.updateMatrixWorld();
updateLabels();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```