Prompt specification
Build or customize the Three.js 3D scene "Distributed clamp pressure diagram" 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: Distributed clamp pressure diagram
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/distributed-clamp-pressure-diagram-x0254
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts padded clamp jaws. Close padded and unpadded clamps around identical blocks; show symbolic pressure arrows spread across different contact areas while explicitly avoiding numerical material-strength claims. Voxel style.
Working Three.js Starter (distributed-clamp-pressure-diagram-x0254):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Padded vs. Unpadded Clamp Jaws</title>
<style>
:root {
color-scheme: dark;
--bg: #08111f;
--panel: rgba(12, 23, 40, 0.88);
--border: rgba(163, 193, 226, 0.2);
--text: #edf5ff;
--muted: #a9bbd0;
--padding: #35d39a;
--metal: #b9c8d8;
--pressure: #ff704f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--text);
}
#stage {
position: fixed;
inset: 0;
isolation: isolate;
}
#scene {
position: absolute;
inset: 0;
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.hud {
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
}
.panel {
border: 1px solid var(--border);
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
.intro {
position: absolute;
top: 24px;
left: 24px;
width: min(460px, calc(100vw - 48px));
padding: 20px 22px;
border-radius: 16px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 10px;
color: var(--muted);
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
width: 9px;
height: 9px;
content: "";
background: var(--padding);
box-shadow: 0 0 14px rgba(53, 211, 154, 0.8);
}
h1 {
margin: 0;
font-size: clamp(25px, 3vw, 39px);
line-height: 1.04;
letter-spacing: -0.035em;
}
.subtitle {
max-width: 410px;
margin: 12px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.55;
}
.quality {
position: absolute;
top: 24px;
right: 24px;
padding: 11px 14px;
border-radius: 999px;
color: #d8e5f5;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.quality span {
color: var(--pressure);
}
.legend {
position: absolute;
bottom: 24px;
left: 24px;
width: min(650px, calc(100vw - 48px));
padding: 15px 17px;
border-radius: 15px;
}
.legend-row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 11px 22px;
margin-bottom: 10px;
}
.key {
display: inline-flex;
align-items: center;
gap: 8px;
color: #dce8f7;
font-size: 12px;
font-weight: 700;
}
.swatch {
width: 14px;
height: 14px;
border: 1px solid rgba(255, 255, 255, 0.28);
box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.13);
}
.swatch.padding {
background: var(--padding);
}
.swatch.metal {
background: var(--metal);
}
.arrow-key {
position: relative;
width: 29px;
height: 12px;
background: var(--pressure);
}
.arrow-key::after {
position: absolute;
top: -4px;
right: -1px;
width: 0;
height: 0;
content: "";
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid var(--pressure);
}
.notice {
padding-top: 10px;
border-top: 1px solid rgba(163, 193, 226, 0.14);
color: var(--muted);
font-size: 12px;
line-height: 1.48;
}
.notice strong {
color: #f4f8ff;
}
.controls {
position: absolute;
right: 24px;
bottom: 24px;
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 9px;
pointer-events: auto;
}
.control-row {
display: flex;
gap: 7px;
}
button {
min-width: 42px;
height: 39px;
padding: 0 13px;
border: 1px solid var(--border);
border-radius: 10px;
background: rgba(15, 29, 49, 0.92);
color: var(--text);
font: 700 12px ui-monospace, SFMono-Regular, Menlo, monospace;
cursor: pointer;
transition:
background 140ms ease,
border-color 140ms ease,
transform 140ms ease;
}
button:hover {
border-color: rgba(113, 228, 191, 0.58);
background: rgba(28, 50, 72, 0.96);
transform: translateY(-1px);
}
button:focus-visible {
outline: 2px solid var(--padding);
outline-offset: 2px;
}
.help {
padding: 7px 10px;
border-radius: 8px;
background: rgba(8, 17, 31, 0.68);
color: #91a5bb;
font: 11px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (max-width: 900px) {
.intro {
top: 12px;
left: 12px;
width: min(410px, calc(100vw - 24px));
padding: 15px 16px;
}
.subtitle {
display: none;
}
.quality {
display: none;
}
.legend {
bottom: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 12px 13px;
}
.legend-row {
gap: 8px 14px;
margin-bottom: 8px;
}
.notice {
font-size: 11px;
}
.controls {
top: 12px;
right: 12px;
bottom: auto;
}
.help {
display: none;
}
}
@media (max-width: 560px) {
.intro {
width: calc(100vw - 112px);
}
.eyebrow {
font-size: 9px;
}
h1 {
font-size: 22px;
}
.legend-row {
gap: 7px 12px;
}
.key {
font-size: 10px;
}
.notice {
font-size: 10px;
}
}
</style>
</head>
<body>
<main id="stage">
<canvas
id="scene"
tabindex="0"
aria-label="Interactive voxel scene comparing padded and unpadded clamp jaws around identical blocks. Drag to orbit, scroll to zoom, or use the camera buttons."
></canvas>
<div class="hud">
<header class="intro panel">
<div class="eyebrow">Voxel mechanics study</div>
<h1>Padded vs. unpadded clamp jaws</h1>
<p class="subtitle">
Identical voxel blocks are held in matching clamp frames.
Equal-size pressure arrows show symbolic direction and contact
placement across differently spread contact areas.
</p>
</header>
<div class="quality panel">
Qualitative only <span> / no strength values</span>
</div>
<section class="legend panel" aria-label="Scene legend and qualification">
<div class="legend-row">
<span class="key">
<span class="swatch padding"></span>
Padding
</span>
<span class="key">
<span class="swatch metal"></span>
Unpadded metal
</span>
<span class="key">
<span class="arrow-key"></span>
Symbolic pressure direction
</span>
</div>
<div class="notice">
<strong>Qualitative geometry only.</strong>
Equal-size arrows indicate direction and placement, not magnitude.
Contact spread is schematic. No force, stress, or
<strong>material-strength values or claims</strong> are implied.
</div>
</section>
<div class="controls">
<div class="control-row">
<button id="zoomIn" type="button" aria-label="Zoom in">+</button>
<button id="zoomOut" type="button" aria-label="Zoom out">−</button>
<button id="reset" type="button">Reset view</button>
</div>
<div class="help">Drag to orbit · Scroll to zoom · R to reset</div>
</div>
</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 stage = document.querySelector("#stage");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x08111f);
scene.fog = new THREE.Fog(0x08111f, 13, 31);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 60);
const hemisphere = new THREE.HemisphereLight(0xc8e6ff, 0x142033, 2.0);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.1);
keyLight.position.set(5.5, 11, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 30;
keyLight.shadow.bias = -0.0004;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x568cff, 1.55);
rimLight.position.set(-9, 6, -7);
scene.add(rimLight);
const warmFill = new THREE.PointLight(0xffb27a, 12, 18, 2);
warmFill.position.set(0, 5, 7);
scene.add(warmFill);
const materials = {
floor: new THREE.MeshStandardMaterial({
color: 0x0b1728,
roughness: 0.96,
metalness: 0.03
}),
platform: new THREE.MeshStandardMaterial({
color: 0x18283c,
roughness: 0.82,
metalness: 0.22
}),
platformEdge: new THREE.MeshStandardMaterial({
color: 0x334c68,
roughness: 0.65,
metalness: 0.42
}),
frame: new THREE.MeshStandardMaterial({
color: 0x435a76,
roughness: 0.68,
metalness: 0.36
}),
frameLight: new THREE.MeshStandardMaterial({
color: 0x5d7694,
roughness: 0.58,
metalness: 0.42
}),
frameDark: new THREE.MeshStandardMaterial({
color: 0x24364d,
roughness: 0.74,
metalness: 0.34
}),
padding: new THREE.MeshStandardMaterial({
color: 0x35d39a,
roughness: 0.88,
metalness: 0.02
}),
paddingDark: new THREE.MeshStandardMaterial({
color: 0x167557,
roughness: 0.9,
metalness: 0.01
}),
steel: new THREE.MeshStandardMaterial({
color: 0xb9c8d8,
roughness: 0.28,
metalness: 0.72
}),
arrow: new THREE.MeshStandardMaterial({
color: 0xff704f,
emissive: 0x7c1d0d,
emissiveIntensity: 0.72,
roughness: 0.36,
metalness: 0.12
}),
block: [
new THREE.MeshStandardMaterial({
color: 0xb7aa91,
roughness: 0.91,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xc8baa0,
roughness: 0.9,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xa99c84,
roughness: 0.94,
metalness: 0.02
}),
new THREE.MeshStandardMaterial({
color: 0xd0c3aa,
roughness: 0.89,
metalness: 0.02
})
]
};
function addBox(parent, size, position, material, castShadow = true) {
const geometry = new THREE.BoxGeometry(
size[0],
size[1],
size[2]
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// Ground and a restrained technical grid.
const floor = addBox(
scene,
[28, 0.18, 24],
[0, -0.22, 0],
materials.floor,
false
);
floor.receiveShadow = true;
const grid = new THREE.GridHelper(28, 28, 0x36516f, 0x20344b);
grid.position.y = -0.115;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
function createVoxelBlock(centerX) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
const cubeSize = 0.56;
const spacing = 0.585;
for (let x = -1; x <= 1; x++) {
for (let y = -1; y <= 1; y++) {
for (let z = -1; z <= 1; z++) {
const variant =
(Math.abs(x) * 3 + Math.abs(y) * 5 + Math.abs(z) * 7) %
materials.block.length;
addBox(
group,
[cubeSize, cubeSize, cubeSize],
[
x * spacing,
1.20 + y * spacing,
z * spacing
],
materials.block[variant]
);
}
}
}
return group;
}
function createPressureArrow(side, y, z, centerX) {
const group = new THREE.Group();
// The local arrow points toward +X.
// Its tip lands on the specimen block's side surface.
addBox(
group,
[0.74, 0.15, 0.14],
[-0.38, 0, 0],
materials.arrow
);
// Stepped, voxel-like arrowhead.
addBox(
group,
[0.18, 0.27, 0.14],
[0.45, 0, 0],
materials.arrow
);
addBox(
group,
[0.18, 0.44, 0.14],
[0.27, 0, 0],
materials.arrow
);
addBox(
group,
[0.18, 0.61, 0.14],
[0.09, 0, 0],
materials.arrow
);
addBox(
group,
[0.12, 0.24, 0.14],
[-0.77, 0, 0],
materials.arrow
);
group.position.set(
centerX + side * 1.405,
y,
z
);
if (side > 0) {
group.rotation.y = Math.PI;
}
scene.add(group);
return group;
}
function createClamp(centerX, padded) {
const group = new THREE.Group();
group.position.x = centerX;
scene.add(group);
// Matching display platform.
addBox(
group,
[5.05, 0.18, 2.80],
[0, -0.02, 0],
materials.platform
);
for (const x of [-2.25, 2.25]) {
addBox(
group,
[0.30, 0.23, 2.82],
[x, 0.02, 0],
materials.platformEdge
);
}
for (const z of [-1.20, 1.20]) {
addBox(
group,
[4.55, 0.22, 0.22],
[0, 0.02, z],
materials.frameDark
);
}
// Identical lower saddle for both clamps.
addBox(
group,
[1.90, 0.34, 1.88],
[0, 0.22, 0],
materials.frameDark
);
addBox(
group,
[1.65, 0.16, 1.64],
[0, 0.43, 0],
materials.frameLight
);
// Identical frame columns.
for (const side of [-1, 1]) {
addBox(
group,
[0.46, 2.94, 0.92],
[side * 2.08, 1.68, 0],
materials.frame
);
// Front reinforcement plate.
addBox(
group,
[0.54, 0.72, 0.08],
[side * 2.08, 1.84, 0.50],
materials.frameLight
);
// Voxel adjustment cap.
addBox(
group,
[0.66, 0.27, 0.66],
[side * 2.08, 3.70, 0],
materials.frameDark
);
addBox(
group,
[0.44, 0.18, 0.44],
[side * 2.08, 3.92, 0],
materials.frameLight
);
// Inward-facing jaw arm.
addBox(
group,
[1.25, 0.42, 0.92],
[side * 1.28, 1.20, 0],
materials.frame
);
// Square fasteners.
addBox(
group,
[0.18, 0.18, 0.10],
[side * 2.08, 2.08, 0.57],
materials.steel
);
addBox(
group,
[0.18, 0.18, 0.10],
[side * 2.08, 1.58, 0.57],
materials.steel
);
}
// Identical top bridge.
addBox(
group,
[4.62, 0.46, 1.02],
[0, 3.36, 0],
materials.frameLight
);
addBox(
group,
[0.12, 0.52, 1.08],
[0, 3.36, 0],
materials.frameDark
);
for (const x of [-0.85, 0.85]) {
addBox(
group,
[0.20, 0.20, 0.12],
[x, 3.36, 0.56],
materials.steel
);
}
// The only material/geometry distinction is the contact treatment.
if (padded) {
for (const side of [-1, 1]) {
// Three broad pad segments create a visibly extended contact area.
for (const y of [0.62, 1.20, 1.78]) {
addBox(
group,
[0.18, 0.56, 1.42],
[side * 0.955, y, 0],
materials.padding
);
}
// Small voxel stitch marks on the front of the pad.
for (const y of [0.62, 1.20, 1.78]) {
for (const z of [-0.42, 0.42]) {
addBox(
group,
[0.035, 0.11, 0.11],
[side * 0.955, y, z],
materials.paddingDark,
false
);
}
}
}
} else {
for (const side of [-1, 1]) {
// A smaller bare-metal contact tip.
addBox(
group,
[0.18, 0.60, 0.60],
[side * 0.955, 1.20, 0],
materials.steel
);
addBox(
group,
[0.10, 0.22, 0.22],
[side * 0.84, 1.20, 0],
materials.frameDark
);
}
}
createVoxelBlock(centerX);
// Every arrow has the same dimensions. Only their placement differs.
const arrowYPositions = padded
? [0.61, 1.20, 1.79] // spread across the wide padded contact area
: [1.03, 1.20, 1.37]; // grouped across the narrow metal contact area
for (const side of [-1, 1]) {
for (const y of arrowYPositions) {
createPressureArrow(side, y, 0.73, centerX);
}
}
}
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.arcTo(x + width, y, x + width, y + height, r);
ctx.arcTo(x + width, y + height, x, y + height, r);
ctx.arcTo(x, y + height, x, y, r);
ctx.arcTo(x, y, x + width, y, r);
ctx.closePath();
}
function createWorldLabel(centerX, title, subtitle, accent) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 768;
labelCanvas.height = 220;
const ctx = labelCanvas.getContext("2d");
roundedRect(ctx, 8, 8, 752, 204, 24);
ctx.fillStyle = "rgba(8, 17, 31, 0.92)";
ctx.fill();
ctx.lineWidth = 7;
ctx.strokeStyle = accent;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = accent;
ctx.font = "800 57px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.fillText(title, 384, 76);
ctx.fillStyle = "#b8c8dc";
ctx.font = "600 31px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace";
ctx.fillText(subtitle, 384, 151);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.position.set(centerX, 4.64, 0);
sprite.scale.set(3.72, 1.07, 1);
sprite.renderOrder = 10;
scene.add(sprite);
}
const leftCenter = -3.15;
const rightCenter = 3.15;
createClamp(leftCenter, true);
createClamp(rightCenter, false);
createWorldLabel(
leftCenter,
"PADDED CLAMP",
"WIDE CONTACT AREA",
"#35d39a"
);
createWorldLabel(
rightCenter,
"UNPADDED CLAMP",
"NARROW CONTACT AREA",
"#b9c8d8"
);
// -------------------------------------------------------------------------
// Custom camera controls. No OrbitControls or other addons are imported.
// -------------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 1.55, 0),
theta: 0.28,
phi: 1.15,
radius: 13.8,
desiredTheta: 0.28,
desiredPhi: 1.15,
desiredRadius: 13.8,
dragging: false,
pointerId: null,
lastX: 0,
lastY: 0
};
function resetCamera() {
const narrow = window.innerWidth / window.innerHeight < 0.9;
controls.desiredTheta = 0.28;
controls.desiredPhi = narrow ? 1.08 : 1.15;
controls.desiredRadius = narrow ? 17.2 : 13.8;
}
function zoomBy(factor) {
controls.desiredRadius = THREE.MathUtils.clamp(
controls.desiredRadius * factor,
8.2,
21
);
}
canvas.addEventListener("pointerdown", (event) => {
controls.dragging = true;
controls.pointerId = event.pointerId;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
canvas.setPointerCapture(event.pointerId);
canvas.focus({ preventScroll: true });
});
canvas.addEventListener("pointermove", (event) => {
if (!controls.dragging || event.pointerId !== controls.pointerId) {
return;
}
const dx = event.clientX - controls.lastX;
const dy = event.clientY - controls.lastY;
controls.lastX = event.clientX;
controls.lastY = event.clientY;
controls.desiredTheta -= dx * 0.006;
controls.desiredPhi = THREE.MathUtils.clamp(
controls.desiredPhi - dy * 0.005,
0.48,
1.46
);
});
function stopDragging(event) {
if (
controls.dragging &&
(
event.pointerId === undefined ||
event.pointerId === controls.pointerId
)
) {
controls.dragging = false;
if (
event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)
) {
canvas.releasePointerCapture(event.pointerId);
}
controls.pointerId = null;
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("lostpointercapture", () => {
controls.dragging = false;
controls.pointerId = null;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
zoomBy(Math.exp(event.deltaY * 0.001));
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
document.querySelector("#reset").addEventListener("click", resetCamera);
document.querySelector("#zoomIn").addEventListener("click", () => zoomBy(0.88));
document.querySelector("#zoomOut").addEventListener("click", () => zoomBy(1.12));
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.fov = camera.aspect < 0.9 ? 54 : 42;
camera.updateProjectionMatrix();
}
window.addEventListener("resize", resize);
resize();
resetCamera();
controls.theta = controls.desiredTheta;
controls.phi = controls.desiredPhi;
controls.radius = controls.desiredRadius;
function updateCamera() {
const smoothing = 0.11;
controls.theta +=
(controls.desiredTheta - controls.theta) * smoothing;
controls.phi +=
(controls.desiredPhi - controls.phi) * smoothing;
controls.radius +=
(controls.desiredRadius - controls.radius) * smoothing;
const sinPhi = Math.sin(controls.phi);
camera.position.set(
controls.target.x +
controls.radius * sinPhi * Math.sin(controls.theta),
controls.target.y +
controls.radius * Math.cos(controls.phi),
controls.target.z +
controls.radius * sinPhi * Math.cos(controls.theta)
);
camera.lookAt(controls.target);
}
function animate() {
requestAnimationFrame(animate);
updateCamera();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```