Prompt specification
Build or customize the Three.js 3D scene "Nested container dolls 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: Nested container dolls section
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/nested-container-dolls-section-x0357
Scene Description Prompt:
Create three stylized nesting dolls with separated shell halves and visible wall thickness; smaller dolls fit inside larger ones. Three.js from cdnjs, standalone HTML.
Working Three.js Starter (nested-container-dolls-section-x0357):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Three Nested Dolls</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eadfce;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #382d29;
}
#app,
canvas {
display: block;
width: 100%;
height: 100%;
}
.hud {
position: fixed;
top: clamp(24px, 5vw, 64px);
left: clamp(24px, 5vw, 64px);
z-index: 2;
pointer-events: none;
user-select: none;
}
.eyebrow {
display: block;
margin-bottom: 12px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.28em;
text-transform: uppercase;
opacity: 0.55;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(38px, 6vw, 78px);
font-weight: 400;
line-height: 0.88;
letter-spacing: -0.055em;
}
.hud p {
max-width: 230px;
margin: 20px 0 0;
font-size: 12px;
line-height: 1.55;
opacity: 0.62;
}
.controls {
position: fixed;
right: clamp(18px, 3vw, 38px);
bottom: clamp(18px, 3vw, 34px);
z-index: 3;
display: flex;
align-items: center;
gap: 12px;
}
.controls span {
font-size: 10px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
opacity: 0.55;
pointer-events: none;
}
button {
border: 1px solid rgba(56, 45, 41, 0.22);
border-radius: 999px;
padding: 10px 15px;
background: rgba(255, 255, 255, 0.38);
color: #382d29;
font: inherit;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.7);
transform: translateY(-1px);
}
@media (max-width: 640px) {
.hud p {
display: none;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<main id="app" aria-label="Interactive three-dimensional nesting doll study"></main>
<section class="hud">
<span class="eyebrow">Form Study / 03</span>
<h1>Nesting<br>Dolls</h1>
<p>Three hollow lacquer shells, opened along their seams and nested around a shared center.</p>
</section>
<div class="controls">
<span>Drag · Scroll · Double-click</span>
<button id="reset" 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 app = document.querySelector("#app");
const resetButton = document.querySelector("#reset");
// ---------------------------------------------------------------------
// Renderer and scene
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeadfce);
scene.fog = new THREE.Fog(0xeadfce, 9, 19);
const camera = new THREE.PerspectiveCamera(
35,
window.innerWidth / window.innerHeight,
0.1,
40
);
const renderer = new THREE.WebGLRenderer({
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.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const maxAnisotropy = renderer.capabilities.getMaxAnisotropy();
// ---------------------------------------------------------------------
// Lighting and studio
// ---------------------------------------------------------------------
scene.add(new THREE.HemisphereLight(0xfff7e8, 0x75635c, 2.15));
const keyLight = new THREE.DirectionalLight(0xfff0d5, 3.25);
keyLight.position.set(4.5, 7.5, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -3;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.bias = -0.0002;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb9d9df, 1.1);
fillLight.position.set(-4, 3, 3);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xff9d5c, 16, 12, 2);
rimLight.position.set(-2.5, 3.2, -3);
scene.add(rimLight);
const backdrop = new THREE.Mesh(
new THREE.CylinderGeometry(9, 9, 12, 64, 1, true),
new THREE.MeshStandardMaterial({
color: 0xeadfce,
roughness: 1,
side: THREE.BackSide
})
);
backdrop.position.y = 4;
scene.add(backdrop);
const floor = new THREE.Mesh(
new THREE.CircleGeometry(20, 96),
new THREE.MeshStandardMaterial({
color: 0xd8cbb7,
roughness: 1
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.16;
floor.receiveShadow = true;
scene.add(floor);
const platform = new THREE.Mesh(
new THREE.CylinderGeometry(2.05, 2.12, 0.15, 96),
new THREE.MeshStandardMaterial({
color: 0xf2e8d7,
roughness: 0.88
})
);
platform.position.y = -0.075;
platform.receiveShadow = true;
platform.castShadow = true;
scene.add(platform);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(2.015, 0.012, 8, 128),
new THREE.MeshStandardMaterial({
color: 0xb89965,
roughness: 0.45,
metalness: 0.12
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = 0.004;
scene.add(platformRing);
// Soft painted contact shadow beneath the nested dolls.
const shadowCanvas = document.createElement("canvas");
shadowCanvas.width = shadowCanvas.height = 256;
const shadowContext = shadowCanvas.getContext("2d");
const shadowGradient = shadowContext.createRadialGradient(
128, 128, 8,
128, 128, 124
);
shadowGradient.addColorStop(0, "rgba(55, 37, 30, .32)");
shadowGradient.addColorStop(0.45, "rgba(55, 37, 30, .14)");
shadowGradient.addColorStop(1, "rgba(55, 37, 30, 0)");
shadowContext.fillStyle = shadowGradient;
shadowContext.fillRect(0, 0, 256, 256);
const contactShadow = new THREE.Mesh(
new THREE.PlaneGeometry(3.4, 2.5),
new THREE.MeshBasicMaterial({
map: new THREE.CanvasTexture(shadowCanvas),
transparent: true,
depthWrite: false
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.position.set(0, 0.008, 0.05);
scene.add(contactShadow);
// ---------------------------------------------------------------------
// Procedural painted textures
// ---------------------------------------------------------------------
function seededRandom(seed) {
let value = seed >>> 0;
return () => {
value = (value * 1664525 + 1013904223) >>> 0;
return value / 4294967296;
};
}
function drawFlower(context, x, y, radius, accent, dark) {
context.save();
context.translate(x, y);
for (let petal = 0; petal < 6; petal += 1) {
context.save();
context.rotate((petal / 6) * Math.PI * 2);
context.beginPath();
context.ellipse(0, -radius * 0.58, radius * 0.28, radius * 0.56, 0, 0, Math.PI * 2);
context.fillStyle = accent;
context.fill();
context.strokeStyle = dark;
context.lineWidth = Math.max(1, radius * 0.05);
context.stroke();
context.restore();
}
context.beginPath();
context.arc(0, 0, radius * 0.3, 0, Math.PI * 2);
context.fillStyle = dark;
context.fill();
context.restore();
}
function createPaintTexture(baseColor, accentColor, darkColor, seed) {
const size = 1024;
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
const context = canvas.getContext("2d");
const random = seededRandom(seed);
context.fillStyle = baseColor;
context.fillRect(0, 0, size, size);
// Subtle lacquer variation.
for (let index = 0; index < 1100; index += 1) {
const x = random() * size;
const y = random() * size;
const alpha = 0.012 + random() * 0.025;
context.fillStyle = `rgba(255,255,255,${alpha})`;
context.beginPath();
context.arc(x, y, random() * 2.2 + 0.35, 0, Math.PI * 2);
context.fill();
}
const horizontalBand = (v, height, color, alpha = 1) => {
context.save();
context.globalAlpha = alpha;
context.fillStyle = color;
context.fillRect(0, (1 - v) * size - height / 2, size, height);
context.restore();
};
horizontalBand(0.055, size * 0.035, darkColor, 0.78);
horizontalBand(0.095, size * 0.012, accentColor);
horizontalBand(0.17, size * 0.025, accentColor, 0.85);
horizontalBand(0.205, size * 0.010, darkColor, 0.65);
horizontalBand(0.535, size * 0.024, accentColor, 0.9);
horizontalBand(0.565, size * 0.009, darkColor, 0.55);
horizontalBand(0.675, size * 0.055, accentColor, 0.94);
horizontalBand(0.715, size * 0.012, darkColor, 0.55);
horizontalBand(0.945, size * 0.025, accentColor, 0.8);
// Floral body decoration.
const flowerRows = [
{ v: 0.285, radius: 22 },
{ v: 0.405, radius: 17 }
];
for (const row of flowerRows) {
for (const u of [0.11, 0.37, 0.63, 0.89]) {
drawFlower(
context,
u * size,
(1 - row.v) * size,
row.radius,
accentColor,
darkColor
);
}
}
// A small decorative diamond motif.
context.save();
context.translate(size * 0.5, size * (1 - 0.46));
context.rotate(Math.PI / 4);
context.fillStyle = accentColor;
context.fillRect(-15, -15, 30, 30);
context.strokeStyle = darkColor;
context.lineWidth = 4;
context.strokeRect(-15, -15, 30, 30);
context.restore();
// The face is centered across the front seam. The two eyes sit just
// to either side of that seam and travel with their respective halves.
const faceY = size * (1 - 0.775);
context.fillStyle = darkColor;
context.beginPath();
context.arc(size * 0.034, faceY, 12, 0, Math.PI * 2);
context.arc(size * 0.966, faceY, 12, 0, Math.PI * 2);
context.fill();
context.fillStyle = "rgba(255,255,255,.8)";
context.beginPath();
context.arc(size * 0.034 + 3, faceY - 4, 3, 0, Math.PI * 2);
context.arc(size * 0.966 + 3, faceY - 4, 3, 0, Math.PI * 2);
context.fill();
// Wrapped nose and mouth halves.
context.fillStyle = accentColor;
context.beginPath();
context.arc(0, faceY + 39, 8, 0, Math.PI * 2);
context.arc(size, faceY + 39, 8, 0, Math.PI * 2);
context.fill();
context.strokeStyle = darkColor;
context.lineWidth = 5;
context.lineCap = "round";
context.beginPath();
context.arc(0, faceY + 57, 19, 0.08 * Math.PI, 0.92 * Math.PI);
context.stroke();
context.beginPath();
context.arc(size, faceY + 57, 19, 0.08 * Math.PI, 0.92 * Math.PI);
context.stroke();
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = maxAnisotropy;
texture.wrapS = THREE.ClampToEdgeWrapping;
texture.wrapT = THREE.ClampToEdgeWrapping;
return texture;
}
// ---------------------------------------------------------------------
// Hollow shell profiles
// ---------------------------------------------------------------------
const outerControls = [
[0.00, 0.00],
[0.34, 0.00],
[0.52, 0.09],
[0.59, 0.30],
[0.60, 0.52],
[0.55, 0.76],
[0.46, 1.02],
[0.38, 1.24],
[0.31, 1.44],
[0.40, 1.60],
[0.41, 1.87],
[0.34, 2.09],
[0.23, 2.28],
[0.17, 2.34]
];
const innerControls = [
[0.09, 2.34],
[0.10, 2.25],
[0.22, 2.08],
[0.32, 1.86],
[0.31, 1.62],
[0.21, 1.46],
[0.27, 1.24],
[0.37, 1.02],
[0.46, 0.76],
[0.51, 0.52],
[0.51, 0.31],
[0.44, 0.18],
[0.29, 0.14],
[0.00, 0.14]
];
function sampleProfile(controls, minimumY, maximumY) {
const curve = new THREE.CatmullRomCurve3(
controls.map(([radius, y]) => new THREE.Vector3(radius, y, 0)),
false,
"catmullrom",
0.5
);
return curve.getPoints(72).map((point) => {
return new THREE.Vector2(
THREE.MathUtils.clamp(point.x, 0, 0.72),
THREE.MathUtils.clamp(point.y, minimumY, maximumY)
);
});
}
const outerProfile = sampleProfile(outerControls, 0, 2.34);
const innerProfile = sampleProfile(innerControls, 0.14, 2.34);
function createCutGeometry(profile, angle) {
const polygon = [...profile.outer, ...profile.inner];
const shape = new THREE.Shape();
polygon.forEach((point, index) => {
if (index === 0) {
shape.moveTo(point.x, point.y);
} else {
shape.lineTo(point.x, point.y);
}
});
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
const position = geometry.attributes.position;
const sine = Math.sin(angle);
const cosine = Math.cos(angle);
for (let index = 0; index < position.count; index += 1) {
const radius = position.getX(index);
const y = position.getY(index);
// Match THREE.LatheGeometry's radial convention:
// x = radius * sin(angle), z = radius * cos(angle).
position.setXYZ(
index,
radius * sine,
y,
radius * cosine
);
}
position.needsUpdate = true;
geometry.computeVertexNormals();
return geometry;
}
function createRimGeometry(innerRadius, outerRadius, start, length, segments = 64) {
const positions = [];
const indices = [];
for (let index = 0; index <= segments; index += 1) {
const angle = start + (index / segments) * length;
const sine = Math.sin(angle);
const cosine = Math.cos(angle);
positions.push(
outerRadius * sine, 2.34, outerRadius * cosine,
innerRadius * sine, 2.34, innerRadius * cosine
);
if (index < segments) {
const outer = index * 2;
const inner = outer + 1;
const nextOuter = outer + 2;
const nextInner = outer + 3;
indices.push(outer, nextOuter, inner);
indices.push(inner, nextOuter, nextInner);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// ---------------------------------------------------------------------
// Doll construction
// ---------------------------------------------------------------------
function createDoll(options) {
const root = new THREE.Group();
root.position.y = options.y;
root.scale.setScalar(options.scale);
const paintTexture = createPaintTexture(
options.base,
options.accent,
options.dark,
options.seed
);
const outerMaterial = new THREE.MeshPhysicalMaterial({
map: paintTexture,
roughness: 0.62,
metalness: 0.02,
clearcoat: 0.28,
clearcoatRoughness: 0.42
});
const innerMaterial = new THREE.MeshStandardMaterial({
color: 0xc99462,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide
});
const cutMaterial = new THREE.MeshStandardMaterial({
color: 0xe4b982,
roughness: 0.74,
metalness: 0.02,
side: THREE.DoubleSide
});
const rimMaterial = new THREE.MeshStandardMaterial({
color: options.accent,
roughness: 0.42,
metalness: 0.08,
side: THREE.DoubleSide
});
const profile = {
outer: outerProfile,
inner: innerProfile
};
function createHalf(start, length, direction) {
const half = new THREE.Group();
half.position.x = direction * options.split;
half.rotation.y = direction * options.tilt;
const outerGeometry = new THREE.LatheGeometry(
profile.outer,
64,
start,
length
);
const innerGeometry = new THREE.LatheGeometry(
profile.inner,
64,
start,
length
);
const outerShell = new THREE.Mesh(outerGeometry, outerMaterial);
outerShell.castShadow = true;
outerShell.receiveShadow = true;
half.add(outerShell);
const innerShell = new THREE.Mesh(innerGeometry, innerMaterial);
innerShell.castShadow = true;
innerShell.receiveShadow = true;
half.add(innerShell);
// Visible annular top surface: this is the open shell's wall.
const rim = new THREE.Mesh(
createRimGeometry(0.09, 0.17, start, length),
rimMaterial
);
rim.castShadow = true;
rim.receiveShadow = true;
half.add(rim);
// Two longitudinal cut faces expose the complete wall cross-section.
for (const angle of [start, start + length]) {
const cutFace = new THREE.Mesh(
createCutGeometry(profile, angle),
cutMaterial
);
cutFace.castShadow = true;
cutFace.receiveShadow = true;
half.add(cutFace);
}
return half;
}
// Right and left longitudinal shell halves.
root.add(createHalf(0, Math.PI, 1));
root.add(createHalf(Math.PI, Math.PI, -1));
scene.add(root);
return root;
}
createDoll({
scale: 1.00,
y: 0.02,
split: 0.16,
tilt: 0.085,
base: "#bb4d45",
accent: "#f0cc78",
dark: "#632f31",
seed: 113
});
createDoll({
scale: 0.78,
y: 0.19,
split: 0.11,
tilt: 0.065,
base: "#347f79",
accent: "#f2d486",
dark: "#173f43",
seed: 227
});
createDoll({
scale: 0.58,
y: 0.37,
split: 0.065,
tilt: 0.045,
base: "#d79a3d",
accent: "#fff0b5",
dark: "#6d3d28",
seed: 349
});
// ---------------------------------------------------------------------
// Camera controls implemented directly, without external addons
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.12, 0),
theta: 0.42,
phi: 1.15,
radius: 6.35,
dragging: false,
pointerX: 0,
pointerY: 0,
lastInteraction: performance.now()
};
const defaultView = {
theta: 0.42,
phi: 1.15,
radius: 6.35
};
function updateCamera() {
const sinPhi = Math.sin(controls.phi);
const cosPhi = Math.cos(controls.phi);
camera.position.set(
controls.target.x + controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y + controls.radius * cosPhi,
controls.target.z + controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function resetView() {
controls.theta = defaultView.theta;
controls.phi = defaultView.phi;
controls.radius = defaultView.radius;
controls.lastInteraction = performance.now();
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
controls.dragging = true;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.lastInteraction = performance.now();
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!controls.dragging) return;
const deltaX = event.clientX - controls.pointerX;
const deltaY = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
controls.theta -= deltaX * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - deltaY * 0.005,
0.38,
1.48
);
controls.lastInteraction = performance.now();
});
function releasePointer(event) {
controls.dragging = false;
renderer.domElement.style.cursor = "grab";
if (event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.style.cursor = "grab";
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
4.2,
9.5
);
controls.lastInteraction = performance.now();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
resetButton.addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
controls.theta -= 0.09;
break;
case "ArrowRight":
controls.theta += 0.09;
break;
case "ArrowUp":
controls.phi = Math.max(0.38, controls.phi - 0.07);
break;
case "ArrowDown":
controls.phi = Math.min(1.48, controls.phi + 0.07);
break;
case "+":
case "=":
controls.radius = Math.max(4.2, controls.radius - 0.25);
break;
case "-":
controls.radius = Math.min(9.5, controls.radius + 0.25);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
controls.lastInteraction = performance.now();
}
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateCamera();
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const now = performance.now();
// Very slow automatic turntable after the viewer stops interacting.
if (!controls.dragging && now - controls.lastInteraction > 2600) {
controls.theta += delta * 0.025;
}
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```