Prompt specification
Build or customize the Three.js 3D scene "Stall lamp and shadow sample" 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: Stall lamp and shadow sample
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/stall-lamp-and-shadow-sample-x0517
Scene Description Prompt:
Please use Three.js from cdnjs for a stylized scene based on this idea: stall lamp and shadow sample. Model a small serving counter with overhead and side lamps; switch between them to reveal different shadows on products while keeping geometry and exposure comparable. Return one self-contained HTML file.
Working Three.js Starter (stall-lamp-and-shadow-sample-x0517):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stall Light — Shadow Sample</title>
<style>
:root {
--ink: #173b3a;
--muted: #65716f;
--paper: rgba(255, 250, 239, 0.92);
--line: rgba(23, 59, 58, 0.14);
--teal: #26716c;
--coral: #df6f58;
--shadow: 0 18px 55px rgba(34, 46, 48, 0.14);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #d8d4dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active { cursor: grabbing; }
.panel {
position: fixed;
z-index: 10;
border: 1px solid rgba(255, 255, 255, 0.68);
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px) saturate(1.15);
-webkit-backdrop-filter: blur(18px) saturate(1.15);
}
.intro {
top: 22px;
left: 22px;
width: min(380px, calc(100vw - 44px));
padding: 18px 20px 19px;
border-radius: 20px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 9px;
color: var(--coral);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--coral);
box-shadow: 0 0 0 5px rgba(223, 111, 88, 0.12);
}
h1 {
margin: 0;
font-size: clamp(24px, 3.2vw, 38px);
line-height: 1.04;
letter-spacing: -0.045em;
font-weight: 760;
}
.intro p {
max-width: 330px;
margin: 11px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.lock {
top: 22px;
right: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 11px 14px;
border-radius: 14px;
pointer-events: none;
}
.lock-dot {
width: 9px;
height: 9px;
border-radius: 50%;
background: #49a16d;
box-shadow: 0 0 0 5px rgba(73, 161, 109, 0.12);
}
.lock strong {
display: block;
font-size: 10px;
line-height: 1.1;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.lock span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 11px;
}
.controls {
left: 50%;
bottom: 22px;
width: min(570px, calc(100vw - 32px));
padding: 10px;
transform: translateX(-50%);
border-radius: 22px;
}
.control-head {
display: flex;
align-items: center;
justify-content: space-between;
padding: 3px 7px 9px;
gap: 12px;
}
.control-label {
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
white-space: nowrap;
}
#status {
overflow: hidden;
color: var(--ink);
font-size: 11px;
text-align: right;
text-overflow: ellipsis;
white-space: nowrap;
}
.switch {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.mode {
position: relative;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
min-height: 52px;
padding: 10px 14px;
border: 1px solid transparent;
border-radius: 15px;
background: rgba(23, 59, 58, 0.055);
color: var(--muted);
cursor: pointer;
font: inherit;
font-size: 13px;
font-weight: 700;
transition:
color 180ms ease,
background 180ms ease,
transform 180ms ease,
border-color 180ms ease;
}
.mode:hover {
background: rgba(23, 59, 58, 0.09);
transform: translateY(-1px);
}
.mode.active {
border-color: rgba(38, 113, 108, 0.2);
background: var(--teal);
color: #fffdf7;
box-shadow: 0 8px 18px rgba(38, 113, 108, 0.2);
}
.mode[data-mode="side"].active {
background: var(--coral);
border-color: rgba(223, 111, 88, 0.22);
box-shadow: 0 8px 18px rgba(223, 111, 88, 0.2);
}
.mode svg {
width: 25px;
height: 25px;
flex: 0 0 auto;
stroke-width: 1.7;
}
.mode kbd {
position: absolute;
top: 6px;
right: 8px;
opacity: 0.58;
font-family: inherit;
font-size: 9px;
font-weight: 800;
}
.hint {
right: 22px;
bottom: 24px;
padding: 9px 12px;
border-radius: 12px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
text-align: right;
pointer-events: none;
}
.hint strong {
color: var(--ink);
font-weight: 750;
}
#reset {
position: fixed;
z-index: 11;
left: 22px;
bottom: 24px;
width: 38px;
height: 38px;
border: 1px solid rgba(255, 255, 255, 0.7);
border-radius: 12px;
background: var(--paper);
box-shadow: var(--shadow);
color: var(--ink);
cursor: pointer;
}
#reset:hover { transform: translateY(-1px); }
#reset svg {
width: 18px;
height: 18px;
vertical-align: middle;
}
@media (max-width: 760px) {
.intro {
top: 12px;
left: 12px;
width: min(330px, calc(100vw - 24px));
padding: 14px 16px;
border-radius: 16px;
}
.intro p { display: none; }
.lock { top: 12px; right: 12px; }
.lock span { display: none; }
.controls { bottom: 12px; width: calc(100vw - 24px); }
.hint, #reset { display: none; }
}
@media (max-width: 480px) {
.lock { display: none; }
.intro { width: calc(100vw - 24px); }
.control-head { padding-bottom: 7px; }
#status { max-width: 210px; }
.mode { min-height: 48px; padding-inline: 8px; }
}
</style>
</head>
<body>
<header class="panel intro">
<div class="eyebrow">Three.js light study</div>
<h1>One stall.<br />Two shadows.</h1>
<p>
Switch the key light without moving the products. The lamp output, spot cone,
geometry, and camera exposure remain matched for a clean shadow comparison.
</p>
</header>
<aside class="panel lock" aria-label="Comparison settings">
<div class="lock-dot"></div>
<div>
<strong>Exposure locked</strong>
<span>Same output · same cone · 1.05 exposure</span>
</div>
</aside>
<section class="panel controls" aria-label="Lamp controls">
<div class="control-head">
<span class="control-label">Key light</span>
<span id="status" aria-live="polite">Overhead · compact shadows beneath the products</span>
</div>
<div class="switch">
<button class="mode active" data-mode="overhead" aria-pressed="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true">
<path d="M7 3h10M12 3v4M5.5 11 12 7l6.5 4v1h-13z" />
<path d="M9 15c0-1.5 1.2-2.5 3-2.5s3 1 3 2.5c0 2-1.2 3.3-3 5-1.8-1.7-3-3-3-5Z" />
<path d="M8.5 19h7" />
</svg>
Overhead lamp
<kbd>1</kbd>
</button>
<button class="mode" data-mode="side" aria-pressed="false">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" aria-hidden="true">
<path d="M15.5 3v8M12.5 11h6M18 8l3 3-3 3" />
<path d="m14.7 12.5-5.3 5.3 3.5 3.5 5.3-5.3z" />
<path d="m9.4 17.8-2.1 2.1" />
</svg>
Side lamp
<kbd>2</kbd>
</button>
</div>
</section>
<button id="reset" title="Reset camera" aria-label="Reset camera">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
<path d="M4 8V4h4M5.5 5.5A8 8 0 1 1 4 14" />
</svg>
</button>
<div class="panel hint">
<strong>Drag</strong> to orbit · <strong>Scroll</strong> to zoom<br />
Press <strong>1</strong> / <strong>2</strong> to compare
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xd8d4dd);
scene.fog = new THREE.Fog(0xd8d4dd, 12, 25);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
60
);
const cameraTarget = new THREE.Vector3(0, 2.05, 0);
let cameraYaw = -0.58;
let cameraPitch = 1.12;
let cameraRadius = window.innerWidth < 700 ? 10.8 : 9.4;
let cameraTouched = false;
function updateCamera() {
const horizontal = cameraRadius * Math.sin(cameraPitch);
camera.position.set(
cameraTarget.x + horizontal * Math.sin(cameraYaw),
cameraTarget.y + cameraRadius * Math.cos(cameraPitch),
cameraTarget.z + horizontal * Math.cos(cameraYaw)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraYaw = -0.58;
cameraPitch = 1.12;
cameraRadius = window.innerWidth < 700 ? 10.8 : 9.4;
cameraTouched = false;
updateCamera();
}
updateCamera();
// Stable ambient and fill lighting. The switchable key below is the only
// shadow-casting light, and its intensity/angle never changes.
const hemi = new THREE.HemisphereLight(0xe7efff, 0x806557, 0.72);
scene.add(hemi);
const fill = new THREE.DirectionalLight(0xfff1dd, 0.34);
fill.position.set(-4, 6, 7);
scene.add(fill);
const keyLight = new THREE.SpotLight(
0xffefd4,
4.5,
0,
0.62,
0.42,
0
);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.near = 0.1;
keyLight.shadow.camera.far = 18;
keyLight.shadow.bias = -0.00015;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.focus = 1;
scene.add(keyLight);
scene.add(keyLight.target);
const mats = {
ground: new THREE.MeshStandardMaterial({ color: 0xc9bfb8, roughness: 0.95 }),
wall: new THREE.MeshStandardMaterial({ color: 0xdcd8df, roughness: 1 }),
counter: new THREE.MeshStandardMaterial({ color: 0x2d6661, roughness: 0.67 }),
counterDark: new THREE.MeshStandardMaterial({ color: 0x1e4c49, roughness: 0.72 }),
slatA: new THREE.MeshStandardMaterial({ color: 0x34766f, roughness: 0.72 }),
slatB: new THREE.MeshStandardMaterial({ color: 0x3e8278, roughness: 0.7 }),
top: new THREE.MeshStandardMaterial({ color: 0xf1e5cd, roughness: 0.76 }),
coral: new THREE.MeshStandardMaterial({ color: 0xd96e57, roughness: 0.58 }),
gold: new THREE.MeshStandardMaterial({ color: 0xd9a83f, roughness: 0.48, metalness: 0.08 }),
blue: new THREE.MeshStandardMaterial({ color: 0x4d7c91, roughness: 0.54 }),
cream: new THREE.MeshStandardMaterial({ color: 0xfff2d7, roughness: 0.72 }),
green: new THREE.MeshStandardMaterial({ color: 0x72945c, roughness: 0.68 }),
dark: new THREE.MeshStandardMaterial({ color: 0x263c3b, roughness: 0.6 }),
brass: new THREE.MeshStandardMaterial({ color: 0xc69443, roughness: 0.35, metalness: 0.55 })
};
function addMesh(geometry, material, x, y, z, parent = scene, cast = true, receive = true) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addBox(w, h, d, material, x, y, z, parent = scene, cast = true) {
return addMesh(new THREE.BoxGeometry(w, h, d), material, x, y, z, parent, cast, true);
}
function addCylinder(rt, rb, h, material, x, y, z, parent = scene, segments = 24, cast = true) {
return addMesh(
new THREE.CylinderGeometry(rt, rb, h, segments),
material,
x,
y,
z,
parent,
cast,
true
);
}
function cylinderBetween(a, b, radius, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const mesh = addMesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 14),
material,
0,
0,
0,
parent,
true,
true
);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
return mesh;
}
function makeCanvasTexture(width, height, draw) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
draw(ctx, width, height);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
// Background and floor.
const floor = addMesh(
new THREE.PlaneGeometry(40, 40),
mats.ground,
0,
0,
0,
scene,
false,
true
);
floor.rotation.x = -Math.PI / 2;
const wall = addMesh(
new THREE.PlaneGeometry(30, 12),
mats.wall,
0,
5,
-5.5,
scene,
false,
true
);
const wallDiscMat = new THREE.MeshBasicMaterial({ color: 0xe9dfd7 });
addMesh(new THREE.CircleGeometry(1.25, 48), wallDiscMat, -2.0, 3.0, -5.47, scene, false, false);
addMesh(new THREE.CircleGeometry(0.55, 40), wallDiscMat, 2.7, 4.0, -5.46, scene, false, false);
// Soft static contact shadow beneath the stall.
const blobTexture = makeCanvasTexture(256, 256, (ctx, w, h) => {
const gradient = ctx.createRadialGradient(w / 2, h / 2, 8, w / 2, h / 2, w / 2);
gradient.addColorStop(0, "rgba(33,45,45,0.42)");
gradient.addColorStop(0.55, "rgba(33,45,45,0.16)");
gradient.addColorStop(1, "rgba(33,45,45,0)");
ctx.fillStyle = gradient;
ctx.fillRect(0, 0, w, h);
});
const blob = addMesh(
new THREE.PlaneGeometry(7.1, 3.25),
new THREE.MeshBasicMaterial({
map: blobTexture,
transparent: true,
depthWrite: false,
opacity: 0.72
}),
0,
0.012,
0.05,
scene,
false,
false
);
blob.rotation.x = -Math.PI / 2;
// Counter.
addBox(5.45, 1.18, 1.68, mats.counter, 0, 0.83, 0);
addBox(5.62, 0.18, 0.2, mats.counterDark, 0, 0.13, 0.04);
addBox(5.78, 0.2, 2.02, mats.top, 0, 1.52, 0);
for (let i = -6; i <= 6; i++) {
addBox(
0.34,
0.86,
0.075,
i % 2 === 0 ? mats.slatA : mats.slatB,
i * 0.405,
0.82,
0.885
);
}
addBox(5.4, 0.09, 0.09, mats.gold, 0, 1.28, 0.91);
addBox(5.4, 0.07, 0.09, mats.coral, 0, 0.34, 0.91);
const signTexture = makeCanvasTexture(1024, 256, (ctx, w, h) => {
ctx.fillStyle = "#f8ead1";
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = "#d49a3c";
ctx.lineWidth = 10;
ctx.strokeRect(15, 15, w - 30, h - 30);
ctx.textAlign = "center";
ctx.fillStyle = "#234f4b";
ctx.font = "800 92px system-ui, sans-serif";
ctx.fillText("GLOW GOODS", w / 2, 126);
ctx.fillStyle = "#b7654e";
ctx.font = "700 30px system-ui, sans-serif";
ctx.letterSpacing = "6px";
ctx.fillText("SMALL BATCH · STALL 07", w / 2, 192);
});
addBox(3.62, 0.67, 0.07, mats.counterDark, 0, 0.84, 0.96);
const sign = addMesh(
new THREE.PlaneGeometry(3.48, 0.57),
new THREE.MeshBasicMaterial({ map: signTexture }),
0,
0.84,
1.001,
scene,
false,
false
);
// Rear stall frame.
const frameMat = new THREE.MeshStandardMaterial({
color: 0xc76551,
roughness: 0.56,
metalness: 0.08
});
addBox(0.1, 4.75, 0.1, frameMat, -2.68, 2.45, -0.92);
addBox(0.1, 4.75, 0.1, frameMat, 2.68, 2.45, -0.92);
addBox(5.46, 0.11, 0.11, frameMat, 0, 4.81, -0.92);
addBox(5.48, 0.07, 0.07, mats.brass, 0, 4.68, -0.92);
// Product helpers.
function productLabel(text, sub, background = "#f8ead1", foreground = "#214e4a") {
const texture = makeCanvasTexture(512, 256, (ctx, w, h) => {
ctx.fillStyle = background;
ctx.fillRect(0, 0, w, h);
ctx.strokeStyle = foreground;
ctx.globalAlpha = 0.35;
ctx.lineWidth = 8;
ctx.strokeRect(12, 12, w - 24, h - 24);
ctx.globalAlpha = 1;
ctx.textAlign = "center";
ctx.fillStyle = foreground;
ctx.font = "800 72px system-ui, sans-serif";
ctx.fillText(text, w / 2, 116);
ctx.font = "700 27px system-ui, sans-serif";
ctx.fillText(sub, w / 2, 177);
});
return new THREE.MeshBasicMaterial({ map: texture });
}
function makeBottle(x, z, colorMaterial, labelText, sub, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.64, z);
group.rotation.y = rotation;
scene.add(group);
const points = [
new THREE.Vector2(0, 0),
new THREE.Vector2(0.24, 0),
new THREE.Vector2(0.29, 0.045),
new THREE.Vector2(0.29, 0.62),
new THREE.Vector2(0.245, 0.74),
new THREE.Vector2(0.13, 0.84),
new THREE.Vector2(0.13, 1.03)
];
addMesh(new THREE.LatheGeometry(points, 24), colorMaterial, 0, 0, 0, group);
addCylinder(0.298, 0.298, 0.24, mats.cream, 0, 0.34, 0, group, 24, false);
addCylinder(0.153, 0.153, 0.17, mats.dark, 0, 1.08, 0, group, 20);
addBox(0.32, 0.15, 0.012, productLabel(labelText, sub), 0, 0.35, 0.301, group, false);
return group;
}
function makeJar(x, z, colorMaterial, labelText, sub, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.64, z);
group.rotation.y = rotation;
scene.add(group);
addCylinder(0.3, 0.3, 0.55, colorMaterial, 0, 0.275, 0, group);
addCylinder(0.325, 0.325, 0.085, mats.brass, 0, 0.59, 0, group);
addBox(0.31, 0.17, 0.012, productLabel(labelText, sub), 0, 0.3, 0.306, group, false);
return group;
}
function makeCan(x, z, colorMaterial, labelText, sub, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.64, z);
group.rotation.y = rotation;
scene.add(group);
addCylinder(0.22, 0.22, 0.58, colorMaterial, 0, 0.29, 0, group);
addCylinder(0.235, 0.235, 0.045, mats.brass, 0, 0.59, 0, group);
addBox(0.25, 0.15, 0.012, productLabel(labelText, sub), 0, 0.31, 0.226, group, false);
return group;
}
function makeBoxProduct(x, z, colorMaterial, labelText, sub, rotation = 0) {
const group = new THREE.Group();
group.position.set(x, 1.64, z);
group.rotation.y = rotation;
scene.add(group);
addBox(0.66, 0.64, 0.56, colorMaterial, 0, 0.32, 0, group);
addBox(0.7, 0.055, 0.6, mats.cream, 0, 0.665, 0, group);
addBox(0.36, 0.19, 0.012, productLabel(labelText, sub), 0, 0.34, 0.286, group, false);
return group;
}
function makeFruitPlate() {
const group = new THREE.Group();
group.position.set(1.94, 1.64, 0.06);
scene.add(group);
addCylinder(0.59, 0.55, 0.07, mats.cream, 0, 0.035, 0, group, 32);
const fruitData = [
[-0.22, 0.22, 0.2, mats.coral],
[0.05, 0.28, 0.21, mats.gold],
[0.26, 0.12, 0.19, mats.green],
[0.02, 0.02, 0.21, mats.coral],
[-0.19, -0.07, 0.18, mats.gold]
];
fruitData.forEach(([x, z, radius, material], index) => {
const fruit = addMesh(
new THREE.SphereGeometry(radius, 18, 12),
material,
x,
0.23 + (index % 2) * 0.04,
z,
group
);
fruit.scale.y = 0.94;
const stem = addMesh(
new THREE.CylinderGeometry(0.018, 0.024, 0.12, 8),
mats.dark,
x,
0.43 + (index % 2) * 0.04,
z,
group
);
stem.rotation.z = index % 2 ? 0.18 : -0.18;
});
}
// Arranged so both compact overhead shadows and long side shadows are visible.
makeBottle(-2.12, 0.34, mats.coral, "TONIC", "CITRUS", -0.08);
makeJar(-1.25, 0.43, mats.gold, "HONEY", "WILD", 0.05);
makeCan(-0.53, 0.47, mats.blue, "SALT", "SEA", -0.04);
makeBoxProduct(0.23, 0.36, mats.coral, "SPICE", "WARM", -0.05);
makeBoxProduct(1.02, 0.41, mats.green, "TEA", "LEAF", 0.04);
makeFruitPlate();
makeJar(-1.62, -0.42, mats.blue, "JAM", "BERRY", -0.08);
makeBottle(-0.77, -0.46, mats.green, "SODA", "MINT", 0.07);
makeCan(0.09, -0.48, mats.coral, "OIL", "OLIVE", 0.03);
makeBoxProduct(0.86, -0.43, mats.gold, "COFFEE", "ROAST", -0.07);
// Overhead lamp fixture.
const overheadBulbMat = new THREE.MeshStandardMaterial({
color: 0xffefcb,
emissive: 0xffc66f,
emissiveIntensity: 3,
roughness: 0.32
});
const sideBulbMat = new THREE.MeshStandardMaterial({
color: 0xffefcb,
emissive: 0xffc66f,
emissiveIntensity: 0.08,
roughness: 0.32
});
const overheadShadeMat = new THREE.MeshStandardMaterial({
color: 0x285f5b,
roughness: 0.43,
metalness: 0.16,
side: THREE.DoubleSide
});
const overheadLamp = new THREE.Group();
overheadLamp.position.set(-0.24, 4.43, 0.05);
scene.add(overheadLamp);
const overheadCone = addMesh(
new THREE.ConeGeometry(0.55, 0.42, 32, 1, true),
overheadShadeMat,
0,
0,
0,
overheadLamp,
false,
false
);
const overheadRim = addMesh(
new THREE.TorusGeometry(0.55, 0.024, 8, 36),
mats.brass,
0,
-0.21,
0,
overheadLamp,
false,
false
);
overheadRim.rotation.x = Math.PI / 2;
addMesh(
new THREE.SphereGeometry(0.105, 16, 12),
overheadBulbMat,
0,
-0.07,
0,
overheadLamp,
false,
false
);
cylinderBetween(
new THREE.Vector3(-0.24, 4.86, -0.92),
new THREE.Vector3(-0.24, 4.86, 0.05),
0.045,
mats.brass
);
cylinderBetween(
new THREE.Vector3(-0.24, 4.86, 0.05),
new THREE.Vector3(-0.24, 4.65, 0.05),
0.018,
mats.dark
);
// Side lamp fixture.
const sideShadeMat = new THREE.MeshStandardMaterial({
color: 0xd56d57,
roughness: 0.4,
metalness: 0.13,
side: THREE.DoubleSide
});
addCylinder(0.34, 0.4, 0.12, mats.counterDark, 3.76, 0.07, 0.94);
cylinderBetween(
new THREE.Vector3(3.76, 0.12, 0.94),
new THREE.Vector3(3.76, 2.95, 0.94),
0.042,
mats.brass
);
const sideLamp = new THREE.Group();
sideLamp.position.set(3.38, 3.32, 0.79);
scene.add(sideLamp);
addMesh(
new THREE.ConeGeometry(0.48, 0.4, 32, 1, true),
sideShadeMat,
0,
0,
0,
sideLamp,
false,
false
);
const sideRim = addMesh(
new THREE.TorusGeometry(0.48, 0.023, 8, 36),
mats.brass,
0,
-0.2,
0,
sideLamp,
false,
false
);
sideRim.rotation.x = Math.PI / 2;
addMesh(
new THREE.SphereGeometry(0.095, 16, 12),
sideBulbMat,
0,
-0.055,
0,
sideLamp,
false,
false
);
const sideTarget = new THREE.Vector3(-0.25, 1.56, 0.05);
const sideDirection = sideTarget.clone().sub(sideLamp.position).normalize();
sideLamp.quaternion.setFromUnitVectors(new THREE.Vector3(0, -1, 0), sideDirection);
const sideRear = sideLamp.position.clone().addScaledVector(sideDirection, -0.18);
cylinderBetween(
new THREE.Vector3(3.76, 2.95, 0.94),
sideRear,
0.04,
mats.brass
);
const overheadPosition = new THREE.Vector3(-0.24, 4.18, 0.05);
const overheadTarget = new THREE.Vector3(-0.1, 1.55, -0.08);
const sidePosition = sideLamp.position.clone().addScaledVector(sideDirection, 0.19);
let currentMode = "overhead";
function setMode(mode) {
currentMode = mode;
if (mode === "overhead") {
keyLight.position.copy(overheadPosition);
keyLight.target.position.copy(overheadTarget);
overheadBulbMat.emissiveIntensity = 3;
sideBulbMat.emissiveIntensity = 0.08;
} else {
keyLight.position.copy(sidePosition);
keyLight.target.position.copy(sideTarget);
overheadBulbMat.emissiveIntensity = 0.08;
sideBulbMat.emissiveIntensity = 3;
}
keyLight.target.updateMatrixWorld();
document.querySelectorAll(".mode").forEach((button) => {
const active = button.dataset.mode === mode;
button.classList.toggle("active", active);
button.setAttribute("aria-pressed", String(active));
});
document.getElementById("status").textContent =
mode === "overhead"
? "Overhead · compact shadows beneath the products"
: "Side · long, directional shadows across the counter";
renderer.render(scene, camera);
}
document.querySelectorAll(".mode").forEach((button) => {
button.addEventListener("click", () => setMode(button.dataset.mode));
});
document.getElementById("reset").addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "1") setMode("overhead");
if (event.key === "2") setMode("side");
if (event.key.toLowerCase() === "r") resetCamera();
});
// Camera controls implemented directly without Three.js addons.
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTouched = true;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraYaw = THREE.MathUtils.clamp(cameraYaw - dx * 0.0045, -1.02, 1.02);
cameraPitch = THREE.MathUtils.clamp(cameraPitch + dy * 0.0038, 0.72, 1.34);
updateCamera();
});
function endDrag(event) {
dragging = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraTouched = true;
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.006,
7.2,
12.4
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
if (!cameraTouched) {
cameraRadius = window.innerWidth < 700 ? 10.8 : 9.4;
updateCamera();
}
});
setMode("overhead");
</script>
</body>
</html>
```