Prompt specification
Build or customize the Three.js 3D scene "Kernel and popped corn section" 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: Kernel and popped corn section
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/kernel-and-popped-corn-section-x0137
Scene Description Prompt:
Show an intact corn kernel beside popped corn, with stylized shell and starch sections. Three.js from cdnjs in one HTML file.
Working Three.js Starter (kernel-and-popped-corn-section-x0137):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Corn: Intact Kernel and Popped Corn</title>
<style>
:root {
color-scheme: light;
--ink: #25251f;
--muted: #716f64;
--paper: #eee9df;
--shell: #a77d32;
--starch: #efb92d;
--germ: #fff0bd;
--popped: #f8f1df;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--paper);
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%;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 48%, rgba(55, 49, 35, 0.08) 100%),
linear-gradient(180deg, rgba(255,255,255,0.18), transparent 28%);
}
.header {
position: fixed;
top: 30px;
left: 34px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: #9a681f;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3.2vw, 48px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
max-width: 360px;
margin-top: 12px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
left: 34px;
bottom: 30px;
z-index: 5;
display: flex;
flex-wrap: wrap;
gap: 17px;
max-width: calc(100vw - 240px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #5e5b52;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.swatch.shell { background: var(--shell); }
.swatch.starch { background: var(--starch); }
.swatch.germ { background: var(--germ); }
.swatch.popped { background: var(--popped); }
.help {
position: fixed;
right: 32px;
bottom: 29px;
z-index: 6;
display: flex;
align-items: center;
gap: 12px;
color: #777267;
font-size: 11px;
}
button {
border: 1px solid rgba(55, 50, 39, 0.18);
border-radius: 999px;
padding: 9px 14px;
background: rgba(255,255,255,0.58);
color: #4c493f;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 160ms ease, transform 160ms ease;
}
button:hover {
background: rgba(255,255,255,0.9);
transform: translateY(-1px);
}
.callout {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 8px;
min-width: 126px;
padding: 8px 11px;
border: 1px solid rgba(62, 55, 39, 0.13);
border-radius: 10px;
background: rgba(249, 247, 240, 0.83);
box-shadow: 0 8px 28px rgba(62, 52, 34, 0.08);
color: #3f3c33;
font-size: 11px;
font-weight: 750;
line-height: 1.1;
pointer-events: none;
backdrop-filter: blur(9px);
transform: translate(-50%, -50%);
transition: opacity 160ms ease;
}
.callout b {
color: #a77725;
font-size: 9px;
letter-spacing: 0.08em;
}
.callout small {
display: block;
margin-top: 3px;
color: #898478;
font-size: 9px;
font-weight: 550;
}
.callout.left::before,
.callout.right::before {
content: "";
position: absolute;
top: 50%;
width: 42px;
height: 1px;
background: rgba(74, 66, 50, 0.35);
}
.callout.left::before {
right: -43px;
}
.callout.right::before {
left: -43px;
}
.callout.left::after,
.callout.right::after {
content: "";
position: absolute;
top: calc(50% - 3px);
width: 6px;
height: 6px;
border-radius: 50%;
background: #8e6725;
box-shadow: 0 0 0 3px rgba(255,255,255,0.7);
}
.callout.left::after {
right: -46px;
}
.callout.right::after {
left: -46px;
}
.callout.up::before {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 34px;
background: rgba(74, 66, 50, 0.35);
}
.callout.up::after {
content: "";
position: absolute;
left: calc(50% - 3px);
top: calc(100% + 31px);
width: 6px;
height: 6px;
border-radius: 50%;
background: #8e6725;
box-shadow: 0 0 0 3px rgba(255,255,255,0.7);
}
@media (max-width: 720px) {
.header {
top: 20px;
left: 20px;
}
.subtitle {
max-width: 270px;
font-size: 11px;
}
.legend {
left: 20px;
bottom: 20px;
gap: 10px;
}
.legend-item {
font-size: 9px;
}
.help {
right: 18px;
bottom: 18px;
}
.help span {
display: none;
}
.callout {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div class="vignette"></div>
<header class="header">
<div class="eyebrow">Botanical study / thermal transformation</div>
<h1>One kernel.<br>Two textures.</h1>
<p class="subtitle">
A stylized longitudinal section of an intact corn kernel beside its
heat-expanded, irregularly lobed popped form.
</p>
</header>
<div id="shellLabel" class="callout left">
<b>01</b><span>Shell<small>outer pericarp</small></span>
</div>
<div id="starchLabel" class="callout right">
<b>02</b><span>Starch<small>golden endosperm</small></span>
</div>
<div id="poppedLabel" class="callout up">
<b>03</b><span>Popped corn<small>expanded starch</small></span>
</div>
<div class="legend">
<div class="legend-item">
<span class="swatch shell"></span>Shell
</div>
<div class="legend-item">
<span class="swatch starch"></span>Starch
</div>
<div class="legend-item">
<span class="swatch germ"></span>Germ
</div>
<div class="legend-item">
<span class="swatch popped"></span>Popped form
</div>
</div>
<div class="help">
<span>Drag to orbit · Scroll to zoom</span>
<button id="resetView" type="button">Reset view</button>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
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;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeee9df);
scene.fog = new THREE.Fog(0xeee9df, 10, 21);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
60
);
const target = new THREE.Vector3(0, -0.04, 0);
const spherical = new THREE.Spherical(8.25, 1.19, 0.38);
const desired = spherical.clone();
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
const hemisphere = new THREE.HemisphereLight(0xfff9e8, 0x8f7650, 2.2);
scene.add(hemisphere);
const key = new THREE.DirectionalLight(0xfff2d6, 4.1);
key.position.set(4.5, 8, 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 = 1;
key.shadow.camera.far = 20;
key.shadow.bias = -0.0002;
key.shadow.normalBias = 0.025;
scene.add(key);
const fill = new THREE.DirectionalLight(0xc9dcff, 1.35);
fill.position.set(-5, 3, 4);
scene.add(fill);
const warmRim = new THREE.PointLight(0xffb846, 18, 8, 2);
warmRim.position.set(-2.2, 1.8, 2.4);
scene.add(warmRim);
const stageMaterial = new THREE.MeshStandardMaterial({
color: 0xded5c5,
roughness: 0.95,
metalness: 0
});
const stage = new THREE.Mesh(
new THREE.CylinderGeometry(4.45, 4.58, 0.16, 96),
stageMaterial
);
stage.position.y = -1.29;
stage.receiveShadow = true;
scene.add(stage);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xeee9df,
roughness: 1
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.38;
ground.receiveShadow = true;
scene.add(ground);
const ringMaterial = new THREE.MeshBasicMaterial({
color: 0xc6bba7,
transparent: true,
opacity: 0.36,
side: THREE.DoubleSide
});
for (const radius of [3.78, 4.18]) {
const ring = new THREE.Mesh(
new THREE.RingGeometry(radius, radius + 0.012, 128),
ringMaterial
);
ring.rotation.x = -Math.PI / 2;
ring.position.y = -1.202;
scene.add(ring);
}
// ---------------------------------------------------------------------
// Intact corn kernel with a stylized longitudinal section
// ---------------------------------------------------------------------
const kernel = new THREE.Group();
kernel.position.set(-1.42, -0.015, 0);
kernel.rotation.set(0.02, 0.43, -0.075);
scene.add(kernel);
const outerProfile = [
new THREE.Vector2(0.035, -1.16),
new THREE.Vector2(0.23, -1.12),
new THREE.Vector2(0.43, -0.95),
new THREE.Vector2(0.58, -0.64),
new THREE.Vector2(0.66, -0.25),
new THREE.Vector2(0.68, 0.18),
new THREE.Vector2(0.62, 0.58),
new THREE.Vector2(0.48, 0.88),
new THREE.Vector2(0.29, 1.10),
new THREE.Vector2(0.07, 1.22)
];
const innerProfile = outerProfile.map(
(point) => new THREE.Vector2(point.x * 0.86, point.y * 0.89 + 0.025)
);
const shellMaterial = new THREE.MeshStandardMaterial({
color: 0xa67a31,
roughness: 0.78,
metalness: 0,
side: THREE.DoubleSide
});
const shell = new THREE.Mesh(
new THREE.LatheGeometry(
outerProfile,
72,
0.72,
Math.PI * 2 - 1.44
),
shellMaterial
);
shell.scale.z = 0.78;
shell.castShadow = true;
shell.receiveShadow = true;
kernel.add(shell);
const starchMaterial = new THREE.MeshStandardMaterial({
color: 0xeeb526,
roughness: 0.72,
metalness: 0
});
const starchBody = new THREE.Mesh(
new THREE.LatheGeometry(innerProfile, 72),
starchMaterial
);
starchBody.scale.z = 0.79;
starchBody.castShadow = true;
starchBody.receiveShadow = true;
kernel.add(starchBody);
function profileShape(profile, xScale = 1, yScale = 1) {
const shape = new THREE.Shape();
shape.moveTo(profile[0].x * xScale, profile[0].y * yScale);
for (let i = 1; i < profile.length; i++) {
shape.lineTo(profile[i].x * xScale, profile[i].y * yScale);
}
for (let i = profile.length - 1; i >= 0; i--) {
shape.lineTo(-profile[i].x * xScale, profile[i].y * yScale);
}
shape.closePath();
return shape;
}
const sectionShell = new THREE.Mesh(
new THREE.ShapeGeometry(profileShape(outerProfile), 32),
new THREE.MeshStandardMaterial({
color: 0xc39842,
roughness: 0.88,
side: THREE.DoubleSide
})
);
sectionShell.position.z = 0.547;
sectionShell.castShadow = true;
kernel.add(sectionShell);
const sectionStarch = new THREE.Mesh(
new THREE.ShapeGeometry(profileShape(innerProfile, 0.93, 0.95), 32),
new THREE.MeshStandardMaterial({
color: 0xf3bd32,
roughness: 0.76,
side: THREE.DoubleSide
})
);
sectionStarch.position.z = 0.557;
sectionStarch.castShadow = true;
kernel.add(sectionStarch);
// Cream-colored germ embedded in the lower part of the cut face.
const germ = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
new THREE.MeshStandardMaterial({
color: 0xffefb8,
roughness: 0.82,
side: THREE.DoubleSide
})
);
germ.position.set(0.015, -0.53, 0.566);
germ.scale.set(0.205, 0.345, 1);
germ.rotation.z = -0.14;
kernel.add(germ);
const germOutline = new THREE.Mesh(
new THREE.CircleGeometry(1, 48),
new THREE.MeshBasicMaterial({
color: 0xd39a37,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide
})
);
germOutline.position.set(0.015, -0.53, 0.568);
germOutline.scale.set(0.215, 0.355, 1);
germOutline.rotation.z = -0.14;
kernel.add(germOutline);
// Cut rims make the shell thickness legible.
function profileCurve(profile, phi, zScale = 0.78) {
const points = profile.map(
(point) =>
new THREE.Vector3(
point.x * Math.sin(phi),
point.y,
point.x * Math.cos(phi) * zScale
)
);
return new THREE.CatmullRomCurve3(points, false, "centripetal");
}
const rimMaterial = new THREE.MeshStandardMaterial({
color: 0x76521e,
roughness: 0.85
});
for (const phi of [0.72, Math.PI * 2 - 0.72]) {
const rim = new THREE.Mesh(
new THREE.TubeGeometry(
profileCurve(outerProfile, phi),
72,
0.028,
8,
false
),
rimMaterial
);
rim.castShadow = true;
kernel.add(rim);
}
const innerRimMaterial = new THREE.MeshStandardMaterial({
color: 0xe1ad3a,
roughness: 0.76
});
for (const phi of [0.72, Math.PI * 2 - 0.72]) {
const rim = new THREE.Mesh(
new THREE.TubeGeometry(
profileCurve(innerProfile, phi, 0.79),
72,
0.016,
7,
false
),
innerRimMaterial
);
kernel.add(rim);
}
// Fine longitudinal shell ridges.
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x79551f,
roughness: 0.9
});
for (const phi of [1.08, 1.68, 2.35, 3.05, 3.75, 4.42, 5.08]) {
const groove = new THREE.Mesh(
new THREE.TubeGeometry(
profileCurve(outerProfile, phi),
64,
0.0065,
5,
false
),
grooveMaterial
);
kernel.add(groove);
}
// Tiny pores in the exposed endosperm.
let randomSeed = 173;
function seededRandom() {
randomSeed =
(randomSeed * 1664525 + 1013904223) >>> 0;
return randomSeed / 4294967296;
}
const poreMaterial = new THREE.MeshBasicMaterial({
color: 0xb47d1d,
transparent: true,
opacity: 0.36,
side: THREE.DoubleSide
});
for (let i = 0; i < 22; i++) {
const pore = new THREE.Mesh(
new THREE.CircleGeometry(0.008 + seededRandom() * 0.011, 10),
poreMaterial
);
pore.position.set(
(seededRandom() - 0.5) * 0.83,
-0.82 + seededRandom() * 1.62,
0.559
);
pore.scale.y = 0.65 + seededRandom() * 1.3;
pore.rotation.z = seededRandom() * Math.PI;
kernel.add(pore);
}
// ---------------------------------------------------------------------
// Popped corn: many irregular, expanded starch lobes
// ---------------------------------------------------------------------
const popped = new THREE.Group();
popped.position.set(1.48, 0.07, 0);
popped.rotation.y = -0.32;
popped.scale.setScalar(1.15);
scene.add(popped);
const poppedMaterials = [
new THREE.MeshStandardMaterial({
color: 0xfaf3e1,
roughness: 0.88
}),
new THREE.MeshStandardMaterial({
color: 0xf2e7cf,
roughness: 0.9
}),
new THREE.MeshStandardMaterial({
color: 0xfffaec,
roughness: 0.86
}),
new THREE.MeshStandardMaterial({
color: 0xe8d8b9,
roughness: 0.93
})
];
function lobedGeometry(seed) {
const geometry = new THREE.IcosahedronGeometry(1, 3);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const z = positions.getZ(i);
const length = Math.hypot(x, y, z) || 1;
const waveA =
Math.sin(x * 5.1 + y * 7.3 + z * 4.7 + seed * 0.71);
const waveB =
Math.sin(x * 12.4 - y * 9.1 + z * 10.3 + seed * 1.37);
const waveC =
Math.cos(x * 17.0 + y * 13.0 - z * 11.0 + seed);
const factor =
1 +
waveA * 0.065 +
waveB * 0.028 +
waveC * 0.012;
positions.setXYZ(
i,
x * factor,
y * factor,
z * factor
);
}
geometry.computeVertexNormals();
return geometry;
}
const branchSpecs = [
[ 0.00, 0.45, 0.00, 0.38, 0.44, 0.34],
[-0.46, 0.62, 0.02, 0.35, 0.43, 0.32],
[ 0.47, 0.66, -0.04, 0.39, 0.46, 0.35],
[-0.73, 0.17, 0.02, 0.35, 0.39, 0.32],
[ 0.73, 0.20, 0.03, 0.38, 0.42, 0.34],
[-0.45, -0.19, 0.08, 0.36, 0.37, 0.33],
[ 0.45, -0.19, 0.10, 0.38, 0.38, 0.34],
[ 0.00, -0.17, 0.48, 0.39, 0.39, 0.32],
[ 0.00, -0.43, -0.12, 0.31, 0.32, 0.29]
];
function addPoppedLobe(parent, position, scale, seed) {
const mesh = new THREE.Mesh(
lobedGeometry(seed),
poppedMaterials[Math.floor(seededRandom() * poppedMaterials.length)]
);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.rotation.set(
seededRandom() * Math.PI,
seededRandom() * Math.PI,
seededRandom() * Math.PI
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
let lobeSeed = 1;
branchSpecs.forEach((spec, branchIndex) => {
addPoppedLobe(
popped,
[spec[0], spec[1], spec[2]],
[spec[3], spec[4], spec[5]],
lobeSeed++
);
for (let j = 0; j < 4; j++) {
const angle = seededRandom() * Math.PI * 2;
const distance = 0.25 + seededRandom() * 0.24;
const size = 0.17 + seededRandom() * 0.13;
addPoppedLobe(
popped,
[
spec[0] + Math.cos(angle) * distance,
spec[1] + Math.sin(angle) * distance * 0.82,
spec[2] + (seededRandom() - 0.5) * 0.48
],
[
size * (0.9 + seededRandom() * 0.35),
size * (0.85 + seededRandom() * 0.5),
size * (0.8 + seededRandom() * 0.35)
],
lobeSeed++
);
}
});
// A small unexpanded base at the bottom.
const poppedBase = new THREE.Mesh(
lobedGeometry(91),
new THREE.MeshStandardMaterial({
color: 0xd9a84b,
roughness: 0.92
})
);
poppedBase.position.set(0, -0.88, 0.01);
poppedBase.scale.set(0.28, 0.14, 0.22);
poppedBase.castShadow = true;
popped.add(poppedBase);
// Warm folds visible between the pale expanded lobes.
const creaseMaterial = new THREE.MeshStandardMaterial({
color: 0xb97828,
roughness: 0.9
});
const creaseCurves = [
[[-0.31, 0.25, 0.55], [-0.16, 0.08, 0.67], [-0.03, -0.08, 0.69]],
[[0.26, 0.33, 0.54], [0.12, 0.13, 0.68], [0.03, -0.03, 0.72]],
[[-0.65, 0.08, 0.32], [-0.52, -0.02, 0.48], [-0.42, -0.17, 0.51]],
[[0.63, 0.12, 0.32], [0.51, 0.00, 0.47], [0.41, -0.13, 0.51]],
[[-0.18, 0.73, 0.22], [-0.09, 0.57, 0.38], [-0.02, 0.42, 0.43]],
[[0.20, 0.78, 0.18], [0.12, 0.61, 0.35], [0.05, 0.46, 0.42]]
];
creaseCurves.forEach((points, index) => {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const crease = new THREE.Mesh(
new THREE.TubeGeometry(curve, 20, 0.012, 6, false),
creaseMaterial
);
crease.castShadow = true;
popped.add(crease);
});
// A couple of tiny escaped puffs.
const escapedPuffMaterial = new THREE.MeshStandardMaterial({
color: 0xf8efd9,
roughness: 0.9
});
addPoppedLobe(
popped,
[0.75, 1.46, -0.08],
[0.13, 0.15, 0.12],
130
);
addPoppedLobe(
popped,
[1.22, 1.18, 0.16],
[0.09, 0.10, 0.08],
141
);
// ---------------------------------------------------------------------
// Screen-space callout placement
// ---------------------------------------------------------------------
const shellLabel = document.getElementById("shellLabel");
const starchLabel = document.getElementById("starchLabel");
const poppedLabel = document.getElementById("poppedLabel");
const shellAnchor = new THREE.Vector3(-0.57, 0.48, 0.46);
const starchAnchor = new THREE.Vector3(0.15, 0.08, 0.61);
const poppedAnchor = new THREE.Vector3(0.26, 0.82, 0.38);
function placeLabel(element, localPoint, object, offsetX, offsetY) {
const worldPoint = localPoint.clone();
object.localToWorld(worldPoint);
worldPoint.project(camera);
const x = (worldPoint.x * 0.5 + 0.5) * window.innerWidth;
const y = (-worldPoint.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x + offsetX}px`;
element.style.top = `${y + offsetY}px`;
element.style.opacity = worldPoint.z > 1 ? "0" : "1";
}
// ---------------------------------------------------------------------
// Custom orbit and zoom controls, implemented without addons
// ---------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
desired.theta -= dx * 0.006;
desired.phi -= dy * 0.005;
desired.phi = THREE.MathUtils.clamp(desired.phi, 0.48, 1.48);
});
function stopDragging(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius *= Math.exp(event.deltaY * 0.001);
desired.radius = THREE.MathUtils.clamp(desired.radius, 5.3, 12.5);
},
{ passive: false }
);
document.getElementById("resetView").addEventListener("click", () => {
desired.set(8.25, 1.19, 0.38);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
spherical.radius += (desired.radius - spherical.radius) * 0.075;
spherical.phi += (desired.phi - spherical.phi) * 0.075;
spherical.theta += (desired.theta - spherical.theta) * 0.075;
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
// Very subtle living motion; the objects remain grounded.
popped.rotation.z = Math.sin(elapsed * 0.38) * 0.012;
popped.position.y = 0.07 + Math.sin(elapsed * 0.72) * 0.008;
kernel.updateMatrixWorld(true);
popped.updateMatrixWorld(true);
placeLabel(shellLabel, shellAnchor, kernel, -116, -42);
placeLabel(starchLabel, starchAnchor, kernel, 118, 24);
placeLabel(poppedLabel, poppedAnchor, popped, 12, -72);
renderer.render(scene, camera);
});
</script>
</body>
</html>
```