Prompt specification
Build or customize the Three.js 3D scene "Cell-size exchange-budget sandbox" 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: Cell-size exchange-budget sandbox
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cell-size-exchange-budget-sandbox-x0872
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows cellular surface-area-to-volume ratios. Let users change cube size and subdivision count; compute geometric ratios exactly and use a clearly labeled toy demand model to illustrate transport constraints. Low-poly.
Working Three.js Starter (cell-size-exchange-budget-sandbox-x0872):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cellular Surface-to-Volume Ratios</title>
<style>
:root {
color-scheme: dark;
--bg: #08111f;
--panel: rgba(13, 24, 42, 0.93);
--border: rgba(148, 163, 184, 0.22);
--text: #eef4ff;
--muted: #9fb0c8;
--good: #45d6c3;
--warning: #f4c65c;
--bad: #ff7468;
--accent: #74c7ff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
top: 18px;
left: 18px;
width: min(430px, calc(100vw - 36px));
max-height: calc(100vh - 36px);
overflow-y: auto;
padding: 22px;
border: 1px solid var(--border);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 20px 70px rgba(0, 0, 0, 0.36);
backdrop-filter: blur(14px);
scrollbar-width: thin;
scrollbar-color: #40516a transparent;
}
.eyebrow {
margin-bottom: 7px;
color: var(--accent);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(1.55rem, 3vw, 2rem);
line-height: 1.12;
letter-spacing: -0.035em;
}
.intro {
margin: 10px 0 20px;
color: var(--muted);
font-size: 0.92rem;
line-height: 1.5;
}
section {
padding-top: 17px;
margin-top: 17px;
border-top: 1px solid var(--border);
}
h2 {
margin: 0 0 12px;
font-size: 0.88rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.control + .control {
margin-top: 17px;
}
.control-label {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 0.9rem;
font-weight: 700;
}
output {
color: var(--accent);
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 4px;
color: #71839e;
font-size: 0.7rem;
}
.metric-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 9px;
}
.metric {
min-height: 98px;
padding: 12px;
border: 1px solid var(--border);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.metric span {
display: block;
color: var(--muted);
font-size: 0.72rem;
line-height: 1.25;
}
.metric strong {
display: block;
margin: 7px 0 4px;
color: var(--text);
font-size: 1.08rem;
line-height: 1.2;
font-variant-numeric: tabular-nums;
}
.metric small {
display: block;
color: #8193ae;
font-size: 0.68rem;
line-height: 1.3;
}
.detail-list {
display: grid;
gap: 8px;
margin-top: 11px;
}
.detail {
display: flex;
justify-content: space-between;
gap: 14px;
padding-bottom: 7px;
border-bottom: 1px solid rgba(148, 163, 184, 0.12);
color: var(--muted);
font-size: 0.78rem;
}
.detail b {
color: var(--text);
text-align: right;
font-variant-numeric: tabular-nums;
}
.note {
margin: 11px 0 0;
color: #8799b4;
font-size: 0.72rem;
line-height: 1.45;
}
.model-box {
padding: 14px;
border: 1px solid rgba(116, 199, 255, 0.24);
border-radius: 12px;
background: rgba(116, 199, 255, 0.055);
}
.model-box h2 {
color: #bfe4ff;
}
.model-assumptions {
margin: 0 0 12px;
color: var(--muted);
font-size: 0.78rem;
line-height: 1.48;
}
.model-assumptions code {
color: #d8ecff;
font-family: inherit;
}
.status {
display: inline-flex;
align-items: center;
gap: 7px;
margin: 2px 0 10px;
padding: 7px 10px;
border-radius: 999px;
font-size: 0.75rem;
font-weight: 800;
}
.status::before {
width: 8px;
height: 8px;
border-radius: 50%;
background: currentColor;
content: "";
box-shadow: 0 0 12px currentColor;
}
.status.good {
color: var(--good);
background: rgba(69, 214, 195, 0.11);
}
.status.warning {
color: var(--warning);
background: rgba(244, 198, 92, 0.11);
}
.status.bad {
color: var(--bad);
background: rgba(255, 116, 104, 0.11);
}
.model-explanation {
min-height: 42px;
margin: 0 0 12px;
color: #b9c8dc;
font-size: 0.78rem;
line-height: 1.45;
}
.bars {
display: grid;
gap: 9px;
}
.bar-row {
display: grid;
grid-template-columns: 70px 1fr;
align-items: center;
gap: 10px;
}
.bar-label {
color: var(--muted);
font-size: 0.72rem;
}
.bar {
position: relative;
height: 11px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
.bar > span {
display: block;
height: 100%;
border-radius: inherit;
transition: width 180ms ease;
}
.bar.demand > span {
background: var(--bad);
}
.bar.capacity > span {
background: var(--good);
}
.model-values {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 11px;
color: #8fa1ba;
font-size: 0.69rem;
}
.model-values b {
color: #dceaff;
font-variant-numeric: tabular-nums;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 14px;
color: var(--muted);
font-size: 0.73rem;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 11px;
height: 11px;
border-radius: 3px;
}
.swatch.good {
background: var(--good);
}
.swatch.warning {
background: var(--warning);
}
.swatch.bad {
background: var(--bad);
}
.swatch.shell {
border: 1px solid var(--accent);
background: transparent;
}
.actions {
display: flex;
gap: 9px;
margin-top: 14px;
}
button {
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 0.77rem;
cursor: pointer;
}
button:hover {
background: rgba(255, 255, 255, 0.1);
}
.scene-hint {
position: fixed;
z-index: 5;
right: 18px;
bottom: 17px;
padding: 9px 12px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(8, 17, 31, 0.76);
color: #9eb0c8;
font-size: 0.73rem;
pointer-events: none;
}
@media (max-width: 680px) {
.panel {
top: auto;
right: 10px;
bottom: 10px;
left: 10px;
width: auto;
max-height: 53vh;
padding: 17px;
border-radius: 15px;
}
.scene-hint {
top: 12px;
right: 12px;
bottom: auto;
}
.metric-grid {
grid-template-columns: 1fr 1fr;
}
}
</style>
</head>
<body>
<canvas id="view" aria-label="Interactive three-dimensional subdivided cube"></canvas>
<aside class="panel">
<div class="eyebrow">Exact cube geometry</div>
<h1>Cellular Surface-to-Volume</h1>
<p class="intro">
Subdivide one cube into <strong>n³ congruent cubic cells</strong>.
The calculations are algebraic; the low-poly rendering is only an illustration.
</p>
<section>
<h2>Controls</h2>
<div class="control">
<label class="control-label" for="cubeSize">
<span>Cube edge length, L</span>
<output id="cubeSizeValue">6 units</output>
</label>
<input
id="cubeSize"
type="range"
min="1"
max="10"
step="0.5"
value="6"
>
<div class="range-ends">
<span>1 unit</span>
<span>10 units</span>
</div>
</div>
<div class="control">
<label class="control-label" for="subdivisions">
<span>Subdivisions per edge, n</span>
<output id="subdivisionsValue">3 · 27 cells</output>
</label>
<input
id="subdivisions"
type="range"
min="1"
max="12"
step="1"
value="3"
>
<div class="range-ends">
<span>1</span>
<span>12</span>
</div>
</div>
</section>
<section>
<h2>Exact geometric results</h2>
<div class="metric-grid">
<div class="metric">
<span>Enclosing cube SA/V</span>
<strong id="outerRatio">—</strong>
<small>SA/V = 6/L</small>
</div>
<div class="metric">
<span>Each cell SA/V</span>
<strong id="cellRatio">—</strong>
<small>SA/V = 6/s = 6n/L</small>
</div>
<div class="metric">
<span>Cell / cube SA/V ratio</span>
<strong id="ratioGain">—</strong>
<small>(cell SA/V) / (cube SA/V)</small>
</div>
<div class="metric">
<span>Unique membrane / outer area</span>
<strong id="uniqueRatio">—</strong>
<small>Each shared interface counted once</small>
</div>
</div>
<div class="detail-list">
<div class="detail">
<span>Cell edge, s = L/n</span>
<b id="sideValue">—</b>
</div>
<div class="detail">
<span>Summed cell surfaces, 6nL²</span>
<b id="summedValue">—</b>
</div>
<div class="detail">
<span>Unique membrane area, 3(n+1)L²</span>
<b id="uniqueValue">—</b>
</div>
</div>
<p class="note">
The summed cell-surface value counts a shared interface twice because it
belongs to both adjacent cells. Unique membrane area counts it once.
Displayed decimals are rounded; fractions and formulas are exact.
</p>
</section>
<section class="model-box">
<h2>Toy transport model — not biological</h2>
<p class="model-assumptions">
Each cell is treated as independently supplied across its own membrane.
Demand density is <code>1 toy unit/(volume·time)</code>; membrane throughput
density is <code>0.5 toy unit/(area·time)</code>. Therefore
<code>D = s³</code>, <code>C = 3s²</code>, and a cell is constrained when
<code>D > C</code>. This intentionally ignores diffusion, neighboring-cell
exchange, and real transporter kinetics.
</p>
<div id="modelStatus" class="status good">Capacity sufficient</div>
<p id="modelExplanation" class="model-explanation"></p>
<div class="bars" aria-label="Relative toy demand and capacity bars">
<div class="bar-row">
<div class="bar-label">Demand D</div>
<div class="bar demand"><span id="demandBar"></span></div>
</div>
<div class="bar-row">
<div class="bar-label">Capacity C</div>
<div class="bar capacity"><span id="capacityBar"></span></div>
</div>
</div>
<div class="model-values">
<span>Demand: <b id="demandValue">—</b></span>
<span>Capacity: <b id="capacityValue">—</b></span>
<span>D/C: <b id="utilizationValue">—</b></span>
</div>
<p class="note">
Since <code>D/C = s/3</code>, the toy constraint begins when the cell edge
<code>s > 3</code>. Smaller cells have more transport headroom.
</p>
</section>
<section>
<h2>Visual key</h2>
<div class="legend">
<span><i class="swatch good"></i> Capacity sufficient</span>
<span><i class="swatch warning"></i> At limit</span>
<span><i class="swatch bad"></i> Transport-limited</span>
<span><i class="swatch shell"></i> Original cube</span>
</div>
<p class="note">
Conceptually, the cells touch. Small gaps between rendered cubes only make
the subdivision visible.
</p>
<div class="actions">
<button id="resetView" type="button">Reset camera</button>
</div>
</section>
</aside>
<div class="scene-hint">Drag to orbit · mouse wheel to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// DOM and exact rational helpers
// ---------------------------------------------------------------------
const canvas = document.querySelector("#view");
const sizeInput = document.querySelector("#cubeSize");
const subdivisionInput = document.querySelector("#subdivisions");
const elements = {
cubeSizeValue: document.querySelector("#cubeSizeValue"),
subdivisionsValue: document.querySelector("#subdivisionsValue"),
outerRatio: document.querySelector("#outerRatio"),
cellRatio: document.querySelector("#cellRatio"),
ratioGain: document.querySelector("#ratioGain"),
uniqueRatio: document.querySelector("#uniqueRatio"),
sideValue: document.querySelector("#sideValue"),
summedValue: document.querySelector("#summedValue"),
uniqueValue: document.querySelector("#uniqueValue"),
modelStatus: document.querySelector("#modelStatus"),
modelExplanation: document.querySelector("#modelExplanation"),
demandBar: document.querySelector("#demandBar"),
capacityBar: document.querySelector("#capacityBar"),
demandValue: document.querySelector("#demandValue"),
capacityValue: document.querySelector("#capacityValue"),
utilizationValue: document.querySelector("#utilizationValue")
};
function gcd(a, b) {
a = Math.abs(a);
b = Math.abs(b);
while (b !== 0) {
const next = a % b;
a = b;
b = next;
}
return a || 1;
}
function exactText(numerator, denominator) {
if (denominator === 0) return "undefined";
let n = numerator;
let d = denominator;
if (d < 0) {
n = -n;
d = -d;
}
const divisor = gcd(n, d);
n /= divisor;
d /= divisor;
if (d === 1) return `${n}`;
const decimal = (n / d).toLocaleString(undefined, {
maximumFractionDigits: 3
});
return `${n}/${d} ≈ ${decimal}`;
}
// ---------------------------------------------------------------------
// Three.js scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 27, 58);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xcce7ff, 0x182033, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.6);
keyLight.position.set(9, 13, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -13;
keyLight.shadow.camera.right = 13;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -13;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x5aa9ff, 1.35);
rimLight.position.set(-8, 5, -10);
scene.add(rimLight);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
new THREE.MeshStandardMaterial({
color: 0x0b1728,
roughness: 0.95,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(40, 40, 0x31506d, 0x1a2b40);
grid.material.transparent = true;
grid.material.opacity = 0.33;
scene.add(grid);
const cubeRoot = new THREE.Group();
scene.add(cubeRoot);
// ---------------------------------------------------------------------
// Direct camera controls: no addons or external controls are used.
// ---------------------------------------------------------------------
const cameraState = {
theta: 0.68,
phi: 1.04,
zoom: 1,
dragging: false,
lastX: 0,
lastY: 0
};
function updateCamera() {
const L = Number(sizeInput.value);
const radius = L * 2.35 * cameraState.zoom;
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
radius * sinPhi * Math.sin(cameraState.theta),
radius * Math.cos(cameraState.phi),
radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(0, 0, 0);
}
canvas.addEventListener("pointerdown", (event) => {
if (event.pointerType === "mouse" && event.button !== 0) return;
cameraState.dragging = true;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!cameraState.dragging) return;
const dx = event.clientX - cameraState.lastX;
const dy = event.clientY - cameraState.lastY;
cameraState.lastX = event.clientX;
cameraState.lastY = event.clientY;
cameraState.theta -= dx * 0.008;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.008,
0.18,
Math.PI - 0.18
);
});
function endDrag(event) {
cameraState.dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(event.deltaY * 0.001),
0.52,
1.85
);
},
{ passive: false }
);
document.querySelector("#resetView").addEventListener("click", () => {
cameraState.theta = 0.68;
cameraState.phi = 1.04;
cameraState.zoom = 1;
});
// ---------------------------------------------------------------------
// Geometric and toy-model calculations
// ---------------------------------------------------------------------
function getModelState() {
const L = Number(sizeInput.value);
const n = Number(subdivisionInput.value);
// L is always a multiple of 1/2, so store L = LUnits / 2 exactly.
const LUnits = Math.round(L * 2);
const cellCount = n * n * n;
const side = L / n;
const outerArea = 6 * L * L;
const outerVolume = L * L * L;
const cellArea = 6 * side * side;
const cellVolume = side * side * side;
const outerRatio = outerArea / outerVolume;
const cellRatio = cellArea / cellVolume;
// Shared faces are counted twice when summing all cell surfaces.
const summedCellArea = cellCount * cellArea;
// Outer surface plus each internal interface counted once.
const uniqueMembraneArea =
outerArea + 3 * (n - 1) * n * n * side * side;
// Toy model:
// D = 1 * V_cell
// C = 0.5 * A_cell = 3 * s^2
const demand = cellVolume;
const capacity = 0.5 * cellArea;
const utilization = demand / capacity;
let status = "good";
if (utilization > 1) status = "bad";
else if (utilization === 1) status = "warning";
return {
L,
n,
LUnits,
cellCount,
side,
outerArea,
outerVolume,
cellArea,
cellVolume,
outerRatio,
cellRatio,
summedCellArea,
uniqueMembraneArea,
demand,
capacity,
utilization,
status
};
}
function updateReadouts() {
const state = getModelState();
const { L, n, LUnits, cellCount } = state;
elements.cubeSizeValue.textContent = `${L} units`;
elements.subdivisionsValue.textContent = `${n} · ${cellCount} cells`;
// Exact ratios. For example, L = LUnits / 2.
elements.outerRatio.textContent = exactText(12, LUnits);
elements.cellRatio.textContent = exactText(12 * n, LUnits);
elements.ratioGain.textContent = `${n}`;
elements.uniqueRatio.textContent = exactText(n + 1, 2);
elements.sideValue.textContent = exactText(LUnits, 2 * n);
elements.summedValue.textContent =
`${exactText(3 * n * LUnits * LUnits, 2)} units²`;
elements.uniqueValue.textContent =
`${exactText(3 * (n + 1) * LUnits * LUnits, 4)} units²`;
elements.demandValue.textContent =
`${exactText(LUnits ** 3, 8 * n ** 3)} units/time`;
elements.capacityValue.textContent =
`${exactText(3 * LUnits ** 2, 4 * n ** 2)} units/time`;
elements.utilizationValue.textContent = exactText(LUnits, 6 * n);
const largest = Math.max(state.demand, state.capacity);
elements.demandBar.style.width =
`${100 * state.demand / largest}%`;
elements.capacityBar.style.width =
`${100 * state.capacity / largest}%`;
elements.modelStatus.className = `status ${state.status}`;
const sideText = exactText(LUnits, 2 * n);
if (state.status === "bad") {
elements.modelStatus.textContent = "Transport-limited";
elements.modelExplanation.textContent =
`Demand exceeds capacity for every cell because s = ${sideText} > 3. ` +
`All ${cellCount} cells are constrained in this toy model.`;
} else if (state.status === "warning") {
elements.modelStatus.textContent = "Exactly at the limit";
elements.modelExplanation.textContent =
`Demand equals capacity for every cell because s = ${sideText} = 3. ` +
`There is no transport headroom in this toy model.`;
} else {
elements.modelStatus.textContent = "Capacity sufficient";
elements.modelExplanation.textContent =
`Capacity exceeds demand for every cell because s = ${sideText} < 3. ` +
`All ${cellCount} cells have transport headroom in this toy model.`;
}
}
// ---------------------------------------------------------------------
// Low-poly instanced cube rendering
// ---------------------------------------------------------------------
function disposeObject(object) {
object.geometry?.dispose();
if (Array.isArray(object.material)) {
object.material.forEach((material) => material.dispose());
} else {
object.material?.dispose();
}
}
function rebuildCells() {
for (const child of [...cubeRoot.children]) {
cubeRoot.remove(child);
disposeObject(child);
}
const state = getModelState();
const { L, n, side, cellCount, status } = state;
const statusColors = {
good: new THREE.Color(0x45d6c3),
warning: new THREE.Color(0xf4c65c),
bad: new THREE.Color(0xff7468)
};
const cellColor = statusColors[status];
const cellGeometry = new THREE.BoxGeometry(1, 1, 1);
const cellMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0.03,
flatShading: true
});
const cells = new THREE.InstancedMesh(
cellGeometry,
cellMaterial,
cellCount
);
cells.instanceMatrix.setUsage(THREE.StaticDrawUsage);
cells.castShadow = true;
cells.receiveShadow = true;
cells.frustumCulled = false;
const dummy = new THREE.Object3D();
const visualScale = side * (n === 1 ? 0.98 : 0.9);
let index = 0;
for (let x = 0; x < n; x++) {
for (let y = 0; y < n; y++) {
for (let z = 0; z < n; z++) {
dummy.position.set(
(x - (n - 1) / 2) * side,
(y - (n - 1) / 2) * side,
(z - (n - 1) / 2) * side
);
dummy.scale.set(visualScale, visualScale, visualScale);
dummy.updateMatrix();
cells.setMatrixAt(index, dummy.matrix);
cells.setColorAt(index, cellColor);
index++;
}
}
}
cells.instanceMatrix.needsUpdate = true;
cells.instanceColor.needsUpdate = true;
cubeRoot.add(cells);
// Transparent original-cube shell.
const shellGeometry = new THREE.BoxGeometry(L, L, L);
const shellMaterial = new THREE.MeshBasicMaterial({
color: 0x74c7ff,
transparent: true,
opacity: 0.055,
depthWrite: false,
side: THREE.DoubleSide
});
const shell = new THREE.Mesh(shellGeometry, shellMaterial);
shell.renderOrder = 2;
cubeRoot.add(shell);
const edgeGeometry = new THREE.EdgesGeometry(shellGeometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x74c7ff,
transparent: true,
opacity: 0.48
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edges.renderOrder = 3;
cubeRoot.add(edges);
floor.position.y = -L / 2 - 0.08;
grid.position.y = -L / 2 - 0.065;
}
// ---------------------------------------------------------------------
// Events and render loop
// ---------------------------------------------------------------------
function updateAll() {
updateReadouts();
rebuildCells();
updateCamera();
}
sizeInput.addEventListener("input", updateAll);
subdivisionInput.addEventListener("input", updateAll);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
updateAll();
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```