Prompt specification
Build or customize the Three.js 3D scene "Small house envelope section" 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: Small house envelope section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/small-house-envelope-section-x2179
Scene Description Prompt:
Cut away a voxel house to show roof, wall, floor, and window layers forming its thermal envelope. Use Three.js from cdnjs in standalone HTML.
Working Three.js Starter (small-house-envelope-section-x2179):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Thermal Envelope</title>
<style>
:root {
color-scheme: dark;
--bg: #071117;
--panel: rgba(12, 24, 31, 0.82);
--panel-border: rgba(174, 220, 231, 0.14);
--text: #edf7f8;
--muted: #8ea6ad;
--cyan: #71d4e5;
--orange: #ff9c68;
--yellow: #f2ca62;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 68% 38%, #13252e 0, #09151b 42%, #050c10 100%);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
}
.ui button,
.ui input,
.panel,
.readout {
pointer-events: auto;
}
header {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 72px;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 26px;
background: linear-gradient(
to bottom,
rgba(5, 13, 17, 0.92),
rgba(5, 13, 17, 0)
);
}
.brand {
display: flex;
align-items: center;
gap: 13px;
}
.brand-mark {
position: relative;
width: 34px;
height: 34px;
border: 1px solid rgba(113, 212, 229, 0.5);
border-radius: 7px;
transform: rotate(45deg);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--cyan);
opacity: 0.8;
}
.brand-mark::before {
width: 16px;
height: 1px;
left: 8px;
top: 16px;
}
.brand-mark::after {
width: 1px;
height: 16px;
left: 16px;
top: 8px;
}
.brand-title {
font-size: 13px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.brand-subtitle {
margin-top: 3px;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
}
.header-actions {
display: flex;
align-items: center;
gap: 12px;
}
.live-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 8px 12px;
border: 1px solid var(--panel-border);
border-radius: 999px;
background: rgba(12, 26, 32, 0.68);
color: #bdd0d4;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.live-dot {
width: 6px;
height: 6px;
border-radius: 50%;
background: #73e0a6;
box-shadow: 0 0 12px #73e0a6;
}
.reset-button {
border: 1px solid var(--panel-border);
background: rgba(12, 26, 32, 0.72);
border-radius: 9px;
padding: 9px 13px;
cursor: pointer;
color: #d6e5e8;
font-size: 12px;
transition:
background 160ms ease,
border-color 160ms ease;
}
.reset-button:hover {
background: rgba(29, 55, 66, 0.88);
border-color: rgba(113, 212, 229, 0.38);
}
.panel {
position: absolute;
top: 88px;
left: 24px;
width: 292px;
padding: 21px;
border: 1px solid var(--panel-border);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 20px 60px rgba(0, 0, 0, 0.25),
inset 0 1px 0 rgba(255, 255, 255, 0.03);
backdrop-filter: blur(18px);
}
.eyebrow {
color: var(--cyan);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 7px 0 8px;
font-size: 24px;
line-height: 1.08;
font-weight: 650;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 19px;
color: var(--muted);
font-size: 12px;
line-height: 1.55;
}
.section-label {
display: flex;
justify-content: space-between;
margin: 17px 0 9px;
color: #8ea6ad;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.layer-list {
display: grid;
gap: 7px;
}
.layer-button {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 12px 1fr auto;
align-items: center;
gap: 11px;
min-height: 45px;
padding: 10px 11px;
border: 1px solid transparent;
border-radius: 10px;
background: rgba(255, 255, 255, 0.035);
text-align: left;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.layer-button:hover {
background: rgba(255, 255, 255, 0.065);
transform: translateX(2px);
}
.layer-button.active {
background: rgba(113, 212, 229, 0.095);
border-color: rgba(113, 212, 229, 0.34);
}
.layer-swatch {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: 0 0 12px currentColor;
}
.layer-name {
display: block;
font-size: 12px;
font-weight: 650;
}
.layer-detail {
display: block;
margin-top: 2px;
color: #7f979f;
font-size: 9px;
}
.layer-count {
color: #80969e;
font-size: 10px;
font-variant-numeric: tabular-nums;
}
.range-header {
display: flex;
align-items: center;
justify-content: space-between;
margin: 19px 0 9px;
color: #9bb0b6;
font-size: 10px;
}
.range-header output {
color: var(--cyan);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 4px;
margin: 4px 0 0;
border-radius: 4px;
appearance: none;
background: linear-gradient(
to right,
var(--cyan) 0%,
var(--cyan) var(--range-progress, 28%),
rgba(255, 255, 255, 0.1) var(--range-progress, 28%),
rgba(255, 255, 255, 0.1) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 14px;
height: 14px;
border: 2px solid #0b1920;
border-radius: 50%;
appearance: none;
background: var(--cyan);
box-shadow: 0 0 0 1px rgba(113, 212, 229, 0.45);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 2px solid #0b1920;
border-radius: 50%;
background: var(--cyan);
}
.setting {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 16px;
color: #bdcdd1;
font-size: 11px;
}
.setting-copy strong {
display: block;
margin-bottom: 3px;
font-size: 11px;
font-weight: 600;
}
.setting-copy span {
display: block;
color: #718990;
font-size: 9px;
}
.switch {
position: relative;
flex: 0 0 auto;
width: 36px;
height: 20px;
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
cursor: pointer;
transition: 160ms ease;
}
.switch-track::after {
content: "";
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
border-radius: 50%;
background: #71858c;
transition: 160ms ease;
}
.switch input:checked + .switch-track {
border-color: rgba(113, 212, 229, 0.42);
background: rgba(113, 212, 229, 0.18);
}
.switch input:checked + .switch-track::after {
transform: translateX(16px);
background: var(--cyan);
box-shadow: 0 0 9px rgba(113, 212, 229, 0.6);
}
.readout {
position: absolute;
top: 91px;
right: 26px;
width: 230px;
padding: 17px 18px;
border: 1px solid var(--panel-border);
border-radius: 14px;
background: rgba(9, 21, 27, 0.67);
backdrop-filter: blur(14px);
}
.component-name {
margin-top: 7px;
font-size: 16px;
font-weight: 650;
}
.metric-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 15px;
}
.metric {
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.metric-value {
display: block;
font-size: 16px;
font-weight: 650;
font-variant-numeric: tabular-nums;
}
.metric-label {
display: block;
margin-top: 3px;
color: #718a92;
font-size: 8px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.legend {
position: absolute;
left: 50%;
bottom: 25px;
display: flex;
align-items: center;
gap: 18px;
max-width: calc(100% - 50px);
padding: 11px 16px;
border: 1px solid var(--panel-border);
border-radius: 12px;
background: rgba(7, 18, 23, 0.8);
backdrop-filter: blur(14px);
transform: translateX(-50%);
white-space: nowrap;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: #9fb2b8;
font-size: 9px;
}
.legend-item i {
width: 8px;
height: 8px;
border-radius: 2px;
}
.hint {
position: absolute;
right: 27px;
bottom: 26px;
color: rgba(165, 189, 195, 0.58);
font-size: 9px;
letter-spacing: 0.05em;
}
.world-label {
position: absolute;
z-index: 3;
display: flex;
align-items: center;
gap: 8px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(172, 215, 222, 0.18);
border-radius: 8px;
background: rgba(7, 18, 23, 0.76);
box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(10px);
color: #d9e7e9;
font-size: 9px;
letter-spacing: 0.04em;
white-space: nowrap;
pointer-events: none;
transform: translate(-50%, -50%);
transition:
opacity 180ms ease,
border-color 180ms ease;
}
.world-label span {
display: grid;
place-items: center;
width: 20px;
height: 20px;
border-radius: 5px;
background: rgba(113, 212, 229, 0.13);
color: var(--cyan);
font-size: 8px;
font-weight: 750;
}
.world-label.muted {
opacity: 0.22;
}
.world-label.active {
border-color: rgba(113, 212, 229, 0.48);
}
@media (max-width: 900px) {
.readout,
.hint {
display: none;
}
.panel {
width: 270px;
}
.legend {
left: 24px;
transform: none;
}
}
@media (max-width: 640px) {
header {
height: 62px;
padding: 0 14px;
}
.brand-subtitle,
.live-pill {
display: none;
}
.panel {
top: 72px;
left: 12px;
right: 12px;
width: auto;
max-height: 45vh;
padding: 15px;
overflow-y: auto;
}
h1 {
font-size: 19px;
}
.intro,
.legend {
display: none;
}
.layer-list {
grid-template-columns: repeat(2, 1fr);
}
.layer-button {
min-height: 39px;
}
.layer-detail {
display: none;
}
.world-label {
display: none !important;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway of a voxel house thermal envelope"></canvas>
<div class="ui">
<header>
<div class="brand">
<div class="brand-mark"></div>
<div>
<div class="brand-title">Heat Path / 01</div>
<div class="brand-subtitle">Voxel building envelope study</div>
</div>
</div>
<div class="header-actions">
<div class="live-pill">
<span class="live-dot"></span>
Interactive model
</div>
<button class="reset-button" id="resetView">Reset view</button>
</div>
</header>
<aside class="panel">
<div class="eyebrow">Assembly explorer</div>
<h1>Thermal envelope</h1>
<p class="intro">
Inspect the roof, wall, floor, and glazing assemblies exposed by the
diagonal cutaway.
</p>
<div class="section-label">
<span>Component</span>
<span>Layers</span>
</div>
<div class="layer-list">
<button class="layer-button active" data-layer="all">
<i class="layer-swatch" style="color:#71d4e5;background:#71d4e5"></i>
<span>
<span class="layer-name">Overview</span>
<span class="layer-detail">Complete envelope</span>
</span>
<span class="layer-count">4</span>
</button>
<button class="layer-button" data-layer="roof">
<i class="layer-swatch" style="color:#4e8298;background:#4e8298"></i>
<span>
<span class="layer-name">Roof</span>
<span class="layer-detail">Membrane / wool / deck</span>
</span>
<span class="layer-count">3</span>
</button>
<button class="layer-button" data-layer="wall">
<i class="layer-swatch" style="color:#d9c47d;background:#d9c47d"></i>
<span>
<span class="layer-name">Walls</span>
<span class="layer-detail">Cladding / wool / lining</span>
</span>
<span class="layer-count">3</span>
</button>
<button class="layer-button" data-layer="floor">
<i class="layer-swatch" style="color:#b77546;background:#b77546"></i>
<span>
<span class="layer-name">Floor</span>
<span class="layer-detail">Slab / wool / finish</span>
</span>
<span class="layer-count">3</span>
</button>
<button class="layer-button" data-layer="window">
<i class="layer-swatch" style="color:#66c9dd;background:#66c9dd"></i>
<span>
<span class="layer-name">Windows</span>
<span class="layer-detail">Frame / pane / reveal</span>
</span>
<span class="layer-count">2</span>
</button>
</div>
<div class="range-header">
<span>Layer separation</span>
<output id="separationValue">28%</output>
</div>
<input
id="separation"
type="range"
min="0"
max="100"
value="28"
aria-label="Layer separation"
/>
<div class="setting">
<div class="setting-copy">
<strong>Diagonal cutaway</strong>
<span>Reveal the interior assembly</span>
</div>
<label class="switch">
<input id="cutaway" type="checkbox" checked />
<span class="switch-track"></span>
</label>
</div>
<div class="setting">
<div class="setting-copy">
<strong>Thermal overlay</strong>
<span>Highlight resistance and heat paths</span>
</div>
<label class="switch">
<input id="thermal" type="checkbox" />
<span class="switch-track"></span>
</label>
</div>
</aside>
<section class="readout">
<div class="eyebrow">Active component</div>
<div class="component-name" id="componentName">Complete envelope</div>
<div class="metric-grid">
<div class="metric">
<span class="metric-value" id="metricLayers">4</span>
<span class="metric-label">Systems</span>
</div>
<div class="metric">
<span class="metric-value" id="metricResistance">R-28</span>
<span class="metric-label">Assembly</span>
</div>
<div class="metric">
<span class="metric-value" id="metricArea">31.6 m²</span>
<span class="metric-label">Footprint</span>
</div>
<div class="metric">
<span class="metric-value" id="metricMode">Cut</span>
<span class="metric-label">View</span>
</div>
</div>
</section>
<div class="legend" id="materialLegend">
<div class="legend-item">
<i style="background:#4e8298"></i>
Weather membrane
</div>
<div class="legend-item">
<i style="background:#f2ca62"></i>
Mineral wool
</div>
<div class="legend-item">
<i style="background:#66c9dd"></i>
Glazing
</div>
<div class="legend-item">
<i style="background:#b77546"></i>
Timber deck
</div>
</div>
<div class="legend" id="thermalLegend" style="display:none">
<div class="legend-item">
<i style="background:#4f91b3"></i>
Exterior loss
</div>
<div class="legend-item">
<i style="background:#ef7258"></i>
High resistance
</div>
<div class="legend-item">
<i style="background:#efbd63"></i>
Interior gain
</div>
<div class="legend-item">
<i style="background:#67d1df"></i>
Cold glazing
</div>
</div>
<div class="hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<div class="world-label" id="label-roof">
<span>01</span> Roof assembly
</div>
<div class="world-label" id="label-wall">
<span>02</span> Wall sandwich
</div>
<div class="world-label" id="label-floor">
<span>03</span> Floor build-up
</div>
<div class="world-label" id="label-window">
<span>04</span> Glazing unit
</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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071117);
scene.fog = new THREE.FogExp2(0x071117, 0.022);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const model = new THREE.Group();
scene.add(model);
const groups = {
roof: new THREE.Group(),
wall: new THREE.Group(),
floor: new THREE.Group(),
window: new THREE.Group()
};
Object.values(groups).forEach((group) => model.add(group));
// A diagonal plane removes the front-right portion of the shell.
const cutPlane = new THREE.Plane(
new THREE.Vector3(1, 0, 1).normalize(),
-1.35
);
let cutCurrent = 1.35;
let cutTarget = 1.35;
const trackedMaterials = [];
function makeMaterial(
category,
color,
{
clip = false,
thermal = color,
opacity = 1,
roughness = 0.78,
metalness = 0,
emissive = 0x000000,
emissiveIntensity = 0
} = {}
) {
const material = new THREE.MeshStandardMaterial({
color,
roughness,
metalness,
transparent: opacity < 1,
opacity,
depthWrite: opacity >= 1,
emissive,
emissiveIntensity
});
if (clip) {
material.clippingPlanes = [cutPlane];
material.clipShadows = true;
}
material.userData = {
category,
baseColor: new THREE.Color(color),
thermalColor: new THREE.Color(thermal),
baseOpacity: opacity,
baseTransparent: opacity < 1,
baseDepthWrite: opacity >= 1,
baseEmissiveIntensity: emissiveIntensity
};
trackedMaterials.push(material);
return material;
}
const materials = {
wallOuter: makeMaterial(
"wall",
0x738780,
{
clip: true,
thermal: 0x4f91b3,
roughness: 0.88
}
),
wallInsulation: makeMaterial(
"wall",
0xf2ca62,
{
clip: true,
thermal: 0xef7258,
roughness: 0.96
}
),
wallInner: makeMaterial(
"wall",
0xe8dfca,
{
clip: true,
thermal: 0xefbd63,
roughness: 0.88
}
),
roofMembrane: makeMaterial(
"roof",
0x416d83,
{
clip: true,
thermal: 0x4f91b3,
roughness: 0.72
}
),
roofInsulation: makeMaterial(
"roof",
0xf2ca62,
{
clip: true,
thermal: 0xef7258,
roughness: 0.96
}
),
roofDeck: makeMaterial(
"roof",
0xa96f45,
{
clip: true,
thermal: 0xb66d3f,
roughness: 0.82
}
),
concrete: makeMaterial(
"floor",
0x667077,
{
thermal: 0x5186a0,
roughness: 0.98
}
),
floorInsulation: makeMaterial(
"floor",
0xf2ca62,
{
thermal: 0xef7258,
roughness: 0.98
}
),
floorFinish: makeMaterial(
"floor",
0xb77546,
{
thermal: 0xb66d3f,
roughness: 0.74
}
),
windowFrame: makeMaterial(
"window",
0x29434d,
{
clip: true,
thermal: 0x2e6077,
roughness: 0.32,
metalness: 0.5
}
),
glass: makeMaterial(
"window",
0x70cbe0,
{
clip: true,
thermal: 0x67d1df,
opacity: 0.46,
roughness: 0.12,
metalness: 0.08,
emissive: 0x174e63,
emissiveIntensity: 0.28
}
),
rug: makeMaterial(
"interior",
0x31454b,
{ roughness: 1 }
),
furniture: makeMaterial(
"interior",
0xa45f4d,
{ roughness: 0.88 }
),
furnitureDark: makeMaterial(
"interior",
0x27383e,
{ roughness: 0.85 }
)
};
// -------------------------------------------------------------------------
// Ground, lighting, and atmosphere
// -------------------------------------------------------------------------
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0x071217,
roughness: 1,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(32, 32, 0x31515a, 0x142b34);
grid.position.y = -0.015;
grid.material.transparent = true;
grid.material.opacity = 0.42;
scene.add(grid);
const hemisphere = new THREE.HemisphereLight(
0xbfe8ff,
0x152027,
1.65
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffffff, 3.1);
sun.position.set(8, 13, 10);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.00025;
scene.add(sun);
const rim = new THREE.DirectionalLight(0x4fc3ff, 1.5);
rim.position.set(-8, 7, -6);
scene.add(rim);
const interiorLight = new THREE.PointLight(0xffb45c, 18, 10, 2);
interiorLight.position.set(-0.2, 2.2, 0.4);
scene.add(interiorLight);
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
const dummy = new THREE.Object3D();
function addBox(parent, size, position, material, options = {}) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = options.castShadow !== false;
mesh.receiveShadow = options.receiveShadow !== false;
mesh.userData.category = material.userData.category;
parent.add(mesh);
return mesh;
}
function addInstances(
parent,
geometry,
material,
positions,
category
) {
if (!positions.length) return null;
const mesh = new THREE.InstancedMesh(
geometry,
material,
positions.length
);
positions.forEach((position, index) => {
dummy.position.set(position[0], position[1], position[2]);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
mesh.setMatrixAt(index, dummy.matrix);
});
mesh.instanceMatrix.needsUpdate = true;
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.category = category;
mesh.computeBoundingSphere();
parent.add(mesh);
return mesh;
}
function roofStep(z) {
return 4 - Math.min(4, Math.floor(Math.abs(z) / 0.5 + 0.5));
}
// -------------------------------------------------------------------------
// Floor assembly
// -------------------------------------------------------------------------
addBox(
groups.floor,
[6.72, 0.32, 5.58],
[0, 0.16, 0],
materials.concrete
);
addBox(
groups.floor,
[6.28, 0.16, 5.12],
[0, 0.40, 0],
materials.concrete
);
addBox(
groups.floor,
[6.04, 0.16, 4.88],
[0, 0.56, 0],
materials.floorInsulation
);
addBox(
groups.floor,
[5.82, 0.10, 4.66],
[0, 0.69, 0],
materials.floorFinish
);
// Small interior elements provide scale without competing with the envelope.
addBox(
groups.floor,
[2.3, 0.025, 1.36],
[0.45, 0.752, 0.52],
materials.rug,
{ castShadow: false }
);
addBox(
groups.floor,
[1.72, 0.34, 0.72],
[-0.85, 0.94, -0.72],
materials.furniture
);
addBox(
groups.floor,
[1.72, 0.68, 0.17],
[-0.85, 1.18, -1.06],
materials.furniture
);
addBox(
groups.floor,
[0.16, 0.32, 0.72],
[-1.66, 0.9, -0.72],
materials.furnitureDark
);
addBox(
groups.floor,
[0.16, 0.32, 0.72],
[-0.04, 0.9, -0.72],
materials.furnitureDark
);
addBox(
groups.floor,
[0.92, 0.12, 0.86],
[0.82, 1.05, 0.52],
materials.furnitureDark
);
for (const x of [0.48, 1.16]) {
for (const z of [0.30, 0.74]) {
addBox(
groups.floor,
[0.09, 0.31, 0.09],
[x, 0.87, z],
materials.furnitureDark
);
}
}
// -------------------------------------------------------------------------
// Window assemblies
// -------------------------------------------------------------------------
function addWindow(center, orientation, width = 1, height = 1) {
const [cx, cy, cz] = center;
const isZ = orientation === "z";
const depth = 0.30;
const makePart = (size, offset, material = materials.windowFrame) => {
const position = isZ
? [cx + offset[0], cy + offset[1], cz + offset[2]]
: [cx + offset[2], cy + offset[1], cz + offset[0]];
const dimensions = isZ
? [size[0], size[1], size[2]]
: [size[2], size[1], size[0]];
return addBox(
groups.window,
dimensions,
position,
material
);
};
// Outer frame.
makePart(
[0.09, height, depth],
[-width / 2 + 0.045, 0, 0]
);
makePart(
[0.09, height, depth],
[width / 2 - 0.045, 0, 0]
);
makePart(
[width, 0.09, depth],
[0, -height / 2 + 0.045, 0]
);
makePart(
[width, 0.09, depth],
[0, height / 2 - 0.045, 0]
);
// Central mullions.
makePart(
[0.055, height - 0.08, 0.18],
[0, 0, 0]
);
makePart(
[width - 0.08, 0.055, 0.18],
[0, 0, 0]
);
// Glass pane.
makePart(
[width - 0.12, height - 0.12, 0.065],
[0, 0, 0],
materials.glass
);
// Projecting sill.
makePart(
[width + 0.18, 0.08, 0.42],
[0, -height / 2 - 0.035, 0]
);
}
// -------------------------------------------------------------------------
// Voxel wall assemblies
// -------------------------------------------------------------------------
const wallBottom = 0.74;
const rowY = (row) => wallBottom + 0.25 + row * 0.5;
const openings = {
back: new Set([
"3,2", "4,2", "3,3", "4,3",
"7,2", "8,2", "7,3", "8,3"
]),
front: new Set([
"2,2", "3,2", "2,3", "3,3",
"8,2", "9,2", "8,3", "9,3"
]),
left: new Set([
"3,2", "4,2", "3,3", "4,3",
"7,2", "8,2", "7,3", "8,3"
]),
right: new Set([
"2,2", "3,2", "2,3", "3,3",
"6,2", "7,2", "6,3", "7,3"
])
};
const zWallLayers = [[], [], []];
const xWallLayers = [[], [], []];
// Back and front walls.
for (const side of ["back", "front"]) {
const sign = side === "back" ? -1 : 1;
for (let column = 0; column < 12; column++) {
const x = -2.75 + column * 0.5;
for (let row = 0; row < 7; row++) {
if (openings[side].has(`${column},${row}`)) continue;
const y = rowY(row);
for (let layer = 0; layer < 3; layer++) {
zWallLayers[layer].push([
x,
y,
sign * (2.46 - layer * 0.15)
]);
}
}
}
}
// Left and right walls.
for (const side of ["left", "right"]) {
const sign = side === "left" ? -1 : 1;
for (let column = 0; column < 10; column++) {
const z = -2.25 + column * 0.5;
for (let row = 0; row < 7; row++) {
if (openings[side].has(`${column},${row}`)) continue;
const y = rowY(row);
for (let layer = 0; layer < 3; layer++) {
xWallLayers[layer].push([
sign * (3.01 - layer * 0.15),
y,
z
]);
}
}
}
}
const wallMaterials = [
materials.wallOuter,
materials.wallInsulation,
materials.wallInner
];
zWallLayers.forEach((positions, layer) => {
addInstances(
groups.wall,
new THREE.BoxGeometry(0.48, 0.48, 0.145),
wallMaterials[layer],
positions,
"wall"
);
});
xWallLayers.forEach((positions, layer) => {
addInstances(
groups.wall,
new THREE.BoxGeometry(0.145, 0.48, 0.48),
wallMaterials[layer],
positions,
"wall"
);
});
// Back windows.
addWindow([-1.0, 2.24, -2.31], "z");
addWindow([1.0, 2.24, -2.31], "z");
// Front windows.
addWindow([-1.5, 2.24, 2.31], "z");
addWindow([1.5, 2.24, 2.31], "z");
// Left windows.
addWindow([-2.88, 2.24, -0.5], "x");
addWindow([-2.88, 2.24, 1.5], "x");
// Right windows.
addWindow([2.88, 2.24, -1.0], "x");
addWindow([2.88, 2.24, 1.0], "x");
// Stepped gable infill at both ends.
for (const sign of [-1, 1]) {
for (let column = 0; column < 10; column++) {
const z = -2.25 + column * 0.5;
const height = roofStep(z) * 0.23;
if (height <= 0.02) continue;
addBox(
groups.wall,
[0.24, height, 0.48],
[sign * 2.89, 4.24 + height / 2, z],
materials.wallInner
);
}
}
// -------------------------------------------------------------------------
// Stepped voxel roof assembly
// -------------------------------------------------------------------------
const membranePositions = [];
const insulationPositions = [];
const deckPositions = [];
for (let column = 0; column < 13; column++) {
const x = -3 + column * 0.5;
for (let row = 0; row < 10; row++) {
const z = -2.25 + row * 0.5;
const step = roofStep(z);
const topSurface = 4.56 + step * 0.23;
membranePositions.push([x, topSurface - 0.04, z]);
insulationPositions.push([x, topSurface - 0.16, z]);
deckPositions.push([x, topSurface - 0.27, z]);
}
}
addInstances(
groups.roof,
new THREE.BoxGeometry(0.49, 0.08, 0.49),
materials.roofMembrane,
membranePositions,
"roof"
);
addInstances(
groups.roof,
new THREE.BoxGeometry(0.49, 0.16, 0.49),
materials.roofInsulation,
insulationPositions,
"roof"
);
addInstances(
groups.roof,
new THREE.BoxGeometry(0.49, 0.10, 0.49),
materials.roofDeck,
deckPositions,
"roof"
);
// -------------------------------------------------------------------------
// Cut edge indicator
// -------------------------------------------------------------------------
const cutEdgeGeometry = new THREE.BufferGeometry();
cutEdgeGeometry.setAttribute(
"position",
new THREE.BufferAttribute(new Float32Array(12), 3)
);
const cutEdge = new THREE.LineSegments(
cutEdgeGeometry,
new THREE.LineBasicMaterial({
color: 0xff9c68,
transparent: true,
opacity: 0.9,
depthTest: false
})
);
cutEdge.renderOrder = 10;
scene.add(cutEdge);
function updateCutEdge(threshold) {
const xMin = Math.max(-3.3, threshold - 2.7);
const xMax = Math.min(3.3, threshold + 2.7);
cutEdge.visible = xMin < xMax && threshold < 20;
if (!cutEdge.visible) return;
const positions = cutEdgeGeometry.attributes.position;
const zMin = threshold - xMin;
const zMax = threshold - xMax;
positions.setXYZ(0, xMin, 0.72, zMin);
positions.setXYZ(1, xMin, 5.62, zMin);
positions.setXYZ(2, xMax, 0.72, zMax);
positions.setXYZ(3, xMax, 5.62, zMax);
positions.needsUpdate = true;
cutEdgeGeometry.computeBoundingSphere();
}
// -------------------------------------------------------------------------
// UI state and component highlighting
// -------------------------------------------------------------------------
let selectedLayer = "all";
let separation = 0.28;
let thermalTarget = 0;
let thermalMix = 0;
const layerButtons = [...document.querySelectorAll(".layer-button")];
const separationInput = document.querySelector("#separation");
const separationValue = document.querySelector("#separationValue");
const cutawayInput = document.querySelector("#cutaway");
const thermalInput = document.querySelector("#thermal");
const materialLegend = document.querySelector("#materialLegend");
const thermalLegend = document.querySelector("#thermalLegend");
const componentName = document.querySelector("#componentName");
const metricLayers = document.querySelector("#metricLayers");
const metricResistance = document.querySelector("#metricResistance");
const metricArea = document.querySelector("#metricArea");
const metricMode = document.querySelector("#metricMode");
const componentMeta = {
all: ["Complete envelope", "4", "R-28", "31.6 m²"],
roof: ["Roof assembly", "3", "R-32", "31.6 m²"],
wall: ["Wall sandwich", "3", "R-24", "62.4 m²"],
floor: ["Floor build-up", "3", "R-22", "31.6 m²"],
window: ["Glazing unit", "2", "U-1.6", "8.0 m²"]
};
function updateComponentReadout() {
const meta = componentMeta[selectedLayer];
componentName.textContent = meta[0];
metricLayers.textContent = meta[1];
metricResistance.textContent = meta[2];
metricArea.textContent = meta[3];
metricMode.textContent = cutTarget < 20 ? "Cut" : "Full";
}
function focusMaterials() {
trackedMaterials.forEach((material) => {
const data = material.userData;
const active =
selectedLayer === "all" ||
data.category === selectedLayer;
const opacity = active
? data.baseOpacity
: Math.max(0.045, data.baseOpacity * 0.16);
material.opacity = opacity;
material.transparent = data.baseTransparent || opacity < 0.995;
material.depthWrite = active ? data.baseDepthWrite : false;
material.emissiveIntensity = active
? data.baseEmissiveIntensity
: 0;
material.needsUpdate = true;
});
layerButtons.forEach((button) => {
button.classList.toggle(
"active",
button.dataset.layer === selectedLayer
);
});
document.querySelectorAll(".world-label").forEach((label) => {
const layer = label.id.replace("label-", "");
const active =
selectedLayer === "all" ||
selectedLayer === layer;
label.classList.toggle("active", active);
label.classList.toggle("muted", !active);
});
updateComponentReadout();
}
function selectLayer(layer) {
selectedLayer = layer;
focusMaterials();
}
layerButtons.forEach((button) => {
button.addEventListener("click", () => {
selectLayer(button.dataset.layer);
});
});
separationInput.addEventListener("input", () => {
separation = Number(separationInput.value) / 100;
separationValue.textContent = `${separationInput.value}%`;
separationInput.style.setProperty(
"--range-progress",
`${separationInput.value}%`
);
});
cutawayInput.addEventListener("change", () => {
cutTarget = cutawayInput.checked ? 1.35 : 100;
updateComponentReadout();
});
thermalInput.addEventListener("change", () => {
thermalTarget = thermalInput.checked ? 1 : 0;
materialLegend.style.display = thermalInput.checked ? "none" : "flex";
thermalLegend.style.display = thermalInput.checked ? "flex" : "none";
});
// -------------------------------------------------------------------------
// Custom camera controls
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 2.1, 0),
desiredTarget: new THREE.Vector3(0, 2.1, 0),
yaw: 0.72,
desiredYaw: 0.72,
pitch: 0.52,
desiredPitch: 0.52,
radius: 13.2,
desiredRadius: 13.2
};
function updateCamera() {
controls.yaw += (controls.desiredYaw - controls.yaw) * 0.13;
controls.pitch +=
(controls.desiredPitch - controls.pitch) * 0.13;
controls.radius +=
(controls.desiredRadius - controls.radius) * 0.13;
controls.target.lerp(controls.desiredTarget, 0.13);
const horizontal = Math.cos(controls.pitch) * controls.radius;
camera.position.set(
controls.target.x + horizontal * Math.sin(controls.yaw),
controls.target.y + Math.sin(controls.pitch) * controls.radius,
controls.target.z + horizontal * Math.cos(controls.yaw)
);
camera.lookAt(controls.target);
}
function resetView() {
controls.desiredYaw = 0.72;
controls.desiredPitch = 0.52;
controls.desiredRadius = 13.2;
controls.desiredTarget.set(0, 2.1, 0);
}
document.querySelector("#resetView").addEventListener("click", resetView);
let pointerDown = false;
let pointerMoved = 0;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("pointerdown", (event) => {
pointerDown = true;
pointerMoved = 0;
lastX = event.clientX;
lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = "grabbing";
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerDown) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
pointerMoved += Math.abs(dx) + Math.abs(dy);
lastX = event.clientX;
lastY = event.clientY;
if (event.shiftKey) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(
camera.quaternion
);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(
camera.quaternion
);
const panScale = controls.radius * 0.0014;
controls.desiredTarget.addScaledVector(
right,
-dx * panScale
);
controls.desiredTarget.addScaledVector(
up,
dy * panScale
);
} else {
controls.desiredYaw -= dx * 0.006;
controls.desiredPitch = THREE.MathUtils.clamp(
controls.desiredPitch + dy * 0.005,
0.18,
1.25
);
}
});
canvas.addEventListener("pointerup", (event) => {
pointerDown = false;
canvas.style.cursor = "grab";
if (pointerMoved < 6) {
selectFromCanvas(event.clientX, event.clientY);
}
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("wheel", (event) => {
event.preventDefault();
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * Math.exp(event.deltaY * 0.001),
7,
24
);
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
canvas.style.cursor = "grab";
// -------------------------------------------------------------------------
// Mesh picking
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectFromCanvas(clientX, clientY) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObject(model, true);
for (const intersection of intersections) {
const category =
intersection.object.userData.category ||
intersection.object.material?.userData?.category;
if (category && category !== "interior") {
selectLayer(category);
break;
}
}
}
// -------------------------------------------------------------------------
// Projected HTML labels
// -------------------------------------------------------------------------
const labelData = [
{
element: document.querySelector("#label-roof"),
group: groups.roof,
anchor: new THREE.Vector3(1.1, 5.35, -0.65),
layer: "roof"
},
{
element: document.querySelector("#label-wall"),
group: groups.wall,
anchor: new THREE.Vector3(-3.02, 2.62, -1.18),
layer: "wall"
},
{
element: document.querySelector("#label-floor"),
group: groups.floor,
anchor: new THREE.Vector3(2.05, 0.76, 1.30),
layer: "floor"
},
{
element: document.querySelector("#label-window"),
group: groups.window,
anchor: new THREE.Vector3(1.0, 2.24, -2.31),
layer: "window"
}
];
const projected = new THREE.Vector3();
function updateLabels() {
model.updateMatrixWorld(true);
labelData.forEach((label) => {
projected.copy(label.anchor);
label.group.localToWorld(projected);
projected.project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.15 &&
projected.x < 1.15 &&
projected.y > -1.15 &&
projected.y < 1.15;
label.element.style.visibility = visible ? "visible" : "hidden";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
});
}
// -------------------------------------------------------------------------
// Resize and animation
// -------------------------------------------------------------------------
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
}
window.addEventListener("resize", resize);
const groupTargets = {
roof: new THREE.Vector3(),
wall: new THREE.Vector3(),
floor: new THREE.Vector3(),
window: new THREE.Vector3()
};
function animate() {
requestAnimationFrame(animate);
const smoothing = 0.075;
cutCurrent += (cutTarget - cutCurrent) * smoothing;
cutPlane.constant = -cutCurrent;
updateCutEdge(cutCurrent);
thermalMix += (thermalTarget - thermalMix) * smoothing;
trackedMaterials.forEach((material) => {
material.color
.copy(material.userData.baseColor)
.lerp(material.userData.thermalColor, thermalMix);
});
groupTargets.roof.set(
0,
separation * 1.20,
0
);
groupTargets.wall.set(
-separation * 0.55,
0,
-separation * 0.20
);
groupTargets.floor.set(
0,
-separation * 0.55,
0
);
groupTargets.window.set(
separation * 0.55,
separation * 0.12,
separation * 0.55
);
Object.entries(groups).forEach(([key, group]) => {
group.position.lerp(groupTargets[key], 0.075);
});
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
focusMaterials();
updateCutEdge(cutCurrent);
updateCamera();
animate();
</script>
</body>
</html>
```