Prompt specification
Build or customize the Three.js 3D scene "Adjust an entrance within a fixed 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: Adjust an entrance within a fixed footprint
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/adjust-an-entrance-within-a-fixed-footprint-x2224
Scene Description Prompt:
Create a standalone low-poly scene in one HTML file using Three.js from cdnjs. Let users change ramp length and landing position inside a bounded site. Update slope and turning-space indicators, labeling all constraints as teaching parameters rather than compliance advice.
Working Three.js Starter (adjust-an-entrance-within-a-fixed-footprint-x2224):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ramp Geometry Lab — Teaching Model</title>
<style>
:root {
--ink: #24332f;
--muted: #66756f;
--paper: #f4f1e8;
--panel: #fffdf7;
--line: #d9ded5;
--green: #28766d;
--green-light: #dcece7;
--orange: #cc7048;
--orange-light: #f6e4d9;
--amber: #a86b20;
--shadow: 0 12px 40px rgba(31, 48, 43, 0.11);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
}
body {
overflow: hidden;
background: #dfe7e3;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button,
input {
font: inherit;
}
#app {
display: grid;
grid-template-columns: 340px minmax(0, 1fr);
width: 100%;
height: 100%;
}
aside {
position: relative;
z-index: 5;
overflow-y: auto;
padding: 25px 23px 20px;
background: var(--paper);
border-right: 1px solid rgba(44, 69, 61, 0.12);
box-shadow: var(--shadow);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 20px;
}
.brand-mark {
position: relative;
width: 42px;
height: 42px;
flex: 0 0 auto;
border-radius: 12px;
background: var(--ink);
overflow: hidden;
}
.brand-mark::before {
content: "";
position: absolute;
left: 7px;
bottom: 8px;
width: 29px;
height: 11px;
background: var(--orange);
clip-path: polygon(0 100%, 100% 0, 100% 100%);
}
.brand-mark::after {
content: "";
position: absolute;
right: 7px;
bottom: 8px;
width: 12px;
height: 8px;
background: #75b7aa;
}
.eyebrow {
margin: 0 0 3px;
color: var(--green);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: 23px;
line-height: 1.08;
letter-spacing: -0.035em;
}
.intro {
margin: 0 0 16px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.notice {
display: flex;
gap: 10px;
margin: 0 0 22px;
padding: 11px 12px;
border: 1px solid #d8c9a8;
border-radius: 10px;
background: #fff7df;
color: #735827;
font-size: 11px;
line-height: 1.45;
}
.notice strong {
display: block;
margin-bottom: 2px;
}
.notice-icon {
display: grid;
width: 20px;
height: 20px;
flex: 0 0 auto;
place-items: center;
border: 1px solid currentColor;
border-radius: 50%;
font-size: 11px;
font-weight: 800;
}
.section-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
margin: 0 0 15px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.section-title::after {
content: "";
height: 1px;
flex: 1;
background: var(--line);
}
.control {
margin-bottom: 21px;
}
.control-head {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 10px;
margin-bottom: 9px;
}
.control label {
font-size: 13px;
font-weight: 750;
}
output {
color: var(--green);
font-size: 13px;
font-weight: 800;
font-variant-numeric: tabular-nums;
}
input[type="range"] {
--fill: 50%;
width: 100%;
height: 5px;
margin: 7px 0 8px;
appearance: none;
border-radius: 999px;
background: linear-gradient(
to right,
var(--green) 0 var(--fill),
#d9dfd9 var(--fill) 100%
);
cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
width: 17px;
height: 17px;
appearance: none;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 1px var(--green), 0 2px 5px rgba(30, 70, 61, 0.2);
}
input[type="range"]::-moz-range-thumb {
width: 13px;
height: 13px;
border: 3px solid var(--panel);
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 1px var(--green);
}
.range-ends {
display: flex;
justify-content: space-between;
color: #83908b;
font-size: 10px;
}
.control-note {
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.45;
}
.metrics {
display: grid;
gap: 11px;
margin-top: 8px;
}
.metric {
padding: 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
}
.metric-heading {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 11px;
color: var(--muted);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.metric-heading span:last-child {
color: #8a9892;
font-size: 8px;
letter-spacing: 0.08em;
}
.metric-main {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
}
.big-value {
font-size: 29px;
font-weight: 780;
line-height: 1;
letter-spacing: -0.045em;
font-variant-numeric: tabular-nums;
}
.big-value small {
margin-left: 4px;
color: var(--muted);
font-size: 11px;
font-weight: 650;
letter-spacing: 0;
}
.slope-visual {
position: relative;
width: 78px;
height: 39px;
flex: 0 0 auto;
}
.slope-base {
position: absolute;
right: 0;
bottom: 7px;
left: 0;
height: 1px;
background: #aeb8b3;
}
.slope-line {
position: absolute;
bottom: 7px;
left: 7px;
width: 61px;
height: 4px;
border-radius: 2px;
transform: rotate(-10deg);
transform-origin: left center;
background: var(--orange);
}
.slope-line::after {
content: "";
position: absolute;
right: -2px;
top: -4px;
border-top: 6px solid transparent;
border-bottom: 6px solid transparent;
border-left: 9px solid var(--orange);
}
.detail-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 13px;
padding-top: 11px;
border-top: 1px solid #e5e8e2;
}
.detail-grid > div {
min-width: 0;
}
.detail-grid span {
display: block;
margin-bottom: 3px;
color: #83908b;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.detail-grid strong {
display: block;
overflow: hidden;
font-size: 11px;
text-overflow: ellipsis;
white-space: nowrap;
font-variant-numeric: tabular-nums;
}
.turn-title {
display: flex;
align-items: center;
gap: 11px;
}
.turn-icon {
position: relative;
width: 43px;
height: 43px;
flex: 0 0 auto;
border: 1px dashed var(--green);
border-radius: 50%;
background: var(--green-light);
}
.turn-icon::before,
.turn-icon::after {
content: "";
position: absolute;
top: 50%;
left: 50%;
background: rgba(40, 118, 109, 0.5);
transform: translate(-50%, -50%);
}
.turn-icon::before {
width: 25px;
height: 1px;
}
.turn-icon::after {
width: 1px;
height: 25px;
}
.state {
display: inline-flex;
align-items: center;
gap: 6px;
margin-top: 11px;
padding: 6px 8px;
border-radius: 7px;
background: var(--green-light);
color: var(--green);
font-size: 9px;
font-weight: 750;
line-height: 1.3;
}
.state::before {
content: "";
width: 6px;
height: 6px;
flex: 0 0 auto;
border-radius: 50%;
background: currentColor;
}
.metric[data-state="over"] .state {
background: var(--orange-light);
color: var(--amber);
}
.metric[data-state="over"] .turn-icon {
border-color: var(--amber);
background: var(--orange-light);
}
.site-facts {
display: grid;
gap: 7px;
margin-top: 11px;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.site-facts div {
display: flex;
justify-content: space-between;
gap: 12px;
}
.site-facts strong {
color: var(--ink);
font-variant-numeric: tabular-nums;
}
.actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 16px;
}
.button {
min-height: 38px;
padding: 8px 10px;
border: 1px solid #ccd5cf;
border-radius: 9px;
background: transparent;
color: var(--ink);
font-size: 11px;
font-weight: 750;
cursor: pointer;
transition: background 120ms ease, transform 120ms ease;
}
.button:hover {
background: #e8ede7;
}
.button:active {
transform: translateY(1px);
}
.button.primary {
border-color: var(--ink);
background: var(--ink);
color: white;
}
.button.primary:hover {
background: #344943;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
margin-top: 17px;
color: var(--muted);
font-size: 9px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 5px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 2px;
}
.footer-note {
margin: 17px 0 0;
padding-top: 14px;
border-top: 1px solid var(--line);
color: #7b8983;
font-size: 9px;
line-height: 1.5;
}
main {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #dfe7e3;
}
canvas {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.scene-title {
position: absolute;
z-index: 3;
top: 20px;
left: 22px;
pointer-events: none;
}
.scene-title strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
letter-spacing: -0.01em;
}
.scene-title span {
color: #687972;
font-size: 10px;
}
.view-controls {
position: absolute;
z-index: 4;
top: 18px;
right: 18px;
display: flex;
gap: 6px;
padding: 5px;
border: 1px solid rgba(64, 87, 78, 0.13);
border-radius: 10px;
background: rgba(255, 253, 247, 0.84);
box-shadow: 0 5px 18px rgba(45, 65, 58, 0.08);
backdrop-filter: blur(8px);
}
.view-controls button {
padding: 7px 10px;
border: 0;
border-radius: 7px;
background: transparent;
color: var(--muted);
font-size: 10px;
font-weight: 750;
cursor: pointer;
}
.view-controls button.active {
background: var(--ink);
color: white;
}
.scene-hint {
position: absolute;
z-index: 3;
right: 18px;
bottom: 16px;
padding: 7px 10px;
border-radius: 8px;
background: rgba(255, 253, 247, 0.78);
color: #64736d;
font-size: 9px;
pointer-events: none;
backdrop-filter: blur(8px);
}
#labels {
position: absolute;
z-index: 2;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 90px;
max-width: 190px;
padding: 7px 9px;
border: 1px solid rgba(50, 77, 68, 0.14);
border-radius: 8px;
background: rgba(255, 253, 247, 0.91);
box-shadow: 0 4px 14px rgba(38, 56, 50, 0.09);
color: var(--ink);
text-align: center;
transform: translate(-50%, -100%);
white-space: nowrap;
backdrop-filter: blur(6px);
}
.scene-label::after {
content: "";
position: absolute;
bottom: -5px;
left: 50%;
width: 8px;
height: 8px;
border-right: 1px solid rgba(50, 77, 68, 0.14);
border-bottom: 1px solid rgba(50, 77, 68, 0.14);
background: rgba(255, 253, 247, 0.91);
transform: translateX(-50%) rotate(45deg);
}
.scene-label span,
.scene-label strong,
.scene-label small {
display: block;
}
.scene-label span {
color: #7a8983;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.scene-label strong {
margin: 2px 0;
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.scene-label small {
color: #87938e;
font-size: 7px;
}
.scene-label.orange {
border-color: rgba(204, 112, 72, 0.28);
}
.scene-label.green {
border-color: rgba(40, 118, 109, 0.28);
}
.loading {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
background: #dfe7e3;
color: var(--muted);
font-size: 12px;
}
@media (max-width: 780px) {
body {
overflow: auto;
}
#app {
display: flex;
flex-direction: column;
height: auto;
min-height: 100%;
}
main {
order: -1;
height: 58vh;
min-height: 420px;
}
aside {
overflow: visible;
border-right: 0;
border-top: 1px solid rgba(44, 69, 61, 0.12);
}
.scene-title {
top: 14px;
left: 14px;
}
.view-controls {
top: 12px;
right: 12px;
}
.scene-hint {
display: none;
}
.scene-label {
transform: translate(-50%, -100%) scale(0.88);
}
}
</style>
</head>
<body>
<div id="app">
<aside>
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<p class="eyebrow">Parametric study</p>
<h1>Ramp Geometry Lab</h1>
</div>
</div>
<p class="intro">
Explore how two illustrative teaching parameters change a bounded
ramp-and-landing arrangement.
</p>
<div class="notice" role="note">
<span class="notice-icon" aria-hidden="true">i</span>
<div>
<strong>Teaching model only</strong>
All dimensions, envelopes, and labels are illustrative teaching
parameters—not accessibility, building, safety, or compliance advice.
</div>
</div>
<h2 class="section-title">Teaching parameters</h2>
<div class="control">
<div class="control-head">
<label for="rampLength">Ramp run</label>
<output id="rampLengthValue" for="rampLength">4.80 m</output>
</div>
<input
id="rampLength"
type="range"
min="2"
max="5.6"
step="0.05"
value="4.8"
aria-describedby="rampLengthNote"
>
<div class="range-ends">
<span>2.00 m</span>
<span>5.60 m</span>
</div>
<p class="control-note" id="rampLengthNote">
Illustrative horizontal projection of the sloped teaching segment.
</p>
</div>
<div class="control">
<div class="control-head">
<label for="landingPosition">Landing position</label>
<output id="landingPositionValue" for="landingPosition">0.00 m</output>
</div>
<input
id="landingPosition"
type="range"
min="-5.1"
max="5.1"
step="0.05"
value="0"
aria-describedby="landingPositionNote"
>
<div class="range-ends">
<span>−5.10 m</span>
<span>Centre</span>
<span>+5.10 m</span>
</div>
<p class="control-note" id="landingPositionNote">
Illustrative lateral X offset from the ramp centreline. The landing
follows the ramp end in depth and remains inside the teaching site.
</p>
</div>
<h2 class="section-title">Live indicators</h2>
<div class="metrics" aria-live="polite">
<section class="metric" aria-labelledby="slopeTitle">
<div class="metric-heading">
<span id="slopeTitle">Slope indicator</span>
<span>teaching parameter</span>
</div>
<div class="metric-main">
<div class="big-value">
<span id="gradeValue">18.8</span><small>%</small>
</div>
<div class="slope-visual" aria-hidden="true">
<span class="slope-base"></span>
<span class="slope-line" id="slopeLine"></span>
</div>
</div>
<div class="detail-grid">
<div>
<span>Run : rise</span>
<strong id="ratioValue">1 : 5.3</strong>
</div>
<div>
<span>Angle</span>
<strong id="angleValue">10.6°</strong>
</div>
<div>
<span>Teaching rise</span>
<strong id="riseValue">0.90 m</strong>
</div>
</div>
</section>
<section class="metric" id="turnMetric" data-state="inside" aria-labelledby="turnTitle">
<div class="metric-heading">
<span id="turnTitle">Turning-space indicator</span>
<span>teaching parameter</span>
</div>
<div class="turn-title">
<div class="turn-icon" aria-hidden="true"></div>
<div>
<div class="big-value">
<span id="turnValue">1.80</span><small>m diameter</small>
</div>
<div class="control-note" style="margin-top: 4px">
Illustrative circular turning envelope
</div>
</div>
</div>
<div class="state" id="turnState">
Envelope remains inside the teaching site
</div>
<div class="site-facts">
<div>
<span>Nearest teaching datum</span>
<strong id="clearanceValue">2.10 m</strong>
</div>
<div>
<span>Landing footprint</span>
<strong>1.80 × 1.80 m</strong>
</div>
<div>
<span>Teaching site bounds</span>
<strong>12.00 × 8.00 m</strong>
</div>
</div>
</section>
</div>
<div class="actions">
<button class="button primary" id="resetParameters" type="button">
Reset parameters
</button>
<button class="button" id="resetView" type="button">
Reset camera
</button>
</div>
<div class="legend" aria-label="Scene legend">
<span><i class="swatch" style="background:#cc7048"></i>Ramp teaching segment</span>
<span><i class="swatch" style="background:#3d8e87"></i>Landing teaching area</span>
<span><i class="swatch" style="background:#9bada6"></i>Teaching site datum</span>
</div>
<p class="footer-note">
The landing is connected to the ramp by a level teaching connector.
Boundary relationships are geometric observations only; no acceptance
criteria or jurisdiction-specific requirements are represented.
</p>
</aside>
<main id="viewport">
<div class="loading" id="loading">Loading teaching scene…</div>
<div class="scene-title">
<strong>Bounded ramp study</strong>
<span>12.0 × 8.0 m illustrative teaching site</span>
</div>
<div class="view-controls" aria-label="Camera views">
<button id="isoView" class="active" type="button">3D view</button>
<button id="planView" type="button">Plan view</button>
</div>
<div id="labels" aria-hidden="true"></div>
<div class="scene-hint">
Drag: orbit · Shift-drag: pan · Scroll: zoom
</div>
</main>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const viewport = document.getElementById("viewport");
const labelsLayer = document.getElementById("labels");
const loading = document.getElementById("loading");
const SITE = Object.freeze({
width: 12,
depth: 8,
halfWidth: 6,
halfDepth: 4
});
const TEACHING = Object.freeze({
rise: 0.90,
rampWidth: 1.50,
landingSize: 1.80,
turningDiameter: 1.80,
toeZ: -3.20
});
const DEFAULTS = Object.freeze({
rampLength: 4.80,
landingPosition: 0
});
let rampLength = DEFAULTS.rampLength;
let landingPosition = DEFAULTS.landingPosition;
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional teaching model of a ramp and landing"
);
viewport.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdfe7e3);
scene.fog = new THREE.Fog(0xdfe7e3, 20, 38);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 80);
const hemisphere = new THREE.HemisphereLight(0xf5fbfa, 0x9a8b76, 2.1);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff6e8, 3.1);
sun.position.set(-7, 13, 7);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 10;
sun.shadow.camera.bottom = -10;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0004;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0xc9e5e1, 1.15);
fillLight.position.set(8, 5, -6);
scene.add(fillLight);
const materials = {
site: new THREE.MeshStandardMaterial({
color: 0xe9e4d8,
roughness: 0.95,
flatShading: true
}),
siteEdge: new THREE.MeshStandardMaterial({
color: 0xcfc8b8,
roughness: 0.95,
flatShading: true
}),
ramp: new THREE.MeshStandardMaterial({
color: 0xcc7048,
roughness: 0.76,
flatShading: true
}),
rampSide: new THREE.MeshStandardMaterial({
color: 0xa95135,
roughness: 0.86,
flatShading: true
}),
landing: new THREE.MeshStandardMaterial({
color: 0x3d8e87,
roughness: 0.72,
flatShading: true
}),
connector: new THREE.MeshStandardMaterial({
color: 0x6b8f87,
roughness: 0.8,
flatShading: true
}),
post: new THREE.MeshStandardMaterial({
color: 0x7a5546,
roughness: 0.8,
flatShading: true
})
};
const siteBase = new THREE.Mesh(
new THREE.BoxGeometry(SITE.width + 0.36, 0.28, SITE.depth + 0.36),
materials.site
);
siteBase.position.y = -0.16;
siteBase.receiveShadow = true;
scene.add(siteBase);
const siteLip = new THREE.Mesh(
new THREE.BoxGeometry(SITE.width + 0.48, 0.12, SITE.depth + 0.48),
materials.siteEdge
);
siteLip.position.y = -0.31;
siteLip.receiveShadow = true;
scene.add(siteLip);
const gridPositions = [];
for (let x = -6; x <= 6; x += 1) {
gridPositions.push(x, 0.005, -4, x, 0.005, 4);
}
for (let z = -4; z <= 4; z += 1) {
gridPositions.push(-6, 0.005, z, 6, 0.005, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridPositions, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x73827b,
transparent: true,
opacity: 0.18
})
);
scene.add(grid);
const boundaryPoints = [
new THREE.Vector3(-6, 0.025, -4),
new THREE.Vector3(6, 0.025, -4),
new THREE.Vector3(6, 0.025, 4),
new THREE.Vector3(-6, 0.025, 4),
new THREE.Vector3(-6, 0.025, -4)
];
const boundary = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(boundaryPoints),
new THREE.LineBasicMaterial({ color: 0x667a72 })
);
scene.add(boundary);
const cornerGeometry = new THREE.BoxGeometry(0.22, 0.10, 0.22);
for (const x of [-6, 6]) {
for (const z of [-4, 4]) {
const corner = new THREE.Mesh(cornerGeometry, materials.post);
corner.position.set(x, 0.025, z);
scene.add(corner);
}
}
const rampGroup = new THREE.Group();
scene.add(rampGroup);
const rampMesh = new THREE.Mesh(
new THREE.BufferGeometry(),
[materials.ramp, materials.rampSide]
);
rampMesh.castShadow = true;
rampMesh.receiveShadow = true;
rampGroup.add(rampMesh);
const railMaterial = new THREE.LineBasicMaterial({ color: 0x704a3d });
const railLeft = new THREE.Line(new THREE.BufferGeometry(), railMaterial);
const railRight = new THREE.Line(new THREE.BufferGeometry(), railMaterial);
rampGroup.add(railLeft, railRight);
const postGeometry = new THREE.CylinderGeometry(0.025, 0.025, 0.38, 6);
const posts = [];
for (let side = -1; side <= 1; side += 2) {
for (let i = 0; i < 5; i++) {
const post = new THREE.Mesh(postGeometry, materials.post);
post.castShadow = true;
posts.push({ mesh: post, side, index: i });
rampGroup.add(post);
}
}
const rampArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0.2, 1).normalize(),
new THREE.Vector3(),
0.95,
0x6e3527,
0.24,
0.17
);
rampGroup.add(rampArrow);
const runDimension = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({ color: 0x63756d })
);
scene.add(runDimension);
const riseDimension = new THREE.LineSegments(
new THREE.BufferGeometry(),
new THREE.LineBasicMaterial({ color: 0x63756d })
);
scene.add(riseDimension);
const bridgeMesh = new THREE.Mesh(
new THREE.BoxGeometry(1, 0.14, 0.76),
materials.connector
);
bridgeMesh.castShadow = true;
bridgeMesh.receiveShadow = true;
scene.add(bridgeMesh);
const landingMesh = new THREE.Mesh(
new THREE.BoxGeometry(
TEACHING.landingSize,
0.16,
TEACHING.landingSize
),
materials.landing
);
landingMesh.castShadow = true;
landingMesh.receiveShadow = true;
scene.add(landingMesh);
const landingEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(landingMesh.geometry),
new THREE.LineBasicMaterial({ color: 0x246b65 })
);
scene.add(landingEdges);
const turningRadius = TEACHING.turningDiameter / 2;
const turningFill = new THREE.Mesh(
new THREE.CircleGeometry(turningRadius, 32),
new THREE.MeshBasicMaterial({
color: 0x4e9a91,
transparent: true,
opacity: 0.16,
depthWrite: false,
side: THREE.DoubleSide
})
);
turningFill.rotation.x = -Math.PI / 2;
scene.add(turningFill);
const turningPoints = [];
for (let i = 0; i <= 64; i++) {
const angle = (i / 64) * Math.PI * 2;
turningPoints.push(
new THREE.Vector3(
Math.cos(angle) * turningRadius,
0,
Math.sin(angle) * turningRadius
)
);
}
const turningOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(turningPoints),
new THREE.LineDashedMaterial({
color: 0x28766d,
dashSize: 0.14,
gapSize: 0.08,
transparent: true,
opacity: 0.85
})
);
turningOutline.computeLineDistances();
scene.add(turningOutline);
const centerMarker = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.025, 8),
new THREE.MeshBasicMaterial({ color: 0x235f59 })
);
scene.add(centerMarker);
const labels = new Map();
function addLabel(id, html, className = "") {
const element = document.createElement("div");
element.className = `scene-label ${className}`.trim();
element.innerHTML = html;
labelsLayer.appendChild(element);
labels.set(id, {
element,
anchor: new THREE.Vector3(),
offset: [0, 0],
visible: true
});
return labels.get(id);
}
addLabel(
"siteWidth",
`
<span>Teaching site datum</span>
<strong>12.00 m width</strong>
<small>illustrative boundary</small>
`,
"optional-label"
).anchor.set(-2.8, 0.05, 4.22);
addLabel(
"siteDepth",
`
<span>Teaching site datum</span>
<strong>8.00 m depth</strong>
<small>illustrative boundary</small>
`,
"optional-label"
).anchor.set(6.28, 0.05, 0);
const rampLabel = addLabel(
"ramp",
"",
"orange"
);
const riseLabel = addLabel(
"rise",
`
<span>Teaching rise</span>
<strong>0.90 m</strong>
<small>teaching parameter</small>
`,
"orange optional-label"
);
const runLabel = addLabel(
"run",
"",
"orange optional-label"
);
const landingLabel = addLabel(
"landing",
"",
"green"
);
const turningLabel = addLabel(
"turning",
"",
"green"
);
const cameraState = {
theta: 0.72,
phi: 0.82,
radius: 16,
target: new THREE.Vector3(0, 0.38, 0)
};
function fitRadius(base = 16) {
const aspect = Math.max(camera.aspect, 0.5);
return base * Math.max(1, 1.20 / aspect);
}
function applyCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x +
cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y +
cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z +
cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
}
function setView(view) {
const isoButton = document.getElementById("isoView");
const planButton = document.getElementById("planView");
if (view === "plan") {
cameraState.theta = 0;
cameraState.phi = 0.035;
cameraState.radius = fitRadius(16.7);
cameraState.target.set(0, 0, 0);
isoButton.classList.remove("active");
planButton.classList.add("active");
} else {
cameraState.theta = 0.72;
cameraState.phi = 0.82;
cameraState.radius = fitRadius(16);
cameraState.target.set(0, 0.38, 0);
isoButton.classList.add("active");
planButton.classList.remove("active");
}
applyCamera();
}
function replaceLineGeometry(line, points) {
line.geometry.dispose();
line.geometry = new THREE.BufferGeometry().setFromPoints(points);
}
function createRampGeometry(length) {
const w = TEACHING.rampWidth / 2;
const z0 = TEACHING.toeZ;
const z1 = z0 + length;
const y0 = 0.015;
const y1 = y0 + TEACHING.rise;
const positions = [
-w, y0, z0,
w, y0, z0,
w, y1, z1,
-w, y1, z1,
-w, 0, z0,
w, 0, z0,
w, 0, z1,
-w, 0, z1
];
const indices = [
0, 3, 2, 0, 2, 1, // sloped top
1, 2, 6, 1, 6, 5, // right side
0, 7, 3, 0, 4, 7, // left side
3, 7, 6, 3, 6, 2, // end face
4, 6, 7, 4, 5, 6 // bottom
];
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function updateRangeAppearance(input) {
const min = Number(input.min);
const max = Number(input.max);
const value = Number(input.value);
const percentage = ((value - min) / (max - min)) * 100;
input.style.setProperty("--fill", `${percentage}%`);
}
function updateModel() {
const z0 = TEACHING.toeZ;
const z1 = z0 + rampLength;
const x = landingPosition;
const endHeight = 0.015 + TEACHING.rise;
rampMesh.geometry.dispose();
rampMesh.geometry = createRampGeometry(rampLength);
const halfWidth = TEACHING.rampWidth / 2;
replaceLineGeometry(railLeft, [
new THREE.Vector3(-halfWidth, 0.395, z0),
new THREE.Vector3(-halfWidth, endHeight + 0.38, z1)
]);
replaceLineGeometry(railRight, [
new THREE.Vector3(halfWidth, 0.395, z0),
new THREE.Vector3(halfWidth, endHeight + 0.38, z1)
]);
for (const post of posts) {
const t = post.index / 4;
const surface = 0.015 + TEACHING.rise * t;
post.mesh.position.set(
post.side * halfWidth,
surface + 0.19,
z0 + rampLength * t
);
}
const arrowOriginT = 0.28;
const arrowOrigin = new THREE.Vector3(
0,
0.015 + TEACHING.rise * arrowOriginT + 0.055,
z0 + rampLength * arrowOriginT
);
rampArrow.position.copy(arrowOrigin);
rampArrow.setDirection(
new THREE.Vector3(0, TEACHING.rise / rampLength, 1).normalize()
);
const dimensionX = 1.18;
const runPoints = [
new THREE.Vector3(dimensionX, 0.04, z0),
new THREE.Vector3(dimensionX, 0.04, z1),
new THREE.Vector3(dimensionX - 0.13, 0.04, z0),
new THREE.Vector3(dimensionX + 0.13, 0.04, z0),
new THREE.Vector3(dimensionX - 0.13, 0.04, z1),
new THREE.Vector3(dimensionX + 0.13, 0.04, z1)
];
replaceLineGeometry(runDimension, runPoints);
const riseX = -1.15;
const riseZ = z0 + 0.22;
const risePoints = [
new THREE.Vector3(riseX, 0.015, riseZ),
new THREE.Vector3(riseX, endHeight, riseZ),
new THREE.Vector3(riseX - 0.13, 0.015, riseZ),
new THREE.Vector3(riseX + 0.13, 0.015, riseZ),
new THREE.Vector3(riseX - 0.13, endHeight, riseZ),
new THREE.Vector3(riseX + 0.13, endHeight, riseZ)
];
replaceLineGeometry(riseDimension, risePoints);
const connectorLength = Math.abs(x);
if (connectorLength > 0.025) {
bridgeMesh.visible = true;
bridgeMesh.geometry.dispose();
bridgeMesh.geometry = new THREE.BoxGeometry(
connectorLength,
0.14,
0.76
);
bridgeMesh.position.set(x / 2, endHeight - 0.075, z1);
} else {
bridgeMesh.visible = false;
}
landingMesh.position.set(x, endHeight - 0.08, z1);
landingEdges.position.copy(landingMesh.position);
turningFill.position.set(x, endHeight + 0.012, z1);
turningOutline.position.set(x, endHeight + 0.024, z1);
centerMarker.position.set(x, endHeight + 0.028, z1);
const grade = (TEACHING.rise / rampLength) * 100;
const ratio = rampLength / TEACHING.rise;
const angle = Math.atan2(TEACHING.rise, rampLength) * 180 / Math.PI;
const xBoundaryClearance =
SITE.halfWidth - (Math.abs(x) + turningRadius);
const zBoundaryClearance =
SITE.halfDepth - (Math.abs(z1) + turningRadius);
const boundaryClearance = Math.min(
xBoundaryClearance,
zBoundaryClearance
);
const crossingAmount = Math.max(0, -boundaryClearance);
const insideEnvelope = crossingAmount === 0;
const envelopeColor = insideEnvelope ? 0x28766d : 0xb1762e;
turningOutline.material.color.setHex(envelopeColor);
turningFill.material.color.setHex(envelopeColor);
document.getElementById("rampLengthValue").textContent =
`${rampLength.toFixed(2)} m`;
document.getElementById("landingPositionValue").textContent =
`${landingPosition >= 0 ? "+" : ""}${landingPosition.toFixed(2)} m`;
document.getElementById("gradeValue").textContent =
grade.toFixed(1);
document.getElementById("ratioValue").textContent =
`1 : ${ratio.toFixed(1)}`;
document.getElementById("angleValue").textContent =
`${angle.toFixed(1)}°`;
document.getElementById("riseValue").textContent =
`${TEACHING.rise.toFixed(2)} m`;
document.getElementById("slopeLine").style.transform =
`rotate(${-angle}deg)`;
document.getElementById("turnValue").textContent =
TEACHING.turningDiameter.toFixed(2);
const turnMetric = document.getElementById("turnMetric");
const turnState = document.getElementById("turnState");
const clearanceValue = document.getElementById("clearanceValue");
if (insideEnvelope) {
turnMetric.dataset.state = "inside";
turnState.textContent =
"Envelope remains inside the teaching site";
clearanceValue.textContent =
`${boundaryClearance.toFixed(2)} m to nearest teaching datum`;
} else {
turnMetric.dataset.state = "over";
turnState.textContent =
"Envelope crosses the teaching site datum";
clearanceValue.textContent =
`${crossingAmount.toFixed(2)} m beyond teaching datum`;
}
rampLabel.element.innerHTML = `
<span>Ramp run</span>
<strong>${rampLength.toFixed(2)} m</strong>
<small>teaching parameter</small>
`;
rampLabel.anchor.set(-1.03, endHeight + 0.52, z1 - 0.40);
rampLabel.offset = [-28, -2];
runLabel.element.innerHTML = `
<span>Horizontal run</span>
<strong>${rampLength.toFixed(2)} m</strong>
<small>teaching parameter</small>
`;
runLabel.anchor.set(dimensionX, 0.10, (z0 + z1) / 2);
runLabel.offset = [20, 0];
riseLabel.anchor.set(riseX, endHeight * 0.52, riseZ);
riseLabel.offset = [-24, 0];
landingLabel.element.innerHTML = `
<span>Landing centre</span>
<strong>${landingPosition >= 0 ? "+" : ""}${landingPosition.toFixed(2)} m lateral</strong>
<small>teaching position</small>
`;
landingLabel.anchor.set(x, endHeight + 0.08, z1 + 0.88);
landingLabel.offset = [0, -4];
turningLabel.element.innerHTML = `
<span>Turning envelope</span>
<strong>Ø ${TEACHING.turningDiameter.toFixed(2)} m</strong>
<small>teaching parameter</small>
`;
turningLabel.anchor.set(x, endHeight + 0.08, z1 - 0.90);
turningLabel.offset = [0, 4];
}
function updateProjectedLabels() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
for (const label of labels.values()) {
const projected = label.anchor.clone().project(camera);
const isVisible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.25 &&
projected.x < 1.25 &&
projected.y > -1.25 &&
projected.y < 1.25;
if (!isVisible || !label.visible) {
label.element.style.display = "none";
continue;
}
label.element.style.display = "block";
label.element.style.left =
`${(projected.x * 0.5 + 0.5) * width + label.offset[0]}px`;
label.element.style.top =
`${(-projected.y * 0.5 + 0.5) * height + label.offset[1]}px`;
}
}
const rampInput = document.getElementById("rampLength");
const landingInput = document.getElementById("landingPosition");
rampInput.addEventListener("input", () => {
rampLength = Number(rampInput.value);
updateRangeAppearance(rampInput);
updateModel();
});
landingInput.addEventListener("input", () => {
landingPosition = Number(landingInput.value);
updateRangeAppearance(landingInput);
updateModel();
});
document.getElementById("resetParameters").addEventListener("click", () => {
rampLength = DEFAULTS.rampLength;
landingPosition = DEFAULTS.landingPosition;
rampInput.value = String(rampLength);
landingInput.value = String(landingPosition);
updateRangeAppearance(rampInput);
updateRangeAppearance(landingInput);
updateModel();
});
document.getElementById("resetView").addEventListener("click", () => {
setView("iso");
});
document.getElementById("isoView").addEventListener("click", () => {
setView("iso");
});
document.getElementById("planView").addEventListener("click", () => {
setView("plan");
});
// Custom camera controls: orbit, pan and zoom are implemented here so
// that no Three.js examples/addons modules are required.
const canvas = renderer.domElement;
let dragState = null;
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragState = {
pointerId: event.pointerId,
x: event.clientX,
y: event.clientY,
pan: event.shiftKey
};
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragState || dragState.pointerId !== event.pointerId) return;
const dx = event.clientX - dragState.x;
const dy = event.clientY - dragState.y;
dragState.x = event.clientX;
dragState.y = event.clientY;
if (dragState.pan) {
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, new THREE.Vector3(0, 1, 0))
.normalize();
const panScale = cameraState.radius * 0.0014;
cameraState.target.addScaledVector(right, -dx * panScale);
cameraState.target.addScaledVector(forward, dy * panScale);
cameraState.target.x = THREE.MathUtils.clamp(
cameraState.target.x,
-7,
7
);
cameraState.target.z = THREE.MathUtils.clamp(
cameraState.target.z,
-6,
6
);
} else {
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.035,
1.45
);
}
applyCamera();
});
function endPointerDrag(event) {
if (!dragState || dragState.pointerId !== event.pointerId) return;
dragState = null;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endPointerDrag);
canvas.addEventListener("pointercancel", endPointerDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
const zoomFactor = Math.exp(event.deltaY * 0.001);
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * zoomFactor,
7,
32
);
applyCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", () => {
setView("iso");
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
});
function resize() {
const width = viewport.clientWidth;
const height = viewport.clientHeight;
renderer.setSize(width, height, false);
camera.aspect = width / Math.max(height, 1);
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(viewport);
updateRangeAppearance(rampInput);
updateRangeAppearance(landingInput);
updateModel();
resize();
setView("iso");
loading.remove();
renderer.setAnimationLoop(() => {
applyCamera();
renderer.render(scene, camera);
updateProjectedLabels();
});
</script>
</body>
</html>
```