Prompt specification
Build or customize the Three.js 3D scene "Curtain overlap light 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: Curtain overlap light study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/curtain-overlap-light-study-x0182
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing curtains and light transmission. Slide two sheer panels across a bright window and compare overlapped versus single layers; use consistent backlighting so the change in transmitted brightness is readable. Voxel style.
Working Three.js Starter (curtain-overlap-light-study-x0182):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sheer Stack Lab — Voxel Light Transmission</title>
<style>
:root {
--ink: #eef7fa;
--muted: #a9bdc8;
--panel: rgba(19, 31, 41, 0.91);
--line: rgba(222, 240, 248, 0.14);
--accent: #ffd166;
--cyan: #7de2f1;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce5e9;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.controls-panel {
position: fixed;
z-index: 10;
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
max-height: calc(100vh - 44px);
overflow: auto;
padding: 22px;
color: var(--ink);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 20px;
box-shadow: 0 22px 70px rgba(19, 31, 41, 0.24);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 34px);
line-height: 1.05;
letter-spacing: -0.04em;
}
.intro {
margin: 12px 0 18px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.fixed-light {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 18px;
padding: 10px 12px;
color: #ffe7a0;
background: rgba(255, 209, 102, 0.09);
border: 1px solid rgba(255, 209, 102, 0.2);
border-radius: 12px;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.sun-dot {
width: 9px;
height: 9px;
background: var(--accent);
box-shadow: 0 0 14px rgba(255, 209, 102, 0.8);
}
.section-title {
margin: 18px 0 10px;
color: #d8e8ef;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.presets {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 10px;
padding: 10px 11px;
color: #dcebf1;
background: rgba(255, 255, 255, 0.055);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.1);
border-color: rgba(222, 240, 248, 0.3);
}
button:active {
transform: translateY(1px);
}
button.active {
color: #15232c;
background: var(--cyan);
border-color: var(--cyan);
}
.slider-row {
margin-top: 16px;
padding: 13px 14px 11px;
background: rgba(255, 255, 255, 0.04);
border: 1px solid var(--line);
border-radius: 13px;
}
.slider-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
font-size: 12px;
font-weight: 750;
}
.panel-name {
display: flex;
align-items: center;
gap: 8px;
}
.panel-badge {
display: inline-grid;
width: 22px;
height: 22px;
place-items: center;
color: #102029;
background: #9eb5c4;
border-radius: 6px;
font-size: 11px;
font-weight: 900;
}
.panel-badge.b {
background: #6f899c;
}
.slider-value {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-weight: 650;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 4px 0 2px;
appearance: none;
background: rgba(255, 255, 255, 0.14);
border-radius: 999px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
background: var(--cyan);
border: 3px solid #e9f9fc;
border-radius: 5px;
box-shadow: 0 2px 9px rgba(0, 0, 0, 0.28);
cursor: ew-resize;
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
background: var(--cyan);
border: 3px solid #e9f9fc;
border-radius: 5px;
box-shadow: 0 2px 9px rgba(0, 0, 0, 0.28);
cursor: ew-resize;
}
.toggle-row {
display: flex;
gap: 8px;
margin-top: 10px;
}
.toggle {
display: flex;
flex: 1;
align-items: center;
justify-content: center;
gap: 7px;
padding: 8px;
color: var(--muted);
background: rgba(255, 255, 255, 0.035);
border: 1px solid var(--line);
border-radius: 9px;
font-size: 11px;
cursor: pointer;
}
.toggle input {
accent-color: var(--cyan);
}
.readouts {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 15px;
}
.readout {
padding: 12px;
background: rgba(255, 255, 255, 0.045);
border: 1px solid var(--line);
border-radius: 12px;
}
.readout span {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.readout strong {
display: block;
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.legend {
display: flex;
align-items: center;
gap: 8px;
margin-top: 13px;
color: var(--muted);
font-size: 10px;
}
.legend-item {
display: flex;
align-items: center;
gap: 5px;
white-space: nowrap;
}
.swatch {
width: 15px;
height: 15px;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 4px;
}
.swatch.none {
background: #f4fbff;
}
.swatch.one {
background: #8fa5b3;
}
.swatch.two {
background: #637886;
}
.note {
margin: 14px 0 0;
padding-top: 13px;
color: #90a8b5;
border-top: 1px solid var(--line);
font-size: 10px;
line-height: 1.55;
}
.light-badge {
position: fixed;
z-index: 5;
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
color: #30424c;
background: rgba(255, 255, 255, 0.82);
border: 1px solid rgba(48, 66, 76, 0.12);
border-radius: 999px;
box-shadow: 0 10px 35px rgba(35, 55, 66, 0.12);
backdrop-filter: blur(12px);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
.light-badge i {
width: 10px;
height: 10px;
background: #ffc94a;
box-shadow: 0 0 12px rgba(255, 201, 74, 0.75);
}
.hint {
position: fixed;
z-index: 5;
right: 22px;
bottom: 18px;
padding: 9px 12px;
color: rgba(35, 55, 66, 0.72);
background: rgba(255, 255, 255, 0.68);
border-radius: 999px;
backdrop-filter: blur(10px);
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.tag {
position: fixed;
z-index: 4;
display: none;
padding: 5px 8px;
color: #12222b;
background: rgba(235, 247, 251, 0.93);
border: 2px solid #8099aa;
border-radius: 7px;
box-shadow: 0 5px 18px rgba(20, 40, 52, 0.18);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.06em;
pointer-events: none;
transform: translate(-50%, -50%);
}
.tag.b {
border-color: #526b7d;
}
.tag.stack {
color: #16232c;
background: rgba(255, 209, 102, 0.94);
border-color: rgba(95, 74, 31, 0.35);
}
@media (max-width: 720px) {
.controls-panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
padding: 16px;
border-radius: 16px;
}
.intro {
display: none;
}
h1 {
font-size: 24px;
}
.fixed-light {
margin: 12px 0;
}
.section-title {
margin-top: 13px;
}
.light-badge {
top: 12px;
right: 12px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel curtains in front of a bright window"></canvas>
<aside class="controls-panel">
<div class="eyebrow">Voxel Optics / 01</div>
<h1>Sheer Stack Lab</h1>
<p class="intro">
Slide the two gauze panels to compare a single layer with an overlapped,
double-transmission region.
</p>
<div class="fixed-light">
<span class="sun-dot"></span>
Window backlight locked at 100%
</div>
<div class="section-title">Quick arrangements</div>
<div class="presets">
<button type="button" data-preset="single">1 layer</button>
<button type="button" data-preset="split">Split panels</button>
<button type="button" data-preset="overlap">2× band</button>
<button type="button" data-preset="stack">Full stack</button>
</div>
<div class="slider-row">
<div class="slider-heading">
<span class="panel-name">
<span class="panel-badge">A</span>
Panel A
</span>
<span class="slider-value" id="valueA">-2.35</span>
</div>
<input
id="panelA"
type="range"
min="-8"
max="8"
step="0.05"
value="-2.35"
aria-label="Panel A horizontal position"
>
</div>
<div class="slider-row">
<div class="slider-heading">
<span class="panel-name">
<span class="panel-badge b">B</span>
Panel B
</span>
<span class="slider-value" id="valueB">2.35</span>
</div>
<input
id="panelB"
type="range"
min="-8"
max="8"
step="0.05"
value="2.35"
aria-label="Panel B horizontal position"
>
</div>
<div class="toggle-row">
<label class="toggle">
<input id="showA" type="checkbox" checked>
Show A
</label>
<label class="toggle">
<input id="showB" type="checkbox" checked>
Show B
</label>
</div>
<div class="readouts">
<div class="readout">
<span>Visible 2× overlap</span>
<strong id="overlapValue">0.0%</strong>
</div>
<div class="readout">
<span>Current region</span>
<strong id="regionValue">1×</strong>
</div>
</div>
<div class="legend" aria-label="Transmission color comparison">
<div class="legend-item">
<i class="swatch none"></i>
Window
</div>
<div class="legend-item">
<i class="swatch one"></i>
1 sheer
</div>
<div class="legend-item">
<i class="swatch two"></i>
2 sheer
</div>
</div>
<p class="note">
The source brightness never changes. Where the panels overlap, the same
backlight passes through two fixed-opacity layers and is visibly dimmer.
</p>
</aside>
<div class="light-badge">
<i></i>
Fixed backlight
</div>
<div class="hint">Drag panels · drag background to orbit · wheel to zoom</div>
<div class="tag" id="tagA">A · 1 SHEER</div>
<div class="tag b" id="tagB">B · 1 SHEER</div>
<div class="tag stack" id="tagStack">2× TRANSMISSION</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.NoToneMapping;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdbe5e9);
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0, 0);
const state = {
a: -2.35,
b: 2.35,
aOn: true,
bOn: true,
yaw: -0.075,
pitch: 0.035,
zoom: 1
};
const PANEL_WIDTH = 4.7;
const PANEL_HEIGHT = 5.65;
const HALF_PANEL = PANEL_WIDTH / 2;
const WINDOW_HALF = 5.05;
const sliderA = document.querySelector("#panelA");
const sliderB = document.querySelector("#panelB");
const valueA = document.querySelector("#valueA");
const valueB = document.querySelector("#valueB");
const showA = document.querySelector("#showA");
const showB = document.querySelector("#showB");
const overlapValue = document.querySelector("#overlapValue");
const regionValue = document.querySelector("#regionValue");
const tagA = document.querySelector("#tagA");
const tagB = document.querySelector("#tagB");
const tagStack = document.querySelector("#tagStack");
const presetButtons = [...document.querySelectorAll("[data-preset]")];
const standardMaterials = new Map();
function standardMaterial(color) {
if (!standardMaterials.has(color)) {
standardMaterials.set(
color,
new THREE.MeshStandardMaterial({
color,
roughness: 0.88,
metalness: 0.02
})
);
}
return standardMaterials.get(color);
}
function addBox(width, height, depth, color, x, y, z, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
standardMaterial(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Lighting affects the room blocks, but the window itself uses an
// unlit material so its backlight remains exactly consistent.
scene.add(new THREE.AmbientLight(0xdcecf2, 0.72));
const keyLight = new THREE.DirectionalLight(0xffedcf, 1.55);
keyLight.position.set(-4, 7, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc7e8ff, 0.42);
fillLight.position.set(7, 1, 5);
scene.add(fillLight);
// Back wall behind the voxel window.
addBox(15.6, 8.2, 0.25, 0xaebdc3, 0, 0, -2.12);
// Instanced voxel wall tiles surrounding the opening.
const tileGeometry = new THREE.BoxGeometry(0.65, 0.62, 0.18);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xc3cdd1,
roughness: 1
});
const tilePositions = [];
const spacing = 0.68;
for (let row = 0; row < 11; row++) {
for (let column = 0; column < 21; column++) {
const x = -6.8 + column * spacing;
const y = -3.4 + row * spacing;
const insideWindow =
x > -5.08 &&
x < 5.08 &&
y > -3.05 &&
y < 3.22;
if (!insideWindow) {
tilePositions.push({ x, y });
}
}
}
const wallTiles = new THREE.InstancedMesh(
tileGeometry,
tileMaterial,
tilePositions.length
);
const tileMatrix = new THREE.Matrix4();
const tileColor = new THREE.Color();
tilePositions.forEach(({ x, y }, index) => {
tileMatrix.makeTranslation(x, y, -1.93);
wallTiles.setMatrixAt(index, tileMatrix);
const variation = 0.94 + Math.random() * 0.08;
tileColor.setRGB(
0.76 * variation,
0.81 * variation,
0.83 * variation
);
wallTiles.setColorAt(index, tileColor);
});
wallTiles.instanceMatrix.needsUpdate = true;
if (wallTiles.instanceColor) {
wallTiles.instanceColor.needsUpdate = true;
}
scene.add(wallTiles);
// Bright, unlit window surface.
const paneMaterial = new THREE.MeshBasicMaterial({
color: 0xf4fbff
});
const pane = new THREE.Mesh(
new THREE.BoxGeometry(10.2, 6.3, 0.12),
paneMaterial
);
pane.position.set(0, 0.08, -1.45);
scene.add(pane);
// Pixel sun.
const sun = new THREE.Mesh(
new THREE.BoxGeometry(0.88, 0.88, 0.08),
new THREE.MeshBasicMaterial({ color: 0xffdf76 })
);
sun.position.set(3.55, 1.72, -1.31);
scene.add(sun);
// Voxel clouds.
const cloudMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff });
const clouds = [
[-3.1, 1.75, 0.8, 0.28, 0.34],
[-2.45, 1.78, 0.55, 0.45, 0.32],
[-2.8, 2.05, 0.48, 0.36, 0.35],
[0.7, 2.45, 0.65, 0.26, 0.3],
[1.2, 2.42, 0.5, 0.38, 0.28],
[3.25, -0.35, 0.65, 0.25, 0.3]
];
for (const [x, y, w, h, d] of clouds) {
const cloud = new THREE.Mesh(
new THREE.BoxGeometry(w, h, d),
cloudMaterial
);
cloud.position.set(x, y, -1.27);
scene.add(cloud);
}
// Blocky skyline behind the sheer fabric.
const skyline = [
[-4.45, -2.55, 0.8, 1.2, 0x9abcc9],
[-3.45, -2.4, 0.7, 1.5, 0x86adbd],
[-2.55, -2.68, 0.9, 0.85, 0xa9c8d2],
[-1.55, -2.48, 0.65, 1.25, 0x91b5c5],
[-0.65, -2.72, 1.0, 0.75, 0xb0ccd5],
[0.55, -2.48, 0.75, 1.25, 0x82aabd],
[1.55, -2.62, 0.95, 0.95, 0x9fc0cd],
[2.55, -2.42, 0.75, 1.35, 0x7fa5b8],
[3.55, -2.58, 1.0, 1.0, 0x9bbdca],
[4.45, -2.44, 0.7, 1.3, 0x87adbd]
];
for (const [x, y, w, h, color] of skyline) {
const building = new THREE.Mesh(
new THREE.BoxGeometry(w, h, 0.14),
new THREE.MeshBasicMaterial({ color })
);
building.position.set(x, y, -1.24);
scene.add(building);
for (let wx = -w / 2 + 0.17; wx < w / 2 - 0.08; wx += 0.3) {
for (let wy = -h / 2 + 0.22; wy < h / 2 - 0.08; wy += 0.3) {
const windowPixel = new THREE.Mesh(
new THREE.BoxGeometry(0.1, 0.1, 0.025),
new THREE.MeshBasicMaterial({ color: 0xdcecf1 })
);
windowPixel.position.set(
x + wx,
y + wy,
-1.155
);
scene.add(windowPixel);
}
}
}
// Chunky window frame and mullions.
addBox(0.34, 6.55, 0.34, 0x344955, -5.18, 0.08, -0.48);
addBox(0.34, 6.55, 0.34, 0x344955, 5.18, 0.08, -0.48);
addBox(10.7, 0.34, 0.34, 0x344955, 0, 3.32, -0.48);
addBox(10.7, 0.34, 0.34, 0x344955, 0, -3.15, -0.48);
addBox(0.13, 6.2, 0.2, 0x78909c, 0, 0.08, -0.49);
addBox(11.2, 0.32, 0.75, 0x405761, 0, -3.28, -0.24);
// Floor slab and a few voxel highlights.
addBox(16.2, 0.4, 5.0, 0x87979e, 0, -3.88, -0.55);
addBox(2.2, 0.12, 0.55, 0xb9c8cd, -3.2, -3.64, 0.18);
addBox(1.45, 0.12, 0.45, 0xc9d5d9, 2.9, -3.64, 0.1);
// Long voxel curtain rail.
addBox(16.3, 0.15, 0.19, 0x263b47, 0, 3.43, 0.43);
addBox(0.35, 0.35, 0.45, 0x263b47, -8.12, 3.43, 0.43);
addBox(0.35, 0.35, 0.45, 0x263b47, 8.12, 3.43, 0.43);
// A fixed-opacity shader creates the square-grid sheer fabric.
// Alpha blending then naturally applies attenuation twice in overlap.
const sheerVertexShader = `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;
const sheerFragmentShader = `
uniform vec3 uColor;
uniform float uOpacity;
varying vec2 vUv;
void main() {
vec2 grid = fract(vUv * vec2(12.0, 14.0));
float holeX = step(0.15, grid.x) * step(grid.x, 0.85);
float holeY = step(0.14, grid.y) * step(grid.y, 0.86);
float hole = holeX * holeY;
float thread = 1.0 - hole;
float alpha = uOpacity * (0.38 + 0.62 * thread);
vec3 color = uColor * (0.95 + 0.05 * thread);
gl_FragColor = vec4(color, alpha);
#include <tonemapping_fragment>
#include <colorspace_fragment>
}
`;
function createCurtain(key, z, renderOrder) {
const group = new THREE.Group();
const material = new THREE.ShaderMaterial({
uniforms: {
uColor: { value: new THREE.Color(0x50697c) },
uOpacity: { value: 0.58 }
},
vertexShader: sheerVertexShader,
fragmentShader: sheerFragmentShader,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
});
const fabric = new THREE.Mesh(
new THREE.PlaneGeometry(PANEL_WIDTH, PANEL_HEIGHT),
material
);
fabric.position.set(0, 0.05, z);
fabric.renderOrder = renderOrder;
fabric.userData.panelKey = key;
group.add(fabric);
// Voxel hanging tabs.
for (let i = 0; i < 6; i++) {
addBox(
0.14,
0.23,
0.14,
0x344b59,
(i - 2.5) * (PANEL_WIDTH / 6),
3.04,
0.4,
group
);
}
// Small weighted blocks along the bottom hem.
for (let i = 0; i < 7; i++) {
addBox(
0.15,
0.25,
0.16,
0x3f5666,
(i - 3) * (PANEL_WIDTH / 7),
-2.88,
z + 0.06,
group
);
}
scene.add(group);
return { group, fabric, key, z };
}
const curtainA = createCurtain("a", 0.14, 20);
const curtainB = createCurtain("b", 0.23, 21);
const curtains = { a: curtainA, b: curtainB };
const curtainMeshes = [curtainA.fabric, curtainB.fabric];
function overlapInterval() {
if (!state.aOn || !state.bOn) {
return null;
}
const start = Math.max(state.a - HALF_PANEL, state.b - HALF_PANEL);
const end = Math.min(state.a + HALF_PANEL, state.b + HALF_PANEL);
if (end <= start) {
return null;
}
const visibleStart = Math.max(start, -WINDOW_HALF);
const visibleEnd = Math.min(end, WINDOW_HALF);
if (visibleEnd <= visibleStart) {
return null;
}
return {
start: visibleStart,
end: visibleEnd,
width: visibleEnd - visibleStart,
center: (visibleStart + visibleEnd) / 2
};
}
function updateReadout() {
const overlap = overlapInterval();
const percentage = overlap
? Math.min(100, (overlap.width / (WINDOW_HALF * 2)) * 100)
: 0;
overlapValue.textContent = `${percentage.toFixed(1)}%`;
regionValue.textContent = percentage > 0.5 ? "2×" : "1×";
}
function updatePanel(key, value) {
const clamped = THREE.MathUtils.clamp(value, -8, 8);
state[key] = clamped;
curtains[key].group.position.x = clamped;
updateReadout();
updatePresetState();
}
function updatePresetState() {
const presets = {
single: { a: 0, b: 7.6 },
split: { a: -2.35, b: 2.35 },
overlap: { a: -1.15, b: 1.15 },
stack: { a: 0.05, b: 0.15 }
};
presetButtons.forEach((button) => {
const preset = presets[button.dataset.preset];
const matches =
Math.abs(state.a - preset.a) < 0.03 &&
Math.abs(state.b - preset.b) < 0.03;
button.classList.toggle("active", matches);
});
}
function syncUI() {
sliderA.value = state.a;
sliderB.value = state.b;
valueA.textContent = state.a.toFixed(2);
valueB.textContent = state.b.toFixed(2);
showA.checked = state.aOn;
showB.checked = state.bOn;
curtainA.group.visible = state.aOn;
curtainB.group.visible = state.bOn;
updateReadout();
updatePresetState();
}
sliderA.addEventListener("input", () => {
updatePanel("a", Number(sliderA.value));
valueA.textContent = state.a.toFixed(2);
});
sliderB.addEventListener("input", () => {
updatePanel("b", Number(sliderB.value));
valueB.textContent = state.b.toFixed(2);
});
showA.addEventListener("change", () => {
state.aOn = showA.checked;
curtainA.group.visible = state.aOn;
updateReadout();
});
showB.addEventListener("change", () => {
state.bOn = showB.checked;
curtainB.group.visible = state.bOn;
updateReadout();
});
presetButtons.forEach((button) => {
button.addEventListener("click", () => {
const preset = button.dataset.preset;
if (preset === "single") {
state.a = 0;
state.b = 7.6;
} else if (preset === "split") {
state.a = -2.35;
state.b = 2.35;
} else if (preset === "overlap") {
state.a = -1.15;
state.b = 1.15;
} else {
state.a = 0.05;
state.b = 0.15;
}
curtainA.group.position.x = state.a;
curtainB.group.position.x = state.b;
syncUI();
});
});
function updateCamera() {
const radius = 16;
const cosPitch = Math.cos(state.pitch);
camera.position.set(
cameraTarget.x + Math.sin(state.yaw) * cosPitch * radius,
cameraTarget.y + Math.sin(state.pitch) * radius,
cameraTarget.z + Math.cos(state.yaw) * cosPitch * radius
);
camera.lookAt(cameraTarget);
camera.zoom = state.zoom;
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
const aspect = width / height;
const fitWidth = aspect < 1 ? 12.8 : 16.4;
const viewHeight = Math.max(8.3, fitWidth / aspect);
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
renderer.setSize(width, height, false);
updateCamera();
}
window.addEventListener("resize", resize);
// Direct camera interaction, implemented without external controls.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane();
const planeHit = new THREE.Vector3();
let pointerDrag = null;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickCurtain(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const candidates = curtainMeshes.filter((mesh) => {
const key = mesh.userData.panelKey;
return key === "a" ? state.aOn : state.bOn;
});
const hits = raycaster.intersectObjects(candidates, false);
return hits.length ? hits[0].object.userData.panelKey : null;
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
const key = pickCurtain(event);
if (key) {
const curtain = curtains[key];
dragPlane.set(new THREE.Vector3(0, 0, 1), -curtain.z);
pointerDrag = {
type: "panel",
key,
planeZ: curtain.z
};
} else {
pointerDrag = {
type: "camera",
x: event.clientX,
y: event.clientY,
yaw: state.yaw,
pitch: state.pitch
};
}
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDrag) {
canvas.style.cursor = pickCurtain(event) ? "ew-resize" : "grab";
return;
}
if (pointerDrag.type === "panel") {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
dragPlane.set(
new THREE.Vector3(0, 0, 1),
-pointerDrag.planeZ
);
if (raycaster.ray.intersectPlane(dragPlane, planeHit)) {
updatePanel(pointerDrag.key, planeHit.x);
if (pointerDrag.key === "a") {
valueA.textContent = state.a.toFixed(2);
} else {
valueB.textContent = state.b.toFixed(2);
}
}
} else {
const dx = event.clientX - pointerDrag.x;
const dy = event.clientY - pointerDrag.y;
state.yaw = pointerDrag.yaw + dx * 0.005;
state.pitch = THREE.MathUtils.clamp(
pointerDrag.pitch + dy * 0.004,
-0.32,
0.32
);
updateCamera();
}
});
function endPointerDrag(event) {
pointerDrag = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointerDrag);
canvas.addEventListener("pointercancel", endPointerDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const factor = event.deltaY > 0 ? 0.92 : 1.08;
state.zoom = THREE.MathUtils.clamp(
state.zoom * factor,
0.75,
1.65
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
state.yaw = -0.075;
state.pitch = 0.035;
state.zoom = 1;
updateCamera();
});
const projected = new THREE.Vector3();
function positionTag(element, x, y, z, visible = true) {
if (!visible) {
element.style.display = "none";
return;
}
projected.set(x, y, z).project(camera);
const screenX = (projected.x * 0.5 + 0.5) * window.innerWidth;
const screenY = (-projected.y * 0.5 + 0.5) * window.innerHeight;
const onScreen =
screenX > -40 &&
screenX < window.innerWidth + 40 &&
screenY > -40 &&
screenY < window.innerHeight + 40;
element.style.display = onScreen ? "block" : "none";
element.style.left = `${screenX}px`;
element.style.top = `${screenY}px`;
}
function updateTags() {
positionTag(
tagA,
state.a,
3.72,
0.43,
state.aOn
);
positionTag(
tagB,
state.b,
3.72,
0.43,
state.bOn
);
const overlap = overlapInterval();
positionTag(
tagStack,
overlap ? overlap.center : 0,
-2.25,
0.36,
Boolean(overlap && overlap.width > 0.25)
);
}
function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
updateTags();
}
curtainA.group.position.x = state.a;
curtainB.group.position.x = state.b;
syncUI();
resize();
animate();
</script>
</body>
</html>
```