Prompt specification
Build or customize the Three.js 3D scene "Design a Shadow Void Installation" 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: Design a Shadow Void Installation
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/design-a-shadow-void-installation-x3348
Scene Description Prompt:
Make a low-poly sculpture puzzle where adjustable holes cast a target shadow onto a wall under one light. One HTML file using Three.js from cdnjs.
Working Three.js Starter (design-a-shadow-void-installation-x3348):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>UMBRA — Aperture Puzzle</title>
<style>
:root {
color-scheme: dark;
--bg: #090b0d;
--panel: rgba(18, 21, 24, 0.88);
--line: rgba(255, 255, 255, 0.12);
--text: #f4eee4;
--muted: #9c9b96;
--gold: #e5b874;
--cyan: #79d5ef;
--orange: #ffb16f;
--pink: #ef96bd;
--green: #8de0ad;
}
* {
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;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.brand {
position: absolute;
top: 28px;
left: 32px;
max-width: 430px;
text-shadow: 0 2px 20px #000;
}
.eyebrow {
margin: 0 0 8px;
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.25em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 54px);
font-weight: 750;
letter-spacing: -0.055em;
line-height: 0.95;
}
.intro {
max-width: 360px;
margin: 15px 0 0;
color: #b6b4ae;
font-size: 13px;
line-height: 1.55;
}
.controls {
position: absolute;
top: 24px;
right: 24px;
width: min(330px, calc(100vw - 48px));
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background:
linear-gradient(145deg, rgba(255, 255, 255, 0.055), transparent 45%),
var(--panel);
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
backdrop-filter: blur(18px);
pointer-events: auto;
}
.controls-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin-bottom: 17px;
}
.controls h2 {
margin: 0;
font-size: 13px;
font-weight: 750;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.live-score {
color: var(--gold);
font-size: 12px;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.control {
margin-top: 15px;
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 8px;
color: #d3d0c9;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.control-label output {
color: #fff8ee;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--pct: 0%;
width: 100%;
height: 4px;
margin: 7px 0;
border: 0;
border-radius: 99px;
outline: none;
appearance: none;
background: linear-gradient(
to right,
var(--accent, var(--gold)) 0%,
var(--accent, var(--gold)) var(--pct),
rgba(255, 255, 255, 0.13) var(--pct),
rgba(255, 255, 255, 0.13) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 15px;
height: 15px;
border: 2px solid #151719;
border-radius: 50%;
appearance: none;
background: var(--accent, var(--gold));
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #151719;
border-radius: 50%;
background: var(--accent, var(--gold));
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.divider {
height: 1px;
margin: 18px 0 15px;
background: var(--line);
}
.readout {
margin-top: 14px;
padding: 12px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 11px;
background: rgba(255, 255, 255, 0.035);
}
.readout-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 9px;
color: #bbb8b0;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.readout-title span:last-child {
color: var(--gold);
}
.meter {
display: grid;
grid-template-columns: 17px 1fr 42px;
align-items: center;
gap: 8px;
margin: 7px 0;
color: #aaa7a0;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.meter-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--meter-color);
box-shadow: 0 0 9px var(--meter-color);
}
.meter-track {
height: 3px;
overflow: hidden;
border-radius: 99px;
background: rgba(255, 255, 255, 0.09);
}
.meter-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--meter-color);
transition: width 160ms ease;
}
.meter-value {
text-align: right;
}
.status {
min-height: 33px;
margin: 11px 0 0;
color: #aaa7a0;
font-size: 11px;
line-height: 1.45;
}
.status.locked {
color: var(--green);
}
.buttons {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
margin-top: 14px;
}
button {
min-height: 37px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
color: #e9e4da;
background: rgba(255, 255, 255, 0.055);
cursor: pointer;
transition:
transform 120ms ease,
background 120ms ease,
border-color 120ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(229, 184, 116, 0.5);
background: rgba(229, 184, 116, 0.1);
}
button:active {
transform: translateY(0);
}
button.primary {
border-color: rgba(229, 184, 116, 0.36);
color: #17130e;
background: var(--gold);
font-weight: 750;
}
.hint-button {
width: 100%;
margin-top: 9px;
color: #c3bfb6;
font-size: 11px;
}
.hint-text {
min-height: 30px;
margin: 8px 1px 0;
color: #918f89;
font-size: 10px;
line-height: 1.45;
}
.interaction-note {
position: absolute;
bottom: 26px;
left: 32px;
display: flex;
align-items: center;
gap: 9px;
color: #888782;
font-size: 10px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
.interaction-note::before {
width: 23px;
height: 1px;
content: "";
background: var(--gold);
}
.toast {
position: absolute;
left: 50%;
bottom: 28px;
padding: 10px 15px;
transform: translate(-50%, 12px);
border: 1px solid rgba(229, 184, 116, 0.25);
border-radius: 99px;
opacity: 0;
color: #e9dfcf;
background: rgba(16, 18, 20, 0.88);
box-shadow: 0 10px 35px rgba(0, 0, 0, 0.3);
font-size: 11px;
transition:
opacity 180ms ease,
transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.win {
position: absolute;
top: 50%;
left: 50%;
width: min(350px, calc(100vw - 40px));
padding: 27px;
transform: translate(-50%, -46%) scale(0.96);
border: 1px solid rgba(141, 224, 173, 0.35);
border-radius: 18px;
opacity: 0;
visibility: hidden;
text-align: center;
background: rgba(14, 19, 18, 0.94);
box-shadow:
0 30px 90px rgba(0, 0, 0, 0.55),
0 0 50px rgba(141, 224, 173, 0.08);
backdrop-filter: blur(20px);
pointer-events: auto;
transition:
opacity 220ms ease,
transform 220ms ease,
visibility 220ms;
}
.win.show {
opacity: 1;
visibility: visible;
transform: translate(-50%, -50%) scale(1);
}
.win-mark {
display: grid;
width: 48px;
height: 48px;
margin: 0 auto 14px;
place-items: center;
border: 1px solid rgba(141, 224, 173, 0.45);
border-radius: 50%;
color: var(--green);
font-size: 22px;
box-shadow: inset 0 0 22px rgba(141, 224, 173, 0.09);
}
.win h2 {
margin: 0;
font-size: 25px;
letter-spacing: -0.035em;
}
.win p {
margin: 10px 0 19px;
color: #a8afa9;
font-size: 12px;
line-height: 1.5;
}
.win button {
width: 100%;
}
@media (max-width: 760px) {
.brand {
top: 18px;
left: 20px;
max-width: calc(100vw - 40px);
}
h1 {
font-size: 34px;
}
.intro {
display: none;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
max-height: 48vh;
overflow-y: auto;
padding: 15px;
border-radius: 14px;
}
.control {
margin-top: 10px;
}
.interaction-note {
top: 106px;
bottom: auto;
left: 20px;
}
.readout,
.hint-button,
.hint-text {
display: none;
}
.divider {
margin: 13px 0 5px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly aperture shadow puzzle"></canvas>
<div class="hud">
<header class="brand">
<p class="eyebrow">Aperture study No. 07</p>
<h1>UMBRA</h1>
<p class="intro">
Shape the openings in the suspended plate until their projected light
aligns with the three marks on the wall. One light. No shortcuts.
</p>
</header>
<section class="controls" aria-label="Puzzle controls">
<div class="controls-head">
<h2>Shape the light</h2>
<div class="live-score" id="liveScore">0% match</div>
</div>
<div class="control">
<label class="control-label" for="twist">
<span>Plate rotation</span>
<output id="twistValue">-22°</output>
</label>
<input
id="twist"
type="range"
min="-180"
max="180"
step="1"
value="-22"
style="--accent: var(--gold)"
/>
</div>
<div class="control">
<label class="control-label" for="hole0">
<span><span style="color: var(--cyan)">●</span> Aperture A</span>
<output id="hole0Value">0.28</output>
</label>
<input
id="hole0"
type="range"
min="0.18"
max="0.70"
step="0.01"
value="0.28"
style="--accent: var(--cyan)"
/>
</div>
<div class="control">
<label class="control-label" for="hole1">
<span><span style="color: var(--orange)">●</span> Aperture B</span>
<output id="hole1Value">0.62</output>
</label>
<input
id="hole1"
type="range"
min="0.18"
max="0.70"
step="0.01"
value="0.62"
style="--accent: var(--orange)"
/>
</div>
<div class="control">
<label class="control-label" for="hole2">
<span><span style="color: var(--pink)">●</span> Aperture C</span>
<output id="hole2Value">0.38</output>
</label>
<input
id="hole2"
type="range"
min="0.18"
max="0.70"
step="0.01"
value="0.38"
style="--accent: var(--pink)"
/>
</div>
<div class="divider"></div>
<div class="readout">
<div class="readout-title">
<span>Wall alignment</span>
<span id="readoutStatus">Seeking</span>
</div>
<div class="meter" style="--meter-color: var(--cyan)">
<span class="meter-dot"></span>
<div class="meter-track"><div class="meter-fill" id="meter0"></div></div>
<span class="meter-value" id="meterValue0">0%</span>
</div>
<div class="meter" style="--meter-color: var(--orange)">
<span class="meter-dot"></span>
<div class="meter-track"><div class="meter-fill" id="meter1"></div></div>
<span class="meter-value" id="meterValue1">0%</span>
</div>
<div class="meter" style="--meter-color: var(--pink)">
<span class="meter-dot"></span>
<div class="meter-track"><div class="meter-fill" id="meter2"></div></div>
<span class="meter-value" id="meterValue2">0%</span>
</div>
<p class="status" id="statusText">
Match both the position and scale of each projected aperture.
</p>
</div>
<div class="buttons">
<button id="resetButton" type="button">Reset</button>
<button id="newButton" class="primary" type="button">New score</button>
</div>
<button id="hintButton" class="hint-button" type="button">
Reveal a hint
</button>
<p class="hint-text" id="hintText">
Drag the amber rims to resize. Drag the solid plate to twist.
</p>
</section>
<div class="interaction-note">
Drag rims to resize · Drag plate to rotate
</div>
<div class="toast" id="toast"></div>
<div class="win" id="winCard" role="dialog" aria-modal="true">
<div class="win-mark">✓</div>
<h2>Shadow resolved</h2>
<p>
All three apertures now register with the wall score. Try a new set of
marks or refine the sculpture further.
</p>
<button id="winNewButton" class="primary" type="button">
Cast another score
</button>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x090b0d);
scene.fog = new THREE.Fog(0x090b0d, 14, 29);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
60
);
camera.position.set(7.2, 3.7, 10.4);
camera.lookAt(0, 0.45, -1.4);
// -------------------------------------------------------------------------
// Puzzle geometry constants
// -------------------------------------------------------------------------
const WALL_Z = -4;
const APERTURE_Z = 0.12;
const PANEL_CENTER = new THREE.Vector3(0, 1.55, 0);
const LIGHT_POSITION = new THREE.Vector3(-2.8, 2.6, 5.6);
const Z_AXIS = new THREE.Vector3(0, 0, 1);
const HOLE_POSITIONS = [
new THREE.Vector2(-0.82, 0.64),
new THREE.Vector2(0.92, 0.28),
new THREE.Vector2(-0.05, -0.92)
];
const HOLE_COLORS = [0x79d5ef, 0xffb16f, 0xef96bd];
const HOLE_CSS = ["#79d5ef", "#ffb16f", "#ef96bd"];
const state = {
twist: -22,
radii: [0.28, 0.62, 0.38]
};
const target = {
twist: 38,
radii: [0.55, 0.43, 0.64]
};
let roundInitial = {
twist: state.twist,
radii: [...state.radii]
};
// Central projection from the light through the aperture plane to the wall.
const projectionScale =
(LIGHT_POSITION.z - WALL_Z) /
(LIGHT_POSITION.z - APERTURE_Z);
function projectToWall(point) {
return LIGHT_POSITION.clone().lerp(point, projectionScale);
}
function holeWorldPosition(index, twistDegrees) {
const local = HOLE_POSITIONS[index]
.clone()
.rotateAround(new THREE.Vector2(), THREE.MathUtils.degToRad(twistDegrees));
return PANEL_CENTER.clone().add(
new THREE.Vector3(local.x, local.y, APERTURE_Z)
);
}
// -------------------------------------------------------------------------
// Procedural low-poly wall texture
// -------------------------------------------------------------------------
function createWallTexture() {
const c = document.createElement("canvas");
c.width = 512;
c.height = 512;
const ctx = c.getContext("2d");
ctx.fillStyle = "#5c5b55";
ctx.fillRect(0, 0, 512, 512);
for (let i = 0; i < 110; i++) {
const x = Math.random() * 512;
const y = Math.random() * 512;
const size = 35 + Math.random() * 120;
const lightness = 62 + Math.random() * 28;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + size * (Math.random() - 0.5), y + size);
ctx.lineTo(x + size, y + size * (Math.random() - 0.5));
ctx.closePath();
ctx.fillStyle = `hsla(${
35 + Math.random() * 15
}, 8%, ${lightness}%, ${0.025 + Math.random() * 0.045})`;
ctx.fill();
}
ctx.strokeStyle = "rgba(0,0,0,0.10)";
ctx.lineWidth = 2;
ctx.strokeRect(1, 1, 510, 510);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const wallTexture = createWallTexture();
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0x89857b,
map: wallTexture,
roughness: 0.96,
metalness: 0.02,
emissive: 0x161510,
emissiveIntensity: 0.2
});
const wall = new THREE.Mesh(
new THREE.PlaneGeometry(15, 8.5),
wallMaterial
);
wall.position.set(0, 1.2, WALL_Z);
wall.receiveShadow = true;
scene.add(wall);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x25282a,
roughness: 0.9,
metalness: 0.08,
emissive: 0x0b0c0d,
emissiveIntensity: 0.25
});
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(28, 28),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.set(0, -2.2, 0);
floor.receiveShadow = true;
scene.add(floor);
// A few architectural seams keep the wall from feeling flat.
const seamMaterial = new THREE.MeshStandardMaterial({
color: 0x292a29,
roughness: 1,
emissive: 0x10110f,
emissiveIntensity: 0.15
});
for (const x of [-5.5, 5.5]) {
const seam = new THREE.Mesh(
new THREE.BoxGeometry(0.025, 8.5, 0.025),
seamMaterial
);
seam.position.set(x, 1.2, WALL_Z + 0.025);
scene.add(seam);
}
// -------------------------------------------------------------------------
// The one light
// -------------------------------------------------------------------------
const spotLight = new THREE.SpotLight(
0xffe3b5,
2850,
22,
0.42,
0.16,
2
);
spotLight.position.copy(LIGHT_POSITION);
spotLight.castShadow = true;
spotLight.shadow.mapSize.set(2048, 2048);
spotLight.shadow.camera.near = 0.5;
spotLight.shadow.camera.far = 20;
spotLight.shadow.bias = -0.00035;
spotLight.shadow.normalBias = 0.012;
spotLight.shadow.radius = 2;
const spotTarget = new THREE.Object3D();
spotTarget.position.copy(
projectToWall(
PANEL_CENTER.clone().add(
new THREE.Vector3(0, 0, APERTURE_Z)
)
)
);
scene.add(spotLight, spotTarget);
spotLight.target = spotTarget;
// Visible low-poly lamp housing. It does not cast a second shadow.
const lampGroup = new THREE.Group();
lampGroup.position.copy(LIGHT_POSITION);
const lampDirection = spotTarget.position.clone().sub(LIGHT_POSITION);
lampGroup.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 0, -1),
lampDirection.normalize()
);
const housingMaterial = new THREE.MeshStandardMaterial({
color: 0x22262a,
roughness: 0.55,
metalness: 0.72,
flatShading: true
});
const housing = new THREE.Mesh(
new THREE.CylinderGeometry(0.39, 0.46, 0.78, 8, 1, false),
housingMaterial
);
housing.rotation.x = Math.PI / 2;
lampGroup.add(housing);
const lensMaterial = new THREE.MeshStandardMaterial({
color: 0xffdfad,
emissive: 0xffc46f,
emissiveIntensity: 3,
roughness: 0.25,
side: THREE.DoubleSide
});
const lens = new THREE.Mesh(
new THREE.CircleGeometry(0.31, 16),
lensMaterial
);
lens.position.z = -0.4;
lampGroup.add(lens);
scene.add(lampGroup);
// -------------------------------------------------------------------------
// Sculpture stand
// -------------------------------------------------------------------------
const standMaterial = new THREE.MeshStandardMaterial({
color: 0x25292c,
roughness: 0.7,
metalness: 0.62,
flatShading: true
});
function cylinderBetween(start, end, radius, material, segments = 6) {
const direction = end.clone().sub(start);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(
radius,
radius,
direction.length(),
segments
),
material
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add(mesh);
return mesh;
}
cylinderBetween(
new THREE.Vector3(0, -2.1, -0.25),
new THREE.Vector3(0, 0.15, -0.25),
0.11,
standMaterial
);
cylinderBetween(
new THREE.Vector3(-1.35, -2.1, -0.32),
new THREE.Vector3(0, -0.25, -0.32),
0.08,
standMaterial
);
cylinderBetween(
new THREE.Vector3(1.35, -2.1, -0.32),
new THREE.Vector3(0, -0.25, -0.32),
0.08,
standMaterial
);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.7, 1.9, 0.18, 8),
standMaterial
);
base.position.set(0, -2.1, -0.2);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
// -------------------------------------------------------------------------
// Faceted aperture plate
// -------------------------------------------------------------------------
const panelGroup = new THREE.Group();
panelGroup.position.copy(PANEL_CENTER);
scene.add(panelGroup);
const panelFaceMaterial = new THREE.MeshStandardMaterial({
color: 0x29343b,
roughness: 0.5,
metalness: 0.7,
flatShading: true
});
const panelSideMaterial = new THREE.MeshStandardMaterial({
color: 0x8f603a,
roughness: 0.45,
metalness: 0.7,
flatShading: true
});
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0xd39a56,
transparent: true,
opacity: 0.62
});
let panelMesh = null;
let panelEdges = null;
function createPanelGeometry() {
const shape = new THREE.Shape();
const outerRadius = 2.16;
for (let i = 0; i < 8; i++) {
const angle = Math.PI / 8 + (i * Math.PI) / 4;
const x = Math.cos(angle) * outerRadius;
const y = Math.sin(angle) * outerRadius;
if (i === 0) shape.moveTo(x, y);
else shape.lineTo(x, y);
}
shape.closePath();
state.radii.forEach((radius, index) => {
const position = HOLE_POSITIONS[index];
const hole = new THREE.Path();
hole.absarc(
position.x,
position.y,
radius,
0,
Math.PI * 2,
true
);
shape.holes.push(hole);
});
return new THREE.ExtrudeGeometry(shape, {
depth: APERTURE_Z,
bevelEnabled: false,
curveSegments: 16,
steps: 1
});
}
function rebuildPanel() {
if (panelMesh) {
panelGroup.remove(panelMesh);
panelMesh.geometry.dispose();
}
if (panelEdges) {
panelGroup.remove(panelEdges);
panelEdges.geometry.dispose();
}
const geometry = createPanelGeometry();
panelMesh = new THREE.Mesh(geometry, [
panelFaceMaterial,
panelSideMaterial
]);
panelMesh.castShadow = true;
panelMesh.receiveShadow = true;
panelGroup.add(panelMesh);
panelEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 18),
edgeMaterial
);
panelGroup.add(panelEdges);
}
rebuildPanel();
// Amber rims are both visual guides and direct manipulation targets.
const handleRings = [];
const hitMeshes = [];
const hitMaterial = new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
});
hitMaterial.colorWrite = false;
for (let i = 0; i < 3; i++) {
const ringMaterial = new THREE.MeshStandardMaterial({
color: 0xd99a4e,
emissive: 0x5b3212,
emissiveIntensity: 0.45,
roughness: 0.42,
metalness: 0.75
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1, 0.026, 5, 24),
ringMaterial
);
ring.position.set(
HOLE_POSITIONS[i].x,
HOLE_POSITIONS[i].y,
APERTURE_Z + 0.025
);
ring.userData.holeIndex = i;
panelGroup.add(ring);
handleRings.push(ring);
const hit = new THREE.Mesh(
new THREE.CircleGeometry(1, 20),
hitMaterial
);
hit.position.copy(ring.position);
hit.position.z += 0.015;
hit.userData.holeIndex = i;
panelGroup.add(hit);
hitMeshes.push(hit);
}
function updateHandleScales() {
state.radii.forEach((radius, index) => {
handleRings[index].scale.setScalar(radius);
hitMeshes[index].scale.setScalar(radius + 0.13);
});
}
updateHandleScales();
// Small brass fasteners emphasize the low-poly construction.
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0xb98347,
roughness: 0.38,
metalness: 0.85,
flatShading: true
});
for (let i = 0; i < 8; i++) {
const angle = Math.PI / 8 + (i * Math.PI) / 4;
const bolt = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.055, 0.035, 6),
boltMaterial
);
bolt.rotation.x = Math.PI / 2;
bolt.position.set(
Math.cos(angle) * 1.93,
Math.sin(angle) * 1.93,
APERTURE_Z + 0.02
);
panelGroup.add(bolt);
}
// -------------------------------------------------------------------------
// Wall target score
// -------------------------------------------------------------------------
const targetGroup = new THREE.Group();
scene.add(targetGroup);
let targetMarkers = [];
function makeLabelTexture(letter, color) {
const c = document.createElement("canvas");
c.width = 128;
c.height = 128;
const ctx = c.getContext("2d");
ctx.font = "800 62px system-ui";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.shadowColor = color;
ctx.shadowBlur = 14;
ctx.fillText(letter, 64, 65);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
function disposeTargetGroup() {
targetGroup.traverse((object) => {
if (object.geometry) object.geometry.dispose();
if (object.material) {
const materials = Array.isArray(object.material)
? object.material
: [object.material];
materials.forEach((material) => {
if (material.map) material.map.dispose();
material.dispose();
});
}
});
targetGroup.clear();
targetMarkers = [];
}
function buildTargetMarks() {
disposeTargetGroup();
target.radii.forEach((radius, index) => {
const projected = projectToWall(
holeWorldPosition(index, target.twist)
);
const projectedRadius = radius * projectionScale;
const marker = new THREE.Group();
marker.position.copy(projected);
marker.position.z = WALL_Z + 0.035;
targetGroup.add(marker);
const ringMaterial = new THREE.MeshBasicMaterial({
color: HOLE_COLORS[index],
transparent: true,
opacity: 0.86,
depthWrite: false
});
const ring = new THREE.Mesh(
new THREE.TorusGeometry(projectedRadius, 0.016, 5, 36),
ringMaterial
);
marker.add(ring);
const fillMaterial = new THREE.MeshBasicMaterial({
color: HOLE_COLORS[index],
transparent: true,
opacity: 0.045,
depthWrite: false,
side: THREE.DoubleSide
});
const fill = new THREE.Mesh(
new THREE.CircleGeometry(projectedRadius, 36),
fillMaterial
);
fill.position.z = -0.008;
marker.add(fill);
// Four registration ticks.
const tickMaterial = new THREE.MeshBasicMaterial({
color: HOLE_COLORS[index],
transparent: true,
opacity: 0.65,
depthWrite: false
});
for (let t = 0; t < 4; t++) {
const angle = (t * Math.PI) / 2;
const tick = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.016, 0.012),
tickMaterial
);
tick.position.set(
Math.cos(angle) * (projectedRadius + 0.105),
Math.sin(angle) * (projectedRadius + 0.105),
0.004
);
tick.rotation.z = angle;
marker.add(tick);
}
const labelTexture = makeLabelTexture(
String.fromCharCode(65 + index),
HOLE_CSS[index]
);
const label = new THREE.Mesh(
new THREE.PlaneGeometry(0.24, 0.24),
new THREE.MeshBasicMaterial({
map: labelTexture,
transparent: true,
depthWrite: false
})
);
label.position.set(
0,
-projectedRadius - 0.19,
0.012
);
marker.add(label);
targetMarkers.push({ ring, fill, baseRadius: projectedRadius });
});
}
buildTargetMarks();
// -------------------------------------------------------------------------
// UI and scoring
// -------------------------------------------------------------------------
const twistInput = document.querySelector("#twist");
const radiusInputs = [
document.querySelector("#hole0"),
document.querySelector("#hole1"),
document.querySelector("#hole2")
];
const twistValue = document.querySelector("#twistValue");
const radiusValues = [
document.querySelector("#hole0Value"),
document.querySelector("#hole1Value"),
document.querySelector("#hole2Value")
];
const liveScore = document.querySelector("#liveScore");
const readoutStatus = document.querySelector("#readoutStatus");
const statusText = document.querySelector("#statusText");
const meterFills = [
document.querySelector("#meter0"),
document.querySelector("#meter1"),
document.querySelector("#meter2")
];
const meterValues = [
document.querySelector("#meterValue0"),
document.querySelector("#meterValue1"),
document.querySelector("#meterValue2")
];
const winCard = document.querySelector("#winCard");
const toast = document.querySelector("#toast");
let toastTimer = null;
let solved = false;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
}
function updateSliderFill(input) {
const percent =
((Number(input.value) - Number(input.min)) /
(Number(input.max) - Number(input.min))) *
100;
input.style.setProperty("--pct", `${percent}%`);
}
function syncUI() {
twistInput.value = Math.round(state.twist);
twistValue.textContent = `${Math.round(state.twist)}°`;
state.radii.forEach((radius, index) => {
radiusInputs[index].value = radius.toFixed(2);
radiusValues[index].textContent = radius.toFixed(2);
});
[...[twistInput], ...radiusInputs].forEach(updateSliderFill);
}
function evaluatePuzzle() {
let total = 0;
let allMatched = true;
const results = state.radii.map((radius, index) => {
const actualPoint = projectToWall(
holeWorldPosition(index, state.twist)
);
const targetPoint = projectToWall(
holeWorldPosition(index, target.twist)
);
const positionError = actualPoint.distanceTo(targetPoint);
const sizeError = Math.abs(
radius * projectionScale -
target.radii[index] * projectionScale
);
const positionScore = THREE.MathUtils.clamp(
1 - positionError / 0.42,
0,
1
);
const sizeScore = THREE.MathUtils.clamp(
1 - sizeError / 0.19,
0,
1
);
const score = positionScore * 0.46 + sizeScore * 0.54;
const matched = positionError < 0.075 && sizeError < 0.035;
total += score;
if (!matched) allMatched = false;
return { score, matched };
});
const percent = Math.round((total / 3) * 100);
liveScore.textContent = `${percent}% match`;
results.forEach((result, index) => {
const value = Math.round(result.score * 100);
meterFills[index].style.width = `${value}%`;
meterValues[index].textContent = `${value}%`;
});
if (allMatched) {
readoutStatus.textContent = "Resolved";
statusText.textContent =
"The three apertures register exactly with the wall score.";
statusText.classList.add("locked");
if (!solved) {
solved = true;
winCard.classList.add("show");
}
} else {
readoutStatus.textContent = "Seeking";
statusText.textContent =
"Match both the position and scale of each projected aperture.";
statusText.classList.remove("locked");
solved = false;
winCard.classList.remove("show");
}
}
function setTwist(value) {
state.twist = THREE.MathUtils.clamp(value, -180, 180);
panelGroup.rotation.z = THREE.MathUtils.degToRad(state.twist);
syncUI();
evaluatePuzzle();
}
function setRadius(index, value) {
state.radii[index] = THREE.MathUtils.clamp(value, 0.18, 0.7);
updateHandleScales();
rebuildPanel();
syncUI();
evaluatePuzzle();
}
twistInput.addEventListener("input", () => {
setTwist(Number(twistInput.value));
});
radiusInputs.forEach((input, index) => {
input.addEventListener("input", () => {
setRadius(index, Number(input.value));
});
});
// -------------------------------------------------------------------------
// Direct manipulation
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const dragPlane = new THREE.Plane(
new THREE.Vector3(0, 0, 1),
-(APERTURE_Z + 0.05)
);
const worldPoint = new THREE.Vector3();
let drag = null;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
}
function pointerOnPlane() {
return raycaster.ray.intersectPlane(dragPlane, worldPoint);
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
updatePointer(event);
const handleHits = raycaster.intersectObjects(hitMeshes, false);
if (handleHits.length) {
const index = handleHits[0].object.userData.holeIndex;
const localPoint = panelGroup.worldToLocal(
handleHits[0].point.clone()
);
const holeCenter = HOLE_POSITIONS[index];
const startDistance = new THREE.Vector2(localPoint.x, localPoint.y).distanceTo(holeCenter);
drag = {
mode: "resize",
index,
startDistance,
startRadius: state.radii[index]
};
} else {
const panelHits = raycaster.intersectObject(panelMesh, false);
if (!panelHits.length) return;
if (!pointerOnPlane()) return;
const startAngle = Math.atan2(
worldPoint.y - PANEL_CENTER.y,
worldPoint.x - PANEL_CENTER.x
);
drag = {
mode: "twist",
startAngle,
startTwist: state.twist
};
}
canvas.setPointerCapture(event.pointerId);
event.preventDefault();
});
canvas.addEventListener("pointermove", (event) => {
if (!drag) return;
updatePointer(event);
if (!pointerOnPlane()) return;
if (drag.mode === "resize") {
const localPoint = panelGroup.worldToLocal(worldPoint.clone());
const distance = new THREE.Vector2(localPoint.x, localPoint.y).distanceTo(
HOLE_POSITIONS[drag.index]
);
const nextRadius =
drag.startRadius + (distance - drag.startDistance) * 0.012;
setRadius(drag.index, nextRadius);
} else {
const currentAngle = Math.atan2(
worldPoint.y - PANEL_CENTER.y,
worldPoint.x - PANEL_CENTER.x
);
let delta = currentAngle - drag.startAngle;
if (delta > Math.PI) delta -= Math.PI * 2;
if (delta < -Math.PI) delta += Math.PI * 2;
setTwist(
drag.startTwist + THREE.MathUtils.radToDeg(delta)
);
}
event.preventDefault();
});
function endDrag(event) {
drag = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
// -------------------------------------------------------------------------
// Puzzle lifecycle
// -------------------------------------------------------------------------
function randomWrongState() {
const twist = THREE.MathUtils.randFloat(-165, 165);
const radii = [0, 1, 2].map(() =>
THREE.MathUtils.randFloat(0.22, 0.68)
);
// Avoid an accidental immediate solution.
const projectedDiameter =
Math.abs(twist - target.twist) > 4;
if (
projectedDiameter &&
radii.every(
(radius, index) =>
Math.abs(radius - target.radii[index]) < 0.035
)
) {
radii[0] = THREE.MathUtils.clamp(
radii[0] + 0.12,
0.18,
0.7
);
}
return { twist, radii };
}
function applyState(values) {
state.twist = values.twist;
state.radii = [...values.radii];
panelGroup.rotation.z = THREE.MathUtils.degToRad(state.twist);
updateHandleScales();
rebuildPanel();
syncUI();
evaluatePuzzle();
}
function newPuzzle() {
target.twist = THREE.MathUtils.randFloat(-150, 150);
target.radii = [0, 1, 2].map(() =>
THREE.MathUtils.randFloat(0.37, 0.66)
);
buildTargetMarks();
const start = randomWrongState();
roundInitial = {
twist: start.twist,
radii: [...start.radii]
};
applyState(start);
winCard.classList.remove("show");
solved = false;
showToast("A new wall score has been cast.");
}
document.querySelector("#resetButton").addEventListener("click", () => {
applyState(roundInitial);
showToast("Sculpture reset to the start of this score.");
});
document.querySelector("#newButton").addEventListener("click", newPuzzle);
document.querySelector("#winNewButton").addEventListener("click", newPuzzle);
document.querySelector("#hintButton").addEventListener("click", () => {
let delta = ((target.twist - state.twist + 540) % 360) - 180;
if (Math.abs(delta) > 3) {
const direction = delta > 0 ? "counter-clockwise" : "clockwise";
document.querySelector("#hintText").textContent =
`Turn the plate slightly ${direction}. The triangular score has not settled into place.`;
return;
}
let bestIndex = 0;
let bestError = 0;
state.radii.forEach((radius, index) => {
const error = Math.abs(radius - target.radii[index]);
if (error > bestError) {
bestError = error;
bestIndex = index;
}
});
const letter = String.fromCharCode(65 + bestIndex);
const direction =
state.radii[bestIndex] < target.radii[bestIndex]
? "larger"
: "smaller";
document.querySelector("#hintText").textContent =
`Aperture ${letter} should be ${direction}. Adjust its amber rim.`;
});
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
syncUI();
evaluatePuzzle();
const clock = new THREE.Clock();
function animate() {
const elapsed = clock.getElapsedTime();
targetMarkers.forEach((marker, index) => {
const pulse = 1 + Math.sin(elapsed * 1.8 + index * 1.7) * 0.009;
marker.ring.scale.setScalar(pulse);
marker.fill.material.opacity =
0.035 + Math.sin(elapsed * 1.5 + index) * 0.012;
});
lensMaterial.emissiveIntensity =
2.8 + Math.sin(elapsed * 2.2) * 0.15;
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```