Prompt specification
Build or customize the Three.js 3D scene "Soap-film frame comparison" 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: Soap-film frame comparison
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/soap-film-frame-comparison-x1502
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring surface tension and wetting. Place circular and rectangular wire frames with simplified spanning films; label surface shapes as approximations and avoid implying that all films are flat under every boundary. Stylized solid forms.
Working Three.js Starter (soap-film-frame-comparison-x1502):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Surface Tension & Wetting</title>
<style>
:root {
--ink: #14283d;
--muted: #5c7185;
--orange: #e7683b;
--cyan: #68c8dd;
--glass: rgba(255, 255, 255, 0.84);
--line: rgba(33, 67, 91, 0.15);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 18% 12%, rgba(132, 214, 226, 0.42), transparent 35%),
radial-gradient(circle at 85% 80%, rgba(238, 180, 132, 0.27), transparent 36%),
linear-gradient(145deg, #f7fbfc 0%, #e9f0f4 52%, #e4ebf1 100%);
}
#stage {
position: fixed;
inset: 0;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
top: 22px;
left: 24px;
right: 24px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 20px;
pointer-events: none;
z-index: 5;
}
.title-block {
max-width: 430px;
}
.eyebrow {
margin-bottom: 7px;
color: #3d8294;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 760;
line-height: 0.98;
letter-spacing: -0.055em;
}
h1 span {
color: var(--orange);
font-weight: 430;
}
.instructions {
margin: 13px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.controls {
display: flex;
gap: 8px;
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid var(--line);
border-radius: 999px;
padding: 10px 14px;
color: var(--ink);
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 8px 26px rgba(41, 70, 91, 0.08);
backdrop-filter: blur(12px);
cursor: pointer;
font: inherit;
font-size: 12px;
font-weight: 700;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
background: rgba(255, 255, 255, 0.96);
border-color: rgba(33, 67, 91, 0.28);
}
button:focus-visible {
outline: 3px solid rgba(104, 200, 221, 0.55);
outline-offset: 2px;
}
button[aria-pressed="true"] {
color: #a73c1c;
border-color: rgba(231, 104, 59, 0.35);
background: rgba(255, 239, 232, 0.9);
}
#labels {
position: fixed;
inset: 0;
z-index: 4;
pointer-events: none;
}
.annotation {
position: absolute;
top: 0;
left: 0;
width: max-content;
max-width: 250px;
padding: 11px 13px 12px;
border: 1px solid rgba(44, 84, 105, 0.14);
border-radius: 13px;
color: var(--ink);
background: var(--glass);
box-shadow: 0 12px 35px rgba(37, 67, 87, 0.10);
backdrop-filter: blur(13px);
will-change: transform;
transition: opacity 120ms linear;
}
.annotation::after {
content: "";
position: absolute;
left: 50%;
bottom: -7px;
width: 12px;
height: 12px;
border-right: 1px solid rgba(44, 84, 105, 0.14);
border-bottom: 1px solid rgba(44, 84, 105, 0.14);
background: rgba(255, 255, 255, 0.86);
transform: translateX(-50%) rotate(45deg);
}
.annotation .tag {
display: block;
margin-bottom: 4px;
color: #438394;
font-size: 9px;
font-weight: 850;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.annotation strong {
display: block;
font-size: 13px;
line-height: 1.25;
}
.annotation small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.annotation.wetting .tag {
color: #b64c29;
}
.angle-label {
position: absolute;
top: 0;
left: 0;
padding: 5px 8px;
border-radius: 8px;
color: #9d3d20;
background: rgba(255, 239, 232, 0.94);
box-shadow: 0 6px 18px rgba(108, 57, 37, 0.10);
font-size: 11px;
font-weight: 800;
white-space: nowrap;
will-change: transform;
}
.bottom {
position: fixed;
left: 24px;
right: 24px;
bottom: 20px;
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 20px;
pointer-events: none;
z-index: 5;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
color: #50687b;
font-size: 11px;
font-weight: 650;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 6px;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--orange);
}
.swatch.film {
border: 1px solid rgba(41, 126, 146, 0.48);
background: rgba(104, 200, 221, 0.66);
}
.swatch.bead {
background: #286a8d;
}
.note {
max-width: 510px;
padding: 11px 14px;
border: 1px solid rgba(44, 84, 105, 0.12);
border-radius: 12px;
color: #586d7e;
background: rgba(255, 255, 255, 0.76);
box-shadow: 0 10px 30px rgba(37, 67, 87, 0.07);
backdrop-filter: blur(12px);
font-size: 11px;
line-height: 1.45;
}
.note strong {
color: #344e61;
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
flex-direction: column;
}
.controls {
align-self: flex-start;
}
.instructions {
margin-top: 9px;
}
.annotation {
max-width: 185px;
padding: 8px 10px;
}
.annotation small {
display: none;
}
.bottom {
left: 14px;
right: 14px;
bottom: 14px;
flex-direction: column-reverse;
align-items: flex-start;
}
.note {
max-width: none;
font-size: 10px;
}
.legend {
gap: 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive surface tension and wetting illustration"></main>
<header class="topbar">
<div class="title-block">
<div class="eyebrow">Interactive concept model</div>
<h1>Surface tension <span>&</span> wetting</h1>
<p class="instructions">
Drag to orbit · Scroll to zoom · Double-click to reset
</p>
</div>
<div class="controls">
<button id="guidesButton" type="button" aria-pressed="true">
Hide pull guides
</button>
<button id="resetButton" type="button">Reset view</button>
</div>
</header>
<div id="labels" aria-hidden="true">
<div class="annotation" id="circleLabel">
<span class="tag">Film 01 · surface tension</span>
<strong>Circular wire frame</strong>
<small>Gently dished spanning-film approximation</small>
</div>
<div class="annotation" id="rectangleLabel">
<span class="tag">Film 02 · boundary response</span>
<strong>Rectangular wire frame</strong>
<small>Sagging, non-planar film approximation</small>
</div>
<div class="annotation wetting" id="wettingLabel">
<span class="tag">Wetting</span>
<strong>Partially wetting bead</strong>
<small>Stylized solid bead with contact angle θ ≈ 55°</small>
</div>
<div class="angle-label" id="angleLabel">θ ≈ 55°</div>
</div>
<footer class="bottom">
<div class="legend" aria-hidden="true">
<span><i class="swatch"></i> Perimeter tension, γ</span>
<span><i class="swatch film"></i> Illustrative film</span>
<span><i class="swatch bead"></i> Wetting bead</span>
</div>
<div class="note">
<strong>Approximation note:</strong>
the curved films are visual approximations, not computed minimal surfaces.
Different boundaries, supports, pressures, and gravity can produce flat,
bowed, sagging, or unstable configurations.
</div>
</footer>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const scene = new THREE.Scene();
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true
});
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;
stage.appendChild(renderer.domElement);
const canvas = renderer.domElement;
canvas.tabIndex = 0;
canvas.setAttribute(
"aria-label",
"Three-dimensional surface tension and wetting model. Drag to orbit and scroll to zoom."
);
const camera = new THREE.PerspectiveCamera(
37,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
radius: window.innerWidth < 700 ? 11.7 : 9.6,
theta: 0.48,
phi: 1.04,
target: new THREE.Vector3(0, 1.25, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.cos(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.sin(orbit.theta)
);
camera.lookAt(orbit.target);
}
updateCamera();
// Lighting
scene.add(new THREE.HemisphereLight(0xdff4ff, 0x718096, 1.55));
const ambient = new THREE.AmbientLight(0xffffff, 0.42);
scene.add(ambient);
const keyLight = new THREE.DirectionalLight(0xfff5e8, 3.1);
keyLight.position.set(-4.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x85d8ef, 1.35);
rimLight.position.set(6, 4, -5);
scene.add(rimLight);
// Shared materials
const wireMaterial = new THREE.MeshStandardMaterial({
color: 0xc88c4f,
metalness: 0.72,
roughness: 0.25
});
const supportMaterial = new THREE.MeshStandardMaterial({
color: 0x34536b,
metalness: 0.46,
roughness: 0.36
});
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xe9edf0,
metalness: 0.04,
roughness: 0.76
});
const baseTopMaterial = new THREE.MeshStandardMaterial({
color: 0xf7f8f7,
metalness: 0.02,
roughness: 0.64
});
const filmMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8bdce9,
metalness: 0,
roughness: 0.13,
transmission: 0.08,
thickness: 0.25,
transparent: true,
opacity: 0.56,
depthWrite: false,
side: THREE.DoubleSide,
clearcoat: 0.7,
clearcoatRoughness: 0.12,
iridescence: 0.6,
iridescenceIOR: 1.28,
iridescenceThicknessRange: [120, 420]
});
const orange = 0xe7683b;
// Floor and subtle grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xe8eef2,
roughness: 0.93,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.005;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0xb9c9d2, 0xcbd7de);
grid.position.y = 0.006;
grid.material.transparent = true;
grid.material.opacity = 0.24;
scene.add(grid);
const up = new THREE.Vector3(0, 1, 0);
function rodBetween(a, b, radius, material, parent = scene) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const rod = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 16),
material
);
rod.position.copy(a).add(b).multiplyScalar(0.5);
rod.quaternion.setFromUnitVectors(up, direction.normalize());
rod.castShadow = true;
rod.receiveShadow = true;
parent.add(rod);
return rod;
}
function createCircularFilmGeometry(radius, sag) {
const radialSegments = 22;
const angularSegments = 96;
const positions = [0, 0, 0];
const uvs = [0.5, 0.5];
const indices = [];
for (let ring = 1; ring <= radialSegments; ring++) {
const edge = ring / radialSegments;
const r = radius * edge;
for (let segment = 0; segment < angularSegments; segment++) {
const angle = (segment / angularSegments) * Math.PI * 2;
const bowl = Math.pow(1 - edge * edge, 2);
const ripple =
0.022 *
Math.sin(3 * angle + 0.7) *
edge *
(1 - edge);
positions.push(
r * Math.cos(angle),
-sag * bowl + ripple,
r * Math.sin(angle)
);
uvs.push(
0.5 + 0.5 * edge * Math.cos(angle),
0.5 + 0.5 * edge * Math.sin(angle)
);
}
}
for (let segment = 0; segment < angularSegments; segment++) {
indices.push(
0,
1 + ((segment + 1) % angularSegments),
1 + segment
);
}
for (let ring = 1; ring < radialSegments; ring++) {
const inner = 1 + (ring - 1) * angularSegments;
const outer = 1 + ring * angularSegments;
for (let segment = 0; segment < angularSegments; segment++) {
const next = (segment + 1) % angularSegments;
const a = inner + segment;
const b = inner + next;
const c = outer + segment;
const d = outer + next;
indices.push(a, b, c, b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function createRectangularFilmGeometry(width, depth, sag) {
const widthSegments = 40;
const depthSegments = 28;
const positions = [];
const uvs = [];
const indices = [];
for (let iz = 0; iz <= depthSegments; iz++) {
const v = iz / depthSegments;
const z = (v - 0.5) * depth;
for (let ix = 0; ix <= widthSegments; ix++) {
const u = ix / widthSegments;
const x = (u - 0.5) * width;
const edgeFade = (1 - u * u) * (1 - v * v);
const y =
-sag * edgeFade +
0.022 *
Math.sin(3 * Math.PI * u) *
Math.sin(2 * Math.PI * v) *
edgeFade;
positions.push(x, y, z);
uvs.push(u, v);
}
}
const stride = widthSegments + 1;
for (let iz = 0; iz < depthSegments; iz++) {
for (let ix = 0; ix < widthSegments; ix++) {
const a = iz * stride + ix;
const b = a + 1;
const c = a + stride;
const d = c + 1;
indices.push(a, c, b, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"uv",
new THREE.Float32BufferAttribute(uvs, 2)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
// ---------------------------------------------------------------
// Circular wire frame and illustrative spanning film
// ---------------------------------------------------------------
const circleCenter = new THREE.Vector3(-1.65, 2.12, 0);
const circleRadius = 1.16;
const circleGroup = new THREE.Group();
circleGroup.position.copy(circleCenter);
scene.add(circleGroup);
const circularWire = new THREE.Mesh(
new THREE.TorusGeometry(circleRadius, 0.045, 12, 112),
wireMaterial
);
circularWire.rotation.x = Math.PI / 2;
circularWire.castShadow = true;
circularWire.receiveShadow = true;
circleGroup.add(circularWire);
const circularFilm = new THREE.Mesh(
createCircularFilmGeometry(1.115, 0.38),
filmMaterial
);
circularFilm.renderOrder = 2;
circleGroup.add(circularFilm);
// Circular support and pedestal
const circleBase = new THREE.Mesh(
new THREE.CylinderGeometry(1.46, 1.53, 0.15, 64),
baseMaterial
);
circleBase.position.set(circleCenter.x, 0.075, circleCenter.z);
circleBase.castShadow = true;
circleBase.receiveShadow = true;
scene.add(circleBase);
const circleTop = new THREE.Mesh(
new THREE.CylinderGeometry(1.36, 1.42, 0.08, 64),
baseTopMaterial
);
circleTop.position.set(circleCenter.x, 0.19, circleCenter.z);
circleTop.castShadow = true;
circleTop.receiveShadow = true;
scene.add(circleTop);
for (const side of [-1, 1]) {
const postX = circleCenter.x + side * 1.32;
rodBetween(
new THREE.Vector3(postX, 0.2, 0),
new THREE.Vector3(postX, circleCenter.y, 0),
0.034,
supportMaterial
);
rodBetween(
new THREE.Vector3(postX, circleCenter.y, 0),
new THREE.Vector3(
circleCenter.x + side * circleRadius,
circleCenter.y,
0
),
0.034,
supportMaterial
);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.16, 0.19, 0.08, 32),
baseTopMaterial
);
foot.position.set(postX, 0.21, 0);
foot.castShadow = true;
scene.add(foot);
}
// ---------------------------------------------------------------
// Rectangular wire frame and sagging non-planar film
// ---------------------------------------------------------------
const rectangleCenter = new THREE.Vector3(1.75, 2.12, -0.15);
const rectangleWidth = 2.4;
const rectangleDepth = 1.55;
const rectangleGroup = new THREE.Group();
rectangleGroup.position.copy(rectangleCenter);
scene.add(rectangleGroup);
const rectangleCorners = [
new THREE.Vector3(
-rectangleWidth / 2,
0,
-rectangleDepth / 2
),
new THREE.Vector3(
rectangleWidth / 2,
0,
-rectangleDepth / 2
),
new THREE.Vector3(
rectangleWidth / 2,
0,
rectangleDepth / 2
),
new THREE.Vector3(
-rectangleWidth / 2,
0,
rectangleDepth / 2
)
];
for (let index = 0; index < rectangleCorners.length; index++) {
const start = rectangleCorners[index];
const end = rectangleCorners[(index + 1) % rectangleCorners.length];
rodBetween(start, end, 0.043, wireMaterial, rectangleGroup);
const joint = new THREE.Mesh(
new THREE.SphereGeometry(0.06, 16, 12),
wireMaterial
);
joint.position.copy(start);
joint.castShadow = true;
rectangleGroup.add(joint);
}
const rectangularFilm = new THREE.Mesh(
createRectangularFilmGeometry(2.315, 1.465, 0.50),
filmMaterial
);
rectangularFilm.renderOrder = 2;
rectangleGroup.add(rectangularFilm);
// Rectangular support and pedestal
const rectangleBase = new THREE.Mesh(
new THREE.BoxGeometry(2.72, 0.15, 1.98),
baseMaterial
);
rectangleBase.position.set(
rectangleCenter.x,
0.075,
rectangleCenter.z
);
rectangleBase.castShadow = true;
rectangleBase.receiveShadow = true;
scene.add(rectangleBase);
const rectangleTop = new THREE.Mesh(
new THREE.BoxGeometry(2.61, 0.08, 1.87),
baseTopMaterial
);
rectangleTop.position.set(
rectangleCenter.x,
0.19,
rectangleCenter.z
);
rectangleTop.castShadow = true;
rectangleTop.receiveShadow = true;
scene.add(rectangleTop);
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const post = new THREE.Vector3(
rectangleCenter.x + sx * 1.31,
2.12,
rectangleCenter.z + sz * 0.89
);
rodBetween(
new THREE.Vector3(post.x, 0.2, post.z),
post,
0.033,
supportMaterial
);
rodBetween(
post,
new THREE.Vector3(
rectangleCenter.x + sx * rectangleWidth / 2,
rectangleCenter.y,
rectangleCenter.z + sz * rectangleDepth / 2
),
0.033,
supportMaterial
);
const foot = new THREE.Mesh(
new THREE.CylinderGeometry(0.13, 0.16, 0.07, 24),
baseTopMaterial
);
foot.position.set(post.x, 0.205, post.z);
foot.castShadow = true;
scene.add(foot);
}
}
// ---------------------------------------------------------------
// Wetting: a stylized solid bead and contact-angle construction
// ---------------------------------------------------------------
const wettingCenter = new THREE.Vector3(0, 0, 2.25);
const substrate = new THREE.Mesh(
new THREE.CylinderGeometry(1.08, 1.13, 0.28, 64),
baseMaterial
);
substrate.position.set(
wettingCenter.x,
0.26,
wettingCenter.z
);
substrate.castShadow = true;
substrate.receiveShadow = true;
scene.add(substrate);
const substrateTop = new THREE.Mesh(
new THREE.CylinderGeometry(1.02, 1.08, 0.12, 64),
baseTopMaterial
);
substrateTop.position.set(
wettingCenter.x,
0.46,
wettingCenter.z
);
substrateTop.castShadow = true;
substrateTop.receiveShadow = true;
scene.add(substrateTop);
const beadProfile = [
new THREE.Vector2(0.0, 0.0),
new THREE.Vector2(0.24, 0.0),
new THREE.Vector2(0.32, 0.014),
new THREE.Vector2(0.41, 0.058),
new THREE.Vector2(0.49, 0.135),
new THREE.Vector2(0.535, 0.235),
new THREE.Vector2(0.54, 0.33),
new THREE.Vector2(0.51, 0.43),
new THREE.Vector2(0.43, 0.52),
new THREE.Vector2(0.30, 0.59),
new THREE.Vector2(0.15, 0.625),
new THREE.Vector2(0.0, 0.63)
];
const beadMaterial = new THREE.MeshPhysicalMaterial({
color: 0x286b90,
roughness: 0.25,
metalness: 0.02,
clearcoat: 0.8,
clearcoatRoughness: 0.12
});
const bead = new THREE.Mesh(
new THREE.LatheGeometry(beadProfile, 64),
beadMaterial
);
bead.position.set(
wettingCenter.x,
0.525,
wettingCenter.z
);
bead.castShadow = true;
bead.receiveShadow = true;
scene.add(bead);
// Contact patch
const contactPatch = new THREE.Mesh(
new THREE.CircleGeometry(0.25, 64),
new THREE.MeshBasicMaterial({
color: 0x1b526f,
transparent: true,
opacity: 0.42,
side: THREE.DoubleSide
})
);
contactPatch.rotation.x = -Math.PI / 2;
contactPatch.position.set(
wettingCenter.x,
0.528,
wettingCenter.z
);
scene.add(contactPatch);
// Contact-angle construction in the front vertical plane
const diagramZ = wettingCenter.z + 0.548;
const contactPoint = new THREE.Vector3(
wettingCenter.x + 0.24,
0.535,
diagramZ
);
const baselinePoints = [
contactPoint.clone(),
contactPoint.clone().add(new THREE.Vector3(0.58, 0, 0))
];
const baseline = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(baselinePoints),
new THREE.LineBasicMaterial({
color: 0x677d8d,
transparent: true,
opacity: 0.9
})
);
scene.add(baseline);
const angleRadians = THREE.MathUtils.degToRad(55);
const tangentDirection = new THREE.Vector3(
Math.cos(angleRadians),
Math.sin(angleRadians),
0
);
const tangentEnd = contactPoint
.clone()
.addScaledVector(tangentDirection, 0.42);
const tangent = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
contactPoint.clone(),
tangentEnd
]),
new THREE.LineBasicMaterial({ color: orange })
);
scene.add(tangent);
const arcPoints = [];
for (let index = 0; index <= 28; index++) {
const t = index / 28;
const angle = angleRadians * t;
arcPoints.push(
contactPoint.clone().add(
new THREE.Vector3(
Math.cos(angle) * 0.24,
Math.sin(angle) * 0.24,
0
)
)
);
}
const arc = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(arcPoints),
new THREE.LineDashedMaterial({
color: orange,
dashSize: 0.045,
gapSize: 0.026
})
);
arc.computeLineDistances();
scene.add(arc);
const contactDot = new THREE.Mesh(
new THREE.SphereGeometry(0.027, 16, 12),
new THREE.MeshBasicMaterial({ color: orange })
);
contactDot.position.copy(contactPoint);
scene.add(contactDot);
// ---------------------------------------------------------------
// Tangential perimeter-pull guides
// ---------------------------------------------------------------
const surfaceGuides = new THREE.Group();
scene.add(surfaceGuides);
// Circular frame arrows
for (let index = 0; index < 6; index++) {
const angle = (index / 6) * Math.PI * 2 + 0.18;
const radius = 1.31;
const origin = new THREE.Vector3(
circleCenter.x + radius * Math.cos(angle),
circleCenter.y + 0.095,
circleCenter.z + radius * Math.sin(angle)
);
const direction = new THREE.Vector3(
-Math.sin(angle),
0,
Math.cos(angle)
);
surfaceGuides.add(
new THREE.ArrowHelper(
direction,
origin,
0.34,
orange,
0.11,
0.075
)
);
}
// Rectangular frame arrows
const rectY = rectangleCenter.y + 0.095;
const rectLeft = rectangleCenter.x - rectangleWidth / 2 - 0.10;
const rectRight = rectangleCenter.x + rectangleWidth / 2 + 0.10;
const rectBack = rectangleCenter.z - rectangleDepth / 2 - 0.10;
const rectFront = rectangleCenter.z + rectangleDepth / 2 + 0.10;
for (const x of [rectangleCenter.x - 0.48, rectangleCenter.x + 0.48]) {
surfaceGuides.add(
new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(x, rectY, rectBack),
0.34,
orange,
0.11,
0.075
)
);
surfaceGuides.add(
new THREE.ArrowHelper(
new THREE.Vector3(-1, 0, 0),
new THREE.Vector3(x, rectY, rectFront),
0.34,
orange,
0.11,
0.075
)
);
}
for (const z of [rectangleCenter.z - 0.34, rectangleCenter.z + 0.34]) {
surfaceGuides.add(
new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(rectRight, rectY, z),
0.34,
orange,
0.11,
0.075
)
);
surfaceGuides.add(
new THREE.ArrowHelper(
new THREE.Vector3(0, 0, -1),
new THREE.Vector3(rectLeft, rectY, z),
0.34,
orange,
0.11,
0.075
)
);
}
// ---------------------------------------------------------------
// DOM annotations projected from world-space anchors
// ---------------------------------------------------------------
const labelEntries = [
{
element: document.querySelector("#circleLabel"),
anchor: new THREE.Vector3(-1.65, 3.00, 0)
},
{
element: document.querySelector("#rectangleLabel"),
anchor: new THREE.Vector3(1.75, 3.02, -0.15)
},
{
element: document.querySelector("#wettingLabel"),
anchor: new THREE.Vector3(0, 1.37, 2.25)
},
{
element: document.querySelector("#angleLabel"),
anchor: new THREE.Vector3(0.82, 0.91, 2.80)
}
];
const projected = new THREE.Vector3();
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
for (const entry of labelEntries) {
projected.copy(entry.anchor).project(camera);
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
const visible =
projected.z > -1 &&
projected.z < 1 &&
x > -150 &&
x < width + 150 &&
y > -100 &&
y < height + 100;
entry.element.style.opacity = visible ? "1" : "0";
entry.element.style.transform =
`translate3d(${x.toFixed(2)}px, ${y.toFixed(2)}px, 0) ` +
"translate(-50%, -50%)";
}
}
// ---------------------------------------------------------------
// Custom camera interaction — no camera-control addons
// ---------------------------------------------------------------
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.classList.add("dragging");
canvas.focus();
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.32,
1.46
);
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event.pointerId !== undefined &&
canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.8,
14
);
},
{ passive: false }
);
function resetView() {
orbit.radius = window.innerWidth < 700 ? 11.7 : 9.6;
orbit.theta = 0.48;
orbit.phi = 1.04;
orbit.target.set(0, 1.25, 0);
}
canvas.addEventListener("dblclick", resetView);
document.querySelector("#resetButton").addEventListener("click", resetView);
const guidesButton = document.querySelector("#guidesButton");
guidesButton.addEventListener("click", () => {
surfaceGuides.visible = !surfaceGuides.visible;
guidesButton.setAttribute(
"aria-pressed",
String(surfaceGuides.visible)
);
guidesButton.textContent = surfaceGuides.visible
? "Hide pull guides"
: "Show pull guides";
});
window.addEventListener("keydown", (event) => {
if (event.target instanceof HTMLInputElement ||
event.target instanceof HTMLTextAreaElement) {
return;
}
switch (event.key) {
case "ArrowLeft":
orbit.theta -= 0.08;
break;
case "ArrowRight":
orbit.theta += 0.08;
break;
case "ArrowUp":
orbit.phi = Math.max(0.32, orbit.phi - 0.05);
break;
case "ArrowDown":
orbit.phi = Math.min(1.46, orbit.phi + 0.05);
break;
case "+":
case "=":
orbit.radius = Math.max(5.8, orbit.radius - 0.35);
break;
case "-":
orbit.radius = Math.min(14, orbit.radius + 0.35);
break;
case "r":
case "R":
resetView();
break;
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", resize);
function animate() {
updateCamera();
updateLabels();
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```