Prompt specification
Build or customize the Three.js 3D scene "Jigsaw connector polarity pairs" 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: Jigsaw connector polarity pairs
Category: Games & Play · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/jigsaw-connector-polarity-pairs-x0341
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows four thick jigsaw pieces in a clean stylized solid style. Give the pieces a mixture of projecting tabs, recessed sockets, and flat outer-boundary edges. Lay them on a neutral tabletop with enough spacing to inspect every profile. Bring one matching tab-and-socket pair together along a visible insertion direction, while keeping an obviously incompatible pair beside it for comparison. The matching profiles should meet without overlapping the solid pieces, and the incompatible pair should stop at contact.
Working Three.js Starter (jigsaw-connector-polarity-pairs-x0341):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Jigsaw Profile Study</title>
<style>
:root {
color-scheme: light;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #eceae5;
color: #262a2b;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.ui {
position: fixed;
z-index: 10;
pointer-events: none;
}
.heading {
top: 22px;
left: 24px;
max-width: 390px;
}
.eyebrow {
margin-bottom: 6px;
color: #6e7474;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(23px, 3vw, 36px);
font-weight: 760;
letter-spacing: -0.035em;
}
.subtitle {
margin-top: 7px;
color: #697071;
font-size: 13px;
line-height: 1.45;
}
.legend {
top: 22px;
right: 24px;
display: flex;
gap: 10px;
align-items: stretch;
}
.card {
min-width: 190px;
padding: 13px 15px;
border: 1px solid rgba(38, 42, 43, 0.11);
border-radius: 14px;
background: rgba(250, 249, 246, 0.88);
box-shadow: 0 9px 30px rgba(37, 42, 43, 0.08);
backdrop-filter: blur(12px);
}
.card-title {
display: flex;
gap: 8px;
align-items: center;
font-size: 13px;
font-weight: 760;
}
.dot {
width: 10px;
height: 10px;
border-radius: 50%;
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}
.dot.match {
background: linear-gradient(90deg, #ef6a55 50%, #2a9d8f 50%);
}
.dot.mismatch {
background: linear-gradient(90deg, #e9b949 50%, #7067cf 50%);
}
.card small {
display: block;
margin-top: 5px;
color: #73797a;
font-size: 11px;
}
.controls {
right: 24px;
bottom: 22px;
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
border: 1px solid rgba(38, 42, 43, 0.13);
border-radius: 11px;
padding: 10px 14px;
background: rgba(250, 249, 246, 0.92);
color: #303536;
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
box-shadow: 0 7px 24px rgba(37, 42, 43, 0.08);
backdrop-filter: blur(10px);
transition: transform 150ms ease, background 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff;
}
button:disabled {
cursor: default;
opacity: 0.62;
transform: none;
}
.hint {
left: 24px;
bottom: 25px;
color: #73797a;
font-size: 11px;
letter-spacing: 0.015em;
}
@media (max-width: 820px) {
.heading {
top: 16px;
left: 16px;
max-width: calc(100vw - 32px);
}
.subtitle {
display: none;
}
.legend {
top: auto;
right: 16px;
bottom: 64px;
flex-direction: column;
}
.card {
min-width: 175px;
padding: 9px 12px;
}
.controls {
right: 16px;
bottom: 16px;
}
.hint {
left: 16px;
bottom: 22px;
max-width: 110px;
line-height: 1.4;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui heading">
<div class="eyebrow">Solid profile study</div>
<h1>Jigsaw compatibility</h1>
<div class="subtitle">
The arrow indicates the insertion direction. A complementary socket seats
flush, while an undersized socket stops at first contact.
</div>
</div>
<div class="ui legend">
<div class="card">
<div class="card-title">
<span class="dot match"></span>
Matching pair
</div>
<small>Identical curved profiles · fully seated</small>
</div>
<div class="card">
<div class="card-title">
<span class="dot mismatch"></span>
Incompatible pair
</div>
<small>Large tab · shallow socket · blocked</small>
</div>
</div>
<div class="ui controls">
<button id="replay" type="button">Replay insertion</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="ui hint">Drag to orbit · Scroll to zoom · Shift-drag to pan</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, camera, and lights
// -------------------------------------------------------------------------
const container = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false
});
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;
container.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xeceae5);
scene.fog = new THREE.Fog(0xeceae5, 16, 31);
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
100
);
const homeView = {
target: new THREE.Vector3(0.45, 0.1, 0.15),
radius: 12.4,
theta: 0.32,
phi: 0.72
};
const orbit = {
target: homeView.target.clone(),
radius: homeView.radius,
theta: homeView.theta,
phi: homeView.phi
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
const cosPhi = Math.cos(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * cosPhi,
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xffffff, 0xa7a39b, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff8ed, 3.15);
keyLight.position.set(-5.5, 10, 7.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 28;
keyLight.shadow.normalBias = 0.025;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xdde9ff, 1.1);
fillLight.position.set(7, 5, -6);
scene.add(fillLight);
// Neutral tabletop
const tabletop = new THREE.Mesh(
new THREE.PlaneGeometry(34, 23),
new THREE.MeshStandardMaterial({
color: 0xd8d5cf,
roughness: 0.96,
metalness: 0
})
);
tabletop.rotation.x = -Math.PI / 2;
tabletop.position.y = 0;
tabletop.receiveShadow = true;
scene.add(tabletop);
// -------------------------------------------------------------------------
// Jigsaw profile functions
//
// Each function returns the x-coordinate of one vertical edge at height y.
// The matching pair uses exactly the same function on opposite sides.
// -------------------------------------------------------------------------
const clamp01 = (v) => Math.max(0, Math.min(1, v));
const smoothstep = (t) => t * t * (3 - 2 * t);
function matchingProfile(y) {
if (y <= -0.92 || y >= 0.92) return 0;
if (y < -0.58) {
const t = clamp01((y + 0.92) / 0.34);
return 0.16 * smoothstep(t);
}
if (y <= 0.42) {
const t = clamp01((y + 0.58) / 1.0);
return (
0.16 +
0.5 * Math.pow(Math.sin(Math.PI * t), 1.15)
);
}
const t = clamp01((0.92 - y) / 0.50);
return 0.16 * (1 - smoothstep(t));
}
function oversizedTabProfile(y) {
if (y <= -0.92 || y >= 0.92) return 0;
if (y < -0.58) {
const t = clamp01((y + 0.92) / 0.34);
return 0.18 * smoothstep(t);
}
if (y <= 0.42) {
const t = clamp01((y + 0.58) / 1.0);
return (
0.18 +
0.68 * Math.pow(Math.sin(Math.PI * t), 1.08)
);
}
const t = clamp01((0.92 - y) / 0.50);
return 0.18 * (1 - smoothstep(t));
}
function shallowSocketProfile(y) {
if (y <= -0.92 || y >= 0.92) return 0;
if (y < -0.58) {
const t = clamp01((y + 0.92) / 0.34);
return 0.08 * smoothstep(t);
}
if (y <= 0.42) {
const t = clamp01((y + 0.58) / 1.0);
return (
0.08 +
0.30 * Math.pow(Math.sin(Math.PI * t), 1.08)
);
}
const t = clamp01((0.92 - y) / 0.50);
return 0.08 * (1 - smoothstep(t));
}
// -------------------------------------------------------------------------
// Shape construction
// -------------------------------------------------------------------------
const BODY_LEFT = -1.48;
const BODY_RIGHT = 1.48;
const BODY_HALF_HEIGHT = 1.25;
const PROFILE_STEP = 0.025;
function sampledYs() {
const values = [];
const count = Math.ceil(
(2 * BODY_HALF_HEIGHT) / PROFILE_STEP
);
for (let i = 0; i <= count; i++) {
values.push(
-BODY_HALF_HEIGHT +
(2 * BODY_HALF_HEIGHT * i) / count
);
}
return values;
}
// A left-hand piece: solid lies to the left of the profiled edge.
function makeLeftPiece(profileFunction) {
const shape = new THREE.Shape();
const ys = sampledYs();
shape.moveTo(BODY_LEFT, -BODY_HALF_HEIGHT);
shape.lineTo(0, -BODY_HALF_HEIGHT);
for (const y of ys) {
shape.lineTo(profileFunction(y), y);
}
shape.lineTo(BODY_LEFT, BODY_HALF_HEIGHT);
shape.closePath();
return shape;
}
// A right-hand piece: solid lies to the right of the profiled edge.
function makeRightPiece(profileFunction) {
const shape = new THREE.Shape();
const ys = sampledYs();
shape.moveTo(0, -BODY_HALF_HEIGHT);
shape.lineTo(BODY_RIGHT, -BODY_HALF_HEIGHT);
shape.lineTo(BODY_RIGHT, BODY_HALF_HEIGHT);
shape.lineTo(0, BODY_HALF_HEIGHT);
for (let i = ys.length - 1; i >= 0; i--) {
const y = ys[i];
shape.lineTo(profileFunction(y), y);
}
shape.closePath();
return shape;
}
function createPiece(shape, topColor, sideColor) {
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.42,
steps: 1,
bevelEnabled: true,
bevelSegments: 4,
bevelSize: 0.035,
bevelThickness: 0.035,
curveSegments: 18
});
// Shape XY becomes tabletop XZ; extrusion becomes world Y.
geometry.rotateX(-Math.PI / 2);
geometry.computeBoundingBox();
geometry.translate(0, -geometry.boundingBox.min.y, 0);
geometry.computeBoundingBox();
const topMaterial = new THREE.MeshStandardMaterial({
color: topColor,
roughness: 0.57,
metalness: 0.02
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: sideColor,
roughness: 0.72,
metalness: 0.01
});
const mesh = new THREE.Mesh(geometry, [
topMaterial,
sideMaterial
]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.topY = geometry.boundingBox.max.y;
const outline = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 32),
new THREE.LineBasicMaterial({
color: 0x303536,
transparent: true,
opacity: 0.22
})
);
mesh.add(outline);
scene.add(mesh);
return mesh;
}
const MATCH_X = -2.0;
const MATCH_Z = -0.45;
const BAD_X = 2.55;
const BAD_Z = -0.45;
// The two matching pieces use exactly the same boundary function and
// are placed at the same origin. Their solids meet but do not overlap.
const pieceA = createPiece(
makeLeftPiece(matchingProfile),
0xef6a55,
0xb9493a
);
const pieceB = createPiece(
makeRightPiece(matchingProfile),
0x2a9d8f,
0x207568
);
pieceA.position.set(MATCH_X, 0.018, MATCH_Z);
pieceB.position.set(MATCH_X, 0.018, MATCH_Z);
// Find the exact separation at which the oversized tab first touches
// the shallow socket. This guarantees no interpenetration.
let badSeparation = -Infinity;
let contactY = 0;
for (const y of sampledYs()) {
const difference =
oversizedTabProfile(y) - shallowSocketProfile(y);
if (difference > badSeparation) {
badSeparation = difference;
contactY = y;
}
}
const pieceC = createPiece(
makeLeftPiece(oversizedTabProfile),
0xe9b949,
0xb48c29
);
const pieceD = createPiece(
makeRightPiece(shallowSocketProfile),
0x7067cf,
0x5148a9
);
pieceC.position.set(BAD_X, 0.018, BAD_Z);
pieceD.position.set(
BAD_X + badSeparation,
0.018,
BAD_Z
);
// -------------------------------------------------------------------------
// Seam and contact annotations
// -------------------------------------------------------------------------
const topY =
pieceA.userData.topY + pieceA.position.y;
const seamPoints = [];
for (const y of sampledYs()) {
seamPoints.push(
new THREE.Vector3(
MATCH_X + matchingProfile(y),
topY + 0.012,
MATCH_Z - y
)
);
}
const seam = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(seamPoints),
new THREE.LineBasicMaterial({
color: 0x263b3a,
transparent: true,
opacity: 0.55
})
);
seam.renderOrder = 4;
scene.add(seam);
const contactX =
BAD_X + oversizedTabProfile(contactY);
const contactZ = BAD_Z - contactY;
const contactMarker = new THREE.Mesh(
new THREE.SphereGeometry(0.065, 20, 20),
new THREE.MeshBasicMaterial({
color: 0xc9473d,
depthTest: false
})
);
contactMarker.position.set(
contactX,
topY + 0.075,
contactZ
);
contactMarker.renderOrder = 8;
scene.add(contactMarker);
const contactRing = new THREE.Mesh(
new THREE.TorusGeometry(0.12, 0.018, 10, 36),
new THREE.MeshBasicMaterial({
color: 0xc9473d,
depthTest: false
})
);
contactRing.rotation.x = Math.PI / 2;
contactRing.position.set(
contactX,
topY + 0.055,
contactZ
);
contactRing.renderOrder = 8;
scene.add(contactRing);
// -------------------------------------------------------------------------
// Insertion-direction arrows
// -------------------------------------------------------------------------
function createArrow(origin, direction, color, length) {
const arrow = new THREE.ArrowHelper(
direction,
origin,
length,
color,
0.23,
0.15
);
arrow.line.material.depthTest = false;
arrow.cone.material.depthTest = false;
arrow.line.material.transparent = true;
arrow.cone.material.transparent = true;
arrow.line.material.opacity = 0.94;
arrow.cone.material.opacity = 0.94;
arrow.line.renderOrder = 7;
arrow.cone.renderOrder = 7;
scene.add(arrow);
return arrow;
}
// The right piece travels left into the left piece's tab.
createArrow(
new THREE.Vector3(
MATCH_X + 1.28,
topY + 0.24,
MATCH_Z + 0.18
),
new THREE.Vector3(-1, 0, 0),
0x216f68,
0.82
);
// The incompatible right piece also travels left, but stops at contact.
createArrow(
new THREE.Vector3(
BAD_X + badSeparation + 1.16,
topY + 0.24,
BAD_Z + 0.18
),
new THREE.Vector3(-1, 0, 0),
0xc9473d,
0.77
);
// -------------------------------------------------------------------------
// Tabletop labels
// -------------------------------------------------------------------------
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 createPlaque(title, subtitle, accent, x, z) {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(
ctx,
8,
8,
canvas.width - 16,
canvas.height - 16,
36
);
ctx.fillStyle = "rgba(248,247,243,0.91)";
ctx.fill();
ctx.lineWidth = 9;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "#293031";
ctx.font = "800 54px Inter, Arial, sans-serif";
ctx.fillText(title, canvas.width / 2, 96);
ctx.fillStyle = "#727879";
ctx.font = "600 31px Inter, Arial, sans-serif";
ctx.fillText(subtitle, canvas.width / 2, 163);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
const plaque = new THREE.Mesh(
new THREE.PlaneGeometry(3.45, 0.86),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
depthWrite: false,
toneMapped: false
})
);
plaque.rotation.x = -Math.PI / 2;
plaque.position.set(x, 0.035, z);
plaque.renderOrder = 2;
scene.add(plaque);
}
createPlaque(
"MATCHING PROFILE",
"IDENTICAL TAB + SOCKET / SEATED",
"#367d74",
MATCH_X + 0.12,
MATCH_Z + 1.92
);
createPlaque(
"MISMATCHED PROFILE",
"LARGE TAB + SHALLOW SOCKET / STOPPED",
"#b76538",
BAD_X + 0.52,
BAD_Z + 1.92
);
// -------------------------------------------------------------------------
// Direct camera controls — no external controls module
// -------------------------------------------------------------------------
const canvas = renderer.domElement;
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
if (event.shiftKey || event.buttons === 2) {
const scale = orbit.radius * 0.00125;
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const right = new THREE.Vector3()
.crossVectors(forward, camera.up)
.normalize();
orbit.target.addScaledVector(right, -dx * scale);
orbit.target.addScaledVector(forward, dy * scale);
} else {
orbit.theta -= dx * 0.006;
orbit.phi = Math.max(
0.28,
Math.min(1.36, orbit.phi - dy * 0.005)
);
}
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined) {
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", (event) => event.preventDefault());
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = Math.max(
7,
Math.min(21, orbit.radius * Math.exp(event.deltaY * 0.001))
);
updateCamera();
},
{ passive: false }
);
function resetView() {
orbit.target.copy(homeView.target);
orbit.radius = homeView.radius;
orbit.theta = homeView.theta;
orbit.phi = homeView.phi;
updateCamera();
}
document.getElementById("reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Replay animation
// -------------------------------------------------------------------------
const replayButton = document.getElementById("replay");
let replayStart = null;
const easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
function startReplay() {
replayStart = performance.now();
replayButton.disabled = true;
replayButton.textContent = "Replaying…";
seam.visible = false;
pieceB.position.x = MATCH_X + 1.05;
pieceD.position.x = BAD_X + badSeparation + 0.72;
}
replayButton.addEventListener("click", startReplay);
function updateReplay(now) {
if (replayStart === null) return;
const t = Math.min((now - replayStart) / 1800, 1);
const matchingProgress = Math.min(t / 0.82, 1);
const matchingEase = easeOutCubic(matchingProgress);
pieceB.position.x =
MATCH_X + 1.05 * (1 - matchingEase);
const contactProgress = Math.min(t / 0.72, 1);
const contactEase = easeOutCubic(contactProgress);
let incompatibleOffset =
0.72 * (1 - contactEase);
// A tiny recoil makes the blocked insertion readable without overlap.
if (t > 0.72 && t < 0.94) {
incompatibleOffset +=
0.022 *
Math.exp(-10 * (t - 0.72)) *
Math.sin((t - 0.72) * 75);
}
pieceD.position.x =
BAD_X + badSeparation + incompatibleOffset;
if (t >= 1) {
replayStart = null;
pieceB.position.x = MATCH_X;
pieceD.position.x = BAD_X + badSeparation;
seam.visible = true;
replayButton.disabled = false;
replayButton.textContent = "Replay insertion";
}
}
// -------------------------------------------------------------------------
// Resize and render loop
// -------------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
function animate(now) {
requestAnimationFrame(animate);
updateReplay(now);
renderer.render(scene, camera);
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```