Prompt specification
Build or customize the Three.js 3D scene "Whisker follicle and reach model" 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: Whisker follicle and reach model
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/whisker-follicle-and-reach-model-x0665
Scene Description Prompt:
Model a cat head with distinct whisker arcs and a magnified symbolic follicle; show surrounding object distances without claiming whisker span perfectly measures body width. Build this with Three.js from cdnjs as a stylized scene in one self-contained HTML file.
Working Three.js Starter (whisker-follicle-and-reach-model-x0665):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Cat Whisker Field — Three.js Study</title>
<style>
:root {
--ink: #302b28;
--muted: #746b63;
--paper: rgba(250, 247, 240, 0.84);
--line: rgba(67, 57, 49, 0.16);
--accent: #b35d39;
--accent-soft: #e8b99f;
--sage: #6f8f73;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eee9df;
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;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.masthead {
position: absolute;
top: clamp(20px, 3vw, 42px);
left: clamp(20px, 3vw, 46px);
max-width: 430px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: .19em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 2px;
background: var(--accent);
border-radius: 99px;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(37px, 5vw, 68px);
font-weight: 400;
line-height: .94;
letter-spacing: -.045em;
}
.dek {
max-width: 360px;
margin: 17px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: clamp(20px, 3vw, 38px);
right: clamp(20px, 3vw, 42px);
width: 220px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--paper);
box-shadow: 0 14px 45px rgba(71, 57, 43, .08);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
pointer-events: auto;
}
.controls-title {
margin: 0 0 11px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: .17em;
text-transform: uppercase;
}
.control {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
min-height: 38px;
padding: 8px 0;
border: 0;
border-top: 1px solid var(--line);
background: transparent;
color: var(--ink);
font: inherit;
font-size: 12px;
text-align: left;
cursor: pointer;
}
.control:first-of-type { border-top: 0; }
.control:hover { color: var(--accent); }
.switch {
position: relative;
width: 32px;
height: 18px;
flex: 0 0 auto;
border-radius: 99px;
background: #cfc6bb;
transition: background .2s ease;
}
.switch::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(0,0,0,.18);
transition: transform .2s ease;
}
.control[aria-pressed="true"] .switch { background: var(--accent); }
.control[aria-pressed="true"] .switch::after { transform: translateX(14px); }
.note {
position: absolute;
left: clamp(20px, 3vw, 46px);
bottom: clamp(20px, 3vw, 38px);
width: min(430px, calc(100vw - 40px));
padding: 15px 17px;
border-left: 3px solid var(--accent);
border-radius: 0 13px 13px 0;
background: rgba(250, 247, 240, .82);
box-shadow: 0 14px 40px rgba(70, 55, 40, .07);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.note strong {
display: block;
margin-bottom: 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 15px;
font-weight: 400;
}
.note p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.instructions {
position: absolute;
right: clamp(20px, 3vw, 42px);
bottom: clamp(20px, 3vw, 38px);
color: var(--muted);
font-size: 10px;
letter-spacing: .04em;
text-align: right;
}
.measure-label,
.inset-caption {
position: absolute;
left: 0;
top: 0;
opacity: 0;
transform: translate(-50%, -50%);
transition: opacity .15s ease;
will-change: transform, opacity;
}
.measure-label {
min-width: 112px;
padding: 7px 10px;
border: 1px solid rgba(71, 57, 43, .16);
border-radius: 10px;
background: rgba(252, 249, 243, .92);
box-shadow: 0 7px 22px rgba(61, 48, 35, .09);
color: var(--muted);
font-size: 9px;
line-height: 1.35;
text-align: center;
white-space: nowrap;
}
.measure-label b {
display: block;
color: var(--ink);
font-size: 11px;
font-weight: 700;
}
.measure-label::before {
content: "";
display: inline-block;
width: 13px;
height: 1px;
margin-right: 5px;
vertical-align: middle;
background: var(--accent);
}
.inset-caption {
padding: 8px 12px;
border: 1px solid rgba(180, 95, 58, .22);
border-radius: 10px;
background: rgba(250, 244, 236, .9);
box-shadow: 0 8px 25px rgba(61, 48, 35, .08);
text-align: center;
white-space: nowrap;
}
.inset-caption b {
display: block;
color: var(--accent);
font-size: 9px;
letter-spacing: .14em;
text-transform: uppercase;
}
.inset-caption span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
@media (max-width: 760px) {
.masthead { max-width: 280px; }
.dek { display: none; }
.controls { width: 180px; padding: 10px; }
.note { width: calc(100vw - 40px); }
.instructions { display: none; }
.inset-caption span { display: none; }
}
</style>
</head>
<body>
<div class="ui">
<header class="masthead">
<div class="eyebrow">Sensory field study · 03</div>
<h1>Cat whisker<br />field</h1>
<p class="dek">
A stylized portrait of the whisker array, paired with a conceptual
follicle cutaway and nearby spatial references.
</p>
</header>
<aside class="controls" aria-label="Scene controls">
<p class="controls-title">Explore the model</p>
<button class="control" id="toggleDistances" aria-pressed="true">
<span>Distance annotations</span>
<span class="switch" aria-hidden="true"></span>
</button>
<button class="control" id="toggleFollicle" aria-pressed="true">
<span>Magnified follicle</span>
<span class="switch" aria-hidden="true"></span>
</button>
<button class="control" id="toggleOrbit" aria-pressed="false">
<span>Slow orbit</span>
<span class="switch" aria-hidden="true"></span>
</button>
<button class="control" id="resetView">
<span>Reset viewpoint</span>
<span aria-hidden="true">↺</span>
</button>
</aside>
<section class="note">
<strong>Read the diagram, not a biological claim.</strong>
<p>
The whiskers are expressive curved forms, not calibrated rulers, so their
span does not perfectly measure body width. Nearby distances use
illustrative scene units; the follicle is a symbolic enlargement.
</p>
</section>
<div class="instructions">
Drag to orbit · Scroll to zoom<br />
Shift-drag to pan
</div>
<div id="labels"></div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
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 scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 10, 19);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
40
);
const hemisphere = new THREE.HemisphereLight(0xfff8e9, 0x9b8170, 2.15);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff0d7, 4.1);
key.position.set(-4.5, 7.5, 6);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -6;
key.shadow.camera.right = 6;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -3;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0004;
scene.add(key);
const fill = new THREE.DirectionalLight(0xb9d4cf, 1.25);
fill.position.set(5, 3, 3);
scene.add(fill);
const rim = new THREE.DirectionalLight(0xffb985, 1.4);
rim.position.set(2, 5, -5);
scene.add(rim);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xe6ded1,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.02;
floor.receiveShadow = true;
scene.add(floor);
// A quiet backdrop ring gives the portrait a diagrammatic setting.
const backdropRing = new THREE.Mesh(
new THREE.TorusGeometry(2.42, 0.032, 10, 100),
new THREE.MeshStandardMaterial({
color: 0xd8b89c,
roughness: 0.85,
transparent: true,
opacity: 0.55
})
);
backdropRing.position.set(-0.6, 1.95, -1.55);
scene.add(backdropRing);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const fur = new THREE.MeshStandardMaterial({
color: 0xc88343,
roughness: 0.86,
metalness: 0
});
const furLight = new THREE.MeshStandardMaterial({
color: 0xe5b071,
roughness: 0.91
});
const cream = new THREE.MeshStandardMaterial({
color: 0xf3dfbc,
roughness: 0.95
});
const darkFur = new THREE.MeshStandardMaterial({
color: 0x5a3827,
roughness: 0.9
});
const stripeMaterial = new THREE.MeshStandardMaterial({
color: 0x71442d,
roughness: 0.92
});
const whiskerMaterial = new THREE.MeshStandardMaterial({
color: 0xfff4d8,
roughness: 0.48
});
const pink = new THREE.MeshStandardMaterial({
color: 0xd98478,
roughness: 0.72
});
const eyeMaterial = new THREE.MeshStandardMaterial({
color: 0x111313,
roughness: 0.2,
metalness: 0.05
});
const irisMaterial = new THREE.MeshStandardMaterial({
color: 0x8ca36d,
roughness: 0.33
});
const glintMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const accentMaterial = new THREE.MeshStandardMaterial({
color: 0xb35d39,
roughness: 0.48
});
function mesh(geometry, material, position, scale, parent = scene) {
const object = new THREE.Mesh(geometry, material);
if (position) object.position.set(...position);
if (scale) object.scale.set(...scale);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function tube(points, radius, material, parent = scene, segments = 36) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const geometry = new THREE.TubeGeometry(curve, segments, radius, 7, false);
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
parent.add(object);
return object;
}
// -------------------------------------------------------------------------
// Stylized cat head
// -------------------------------------------------------------------------
const cat = new THREE.Group();
cat.position.set(-0.65, 1.72, 0);
scene.add(cat);
// Narrow portrait stand rather than a full body.
const stand = mesh(
new THREE.CylinderGeometry(0.63, 0.82, 0.18, 64),
new THREE.MeshStandardMaterial({ color: 0xd9cbbb, roughness: 0.82 }),
[0, 0.08, 0],
null,
cat
);
stand.receiveShadow = true;
mesh(
new THREE.CylinderGeometry(0.28, 0.42, 0.54, 48),
new THREE.MeshStandardMaterial({ color: 0xcab9a7, roughness: 0.8 }),
[0, 0.43, 0],
null,
cat
);
mesh(
new THREE.SphereGeometry(1, 48, 36),
fur,
[0, 0, 0],
[1.19, 1.03, 0.91],
cat
);
// Cheeks and muzzle.
mesh(
new THREE.SphereGeometry(1, 36, 28),
furLight,
[-0.38, -0.27, 0.73],
[0.58, 0.4, 0.32],
cat
);
mesh(
new THREE.SphereGeometry(1, 36, 28),
furLight,
[0.38, -0.27, 0.73],
[0.58, 0.4, 0.32],
cat
);
mesh(
new THREE.SphereGeometry(1, 36, 28),
cream,
[0, -0.38, 0.88],
[0.48, 0.3, 0.27],
cat
);
// Ears.
const leftEar = mesh(
new THREE.ConeGeometry(0.55, 1.17, 3, 1),
fur,
[-0.72, 0.88, -0.03],
null,
cat
);
leftEar.rotation.z = -0.16;
leftEar.rotation.y = -0.12;
const rightEar = mesh(
new THREE.ConeGeometry(0.55, 1.17, 3, 1),
fur,
[0.72, 0.88, -0.03],
null,
cat
);
rightEar.rotation.z = 0.16;
rightEar.rotation.y = 0.12;
const leftInner = mesh(
new THREE.ConeGeometry(0.29, 0.72, 3, 1),
pink,
[-0.72, 0.88, 0.2],
null,
cat
);
leftInner.rotation.z = -0.16;
leftInner.rotation.y = -0.12;
const rightInner = mesh(
new THREE.ConeGeometry(0.29, 0.72, 3, 1),
pink,
[0.72, 0.88, 0.2],
null,
cat
);
rightInner.rotation.z = 0.16;
rightInner.rotation.y = 0.12;
// Eyes.
for (const side of [-1, 1]) {
mesh(
new THREE.SphereGeometry(1, 32, 24),
eyeMaterial,
[side * 0.45, 0.16, 0.83],
[0.31, 0.18, 0.11],
cat
);
mesh(
new THREE.SphereGeometry(1, 32, 24),
irisMaterial,
[side * 0.45, 0.16, 0.915],
[0.2, 0.14, 0.045],
cat
);
mesh(
new THREE.SphereGeometry(1, 24, 18),
eyeMaterial,
[side * 0.45, 0.155, 0.958],
[0.07, 0.115, 0.022],
cat
);
mesh(
new THREE.SphereGeometry(1, 16, 12),
glintMaterial,
[side * 0.45 - 0.07, 0.215, 0.987],
[0.043, 0.043, 0.018],
cat
);
tube(
[
[side * 0.18, 0.27, 0.91],
[side * 0.34, 0.36, 0.91],
[side * 0.54, 0.33, 0.89],
[side * 0.71, 0.23, 0.83]
],
0.022,
darkFur,
cat
);
}
// Nose and mouth.
const nose = mesh(
new THREE.SphereGeometry(1, 28, 20),
pink,
[0, -0.16, 1.105],
[0.17, 0.115, 0.11],
cat
);
nose.rotation.x = -0.1;
tube(
[
[0, -0.19, 1.18],
[0, -0.3, 1.17],
[0, -0.37, 1.11]
],
0.018,
darkFur,
cat
);
tube(
[
[0, -0.36, 1.12],
[-0.12, -0.43, 1.1],
[-0.25, -0.38, 1.04]
],
0.016,
darkFur,
cat
);
tube(
[
[0, -0.36, 1.12],
[0.12, -0.43, 1.1],
[0.25, -0.38, 1.04]
],
0.016,
darkFur,
cat
);
// Forehead stripes.
const stripeXs = [-0.28, 0, 0.28];
stripeXs.forEach((x, index) => {
tube(
[
[x * 0.6, 0.82, 0.76],
[x * 0.82, 0.62, 0.88],
[x, 0.42 + index * 0.015, 0.9],
[x * 0.92, 0.28, 0.9]
],
0.045,
stripeMaterial,
cat,
24
);
});
// Distinct, individually curved whiskers.
const whiskerData = [
{ y: -0.08, rise: 0.39, reach: 2.15 },
{ y: -0.19, rise: 0.22, reach: 2.35 },
{ y: -0.31, rise: 0.03, reach: 2.48 },
{ y: -0.42, rise: -0.18, reach: 2.35 },
{ y: -0.51, rise: -0.35, reach: 2.10 }
];
for (const side of [-1, 1]) {
whiskerData.forEach((w, i) => {
const rootX = side * (0.54 + i * 0.025);
const rootY = w.y;
const endX = side * w.reach;
tube(
[
[rootX, rootY, 1.01],
[side * 0.92, rootY + w.rise * 0.38, 1.00],
[side * 1.38, rootY + w.rise * 0.72, 0.91],
[side * 1.79, rootY + w.rise * 0.94, 0.79],
[endX, rootY + w.rise, 0.67 - i * 0.025]
],
0.019,
whiskerMaterial,
cat,
48
);
mesh(
new THREE.SphereGeometry(0.035, 12, 8),
cream,
[rootX, rootY, 1.02],
null,
cat
);
});
}
// Small symbolic follicle marker on the cheek.
const follicleMarker = mesh(
new THREE.SphereGeometry(0.075, 20, 14),
new THREE.MeshStandardMaterial({
color: 0xffc58c,
emissive: 0xb35d39,
emissiveIntensity: 0.4,
roughness: 0.5
}),
[0.69, -0.23, 0.92],
null,
cat
);
const markerHalo = mesh(
new THREE.TorusGeometry(0.115, 0.017, 8, 40),
accentMaterial,
[0.69, -0.23, 0.95],
null,
cat
);
// -------------------------------------------------------------------------
// Nearby objects
// -------------------------------------------------------------------------
const plant = new THREE.Group();
plant.position.set(-3.0, 0, -0.55);
scene.add(plant);
mesh(
new THREE.CylinderGeometry(0.42, 0.32, 0.58, 40),
new THREE.MeshStandardMaterial({ color: 0xb96d52, roughness: 0.8 }),
[0, 0.29, 0],
null,
plant
);
mesh(
new THREE.CylinderGeometry(0.43, 0.43, 0.07, 40),
new THREE.MeshStandardMaterial({ color: 0x654638, roughness: 1 }),
[0, 0.59, 0],
null,
plant
);
mesh(
new THREE.CylinderGeometry(0.022, 0.03, 0.85, 12),
new THREE.MeshStandardMaterial({ color: 0x5d7b52, roughness: 0.88 }),
[0, 1.02, 0],
null,
plant
);
const leafMaterial = new THREE.MeshStandardMaterial({
color: 0x6f8c61,
roughness: 0.85
});
[
[-0.17, 1.0, 0.01, -0.4, 0.55, 0.18],
[0.16, 1.22, 0, 0.38, 0.62, 0.2],
[-0.2, 1.37, 0.02, -0.48, 0.68, 0.21],
[0.18, 1.51, 0.01, 0.48, 0.64, 0.2]
].forEach(([x, y, z, rx, ry, rz]) => {
const leaf = mesh(
new THREE.SphereGeometry(1, 24, 18),
leafMaterial,
[x, y, z],
[0.25, 0.1, 0.48],
plant
);
leaf.rotation.set(rx, ry, rz);
});
const yarn = new THREE.Group();
yarn.position.set(1.48, 0.4, 1.35);
scene.add(yarn);
mesh(
new THREE.SphereGeometry(0.39, 36, 26),
new THREE.MeshStandardMaterial({ color: 0xc78a82, roughness: 0.95 }),
[0, 0, 0],
null,
yarn
);
const yarnWrap = new THREE.MeshStandardMaterial({
color: 0xe4b3a9,
roughness: 0.95
});
const wrapA = mesh(
new THREE.TorusGeometry(0.39, 0.022, 8, 60),
yarnWrap,
[0, 0, 0],
null,
yarn
);
wrapA.rotation.set(0.3, 0.5, 0.2);
const wrapB = mesh(
new THREE.TorusGeometry(0.39, 0.021, 8, 60),
yarnWrap,
[0, 0, 0],
null,
yarn
);
wrapB.rotation.set(1.05, -0.25, 0.4);
const wrapC = mesh(
new THREE.TorusGeometry(0.39, 0.019, 8, 60),
yarnWrap,
[0, 0, 0],
null,
yarn
);
wrapC.rotation.set(-0.7, 0.7, 1.1);
const block = new THREE.Group();
block.position.set(1.65, 0.37, -1.38);
block.rotation.y = -0.22;
scene.add(block);
mesh(
new THREE.BoxGeometry(0.7, 0.7, 0.7),
new THREE.MeshStandardMaterial({ color: 0x739095, roughness: 0.76 }),
[0, 0, 0],
null,
block
);
mesh(
new THREE.BoxGeometry(0.44, 0.44, 0.015),
new THREE.MeshStandardMaterial({ color: 0xd6b665, roughness: 0.75 }),
[0, 0, 0.358],
null,
block
);
// -------------------------------------------------------------------------
// Illustrative nearby-distance annotations
// -------------------------------------------------------------------------
const distanceGroup = new THREE.Group();
scene.add(distanceGroup);
const distanceLabelsRoot = document.getElementById("labels");
const measurements = [
{
name: "to plant",
from: new THREE.Vector3(-1.61, 1.42, -0.25),
to: new THREE.Vector3(-2.68, 1.18, -0.55),
label: new THREE.Vector3(-2.22, 1.75, -0.42)
},
{
name: "to yarn",
from: new THREE.Vector3(-0.08, 1.16, 0.76),
to: new THREE.Vector3(1.16, 0.51, 1.13),
label: new THREE.Vector3(0.58, 1.46, 1.08)
},
{
name: "to block",
from: new THREE.Vector3(-0.12, 1.37, -0.72),
to: new THREE.Vector3(1.48, 0.56, -1.24),
label: new THREE.Vector3(0.72, 1.52, -1.05)
}
];
measurements.forEach((measurement) => {
const distance = measurement.from.distanceTo(measurement.to);
const geometry = new THREE.BufferGeometry().setFromPoints([
measurement.from,
measurement.to
]);
const material = new THREE.LineDashedMaterial({
color: 0xb35d39,
dashSize: 0.09,
gapSize: 0.065,
transparent: true,
opacity: 0.85,
depthTest: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
line.renderOrder = 20;
distanceGroup.add(line);
[measurement.from, measurement.to].forEach((point) => {
const dot = new THREE.Mesh(
new THREE.SphereGeometry(0.045, 12, 8),
new THREE.MeshBasicMaterial({
color: 0xb35d39,
depthTest: false
})
);
dot.position.copy(point);
dot.renderOrder = 21;
distanceGroup.add(dot);
});
const element = document.createElement("div");
element.className = "measure-label";
element.innerHTML = `<b>${measurement.name}</b>≈ ${distance.toFixed(1)} scene units`;
distanceLabelsRoot.appendChild(element);
measurement.element = element;
});
// -------------------------------------------------------------------------
// Magnified conceptual follicle inset
// -------------------------------------------------------------------------
const follicleGroup = new THREE.Group();
follicleGroup.position.set(2.55, 2.67, 0.52);
scene.add(follicleGroup);
const insetBack = new THREE.Mesh(
new THREE.CircleGeometry(0.83, 64),
new THREE.MeshBasicMaterial({
color: 0xf8f1e6,
transparent: true,
opacity: 0.91,
side: THREE.DoubleSide,
depthTest: false
})
);
insetBack.position.z = -0.08;
insetBack.renderOrder = 30;
follicleGroup.add(insetBack);
const insetRing = new THREE.Mesh(
new THREE.TorusGeometry(0.83, 0.035, 12, 80),
accentMaterial
);
insetRing.position.z = -0.05;
insetRing.renderOrder = 31;
follicleGroup.add(insetRing);
const follicleSheath = new THREE.Mesh(
new THREE.SphereGeometry(1, 40, 28),
new THREE.MeshStandardMaterial({
color: 0xeab08f,
transparent: true,
opacity: 0.27,
roughness: 0.5,
depthWrite: false
})
);
follicleSheath.scale.set(0.39, 0.56, 0.2);
follicleSheath.position.z = 0.03;
follicleGroup.add(follicleSheath);
const follicleCavity = new THREE.Mesh(
new THREE.SphereGeometry(1, 36, 24),
new THREE.MeshStandardMaterial({
color: 0xf4c3a2,
transparent: true,
opacity: 0.58,
roughness: 0.66,
depthWrite: false
})
);
follicleCavity.scale.set(0.29, 0.42, 0.16);
follicleCavity.position.z = 0.07;
follicleGroup.add(follicleCavity);
const oocyte = new THREE.Mesh(
new THREE.SphereGeometry(0.19, 32, 24),
new THREE.MeshStandardMaterial({
color: 0xc6d4a7,
roughness: 0.48,
emissive: 0x5f7544,
emissiveIntensity: 0.12
})
);
oocyte.position.set(0, -0.03, 0.12);
follicleGroup.add(oocyte);
const nucleus = new THREE.Mesh(
new THREE.SphereGeometry(0.068, 24, 18),
new THREE.MeshStandardMaterial({
color: 0x71845a,
roughness: 0.55
})
);
nucleus.position.set(-0.025, 0.01, 0.285);
follicleGroup.add(nucleus);
const cellMaterial = new THREE.MeshStandardMaterial({
color: 0xd99675,
roughness: 0.7
});
for (let i = 0; i < 9; i++) {
const angle = (i / 9) * Math.PI * 2;
const cell = new THREE.Mesh(
new THREE.SphereGeometry(0.066, 16, 12),
cellMaterial
);
cell.position.set(
Math.cos(angle) * 0.29,
Math.sin(angle) * 0.4,
0.08
);
cell.scale.set(1, 1, 0.65);
follicleGroup.add(cell);
}
const follicleStem = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.08, 0.32, 24),
new THREE.MeshStandardMaterial({
color: 0xc8874b,
roughness: 0.85
})
);
follicleStem.position.set(0, -0.64, 0);
follicleGroup.add(follicleStem);
const leaderCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(0.02, 1.49, 0.94),
new THREE.Vector3(0.72, 1.67, 0.84),
new THREE.Vector3(1.42, 2.05, 0.67),
new THREE.Vector3(1.96, 2.5, 0.57)
]);
const leader = new THREE.Mesh(
new THREE.TubeGeometry(leaderCurve, 48, 0.018, 6, false),
new THREE.MeshBasicMaterial({
color: 0xb35d39,
transparent: true,
opacity: 0.72,
depthTest: false
})
);
leader.renderOrder = 29;
scene.add(leader);
const insetCaption = document.createElement("div");
insetCaption.className = "inset-caption";
insetCaption.innerHTML =
"<b>Magnified follicle</b><span>symbolic cutaway · not histological scale</span>";
distanceLabelsRoot.appendChild(insetCaption);
const insetCaptionPosition = new THREE.Vector3(2.55, 3.75, 0.52);
// -------------------------------------------------------------------------
// Direct camera controls — no addons
// -------------------------------------------------------------------------
const home = {
theta: 0.31,
phi: 1.18,
radius: 7.65,
target: new THREE.Vector3(-0.05, 1.56, 0)
};
const orbit = {
theta: home.theta,
phi: home.phi,
radius: home.radius,
target: home.target.clone()
};
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
let autoOrbit = false;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
camera.matrixWorld.extractBasis(right, up, new THREE.Vector3());
const panScale = orbit.radius * 0.0013;
orbit.target.addScaledVector(right, -dx * panScale);
orbit.target.addScaledVector(up, dy * panScale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi - dy * 0.005, 0.48, 1.45);
}
});
function stopDragging(event) {
dragging = false;
panning = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
4.5,
11.5
);
},
{ passive: false }
);
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
const toggleDistances = document.getElementById("toggleDistances");
const toggleFollicle = document.getElementById("toggleFollicle");
const toggleOrbit = document.getElementById("toggleOrbit");
toggleDistances.addEventListener("click", () => {
const visible = toggleDistances.getAttribute("aria-pressed") !== "true";
toggleDistances.setAttribute("aria-pressed", String(visible));
distanceGroup.visible = visible;
measurements.forEach((measurement) => {
measurement.element.style.visibility = visible ? "visible" : "hidden";
});
});
toggleFollicle.addEventListener("click", () => {
const visible = toggleFollicle.getAttribute("aria-pressed") !== "true";
toggleFollicle.setAttribute("aria-pressed", String(visible));
follicleGroup.visible = visible;
leader.visible = visible;
follicleMarker.visible = visible;
markerHalo.visible = visible;
insetCaption.style.visibility = visible ? "visible" : "hidden";
});
toggleOrbit.addEventListener("click", () => {
autoOrbit = toggleOrbit.getAttribute("aria-pressed") !== "true";
toggleOrbit.setAttribute("aria-pressed", String(autoOrbit));
});
document.getElementById("resetView").addEventListener("click", () => {
orbit.theta = home.theta;
orbit.phi = home.phi;
orbit.radius = home.radius;
orbit.target.copy(home.target);
});
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const projected = new THREE.Vector3();
function placeLabel(element, worldPosition, visible = true) {
projected.copy(worldPosition).project(camera);
const inFront = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
element.style.opacity = visible && inFront ? "1" : "0";
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
if (autoOrbit && !dragging) {
orbit.theta += 0.0028;
}
updateCamera();
// Keep the cutaway facing the viewer while retaining its world position.
follicleGroup.quaternion.copy(camera.quaternion);
// A very small breathing motion gives the portrait life.
cat.position.y = 1.72 + Math.sin(elapsed * 0.8) * 0.012;
cat.rotation.y = Math.sin(elapsed * 0.33) * 0.018;
measurements.forEach((measurement) => {
placeLabel(
measurement.element,
measurement.label,
distanceGroup.visible
);
});
placeLabel(
insetCaption,
insetCaptionPosition,
follicleGroup.visible
);
renderer.render(scene, camera);
}
updateCamera();
animate();
</script>
</body>
</html>
```