Prompt specification
Build or customize the Three.js 3D scene "Display lighting angle comparison" 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: Display lighting angle comparison
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/display-lighting-angle-comparison-x0190
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: display lighting angle comparison. Move a lamp around a small glass case containing a model; observe changing highlights while an alternate light position keeps the displayed object's front unobscured.
Working Three.js Starter (display-lighting-angle-comparison-x0190):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Voxel Light Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #071014;
--panel: #0c171d;
--panel-2: #111e25;
--line: rgba(165, 210, 220, 0.14);
--text: #e8f1f2;
--muted: #82979f;
--amber: #ffc978;
--cyan: #78ddff;
--radius: 14px;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#app {
display: grid;
grid-template-rows: 72px minmax(0, 1fr) auto;
width: 100%;
height: 100%;
background:
radial-gradient(circle at 72% 24%, rgba(43, 95, 109, 0.12), transparent 38%),
var(--bg);
}
.topbar {
z-index: 10;
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
padding: 0 26px;
border-bottom: 1px solid var(--line);
background: rgba(7, 16, 20, 0.92);
}
.brand {
display: flex;
align-items: center;
gap: 15px;
min-width: 0;
}
.brand-mark {
display: grid;
place-items: center;
width: 37px;
height: 37px;
flex: 0 0 auto;
border: 1px solid rgba(255, 201, 120, 0.4);
background: rgba(255, 201, 120, 0.08);
color: var(--amber);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
transform: rotate(45deg);
}
.brand-mark span {
transform: rotate(-45deg);
}
.brand-copy {
min-width: 0;
}
.eyebrow {
margin: 0 0 3px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.24em;
text-transform: uppercase;
}
h1 {
margin: 0;
overflow: hidden;
font-size: 17px;
font-weight: 650;
letter-spacing: 0.03em;
text-overflow: ellipsis;
white-space: nowrap;
}
.top-meta {
display: flex;
align-items: center;
gap: 18px;
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live {
display: flex;
align-items: center;
gap: 8px;
color: #b8c9cd;
}
.live::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 12px var(--cyan);
content: "";
}
#stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
isolation: isolate;
background: #071014;
}
#scene {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.stage-vignette {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(180deg, rgba(2, 8, 11, 0.28), transparent 20%, transparent 78%, rgba(2, 8, 11, 0.3)),
radial-gradient(circle at center, transparent 48%, rgba(2, 7, 10, 0.26) 100%);
}
.view-label {
position: absolute;
z-index: 4;
top: 22px;
left: 22px;
min-width: 190px;
padding: 12px 14px 11px;
border: 1px solid rgba(176, 220, 229, 0.14);
border-radius: 10px;
background: rgba(7, 16, 20, 0.68);
box-shadow: 0 12px 35px rgba(0, 0, 0, 0.14);
backdrop-filter: blur(12px);
pointer-events: none;
}
.view-label .tag {
display: flex;
align-items: center;
gap: 8px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.view-label .tag::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 9px rgba(255, 201, 120, 0.75);
content: "";
}
.view-label.alt .tag::before {
background: var(--cyan);
box-shadow: 0 0 9px rgba(120, 221, 255, 0.75);
}
.view-label strong {
display: block;
margin-top: 5px;
font-size: 23px;
font-weight: 500;
letter-spacing: -0.03em;
}
.view-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#altLabel {
top: 22px;
left: auto;
}
#altFrame {
position: absolute;
z-index: 3;
display: none;
border: 1px solid rgba(120, 221, 255, 0.22);
pointer-events: none;
}
#separator {
position: absolute;
z-index: 3;
top: 0;
bottom: 0;
display: none;
width: 1px;
background: linear-gradient(
transparent,
rgba(160, 211, 222, 0.28) 16%,
rgba(160, 211, 222, 0.28) 84%,
transparent
);
pointer-events: none;
}
.stage-note {
position: absolute;
z-index: 4;
right: 18px;
bottom: 16px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(172, 199, 205, 0.65);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.stage-note::before {
width: 18px;
height: 1px;
background: rgba(172, 199, 205, 0.45);
content: "";
}
.console {
z-index: 10;
display: grid;
grid-template-columns: 168px repeat(3, minmax(150px, 1fr)) 210px;
gap: 22px;
align-items: center;
min-height: 178px;
padding: 20px 26px 22px;
border-top: 1px solid var(--line);
background:
linear-gradient(90deg, rgba(255, 201, 120, 0.025), transparent 30%),
rgba(9, 18, 23, 0.97);
box-shadow: 0 -20px 50px rgba(0, 0, 0, 0.18);
}
.dial-wrap {
display: flex;
align-items: center;
gap: 15px;
}
.dial {
position: relative;
width: 92px;
height: 92px;
flex: 0 0 auto;
border: 1px solid rgba(177, 220, 229, 0.15);
border-radius: 50%;
background:
radial-gradient(circle, rgba(255, 201, 120, 0.06), transparent 65%),
rgba(255, 255, 255, 0.015);
}
.dial::before,
.dial::after {
position: absolute;
background: rgba(168, 207, 216, 0.13);
content: "";
}
.dial::before {
top: 8px;
bottom: 8px;
left: 50%;
width: 1px;
}
.dial::after {
top: 50%;
right: 8px;
left: 8px;
height: 1px;
}
.dial-center {
position: absolute;
z-index: 2;
top: 50%;
left: 50%;
width: 7px;
height: 7px;
border: 1px solid var(--amber);
border-radius: 50%;
background: #162127;
transform: translate(-50%, -50%);
}
#dialNeedle {
position: absolute;
z-index: 1;
top: 50%;
left: 50%;
width: 1px;
height: 35px;
background: linear-gradient(var(--amber), rgba(255, 201, 120, 0.12));
transform-origin: 50% 100%;
transform: translate(-50%, -100%) rotate(48deg);
}
.dial-copy strong {
display: block;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.08em;
}
.dial-copy span {
display: block;
margin-top: 5px;
color: var(--muted);
font-size: 9px;
line-height: 1.5;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.control {
min-width: 0;
}
.control-heading {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 12px;
}
.control-heading label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.control-heading output {
color: var(--text);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 3px;
margin: 0;
border-radius: 3px;
outline: none;
appearance: none;
background: linear-gradient(90deg, rgba(255, 201, 120, 0.7), rgba(255, 201, 120, 0.12));
cursor: ew-resize;
}
input[type="range"]::-webkit-slider-thumb {
width: 13px;
height: 13px;
border: 2px solid #132027;
border-radius: 50%;
appearance: none;
background: var(--amber);
box-shadow: 0 0 0 1px rgba(255, 201, 120, 0.6);
}
input[type="range"]::-moz-range-thumb {
width: 10px;
height: 10px;
border: 2px solid #132027;
border-radius: 50%;
background: var(--amber);
box-shadow: 0 0 0 1px rgba(255, 201, 120, 0.6);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 9px;
color: rgba(130, 151, 159, 0.7);
font-size: 8px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.actions {
display: flex;
flex-direction: column;
gap: 9px;
}
.presets {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 5px;
}
.preset,
.action-button {
min-height: 30px;
border: 1px solid var(--line);
border-radius: 7px;
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
.preset:hover,
.action-button:hover {
border-color: rgba(255, 201, 120, 0.36);
background: rgba(255, 201, 120, 0.07);
color: var(--text);
}
.action-button {
min-height: 34px;
color: #bacbd0;
}
.action-button.primary {
border-color: rgba(120, 221, 255, 0.25);
background: rgba(120, 221, 255, 0.07);
color: var(--cyan);
}
.action-button.primary[aria-pressed="true"] {
border-color: rgba(120, 221, 255, 0.5);
background: rgba(120, 221, 255, 0.13);
}
.instructions {
color: rgba(130, 151, 159, 0.7);
font-size: 8px;
line-height: 1.5;
text-align: center;
text-transform: uppercase;
}
@media (max-width: 1080px) {
.console {
grid-template-columns: 145px repeat(3, minmax(120px, 1fr));
gap: 16px;
}
.actions {
grid-column: 1 / -1;
display: grid;
grid-template-columns: 1fr 145px 145px;
}
.instructions {
display: none;
}
}
@media (max-width: 720px) {
html,
body {
overflow: auto;
}
#app {
min-height: 100%;
height: auto;
grid-template-rows: 64px 58vh auto;
}
.topbar {
padding: 0 16px;
}
.top-meta > span:not(.live) {
display: none;
}
.brand-mark {
width: 31px;
height: 31px;
}
h1 {
font-size: 14px;
}
#stage {
min-height: 430px;
}
.view-label {
top: 14px;
left: 14px;
min-width: 155px;
padding: 10px 12px;
}
.view-label strong {
font-size: 19px;
}
.stage-note {
display: none;
}
.console {
grid-template-columns: repeat(3, 1fr);
gap: 20px 14px;
padding: 22px 18px 28px;
}
.dial-wrap {
grid-column: 1 / -1;
justify-content: center;
}
.actions {
grid-column: 1 / -1;
grid-template-columns: 1fr 1fr;
}
.presets {
grid-column: 1 / -1;
}
}
@media (prefers-reduced-motion: reduce) {
* {
scroll-behavior: auto !important;
transition: none !important;
}
}
</style>
</head>
<body>
<div id="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark"><span>L3</span></div>
<div class="brand-copy">
<p class="eyebrow">Voxel Lighting Instrument</p>
<h1>Light Angle Lab</h1>
</div>
</div>
<div class="top-meta">
<span>Glass case 02 / Model 07</span>
<span class="live">Live comparison</span>
</div>
</header>
<main id="stage">
<canvas id="scene" tabindex="0" aria-label="Interactive voxel model and movable studio lamp"></canvas>
<div class="stage-vignette"></div>
<div class="view-label" id="activeLabel">
<div class="tag">A / Active key</div>
<strong id="activeAngle">048°</strong>
<small id="activeDescription">Right-front · 38° elevation</small>
</div>
<div class="view-label alt" id="altLabel">
<div class="tag">B / Front-safe alternate</div>
<strong>−42°</strong>
<small>Fixed fill · 30° elevation</small>
</div>
<div id="separator"></div>
<div id="altFrame"></div>
<div class="stage-note">Drag lamp to relight · drag scene to orbit</div>
</main>
<footer class="console">
<div class="dial-wrap">
<div class="dial" aria-hidden="true">
<div id="dialNeedle"></div>
<div class="dial-center"></div>
</div>
<div class="dial-copy">
<strong>Key position</strong>
<span>Drag fixture<br>around case</span>
</div>
</div>
<div class="control">
<div class="control-heading">
<label for="azimuth">Azimuth</label>
<output id="azimuthValue" for="azimuth">048°</output>
</div>
<input id="azimuth" type="range" min="-180" max="180" step="1" value="48">
<div class="range-ends"><span>−180°</span><span>Front 0°</span><span>180°</span></div>
</div>
<div class="control">
<div class="control-heading">
<label for="elevation">Elevation</label>
<output id="elevationValue" for="elevation">38°</output>
</div>
<input id="elevation" type="range" min="8" max="76" step="1" value="38">
<div class="range-ends"><span>Low</span><span>45°</span><span>High</span></div>
</div>
<div class="control">
<div class="control-heading">
<label for="distance">Orbit radius</label>
<output id="distanceValue" for="distance">4.6 m</output>
</div>
<input id="distance" type="range" min="3.4" max="6.2" step="0.05" value="4.55">
<div class="range-ends"><span>Near</span><span>Model</span><span>Far</span></div>
</div>
<div class="actions">
<div class="presets">
<button class="preset" data-azimuth="0" data-elevation="34">Front</button>
<button class="preset" data-azimuth="48" data-elevation="38">3/4</button>
<button class="preset" data-azimuth="112" data-elevation="46">Side</button>
<button class="preset" data-azimuth="165" data-elevation="40">Back</button>
</div>
<button class="action-button primary" id="compareButton" aria-pressed="true">Comparison: on</button>
<button class="action-button" id="resetButton">Reset light + camera</button>
<div class="instructions">Drag: orbit · Shift/right drag: pan · Wheel: zoom</div>
</div>
</footer>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.getElementById("stage");
const canvas = document.getElementById("scene");
const ui = {
activeAngle: document.getElementById("activeAngle"),
activeDescription: document.getElementById("activeDescription"),
altLabel: document.getElementById("altLabel"),
altFrame: document.getElementById("altFrame"),
separator: document.getElementById("separator"),
azimuth: document.getElementById("azimuth"),
elevation: document.getElementById("elevation"),
distance: document.getElementById("distance"),
azimuthValue: document.getElementById("azimuthValue"),
elevationValue: document.getElementById("elevationValue"),
distanceValue: document.getElementById("distanceValue"),
needle: document.getElementById("dialNeedle"),
compareButton: document.getElementById("compareButton"),
resetButton: document.getElementById("resetButton")
};
// ---------------------------------------------------------------------
// Renderer and cameras
// ---------------------------------------------------------------------
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.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.setClearColor(0x071014, 1);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071014);
scene.fog = new THREE.FogExp2(0x071014, 0.035);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 60);
const comparisonCamera = new THREE.PerspectiveCamera(35, 1, 0.1, 60);
const modelTarget = new THREE.Vector3(0, 1.18, 0);
const cameraTarget = new THREE.Vector3(0, 1.18, 0);
const cameraState = {
radius: 6.8,
theta: 0.67,
phi: 1.10
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
const c = Math.cos(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * s * Math.sin(cameraState.theta),
cameraTarget.y + cameraState.radius * c,
cameraTarget.z + cameraState.radius * s * Math.cos(cameraState.theta)
);
camera.lookAt(cameraTarget);
camera.updateMatrixWorld();
}
updateCamera();
comparisonCamera.position.set(1.1, 2.75, 5.45);
comparisonCamera.lookAt(modelTarget);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(0x9dd9ff, 0x24190f, 0.65);
scene.add(hemisphere);
const frontFill = new THREE.DirectionalLight(0xb8ddff, 1.15);
frontFill.position.set(1.7, 4.4, 6.0);
frontFill.target.position.copy(modelTarget);
scene.add(frontFill, frontFill.target);
const rimLight = new THREE.PointLight(0x39c9ff, 20, 9, 2);
rimLight.position.set(-3.1, 3.1, -2.8);
scene.add(rimLight);
const lightTarget = new THREE.Object3D();
lightTarget.position.copy(modelTarget);
scene.add(lightTarget);
const keyLight = new THREE.SpotLight(
0xffcf88,
125,
13,
Math.PI / 7.1,
0.56,
1.45
);
keyLight.target = lightTarget;
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.near = 0.3;
keyLight.shadow.camera.far = 14;
keyLight.shadow.bias = -0.00018;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const alternateLight = new THREE.SpotLight(
0xd8ecff,
125,
13,
Math.PI / 7.1,
0.62,
1.4
);
alternateLight.target = lightTarget;
scene.add(alternateLight);
const lightState = {
azimuth: 48,
elevation: 38,
distance: 4.55
};
const alternatePosition = new THREE.Vector3();
const alternateState = {
azimuth: -42,
elevation: 30,
distance: 4.45
};
function positionFromAngles(azimuth, elevation, distance, out) {
const az = THREE.MathUtils.degToRad(azimuth);
const el = THREE.MathUtils.degToRad(elevation);
const horizontal = distance * Math.cos(el);
return out.set(
modelTarget.x + horizontal * Math.sin(az),
modelTarget.y + distance * Math.sin(el),
modelTarget.z + horizontal * Math.cos(az)
);
}
positionFromAngles(
alternateState.azimuth,
alternateState.elevation,
alternateState.distance,
alternatePosition
);
alternateLight.position.copy(alternatePosition);
// ---------------------------------------------------------------------
// Studio floor and light orbit guides
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.MeshStandardMaterial({
color: 0x0a151a,
roughness: 0.73,
metalness: 0.18
})
);
floor.rotation.x = -Math.PI / 2;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x2c5260, 0x162a32);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.3;
scene.add(grid);
const orbitRadius = 4.55;
const orbitPoints = [];
for (let i = 0; i <= 128; i++) {
const angle = (i / 128) * Math.PI * 2;
orbitPoints.push(
new THREE.Vector3(
Math.sin(angle) * orbitRadius,
0.018,
Math.cos(angle) * orbitRadius
)
);
}
const orbitLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(orbitPoints),
new THREE.LineDashedMaterial({
color: 0x668894,
transparent: true,
opacity: 0.34,
dashSize: 0.11,
gapSize: 0.09
})
);
orbitLine.computeLineDistances();
scene.add(orbitLine);
const tickGeometry = new THREE.BoxGeometry(0.065, 0.025, 0.065);
const tickMaterial = new THREE.MeshStandardMaterial({
color: 0x51717c,
emissive: 0x162c34,
metalness: 0.65,
roughness: 0.3
});
for (let i = 0; i < 12; i++) {
const angle = (i / 12) * Math.PI * 2;
const tick = new THREE.Mesh(tickGeometry, tickMaterial);
tick.position.set(
Math.sin(angle) * orbitRadius,
0.025,
Math.cos(angle) * orbitRadius
);
tick.rotation.y = angle;
scene.add(tick);
}
// ---------------------------------------------------------------------
// Display plinth and glass case
// ---------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
function box(parent, size, position, material, castShadow = 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 = true;
parent.add(mesh);
return mesh;
}
const plinthMaterial = new THREE.MeshStandardMaterial({
color: 0x152027,
metalness: 0.78,
roughness: 0.27
});
const plinthInsetMaterial = new THREE.MeshStandardMaterial({
color: 0x25343a,
metalness: 0.68,
roughness: 0.32
});
box(scene, [3.08, 0.18, 3.08], [0, 0.09, 0], plinthMaterial);
box(scene, [2.66, 0.12, 2.66], [0, 0.23, 0], plinthInsetMaterial);
box(scene, [2.46, 0.07, 2.46], [0, 0.32, 0], plinthMaterial);
const caseGroup = new THREE.Group();
scene.add(caseGroup);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0xb9e8ef,
transparent: true,
opacity: 0.17,
transmission: 0.58,
thickness: 0.08,
ior: 1.45,
roughness: 0.045,
metalness: 0,
side: THREE.DoubleSide,
depthWrite: false
});
const caseWidth = 2.36;
const caseHeight = 2.72;
const caseY = 0.36 + caseHeight / 2;
const half = caseWidth / 2;
box(caseGroup, [caseWidth, caseHeight, 0.028], [0, caseY, half], glassMaterial, false);
box(caseGroup, [caseWidth, caseHeight, 0.028], [0, caseY, -half], glassMaterial, false);
box(caseGroup, [0.028, caseHeight, caseWidth], [half, caseY, 0], glassMaterial, false);
box(caseGroup, [0.028, caseHeight, caseWidth], [-half, caseY, 0], glassMaterial, false);
box(caseGroup, [caseWidth, 0.028, caseWidth], [0, 0.36 + caseHeight, 0], glassMaterial, false);
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x71858d,
metalness: 0.86,
roughness: 0.27,
transparent: true,
opacity: 0.56
});
for (const x of [-half, half]) {
for (const z of [-half, half]) {
box(caseGroup, [0.035, caseHeight + 0.05, 0.035], [x, caseY, z], frameMaterial);
}
}
for (const y of [0.36, 0.36 + caseHeight]) {
box(caseGroup, [caseWidth + 0.04, 0.035, 0.035], [0, y, half], frameMaterial);
box(caseGroup, [caseWidth + 0.04, 0.035, 0.035], [0, y, -half], frameMaterial);
box(caseGroup, [0.035, 0.035, caseWidth + 0.04], [half, y, 0], frameMaterial);
box(caseGroup, [0.035, 0.035, caseWidth + 0.04], [-half, y, 0], frameMaterial);
}
// ---------------------------------------------------------------------
// Voxel fox model
// ---------------------------------------------------------------------
const modelGroup = new THREE.Group();
scene.add(modelGroup);
const goldMaterial = new THREE.MeshStandardMaterial({
color: 0xd89438,
metalness: 0.72,
roughness: 0.22
});
const ivoryMaterial = new THREE.MeshStandardMaterial({
color: 0xead8b9,
metalness: 0.3,
roughness: 0.3
});
const darkMaterial = new THREE.MeshStandardMaterial({
color: 0x171d20,
metalness: 0.65,
roughness: 0.31
});
const gemMaterial = new THREE.MeshStandardMaterial({
color: 0x8aeaff,
emissive: 0x1597b8,
emissiveIntensity: 1.6,
metalness: 0.52,
roughness: 0.14
});
const modelBaseMaterial = new THREE.MeshStandardMaterial({
color: 0x202d32,
metalness: 0.8,
roughness: 0.26
});
box(modelGroup, [1.76, 0.13, 1.42], [0, 0.42, 0], modelBaseMaterial);
box(modelGroup, [1.58, 0.035, 1.24], [0, 0.50, 0], darkMaterial);
// Body and chest
box(modelGroup, [0.86, 0.46, 0.50], [0, 0.87, -0.08], goldMaterial);
box(modelGroup, [0.54, 0.43, 0.37], [0, 0.85, 0.23], ivoryMaterial);
box(modelGroup, [0.54, 0.28, 0.40], [0, 0.72, -0.23], goldMaterial);
// Neck and head
box(modelGroup, [0.37, 0.34, 0.35], [0, 1.14, 0.16], goldMaterial);
box(modelGroup, [0.56, 0.43, 0.44], [0, 1.38, 0.27], goldMaterial);
box(modelGroup, [0.37, 0.24, 0.31], [0, 1.29, 0.59], ivoryMaterial);
box(modelGroup, [0.14, 0.11, 0.085], [0, 1.34, 0.765], darkMaterial);
// Ears
for (const x of [-0.18, 0.18]) {
box(modelGroup, [0.17, 0.32, 0.17], [x, 1.69, 0.24], goldMaterial);
box(modelGroup, [0.08, 0.20, 0.03], [x, 1.69, 0.337], ivoryMaterial);
}
// Eyes
box(modelGroup, [0.075, 0.075, 0.035], [-0.145, 1.46, 0.507], gemMaterial);
box(modelGroup, [0.075, 0.075, 0.035], [0.145, 1.46, 0.507], gemMaterial);
// Legs and paws
for (const x of [-0.27, 0.27]) {
for (const z of [-0.23, 0.17]) {
box(modelGroup, [0.17, 0.39, 0.18], [x, 0.70, z], goldMaterial);
box(modelGroup, [0.19, 0.10, 0.22], [x, 0.51, z + 0.02], ivoryMaterial);
}
}
// Raised voxel tail
box(modelGroup, [0.28, 0.27, 0.34], [0, 0.88, -0.46], goldMaterial);
box(modelGroup, [0.26, 0.26, 0.32], [0, 1.00, -0.69], goldMaterial);
box(modelGroup, [0.24, 0.24, 0.29], [0, 1.16, -0.88], goldMaterial);
box(modelGroup, [0.22, 0.22, 0.24], [0, 1.33, -1.00], ivoryMaterial);
// Small chest gem catches the active highlights.
box(modelGroup, [0.13, 0.13, 0.055], [0, 1.01, 0.425], gemMaterial);
// ---------------------------------------------------------------------
// Visible lamps
// ---------------------------------------------------------------------
function createLamp(color, emissive) {
const group = new THREE.Group();
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x253039,
metalness: 0.84,
roughness: 0.26
});
const trimMaterial = new THREE.MeshStandardMaterial({
color: 0x7f929a,
metalness: 0.9,
roughness: 0.2
});
const lensMaterial = new THREE.MeshStandardMaterial({
color,
emissive,
emissiveIntensity: 3.2,
metalness: 0.15,
roughness: 0.18
});
box(group, [0.44, 0.28, 0.34], [0, 0, -0.05], bodyMaterial);
box(group, [0.50, 0.055, 0.39], [0, 0.15, -0.05], trimMaterial);
box(group, [0.29, 0.19, 0.045], [0, -0.015, 0.145], lensMaterial, false);
const handle = box(group, [0.045, 0.30, 0.045], [0, 0.28, -0.07], trimMaterial);
handle.rotation.z = -0.18;
const glow = new THREE.PointLight(color, 3.5, 1.7, 2);
glow.position.set(0, 0, 0.22);
group.add(glow);
group.userData.lensMaterial = lensMaterial;
group.userData.glow = glow;
return group;
}
const activeLamp = createLamp(0xffc36d, 0xff9e32);
const alternateLamp = createLamp(0xc9eaff, 0x51c8ff);
scene.add(activeLamp, alternateLamp);
alternateLamp.position.copy(alternatePosition);
alternateLamp.lookAt(modelTarget);
alternateLamp.visible = false;
const beamMaterial = new THREE.LineDashedMaterial({
color: 0xffc778,
transparent: true,
opacity: 0.3,
dashSize: 0.12,
gapSize: 0.10
});
const beam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(),
modelTarget.clone()
]),
beamMaterial
);
beam.computeLineDistances();
scene.add(beam);
function normalizeAngle(angle) {
let value = angle;
while (value > 180) value -= 360;
while (value < -180) value += 360;
return value;
}
function updateLight() {
const position = positionFromAngles(
lightState.azimuth,
lightState.elevation,
lightState.distance,
new THREE.Vector3()
);
keyLight.position.copy(position);
activeLamp.position.copy(position);
activeLamp.lookAt(modelTarget);
const positions = beam.geometry.attributes.position;
positions.setXYZ(0, position.x, position.y, position.z);
positions.setXYZ(1, modelTarget.x, modelTarget.y, modelTarget.z);
positions.needsUpdate = true;
beam.computeLineDistances();
const azimuth = Math.round(normalizeAngle(lightState.azimuth));
const elevation = Math.round(lightState.elevation);
ui.azimuth.value = azimuth;
ui.elevation.value = elevation;
ui.distance.value = lightState.distance;
ui.azimuthValue.value = `${String(azimuth).padStart(3, "0")}°`;
ui.elevationValue.value = `${elevation}°`;
ui.distanceValue.value = `${lightState.distance.toFixed(1)} m`;
ui.activeAngle.textContent = `${String(azimuth).padStart(3, "0")}°`;
const direction =
Math.abs(azimuth) < 22 ? "Front" :
Math.abs(azimuth) < 70 ? "Right-front" :
Math.abs(azimuth) < 115 ? "Right side" :
Math.abs(azimuth) < 160 ? "Rear side" : "Back";
ui.activeDescription.textContent =
`${direction} · ${elevation}° elevation`;
ui.needle.style.transform =
`translate(-50%, -100%) rotate(${azimuth}deg)`;
}
updateLight();
// ---------------------------------------------------------------------
// View layout and comparison rendering
// ---------------------------------------------------------------------
let comparisonEnabled = true;
let stageWidth = 1;
let stageHeight = 1;
let mainRect = { x: 0, y: 0, w: 1, h: 1 };
let alternateRect = null;
function updateLayout() {
stageWidth = Math.max(1, stage.clientWidth);
stageHeight = Math.max(1, stage.clientHeight);
renderer.setSize(stageWidth, stageHeight, false);
if (!comparisonEnabled) {
mainRect = { x: 0, y: 0, w: stageWidth, h: stageHeight };
alternateRect = null;
} else if (stageWidth >= 820) {
const split = Math.floor(stageWidth * 0.68);
mainRect = { x: 0, y: 0, w: split, h: stageHeight };
alternateRect = {
x: split,
y: 0,
w: stageWidth - split,
h: stageHeight
};
} else {
mainRect = { x: 0, y: 0, w: stageWidth, h: stageHeight };
const width = Math.min(330, stageWidth * 0.58);
const height = Math.min(270, stageHeight * 0.52);
alternateRect = {
x: stageWidth - width - 12,
y: stageHeight - height - 44,
w: width,
h: height
};
}
camera.aspect = mainRect.w / mainRect.h;
camera.updateProjectionMatrix();
if (alternateRect) {
comparisonCamera.aspect = alternateRect.w / alternateRect.h;
comparisonCamera.updateProjectionMatrix();
ui.altLabel.style.display = "block";
ui.altFrame.style.display = "block";
ui.separator.style.display = "block";
ui.altLabel.style.left = `${alternateRect.x + 14}px`;
ui.altLabel.style.top = `${alternateRect.y + 14}px`;
ui.altLabel.style.width = `${Math.max(150, alternateRect.w - 28)}px`;
ui.altFrame.style.left = `${alternateRect.x}px`;
ui.altFrame.style.top = `${alternateRect.y}px`;
ui.altFrame.style.width = `${alternateRect.w}px`;
ui.altFrame.style.height = `${alternateRect.h}px`;
ui.separator.style.left = `${alternateRect.x}px`;
} else {
ui.altLabel.style.display = "none";
ui.altFrame.style.display = "none";
ui.separator.style.display = "none";
}
}
function renderView(rect, viewCamera) {
const y = stageHeight - rect.y - rect.h;
renderer.setViewport(rect.x, y, rect.w, rect.h);
renderer.setScissor(rect.x, y, rect.w, rect.h);
renderer.render(scene, viewCamera);
}
function renderScene() {
renderer.setScissorTest(true);
// A: user-controlled camera and movable warm key.
keyLight.intensity = 125;
keyLight.castShadow = true;
alternateLight.intensity = 17;
activeLamp.visible = true;
alternateLamp.visible = false;
beam.visible = true;
renderView(mainRect, camera);
// B: fixed front-safe lighting comparison.
if (comparisonEnabled && alternateRect) {
keyLight.intensity = 0;
keyLight.castShadow = false;
alternateLight.intensity = 125;
activeLamp.visible = false;
alternateLamp.visible = true;
beam.visible = false;
renderView(alternateRect, comparisonCamera);
}
renderer.setScissorTest(false);
}
const resizeObserver = new ResizeObserver(updateLayout);
resizeObserver.observe(stage);
window.addEventListener("resize", updateLayout);
updateLayout();
// ---------------------------------------------------------------------
// Direct camera and lamp controls — no external controls addon
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 1, 0),
-modelTarget.y
);
const planePoint = new THREE.Vector3();
let interaction = null;
function pointerInMainView(event) {
const bounds = canvas.getBoundingClientRect();
const x = event.clientX - bounds.left;
const y = event.clientY - bounds.top;
if (x < mainRect.x || x > mainRect.x + mainRect.w) return false;
if (y < mainRect.y || y > mainRect.y + mainRect.h) return false;
if (alternateRect) {
const insideAlternate =
x >= alternateRect.x &&
x <= alternateRect.x + alternateRect.w &&
y >= alternateRect.y &&
y <= alternateRect.y + alternateRect.h;
if (insideAlternate) return false;
}
return true;
}
function setPointerFromEvent(event) {
const bounds = canvas.getBoundingClientRect();
const localX = event.clientX - bounds.left;
const localY = event.clientY - bounds.top;
pointer.x = ((localX - mainRect.x) / mainRect.w) * 2 - 1;
pointer.y = -((localY - mainRect.y) / mainRect.h) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function hitActiveLamp(event) {
setPointerFromEvent(event);
return raycaster.intersectObject(activeLamp, true).length > 0;
}
canvas.addEventListener("pointerdown", (event) => {
if (!pointerInMainView(event)) return;
if (event.button !== 0 && event.button !== 2) return;
canvas.focus({ preventScroll: true });
canvas.setPointerCapture(event.pointerId);
if (event.button === 0 && hitActiveLamp(event)) {
raycaster.ray.intersectPlane(dragPlane, planePoint);
const dx = planePoint.x - modelTarget.x;
const dz = planePoint.z - modelTarget.z;
const pointerAngle = Math.atan2(dx, dz);
const pointerRadius = Math.hypot(dx, dz);
const currentRadius =
lightState.distance * Math.cos(THREE.MathUtils.degToRad(lightState.elevation));
interaction = {
type: "lamp",
angleOffset:
THREE.MathUtils.degToRad(lightState.azimuth) - pointerAngle,
radiusOffset: currentRadius - pointerRadius
};
canvas.style.cursor = "grabbing";
} else {
interaction = {
type: event.shiftKey || event.button === 2 ? "pan" : "orbit",
x: event.clientX,
y: event.clientY
};
canvas.style.cursor = "grabbing";
}
event.preventDefault();
});
canvas.addEventListener("pointermove", (event) => {
if (!interaction) {
if (pointerInMainView(event)) {
canvas.style.cursor = hitActiveLamp(event) ? "grab" : "default";
}
return;
}
if (interaction.type === "lamp") {
setPointerFromEvent(event);
if (raycaster.ray.intersectPlane(dragPlane, planePoint)) {
const dx = planePoint.x - modelTarget.x;
const dz = planePoint.z - modelTarget.z;
const radius = Math.max(0.1, Math.hypot(dx, dz) + interaction.radiusOffset);
const angle = Math.atan2(dx, dz) + interaction.angleOffset;
const elevation = THREE.MathUtils.degToRad(lightState.elevation);
lightState.distance = THREE.MathUtils.clamp(
radius / Math.cos(elevation),
3.4,
6.2
);
lightState.azimuth = normalizeAngle(THREE.MathUtils.radToDeg(angle));
updateLight();
}
} else {
const dx = event.clientX - interaction.x;
const dy = event.clientY - interaction.y;
interaction.x = event.clientX;
interaction.y = event.clientY;
if (interaction.type === "orbit") {
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi + dy * 0.005,
0.50,
1.43
);
updateCamera();
} else {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrixWorld, 1);
const scale = cameraState.radius / stageHeight * 0.85;
cameraTarget.addScaledVector(right, -dx * scale);
cameraTarget.addScaledVector(up, dy * scale);
cameraTarget.x = THREE.MathUtils.clamp(cameraTarget.x, -1.4, 1.4);
cameraTarget.y = THREE.MathUtils.clamp(cameraTarget.y, 0.75, 1.8);
cameraTarget.z = THREE.MathUtils.clamp(cameraTarget.z, -1.4, 1.4);
updateCamera();
}
}
event.preventDefault();
});
function endPointer(event) {
interaction = null;
canvas.style.cursor = "default";
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
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),
4.25,
9.2
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
cameraState.radius = 6.8;
cameraState.theta = 0.67;
cameraState.phi = 1.10;
cameraTarget.set(0, 1.18, 0);
updateCamera();
});
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
lightState.azimuth = normalizeAngle(lightState.azimuth - 2);
break;
case "ArrowRight":
lightState.azimuth = normalizeAngle(lightState.azimuth + 2);
break;
case "ArrowUp":
lightState.elevation = Math.min(76, lightState.elevation + 2);
break;
case "ArrowDown":
lightState.elevation = Math.max(8, lightState.elevation - 2);
break;
case "+":
case "=":
lightState.distance = Math.min(6.2, lightState.distance + 0.1);
break;
case "-":
lightState.distance = Math.max(3.4, lightState.distance - 0.1);
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateLight();
}
});
// ---------------------------------------------------------------------
// UI controls
// ---------------------------------------------------------------------
ui.azimuth.addEventListener("input", (event) => {
lightState.azimuth = Number(event.target.value);
updateLight();
});
ui.elevation.addEventListener("input", (event) => {
lightState.elevation = Number(event.target.value);
updateLight();
});
ui.distance.addEventListener("input", (event) => {
lightState.distance = Number(event.target.value);
updateLight();
});
document.querySelectorAll(".preset").forEach((button) => {
button.addEventListener("click", () => {
lightState.azimuth = Number(button.dataset.azimuth);
lightState.elevation = Number(button.dataset.elevation);
updateLight();
});
});
ui.compareButton.addEventListener("click", () => {
comparisonEnabled = !comparisonEnabled;
ui.compareButton.setAttribute("aria-pressed", String(comparisonEnabled));
ui.compareButton.textContent = `Comparison: ${comparisonEnabled ? "on" : "off"}`;
updateLayout();
});
ui.resetButton.addEventListener("click", () => {
lightState.azimuth = 48;
lightState.elevation = 38;
lightState.distance = 4.55;
cameraState.radius = 6.8;
cameraState.theta = 0.67;
cameraState.phi = 1.10;
cameraTarget.set(0, 1.18, 0);
updateLight();
updateCamera();
});
// ---------------------------------------------------------------------
// Animation
// ---------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
const pulse = 1 + Math.sin(elapsed * 2.2) * 0.07;
activeLamp.userData.glow.intensity = 3.5 * pulse;
activeLamp.userData.lensMaterial.emissiveIntensity = 3.2 * pulse;
alternateLamp.userData.glow.intensity = 3.2 * (2 - pulse);
alternateLamp.userData.lensMaterial.emissiveIntensity =
3.1 * (2 - pulse);
renderScene();
requestAnimationFrame(animate);
}
animate();
</script>
</body>
</html>
```