Prompt specification
Build or customize the Three.js 3D scene "Greenhouse vent hinge 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: Greenhouse vent hinge section
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/greenhouse-vent-hinge-section-x1069
Scene Description Prompt:
Model a greenhouse roof panel with hinged vent, support arm, and adjacent fixed glazing; show the open gap clearly from both interior and exterior viewpoints. Build this with Three.js from cdnjs as a voxel scene in one self-contained HTML file.
Working Three.js Starter (greenhouse-vent-hinge-section-x1069):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voxel Greenhouse — Hinged Roof Vent</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(16, 31, 29, 0.88);
--line: rgba(210, 245, 231, 0.2);
--text: #edf8ef;
--muted: #a9c4b5;
--green: #72d29a;
--amber: #ffb547;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #a8c6aa;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.panel {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(330px, calc(100vw - 40px));
padding: 18px;
color: var(--text);
background: var(--panel);
border: 1px solid var(--line);
border-radius: 8px;
box-shadow: 0 14px 38px rgba(9, 28, 23, 0.24);
backdrop-filter: blur(12px);
}
.eyebrow {
margin: 0 0 6px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0 0 4px;
font-size: 21px;
line-height: 1.15;
letter-spacing: -0.02em;
}
.subtitle {
margin: 0 0 16px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.view-row,
.vent-row {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
button {
flex: 1;
min-height: 38px;
padding: 9px 10px;
color: var(--text);
background: rgba(255, 255, 255, 0.055);
border: 1px solid var(--line);
border-radius: 5px;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(210, 245, 231, 0.38);
}
button:active {
transform: translateY(1px);
}
button.active {
color: #10231d;
background: var(--green);
border-color: var(--green);
}
button.amber.active {
color: #372208;
background: var(--amber);
border-color: var(--amber);
}
.control-label {
display: flex;
align-items: center;
justify-content: space-between;
margin: 3px 0 8px;
color: var(--muted);
font-size: 11px;
font-weight: 700;
letter-spacing: 0.04em;
text-transform: uppercase;
}
#angle-value {
color: var(--amber);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 18px;
margin: 0 0 13px;
accent-color: var(--amber);
cursor: pointer;
}
.check-row {
display: flex;
align-items: center;
gap: 9px;
color: var(--muted);
font-size: 12px;
}
.check-row input {
width: 15px;
height: 15px;
accent-color: var(--amber);
}
.legend {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px 10px;
margin-top: 15px;
padding-top: 13px;
border-top: 1px solid var(--line);
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
color: var(--muted);
font-size: 10px;
line-height: 1.25;
}
.swatch {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 1px;
}
.instructions {
position: fixed;
z-index: 10;
right: 18px;
bottom: 16px;
max-width: calc(100vw - 36px);
padding: 9px 12px;
color: rgba(18, 38, 32, 0.82);
background: rgba(247, 252, 244, 0.72);
border: 1px solid rgba(28, 70, 55, 0.13);
border-radius: 5px;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.03em;
backdrop-filter: blur(7px);
pointer-events: none;
}
.view-badge {
position: fixed;
z-index: 10;
right: 20px;
top: 20px;
padding: 8px 11px;
color: #18392e;
background: rgba(245, 252, 244, 0.8);
border: 1px solid rgba(25, 72, 53, 0.16);
border-radius: 4px;
font-size: 10px;
font-weight: 900;
letter-spacing: 0.12em;
backdrop-filter: blur(8px);
pointer-events: none;
}
.label {
position: fixed;
z-index: 8;
top: 0;
left: 0;
display: flex;
align-items: center;
gap: 6px;
padding: 5px 7px;
color: #15372d;
background: rgba(248, 255, 249, 0.9);
border: 1px solid rgba(22, 68, 52, 0.18);
border-radius: 3px;
box-shadow: 0 4px 14px rgba(15, 47, 36, 0.14);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.07em;
white-space: nowrap;
pointer-events: none;
will-change: transform;
}
.label::before {
content: "";
width: 7px;
height: 7px;
background: var(--green);
border-radius: 1px;
}
.label.gap {
color: #4b2c05;
background: rgba(255, 244, 218, 0.94);
border-color: rgba(180, 102, 0, 0.3);
}
.label.gap::before {
background: var(--amber);
}
.label.arm::before {
background: #ee8f20;
}
.label.fixed::before {
background: #5fb6b5;
}
@media (max-width: 700px) {
.panel {
top: 10px;
left: 10px;
width: 285px;
padding: 14px;
}
.subtitle,
.legend {
display: none;
}
h1 {
font-size: 18px;
}
.view-badge {
top: 10px;
right: 10px;
}
.instructions {
right: 10px;
bottom: 10px;
}
.label {
font-size: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<section class="panel" aria-label="Greenhouse scene controls">
<p class="eyebrow">Structural study 01</p>
<h1>Voxel Greenhouse<br>Hinged Roof Vent</h1>
<p class="subtitle">
A block-built roof assembly showing the raised vent, open daylight gap,
articulated support arm, and neighboring fixed glazing.
</p>
<div class="view-row">
<button id="exteriorButton" class="active">Exterior</button>
<button id="interiorButton">Interior</button>
</div>
<div class="vent-row">
<button id="ventButton" class="amber active">Close vent</button>
</div>
<label class="control-label" for="ventAngle">
Vent opening
<span id="angle-value">34°</span>
</label>
<input id="ventAngle" type="range" min="0" max="34" step="1" value="34">
<label class="check-row">
<input id="gapToggle" type="checkbox" checked>
Highlight the open gap
</label>
<div class="legend">
<div class="legend-item">
<span class="swatch" style="background:#315f51"></span>
Greenhouse frame
</div>
<div class="legend-item">
<span class="swatch" style="background:#91d7d3"></span>
Fixed glazing
</div>
<div class="legend-item">
<span class="swatch" style="background:#f0a02f"></span>
Support arm
</div>
<div class="legend-item">
<span class="swatch" style="background:#ffb547"></span>
Open-gap marker
</div>
</div>
</section>
<div id="viewBadge" class="view-badge">EXTERIOR VIEW</div>
<div id="hingeLabel" class="label">HINGE LINE</div>
<div id="gapLabel" class="label gap">OPEN GAP</div>
<div id="armLabel" class="label arm">SUPPORT ARM</div>
<div id="fixedLabel" class="label fixed">FIXED GLAZING</div>
<div class="instructions">
DRAG TO ORBIT · WHEEL TO ZOOM · RIGHT-DRAG TO PAN
</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 stage = document.getElementById("stage");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xaac7aa);
scene.fog = new THREE.Fog(0xaac7aa, 17, 38);
const camera = new THREE.PerspectiveCamera(
58,
window.innerWidth / window.innerHeight,
0.05,
80
);
const controls = {
target: new THREE.Vector3(0.85, 3.55, -0.65),
dragging: false,
mode: "orbit",
pointerX: 0,
pointerY: 0
};
const hemisphere = new THREE.HemisphereLight(0xe8f7ff, 0x6e7854, 2.25);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0d2, 3.2);
sun.position.set(9, 13, -8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0005;
scene.add(sun);
const fill = new THREE.DirectionalLight(0x9cd7da, 0.7);
fill.position.set(-8, 5, 8);
scene.add(fill);
// -------------------------------------------------------------------------
// Shared materials and box helpers
// -------------------------------------------------------------------------
const unitBox = new THREE.BoxGeometry(1, 1, 1);
const yAxis = new THREE.Vector3(0, 1, 0);
const materials = {
frame: new THREE.MeshStandardMaterial({
color: 0x315f51,
roughness: 0.76,
metalness: 0.14
}),
frameLight: new THREE.MeshStandardMaterial({
color: 0x487666,
roughness: 0.72,
metalness: 0.12
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0x9bdcd8,
transparent: true,
opacity: 0.23,
roughness: 0.12,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
}),
ventGlass: new THREE.MeshPhysicalMaterial({
color: 0xa4e5df,
transparent: true,
opacity: 0.29,
roughness: 0.1,
metalness: 0.02,
side: THREE.DoubleSide,
depthWrite: false
}),
amber: new THREE.MeshStandardMaterial({
color: 0xf0a02f,
roughness: 0.47,
metalness: 0.25
}),
hinge: new THREE.MeshStandardMaterial({
color: 0xc99b45,
roughness: 0.35,
metalness: 0.65
}),
marker: new THREE.MeshBasicMaterial({
color: 0xffb547,
transparent: true,
opacity: 0.82,
depthWrite: false
}),
markerFill: new THREE.MeshBasicMaterial({
color: 0xffb547,
transparent: true,
opacity: 0.14,
depthWrite: false
}),
ground: new THREE.MeshStandardMaterial({
color: 0x8eac88,
roughness: 1
}),
foundation: new THREE.MeshStandardMaterial({
color: 0x65766b,
roughness: 0.94
}),
soil: new THREE.MeshStandardMaterial({
color: 0x554538,
roughness: 1
}),
bench: new THREE.MeshStandardMaterial({
color: 0x8f7352,
roughness: 0.88
}),
leafA: new THREE.MeshStandardMaterial({
color: 0x4d9b54,
roughness: 0.9
}),
leafB: new THREE.MeshStandardMaterial({
color: 0x74b85d,
roughness: 0.9
}),
stem: new THREE.MeshStandardMaterial({
color: 0x397e43,
roughness: 0.9
})
};
function box(w, h, d, material, x = 0, y = 0, z = 0, parent = scene) {
const mesh = new THREE.Mesh(unitBox, material);
mesh.scale.set(w, h, d);
mesh.position.set(x, y, z);
mesh.castShadow = material !== materials.glass &&
material !== materials.ventGlass &&
material !== materials.marker &&
material !== materials.markerFill;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function setBeam(mesh, a, b, width, depth = width) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = Math.max(direction.length(), 0.0001);
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(yAxis, direction.normalize());
mesh.scale.set(width, length, depth);
}
function beam(a, b, width, material, depth = width, parent = scene) {
const mesh = new THREE.Mesh(unitBox, material);
setBeam(mesh, a, b, width, depth);
mesh.castShadow = material !== materials.marker &&
material !== materials.markerFill;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function boxBetween(a, b, width, depth, material, parent = scene) {
return beam(a, b, width, material, depth, parent);
}
// -------------------------------------------------------------------------
// Greenhouse dimensions
// -------------------------------------------------------------------------
const HALF_WIDTH = 3.1;
const RIDGE_Y = 4.7;
const EAVE_Y = 2.55;
const HALF_LENGTH = 4.4;
const ROOF_ANGLE = Math.atan2(
RIDGE_Y - EAVE_Y,
HALF_WIDTH
);
const HINGE_X = 0.3;
const HINGE_Y = RIDGE_Y - Math.tan(ROOF_ANGLE) * HINGE_X;
const VENT_LENGTH = 2.75;
const VENT_WIDTH = 2.65;
const VENT_Z = -1.25;
function roofY(x) {
return RIDGE_Y - Math.tan(ROOF_ANGLE) * Math.abs(x);
}
// -------------------------------------------------------------------------
// Ground, foundation, and voxel floor
// -------------------------------------------------------------------------
box(44, 0.3, 44, materials.ground, 0, -0.48, 0);
box(
HALF_WIDTH * 2 + 0.45,
0.24,
HALF_LENGTH * 2 + 0.45,
materials.foundation,
0,
-0.15,
0
);
const paverGeometry = new THREE.BoxGeometry(0.68, 0.08, 0.68);
const paverMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.97
});
const pavers = new THREE.InstancedMesh(
paverGeometry,
paverMaterial,
8 * 12
);
pavers.receiveShadow = true;
const dummy = new THREE.Object3D();
const paverColors = [
new THREE.Color(0xbfc2b6),
new THREE.Color(0xc8c8bb),
new THREE.Color(0xb2b8ad),
new THREE.Color(0xd0ccbd)
];
let paverIndex = 0;
for (let ix = 0; ix < 8; ix++) {
for (let iz = 0; iz < 12; iz++) {
dummy.position.set(
-2.72 + ix * 0.78,
0.015,
-4.29 + iz * 0.78
);
dummy.rotation.y = ((ix + iz) % 2) * Math.PI * 0.5;
dummy.updateMatrix();
pavers.setMatrixAt(paverIndex, dummy.matrix);
pavers.setColorAt(
paverIndex,
paverColors[(ix * 3 + iz * 5) % paverColors.length]
);
paverIndex++;
}
}
pavers.instanceMatrix.needsUpdate = true;
pavers.instanceColor.needsUpdate = true;
scene.add(pavers);
// -------------------------------------------------------------------------
// Main structural frame
// -------------------------------------------------------------------------
box(0.14, 0.14, HALF_LENGTH * 2 + 0.2, materials.frame, 0, RIDGE_Y, 0);
for (const side of [-1, 1]) {
box(
0.13,
0.13,
HALF_LENGTH * 2 + 0.2,
materials.frame,
side * HALF_WIDTH,
EAVE_Y,
0
);
const postZ = [-4.4, -1.5, 1.5, 4.4];
for (const z of postZ) {
box(
0.13,
EAVE_Y,
0.13,
materials.frame,
side * HALF_WIDTH,
EAVE_Y * 0.5,
z
);
}
box(
0.1,
0.1,
HALF_LENGTH * 2,
materials.frameLight,
side * HALF_WIDTH,
0.24,
0
);
box(
0.08,
0.08,
HALF_LENGTH * 2,
materials.frameLight,
side * HALF_WIDTH,
1.38,
0
);
}
const endZ = [-4.4, 4.4];
for (const z of endZ) {
box(
HALF_WIDTH * 2,
0.12,
0.12,
materials.frame,
0,
0.24,
z
);
box(
HALF_WIDTH * 2,
0.12,
0.12,
materials.frame,
0,
EAVE_Y,
z
);
for (const x of [-3.1, -1.55, 0, 1.55, 3.1]) {
box(
0.11,
EAVE_Y,
0.11,
materials.frame,
x,
EAVE_Y * 0.5,
z
);
}
}
// Sloped rafters.
const rafterZ = [-4.4, -2.6, 0.1, 3.2, 4.4];
for (const z of rafterZ) {
beam(
new THREE.Vector3(0, RIDGE_Y, z),
new THREE.Vector3(HALF_WIDTH, EAVE_Y, z),
0.11,
materials.frame
);
beam(
new THREE.Vector3(-HALF_WIDTH, EAVE_Y, z),
new THREE.Vector3(0, RIDGE_Y, z),
0.11,
materials.frame
);
}
// Side-wall glazing.
for (const side of [-1, 1]) {
const zBays = [-4.4, -2.2, 0, 2.2, 4.4];
for (let i = 0; i < zBays.length - 1; i++) {
const z0 = zBays[i];
const z1 = zBays[i + 1];
const zCenter = (z0 + z1) * 0.5;
const width = z1 - z0 - 0.1;
const pane = box(
0.035,
2.15,
width,
materials.glass,
side * HALF_WIDTH,
1.39,
zCenter
);
pane.renderOrder = 1;
}
}
// End-wall glazing, including a central framed doorway.
for (const z of endZ) {
for (const side of [-1, 1]) {
for (const x of [side * 2.33, side * 0.78]) {
const pane = box(
1.42,
2.15,
0.035,
materials.glass,
x,
1.39,
z
);
pane.renderOrder = 1;
}
}
}
// -------------------------------------------------------------------------
// Fixed roof glazing
// -------------------------------------------------------------------------
function addFixedRoofPanel(side, z0, z1, subdivisionsZ = 3) {
const xEdges = side > 0
? [0.05, 1.05, 2.08, HALF_WIDTH]
: [-HALF_WIDTH, -2.08, -1.05, -0.05];
const zWidth = z1 - z0;
const tileWidth = zWidth / subdivisionsZ;
for (let ix = 0; ix < xEdges.length - 1; ix++) {
const xa = xEdges[ix];
const xb = xEdges[ix + 1];
const xCenter = (xa + xb) * 0.5;
const length = Math.abs(xb - xa) / Math.cos(ROOF_ANGLE);
for (let iz = 0; iz < subdivisionsZ; iz++) {
const zCenter = z0 + (iz + 0.5) * tileWidth;
const pane = box(
length - 0.075,
0.035,
tileWidth - 0.075,
materials.glass,
xCenter,
roofY(xCenter),
zCenter
);
pane.rotation.z = side > 0 ? -ROOF_ANGLE : ROOF_ANGLE;
pane.renderOrder = 1;
}
}
// Longitudinal glazing bars.
for (let iz = 0; iz <= subdivisionsZ; iz++) {
const z = z0 + iz * tileWidth;
if (side > 0) {
beam(
new THREE.Vector3(0.03, RIDGE_Y, z),
new THREE.Vector3(HALF_WIDTH, EAVE_Y, z),
0.065,
materials.frameLight,
0.065
);
} else {
beam(
new THREE.Vector3(-HALF_WIDTH, EAVE_Y, z),
new THREE.Vector3(-0.03, RIDGE_Y, z),
0.065,
materials.frameLight,
0.065
);
}
}
// Cross-slope mullions.
for (const x of xEdges) {
const y = roofY(x);
box(
0.06,
0.06,
zWidth,
materials.frameLight,
x,
y + 0.015,
(z0 + z1) * 0.5
);
}
}
// Entire left roof is fixed.
addFixedRoofPanel(-1, -4.4, 4.4, 6);
// Right roof: adjacent fixed panel, rear panel, and front panel.
// The bay between z=-2.6 and z=0.1 is reserved for the hinged vent.
addFixedRoofPanel(1, -4.4, -2.6, 2);
addFixedRoofPanel(1, 0.1, 3.2, 3);
addFixedRoofPanel(1, 3.2, 4.4, 1);
// Fixed purlins remain visible beneath the open vent.
for (const x of [1.05, 2.08]) {
box(
0.07,
0.07,
6.85,
materials.frameLight,
x,
roofY(x),
-1.25
);
}
// Fixed lower rail along the closed position of the vent's outer edge.
const ventClosedOuterX = HINGE_X + VENT_LENGTH * Math.cos(ROOF_ANGLE);
const ventClosedOuterY = HINGE_Y - VENT_LENGTH * Math.sin(ROOF_ANGLE);
box(
0.085,
0.085,
VENT_WIDTH + 0.12,
materials.frameLight,
ventClosedOuterX,
ventClosedOuterY,
VENT_Z
);
// -------------------------------------------------------------------------
// Hinged vent assembly
// -------------------------------------------------------------------------
const roofMount = new THREE.Group();
roofMount.position.set(HINGE_X, HINGE_Y, VENT_Z);
roofMount.rotation.z = -ROOF_ANGLE;
scene.add(roofMount);
// Fixed hinge rail and blocky hinge knuckles.
box(
0.12,
0.12,
VENT_WIDTH + 0.2,
materials.frame,
0,
0,
0,
roofMount
);
for (let i = 0; i < 5; i++) {
const z = -VENT_WIDTH * 0.42 + i * VENT_WIDTH * 0.21;
box(
0.2,
0.2,
0.22,
materials.hinge,
0.01,
0.025,
z,
roofMount
);
box(
0.11,
0.28,
0.13,
materials.hinge,
0.01,
0.025,
z,
roofMount
);
}
const ventSash = new THREE.Group();
roofMount.add(ventSash);
const ventFrameDepth = 0.09;
// Perimeter frame.
box(
VENT_LENGTH,
ventFrameDepth,
ventFrameDepth,
materials.frame,
VENT_LENGTH * 0.5,
0,
-VENT_WIDTH * 0.5,
ventSash
);
box(
VENT_LENGTH,
ventFrameDepth,
ventFrameDepth,
materials.frame,
VENT_LENGTH * 0.5,
0,
VENT_WIDTH * 0.5,
ventSash
);
box(
ventFrameDepth,
ventFrameDepth,
VENT_WIDTH,
materials.frame,
0,
0,
0,
ventSash
);
box(
ventFrameDepth,
ventFrameDepth,
VENT_WIDTH,
materials.frame,
VENT_LENGTH,
0,
0,
ventSash
);
// Interior mullions.
box(
0.075,
0.075,
VENT_WIDTH,
materials.frameLight,
VENT_LENGTH * 0.5,
0,
0,
ventSash
);
box(
VENT_LENGTH,
0.075,
0.075,
materials.frameLight,
VENT_LENGTH * 0.5,
0,
0,
ventSash
);
// Four-by-two vent glazing.
for (let ix = 0; ix < 4; ix++) {
for (let iz = 0; iz < 2; iz++) {
const pane = box(
VENT_LENGTH * 0.25 - 0.075,
0.035,
VENT_WIDTH * 0.5 - 0.075,
materials.ventGlass,
VENT_LENGTH * (ix + 0.5) * 0.25,
0,
-VENT_WIDTH * 0.5 + VENT_WIDTH * (iz + 0.5) * 0.5,
ventSash
);
pane.renderOrder = 2;
}
}
// -------------------------------------------------------------------------
// Articulated support arm
// -------------------------------------------------------------------------
const armGroup = new THREE.Group();
scene.add(armGroup);
const armLower = box(1, 1, 1, materials.amber, 0, 0, 0, armGroup);
const armUpper = box(1, 1, 1, materials.frameLight, 0, 0, 0, armGroup);
const armSlider = box(1, 1, 1, materials.hinge, 0, 0, 0, armGroup);
const armAnchor = new THREE.Vector3(
ventClosedOuterX + 0.08,
ventClosedOuterY + 0.06,
VENT_Z
);
const armAttach = new THREE.Vector3();
const armMid = new THREE.Vector3();
function updateSupportArm() {
scene.updateMatrixWorld(true);
armAttach.copy(
ventSash.localToWorld(
new THREE.Vector3(VENT_LENGTH * 0.58, -0.075, 0)
)
);
armMid.lerpVectors(armAnchor, armAttach, 0.57);
setBeam(armLower, armAnchor, armMid, 0.095, 0.095);
setBeam(armUpper, armMid, armAttach, 0.075, 0.075);
armSlider.position.copy(armMid);
armSlider.quaternion.copy(armUpper.quaternion);
armSlider.scale.set(0.15, 0.18, 0.15);
}
// -------------------------------------------------------------------------
// Open-gap annotation geometry
// -------------------------------------------------------------------------
const gapGroup = new THREE.Group();
scene.add(gapGroup);
const gapNear = box(1, 1, 1, materials.marker, 0, 0, 0, gapGroup);
const gapFar = box(1, 1, 1, materials.marker, 0, 0, 0, gapGroup);
const gapLower = box(1, 1, 1, materials.marker, 0, 0, 0, gapGroup);
const gapUpper = box(1, 1, 1, materials.marker, 0, 0, 0, gapGroup);
const gapFillNear = box(1, 1, 1, materials.markerFill, 0, 0, 0, gapGroup);
const gapFillFar = box(1, 1, 1, materials.markerFill, 0, 0, 0, gapGroup);
function updateGapMarker() {
const nearClosed = new THREE.Vector3(
ventClosedOuterX,
ventClosedOuterY,
VENT_Z - VENT_WIDTH * 0.5
);
const farClosed = new THREE.Vector3(
ventClosedOuterX,
ventClosedOuterY,
VENT_Z + VENT_WIDTH * 0.5
);
const nearOpen = ventSash.localToWorld(
new THREE.Vector3(VENT_LENGTH, 0, -VENT_WIDTH * 0.5)
);
const farOpen = ventSash.localToWorld(
new THREE.Vector3(VENT_LENGTH, 0, VENT_WIDTH * 0.5)
);
setBeam(gapNear, nearClosed, nearOpen, 0.055, 0.055);
setBeam(gapFar, farClosed, farOpen, 0.055, 0.055);
setBeam(gapLower, nearClosed, farClosed, 0.045, 0.045);
setBeam(gapUpper, nearOpen, farOpen, 0.055, 0.055);
const nearMid = nearClosed.clone().lerp(nearOpen, 0.5);
const farMid = farClosed.clone().lerp(farOpen, 0.5);
setBeam(gapFillNear, nearClosed, nearOpen, 0.018, 0.045);
setBeam(gapFillFar, farClosed, farOpen, 0.018, 0.045);
gapFillNear.position.copy(nearMid);
gapFillFar.position.copy(farMid);
}
// -------------------------------------------------------------------------
// Interior voxel furnishings
// -------------------------------------------------------------------------
function makeBench(x, z, length = 2.1) {
box(1.25, 0.16, length, materials.bench, x, 1.0, z);
for (const dx of [-0.48, 0.48]) {
for (const dz of [-length * 0.38, length * 0.38]) {
box(
0.12,
0.9,
0.12,
materials.frame,
x + dx,
0.48,
z + dz
);
}
}
}
function makePlanter(x, z, width = 0.9, depth = 0.9) {
box(width, 0.35, depth, materials.frame, x, 0.27, z);
box(
width - 0.12,
0.06,
depth - 0.12,
materials.soil,
x,
0.46,
z
);
}
function makePlant(x, z, baseY = 0.5, size = 1) {
box(
0.07 * size,
0.65 * size,
0.07 * size,
materials.stem,
x,
baseY + 0.32 * size,
z
);
box(
0.5 * size,
0.16 * size,
0.24 * size,
materials.leafA,
x - 0.12 * size,
baseY + 0.38 * size,
z,
scene
);
box(
0.45 * size,
0.16 * size,
0.23 * size,
materials.leafB,
x + 0.13 * size,
baseY + 0.57 * size,
z
);
box(
0.38 * size,
0.16 * size,
0.22 * size,
materials.leafA,
x,
baseY + 0.75 * size,
z
);
}
makeBench(-1.72, -1.55, 2.1);
makeBench(-1.72, 1.35, 2.1);
makePlanter(1.7, 2.45, 1.2, 1.1);
makePlanter(1.85, -3.35, 0.95, 0.95);
makePlanter(-0.8, -3.2, 0.95, 0.9);
makePlant(1.45, 2.43, 0.5, 0.9);
makePlant(1.9, 2.5, 0.5, 1.05);
makePlant(1.75, -3.3, 0.5, 0.95);
makePlant(-0.9, -3.17, 0.5, 0.82);
makePlant(-0.67, -3.25, 0.5, 1.0);
// Small outdoor voxel planters add scale.
for (const x of [-4.4, 4.35]) {
box(0.85, 0.55, 0.85, materials.foundation, x, 0.16, -2.7);
box(0.68, 0.06, 0.68, materials.soil, x, 0.46, -2.7);
makePlant(x, -2.7, 0.5, 1.15);
}
// -------------------------------------------------------------------------
// Vent animation and UI
// -------------------------------------------------------------------------
const DEG = Math.PI / 180;
let currentOpen = 34;
let targetOpen = 34;
const angleValue = document.getElementById("angle-value");
const ventAngle = document.getElementById("ventAngle");
const ventButton = document.getElementById("ventButton");
const gapToggle = document.getElementById("gapToggle");
function syncVentButton() {
const isOpen = targetOpen > 1;
ventButton.textContent = isOpen ? "Close vent" : "Open vent";
ventButton.classList.toggle("active", isOpen);
}
ventButton.addEventListener("click", () => {
targetOpen = targetOpen > 1 ? 0 : 34;
ventAngle.value = String(targetOpen);
angleValue.textContent = `${Math.round(targetOpen)}°`;
syncVentButton();
});
ventAngle.addEventListener("input", () => {
targetOpen = Number(ventAngle.value);
angleValue.textContent = `${Math.round(targetOpen)}°`;
syncVentButton();
});
gapToggle.addEventListener("change", () => {
gapGroup.visible = gapToggle.checked;
});
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and animated presets
// -------------------------------------------------------------------------
const views = {
exterior: {
position: new THREE.Vector3(10.2, 7.4, -9.5),
target: new THREE.Vector3(0.85, 3.65, -0.65)
},
interior: {
position: new THREE.Vector3(0.1, 1.48, 3.72),
target: new THREE.Vector3(1.62, 4.2, -0.78)
}
};
let cameraTween = null;
let currentView = "exterior";
camera.position.copy(views.exterior.position);
controls.target.copy(views.exterior.target);
camera.lookAt(controls.target);
const exteriorButton = document.getElementById("exteriorButton");
const interiorButton = document.getElementById("interiorButton");
const viewBadge = document.getElementById("viewBadge");
function goToView(name) {
const view = views[name];
if (!view) return;
currentView = name;
cameraTween = {
start: performance.now(),
duration: 1150,
fromPosition: camera.position.clone(),
fromTarget: controls.target.clone(),
toPosition: view.position.clone(),
toTarget: view.target.clone()
};
exteriorButton.classList.toggle("active", name === "exterior");
interiorButton.classList.toggle("active", name === "interior");
viewBadge.textContent = name === "exterior" ? "EXTERIOR VIEW" : "INTERIOR VIEW";
}
exteriorButton.addEventListener("click", () => goToView("exterior"));
interiorButton.addEventListener("click", () => goToView("interior"));
const rayPointer = new THREE.Vector2();
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
const panRight = new THREE.Vector3();
const panUp = new THREE.Vector3();
renderer.domElement.addEventListener("contextmenu", event => {
event.preventDefault();
});
renderer.domElement.addEventListener("pointerdown", event => {
cameraTween = null;
controls.dragging = true;
controls.mode = event.button === 2 || event.button === 1 || event.shiftKey
? "pan"
: "orbit";
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", event => {
if (!controls.dragging) return;
const dx = event.clientX - controls.pointerX;
const dy = event.clientY - controls.pointerY;
controls.pointerX = event.clientX;
controls.pointerY = event.clientY;
cameraOffset.copy(camera.position).sub(controls.target);
if (controls.mode === "orbit") {
spherical.setFromVector3(cameraOffset);
spherical.theta -= dx * 0.0055;
spherical.phi = THREE.MathUtils.clamp(
spherical.phi - dy * 0.0055,
0.08,
Math.PI - 0.08
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(controls.target).add(cameraOffset);
} else {
camera.updateMatrixWorld();
panRight.setFromMatrixColumn(camera.matrix, 0);
panUp.setFromMatrixColumn(camera.matrix, 1);
const panScale = cameraOffset.length() * 0.00125;
controls.target.addScaledVector(panRight, -dx * panScale);
controls.target.addScaledVector(panUp, dy * panScale);
camera.position.copy(controls.target).add(cameraOffset);
}
camera.lookAt(controls.target);
});
function endPointerDrag(event) {
controls.dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endPointerDrag);
renderer.domElement.addEventListener("pointercancel", endPointerDrag);
renderer.domElement.addEventListener(
"wheel",
event => {
event.preventDefault();
cameraTween = null;
cameraOffset.copy(camera.position).sub(controls.target);
const scale = Math.exp(event.deltaY * 0.001);
const newLength = THREE.MathUtils.clamp(
cameraOffset.length() * scale,
0.28,
38
);
cameraOffset.setLength(newLength);
camera.position.copy(controls.target).add(cameraOffset);
camera.lookAt(controls.target);
},
{ passive: false }
);
// -------------------------------------------------------------------------
// Projected HTML annotations
// -------------------------------------------------------------------------
const labels = {
hinge: {
element: document.getElementById("hingeLabel"),
point: new THREE.Vector3(HINGE_X, HINGE_Y, VENT_Z - VENT_WIDTH * 0.5)
},
gap: {
element: document.getElementById("gapLabel"),
point: new THREE.Vector3()
},
arm: {
element: document.getElementById("armLabel"),
point: new THREE.Vector3()
},
fixed: {
element: document.getElementById("fixedLabel"),
point: new THREE.Vector3(1.55, roofY(1.55) + 0.15, 1.6)
}
};
const projected = new THREE.Vector3();
function updateLabel(label) {
projected.copy(label.point).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.08 &&
projected.x < 1.08 &&
projected.y > -1.08 &&
projected.y < 1.08;
if (!visible) {
label.element.style.opacity = "0";
return;
}
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
label.element.style.opacity = "1";
label.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
}
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
// Smoothly approach the requested vent angle.
currentOpen += (targetOpen - currentOpen) * (1 - Math.exp(-delta * 7.5));
ventSash.rotation.z = currentOpen * DEG;
scene.updateMatrixWorld(true);
updateSupportArm();
updateGapMarker();
// Animated camera transition.
if (cameraTween) {
const now = performance.now();
const raw = (now - cameraTween.start) / cameraTween.duration;
const t = THREE.MathUtils.clamp(raw, 0, 1);
const eased = t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
camera.position.lerpVectors(
cameraTween.fromPosition,
cameraTween.toPosition,
eased
);
controls.target.lerpVectors(
cameraTween.fromTarget,
cameraTween.toTarget,
eased
);
if (t >= 1) {
cameraTween = null;
}
}
camera.lookAt(controls.target);
// Dynamic annotation anchors.
const closedNear = new THREE.Vector3(
ventClosedOuterX,
ventClosedOuterY,
VENT_Z - VENT_WIDTH * 0.5
);
const openNear = ventSash.localToWorld(
new THREE.Vector3(VENT_LENGTH, 0, -VENT_WIDTH * 0.5)
);
labels.gap.point.copy(closedNear).lerp(openNear, 0.5);
labels.arm.point.copy(armMid);
for (const label of Object.values(labels)) {
updateLabel(label);
}
renderer.render(scene, camera);
}
syncVentButton();
animate();
</script>
</body>
</html>
```