Prompt specification
Build or customize the Three.js 3D scene "Pleated dumpling seam study" 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: Pleated dumpling seam study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/pleated-dumpling-seam-study-x0097
Scene Description Prompt:
A voxel dumpling with a raised pleated seam beside its unfolded wrapper. Three.js from cdnjs, one HTML file.
Working Three.js Starter (pleated-dumpling-seam-study-x0097):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#d8d0c3">
<title>Pleated — Voxel Dumpling</title>
<style>
:root {
color-scheme: light;
--ink: #373229;
--muted: #756d61;
--paper: #f4ead7;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d0c3;
}
body {
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(
ellipse at 50% 45%,
transparent 42%,
rgba(67, 56, 40, 0.08) 100%
);
}
.hud {
position: fixed;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 54px);
pointer-events: none;
user-select: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.eyebrow::before {
width: 20px;
height: 2px;
content: "";
background: var(--muted);
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(36px, 5vw, 68px);
font-weight: 400;
line-height: 0.9;
letter-spacing: -0.045em;
}
.subtitle {
margin: 12px 0 0;
color: var(--muted);
font-size: 11px;
font-weight: 600;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.help {
position: fixed;
right: clamp(20px, 3vw, 42px);
bottom: clamp(20px, 3vw, 38px);
display: flex;
align-items: center;
gap: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
user-select: none;
}
.keys {
display: flex;
gap: 6px;
}
.key {
padding: 6px 8px;
border: 1px solid rgba(55, 50, 41, 0.2);
border-radius: 4px;
background: rgba(244, 234, 215, 0.35);
backdrop-filter: blur(8px);
}
#reset {
position: fixed;
right: clamp(20px, 3vw, 42px);
top: clamp(20px, 3vw, 38px);
width: 42px;
height: 42px;
padding: 0;
border: 1px solid rgba(55, 50, 41, 0.22);
border-radius: 50%;
color: var(--ink);
background: rgba(244, 234, 215, 0.4);
font: inherit;
font-size: 21px;
line-height: 1;
cursor: pointer;
backdrop-filter: blur(8px);
transition:
background 160ms ease,
transform 160ms ease;
}
#reset:hover {
background: rgba(244, 234, 215, 0.75);
transform: rotate(-18deg);
}
#reset:focus-visible {
outline: 2px solid var(--ink);
outline-offset: 3px;
}
@media (max-width: 640px) {
.subtitle {
max-width: 180px;
line-height: 1.5;
}
.help {
left: 22px;
right: auto;
}
.help .key:first-child {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive voxel dumpling scene"></main>
<div class="vignette" aria-hidden="true"></div>
<header class="hud">
<div class="eyebrow">Form study / 01</div>
<h1>Pleated</h1>
<p class="subtitle">Voxel dumpling with unfolded wrapper</p>
</header>
<button id="reset" type="button" aria-label="Reset camera" title="Reset camera">
↺
</button>
<div class="help" aria-hidden="true">
<div class="keys">
<span class="key">Drag</span>
<span class="key">Shift + drag</span>
</div>
<span>Orbit · pan · scroll to zoom</span>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d0c3);
scene.fog = new THREE.Fog(0xd8d0c3, 22, 46);
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;
renderer.domElement.setAttribute(
"aria-label",
"A voxel dumpling beside its unfolded wrapper. Drag to orbit."
);
stage.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(
-7,
7,
4,
-4,
0.1,
100
);
const worldWidth = 12.8;
const minimumViewHeight = 7.5;
const cameraRadius = 18;
const defaultTarget = new THREE.Vector3(0.55, 1.55, 0);
const target = defaultTarget.clone();
let currentYaw = 0.72;
let currentPitch = 0.57;
let currentZoom = 1;
let desiredYaw = currentYaw;
let desiredPitch = currentPitch;
let desiredZoom = currentZoom;
const clamp = THREE.MathUtils.clamp;
function updateCamera() {
const horizontal = Math.cos(currentPitch) * cameraRadius;
camera.position.set(
target.x + Math.sin(currentYaw) * horizontal,
target.y + Math.sin(currentPitch) * cameraRadius,
target.z + Math.cos(currentYaw) * horizontal
);
camera.zoom = currentZoom;
camera.lookAt(target);
camera.updateProjectionMatrix();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const viewHeight = Math.max(
minimumViewHeight,
worldWidth / aspect
);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", resize);
// Lighting
scene.add(new THREE.HemisphereLight(0xfff4dd, 0x766d61, 1.9));
const keyLight = new THREE.DirectionalLight(0xfff0d2, 3.25);
keyLight.position.set(-5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.bias = -0.00015;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9dcff, 1.1);
fillLight.position.set(8, 6, -8);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffd9a0, 0.7);
rimLight.position.set(-8, 4, -5);
scene.add(rimLight);
// Ground
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xd1c8ba,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.006;
ground.receiveShadow = true;
scene.add(ground);
function makeSoftShadowTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
128,
18,
128,
128,
128
);
gradient.addColorStop(0, "rgba(45, 38, 29, 0.38)");
gradient.addColorStop(0.45, "rgba(45, 38, 29, 0.18)");
gradient.addColorStop(1, "rgba(45, 38, 29, 0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
const texture = new THREE.CanvasTexture(canvas);
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
const softShadowTexture = makeSoftShadowTexture();
function addSoftShadow(x, z, width, depth, opacity) {
const shadow = new THREE.Mesh(
new THREE.PlaneGeometry(width, depth),
new THREE.MeshBasicMaterial({
map: softShadowTexture,
transparent: true,
opacity,
depthWrite: false
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.set(x, 0.003, z);
shadow.renderOrder = 1;
scene.add(shadow);
}
addSoftShadow(-1.55, 0, 7.5, 5.2, 0.48);
addSoftShadow(4.25, 0.65, 4.7, 4.7, 0.27);
// Voxel dumpling body
const bodyCenterX = -1.55;
const voxelStep = 0.42;
const voxelSize = 0.385;
const bodyPositions = [];
const bodyColors = [];
const bodyTopMap = new Map();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.82,
metalness: 0
});
function hash3(x, y, z) {
const value = Math.sin(
x * 12.9898 + y * 78.233 + z * 37.719
) * 43758.5453;
return value - Math.floor(value);
}
for (let ix = -7; ix <= 7; ix++) {
for (let iz = -5; iz <= 5; iz++) {
for (let iy = 0; iy <= 10; iy++) {
const x = ix * voxelStep;
const z = iz * voxelStep;
const y = 0.21 + iy * voxelStep;
const nx = x / 3.25;
const nz = z / 2.12;
const ny = (y - 2.0) / 2.34;
if (nx * nx + nz * nz + ny * ny > 1) {
continue;
}
const px = bodyCenterX + x;
const py = y;
const pz = z;
bodyPositions.push([px, py, pz]);
const random = hash3(ix, iy, iz);
const heightLight = clamp(y / 4.4, 0, 1);
const lightness = clamp(
0.735 +
random * 0.105 +
heightLight * 0.055 -
(1 - heightLight) * 0.035,
0.69,
0.9
);
const color = new THREE.Color().setHSL(
0.105 + (random - 0.5) * 0.014,
0.4 + random * 0.08,
lightness
);
bodyColors.push(color);
const top = py + voxelSize / 2;
const key = `${ix},${iz}`;
if (!bodyTopMap.has(key) || bodyTopMap.get(key) < top) {
bodyTopMap.set(key, top);
}
}
}
}
const bodyGeometry = new THREE.BoxGeometry(1, 1, 1);
const body = new THREE.InstancedMesh(
bodyGeometry,
bodyMaterial,
bodyPositions.length
);
body.castShadow = true;
body.receiveShadow = true;
body.instanceMatrix.setUsage(THREE.StaticDrawUsage);
const dummy = new THREE.Object3D();
bodyPositions.forEach((position, index) => {
dummy.position.set(...position);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(voxelSize, voxelSize, voxelSize);
dummy.updateMatrix();
body.setMatrixAt(index, dummy.matrix);
body.setColorAt(index, bodyColors[index]);
});
body.instanceMatrix.needsUpdate = true;
body.instanceColor.needsUpdate = true;
scene.add(body);
// Raised seam
const seamMatrices = [];
const seamColors = [];
for (let ix = -7; ix <= 7; ix++) {
const top = bodyTopMap.get(`${ix},0`);
if (top === undefined) {
continue;
}
const crimp = hash3(ix, 19, 3);
const height = 0.24 + crimp * 0.075;
seamMatrices.push({
x: bodyCenterX + ix * voxelStep,
y: top + height * 0.46,
z: 0,
sx: 0.35,
sy: height,
sz: 0.39
});
seamColors.push(
new THREE.Color().setHSL(
0.105,
0.48,
0.84 + crimp * 0.07
)
);
}
const seam = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.76,
metalness: 0
}),
seamMatrices.length
);
seam.castShadow = true;
seam.receiveShadow = true;
seamMatrices.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(item.sx, item.sy, item.sz);
dummy.updateMatrix();
seam.setMatrixAt(index, dummy.matrix);
seam.setColorAt(index, seamColors[index]);
});
seam.instanceMatrix.needsUpdate = true;
seam.instanceColor.needsUpdate = true;
scene.add(seam);
// Stepped pleats fanning down both sides of the seam
const pleatMatrices = [];
const pleatColors = [];
for (let ix = -6; ix <= 6; ix += 2) {
for (const side of [-1, 1]) {
for (let step = 1; step <= 4; step++) {
const xShift =
side === 1
? -Math.floor(step / 2)
: Math.floor(step / 2);
const px = ix + xShift;
const pz = side * step;
const top = bodyTopMap.get(`${px},${pz}`);
if (top === undefined) {
continue;
}
const random = hash3(px, pz, 41);
pleatMatrices.push({
x: bodyCenterX + px * voxelStep,
y: top + 0.066,
z: pz * voxelStep,
scale: 0.31 + random * 0.025
});
pleatColors.push(
new THREE.Color().setHSL(
0.105,
0.43,
0.82 + random * 0.06
)
);
}
}
}
const pleats = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.79,
metalness: 0
}),
pleatMatrices.length
);
pleats.castShadow = true;
pleats.receiveShadow = true;
pleatMatrices.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(item.scale, 0.145, item.scale);
dummy.updateMatrix();
pleats.setMatrixAt(index, dummy.matrix);
pleats.setColorAt(index, pleatColors[index]);
});
pleats.instanceMatrix.needsUpdate = true;
pleats.instanceColor.needsUpdate = true;
scene.add(pleats);
// Unfolded wrapper: a low, pixel-edged circular dough sheet
const wrapper = new THREE.Group();
wrapper.position.set(4.25, 0, 0.65);
wrapper.rotation.y = -0.12;
scene.add(wrapper);
const wrapperTileSize = 0.385;
const wrapperStep = 0.405;
const wrapperMatrices = [];
const wrapperColors = [];
for (let ix = -5; ix <= 5; ix++) {
for (let iz = -5; iz <= 5; iz++) {
const x = ix * wrapperStep;
const z = iz * wrapperStep;
if (Math.hypot(x, z) > 2.02) {
continue;
}
const random = hash3(ix, iz, 71);
const radius = Math.hypot(x, z) / 2.02;
wrapperMatrices.push({
x,
y: 0.045 + Math.sin(radius * Math.PI) * 0.018,
z,
rotation: (random - 0.5) * 0.012
});
wrapperColors.push(
new THREE.Color().setHSL(
0.105,
0.34,
0.84 + random * 0.055
)
);
}
}
const wrapperSheet = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.94,
metalness: 0
}),
wrapperMatrices.length
);
wrapperSheet.castShadow = true;
wrapperSheet.receiveShadow = true;
wrapperMatrices.forEach((item, index) => {
dummy.position.set(item.x, item.y, item.z);
dummy.rotation.set(0, item.rotation, 0);
dummy.scale.set(
wrapperTileSize,
0.08,
wrapperTileSize
);
dummy.updateMatrix();
wrapperSheet.setMatrixAt(index, dummy.matrix);
wrapperSheet.setColorAt(index, wrapperColors[index]);
});
wrapperSheet.instanceMatrix.needsUpdate = true;
wrapperSheet.instanceColor.needsUpdate = true;
wrapper.add(wrapperSheet);
// Subtle radial fold guides made from tiny rectangular marks
const guideMatrices = [];
for (let ray = 0; ray < 8; ray++) {
const angle = (ray / 8) * Math.PI * 2;
for (let radius = 0.48; radius <= 1.58; radius += 0.27) {
guideMatrices.push({
x: Math.cos(angle) * radius,
z: Math.sin(angle) * radius,
angle
});
}
}
const guides = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshBasicMaterial({
color: 0xa99778,
transparent: true,
opacity: 0.25,
depthWrite: false
}),
guideMatrices.length
);
guideMatrices.forEach((item, index) => {
dummy.position.set(item.x, 0.091, item.z);
dummy.rotation.set(0, -item.angle, 0);
dummy.scale.set(0.13, 0.012, 0.022);
dummy.updateMatrix();
guides.setMatrixAt(index, dummy.matrix);
});
guides.instanceMatrix.needsUpdate = true;
wrapper.add(guides);
// Custom camera controls
const canvas = renderer.domElement;
const pointers = new Map();
let drag = null;
let pinch = null;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) {
return 0;
}
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
event.preventDefault();
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
} else if (pointers.size === 2) {
drag = null;
pinch = {
distance: pointerDistance(),
zoom: desiredZoom
};
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) {
return;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size >= 2 && pinch) {
const distance = pointerDistance();
if (distance > 0) {
desiredZoom = clamp(
pinch.zoom * (pinch.distance / distance),
0.65,
1.8
);
}
return;
}
if (!drag || drag.id !== event.pointerId) {
return;
}
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const worldPerPixel =
(camera.top - camera.bottom) /
(canvas.clientHeight * currentZoom);
const right = new THREE.Vector3(
Math.cos(currentYaw),
0,
-Math.sin(currentYaw)
);
target.addScaledVector(right, -dx * worldPerPixel);
target.y += dy * worldPerPixel * 0.7;
} else {
desiredYaw -= dx * 0.006;
desiredPitch = clamp(
desiredPitch + dy * 0.005,
0.3,
1.12
);
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (drag && drag.id === event.pointerId) {
drag = null;
}
if (pointers.size < 2) {
pinch = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desiredZoom = clamp(
desiredZoom * Math.exp(-event.deltaY * 0.001),
0.65,
1.8
);
},
{ passive: false }
);
function resetCamera() {
desiredYaw = 0.72;
desiredPitch = 0.57;
desiredZoom = 1;
target.copy(defaultTarget);
}
resetButton.addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.key === "ArrowLeft") {
desiredYaw -= 0.12;
}
if (event.key === "ArrowRight") {
desiredYaw += 0.12;
}
if (event.key === "ArrowUp") {
desiredPitch = clamp(desiredPitch + 0.08, 0.3, 1.12);
}
if (event.key === "ArrowDown") {
desiredPitch = clamp(desiredPitch - 0.08, 0.3, 1.12);
}
if (event.key === "+" || event.key === "=") {
desiredZoom = clamp(desiredZoom + 0.08, 0.65, 1.8);
}
if (event.key === "-" || event.key === "_") {
desiredZoom = clamp(desiredZoom - 0.08, 0.65, 1.8);
}
});
// Render loop
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-delta * 10);
currentYaw += (desiredYaw - currentYaw) * smoothing;
currentPitch += (desiredPitch - currentPitch) * smoothing;
currentZoom += (desiredZoom - currentZoom) * smoothing;
updateCamera();
renderer.render(scene, camera);
}
resize();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```