Prompt specification
Build or customize the Three.js 3D scene "Longer ramp lower slope" 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: Longer ramp lower slope
Category: Architecture & Cities · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/longer-ramp-lower-slope-x0458
Scene Description Prompt:
Two low-poly ramps reach equal heights over different distances; moving wheeled markers reveal their different slopes. Three.js from cdnjs, one HTML file.
Working Three.js Starter (longer-ramp-lower-slope-x0458):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Same Height, Different Slope</title>
<style>
:root {
--ink: #18332d;
--muted: #61756f;
--gentle: #18a999;
--gentle-dark: #087d74;
--steep: #f27a55;
--steep-dark: #c65335;
--panel: rgba(255, 255, 255, 0.82);
--line: rgba(24, 51, 45, 0.12);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eaf1ed;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#app {
position: fixed;
inset: 0;
}
#app canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#app canvas:active {
cursor: grabbing;
}
.intro {
position: fixed;
top: clamp(22px, 4vw, 48px);
left: clamp(22px, 4vw, 54px);
width: min(430px, calc(100vw - 44px));
pointer-events: none;
z-index: 3;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 9px;
margin-bottom: 13px;
color: var(--gentle-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
width: 26px;
height: 2px;
background: var(--gentle);
content: "";
}
h1 {
margin: 0;
max-width: 410px;
font-size: clamp(38px, 5.2vw, 68px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.96;
}
.intro p {
max-width: 390px;
margin: 19px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.65;
}
.equal-badge {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 18px;
padding: 9px 13px;
border: 1px solid rgba(24, 51, 45, 0.1);
border-radius: 999px;
background: rgba(255, 255, 255, 0.66);
color: var(--ink);
font-size: 12px;
font-weight: 750;
backdrop-filter: blur(10px);
}
.equal-badge span {
width: 8px;
height: 8px;
border-radius: 50%;
background: #f1b83c;
box-shadow: 0 0 0 4px rgba(241, 184, 60, 0.16);
}
.metrics {
position: fixed;
top: clamp(22px, 4vw, 48px);
right: clamp(22px, 4vw, 54px);
z-index: 3;
width: min(320px, calc(100vw - 44px));
padding: 16px;
border: 1px solid rgba(255, 255, 255, 0.76);
border-radius: 22px;
background: var(--panel);
box-shadow: 0 20px 60px rgba(35, 70, 59, 0.1);
backdrop-filter: blur(16px);
}
.metric {
padding: 14px 14px 13px;
border-radius: 15px;
color: white;
}
.metric.gentle {
background: linear-gradient(135deg, #20b8a7, #07847b);
}
.metric.steep {
margin-top: 10px;
background: linear-gradient(135deg, #fa8a63, #c95838);
}
.metric-head,
.metric-bottom {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.metric-name {
font-size: 10px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
opacity: 0.86;
}
.metric-status {
padding: 4px 7px;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 999px;
background: rgba(255, 255, 255, 0.12);
font-size: 9px;
font-weight: 750;
}
.metric-angle {
margin-top: 8px;
font-size: 31px;
font-weight: 800;
letter-spacing: -0.045em;
}
.metric-angle small {
font-size: 17px;
font-weight: 700;
}
.metric-bottom {
margin-top: 10px;
font-size: 11px;
font-weight: 650;
opacity: 0.92;
}
.progress {
height: 4px;
margin-top: 10px;
overflow: hidden;
border-radius: 999px;
background: rgba(255, 255, 255, 0.24);
}
.progress > span {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: white;
transition: width 80ms linear;
}
.controls-wrap {
position: fixed;
left: 50%;
bottom: clamp(18px, 3vw, 34px);
z-index: 4;
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
transform: translateX(-50%);
}
.hint {
color: rgba(24, 51, 45, 0.64);
font-size: 11px;
font-weight: 650;
letter-spacing: 0.025em;
pointer-events: none;
}
.controls {
display: flex;
gap: 8px;
padding: 7px;
border: 1px solid rgba(255, 255, 255, 0.85);
border-radius: 16px;
background: rgba(255, 255, 255, 0.82);
box-shadow: 0 14px 40px rgba(35, 70, 59, 0.12);
backdrop-filter: blur(14px);
}
.controls button {
min-width: 78px;
padding: 10px 15px;
border: 0;
border-radius: 10px;
background: transparent;
color: var(--ink);
font-size: 12px;
font-weight: 750;
cursor: pointer;
transition:
color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.controls button:hover {
background: rgba(24, 51, 45, 0.07);
}
.controls button:active {
transform: translateY(1px);
}
.controls button.primary {
min-width: 92px;
background: var(--ink);
color: white;
}
.controls button.primary:hover {
background: #285047;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #eaf1ed;
color: var(--ink);
font-size: 13px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: opacity 300ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 760px) {
.intro {
top: 20px;
}
h1 {
font-size: clamp(36px, 11vw, 54px);
}
.intro p {
max-width: 330px;
font-size: 12px;
}
.equal-badge {
margin-top: 12px;
}
.metrics {
top: auto;
right: 16px;
bottom: 102px;
width: 210px;
padding: 10px;
border-radius: 17px;
}
.metric {
padding: 10px 11px;
}
.metric.steep {
margin-top: 7px;
}
.metric-angle {
font-size: 24px;
}
.metric-angle small {
font-size: 13px;
}
.metric-bottom {
font-size: 9px;
}
.controls-wrap {
bottom: 15px;
}
.controls button {
min-width: 64px;
padding: 9px 12px;
font-size: 11px;
}
.controls button.primary {
min-width: 78px;
}
}
</style>
</head>
<body>
<div id="app"></div>
<header class="intro">
<div class="eyebrow">Interactive geometry</div>
<h1>Same height.<br>Different slope.</h1>
<p>
Two ramps rise by exactly 3.0 meters, but one travels much farther.
Watch the wheeled markers climb each ramp.
</p>
<div class="equal-badge">
<span></span>
Equal vertical rise: 3.0 m
</div>
</header>
<aside class="metrics" aria-label="Ramp comparison">
<section class="metric gentle">
<div class="metric-head">
<span class="metric-name">Gentle ramp</span>
<span id="gentleStatus" class="metric-status">Climbing</span>
</div>
<div class="metric-angle">18.4<small>°</small></div>
<div class="metric-bottom">
<span>9.0 m run</span>
<span>3.0 m rise</span>
</div>
<div class="progress"><span id="gentleBar"></span></div>
</section>
<section class="metric steep">
<div class="metric-head">
<span class="metric-name">Steep ramp</span>
<span id="steepStatus" class="metric-status">Climbing</span>
</div>
<div class="metric-angle">31.0<small>°</small></div>
<div class="metric-bottom">
<span>5.0 m run</span>
<span>3.0 m rise</span>
</div>
<div class="progress"><span id="steepBar"></span></div>
</section>
</aside>
<div class="controls-wrap">
<div class="hint">Drag to orbit · Scroll or pinch to zoom · Double-click to reset view</div>
<div class="controls">
<button id="toggle" class="primary" type="button">Pause</button>
<button id="speed" type="button">1× speed</button>
<button id="reset" type="button">Reset run</button>
</div>
</div>
<div id="loading">Building the ramps…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const app = document.querySelector("#app");
const loading = document.querySelector("#loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeaf1ed);
scene.fog = new THREE.Fog(0xeaf1ed, 24, 48);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D comparison of two ramps with different slopes"
);
app.appendChild(renderer.domElement);
// Lighting
const hemisphere = new THREE.HemisphereLight(0xf8fff9, 0x68796f, 2.15);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d2, 3.1);
sun.position.set(-7, 13, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -18;
sun.shadow.camera.right = 18;
sun.shadow.camera.top = 16;
sun.shadow.camera.bottom = -14;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 38;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const fill = new THREE.DirectionalLight(0xbadbff, 0.75);
fill.position.set(10, 7, -10);
scene.add(fill);
// Shared dimensions
const RISE = 3;
const RAMP_WIDTH = 1.65;
const rampConfigs = [
{
id: "gentle",
startX: -4.4,
length: 9,
height: RISE,
z: 2.55,
color: 0x20b6a5,
sideColor: 0x087f76,
backColor: 0x129489
},
{
id: "steep",
startX: -0.4,
length: 5,
height: RISE,
z: -2.55,
color: 0xf48760,
sideColor: 0xc45436,
backColor: 0xdd6845
}
];
// Ground
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(42, 32),
new THREE.MeshStandardMaterial({
color: 0xdde9df,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.055;
ground.receiveShadow = true;
scene.add(ground);
// Subtle geometric ground patches
const patchMaterial = new THREE.MeshStandardMaterial({
color: 0xd2e2d5,
roughness: 1
});
[
[-6.2, 3.5, 7.4, 4.3],
[-1.7, -3.4, 8.2, 4.2],
[6.4, 0.8, 3.3, 10.8]
].forEach(([x, z, w, d]) => {
const patch = new THREE.Mesh(
new THREE.PlaneGeometry(w, d),
patchMaterial
);
patch.rotation.x = -Math.PI / 2;
patch.position.set(x, -0.035, z);
patch.receiveShadow = true;
scene.add(patch);
});
function roundedRect(ctx, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
ctx.beginPath();
ctx.moveTo(x + r, y);
ctx.lineTo(x + width - r, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + r);
ctx.lineTo(x + width, y + height - r);
ctx.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
ctx.lineTo(x + r, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - r);
ctx.lineTo(x, y + r);
ctx.quadraticCurveTo(x, y, x + r, y);
ctx.closePath();
}
function makeTextSprite(text, options = {}) {
const {
color = "#18332d",
background = "rgba(255,255,255,0.9)",
border = "rgba(24,51,45,0.12)",
width = 512,
height = 128
} = options;
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, width, height);
roundedRect(ctx, 5, 5, width - 10, height - 10, 28);
ctx.fillStyle = background;
ctx.fill();
ctx.strokeStyle = border;
ctx.lineWidth = 3;
ctx.stroke();
ctx.fillStyle = color;
ctx.font = "800 43px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, width / 2, height / 2 + 1);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.renderOrder = 20;
return sprite;
}
function createWedgeGeometry(length, height, width) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
0, 0, -width / 2,
0, 0, width / 2,
length, height, -width / 2,
length, height, width / 2,
length, 0, -width / 2,
length, 0, width / 2
],
3
)
);
geometry.setIndex([
0, 4, 2,
1, 3, 5,
0, 2, 3, 0, 3, 1,
0, 1, 5, 0, 5, 4,
4, 2, 3, 4, 3, 5
]);
geometry.addGroup(0, 3, 0);
geometry.addGroup(3, 3, 1);
geometry.addGroup(6, 6, 2);
geometry.addGroup(12, 6, 3);
geometry.addGroup(18, 6, 4);
geometry.computeVertexNormals();
return geometry;
}
function addMeasurementLine(points, color = 0x55756b) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: true,
opacity: 0.72
});
return new THREE.Line(geometry, material);
}
function createRamp(config) {
const group = new THREE.Group();
group.position.set(config.startX, 0, config.z);
const geometry = createWedgeGeometry(
config.length,
config.height,
RAMP_WIDTH
);
const materials = [
new THREE.MeshStandardMaterial({
color: config.sideColor,
roughness: 0.84,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: config.sideColor,
roughness: 0.84,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: config.color,
roughness: 0.76,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x526b62,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: config.backColor,
roughness: 0.82,
flatShading: true
})
];
const ramp = new THREE.Mesh(geometry, materials);
ramp.castShadow = true;
ramp.receiveShadow = true;
group.add(ramp);
// Bright outline around the sloping top.
const topOutline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(0, 0.012, -RAMP_WIDTH / 2),
new THREE.Vector3(
config.length,
config.height + 0.012,
-RAMP_WIDTH / 2
),
new THREE.Vector3(
config.length,
config.height + 0.012,
RAMP_WIDTH / 2
),
new THREE.Vector3(0, 0.012, RAMP_WIDTH / 2),
new THREE.Vector3(0, 0.012, -RAMP_WIDTH / 2)
]),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.58
})
);
group.add(topOutline);
// Meter marks across the ramp surface.
const tickVertices = [];
for (let meter = 1; meter < config.length; meter++) {
const x = meter;
const y = (meter / config.length) * config.height + 0.018;
tickVertices.push(
x, y, -RAMP_WIDTH / 2 + 0.09,
x, y, RAMP_WIDTH / 2 - 0.09
);
}
const tickGeometry = new THREE.BufferGeometry();
tickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(tickVertices, 3)
);
group.add(
new THREE.LineSegments(
tickGeometry,
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.28
})
)
);
scene.add(group);
// Low plinth under the ramp.
const plinth = new THREE.Mesh(
new THREE.BoxGeometry(
config.length + 1.1,
0.08,
RAMP_WIDTH + 1.2
),
new THREE.MeshStandardMaterial({
color: config.id === "gentle" ? 0xc7e1d7 : 0xe8d8ca,
roughness: 1
})
);
plinth.position.set(
config.startX + config.length / 2,
-0.035,
config.z
);
plinth.receiveShadow = true;
scene.add(plinth);
// Starting and landing pads.
const padMaterial = new THREE.MeshStandardMaterial({
color: 0xf3eee2,
roughness: 0.92
});
const startPad = new THREE.Mesh(
new THREE.BoxGeometry(0.9, 0.13, RAMP_WIDTH + 0.42),
padMaterial
);
startPad.position.set(
config.startX - 0.45,
0.045,
config.z
);
startPad.castShadow = true;
startPad.receiveShadow = true;
scene.add(startPad);
const topPad = new THREE.Mesh(
new THREE.BoxGeometry(1.1, 0.16, RAMP_WIDTH + 0.42),
padMaterial
);
topPad.position.set(
config.startX + config.length + 0.55,
config.height - 0.08,
config.z
);
topPad.castShadow = true;
topPad.receiveShadow = true;
scene.add(topPad);
// Ground-level run measurement.
const measureZ = config.z + RAMP_WIDTH / 2 + 0.72;
const endX = config.startX + config.length;
scene.add(
addMeasurementLine([
new THREE.Vector3(config.startX, 0.035, measureZ),
new THREE.Vector3(endX, 0.035, measureZ)
])
);
const measureTicks = [];
for (let meter = 0; meter <= config.length; meter++) {
const x = config.startX + meter;
measureTicks.push(
x, 0.035, measureZ - 0.12,
x, 0.035, measureZ + 0.12
);
}
const measureTickGeometry = new THREE.BufferGeometry();
measureTickGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(measureTicks, 3)
);
scene.add(
new THREE.LineSegments(
measureTickGeometry,
new THREE.LineBasicMaterial({
color: 0x55756b,
transparent: true,
opacity: 0.6
})
)
);
const runLabel = makeTextSprite(
`${config.length.toFixed(1)} m RUN`,
{
color: config.id === "gentle" ? "#087d74" : "#c65335",
background: "rgba(255,255,255,0.94)"
}
);
runLabel.scale.set(1.8, 0.45, 1);
runLabel.position.set(
config.startX + config.length / 2,
0.34,
measureZ + 0.08
);
scene.add(runLabel);
// Vertical rise measurement.
const riseX = endX + 1.25;
scene.add(
addMeasurementLine([
new THREE.Vector3(riseX, 0.03, config.z),
new THREE.Vector3(riseX, config.height, config.z)
])
);
scene.add(
addMeasurementLine([
new THREE.Vector3(riseX - 0.14, 0.03, config.z),
new THREE.Vector3(riseX + 0.14, 0.03, config.z)
])
);
scene.add(
addMeasurementLine([
new THREE.Vector3(riseX - 0.14, config.height, config.z),
new THREE.Vector3(riseX + 0.14, config.height, config.z)
])
);
const riseLabel = makeTextSprite("3.0 m RISE", {
color: "#18332d",
background: "rgba(255,255,255,0.94)"
});
riseLabel.scale.set(1.85, 0.46, 1);
riseLabel.position.set(riseX + 0.55, 1.65, config.z);
scene.add(riseLabel);
// Angle arc, positioned just outside the near edge.
const angle = Math.atan2(config.height, config.length);
const radius = 0.9;
const arcPoints = [];
for (let i = 0; i <= 28; i++) {
const a = (i / 28) * angle;
arcPoints.push(
new THREE.Vector3(
config.startX + 0.08 + radius * Math.cos(a),
0.045 + radius * Math.sin(a),
config.z + RAMP_WIDTH / 2 + 0.14
)
);
}
scene.add(addMeasurementLine(arcPoints, 0xf1b83c));
const angleLabel = makeTextSprite(
`${THREE.MathUtils.radToDeg(angle).toFixed(1)}°`,
{
color: "#8b6412",
background: "rgba(255,248,221,0.95)",
border: "rgba(241,184,60,0.3)"
}
);
angleLabel.scale.set(1.05, 0.39, 1);
angleLabel.position.set(
config.startX + 1.05,
0.79,
config.z + RAMP_WIDTH / 2 + 0.18
);
scene.add(angleLabel);
}
rampConfigs.forEach(createRamp);
// Low-poly scenery
function addTree(x, z, scale = 1) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
tree.scale.setScalar(scale);
const trunk = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.19, 1.15, 5),
new THREE.MeshStandardMaterial({
color: 0x876448,
roughness: 1,
flatShading: true
})
);
trunk.position.y = 0.575;
trunk.castShadow = true;
tree.add(trunk);
const foliageMaterial = new THREE.MeshStandardMaterial({
color: 0x6da27e,
roughness: 1,
flatShading: true
});
const lower = new THREE.Mesh(
new THREE.ConeGeometry(0.72, 1.35, 6),
foliageMaterial
);
lower.position.y = 1.45;
lower.castShadow = true;
tree.add(lower);
const upper = new THREE.Mesh(
new THREE.ConeGeometry(0.55, 1.15, 6),
new THREE.MeshStandardMaterial({
color: 0x7cad88,
roughness: 1,
flatShading: true
})
);
upper.position.y = 2.02;
upper.castShadow = true;
tree.add(upper);
scene.add(tree);
}
addTree(-9.1, -5.6, 1.1);
addTree(-7.5, 6.4, 0.78);
addTree(8.3, -6.7, 1.25);
addTree(9.0, 4.9, 0.72);
addTree(-10.3, 1.3, 0.65);
const rockMaterial = new THREE.MeshStandardMaterial({
color: 0xb8c7ba,
roughness: 1,
flatShading: true
});
[
[-7.5, -1.9, 0.55],
[7.8, -3.7, 0.75],
[8.5, 2.6, 0.42],
[-6.3, 5.2, 0.36]
].forEach(([x, z, s]) => {
const rock = new THREE.Mesh(
new THREE.DodecahedronGeometry(s, 0),
rockMaterial
);
rock.position.set(x, s * 0.35, z);
rock.rotation.set(0.2, 0.4, 0.1);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
});
// Wheeled markers
const wheelRadius = 0.22;
const wheelGeometry = new THREE.CylinderGeometry(
wheelRadius,
wheelRadius,
0.16,
12
);
wheelGeometry.rotateX(Math.PI / 2);
function createMarker(flagColor) {
const group = new THREE.Group();
const wheels = [];
const tireMaterial = new THREE.MeshStandardMaterial({
color: 0x24322f,
roughness: 0.9,
flatShading: true
});
const hubMaterial = new THREE.MeshStandardMaterial({
color: 0xd8dfda,
roughness: 0.65,
metalness: 0.12,
flatShading: true
});
for (const x of [-0.34, 0.34]) {
for (const z of [-0.34, 0.34]) {
const wheel = new THREE.Mesh(wheelGeometry, tireMaterial);
wheel.position.set(x, wheelRadius + 0.015, z);
wheel.castShadow = true;
const hub = new THREE.Mesh(
new THREE.CylinderGeometry(0.09, 0.09, 0.175, 10),
hubMaterial
);
hub.rotation.x = Math.PI / 2;
hub.position.copy(wheel.position);
hub.castShadow = true;
group.add(wheel, hub);
wheels.push(wheel);
}
}
const body = new THREE.Mesh(
new THREE.BoxGeometry(0.94, 0.32, 0.64),
new THREE.MeshStandardMaterial({
color: 0xffd75e,
roughness: 0.72,
flatShading: true
})
);
body.position.y = 0.53;
body.castShadow = true;
group.add(body);
const cabin = new THREE.Mesh(
new THREE.BoxGeometry(0.44, 0.25, 0.54),
new THREE.MeshStandardMaterial({
color: 0xfff0b4,
roughness: 0.78,
flatShading: true
})
);
cabin.position.set(0.17, 0.8, 0);
cabin.castShadow = true;
group.add(cabin);
const windowMesh = new THREE.Mesh(
new THREE.BoxGeometry(0.455, 0.12, 0.555),
new THREE.MeshStandardMaterial({
color: 0x365c61,
roughness: 0.38,
metalness: 0.08
})
);
windowMesh.position.set(0.17, 0.83, 0);
group.add(windowMesh);
const pole = new THREE.Mesh(
new THREE.CylinderGeometry(0.025, 0.025, 0.7, 6),
new THREE.MeshStandardMaterial({
color: 0x374641,
roughness: 0.8
})
);
pole.position.set(-0.34, 1.15, 0);
pole.castShadow = true;
group.add(pole);
const flagGeometry = new THREE.BufferGeometry();
flagGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(
[
-0.34, 1.03, 0,
0.12, 1.18, 0,
-0.34, 1.43, 0
],
3
)
);
flagGeometry.computeVertexNormals();
const flag = new THREE.Mesh(
flagGeometry,
new THREE.MeshStandardMaterial({
color: flagColor,
roughness: 0.75,
side: THREE.DoubleSide,
flatShading: true
})
);
flag.castShadow = true;
group.add(flag);
scene.add(group);
return {
group,
wheels,
distance: 0,
direction: 1,
wait: 0,
minDistance: 0.3,
maxDistance: 0
};
}
const markers = {
gentle: createMarker(0x18a999),
steep: createMarker(0xf27a55)
};
rampConfigs.forEach((config) => {
const marker = markers[config.id];
marker.maxDistance = config.length - 0.38;
marker.distance = marker.minDistance;
});
// Custom camera controls
const cameraTarget = new THREE.Vector3(0.2, 1.1, 0);
let cameraRadius = 18.5;
let cameraTheta = 0.64;
let cameraPhi = 1.03;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
function updateCamera() {
const sinPhi = Math.sin(cameraPhi);
camera.position.set(
cameraTarget.x + cameraRadius * sinPhi * Math.sin(cameraTheta),
cameraTarget.y + cameraRadius * Math.cos(cameraPhi),
cameraTarget.z + cameraRadius * sinPhi * Math.cos(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = 18.5;
cameraTheta = 0.64;
cameraPhi = 1.03;
updateCamera();
}
updateCamera();
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraTheta -= deltaX * 0.006;
cameraPhi = THREE.MathUtils.clamp(
cameraPhi - deltaY * 0.005,
0.48,
1.4
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.012,
10,
29
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// Controls
let playing = true;
let playbackSpeed = 1;
const markerSpeed = 2.15;
const toggleButton = document.querySelector("#toggle");
const speedButton = document.querySelector("#speed");
const resetButton = document.querySelector("#reset");
toggleButton.addEventListener("click", () => {
playing = !playing;
toggleButton.textContent = playing ? "Pause" : "Play";
});
speedButton.addEventListener("click", () => {
if (playbackSpeed === 1) {
playbackSpeed = 2;
} else if (playbackSpeed === 2) {
playbackSpeed = 0.5;
} else {
playbackSpeed = 1;
}
speedButton.textContent = `${playbackSpeed}× speed`;
});
resetButton.addEventListener("click", () => {
Object.values(markers).forEach((marker) => {
marker.distance = marker.minDistance;
marker.direction = 1;
marker.wait = 0;
marker.wheels.forEach((wheel) => {
wheel.rotation.z = 0;
});
});
});
const gentleBar = document.querySelector("#gentleBar");
const steepBar = document.querySelector("#steepBar");
const gentleStatus = document.querySelector("#gentleStatus");
const steepStatus = document.querySelector("#steepStatus");
function updateMarker(config, marker, dt) {
if (playing) {
if (marker.wait > 0) {
marker.wait = Math.max(0, marker.wait - dt * playbackSpeed);
} else {
const travel = marker.direction * markerSpeed * dt * playbackSpeed;
marker.distance += travel;
if (marker.distance >= marker.maxDistance) {
marker.distance = marker.maxDistance;
marker.direction = -1;
marker.wait = 0.65;
} else if (marker.distance <= marker.minDistance) {
marker.distance = marker.minDistance;
marker.direction = 1;
marker.wait = 0.4;
}
marker.wheels.forEach((wheel) => {
wheel.rotation.z -= travel / wheelRadius;
});
}
}
const ratio = marker.distance / config.length;
const surfaceY = ratio * config.height;
const angle = Math.atan2(config.height, config.length);
marker.group.position.set(
config.startX + marker.distance,
surfaceY,
config.z
);
marker.group.rotation.z = angle;
const progress =
((marker.distance - marker.minDistance) /
(marker.maxDistance - marker.minDistance)) *
100;
const isPausedAtTop =
marker.wait > 0 && marker.direction === -1;
const isPausedAtBase =
marker.wait > 0 && marker.direction === 1;
const status = isPausedAtTop
? "At top"
: isPausedAtBase
? "At base"
: marker.direction > 0
? "Climbing"
: "Descending";
if (config.id === "gentle") {
gentleBar.style.width = `${progress}%`;
gentleStatus.textContent = status;
} else {
steepBar.style.width = `${progress}%`;
steepStatus.textContent = status;
}
}
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
let previousTime = performance.now();
function animate(time) {
const dt = Math.min((time - previousTime) / 1000, 0.05);
previousTime = time;
rampConfigs.forEach((config) => {
updateMarker(config, markers[config.id], dt);
});
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
requestAnimationFrame(animate);
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 350);
});
</script>
</body>
</html>
```