Prompt specification
Build or customize the Three.js 3D scene "Polarized epithelial cell block" 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: Polarized epithelial cell block
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/polarized-epithelial-cell-block-x0821
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this low-poly scene: Model a column-shaped cell with distinct apical and basal surfaces and directional labels; place surface features asymmetrically and keep neighboring tissue orientation consistent.
Working Three.js Starter (polarized-epithelial-cell-block-x0821):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Polarized Columnar Cell</title>
<style>
:root {
--ink: #17343b;
--muted: #5d777b;
--panel: rgba(248, 252, 251, 0.82);
--line: rgba(44, 88, 91, 0.16);
--apical: #efb84f;
--basal: #354c7b;
--marker: #e66d59;
--cell: #3e9b83;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e8f0ef;
color: var(--ink);
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;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card,
.controls-card,
.orientation-card,
.legend {
position: absolute;
border: 1px solid var(--line);
background: var(--panel);
box-shadow: 0 12px 32px rgba(35, 69, 72, 0.1);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.title-card {
top: 22px;
left: 22px;
width: min(330px, calc(100vw - 44px));
padding: 18px 19px 17px;
border-radius: 18px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 7px;
color: #3a7770;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--marker);
box-shadow: 0 0 0 4px rgba(230, 109, 89, 0.13);
content: "";
}
h1 {
margin: 0;
font-size: clamp(21px, 2.4vw, 29px);
line-height: 1.08;
letter-spacing: -0.035em;
}
.subtitle {
margin: 9px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls-card {
top: 22px;
right: 22px;
padding: 11px 12px;
border-radius: 14px;
color: var(--muted);
font-size: 11px;
line-height: 1.5;
}
.controls-card strong {
display: block;
color: var(--ink);
font-size: 12px;
}
button {
pointer-events: auto;
margin-top: 8px;
padding: 7px 10px;
border: 1px solid rgba(44, 88, 91, 0.18);
border-radius: 9px;
background: rgba(255, 255, 255, 0.76);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
transition: background 150ms ease, transform 150ms ease;
}
button:hover {
background: #fff;
transform: translateY(-1px);
}
.orientation-card {
bottom: 22px;
left: 22px;
display: grid;
grid-template-columns: auto 1fr;
gap: 4px 11px;
align-items: center;
min-width: 178px;
padding: 13px 15px;
border-radius: 15px;
}
.axis-arrow {
grid-row: 1 / 3;
color: #34796f;
font-size: 35px;
line-height: 1;
font-weight: 300;
}
.axis-label strong {
display: block;
font-size: 11px;
letter-spacing: 0.08em;
}
.axis-label small {
color: var(--muted);
font-size: 10px;
}
.axis-label.apical strong {
color: #b67d12;
}
.axis-label.basal strong {
color: var(--basal);
}
.legend {
right: 22px;
bottom: 22px;
display: flex;
flex-wrap: wrap;
gap: 9px 14px;
padding: 10px 13px;
border-radius: 13px;
color: var(--muted);
font-size: 10px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 3px;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
pointer-events: none;
}
#leaders line {
fill: none;
stroke-width: 1.4;
stroke-dasharray: 4 5;
opacity: 0.72;
}
#leaders circle {
stroke-width: 1.4;
fill: rgba(255, 255, 255, 0.82);
}
.annotation {
position: fixed;
left: 0;
top: 0;
min-width: 145px;
max-width: 210px;
padding: 9px 12px 10px;
border: 1px solid rgba(44, 88, 91, 0.15);
border-left-width: 4px;
border-radius: 10px;
background: rgba(250, 253, 252, 0.9);
box-shadow: 0 8px 22px rgba(35, 69, 72, 0.09);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
pointer-events: none;
will-change: transform;
}
.annotation strong {
display: block;
color: var(--ink);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.11em;
text-transform: uppercase;
}
.annotation small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
line-height: 1.35;
}
#label-apical {
border-left-color: var(--apical);
}
#label-basal {
border-left-color: var(--basal);
}
#label-feature {
border-left-color: var(--marker);
}
#label-tissue {
border-left-color: var(--cell);
}
@media (max-width: 720px) {
.title-card {
top: 12px;
left: 12px;
padding: 13px 14px;
}
.subtitle {
display: none;
}
.controls-card {
top: 12px;
right: 12px;
padding: 8px 9px;
}
.controls-card span {
display: none;
}
.orientation-card {
bottom: 12px;
left: 12px;
transform: scale(0.9);
transform-origin: bottom left;
}
.legend {
right: 12px;
bottom: 12px;
max-width: 210px;
}
.annotation {
min-width: 120px;
padding: 7px 9px;
}
.annotation small {
font-size: 9px;
}
}
</style>
</head>
<body>
<svg id="leaders" aria-hidden="true">
<line id="line-apical" stroke="#d49a27"></line>
<circle id="dot-apical" r="4" stroke="#d49a27"></circle>
<line id="line-basal" stroke="#354c7b"></line>
<circle id="dot-basal" r="4" stroke="#354c7b"></circle>
<line id="line-feature" stroke="#e66d59"></line>
<circle id="dot-feature" r="4" stroke="#e66d59"></circle>
<line id="line-tissue" stroke="#3e9b83"></line>
<circle id="dot-tissue" r="4" stroke="#3e9b83"></circle>
</svg>
<div class="hud">
<section class="title-card">
<div class="eyebrow">Low-poly epithelial model</div>
<h1>Polarized columnar cell</h1>
<p class="subtitle">
Distinct luminal and basement-facing surfaces, with an eccentric cluster of
apical specializations and aligned neighboring tissue.
</p>
</section>
<section class="controls-card">
<strong>Orbit inspection</strong>
<span>Drag to rotate · wheel to zoom</span><br>
<button id="reset" type="button">Reset view</button>
</section>
<section class="orientation-card">
<div class="axis-arrow">↑</div>
<div class="axis-label apical">
<strong>APICAL</strong>
<small>luminal direction</small>
</div>
<div class="axis-label basal">
<strong>BASAL</strong>
<small>basement interface</small>
</div>
</section>
<section class="legend">
<span><i class="swatch" style="background:#efb84f"></i>Apical</span>
<span><i class="swatch" style="background:#354c7b"></i>Basal</span>
<span><i class="swatch" style="background:#e66d59"></i>Asymmetric markers</span>
</section>
<div class="annotation" id="label-apical">
<strong>Apical surface</strong>
<small>Luminal-facing membrane</small>
</div>
<div class="annotation" id="label-basal">
<strong>Basal surface</strong>
<small>Basement-membrane interface</small>
</div>
<div class="annotation" id="label-feature">
<strong>Asymmetric features</strong>
<small>Offset microvillar cluster and cilium</small>
</div>
<div class="annotation" id="label-tissue">
<strong>Aligned tissue</strong>
<small>Neighbors share the same apical–basal axis</small>
</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(0xe8f0ef);
scene.fog = new THREE.Fog(0xe8f0ef, 10, 18);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
document.body.prepend(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional model of a polarized columnar epithelial cell"
);
const hemi = new THREE.HemisphereLight(0xffffff, 0x5f7776, 2.15);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff1d5, 3.25);
key.position.set(4.5, 7, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 6;
key.shadow.camera.bottom = -6;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.00035;
scene.add(key);
const rim = new THREE.DirectionalLight(0x9ed9ef, 1.65);
rim.position.set(-5, 2.5, -4);
scene.add(rim);
const TOP_Y = 1.62;
const BOTTOM_Y = -1.34;
const CENTRAL_Z = 0.35;
function mulberry32(seed) {
return function () {
let t = seed += 0x6D2B79F5;
t = Math.imul(t ^ t >>> 15, t | 1);
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
return ((t ^ t >>> 14) >>> 0) / 4294967296;
};
}
function makePrismGeometry(radiusTop, radiusBottom, top, bottom, seed) {
const height = top - bottom;
const geometry = new THREE.CylinderGeometry(
radiusTop,
radiusBottom,
height,
8,
2,
false
);
geometry.translate(0, (top + bottom) / 2, 0);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
let x = positions.getX(i);
const y = positions.getY(i);
let z = positions.getZ(i);
const radius = Math.hypot(x, z);
if (radius > 0.0001) {
const angle = Math.atan2(z, x);
const t = (y - bottom) / height;
const irregularity =
1 +
0.045 * Math.sin(angle * 3 + seed) +
0.024 * Math.sin(angle * 7 - seed + t * 1.35);
const lean = 0.024 * Math.sin(t * Math.PI) * Math.cos(seed);
positions.setX(i, x * irregularity + lean);
positions.setZ(i, z * irregularity);
}
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
function makeCell({
x,
z,
radiusTop,
radiusBottom,
sideColor,
apicalColor,
basalColor,
seed,
central = false
}) {
const group = new THREE.Group();
group.position.set(x, 0, z);
const geometry = makePrismGeometry(
radiusTop,
radiusBottom,
TOP_Y,
BOTTOM_Y,
seed
);
const sideMaterial = new THREE.MeshStandardMaterial({
color: sideColor,
roughness: 0.78,
metalness: 0.02,
flatShading: true
});
const apicalMaterial = new THREE.MeshStandardMaterial({
color: apicalColor,
roughness: 0.58,
metalness: 0.02,
flatShading: true
});
const basalMaterial = new THREE.MeshStandardMaterial({
color: basalColor,
roughness: 0.88,
metalness: 0,
flatShading: true
});
const body = new THREE.Mesh(
geometry,
[sideMaterial, apicalMaterial, basalMaterial]
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 19),
new THREE.LineBasicMaterial({
color: central ? 0xeafff8 : 0xd8e8e5,
transparent: true,
opacity: central ? 0.56 : 0.34
})
);
group.add(edges);
const topRing = new THREE.Mesh(
new THREE.TorusGeometry(radiusTop * 0.985, 0.018, 4, 8),
new THREE.MeshStandardMaterial({
color: central ? 0xffe29a : 0xd5e2df,
roughness: 0.5,
flatShading: true
})
);
topRing.rotation.x = Math.PI / 2;
topRing.position.y = TOP_Y + 0.012;
topRing.castShadow = true;
group.add(topRing);
const basalRing = new THREE.Mesh(
new THREE.TorusGeometry(radiusBottom * 0.985, 0.023, 4, 8),
new THREE.MeshStandardMaterial({
color: central ? 0x24375f : 0x526783,
roughness: 0.82,
flatShading: true
})
);
basalRing.rotation.x = Math.PI / 2;
basalRing.position.y = BOTTOM_Y - 0.012;
group.add(basalRing);
if (central) {
const apicalInset = new THREE.Mesh(
new THREE.CircleGeometry(radiusTop * 0.76, 8),
new THREE.MeshStandardMaterial({
color: 0xffdf87,
roughness: 0.66,
flatShading: true,
side: THREE.DoubleSide
})
);
apicalInset.rotation.x = -Math.PI / 2;
apicalInset.position.y = TOP_Y + 0.018;
group.add(apicalInset);
const basalInset = new THREE.Mesh(
new THREE.CircleGeometry(radiusBottom * 0.88, 8),
new THREE.MeshStandardMaterial({
color: 0x27375d,
roughness: 0.9,
flatShading: true,
side: THREE.DoubleSide
})
);
basalInset.rotation.x = Math.PI / 2;
basalInset.position.y = BOTTOM_Y - 0.018;
group.add(basalInset);
}
scene.add(group);
return { group, body, topRing, basalRing };
}
const centralCell = makeCell({
x: 0,
z: CENTRAL_Z,
radiusTop: 0.70,
radiusBottom: 0.76,
sideColor: 0x3e9b83,
apicalColor: 0xefb84f,
basalColor: 0x354c7b,
seed: 1.2,
central: true
});
// Neighboring epithelial cells all share the same top and bottom planes.
const neighborSpecs = [
[-1.48, -0.62, 0],
[1.48, -0.62, 1],
[-0.96, -1.55, 2],
[0.98, -1.58, 3],
[-2.15, -1.42, 4],
[2.15, -1.42, 5],
[-0.55, -2.42, 6],
[0.62, -2.44, 7],
[-2.52, -0.12, 8],
[2.52, -0.12, 9]
];
const neighborPalette = [
0x9fbbb6,
0xa9c2bd,
0x94b1ae,
0xb1c5c1,
0x9eb8b4,
0xa8bfbc
];
neighborSpecs.forEach((spec, index) => {
makeCell({
x: spec[0],
z: spec[1],
radiusTop: 0.60,
radiusBottom: 0.66,
sideColor: neighborPalette[index % neighborPalette.length],
apicalColor: 0xc5d7d3,
basalColor: 0x596c87,
seed: 2.4 + index * 0.73
});
});
// Basement membrane substrate.
const basement = new THREE.Mesh(
new THREE.PlaneGeometry(14, 11),
new THREE.MeshStandardMaterial({
color: 0xd6e3e1,
roughness: 0.97,
metalness: 0
})
);
basement.rotation.x = -Math.PI / 2;
basement.position.y = BOTTOM_Y - 0.045;
basement.receiveShadow = true;
scene.add(basement);
const basementGrid = new THREE.GridHelper(10, 20, 0x8fb4af, 0xbfd3cf);
basementGrid.position.y = BOTTOM_Y - 0.034;
basementGrid.material.transparent = true;
basementGrid.material.opacity = 0.28;
scene.add(basementGrid);
// Eccentric cluster of short apical microvilli.
const microvilliRoot = new THREE.Group();
microvilliRoot.position.set(0, TOP_Y + 0.025, 0);
centralCell.group.add(microvilliRoot);
const random = mulberry32(92);
const microvilliMaterial = new THREE.MeshStandardMaterial({
color: 0xffed9d,
roughness: 0.54,
flatShading: true
});
const microvilliTipMaterial = new THREE.MeshStandardMaterial({
color: 0xffe075,
roughness: 0.58,
flatShading: true
});
function addMicrovillus(x, z, height, material = microvilliMaterial) {
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.027, 0.038, height, 5),
material
);
shaft.position.set(x, height / 2, z);
shaft.castShadow = true;
microvilliRoot.add(shaft);
const tip = new THREE.Mesh(
new THREE.SphereGeometry(0.031, 5, 3),
material
);
tip.position.set(x, height, z);
tip.castShadow = true;
microvilliRoot.add(tip);
}
for (let i = 0; i < 14; i++) {
const angle = random() * Math.PI * 2;
const radius = Math.sqrt(random());
const x = -0.22 + Math.cos(angle) * radius * 0.39;
const z = -0.09 + Math.sin(angle) * radius * 0.30;
const height = 0.15 + random() * 0.25;
addMicrovillus(x, z, height);
}
// A solitary short specialization makes the distribution visibly unequal.
addMicrovillus(0.49, -0.29, 0.24);
// Long, offset primary cilium.
const ciliumPivot = new THREE.Group();
ciliumPivot.position.set(0.36, TOP_Y + 0.035, 0.18);
centralCell.group.add(ciliumPivot);
const ciliumMaterial = new THREE.MeshStandardMaterial({
color: 0xe66d59,
roughness: 0.48,
flatShading: true
});
const ciliumShaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.017, 0.024, 0.78, 6),
ciliumMaterial
);
ciliumShaft.position.y = 0.39;
ciliumShaft.castShadow = true;
ciliumPivot.add(ciliumShaft);
const ciliumTip = new THREE.Mesh(
new THREE.SphereGeometry(0.029, 6, 4),
ciliumMaterial
);
ciliumTip.position.y = 0.78;
ciliumPivot.add(ciliumTip);
// Small raised membrane markers clustered asymmetrically on one side.
const receptorGeometry = new THREE.CylinderGeometry(0.078, 0.078, 0.035, 6);
const receptorMaterial = new THREE.MeshStandardMaterial({
color: 0xe66d59,
roughness: 0.5,
flatShading: true
});
const receptorData = [
[0.48, 0.73],
[0.68, 0.57],
[0.50, 0.42],
[0.82, 0.31],
[0.94, 0.69]
];
receptorData.forEach(([angle, y]) => {
const normal = new THREE.Vector3(Math.cos(angle), 0, Math.sin(angle));
const radiusAtY =
0.76 + (0.70 - 0.76) * ((y - BOTTOM_Y) / (TOP_Y - BOTTOM_Y));
const receptor = new THREE.Mesh(receptorGeometry, receptorMaterial);
receptor.position.copy(normal).multiplyScalar(radiusAtY + 0.012);
receptor.position.y = y;
receptor.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
normal
);
receptor.castShadow = true;
centralCell.group.add(receptor);
});
// Camera controls implemented directly, without addons.
const target = new THREE.Vector3(0, 0.22, -0.25);
let theta = 0.52;
let phi = 1.12;
let radius = 7.6;
let targetTheta = theta;
let targetPhi = phi;
let targetRadius = radius;
let dragging = false;
let previousX = 0;
let previousY = 0;
function updateCamera() {
const sinPhi = Math.sin(phi);
camera.position.set(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(target);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
targetTheta -= dx * 0.006;
targetPhi = THREE.MathUtils.clamp(
targetPhi - dy * 0.005,
0.43,
2.48
);
});
function endDrag(event) {
dragging = false;
renderer.domElement.style.cursor = "grab";
if (event && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetRadius = THREE.MathUtils.clamp(
targetRadius + event.deltaY * 0.006,
4.2,
12
);
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") targetTheta += 0.08;
if (event.key === "ArrowRight") targetTheta -= 0.08;
if (event.key === "ArrowUp") {
targetPhi = Math.max(0.43, targetPhi - 0.06);
}
if (event.key === "ArrowDown") {
targetPhi = Math.min(2.48, targetPhi + 0.06);
}
if (event.key === "+" || event.key === "=") {
targetRadius = Math.max(4.2, targetRadius - 0.35);
}
if (event.key === "-") {
targetRadius = Math.min(12, targetRadius + 0.35);
}
});
document.getElementById("reset").addEventListener("click", () => {
targetTheta = 0.52;
targetPhi = 1.12;
targetRadius = 7.6;
});
// HTML annotation projection.
const annotations = [
{
element: document.getElementById("label-apical"),
line: document.getElementById("line-apical"),
dot: document.getElementById("dot-apical"),
anchor: new THREE.Vector3(-0.12, TOP_Y + 0.08, CENTRAL_Z),
offset: new THREE.Vector2(150, -78)
},
{
element: document.getElementById("label-basal"),
line: document.getElementById("line-basal"),
dot: document.getElementById("dot-basal"),
anchor: new THREE.Vector3(-0.53, BOTTOM_Y - 0.03, CENTRAL_Z),
offset: new THREE.Vector2(-145, 58)
},
{
element: document.getElementById("label-feature"),
line: document.getElementById("line-feature"),
dot: document.getElementById("dot-feature"),
anchor: new THREE.Vector3(0.36, TOP_Y + 0.78, CENTRAL_Z + 0.18),
offset: new THREE.Vector2(150, 18)
},
{
element: document.getElementById("label-tissue"),
line: document.getElementById("line-tissue"),
dot: document.getElementById("dot-tissue"),
anchor: new THREE.Vector3(1.48, TOP_Y, -0.62),
offset: new THREE.Vector2(125, 48)
}
];
function updateAnnotations() {
const width = window.innerWidth;
const height = window.innerHeight;
const compact = width < 720;
annotations.forEach((annotation) => {
const projected = annotation.anchor.clone().project(camera);
const anchorX = (projected.x * 0.5 + 0.5) * width;
const anchorY = (-projected.y * 0.5 + 0.5) * height;
const scale = compact ? 0.7 : 1;
let labelX = anchorX + annotation.offset.x * scale;
let labelY = anchorY + annotation.offset.y * scale;
labelX = THREE.MathUtils.clamp(labelX, 90, width - 90);
labelY = THREE.MathUtils.clamp(labelY, 62, height - 82);
annotation.element.style.transform =
`translate3d(${labelX}px, ${labelY}px, 0) translate(-50%, -50%)`;
annotation.line.setAttribute("x1", anchorX);
annotation.line.setAttribute("y1", anchorY);
annotation.line.setAttribute("x2", labelX);
annotation.line.setAttribute("y2", labelY);
annotation.dot.setAttribute("cx", anchorX);
annotation.dot.setAttribute("cy", anchorY);
});
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", onResize);
updateCamera();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
theta += (targetTheta - theta) * 0.085;
phi += (targetPhi - phi) * 0.085;
radius += (targetRadius - radius) * 0.09;
microvilliRoot.rotation.z = Math.sin(elapsed * 0.9) * 0.024;
microvilliRoot.rotation.x = Math.cos(elapsed * 0.72) * 0.017;
ciliumPivot.rotation.z = Math.sin(elapsed * 0.78) * 0.065;
ciliumPivot.rotation.x = Math.cos(elapsed * 0.64) * 0.045;
updateCamera();
updateAnnotations();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```