Prompt specification
Build or customize the Three.js 3D scene "Sunlit bedroom privacy corner" 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: Sunlit bedroom privacy corner
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sunlit-bedroom-privacy-corner-x0183
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Build a bedroom with window, curtains, bed, and exterior courtyard model; allow panel positions to change both the room's light patch and outside sightline.
Working Three.js Starter (sunlit-bedroom-privacy-corner-x0183):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sunlit Bedroom — Interactive Three.js Scene</title>
<style>
:root {
color-scheme: dark;
--ink: #f8f3e9;
--muted: #c9d1cd;
--glass: rgba(25, 35, 40, 0.78);
--line: rgba(255, 255, 255, 0.16);
--accent: #f0b96b;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #b8d5dc;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene,
#scene canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
}
#scene canvas {
touch-action: none;
}
#ui {
position: fixed;
z-index: 10;
top: 20px;
left: 20px;
width: min(340px, calc(100vw - 40px));
padding: 18px;
color: var(--ink);
background: var(--glass);
border: 1px solid var(--line);
border-radius: 18px;
box-shadow: 0 18px 55px rgba(19, 31, 35, 0.24);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
user-select: none;
}
.eyebrow {
margin: 0 0 5px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 9px 0 17px;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.control {
margin-top: 14px;
}
.control label {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 7px;
color: #edf1ed;
font-size: 12px;
font-weight: 650;
}
output {
color: var(--accent);
font-variant-numeric: tabular-nums;
}
input[type="range"] {
width: 100%;
height: 5px;
margin: 5px 0;
border-radius: 99px;
background: rgba(255, 255, 255, 0.18);
accent-color: var(--accent);
cursor: pointer;
}
.buttons {
display: flex;
gap: 7px;
margin-top: 16px;
}
button {
flex: 1;
min-width: 0;
padding: 9px 8px;
color: var(--ink);
background: rgba(255, 255, 255, 0.08);
border: 1px solid var(--line);
border-radius: 10px;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.16);
transform: translateY(-1px);
}
button:focus-visible,
input:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 3px;
}
.toggle {
display: flex;
align-items: center;
gap: 8px;
margin-top: 15px;
color: var(--muted);
font-size: 11px;
cursor: pointer;
}
.toggle input {
accent-color: var(--accent);
}
#readout {
margin: 13px 0 0;
padding-top: 12px;
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
#hint {
position: fixed;
z-index: 5;
right: 20px;
bottom: 18px;
padding: 9px 12px;
color: rgba(255, 255, 255, 0.88);
background: rgba(25, 35, 40, 0.64);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 99px;
font-size: 11px;
backdrop-filter: blur(12px);
pointer-events: none;
}
#insetLabel {
position: fixed;
z-index: 6;
top: 20px;
right: 20px;
padding: 6px 9px;
color: #263437;
background: rgba(248, 243, 233, 0.9);
border-radius: 7px 7px 0 0;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
pointer-events: none;
}
#insetFrame {
position: fixed;
z-index: 5;
border: 2px solid rgba(248, 243, 233, 0.88);
border-radius: 0 0 12px 12px;
box-shadow: 0 15px 45px rgba(19, 31, 35, 0.28);
pointer-events: none;
}
@media (max-width: 650px) {
#ui {
top: 12px;
left: 12px;
width: min(300px, calc(100vw - 24px));
padding: 14px;
}
h1 {
font-size: 19px;
}
.intro {
margin-bottom: 11px;
}
.control {
margin-top: 10px;
}
#insetLabel {
top: 12px;
right: 12px;
}
#hint {
right: 12px;
bottom: 12px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<section id="ui" aria-label="Scene controls">
<p class="eyebrow">Interactive interior study</p>
<h1>Sunlit courtyard bedroom</h1>
<p class="intro">
Slide the wooden window panels. Their positions change the floor light,
cast shadows, and the amount of courtyard visible through the window.
</p>
<div class="control">
<label for="leftPanel">
Left panel position
<output id="leftValue" for="leftPanel">40%</output>
</label>
<input id="leftPanel" type="range" min="0" max="100" value="40">
</div>
<div class="control">
<label for="rightPanel">
Right panel position
<output id="rightValue" for="rightPanel">45%</output>
</label>
<input id="rightPanel" type="range" min="0" max="100" value="45">
</div>
<div class="buttons">
<button type="button" data-preset="closed">Close</button>
<button type="button" data-preset="open">Open</button>
<button type="button" data-preset="offset">Offset</button>
<button id="resetView" type="button">View</button>
</div>
<label class="toggle">
<input id="insetToggle" type="checkbox" checked>
Show courtyard sightline
</label>
<p id="readout" aria-live="polite"></p>
</section>
<div id="insetLabel">Bed's-eye courtyard view</div>
<div id="insetFrame"></div>
<div id="hint">Drag to orbit · Scroll to zoom · Shift/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 host = document.getElementById("scene");
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.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = false;
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color("#b9d7de");
scene.fog = new THREE.Fog("#b9d7de", 19, 39);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const sightlineCamera = new THREE.PerspectiveCamera(48, 1.6, 0.1, 60);
sightlineCamera.position.set(-1.35, 2.28, -0.05);
sightlineCamera.lookAt(0.35, 1.9, -13);
// -------------------------------------------------------------------------
// Materials and helpers
// -------------------------------------------------------------------------
const material = (color, roughness = 0.8, metalness = 0) =>
new THREE.MeshStandardMaterial({ color, roughness, metalness });
const mats = {
wall: material("#e9dfcf"),
wallSide: material("#dfd1bd"),
trim: material("#f8f1e5"),
darkWood: material("#65483a"),
bedWood: material("#936a52"),
mattress: material("#f5eee1"),
blanket: material("#c96f58"),
blanketDark: material("#9e4e46"),
pillow: material("#fff9ed"),
rug: material("#d7b68d"),
rugInset: material("#b48d6e"),
panel: material("#648b88"),
panelInset: material("#86aaa4"),
metal: material("#433c36", 0.42, 0.5),
brass: material("#b98743", 0.35, 0.6),
pot: material("#b86e50"),
leaf: material("#5c8461"),
leafLight: material("#7fa16f"),
water: material("#65aebb", 0.24, 0.12),
courtyard: material("#d5b995"),
courtyardLight: material("#e8d7bc"),
trunk: material("#76543f")
};
function addBox(parent, size, position, mat, cast = true, receive = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = receive;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radiusTop,
radiusBottom,
height,
position,
mat,
segments = 20,
cast = true
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addSphere(parent, radius, position, mat, detail = 1) {
const mesh = new THREE.Mesh(
new THREE.IcosahedronGeometry(radius, detail),
mat
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Lighting
// -------------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight("#d9f1ff", "#775b43", 1.75);
scene.add(hemisphere);
const ambient = new THREE.AmbientLight("#fff3df", 0.28);
scene.add(ambient);
const sun = new THREE.DirectionalLight("#ffe0a3", 3.8);
sun.position.set(-6, 10, -12);
sun.target.position.set(1, 0, 2.5);
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 = 1;
sun.shadow.camera.far = 42;
sun.shadow.normalBias = 0.035;
scene.add(sun, sun.target);
const roomFill = new THREE.PointLight("#ffd9a1", 10, 9, 2);
roomFill.position.set(-0.5, 3.2, -1.1);
scene.add(roomFill);
// -------------------------------------------------------------------------
// Bedroom shell
// -------------------------------------------------------------------------
const ROOM_Z = -4.7;
const WINDOW_HALF_WIDTH = 2.7;
const WINDOW_BOTTOM = 0.9;
const WINDOW_TOP = 3.8;
// Subfloor and individually colored wooden planks.
addBox(
scene,
[10.6, 0.16, 10.3],
[0, -0.13, 0.35],
material("#7a5943"),
false,
true
);
const plankMaterials = [
material("#b98b62"),
material("#c3976d"),
material("#ad7d58"),
material("#c59b73")
];
for (let i = 0; i < 11; i++) {
addBox(
scene,
[0.98, 0.075, 10.2],
[-5 + i, 0, 0.35],
plankMaterials[i % plankMaterials.length],
false,
true
);
}
// Back wall built around a real window opening.
addBox(
scene,
[10.4, WINDOW_BOTTOM, 0.28],
[0, WINDOW_BOTTOM / 2, ROOM_Z],
mats.wall
);
const upperWallHeight = 4.6 - WINDOW_TOP;
addBox(
scene,
[10.4, upperWallHeight, 0.28],
[0, WINDOW_TOP + upperWallHeight / 2, ROOM_Z],
mats.wall
);
const sideWallWidth = 5.2 - WINDOW_HALF_WIDTH;
addBox(
scene,
[sideWallWidth, WINDOW_TOP - WINDOW_BOTTOM, 0.28],
[
-(WINDOW_HALF_WIDTH + sideWallWidth / 2),
(WINDOW_TOP + WINDOW_BOTTOM) / 2,
ROOM_Z
],
mats.wall
);
addBox(
scene,
[sideWallWidth, WINDOW_TOP - WINDOW_BOTTOM, 0.28],
[
WINDOW_HALF_WIDTH + sideWallWidth / 2,
(WINDOW_TOP + WINDOW_BOTTOM) / 2,
ROOM_Z
],
mats.wall
);
// Left wall and simple architectural trim.
addBox(
scene,
[0.28, 4.6, 10.3],
[-5.25, 2.3, 0.35],
mats.wallSide
);
addBox(
scene,
[0.14, 0.16, 10.2],
[-5.06, 0.22, 0.35],
mats.trim
);
addBox(
scene,
[0.14, 0.16, 10.2],
[-5.06, 4.28, 0.35],
mats.trim
);
// -------------------------------------------------------------------------
// Window frame, curtains, and sliding panels
// -------------------------------------------------------------------------
const frameZ = -4.43;
addBox(
scene,
[0.15, 3.05, 0.18],
[-WINDOW_HALF_WIDTH - 0.02, 2.35, frameZ],
mats.trim
);
addBox(
scene,
[0.15, 3.05, 0.18],
[WINDOW_HALF_WIDTH + 0.02, 2.35, frameZ],
mats.trim
);
addBox(
scene,
[5.65, 0.15, 0.18],
[0, WINDOW_TOP + 0.02, frameZ],
mats.trim
);
addBox(
scene,
[5.65, 0.15, 0.18],
[0, WINDOW_BOTTOM - 0.02, frameZ],
mats.trim
);
addBox(
scene,
[6.05, 0.16, 0.58],
[0, 0.77, -4.24],
mats.trim
);
addBox(
scene,
[5.55, 0.06, 0.1],
[0, 3.83, -4.28],
mats.metal
);
addBox(
scene,
[5.55, 0.06, 0.1],
[0, 0.92, -4.28],
mats.metal
);
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.035, 7.0, 12),
mats.brass
);
rod.rotation.z = Math.PI / 2;
rod.position.set(0, 3.98, -4.19);
rod.castShadow = true;
scene.add(rod);
function createCurtain(x, sign) {
const geometry = new THREE.PlaneGeometry(1.16, 3.25, 30, 12);
const position = geometry.attributes.position;
for (let i = 0; i < position.count; i++) {
const px = position.getX(i);
const py = position.getY(i);
const u = (px + 0.58) / 1.16;
const wave = Math.sin(u * Math.PI * 9) * 0.075;
const taper = 0.035 * ((py + 1.625) / 3.25);
position.setXYZ(i, px, py, wave + taper);
}
geometry.computeVertexNormals();
const curtain = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: sign > 0 ? "#d5bca5" : "#c9ae96",
roughness: 0.96,
side: THREE.DoubleSide
})
);
curtain.position.set(x, 2.3, -4.13);
curtain.castShadow = true;
curtain.receiveShadow = true;
scene.add(curtain);
return curtain;
}
createCurtain(-3.12, -1);
createCurtain(3.12, 1);
function createSlidingPanel(side) {
const group = new THREE.Group();
addBox(
group,
[2.7, 2.78, 0.1],
[0, 0, 0],
mats.panel
);
addBox(
group,
[2.39, 2.46, 0.035],
[0, 0, 0.067],
mats.panelInset
);
for (let i = 0; i < 5; i++) {
addBox(
group,
[2.12, 0.025, 0.025],
[0, -0.88 + i * 0.44, 0.095],
material("#4d7471"),
false,
false
);
}
const handleX = side === "left" ? 1.04 : -1.04;
addBox(
group,
[0.07, 0.38, 0.1],
[handleX, 0, 0.14],
mats.brass,
true,
false
);
group.position.set(side === "left" ? -1.35 : 1.35, 2.35, -4.31);
scene.add(group);
return group;
}
const leftPanel = createSlidingPanel("left");
const rightPanel = createSlidingPanel("right");
// -------------------------------------------------------------------------
// Stylized bedroom furniture
// -------------------------------------------------------------------------
addBox(
scene,
[4.55, 0.035, 5.25],
[-1.75, 0.065, 1.05],
mats.rug,
false,
true
);
addBox(
scene,
[4.18, 0.012, 4.88],
[-1.75, 0.087, 1.05],
mats.rugInset,
false,
true
);
// Bed frame and mattress.
addBox(
scene,
[2.85, 0.42, 3.72],
[-2.35, 0.28, 1.15],
mats.bedWood
);
addBox(
scene,
[2.66, 0.44, 3.48],
[-2.35, 0.68, 1.12],
mats.mattress
);
addBox(
scene,
[2.82, 1.55, 0.22],
[-2.35, 1.1, -0.72],
mats.darkWood
);
addBox(
scene,
[2.75, 0.13, 2.25],
[-2.35, 0.94, 1.47],
mats.blanket
);
addBox(
scene,
[2.77, 0.045, 0.58],
[-2.35, 1.025, 0.55],
mats.blanketDark,
false,
true
);
const pillowA = addBox(
scene,
[1.03, 0.24, 0.63],
[-2.93, 0.99, -0.15],
mats.pillow
);
pillowA.rotation.z = -0.055;
const pillowB = addBox(
scene,
[1.03, 0.24, 0.63],
[-1.8, 0.99, -0.15],
mats.pillow
);
pillowB.rotation.z = 0.055;
// Nightstand and lamp.
addBox(
scene,
[0.82, 0.74, 0.72],
[-0.55, 0.48, -0.12],
mats.bedWood
);
addCylinder(
scene,
0.28,
0.34,
0.09,
[-0.55, 0.9, -0.12],
mats.brass
);
addCylinder(
scene,
0.045,
0.045,
0.62,
[-0.55, 1.24, -0.12],
mats.brass,
12
);
const lampShade = new THREE.Mesh(
new THREE.CylinderGeometry(0.25, 0.4, 0.43, 18, 1, true),
new THREE.MeshStandardMaterial({
color: "#f3d6a5",
roughness: 0.9,
side: THREE.DoubleSide
})
);
lampShade.position.set(-0.55, 1.64, -0.12);
lampShade.castShadow = true;
scene.add(lampShade);
// Dresser and decorative objects.
addBox(
scene,
[1.75, 1.15, 0.78],
[3.55, 0.63, 1.85],
mats.bedWood
);
addBox(
scene,
[1.87, 0.1, 0.88],
[3.55, 1.25, 1.85],
mats.darkWood
);
for (let i = 0; i < 3; i++) {
addBox(
scene,
[1.5, 0.025, 0.03],
[3.55, 0.36 + i * 0.32, 2.255],
mats.darkWood,
false,
false
);
}
const vase = addCylinder(
scene,
0.14,
0.2,
0.38,
[3.22, 1.49, 1.82],
material("#6d9692"),
16
);
vase.castShadow = true;
// Framed pictures on the left wall.
for (let i = 0; i < 2; i++) {
addBox(
scene,
[0.08, 1.25, 1.25],
[-5.04, 2.45, -0.65 + i * 1.55],
mats.darkWood
);
addBox(
scene,
[0.025, 1.02, 1.02],
[-4.985, 2.45, -0.65 + i * 1.55],
i === 0 ? material("#b6c2ae") : material("#d5a879"),
false,
false
);
}
// Large indoor plant.
addCylinder(
scene,
0.42,
0.32,
0.65,
[3.8, 0.38, 3.65],
mats.pot,
16
);
addCylinder(
scene,
0.055,
0.075,
1.35,
[3.8, 1.3, 3.65],
mats.trunk,
10
);
const leafPositions = [
[3.45, 1.65, 3.58, 0.42],
[4.08, 1.82, 3.62, 0.47],
[3.7, 2.05, 3.53, 0.39],
[3.56, 1.42, 3.86, 0.34],
[4.02, 1.4, 3.34, 0.35]
];
leafPositions.forEach((p, index) => {
const leaf = addSphere(
scene,
p[3],
[p[0], p[1], p[2]],
index % 2 ? mats.leaf : mats.leafLight,
1
);
leaf.scale.set(0.72, 1.2, 0.58);
leaf.rotation.z = (index - 2) * 0.18;
});
// -------------------------------------------------------------------------
// Exterior courtyard
// -------------------------------------------------------------------------
addBox(
scene,
[15.2, 0.28, 12.8],
[0, -0.25, -11.4],
material("#bca27f"),
false,
true
);
// Courtyard side walls.
addBox(
scene,
[0.42, 5.2, 12.5],
[-7.55, 2.35, -11.4],
mats.courtyard
);
addBox(
scene,
[0.42, 5.2, 12.5],
[7.55, 2.35, -11.4],
mats.courtyard
);
// Back wall with a tall arched opening.
addBox(
scene,
[5.45, 5.2, 0.45],
[-4.875, 2.35, -17.4],
mats.courtyardLight
);
addBox(
scene,
[5.45, 5.2, 0.45],
[4.875, 2.35, -17.4],
mats.courtyardLight
);
const archShape = new THREE.Shape();
archShape.moveTo(-2.1, 5.2);
archShape.lineTo(2.1, 5.2);
archShape.lineTo(2.1, 2.6);
archShape.absarc(0, 2.6, 2.1, 0, Math.PI, false);
archShape.lineTo(-2.1, 5.2);
const archMesh = new THREE.Mesh(
new THREE.ShapeGeometry(archShape),
mats.courtyardLight
);
archMesh.position.set(0, 0, -17.18);
archMesh.receiveShadow = true;
scene.add(archMesh);
// Columns framing the courtyard.
[-5.9, 5.9].forEach((x) => {
addCylinder(
scene,
0.28,
0.32,
4.1,
[x, 2.05, -15.5],
mats.courtyardLight,
16
);
addBox(
scene,
[0.82, 0.24, 0.82],
[x, 0.12, -15.5],
mats.courtyard
);
addBox(
scene,
[0.82, 0.24, 0.82],
[x, 4.05, -15.5],
mats.courtyard
);
});
// Fountain.
addCylinder(
scene,
1.35,
1.5,
0.34,
[0, 0.05, -10.9],
material("#c8aa83"),
28
);
addCylinder(
scene,
1.16,
1.16,
0.035,
[0, 0.235, -10.9],
mats.water,
28,
false
);
addCylinder(
scene,
0.24,
0.38,
1.05,
[0, 0.68, -10.9],
material("#d4bb96"),
18
);
addCylinder(
scene,
0.83,
0.55,
0.2,
[0, 1.23, -10.9],
material("#d9c19d"),
24
);
addCylinder(
scene,
0.67,
0.67,
0.025,
[0, 1.345, -10.9],
mats.water,
24,
false
);
addSphere(scene, 0.11, [0, 1.56, -10.9], mats.water, 1);
// Planter trees.
function addTree(x, z, scale = 1) {
addCylinder(
scene,
0.62 * scale,
0.48 * scale,
0.55 * scale,
[x, 0.17 * scale, z],
material("#b87558"),
14
);
addCylinder(
scene,
0.13 * scale,
0.18 * scale,
2.3 * scale,
[x, 1.4 * scale, z],
mats.trunk,
10
);
const crown = addSphere(
scene,
1.12 * scale,
[x, 2.8 * scale, z],
mats.leaf,
1
);
crown.scale.set(0.9, 1.1, 0.9);
const crown2 = addSphere(
scene,
0.72 * scale,
[x + 0.58 * scale, 2.55 * scale, z + 0.1],
mats.leafLight,
1
);
crown2.scale.set(0.9, 1.05, 0.9);
}
addTree(-4.2, -12.8, 1.08);
addTree(4.4, -13.6, 1.2);
addTree(-5.7, -8.6, 0.72);
// Low shrubs and terracotta pots.
for (let i = 0; i < 5; i++) {
const x = -3.3 + i * 1.65;
const pot = addCylinder(
scene,
0.28,
0.22,
0.42,
[x, 0.12, -7.7],
mats.pot,
12
);
pot.castShadow = true;
addSphere(
scene,
0.42,
[x, 0.65, -7.7],
i % 2 ? mats.leaf : mats.leafLight,
1
).scale.set(1.1, 0.75, 1);
}
// -------------------------------------------------------------------------
// Simulated light patch, derived from the current panel aperture
// -------------------------------------------------------------------------
const patchMaterial = new THREE.MeshBasicMaterial({
color: "#ffd88c",
transparent: true,
opacity: 0.25,
depthWrite: false,
side: THREE.DoubleSide,
blending: THREE.AdditiveBlending
});
const patchGeometry = new THREE.BufferGeometry();
patchGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(new Float32Array(12), 3)
);
patchGeometry.setIndex([0, 1, 2, 0, 2, 3]);
const lightPatch = new THREE.Mesh(patchGeometry, patchMaterial);
lightPatch.frustumCulled = false;
lightPatch.renderOrder = 2;
scene.add(lightPatch);
const lightDirection = new THREE.Vector3()
.subVectors(sun.target.position, sun.position)
.normalize();
function projectToFloor(x, y) {
const t = (0.095 - y) / lightDirection.y;
return new THREE.Vector3(
x + t * lightDirection.x,
0.095,
-4.35 + t * lightDirection.z
);
}
function updateLightPatch(innerLeft, innerRight) {
const gap = innerRight - innerLeft;
if (gap <= 0.025) {
lightPatch.visible = false;
return;
}
lightPatch.visible = true;
const bottomLeft = projectToFloor(innerLeft, WINDOW_BOTTOM + 0.05);
const bottomRight = projectToFloor(innerRight, WINDOW_BOTTOM + 0.05);
const topRight = projectToFloor(innerRight, WINDOW_TOP - 0.05);
const topLeft = projectToFloor(innerLeft, WINDOW_TOP - 0.05);
const vertices = [
bottomLeft.x, bottomLeft.y, bottomLeft.z,
bottomRight.x, bottomRight.y, bottomRight.z,
topRight.x, topRight.y, topRight.z,
topLeft.x, topLeft.y, topLeft.z
];
patchGeometry.attributes.position.array.set(vertices);
patchGeometry.attributes.position.needsUpdate = true;
patchGeometry.computeBoundingSphere();
patchMaterial.opacity = 0.18 + 0.12 * Math.min(1, gap / 2.7);
}
// -------------------------------------------------------------------------
// UI and panel interaction
// -------------------------------------------------------------------------
const leftSlider = document.getElementById("leftPanel");
const rightSlider = document.getElementById("rightPanel");
const leftValue = document.getElementById("leftValue");
const rightValue = document.getElementById("rightValue");
const readout = document.getElementById("readout");
const insetToggle = document.getElementById("insetToggle");
const PANEL_HALF_WIDTH = 1.35;
const PANEL_TRAVEL = 1.35;
function updatePanels() {
const left = Number(leftSlider.value) / 100;
const right = Number(rightSlider.value) / 100;
leftPanel.position.x = -PANEL_HALF_WIDTH - PANEL_TRAVEL * left;
rightPanel.position.x = PANEL_HALF_WIDTH + PANEL_TRAVEL * right;
const innerLeft = leftPanel.position.x + PANEL_HALF_WIDTH;
const innerRight = rightPanel.position.x - PANEL_HALF_WIDTH;
const gap = Math.max(0, innerRight - innerLeft);
leftValue.textContent = `${leftSlider.value}%`;
rightValue.textContent = `${rightSlider.value}%`;
const patchStrength = Math.min(100, Math.round((gap / 2.7) * 100));
readout.textContent =
`Clear aperture: ${gap.toFixed(2)} m · ` +
`floor light: ${patchStrength}% · ` +
`courtyard view changes with the opening.`;
updateLightPatch(innerLeft, innerRight);
}
leftSlider.addEventListener("input", updatePanels);
rightSlider.addEventListener("input", updatePanels);
document.querySelectorAll("[data-preset]").forEach((button) => {
button.addEventListener("click", () => {
const preset = button.dataset.preset;
if (preset === "closed") {
leftSlider.value = 0;
rightSlider.value = 0;
} else if (preset === "open") {
leftSlider.value = 100;
rightSlider.value = 100;
} else {
leftSlider.value = 100;
rightSlider.value = 20;
}
updatePanels();
});
});
updatePanels();
// -------------------------------------------------------------------------
// Camera controls implemented directly without an addon
// -------------------------------------------------------------------------
const orbit = {
theta: 0.62,
phi: 1.18,
radius: 13.7,
target: new THREE.Vector3(0, 1.55, -0.55)
};
const desired = {
theta: orbit.theta,
phi: orbit.phi,
radius: orbit.radius,
target: orbit.target.clone()
};
let dragging = false;
let panning = false;
let previousX = 0;
let previousY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
panning = event.button === 2 || event.shiftKey;
previousX = event.clientX;
previousY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
if (panning) {
const right = new THREE.Vector3(1, 0, 0).applyQuaternion(camera.quaternion);
const up = new THREE.Vector3(0, 1, 0).applyQuaternion(camera.quaternion);
const panScale = desired.radius * 0.00125;
desired.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
desired.target.x = THREE.MathUtils.clamp(desired.target.x, -6, 6);
desired.target.y = THREE.MathUtils.clamp(desired.target.y, 0.2, 4);
desired.target.z = THREE.MathUtils.clamp(desired.target.z, -6, 6);
} else {
desired.theta -= dx * 0.005;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.0045,
0.48,
1.46
);
}
});
function endDrag(event) {
dragging = false;
panning = false;
if (event.pointerId !== undefined && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
7,
21
);
},
{ passive: false }
);
function resetCamera() {
desired.theta = 0.62;
desired.phi = 1.18;
desired.radius = 13.7;
desired.target.set(0, 1.55, -0.55);
}
document.getElementById("resetView").addEventListener("click", resetCamera);
canvas.addEventListener("dblclick", resetCamera);
function updateCamera() {
const smoothing = 0.12;
orbit.theta += (desired.theta - orbit.theta) * smoothing;
orbit.phi += (desired.phi - orbit.phi) * smoothing;
orbit.radius += (desired.radius - orbit.radius) * smoothing;
orbit.target.lerp(desired.target, smoothing);
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
// -------------------------------------------------------------------------
// Inset render viewport for the fixed outside sightline
// -------------------------------------------------------------------------
const insetFrame = document.getElementById("insetFrame");
const insetLabel = document.getElementById("insetLabel");
let insetWidth = 300;
let insetHeight = 185;
let insetX = 0;
let insetY = 0;
function resizeInset() {
insetWidth = window.innerWidth < 650 ? 200 : Math.min(310, window.innerWidth * 0.3);
insetHeight = Math.round(insetWidth * 0.61);
const margin = window.innerWidth < 650 ? 12 : 20;
const top = window.innerWidth < 650 ? 43 : 52;
insetX = window.innerWidth - insetWidth - margin;
insetY = window.innerHeight - insetHeight - top;
insetFrame.style.width = `${insetWidth}px`;
insetFrame.style.height = `${insetHeight}px`;
insetFrame.style.left = `${insetX}px`;
insetFrame.style.top = `${top}px`;
insetFrame.style.right = "auto";
insetFrame.style.bottom = "auto";
insetLabel.style.right = `${margin}px`;
insetLabel.style.top = `${top - 29}px`;
sightlineCamera.aspect = insetWidth / insetHeight;
sightlineCamera.updateProjectionMatrix();
}
function onResize() {
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
resizeInset();
}
window.addEventListener("resize", onResize);
resizeInset();
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
function animate() {
requestAnimationFrame(animate);
updateCamera();
const width = window.innerWidth;
const height = window.innerHeight;
// Main scene.
renderer.setScissorTest(false);
renderer.setViewport(0, 0, width, height);
renderer.clear(true, true, true);
renderer.render(scene, camera);
// Fixed bed-level view showing how the panels block the courtyard.
if (insetToggle.checked) {
insetFrame.style.display = "block";
insetLabel.style.display = "block";
renderer.setScissorTest(true);
renderer.setScissor(insetX, insetY, insetWidth, insetHeight);
renderer.setViewport(insetX, insetY, insetWidth, insetHeight);
renderer.clear(true, true, true);
renderer.render(scene, sightlineCamera);
renderer.setScissorTest(false);
} else {
insetFrame.style.display = "none";
insetLabel.style.display = "none";
}
}
animate();
</script>
</body>
</html>
```