Prompt specification
Build or customize the Three.js 3D scene "Sheer and opaque curtain samples" 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: Sheer and opaque curtain samples
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sheer-and-opaque-curtain-samples-x0181
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows curtains and light transmission. Hang two equally sized fabric panels before a window, using different opacity and thickness; silhouettes behind them must be visible through only the sheer sample. Stylized solid forms.
Working Three.js Starter (sheer-and-opaque-curtain-samples-x0181):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Curtain Transmission Study</title>
<style>
:root {
color-scheme: dark;
--cream: #fff8e9;
--muted: rgba(255, 248, 233, 0.68);
--glass: rgba(31, 29, 27, 0.58);
--line: rgba(255, 248, 233, 0.18);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #292725;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#app,
#app canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#app canvas {
touch-action: none;
cursor: grab;
}
#app canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
color: var(--cream);
}
.title-card {
position: absolute;
top: clamp(20px, 4vw, 48px);
left: clamp(20px, 4vw, 52px);
width: min(390px, calc(100vw - 40px));
padding: 20px 22px;
border: 1px solid var(--line);
border-radius: 18px;
background: linear-gradient(145deg, rgba(30, 28, 26, 0.78), rgba(30, 28, 26, 0.42));
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.eyebrow {
margin: 0 0 8px;
color: #efc979;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 36px);
font-weight: 570;
line-height: 1.04;
letter-spacing: -0.035em;
}
.description {
max-width: 330px;
margin: 12px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.legend {
position: absolute;
left: clamp(20px, 4vw, 52px);
bottom: clamp(20px, 4vw, 48px);
display: flex;
gap: 10px;
pointer-events: none;
}
.legend-card {
min-width: 166px;
padding: 13px 15px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--glass);
box-shadow: 0 12px 34px rgba(0, 0, 0, 0.2);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
.legend-title {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 6px;
font-size: 11px;
font-weight: 760;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.swatch {
width: 12px;
height: 12px;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.swatch.sheer {
background: rgba(255, 239, 194, 0.28);
}
.swatch.heavy {
background: #b85f49;
}
.legend-meta {
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.controls {
position: absolute;
right: clamp(20px, 4vw, 52px);
bottom: clamp(20px, 4vw, 48px);
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 15px;
color: var(--cream);
background: var(--glass);
font: inherit;
font-size: 11px;
font-weight: 650;
letter-spacing: 0.02em;
cursor: pointer;
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
transition:
background 160ms ease,
transform 160ms ease,
border-color 160ms ease;
}
button:hover {
border-color: rgba(255, 248, 233, 0.38);
background: rgba(55, 50, 45, 0.78);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid #efc979;
outline-offset: 3px;
}
button[aria-pressed="true"] .status-dot {
background: #efc979;
box-shadow: 0 0 10px rgba(239, 201, 121, 0.8);
}
.status-dot {
display: inline-block;
width: 6px;
height: 6px;
margin-right: 7px;
border-radius: 50%;
background: #8c8881;
vertical-align: 1px;
}
.sample-label {
position: absolute;
top: 0;
left: 0;
min-width: 135px;
padding: 8px 10px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 10px;
color: #fff9ec;
background: rgba(24, 23, 21, 0.68);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
opacity: 0;
transform: translate(-50%, -100%);
transition: opacity 120ms ease;
white-space: nowrap;
}
.sample-label.visible {
opacity: 1;
}
.sample-label strong {
display: block;
font-size: 10px;
font-weight: 780;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sample-label span {
display: block;
margin-top: 3px;
color: rgba(255, 249, 236, 0.64);
font-size: 9px;
}
.hint {
position: absolute;
right: clamp(20px, 4vw, 52px);
top: clamp(22px, 4vw, 48px);
color: rgba(255, 248, 233, 0.58);
font-size: 10px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
@media (max-width: 720px) {
.title-card {
padding: 16px 18px;
}
.description {
max-width: 290px;
font-size: 11px;
}
.legend {
right: 20px;
gap: 7px;
}
.legend-card {
min-width: 0;
flex: 1;
padding: 10px 11px;
}
.legend-meta {
font-size: 9px;
}
.controls {
top: auto;
bottom: 126px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app"></div>
<div class="ui">
<section class="title-card">
<p class="eyebrow">Material / Light Study</p>
<h1>Curtain<br />Transmission</h1>
<p class="description">
Two equal fabric panels stand before a backlit window. Matched silhouettes
are visible through the sheer sample and fully concealed by the heavy cloth.
</p>
</section>
<div class="legend">
<div class="legend-card">
<div class="legend-title">
<span class="swatch sheer"></span>
Sheer sample
</div>
<div class="legend-meta">
24% opacity<br />Thin · 0.025 thickness
</div>
</div>
<div class="legend-card">
<div class="legend-title">
<span class="swatch heavy"></span>
Heavy sample
</div>
<div class="legend-meta">
100% opacity<br />Thick · 0.220 thickness
</div>
</div>
</div>
<div class="controls">
<button id="backlight" type="button" aria-pressed="true">
<span class="status-dot"></span><span id="backlightText">Backlight on</span>
</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="hint">Drag to orbit · Scroll to zoom</div>
<div id="sheerLabel" class="sample-label">
<strong>01 / Sheer</strong>
<span>Light passes · silhouette visible</span>
</div>
<div id="heavyLabel" class="sample-label">
<strong>02 / Heavy</strong>
<span>Light blocked · silhouette hidden</span>
</div>
</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 sheerLabel = document.querySelector("#sheerLabel");
const heavyLabel = document.querySelector("#heavyLabel");
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
app.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x4b4641);
scene.fog = new THREE.Fog(0x6f685f, 12, 25);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
60
);
// ---------------------------------------------------------------------
// Small custom orbit controller. No examples/addons are used.
// ---------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.3, -1.35),
desired: {
theta: 0,
phi: 1.34,
radius: 9.25
},
current: {
theta: 0,
phi: 1.34,
radius: 9.25
}
};
const resetView = () => {
controls.desired.theta = 0;
controls.desired.phi = 1.34;
controls.desired.radius = 9.25;
};
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
controls.desired.theta = THREE.MathUtils.clamp(
controls.desired.theta - dx * 0.0045,
-0.3,
0.3
);
controls.desired.phi = THREE.MathUtils.clamp(
controls.desired.phi - dy * 0.0038,
1.18,
1.49
);
});
const stopDragging = (event) => {
dragging = false;
if (event.pointerId !== undefined) {
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
};
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.desired.radius = THREE.MathUtils.clamp(
controls.desired.radius + event.deltaY * 0.007,
7.65,
12.2
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
function updateCamera(delta) {
const smoothing = 1 - Math.exp(-delta * 8);
controls.current.theta = THREE.MathUtils.lerp(
controls.current.theta,
controls.desired.theta,
smoothing
);
controls.current.phi = THREE.MathUtils.lerp(
controls.current.phi,
controls.desired.phi,
smoothing
);
controls.current.radius = THREE.MathUtils.lerp(
controls.current.radius,
controls.desired.radius,
smoothing
);
const { theta, phi, radius } = controls.current;
const sinPhi = Math.sin(phi);
camera.position.set(
controls.target.x + radius * sinPhi * Math.sin(theta),
controls.target.y + radius * Math.cos(phi),
controls.target.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(controls.target);
}
// ---------------------------------------------------------------------
// Lighting and room
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfff3d8,
0x5b4c40,
1.65
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffe4bd, 2.4);
keyLight.position.set(-4.5, 7, 7);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -2;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const backLight = new THREE.DirectionalLight(0xffe5a8, 2.8);
backLight.position.set(-2.5, 5.5, -7);
backLight.target.position.set(0, 1.2, 1.5);
scene.add(backLight);
scene.add(backLight.target);
const windowGlow = new THREE.PointLight(0xffd58a, 20, 9, 2);
windowGlow.position.set(-0.7, 3.3, -2.8);
scene.add(windowGlow);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x8a8075,
roughness: 0.96,
metalness: 0
});
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x695448,
roughness: 0.86,
metalness: 0
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.015;
floor.receiveShadow = true;
scene.add(floor);
const opening = {
left: -3.3,
right: 3.3,
bottom: 0.35,
top: 4.45
};
function addWallBox(x, y, width, height) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, 0.34),
wallMaterial
);
mesh.position.set(x, y, -2.4);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
}
addWallBox(-5.25, 3.5, 3.9, 7);
addWallBox(5.25, 3.5, 3.9, 7);
addWallBox(0, 5.72, 6.6, 2.54);
addWallBox(0, 0.175, 6.6, 0.35);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0xe9dfce,
roughness: 0.62,
metalness: 0.02
});
function addFrameBox(x, y, width, height, depth = 0.18) {
const frame = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
frameMaterial
);
frame.position.set(x, y, -2.18);
frame.castShadow = true;
frame.receiveShadow = true;
scene.add(frame);
}
addFrameBox(-3.27, 2.4, 0.16, 4.25);
addFrameBox(3.27, 2.4, 0.16, 4.25);
addFrameBox(0, 0.4, 6.65, 0.16);
addFrameBox(0, 4.4, 6.65, 0.16);
const sill = new THREE.Mesh(
new THREE.BoxGeometry(7.1, 0.18, 0.68),
frameMaterial
);
sill.position.set(0, 0.28, -2.03);
sill.castShadow = true;
sill.receiveShadow = true;
scene.add(sill);
// ---------------------------------------------------------------------
// Bright exterior and matching silhouettes
// ---------------------------------------------------------------------
const skyMaterial = new THREE.ShaderMaterial({
uniforms: {
topColor: { value: new THREE.Color(0x79bfd0) },
bottomColor: { value: new THREE.Color(0xffe6ad) }
},
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
varying vec2 vUv;
uniform vec3 topColor;
uniform vec3 bottomColor;
void main() {
float blend = smoothstep(0.0, 1.0, vUv.y);
vec3 color = mix(bottomColor, topColor, blend);
gl_FragColor = vec4(color, 1.0);
}
`,
depthWrite: false,
fog: false
});
const sky = new THREE.Mesh(
new THREE.PlaneGeometry(6.55, 4.05),
skyMaterial
);
sky.position.set(0, 2.4, -3.5);
scene.add(sky);
const sunMaterial = new THREE.MeshBasicMaterial({
color: 0xffefae,
transparent: true,
opacity: 0.95,
depthWrite: false,
fog: false
});
const sun = new THREE.Mesh(
new THREE.CircleGeometry(0.47, 48),
sunMaterial
);
sun.position.set(-1.72, 3.2, -3.43);
scene.add(sun);
const silhouetteMaterial = new THREE.MeshBasicMaterial({
color: 0x273139,
fog: false
});
function makeLimb(start, end, radius, material) {
const direction = new THREE.Vector3().subVectors(end, start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radius,
radius,
length,
10
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeSilhouette(x, variant = 0) {
const group = new THREE.Group();
group.position.set(x, 0, -3.28);
const torso = new THREE.Mesh(
new THREE.CylinderGeometry(0.29, 0.38, 1.3, 10),
silhouetteMaterial
);
torso.position.y = 2.4;
group.add(torso);
const head = new THREE.Mesh(
new THREE.SphereGeometry(0.27, 20, 14),
silhouetteMaterial
);
head.position.set(0, 3.42, 0);
head.scale.set(0.9, 1.08, 0.9);
group.add(head);
group.add(
makeLimb(
new THREE.Vector3(0, 3.04, 0),
new THREE.Vector3(0, 3.18, 0),
0.1,
silhouetteMaterial
)
);
const leftShoulder = new THREE.Vector3(-0.27, 2.98, 0);
const rightShoulder = new THREE.Vector3(0.27, 2.98, 0);
const leftElbow = new THREE.Vector3(
-0.49 - variant * 0.07,
2.34,
0
);
const rightElbow = new THREE.Vector3(
0.48 + variant * 0.05,
2.36,
0
);
const leftHand = new THREE.Vector3(
-0.5 - variant * 0.12,
1.82 + variant * 0.2,
0
);
const rightHand = new THREE.Vector3(
0.57,
1.87,
0
);
group.add(
makeLimb(leftShoulder, leftElbow, 0.105, silhouetteMaterial),
makeLimb(leftElbow, leftHand, 0.09, silhouetteMaterial),
makeLimb(rightShoulder, rightElbow, 0.105, silhouetteMaterial),
makeLimb(rightElbow, rightHand, 0.09, silhouetteMaterial)
);
const hipLeft = new THREE.Vector3(-0.16, 1.77, 0);
const hipRight = new THREE.Vector3(0.16, 1.77, 0);
const kneeLeft = new THREE.Vector3(-0.2, 0.98, 0);
const kneeRight = new THREE.Vector3(0.2, 0.98, 0);
const footLeft = new THREE.Vector3(-0.26, 0.42, 0);
const footRight = new THREE.Vector3(0.29, 0.42, 0);
group.add(
makeLimb(hipLeft, kneeLeft, 0.13, silhouetteMaterial),
makeLimb(kneeLeft, footLeft, 0.11, silhouetteMaterial),
makeLimb(hipRight, kneeRight, 0.13, silhouetteMaterial),
makeLimb(kneeRight, footRight, 0.11, silhouetteMaterial)
);
scene.add(group);
}
// Identical figures behind the two equal panels.
makeSilhouette(-1.48, 0);
makeSilhouette(1.48, 0);
const glass = new THREE.Mesh(
new THREE.PlaneGeometry(6.5, 4.02),
new THREE.MeshBasicMaterial({
color: 0xd8f2f4,
transparent: true,
opacity: 0.035,
depthWrite: false,
side: THREE.DoubleSide,
fog: false
})
);
glass.position.set(0, 2.4, -2.82);
glass.renderOrder = 1;
scene.add(glass);
// ---------------------------------------------------------------------
// Procedural woven bump texture
// ---------------------------------------------------------------------
function createWeaveTexture() {
const canvas = document.createElement("canvas");
canvas.width = 128;
canvas.height = 128;
const context = canvas.getContext("2d");
const image = context.createImageData(128, 128);
for (let y = 0; y < 128; y++) {
for (let x = 0; x < 128; x++) {
const warp = Math.sin(x * Math.PI * 0.5) * 20;
const weft = Math.sin(y * Math.PI * 0.5) * 16;
const thread = ((x % 4 < 2) !== (y % 4 < 2)) ? 11 : -7;
const grain = ((x * 17 + y * 31 + x * y) % 13) - 6;
const value = Math.max(
30,
Math.min(220, 128 + warp + weft + thread + grain)
);
const offset = (y * 128 + x) * 4;
image.data[offset] = value;
image.data[offset + 1] = value;
image.data[offset + 2] = value;
image.data[offset + 3] = 255;
}
}
context.putImageData(image, 0, 0);
const texture = new THREE.CanvasTexture(canvas);
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(14, 20);
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
texture.colorSpace = THREE.NoColorSpace;
return texture;
}
const weaveTexture = createWeaveTexture();
const samples = {
sheer: {
opacity: 0.24,
thickness: 0.025,
color: 0xffedbd,
roughness: 0.9,
sheen: 0.72,
bumpScale: 0.008
},
heavy: {
opacity: 1.0,
thickness: 0.22,
color: 0xb85f49,
roughness: 0.94,
sheen: 0.28,
bumpScale: 0.026
}
};
function createSampleMaterial(config, transparent) {
const material = new THREE.MeshPhysicalMaterial({
color: config.color,
roughness: config.roughness,
metalness: 0,
opacity: config.opacity,
transparent,
depthWrite: !transparent,
side: THREE.DoubleSide,
thickness: config.thickness,
ior: 1.42,
transmission: 0,
sheen: config.sheen,
sheenRoughness: 0.8,
sheenColor: new THREE.Color(
config.sheer > 0.5 ? 0xfff1cf : 0x5f1f16
),
bumpMap: weaveTexture,
bumpScale: config.bumpScale,
emissive: config.sheer > 0.5 ? 0x6d4a18 : 0x000000,
emissiveIntensity: config.sheer > 0.5 ? 0.055 : 0
});
material.forceSinglePass = true;
return material;
}
const sheerMaterial = createSampleMaterial(samples.sheer, true);
const heavyMaterial = createSampleMaterial(samples.heavy, false);
// ---------------------------------------------------------------------
// Equal-size curtain panels with modeled folds and hems
// ---------------------------------------------------------------------
const panelWidth = 2.85;
const panelHeight = 4.0;
const panelDepth = -1.55;
function createCurtainGeometry(width, height, amplitude, phase) {
const geometry = new THREE.PlaneGeometry(width, height, 64, 30);
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const y = positions.getY(i);
const u = x / width + 0.5;
const v = y / height + 0.5;
const largeFold = Math.sin(u * Math.PI * 14 + phase);
const smallFold = Math.sin(u * Math.PI * 28 + phase * 0.55);
const fullness = 0.78 + v * 0.25;
const z = (
largeFold * amplitude +
smallFold * amplitude * 0.2
) * fullness;
positions.setZ(i, z);
// Slightly irregular lower hems.
if (y < -height * 0.49) {
positions.setY(
i,
y + Math.sin(u * Math.PI * 14 + phase) * 0.027
);
}
}
positions.needsUpdate = true;
geometry.computeVertexNormals();
geometry.computeBoundingSphere();
return geometry;
}
function createPanel({
x,
geometry,
material,
hemRadius,
ringCount,
ringPhase
}) {
const group = new THREE.Group();
group.position.set(x, 2.35, panelDepth);
const curtain = new THREE.Mesh(geometry, material);
curtain.receiveShadow = !material.transparent;
curtain.castShadow = !material.transparent;
curtain.renderOrder = material.transparent ? 3 : 0;
group.add(curtain);
const positions = geometry.attributes.position;
const widthSegments = 64;
const heightSegments = 30;
const bottomPoints = [];
const leftPoints = [];
const rightPoints = [];
for (let i = 0; i <= widthSegments; i++) {
const index = i;
bottomPoints.push(
new THREE.Vector3(
positions.getX(index),
positions.getY(index),
positions.getZ(index)
)
);
}
for (let row = 0; row <= heightSegments; row++) {
const leftIndex = row * (widthSegments + 1);
const rightIndex = leftIndex + widthSegments;
leftPoints.push(
new THREE.Vector3(
positions.getX(leftIndex),
positions.getY(leftIndex),
positions.getZ(leftIndex)
)
);
rightPoints.push(
new THREE.Vector3(
positions.getX(rightIndex),
positions.getY(rightIndex),
positions.getZ(rightIndex)
)
);
}
const hems = [
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(bottomPoints),
72,
hemRadius,
7,
false
),
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(leftPoints),
40,
hemRadius * 0.85,
7,
false
),
new THREE.TubeGeometry(
new THREE.CatmullRomCurve3(rightPoints),
40,
hemRadius * 0.85,
7,
false
)
];
for (const hemGeometry of hems) {
const hem = new THREE.Mesh(hemGeometry, material);
hem.renderOrder = material.transparent ? 3 : 0;
group.add(hem);
}
// Ring-and-clip details.
for (let i = 0; i < ringCount; i++) {
const t = ringCount === 1 ? 0.5 : i / (ringCount - 1);
const localX = THREE.MathUtils.lerp(
-panelWidth * 0.44,
panelWidth * 0.44,
t
);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.13, 0.022, 10, 28),
frameMaterial
);
ring.rotation.y = Math.PI / 2;
ring.position.set(localX, 2.25, 0.1);
ring.castShadow = true;
group.add(ring);
const clip = new THREE.Mesh(
new THREE.CylinderGeometry(0.022, 0.022, 0.17, 8),
frameMaterial
);
clip.position.set(localX, 2.075, 0.075);
group.add(clip);
}
scene.add(group);
return group;
}
createPanel({
x: -1.48,
geometry: createCurtainGeometry(
panelWidth,
panelHeight,
0.125,
0.18
),
material: sheerMaterial,
hemRadius: 0.011,
ringCount: 9,
ringPhase: 0
});
createPanel({
x: 1.48,
geometry: createCurtainGeometry(
panelWidth,
panelHeight,
0.16,
0.18
),
material: heavyMaterial,
hemRadius: 0.038,
ringCount: 9,
ringPhase: 0
});
// Curtain rod and finials.
const rodMaterial = new THREE.MeshStandardMaterial({
color: 0x5a4a3d,
roughness: 0.42,
metalness: 0.48
});
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.052, 0.052, 6.65, 24),
rodMaterial
);
rod.rotation.z = Math.PI / 2;
rod.position.set(0, 4.6, -1.45);
rod.castShadow = true;
scene.add(rod);
for (const direction of [-1, 1]) {
const finial = new THREE.Mesh(
new THREE.SphereGeometry(0.11, 18, 12),
rodMaterial
);
finial.position.set(direction * 3.38, 4.6, -1.45);
finial.castShadow = true;
scene.add(finial);
}
// ---------------------------------------------------------------------
// Stylized transmitted-light pools
// ---------------------------------------------------------------------
function createLightTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
128,
128,
10,
128,
128,
128
);
gradient.addColorStop(0, "rgba(255,255,255,0.9)");
gradient.addColorStop(0.45, "rgba(255,255,255,0.45)");
gradient.addColorStop(1, "rgba(255,255,255,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 256, 256);
return new THREE.CanvasTexture(canvas);
}
const lightTexture = createLightTexture();
const sheerLightPool = new THREE.Mesh(
new THREE.PlaneGeometry(3.4, 2.35),
new THREE.MeshBasicMaterial({
map: lightTexture,
color: 0xffd584,
transparent: true,
opacity: 0.18,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
sheerLightPool.rotation.x = -Math.PI / 2;
sheerLightPool.position.set(-1.42, 0.012, 0.65);
scene.add(sheerLightPool);
const heavyLightPool = new THREE.Mesh(
new THREE.PlaneGeometry(3.0, 2.1),
new THREE.MeshBasicMaterial({
map: lightTexture,
color: 0xffd584,
transparent: true,
opacity: 0.035,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
heavyLightPool.rotation.x = -Math.PI / 2;
heavyLightPool.position.set(1.48, 0.014, 0.65);
scene.add(heavyLightPool);
// Fine dust makes the backlit volume legible.
const dustCount = 90;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = THREE.MathUtils.lerp(-3.0, 0.5, Math.random());
dustPositions[i * 3 + 1] = THREE.MathUtils.lerp(0.5, 4.3, Math.random());
dustPositions[i * 3 + 2] = THREE.MathUtils.lerp(-1.7, 2.2, Math.random());
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xffe8b1,
size: 0.026,
transparent: true,
opacity: 0.46,
depthWrite: false,
blending: THREE.AdditiveBlending
})
);
scene.add(dust);
// ---------------------------------------------------------------------
// Backlight toggle
// ---------------------------------------------------------------------
const backlightButton = document.querySelector("#backlight");
const backlightText = document.querySelector("#backlightText");
let backlightOn = true;
backlightButton.addEventListener("click", () => {
backlightOn = !backlightOn;
backlightButton.setAttribute("aria-pressed", String(backlightOn));
backlightText.textContent = backlightOn
? "Backlight on"
: "Backlight off";
skyMaterial.uniforms.topColor.value.set(
backlightOn ? 0x79bfd0 : 0x61747b
);
skyMaterial.uniforms.bottomColor.value.set(
backlightOn ? 0xffe6ad : 0x88796c
);
sunMaterial.opacity = backlightOn ? 0.95 : 0.18;
backLight.intensity = backlightOn ? 2.8 : 0.35;
windowGlow.intensity = backlightOn ? 20 : 3;
sheerLightPool.material.opacity = backlightOn ? 0.18 : 0.025;
heavyLightPool.material.opacity = backlightOn ? 0.035 : 0.008;
dust.material.opacity = backlightOn ? 0.46 : 0.08;
});
document.querySelector("#reset").addEventListener("click", resetView);
// ---------------------------------------------------------------------
// Projected HTML labels
// ---------------------------------------------------------------------
const labelAnchors = [
{
element: sheerLabel,
position: new THREE.Vector3(-1.48, 4.43, -1.35)
},
{
element: heavyLabel,
position: new THREE.Vector3(1.48, 4.43, -1.35)
}
];
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const label of labelAnchors) {
const projected = label.position.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.1 &&
projected.x < 1.1 &&
projected.y > -1.1 &&
projected.y < 1.1;
label.element.classList.toggle("visible", visible);
if (visible) {
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
label.element.style.transform =
`translate(${x}px, ${y}px) translate(-50%, -100%)`;
}
}
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateCamera(delta);
updateLabels();
const positions = dust.geometry.attributes.position;
for (let i = 0; i < dustCount; i++) {
let y = positions.getY(i) + delta * (0.018 + (i % 5) * 0.003);
if (y > 4.35) y = 0.45;
positions.setY(i, y);
positions.setX(
i,
positions.getX(i) + Math.sin(elapsed * 0.28 + i) * delta * 0.004
);
}
positions.needsUpdate = true;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```