Prompt specification
Build or customize the Three.js 3D scene "Peeling versus direct separation" 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: Peeling versus direct separation
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/peeling-versus-direct-separation-x0594
Scene Description Prompt:
Compare peeling and straight pulling on low-poly hook-and-loop patches, highlighting simultaneously engaged contacts. Three.js from cdnjs, one HTML file.
Working Three.js Starter (peeling-versus-direct-separation-x0594):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hook-and-Loop: Peeling vs. Straight Pulling</title>
<style>
:root {
color-scheme: dark;
--bg: #070a0f;
--panel: rgba(14, 19, 27, 0.78);
--line: rgba(255, 255, 255, 0.13);
--text: #f5f7fb;
--muted: #9aa7b8;
--peel: #ff8a4c;
--pull: #43d9dc;
--glow: #ffe36e;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
display: block;
touch-action: none;
}
.overlay {
position: fixed;
inset: 0;
pointer-events: none;
}
.masthead {
position: absolute;
top: 22px;
left: 28px;
max-width: 390px;
text-shadow: 0 2px 16px #000;
}
.eyebrow {
color: #bec8d6;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 5px 0 2px;
font-size: clamp(26px, 3vw, 43px);
line-height: 1;
letter-spacing: -0.045em;
}
.masthead p {
margin: 8px 0 0;
color: var(--muted);
font-size: 12px;
letter-spacing: 0.02em;
}
.panel-tag {
position: absolute;
top: 112px;
left: 30px;
width: min(290px, 32vw);
padding: 11px 13px 10px;
border: 1px solid var(--line);
border-left: 3px solid var(--peel);
border-radius: 4px 12px 12px 4px;
background: linear-gradient(100deg, rgba(12, 16, 23, 0.88), rgba(12, 16, 23, 0.35));
backdrop-filter: blur(10px);
}
.panel-tag.right {
right: 30px;
left: auto;
border-left: 1px solid var(--line);
border-right: 3px solid var(--pull);
border-radius: 12px 4px 4px 12px;
text-align: right;
}
.panel-tag .number {
color: var(--peel);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.right .panel-tag .number,
.panel-tag.right .number { color: var(--pull); }
.panel-tag h2 {
margin: 3px 0 4px;
font-size: 20px;
letter-spacing: -0.025em;
}
.panel-tag p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.metrics {
position: absolute;
bottom: 116px;
left: 30px;
width: 246px;
padding: 14px;
border: 1px solid var(--line);
border-radius: 14px;
background: var(--panel);
backdrop-filter: blur(14px);
box-shadow: 0 16px 45px rgba(0, 0, 0, 0.22);
}
.metrics.right {
right: 30px;
left: auto;
}
.metric-row,
.release-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 14px;
}
.metric-row span,
.release-row span {
color: var(--muted);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
}
.metric-row strong {
font-size: 18px;
font-variant-numeric: tabular-nums;
}
.meter {
height: 5px;
margin: 8px 0 13px;
overflow: hidden;
border-radius: 10px;
background: rgba(255, 255, 255, 0.08);
}
.meter i {
display: block;
width: 0;
height: 100%;
border-radius: inherit;
background: var(--peel);
box-shadow: 0 0 14px var(--peel);
transition: width 80ms linear;
}
.right .meter i {
background: var(--pull);
box-shadow: 0 0 14px var(--pull);
}
.release-row {
padding-top: 10px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.release-row b {
color: var(--peel);
font-size: 11px;
}
.right .release-row b { color: var(--pull); }
.map-label {
margin: 12px 0 7px;
color: #778397;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.contact-map {
display: grid;
grid-template-columns: repeat(13, 1fr);
gap: 3px;
max-width: 150px;
}
.right .contact-map { margin-left: auto; }
.contact-map span {
aspect-ratio: 1;
border-radius: 2px;
background: rgba(255, 255, 255, 0.09);
transition: background 90ms linear, box-shadow 90ms linear;
}
.contact-map span.active {
background: var(--peel);
box-shadow: 0 0 7px rgba(255, 138, 76, 0.85);
}
.right .contact-map span.active {
background: var(--pull);
box-shadow: 0 0 7px rgba(67, 217, 220, 0.85);
}
.legend {
position: absolute;
top: 27px;
right: 30px;
display: flex;
align-items: center;
gap: 15px;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(9, 13, 19, 0.68);
color: #bdc6d3;
font-size: 10px;
backdrop-filter: blur(10px);
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.legend i {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--glow);
box-shadow: 0 0 9px var(--glow);
}
.legend .hook {
width: 12px;
height: 3px;
border-radius: 0;
background: #cbd3df;
box-shadow: none;
}
.divider {
position: absolute;
top: 0;
bottom: 0;
left: 50%;
width: 1px;
background: linear-gradient(transparent, rgba(255,255,255,.2) 12%,
rgba(255,255,255,.2) 88%, transparent);
}
.controls {
position: absolute;
left: 50%;
bottom: 18px;
display: flex;
align-items: center;
gap: 11px;
width: min(860px, calc(100% - 32px));
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.14);
border-radius: 16px;
background: rgba(10, 14, 21, 0.88);
box-shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
backdrop-filter: blur(18px);
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
background: rgba(255, 255, 255, 0.055);
color: var(--text);
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 150ms, border-color 150ms;
}
button:hover {
background: rgba(255, 255, 255, 0.11);
border-color: rgba(255, 255, 255, 0.25);
}
button.primary {
min-width: 75px;
border-color: rgba(255, 227, 110, 0.38);
background: rgba(255, 227, 110, 0.11);
color: #ffe98c;
}
.timeline {
display: flex;
flex: 1;
align-items: center;
gap: 9px;
min-width: 150px;
}
.timeline label {
color: var(--muted);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
}
input[type="range"] {
width: 100%;
height: 4px;
accent-color: #ffe36e;
cursor: pointer;
}
#progressValue {
width: 35px;
color: #d6dde7;
font-size: 10px;
font-variant-numeric: tabular-nums;
text-align: right;
}
.toggle {
display: inline-flex;
align-items: center;
gap: 7px;
color: #b8c2d0;
font-size: 10px;
font-weight: 700;
white-space: nowrap;
cursor: pointer;
}
.toggle input {
width: 14px;
height: 14px;
accent-color: #ffe36e;
}
.hint {
position: absolute;
right: 31px;
bottom: 91px;
color: rgba(199, 210, 225, 0.52);
font-size: 9px;
letter-spacing: 0.05em;
}
@media (max-width: 850px) {
.legend { display: none; }
.masthead p { display: none; }
.panel-tag { top: 86px; }
.metrics { bottom: 104px; }
.contact-map, .map-label { display: none; }
.hint { display: none; }
}
@media (max-width: 700px) {
.masthead { top: 14px; left: 16px; }
.masthead h1 { font-size: 25px; }
.panel-tag {
top: 67px;
left: 13px;
width: calc(50% - 20px);
padding: 8px 9px;
}
.panel-tag.right {
top: calc(50% + 12px);
right: 13px;
}
.panel-tag h2 { font-size: 15px; }
.panel-tag p { display: none; }
.metrics {
top: 137px;
bottom: auto;
left: 13px;
width: calc(50% - 20px);
padding: 9px;
}
.metrics.right {
top: calc(50% + 82px);
right: 13px;
}
.metric-row strong { font-size: 14px; }
.release-row { padding-top: 6px; }
.release-row b { font-size: 9px; }
.divider {
top: 50%;
right: 0;
bottom: auto;
left: 0;
width: auto;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(255,255,255,.2) 12%,
rgba(255,255,255,.2) 88%, transparent);
}
.controls {
bottom: 8px;
width: calc(100% - 16px);
flex-wrap: wrap;
gap: 7px;
padding: 8px;
}
.timeline { order: 5; flex-basis: 100%; }
.toggle { margin-left: auto; }
}
</style>
</head>
<body>
<canvas id="view"></canvas>
<div class="overlay">
<header class="masthead">
<div class="eyebrow">Contact mechanics / 01</div>
<h1>Peel vs. Pull</h1>
<p>Low-poly hook–loop interface · 91 discrete contacts</p>
</header>
<div class="panel-tag left">
<div class="number">Method A</div>
<h2>Progressive peeling</h2>
<p>A moving peel front releases contacts sequentially.</p>
</div>
<div class="panel-tag right">
<div class="number">Method B</div>
<h2>Straight pulling</h2>
<p>The entire interface loads and releases together.</p>
</div>
<section class="metrics left">
<div class="metric-row">
<span>Engaged contacts</span>
<strong id="peelCount">91 / 91</strong>
</div>
<div class="meter"><i id="peelMeter"></i></div>
<div class="release-row">
<span>Release</span>
<b id="peelRelease">Sequential</b>
</div>
<div class="map-label">Interface contact map</div>
<div class="contact-map" id="peelMap"></div>
</section>
<section class="metrics right">
<div class="metric-row">
<span>Engaged contacts</span>
<strong id="pullCount">91 / 91</strong>
</div>
<div class="meter"><i id="pullMeter"></i></div>
<div class="release-row">
<span>Release</span>
<b id="pullRelease">Collective</b>
</div>
<div class="map-label">Interface contact map</div>
<div class="contact-map" id="pullMap"></div>
</section>
<div class="legend">
<span><i></i> engaged contact</span>
<span><i class="hook"></i> hook / loop</span>
</div>
<div class="divider"></div>
<div class="hint">Drag to orbit · Wheel to zoom · Space to pause</div>
<div class="controls">
<button class="primary" id="play">Pause</button>
<button id="restart">Restart</button>
<button id="cameraReset">Reset view</button>
<div class="timeline">
<label for="progress">Pull</label>
<input id="progress" type="range" min="0" max="1000" value="180">
<span id="progressValue">18%</span>
</div>
<label class="toggle">
<input id="showContacts" type="checkbox" checked>
Contacts
</label>
<button id="speed">1.0×</button>
</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('view');
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: 'high-performance'
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.75));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.autoClear = true;
const clamp = THREE.MathUtils.clamp;
const smooth = t => t * t * (3 - 2 * t);
const L = 8;
const W = 2.8;
const CONTACT_COLS = 13;
const CONTACT_ROWS = 7;
const CONTACT_COUNT = CONTACT_COLS * CONTACT_ROWS;
const themes = {
peel: {
background: 0x11151d,
patch: new THREE.Color(0xe96f3d),
hot: new THREE.Color(0xffc05a),
glow: 0xffe36e,
arrow: 0xffa35f
},
pull: {
background: 0x0d171b,
patch: new THREE.Color(0x27b9bd),
hot: new THREE.Color(0x8df4ee),
glow: 0x7df9ff,
arrow: 0x61e9e5
}
};
function createHookGeometry() {
const s = new THREE.Shape();
s.moveTo(-0.025, 0);
s.lineTo(0.025, 0);
s.lineTo(0.025, -0.145);
s.lineTo(0.115, -0.145);
s.lineTo(0.115, -0.205);
s.lineTo(0.075, -0.245);
s.lineTo(0.018, -0.215);
s.lineTo(-0.025, -0.18);
s.closePath();
const geometry = new THREE.ExtrudeGeometry(s, {
depth: 0.035,
bevelEnabled: false,
curveSegments: 1
});
geometry.translate(0, 0, -0.0175);
geometry.computeVertexNormals();
return geometry;
}
const hookGeometry = createHookGeometry();
const loopGeometry = new THREE.TorusGeometry(0.064, 0.017, 4, 8);
loopGeometry.rotateX(Math.PI / 2);
const contactPositions = [];
for (let row = 0; row < CONTACT_ROWS; row++) {
for (let col = 0; col < CONTACT_COLS; col++) {
contactPositions.push({
x: -3.65 + col * (7.3 / (CONTACT_COLS - 1)),
z: -1.10 + row * (2.2 / (CONTACT_ROWS - 1))
});
}
}
class FlexiblePatch {
constructor(scene, theme) {
this.nx = 24;
this.nz = 8;
this.topY = 0.22;
this.bottomY = 0.10;
this.baseColor = theme.patch.clone();
this.hotColor = theme.hot.clone();
const cols = this.nx + 1;
const rows = this.nz + 1;
const layerSize = cols * rows;
const vertexCount = layerSize * 2;
const positions = new Float32Array(vertexCount * 3);
const colors = new Float32Array(vertexCount * 3);
const indices = [];
const index = (layer, row, col) =>
layer * layerSize + row * cols + col;
for (let layer = 0; layer < 2; layer++) {
for (let row = 0; row <= this.nz; row++) {
for (let col = 0; col <= this.nx; col++) {
const i = index(layer, row, col);
positions[i * 3] = -L / 2 + col * L / this.nx;
positions[i * 3 + 1] = layer === 0 ? this.topY : this.bottomY;
positions[i * 3 + 2] = -W / 2 + row * W / this.nz;
}
}
}
for (let row = 0; row < this.nz; row++) {
for (let col = 0; col < this.nx; col++) {
const a = index(0, row, col);
const b = index(0, row, col + 1);
const c = index(0, row + 1, col);
const d = index(0, row + 1, col + 1);
indices.push(a, c, b, b, c, d);
const A = index(1, row, col);
const B = index(1, row, col + 1);
const C = index(1, row + 1, col);
const D = index(1, row + 1, col + 1);
indices.push(A, B, C, B, D, C);
}
}
// Long edges.
for (let col = 0; col < this.nx; col++) {
let a = index(0, 0, col);
let b = index(0, 0, col + 1);
let c = index(1, 0, col);
let d = index(1, 0, col + 1);
indices.push(a, b, c, b, d, c);
a = index(0, this.nz, col);
b = index(0, this.nz, col + 1);
c = index(1, this.nz, col);
d = index(1, this.nz, col + 1);
indices.push(a, c, b, b, c, d);
}
// End edges.
for (let row = 0; row < this.nz; row++) {
let a = index(0, row, 0);
let b = index(0, row + 1, 0);
let c = index(1, row, 0);
let d = index(1, row + 1, 0);
indices.push(a, c, b, b, c, d);
a = index(0, row, this.nx);
b = index(0, row + 1, this.nx);
c = index(1, row, this.nx);
d = index(1, row + 1, this.nx);
indices.push(a, b, c, b, d, c);
}
this.geometry = new THREE.BufferGeometry();
this.geometry.setAttribute(
'position',
new THREE.BufferAttribute(positions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
this.geometry.setAttribute(
'color',
new THREE.BufferAttribute(colors, 3)
.setUsage(THREE.DynamicDrawUsage)
);
this.geometry.setIndex(indices);
this.material = new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
flatShading: true,
roughness: 0.78,
metalness: 0.06,
side: THREE.DoubleSide,
emissive: this.baseColor.clone().multiplyScalar(0.055)
});
this.mesh = new THREE.Mesh(this.geometry, this.material);
this.mesh.castShadow = true;
this.mesh.receiveShadow = true;
scene.add(this.mesh);
this.tempColor = new THREE.Color();
}
update(heightAt, colorFactorAt) {
const positions = this.geometry.attributes.position.array;
const colors = this.geometry.attributes.color.array;
const cols = this.nx + 1;
const layerSize = cols * (this.nz + 1);
for (let layer = 0; layer < 2; layer++) {
for (let row = 0; row <= this.nz; row++) {
for (let col = 0; col <= this.nx; col++) {
const i = layer * layerSize + row * cols + col;
const x = positions[i * 3];
const z = positions[i * 3 + 2];
const h = heightAt(x);
const y = (layer === 0 ? this.topY : this.bottomY) + h;
positions[i * 3 + 1] = y;
const factor = clamp(colorFactorAt(x, h), 0, 1);
this.tempColor.copy(this.baseColor).lerp(this.hotColor, factor);
colors[i * 3] = this.tempColor.r;
colors[i * 3 + 1] = this.tempColor.g;
colors[i * 3 + 2] = this.tempColor.b;
}
}
}
this.geometry.attributes.position.needsUpdate = true;
this.geometry.attributes.color.needsUpdate = true;
this.geometry.computeVertexNormals();
}
}
function createFabric(scene) {
const platform = new THREE.Mesh(
new THREE.BoxGeometry(10.7, 0.3, 7.25),
new THREE.MeshStandardMaterial({
color: 0x080c12,
roughness: 0.92,
metalness: 0.05
})
);
platform.position.y = -0.19;
platform.receiveShadow = true;
scene.add(platform);
const geometry = new THREE.PlaneGeometry(10.55, 7.08, 18, 12);
geometry.rotateX(-Math.PI / 2);
const pos = geometry.attributes.position;
const colors = new Float32Array(pos.count * 3);
const c = new THREE.Color();
for (let i = 0; i < pos.count; i++) {
const x = pos.getX(i);
const z = pos.getZ(i);
const wave =
Math.sin(x * 2.7) * 0.009 +
Math.cos(z * 3.4 + x * 0.35) * 0.007;
pos.setY(i, wave);
const checker = (Math.round((x + 5.3) * 1.25) +
Math.round((z + 3.55) * 1.25)) % 2;
c.set(checker ? 0x1a2632 : 0x202d39);
c.multiplyScalar(0.9 + 0.12 * Math.sin(i * 1.7));
colors[i * 3] = c.r;
colors[i * 3 + 1] = c.g;
colors[i * 3 + 2] = c.b;
}
geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3));
geometry.computeVertexNormals();
const fabric = new THREE.Mesh(
geometry,
new THREE.MeshStandardMaterial({
color: 0xffffff,
vertexColors: true,
flatShading: true,
roughness: 0.96,
metalness: 0,
side: THREE.DoubleSide
})
);
fabric.receiveShadow = true;
scene.add(fabric);
const wire = new THREE.LineSegments(
new THREE.WireframeGeometry(geometry),
new THREE.LineBasicMaterial({
color: 0x60758a,
transparent: true,
opacity: 0.14
})
);
wire.position.y = 0.002;
scene.add(wire);
}
function createInterface(scene, theme) {
const hookMaterial = new THREE.MeshStandardMaterial({
color: 0xc7cfda,
metalness: 0.55,
roughness: 0.33,
flatShading: true
});
const hooks = new THREE.InstancedMesh(
hookGeometry,
hookMaterial,
CONTACT_COUNT
);
hooks.instanceMatrix.setUsage(THREE.DynamicDrawUsage);
hooks.castShadow = true;
hooks.frustumCulled = false;
scene.add(hooks);
const loops = new THREE.InstancedMesh(
loopGeometry,
new THREE.MeshStandardMaterial({
color: 0x8292a4,
metalness: 0.25,
roughness: 0.6,
flatShading: true
}),
CONTACT_COUNT
);
const dummy = new THREE.Object3D();
contactPositions.forEach((p, i) => {
dummy.position.set(p.x, 0.038, p.z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
loops.setMatrixAt(i, dummy.matrix);
});
loops.instanceMatrix.needsUpdate = true;
loops.receiveShadow = true;
scene.add(loops);
const linePositions = new Float32Array(CONTACT_COUNT * 2 * 3);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
'position',
new THREE.BufferAttribute(linePositions, 3)
.setUsage(THREE.DynamicDrawUsage)
);
lineGeometry.setDrawRange(0, 0);
const lines = new THREE.LineSegments(
lineGeometry,
new THREE.LineBasicMaterial({
color: theme.glow,
transparent: true,
opacity: 0.92,
blending: THREE.AdditiveBlending,
depthWrite: false,
depthTest: false
})
);
lines.frustumCulled = false;
lines.renderOrder = 10;
scene.add(lines);
const dots = new THREE.InstancedMesh(
new THREE.SphereGeometry(0.043, 6, 4),
new THREE.MeshBasicMaterial({
color: theme.glow,
transparent: true,
opacity: 0.72,
blending: THREE.AdditiveBlending,
depthWrite: false,
depthTest: false
}),
CONTACT_COUNT
);
dots.frustumCulled = false;
dots.renderOrder = 11;
scene.add(dots);
return { hooks, loops, lines, dots, dummy, linePositions };
}
function addLighting(scene, background) {
scene.background = new THREE.Color(background);
scene.add(new THREE.HemisphereLight(0xb8d4ff, 0x16110c, 1.7));
const key = new THREE.DirectionalLight(0xfff1db, 3.2);
key.position.set(4.5, 9, 5.5);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -7;
key.shadow.camera.right = 7;
key.shadow.camera.top = 7;
key.shadow.camera.bottom = -7;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0003;
scene.add(key);
const rim = new THREE.DirectionalLight(0x72baff, 1.9);
rim.position.set(-5, 4, -6);
scene.add(rim);
const warm = new THREE.PointLight(0xff9a55, 10, 12, 2);
warm.position.set(5, 2, 1);
scene.add(warm);
}
function createDemo(themeName) {
const theme = themes[themeName];
const scene = new THREE.Scene();
addLighting(scene, theme.background);
createFabric(scene);
const patch = new FlexiblePatch(scene, theme);
const iface = createInterface(scene, theme);
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(0, 1, 0),
1.15,
theme.arrow,
0.24,
0.13
);
arrow.line.material.transparent = true;
arrow.line.material.opacity = 0.85;
arrow.cone.material.transparent = true;
arrow.cone.material.opacity = 0.9;
scene.add(arrow);
let frontLine = null;
if (themeName === 'peel') {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
'position',
new THREE.BufferAttribute(new Float32Array(6), 3)
);
frontLine = new THREE.Line(
geometry,
new THREE.LineBasicMaterial({
color: 0xffe36e,
transparent: true,
opacity: 0.9
})
);
scene.add(frontLine);
}
return { scene, theme, themeName, patch, iface, arrow, frontLine };
}
const peelDemo = createDemo('peel');
const pullDemo = createDemo('pull');
// Direct, dependency-free camera controls.
const camera = new THREE.PerspectiveCamera(43, 1, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 1.05, 0);
let cameraTheta = 0.72;
let cameraPhi = 1.14;
let cameraRadius = 16.8;
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
const vertical = window.innerWidth <= 700;
const radius = cameraRadius * (vertical ? 1.27 : 1);
camera.position.set(
cameraTarget.x + radius * Math.sin(cameraPhi) * Math.cos(cameraTheta),
cameraTarget.y + radius * Math.cos(cameraPhi),
cameraTarget.z + radius * Math.sin(cameraPhi) * Math.sin(cameraTheta)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraTheta = 0.72;
cameraPhi = 1.14;
cameraRadius = 16.8;
updateCamera();
}
canvas.addEventListener('pointerdown', event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.style.cursor = 'grabbing';
});
canvas.addEventListener('pointermove', event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraTheta -= dx * 0.006;
cameraPhi = clamp(cameraPhi - dy * 0.005, 0.38, 1.46);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.style.cursor = 'grab';
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener('pointerup', endDrag);
canvas.addEventListener('pointercancel', endDrag);
canvas.addEventListener('pointerleave', endDrag);
canvas.style.cursor = 'grab';
canvas.addEventListener('wheel', event => {
event.preventDefault();
cameraRadius = clamp(cameraRadius + event.deltaY * 0.009, 9, 25);
updateCamera();
}, { passive: false });
let width = innerWidth;
let height = innerHeight;
let verticalLayout = innerWidth <= 700;
function resize() {
width = innerWidth;
height = innerHeight;
verticalLayout = width <= 700;
renderer.setSize(width, height, false);
camera.aspect = verticalLayout
? width / (height / 2)
: (width / 2) / height;
camera.updateProjectionMatrix();
updateCamera();
}
addEventListener('resize', resize);
resize();
// Interface state.
let progress = 0.18;
let playing = true;
let speed = 1;
let showContacts = true;
const playButton = document.getElementById('play');
const progressInput = document.getElementById('progress');
const progressValue = document.getElementById('progressValue');
const speedButton = document.getElementById('speed');
const contactsInput = document.getElementById('showContacts');
const peelCountEl = document.getElementById('peelCount');
const pullCountEl = document.getElementById('pullCount');
const peelMeter = document.getElementById('peelMeter');
const pullMeter = document.getElementById('pullMeter');
const peelRelease = document.getElementById('peelRelease');
const pullRelease = document.getElementById('pullRelease');
function buildContactMap(element) {
const fragment = document.createDocumentFragment();
for (let i = 0; i < CONTACT_COUNT; i++) {
fragment.appendChild(document.createElement('span'));
}
element.appendChild(fragment);
return [...element.children];
}
const peelMap = buildContactMap(document.getElementById('peelMap'));
const pullMap = buildContactMap(document.getElementById('pullMap'));
function setPlaying(value) {
playing = value;
playButton.textContent = playing ? 'Pause' : 'Play';
}
playButton.addEventListener('click', () => setPlaying(!playing));
document.getElementById('restart').addEventListener('click', () => {
progress = 0;
setPlaying(true);
});
document.getElementById('cameraReset').addEventListener('click', resetCamera);
progressInput.addEventListener('input', () => {
progress = Number(progressInput.value) / 1000;
setPlaying(false);
});
contactsInput.addEventListener('change', () => {
showContacts = contactsInput.checked;
});
speedButton.addEventListener('click', () => {
speed = speed === 1 ? 1.5 : speed === 1.5 ? 0.5 : 1;
speedButton.textContent = `${speed.toFixed(1)}×`;
});
addEventListener('keydown', event => {
if (event.code === 'Space') {
event.preventDefault();
setPlaying(!playing);
}
if (event.key.toLowerCase() === 'r') resetCamera();
});
function updateInterface(demo, heightAt, engagedAt, colorFactorAt) {
demo.patch.update(heightAt, colorFactorAt);
const positions = demo.iface.linePositions;
let count = 0;
const dummy = demo.iface.dummy;
const endpoint = new THREE.Vector3();
contactPositions.forEach((p, i) => {
const h = heightAt(p.x);
const e = 0.025;
const slope = (heightAt(p.x + e) - heightAt(p.x - e)) / (2 * e);
const angle = -Math.atan(slope);
const hookY = demo.patch.bottomY + h;
dummy.position.set(p.x, hookY, p.z);
dummy.rotation.set(0, 0, angle);
dummy.updateMatrix();
demo.iface.hooks.setMatrixAt(i, dummy.matrix);
if (!engagedAt(p.x)) return;
const cos = Math.cos(angle);
const sin = Math.sin(angle);
endpoint.set(
p.x + 0.21 * sin,
hookY - 0.21 * cos,
p.z
);
const j = count * 6;
positions[j] = p.x;
positions[j + 1] = 0.052;
positions[j + 2] = p.z;
positions[j + 3] = endpoint.x;
positions[j + 4] = endpoint.y;
positions[j + 5] = endpoint.z;
dummy.position.set(p.x, 0.075, p.z);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
demo.iface.dots.setMatrixAt(count, dummy.matrix);
count++;
});
demo.iface.hooks.instanceMatrix.needsUpdate = true;
demo.iface.lines.geometry.attributes.position.needsUpdate = true;
demo.iface.lines.geometry.setDrawRange(0, count * 2);
demo.iface.dots.count = count;
demo.iface.dots.instanceMatrix.needsUpdate = true;
demo.iface.lines.visible = showContacts;
demo.iface.dots.visible = showContacts;
return count;
}
function updatePeel() {
const front = L / 2 + 0.02 - (L + 0.04) * progress;
const edgeLift = 3.6 * Math.pow(progress, 0.92);
const span = L / 2 - front;
const heightAt = x => {
if (span <= 0.0001) return edgeLift;
const u = clamp((x - front) / span, 0, 1);
return edgeLift * smooth(u);
};
const engagedAt = x => x <= front;
const colorFactorAt = x => {
const d = Math.abs(x - front);
return 0.12 + 0.62 * Math.exp(-(d * d) / 0.9);
};
const count = updateInterface(
peelDemo, heightAt, engagedAt, colorFactorAt
);
if (peelDemo.frontLine) {
const a = peelDemo.frontLine.geometry.attributes.position.array;
const x = clamp(front, -L / 2, L / 2);
a[0] = x;
a[1] = heightAt(x) + peelDemo.patch.topY + 0.025;
a[2] = -W / 2;
a[3] = x;
a[4] = heightAt(x) + peelDemo.patch.topY + 0.025;
a[5] = W / 2;
peelDemo.frontLine.geometry.attributes.position.needsUpdate = true;
peelDemo.frontLine.visible = progress > 0.005 && progress < 0.995;
}
peelDemo.arrow.position.set(
L / 2 - 0.25,
heightAt(L / 2 - 0.25) + peelDemo.patch.topY + 0.45,
0
);
peelDemo.arrow.setDirection(
new THREE.Vector3(0.16, 1, 0).normalize()
);
const fraction = count / CONTACT_COUNT;
peelCountEl.textContent = `${count} / ${CONTACT_COUNT}`;
peelMeter.style.width = `${fraction * 100}%`;
peelRelease.textContent =
progress > 0.985 ? 'Fully separated' : 'Sequential';
peelMap.forEach((el, i) => el.classList.toggle('active', i < count));
}
function updatePull() {
const releasePoint = 0.70;
const released = progress > releasePoint;
// A short compliance stage keeps all contacts loaded before the
// entire interface releases at once.
let lift;
if (progress <= releasePoint) {
lift = 0.42 * progress / releasePoint;
} else {
const t = (progress - releasePoint) / (1 - releasePoint);
lift = 0.42 + 3.18 * Math.pow(t, 1.08);
}
const heightAt = () => lift;
const engagedAt = () => !released;
const colorFactorAt = () => released ? 0.05 : 0.28;
const count = updateInterface(
pullDemo, heightAt, engagedAt, colorFactorAt
);
pullDemo.arrow.position.set(
0,
lift + pullDemo.patch.topY + 0.55,
0
);
pullDemo.arrow.setDirection(new THREE.Vector3(0, 1, 0));
const fraction = count / CONTACT_COUNT;
pullCountEl.textContent = `${count} / ${CONTACT_COUNT}`;
pullMeter.style.width = `${fraction * 100}%`;
pullRelease.textContent = released ? 'Collective release' : 'Collective';
pullMap.forEach((el, i) => el.classList.toggle('active', i < count));
}
function renderViewport(scene, x, y, w, h) {
renderer.setViewport(x, y, w, h);
renderer.setScissor(x, y, w, h);
renderer.render(scene, camera);
}
let previousTime = performance.now();
function animate(now) {
requestAnimationFrame(animate);
const dt = Math.min((now - previousTime) / 1000, 0.05);
previousTime = now;
if (playing) {
progress += dt * 0.065 * speed;
if (progress >= 1) {
progress = 1;
setPlaying(false);
}
}
updatePeel();
updatePull();
progressInput.value = Math.round(progress * 1000);
progressValue.textContent = `${Math.round(progress * 100)}%`;
renderer.setScissorTest(true);
if (verticalLayout) {
const half = Math.floor(height / 2);
renderViewport(peelDemo.scene, 0, half, width, height - half);
renderViewport(pullDemo.scene, 0, 0, width, half);
} else {
const half = Math.floor(width / 2);
renderViewport(peelDemo.scene, 0, 0, half, height);
renderViewport(pullDemo.scene, half, 0, width - half, height);
}
}
requestAnimationFrame(animate);
</script>
</body>
</html>
```