Prompt specification
Build or customize the Three.js 3D scene "Start Goal and Mandatory Connector Tiles" 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: Start Goal and Mandatory Connector Tiles
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/start-goal-and-mandatory-connector-tiles-x3489
Scene Description Prompt:
Make one HTML file using Three.js from cdnjs for this stylized scene: Display start and goal tiles with a connector piece and forbidden gap. Show the minimum adjacency requirement that a valid generated path must preserve.
Working Three.js Starter (start-goal-and-mandatory-connector-tiles-x3489):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Path Lab — Adjacency Systems</title>
<style>
:root {
--ink: #18312d;
--muted: #6f7e78;
--paper: #f7f8f3;
--line: rgba(24, 49, 45, 0.12);
--green: #169b83;
--green-soft: #d9f0e9;
--coral: #ec705e;
--gold: #e6ad3b;
--red: #c84c49;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9eee8;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
cursor: grab;
touch-action: none;
}
#scene.dragging {
cursor: grabbing;
}
.hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.topbar {
position: absolute;
top: 0;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: space-between;
padding: 24px 28px;
}
.brand {
display: flex;
align-items: center;
gap: 12px;
}
.brand-mark {
position: relative;
width: 38px;
height: 38px;
border: 1px solid rgba(24, 49, 45, 0.24);
border-radius: 11px;
background: rgba(247, 248, 243, 0.72);
box-shadow: 0 8px 24px rgba(24, 49, 45, 0.08);
backdrop-filter: blur(12px);
}
.brand-mark::before,
.brand-mark::after {
content: "";
position: absolute;
background: var(--green);
border-radius: 2px;
}
.brand-mark::before {
width: 8px;
height: 8px;
left: 8px;
top: 9px;
box-shadow: 14px 0 0 var(--gold);
}
.brand-mark::after {
width: 8px;
height: 8px;
left: 8px;
top: 22px;
box-shadow: 14px 0 0 var(--coral);
}
.brand-copy {
display: flex;
flex-direction: column;
gap: 2px;
}
.brand-copy span {
font-size: 10px;
font-weight: 800;
letter-spacing: 0.18em;
color: var(--muted);
}
.brand-copy strong {
font-size: 14px;
letter-spacing: -0.01em;
}
.top-actions {
display: flex;
align-items: center;
gap: 10px;
pointer-events: auto;
}
.live-pill {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 13px;
border: 1px solid rgba(24, 49, 45, 0.12);
border-radius: 999px;
background: rgba(247, 248, 243, 0.7);
backdrop-filter: blur(12px);
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.12em;
}
.live-pill::before {
content: "";
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 4px rgba(22, 155, 131, 0.12);
}
.quiet-button {
border: 1px solid rgba(24, 49, 45, 0.14);
border-radius: 999px;
padding: 10px 14px;
background: rgba(247, 248, 243, 0.76);
color: var(--ink);
cursor: pointer;
font-size: 11px;
font-weight: 700;
backdrop-filter: blur(12px);
transition:
transform 160ms ease,
background 160ms ease;
}
.quiet-button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.94);
}
.panel {
position: absolute;
top: 100px;
left: 28px;
width: min(342px, calc(100vw - 56px));
padding: 24px;
border: 1px solid rgba(24, 49, 45, 0.12);
border-radius: 24px;
background: rgba(247, 248, 243, 0.82);
box-shadow:
0 24px 70px rgba(35, 55, 49, 0.13),
inset 0 1px 0 rgba(255, 255, 255, 0.8);
backdrop-filter: blur(20px) saturate(1.15);
pointer-events: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 12px;
color: var(--green);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 19px;
height: 2px;
border-radius: 2px;
background: currentColor;
}
h1 {
max-width: 285px;
margin: 0;
font-size: clamp(26px, 2.7vw, 35px);
line-height: 1.02;
letter-spacing: -0.045em;
}
.copy {
margin: 14px 0 19px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.minimum {
display: grid;
grid-template-columns: 1fr auto;
align-items: end;
gap: 14px;
padding: 15px 16px;
border: 1px solid rgba(22, 155, 131, 0.18);
border-radius: 17px;
background: linear-gradient(135deg, rgba(217, 240, 233, 0.85), rgba(255, 255, 255, 0.55));
}
.minimum-label {
display: block;
margin-bottom: 5px;
color: var(--green);
font-size: 9px;
font-weight: 850;
letter-spacing: 0.15em;
}
.minimum strong {
font-size: 17px;
letter-spacing: -0.03em;
}
.minimum-number {
font-size: 52px;
font-weight: 850;
line-height: 0.78;
letter-spacing: -0.08em;
color: var(--green);
}
.rule-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 7px;
margin: 10px 0 16px;
}
.rule {
min-height: 74px;
padding: 10px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(255, 255, 255, 0.48);
}
.rule span {
display: block;
margin-bottom: 6px;
color: var(--muted);
font-size: 8px;
font-weight: 800;
letter-spacing: 0.12em;
}
.rule strong {
display: block;
font-size: 12px;
line-height: 1.25;
}
.rule em {
display: block;
margin-top: 4px;
color: var(--red);
font-size: 9px;
font-style: normal;
font-weight: 700;
}
.validation {
display: grid;
grid-template-columns: auto 1fr;
column-gap: 10px;
align-items: center;
padding: 12px 13px;
border: 1px solid rgba(22, 155, 131, 0.15);
border-radius: 14px;
background: rgba(217, 240, 233, 0.55);
}
.validation-dot {
grid-row: 1 / 3;
width: 12px;
height: 12px;
border: 3px solid rgba(22, 155, 131, 0.18);
border-radius: 50%;
background: var(--green);
box-shadow: 0 0 0 3px rgba(22, 155, 131, 0.1);
}
.validation strong {
display: block;
color: var(--green);
font-size: 10px;
letter-spacing: 0.13em;
}
.validation span {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.panel-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin-top: 12px;
}
.action-button {
min-height: 44px;
padding: 10px 11px;
border-radius: 13px;
cursor: pointer;
font-size: 10px;
font-weight: 800;
line-height: 1.25;
transition:
transform 160ms ease,
box-shadow 160ms ease,
background 160ms ease;
}
.action-button:hover {
transform: translateY(-1px);
}
.action-button.primary {
border: 1px solid var(--ink);
background: var(--ink);
color: white;
box-shadow: 0 8px 18px rgba(24, 49, 45, 0.16);
}
.action-button.secondary {
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.58);
color: var(--ink);
}
.action-button.secondary[aria-pressed="true"] {
border-color: rgba(22, 155, 131, 0.24);
background: var(--green-soft);
color: #087763;
}
.scene-caption {
position: absolute;
left: 50%;
bottom: 28px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 10px;
padding: 9px 14px;
border: 1px solid rgba(24, 49, 45, 0.1);
border-radius: 999px;
background: rgba(247, 248, 243, 0.7);
color: var(--muted);
font-size: 9px;
font-weight: 700;
letter-spacing: 0.06em;
backdrop-filter: blur(12px);
white-space: nowrap;
}
.scene-caption kbd {
padding: 3px 6px;
border: 1px solid rgba(24, 49, 45, 0.13);
border-radius: 5px;
background: rgba(255, 255, 255, 0.6);
color: var(--ink);
font: inherit;
font-size: 8px;
}
.legend {
position: absolute;
right: 28px;
bottom: 28px;
display: flex;
gap: 15px;
padding: 12px 15px;
border: 1px solid rgba(24, 49, 45, 0.11);
border-radius: 15px;
background: rgba(247, 248, 243, 0.74);
box-shadow: 0 12px 30px rgba(24, 49, 45, 0.08);
backdrop-filter: blur(14px);
}
.legend-item {
display: flex;
align-items: center;
gap: 6px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.swatch.start {
background: var(--green);
}
.swatch.path {
background: #f6f8f3;
border: 1px solid #c9d2ca;
}
.swatch.connector {
background: var(--gold);
}
.swatch.forbidden {
background: #332f31;
border: 1px solid var(--red);
}
#world-labels {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px;
border: 1px solid rgba(24, 49, 45, 0.13);
border-radius: 9px;
background: rgba(250, 251, 247, 0.88);
box-shadow: 0 7px 20px rgba(24, 49, 45, 0.1);
color: var(--ink);
font-size: 8px;
font-weight: 850;
letter-spacing: 0.12em;
white-space: nowrap;
backdrop-filter: blur(9px);
}
.world-label::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--green);
}
.world-label.goal::before {
background: var(--coral);
}
.world-label.connector {
border-color: rgba(230, 173, 59, 0.3);
}
.world-label.connector::before {
background: var(--gold);
}
.world-label.forbidden {
border-color: rgba(200, 76, 73, 0.3);
color: #9d3f3c;
}
.world-label.forbidden::before {
background: var(--red);
}
.world-label small {
color: var(--muted);
font-size: 7px;
font-weight: 700;
letter-spacing: 0.05em;
}
#adjacency-badges {
position: fixed;
inset: 0;
z-index: 2;
pointer-events: none;
opacity: 1;
transition: opacity 180ms ease;
}
#adjacency-badges.hidden {
opacity: 0;
}
.adjacency-badge {
position: absolute;
transform: translate(-50%, -50%);
display: flex;
align-items: center;
justify-content: center;
min-width: 24px;
height: 24px;
padding: 0 7px;
border: 2px solid rgba(255, 255, 255, 0.9);
border-radius: 999px;
background: var(--green);
box-shadow: 0 5px 14px rgba(22, 155, 131, 0.25);
color: white;
font-size: 9px;
font-weight: 850;
}
@media (max-width: 760px) {
.topbar {
padding: 16px;
}
.live-pill {
display: none;
}
.panel {
top: 74px;
left: 14px;
width: calc(100vw - 28px);
padding: 16px;
border-radius: 19px;
}
h1 {
max-width: none;
font-size: 23px;
}
.copy,
.rule-grid {
display: none;
}
.minimum {
margin-top: 14px;
padding: 11px 13px;
}
.minimum-number {
font-size: 39px;
}
.minimum strong {
font-size: 14px;
}
.panel-actions {
margin-top: 9px;
}
.legend,
.scene-caption {
display: none;
}
.world-label {
padding: 5px 7px;
font-size: 7px;
}
}
@media (max-height: 680px) and (min-width: 761px) {
.panel {
top: 82px;
padding: 18px;
}
.copy {
margin: 10px 0 13px;
}
.minimum {
padding: 11px 13px;
}
.rule-grid {
margin-bottom: 11px;
}
.rule {
min-height: 60px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive 3D path adjacency scene"></canvas>
<div id="world-labels">
<div class="world-label start" id="label-start">START</div>
<div class="world-label goal" id="label-goal">GOAL</div>
<div class="world-label connector" id="label-connector">
CONNECTOR <small>bridge piece</small>
</div>
<div class="world-label forbidden" id="label-forbidden">
FORBIDDEN <small>no floor tile</small>
</div>
</div>
<div id="adjacency-badges"></div>
<div class="hud">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div class="brand-copy">
<span>PATH LAB / 04</span>
<strong>Adjacency systems</strong>
</div>
</div>
<div class="top-actions">
<div class="live-pill">LIVE GENERATION</div>
<button class="quiet-button" id="reset-view" type="button">
Reset view
</button>
</div>
</header>
<aside class="panel">
<div class="eyebrow">Generation guardrail</div>
<h1>Every tile must have an edge.</h1>
<p class="copy">
A generated route may bend, but it cannot rely on diagonal contact.
The connector may span the forbidden cell; its two landings still need
full-edge neighbors.
</p>
<div class="minimum">
<div>
<span class="minimum-label">MINIMUM ADJACENCY</span>
<strong>One orthogonal neighbor</strong>
</div>
<div class="minimum-number">01</div>
</div>
<div class="rule-grid">
<div class="rule">
<span>ENDPOINT</span>
<strong>1+ neighbor</strong>
<em>Start / goal</em>
</div>
<div class="rule">
<span>INTERIOR</span>
<strong>2+ neighbors</strong>
<em>Continuous route</em>
</div>
<div class="rule">
<span>CONTACT</span>
<strong>Edge only</strong>
<em>Diagonals ×</em>
</div>
</div>
<div class="validation">
<div class="validation-dot"></div>
<strong id="validation-title">VALID GENERATED PATH</strong>
<span id="validation-stats">8 nodes · minimum degree 1</span>
</div>
<div class="panel-actions">
<button class="action-button primary" id="generate-path" type="button">
↻ Generate valid route
</button>
<button
class="action-button secondary"
id="toggle-guides"
type="button"
aria-pressed="true"
>
Adjacency guides: ON
</button>
</div>
</aside>
<div class="scene-caption">
<kbd>DRAG</kbd> orbit
<span>·</span>
<kbd>SCROLL</kbd> zoom
</div>
<div class="legend" aria-label="Scene legend">
<div class="legend-item"><i class="swatch start"></i>Start</div>
<div class="legend-item"><i class="swatch path"></i>Path tile</div>
<div class="legend-item"><i class="swatch connector"></i>Connector</div>
<div class="legend-item"><i class="swatch forbidden"></i>Forbidden</div>
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.getElementById("scene");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9eee8);
scene.fog = new THREE.Fog(0xe9eee8, 18, 32);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
const camera = new THREE.OrthographicCamera(-8, 8, 5, -5, 0.1, 100);
const cameraState = {
azimuth: 0.72,
polar: 0.9,
zoom: 1,
target: new THREE.Vector3(-0.75, 0.05, 0.1)
};
const hemi = new THREE.HemisphereLight(0xf8fff8, 0x84968b, 2.4);
scene.add(hemi);
const key = new THREE.DirectionalLight(0xfff7df, 4.1);
key.position.set(-5, 10, 7);
key.castShadow = true;
key.shadow.mapSize.set(2048, 2048);
key.shadow.camera.left = -9;
key.shadow.camera.right = 9;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -9;
key.shadow.camera.near = 1;
key.shadow.camera.far = 30;
key.shadow.bias = -0.00035;
key.shadow.normalBias = 0.025;
scene.add(key);
const rim = new THREE.DirectionalLight(0xb9d8ff, 1.45);
rim.position.set(8, 5, -7);
scene.add(rim);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(100, 100),
new THREE.MeshStandardMaterial({
color: 0xe9eee8,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.39;
ground.receiveShadow = true;
scene.add(ground);
function roundedShape(width, depth, radius) {
const x = -width / 2;
const y = -depth / 2;
const shape = new THREE.Shape();
shape.moveTo(x + radius, y);
shape.lineTo(x + width - radius, y);
shape.quadraticCurveTo(x + width, y, x + width, y + radius);
shape.lineTo(x + width, y + depth - radius);
shape.quadraticCurveTo(
x + width,
y + depth,
x + width - radius,
y + depth
);
shape.lineTo(x + radius, y + depth);
shape.quadraticCurveTo(x, y + depth, x, y + depth - radius);
shape.lineTo(x, y + radius);
shape.quadraticCurveTo(x, y, x + radius, y);
return shape;
}
function roundedPrismGeometry(width, depth, height, radius) {
const geometry = new THREE.ExtrudeGeometry(roundedShape(width, depth, radius), {
depth: height,
bevelEnabled: true,
bevelThickness: 0.035,
bevelSize: 0.035,
bevelSegments: 3,
curveSegments: 8,
steps: 1
});
geometry.rotateX(-Math.PI / 2);
geometry.computeVertexNormals();
return geometry;
}
const boardGeometry = roundedPrismGeometry(8.7, 6.3, 0.34, 0.42);
const board = new THREE.Mesh(boardGeometry, [
new THREE.MeshStandardMaterial({
color: 0xd9ded7,
roughness: 0.82,
metalness: 0
}),
new THREE.MeshStandardMaterial({
color: 0xaebbb2,
roughness: 0.9,
metalness: 0
})
]);
board.position.y = -0.33;
board.castShadow = true;
board.receiveShadow = true;
scene.add(board);
const gridVertices = [];
for (let x = -3.5; x <= 3.5; x += 1) {
gridVertices.push(x, 0.035, -2.5, x, 0.035, 2.5);
}
for (let z = -2.5; z <= 2.5; z += 1) {
gridVertices.push(-3.5, 0.035, z, 3.5, 0.035, z);
}
const gridGeometry = new THREE.BufferGeometry();
gridGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(gridVertices, 3)
);
const grid = new THREE.LineSegments(
gridGeometry,
new THREE.LineBasicMaterial({
color: 0x6d8177,
transparent: true,
opacity: 0.2
})
);
scene.add(grid);
const cornerMaterial = new THREE.MeshStandardMaterial({
color: 0x91a098,
roughness: 0.55,
metalness: 0.35
});
for (const x of [-3.92, 3.92]) {
for (const z of [-2.62, 2.62]) {
const pin = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.035, 20),
cornerMaterial
);
pin.position.set(x, 0.07, z);
pin.castShadow = true;
scene.add(pin);
}
}
const pitGeometry = roundedPrismGeometry(0.92, 0.92, 0.035, 0.13);
const pit = new THREE.Mesh(
pitGeometry,
new THREE.MeshStandardMaterial({
color: 0x272628,
roughness: 0.72,
metalness: 0.18
})
);
pit.position.set(0, 0.025, 0);
pit.receiveShadow = true;
scene.add(pit);
const hazardMaterial = new THREE.MeshStandardMaterial({
color: 0xc84c49,
roughness: 0.52,
metalness: 0.08,
emissive: 0x5b100d,
emissiveIntensity: 0.16
});
for (const z of [-0.47, 0.47]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.98, 0.035, 0.045),
hazardMaterial
);
rail.position.set(0, 0.085, z);
rail.castShadow = true;
scene.add(rail);
}
for (const x of [-0.47, 0.47]) {
const rail = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.035, 0.98),
hazardMaterial
);
rail.position.set(x, 0.085, 0);
rail.castShadow = true;
scene.add(rail);
}
function horizontalCylinderBetween(a, b, radius, material) {
const midpoint = a.clone().add(b).multiplyScalar(0.5);
const direction = b.clone().sub(a);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, direction.length(), 12),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
return mesh;
}
const forbiddenMark = new THREE.Group();
forbiddenMark.add(
horizontalCylinderBetween(
new THREE.Vector3(-0.31, 0.082, -0.31),
new THREE.Vector3(0.31, 0.082, 0.31),
0.018,
hazardMaterial
)
);
forbiddenMark.add(
horizontalCylinderBetween(
new THREE.Vector3(-0.31, 0.083, 0.31),
new THREE.Vector3(0.31, 0.083, -0.31),
0.018,
hazardMaterial
)
);
scene.add(forbiddenMark);
const tileGeometry = roundedPrismGeometry(0.9, 0.9, 0.17, 0.13);
const materials = {
path: {
face: new THREE.MeshStandardMaterial({
color: 0xf7f8f3,
roughness: 0.56,
metalness: 0.02
}),
side: new THREE.MeshStandardMaterial({
color: 0xb8c6be,
roughness: 0.72,
metalness: 0.03
})
},
start: {
face: new THREE.MeshStandardMaterial({
color: 0x169b83,
roughness: 0.43,
metalness: 0.08,
emissive: 0x073d34,
emissiveIntensity: 0.1
}),
side: new THREE.MeshStandardMaterial({
color: 0x0c6f5f,
roughness: 0.58,
metalness: 0.1
})
},
goal: {
face: new THREE.MeshStandardMaterial({
color: 0xec705e,
roughness: 0.43,
metalness: 0.08,
emissive: 0x4e120b,
emissiveIntensity: 0.08
}),
side: new THREE.MeshStandardMaterial({
color: 0xb94d41,
roughness: 0.6,
metalness: 0.08
})
}
};
const connectorGeometry = roundedPrismGeometry(1.16, 0.42, 0.16, 0.12);
const connectorMaterial = {
face: new THREE.MeshStandardMaterial({
color: 0xe6ad3b,
roughness: 0.32,
metalness: 0.58,
emissive: 0x5a3704,
emissiveIntensity: 0.08
}),
side: new THREE.MeshStandardMaterial({
color: 0x9e7422,
roughness: 0.46,
metalness: 0.52
})
};
const whiteMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.45,
metalness: 0.02
});
const dotMaterial = new THREE.MeshStandardMaterial({
color: 0x92a39a,
roughness: 0.6,
metalness: 0.12
});
function makeStartArrow() {
const shape = new THREE.Shape();
shape.moveTo(-0.16, -0.065);
shape.lineTo(0.025, -0.065);
shape.lineTo(0.025, -0.15);
shape.lineTo(0.18, 0);
shape.lineTo(0.025, 0.15);
shape.lineTo(0.025, 0.065);
shape.lineTo(-0.16, 0.065);
shape.closePath();
const geometry = new THREE.ShapeGeometry(shape);
geometry.rotateX(-Math.PI / 2);
const arrow = new THREE.Mesh(geometry, whiteMaterial);
arrow.position.y = 0.205;
arrow.castShadow = true;
return arrow;
}
function makeGoalMark() {
const group = new THREE.Group();
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.14, 0.027, 10, 36),
whiteMaterial
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.205;
group.add(ring);
const checkA = horizontalCylinderBetween(
new THREE.Vector3(-0.09, 0.215, 0.055),
new THREE.Vector3(-0.015, 0.215, -0.055),
0.022,
whiteMaterial
);
const checkB = horizontalCylinderBetween(
new THREE.Vector3(-0.015, 0.216, -0.055),
new THREE.Vector3(0.12, 0.216, 0.07),
0.022,
whiteMaterial
);
group.add(checkA, checkB);
return group;
}
function createTile(node, index, nextNode) {
const group = new THREE.Group();
const isConnector = node.kind === "connector";
const isStart = node.kind === "start";
const isGoal = node.kind === "goal";
const baseY = isConnector ? 0.16 : 0.065;
group.position.set(node.x, baseY, node.z);
const geometry = isConnector ? connectorGeometry : tileGeometry;
const materialSet = isConnector
? connectorMaterial
: isStart
? materials.start
: isGoal
? materials.goal
: materials.path;
const mesh = new THREE.Mesh(geometry, [
materialSet.face,
materialSet.side
]);
mesh.castShadow = true;
mesh.receiveShadow = true;
group.add(mesh);
if (isStart) {
const arrow = makeStartArrow();
if (nextNode) {
const dx = nextNode.x - node.x;
const dz = nextNode.z - node.z;
arrow.rotation.y = Math.atan2(-dz, dx);
}
group.add(arrow);
} else if (isGoal) {
group.add(makeGoalMark());
} else if (isConnector) {
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x8e681d,
roughness: 0.5,
metalness: 0.35
});
for (const x of [-0.25, 0, 0.25]) {
const groove = new THREE.Mesh(
new THREE.BoxGeometry(0.045, 0.018, 0.27),
grooveMaterial
);
groove.position.set(x, 0.18, 0);
group.add(groove);
}
} else {
const dot = new THREE.Mesh(
new THREE.CylinderGeometry(0.045, 0.045, 0.012, 18),
dotMaterial
);
dot.position.y = 0.19;
group.add(dot);
}
group.userData.baseY = baseY;
group.userData.delay = index * 45;
group.scale.y = 0.02;
return group;
}
const adjacencyGroup = new THREE.Group();
scene.add(adjacencyGroup);
const adjacencyMaterial = new THREE.LineBasicMaterial({
color: 0x00a98d,
transparent: true,
opacity: 0.72,
depthTest: false
});
const badgeContainer = document.getElementById("adjacency-badges");
const validationTitle = document.getElementById("validation-title");
const validationStats = document.getElementById("validation-stats");
const toggleButton = document.getElementById("toggle-guides");
let routeGroup = null;
let currentRoute = [];
let animationStart = 0;
let guidesVisible = true;
let generation = 1;
function distance(a, b) {
return Math.abs(a.x - b.x) + Math.abs(a.z - b.z);
}
function analyzeRoute(route) {
const degrees = route.map(() => 0);
for (let i = 0; i < route.length; i++) {
for (let j = i + 1; j < route.length; j++) {
if (distance(route[i], route[j]) === 1) {
degrees[i]++;
degrees[j]++;
}
}
}
const consecutiveEdgesValid = route.every(
(node, index) => index === 0 || distance(route[index - 1], node) === 1
);
const minimumDegree = Math.min(...degrees);
const valid =
route[0]?.kind === "start" &&
route.at(-1)?.kind === "goal" &&
consecutiveEdgesValid &&
degrees.every((degree) => degree >= 1);
return { degrees, minimumDegree, valid };
}
function rebuildAdjacency(route, degrees) {
while (adjacencyGroup.children.length) {
const child = adjacencyGroup.children[0];
adjacencyGroup.remove(child);
child.geometry?.dispose();
}
badgeContainer.replaceChildren();
for (let i = 0; i < route.length - 1; i++) {
const a = route[i];
const b = route[i + 1];
const geometry = new THREE.BufferGeometry().setFromPoints([
new THREE.Vector3(a.x, 0.53, a.z),
new THREE.Vector3(b.x, 0.53, b.z)
]);
const line = new THREE.Line(geometry, adjacencyMaterial);
line.computeLineDistances();
line.renderOrder = 20;
adjacencyGroup.add(line);
}
route.forEach((node, index) => {
const badge = document.createElement("div");
badge.className = "adjacency-badge";
badge.textContent = degrees[index];
badge.dataset.index = index;
badgeContainer.appendChild(badge);
});
}
function buildRoute(route) {
currentRoute = route.map((node) => ({ ...node }));
if (routeGroup) {
scene.remove(routeGroup);
}
routeGroup = new THREE.Group();
scene.add(routeGroup);
route.forEach((node, index) => {
const next = route[index + 1];
const tile = createTile(node, index, next);
routeGroup.add(tile);
});
const analysis = analyzeRoute(currentRoute);
rebuildAdjacency(currentRoute, analysis.degrees);
validationTitle.textContent = analysis.valid
? "VALID GENERATED PATH"
: "INVALID GENERATED PATH";
validationStats.textContent =
`${currentRoute.length} nodes · minimum degree ${analysis.minimumDegree}`;
animationStart = performance.now();
}
const directions = [
{ x: 1, z: 0 },
{ x: 0, z: 1 },
{ x: -1, z: 0 },
{ x: 0, z: -1 }
];
function shuffledDirections(seed) {
const result = [...directions];
let value = seed * 9301 + 49297;
for (let i = result.length - 1; i > 0; i--) {
value = (value * 9301 + 49297) % 233280;
const j = Math.floor((value / 233280) * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
function findRoute(start, end, bounds, seed) {
const visited = new Set();
const orderedDirections = shuffledDirections(seed);
function dfs(node, path) {
const key = `${node.x},${node.z}`;
if (node.x === end.x && node.z === end.z) {
return path;
}
visited.add(key);
for (const direction of orderedDirections) {
const next = {
x: node.x + direction.x,
z: node.z + direction.z
};
if (
next.x < bounds.minX ||
next.x > bounds.maxX ||
next.z < bounds.minZ ||
next.z > bounds.maxZ
) {
continue;
}
const nextKey = `${next.x},${next.z}`;
if (visited.has(nextKey)) continue;
const result = dfs(next, [...path, next]);
if (result) return result;
}
return null;
}
return dfs(start, [start]);
}
function generateRoute() {
const seed = generation++;
const left = findRoute(
{ x: -3, z: 1 },
{ x: -1, z: 0 },
{ minX: -3, maxX: -1, minZ: -2, maxZ: 2 },
seed
);
const right = findRoute(
{ x: 1, z: 0 },
{ x: 2, z: -1 },
{ minX: 1, maxX: 3, minZ: -2, maxZ: 2 },
seed + 17
);
if (!left || !right) return;
const route = [
...left.map((node, index) => ({
...node,
kind: index === 0 ? "start" : "path"
})),
{ x: 0, z: 0, kind: "connector" },
...right.map((node, index) => ({
...node,
kind: index === right.length - 1 ? "goal" : "path"
}))
];
buildRoute(route);
}
generateRoute();
toggleButton.addEventListener("click", () => {
guidesVisible = !guidesVisible;
adjacencyGroup.visible = guidesVisible;
badgeContainer.classList.toggle("hidden", !guidesVisible);
toggleButton.setAttribute("aria-pressed", String(guidesVisible));
toggleButton.textContent = `Adjacency guides: ${guidesVisible ? "ON" : "OFF"}`;
});
document
.getElementById("generate-path")
.addEventListener("click", generateRoute);
function updateCamera() {
const radius = 15;
const { azimuth, polar, zoom, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(polar) * Math.cos(azimuth),
target.y + radius * Math.cos(polar),
target.z + radius * Math.sin(polar) * Math.sin(azimuth)
);
camera.lookAt(target);
const aspect = window.innerWidth / window.innerHeight;
const viewHeight = Math.max(9.2, 10.8 / aspect) / zoom;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
updateCamera();
document.getElementById("reset-view").addEventListener("click", () => {
cameraState.azimuth = 0.72;
cameraState.polar = 0.9;
cameraState.zoom = 1;
cameraState.target.set(-0.75, 0.05, 0.1);
updateCamera();
});
const pointers = new Map();
let gestureDistance = 0;
function getPointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
gestureDistance = getPointerDistance();
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
const previous = pointers.get(event.pointerId);
if (!previous) return;
const oldDistance = getPointerDistance();
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
cameraState.azimuth -=
(event.clientX - previous.x) * 0.006;
cameraState.polar = THREE.MathUtils.clamp(
cameraState.polar +
(event.clientY - previous.y) * 0.004,
0.48,
1.22
);
} else if (pointers.size === 2) {
const newDistance = getPointerDistance();
if (oldDistance > 0 && newDistance > 0) {
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * (oldDistance / newDistance),
0.72,
1.55
);
}
}
updateCamera();
});
function endPointer(event) {
pointers.delete(event.pointerId);
gestureDistance = getPointerDistance();
if (!pointers.size) canvas.classList.remove("dragging");
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.zoom = THREE.MathUtils.clamp(
cameraState.zoom * Math.exp(-event.deltaY * 0.001),
0.72,
1.55
);
updateCamera();
},
{ passive: false }
);
const labelDefinitions = [
{
element: document.getElementById("label-start"),
position: new THREE.Vector3(-3, 0.68, 1),
offset: [0, -12]
},
{
element: document.getElementById("label-goal"),
position: new THREE.Vector3(2, 0.7, -1),
offset: [0, -12]
},
{
element: document.getElementById("label-connector"),
position: new THREE.Vector3(0, 0.95, 0),
offset: [0, -15]
},
{
element: document.getElementById("label-forbidden"),
position: new THREE.Vector3(0, 0.08, 0),
offset: [0, 55]
}
];
function projectToScreen(position) {
const projected = position.clone().project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight,
visible:
projected.z >= -1 &&
projected.z <= 1 &&
projected.x >= -1.2 &&
projected.x <= 1.2 &&
projected.y >= -1.2 &&
projected.y <= 1.2
};
}
function updateLabels() {
for (const definition of labelDefinitions) {
const screen = projectToScreen(definition.position);
definition.element.style.left = `${screen.x + definition.offset[0]}px`;
definition.element.style.top = `${screen.y + definition.offset[1]}px`;
definition.element.style.opacity = screen.visible ? "1" : "0";
}
const badges = badgeContainer.querySelectorAll(".adjacency-badge");
currentRoute.forEach((node, index) => {
const badge = badges[index];
if (!badge) return;
const screen = projectToScreen(
new THREE.Vector3(node.x, node.kind === "connector" ? 0.82 : 0.7, node.z)
);
badge.style.left = `${screen.x}px`;
badge.style.top = `${screen.y}px`;
badge.style.visibility = screen.visible ? "visible" : "hidden";
});
}
function resize() {
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
updateCamera();
}
window.addEventListener("resize", resize);
function animate(time) {
requestAnimationFrame(animate);
if (routeGroup) {
routeGroup.children.forEach((tile) => {
const delay = tile.userData.delay;
const progress = THREE.MathUtils.clamp(
(time - animationStart - delay) / 420,
0,
1
);
const eased = 1 - Math.pow(1 - progress, 3);
tile.scale.y = Math.max(0.02, eased);
tile.position.y =
tile.userData.baseY + (1 - eased) * 0.24;
});
}
updateLabels();
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```