Prompt specification
Build or customize the Three.js 3D scene "Sliding versus hinged door footprint" 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: Sliding versus hinged door footprint
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/sliding-versus-hinged-door-footprint-x0233
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing sliding and hinged doors. Display miniature sliding and hinged doors beside marked floor footprints; opening each reveals the different swept areas while identical doorway widths remain fixed. Stylized solid forms.
Working Three.js Starter (sliding-versus-hinged-door-footprint-x0233):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Door Motion Study</title>
<style>
:root {
--ink: #172c38;
--muted: #60737c;
--paper: rgba(249, 251, 250, 0.9);
--line: rgba(23, 44, 56, 0.12);
--orange: #f47745;
--orange-soft: #fff0e9;
--teal: #159d9a;
--teal-soft: #e8f7f5;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eeef;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
.intro {
position: fixed;
top: 28px;
left: 30px;
z-index: 5;
width: min(440px, calc(100vw - 60px));
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: #526b76;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 3px;
border-radius: 10px;
background: var(--orange);
content: "";
}
h1 {
margin: 0;
max-width: 410px;
font-size: clamp(34px, 4.3vw, 62px);
font-weight: 780;
line-height: 0.98;
letter-spacing: -0.055em;
}
.intro p {
max-width: 380px;
margin: 16px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.6;
}
.fixed-badge {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 18px;
padding: 9px 13px;
border: 1px solid rgba(23, 44, 56, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.62);
color: #405965;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
backdrop-filter: blur(12px);
}
.fixed-badge span {
width: 7px;
height: 7px;
border-radius: 50%;
background: #37aa76;
box-shadow: 0 0 0 4px rgba(55, 170, 118, 0.13);
}
.panel {
position: fixed;
top: 24px;
right: 24px;
z-index: 10;
width: 326px;
padding: 18px;
border: 1px solid rgba(255, 255, 255, 0.68);
border-radius: 22px;
background: var(--paper);
box-shadow:
0 20px 55px rgba(38, 57, 65, 0.12),
0 2px 8px rgba(38, 57, 65, 0.05);
backdrop-filter: blur(18px) saturate(120%);
}
.panel-heading {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
margin-bottom: 15px;
}
.panel-heading strong {
font-size: 13px;
letter-spacing: 0.02em;
}
.text-button {
padding: 0;
border: 0;
background: transparent;
color: #73858d;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 700;
}
.text-button:hover {
color: var(--ink);
}
.door-card {
padding: 14px;
border: 1px solid var(--line);
border-radius: 15px;
background: rgba(255, 255, 255, 0.64);
}
.door-card + .door-card {
margin-top: 10px;
}
.door-card.sliding {
border-left: 4px solid var(--orange);
}
.door-card.hinged {
border-left: 4px solid var(--teal);
}
.door-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
}
.door-name {
display: flex;
align-items: center;
gap: 8px;
font-size: 13px;
font-weight: 780;
}
.door-name small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
font-weight: 600;
letter-spacing: 0.035em;
}
.motion-button {
min-width: 64px;
padding: 7px 11px;
border: 0;
border-radius: 9px;
color: white;
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 800;
transition: transform 150ms ease, filter 150ms ease;
}
.motion-button:hover {
filter: brightness(0.94);
transform: translateY(-1px);
}
.motion-button.sliding {
background: var(--orange);
}
.motion-button.hinged {
background: var(--teal);
}
input[type="range"] {
--pct: 0%;
width: 100%;
height: 5px;
margin: 17px 0 5px;
border-radius: 10px;
outline: none;
appearance: none;
background:
linear-gradient(
to right,
var(--range-color) 0%,
var(--range-color) var(--pct),
#dfe6e7 var(--pct),
#dfe6e7 100%
);
cursor: pointer;
}
input[type="range"].slide-range {
--range-color: var(--orange);
}
input[type="range"].hinge-range {
--range-color: var(--teal);
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
border: 3px solid white;
border-radius: 50%;
appearance: none;
background: var(--range-color);
box-shadow: 0 2px 7px rgba(27, 45, 53, 0.22);
}
input[type="range"]::-moz-range-thumb {
width: 12px;
height: 12px;
border: 3px solid white;
border-radius: 50%;
background: var(--range-color);
box-shadow: 0 2px 7px rgba(27, 45, 53, 0.22);
}
.range-labels {
display: flex;
justify-content: space-between;
color: #8a989e;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.panel-actions button {
padding: 10px;
border: 1px solid var(--line);
border-radius: 10px;
background: rgba(255, 255, 255, 0.75);
color: var(--ink);
cursor: pointer;
font: inherit;
font-size: 11px;
font-weight: 760;
}
.panel-actions button:hover {
background: white;
}
.panel-actions .compare {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.show-area {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-top: 14px;
padding-top: 14px;
border-top: 1px solid var(--line);
color: #536a74;
cursor: pointer;
font-size: 11px;
font-weight: 700;
}
.switch {
position: relative;
width: 34px;
height: 19px;
flex: 0 0 auto;
}
.switch input {
position: absolute;
opacity: 0;
}
.switch-track {
position: absolute;
inset: 0;
border-radius: 20px;
background: #cbd5d8;
transition: background 180ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 13px;
height: 13px;
border-radius: 50%;
background: white;
box-shadow: 0 1px 4px rgba(23, 44, 56, 0.2);
content: "";
transition: transform 180ms ease;
}
.switch input:checked + .switch-track {
background: #37a979;
}
.switch input:checked + .switch-track::after {
transform: translateX(15px);
}
.legend {
position: fixed;
bottom: 25px;
left: 28px;
z-index: 6;
display: flex;
flex-wrap: wrap;
gap: 9px 18px;
max-width: 520px;
padding: 12px 15px;
border: 1px solid rgba(255, 255, 255, 0.6);
border-radius: 14px;
background: rgba(249, 251, 250, 0.78);
box-shadow: 0 8px 30px rgba(35, 56, 65, 0.08);
color: #5f737c;
font-size: 10px;
font-weight: 650;
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-item {
display: flex;
align-items: center;
gap: 7px;
}
.swatch {
width: 18px;
height: 8px;
border-radius: 10px;
}
.swatch.orange {
background: rgba(244, 119, 69, 0.75);
}
.swatch.teal {
background: rgba(21, 157, 154, 0.75);
}
.swatch.dash {
height: 0;
border-top: 2px dashed #647982;
border-radius: 0;
}
.camera-hint {
position: fixed;
right: 26px;
bottom: 25px;
z-index: 6;
color: #71858d;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.02em;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 18px;
left: 18px;
width: calc(100vw - 36px);
}
.intro p,
.fixed-badge {
display: none;
}
h1 {
max-width: 280px;
font-size: 38px;
}
.panel {
top: auto;
right: 12px;
bottom: 12px;
left: 12px;
width: auto;
padding: 13px;
border-radius: 18px;
}
.panel-heading {
margin-bottom: 9px;
}
.door-card {
padding: 10px 11px;
}
.door-card + .door-card {
margin-top: 7px;
}
input[type="range"] {
margin-top: 12px;
}
.legend,
.camera-hint {
display: none;
}
}
</style>
</head>
<body>
<canvas
id="scene"
tabindex="0"
aria-label="Interactive 3D comparison of sliding and hinged miniature doors"
></canvas>
<header class="intro">
<div class="eyebrow">Architectural motion lab</div>
<h1>Two doors.<br />Two clearances.</h1>
<p>
The openings stay exactly the same width. Move each door to compare
its linear sliding path with the quarter-circle swept by a hinged leaf.
</p>
<div class="fixed-badge">
<span></span>
Identical clear opening · 2.30 m
</div>
</header>
<aside class="panel" aria-label="Door controls">
<div class="panel-heading">
<strong>Motion controls</strong>
<button class="text-button" id="resetView" type="button">Reset view</button>
</div>
<section class="door-card sliding">
<div class="door-row">
<div class="door-name">
<div>
Sliding door
<small>Linear travel / parallel track</small>
</div>
</div>
<button class="motion-button sliding" id="slideToggle" type="button">
Open
</button>
</div>
<input
class="slide-range"
id="slideRange"
type="range"
min="0"
max="100"
value="0"
aria-label="Sliding door opening"
/>
<div class="range-labels">
<span>Closed</span>
<span>Fully open</span>
</div>
</section>
<section class="door-card hinged">
<div class="door-row">
<div class="door-name">
<div>
Hinged door
<small>90° rotation / radial sweep</small>
</div>
</div>
<button class="motion-button hinged" id="hingeToggle" type="button">
Open
</button>
</div>
<input
class="hinge-range"
id="hingeRange"
type="range"
min="0"
max="100"
value="0"
aria-label="Hinged door opening"
/>
<div class="range-labels">
<span>Closed</span>
<span>Fully open</span>
</div>
</section>
<div class="panel-actions">
<button class="compare" id="openBoth" type="button">Compare open</button>
<button id="resetDoors" type="button">Reset doors</button>
</div>
<label class="show-area">
Show swept areas
<span class="switch">
<input id="showSweeps" type="checkbox" checked />
<span class="switch-track"></span>
</span>
</label>
</aside>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch orange"></span>
Sliding travel
</div>
<div class="legend-item">
<span class="swatch teal"></span>
Hinged sweep
</div>
<div class="legend-item">
<span class="swatch dash"></span>
Closed / open footprints
</div>
</div>
<div class="camera-hint">Drag to orbit · Shift-drag to pan · Scroll to zoom</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eeef);
scene.fog = new THREE.Fog(0xe9eeef, 24, 48);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
const hemisphere = new THREE.HemisphereLight(0xf8fcff, 0x84939a, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff4e8, 3.3);
keyLight.position.set(-7, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -14;
keyLight.shadow.camera.right = 14;
keyLight.shadow.camera.top = 13;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc9f4f2, 1.0);
fillLight.position.set(9, 7, -7);
scene.add(fillLight);
const warmLight = new THREE.PointLight(0xffc9a8, 18, 22, 2);
warmLight.position.set(-4, 5, 4);
scene.add(warmLight);
// -------------------------------------------------------------------------
// Shared dimensions and materials
// -------------------------------------------------------------------------
const DOOR_WIDTH = 2.3;
const DOOR_HEIGHT = 3.05;
const BASE_TOP = 0.26;
const WALL_Z = -0.35;
const DOOR_Z = -0.055;
const STATION_X = 3.55;
const material = {
ground: new THREE.MeshStandardMaterial({
color: 0xe5ebeb,
roughness: 0.95,
metalness: 0
}),
base: new THREE.MeshStandardMaterial({
color: 0xd7d0c4,
roughness: 0.88,
metalness: 0
}),
floor: new THREE.MeshStandardMaterial({
color: 0xf3f0e8,
roughness: 0.92,
metalness: 0
}),
wall: new THREE.MeshStandardMaterial({
color: 0xf5f0e6,
roughness: 0.82,
metalness: 0
}),
wallSide: new THREE.MeshStandardMaterial({
color: 0xe5ddd0,
roughness: 0.86,
metalness: 0
}),
frame: new THREE.MeshStandardMaterial({
color: 0x263b45,
roughness: 0.58,
metalness: 0.12
}),
sliding: new THREE.MeshStandardMaterial({
color: 0xf47745,
roughness: 0.48,
metalness: 0.05
}),
slidingInset: new THREE.MeshStandardMaterial({
color: 0xff9166,
roughness: 0.54,
metalness: 0
}),
hinged: new THREE.MeshStandardMaterial({
color: 0x159d9a,
roughness: 0.48,
metalness: 0.05
}),
hingedInset: new THREE.MeshStandardMaterial({
color: 0x39b6b1,
roughness: 0.54,
metalness: 0
}),
orange: new THREE.Color(0xf47745),
teal: new THREE.Color(0x159d9a),
footprint: new THREE.Color(0x506b76)
};
// -------------------------------------------------------------------------
// Geometry helpers
// -------------------------------------------------------------------------
function addBox(parent, width, height, depth, mat, x, y, z, cast = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
mat
);
mesh.position.set(x, y, z);
mesh.castShadow = cast;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addCylinder(
parent,
radius,
height,
mat,
x,
y,
z,
rotation = null
) {
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, height, 20),
mat
);
mesh.position.set(x, y, z);
if (rotation) mesh.rotation.set(...rotation);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeDashedLine(parent, points, color, opacity = 0.65, dashed = true) {
const geometry = new THREE.BufferGeometry().setFromPoints(
points.map((point) => new THREE.Vector3(...point))
);
const lineMaterial = dashed
? new THREE.LineDashedMaterial({
color,
transparent: true,
opacity,
dashSize: 0.13,
gapSize: 0.09,
depthWrite: false
})
: new THREE.LineBasicMaterial({
color,
transparent: true,
opacity,
depthWrite: false
});
const line = new THREE.Line(geometry, lineMaterial);
if (dashed) line.computeLineDistances();
line.renderOrder = 3;
parent.add(line);
return line;
}
function rectanglePoints(x1, x2, z1, z2, y = BASE_TOP + 0.025) {
return [
[x1, y, z1],
[x2, y, z1],
[x2, y, z2],
[x1, y, z2],
[x1, y, z1]
];
}
function makeLabelSprite(title, subtitle, accent, width = 2.45) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 256;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 1024, 256);
const accentColor = `#${accent.getHexString()}`;
context.fillStyle = "rgba(25, 43, 52, 0.94)";
context.beginPath();
context.roundRect(12, 18, 1000, 220, 42);
context.fill();
context.fillStyle = accentColor;
context.beginPath();
context.roundRect(40, 52, 14, 152, 7);
context.fill();
context.fillStyle = "#ffffff";
context.font = "800 64px system-ui, sans-serif";
context.textBaseline = "middle";
context.fillText(title, 86, 91);
context.fillStyle = "rgba(255,255,255,0.67)";
context.font = "600 34px system-ui, sans-serif";
context.fillText(subtitle, 87, 160);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(width, width * 0.25, 1);
sprite.renderOrder = 20;
return sprite;
}
function makeSmallLabel(text, color = "#526b76") {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 512;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 512, 128);
context.fillStyle = "rgba(255,255,255,0.82)";
context.beginPath();
context.roundRect(8, 12, 496, 104, 28);
context.fill();
context.strokeStyle = "rgba(52,75,86,0.18)";
context.lineWidth = 3;
context.stroke();
context.fillStyle = color;
context.font = "800 36px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 256, 65);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
})
);
sprite.scale.set(1.35, 0.34, 1);
sprite.renderOrder = 15;
return sprite;
}
function makeFloorLabel(text, width, x, z, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 1024;
labelCanvas.height = 160;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 1024, 160);
context.fillStyle = "rgba(255,255,255,0.8)";
context.beginPath();
context.roundRect(10, 15, 1004, 130, 32);
context.fill();
context.fillStyle = `#${accent.getHexString()}`;
context.beginPath();
context.roundRect(35, 44, 14, 72, 7);
context.fill();
context.fillStyle = "#314b57";
context.font = "800 44px system-ui, sans-serif";
context.textBaseline = "middle";
context.fillText(text, 78, 82);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(
8,
renderer.capabilities.getMaxAnisotropy()
);
const mesh = new THREE.Mesh(
new THREE.PlaneGeometry(width, width * 0.15625),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
side: THREE.DoubleSide
})
);
mesh.rotation.x = -Math.PI / 2;
mesh.position.set(x, BASE_TOP + 0.033, z);
mesh.renderOrder = 5;
return mesh;
}
function makeSectorGeometry(radius, steps = 48) {
const positions = [0, 0, 0];
const indices = [];
for (let i = 0; i <= steps; i++) {
const angle = (i / steps) * Math.PI * 0.5;
positions.push(
Math.cos(angle) * radius,
0,
Math.sin(angle) * radius
);
if (i < steps) {
indices.push(0, i + 1, i + 2);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// -------------------------------------------------------------------------
// Ground and display platforms
// -------------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(60, 60),
material.ground
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.025;
ground.receiveShadow = true;
scene.add(ground);
function createPlatform(x, accent) {
const group = new THREE.Group();
group.position.x = x;
addBox(group, 6.8, 0.26, 5.4, material.base, 0, 0.13, 0.65);
addBox(
group,
6.62,
0.025,
5.22,
material.floor,
0,
BASE_TOP + 0.005,
0.65,
false
);
addBox(
group,
6.8,
0.065,
0.075,
new THREE.MeshStandardMaterial({
color: accent,
roughness: 0.55
}),
0,
0.17,
3.35,
false
);
scene.add(group);
return group;
}
const slidingStation = createPlatform(-STATION_X, material.orange);
const hingedStation = createPlatform(STATION_X, material.teal);
// -------------------------------------------------------------------------
// Fixed wall, frame, and dimension graphics
// -------------------------------------------------------------------------
function createWallAndFrame(station, accent) {
const wallHeight = 3.55;
const wallCenterY = BASE_TOP + wallHeight / 2;
const outer = 3.35;
const openingHalf = DOOR_WIDTH / 2;
const postWidth = 0.14;
const leftInner = -openingHalf - postWidth;
const rightInner = openingHalf + postWidth;
addBox(
station,
Math.abs(leftInner - outer),
wallHeight,
0.26,
material.wall,
(leftInner + outer) / 2,
wallCenterY,
WALL_Z
);
addBox(
station,
Math.abs(outer - rightInner),
wallHeight,
0.26,
material.wall,
(rightInner + outer) / 2,
wallCenterY,
WALL_Z
);
addBox(
station,
DOOR_WIDTH + postWidth * 2,
0.49,
0.26,
material.wall,
0,
BASE_TOP + DOOR_HEIGHT + 0.245,
WALL_Z
);
// A subtle side cap gives the solid wall a crafted, miniature-model feel.
addBox(
station,
0.08,
wallHeight,
0.31,
material.wallSide,
outer,
wallCenterY,
WALL_Z
);
// Fixed jambs: their inner faces are exactly DOOR_WIDTH apart.
addBox(
station,
postWidth,
DOOR_HEIGHT + 0.15,
0.36,
material.frame,
-openingHalf - postWidth / 2,
BASE_TOP + (DOOR_HEIGHT + 0.15) / 2,
-0.26
);
addBox(
station,
postWidth,
DOOR_HEIGHT + 0.15,
0.36,
material.frame,
openingHalf + postWidth / 2,
BASE_TOP + (DOOR_HEIGHT + 0.15) / 2,
-0.26
);
addBox(
station,
DOOR_WIDTH + postWidth * 2 + 0.06,
0.16,
0.36,
material.frame,
0,
BASE_TOP + DOOR_HEIGHT + 0.1,
-0.26
);
// Fixed dimension line.
const dimensionY = 4.03;
const dimensionZ = 0.04;
makeDashedLine(
station,
[
[-openingHalf, dimensionY, dimensionZ],
[openingHalf, dimensionY, dimensionZ]
],
0x405b66,
0.78,
false
);
for (const x of [-openingHalf, openingHalf]) {
makeDashedLine(
station,
[
[x, dimensionY - 0.13, dimensionZ],
[x, dimensionY + 0.13, dimensionZ]
],
0x405b66,
0.78,
false
);
}
const dimensionLabel = makeLabelSprite(
"2.30 m",
"FIXED CLEAR OPENING",
accent,
2.4
);
dimensionLabel.position.set(0, 4.18, dimensionZ);
station.add(dimensionLabel);
}
createWallAndFrame(slidingStation, material.orange);
createWallAndFrame(hingedStation, material.teal);
// -------------------------------------------------------------------------
// Sliding door
// -------------------------------------------------------------------------
const slidingDoor = new THREE.Group();
slidingDoor.position.set(0, BASE_TOP + DOOR_HEIGHT / 2, DOOR_Z);
slidingStation.add(slidingDoor);
addBox(
slidingDoor,
DOOR_WIDTH,
DOOR_HEIGHT,
0.14,
material.sliding,
0,
0,
0
);
addBox(
slidingDoor,
DOOR_WIDTH - 0.28,
DOOR_HEIGHT - 0.3,
0.035,
material.slidingInset,
0,
0,
0.087
);
addBox(
slidingDoor,
0.065,
0.42,
0.12,
material.frame,
DOOR_WIDTH / 2 - 0.23,
-0.05,
0.15
);
// Rail extends beyond the fixed opening to show the full travel direction.
addBox(
slidingStation,
4.85,
0.11,
0.2,
material.frame,
-1.12,
BASE_TOP + DOOR_HEIGHT + 0.12,
-0.05
);
for (const x of [-DOOR_WIDTH * 0.34, DOOR_WIDTH * 0.34]) {
addBox(
slidingDoor,
0.11,
0.17,
0.12,
material.frame,
x,
DOOR_HEIGHT / 2 + 0.09,
-0.035
);
}
// Sliding swept-area graphics.
const slidingSweepGroup = new THREE.Group();
slidingStation.add(slidingSweepGroup);
const slidingFullMaterial = new THREE.MeshBasicMaterial({
color: material.orange,
transparent: true,
opacity: 0.09,
depthWrite: false,
side: THREE.DoubleSide
});
const slidingFull = new THREE.Mesh(
new THREE.PlaneGeometry(DOOR_WIDTH * 2, 0.7),
slidingFullMaterial
);
slidingFull.rotation.x = -Math.PI / 2;
slidingFull.position.set(-DOOR_WIDTH / 2, BASE_TOP + 0.018, -0.02);
slidingSweepGroup.add(slidingFull);
const slidingActiveMaterial = new THREE.MeshBasicMaterial({
color: material.orange,
transparent: true,
opacity: 0.28,
depthWrite: false,
side: THREE.DoubleSide
});
const slidingActive = new THREE.Mesh(
new THREE.PlaneGeometry(1, 0.7),
slidingActiveMaterial
);
slidingActive.rotation.x = -Math.PI / 2;
slidingActive.position.set(
0,
BASE_TOP + 0.022,
-0.02
);
slidingSweepGroup.add(slidingActive);
makeDashedLine(
slidingSweepGroup,
rectanglePoints(
-DOOR_WIDTH * 1.5,
DOOR_WIDTH * 0.5,
-0.37,
0.33,
BASE_TOP + 0.031
),
material.orange,
0.62
);
// Closed and open leaf footprints.
makeDashedLine(
slidingStation,
rectanglePoints(
-DOOR_WIDTH / 2,
DOOR_WIDTH / 2,
-0.12,
0.01,
BASE_TOP + 0.036
),
material.footprint,
0.62
);
makeDashedLine(
slidingStation,
rectanglePoints(
-DOOR_WIDTH * 1.5,
-DOOR_WIDTH / 2,
-0.12,
0.01,
BASE_TOP + 0.039
),
material.footprint,
0.62
);
const slideArrow = new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(0.74, BASE_TOP + 0.05, 0.46),
1.25,
material.orange,
0.2,
0.12
);
slidingSweepGroup.add(slideArrow);
const slidingFloorLabel = makeFloorLabel(
"LINEAR TRAVEL · 2.30 m",
3.25,
-1.2,
1.08,
material.orange
);
slidingStation.add(slidingFloorLabel);
const slidingClosedLabel = makeSmallLabel("CLOSED", "#e36b3e");
slidingClosedLabel.position.set(0, BASE_TOP + 0.18, -0.66);
slidingStation.add(slidingClosedLabel);
const slidingOpenLabel = makeSmallLabel("OPEN", "#e36b3e");
slidingOpenLabel.position.set(-2.3, BASE_TOP + 0.18, -0.66);
slidingStation.add(slidingOpenLabel);
const slidingTitle = makeLabelSprite(
"01 SLIDING",
"PARALLEL LEAF / LINEAR PATH",
material.orange,
2.75
);
slidingTitle.position.set(0, 4.68, -0.04);
slidingStation.add(slidingTitle);
// -------------------------------------------------------------------------
// Hinged door
// -------------------------------------------------------------------------
const hingedDoor = new THREE.Group();
hingedDoor.position.set(
-DOOR_WIDTH / 2,
BASE_TOP + DOOR_HEIGHT / 2,
DOOR_Z
);
hingedStation.add(hingedDoor);
const hingedLeaf = new THREE.Group();
hingedLeaf.position.x = DOOR_WIDTH / 2;
hingedDoor.add(hingedLeaf);
addBox(
hingedLeaf,
DOOR_WIDTH,
DOOR_HEIGHT,
0.14,
material.hinged,
0,
0,
0
);
addBox(
hingedLeaf,
DOOR_WIDTH - 0.28,
DOOR_HEIGHT - 0.3,
0.035,
material.hingedInset,
0,
0,
0.087
);
addBox(
hingedLeaf,
0.065,
0.42,
0.12,
material.frame,
DOOR_WIDTH / 2 - 0.23,
-0.05,
0.15
);
// Visible hinge barrels.
for (const y of [0.72, 2.35]) {
addCylinder(
hingedStation,
0.075,
0.25,
material.frame,
-DOOR_WIDTH / 2,
BASE_TOP + y,
DOOR_Z,
[0, 0, 0]
);
}
// Hinged swept-area graphics.
const hingedSweepGroup = new THREE.Group();
hingedStation.add(hingedSweepGroup);
const sectorGeometry = makeSectorGeometry(DOOR_WIDTH, 48);
sectorGeometry.translate(-DOOR_WIDTH / 2, 0, DOOR_Z);
const hingedFullMaterial = new THREE.MeshBasicMaterial({
color: material.teal,
transparent: true,
opacity: 0.085,
depthWrite: false,
side: THREE.DoubleSide
});
const hingedFull = new THREE.Mesh(
sectorGeometry,
hingedFullMaterial
);
hingedFull.position.y = BASE_TOP + 0.018;
hingedSweepGroup.add(hingedFull);
const activeSectorGeometry = makeSectorGeometry(DOOR_WIDTH, 48);
activeSectorGeometry.translate(-DOOR_WIDTH / 2, 0, DOOR_Z);
activeSectorGeometry.setDrawRange(0, 0);
const hingedActiveMaterial = new THREE.MeshBasicMaterial({
color: material.teal,
transparent: true,
opacity: 0.3,
depthWrite: false,
side: THREE.DoubleSide
});
const hingedActive = new THREE.Mesh(
activeSectorGeometry,
hingedActiveMaterial
);
hingedActive.position.y = BASE_TOP + 0.024;
hingedSweepGroup.add(hingedActive);
const arcPoints = [];
for (let i = 0; i <= 64; i++) {
const angle = (i / 64) * Math.PI * 0.5;
arcPoints.push([
-DOOR_WIDTH / 2 + Math.cos(angle) * DOOR_WIDTH,
BASE_TOP + 0.034,
DOOR_Z + Math.sin(angle) * DOOR_WIDTH
]);
}
makeDashedLine(
hingedSweepGroup,
arcPoints,
material.teal,
0.72
);
makeDashedLine(
hingedSweepGroup,
[
[-DOOR_WIDTH / 2, BASE_TOP + 0.034, DOOR_Z],
[-DOOR_WIDTH / 2, BASE_TOP + 0.034, DOOR_Z + DOOR_WIDTH]
],
material.teal,
0.58
);
// Closed and open leaf footprints.
makeDashedLine(
hingedStation,
rectanglePoints(
-DOOR_WIDTH / 2,
DOOR_WIDTH / 2,
-0.13,
0.0,
BASE_TOP + 0.036
),
material.footprint,
0.62
);
makeDashedLine(
hingedStation,
rectanglePoints(
-DOOR_WIDTH / 2 - 0.065,
-DOOR_WIDTH / 2 + 0.065,
DOOR_Z,
DOOR_Z + DOOR_WIDTH,
BASE_TOP + 0.039
),
material.footprint,
0.62
);
const hingeArrow = new THREE.ArrowHelper(
new THREE.Vector3(-Math.sin(Math.PI / 3), 0, Math.cos(Math.PI / 3)),
new THREE.Vector3(
-DOOR_WIDTH / 2 + Math.cos(Math.PI / 3) * DOOR_WIDTH,
BASE_TOP + 0.055,
DOOR_Z + Math.sin(Math.PI / 3) * DOOR_WIDTH
),
0.72,
material.teal,
0.18,
0.11
);
hingedSweepGroup.add(hingeArrow);
const hingedFloorLabel = makeFloorLabel(
"90° SWEEP · R = 2.30 m",
3.3,
0.68,
1.55,
material.teal
);
hingedStation.add(hingedFloorLabel);
const hingeClosedLabel = makeSmallLabel("CLOSED", "#168f8c");
hingeClosedLabel.position.set(0, BASE_TOP + 0.18, -0.66);
hingedStation.add(hingeClosedLabel);
const hingeOpenLabel = makeSmallLabel("OPEN", "#168f8c");
hingeOpenLabel.position.set(-1.72, BASE_TOP + 0.18, 1.35);
hingedStation.add(hingeOpenLabel);
const hingedTitle = makeLabelSprite(
"02 HINGED",
"ROTATING LEAF / RADIAL PATH",
material.teal,
2.75
);
hingedTitle.position.set(0, 4.68, -0.04);
hingedStation.add(hingedTitle);
// -------------------------------------------------------------------------
// Interaction state
// -------------------------------------------------------------------------
const state = {
slide: 0,
slideTarget: 0,
hinge: 0,
hingeTarget: 0,
showSweeps: true
};
const slideRange = document.querySelector("#slideRange");
const hingeRange = document.querySelector("#hingeRange");
const slideToggle = document.querySelector("#slideToggle");
const hingeToggle = document.querySelector("#hingeToggle");
const showSweeps = document.querySelector("#showSweeps");
function updateRange(range, value) {
range.value = Math.round(value * 100);
range.style.setProperty("--pct", `${Math.round(value * 100)}%`);
}
function updateToggle(button, value) {
button.textContent = value < 0.5 ? "Open" : "Close";
}
function setSlide(value) {
state.slideTarget = THREE.MathUtils.clamp(value, 0, 1);
updateRange(slideRange, state.slideTarget);
updateToggle(slideToggle, state.slideTarget);
}
function setHinge(value) {
state.hingeTarget = THREE.MathUtils.clamp(value, 0, 1);
updateRange(hingeRange, state.hingeTarget);
updateToggle(hingeToggle, state.hingeTarget);
}
slideRange.addEventListener("input", () => {
setSlide(Number(slideRange.value) / 100);
});
hingeRange.addEventListener("input", () => {
setHinge(Number(hingeRange.value) / 100);
});
slideToggle.addEventListener("click", () => {
setSlide(state.slideTarget < 0.5 ? 1 : 0);
});
hingeToggle.addEventListener("click", () => {
setHinge(state.hingeTarget < 0.5 ? 1 : 0);
});
document.querySelector("#openBoth").addEventListener("click", () => {
setSlide(1);
setHinge(1);
});
document.querySelector("#resetDoors").addEventListener("click", () => {
setSlide(0);
setHinge(0);
});
showSweeps.addEventListener("change", () => {
state.showSweeps = showSweeps.checked;
slidingSweepGroup.visible = state.showSweeps;
hingedSweepGroup.visible = state.showSweeps;
});
updateRange(slideRange, 0);
updateRange(hingeRange, 0);
// -------------------------------------------------------------------------
// Direct camera controls: orbit, pan, wheel zoom, and touch pinch
// -------------------------------------------------------------------------
const cameraTarget = new THREE.Vector3(0, 1.65, 0.55);
let cameraYaw = 0.62;
let cameraPitch = 0.56;
let cameraRadius = 15.8;
const defaultCamera = {
target: cameraTarget.clone(),
yaw: cameraYaw,
pitch: cameraPitch,
radius: cameraRadius
};
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraRadius;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraRadius,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
document.querySelector("#resetView").addEventListener("click", () => {
cameraTarget.copy(defaultCamera.target);
cameraYaw = defaultCamera.yaw;
cameraPitch = defaultCamera.pitch;
cameraRadius = defaultCamera.radius;
updateCamera();
});
const pointers = new Map();
let lastPinchDistance = 0;
let activePointer = null;
let lastX = 0;
let lastY = 0;
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
activePointer = event.pointerId;
lastX = event.clientX;
lastY = event.clientY;
} else if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1 && event.pointerId === activePointer) {
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
const wantsPan = event.shiftKey || event.buttons === 2;
if (wantsPan) {
updateCamera();
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0)
.normalize();
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1)
.normalize();
const panScale = cameraRadius * 0.00125;
cameraTarget.addScaledVector(right, -dx * panScale);
cameraTarget.addScaledVector(up, dy * panScale);
} else {
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.005,
0.18,
1.24
);
}
} else if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * (lastPinchDistance / distance),
8,
28
);
}
lastPinchDistance = distance;
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
if (event.pointerId === activePointer) {
activePointer = null;
}
if (pointers.size < 2) {
lastPinchDistance = 0;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius * Math.exp(event.deltaY * 0.001),
8,
28
);
updateCamera();
},
{ passive: false }
);
updateCamera();
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
const smoothing = 1 - Math.exp(-7 * dt);
state.slide += (state.slideTarget - state.slide) * smoothing;
state.hinge += (state.hingeTarget - state.hinge) * smoothing;
// Sliding leaf moves in a straight line.
slidingDoor.position.x = -DOOR_WIDTH * state.slide;
// Hinged leaf rotates around its fixed hinge.
hingedDoor.rotation.y = -Math.PI * 0.5 * state.hinge;
// Reveal only the swept portion traveled so far.
slidingActive.scale.x = DOOR_WIDTH * (1 + state.slide);
slidingActive.position.x = -DOOR_WIDTH * state.slide * 0.5;
const sectorSteps = 48;
const visibleTriangles = Math.floor(sectorSteps * state.hinge);
activeSectorGeometry.setDrawRange(0, visibleTriangles * 3);
const sweepPulse = 0.96 + Math.sin(performance.now() * 0.002) * 0.04;
slidingFullMaterial.opacity = 0.065 * sweepPulse;
slidingActiveMaterial.opacity = 0.24 + state.slide * 0.12;
hingedFullMaterial.opacity = 0.055 * sweepPulse;
hingedActiveMaterial.opacity = 0.23 + state.hinge * 0.13;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
animate();
// -------------------------------------------------------------------------
// Resize
// -------------------------------------------------------------------------
function handleResize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.fov = width < 760 ? 48 : 38;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", handleResize);
handleResize();
</script>
</body>
</html>
```