Prompt specification
Build or customize the Three.js 3D scene "Two-cord overhand knot study" 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: Two-cord overhand knot study
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/two-cord-overhand-knot-study-x0277
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows a loose overhand knot as a deliberate voxel model. Use one thick cord with contrasting colors near its two free ends, leaving the knot open enough that its full route can be inspected. Build the bends from short stepped sections, but keep adjacent sections connected without gaps. At the central crossing, one section must clearly pass above the other, with enough separation to prevent their blocks from merging. Lay the two free ends apart on the base and mark a single starting end so the viewer can trace the cord continuously through the loop.
Working Three.js Starter (two-cord-overhand-knot-study-x0277):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Overhand Knot</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(13, 20, 33, 0.82);
--border: rgba(255, 255, 255, 0.13);
--text: #eef4ff;
--muted: #aebbd0;
--start: #25d6c3;
--finish: #ff675d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #101827;
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
border-radius: 14px;
background: var(--panel);
color: var(--text);
box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
}
#info {
top: 18px;
left: 18px;
max-width: min(360px, calc(100vw - 36px));
padding: 15px 17px;
pointer-events: none;
}
h1 {
margin: 0 0 7px;
font-size: 17px;
font-weight: 700;
letter-spacing: 0.015em;
}
#info p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.legend {
display: flex;
gap: 16px;
align-items: center;
margin-top: 11px;
color: var(--muted);
font-size: 12px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 3px;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}
#start-swatch {
background: var(--start);
}
#finish-swatch {
background: var(--finish);
}
#controls {
right: 18px;
bottom: 18px;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
padding: 10px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
padding: 9px 12px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
font: inherit;
font-size: 12px;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
button:hover {
background: rgba(255, 255, 255, 0.13);
border-color: rgba(255, 255, 255, 0.28);
}
button:active {
transform: translateY(1px);
}
@media (max-width: 600px) {
#info {
top: 10px;
left: 10px;
padding: 12px 14px;
}
#controls {
right: 10px;
bottom: 10px;
left: 10px;
justify-content: center;
}
}
</style>
</head>
<body>
<canvas
id="scene"
aria-label="Interactive three-dimensional voxel model of an open overhand knot"
></canvas>
<section id="info" class="panel">
<h1>Loose Voxel Overhand</h1>
<p>
Drag to orbit · Right-drag to pan · Scroll to zoom.
The gold marker identifies the single starting end.
</p>
<div class="legend">
<span><i class="swatch" id="start-swatch"></i>Start end</span>
<span><i class="swatch" id="finish-swatch"></i>Finish end</span>
</div>
</section>
<nav id="controls" class="panel" aria-label="Camera controls">
<button id="reset" type="button">Reset view</button>
<button id="top" type="button">Top view</button>
<button id="crossing" type="button">Inspect crossing</button>
</nav>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer and scene
// -------------------------------------------------------------------------
const canvas = document.getElementById("scene");
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.12;
const scene = new THREE.Scene();
scene.background = new THREE.Color("#101827");
scene.fog = new THREE.Fog("#101827", 22, 42);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.05,
100
);
// -------------------------------------------------------------------------
// Base, grid, and lighting
// -------------------------------------------------------------------------
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0x172235,
roughness: 0.95,
metalness: 0.02
});
const base = new THREE.Mesh(
new THREE.BoxGeometry(18, 0.4, 18),
baseMaterial
);
base.position.y = -0.2;
base.receiveShadow = true;
scene.add(base);
const grid = new THREE.GridHelper(18, 36, 0x60718c, 0x33435c);
grid.position.y = 0.012;
grid.material.transparent = true;
grid.material.opacity = 0.28;
grid.material.depthWrite = false;
scene.add(grid);
const hemisphere = new THREE.HemisphereLight(0xe6f2ff, 0x1b2130, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d7, 3.7);
keyLight.position.set(-6, 12, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x83bfff, 1.45);
fillLight.position.set(9, 6, -7);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xff8e78, 0.65);
rimLight.position.set(-4, 4, -10);
scene.add(rimLight);
// -------------------------------------------------------------------------
// Continuous cord path
//
// Each path segment is axis-aligned. Long segments are divided into short
// blocks, and adjacent blocks overlap slightly so there are no gaps.
//
// The first horizontal section passes underneath the elevated vertical
// section at the central crossing.
// -------------------------------------------------------------------------
const CORD_SIZE = 0.56;
const BLOCK_STEP = 0.5;
const BLOCK_OVERLAP = 0.07;
// The lower cord rests just above the base.
const BASE_Y = CORD_SIZE / 2 + 0.025;
// The elevated section leaves a large visible gap over the lower strand.
const OVER_Y = 1.55;
const path = [
[-6.0, BASE_Y, 0.0], // Starting end
[ 1.0, BASE_Y, 0.0], // Lower strand continues toward the crossing
[ 1.0, BASE_Y, -1.0],
[ 2.0, BASE_Y, -1.0],
[ 2.0, BASE_Y, -2.0],
[ 3.0, BASE_Y, -2.0],
[ 3.0, BASE_Y, -1.0],
[ 4.0, BASE_Y, -1.0],
[ 4.0, BASE_Y, 0.0],
[ 4.0, BASE_Y, 1.0],
[ 3.0, BASE_Y, 1.0],
[ 3.0, BASE_Y, 2.0],
[ 2.0, BASE_Y, 2.0],
[ 1.0, BASE_Y, 2.0],
[ 0.0, BASE_Y, 2.0],
// Lift the cord without breaking it, then carry it over the lower strand.
[ 0.0, OVER_Y, 2.0],
[ 0.0, OVER_Y, 1.0],
[ 0.0, OVER_Y, 0.0], // Central overcrossing
[ 0.0, OVER_Y, -1.0],
[ 0.0, OVER_Y, -2.0],
// Return to the base and lay the finish end apart on the plinth.
[ 0.0, BASE_Y, -2.0],
[ 0.0, BASE_Y, -3.0],
[ 5.0, BASE_Y, -3.0] // Finish end
];
const startColor = new THREE.Color("#25d6c3");
const finishColor = new THREE.Color("#ff675d");
const middleColor = new THREE.Color("#d9ad72");
const END_BAND = 2.15;
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function colorAtDistance(distance, totalLength) {
const color = new THREE.Color();
if (distance < END_BAND) {
const t = smoothstep(distance / END_BAND);
return color.copy(middleColor).lerp(startColor, 1 - t);
}
const remaining = totalLength - distance;
if (remaining < END_BAND) {
const t = smoothstep(remaining / END_BAND);
return color.copy(middleColor).lerp(finishColor, 1 - t);
}
return color.copy(middleColor);
}
let totalLength = 0;
for (let i = 0; i < path.length - 1; i++) {
totalLength += new THREE.Vector3(
path[i + 1][0] - path[i][0],
path[i + 1][1] - path[i][1],
path[i + 1][2] - path[i][2]
).length();
}
const transforms = [];
const colors = [];
const identityQuaternion = new THREE.Quaternion();
let distanceBeforeSegment = 0;
for (let i = 0; i < path.length - 1; i++) {
const a = new THREE.Vector3(...path[i]);
const b = new THREE.Vector3(...path[i + 1]);
const direction = b.clone().sub(a);
const segmentLength = direction.length();
const axis = {
x: Math.abs(direction.x),
y: Math.abs(direction.y),
z: Math.abs(direction.z)
};
const activeAxis = Object.keys(axis).find(
key => axis[key] > 0.000001
);
direction.normalize();
const blockCount = Math.max(1, Math.ceil(segmentLength / BLOCK_STEP));
const actualStep = segmentLength / blockCount;
for (let block = 0; block < blockCount; block++) {
const center = a.clone().addScaledVector(
direction,
actualStep * (block + 0.5)
);
const scale = new THREE.Vector3(
CORD_SIZE,
CORD_SIZE,
CORD_SIZE
);
if (activeAxis === "x") {
scale.x = actualStep + BLOCK_OVERLAP;
} else if (activeAxis === "y") {
scale.y = actualStep + BLOCK_OVERLAP;
} else {
scale.z = actualStep + BLOCK_OVERLAP;
}
const matrix = new THREE.Matrix4();
matrix.compose(center, identityQuaternion, scale);
transforms.push(matrix);
const distance = distanceBeforeSegment + actualStep * (block + 0.5);
colors.push(colorAtDistance(distance, totalLength));
}
distanceBeforeSegment += segmentLength;
}
// One instanced mesh represents the entire continuous cord.
const cord = new THREE.InstancedMesh(
new THREE.BoxGeometry(1, 1, 1),
new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.02
}),
transforms.length
);
transforms.forEach((matrix, index) => {
cord.setMatrixAt(index, matrix);
cord.setColorAt(index, colors[index]);
});
cord.instanceMatrix.needsUpdate = true;
if (cord.instanceColor) {
cord.instanceColor.needsUpdate = true;
}
cord.castShadow = true;
cord.receiveShadow = true;
cord.frustumCulled = false;
cord.name = "Continuous voxel overhand cord";
scene.add(cord);
// -------------------------------------------------------------------------
// Single starting-end marker
// -------------------------------------------------------------------------
const markerMaterial = new THREE.MeshStandardMaterial({
color: 0xffd166,
emissive: 0x6b4b00,
emissiveIntensity: 0.4,
roughness: 0.5
});
const marker = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.36, 4),
markerMaterial
);
marker.rotation.z = Math.PI;
marker.position.set(path[0][0], 0.96, path[0][2]);
marker.castShadow = true;
scene.add(marker);
function createStartLabel() {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 256;
labelCanvas.height = 80;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 256, 80);
context.fillStyle = "rgba(13, 20, 33, 0.9)";
context.strokeStyle = "#ffd166";
context.lineWidth = 4;
context.beginPath();
context.roundRect(4, 4, 248, 72, 16);
context.fill();
context.stroke();
context.fillStyle = "#ffe49a";
context.font = "700 34px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText("START", 128, 42);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false,
fog: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(path[0][0], 1.48, path[0][2]);
sprite.scale.set(1.7, 0.53, 1);
sprite.renderOrder = 20;
scene.add(sprite);
}
createStartLabel();
// -------------------------------------------------------------------------
// Custom camera controls, implemented without Three.js addons
// -------------------------------------------------------------------------
const controlState = {
target: new THREE.Vector3(-0.5, 0.45, -0.5),
desiredTarget: new THREE.Vector3(-0.5, 0.45, -0.5),
theta: 0.76,
desiredTheta: 0.76,
phi: 0.86,
desiredPhi: 0.86,
radius: 16.5,
desiredRadius: 16.5,
dragging: null,
lastX: 0,
lastY: 0
};
const spherical = new THREE.Spherical();
const cameraOffset = new THREE.Vector3();
const panRight = new THREE.Vector3();
const panUp = new THREE.Vector3();
function setView(theta, phi, radius, target) {
controlState.desiredTheta = theta;
controlState.desiredPhi = phi;
controlState.desiredRadius = radius;
controlState.desiredTarget.copy(target);
}
canvas.addEventListener("contextmenu", event => {
event.preventDefault();
});
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
controlState.dragging = event.button === 0 ? "orbit" : "pan";
controlState.lastX = event.clientX;
controlState.lastY = event.clientY;
});
canvas.addEventListener("pointermove", event => {
if (!controlState.dragging) return;
const dx = event.clientX - controlState.lastX;
const dy = event.clientY - controlState.lastY;
controlState.lastX = event.clientX;
controlState.lastY = event.clientY;
if (controlState.dragging === "orbit") {
controlState.desiredTheta -= dx * 0.006;
controlState.desiredPhi = THREE.MathUtils.clamp(
controlState.desiredPhi - dy * 0.006,
0.055,
1.48
);
} else {
camera.updateMatrixWorld();
panRight.setFromMatrixColumn(camera.matrix, 0);
panUp.setFromMatrixColumn(camera.matrix, 1);
const scale = controlState.radius * 0.0015;
controlState.desiredTarget
.addScaledVector(panRight, -dx * scale)
.addScaledVector(panUp, dy * scale);
controlState.desiredTarget.y = THREE.MathUtils.clamp(
controlState.desiredTarget.y,
-1,
4
);
}
});
function endPointerDrag(event) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
controlState.dragging = null;
}
canvas.addEventListener("pointerup", endPointerDrag);
canvas.addEventListener("pointercancel", endPointerDrag);
canvas.addEventListener(
"wheel",
event => {
event.preventDefault();
controlState.desiredRadius = THREE.MathUtils.clamp(
controlState.desiredRadius * Math.exp(event.deltaY * 0.001),
5.0,
30.0
);
},
{ passive: false }
);
document.getElementById("reset").addEventListener("click", () => {
setView(
0.76,
0.86,
16.5,
new THREE.Vector3(-0.5, 0.45, -0.5)
);
});
document.getElementById("top").addEventListener("click", () => {
setView(
0,
0.055,
14.2,
new THREE.Vector3(-0.5, 0.45, -0.5)
);
});
document.getElementById("crossing").addEventListener("click", () => {
setView(
0.78,
0.66,
6.7,
new THREE.Vector3(0, 0.72, 0)
);
});
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
function updateCamera() {
const smoothing = 0.13;
controlState.theta +=
(controlState.desiredTheta - controlState.theta) * smoothing;
controlState.phi +=
(controlState.desiredPhi - controlState.phi) * smoothing;
controlState.radius +=
(controlState.desiredRadius - controlState.radius) * smoothing;
controlState.target.lerp(
controlState.desiredTarget,
smoothing
);
spherical.set(
controlState.radius,
controlState.phi,
controlState.theta
);
cameraOffset.setFromSpherical(spherical);
camera.position.copy(controlState.target).add(cameraOffset);
camera.lookAt(controlState.target);
}
function animate() {
updateCamera();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
animate();
</script>
</body>
</html>
```