Prompt specification
Build or customize the Three.js 3D scene "Egg shell membrane and contents" 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: Egg shell membrane and contents
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/egg-shell-membrane-and-contents-x0101
Scene Description Prompt:
Egg shell membrane and contents. Display an opened egg with shell halves, pale membrane edge, white, and rounded yolk; position labels outside the model without obscuring the nested arrangement. Please build this with Three.js from cdnjs in one self-contained HTML file, using stylized solid shapes.
Working Three.js Starter (egg-shell-membrane-and-contents-x0101):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Opened Egg — Anatomical Study</title>
<style>
:root {
--ink: #393a34;
--muted: #74766c;
--paper: #f3efe6;
--card: rgba(255, 253, 247, 0.84);
--line: rgba(73, 70, 58, 0.16);
--shell: #d7b48b;
--membrane: #efd8cf;
--white: #fffdf5;
--yolk: #efb42f;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
canvas:active {
cursor: grabbing;
}
header {
position: fixed;
top: 28px;
left: 32px;
z-index: 5;
pointer-events: none;
}
.eyebrow {
margin: 0 0 7px;
color: #8a795c;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(28px, 3vw, 45px);
font-weight: 500;
letter-spacing: -0.035em;
line-height: 1;
}
.subtitle {
margin-top: 9px;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.04em;
}
.labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.label-column {
position: absolute;
top: 50%;
display: flex;
width: clamp(150px, 15vw, 205px);
flex-direction: column;
gap: 14px;
transform: translateY(-43%);
}
.label-column.left {
left: clamp(16px, 3vw, 46px);
}
.label-column.right {
right: clamp(16px, 3vw, 46px);
}
.label {
position: relative;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 12px;
background: var(--card);
box-shadow: 0 8px 28px rgba(67, 58, 42, 0.06);
backdrop-filter: blur(9px);
}
.label::after {
position: absolute;
top: 50%;
width: 22px;
height: 1px;
content: "";
background: rgba(82, 79, 68, 0.25);
}
.left .label::after {
right: -23px;
}
.right .label::after {
left: -23px;
}
.label-head {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border: 1px solid rgba(50, 48, 40, 0.12);
border-radius: 50%;
box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.6);
}
.swatch.shell {
background: var(--shell);
}
.swatch.membrane {
background: var(--membrane);
}
.swatch.white {
background: var(--white);
}
.swatch.yolk {
background: var(--yolk);
}
.number {
margin-left: auto;
color: #9a978b;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
}
.label h2 {
margin: 7px 0 4px;
font-size: 13px;
font-weight: 750;
letter-spacing: -0.01em;
}
.label p {
margin: 0;
color: var(--muted);
font-size: 10.5px;
line-height: 1.45;
}
.hint {
position: fixed;
bottom: 22px;
left: 50%;
z-index: 5;
padding: 8px 13px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(255, 253, 247, 0.7);
color: #77776e;
font-size: 10px;
letter-spacing: 0.06em;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
@media (max-width: 700px) {
header {
top: 18px;
left: 18px;
}
.subtitle {
display: none;
}
.label-column {
top: auto;
bottom: 50px;
width: calc(50% - 24px);
gap: 8px;
transform: none;
}
.label-column.left {
left: 12px;
}
.label-column.right {
right: 12px;
}
.label {
padding: 9px 10px;
}
.label h2 {
margin-top: 5px;
font-size: 11px;
}
.label p,
.label::after,
.number {
display: none;
}
.hint {
bottom: 14px;
white-space: nowrap;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional model of an opened egg"></main>
<header>
<p class="eyebrow">Anatomical study</p>
<h1>Opened egg</h1>
<p class="subtitle">Shell, membrane, albumen and yolk</p>
</header>
<aside class="labels" aria-label="Model labels">
<div class="label-column left">
<section class="label">
<div class="label-head">
<span class="swatch shell"></span>
<span class="number">01</span>
</div>
<h2>Eggshell halves</h2>
<p>Two open, bowl-like pieces with irregular cracked edges.</p>
</section>
<section class="label">
<div class="label-head">
<span class="swatch membrane"></span>
<span class="number">02</span>
</div>
<h2>Inner membrane</h2>
<p>A thin, pale lining folded around each shell rim.</p>
</section>
</div>
<div class="label-column right">
<section class="label">
<div class="label-head">
<span class="swatch white"></span>
<span class="number">03</span>
</div>
<h2>Egg white</h2>
<p>Soft albumen pooled into a broad, organic shape.</p>
</section>
<section class="label">
<div class="label-head">
<span class="swatch yolk"></span>
<span class="number">04</span>
</div>
<h2>Rounded yolk</h2>
<p>A compact golden sphere nested within the albumen.</p>
</section>
</div>
</aside>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const container = document.getElementById("scene");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf3efe6);
scene.fog = new THREE.Fog(0xf3efe6, 12, 22);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
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;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Drag to rotate the opened egg. Use the mouse wheel to zoom."
);
container.appendChild(renderer.domElement);
// ---------------------------------------------------------------------
// Materials
// ---------------------------------------------------------------------
const shellOutsideMaterial = new THREE.MeshStandardMaterial({
color: 0xe4c6a0,
roughness: 0.72,
metalness: 0
});
const shellInsideMaterial = new THREE.MeshStandardMaterial({
color: 0xf4e3c8,
roughness: 0.78,
metalness: 0,
side: THREE.BackSide
});
const shellEdgeMaterial = new THREE.MeshStandardMaterial({
color: 0xd0aa7c,
roughness: 0.8,
metalness: 0,
side: THREE.DoubleSide
});
const membraneMaterial = new THREE.MeshStandardMaterial({
color: 0xf0d9d0,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide
});
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xfffdf5,
roughness: 0.48,
metalness: 0
});
const yolkMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf1b42f,
roughness: 0.28,
metalness: 0,
clearcoat: 0.32,
clearcoatRoughness: 0.38
});
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff8e9,
0x929b99,
1.85
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffeac7, 3.15);
keyLight.position.set(-3.8, 7.2, 5.2);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -5;
keyLight.shadow.camera.right = 5;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xd9e9ff, 1.3);
fillLight.position.set(5, 3.5, -4);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd88b, 1.1);
rimLight.position.set(0, 4, -6);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Ground
// ---------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0xe8e1d5,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.015;
ground.receiveShadow = true;
scene.add(ground);
// ---------------------------------------------------------------------
// Irregular shell-rim profile
// ---------------------------------------------------------------------
const rimProfile = [
[0.00, 0.015],
[0.34, 0.075],
[0.68, 0.005],
[1.03, 0.115],
[1.42, 0.020],
[1.84, 0.095],
[2.25, 0.000],
[2.65, 0.070],
[3.02, -0.025],
[3.48, 0.080],
[3.92, 0.005],
[4.38, 0.060],
[4.82, -0.010],
[5.25, 0.070],
[5.72, 0.000],
[Math.PI * 2, 0.015]
];
function sampleRimProfile(angle) {
let a = angle % (Math.PI * 2);
if (a < 0) a += Math.PI * 2;
for (let i = 0; i < rimProfile.length - 1; i++) {
const [a0, v0] = rimProfile[i];
const [a1, v1] = rimProfile[i + 1];
if (a >= a0 && a <= a1) {
const t = (a - a0) / (a1 - a0);
return THREE.MathUtils.lerp(v0, v1, t);
}
}
return rimProfile[0][1];
}
function makeDeformedHemisphere(radius) {
const geometry = new THREE.SphereGeometry(
radius,
96,
48,
0,
Math.PI * 2,
Math.PI / 2,
Math.PI / 2
);
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 angle = Math.atan2(z, x);
const radial = Math.hypot(x, z);
const edgeWeight = 1 - Math.min(1, Math.abs(y) / 0.27);
if (radial > 0.0001) {
const ripple =
1 +
0.011 *
Math.sin(angle * 7.0 + 0.7) *
edgeWeight;
positions.setX(i, x * ripple);
positions.setZ(i, z * ripple);
}
positions.setY(
i,
y + sampleRimProfile(angle) * edgeWeight
);
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
function makeRimGeometry() {
const segments = 128;
const positions = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const y = sampleRimProfile(angle);
positions.push(
Math.cos(angle), y, Math.sin(angle),
Math.cos(angle) * 0.89, y, Math.sin(angle) * 0.89
);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function makeMembraneGeometry() {
const segments = 128;
const positions = [];
const indices = [];
for (let i = 0; i <= segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const rimY = sampleRimProfile(angle);
// A narrow lining that hangs down just inside the shell.
positions.push(
Math.cos(angle) * 0.892,
rimY - 0.006,
Math.sin(angle) * 0.892,
Math.cos(angle) * 0.866,
rimY - 0.185,
Math.sin(angle) * 0.866
);
}
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = a + 1;
const c = a + 2;
const d = a + 3;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const shellScale = new THREE.Vector3(1.13, 1.17, 0.91);
function createShellHalf(side) {
const group = new THREE.Group();
const outside = new THREE.Mesh(
makeDeformedHemisphere(1),
shellOutsideMaterial
);
outside.scale.copy(shellScale);
outside.castShadow = true;
outside.receiveShadow = true;
group.add(outside);
const inside = new THREE.Mesh(
makeDeformedHemisphere(0.89),
shellInsideMaterial
);
inside.scale.copy(shellScale);
inside.receiveShadow = true;
group.add(inside);
const rim = new THREE.Mesh(
makeRimGeometry(),
shellEdgeMaterial
);
rim.scale.copy(shellScale);
rim.castShadow = true;
group.add(rim);
const membrane = new THREE.Mesh(
makeMembraneGeometry(),
membraneMaterial
);
membrane.scale.copy(shellScale);
membrane.castShadow = true;
membrane.receiveShadow = true;
group.add(membrane);
if (side < 0) {
group.position.set(-1.08, 1.02, 0.14);
group.rotation.set(-0.055, 0.22, 0.67);
} else {
group.position.set(1.06, 1.02, -0.12);
group.rotation.set(0.04, -0.21, -0.65);
}
scene.add(group);
return group;
}
createShellHalf(-1);
createShellHalf(1);
// ---------------------------------------------------------------------
// Organic albumen
// ---------------------------------------------------------------------
function createAlbumenShape() {
const shape = new THREE.Shape();
const points = 72;
for (let i = 0; i <= points; i++) {
const angle = (i / points) * Math.PI * 2;
const radius =
1 +
0.055 * Math.sin(angle * 3 + 0.4) +
0.035 * Math.cos(angle * 5 - 0.8) +
0.024 * Math.sin(angle * 8 + 1.4);
const x = Math.cos(angle) * radius * 1.24;
const y = Math.sin(angle) * radius * 0.88;
if (i === 0) {
shape.moveTo(x, y);
} else {
shape.lineTo(x, y);
}
}
shape.closePath();
return shape;
}
const albumenGeometry = new THREE.ExtrudeGeometry(
createAlbumenShape(),
{
depth: 0.27,
steps: 1,
bevelEnabled: true,
bevelThickness: 0.10,
bevelSize: 0.11,
bevelSegments: 4,
curveSegments: 24
}
);
albumenGeometry.rotateX(-Math.PI / 2);
const albumen = new THREE.Mesh(
albumenGeometry,
whiteMaterial
);
albumen.position.set(0, 0.04, 0.04);
albumen.castShadow = true;
albumen.receiveShadow = true;
scene.add(albumen);
const lobeGeometry = new THREE.SphereGeometry(1, 48, 28);
function createAlbumenLobe(position, scale) {
const lobe = new THREE.Mesh(lobeGeometry, whiteMaterial);
lobe.position.copy(position);
lobe.scale.copy(scale);
lobe.castShadow = true;
lobe.receiveShadow = true;
scene.add(lobe);
}
createAlbumenLobe(
new THREE.Vector3(-0.72, 0.29, 0.20),
new THREE.Vector3(0.61, 0.17, 0.44)
);
createAlbumenLobe(
new THREE.Vector3(0.70, 0.28, -0.12),
new THREE.Vector3(0.53, 0.15, 0.39)
);
createAlbumenLobe(
new THREE.Vector3(0.10, 0.27, -0.43),
new THREE.Vector3(0.67, 0.13, 0.33)
);
// ---------------------------------------------------------------------
// Yolk
// ---------------------------------------------------------------------
const yolk = new THREE.Mesh(
new THREE.SphereGeometry(0.56, 64, 40),
yolkMaterial
);
yolk.position.set(0, 0.69, 0.08);
yolk.scale.set(1, 0.94, 1);
yolk.castShadow = true;
yolk.receiveShadow = true;
scene.add(yolk);
// A very subtle upper highlight keeps the yolk visibly rounded.
const yolkHighlight = new THREE.Mesh(
new THREE.SphereGeometry(0.12, 24, 16),
new THREE.MeshBasicMaterial({
color: 0xffdf7b,
transparent: true,
opacity: 0.18,
depthWrite: false
})
);
yolkHighlight.position.set(-0.18, 1.10, 0.43);
yolkHighlight.scale.set(1, 0.32, 0.7);
scene.add(yolkHighlight);
// ---------------------------------------------------------------------
// Custom orbit controls — no Three.js addons
// ---------------------------------------------------------------------
const target = new THREE.Vector3(0, 0.83, 0);
let radius = window.innerWidth < 700 ? 8.6 : 7.4;
let azimuth = 0.18;
let polar = 1.18;
const defaultView = {
radius: window.innerWidth < 700 ? 8.6 : 7.4,
azimuth: 0.18,
polar: 1.18
};
function updateCamera() {
const sinPolar = Math.sin(polar);
camera.position.set(
target.x + radius * sinPolar * Math.sin(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * sinPolar * Math.cos(azimuth)
);
camera.lookAt(target);
}
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
azimuth -= deltaX * 0.006;
polar = THREE.MathUtils.clamp(
polar + deltaY * 0.005,
0.56,
1.46
);
updateCamera();
});
function stopDragging(event) {
if (event.pointerId !== pointerId) return;
dragging = false;
if (canvas.hasPointerCapture(pointerId)) {
canvas.releasePointerCapture(pointerId);
}
pointerId = null;
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius + event.deltaY * 0.005,
5.7,
10.5
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
radius = defaultView.radius;
azimuth = defaultView.azimuth;
polar = defaultView.polar;
updateCamera();
});
canvas.addEventListener("keydown", (event) => {
const step = 0.07;
if (event.key === "ArrowLeft") azimuth += step;
if (event.key === "ArrowRight") azimuth -= step;
if (event.key === "ArrowUp") polar -= step;
if (event.key === "ArrowDown") polar += step;
if (event.key === "+" || event.key === "=") radius -= 0.35;
if (event.key === "-") radius += 0.35;
polar = THREE.MathUtils.clamp(polar, 0.56, 1.46);
radius = THREE.MathUtils.clamp(radius, 5.7, 10.5);
updateCamera();
event.preventDefault();
});
// ---------------------------------------------------------------------
// Resize and render
// ---------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.fov = width < 700 ? 45 : 38;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
resize();
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```