Prompt specification
Build or customize the Three.js 3D scene "Two room modules sharing services" 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: Two room modules sharing services
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-room-modules-sharing-services-x2206
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows modular building bays on a shared grid. Arrange two prefabricated room modules beside a common service wall. Expose their connectors and show which interfaces must align before the modules can join. Voxel style.
Working Three.js Starter (two-room-modules-sharing-services-x2206):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#172028" />
<title>Modular Bay Interface Study</title>
<style>
:root {
--ink: #172028;
--ink-soft: #25313a;
--paper: #e9ece7;
--muted: #91a0a7;
--line: rgba(255, 255, 255, 0.11);
--power: #28d6c3;
--hvac: #7898ff;
--struct: #f4b94f;
--ok: #69e49b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--ink);
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
.app {
display: grid;
grid-template-columns: 350px minmax(0, 1fr);
width: 100%;
height: 100%;
}
.panel {
position: relative;
z-index: 10;
display: flex;
min-height: 0;
flex-direction: column;
padding: 28px 26px 24px;
overflow: auto;
background:
linear-gradient(145deg, rgba(255,255,255,.035), transparent 38%),
var(--ink);
border-right: 1px solid var(--line);
box-shadow: 14px 0 45px rgba(0, 0, 0, .16);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 18px;
color: #b9c4c7;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .16em;
text-transform: uppercase;
}
.eyebrow::before {
width: 22px;
height: 3px;
content: "";
background: var(--power);
box-shadow: 8px 0 0 rgba(40, 214, 195, .35);
}
h1 {
max-width: 280px;
margin: 0;
font-size: clamp(29px, 3vw, 43px);
line-height: .98;
letter-spacing: -.045em;
}
.intro {
margin: 18px 0 24px;
color: #aeb9bd;
font-size: 13px;
line-height: 1.65;
}
.status-card {
padding: 15px;
background: rgba(255, 255, 255, .045);
border: 1px solid var(--line);
border-radius: 4px;
}
.status-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.status-title {
display: flex;
align-items: center;
gap: 8px;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .08em;
text-transform: uppercase;
}
.status-dot {
width: 8px;
height: 8px;
background: var(--struct);
border-radius: 50%;
box-shadow: 0 0 0 4px rgba(244, 185, 79, .12);
}
.status-dot.docking {
background: var(--hvac);
box-shadow: 0 0 0 4px rgba(120, 152, 255, .12);
}
.status-dot.ready {
background: var(--ok);
box-shadow: 0 0 0 4px rgba(105, 228, 155, .12);
}
.status-count {
color: #aeb9bd;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.progress-track {
height: 3px;
overflow: hidden;
background: rgba(255,255,255,.08);
}
.progress-bar {
width: 0;
height: 100%;
background: linear-gradient(90deg, var(--power), var(--hvac));
transition: width .1s linear;
}
.section-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 25px 0 10px;
color: #87969d;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .13em;
text-transform: uppercase;
}
.text-button {
padding: 0;
color: #aeb9bd;
background: transparent;
border: 0;
cursor: pointer;
font: inherit;
letter-spacing: .08em;
}
.text-button:hover {
color: white;
}
.interfaces {
display: grid;
gap: 7px;
}
.interface {
--c: var(--power);
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 11px;
width: 100%;
min-height: 52px;
padding: 10px 12px;
color: #dce2e2;
text-align: left;
background: rgba(255, 255, 255, .025);
border: 1px solid transparent;
border-radius: 3px;
cursor: pointer;
transition: .18s ease;
}
.interface:hover,
.interface.active {
background: rgba(255,255,255,.07);
border-color: color-mix(in srgb, var(--c) 50%, transparent);
}
.interface.dimmed {
opacity: .28;
}
.interface-color {
width: 8px;
height: 28px;
background: var(--c);
box-shadow: 0 0 14px color-mix(in srgb, var(--c) 45%, transparent);
}
.interface-name {
display: block;
margin-bottom: 4px;
font-size: 11px;
font-weight: 750;
letter-spacing: .06em;
}
.interface-code {
display: block;
color: #7f9098;
font: 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .09em;
}
.interface-state {
color: #85949a;
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .08em;
}
.interface-state.ready {
color: var(--ok);
}
.controls {
display: grid;
grid-template-columns: 1fr auto;
gap: 8px;
margin-top: 13px;
}
.button {
min-height: 45px;
padding: 0 15px;
color: #142024;
background: var(--power);
border: 1px solid var(--power);
border-radius: 3px;
cursor: pointer;
font-size: 10px;
font-weight: 850;
letter-spacing: .08em;
text-transform: uppercase;
transition: transform .15s ease, filter .15s ease, opacity .15s ease;
}
.button:hover:not(:disabled) {
transform: translateY(-1px);
filter: brightness(1.08);
}
.button:disabled {
cursor: default;
opacity: .42;
}
.button.secondary {
color: #cbd4d5;
background: transparent;
border-color: rgba(255,255,255,.15);
}
.panel-note {
margin-top: auto;
padding-top: 26px;
color: #788990;
font: 9px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .06em;
text-transform: uppercase;
}
.panel-note strong {
color: #aeb9bd;
font-weight: 700;
}
.stage {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dce1dc;
}
.stage canvas {
position: absolute;
inset: 0;
z-index: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
.stage canvas:active {
cursor: grabbing;
}
.stage-meta {
position: absolute;
z-index: 3;
top: 22px;
left: 24px;
display: flex;
gap: 9px;
color: #3e4b50;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .13em;
text-transform: uppercase;
pointer-events: none;
}
.stage-meta span {
padding: 7px 9px;
background: rgba(247, 249, 245, .74);
border: 1px solid rgba(46, 59, 63, .13);
backdrop-filter: blur(8px);
}
.stage-help {
position: absolute;
z-index: 3;
right: 22px;
bottom: 20px;
padding: 9px 11px;
color: #536065;
background: rgba(247, 249, 245, .76);
border: 1px solid rgba(46, 59, 63, .13);
backdrop-filter: blur(8px);
font: 700 9px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .07em;
pointer-events: none;
}
.view-tools {
position: absolute;
z-index: 4;
right: 22px;
top: 22px;
display: flex;
gap: 5px;
}
.view-tools button {
width: 34px;
height: 34px;
padding: 0;
color: #435156;
background: rgba(247, 249, 245, .78);
border: 1px solid rgba(46, 59, 63, .16);
border-radius: 2px;
cursor: pointer;
font-size: 17px;
backdrop-filter: blur(8px);
}
.view-tools button:hover {
background: white;
}
#labels {
position: absolute;
z-index: 2;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
white-space: nowrap;
transform: translate(-50%, -100%);
will-change: left, top;
}
.scene-label.interface-label {
padding: 5px 7px 5px 6px;
color: #243036;
background: rgba(247, 249, 245, .88);
border: 1px solid rgba(45, 57, 62, .16);
border-left: 4px solid var(--label-color);
border-radius: 2px;
box-shadow: 0 4px 12px rgba(39, 49, 51, .09);
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .09em;
pointer-events: auto;
cursor: pointer;
backdrop-filter: blur(6px);
}
.scene-label.interface-label:hover {
background: white;
transform: translate(-50%, -100%) scale(1.05);
}
.scene-label.module-label {
padding: 6px 8px;
color: #263239;
background: rgba(30, 40, 45, .82);
border: 1px solid rgba(255,255,255,.18);
border-radius: 2px;
box-shadow: 0 4px 12px rgba(39, 49, 51, .12);
font: 800 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .1em;
}
.scene-label.wall-label {
color: #334047;
font: 800 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .17em;
text-transform: uppercase;
}
.scene-label::after {
position: absolute;
top: 100%;
left: 50%;
width: 1px;
height: 13px;
content: "";
background: currentColor;
opacity: .42;
}
.scene-label.wall-label::after {
height: 9px;
}
@media (max-width: 820px) {
html,
body {
overflow: auto;
}
.app {
grid-template-columns: 1fr;
grid-template-rows: 56vh 44vh;
}
.stage {
grid-row: 1;
}
.panel {
grid-row: 2;
padding: 21px;
border-right: 0;
border-top: 1px solid var(--line);
}
h1 {
font-size: 30px;
}
.intro {
margin: 12px 0 17px;
}
.panel-note {
display: none;
}
.stage-meta {
top: 13px;
left: 13px;
}
.stage-meta span:nth-child(2) {
display: none;
}
.view-tools {
top: 13px;
right: 13px;
}
.stage-help {
right: 13px;
bottom: 13px;
}
}
</style>
</head>
<body>
<div class="app">
<aside class="panel">
<div class="eyebrow">Assembly field / 04</div>
<h1>Interface<br />dry-fit</h1>
<p class="intro">
Two prefabricated room bays share one service wall. Each bay uses the same
three keyed interfaces. All six connections must align before docking.
</p>
<section class="status-card" aria-live="polite">
<div class="status-head">
<div class="status-title">
<span id="statusDot" class="status-dot"></span>
<span id="statusTitle">Separated</span>
</div>
<div id="statusCount" class="status-count">0 / 6</div>
</div>
<div class="progress-track">
<div id="progressBar" class="progress-bar"></div>
</div>
</section>
<div class="section-label">
<span>Required interfaces</span>
<button id="showAll" class="text-button">Show all</button>
</div>
<div class="interfaces">
<button class="interface" data-type="power" style="--c: var(--power)">
<span class="interface-color"></span>
<span>
<span class="interface-name">POWER / DATA</span>
<span class="interface-code">PWR-01 · ELECTRICAL BUS</span>
</span>
<span class="interface-state">Pending</span>
</button>
<button class="interface" data-type="hvac" style="--c: var(--hvac)">
<span class="interface-color"></span>
<span>
<span class="interface-name">HVAC / WATER</span>
<span class="interface-code">HVC-02 · FLUID LOOP</span>
</span>
<span class="interface-state">Pending</span>
</button>
<button class="interface" data-type="struct" style="--c: var(--struct)">
<span class="interface-color"></span>
<span>
<span class="interface-name">STRUCTURAL KEY</span>
<span class="interface-code">STR-03 · LOAD + LOCATION</span>
</span>
<span class="interface-state">Pending</span>
</button>
</div>
<div class="controls">
<button id="alignButton" class="button">Align + dock</button>
<button id="explodeButton" class="button secondary">Explode</button>
</div>
<div class="panel-note">
<strong>Sequence:</strong> isolate an interface, align the keyed plugs,
then slide both bays into the common wall.<br />
Click a colored plug or label in the model to isolate it.
</div>
</aside>
<main id="stage" class="stage">
<div class="stage-meta">
<span>Axonometric / Grid C-04</span>
<span>2 room modules · 1 service wall</span>
</div>
<div class="view-tools" aria-label="Camera controls">
<button id="zoomIn" title="Zoom in" aria-label="Zoom in">+</button>
<button id="zoomOut" title="Zoom out" aria-label="Zoom out">−</button>
<button id="resetView" title="Reset view" aria-label="Reset view">↺</button>
</div>
<div class="stage-help">
DRAG TO ORBIT · SCROLL TO ZOOM<br />
CLICK A PORT TO ISOLATE
</div>
<div id="labels"></div>
</main>
</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 labelsLayer = document.getElementById("labels");
const alignButton = document.getElementById("alignButton");
const explodeButton = document.getElementById("explodeButton");
const showAllButton = document.getElementById("showAll");
const statusDot = document.getElementById("statusDot");
const statusTitle = document.getElementById("statusTitle");
const statusCount = document.getElementById("statusCount");
const progressBar = document.getElementById("progressBar");
const interfaceButtons = [...document.querySelectorAll(".interface")];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce1dc);
scene.fog = new THREE.Fog(0xdce1dc, 30, 58);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.prepend(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.45, -0.65);
const controls = {
yaw: 0.48,
pitch: 0.68,
zoom: 1,
dragging: false,
pointerId: null,
startX: 0,
startY: 0,
lastX: 0,
lastY: 0,
moved: false
};
function updateCamera() {
const width = stage.clientWidth;
const height = stage.clientHeight;
const aspect = width / Math.max(height, 1);
const viewSize = Math.max(13.8, 20 / aspect);
camera.left = (-viewSize * aspect) / 2;
camera.right = (viewSize * aspect) / 2;
camera.top = viewSize / 2;
camera.bottom = -viewSize / 2;
camera.zoom = controls.zoom;
camera.updateProjectionMatrix();
const horizontal = Math.cos(controls.pitch);
camera.position.set(
cameraTarget.x + Math.sin(controls.yaw) * horizontal * 32,
cameraTarget.y + Math.sin(controls.pitch) * 32,
cameraTarget.z + Math.cos(controls.yaw) * horizontal * 32
);
camera.lookAt(cameraTarget);
}
function resize() {
renderer.setSize(stage.clientWidth, stage.clientHeight);
updateCamera();
}
new ResizeObserver(resize).observe(stage);
const hemi = new THREE.HemisphereLight(0xf7fbff, 0x69736e, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff7e9, 3.1);
sun.position.set(10, 16, 12);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -16;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rim = new THREE.DirectionalLight(0xaac8ff, 0.8);
rim.position.set(-12, 8, -10);
scene.add(rim);
const materials = {
ground: new THREE.MeshStandardMaterial({
color: 0xbac4bf, roughness: 0.95
}),
floor: new THREE.MeshStandardMaterial({
color: 0x8f9d9b, roughness: 0.86
}),
wall: new THREE.MeshStandardMaterial({
color: 0xd5d9d2, roughness: 0.83
}),
wallDark: new THREE.MeshStandardMaterial({
color: 0x354149, roughness: 0.72
}),
wallRib: new THREE.MeshStandardMaterial({
color: 0x536169, roughness: 0.67
}),
frame: new THREE.MeshStandardMaterial({
color: 0x26323a, roughness: 0.56, metalness: 0.12
}),
cream: new THREE.MeshStandardMaterial({
color: 0xe7e6dc, roughness: 0.87
}),
fabricA: new THREE.MeshStandardMaterial({
color: 0x668d8c, roughness: 0.95
}),
fabricB: new THREE.MeshStandardMaterial({
color: 0xb98261, roughness: 0.95
}),
accentA: new THREE.MeshStandardMaterial({
color: 0x28d6c3, roughness: 0.55
}),
accentB: new THREE.MeshStandardMaterial({
color: 0xf09a62, roughness: 0.55
}),
wood: new THREE.MeshStandardMaterial({
color: 0xb99469, roughness: 0.84
}),
white: new THREE.MeshStandardMaterial({
color: 0xf4f4eb, roughness: 0.72
}),
black: new THREE.MeshStandardMaterial({
color: 0x151d22, roughness: 0.48
}),
green: new THREE.MeshStandardMaterial({
color: 0x4e8b61, roughness: 0.9
}),
yellow: new THREE.MeshStandardMaterial({
color: 0xd6b95f, roughness: 0.82
}),
lock: new THREE.MeshStandardMaterial({
color: 0x69e49b,
emissive: 0x2baa67,
emissiveIntensity: 0.6,
roughness: 0.38
})
};
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x26343a,
transparent: true,
opacity: 0.23,
depthWrite: false
});
function box(
width, height, depth, material,
x = 0, y = 0, z = 0,
parent = scene,
outlined = false
) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (outlined) {
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
edgeMaterial
);
edges.scale.setScalar(1.002);
mesh.add(edges);
}
return mesh;
}
// Shared ground and modular construction grid.
box(22, 0.48, 16, materials.ground, 0, -0.29, -0.4, scene, true);
const grid = new THREE.GridHelper(20, 20, 0x687a78, 0x91a09d);
grid.position.set(0, -0.035, -0.4);
[].concat(grid.material).forEach(material => {
material.transparent = true;
material.opacity = 0.52;
});
scene.add(grid);
// Registration strips along the shared datum.
box(18.6, 0.025, 0.055, materials.yellow, 0, -0.012, 4.0);
box(0.055, 0.025, 13.8, materials.yellow, -8.4, -0.012, -0.2);
box(0.055, 0.025, 13.8, materials.yellow, 8.4, -0.012, -0.2);
const interfaceDefinitions = [
{
type: "power",
name: "POWER / DATA",
short: "PWR",
code: "PWR-01",
offset: -1.65,
color: 0x28d6c3,
css: "#28d6c3"
},
{
type: "hvac",
name: "HVAC / WATER",
short: "HVAC",
code: "HVC-02",
offset: 0,
color: 0x7898ff,
css: "#7898ff"
},
{
type: "struct",
name: "STRUCTURAL KEY",
short: "KEY",
code: "STR-03",
offset: 1.65,
color: 0xf4b94f,
css: "#f4b94f"
}
];
const typeMaterials = {
power: new THREE.MeshStandardMaterial({
color: 0x28d6c3,
emissive: 0x0c6e65,
emissiveIntensity: 0.18,
roughness: 0.42,
transparent: true
}),
hvac: new THREE.MeshStandardMaterial({
color: 0x7898ff,
emissive: 0x263f91,
emissiveIntensity: 0.18,
roughness: 0.42,
transparent: true
}),
struct: new THREE.MeshStandardMaterial({
color: 0xf4b94f,
emissive: 0x835600,
emissiveIntensity: 0.16,
roughness: 0.46,
transparent: true
})
};
// Common service wall.
const serviceWall = new THREE.Group();
scene.add(serviceWall);
box(18.3, 4.25, 0.70, materials.wallDark, 0, 2.125, -3.55, serviceWall, true);
box(18.55, 0.42, 0.82, materials.frame, 0, 0.19, -3.55, serviceWall);
box(18.55, 0.34, 0.86, materials.wallRib, 0, 4.24, -3.55, serviceWall);
[-8.45, -6.0, -3.0, 0, 3.0, 6.0, 8.45].forEach((x, index) => {
box(
0.22, 3.72, 0.82,
index === 3 ? materials.accentB : materials.wallRib,
x, 2.18, -3.51, serviceWall
);
});
// Central service chase.
box(0.66, 3.35, 0.91, materials.cream, 0, 2.1, -3.47, serviceWall);
box(0.12, 2.55, 0.97, materials.accentB, 0, 2.1, -3.44, serviceWall);
box(0.32, 0.36, 0.99, materials.frame, 0, 3.65, -3.43, serviceWall);
const moduleDefinitions = [
{
id: "A",
name: "BAY A / LIVING",
targetX: -4.25,
explodedX: -4.60,
targetZ: -0.35,
explodedZ: 1.05,
accent: materials.accentA,
lab: false
},
{
id: "B",
name: "BAY B / UTILITY",
targetX: 4.25,
explodedX: 4.60,
targetZ: -0.35,
explodedZ: 1.05,
accent: materials.accentB,
lab: true
}
];
function makeFootprint(x, z, width, depth, color) {
const material = new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.42,
depthWrite: false
});
box(width, 0.018, 0.045, material, x, 0.012, z - depth / 2);
box(width, 0.018, 0.045, material, x, 0.012, z + depth / 2);
box(0.045, 0.018, depth, material, x - width / 2, 0.012, z);
box(0.045, 0.018, depth, material, x + width / 2, 0.012, z);
}
makeFootprint(-4.25, -0.35, 7, 5.4, 0x28d6c3);
makeFootprint(4.25, -0.35, 7, 5.4, 0xf09a62);
function createSocket(definition, x) {
const group = new THREE.Group();
group.position.set(x, 3.05, -3.03);
serviceWall.add(group);
box(0.76, 0.65, 0.18, materials.black, 0, 0, 0, group, true);
box(0.58, 0.46, 0.11, typeMaterials[definition.type], 0, 0, 0.13, group);
if (definition.type === "power") {
box(0.075, 0.20, 0.07, materials.black, -0.12, 0, 0.22, group);
box(0.075, 0.20, 0.07, materials.black, 0.12, 0, 0.22, group);
} else if (definition.type === "hvac") {
[-0.13, 0, 0.13].forEach(y => {
box(0.39, 0.055, 0.075, materials.black, 0, y, 0.22, group);
});
} else {
box(0.12, 0.38, 0.075, materials.black, 0, 0, 0.22, group);
box(0.38, 0.12, 0.075, materials.black, 0, 0, 0.22, group);
}
const lock = box(
0.19, 0.19, 0.19,
materials.lock,
0, 0.54, 0.12,
group
);
lock.visible = false;
return { group, lock };
}
function createPlug(definition, moduleGroup, x) {
const group = new THREE.Group();
group.position.set(x, 3.05, -2.25);
moduleGroup.add(group);
box(0.67, 0.56, 0.35, materials.black, 0, 0, 0, group, true);
box(0.55, 0.42, 0.09, typeMaterials[definition.type], 0, 0, 0.20, group);
const stem = box(
0.40, 0.31, 0.30,
typeMaterials[definition.type],
0, 0, -0.26,
group
);
if (definition.type === "power") {
box(0.07, 0.18, 0.09, materials.black, -0.10, 0, -0.45, group);
box(0.07, 0.18, 0.09, materials.black, 0.10, 0, -0.45, group);
} else if (definition.type === "hvac") {
[-0.10, 0, 0.10].forEach(y => {
box(0.31, 0.045, 0.09, materials.black, 0, y, -0.45, group);
});
} else {
box(0.10, 0.28, 0.09, materials.black, 0, 0, -0.45, group);
box(0.28, 0.10, 0.09, materials.black, 0, 0, -0.45, group);
}
group.traverse(object => {
if (object.isMesh) object.userData.interfaceType = definition.type;
});
return { group, stem };
}
function createRoomA(group, accent) {
// Living-room bed.
box(2.20, 0.45, 2.95, materials.frame, -1.75, 0.48, 0.20, group, true);
box(2.08, 0.28, 2.78, materials.white, -1.75, 0.83, 0.20, group);
box(1.98, 0.13, 1.75, materials.fabricA, -1.75, 1.025, 0.56, group);
box(1.62, 0.17, 0.56, materials.white, -1.75, 1.04, -0.75, group, true);
// Sofa.
box(2.35, 0.48, 1.08, materials.fabricA, 1.55, 0.51, 0.78, group, true);
box(2.35, 0.78, 0.25, materials.fabricA, 1.55, 0.98, 0.25, group);
box(0.26, 0.68, 1.12, materials.fabricA, 0.49, 0.76, 0.78, group);
box(0.26, 0.68, 1.12, materials.fabricA, 2.61, 0.76, 0.78, group);
// Table and rug.
box(2.40, 0.04, 2.12, materials.cream, 0.95, 0.275, -0.85, group);
box(1.15, 0.36, 0.70, materials.wood, 1.30, 0.48, -0.58, group, true);
box(0.18, 0.36, 0.18, materials.frame, 1.30, 0.32, -0.58, group);
// Voxel shelf and plant.
box(0.72, 1.45, 0.36, materials.wood, -2.86, 1.00, -1.64, group, true);
box(0.14, 0.70, 0.14, materials.black, 2.77, 0.62, -1.66, group);
box(0.62, 0.36, 0.62, materials.green, 2.77, 1.13, -1.66, group);
box(0.40, 0.42, 0.40, materials.green, 2.77, 1.50, -1.66, group);
}
function createRoomB(group, accent) {
// Rear service counter.
box(4.75, 1.08, 0.72, materials.cream, 0.40, 0.82, -1.75, group, true);
box(4.93, 0.14, 0.84, materials.frame, 0.40, 1.43, -1.75, group);
for (let i = 0; i < 4; i++) {
box(0.06, 0.74, 0.06, materials.black, -1.25 + i * 1.08, 0.88, -1.37, group);
}
// Island.
box(2.65, 0.82, 1.25, materials.fabricB, 0.50, 0.68, 0.15, group, true);
box(2.83, 0.15, 1.42, materials.frame, 0.50, 1.16, 0.15, group);
// Stools.
[-0.30, 0.50, 1.30].forEach(x => {
box(0.52, 0.17, 0.52, materials.accentB, x, 0.74, 1.52, group, true);
box(0.15, 0.50, 0.15, materials.frame, x, 0.46, 1.52, group);
});
// Tall storage blocks.
box(1.15, 2.15, 0.74, materials.wall, 2.67, 1.35, -1.58, group, true);
box(0.92, 0.09, 0.80, materials.frame, 2.67, 1.28, -1.53, group);
box(0.92, 0.09, 0.80, materials.frame, 2.67, 1.72, -1.53, group);
// Utility cabinet and wall-mounted screen.
box(1.18, 1.25, 0.76, materials.wall, -2.70, 0.90, -1.63, group, true);
box(0.74, 0.48, 0.09, materials.black, -2.70, 1.74, -1.30, group);
box(0.56, 0.30, 0.03, accent, -2.70, 1.74, -1.24, group);
}
const modules = [];
const interfaces = [];
const clickTargets = [];
for (const definition of moduleDefinitions) {
const group = new THREE.Group();
group.position.set(definition.explodedX, 0, definition.explodedZ);
scene.add(group);
// Module shell: front and roof are removed for an architectural cutaway.
box(7.05, 0.28, 5.45, materials.floor, 0, 0.13, 0, group, true);
box(7.18, 0.10, 0.16, definition.accent, 0, 0.25, 2.71, group);
box(7.00, 2.28, 0.24, materials.wall, 0, 1.40, -2.58, group, true);
box(0.24, 1.45, 5.30, materials.wall, -3.38, 0.99, 0.03, group, true);
box(0.24, 1.15, 5.30, materials.wall, 3.38, 0.84, 0.03, group, true);
box(0.26, 2.42, 0.29, materials.frame, -3.38, 1.47, -2.56, group);
box(0.26, 2.42, 0.29, materials.frame, 3.38, 1.47, -2.56, group);
box(6.95, 0.18, 0.30, definition.accent, 0, 2.64, -2.58, group);
// Exposed voxel utility rail above the service wall.
box(5.60, 0.14, 0.20, materials.frame, 0, 2.78, -2.50, group);
if (definition.lab) {
createRoomB(group, definition.accent);
} else {
createRoomA(group, definition.accent);
}
const moduleRecord = {
...definition,
group
};
modules.push(moduleRecord);
for (const interfaceDefinition of interfaceDefinitions) {
const worldX = definition.targetX + interfaceDefinition.offset;
const socket = createSocket(interfaceDefinition, worldX);
const plug = createPlug(interfaceDefinition, group, interfaceDefinition.offset);
clickTargets.push(plug.group, socket.group);
const guideGroup = new THREE.Group();
scene.add(guideGroup);
const guideMaterial = new THREE.LineBasicMaterial({
color: interfaceDefinition.color,
transparent: true,
opacity: 0.9,
depthWrite: false
});
const dashes = [];
for (let i = 0; i < 10; i++) {
const dash = new THREE.Mesh(
new THREE.BoxGeometry(0.075, 0.075, 1),
new THREE.MeshBasicMaterial({
color: interfaceDefinition.color,
transparent: true,
opacity: 0.88,
depthWrite: false
})
);
dash.renderOrder = 5;
guideGroup.add(dash);
dashes.push(dash);
}
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.15, 0.15, 0.15),
new THREE.MeshBasicMaterial({
color: interfaceDefinition.color,
transparent: true,
opacity: 0.9,
depthWrite: false
})
);
guideGroup.add(marker);
const record = {
module: moduleRecord,
definition: interfaceDefinition,
plug,
socket,
guideGroup,
guideMaterial,
dashes,
marker,
target: new THREE.Vector3(worldX, 3.05, -2.93)
};
interfaces.push(record);
}
}
// HTML labels are positioned by projecting Three.js world points.
function createSceneLabel(text, className, color) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
element.textContent = text;
if (color) {
element.style.setProperty("--label-color", color);
}
labelsLayer.appendChild(element);
return element;
}
const wallLabel = createSceneLabel("COMMON SERVICE WALL", "wall-label");
for (const moduleRecord of modules) {
moduleRecord.labelElement = createSceneLabel(
moduleRecord.name,
"module-label"
);
}
for (const record of interfaces) {
record.labelElement = createSceneLabel(
record.definition.short,
"interface-label",
record.definition.css
);
record.labelElement.addEventListener("click", event => {
event.stopPropagation();
focusType(record.definition.type);
});
}
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * stage.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * stage.clientHeight;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -100 &&
x < stage.clientWidth + 100 &&
y > -50 &&
y < stage.clientHeight + 50;
element.style.display = visible ? "" : "none";
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
const worldPoint = new THREE.Vector3();
function updateLabels() {
positionLabel(wallLabel, new THREE.Vector3(0, 4.75, -3.48));
for (const moduleRecord of modules) {
moduleRecord.group.getWorldPosition(worldPoint);
worldPoint.y += 0.38;
worldPoint.z += 2.42;
positionLabel(moduleRecord.labelElement, worldPoint);
}
for (const record of interfaces) {
record.plug.group.getWorldPosition(worldPoint);
worldPoint.y += 0.54;
positionLabel(record.labelElement, worldPoint);
}
}
const zAxis = new THREE.Vector3(0, 0, 1);
const guideStart = new THREE.Vector3();
const guideEnd = new THREE.Vector3();
const guideDirection = new THREE.Vector3();
const guideQuaternion = new THREE.Quaternion();
function updateGuides() {
for (const record of interfaces) {
record.plug.group.getWorldPosition(guideStart);
guideStart.z -= 0.41;
guideEnd.copy(record.target);
guideDirection.subVectors(guideEnd, guideStart);
const length = guideDirection.length();
if (length > 0.0001) {
guideQuaternion.setFromUnitVectors(zAxis, guideDirection.normalize());
}
record.dashes.forEach((dash, index) => {
const t = (index + 0.5) / record.dashes.length;
dash.position.lerpVectors(guideStart, guideEnd, t);
dash.quaternion.copy(guideQuaternion);
dash.scale.z = Math.min(0.18, length * 0.055);
dash.visible = length > 0.035;
});
record.marker.position.copy(guideStart);
record.marker.quaternion.copy(guideQuaternion);
record.marker.visible = length > 0.025;
}
}
let focusedType = null;
function focusType(type) {
focusedType = focusedType === type ? null : type;
interfaceButtons.forEach(button => {
const active = button.dataset.type === focusedType;
button.classList.toggle("active", active);
button.classList.toggle("dimmed", focusedType !== null && !active);
});
for (const [key, material] of Object.entries(typeMaterials)) {
const active = focusedType === null || focusedType === key;
material.opacity = active ? 1 : 0.14;
material.depthWrite = active;
}
for (const record of interfaces) {
const active = focusedType === null || focusedType === record.definition.type;
record.dashes.forEach(dash => {
dash.material.opacity = active ? 0.88 : 0.05;
});
record.marker.material.opacity = active ? 0.92 : 0.04;
record.labelElement.style.display = active ? "" : "none";
}
}
interfaceButtons.forEach(button => {
button.addEventListener("click", () => focusType(button.dataset.type));
});
showAllButton.addEventListener("click", () => {
focusedType = null;
interfaceButtons.forEach(button => {
button.classList.remove("active", "dimmed");
});
Object.values(typeMaterials).forEach(material => {
material.opacity = 1;
material.depthWrite = true;
});
interfaces.forEach(record => {
record.dashes.forEach(dash => dash.material.opacity = 0.88);
record.marker.material.opacity = 0.92;
});
});
let transition = null;
let locked = false;
let mode = "exploded";
function beginTransition(dock) {
if (transition) return;
transition = {
startTime: performance.now(),
duration: 1900,
dock,
from: modules.map(module => ({
x: module.group.position.x,
z: module.group.position.z
}))
};
locked = false;
mode = dock ? "docking" : "exploding";
alignButton.disabled = true;
explodeButton.disabled = true;
}
alignButton.addEventListener("click", () => beginTransition(true));
explodeButton.addEventListener("click", () => beginTransition(false));
function easeInOutCubic(value) {
return value < 0.5
? 4 * value * value * value
: 1 - Math.pow(-2 * value + 2, 3) / 2;
}
function updateTransition(now) {
if (!transition) return;
const raw = Math.min(1, (now - transition.startTime) / transition.duration);
const eased = easeInOutCubic(raw);
modules.forEach((module, index) => {
const from = transition.from[index];
const targetX = transition.dock ? module.targetX : module.explodedX;
const targetZ = transition.dock ? module.targetZ : module.explodedZ;
module.group.position.x = THREE.MathUtils.lerp(from.x, targetX, eased);
module.group.position.z = THREE.MathUtils.lerp(from.z, targetZ, eased);
});
progressBar.style.width = `${transition.dock ? raw * 100 : (1 - raw) * 100}%`;
if (raw >= 1) {
locked = transition.dock;
mode = transition.dock ? "docked" : "exploded";
transition = null;
alignButton.disabled = locked;
explodeButton.disabled = false;
alignButton.textContent = locked ? "Modules docked" : "Align + dock";
}
}
function updateStatus() {
let ready = 0;
for (const record of interfaces) {
const dx = Math.abs(record.module.group.position.x - record.module.targetX);
const dz = Math.abs(record.module.group.position.z - record.module.targetZ);
const isReady = dx < 0.09 && dz < 0.09;
if (isReady) ready++;
const row = interfaceButtons.find(button =>
button.dataset.type === record.definition.type
);
// The state reflects all repeated ports of that interface family.
const familyReady = interfaces
.filter(item => item.definition.type === record.definition.type)
.every(item => {
const x = Math.abs(item.module.group.position.x - item.module.targetX);
const z = Math.abs(item.module.group.position.z - item.module.targetZ);
return x < 0.09 && z < 0.09;
});
row.querySelector(".interface-state").textContent = familyReady ? "Aligned" : "Pending";
row.querySelector(".interface-state").classList.toggle("ready", familyReady);
record.socket.lock.visible = isReady;
}
statusCount.textContent = `${ready} / 6`;
if (mode === "docked") {
statusTitle.textContent = "Interfaces locked";
statusDot.className = "status-dot ready";
progressBar.style.width = "100%";
alignButton.textContent = "Modules docked";
} else if (mode === "docking") {
statusTitle.textContent = "Aligning";
statusDot.className = "status-dot docking";
} else if (mode === "exploding") {
statusTitle.textContent = "Releasing";
statusDot.className = "status-dot docking";
} else {
statusTitle.textContent = "Separated";
statusDot.className = "status-dot";
progressBar.style.width = "0%";
alignButton.textContent = "Align + dock";
}
}
// Direct camera controls, implemented without external examples or add-ons.
renderer.domElement.addEventListener("pointerdown", event => {
controls.dragging = true;
controls.pointerId = event.pointerId;
controls.startX = event.lastX;
controls.startY = event.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.moved = false;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging || event.pointerId !== controls.pointerId) return;
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
if (
Math.abs(event.clientX - controls.startX) +
Math.abs(event.clientY - controls.startY) > 4
) {
controls.moved = true;
}
controls.yaw -= dx * 0.005;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.004,
0.28,
1.12
);
controls.lastX = event.clientX;
controls.lastY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", event => {
if (controls.pointerId !== event.pointerId) return;
controls.dragging = false;
controls.pointerId = null;
if (!controls.moved) {
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;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(clickTargets, true);
if (hits.length) {
let object = hits[0].object;
while (object && !object.userData.interfaceType) {
object = object.parent;
}
if (object?.userData.interfaceType) {
focusType(object.userData.interfaceType);
}
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
controls.dragging = false;
controls.pointerId = null;
});
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
controls.zoom = THREE.MathUtils.clamp(
controls.zoom * Math.exp(-event.deltaY * 0.001),
0.68,
1.75
);
updateCamera();
}, { passive: false });
document.getElementById("zoomIn").addEventListener("click", () => {
controls.zoom = Math.min(1.75, controls.zoom * 1.12);
updateCamera();
});
document.getElementById("zoomOut").addEventListener("click", () => {
controls.zoom = Math.max(0.68, controls.zoom / 1.12);
updateCamera();
});
document.getElementById("resetView").addEventListener("click", () => {
controls.yaw = 0.48;
controls.pitch = 0.68;
controls.zoom = 1;
updateCamera();
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
resize();
updateStatus();
renderer.setAnimationLoop(now => {
updateTransition(now);
updateStatus();
updateGuides();
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```