Prompt specification
Build or customize the Three.js 3D scene "Apartment entrance call panel" 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: Apartment entrance call panel
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/apartment-entrance-call-panel-x0015
Scene Description Prompt:
Make a voxel Three.js scene in a self-contained HTML file using cdnjs: apartment entrance call panel. Create a vestibule with numbered call buttons, intercom grille, and accessible clear floor area; selecting a button highlights the corresponding dwelling in a cutaway model.
Working Three.js Starter (apartment-entrance-call-panel-x0015):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#e9e4da">
<title>Voxel Apartment Entrance</title>
<style>
:root {
--ink: #263338;
--muted: #6f7776;
--paper: rgba(250, 248, 242, 0.92);
--accent: #e76f51;
--accent-soft: #f8d8cc;
--access: #287f78;
--line: rgba(38, 51, 56, 0.14);
--shadow: 0 18px 50px rgba(43, 48, 46, 0.14);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e4da;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
#scene canvas:focus-visible {
outline: 3px solid var(--access);
outline-offset: -4px;
}
.hero {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
max-width: 440px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 12px;
color: var(--muted);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.voxel-mark {
display: grid;
grid-template-columns: repeat(2, 7px);
grid-template-rows: repeat(2, 7px);
gap: 2px;
transform: rotate(-6deg);
}
.voxel-mark i {
display: block;
background: var(--ink);
}
.voxel-mark i:nth-child(2) {
background: var(--accent);
}
.voxel-mark i:nth-child(3) {
background: var(--access);
}
.hero h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 780;
line-height: 0.98;
letter-spacing: -0.055em;
}
.hero p {
max-width: 360px;
margin: 13px 0 0;
color: #586365;
font-size: 14px;
line-height: 1.55;
}
.controls {
position: fixed;
top: 26px;
right: 26px;
z-index: 6;
display: flex;
align-items: center;
gap: 12px;
}
.controls button {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 42px;
padding: 0 15px;
border: 1px solid rgba(38, 51, 56, 0.14);
border-radius: 12px;
background: var(--paper);
color: var(--ink);
box-shadow: 0 8px 24px rgba(38, 51, 56, 0.09);
cursor: pointer;
backdrop-filter: blur(14px);
transition: transform 160ms ease, background 160ms ease;
}
.controls button:hover {
transform: translateY(-2px);
background: #fffdf8;
}
.controls svg {
width: 17px;
height: 17px;
stroke: currentColor;
fill: none;
stroke-width: 1.8;
}
.control-hint {
padding: 9px 12px;
border: 1px solid rgba(38, 51, 56, 0.1);
border-radius: 10px;
background: rgba(250, 248, 242, 0.68);
color: #6a7272;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.09em;
text-transform: uppercase;
backdrop-filter: blur(10px);
}
.directory {
position: fixed;
bottom: 25px;
left: 26px;
z-index: 6;
width: min(380px, calc(100vw - 52px));
padding: 18px;
border: 1px solid rgba(38, 51, 56, 0.12);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(18px);
}
.panel-heading {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
margin-bottom: 14px;
}
.panel-heading strong {
display: block;
font-size: 13px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel-heading span {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 12px;
}
.live-dot {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 6px 8px;
border-radius: 999px;
background: #e3efeb;
color: var(--access);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
white-space: nowrap;
}
.live-dot::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: currentColor;
content: "";
box-shadow: 0 0 0 3px rgba(40, 127, 120, 0.12);
}
.button-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
}
.apartment-button {
position: relative;
min-height: 47px;
border: 1px solid var(--line);
border-radius: 11px;
background: #f3efe7;
color: var(--ink);
font-weight: 780;
cursor: pointer;
transition: transform 150ms ease, border-color 150ms ease,
background 150ms ease, color 150ms ease;
}
.apartment-button:hover {
transform: translateY(-2px);
border-color: rgba(231, 111, 81, 0.45);
background: #fffaf4;
}
.apartment-button[aria-pressed="true"] {
border-color: var(--accent);
background: var(--accent);
color: white;
box-shadow: 0 7px 15px rgba(231, 111, 81, 0.22);
}
.apartment-button[aria-pressed="true"]::after {
position: absolute;
top: 5px;
right: 6px;
color: rgba(255, 255, 255, 0.75);
content: "•";
font-size: 15px;
}
.selection-status {
min-height: 36px;
margin: 13px 2px 0;
color: #586365;
font-size: 12px;
line-height: 1.45;
}
.selection-status strong {
color: var(--ink);
}
.access-card {
position: fixed;
right: 26px;
bottom: 25px;
z-index: 5;
display: flex;
align-items: center;
gap: 13px;
max-width: 310px;
padding: 14px 16px;
border: 1px solid rgba(40, 127, 120, 0.18);
border-radius: 16px;
background: rgba(245, 249, 244, 0.9);
box-shadow: 0 12px 34px rgba(38, 51, 56, 0.09);
pointer-events: none;
backdrop-filter: blur(16px);
}
.access-icon {
display: grid;
flex: 0 0 38px;
height: 38px;
place-items: center;
border-radius: 10px;
background: var(--access);
color: white;
}
.access-icon svg {
width: 23px;
height: 23px;
fill: none;
stroke: currentColor;
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 1.8;
}
.access-card strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
}
.access-card p {
margin: 0;
color: #64706e;
font-size: 11px;
line-height: 1.45;
}
#tooltip {
position: fixed;
z-index: 20;
padding: 7px 9px;
border-radius: 8px;
background: rgba(38, 51, 56, 0.94);
color: white;
font-size: 11px;
font-weight: 750;
pointer-events: none;
opacity: 0;
transform: translate(12px, 12px);
transition: opacity 100ms ease;
}
#tooltip.visible {
opacity: 1;
}
#loading {
position: fixed;
inset: 0;
z-index: 50;
display: grid;
place-items: center;
background: #e9e4da;
color: var(--ink);
font-size: 12px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.hero {
top: 18px;
left: 18px;
max-width: calc(100vw - 36px);
}
.hero h1 {
font-size: 32px;
}
.hero p {
display: none;
}
.controls {
top: 17px;
right: 17px;
}
.control-hint {
display: none;
}
.directory {
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 14px;
}
.panel-heading {
margin-bottom: 10px;
}
.selection-status {
min-height: 30px;
margin-top: 9px;
}
.access-card {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive voxel apartment entrance and cutaway building"></main>
<header class="hero">
<div class="eyebrow">
<span class="voxel-mark" aria-hidden="true"><i></i><i></i><i></i><i></i></span>
Cedar House / Voxel Access
</div>
<h1>Apartment<br>entrance</h1>
<p>
Select a resident call button to locate the corresponding dwelling
in the cutaway building.
</p>
</header>
<div class="controls">
<span class="control-hint">Drag to orbit · Scroll to zoom</span>
<button id="reset-view" type="button" aria-label="Reset camera view">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="M4 12a8 8 0 1 0 2.34-5.66L4 8.68"></path>
<path d="M4 4v4.68h4.68"></path>
</svg>
Reset view
</button>
</div>
<section class="directory" aria-labelledby="directory-title">
<div class="panel-heading">
<div>
<strong id="directory-title">Resident call panel</strong>
<span>Choose a dwelling number</span>
</div>
<span class="live-dot">Online</span>
</div>
<div class="button-grid" id="apartment-buttons">
<button class="apartment-button" type="button" data-id="101" aria-pressed="true">101</button>
<button class="apartment-button" type="button" data-id="102" aria-pressed="false">102</button>
<button class="apartment-button" type="button" data-id="201" aria-pressed="false">201</button>
<button class="apartment-button" type="button" data-id="202" aria-pressed="false">202</button>
<button class="apartment-button" type="button" data-id="301" aria-pressed="false">301</button>
<button class="apartment-button" type="button" data-id="302" aria-pressed="false">302</button>
</div>
<p class="selection-status" id="selection-status" aria-live="polite">
<strong>Dwelling 101</strong> highlighted on the ground floor.
</p>
</section>
<aside class="access-card" aria-label="Accessibility information">
<span class="access-icon" aria-hidden="true">
<svg viewBox="0 0 24 24">
<circle cx="10" cy="4.5" r="2"></circle>
<path d="M10 7v5h5l3 5"></path>
<path d="M10 10h5"></path>
<path d="M9 15a5 5 0 1 0 6 0"></path>
</svg>
</span>
<div>
<strong>Step-free approach</strong>
<p>Level vestibule with a marked 1.5 m clear turning area.</p>
</div>
</aside>
<div id="tooltip" role="status"></div>
<div id="loading">Building voxel entrance…</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneMount = document.querySelector("#scene");
const tooltip = document.querySelector("#tooltip");
const status = document.querySelector("#selection-status");
const uiButtons = [...document.querySelectorAll(".apartment-button")];
const ACCENT = 0xe76f51;
const ACCESS = 0x287f78;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e4da);
scene.fog = new THREE.Fog(0xe9e4da, 29, 53);
const renderer = new THREE.WebGLRenderer({
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneMount.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Voxel apartment entrance. Drag to orbit, scroll to zoom, or use the resident call panel buttons."
);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
theta: 0.57,
phi: 1.03,
radius: 20.8,
target: new THREE.Vector3(0, 3.7, -0.15)
};
const currentOrbit = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
const hemi = new THREE.HemisphereLight(0xfffaf0, 0x72817e, 2.15);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff3dc, 3.1);
sun.position.set(-7, 15, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -14;
sun.shadow.camera.right = 14;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.normalBias = 0.035;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbad7df, 1.2);
fill.position.set(9, 7, -8);
scene.add(fill);
const material = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.78,
metalness: 0,
...options
});
const materials = {
ground: material(0xd8d2c6),
plinth: material(0xa99f91),
paving: material(0xeee8dd),
wall: material(0xf1eadf),
wallShade: material(0xd7cdbd),
slab: material(0xb9ad9b),
dark: material(0x303b3e, { roughness: 0.56 }),
metal: material(0x7f8987, { roughness: 0.42, metalness: 0.35 }),
glass: material(0x9bc8c7, {
roughness: 0.12,
metalness: 0,
transparent: true,
opacity: 0.19,
depthWrite: false
}),
window: material(0x729ba7, { roughness: 0.32 }),
wood: material(0xb77d52),
woodLight: material(0xd2a579),
cream: material(0xeee3d0),
charcoal: material(0x485153),
sofa: material(0x6f8b82),
sofaAlt: material(0xc7795f),
rug: material(0xd7b38e),
plant: material(0x527f68),
terracotta: material(0xb9684e)
};
function addBox(parent, size, position, mat, outlined = false) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color: 0x5e5750,
transparent: true,
opacity: 0.2
})
);
mesh.add(edges);
}
return mesh;
}
function makeTextTexture(text, {
color = "#ffffff",
background = null,
fontSize = 72,
weight = 800,
width = 512,
height = 192,
padding = 18
} = {}) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
if (background) {
context.fillStyle = background;
context.fillRect(0, 0, width, height);
}
context.fillStyle = color;
context.font = `${weight} ${fontSize}px Arial, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2, width - padding * 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
return texture;
}
function makeSprite(text, options = {}) {
const texture = makeTextTexture(text, options);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.renderOrder = 20;
scene.add(sprite);
return sprite;
}
function makeFloorText(text, position, width = 2.4, height = 0.42) {
const texture = makeTextTexture(text, {
color: "#287f78",
fontSize: 58,
width: 1024,
height: 192
});
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, height),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(...position);
scene.add(mesh);
return mesh;
}
// Display plinth and surrounding voxel paving.
addBox(scene, [13.25, 0.5, 9.35], [0, -0.15, -0.1], materials.plinth, true);
addBox(scene, [12.9, 0.08, 9.0], [0, 0.13, -0.1], materials.paving, true);
for (let x = -6; x <= 6; x += 1.2) {
addBox(
scene,
[0.025, 0.012, 8.7],
[x, 0.177, -0.1],
material(0xd2cabd)
);
}
for (let z = -4.5; z <= 4.2; z += 1.2) {
addBox(
scene,
[12.65, 0.012, 0.025],
[0, 0.178, z],
material(0xd2cabd)
);
}
addBox(scene, [80, 0.25, 80], [0, -0.58, 0], materials.ground);
// Building shell: front and right walls are intentionally cut away.
addBox(scene, [11.8, 8.9, 0.36], [0, 5.0, -4.58], materials.wall, true);
addBox(scene, [0.36, 8.9, 4.35], [-5.72, 5.0, -2.55], materials.wall, true);
addBox(scene, [0.36, 8.9, 2.3], [5.72, 5.0, -3.55], materials.wallShade, true);
addBox(scene, [11.8, 0.32, 0.36], [0, 9.48, -4.58], materials.wallShade, true);
const buildingSign = makeSprite("CEDAR HOUSE", {
background: "rgba(38,51,56,0.88)",
color: "#fffaf0",
fontSize: 54,
width: 640,
height: 150
});
buildingSign.position.set(0, 9.08, -4.31);
buildingSign.scale.set(3.5, 0.82, 1);
const levelYs = [0.55, 3.65, 6.75];
const levelNames = ["Ground floor", "Second floor", "Third floor"];
levelYs.forEach((y, levelIndex) => {
addBox(scene, [11.8, 0.28, 5.45], [0, y - 0.14, -1.88], materials.slab, true);
// Central apartment partitions with a doorway gap.
addBox(scene, [0.25, 2.72, 1.7], [0, y + 1.36, -3.75], materials.wallShade, true);
addBox(scene, [0.25, 2.72, 0.9], [0, y + 1.36, -1.18], materials.wallShade, true);
// Small voxel landing markers.
for (let x = -4.8; x <= 4.8; x += 1.2) {
addBox(
scene,
[0.6, 0.018, 0.08],
[x, y + 0.018, 0.45],
material(0xc5b8a5)
);
}
if (levelIndex < 2) {
addBox(scene, [11.85, 0.24, 0.22], [0, y + 3.08, -0.78], materials.wallShade);
}
});
const apartments = [
{ id: "101", level: 0, x: -2.85, z: -1.9, side: "left" },
{ id: "102", level: 0, x: 2.85, z: -1.9, side: "right" },
{ id: "201", level: 1, x: -2.85, z: -1.9, side: "left" },
{ id: "202", level: 1, x: 2.85, z: -1.9, side: "right" },
{ id: "301", level: 2, x: -2.85, z: -1.9, side: "left" },
{ id: "302", level: 2, x: 2.85, z: -1.9, side: "right" }
];
function addWindow(x, y) {
addBox(scene, [1.9, 1.15, 0.09], [x, y + 1.65, -4.36], materials.window);
addBox(scene, [0.08, 1.28, 0.11], [x, y + 1.65, -4.29], materials.cream);
addBox(scene, [2.02, 0.08, 0.11], [x, y + 1.65, -4.29], materials.cream);
addBox(scene, [2.12, 0.11, 0.22], [x, y + 1.05, -4.25], materials.woodLight);
}
function buildApartment(apartment) {
const y = levelYs[apartment.level];
const { x, z, id, side } = apartment;
const floorMaterial = material(
apartment.level === 0 ? 0xe5d8c5 : apartment.level === 1 ? 0xe7dfd1 : 0xeadfce,
{ emissive: 0x000000, emissiveIntensity: 0 }
);
addBox(
scene,
[5.35, 0.045, 4.72],
[x, y + 0.025, z],
floorMaterial
);
addWindow(x, y);
const accentMaterial = side === "left"
? materials.sofa
: materials.sofaAlt;
// Rug.
addBox(scene, [2.35, 0.026, 1.65], [x + 0.25, y + 0.062, z + 0.25], materials.rug);
// Sofa.
addBox(scene, [1.8, 0.38, 0.78], [x + 1.35, y + 0.27, z + 0.18], accentMaterial, true);
addBox(scene, [1.8, 0.66, 0.18], [x + 1.35, y + 0.56, z - 0.13], accentMaterial);
addBox(scene, [0.18, 0.54, 0.78], [x + 0.5, y + 0.45, z + 0.18], accentMaterial);
addBox(scene, [0.18, 0.54, 0.78], [x + 2.2, y + 0.45, z + 0.18], accentMaterial);
// Coffee table.
addBox(scene, [1.0, 0.22, 0.56], [x + 0.15, y + 0.2, z + 0.62], materials.woodLight, true);
addBox(scene, [0.12, 0.3, 0.12], [x - 0.18, y + 0.1, z + 0.62], materials.wood);
addBox(scene, [0.12, 0.3, 0.12], [x + 0.48, y + 0.1, z + 0.62], materials.wood);
// Bed.
addBox(scene, [1.48, 0.38, 2.08], [x - 1.45, y + 0.25, z - 1.05], materials.wood, true);
addBox(scene, [1.42, 0.2, 2.0], [x - 1.45, y + 0.52, z - 1.05], materials.cream);
addBox(scene, [1.55, 0.75, 0.16], [x - 1.45, y + 0.58, z - 2.12], materials.woodLight);
addBox(scene, [0.92, 0.18, 0.43], [x - 1.45, y + 0.7, z - 1.78], materials.cream);
// Kitchenette.
addBox(scene, [1.4, 0.82, 0.55], [x - 1.45, y + 0.46, z + 1.72], materials.cream, true);
addBox(scene, [1.47, 0.1, 0.62], [x - 1.45, y + 0.91, z + 1.72], materials.charcoal);
addBox(scene, [0.3, 0.035, 0.34], [x - 1.35, y + 0.98, z + 1.72], materials.dark);
// Plant made from stacked cubes.
addBox(scene, [0.3, 0.36, 0.3], [x + 2.05, y + 0.23, z + 1.52], materials.terracotta);
addBox(scene, [0.16, 0.55, 0.16], [x + 2.05, y + 0.67, z + 1.52], materials.plant);
addBox(scene, [0.48, 0.18, 0.22], [x + 2.05, y + 0.91, z + 1.52], materials.plant);
addBox(scene, [0.22, 0.18, 0.48], [x + 2.05, y + 1.05, z + 1.52], materials.plant);
const label = makeSprite(id, {
background: "rgba(38,51,56,0.91)",
color: "#fffaf0",
fontSize: 76,
width: 360,
height: 150
});
label.position.set(x, y + 2.38, 0.78);
label.scale.set(1.28, 0.56, 1);
const highlight = new THREE.Group();
highlight.position.set(x, y + 0.07, z);
highlight.visible = false;
const glowMaterial = new THREE.MeshBasicMaterial({
color: ACCENT,
transparent: true,
opacity: 0.17,
depthWrite: false,
side: THREE.DoubleSide
});
const glow = new THREE.Mesh(
new THREE.PlaneGeometry(5.25, 4.65),
glowMaterial
);
glow.rotation.x = -Math.PI / 2;
highlight.add(glow);
const borderMaterial = new THREE.MeshBasicMaterial({
color: ACCENT,
transparent: true,
opacity: 0.92
});
addBox(highlight, [5.3, 0.055, 0.075], [0, 0, -2.34], borderMaterial);
addBox(highlight, [5.3, 0.055, 0.075], [0, 0, 2.34], borderMaterial);
addBox(highlight, [0.075, 0.055, 4.75], [-2.64, 0, 0], borderMaterial);
addBox(highlight, [0.075, 0.055, 4.75], [2.64, 0, 0], borderMaterial);
const light = new THREE.PointLight(ACCENT, 0, 5, 2);
light.position.set(0, 1.8, 0.5);
highlight.add(light);
scene.add(highlight);
Object.assign(apartment, {
floorMaterial,
highlight,
glowMaterial,
borderMaterial,
selectionLight: light,
label,
y,
side
});
}
apartments.forEach(buildApartment);
// Vestibule floor and transparent enclosure.
addBox(scene, [11.8, 0.28, 3.4], [0, 0.41, 2.48], materials.slab, true);
addBox(scene, [11.55, 0.035, 3.15], [0, 0.575, 2.47], materials.paving);
addBox(scene, [0.08, 2.85, 3.18], [5.72, 2.02, 2.48], materials.glass);
addBox(scene, [0.08, 2.85, 3.18], [-5.72, 2.02, 2.48], materials.glass);
addBox(scene, [11.45, 0.12, 0.12], [0, 3.43, 4.02], materials.metal);
// Exterior entrance frame.
addBox(scene, [0.14, 2.9, 0.16], [-2.95, 2.0, 4.12], materials.metal);
addBox(scene, [0.14, 2.9, 0.16], [0.45, 2.0, 4.12], materials.metal);
addBox(scene, [3.54, 0.16, 0.16], [-1.25, 3.43, 4.12], materials.metal);
addBox(scene, [1.48, 2.55, 0.055], [-2.13, 1.85, 4.12], materials.glass);
addBox(scene, [1.48, 2.55, 0.055], [-0.37, 1.85, 4.12], materials.glass);
addBox(scene, [0.09, 2.55, 0.11], [-1.25, 1.85, 4.12], materials.metal);
addBox(scene, [0.06, 0.55, 0.09], [-0.92, 1.65, 4.18], materials.charcoal);
addBox(scene, [0.06, 0.55, 0.09], [-1.58, 1.65, 4.18], materials.charcoal);
const entrySign = makeSprite("STEP-FREE ENTRY", {
background: "rgba(40,127,120,0.92)",
color: "#ffffff",
fontSize: 48,
width: 640,
height: 140
});
entrySign.position.set(-1.25, 3.34, 4.24);
entrySign.scale.set(2.45, 0.54, 1);
// Accessible clear floor area.
const clearMaterial = new THREE.MeshBasicMaterial({
color: ACCESS,
transparent: true,
opacity: 0.12,
depthWrite: false,
side: THREE.DoubleSide
});
const clearZone = new THREE.Mesh(
new THREE.PlaneGeometry(2.4, 2.4),
clearMaterial
);
clearZone.rotation.x = -Math.PI / 2;
clearZone.position.set(-1.25, 0.605, 2.55);
scene.add(clearZone);
const markingMaterial = new THREE.MeshBasicMaterial({
color: ACCESS,
transparent: true,
opacity: 0.9
});
// Dashed corner markings.
const cornerOffsets = [-1.2, 1.2];
for (const x of cornerOffsets) {
for (const z of cornerOffsets) {
for (let i = 0; i < 3; i++) {
const t = -0.34 + i * 0.34;
addBox(scene, [0.25, 0.018, 0.075], [-1.25 + x, 0.615, 2.55 + z + t], markingMaterial);
addBox(scene, [0.075, 0.018, 0.25], [-1.25 + x + t, 0.615, 2.55 + z], markingMaterial);
}
}
}
makeFloorText("1.5 m KEEP CLEAR", [-1.25, 0.619, 3.23], 2.15, 0.36);
// Call panel.
const panelGroup = new THREE.Group();
panelGroup.position.set(3.55, 0, 2.22);
scene.add(panelGroup);
addBox(panelGroup, [1.65, 0.48, 0.75], [0, 0.8, -0.03], materials.dark, true);
addBox(panelGroup, [2.08, 2.55, 0.34], [0, 1.83, 0], materials.dark, true);
addBox(panelGroup, [0.08, 2.12, 0.04], [-0.93, 1.82, 0.19], material(ACCESS));
const panelTitle = makeSprite("CALL / RESIDENTS", {
background: "rgba(255,255,255,0.08)",
color: "#f9f3e8",
fontSize: 43,
width: 640,
height: 130
});
panelTitle.position.set(3.55, 2.76, 2.44);
panelTitle.scale.set(1.65, 0.36, 1);
const callButtons = [];
const buttonRecords = [];
function addCallButton(id, x, y) {
const buttonMaterial = material(0x455155, {
roughness: 0.48,
metalness: 0.16,
emissive: 0x000000
});
const mesh = addBox(
panelGroup,
[0.66, 0.46, 0.13],
[x, y, 0.22],
buttonMaterial,
true
);
mesh.userData.dwellingId = id;
callButtons.push(mesh);
const numberTexture = makeTextTexture(id, {
color: "#ffffff",
fontSize: 74,
width: 320,
height: 160
});
const number = new THREE.Mesh(
new THREE.PlaneGeometry(0.58, 0.28),
new THREE.MeshBasicMaterial({
map: numberTexture,
transparent: true,
depthWrite: false
})
);
number.position.set(x, y, 0.289);
panelGroup.add(number);
buttonRecords.push({ id, mesh, material: buttonMaterial, number });
}
addCallButton("301", -0.42, 2.19);
addCallButton("302", 0.42, 2.19);
addCallButton("201", -0.42, 1.56);
addCallButton("202", 0.42, 1.56);
addCallButton("101", -0.42, 0.93);
addCallButton("102", 0.42, 0.93);
// Voxel intercom grille.
for (let i = 0; i < 6; i++) {
addBox(
panelGroup,
[0.95 - (i % 2) * 0.14, 0.045, 0.055],
[0, 0.64 + i * 0.075, 0.19],
materials.metal
);
}
const accessBadge = makeSprite("ACCESS", {
background: "rgba(40,127,120,0.95)",
color: "#ffffff",
fontSize: 49,
width: 360,
height: 140
});
accessBadge.position.set(4.86, 2.42, 2.25);
accessBadge.scale.set(0.76, 0.3, 1);
// A few exterior voxel details.
for (const x of [-5.6, 5.6]) {
addBox(scene, [0.52, 0.55, 0.52], [x, 0.46, 3.95], materials.terracotta, true);
addBox(scene, [0.38, 0.7, 0.38], [x, 1.02, 3.95], materials.plant);
}
let selectedId = "101";
let hoveredId = null;
function sideDescription(apartment) {
const side = apartment.side === "left" ? "left" : "right";
return `${levelNames[apartment.level]}, ${side} side`;
}
function paintCallButtons() {
for (const record of buttonRecords) {
const isSelected = record.id === selectedId;
const isHovered = record.id === hoveredId;
record.material.color.setHex(
isSelected ? ACCENT : isHovered ? 0x607174 : 0x455155
);
record.material.emissive.setHex(ACCENT);
record.material.emissiveIntensity = isSelected ? 0.42 : isHovered ? 0.18 : 0;
record.number.material.opacity = isSelected || isHovered ? 1 : 0.9;
}
}
function selectDwelling(id) {
const apartment = apartments.find((item) => item.id === id);
if (!apartment) return;
selectedId = id;
for (const item of apartments) {
const isSelected = item.id === id;
item.highlight.visible = isSelected;
item.floorMaterial.emissive.setHex(isSelected ? ACCENT : 0x000000);
item.floorMaterial.emissiveIntensity = isSelected ? 0.13 : 0;
item.label.scale.set(isSelected ? 1.52 : 1.28, isSelected ? 0.67 : 0.56, 1);
item.label.material.color.setHex(isSelected ? 0xffb09b : 0xffffff);
}
for (const button of uiButtons) {
button.setAttribute("aria-pressed", String(button.dataset.id === id));
}
status.innerHTML =
`<strong>Dwelling ${id}</strong> highlighted — ${sideDescription(apartment)}.`;
paintCallButtons();
}
uiButtons.forEach((button) => {
button.addEventListener("click", () => selectDwelling(button.dataset.id));
});
// Raycasting for the physical call-panel buttons.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function updatePointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function pickButton(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(callButtons, false);
return hits.length ? hits[0].object.userData.dwellingId : null;
}
// Direct camera controls; no addons are used.
let dragging = false;
let pointerId = null;
let dragStartX = 0;
let dragStartY = 0;
let lastX = 0;
let lastY = 0;
let moved = false;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerId = event.pointerId;
dragStartX = lastX = event.clientX;
dragStartY = lastY = event.clientY;
moved = false;
renderer.domElement.setPointerCapture(pointerId);
tooltip.classList.remove("visible");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (dragging) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (
Math.hypot(
event.clientX - dragStartX,
event.clientY - dragStartY
) > 4
) {
moved = true;
}
orbit.theta -= dx * 0.006;
orbit.phi = THREE.MathUtils.clamp(orbit.phi + dy * 0.005, 0.68, 1.34);
lastX = event.clientX;
lastY = event.clientY;
return;
}
const id = pickButton(event);
if (id !== hoveredId) {
hoveredId = id;
paintCallButtons();
}
renderer.domElement.style.cursor = id ? "pointer" : "grab";
if (id) {
tooltip.textContent = `Call dwelling ${id}`;
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
tooltip.classList.add("visible");
} else {
tooltip.classList.remove("visible");
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
if (!dragging) return;
dragging = false;
renderer.domElement.style.cursor = "grab";
if (renderer.domElement.hasPointerCapture(pointerId)) {
renderer.domElement.releasePointerCapture(pointerId);
}
if (!moved) {
const id = pickButton(event);
if (id) selectDwelling(id);
}
pointerId = null;
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
pointerId = null;
});
renderer.domElement.addEventListener("pointerleave", () => {
if (!dragging) {
hoveredId = null;
paintCallButtons();
tooltip.classList.remove("visible");
}
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.012,
12.5,
29
);
},
{ passive: false }
);
renderer.domElement.addEventListener("keydown", (event) => {
const keyStep = 0.09;
if (event.key === "ArrowLeft") orbit.theta += keyStep;
else if (event.key === "ArrowRight") orbit.theta -= keyStep;
else if (event.key === "ArrowUp") orbit.phi -= keyStep;
else if (event.key === "ArrowDown") orbit.phi += keyStep;
else if (event.key === "+" || event.key === "=") orbit.radius -= 1;
else if (event.key === "-") orbit.radius += 1;
else return;
event.preventDefault();
});
document.querySelector("#reset-view").addEventListener("click", () => {
orbit.theta = 0.57;
orbit.phi = 1.03;
orbit.radius = window.innerWidth < 760 ? 22.6 : 20.8;
orbit.target.set(0, 3.7, -0.15);
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
if (window.innerWidth < 760) {
orbit.radius = Math.max(orbit.radius, 22.6);
}
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
const time = clock.elapsedTime;
const smoothing = 1 - Math.exp(-7 * dt);
currentOrbit.theta += (orbit.theta - currentOrbit.theta) * smoothing;
currentOrbit.phi += (orbit.phi - currentOrbit.phi) * smoothing;
currentOrbit.radius += (orbit.radius - currentOrbit.radius) * smoothing;
currentOrbit.target.lerp(orbit.target, smoothing);
const sinPhi = Math.sin(currentOrbit.phi);
const cosPhi = Math.cos(currentOrbit.phi);
camera.position.set(
currentOrbit.target.x +
currentOrbit.radius * sinPhi * Math.sin(currentOrbit.theta),
currentOrbit.target.y + currentOrbit.radius * cosPhi,
currentOrbit.target.z +
currentOrbit.radius * sinPhi * Math.cos(currentOrbit.theta)
);
camera.lookAt(currentOrbit.target);
for (const apartment of apartments) {
if (apartment.highlight.visible) {
apartment.glowMaterial.opacity =
0.14 + (Math.sin(time * 2.3) + 1) * 0.035;
apartment.borderMaterial.opacity =
0.76 + (Math.sin(time * 2.3) + 1) * 0.1;
apartment.selectionLight.intensity =
0.75 + (Math.sin(time * 2.3) + 1) * 0.18;
}
}
renderer.render(scene, camera);
}
selectDwelling("101");
resize();
animate();
requestAnimationFrame(() => {
document.querySelector("#loading").classList.add("hidden");
});
</script>
</body>
</html>
```