Prompt specification
Build or customize the Three.js 3D scene "Windy seaside drying yard" 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: Windy seaside drying yard
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/windy-seaside-drying-yard-x0003
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring a wooden clothespin. Build a laundry yard with towels, fence, baskets, and grass; vary wind strength so fabric motion changes while every clipped corner remains attached. Stylized solid forms.
Working Three.js Starter (windy-seaside-drying-yard-x0003):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sunny Laundry Yard</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-rounded, "Trebuchet MS", system-ui, sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfe3ea;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
color: #24413b;
}
.title {
position: absolute;
top: 24px;
left: 28px;
padding: 14px 17px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 18px;
background: rgba(255, 252, 235, 0.74);
box-shadow: 0 12px 30px rgba(39, 72, 64, 0.13);
backdrop-filter: blur(10px);
}
.title h1 {
margin: 0 0 3px;
font-size: clamp(17px, 2vw, 24px);
letter-spacing: 0.025em;
}
.title p {
margin: 0;
font-size: 12px;
opacity: 0.7;
}
.wind {
position: absolute;
right: 26px;
bottom: 24px;
width: 190px;
padding: 13px 15px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 16px;
background: rgba(255, 252, 235, 0.76);
box-shadow: 0 12px 30px rgba(39, 72, 64, 0.13);
backdrop-filter: blur(10px);
}
.wind-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
font-size: 12px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.wind-track {
height: 7px;
overflow: hidden;
border-radius: 999px;
background: rgba(50, 91, 82, 0.13);
}
.wind-fill {
width: 100%;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, #77c9bd, #f1bc54, #e8785d);
transform: scaleX(0.4);
transform-origin: left;
}
.hint {
position: absolute;
left: 28px;
bottom: 25px;
padding: 9px 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.6);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.035em;
opacity: 0.8;
}
@media (max-width: 600px) {
.title {
top: 14px;
left: 14px;
}
.wind {
right: 14px;
bottom: 14px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div class="hud">
<div class="title">
<h1>Sunny Laundry Yard</h1>
<p>Solid-form towels, wooden pegs, and a lively breeze.</p>
</div>
<div class="wind">
<div class="wind-row">
<span>Wind</span>
<span id="windValue">40%</span>
</div>
<div class="wind-track">
<div id="windFill" class="wind-fill"></div>
</div>
</div>
<div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</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, scene, lighting
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfe3ea);
scene.fog = new THREE.Fog(0xbfe3ea, 17, 39);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional laundry yard"
);
document.body.prepend(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe7f7ff, 0x637342, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff2cc, 3.15);
sun.position.set(-6, 11, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -6;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.normalBias = 0.035;
sun.shadow.bias = -0.00015;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x8fcbd0, 0.65);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0,
...options
});
// -------------------------------------------------------------------------
// Small geometry helpers
// -------------------------------------------------------------------------
function mesh(geometry, material, parent = scene) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = true;
object.receiveShadow = true;
parent.add(object);
return object;
}
function seededRandom(seed) {
let state = seed >>> 0;
return () => {
state =
(1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
const random = seededRandom(1847);
// -------------------------------------------------------------------------
// Ground and lawn patches
// -------------------------------------------------------------------------
const lawn = mesh(
new THREE.PlaneGeometry(48, 48),
standard(0x7da653)
);
lawn.rotation.x = -Math.PI / 2;
lawn.position.y = -0.025;
lawn.castShadow = false;
const patchMaterial = standard(0x6f9748);
[
[-4.5, 2.2, 3.1, 1.7, -0.3],
[5.8, -1.8, 4.0, 2.4, 0.45],
[-0.5, -4.7, 5.0, 2.0, -0.1]
].forEach(([x, z, rx, rz, rot]) => {
const patch = mesh(
new THREE.CircleGeometry(1, 40),
patchMaterial
);
patch.scale.set(rx, rz, 1);
patch.rotation.x = -Math.PI / 2;
patch.rotation.z = rot;
patch.position.set(x, 0.004, z);
patch.castShadow = false;
});
// A few warm stepping stones near the baskets.
const stoneMaterial = standard(0xd8c79f);
[
[-1.4, 4.3],
[0.25, 3.7],
[1.75, 3.0],
[3.05, 2.6]
].forEach(([x, z], index) => {
const stone = mesh(
new THREE.CylinderGeometry(0.46, 0.49, 0.1, 14),
stoneMaterial
);
stone.position.set(x, 0.045, z);
stone.scale.z = 0.78 + index * 0.025;
stone.rotation.y = random() * Math.PI;
});
// -------------------------------------------------------------------------
// Grass blades and tiny flowers
// -------------------------------------------------------------------------
const bladeGeometry = new THREE.ConeGeometry(0.04, 0.3, 3);
bladeGeometry.translate(0, 0.15, 0);
const grassMaterial = standard(0x4e823d, {
flatShading: true
});
const grassCount = 620;
const grass = new THREE.InstancedMesh(
bladeGeometry,
grassMaterial,
grassCount
);
grass.receiveShadow = true;
grass.castShadow = false;
const dummy = new THREE.Object3D();
const grassColor = new THREE.Color();
for (let i = 0; i < grassCount; i++) {
const x = -11 + random() * 22;
const z = -4.5 + random() * 11.5;
const scale = 0.55 + random() * 1.25;
dummy.position.set(x, 0, z);
dummy.rotation.set(
(random() - 0.5) * 0.18,
random() * Math.PI * 2,
(random() - 0.5) * 0.22
);
dummy.scale.set(
0.75 + random() * 0.45,
scale,
0.75 + random() * 0.45
);
dummy.updateMatrix();
grass.setMatrixAt(i, dummy.matrix);
grassColor.setHSL(
0.25 + random() * 0.035,
0.38 + random() * 0.18,
0.30 + random() * 0.13
);
grass.setColorAt(i, grassColor);
}
grass.instanceMatrix.needsUpdate = true;
if (grass.instanceColor) grass.instanceColor.needsUpdate = true;
scene.add(grass);
const flowerGeometry = new THREE.IcosahedronGeometry(0.055, 0);
const flowerMaterial = standard(0xffffff, {
flatShading: true
});
const flowers = new THREE.InstancedMesh(
flowerGeometry,
flowerMaterial,
38
);
const flowerColor = new THREE.Color();
for (let i = 0; i < 38; i++) {
dummy.position.set(
-8 + random() * 16,
0.18 + random() * 0.1,
-3.4 + random() * 8
);
dummy.rotation.set(random(), random(), random());
dummy.scale.setScalar(0.7 + random() * 0.9);
dummy.updateMatrix();
flowers.setMatrixAt(i, dummy.matrix);
flowerColor.set(
i % 3 === 0 ? 0xf4c95d :
i % 3 === 1 ? 0xf1e6df :
0xe9a0ad
);
flowers.setColorAt(i, flowerColor);
}
flowers.instanceMatrix.needsUpdate = true;
if (flowers.instanceColor) flowers.instanceColor.needsUpdate = true;
scene.add(flowers);
// -------------------------------------------------------------------------
// Fence
// -------------------------------------------------------------------------
const fence = new THREE.Group();
scene.add(fence);
const fenceMaterial = standard(0xd8b47a);
const fenceAccent = standard(0xc69b61);
for (let x = -9.1; x <= 9.1; x += 0.78) {
const height = 2.05 + (random() - 0.5) * 0.08;
const plank = mesh(
new THREE.BoxGeometry(0.18, height, 0.13),
fenceMaterial,
fence
);
plank.position.set(x, height / 2, -5.55);
const cap = mesh(
new THREE.ConeGeometry(0.135, 0.29, 4),
fenceAccent,
fence
);
cap.position.set(x, height + 0.12, -5.55);
cap.rotation.y = Math.PI / 4;
}
[0.62, 1.47].forEach((y) => {
const rail = mesh(
new THREE.BoxGeometry(18.8, 0.14, 0.12),
fenceAccent,
fence
);
rail.position.set(0, y, -5.68);
});
[-8.4, 0, 8.4].forEach((x) => {
const post = mesh(
new THREE.BoxGeometry(0.32, 2.7, 0.3),
fenceAccent,
fence
);
post.position.set(x, 1.25, -5.55);
const cap = mesh(
new THREE.ConeGeometry(0.25, 0.35, 4),
fenceMaterial,
fence
);
cap.position.set(x, 2.72, -5.55);
cap.rotation.y = Math.PI / 4;
});
// -------------------------------------------------------------------------
// Trees, shrubs, and clouds
// -------------------------------------------------------------------------
function makeTree(x, z, scale, crownColor) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
scene.add(tree);
const trunk = mesh(
new THREE.CylinderGeometry(0.18, 0.27, 2.4, 8),
standard(0x88613f),
tree
);
trunk.position.y = 1.2;
const crownMaterial = standard(crownColor, {
flatShading: true
});
const crownPositions = [
[0, 3.0, 0, 1.05],
[-0.62, 2.72, 0.05, 0.76],
[0.58, 2.78, 0.08, 0.82],
[0.08, 3.48, -0.05, 0.76]
];
crownPositions.forEach(([cx, cy, cz, s]) => {
const crown = mesh(
new THREE.IcosahedronGeometry(s, 1),
crownMaterial,
tree
);
crown.position.set(cx, cy, cz);
crown.rotation.set(random(), random(), random());
});
}
makeTree(-7.4, -7.4, 1.15, 0x789b50);
makeTree(5.8, -7.8, 1.3, 0x6f9148);
makeTree(10.1, -8.5, 0.95, 0x8ba858);
const bushMaterial = standard(0x789b50, {
flatShading: true
});
[
[-10.2, -4.8, 0.85],
[-3.8, -5.0, 0.7],
[2.5, -5.2, 0.75],
[9.0, -4.9, 0.95]
].forEach(([x, z, s]) => {
const bush = mesh(
new THREE.IcosahedronGeometry(0.75, 1),
bushMaterial
);
bush.position.set(x, 0.55, z);
bush.scale.set(s * 1.25, s, s);
bush.rotation.y = random() * Math.PI;
});
const cloudMaterial = standard(0xf7fbf4, {
flatShading: true
});
function makeCloud(x, y, z, scale) {
const cloud = new THREE.Group();
cloud.position.set(x, y, z);
cloud.scale.setScalar(scale);
scene.add(cloud);
[
[-0.9, 0, 0, 0.8],
[-0.25, 0.2, 0, 1.05],
[0.55, 0.06, 0, 0.9],
[1.15, -0.06, 0, 0.62]
].forEach(([cx, cy, cz, s]) => {
const puff = mesh(
new THREE.IcosahedronGeometry(s, 2),
cloudMaterial,
cloud
);
puff.position.set(cx, cy, cz);
puff.castShadow = false;
});
}
makeCloud(-5.8, 7.3, -13.5, 1.3);
makeCloud(4.8, 8.0, -15.5, 1.6);
makeCloud(10.0, 6.7, -12.0, 0.9);
// -------------------------------------------------------------------------
// Clothesline
// -------------------------------------------------------------------------
const LINE_Z = -0.8;
const ROPE_HALF_LENGTH = 7.2;
function lineHeight(x) {
// Gently sagging line: lower in the middle, higher at the poles.
return 3.7 + 0.018 * x * x;
}
class RopeCurve extends THREE.Curve {
getPoint(t, target = new THREE.Vector3()) {
const x = -ROPE_HALF_LENGTH + t * ROPE_HALF_LENGTH * 2;
return target.set(x, lineHeight(x), LINE_Z);
}
}
const rope = mesh(
new THREE.TubeGeometry(new RopeCurve(), 100, 0.032, 7, false),
standard(0x4d493e)
);
const poleMaterial = standard(0x8b633e);
const poleTopMaterial = standard(0xa97949);
[-ROPE_HALF_LENGTH, ROPE_HALF_LENGTH].forEach((x) => {
const pole = mesh(
new THREE.CylinderGeometry(0.105, 0.15, 4.7, 10),
poleMaterial
);
pole.position.set(x, 2.35, LINE_Z);
const cap = mesh(
new THREE.SphereGeometry(0.15, 12, 8),
poleTopMaterial
);
cap.position.set(x, 4.7, LINE_Z);
});
// -------------------------------------------------------------------------
// Wooden clothespin
// -------------------------------------------------------------------------
function makeClothespin(scale = 1, hero = false) {
const pin = new THREE.Group();
const woodA = standard(
hero ? 0xe1a85b : 0xc98a48,
{ roughness: 0.76 }
);
const woodB = standard(
hero ? 0xefbd73 : 0xdba15e,
{ roughness: 0.76 }
);
const grain = standard(
hero ? 0x995b2e : 0x7e4d29,
{ roughness: 0.9 }
);
const metal = standard(0x58656a, {
roughness: 0.42,
metalness: 0.55
});
function armGeometry(points) {
const shape = new THREE.Shape();
shape.moveTo(points[0][0], points[0][1]);
for (let i = 1; i < points.length; i++) {
shape.lineTo(points[i][0], points[i][1]);
}
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.18,
bevelEnabled: true,
bevelSegments: 2,
steps: 1,
bevelSize: 0.025,
bevelThickness: 0.025
});
geometry.translate(0, 0, -0.09);
return geometry;
}
const leftArm = mesh(
armGeometry([
[-0.04, 0.72],
[-0.29, 0.55],
[-0.20, -0.68],
[-0.03, -0.76],
[0.02, -0.16],
[0.03, 0.51]
]),
woodA,
pin
);
const rightArm = mesh(
armGeometry([
[0.04, 0.72],
[0.29, 0.55],
[0.20, -0.68],
[0.03, -0.76],
[-0.02, -0.16],
[-0.03, 0.51]
]),
woodB,
pin
);
leftArm.castShadow = true;
rightArm.castShadow = true;
// Simple carved wood-grain marks.
const leftGrain = mesh(
new THREE.BoxGeometry(0.025, 0.62, 0.012),
grain,
pin
);
leftGrain.position.set(-0.115, -0.06, 0.108);
leftGrain.rotation.z = -0.075;
const rightGrain = mesh(
new THREE.BoxGeometry(0.025, 0.58, 0.012),
grain,
pin
);
rightGrain.position.set(0.115, -0.06, 0.108);
rightGrain.rotation.z = 0.075;
// Metal pivot and spring.
const pivot = mesh(
new THREE.CylinderGeometry(0.052, 0.052, 0.26, 12),
metal,
pin
);
pivot.rotation.x = Math.PI / 2;
pivot.position.set(0, -0.08, 0.12);
const spring = mesh(
new THREE.TorusGeometry(0.13, 0.024, 7, 24),
metal,
pin
);
spring.position.set(0, -0.08, 0.13);
pin.scale.setScalar(scale);
return pin;
}
// -------------------------------------------------------------------------
// Towels
//
// Each towel is a custom subdivided surface. Its two upper corners are
// hard-pinned to the exact rope positions. The deformation falloff is zero
// at those points, so clipped corners never drift away from their pegs.
// -------------------------------------------------------------------------
const towels = [];
function createTowel({
x,
width,
height,
color,
accent,
phase,
heroPin = false
}) {
const segmentsX = 24;
const segmentsY = 28;
const positions = [];
const uvs = [];
const colors = [];
const indices = [];
const baseColor = new THREE.Color(color);
const accentColor = new THREE.Color(accent);
for (let iy = 0; iy <= segmentsY; iy++) {
const v = iy / segmentsY;
for (let ix = 0; ix <= segmentsX; ix++) {
const u = ix / segmentsX;
const localX = (u - 0.5) * width;
// The top edge follows the exact slope of the sagging rope.
const topY =
lineHeight(x + localX) - lineHeight(x);
positions.push(localX, topY - v * height, 0);
uvs.push(u, v);
let vertexColor = baseColor.clone();
if (
v < 0.055 ||
(v > 0.83 && v < 0.90) ||
(v > 0.955)
) {
vertexColor = accentColor.clone();
}
colors.push(
vertexColor.r,
vertexColor.g,
vertexColor.b
);
}
}
for (let iy = 0; iy < segmentsY; iy++) {
for (let ix = 0; ix < segmentsX; ix++) {
const a = iy * (segmentsX + 1) + ix;
const b = a + 1;
const c = a + segmentsX + 1;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
side: THREE.DoubleSide,
roughness: 1,
metalness: 0
});
const towel = mesh(geometry, material);
towel.position.set(x, lineHeight(x), LINE_Z - 0.12);
towel.frustumCulled = false;
const pinnedUVs = [
{ u: 0, v: 0 },
{ u: 1, v: 0 }
];
const pinnedIndices = [
0,
segmentsX
];
towels.push({
mesh: towel,
geometry,
basePositions: new Float32Array(positions),
pinnedUVs,
pinnedIndices,
phase
});
// Place a clothespin at each clipped top corner.
const leftX = x - width / 2;
const rightX = x + width / 2;
const leftPin = makeClothespin(heroPin ? 0.92 : 0.66, false);
leftPin.position.set(
leftX,
lineHeight(leftX) - 0.66,
LINE_Z + 0.01
);
scene.add(leftPin);
const rightPin = makeClothespin(heroPin ? 1.04 : 0.66, heroPin);
rightPin.position.set(
rightX,
lineHeight(rightX) - 0.66,
LINE_Z + 0.01
);
scene.add(rightPin);
}
createTowel({
x: -3.15,
width: 2.35,
height: 2.42,
color: 0xe66f5c,
accent: 0xffe3bd,
phase: 0.2
});
createTowel({
x: 0.05,
width: 2.62,
height: 2.72,
color: 0x49a6a0,
accent: 0xf7e6bd,
phase: 1.7,
heroPin: true
});
createTowel({
x: 3.15,
width: 2.22,
height: 2.3,
color: 0xe8b84e,
accent: 0xf8edd0,
phase: 3.4
});
// -------------------------------------------------------------------------
// Laundry baskets
// -------------------------------------------------------------------------
function makeBasket(x, z, scale, basketColor) {
const basket = new THREE.Group();
basket.position.set(x, 0, z);
basket.scale.setScalar(scale);
scene.add(basket);
const material = standard(basketColor, {
side: THREE.DoubleSide
});
const rimMaterial = standard(
new THREE.Color(basketColor).multiplyScalar(0.86)
);
const body = mesh(
new THREE.CylinderGeometry(0.78, 0.62, 0.86, 24, 1, true),
material,
basket
);
body.position.y = 0.53;
const bottom = mesh(
new THREE.CylinderGeometry(0.62, 0.62, 0.08, 24),
rimMaterial,
basket
);
bottom.position.y = 0.12;
// Horizontal woven rings.
for (let i = 0; i < 5; i++) {
const t = i / 4;
const radius = 0.64 + t * 0.13;
const ring = mesh(
new THREE.TorusGeometry(radius, 0.034, 6, 30),
rimMaterial,
basket
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.17 + t * 0.68;
}
// Vertical ribs.
const yAxis = new THREE.Vector3(0, 1, 0);
for (let i = 0; i < 16; i++) {
const angle = (i / 16) * Math.PI * 2;
const bottomPoint = new THREE.Vector3(
Math.cos(angle) * 0.635,
0.16,
Math.sin(angle) * 0.635
);
const topPoint = new THREE.Vector3(
Math.cos(angle) * 0.775,
0.92,
Math.sin(angle) * 0.775
);
const direction = topPoint.clone().sub(bottomPoint);
const length = direction.length();
const midpoint = bottomPoint.clone().add(topPoint).multiplyScalar(0.5);
const rib = mesh(
new THREE.CylinderGeometry(0.021, 0.021, length, 6),
rimMaterial,
basket
);
rib.position.copy(midpoint);
rib.quaternion.setFromUnitVectors(
yAxis,
direction.normalize()
);
}
// Side handles.
[-1, 1].forEach((side) => {
const handle = mesh(
new THREE.TorusGeometry(0.29, 0.045, 8, 24),
rimMaterial,
basket
);
handle.rotation.y = Math.PI / 2;
handle.position.set(side * 0.73, 0.77, 0);
});
// Soft, solid laundry bundles.
const laundryColors = [
0xef816d,
0x68b6ad,
0xf0c35d,
0xf3e4c0
];
const bundleGeometry = new THREE.IcosahedronGeometry(0.42, 2);
for (let i = 0; i < 5; i++) {
const bundle = mesh(
bundleGeometry,
standard(laundryColors[i], {
flatShading: true
}),
basket
);
const angle = (i / 5) * Math.PI * 2;
bundle.position.set(
Math.cos(angle) * 0.31,
0.88 + (i % 2) * 0.12,
Math.sin(angle) * 0.31
);
bundle.scale.set(
1.0 + random() * 0.35,
0.65 + random() * 0.25,
0.85 + random() * 0.25
);
bundle.rotation.set(random(), random(), random());
}
const folded = mesh(
new THREE.BoxGeometry(0.8, 0.28, 0.52),
standard(0xf2dfb9),
basket
);
folded.position.set(0.08, 1.17, -0.02);
folded.rotation.y = -0.22;
}
makeBasket(4.85, 2.25, 1.15, 0xc9754d);
makeBasket(-5.65, 1.85, 0.86, 0xe0b66c);
// -------------------------------------------------------------------------
// Cloth animation
// -------------------------------------------------------------------------
let windStrength = 0.4;
function updateTowel(towel, time) {
const positionAttribute = towel.geometry.attributes.position;
const positionArray = positionAttribute.array;
const uvArray = towel.geometry.attributes.uv.array;
const base = towel.basePositions;
const amplitude = 0.055 + windStrength * 0.43;
const speed = 2.0 + windStrength * 3.1;
for (let i = 0; i < positionArray.length / 3; i++) {
const u = uvArray[i * 2];
const v = uvArray[i * 2 + 1];
// Minimum distance to a hard-pinned corner.
let pinDistance = Infinity;
for (const pin of towel.pinnedUVs) {
const dx = u - pin.u;
const dy = v - pin.v;
pinDistance = Math.min(
pinDistance,
Math.sqrt(dx * dx + dy * dy)
);
}
// Smooth falloff: exactly zero at each clipped corner.
const normalizedDistance = Math.min(1, pinDistance / 0.28);
const falloff =
normalizedDistance *
normalizedDistance *
(3 - 2 * normalizedDistance);
const waveA = Math.sin(
u * 10.5 -
time * speed +
towel.phase +
v * 2.1
);
const waveB = Math.sin(
v * 8.2 +
u * 4.0 -
time * (speed * 1.25) +
towel.phase * 1.7
);
const billow =
Math.sin(Math.PI * u) *
Math.sin(Math.PI * v);
const z =
base[i * 3 + 2] +
falloff *
amplitude *
(
0.48 +
0.43 * waveA +
0.20 * waveB +
0.16 * billow
);
const x =
base[i * 3] +
falloff *
amplitude *
0.11 *
Math.sin(
v * 5.5 +
time * 1.7 +
towel.phase
);
const y =
base[i * 3 + 1] +
falloff *
amplitude *
0.045 *
Math.cos(
u * 6.5 +
time * 1.3 +
towel.phase
);
positionArray[i * 3] = x;
positionArray[i * 3 + 1] = y;
positionArray[i * 3 + 2] = z;
}
// Explicitly restore the pinned vertices as a final safety constraint.
for (const index of towel.pinnedIndices) {
positionArray[index * 3] = base[index * 3];
positionArray[index * 3 + 1] = base[index * 3 + 1];
positionArray[index * 3 + 2] = base[index * 3 + 2];
}
positionAttribute.needsUpdate = true;
towel.geometry.computeVertexNormals();
}
// -------------------------------------------------------------------------
// Custom orbit camera controls — no external control modules
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0.1, 2.15, -0.5);
const cameraHome = {
azimuth: 0.24,
polar: 1.20,
radius: 12.6
};
let cameraAzimuth = cameraHome.azimuth;
let cameraPolar = cameraHome.polar;
let cameraRadius = cameraHome.radius;
let dragging = false;
let previousPointerX = 0;
let previousPointerY = 0;
function updateCamera() {
const sinPolar = Math.sin(cameraPolar);
const cosPolar = Math.cos(cameraPolar);
camera.position.set(
cameraTarget.x +
cameraRadius * sinPolar * Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * cosPolar,
cameraTarget.z +
cameraRadius * sinPolar * Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousPointerX = event.clientX;
previousPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousPointerX;
const deltaY = event.clientY - previousPointerY;
cameraAzimuth -= deltaX * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar + deltaY * 0.005,
0.72,
1.42
);
previousPointerX = event.clientX;
previousPointerY = event.clientY;
updateCamera();
});
function endDrag(event) {
dragging = false;
if (
renderer.domElement.hasPointerCapture &&
event.pointerId !== undefined
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.008,
8.0,
19.0
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
cameraAzimuth = cameraHome.azimuth;
cameraPolar = cameraHome.polar;
cameraRadius = cameraHome.radius;
updateCamera();
});
updateCamera();
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
const windValue = document.getElementById("windValue");
const windFill = document.getElementById("windFill");
function resize() {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
}
addEventListener("resize", resize);
const clock = new THREE.Clock();
let uiFrame = 0;
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
// Layered gusts create a continuously changing breeze.
const gustA = 0.5 + 0.5 * Math.sin(time * 0.48);
const gustB = 0.5 + 0.5 * Math.sin(time * 1.31 + 1.7);
const gustC = 0.5 + 0.5 * Math.sin(time * 0.19 + 0.6);
const targetWind = THREE.MathUtils.clamp(
0.12 +
gustA * 0.46 +
gustB * 0.25 +
gustC * 0.16,
0.1,
1
);
const smoothing = 1 - Math.pow(0.92, delta * 60);
windStrength +=
(targetWind - windStrength) * smoothing;
for (const towel of towels) {
updateTowel(towel, time);
}
if ((uiFrame++ & 3) === 0) {
const percent = Math.round(windStrength * 100);
windValue.textContent = `${percent}%`;
windFill.style.transform = `scaleX(${windStrength})`;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```