Prompt specification
Build or customize the Three.js 3D scene "Community Roof Solar Layout" 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: Community Roof Solar Layout
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/community-roof-solar-layout-x3979
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows solar-panel orientation, exposure, and shading. Build an original roof with chimneys, panels, and a stated sun path. Compare geometric shading and keep installation, electrical design, and structural requirements outside the simplified model. Voxel style.
Working Three.js Starter (community-roof-solar-layout-x3979):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sunward — Voxel Roof Geometry Study</title>
<style>
:root {
--ink: #142b32;
--muted: #5d716f;
--paper: rgba(248, 246, 231, 0.94);
--line: rgba(20, 43, 50, 0.16);
--sun: #f3b63f;
--sunlit: #168b91;
--shade: #ed655d;
--partial: #d99a35;
--back: #706783;
--shadow: rgba(20, 43, 50, 0.16);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8df;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input { font: inherit; }
button { color: inherit; }
#viewport {
position: fixed;
inset: 0;
}
#viewport canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
pointer-events: auto;
background: var(--paper);
border: 1px solid rgba(255,255,255,0.72);
box-shadow: 6px 6px 0 var(--shadow);
backdrop-filter: blur(10px);
}
header {
position: absolute;
top: 24px;
left: 24px;
max-width: 560px;
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
background: var(--ink);
color: #fff9df;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .13em;
text-transform: uppercase;
box-shadow: 4px 4px 0 rgba(20,43,50,.18);
}
.eyebrow::before {
content: "";
width: 7px;
height: 7px;
background: var(--sun);
box-shadow: 0 0 0 2px rgba(243,182,63,.25);
}
h1 {
margin: 12px 0 5px;
font-size: clamp(27px, 4vw, 48px);
line-height: .96;
letter-spacing: -.055em;
text-transform: uppercase;
}
.subtitle {
max-width: 480px;
margin: 0;
color: #415d5c;
font-size: 13px;
line-height: 1.5;
text-wrap: balance;
}
#controls {
position: absolute;
top: 24px;
right: 24px;
width: 326px;
max-height: calc(100vh - 48px);
overflow: auto;
padding: 18px;
scrollbar-width: thin;
}
.section-title {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 14px;
font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .13em;
text-transform: uppercase;
}
.section-title span:last-child {
color: var(--muted);
font-weight: 600;
letter-spacing: .04em;
}
.control {
margin: 0 0 17px;
}
.control label,
.control-head {
display: flex;
justify-content: space-between;
gap: 12px;
margin-bottom: 8px;
font-size: 12px;
font-weight: 750;
}
output {
color: #08727a;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-weight: 800;
white-space: nowrap;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0 2px;
border-radius: 0;
appearance: none;
background: linear-gradient(90deg, #87aaa2, #d8d8c5);
outline: none;
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 16px;
height: 16px;
appearance: none;
border: 3px solid var(--ink);
border-radius: 0;
background: var(--sun);
box-shadow: 2px 2px 0 rgba(20,43,50,.18);
}
input[type="range"]::-moz-range-thumb {
width: 11px;
height: 11px;
border: 3px solid var(--ink);
border-radius: 0;
background: var(--sun);
}
.range-ends {
display: flex;
justify-content: space-between;
margin-top: 6px;
color: var(--muted);
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .08em;
text-transform: uppercase;
}
.segmented {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
}
.segmented button,
.small-button {
border: 1px solid var(--line);
border-radius: 0;
background: rgba(255,255,255,.45);
padding: 9px 7px;
cursor: pointer;
font: 750 10px/1.15 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
text-transform: uppercase;
}
.segmented button:hover,
.small-button:hover {
background: #fffef4;
}
.segmented button.active {
border-color: var(--ink);
background: var(--ink);
color: #fffbe8;
box-shadow: 3px 3px 0 rgba(20,43,50,.15);
}
#sunPath {
display: block;
width: 100%;
height: 166px;
margin: 1px 0 9px;
border: 1px solid var(--line);
background:
linear-gradient(rgba(20,43,50,.045) 1px, transparent 1px),
linear-gradient(90deg, rgba(20,43,50,.045) 1px, transparent 1px),
rgba(255,255,255,.30);
background-size: 20px 20px;
}
.sun-readout {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
margin-bottom: 15px;
}
.sun-readout div {
padding: 8px 5px;
border: 1px solid var(--line);
text-align: center;
background: rgba(255,255,255,.35);
}
.sun-readout small {
display: block;
margin-bottom: 4px;
color: var(--muted);
font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .1em;
text-transform: uppercase;
}
.sun-readout b {
font: 800 12px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.scope {
margin: 16px 0 0;
padding: 12px;
border-left: 4px solid var(--sun);
background: rgba(243,182,63,.12);
color: #526460;
font-size: 10.5px;
line-height: 1.48;
}
.scope strong { color: var(--ink); }
#metrics {
position: absolute;
left: 24px;
bottom: 24px;
width: min(590px, calc(100vw - 48px));
padding: 15px;
}
.metrics-grid {
display: grid;
grid-template-columns: 1.15fr 1fr 1fr 1fr;
gap: 8px;
}
.metric {
min-width: 0;
padding: 11px;
background: rgba(255,255,255,.42);
border: 1px solid var(--line);
}
.metric small {
display: block;
min-height: 24px;
color: var(--muted);
font: 750 9px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .07em;
text-transform: uppercase;
}
.metric strong {
display: block;
margin: 5px 0 3px;
font: 850 25px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: -.06em;
}
.metric em {
color: var(--muted);
font-size: 9px;
font-style: normal;
}
.comparison {
display: grid;
grid-template-columns: 1fr auto 1fr auto;
align-items: center;
gap: 9px;
margin-top: 10px;
padding-top: 10px;
border-top: 1px solid var(--line);
}
.comparison-label {
color: var(--muted);
font: 750 9px/1.25 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .07em;
text-transform: uppercase;
}
.comparison b {
font: 850 14px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.comparison .arrow {
color: var(--muted);
font-size: 16px;
}
#legend {
position: absolute;
right: 24px;
bottom: 24px;
padding: 11px 13px;
font: 750 10px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
white-space: nowrap;
}
.swatch {
width: 11px;
height: 11px;
border: 1px solid rgba(20,43,50,.32);
}
#cameraHint {
position: absolute;
right: 376px;
bottom: 27px;
color: rgba(20,43,50,.65);
font: 650 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .04em;
}
#status {
display: inline-flex;
margin-top: 9px;
padding: 7px 9px;
border: 1px solid var(--line);
background: rgba(255,255,255,.45);
color: var(--ink);
font: 800 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: .05em;
text-transform: uppercase;
}
#status.warn {
border-color: rgba(237,101,93,.55);
background: rgba(237,101,93,.12);
}
@media (max-width: 860px) {
header {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
h1 { font-size: 30px; }
.subtitle { display: none; }
#controls {
top: 106px;
right: 16px;
width: min(310px, calc(100vw - 32px));
max-height: 49vh;
padding: 13px;
}
#metrics {
left: 16px;
bottom: 16px;
width: calc(100vw - 32px);
}
.metrics-grid {
grid-template-columns: repeat(4, 1fr);
}
.metric { padding: 8px; }
.metric strong { font-size: 19px; }
.metric small { min-height: 34px; font-size: 8px; }
#legend, #cameraHint { display: none; }
}
@media (max-width: 520px) {
#controls { width: 286px; }
#metrics { padding: 10px; }
.metrics-grid { grid-template-columns: repeat(2, 1fr); }
.comparison { grid-template-columns: 1fr auto; }
.comparison .arrow { display: none; }
}
</style>
</head>
<body>
<div id="viewport"></div>
<div class="ui">
<header>
<div class="eyebrow">Voxel geometry study</div>
<h1>Sunward<br>Roof Lab</h1>
<p class="subtitle">
An original block-built roof with a south-sloped panel field, two masonry chimneys,
and a stated solar path. Colors distinguish orientation and direct geometric obstruction.
</p>
</header>
<section id="controls" class="panel" aria-label="Solar geometry controls">
<div class="section-title">
<span>Geometry inputs</span>
<span id="status">Updating</span>
</div>
<div class="control">
<label for="bearing">
Roof / panel bearing
<output id="bearingValue">180° S</output>
</label>
<input id="bearing" type="range" min="90" max="270" step="1" value="180">
<div class="range-ends"><span>90° E</span><span>180° S</span><span>270° W</span></div>
</div>
<div class="control">
<label for="tilt">
Panel tilt
<output id="tiltValue">18.4°</output>
</label>
<input id="tilt" type="range" min="10" max="40" step="0.5" value="18.4">
<div class="range-ends"><span>10°</span><span>From horizontal</span><span>40°</span></div>
</div>
<div class="control">
<label for="time">
Local solar time
<output id="timeValue">10:30</output>
</label>
<input id="time" type="range" min="6" max="18" step="0.1" value="10.5">
<div class="range-ends"><span>06:00</span><span>Solar time</span><span>18:00</span></div>
</div>
<div class="control">
<div class="control-head"><span>Declared solar date</span></div>
<div class="segmented" id="seasonButtons">
<button data-decl="0" class="active">Equinox</button>
<button data-decl="23.44">Jun 21</button>
<button data-decl="-23.44">Dec 21</button>
</div>
</div>
<div class="section-title">
<span>Stated sun path</span>
<span>40.7° N</span>
</div>
<canvas id="sunPath" aria-label="Polar sun path chart"></canvas>
<div class="sun-readout">
<div><small>Altitude</small><b id="altitudeValue">—</b></div>
<div><small>Azimuth</small><b id="azimuthValue">—</b></div>
<div><small>Declination</small><b id="declinationValue">0°</b></div>
</div>
<button id="resetCamera" class="small-button" style="width:100%">Reset camera</button>
<p class="scope">
<strong>Simplified model only.</strong>
Sun positions use latitude 40.7° N, the selected solar declination, and local solar time.
“Geometric access” is a cosine-weighted visibility proxy for panel cells.
Installation, electrical design, structural capacity, panel-to-panel shading,
terrain, atmosphere, vegetation, energy yield, and code compliance are outside this model.
</p>
</section>
<section id="metrics" class="panel" aria-label="Geometric comparison">
<div class="section-title">
<span>Geometric shading comparison</span>
<span id="cellSummary">60 cells</span>
</div>
<div class="metrics-grid">
<div class="metric">
<small>Unobstructed orientation proxy</small>
<strong id="orientationValue">—</strong>
<em>No roof or chimney obstruction</em>
</div>
<div class="metric">
<small>Geometric access</small>
<strong id="geometricValue">—</strong>
<em>Roof + chimneys included</em>
</div>
<div class="metric">
<small>Shading loss</small>
<strong id="lossValue">—</strong>
<em>Percentage-point difference</em>
</div>
<div class="metric">
<small>Open incident cells</small>
<strong id="openValue">—</strong>
<em id="blockedValue">—</em>
</div>
</div>
<div class="comparison">
<span class="comparison-label">No obstruction</span>
<b id="compareIdeal">—</b>
<span class="arrow">→</span>
<span class="comparison-label">Geometric model</span>
<b id="compareGeometric">—</b>
</div>
</section>
<div id="legend" class="panel">
<div class="legend-row"><i class="swatch" style="background:#168b91"></i>Directly visible</div>
<div class="legend-row"><i class="swatch" style="background:#d99a35"></i>Partially obstructed</div>
<div class="legend-row"><i class="swatch" style="background:#ed655d"></i>Geometrically shaded</div>
<div class="legend-row"><i class="swatch" style="background:#706783"></i>Back-facing / no incidence</div>
</div>
<div id="cameraHint">Drag to orbit · Shift-drag to pan · Wheel to zoom</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
viewport.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8df);
scene.fog = new THREE.Fog(0xdce8df, 24, 48);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 3.1, 0);
const spherical = new THREE.Spherical(19.5, 1.06, 0.72);
const sphericalGoal = spherical.clone();
const panGoal = cameraTarget.clone();
function updateCamera() {
camera.position.setFromSpherical(sphericalGoal).add(panGoal);
camera.lookAt(panGoal);
}
updateCamera();
const ambient = new THREE.HemisphereLight(0xf1fbff, 0x66745d, 1.75);
scene.add(ambient);
const sunLight = new THREE.DirectionalLight(0xfff0c2, 3.2);
sunLight.castShadow = true;
sunLight.shadow.mapSize.set(2048, 2048);
sunLight.shadow.camera.left = -13;
sunLight.shadow.camera.right = 13;
sunLight.shadow.camera.top = 13;
sunLight.shadow.camera.bottom = -13;
sunLight.shadow.camera.near = 1;
sunLight.shadow.camera.far = 50;
sunLight.shadow.bias = -0.0006;
sunLight.target.position.set(0, 2.6, 0);
scene.add(sunLight, sunLight.target);
const fill = new THREE.DirectionalLight(0xb9d9de, 0.45);
fill.position.set(-10, 8, 8);
scene.add(fill);
// -------------------------------------------------------------------------
// Custom camera interaction: no addons or examples modules
// -------------------------------------------------------------------------
let drag = null;
renderer.domElement.addEventListener("contextmenu", event => event.preventDefault());
renderer.domElement.addEventListener("pointerdown", event => {
drag = {
id: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!drag || drag.id !== event.pointerId) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 1);
const scale = sphericalGoal.radius * 0.0016;
panGoal.addScaledVector(right, -dx * scale);
panGoal.addScaledVector(up, dy * scale);
} else {
sphericalGoal.theta -= dx * 0.006;
sphericalGoal.phi = THREE.MathUtils.clamp(sphericalGoal.phi - dy * 0.005, 0.28, 1.38);
}
});
function endDrag(event) {
if (drag && event.pointerId === drag.id) drag = null;
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener("wheel", event => {
event.preventDefault();
sphericalGoal.radius = THREE.MathUtils.clamp(
sphericalGoal.radius * Math.exp(event.deltaY * 0.001),
9,
32
);
}, { passive: false });
document.getElementById("resetCamera").addEventListener("click", () => {
sphericalGoal.set(19.5, 1.06, 0.72);
panGoal.set(0, 3.1, 0);
});
// -------------------------------------------------------------------------
// Materials and voxel geometry
// -------------------------------------------------------------------------
const material = (color, options = {}) => new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0,
flatShading: true,
...options
});
const M = {
ground: material(0xaec8ad),
groundEdge: material(0x789886),
grid: material(0x789886),
foundation: material(0x667a78),
wall: material(0xe9d9b9),
wallShadow: material(0xd3c09e),
roof: material(0x984b3f),
roofDark: material(0x753a35),
roofLight: material(0xb15a47),
ridge: material(0x5f3531),
frame: material(0x26363b, { roughness: 0.58, metalness: 0.45 }),
window: material(0x5f8790, { roughness: 0.42, metalness: 0.18 }),
door: material(0x426c65),
brickA: material(0xb65e48),
brickB: material(0x9b4c3d),
chimneyCap: material(0x5b4540),
opening: material(0x253236),
paver: material(0xd7cfb8)
};
function box(parent, size, position, mat, blockerLabel = null) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
if (blockerLabel) {
mesh.userData.blockerLabel = blockerLabel;
occluders.push(mesh);
}
return mesh;
}
const occluders = [];
const ground = box(scene, [28, 0.55, 23], [0, -0.38, 0], M.ground);
ground.castShadow = false;
box(scene, [28.4, 0.22, 23.4], [0, -0.73, 0], M.groundEdge);
const grid = new THREE.GridHelper(27, 27, 0x789886, 0x8fae9d);
grid.position.y = -0.095;
grid.material.transparent = true;
grid.material.opacity = 0.32;
scene.add(grid);
// The complete house rotates with the bearing control.
const houseRoot = new THREE.Group();
scene.add(houseRoot);
const roofAngle = Math.atan2(1.5, 4.5);
const roofSlopeLength = Math.hypot(4.5, 1.5);
function roofSurfaceY(z) {
return 6 + (z < 0 ? z / 3 : -z / 3);
}
box(houseRoot, [10.8, 0.35, 8.7], [0, 0.17, 0], M.foundation, "foundation");
box(houseRoot, [10.0, 4.35, 8.0], [0, 2.50, 0], M.wall, "wall");
// Stepped voxel gable ends.
for (const side of [-1, 1]) {
for (let i = 0; i < 5; i++) {
const y = 4.62 + i * 0.29;
const depth = 6 * (6 - y);
box(
houseRoot,
[0.24, 0.31, depth],
[side * 5.02, y, 0],
i % 2 ? M.wall : M.wallShadow,
"gable wall"
);
}
}
// Two simple roof slabs act as geometric occluders.
const southRoof = box(
houseRoot,
[10.65, 0.25, roofSlopeLength],
[0, 5.25, 2.25],
M.roofDark,
"roof"
);
southRoof.rotation.x = roofAngle;
const northRoof = box(
houseRoot,
[10.65, 0.25, roofSlopeLength],
[0, 5.25, -2.25],
M.roofDark,
"roof"
);
northRoof.rotation.x = -roofAngle;
// Individually stepped roof tiles preserve the voxel aesthetic.
const tileCount = 9;
for (let i = 0; i < tileCount; i++) {
const s = 0.29 + i * 0.49;
const tileDepth = 0.46;
const southTile = box(
houseRoot,
[10.38, 0.12, tileDepth],
[
0,
6 - s * Math.sin(roofAngle) + 0.18 * Math.cos(roofAngle),
s * Math.cos(roofAngle) + 0.18 * Math.sin(roofAngle)
],
i % 3 === 0 ? M.roofLight : M.roof
);
southTile.rotation.x = roofAngle;
const northTile = box(
houseRoot,
[10.38, 0.12, tileDepth],
[
0,
6 - s * Math.sin(roofAngle) + 0.18 * Math.cos(roofAngle),
-s * Math.cos(roofAngle) - 0.18 * Math.sin(roofAngle)
],
i % 3 === 1 ? M.roofLight : M.roof
);
northTile.rotation.x = -roofAngle;
}
box(houseRoot, [10.9, 0.30, 0.34], [0, 6.10, 0], M.ridge);
// South wall details.
box(houseRoot, [1.38, 2.38, 0.16], [0, 1.52, 4.06], M.door, "wall");
box(houseRoot, [1.55, 0.15, 0.25], [0, 2.84, 4.08], M.roofDark);
box(houseRoot, [0.11, 0.11, 0.12], [0.48, 1.55, 4.17], M.chimneyCap);
for (const x of [-2.9, 2.9]) {
box(houseRoot, [1.75, 1.45, 0.14], [x, 2.65, 4.06], M.frame, "wall");
box(houseRoot, [1.52, 1.22, 0.16], [x, 2.65, 4.10], M.window, "wall");
box(houseRoot, [0.09, 1.22, 0.18], [x, 2.65, 4.12], M.frame);
box(houseRoot, [1.52, 0.09, 0.18], [x, 2.65, 4.12], M.frame);
}
// East-facing side window.
box(houseRoot, [0.14, 1.35, 1.65], [5.06, 2.65, -0.8], M.frame, "wall");
box(houseRoot, [0.16, 1.12, 1.42], [5.08, 2.65, -0.8], M.window, "wall");
// A tall south-side chimney near the panel field.
const mainChimneyX = 2.50;
const mainChimneyZ = 2.20;
const chimneyBase = roofSurfaceY(mainChimneyZ) - 0.15;
for (let i = 0; i < 6; i++) {
box(
houseRoot,
[0.78, 0.45, 0.76],
[mainChimneyX, chimneyBase + 0.24 + i * 0.45, mainChimneyZ],
i % 2 ? M.brickB : M.brickA,
"main chimney"
);
}
box(
houseRoot,
[1.03, 0.18, 1.00],
[mainChimneyX, chimneyBase + 2.88, mainChimneyZ],
M.chimneyCap,
"main chimney"
);
box(
houseRoot,
[0.46, 0.08, 0.43],
[mainChimneyX, chimneyBase + 3.00, mainChimneyZ],
M.opening
);
// A smaller north-side chimney completes the original roof silhouette.
const smallChimneyX = -3.15;
const smallChimneyZ = -1.55;
const smallBase = roofSurfaceY(smallChimneyZ) - 0.12;
for (let i = 0; i < 4; i++) {
box(
houseRoot,
[0.67, 0.42, 0.66],
[smallChimneyX, smallBase + 0.22 + i * 0.42, smallChimneyZ],
i % 2 ? M.brickA : M.brickB,
"small chimney"
);
}
box(
houseRoot,
[0.88, 0.16, 0.87],
[smallChimneyX, smallBase + 1.82, smallChimneyZ],
M.chimneyCap,
"small chimney"
);
// Voxel stepping stones on the local south side.
for (let i = 0; i < 4; i++) {
box(houseRoot, [1.18, 0.10, 0.66], [0, 0.02, 5.0 + i * 0.92], M.paver);
}
// -------------------------------------------------------------------------
// Panel field: 15 panels, each divided into four independently sampled cells
// -------------------------------------------------------------------------
const panels = [];
const panelCells = [];
const panelColumns = [-4.0, -2.65, -1.30, 1.15, 3.80];
const panelRows = [1.05, 2.35, 3.65];
for (const z of panelRows) {
for (const x of panelColumns) {
const panel = new THREE.Group();
panel.position.set(x, roofSurfaceY(z) + 0.20, z);
houseRoot.add(panel);
panels.push(panel);
box(panel, [1.13, 0.085, 1.31], [0, 0, 0], M.frame);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const cellMaterial = material(0x168b91, {
roughness: 0.42,
metalness: 0.32,
emissive: 0x000000
});
const cell = box(
panel,
[0.495, 0.045, 0.575],
[sx * 0.258, 0.071, sz * 0.302],
cellMaterial
);
cell.userData.visibleFraction = 1;
panelCells.push(cell);
}
}
}
}
// -------------------------------------------------------------------------
// Sun-path graphics in 3D and in the control panel
// -------------------------------------------------------------------------
const sunMarker = new THREE.Group();
const sunCube = new THREE.Mesh(
new THREE.BoxGeometry(0.58, 0.58, 0.58),
material(0xf3b63f, {
roughness: 0.6,
emissive: 0x8a4b05,
emissiveIntensity: 0.28
})
);
sunCube.castShadow = false;
sunMarker.add(sunCube);
scene.add(sunMarker);
let sunPathLine = null;
const pathCanvas = document.getElementById("sunPath");
const pathContext = pathCanvas.getContext("2d");
const latitude = THREE.MathUtils.degToRad(40.7);
let declination = 0;
let solarTime = 10.5;
let bearing = 180;
let panelTilt = 18.4;
let currentSunDirection = new THREE.Vector3(0, 1, 0);
function solarPosition(time, decl) {
const hourAngle = THREE.MathUtils.degToRad(15 * (time - 12));
const dec = THREE.MathUtils.degToRad(decl);
const east = -Math.cos(dec) * Math.sin(hourAngle);
const north =
Math.cos(latitude) * Math.sin(dec) -
Math.sin(latitude) * Math.cos(dec) * Math.cos(hourAngle);
const up =
Math.sin(latitude) * Math.sin(dec) +
Math.cos(latitude) * Math.cos(dec) * Math.cos(hourAngle);
const direction = new THREE.Vector3(east, up, -north).normalize();
const altitude = THREE.MathUtils.radToDeg(Math.asin(THREE.MathUtils.clamp(up, -1, 1)));
let azimuth = THREE.MathUtils.radToDeg(Math.atan2(east, north));
azimuth = (azimuth + 360) % 360;
return { direction, altitude, azimuth };
}
function rebuild3DSunPath() {
const points = [];
for (let t = 4; t <= 20; t += 0.1) {
const position = solarPosition(t, declination);
if (position.altitude > 0) {
points.push(
position.direction.clone().multiplyScalar(11).add(new THREE.Vector3(0, 3.1, 0))
);
}
}
if (sunPathLine) {
scene.remove(sunPathLine);
sunPathLine.geometry.dispose();
}
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const lineMaterial = new THREE.LineDashedMaterial({
color: 0xe6a437,
dashSize: 0.26,
gapSize: 0.16,
transparent: true,
opacity: 0.68
});
sunPathLine = new THREE.Line(geometry, lineMaterial);
sunPathLine.computeLineDistances();
scene.add(sunPathLine);
}
function drawSunPath() {
const rect = pathCanvas.getBoundingClientRect();
const dpr = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.max(250, rect.width);
const height = 166;
pathCanvas.width = Math.round(width * dpr);
pathCanvas.height = Math.round(height * dpr);
pathContext.setTransform(dpr, 0, 0, dpr, 0, 0);
const ctx = pathContext;
const cx = width / 2;
const cy = height * 0.52;
const radius = Math.min(width * 0.39, height * 0.41);
ctx.clearRect(0, 0, width, height);
ctx.strokeStyle = "rgba(20,43,50,.20)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.arc(cx, cy, radius, 0, Math.PI * 2);
ctx.stroke();
ctx.setLineDash([3, 4]);
ctx.beginPath();
ctx.moveTo(cx - radius, cy);
ctx.lineTo(cx + radius, cy);
ctx.moveTo(cx, cy - radius);
ctx.lineTo(cx, cy + radius);
ctx.stroke();
ctx.setLineDash([]);
const path = [];
for (let t = 4; t <= 20; t += 0.08) {
const p = solarPosition(t, declination);
if (p.altitude > 0) {
path.push({
x: cx + Math.sin(THREE.MathUtils.degToRad(p.azimuth)) * radius,
y: cy - Math.cos(THREE.MathUtils.degToRad(p.azimuth)) * radius
});
}
}
if (path.length > 1) {
ctx.strokeStyle = "#dfa02e";
ctx.lineWidth = 3;
ctx.beginPath();
path.forEach((p, index) => index ? ctx.lineTo(p.x, p.y) : ctx.moveTo(p.x, p.y));
ctx.stroke();
}
const current = solarPosition(solarTime, declination);
if (current.altitude > 0) {
const x = cx + Math.sin(THREE.MathUtils.degToRad(current.azimuth)) * radius;
const y = cy - Math.cos(THREE.MathUtils.degToRad(current.azimuth)) * radius;
ctx.fillStyle = "#142b32";
ctx.strokeStyle = "#fff9df";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.arc(x, y, 7, 0, Math.PI * 2);
ctx.fill();
ctx.stroke();
}
ctx.fillStyle = "rgba(20,43,50,.72)";
ctx.font = "700 9px ui-monospace, monospace";
ctx.textAlign = "center";
ctx.fillText("N", cx, 12);
ctx.fillText("S", cx, height - 7);
ctx.textAlign = "left";
ctx.fillText("E", width - 12, cy + 3);
ctx.textAlign = "right";
ctx.fillText("W", 12, cy + 3);
}
// -------------------------------------------------------------------------
// Direct geometric visibility calculation
// -------------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const samplePoint = new THREE.Vector3();
const worldNormal = new THREE.Vector3();
const cellQuaternion = new THREE.Quaternion();
const blockerCounts = {
"main chimney": 0,
"small chimney": 0,
"roof": 0,
"wall": 0,
"gable wall": 0,
"foundation": 0
};
function updateGeometry() {
const position = solarPosition(solarTime, declination);
currentSunDirection.copy(position.direction);
houseRoot.rotation.y = Math.PI - THREE.MathUtils.degToRad(bearing);
const tiltRadians = THREE.MathUtils.degToRad(panelTilt);
panels.forEach(panel => panel.rotation.x = tiltRadians);
houseRoot.updateMatrixWorld(true);
scene.updateMatrixWorld(true);
let orientationIndex = 0;
let geometricIndex = 0;
let incidentCells = 0;
let openIncidentCells = 0;
let backFacingCells = 0;
let blockedCells = 0;
for (const key of Object.keys(blockerCounts)) blockerCounts[key] = 0;
for (const cell of panelCells) {
cell.getWorldQuaternion(cellQuaternion);
worldNormal.set(0, 1, 0).applyQuaternion(cellQuaternion).normalize();
const incidence = worldNormal.dot(currentSunDirection);
const facing = incidence > 0.03;
if (!facing) {
backFacingCells++;
cell.userData.visibleFraction = 0;
cell.material.color.set(0x706783);
cell.material.emissive.set(0x211c30);
continue;
}
incidentCells++;
orientationIndex += incidence;
const localSamples = [
[0, 0],
[-0.205, -0.235],
[0.205, -0.235],
[-0.205, 0.235],
[0.205, 0.235]
];
let visibleCount = 0;
let firstBlocker = null;
for (const [x, z] of localSamples) {
samplePoint.set(x, 0.030, z);
cell.localToWorld(samplePoint);
samplePoint.addScaledVector(worldNormal, 0.015);
raycaster.set(samplePoint, currentSunDirection);
raycaster.near = 0.02;
raycaster.far = 60;
const hits = raycaster.intersectObjects(occluders, false);
if (hits.length === 0) {
visibleCount++;
} else if (!firstBlocker) {
firstBlocker = hits[0].object.userData.blockerLabel || "geometry";
}
}
const visibleFraction = visibleCount / localSamples.length;
geometricIndex += incidence * visibleFraction;
cell.userData.visibleFraction = visibleFraction;
if (visibleFraction >= 0.999) {
cell.material.color.set(0x168b91);
cell.material.emissive.set(0x062e30);
openIncidentCells++;
} else if (visibleFraction >= 0.75) {
cell.material.color.set(0xd99a35);
cell.material.emissive.set(0x3b2404);
} else {
cell.material.color.set(0xed655d);
cell.material.emissive.set(0x40110f);
blockedCells++;
}
if (firstBlocker && blockerCounts[firstBlocker] !== undefined) {
blockerCounts[firstBlocker]++;
}
}
const totalCells = panelCells.length;
const orientationPercent = orientationIndex / totalCells * 100;
const geometricPercent = geometricIndex / totalCells * 100;
const loss = Math.max(0, orientationPercent - geometricPercent);
const openPercent = incidentCells ? openIncidentCells / incidentCells * 100 : 0;
document.getElementById("orientationValue").textContent = `${orientationPercent.toFixed(0)}%`;
document.getElementById("geometricValue").textContent = `${geometricPercent.toFixed(0)}%`;
document.getElementById("lossValue").textContent = `−${loss.toFixed(1)}`;
document.getElementById("openValue").textContent = `${openPercent.toFixed(0)}%`;
document.getElementById("blockedValue").textContent =
`${blockedCells} blocked · ${backFacingCells} back-facing`;
document.getElementById("compareIdeal").textContent = `${orientationPercent.toFixed(1)} / 100`;
document.getElementById("compareGeometric").textContent = `${geometricPercent.toFixed(1)} / 100`;
const status = document.getElementById("status");
status.classList.toggle("warn", blockedCells > 0);
status.textContent = blockedCells ? `${blockedCells} shaded cells` : "No direct shading";
document.getElementById("cellSummary").textContent =
`${totalCells} cells · ${incidentCells} incident`;
// Sun light, marker, and readouts.
sunLight.position.copy(currentSunDirection).multiplyScalar(23).add(new THREE.Vector3(0, 2.6, 0));
sunLight.intensity = position.altitude > 0 ? 3.2 : 0;
sunMarker.position.copy(currentSunDirection).multiplyScalar(12.7).add(new THREE.Vector3(0, 3.1, 0));
sunMarker.visible = position.altitude > 0;
document.getElementById("altitudeValue").textContent = `${position.altitude.toFixed(1)}°`;
document.getElementById("azimuthValue").textContent = `${position.azimuth.toFixed(1)}°`;
document.getElementById("declinationValue").textContent =
`${declination > 0 ? "+" : ""}${declination.toFixed(2)}°`;
const hour = Math.floor(solarTime);
const minute = Math.round((solarTime - hour) * 60);
document.getElementById("timeValue").textContent =
`${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}`;
drawSunPath();
}
// -------------------------------------------------------------------------
// UI bindings
// -------------------------------------------------------------------------
function compassLabel(degrees) {
const labels = ["N", "NE", "E", "SE", "S", "SW", "W", "NW"];
return labels[Math.round(((degrees % 360) + 360) % 360 / 45) % 8];
}
document.getElementById("bearing").addEventListener("input", event => {
bearing = Number(event.target.value);
document.getElementById("bearingValue").textContent = `${bearing}° ${compassLabel(bearing)}`;
updateGeometry();
});
document.getElementById("tilt").addEventListener("input", event => {
panelTilt = Number(event.target.value);
document.getElementById("tiltValue").textContent = `${panelTilt.toFixed(1)}°`;
updateGeometry();
});
document.getElementById("time").addEventListener("input", event => {
solarTime = Number(event.target.value);
updateGeometry();
});
document.getElementById("seasonButtons").addEventListener("click", event => {
const button = event.target.closest("button[data-decl]");
if (!button) return;
document.querySelectorAll("#seasonButtons button").forEach(item => {
item.classList.toggle("active", item === button);
});
declination = Number(button.dataset.decl);
rebuild3DSunPath();
updateGeometry();
});
window.addEventListener("resize", () => {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
drawSunPath();
});
// -------------------------------------------------------------------------
// Start and animate
// -------------------------------------------------------------------------
rebuild3DSunPath();
updateGeometry();
function animate() {
requestAnimationFrame(animate);
spherical.radius = THREE.MathUtils.lerp(spherical.radius, sphericalGoal.radius, 0.10);
spherical.theta = THREE.MathUtils.lerp(spherical.theta, sphericalGoal.theta, 0.10);
spherical.phi = THREE.MathUtils.lerp(spherical.phi, sphericalGoal.phi, 0.10);
cameraTarget.lerp(panGoal, 0.12);
updateCamera();
if (sunMarker.visible) {
const pulse = 1 + Math.sin(performance.now() * 0.0022) * 0.06;
sunMarker.scale.setScalar(pulse);
sunMarker.rotation.y += 0.006;
sunMarker.rotation.x += 0.003;
}
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```