Prompt specification
Build or customize the Three.js 3D scene "Gap-free tiling patch" 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: Gap-free tiling patch
Category: Algorithms & Systems · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/gap-free-tiling-patch-x1741
Scene Description Prompt:
Cover a low-poly plane with regular triangles, squares, or hexagons meeting exactly along visible edges. One HTML file using Three.js from cdnjs.
Working Three.js Starter (gap-free-tiling-patch-x1741):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Edge / Plane — Procedural Tessellation</title>
<style>
:root {
color-scheme: dark;
--accent: #5eead4;
--panel: rgba(8, 18, 32, 0.76);
--border: rgba(148, 210, 230, 0.2);
--text: #e7f7fb;
--muted: #91aebc;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #07111f;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
canvas {
position: fixed;
inset: 0;
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 35%, rgba(2, 8, 16, 0.36) 100%);
}
#ui {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
pointer-events: auto;
background: var(--panel);
border: 1px solid var(--border);
border-radius: 16px;
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
}
#brand {
top: 22px;
left: 22px;
width: min(350px, calc(100vw - 44px));
padding: 19px 20px 17px;
}
.eyebrow {
margin-bottom: 8px;
color: var(--accent);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(25px, 4vw, 36px);
font-weight: 650;
letter-spacing: -0.045em;
line-height: 1;
}
.description {
margin: 11px 0 15px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
#readout {
display: flex;
flex-wrap: wrap;
gap: 7px;
}
.chip {
padding: 5px 8px;
border: 1px solid rgba(148, 210, 230, 0.15);
border-radius: 999px;
background: rgba(255, 255, 255, 0.035);
color: #bdd1da;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.07em;
text-transform: uppercase;
}
#camera-panel {
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 8px;
}
button {
min-height: 38px;
padding: 0 13px;
border: 1px solid rgba(148, 210, 230, 0.16);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #c9dce4;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 150ms ease,
border-color 150ms ease,
color 150ms ease,
transform 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.09);
border-color: rgba(148, 210, 230, 0.35);
color: white;
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
button.active {
border-color: rgba(94, 234, 212, 0.65);
background: rgba(45, 212, 191, 0.16);
color: #d8fff8;
}
#mode-panel {
bottom: 22px;
left: 50%;
display: flex;
gap: 8px;
padding: 9px;
transform: translateX(-50%);
}
#mode-panel button {
min-width: 112px;
}
#hint {
position: absolute;
right: 22px;
bottom: 24px;
color: rgba(183, 211, 222, 0.68);
font-size: 11px;
text-align: right;
line-height: 1.5;
}
@media (max-width: 720px) {
#brand {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
}
.description {
display: none;
}
#camera-panel {
top: auto;
right: 14px;
bottom: 82px;
}
#mode-panel {
bottom: 14px;
width: calc(100vw - 28px);
}
#mode-panel button {
flex: 1;
min-width: 0;
padding: 0 9px;
}
#hint {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly polygon plane"></canvas>
<div id="vignette"></div>
<main id="ui">
<section id="brand" class="panel">
<div class="eyebrow">Procedural Tessellation</div>
<h1>Edge / Plane</h1>
<p class="description">
Regular polygons generated on one continuous lattice.
Every visible boundary is shared exactly, with no gaps or overlaps.
</p>
<div id="readout">
<span class="chip" id="cell-chip">450 cells</span>
<span class="chip" id="side-chip">Side 0.92</span>
<span class="chip">Edge matched</span>
</div>
</section>
<section id="camera-panel" class="panel" aria-label="Camera controls">
<button id="orbit-button" aria-pressed="false">Auto orbit</button>
<button id="reset-button" title="Reset camera">Reset</button>
<button id="zoom-out" aria-label="Zoom out">−</button>
<button id="zoom-in" aria-label="Zoom in">+</button>
</section>
<nav id="mode-panel" class="panel" aria-label="Polygon type">
<button data-mode="tri" class="active">Triangles</button>
<button data-mode="square">Squares</button>
<button data-mode="hex">Hexagons</button>
</nav>
<div id="hint">
Drag to orbit · Scroll or pinch to zoom<br>
Keys: 1 / 2 / 3 · R · Space
</div>
</main>
<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.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.022);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
150
);
const hemisphere = new THREE.HemisphereLight(0xc8f4ff, 0x101522, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 2.7);
keyLight.position.set(-9, 14, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -24;
keyLight.shadow.camera.right = 24;
keyLight.shadow.camera.top = 24;
keyLight.shadow.camera.bottom = -24;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 45;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x2dd4bf, 1.15);
rimLight.position.set(10, 7, -11);
scene.add(rimLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(140, 140),
new THREE.MeshStandardMaterial({
color: 0x081421,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.11;
ground.receiveShadow = true;
scene.add(ground);
const cameraState = {
yaw: 0.62,
pitch: 0.82,
distance: 25,
target: new THREE.Vector3(0, 0, 0),
autoOrbit: false
};
const modeSettings = {
tri: {
side: 0.92,
colors: [
0x14b8a6,
0x2dd4bf,
0x06b6d4,
0x0ea5e9,
0xf59e0b
]
},
square: {
side: 0.88,
colors: [
0xf97316,
0xfb923c,
0xf59e0b,
0xfbbf24,
0x22d3ee
]
},
hex: {
side: 0.78,
colors: [
0x2563eb,
0x3b82f6,
0x06b6d4,
0x14b8a6,
0xa78bfa
]
}
};
let tileGroup = null;
let activeMode = "tri";
function random01(index, seed) {
const value = Math.sin((index + 1) * 12.9898 + seed * 78.233) * 43758.5453;
return value - Math.floor(value);
}
function centeredPolygons(polygons) {
let minX = Infinity;
let maxX = -Infinity;
let minZ = Infinity;
let maxZ = -Infinity;
for (const polygon of polygons) {
for (const point of polygon) {
minX = Math.min(minX, point.x);
maxX = Math.max(maxX, point.x);
minZ = Math.min(minZ, point.z);
maxZ = Math.max(maxZ, point.z);
}
}
const centerX = (minX + maxX) * 0.5;
const centerZ = (minZ + maxZ) * 0.5;
for (const polygon of polygons) {
for (const point of polygon) {
point.x -= centerX;
point.z -= centerZ;
}
}
return {
polygons,
width: maxX - minX,
depth: maxZ - minZ
};
}
function createTriangles(side) {
const polygons = [];
const columns = 19;
const rows = 16;
const height = side * Math.sqrt(3) * 0.5;
const latticePoint = (column, row) => ({
x: (column + row * 0.5) * side,
z: row * height
});
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
polygons.push([
latticePoint(column, row),
latticePoint(column + 1, row),
latticePoint(column, row + 1)
]);
polygons.push([
latticePoint(column + 1, row),
latticePoint(column, row + 1),
latticePoint(column + 1, row + 1)
]);
}
}
return centeredPolygons(polygons);
}
function createSquares(side) {
const polygons = [];
const columns = 21;
const rows = 16;
const half = side * 0.5;
for (let row = 0; row < rows; row++) {
for (let column = 0; column < columns; column++) {
const centerX = column * side;
const centerZ = row * side;
polygons.push([
{ x: centerX - half, z: centerZ - half },
{ x: centerX + half, z: centerZ - half },
{ x: centerX + half, z: centerZ + half },
{ x: centerX - half, z: centerZ + half }
]);
}
}
return centeredPolygons(polygons);
}
function createHexagons(side) {
const polygons = [];
const columns = 15;
const rows = 13;
const rowHeight = Math.sqrt(3) * side;
for (let column = 0; column < columns; column++) {
const offset = column % 2 === 0 ? 0 : rowHeight * 0.5;
for (let row = 0; row < rows; row++) {
const centerX = column * side * 1.5;
const centerZ = row * rowHeight + offset;
const polygon = [];
for (let vertex = 0; vertex < 6; vertex++) {
const angle = vertex * Math.PI / 3;
polygon.push({
x: centerX + Math.cos(angle) * side,
z: centerZ + Math.sin(angle) * side
});
}
polygons.push(polygon);
}
}
return centeredPolygons(polygons);
}
function appendPolygon(
polygon,
color,
positions,
colors,
edges,
edgeKeys
) {
const points = polygon.slice();
// XZ-plane winding is reversed so the visible face points toward +Y.
let signedArea = 0;
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
signedArea += a.x * b.z - b.x * a.z;
}
if (signedArea > 0) {
points.reverse();
}
for (let i = 1; i < points.length - 1; i++) {
const triangle = [points[0], points[i], points[i + 1]];
for (const point of triangle) {
positions.push(point.x, 0, point.z);
colors.push(color.r, color.g, color.b);
}
}
// Add each shared edge only once.
for (let i = 0; i < points.length; i++) {
const a = points[i];
const b = points[(i + 1) % points.length];
const keyA = `${a.x.toFixed(5)},${a.z.toFixed(5)}`;
const keyB = `${b.x.toFixed(5)},${b.z.toFixed(5)}`;
const key = keyA < keyB ? `${keyA}|${keyB}` : `${keyB}|${keyA}`;
if (!edgeKeys.has(key)) {
edgeKeys.add(key);
edges.push(
a.x, 0.014, a.z,
b.x, 0.014, b.z
);
}
}
}
function disposeTileGroup() {
if (!tileGroup) return;
scene.remove(tileGroup);
tileGroup.traverse((object) => {
if (object.geometry) {
object.geometry.dispose();
}
if (object.material) {
object.material.dispose();
}
});
tileGroup = null;
}
function buildMode(mode) {
disposeTileGroup();
activeMode = mode;
const settings = modeSettings[mode];
let pattern;
if (mode === "tri") {
pattern = createTriangles(settings.side);
} else if (mode === "square") {
pattern = createSquares(settings.side);
} else {
pattern = createHexagons(settings.side);
}
const positions = [];
const colors = [];
const edgePositions = [];
const edgeKeys = new Set();
pattern.polygons.forEach((polygon, index) => {
const random = random01(index, mode.length * 3.1);
const paletteIndex = Math.floor(random * settings.colors.length);
const color = new THREE.Color(settings.colors[paletteIndex]);
color.offsetHSL(
(random - 0.5) * 0.025,
(random - 0.5) * 0.07,
(random - 0.5) * 0.08
);
appendPolygon(
polygon,
color,
positions,
colors,
edgePositions,
edgeKeys
);
});
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial({
vertexColors: true,
flatShading: true,
roughness: 0.82,
metalness: 0.08,
side: THREE.FrontSide
});
const surface = new THREE.Mesh(geometry, material);
surface.castShadow = true;
surface.receiveShadow = false;
const edgeGeometry = new THREE.BufferGeometry();
edgeGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(edgePositions, 3)
);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x06131d,
transparent: true,
opacity: 0.8,
depthWrite: false
});
const edgeLines = new THREE.LineSegments(edgeGeometry, edgeMaterial);
tileGroup = new THREE.Group();
tileGroup.add(surface, edgeLines);
scene.add(tileGroup);
const requiredDistance = Math.max(pattern.width, pattern.depth) * 1.18;
cameraState.distance = Math.max(cameraState.distance, requiredDistance);
document.querySelector("#cell-chip").textContent =
`${pattern.polygons.length} cells`;
document.querySelector("#side-chip").textContent =
`Side ${settings.side.toFixed(2)}`;
document.querySelectorAll("[data-mode]").forEach((button) => {
const selected = button.dataset.mode === mode;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
});
}
function updateCamera() {
const { yaw, pitch, distance, target } = cameraState;
const horizontalDistance = Math.cos(pitch) * distance;
camera.position.set(
target.x + horizontalDistance * Math.sin(yaw),
target.y + Math.sin(pitch) * distance,
target.z + horizontalDistance * Math.cos(yaw)
);
camera.lookAt(target);
}
function resetCamera() {
cameraState.yaw = 0.62;
cameraState.pitch = 0.82;
cameraState.distance = Math.max(
20,
Math.max(
activeMode === "tri" ? 22.4 : activeMode === "square" ? 19.7 : 17.6,
20
) * 1.18
);
updateCamera();
}
function zoomBy(factor) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * factor,
8,
45
);
updateCamera();
}
// Direct pointer controls: one pointer orbits; two pointers pinch-zoom.
const pointers = new Map();
function pointerDistance() {
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
});
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const oldDistance = pointerDistance();
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.yaw -= dx * 0.006;
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + dy * 0.005,
0.22,
1.46
);
} else if (pointers.size === 2) {
const newDistance = pointerDistance();
if (oldDistance > 0 && newDistance > 0) {
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * (oldDistance / newDistance),
8,
45
);
}
}
updateCamera();
});
function releasePointer(event) {
pointers.delete(event.pointerId);
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", releasePointer);
canvas.addEventListener("pointercancel", releasePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance * Math.exp(event.deltaY * 0.001),
8,
45
);
updateCamera();
},
{ passive: false }
);
document.querySelectorAll("[data-mode]").forEach((button) => {
button.addEventListener("click", () => {
buildMode(button.dataset.mode);
});
});
document.querySelector("#reset-button").addEventListener("click", resetCamera);
document.querySelector("#zoom-in").addEventListener("click", () => zoomBy(0.85));
document.querySelector("#zoom-out").addEventListener("click", () => zoomBy(1.15));
const orbitButton = document.querySelector("#orbit-button");
orbitButton.addEventListener("click", () => {
cameraState.autoOrbit = !cameraState.autoOrbit;
orbitButton.classList.toggle("active", cameraState.autoOrbit);
orbitButton.setAttribute("aria-pressed", String(cameraState.autoOrbit));
});
window.addEventListener("keydown", (event) => {
if (event.key === "1") buildMode("tri");
if (event.key === "2") buildMode("square");
if (event.key === "3") buildMode("hex");
if (event.key.toLowerCase() === "r") resetCamera();
if (event.code === "Space") {
event.preventDefault();
orbitButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
buildMode("tri");
resetCamera();
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (cameraState.autoOrbit) {
cameraState.yaw += delta * 0.08;
}
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```