Prompt specification
Build or customize the Three.js 3D scene "Hook-and-loop magnified 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: Hook-and-loop magnified patch
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/hook-and-loop-magnified-patch-x0593
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts hook-and-loop fasteners. Show two fabric straps beside enlarged symbolic hooks and loops; their interlocking surfaces should face each other while the smooth backing remains visibly separate. Stylized solid forms.
Working Three.js Starter (hook-and-loop-magnified-patch-x0593):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hook & Loop Fastener</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: #f2ede3;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
top: clamp(18px, 3vw, 38px);
left: clamp(18px, 3vw, 42px);
z-index: 2;
width: min(340px, calc(100vw - 36px));
pointer-events: none;
color: #252b2e;
}
.eyebrow {
margin-bottom: 9px;
color: #798084;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.2em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 54px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
}
.subtitle {
max-width: 290px;
margin: 14px 0 0;
color: #687176;
font-size: 13px;
line-height: 1.55;
}
.legend {
position: fixed;
right: clamp(16px, 2.5vw, 34px);
bottom: clamp(16px, 2.5vw, 30px);
z-index: 3;
display: flex;
gap: 18px;
align-items: center;
padding: 12px 15px;
border: 1px solid rgba(57, 67, 72, 0.12);
border-radius: 14px;
background: rgba(255, 253, 248, 0.82);
box-shadow: 0 12px 40px rgba(55, 49, 38, 0.09);
backdrop-filter: blur(12px);
color: #4d565a;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.045em;
}
.legend-item {
display: flex;
gap: 7px;
align-items: center;
white-space: nowrap;
}
.swatch {
width: 10px;
height: 10px;
border-radius: 50%;
}
.swatch.hook {
background: #f6b83f;
box-shadow: 0 0 0 3px rgba(246, 184, 63, 0.18);
}
.swatch.loop {
background: #38bca9;
box-shadow: 0 0 0 3px rgba(56, 188, 169, 0.18);
}
#reset {
position: fixed;
right: clamp(16px, 2.5vw, 34px);
top: clamp(16px, 2.5vw, 30px);
z-index: 3;
padding: 10px 14px;
border: 1px solid rgba(57, 67, 72, 0.14);
border-radius: 999px;
background: rgba(255, 253, 248, 0.82);
box-shadow: 0 8px 28px rgba(55, 49, 38, 0.07);
color: #4d565a;
font: inherit;
font-size: 11px;
font-weight: 750;
cursor: pointer;
backdrop-filter: blur(12px);
}
#reset:hover {
background: #fffdf8;
color: #20282b;
}
.hint {
position: fixed;
left: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 2.5vw, 30px);
z-index: 2;
color: #8a9295;
font-size: 10px;
font-weight: 650;
letter-spacing: 0.08em;
text-transform: uppercase;
pointer-events: none;
}
@media (max-width: 650px) {
.subtitle {
display: none;
}
.legend {
left: 16px;
right: auto;
bottom: 17px;
}
.hint {
display: none;
}
#reset {
top: 18px;
right: 16px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive three-dimensional hook-and-loop fastener"></canvas>
<header class="title-card">
<div class="eyebrow">Material study / 01</div>
<h1>Hook &<br />Loop</h1>
<p class="subtitle">
Two fabric straps meet at a magnified symbolic interlock.
The colored smooth backings remain distinct.
</p>
</header>
<div class="legend" aria-hidden="true">
<div class="legend-item">
<span class="swatch hook"></span>
<span>HOOK</span>
</div>
<div class="legend-item">
<span class="swatch loop"></span>
<span>LOOP</span>
</div>
</div>
<button id="reset" type="button">Reset view</button>
<div class="hint">Drag to orbit · Wheel or pinch to zoom</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.querySelector("#scene");
const resetButton = document.querySelector("#reset");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xf2ede3);
scene.fog = new THREE.Fog(0xf2ede3, 19, 39);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const hemisphere = new THREE.HemisphereLight(
0xfff9ed,
0x77756e,
2.15
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff3da, 3.4);
keyLight.position.set(-5.5, 9.5, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.00025;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xbdebe4, 1.65);
fillLight.position.set(7, 4, -6);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffb991, 1.1);
rimLight.position.set(-8, 2, -4);
scene.add(rimLight);
const groundMaterial = new THREE.MeshStandardMaterial({
color: 0xe8e1d5,
roughness: 0.97,
metalness: 0
});
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50),
groundMaterial
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -2.65;
ground.receiveShadow = true;
scene.add(ground);
const materials = {
coralBacking: new THREE.MeshStandardMaterial({
color: 0xef6254,
roughness: 0.32,
metalness: 0.05
}),
tealBacking: new THREE.MeshStandardMaterial({
color: 0x18a99d,
roughness: 0.32,
metalness: 0.05
}),
hookFabric: new THREE.MeshStandardMaterial({
color: 0x8b2e43,
roughness: 0.92,
metalness: 0
}),
loopFabric: new THREE.MeshStandardMaterial({
color: 0x08716e,
roughness: 0.92,
metalness: 0
}),
hook: new THREE.MeshStandardMaterial({
color: 0xf8bd45,
roughness: 0.3,
metalness: 0.16
}),
loop: new THREE.MeshStandardMaterial({
color: 0x7ce0ce,
roughness: 0.34,
metalness: 0.08
}),
stitch: new THREE.MeshStandardMaterial({
color: 0xffe7cd,
roughness: 0.8,
metalness: 0
})
};
function roundedShape(width, height, radius) {
const w = width / 2;
const h = height / 2;
const r = Math.min(radius, w, h);
const shape = new THREE.Shape();
shape.moveTo(-w + r, -h);
shape.lineTo(w - r, -h);
shape.quadraticCurveTo(w, -h, w, -h + r);
shape.lineTo(w, h - r);
shape.quadraticCurveTo(w, h, w - r, h);
shape.lineTo(-w + r, h);
shape.quadraticCurveTo(-w, h, -w, h - r);
shape.lineTo(-w, -h + r);
shape.quadraticCurveTo(-w, -h, -w + r, -h);
return shape;
}
function roundedPanel(width, height, depth, radius, material) {
const geometry = new THREE.ExtrudeGeometry(
roundedShape(width, height, radius),
{
depth,
steps: 1,
bevelEnabled: true,
bevelSegments: 4,
bevelSize: Math.min(0.07, depth * 0.22),
bevelThickness: Math.min(0.06, depth * 0.18)
}
);
geometry.translate(0, 0, -depth / 2);
geometry.computeVertexNormals();
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.receiveShadow = true;
return mesh;
}
function addStitches(parent, side) {
const stitchGeometry = new THREE.BoxGeometry(0.045, 0.145, 0.028);
for (const x of [-1.19, 1.19]) {
for (let y = -2.15; y <= 2.16; y += 0.31) {
const stitch = new THREE.Mesh(stitchGeometry, materials.stitch);
stitch.position.set(x, y, 0.155);
stitch.castShadow = true;
parent.add(stitch);
}
}
// Small transverse stitch groups emphasize the woven construction.
for (const y of [-2.38, 2.38]) {
for (let x = -0.96; x <= 0.97; x += 0.24) {
const stitch = new THREE.Mesh(stitchGeometry, materials.stitch);
stitch.rotation.z = Math.PI / 2;
stitch.position.set(x, y, 0.155);
parent.add(stitch);
}
}
}
const smallHookCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0, 0.15),
new THREE.Vector3(0.018, 0, 0.23),
new THREE.Vector3(0.085, 0, 0.285),
new THREE.Vector3(0.15, 0, 0.255),
new THREE.Vector3(0.13, 0, 0.195)
],
false,
"catmullrom",
0.45
);
const smallHookGeometry = new THREE.TubeGeometry(
smallHookCurve,
20,
0.029,
7,
false
);
const macroHookCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(0, 0, 0),
new THREE.Vector3(0, 0, 0.36),
new THREE.Vector3(0.025, 0, 0.71),
new THREE.Vector3(0.09, 0, 1.01),
new THREE.Vector3(0.27, 0, 1.27),
new THREE.Vector3(0.51, 0, 1.35),
new THREE.Vector3(0.66, 0, 1.22),
new THREE.Vector3(0.59, 0, 1.03),
new THREE.Vector3(0.43, 0, 0.96)
],
false,
"catmullrom",
0.5
);
const macroHookGeometry = new THREE.TubeGeometry(
macroHookCurve,
64,
0.073,
12,
false
);
const smallLoopGeometry = new THREE.TorusGeometry(
0.132,
0.038,
10,
30
);
const macroLoopGeometry = new THREE.TorusGeometry(
0.39,
0.069,
14,
56
);
function addSmallHooks(parent, x, y) {
const hook = new THREE.Mesh(smallHookGeometry, materials.hook);
hook.position.set(x, y, 0.205);
hook.rotation.y = Math.PI * 0.04;
hook.castShadow = true;
parent.add(hook);
}
function addSmallLoop(parent, x, y) {
const loop = new THREE.Mesh(smallLoopGeometry, materials.loop);
loop.position.set(x, y, 0.455);
loop.scale.y = 1.12;
loop.castShadow = true;
parent.add(loop);
const postGeometry = new THREE.CylinderGeometry(
0.028,
0.033,
0.24,
8
);
const post = new THREE.Mesh(postGeometry, materials.loop);
post.rotation.x = Math.PI / 2;
post.position.set(x + 0.105, y, 0.33);
post.castShadow = true;
parent.add(post);
}
function createStrap(side) {
const root = new THREE.Group();
const inwardAngle = 1.08;
root.position.set(side * 1.55, 0.2, 0);
root.rotation.y = side < 0 ? inwardAngle : -inwardAngle;
const backingMaterial =
side < 0 ? materials.coralBacking : materials.tealBacking;
const faceMaterial =
side < 0 ? materials.hookFabric : materials.loopFabric;
const backing = roundedPanel(
2.6,
5.2,
0.27,
0.34,
backingMaterial
);
root.add(backing);
const fabricFace = roundedPanel(
2.2,
4.65,
0.065,
0.25,
faceMaterial
);
fabricFace.position.z = 0.165;
root.add(fabricFace);
addStitches(root, side);
const columns = [-0.72, 0, 0.72];
const rows = [-1.82, -1.12, -0.42, 0.28, 0.98, 1.68];
for (const x of columns) {
for (const y of rows) {
// Leave the center open for the enlarged symbolic connection.
if (Math.abs(x) < 0.35 && Math.abs(y) < 0.55) continue;
if (side < 0) {
addSmallHooks(root, x, y);
} else {
addSmallLoop(root, x, y);
}
}
}
if (side < 0) {
const enlargedHook = new THREE.Mesh(
macroHookGeometry,
materials.hook
);
enlargedHook.position.set(0, 0, 0.205);
enlargedHook.castShadow = true;
enlargedHook.receiveShadow = true;
root.add(enlargedHook);
const collar = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.15, 0.11, 20),
materials.hook
);
collar.rotation.x = Math.PI / 2;
collar.position.set(0, 0, 0.245);
collar.castShadow = true;
root.add(collar);
} else {
const enlargedLoop = new THREE.Mesh(
macroLoopGeometry,
materials.loop
);
enlargedLoop.position.set(0, 0, 1.12);
enlargedLoop.scale.y = 1.08;
enlargedLoop.castShadow = true;
enlargedLoop.receiveShadow = true;
root.add(enlargedLoop);
const legGeometry = new THREE.CylinderGeometry(
0.052,
0.064,
0.89,
12
);
for (const x of [-0.265, 0.265]) {
const leg = new THREE.Mesh(legGeometry, materials.loop);
leg.rotation.x = Math.PI / 2;
leg.position.set(x, 0, 0.655);
leg.castShadow = true;
root.add(leg);
}
const footGeometry = new THREE.CylinderGeometry(
0.09,
0.1,
0.08,
16
);
for (const x of [-0.265, 0.265]) {
const foot = new THREE.Mesh(footGeometry, materials.loop);
foot.rotation.x = Math.PI / 2;
foot.position.set(x, 0, 0.215);
foot.castShadow = true;
root.add(foot);
}
}
scene.add(root);
return root;
}
createStrap(-1);
createStrap(1);
// A subtle inlaid line behind the straps anchors the display.
const lineMaterial = new THREE.MeshStandardMaterial({
color: 0xd7cfc0,
roughness: 1
});
const line = new THREE.Mesh(
new THREE.BoxGeometry(8.6, 0.025, 0.22),
lineMaterial
);
line.position.set(0, -2.625, 0);
line.receiveShadow = true;
scene.add(line);
// Camera orbit controls implemented without addons.
const target = new THREE.Vector3(0, 0.12, 0);
const defaultView = {
radius: 13.7,
theta: 0.42,
phi: 1.19
};
let radius = defaultView.radius;
let theta = defaultView.theta;
let phi = defaultView.phi;
const pointers = new Map();
let previousPinchDistance = 0;
function updateCamera() {
const sinPhiRadius = Math.sin(phi) * radius;
camera.position.set(
target.x + sinPhiRadius * Math.sin(theta),
target.y + Math.cos(phi) * radius,
target.z + sinPhiRadius * Math.cos(theta)
);
camera.lookAt(target);
}
function resetView() {
radius = defaultView.radius;
theta = defaultView.theta;
phi = defaultView.phi;
updateCamera();
}
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
});
if (pointers.size === 2) {
previousPinchDistance = pointerDistance();
}
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
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;
theta -= dx * 0.006;
phi = THREE.MathUtils.clamp(phi + dy * 0.005, 0.48, 1.48);
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
radius = THREE.MathUtils.clamp(
radius * (previousPinchDistance / distance),
8,
23
);
}
previousPinchDistance = distance;
}
updateCamera();
});
function removePointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointers.size === 2 ? pointerDistance() : 0;
}
canvas.addEventListener("pointerup", removePointer);
canvas.addEventListener("pointercancel", removePointer);
canvas.addEventListener("lostpointercapture", removePointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
radius = THREE.MathUtils.clamp(
radius * Math.exp(event.deltaY * 0.001),
8,
23
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
theta += 0.08;
break;
case "ArrowRight":
theta -= 0.08;
break;
case "ArrowUp":
phi = Math.max(0.48, phi - 0.06);
break;
case "ArrowDown":
phi = Math.min(1.48, phi + 0.06);
break;
case "+":
case "=":
radius = Math.max(8, radius - 0.5);
break;
case "-":
case "_":
radius = Math.min(23, radius + 0.5);
break;
case "r":
case "R":
resetView();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
resetButton.addEventListener("click", resetView);
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
updateCamera();
renderer.setAnimationLoop(() => {
renderer.render(scene, camera);
});
</script>
</body>
</html>
```