Prompt specification
Build or customize the Three.js 3D scene "Gallery Lighting Design Table" 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: Gallery Lighting Design Table
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/gallery-lighting-design-table-x3287
Scene Description Prompt:
Build a voxel miniature gallery with movable lights and geometric artworks; compare shadows and perceived color. One HTML file using Three.js from cdnjs.
Working Three.js Starter (gallery-lighting-design-table-x3287):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lumen — Voxel Gallery Lab</title>
<style>
:root {
--ink: #202724;
--muted: #69716d;
--paper: #f5f0e7;
--panel: rgba(250, 247, 240, 0.94);
--line: rgba(32, 39, 36, 0.13);
--accent: #ef684f;
--accent-dark: #b84231;
--green: #276b5e;
--shadow: 0 18px 50px rgba(38, 42, 39, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #c9c4ba;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input,
select {
font: inherit;
}
button {
color: inherit;
}
[hidden] {
display: none !important;
}
#scene {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#scene.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 20;
top: 18px;
left: 20px;
right: 20px;
height: 64px;
display: flex;
align-items: center;
justify-content: space-between;
pointer-events: none;
}
.brand,
.top-actions {
pointer-events: auto;
}
.brand {
display: flex;
align-items: center;
gap: 13px;
min-width: 310px;
padding: 10px 15px 10px 11px;
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 16px;
background: rgba(250, 247, 240, 0.88);
box-shadow: 0 8px 30px rgba(38, 42, 39, 0.08);
backdrop-filter: blur(16px);
}
.brand-mark {
position: relative;
width: 39px;
height: 39px;
flex: 0 0 auto;
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
border-radius: 5px;
}
.brand-mark::before {
inset: 4px 12px 12px 4px;
background: var(--accent);
box-shadow: 8px -8px 0 -1px #273d38;
transform: rotate(-8deg);
}
.brand-mark::after {
width: 9px;
height: 9px;
right: 1px;
top: 1px;
background: #f2bd52;
box-shadow: -7px 15px 0 -2px #4e8c80;
}
.brand-title {
font-size: 15px;
font-weight: 800;
letter-spacing: 0.12em;
line-height: 1.05;
}
.brand-subtitle {
margin-top: 5px;
color: var(--muted);
font-size: 10px;
font-weight: 650;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
}
.ui-button {
min-height: 42px;
padding: 0 16px;
border: 1px solid rgba(255, 255, 255, 0.55);
border-radius: 12px;
background: rgba(250, 247, 240, 0.9);
box-shadow: 0 8px 30px rgba(38, 42, 39, 0.08);
backdrop-filter: blur(16px);
cursor: pointer;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: transform 150ms ease, background 150ms ease;
}
.ui-button:hover {
transform: translateY(-1px);
background: #fffaf1;
}
.ui-button.active {
border-color: var(--accent);
background: var(--accent);
color: white;
}
#controlsToggle {
display: none;
}
.panel {
position: fixed;
z-index: 15;
top: 98px;
left: 20px;
width: 330px;
max-height: calc(100vh - 118px);
overflow: auto;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 20px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
scrollbar-width: thin;
scrollbar-color: rgba(32, 39, 36, 0.2) transparent;
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 18px;
}
.eyebrow {
font-size: 9px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
color: var(--muted);
}
.live-badge {
display: flex;
align-items: center;
gap: 6px;
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-badge::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: #47a57d;
box-shadow: 0 0 0 4px rgba(71, 165, 125, 0.12);
}
.section {
padding: 16px 0;
border-top: 1px solid var(--line);
}
.section:first-of-type {
padding-top: 0;
border-top: 0;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
font-size: 12px;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.section-number {
color: var(--accent);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin-bottom: 15px;
padding: 4px;
border-radius: 11px;
background: rgba(32, 39, 36, 0.06);
}
.segmented button {
min-width: 0;
padding: 8px 5px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.segmented button.active {
background: white;
color: var(--ink);
box-shadow: 0 2px 9px rgba(32, 39, 36, 0.08);
}
.field {
margin-top: 12px;
}
.field-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.field-label output {
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 700;
letter-spacing: 0;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 0;
border-radius: 99px;
appearance: none;
background: linear-gradient(90deg, var(--accent) 0 50%, rgba(32, 39, 36, 0.12) 50%);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--accent);
box-shadow: 0 1px 6px rgba(32, 39, 36, 0.28);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 3px solid white;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 1px 6px rgba(32, 39, 36, 0.28);
}
input[type="range"]:disabled {
opacity: 0.35;
cursor: not-allowed;
}
.xyz-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin-top: 12px;
}
.xyz-control {
padding: 8px 9px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.42);
}
.xyz-control label {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
}
.xyz-control input {
width: 100%;
padding: 0;
border: 0;
outline: 0;
background: transparent;
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 11px;
font-weight: 700;
}
.check-row {
display: flex;
align-items: center;
justify-content: space-between;
margin-top: 13px;
color: var(--muted);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.switch {
position: relative;
width: 38px;
height: 21px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch span {
position: absolute;
inset: 0;
border-radius: 99px;
background: rgba(32, 39, 36, 0.18);
cursor: pointer;
transition: background 160ms ease;
}
.switch span::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 15px;
height: 15px;
border-radius: 50%;
background: white;
box-shadow: 0 2px 5px rgba(32, 39, 36, 0.22);
transition: transform 160ms ease;
}
.switch input:checked + span {
background: var(--green);
}
.switch input:checked + span::after {
transform: translateX(17px);
}
.switch input:disabled + span {
opacity: 0.35;
cursor: not-allowed;
}
select {
width: 100%;
height: 39px;
padding: 0 34px 0 11px;
border: 1px solid var(--line);
border-radius: 10px;
outline: none;
background: rgba(255, 255, 255, 0.55);
color: var(--ink);
font-size: 11px;
font-weight: 700;
}
.perception-card {
padding: 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.38);
}
.swatches {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.swatch {
overflow: hidden;
border: 1px solid rgba(32, 39, 36, 0.09);
border-radius: 10px;
background: rgba(255, 255, 255, 0.5);
}
.swatch-color {
height: 42px;
background: #fff2dc;
transition: background 120ms ease;
}
.swatch-copy {
padding: 7px 8px 8px;
}
.swatch-copy strong {
display: block;
font-size: 9px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.swatch-copy span {
display: block;
margin-top: 3px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
}
.metric-row {
display: flex;
justify-content: space-between;
gap: 10px;
margin-top: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.metric-row strong {
color: var(--ink);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
text-align: right;
}
.compare-dock {
position: fixed;
z-index: 18;
left: 50%;
bottom: 21px;
width: min(520px, calc(100vw - 40px));
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.62);
border-radius: 15px;
background: rgba(250, 247, 240, 0.93);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.compare-dock label {
flex: 0 0 auto;
color: var(--muted);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.compare-dock select {
flex: 1 1 auto;
min-width: 0;
}
.compare-dock .ui-button {
min-height: 38px;
box-shadow: none;
}
.compare-labels {
position: fixed;
z-index: 12;
top: 101px;
left: 0;
right: 0;
height: 39px;
pointer-events: none;
}
.compare-label {
position: absolute;
top: 0;
display: flex;
align-items: center;
gap: 9px;
padding: 0 18px;
color: white;
font-size: 10px;
font-weight: 850;
letter-spacing: 0.1em;
text-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
text-transform: uppercase;
}
.compare-label::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: white;
box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.2);
}
#leftCompareLabel {
justify-content: flex-start;
background: linear-gradient(90deg, rgba(24, 31, 29, 0.5), transparent);
}
#rightCompareLabel {
justify-content: flex-end;
background: linear-gradient(270deg, rgba(24, 31, 29, 0.5), transparent);
}
#splitHandle {
position: fixed;
z-index: 14;
top: 0;
bottom: 0;
left: 50%;
width: 30px;
transform: translateX(-50%);
cursor: ew-resize;
touch-action: none;
}
#splitHandle::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
transform: translateX(-50%);
background: rgba(255, 255, 255, 0.82);
box-shadow: 0 0 12px rgba(32, 39, 36, 0.2);
}
#splitHandle span {
position: absolute;
top: 50%;
left: 50%;
display: grid;
width: 32px;
height: 32px;
place-items: center;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.8);
border-radius: 50%;
background: rgba(35, 43, 40, 0.82);
color: white;
font-size: 13px;
box-shadow: 0 4px 14px rgba(32, 39, 36, 0.24);
backdrop-filter: blur(8px);
}
.hint {
position: fixed;
z-index: 10;
right: 20px;
bottom: 22px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(255, 255, 255, 0.45);
border-radius: 12px;
background: rgba(250, 247, 240, 0.78);
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
backdrop-filter: blur(12px);
pointer-events: none;
}
.hint b {
color: var(--ink);
font-weight: 850;
}
.toast {
position: fixed;
z-index: 50;
left: 50%;
bottom: 84px;
padding: 10px 15px;
transform: translate(-50%, 15px);
border-radius: 10px;
background: rgba(30, 37, 34, 0.9);
color: white;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
transform: translate(-50%, 0);
opacity: 1;
}
#loading {
position: fixed;
z-index: 100;
inset: 0;
display: grid;
place-items: center;
background: #d2ccc2;
transition: opacity 350ms ease;
}
#loading.hide {
opacity: 0;
pointer-events: none;
}
.loader {
text-align: center;
}
.loader-cube {
width: 30px;
height: 30px;
margin: 0 auto 15px;
border-radius: 5px;
background: var(--accent);
box-shadow: 10px -10px 0 -2px #2b5148;
animation: loaderPulse 1.1s ease-in-out infinite alternate;
}
.loader span {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
@keyframes loaderPulse {
to {
transform: rotate(8deg) scale(0.9);
}
}
@media (max-width: 900px) {
.hint {
display: none;
}
}
@media (max-width: 720px) {
.topbar {
top: 10px;
left: 10px;
right: 10px;
height: 58px;
}
.brand {
min-width: 0;
padding: 9px 12px 9px 9px;
}
.brand-subtitle {
display: none;
}
.brand-title {
font-size: 12px;
}
.brand-mark {
width: 33px;
height: 33px;
}
.ui-button {
min-height: 38px;
padding: 0 11px;
font-size: 9px;
}
#resetButton {
display: none;
}
#controlsToggle {
display: block;
}
.panel {
top: auto;
bottom: 10px;
left: 10px;
width: calc(100vw - 20px);
max-height: 66vh;
transform: translateY(calc(100% + 24px));
transition: transform 220ms ease;
}
body.controls-open .panel {
transform: translateY(0);
}
.compare-dock {
bottom: 12px;
width: calc(100vw - 20px);
}
body.controls-open .compare-dock {
display: none;
}
.compare-labels {
top: 78px;
}
.compare-label {
padding: 0 8px;
font-size: 8px;
}
.toast {
bottom: 74px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel gallery"></canvas>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-title">LUMEN / 08</div>
<div class="brand-subtitle">Voxel gallery light laboratory</div>
</div>
</div>
<div class="top-actions">
<button class="ui-button" id="resetButton" type="button">Reset room</button>
<button class="ui-button" id="controlsToggle" type="button">Controls</button>
<button class="ui-button" id="compareToggle" type="button">Compare studies</button>
</div>
</header>
<aside class="panel" id="controlPanel">
<div class="panel-heading">
<div class="eyebrow">Control deck</div>
<div class="live-badge">Live scene</div>
</div>
<section class="section">
<div class="section-title">
<span>Movable light</span>
<span class="section-number">01</span>
</div>
<div class="segmented" id="lightTabs">
<button type="button" data-light="key" class="active">Key</button>
<button type="button" data-light="rim">Rim</button>
<button type="button" data-light="fill">Fill</button>
</div>
<div class="field">
<label class="field-label" for="lightTemp">
Color temperature
<output id="lightTempValue">3400 K</output>
</label>
<input id="lightTemp" type="range" min="2200" max="8000" step="50" value="3400" />
</div>
<div class="field">
<label class="field-label" for="lightIntensity">
Intensity
<output id="lightIntensityValue">3.20</output>
</label>
<input id="lightIntensity" type="range" min="0" max="7" step="0.05" value="3.2" />
</div>
<div class="xyz-grid">
<div class="xyz-control">
<label for="lightX">Position X</label>
<input id="lightX" type="number" min="-6" max="6" step="0.1" value="4.5" />
</div>
<div class="xyz-control">
<label for="lightY">Position Y</label>
<input id="lightY" type="number" min="1" max="8" step="0.1" value="7" />
</div>
<div class="xyz-control">
<label for="lightZ">Position Z</label>
<input id="lightZ" type="number" min="-4" max="6" step="0.1" value="5" />
</div>
</div>
<div class="check-row">
<span>Cast shadow</span>
<label class="switch">
<input id="lightShadow" type="checkbox" checked />
<span aria-hidden="true"></span>
</label>
</div>
</section>
<section class="section">
<div class="section-title">
<span>Geometric artwork</span>
<span class="section-number">02</span>
</div>
<select id="artSelect" aria-label="Choose an artwork">
<option value="stack">Chromatic Stack</option>
<option value="field">Signal Field</option>
<option value="orbit">Pixel Orbit</option>
<option value="sculpture">Torus Study</option>
</select>
<div class="field">
<label class="field-label" for="artHue">
Palette hue
<output id="artHueValue">12°</output>
</label>
<input id="artHue" type="range" min="0" max="360" step="1" value="12" />
</div>
<div class="field">
<label class="field-label" for="artRotation">
Rotation
<output id="artRotationValue">0°</output>
</label>
<input id="artRotation" type="range" min="-180" max="180" step="1" value="0" />
</div>
<div class="field">
<label class="field-label" for="artScale">
Scale
<output id="artScaleValue">1.00×</output>
</label>
<input id="artScale" type="range" min="0.55" max="1.45" step="0.01" value="1" />
</div>
<div class="xyz-grid">
<div class="xyz-control">
<label for="artX">Position X</label>
<input id="artX" type="number" min="-6" max="6" step="0.1" value="-3.2" />
</div>
<div class="xyz-control">
<label for="artY">Position Y</label>
<input id="artY" type="number" min="0" max="5" step="0.1" value="2.9" />
</div>
<div class="xyz-control">
<label for="artZ">Position Z</label>
<input id="artZ" type="number" min="-5" max="4" step="0.1" value="-4.36" />
</div>
</div>
</section>
<section class="section">
<div class="section-title">
<span>Perception check</span>
<span class="section-number">03</span>
</div>
<div class="perception-card">
<div class="swatches">
<div class="swatch">
<div class="swatch-color" id="sourceSwatch"></div>
<div class="swatch-copy">
<strong>Current source</strong>
<span id="sourceKelvin">3400 K</span>
</div>
</div>
<div class="swatch">
<div class="swatch-color" style="background: #edf2f7"></div>
<div class="swatch-copy">
<strong>Neutral reference</strong>
<span>5600 K</span>
</div>
</div>
</div>
<div class="metric-row">
<span>Shadow angle</span>
<strong id="shadowAngle">42°</strong>
</div>
<div class="metric-row">
<span>Render exposure</span>
<strong>1.00 / ACES</strong>
</div>
</div>
</section>
</aside>
<div class="compare-labels" id="compareLabels" hidden>
<div class="compare-label" id="leftCompareLabel">5600 K neutral</div>
<div class="compare-label" id="rightCompareLabel">3400 K warm</div>
</div>
<div id="splitHandle" hidden><span>↔</span></div>
<div class="compare-dock" id="compareDock" hidden>
<label for="compareMode">Key light study</label>
<select id="compareMode">
<option value="color">Perceived color</option>
<option value="direction">Shadow direction</option>
<option value="presence">Shadow presence</option>
</select>
<button class="ui-button" id="closeCompare" type="button">Close</button>
</div>
<div class="hint">
<span><b>Drag</b> background to orbit</span>
<span>·</span>
<span><b>Scroll</b> to zoom</span>
<span>·</span>
<span><b>Select</b> a lamp or artwork</span>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div id="loading">
<div class="loader">
<div class="loader-cube"></div>
<span>Building miniature gallery</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 $ = (selector) => document.querySelector(selector);
const canvas = $("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xc9c4ba);
scene.fog = new THREE.Fog(0xc9c4ba, 20, 36);
const mainCamera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const leftCamera = mainCamera.clone();
const rightCamera = mainCamera.clone();
const cameraState = {
target: new THREE.Vector3(0.25, 1.45, -0.45),
radius: 17.2,
theta: 0.68,
phi: 0.93
};
const state = {
selectedLight: "key",
selectedArt: "stack",
compare: false,
compareMode: "color",
split: 0.5,
pointerMode: null,
pointerX: 0,
pointerY: 0
};
const pickables = [];
const lights = {};
const artworks = {};
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane();
const dragPoint = new THREE.Vector3();
const tempVector = new THREE.Vector3();
const selectionBox = new THREE.BoxHelper(scene, 0xef684f);
selectionBox.visible = false;
selectionBox.material.depthTest = false;
selectionBox.material.transparent = true;
selectionBox.material.opacity = 0.9;
scene.add(selectionBox);
const palette = {
base: new THREE.MeshStandardMaterial({ color: 0xb8aa96, roughness: 0.88 }),
floorA: new THREE.MeshStandardMaterial({ color: 0xd9d1c3, roughness: 0.92 }),
floorB: new THREE.MeshStandardMaterial({ color: 0xe6ded0, roughness: 0.92 }),
floorC: new THREE.MeshStandardMaterial({ color: 0xcfc5b5, roughness: 0.94 }),
wallA: new THREE.MeshStandardMaterial({ color: 0xeee7dc, roughness: 0.9 }),
wallB: new THREE.MeshStandardMaterial({ color: 0xe3dacd, roughness: 0.92 }),
trim: new THREE.MeshStandardMaterial({ color: 0x30413c, roughness: 0.78 }),
dark: new THREE.MeshStandardMaterial({ color: 0x28332f, roughness: 0.74 }),
cream: new THREE.MeshStandardMaterial({ color: 0xfaf5e9, roughness: 0.82 }),
wood: new THREE.MeshStandardMaterial({ color: 0xa97952, roughness: 0.86 }),
leaf: new THREE.MeshStandardMaterial({ color: 0x3f806c, roughness: 0.86 }),
pot: new THREE.MeshStandardMaterial({ color: 0xb75d45, roughness: 0.85 }),
ground: new THREE.MeshStandardMaterial({ color: 0xb7b1a7, roughness: 1 })
};
function box(parent, size, position, material, castShadow = true, receiveShadow = true) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(size[0], size[1], size[2]);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = receiveShadow;
parent.add(mesh);
return mesh;
}
function buildRoom() {
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
palette.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.61;
ground.receiveShadow = true;
scene.add(ground);
box(scene, [13.1, 0.58, 10], [0, -0.3, 0], palette.base);
const tileMaterials = [palette.floorA, palette.floorB, palette.floorC];
for (let x = 0; x < 12; x++) {
for (let z = 0; z < 8; z++) {
const material = tileMaterials[(x + z * 2) % tileMaterials.length];
box(
scene,
[1.01, 0.09, 1.01],
[-5.5 + x, 0.025, -3.5 + z],
material,
false,
true
);
}
}
box(scene, [12.75, 5.4, 0.34], [0, 2.62, -4.65], palette.trim);
for (let column = 0; column < 6; column++) {
for (let row = 0; row < 3; row++) {
const material = row === 1 && column % 2 ? palette.wallB : palette.wallA;
box(
scene,
[2.055, 1.74, 0.28],
[-5.125 + column * 2.05, 0.92 + row * 1.75, -4.64],
material,
false,
true
);
}
}
box(scene, [13.15, 0.22, 0.58], [0, 5.39, -4.56], palette.trim);
box(scene, [0.34, 4.75, 6.7], [-6.28, 2.28, -1.55], palette.wallB);
box(scene, [0.58, 0.2, 6.9], [-6.19, 4.75, -1.55], palette.trim);
box(scene, [0.4, 4.6, 0.42], [-6.1, 2.2, -4.38], palette.trim);
// Built-in bench.
box(scene, [2.8, 0.34, 0.85], [-3.7, 0.48, 2.7], palette.wood);
box(scene, [0.32, 0.48, 0.65], [-4.72, 0.23, 2.7], palette.dark);
box(scene, [0.32, 0.48, 0.65], [-2.68, 0.23, 2.7], palette.dark);
// Voxel plant.
const plant = new THREE.Group();
plant.position.set(5.15, 0, -2.55);
scene.add(plant);
box(plant, [0.72, 0.7, 0.72], [0, 0.35, 0], palette.pot);
box(plant, [0.16, 1.2, 0.16], [0, 1.25, 0], palette.dark);
box(plant, [0.72, 0.28, 0.5], [-0.25, 1.55, 0], palette.leaf);
box(plant, [0.55, 0.3, 0.62], [0.28, 1.9, 0], palette.leaf);
box(plant, [0.42, 0.24, 0.48], [-0.1, 2.2, 0], palette.leaf);
// Wall-mounted title blocks.
box(scene, [1.6, 0.16, 0.12], [-4.9, 4.72, -4.35], palette.dark);
box(scene, [1.1, 0.12, 0.12], [-4.9, 4.48, -4.35], palette.trim);
}
function makeFixture() {
const group = new THREE.Group();
const body = box(group, [0.58, 0.48, 0.6], [0, 0, 0], palette.dark);
const hood = box(group, [0.78, 0.12, 0.76], [0, 0.29, 0.02], palette.trim);
const lensMaterial = new THREE.MeshStandardMaterial({
color: 0xffd59a,
emissive: 0xffb45b,
emissiveIntensity: 1.5,
roughness: 0.28
});
const lens = box(group, [0.43, 0.31, 0.08], [0, -0.03, 0.34], lensMaterial, false, false);
group.userData.lens = lens;
group.userData.hood = hood;
scene.add(group);
return group;
}
function addDirectionalLight(id, name, options) {
const light = new THREE.DirectionalLight(0xffffff, options.intensity);
light.castShadow = options.castShadow;
light.shadow.mapSize.set(2048, 2048);
light.shadow.camera.left = -9;
light.shadow.camera.right = 9;
light.shadow.camera.top = 9;
light.shadow.camera.bottom = -9;
light.shadow.camera.near = 0.5;
light.shadow.camera.far = 30;
light.shadow.bias = -0.00035;
light.shadow.normalBias = 0.025;
const target = new THREE.Object3D();
target.position.copy(options.target);
scene.add(target);
light.target = target;
const fixture = makeFixture();
fixture.userData.lightId = id;
const record = {
id,
name,
type: "directional",
light,
target,
fixture,
position: options.position.clone(),
defaultPosition: options.position.clone(),
temperature: options.temperature,
defaultTemperature: options.temperature,
intensity: options.intensity,
defaultIntensity: options.intensity,
castShadow: options.castShadow,
defaultCastShadow: options.castShadow
};
lights[id] = record;
pickables.push(fixture);
return record;
}
function addPointLight(id, name, options) {
const light = new THREE.PointLight(0xffffff, options.intensity, 18, 1.65);
light.castShadow = false;
const fixture = makeFixture();
fixture.userData.lightId = id;
const record = {
id,
name,
type: "point",
light,
target: null,
fixture,
position: options.position.clone(),
defaultPosition: options.position.clone(),
temperature: options.temperature,
defaultTemperature: options.temperature,
intensity: options.intensity,
defaultIntensity: options.intensity,
castShadow: false,
defaultCastShadow: false
};
lights[id] = record;
pickables.push(fixture);
return record;
}
function kelvinToRGB(kelvin) {
const t = Math.max(1000, Math.min(40000, kelvin)) / 100;
let r;
let g;
let b;
if (t <= 66) {
r = 255;
g = 99.4708025861 * Math.log(t) - 161.1195681661;
b = t <= 19
? 0
: 138.5177312231 * Math.log(t - 10) - 305.0447927307;
} else {
r = 329.698727446 * Math.pow(t - 60, -0.1332047592);
g = 288.1221695283 * Math.pow(t - 60, -0.0755148492);
b = 255;
}
return {
r: Math.round(THREE.MathUtils.clamp(r, 0, 255)),
g: Math.round(THREE.MathUtils.clamp(g, 0, 255)),
b: Math.round(THREE.MathUtils.clamp(b, 0, 255))
};
}
function kelvinColor(kelvin) {
const rgb = kelvinToRGB(kelvin);
return new THREE.Color().setRGB(
rgb.r / 255,
rgb.g / 255,
rgb.b / 255,
THREE.SRGBColorSpace
);
}
function kelvinCSS(kelvin) {
const rgb = kelvinToRGB(kelvin);
return `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`;
}
function applyLightState(record) {
const color = kelvinColor(record.temperature);
record.light.position.copy(record.position);
record.light.color.copy(color);
record.light.intensity = record.intensity;
record.light.castShadow = record.castShadow;
record.fixture.position.copy(record.position);
record.fixture.userData.lens.material.color.copy(color);
record.fixture.userData.lens.material.emissive.copy(color);
if (record.target) {
record.fixture.lookAt(record.target.position);
} else {
record.fixture.lookAt(
record.position.x,
Math.max(0, record.position.y - 4),
record.position.z
);
}
}
function createArtMaterial(hue, offset, lightness = 0.55) {
const material = new THREE.MeshStandardMaterial({
color: new THREE.Color().setHSL((hue + offset) % 1, 0.72, lightness),
roughness: 0.63,
metalness: 0.02
});
return material;
}
function addArtVoxel(group, x, y, z, size, hue, offset, materials) {
const material = createArtMaterial(hue, offset);
materials.push({ material, offset });
return box(group, [size, size, size * 0.62], [x, y, z], material);
}
function makeWallArt(id, name, position, pattern, hue) {
const group = new THREE.Group();
group.position.copy(position);
group.userData.artworkId = id;
box(group, [2.7, 2.28, 0.12], [0, 0, 0], palette.cream);
box(group, [2.78, 0.09, 0.18], [0, 1.13, 0.06], palette.dark);
box(group, [2.78, 0.09, 0.18], [0, -1.13, 0.06], palette.dark);
box(group, [0.09, 2.26, 0.18], [-1.35, 0, 0.06], palette.dark);
box(group, [0.09, 2.26, 0.18], [1.35, 0, 0.06], palette.dark);
const materials = [];
const voxelSize = 0.39;
for (const [x, y, colorIndex] of pattern) {
const offset = [0, 0.08, -0.12, 0.16][colorIndex % 4];
const lightness = [0.58, 0.48, 0.66, 0.53][colorIndex % 4];
const material = createArtMaterial(hue, offset, lightness);
materials.push({ material, offset, lightness });
box(
group,
[voxelSize, voxelSize, 0.25],
[x * 0.45, y * 0.45, 0.22],
material
);
}
scene.add(group);
pickables.push(group);
artworks[id] = {
id,
name,
kind: "wall",
group,
materials,
hue,
defaultHue: hue,
rotation: 0,
defaultRotation: 0,
scale: 1,
defaultScale: 1,
defaultPosition: position.clone()
};
}
function makeSculpture() {
const id = "sculpture";
const group = new THREE.Group();
group.position.set(3.35, 0, 1.25);
group.userData.artworkId = id;
box(group, [1.18, 0.72, 1.18], [0, 0.36, 0], palette.cream);
box(group, [1.28, 0.1, 1.28], [0, 0.75, 0], palette.dark);
const materials = [];
const hue = 188;
const positions = [
[-0.65, 1.05, 0],
[0, 1.05, 0],
[0.65, 1.05, 0],
[-0.38, 1.45, 0],
[0.38, 1.45, 0],
[0, 1.85, 0],
[0, 2.25, 0]
];
positions.forEach((position, index) => {
const offset = index % 3 === 0 ? -0.1 : index % 2 === 0 ? 0.09 : 0;
const material = createArtMaterial(hue, offset, index % 2 ? 0.48 : 0.62);
materials.push({ material, offset, lightness: index % 2 ? 0.48 : 0.62 });
box(group, [0.42, 0.42, 0.42], position, material);
});
scene.add(group);
pickables.push(group);
artworks[id] = {
id,
name: "Torus Study",
kind: "plinth",
group,
materials,
hue,
defaultHue: hue,
rotation: 0,
defaultRotation: 0,
scale: 1,
defaultScale: 1,
defaultPosition: group.position.clone()
};
}
function updateArtColor(art) {
for (const entry of art.materials) {
const lightness = entry.lightness ?? 0.55;
entry.material.color.setHSL(
(art.hue + entry.offset) % 1,
0.72,
lightness
);
}
}
function updateArtTransform(art) {
art.group.position.copy(art.group.position);
art.group.scale.setScalar(art.scale);
if (art.kind === "wall") {
art.group.rotation.z = THREE.MathUtils.degToRad(art.rotation);
art.group.rotation.y = 0;
} else {
art.group.rotation.y = THREE.MathUtils.degToRad(art.rotation);
art.group.rotation.z = 0;
}
}
buildRoom();
const hemisphere = new THREE.HemisphereLight(0xe8f1f5, 0x796c5c, 0.85);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight(0xffffff, 0.18);
scene.add(ambient);
addDirectionalLight("key", "Key light", {
position: new THREE.Vector3(4.5, 7, 5),
target: new THREE.Vector3(0, 1.1, -1.1),
temperature: 3400,
intensity: 3.2,
castShadow: true
});
addDirectionalLight("rim", "Rim light", {
position: new THREE.Vector3(-5.1, 4.7, -2.6),
target: new THREE.Vector3(0, 1.9, -2.1),
temperature: 7200,
intensity: 1.15,
castShadow: false
});
addPointLight("fill", "Fill light", {
position: new THREE.Vector3(0.2, 6.2, 3.4),
temperature: 4600,
intensity: 52
});
makeWallArt(
"stack",
"Chromatic Stack",
new THREE.Vector3(-3.2, 2.88, -4.36),
[
[-1, -1, 0],
[-1, 0, 1],
[-1, 1, 2],
[0, -1, 1],
[0, 0, 0],
[0, 1, 3],
[1, -1, 2],
[1, 0, 0],
[1, 1, 1]
],
12
);
makeWallArt(
"field",
"Signal Field",
new THREE.Vector3(0, 2.88, -4.36),
[
[-1, -1, 0],
[0, -1, 1],
[1, -1, 2],
[-1, 0, 3],
[0, 0, 0],
[1, 0, 1],
[-1, 1, 1],
[0, 1, 2],
[1, 1, 3]
],
205
);
makeWallArt(
"orbit",
"Pixel Orbit",
new THREE.Vector3(3.2, 2.88, -4.36),
[
[-1, -2, 0],
[0, -2, 1],
[1, -2, 2],
[-2, -1, 1],
[2, -1, 2],
[-2, 0, 2],
[0, 0, 0],
[2, 0, 3],
[-2, 1, 3],
[2, 1, 1],
[-1, 2, 2],
[0, 2, 3],
[1, 2, 1]
],
44
);
makeSculpture();
Object.values(lights).forEach(applyLightState);
Object.values(artworks).forEach((art) => {
updateArtColor(art);
updateArtTransform(art);
});
function updateCameraRig() {
const { target, radius, theta, phi } = cameraState;
const sinPhi = Math.sin(phi);
const position = new THREE.Vector3(
target.x + radius * sinPhi * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * sinPhi * Math.cos(theta)
);
for (const camera of [mainCamera, leftCamera, rightCamera]) {
camera.position.copy(position);
camera.lookAt(target);
camera.updateMatrixWorld();
}
}
updateCameraRig();
function setRangeFill(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percent = ((value - min) / (max - min)) * 100;
input.style.background = `linear-gradient(90deg, var(--accent) 0 ${percent}%, rgba(32,39,36,.12) ${percent}% 100%)`;
}
function refreshLightUI() {
const record = lights[state.selectedLight];
$("#lightTemp").value = record.temperature;
$("#lightTempValue").textContent = `${Math.round(record.temperature)} K`;
$("#lightIntensity").value = record.intensity;
$("#lightIntensityValue").textContent = record.intensity.toFixed(2);
$("#lightX").value = record.position.x.toFixed(2);
$("#lightY").value = record.position.y.toFixed(2);
$("#lightZ").value = record.position.z.toFixed(2);
$("#lightShadow").checked = record.castShadow;
$("#lightShadow").disabled = record.type === "point";
document.querySelectorAll("[data-light]").forEach((button) => {
button.classList.toggle("active", button.dataset.light === state.selectedLight);
});
$("#sourceSwatch").style.background = kelvinCSS(record.temperature);
$("#sourceKelvin").textContent = `${Math.round(record.temperature)} K`;
if (record.target) {
const dx = record.position.x - record.target.position.x;
const dz = record.position.z - record.target.position.z;
const angle = Math.round((Math.atan2(dx, dz) * 180) / Math.PI);
$("#shadowAngle").textContent = `${angle}°`;
} else {
$("#shadowAngle").textContent = "POINT / SOFT";
}
["#lightTemp", "#lightIntensity"].forEach((selector) => {
setRangeFill($(selector));
});
}
function refreshArtUI() {
const art = artworks[state.selectedArt];
const position = art.group.position;
$("#artSelect").value = art.id;
$("#artHue").value = art.hue;
$("#artHueValue").textContent = `${Math.round(art.hue)}°`;
$("#artRotation").value = art.rotation;
$("#artRotationValue").textContent = `${Math.round(art.rotation)}°`;
$("#artScale").value = art.scale;
$("#artScaleValue").textContent = `${art.scale.toFixed(2)}×`;
$("#artX").value = position.x.toFixed(2);
$("#artY").value = position.y.toFixed(2);
$("#artZ").value = position.z.toFixed(2);
$("#artY").disabled = art.kind === "plinth";
$("#artZ").disabled = art.kind === "wall";
setRangeFill($("#artHue"));
setRangeFill($("#artRotation"));
setRangeFill($("#artScale"));
}
function selectLight(id) {
state.selectedLight = id;
selectionBox.setFromObject(lights[id].fixture);
selectionBox.visible = true;
refreshLightUI();
}
function selectArt(id) {
state.selectedArt = id;
const art = artworks[id];
selectionBox.setFromObject(art.group);
selectionBox.visible = true;
refreshArtUI();
}
function updateSelectedBox() {
if (state.selectedArt && state.selectedArt === "sculpture") {
selectionBox.setFromObject(artworks[state.selectedArt].group);
}
}
document.querySelectorAll("[data-light]").forEach((button) => {
button.addEventListener("click", () => selectLight(button.dataset.light));
});
$("#artSelect").addEventListener("change", (event) => {
selectArt(event.target.value);
});
$("#lightTemp").addEventListener("input", (event) => {
const record = lights[state.selectedLight];
record.temperature = Number(event.target.value);
applyLightState(record);
refreshLightUI();
});
$("#lightIntensity").addEventListener("input", (event) => {
const record = lights[state.selectedLight];
record.intensity = Number(event.target.value);
applyLightState(record);
refreshLightUI();
});
$("#lightShadow").addEventListener("change", (event) => {
const record = lights[state.selectedLight];
record.castShadow = event.target.checked;
applyLightState(record);
refreshLightUI();
});
for (const axis of ["X", "Y", "Z"]) {
$(`#light${axis}`).addEventListener("change", (event) => {
const record = lights[state.selectedLight];
record.position[axis.toLowerCase()] = Number(event.target.value);
applyLightState(record);
refreshLightUI();
});
}
$("#artHue").addEventListener("input", (event) => {
const art = artworks[state.selectedArt];
art.hue = Number(event.target.value);
updateArtColor(art);
refreshArtUI();
});
$("#artRotation").addEventListener("input", (event) => {
const art = artworks[state.selectedArt];
art.rotation = Number(event.target.value);
updateArtTransform(art);
refreshArtUI();
});
$("#artScale").addEventListener("input", (event) => {
const art = artworks[state.selectedArt];
art.scale = Number(event.target.value);
updateArtTransform(art);
refreshArtUI();
});
for (const axis of ["X", "Y", "Z"]) {
$(`#art${axis}`).addEventListener("change", (event) => {
const art = artworks[state.selectedArt];
art.group.position[axis.toLowerCase()] = Number(event.target.value);
updateArtTransform(art);
refreshArtUI();
});
}
function findUserData(object, key) {
let current = object;
while (current) {
if (current.userData[key]) return current.userData[key];
current = current.parent;
}
return null;
}
function cameraForPointer(event) {
const rect = canvas.getBoundingClientRect();
const x = event.clientX - rect.left;
const width = rect.width;
const height = rect.height;
if (!state.compare) {
pointer.x = (x / width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / height) * 2 + 1;
mainCamera.aspect = width / height;
mainCamera.updateProjectionMatrix();
return mainCamera;
}
const splitX = width * state.split;
const useLeft = x <= splitX;
const viewportWidth = useLeft ? splitX : width - splitX;
const localX = useLeft ? x : x - splitX;
pointer.x = (localX / viewportWidth) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / height) * 2 + 1;
const camera = useLeft ? leftCamera : rightCamera;
camera.aspect = viewportWidth / height;
camera.updateProjectionMatrix();
return camera;
}
function pickAt(event) {
const camera = cameraForPointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(pickables, true);
return hits.length ? hits[0] : null;
}
let dragState = null;
function beginObjectDrag(hit, event) {
const lightId = findUserData(hit.object, "lightId");
const artId = findUserData(hit.object, "artworkId");
let object;
let kind;
let normal;
if (lightId) {
selectLight(lightId);
object = lights[lightId].fixture;
kind = "light";
normal = new THREE.Vector3(0, 1, 0);
} else if (artId) {
selectArt(artId);
object = artworks[artId].group;
kind = "art";
normal = artworks[artId].kind === "wall"
? new THREE.Vector3(0, 0, 1)
: new THREE.Vector3(0, 1, 0);
} else {
return;
}
const planePoint = object.position.clone();
dragPlane.setFromNormalAndCoplanarPoint(normal, planePoint);
if (!raycaster.ray.intersectPlane(dragPlane, dragPoint)) return;
dragState = {
kind,
id: lightId || artId,
object,
planePoint: planePoint.clone(),
offset: object.position.clone().sub(dragPoint)
};
state.pointerMode = "object";
canvas.classList.add("dragging");
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
state.pointerX = event.clientX;
state.pointerY = event.clientY;
if (event.button === 0) {
const hit = pickAt(event);
if (hit) {
beginObjectDrag(hit, event);
if (state.pointerMode === "object") return;
}
state.pointerMode = event.shiftKey ? "pan" : "orbit";
} else if (event.button === 1 || event.button === 2) {
state.pointerMode = "pan";
}
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!state.pointerMode) {
const hit = pickAt(event);
canvas.style.cursor = hit ? "pointer" : "grab";
return;
}
const dx = event.clientX - state.pointerX;
const dy = event.clientY - state.pointerY;
state.pointerX = event.clientX;
state.pointerY = event.clientY;
if (state.pointerMode === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.42,
1.38
);
updateCameraRig();
return;
}
if (state.pointerMode === "pan") {
const right = new THREE.Vector3();
const up = new THREE.Vector3();
mainCamera.matrixWorld.extractBasis(right, up, tempVector);
const scale = cameraState.radius * 0.0012;
cameraState.target.addScaledVector(right, -dx * scale);
cameraState.target.addScaledVector(up, dy * scale);
cameraState.target.y = THREE.MathUtils.clamp(cameraState.target.y, 0.5, 3);
updateCameraRig();
return;
}
if (state.pointerMode === "object" && dragState) {
const camera = cameraForPointer(event);
raycaster.setFromCamera(pointer, camera);
if (!raycaster.ray.intersectPlane(dragPlane, dragPoint)) return;
tempVector.copy(dragPoint).add(dragState.offset);
if (dragState.kind === "light") {
const record = lights[dragState.id];
record.position.set(
THREE.MathUtils.clamp(tempVector.x, -6, 6),
THREE.MathUtils.clamp(tempVector.y, 1, 8),
THREE.MathUtils.clamp(tempVector.z, -4, 6)
);
applyLightState(record);
refreshLightUI();
} else {
const art = artworks[dragState.id];
const position = art.group.position;
if (art.kind === "wall") {
position.x = THREE.MathUtils.clamp(tempVector.x, -5, 5);
position.y = THREE.MathUtils.clamp(tempVector.y, 1.25, 4.65);
} else {
position.x = THREE.MathUtils.clamp(tempVector.x, -5, 5);
position.z = THREE.MathUtils.clamp(tempVector.z, -3, 3.6);
}
updateArtTransform(art);
refreshArtUI();
}
}
});
function endPointer(event) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
state.pointerMode = null;
dragState = null;
canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * Math.exp(event.deltaY * 0.001),
10.5,
26
);
updateCameraRig();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.target.set(0.25, 1.45, -0.45);
cameraState.radius = 17.2;
cameraState.theta = 0.68;
cameraState.phi = 0.93;
updateCameraRig();
});
let toastTimer;
function toast(message) {
const element = $("#toast");
element.textContent = message;
element.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => element.classList.remove("show"), 1800);
}
function updateCompareLabels() {
const key = lights.key;
const left = $("#leftCompareLabel");
const right = $("#rightCompareLabel");
if (state.compareMode === "color") {
left.textContent = "5600 K neutral";
right.textContent = `${Math.round(key.temperature)} K current source`;
} else if (state.compareMode === "direction") {
left.textContent = "Original shadow direction";
right.textContent = "Mirrored X position";
} else {
left.textContent = "Shadows on";
right.textContent = "Shadows off";
}
}
function setCompare(enabled) {
state.compare = enabled;
$("#compareDock").hidden = !enabled;
$("#compareLabels").hidden = !enabled;
$("#splitHandle").hidden = !enabled;
$("#compareToggle").classList.toggle("active", enabled);
$("#compareToggle").textContent = enabled ? "Exit compare" : "Compare studies";
updateCompareLabels();
}
$("#compareToggle").addEventListener("click", () => {
setCompare(!state.compare);
if (state.compare) toast("Drag the divider to resize the study");
});
$("#closeCompare").addEventListener("click", () => setCompare(false));
$("#compareMode").addEventListener("change", (event) => {
state.compareMode = event.target.value;
updateCompareLabels();
});
$("#controlsToggle").addEventListener("click", () => {
document.body.classList.toggle("controls-open");
});
const splitHandle = $("#splitHandle");
let splitDragging = false;
splitHandle.addEventListener("pointerdown", (event) => {
splitDragging = true;
splitHandle.setPointerCapture(event.pointerId);
event.stopPropagation();
});
splitHandle.addEventListener("pointermove", (event) => {
if (!splitDragging) return;
const percent = event.clientX / window.innerWidth;
state.split = THREE.MathUtils.clamp(percent, 0.25, 0.75);
splitHandle.style.left = `${state.split * 100}%`;
});
splitHandle.addEventListener("pointerup", (event) => {
splitDragging = false;
if (splitHandle.hasPointerCapture(event.pointerId)) {
splitHandle.releasePointerCapture(event.pointerId);
}
});
function resetRoom() {
Object.values(lights).forEach((record) => {
record.position.copy(record.defaultPosition);
record.temperature = record.defaultTemperature;
record.intensity = record.defaultIntensity;
record.castShadow = record.defaultCastShadow;
applyLightState(record);
});
Object.values(artworks).forEach((art) => {
art.group.position.copy(art.defaultPosition);
art.hue = art.defaultHue;
art.rotation = art.defaultRotation;
art.scale = art.defaultScale;
updateArtColor(art);
updateArtTransform(art);
});
cameraState.target.set(0.25, 1.45, -0.45);
cameraState.radius = 17.2;
cameraState.theta = 0.68;
cameraState.phi = 0.93;
updateCameraRig();
state.selectedLight = "key";
state.selectedArt = "stack";
selectLight("key");
refreshArtUI();
toast("Room reset");
}
$("#resetButton").addEventListener("click", resetRoom);
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement || event.target instanceof HTMLSelectElement) {
return;
}
if (event.key.toLowerCase() === "c") {
setCompare(!state.compare);
}
if (event.key.toLowerCase() === "r") {
resetRoom();
}
if (event.key === "Escape") {
setCompare(false);
document.body.classList.remove("controls-open");
}
});
function configureKeyForPass({ temperature, position, castShadow }) {
const key = lights.key;
key.light.position.copy(position);
key.light.color.copy(kelvinColor(temperature));
key.light.castShadow = castShadow;
key.fixture.position.copy(position);
key.fixture.lookAt(key.target.position);
}
function renderNormal() {
const width = window.innerWidth;
const height = window.innerHeight;
mainCamera.aspect = width / height;
mainCamera.updateProjectionMatrix();
renderer.setScissorTest(false);
renderer.setViewport(0, 0, width, height);
renderer.clear(true, true, true);
applyLightState(lights.key);
renderer.render(scene, mainCamera);
}
function renderComparison() {
const width = window.innerWidth;
const height = window.innerHeight;
const leftWidth = Math.floor(width * state.split);
const rightWidth = width - leftWidth;
const key = lights.key;
leftCamera.aspect = leftWidth / height;
rightCamera.aspect = rightWidth / height;
leftCamera.updateProjectionMatrix();
rightCamera.updateProjectionMatrix();
renderer.setScissorTest(true);
if (state.compareMode === "color") {
configureKeyForPass({
temperature: 5600,
position: key.position,
castShadow: key.castShadow
});
renderer.setViewport(0, 0, leftWidth, height);
renderer.setScissor(0, 0, leftWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, leftCamera);
configureKeyForPass({
temperature: key.temperature,
position: key.position,
castShadow: key.castShadow
});
renderer.setViewport(leftWidth, 0, rightWidth, height);
renderer.setScissor(leftWidth, 0, rightWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, rightCamera);
} else if (state.compareMode === "direction") {
configureKeyForPass({
temperature: key.temperature,
position: key.position,
castShadow: key.castShadow
});
renderer.setViewport(0, 0, leftWidth, height);
renderer.setScissor(0, 0, leftWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, leftCamera);
const mirroredPosition = key.position.clone();
mirroredPosition.x = key.target.position.x * 2 - key.position.x;
configureKeyForPass({
temperature: key.temperature,
position: mirroredPosition,
castShadow: key.castShadow
});
renderer.setViewport(leftWidth, 0, rightWidth, height);
renderer.setScissor(leftWidth, 0, rightWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, rightCamera);
} else {
configureKeyForPass({
temperature: key.temperature,
position: key.position,
castShadow: true
});
renderer.setViewport(0, 0, leftWidth, height);
renderer.setScissor(0, 0, leftWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, leftCamera);
configureKeyForPass({
temperature: key.temperature,
position: key.position,
castShadow: false
});
renderer.setViewport(leftWidth, 0, rightWidth, height);
renderer.setScissor(leftWidth, 0, rightWidth, height);
renderer.clear(true, true, true);
renderer.render(scene, rightCamera);
}
renderer.setScissorTest(false);
applyLightState(key);
}
function resize() {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight, false);
updateCameraRig();
}
window.addEventListener("resize", resize);
refreshLightUI();
refreshArtUI();
selectLight("key");
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
Object.values(lights).forEach((record, index) => {
const lens = record.fixture.userData.lens;
lens.material.emissiveIntensity =
1.25 + Math.sin(elapsed * 2.2 + index * 1.7) * 0.12;
});
updateSelectedBox();
if (state.compare) {
renderComparison();
} else {
renderNormal();
}
}
animate();
requestAnimationFrame(() => {
$("#loading").classList.add("hide");
setTimeout(() => $("#loading").remove(), 400);
});
</script>
</body>
</html>
```