Prompt specification
Build or customize the Three.js 3D scene "Theater lighting and paint studio gallery" 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: Theater lighting and paint studio gallery
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/theater-lighting-and-paint-studio-gallery-x1527
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing additive light mixing and filter transmission. Compose a small stage with colored lamps beside a painter's material table; distinguish modeled light addition from qualitative pigment mixtures and avoid universal pigment-color equations. Voxel style.
Working Three.js Starter (theater-lighting-and-paint-studio-gallery-x1527):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chroma Lab — Additive Light & Pigment</title>
<style>
:root {
--ink: #252824;
--muted: #6e6d64;
--paper: #f4efe4;
--panel: rgba(250, 247, 238, 0.94);
--line: rgba(55, 58, 52, 0.16);
--red: #f05245;
--green: #55b86b;
--blue: #4b83e6;
--shadow: 0 18px 48px rgba(55, 48, 36, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e7e1d5;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
[hidden] {
display: none !important;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.masthead {
position: fixed;
z-index: 5;
top: 24px;
left: 28px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.masthead h1 {
max-width: 520px;
margin: 0;
font-size: clamp(25px, 3vw, 43px);
font-weight: 780;
letter-spacing: -0.045em;
line-height: 0.98;
}
.masthead p {
max-width: 490px;
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.45;
}
.camera-tools {
position: fixed;
z-index: 8;
top: 25px;
right: 25px;
display: flex;
gap: 7px;
}
.icon-button {
display: grid;
width: 39px;
height: 39px;
place-items: center;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(250, 247, 238, 0.88);
box-shadow: 0 8px 24px rgba(58, 51, 39, 0.08);
cursor: pointer;
backdrop-filter: blur(12px);
transition: transform 150ms ease, background 150ms ease;
}
.icon-button:hover {
transform: translateY(-2px);
background: #fffdf7;
}
.icon-button svg {
width: 17px;
height: 17px;
}
.control-panel {
position: fixed;
z-index: 7;
top: 158px;
bottom: 72px;
left: 25px;
width: 342px;
overflow: auto;
border: 1px solid rgba(66, 64, 55, 0.14);
border-radius: 18px;
background: var(--panel);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel-inner {
padding: 18px;
}
.mode-tabs {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 6px;
padding: 5px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(46, 47, 42, 0.055);
}
.mode-tab {
min-height: 47px;
padding: 8px 10px;
border: 0;
border-radius: 8px;
background: transparent;
color: var(--muted);
cursor: pointer;
font-size: 12px;
font-weight: 800;
line-height: 1.15;
transition: background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}
.mode-tab small {
display: block;
margin-top: 3px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mode-tab[aria-selected="true"] {
background: #fffdf7;
color: var(--ink);
box-shadow: 0 3px 12px rgba(45, 43, 36, 0.1);
}
.section-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin: 22px 2px 15px;
}
.section-heading h2 {
margin: 0;
font-size: 15px;
letter-spacing: -0.02em;
}
.model-tag {
padding: 5px 7px;
border: 1px solid var(--line);
border-radius: 6px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
white-space: nowrap;
}
.slider-row {
display: block;
margin-bottom: 14px;
}
.slider-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 7px;
font-size: 12px;
font-weight: 720;
}
.slider-label > span {
display: flex;
align-items: center;
gap: 8px;
}
.slider-label output {
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
}
.dot {
width: 9px;
height: 9px;
border-radius: 2px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.13);
}
.dot.red {
background: var(--red);
}
.dot.green {
background: var(--green);
}
.dot.blue {
background: var(--blue);
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 0;
border-radius: 999px;
accent-color: var(--ink);
cursor: pointer;
}
.light-legend {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 18px;
}
.legend-cell {
min-height: 58px;
padding: 9px 7px;
border: 1px solid var(--line);
border-radius: 9px;
background: rgba(255, 255, 255, 0.38);
text-align: center;
}
.legend-chip {
width: 21px;
height: 21px;
margin: 0 auto 6px;
border-radius: 4px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.legend-cell strong {
display: block;
font-size: 10px;
line-height: 1.1;
}
.legend-cell span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 8px;
}
.model-note {
margin-top: 16px;
padding: 12px 13px;
border-left: 3px solid #444842;
border-radius: 0 9px 9px 0;
background: rgba(42, 45, 40, 0.055);
color: #5c5e56;
font-size: 11px;
line-height: 1.5;
}
.model-note strong {
color: var(--ink);
}
.pair-grid {
display: grid;
grid-template-columns: 1fr;
gap: 7px;
}
.pair-button {
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
gap: 10px;
padding: 10px 11px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.38);
text-align: left;
cursor: pointer;
transition: border 160ms ease, background 160ms ease, transform 160ms ease;
}
.pair-button:hover {
transform: translateX(2px);
background: rgba(255, 255, 255, 0.72);
}
.pair-button[aria-pressed="true"] {
border-color: rgba(41, 43, 39, 0.46);
background: #fffdf7;
box-shadow: 0 4px 13px rgba(43, 41, 35, 0.08);
}
.pair-name {
font-size: 11px;
font-weight: 780;
}
.pair-dots {
display: flex;
gap: 4px;
}
.pair-dots i {
display: block;
width: 12px;
height: 12px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}
.result-card {
display: grid;
grid-template-columns: 78px 1fr;
gap: 13px;
margin-top: 16px;
padding: 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.45);
}
.result-swatch {
min-height: 78px;
border: 5px solid #fffdf7;
border-radius: 8px;
box-shadow: 0 0 0 1px rgba(38, 39, 35, 0.16), 0 8px 16px rgba(41, 37, 30, 0.11);
transition: background 220ms ease;
}
.result-copy small {
display: block;
margin-bottom: 5px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.result-copy h3 {
margin: 0 0 5px;
font-size: 16px;
letter-spacing: -0.025em;
}
.result-copy p {
margin: 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.disclaimer {
margin-top: 15px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 10px;
line-height: 1.5;
}
.disclaimer strong {
color: var(--ink);
}
.mode-badge {
position: fixed;
z-index: 5;
right: 26px;
bottom: 76px;
display: flex;
align-items: center;
gap: 9px;
padding: 10px 13px;
border: 1px solid rgba(55, 55, 49, 0.12);
border-radius: 10px;
background: rgba(250, 247, 238, 0.83);
box-shadow: 0 10px 25px rgba(55, 48, 36, 0.1);
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.07em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.status-dot {
width: 8px;
height: 8px;
border-radius: 2px;
background: var(--red);
box-shadow: 0 0 0 3px rgba(240, 82, 69, 0.13);
}
.camera-hint {
position: fixed;
z-index: 5;
right: 26px;
bottom: 25px;
color: rgba(48, 49, 45, 0.65);
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 760px) {
.masthead {
top: 16px;
left: 16px;
}
.masthead h1 {
max-width: calc(100vw - 95px);
font-size: 26px;
}
.masthead p {
display: none;
}
.camera-tools {
top: 15px;
right: 15px;
}
.control-panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 43vh;
border-radius: 15px;
}
.panel-inner {
padding: 14px;
}
.section-heading {
margin-top: 16px;
}
.mode-badge,
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel stage showing additive light and qualitative pigment mixing"></main>
<header class="masthead">
<div class="eyebrow">Chroma lab · voxel study 01</div>
<h1>Additive light<br>& material color</h1>
<p>Three colored lamps model light addition on a shared surface. The painter’s table shows only qualitative pigment examples.</p>
</header>
<div class="camera-tools" aria-label="Camera controls">
<button class="icon-button" id="zoomIn" type="button" aria-label="Zoom in" title="Zoom in">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="7"></circle><path d="M11 8v6M8 11h6M16.5 16.5 21 21"></path>
</svg>
</button>
<button class="icon-button" id="zoomOut" type="button" aria-label="Zoom out" title="Zoom out">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="7"></circle><path d="M8 11h6M16.5 16.5 21 21"></path>
</svg>
</button>
<button class="icon-button" id="resetCamera" type="button" aria-label="Reset camera" title="Reset camera">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 11a8 8 0 1 0 2-5.3"></path><path d="M4 4v6h6"></path>
</svg>
</button>
</div>
<aside class="control-panel" aria-label="Color model controls">
<div class="panel-inner">
<div class="mode-tabs" role="tablist" aria-label="Color model">
<button class="mode-tab" id="lightTab" data-mode="light" role="tab" aria-selected="true" aria-controls="lightControls">
Additive light
<small>Modeled energy</small>
</button>
<button class="mode-tab" id="pigmentTab" data-mode="pigment" role="tab" aria-selected="false" aria-controls="pigmentControls">
Pigment mixing
<small>Qualitative only</small>
</button>
</div>
<section id="lightControls" role="tabpanel" aria-labelledby="lightTab">
<div class="section-heading">
<h2>Three sources, one surface</h2>
<span class="model-tag">RGB LIGHT MODEL</span>
</div>
<label class="slider-row">
<span class="slider-label">
<span><i class="dot red"></i>Red lamp</span>
<output id="redValue">72%</output>
</span>
<input id="redSlider" type="range" min="0" max="100" value="72" aria-label="Red lamp intensity">
</label>
<label class="slider-row">
<span class="slider-label">
<span><i class="dot green"></i>Green lamp</span>
<output id="greenValue">64%</output>
</span>
<input id="greenSlider" type="range" min="0" max="100" value="64" aria-label="Green lamp intensity">
</label>
<label class="slider-row">
<span class="slider-label">
<span><i class="dot blue"></i>Blue lamp</span>
<output id="blueValue">78%</output>
</span>
<input id="blueSlider" type="range" min="0" max="100" value="78" aria-label="Blue lamp intensity">
</label>
<div class="light-legend" aria-label="Typical additive light overlaps">
<div class="legend-cell">
<div class="legend-chip" style="background:#f6e74d"></div>
<strong>Red + green</strong>
<span>yellow</span>
</div>
<div class="legend-cell">
<div class="legend-chip" style="background:#52e4ef"></div>
<strong>Green + blue</strong>
<span>cyan</span>
</div>
<div class="legend-cell">
<div class="legend-chip" style="background:#ed60dc"></div>
<strong>Red + blue</strong>
<span>magenta</span>
</div>
</div>
<div class="model-note">
<strong>Modeled as light:</strong> each source contributes illumination to the same target. Overlapping contributions brighten. The pixel-like footprints use additive blending, so the central overlap approaches white.
</div>
</section>
<section id="pigmentControls" role="tabpanel" aria-labelledby="pigmentTab" hidden>
<div class="section-heading">
<h2>Choose a pigment pair</h2>
<span class="model-tag">OBSERVATIONAL</span>
</div>
<div class="pair-grid">
<button class="pair-button" type="button" data-pair="yellow-blue" aria-pressed="true">
<span class="pair-name">Yellow + blue</span>
<span class="pair-dots"><i style="background:#e4b92f"></i><i style="background:#315f9f"></i></span>
</button>
<button class="pair-button" type="button" data-pair="yellow-red" aria-pressed="false">
<span class="pair-name">Yellow + red</span>
<span class="pair-dots"><i style="background:#e4b92f"></i><i style="background:#c84d3a"></i></span>
</button>
<button class="pair-button" type="button" data-pair="blue-red" aria-pressed="false">
<span class="pair-name">Blue + red</span>
<span class="pair-dots"><i style="background:#315f9f"></i><i style="background:#c84d3a"></i></span>
</button>
</div>
<div class="result-card" aria-live="polite">
<div class="result-swatch" id="resultSwatch" style="background:#4f8b57"></div>
<div class="result-copy">
<small>Typical family</small>
<h3 id="resultName">Green family</h3>
<p id="resultNote">Often a muted or vivid green, depending on the pigments and mixture.</p>
</div>
</div>
<div class="model-note">
<strong>Not a predictive equation:</strong> these are familiar qualitative outcomes. Actual paint color can shift with pigment identity, binder, concentration, particle size, substrate, lighting, and paint order.
</div>
</section>
<div class="disclaimer">
<strong>Light and pigment are different models.</strong> This scene intentionally does not convert pigment colors with a universal RGB mixing formula.
</div>
</div>
</aside>
<div class="mode-badge">
<span class="status-dot" id="statusDot"></span>
<span id="modeBadgeText">Additive light active</span>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe7e1d5);
scene.fog = new THREE.Fog(0xe7e1d5, 19, 34);
const camera = new THREE.PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 80);
const orbit = {
theta: 0.77,
phi: 1.02,
radius: 15.6,
targetTheta: 0.77,
targetPhi: 1.02,
targetRadius: 15.6,
target: new THREE.Vector3(0.15, 1.7, 0.15)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff8e8, 0x777263, 1.8);
scene.add(hemi);
const keyLight = new THREE.DirectionalLight(0xfff2d8, 2.35);
keyLight.position.set(5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -11;
keyLight.shadow.camera.right = 11;
keyLight.shadow.camera.top = 11;
keyLight.shadow.camera.bottom = -11;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xb8c8db, 0.75);
fillLight.position.set(-8, 5, 6);
scene.add(fillLight);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x4e4a40,
transparent: true,
opacity: 0.25
});
function addBox(width, height, depth, color, x, y, z, parent = scene, options = {}) {
const material = options.material || new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.82,
metalness: options.metalness ?? 0,
flatShading: true
});
const mesh = new THREE.Mesh(new THREE.BoxGeometry(width, height, depth), material);
mesh.position.set(x, y, z);
mesh.castShadow = options.castShadow ?? true;
mesh.receiveShadow = options.receiveShadow ?? true;
parent.add(mesh);
if (options.edges !== false) {
const edges = new THREE.LineSegments(new THREE.EdgesGeometry(mesh.geometry), edgeMaterial);
mesh.add(edges);
}
return mesh;
}
function makeTextPlane(text, width, height, x, y, z, background = "#f6f0e3", foreground = "#373a34") {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 128;
const ctx = canvas.getContext("2d");
ctx.fillStyle = background;
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = foreground;
ctx.font = "800 42px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, canvas.width / 2, canvas.height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.NearestFilter;
texture.magFilter = THREE.NearestFilter;
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({ map: texture })
);
mesh.position.set(x, y, z);
scene.add(mesh);
return mesh;
}
// Tiled voxel stage.
addBox(23, 0.34, 16, 0xc9c0af, 0, -0.35, 0, scene, { edges: false });
const tileGeometry = new THREE.BoxGeometry(1.47, 0.12, 1.47);
const tileMaterial = new THREE.MeshStandardMaterial({ color: 0xffffff, roughness: 0.96 });
const floorTiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, 12 * 8);
const dummy = new THREE.Object3D();
const tileColor = new THREE.Color();
let tileIndex = 0;
for (let row = 0; row < 8; row++) {
for (let col = 0; col < 12; col++) {
dummy.position.set((col - 5.5) * 1.5, -0.13, (row - 3.5) * 1.5);
dummy.updateMatrix();
floorTiles.setMatrixAt(tileIndex, dummy.matrix);
tileColor.set((row + col) % 2 === 0 ? 0xe4ddcf : 0xdcd4c4);
floorTiles.setColorAt(tileIndex, tileColor);
tileIndex++;
}
}
floorTiles.instanceMatrix.needsUpdate = true;
floorTiles.instanceColor.needsUpdate = true;
floorTiles.receiveShadow = true;
scene.add(floorTiles);
// Backdrop wall and little studio details.
addBox(23, 7.6, 0.4, 0xe3dccf, 0, 3.45, -6.25);
addBox(23, 0.26, 0.55, 0x9e8e77, 0, 0.08, -6.02);
addBox(7.7, 0.16, 0.28, 0xb49a79, -3.55, 3.25, -5.96);
makeTextPlane("LIGHT / ADDITIVE", 3.25, 0.7, -1.45, 4.25, -6.01);
makeTextPlane("MATERIAL / PIGMENT", 3.4, 0.7, 3.15, 4.25, -6.01);
// Painter's work table.
const tableGroup = new THREE.Group();
scene.add(tableGroup);
addBox(7.3, 0.34, 4.5, 0x9b6947, 0.55, 2.08, 0.32, tableGroup);
addBox(7.05, 0.13, 4.23, 0xb47b53, 0.55, 2.29, 0.32, tableGroup);
const legPositions = [
[-2.55, -1.45], [3.62, -1.45],
[-2.55, 2.08], [3.62, 2.08]
];
for (const [x, z] of legPositions) {
addBox(0.34, 1.9, 0.34, 0x704b38, x, 1.04, z, tableGroup);
}
addBox(6.45, 0.35, 0.25, 0x80533b, 0.55, 1.7, -1.58, tableGroup);
addBox(6.45, 0.35, 0.25, 0x80533b, 0.55, 1.7, 2.22, tableGroup);
addBox(1.7, 0.62, 0.18, 0x704b38, 1.85, 1.78, 2.55, tableGroup);
addBox(0.55, 0.08, 0.12, 0xcfb57a, 1.85, 1.8, 2.68, tableGroup);
// Matte target panel for the light experiment.
const lightPanelMaterial = new THREE.MeshStandardMaterial({
color: 0x1d2129,
roughness: 0.94,
metalness: 0
});
addBox(4.65, 0.12, 3.1, 0x2a2d31, -0.65, 2.37, 0.12, tableGroup);
addBox(4.42, 0.09, 2.87, 0xffffff, -0.65, 2.44, 0.12, tableGroup, {
material: lightPanelMaterial
});
// Pixel-like additive footprints.
function createPatch(color, centerX, centerZ, y) {
const cells = [];
for (let ix = -5; ix <= 5; ix++) {
for (let iz = -5; iz <= 5; iz++) {
if (Math.sqrt(ix * ix + iz * iz) <= 4.75) {
cells.push([ix * 0.205, iz * 0.205]);
}
}
}
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.3,
blending: THREE.AdditiveBlending,
depthWrite: false,
toneMapped: false
});
const patch = new THREE.InstancedMesh(
new THREE.PlaneGeometry(0.205, 0.205),
material,
cells.length
);
cells.forEach(([px, pz], index) => {
dummy.position.set(centerX + px, y, centerZ + pz);
dummy.rotation.set(-Math.PI / 2, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
patch.setMatrixAt(index, dummy.matrix);
});
patch.instanceMatrix.needsUpdate = true;
patch.renderOrder = 4;
tableGroup.add(patch);
return { mesh: patch, material };
}
const patches = [
createPatch(0xff3027, -1.22, 0.92, 2.493),
createPatch(0x25e663, -0.2, -0.42, 2.494),
createPatch(0x3478ff, 0.82, 0.92, 2.495)
];
function createRectBeam(source, target, startWidth, endWidth) {
const length = source.distanceTo(target);
const vertices = new Float32Array([
-startWidth / 2, -startWidth / 2, 0,
startWidth / 2, -startWidth / 2, 0,
startWidth / 2, startWidth / 2, 0,
-startWidth / 2, startWidth / 2, 0,
-endWidth / 2, -endWidth / 2, -length,
endWidth / 2, -endWidth / 2, -length,
endWidth / 2, endWidth / 2, -length,
-endWidth / 2, endWidth / 2, -length
]);
const indices = [
0, 1, 2, 0, 2, 3,
4, 6, 5, 4, 7, 6,
0, 4, 5, 0, 5, 1,
1, 5, 6, 1, 6, 2,
2, 6, 7, 2, 7, 3,
3, 7, 4, 3, 4, 0
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.BufferAttribute(vertices, 3));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.05,
blending: THREE.AdditiveBlending,
depthWrite: false,
side: THREE.DoubleSide,
toneMapped: false
});
const beam = new THREE.Mesh(geometry, material);
beam.position.copy(source);
beam.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, -1),
target.clone().sub(source).normalize()
);
beam.renderOrder = 2;
scene.add(beam);
return { mesh: beam, material };
}
const lampDefinitions = [
{ color: 0xff4439, source: new THREE.Vector3(-3.48, 4.05, -2.62), target: new THREE.Vector3(-1.22, 2.49, 0.92) },
{ color: 0x37df63, source: new THREE.Vector3(-3.48, 4.05, -0.08), target: new THREE.Vector3(-0.20, 2.49, -0.42) },
{ color: 0x397cff, source: new THREE.Vector3(-3.48, 4.05, 2.35), target: new THREE.Vector3(0.82, 2.49, 0.92) }
];
const lamps = [];
function createLamp(definition) {
const { color, source, target } = definition;
addBox(1.05, 0.3, 1.05, 0x555951, -4.43, 0.18, source.z);
addBox(0.24, 3.75, 0.24, 0x4b5049, -4.43, 2.12, source.z);
addBox(1.2, 0.23, 0.23, 0x4b5049, -4.0, 3.96, source.z);
const direction = target.clone().sub(source).normalize();
const head = addBox(0.82, 0.56, 0.78, color, source.x, source.y, source.z);
head.quaternion.setFromUnitVectors(new THREE.Vector3(0, 0, -1), direction);
const bulbMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 2.4,
roughness: 0.45
});
const bulb = addBox(0.55, 0.35, 0.06, 0xffffff, 0, 0, -0.42, head, {
material: bulbMaterial,
edges: false
});
const spotlight = new THREE.SpotLight(color, 50, 12, 0.38, 0.3, 1.45);
spotlight.position.copy(source);
spotlight.castShadow = true;
spotlight.shadow.mapSize.set(512, 512);
spotlight.shadow.camera.near = 0.2;
spotlight.shadow.camera.far = 12;
spotlight.shadow.bias = -0.0006;
const targetObject = new THREE.Object3D();
targetObject.position.copy(target);
scene.add(targetObject);
spotlight.target = targetObject;
scene.add(spotlight);
const beam = createRectBeam(source, target, 0.48, 1.65);
lamps.push({ spotlight, bulbMaterial, beam, source, target });
}
lampDefinitions.forEach(createLamp);
// Pigment jars and a hand-authored qualitative result palette.
const pigmentGroup = new THREE.Group();
pigmentGroup.visible = false;
scene.add(pigmentGroup);
const pigmentLibrary = {
yellow: { name: "Yellow", color: 0xe4b92f },
blue: { name: "Blue", color: 0x315f9f },
red: { name: "Red", color: 0xc84d3a }
};
const pairResults = {
"yellow-blue": {
color: "#4f8b57",
name: "Green family",
note: "Often a muted or vivid green, depending on the pigments and mixture."
},
"yellow-red": {
color: "#d76b32",
name: "Orange family",
note: "Often reads as orange, though earth pigments can appear browner."
},
"blue-red": {
color: "#765186",
name: "Violet family",
note: "Often reads as violet or purple; some mixtures appear quite dark."
}
};
addBox(1.95, 0.1, 2.03, 0xe2d6bd, 2.82, 2.4, -0.35, pigmentGroup);
const sourceTileMaterials = [
new THREE.MeshStandardMaterial({ color: pigmentLibrary.yellow.color, roughness: 0.9 }),
new THREE.MeshStandardMaterial({ color: pigmentLibrary.blue.color, roughness: 0.9 })
];
addBox(0.5, 0.12, 0.5, 0xffffff, 2.23, 2.5, -0.84, pigmentGroup, {
material: sourceTileMaterials[0]
});
addBox(0.5, 0.12, 0.5, 0xffffff, 2.23, 2.5, 0.12, pigmentGroup, {
material: sourceTileMaterials[1]
});
const resultTileMaterial = new THREE.MeshStandardMaterial({
color: pairResults["yellow-blue"].color,
roughness: 0.86
});
addBox(1.12, 0.15, 1.42, 0xffffff, 3.2, 2.52, -0.35, pigmentGroup, {
material: resultTileMaterial
});
// Small divider blocks between the source pigments and the result.
addBox(0.1, 0.16, 0.72, 0x786e60, 2.72, 2.51, -0.35, pigmentGroup);
const jarGroups = [];
const jarPickables = [];
function createPigmentJar(key, x, z) {
const group = new THREE.Group();
group.position.set(x, 2.4, z);
pigmentGroup.add(group);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xf4eee2,
transparent: true,
opacity: 0.32,
roughness: 0.2,
metalness: 0,
transmission: 0,
depthWrite: false
});
const glass = addBox(0.72, 0.85, 0.72, 0xffffff, 0, 0.43, 0, group, {
material: glassMaterial,
edges: false
});
const pigmentMaterial = new THREE.MeshStandardMaterial({
color: pigmentLibrary[key].color,
roughness: 1
});
const pigment = addBox(0.58, 0.48, 0.58, 0xffffff, 0, 0.24, 0, group, {
material: pigmentMaterial
});
addBox(0.77, 0.12, 0.77, 0x5c5c54, 0, 0.9, 0, group);
addBox(0.31, 0.22, 0.04, pigmentLibrary[key].color, 0, 0.47, 0.37, group, {
edges: false
});
glass.userData.pigment = key;
pigment.userData.pigment = key;
jarPickables.push(glass, pigment);
const record = { key, group, baseScale: 1 };
jarGroups.push(record);
}
createPigmentJar("yellow", 2.12, 1.6);
createPigmentJar("blue", 3.05, 1.6);
createPigmentJar("red", 3.98, 1.6);
// Table accessories: palette knife, brushes, paint tubes and a stool.
addBox(1.25, 0.08, 0.22, 0xb99a63, 1.73, 2.43, 1.82, tableGroup);
addBox(0.55, 0.1, 0.13, 0x424844, 1.18, 2.44, 1.82, tableGroup);
addBox(0.46, 0.05, 0.3, 0xb9b9ad, 2.22, 2.44, 1.82, tableGroup);
addBox(0.5, 0.58, 0.5, 0x8e7053, 0.95, 2.65, -1.48, tableGroup);
for (let i = 0; i < 4; i++) {
const brush = new THREE.Group();
brush.position.set(0.82 + i * 0.08, 3.18, -1.48 + (i - 1.5) * 0.04);
brush.rotation.z = (i - 1.5) * 0.08;
tableGroup.add(brush);
addBox(0.07, 0.9, 0.07, i % 2 ? 0x6c4935 : 0x313a36, 0, 0, 0, brush);
addBox(0.1, 0.2, 0.1, 0xb6a886, 0, 0.53, 0, brush);
addBox(0.13, 0.17, 0.13, 0xded5bf, 0, 0.7, 0, brush);
}
for (let i = 0; i < 3; i++) {
addBox(0.28, 0.75, 0.13, [0xc95043, 0xe1b631, 0x467eb3][i], -4.45 + i * 0.36, 3.47, -5.76, tableGroup);
addBox(0.2, 0.15, 0.14, 0xd8d0bc, -4.45 + i * 0.36, 3.98, -5.76, tableGroup);
}
addBox(1.1, 0.22, 1.0, 0x805943, -1.15, 0.86, 3.6, scene);
for (const [x, z] of [[-1.55, 3.25], [-0.75, 3.25], [-1.55, 3.95], [-0.75, 3.95]]) {
addBox(0.18, 0.75, 0.18, 0x684a38, x, 0.4, z, scene);
}
// Voxel plant.
addBox(0.85, 0.7, 0.85, 0xb96845, 6.45, 0.4, -4.7, scene);
addBox(0.18, 1.2, 0.18, 0x4e6945, 6.45, 1.2, -4.7, scene);
addBox(1.15, 0.24, 0.45, 0x608252, 6.05, 1.55, -4.7, scene);
addBox(0.45, 0.23, 1.05, 0x73915b, 6.82, 1.76, -4.7, scene);
addBox(0.75, 0.22, 0.45, 0x537448, 6.15, 2.0, -4.7, scene);
// State and UI.
const state = {
mode: "light",
intensities: [0.72, 0.64, 0.78],
selectedPigments: ["yellow", "blue"],
lightMix: 1,
hoveredJar: null
};
const sliderIds = ["redSlider", "greenSlider", "blueSlider"];
const outputIds = ["redValue", "greenValue", "blueValue"];
sliderIds.forEach((id, index) => {
document.querySelector(`#${id}`).addEventListener("input", event => {
state.intensities[index] = Number(event.target.value) / 100;
document.querySelector(`#${outputIds[index]}`).value = `${event.target.value}%`;
});
});
function currentPairKey() {
return [...state.selectedPigments].sort().join("-");
}
function updatePigmentResult() {
const key = currentPairKey();
const result = pairResults[key];
if (!result) return;
document.querySelector("#resultSwatch").style.background = result.color;
document.querySelector("#resultName").textContent = result.name;
document.querySelector("#resultNote").textContent = result.note;
document.querySelectorAll(".pair-button").forEach(button => {
button.setAttribute("aria-pressed", String(button.dataset.pair === key));
});
sourceTileMaterials[0].color.setHex(pigmentLibrary[state.selectedPigments[0]].color);
sourceTileMaterials[1].color.setHex(pigmentLibrary[state.selectedPigments[1]].color);
resultTileMaterial.color.set(result.color);
}
document.querySelectorAll(".pair-button").forEach(button => {
button.addEventListener("click", () => {
state.selectedPigments = button.dataset.pair.split("-");
updatePigmentResult();
});
});
function setMode(mode) {
state.mode = mode;
document.querySelector("#lightControls").hidden = mode !== "light";
document.querySelector("#pigmentControls").hidden = mode !== "pigment";
document.querySelectorAll(".mode-tab").forEach(button => {
button.setAttribute("aria-selected", String(button.dataset.mode === mode));
});
pigmentGroup.visible = mode === "pigment";
document.querySelector("#modeBadgeText").textContent =
mode === "light" ? "Additive light active" : "Qualitative pigment examples";
document.querySelector("#statusDot").style.background =
mode === "light" ? "#f05245" : "#55b86b";
}
document.querySelectorAll(".mode-tab").forEach(button => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
updatePigmentResult();
// Direct camera controls implemented here; no controls addon is imported.
let dragging = false;
let dragMoved = false;
let previousX = 0;
let previousY = 0;
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickJar(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(jarPickables, false);
return hits.length ? hits[0].object.userData.pigment : null;
}
renderer.domElement.addEventListener("pointerdown", event => {
dragging = true;
dragMoved = false;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
if (Math.abs(dx) + Math.abs(dy) > 2) dragMoved = true;
orbit.targetTheta -= dx * 0.006;
orbit.targetPhi = THREE.MathUtils.clamp(orbit.targetPhi - dy * 0.005, 0.52, 1.37);
previousX = event.clientX;
previousY = event.clientY;
} else if (state.mode === "pigment") {
const hovered = pickJar(event);
state.hoveredJar = hovered;
renderer.domElement.style.cursor = hovered ? "pointer" : "grab";
}
});
renderer.domElement.addEventListener("pointerup", event => {
if (dragging && !dragMoved && state.mode === "pigment") {
const key = pickJar(event);
if (key) {
if (state.selectedPigments.includes(key)) {
// Keep the selected pair intact when clicking an already selected jar.
} else if (state.selectedPigments.length < 2) {
state.selectedPigments.push(key);
} else {
state.selectedPigments[1] = key;
}
updatePigmentResult();
}
}
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
state.hoveredJar = null;
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
orbit.targetRadius = THREE.MathUtils.clamp(
orbit.targetRadius + event.deltaY * 0.012,
9.5,
23
);
}, { passive: false });
document.querySelector("#resetCamera").addEventListener("click", () => {
orbit.targetTheta = 0.77;
orbit.targetPhi = 1.02;
orbit.targetRadius = 15.6;
});
document.querySelector("#zoomIn").addEventListener("click", () => {
orbit.targetRadius = Math.max(9.5, orbit.targetRadius - 1.4);
});
document.querySelector("#zoomOut").addEventListener("click", () => {
orbit.targetRadius = Math.min(23, orbit.targetRadius + 1.4);
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.8));
});
const clock = new THREE.Clock();
const darkPanel = new THREE.Color(0x1d2129);
const lightPanel = new THREE.Color(0xd8cfbd);
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
const cameraEase = 1 - Math.exp(-dt * 8);
const colorEase = 1 - Math.exp(-dt * 6);
orbit.theta += (orbit.targetTheta - orbit.theta) * cameraEase;
orbit.phi += (orbit.targetPhi - orbit.phi) * cameraEase;
orbit.radius += (orbit.targetRadius - orbit.radius) * cameraEase;
updateCamera();
const lightTarget = state.mode === "light" ? 1 : 0;
state.lightMix += (lightTarget - state.lightMix) * colorEase;
lamps.forEach((lamp, index) => {
const value = state.intensities[index];
lamp.spotlight.intensity = 66 * value * state.lightMix;
lamp.beam.material.opacity = 0.075 * value * state.lightMix;
lamp.bulbMaterial.emissiveIntensity = 1.1 + value * 1.7;
const patch = patches[index];
patch.material.opacity = 0.43 * value * state.lightMix;
});
lightPanelMaterial.color.lerp(
state.mode === "light" ? darkPanel : lightPanel,
colorEase
);
jarGroups.forEach(record => {
const targetScale = state.hoveredJar === record.key ? 1.08 : 1;
const scale = record.group.scale.x + (targetScale - record.group.scale.x) * colorEase;
record.group.scale.setScalar(scale);
});
renderer.render(scene, camera);
});
</script>
</body>
</html>
```