Prompt specification
Build or customize the Three.js 3D scene "Water-strider support exhibit" 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: Water-strider support exhibit
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/water-strider-support-exhibit-x1503
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing surface tension and wetting. Compose a stylized insect over a water surface with local dimples under its legs; explain surface-force support qualitatively without treating the insect as resting on a solid sheet. Voxel style.
Working Three.js Starter (water-strider-support-exhibit-x1503):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Voxel Water Strider — Surface Tension & Wetting</title>
<style>
:root {
--ink: #143b3d;
--muted: #527274;
--paper: rgba(247, 253, 249, 0.91);
--line: rgba(20, 59, 61, 0.14);
--teal: #16b8ad;
--teal-dark: #087d79;
--gold: #efb84d;
--shadow: 0 18px 48px rgba(10, 61, 65, 0.18);
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #bfe5e4;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.title-card {
position: absolute;
top: 24px;
left: 24px;
width: min(430px, calc(100vw - 48px));
pointer-events: none;
}
.eyebrow {
display: inline-flex;
align-items: center;
gap: 8px;
margin-bottom: 10px;
color: var(--teal-dark);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 9px;
height: 9px;
background: var(--gold);
box-shadow: 4px 4px 0 rgba(239, 184, 77, 0.28);
}
h1 {
margin: 0;
max-width: 420px;
font-size: clamp(30px, 4.2vw, 54px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 390px;
margin: 14px 0 0;
color: #365f61;
font-size: 14px;
line-height: 1.5;
text-wrap: balance;
}
.concept {
position: absolute;
top: 24px;
right: 24px;
width: 350px;
padding: 20px;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 18px;
background: var(--paper);
box-shadow: var(--shadow);
backdrop-filter: blur(14px);
pointer-events: auto;
}
.chip {
display: inline-block;
margin-bottom: 12px;
padding: 6px 9px;
border: 1px solid rgba(8, 125, 121, 0.18);
border-radius: 7px;
color: var(--teal-dark);
background: rgba(22, 184, 173, 0.08);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.concept h2 {
margin: 0 0 9px;
font-size: 21px;
letter-spacing: -0.025em;
}
.concept p {
margin: 0;
color: #466668;
font-size: 13px;
line-height: 1.55;
}
.force-balance {
display: flex;
align-items: center;
gap: 10px;
margin: 15px 0;
padding: 11px 12px;
border-left: 4px solid var(--teal);
border-radius: 0 8px 8px 0;
background: rgba(22, 184, 173, 0.08);
color: var(--teal-dark);
font-size: 12px;
font-weight: 750;
line-height: 1.35;
}
.force-balance span {
flex: none;
width: 7px;
height: 7px;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 184, 173, 0.12);
}
.concept dl {
display: grid;
grid-template-columns: 82px 1fr;
gap: 9px 11px;
margin: 0;
font-size: 12px;
line-height: 1.42;
}
.concept dt {
color: var(--ink);
font-weight: 800;
}
.concept dd {
margin: 0;
color: #567174;
}
.note {
margin-top: 15px !important;
padding-top: 13px;
border-top: 1px solid var(--line);
color: #6a5850 !important;
font-size: 11px !important;
}
.toolbar {
position: absolute;
left: 24px;
bottom: 24px;
display: flex;
flex-wrap: wrap;
gap: 8px;
max-width: calc(100vw - 48px);
pointer-events: auto;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.66);
border-radius: 9px;
padding: 10px 12px;
color: var(--ink);
background: rgba(248, 253, 250, 0.88);
box-shadow: 0 8px 22px rgba(16, 70, 72, 0.12);
backdrop-filter: blur(10px);
cursor: pointer;
font: 700 11px/1 Inter, ui-sans-serif, system-ui, sans-serif;
letter-spacing: 0.025em;
transition: transform 120ms ease, background 120ms ease;
}
button:hover {
transform: translateY(-1px);
background: #fff;
}
button:active { transform: translateY(0); }
button[aria-pressed="true"] {
color: white;
border-color: var(--teal-dark);
background: var(--teal-dark);
}
.legend {
position: absolute;
right: 24px;
bottom: 24px;
display: grid;
gap: 8px;
padding: 12px 14px;
border: 1px solid rgba(255, 255, 255, 0.54);
border-radius: 12px;
background: rgba(247, 253, 249, 0.75);
box-shadow: 0 12px 30px rgba(10, 61, 65, 0.11);
backdrop-filter: blur(10px);
color: #4d696a;
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
.legend div {
display: flex;
align-items: center;
gap: 8px;
}
.swatch {
width: 18px;
height: 7px;
border-radius: 2px;
}
.swatch.teal { background: var(--teal); }
.swatch.gold { background: var(--gold); }
.swatch.wave {
position: relative;
width: 20px;
height: 9px;
border-bottom: 2px solid #2b8e91;
}
.swatch.wave::before {
content: "";
position: absolute;
left: 2px;
top: 1px;
width: 15px;
height: 7px;
border-bottom: 2px solid #2b8e91;
border-radius: 50%;
transform: rotate(-8deg);
}
.callout {
position: absolute;
display: flex;
align-items: center;
gap: 9px;
min-width: 150px;
padding: 9px 11px;
border: 1px solid rgba(255, 255, 255, 0.72);
border-radius: 10px;
background: rgba(248, 253, 250, 0.88);
box-shadow: 0 10px 28px rgba(10, 61, 65, 0.15);
backdrop-filter: blur(10px);
transform: translate(-50%, -100%);
transition: opacity 100ms ease;
pointer-events: none;
}
.callout::after {
content: "";
position: absolute;
left: 50%;
top: 100%;
width: 1px;
height: 21px;
background: rgba(20, 59, 61, 0.35);
}
.pin {
flex: none;
width: 9px;
height: 9px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(22, 184, 173, 0.15);
}
.pin.gold {
background: var(--gold);
box-shadow: 0 0 0 4px rgba(239, 184, 77, 0.17);
}
.callout b {
display: block;
color: var(--ink);
font-size: 11px;
line-height: 1.2;
}
.callout small {
display: block;
margin-top: 3px;
color: #668083;
font-size: 9px;
line-height: 1.3;
}
.hint {
position: absolute;
left: 50%;
bottom: 25px;
transform: translateX(-50%);
color: rgba(20, 59, 61, 0.65);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.05em;
pointer-events: none;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #c8e9e6;
color: var(--ink);
font-size: 12px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
transition: opacity 350ms ease;
}
#loading.ready {
opacity: 0;
pointer-events: none;
}
@media (max-width: 860px) {
.title-card {
top: 16px;
left: 16px;
}
h1 {
max-width: 300px;
font-size: 31px;
}
.subtitle {
max-width: 300px;
font-size: 12px;
}
.concept {
top: auto;
right: 14px;
bottom: 14px;
left: 14px;
width: auto;
max-height: 36vh;
padding: 15px;
overflow: auto;
}
.concept h2 { font-size: 17px; }
.concept p, .concept dl { font-size: 11px; }
.force-balance { margin: 10px 0; }
.toolbar {
left: 14px;
bottom: calc(36vh + 26px);
}
.legend, .hint, .callout { display: none; }
}
</style>
</head>
<body>
<div id="loading">Building the liquid interface…</div>
<div class="hud">
<header class="title-card">
<div class="eyebrow">Surface tension · wetting</div>
<h1>Six points of contact</h1>
<p class="subtitle">
A voxel water strider rests on a deformable liquid interface.
The curved menisci redirect surface tension into an upward force.
</p>
</header>
<aside class="concept">
<span class="chip">Qualitative liquid-interface model</span>
<h2>Why it does not sink</h2>
<p>
The feet meet the water over small contact regions, representing partial
wetting and a high contact angle. Each foot depresses the liquid into a
local meniscus.
</p>
<div class="force-balance">
<span></span>
<div>Net upward liquid force ≈ insect weight</div>
</div>
<dl>
<dt>Wetting</dt>
<dd>A small contact line and high contact angle bend the interface around each foot.</dd>
<dt>Surface tension</dt>
<dd>The liquid–air surface pulls tangentially along that curved interface.</dd>
<dt>Support</dt>
<dd>The tilted tangents produce upward components. Together with buoyancy, their sum offsets weight.</dd>
</dl>
<p class="note">
This is not support from a rigid sheet. The surface is liquid: it flows,
redistributes pressure, and changes shape under the insect.
</p>
</aside>
<nav class="toolbar" aria-label="Scene controls">
<button id="pauseButton" type="button">Pause water</button>
<button id="guideButton" type="button" aria-pressed="true">Force guides</button>
<button id="viewButton" type="button">Low angle</button>
<button id="resetButton" type="button">Reset view</button>
</nav>
<div class="legend" aria-hidden="true">
<div><span class="swatch teal"></span>upward force component</div>
<div><span class="swatch gold"></span>tangential surface pull</div>
<div><span class="swatch wave"></span>local liquid meniscus</div>
</div>
<div id="meniscusLabel" class="callout">
<span class="pin"></span>
<div><b>Local meniscus</b><small>the liquid surface bends downward</small></div>
</div>
<div id="wettingLabel" class="callout">
<span class="pin gold"></span>
<div><b>Partial wetting</b><small>a small contact region near the foot</small></div>
</div>
<div id="forceLabel" class="callout">
<span class="pin"></span>
<div><b>Upward component</b><small>curved tension vectors add together</small></div>
</div>
<div class="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Renderer, scene, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xbfe5e4);
scene.fog = new THREE.Fog(0xbfe5e4, 11, 25);
const camera = new THREE.PerspectiveCamera(
39,
innerWidth / innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xe9ffff, 0x173f42, 2.2);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff4d7, 3.1);
sun.position.set(5, 10, 6);
sun.castShadow = true;
sun.shadow.mapSize.set(1024, 1024);
sun.shadow.camera.left = -8;
sun.shadow.camera.right = 8;
sun.shadow.camera.top = 8;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 25;
sun.shadow.bias = -0.0007;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x8ff2e5, 1.25);
rimLight.position.set(-6, 4, -5);
scene.add(rimLight);
const target = new THREE.Vector3(0, 0.72, 0.05);
let yaw = 0.72;
let pitch = 0.40;
let radius = 8.4;
let targetYaw = yaw;
let targetPitch = pitch;
let targetRadius = radius;
function updateCamera() {
const horizontal = radius * Math.sin(pitch);
camera.position.set(
target.x + horizontal * Math.sin(yaw),
target.y + radius * Math.cos(pitch),
target.z + horizontal * Math.cos(yaw)
);
camera.lookAt(target);
}
function setView(low = false) {
targetYaw = low ? 0.88 : 0.72;
targetPitch = low ? 0.17 : 0.40;
targetRadius = low ? 7.2 : 8.4;
}
updateCamera();
// -------------------------------------------------------------------------
// Materials and voxel helpers
// -------------------------------------------------------------------------
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.78,
metalness: options.metalness ?? 0.02,
transparent: options.transparent ?? false,
opacity: options.opacity ?? 1,
depthWrite: options.depthWrite ?? true,
flatShading: options.flatShading ?? true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
const darkBody = material(0x173d3c, { roughness: 0.68 });
const bodyGreen = material(0x285d58, { roughness: 0.72 });
const bodyTeal = material(0x3b8b7e, { roughness: 0.65 });
const legMat = material(0x102f31, { roughness: 0.74 });
const jointMat = material(0x214b47, { roughness: 0.72 });
const goldMat = material(0xe8ad3d, { roughness: 0.56 });
const eyeMat = material(0x081d20, { roughness: 0.32 });
const patchMat = new THREE.MeshBasicMaterial({
color: 0xf1b84c,
transparent: true,
opacity: 0.84,
depthWrite: false
});
const upwardMat = new THREE.MeshBasicMaterial({
color: 0x29d8c5,
transparent: true,
opacity: 0.62,
depthWrite: false
});
const tangentMat = new THREE.MeshBasicMaterial({
color: 0xffca55,
transparent: true,
opacity: 0.94,
depthWrite: false
});
function box(parent, size, position, mat, shadow = true) {
const mesh = new THREE.Mesh(new THREE.BoxGeometry(...size), mat);
mesh.position.set(...position);
mesh.castShadow = shadow;
mesh.receiveShadow = shadow;
parent.add(mesh);
return mesh;
}
const Y_AXIS = new THREE.Vector3(0, 1, 0);
function boxBetween(parent, a, b, width, depth, mat) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, length, depth),
mat
);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(Y_AXIS, direction.normalize());
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Water surface: a moving liquid interface with six Gaussian dimples
// -------------------------------------------------------------------------
const contacts = [];
const legs = [];
const rows = [0.86, 0.03, -0.82];
for (const side of [-1, 1]) {
rows.forEach((z, rowIndex) => {
const spread = rowIndex === 1 ? 2.42 : 2.18;
const footZ = z + (rowIndex === 0 ? 0.12 : rowIndex === 2 ? -0.13 : 0.02);
contacts.push(new THREE.Vector2(side * spread, footZ));
legs.push({ side, rowIndex, z, spread, footZ });
});
}
const waterUniforms = {
uTime: { value: 0 },
uDepthScale: { value: 1 },
uContacts: {
value: contacts.map((p) => new THREE.Vector2(p.x, p.y))
}
};
const waterMaterial = new THREE.MeshStandardMaterial({
color: 0x2ca8a5,
roughness: 0.30,
metalness: 0.05,
transparent: true,
opacity: 0.86,
depthWrite: false,
side: THREE.DoubleSide
});
waterMaterial.onBeforeCompile = (shader) => {
shader.uniforms.uTime = waterUniforms.uTime;
shader.uniforms.uDepthScale = waterUniforms.uDepthScale;
shader.uniforms.uContacts = waterUniforms.uContacts;
shader.vertexShader = shader.vertexShader
.replace(
"#include <common>",
`
#include <common>
uniform float uTime;
uniform float uDepthScale;
uniform vec2 uContacts[6];
varying float vHeight;
varying float vMeniscus;
float surfaceHeightAt(vec2 p) {
float h = 0.0;
// Gentle free-surface motion, independent of the local dimples.
h += 0.018 * sin(p.x * 2.1 + uTime * 1.15)
* cos(p.y * 1.7 - uTime * 0.80);
h += 0.010 * sin(length(p - vec2(4.0, -3.0)) * 3.0
- uTime * 1.60);
for (int i = 0; i < 6; i++) {
vec2 d = p - uContacts[i];
float r2 = dot(d, d);
float r = sqrt(r2);
// Depression under the foot.
h += -0.16 * uDepthScale * exp(-r2 / 0.24);
// Raised meniscus rim around the depression.
float ring = exp(-pow(r - 0.46, 2.0) / 0.012);
h += 0.055 * uDepthScale * ring;
}
return h;
}
float meniscusAt(vec2 p) {
float m = 0.0;
for (int i = 0; i < 6; i++) {
vec2 d = p - uContacts[i];
float r = length(d);
m += exp(-pow(r - 0.46, 2.0) / 0.018);
}
return clamp(m, 0.0, 1.0);
}
`
)
.replace(
"#include <beginnormal_vertex>",
`
vec3 objectNormal = vec3(normal);
float normalEps = 0.025;
float hCenter = surfaceHeightAt(position.xz);
float hX = surfaceHeightAt(position.xz + vec2(normalEps, 0.0));
float hZ = surfaceHeightAt(position.xz + vec2(0.0, normalEps));
objectNormal = normalize(vec3(
hCenter - hX,
normalEps,
hCenter - hZ
));
#ifdef USE_TANGENT
vec3 objectTangent = vec3(tangent.xyz);
#endif
`
)
.replace(
"#include <begin_vertex>",
`
#include <begin_vertex>
float displacedHeight = surfaceHeightAt(position.xz);
transformed.y += displacedHeight;
vHeight = displacedHeight;
vMeniscus = meniscusAt(position.xz);
`
);
shader.fragmentShader = shader.fragmentShader
.replace(
"#include <common>",
`
#include <common>
varying float vHeight;
varying float vMeniscus;
`
)
.replace(
"#include <color_fragment>",
`
#include <color_fragment>
float depressionTint = smoothstep(-0.18, 0.025, vHeight);
diffuseColor.rgb = mix(
vec3(0.025, 0.27, 0.34),
diffuseColor.rgb,
depressionTint
);
diffuseColor.rgb += vec3(0.18, 0.48, 0.34) * vMeniscus * 0.62;
`
);
};
waterMaterial.customProgramCacheKey = () => "voxel-liquid-interface-v1";
const waterGeometry = new THREE.PlaneGeometry(24, 24, 120, 120);
waterGeometry.rotateX(-Math.PI / 2);
const water = new THREE.Mesh(waterGeometry, waterMaterial);
water.receiveShadow = true;
water.renderOrder = 1;
scene.add(water);
// A deep, separate backdrop suggests liquid depth without turning the
// surface itself into a rigid support sheet.
const bottom = new THREE.Mesh(
new THREE.PlaneGeometry(42, 42),
material(0x1b5960, { roughness: 1, flatShading: false })
);
bottom.rotation.x = -Math.PI / 2;
bottom.position.y = -2.3;
bottom.receiveShadow = true;
scene.add(bottom);
// Sparse submerged voxel stones, kept away from the insect.
let seed = 19;
function random() {
seed = (seed * 16807) % 2147483647;
return (seed - 1) / 2147483646;
}
const stoneMats = [
material(0x396c6c),
material(0x477a73),
material(0x2e6264)
];
for (let i = 0; i < 20; i++) {
const angle = random() * Math.PI * 2;
const distance = 4.5 + random() * 8;
const sx = 0.25 + random() * 0.8;
const sy = 0.2 + random() * 0.55;
const sz = 0.3 + random() * 0.75;
const stone = box(
scene,
[sx, sy, sz],
[
Math.cos(angle) * distance,
-2.17 + sy * 0.5,
Math.sin(angle) * distance
],
stoneMats[i % stoneMats.length],
false
);
stone.rotation.y = random() * Math.PI;
}
// -------------------------------------------------------------------------
// Voxel insect
// -------------------------------------------------------------------------
const insect = new THREE.Group();
scene.add(insect);
// Segmented body and thorax.
box(insect, [1.28, 0.66, 0.86], [0, 1.34, 0.58], bodyTeal);
box(insect, [1.12, 0.50, 0.72], [0, 1.30, -0.20], bodyGreen);
box(insect, [0.94, 0.42, 0.72], [0, 1.26, -0.88], bodyGreen);
box(insect, [0.72, 0.34, 0.54], [0, 1.23, -1.46], darkBody);
box(insect, [0.96, 0.56, 0.74], [0, 1.43, 1.29], darkBody);
// Dorsal accent blocks.
box(insect, [0.34, 0.09, 0.22], [0, 1.72, 0.56], goldMat);
box(insect, [0.28, 0.08, 0.18], [0, 1.59, -0.15], goldMat);
box(insect, [0.21, 0.07, 0.15], [0, 1.50, -0.72], goldMat);
// Head details and blocky eyes.
box(insect, [0.24, 0.24, 0.14], [-0.33, 1.58, 1.71], eyeMat);
box(insect, [0.24, 0.24, 0.14], [0.33, 1.58, 1.71], eyeMat);
box(insect, [0.12, 0.11, 0.16], [-0.17, 1.28, 1.74], goldMat);
box(insect, [0.12, 0.11, 0.16], [0.17, 1.28, 1.74], goldMat);
// Antennae.
boxBetween(
insect,
[-0.30, 1.67, 1.49],
[-0.57, 2.02, 1.86],
0.055,
0.055,
darkBody
);
boxBetween(
insect,
[-0.57, 2.02, 1.86],
[-0.68, 2.20, 2.25],
0.045,
0.045,
darkBody
);
boxBetween(
insect,
[0.30, 1.67, 1.49],
[0.57, 2.02, 1.86],
0.055,
0.055,
darkBody
);
boxBetween(
insect,
[0.57, 2.02, 1.86],
[0.68, 2.20, 2.25],
0.045,
0.045,
darkBody
);
box(insect, [0.09, 0.09, 0.09], [-0.68, 2.20, 2.25], goldMat);
box(insect, [0.09, 0.09, 0.09], [0.68, 2.20, 2.25], goldMat);
// Six jointed legs. The final segment reaches the depressed water surface.
legs.forEach((leg) => {
const side = leg.side;
const hip = [side * 0.56, 1.29, leg.z];
const knee = [
side * 1.29,
0.64,
leg.z + (leg.rowIndex === 0 ? 0.09 : leg.rowIndex === 2 ? -0.08 : 0)
];
const foot = [
side * leg.spread,
-0.115,
leg.footZ
];
boxBetween(insect, hip, knee, 0.115, 0.115, legMat);
box(insect, [0.17, 0.17, 0.17], knee, jointMat);
boxBetween(insect, knee, foot, 0.075, 0.085, legMat);
box(insect, [0.28, 0.10, 0.34], foot, darkBody);
// Small square contact/wetting region around the foot.
const patch = new THREE.Group();
patch.position.set(foot[0], -0.125, foot[2]);
box(patch, [0.12, 0.014, 0.34], [-0.20, 0, 0], patchMat, false);
box(patch, [0.12, 0.014, 0.34], [0.20, 0, 0], patchMat, false);
box(patch, [0.28, 0.014, 0.12], [0, 0, -0.17], patchMat, false);
box(patch, [0.28, 0.014, 0.12], [0, 0, 0.17], patchMat, false);
patch.renderOrder = 3;
insect.add(patch);
});
// -------------------------------------------------------------------------
// Force guides: vertical resultant components and tangential pulls
// -------------------------------------------------------------------------
const guideGroup = new THREE.Group();
guideGroup.visible = true;
scene.add(guideGroup);
contacts.forEach((contact, index) => {
const x = contact.x;
const z = contact.y;
// The vertical guide represents the summed upward component, not an
// individual force pushing straight up from a solid surface.
const shaft = box(
guideGroup,
[0.028, 0.60, 0.028],
[x, 0.24, z],
upwardMat,
false
);
shaft.renderOrder = 4;
box(
guideGroup,
[0.11, 0.11, 0.11],
[x, 0.57, z],
upwardMat,
false
).renderOrder = 4;
// Short gold strokes follow the local tangent of the meniscus.
if (index % 2 === 0) {
const angle = index === 0 ? 0.65 : -0.35;
const radius = 0.50;
const px = x + Math.cos(angle) * radius;
const pz = z + Math.sin(angle) * radius;
const py = 0.045;
const tangent = new THREE.Vector3(-Math.sin(angle), 0, Math.cos(angle));
const a = new THREE.Vector3(px, py, pz).addScaledVector(tangent, -0.20);
const b = new THREE.Vector3(px, py, pz).addScaledVector(tangent, 0.20);
boxBetween(
guideGroup,
a.toArray(),
b.toArray(),
0.025,
0.025,
tangentMat
);
// Voxel arrowhead.
const headCenter = b.clone();
const left = headCenter.clone().addScaledVector(tangent, -0.10);
const right = headCenter.clone().addScaledVector(tangent, 0.10);
left.y += 0.055;
right.y += 0.055;
boxBetween(
guideGroup,
headCenter.toArray(),
left.toArray(),
0.025,
0.025,
tangentMat
);
boxBetween(
guideGroup,
headCenter.toArray(),
right.toArray(),
0.025,
0.025,
tangentMat
);
}
});
// -------------------------------------------------------------------------
// Direct camera controls — no imported examples or controls modules
// -------------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
targetYaw -= dx * 0.006;
targetPitch = THREE.MathUtils.clamp(targetPitch + dy * 0.005, 0.10, 1.22);
});
function endDrag(event) {
dragging = false;
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
targetRadius = THREE.MathUtils.clamp(
targetRadius + event.deltaY * 0.006,
5.1,
13.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
setView(false);
lowView = false;
viewButton.textContent = "Low angle";
});
// -------------------------------------------------------------------------
// UI
// -------------------------------------------------------------------------
let paused = false;
let lowView = false;
const pauseButton = document.getElementById("pauseButton");
const guideButton = document.getElementById("guideButton");
const viewButton = document.getElementById("viewButton");
const resetButton = document.getElementById("resetButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume water" : "Pause water";
pauseButton.setAttribute("aria-pressed", String(paused));
});
guideButton.addEventListener("click", () => {
guideGroup.visible = !guideGroup.visible;
guideButton.setAttribute("aria-pressed", String(guideGroup.visible));
});
viewButton.addEventListener("click", () => {
lowView = !lowView;
setView(lowView);
viewButton.textContent = lowView ? "Perspective" : "Low angle";
});
resetButton.addEventListener("click", () => {
setView(false);
lowView = false;
viewButton.textContent = "Low angle";
});
// -------------------------------------------------------------------------
// Screen-space labels projected from world-space anchors
// -------------------------------------------------------------------------
const labels = [
{
element: document.getElementById("meniscusLabel"),
position: new THREE.Vector3(contacts[0].x, 0.05, contacts[0].y),
offset: [-48, -18]
},
{
element: document.getElementById("wettingLabel"),
position: new THREE.Vector3(contacts[3].x, 0.01, contacts[3].y),
offset: [52, -8]
},
{
element: document.getElementById("forceLabel"),
position: new THREE.Vector3(contacts[4].x, 0.64, contacts[4].y),
offset: [56, -12]
}
];
const projected = new THREE.Vector3();
function updateLabels() {
for (const label of labels) {
projected.copy(label.position).project(camera);
const visible = projected.z > -1 && projected.z < 1;
label.element.style.visibility = visible ? "visible" : "hidden";
if (!visible) continue;
const x = (projected.x * 0.5 + 0.5) * innerWidth;
const y = (-projected.y * 0.5 + 0.5) * innerHeight;
label.element.style.left = `${x}px`;
label.element.style.top = `${y}px`;
label.element.style.transform =
`translate(calc(-50% + ${label.offset[0]}px), ` +
`calc(-100% + ${label.offset[1]}px))`;
}
}
// -------------------------------------------------------------------------
// Animation and resize
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
let firstFrame = true;
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) waterUniforms.uTime.value += dt;
yaw += (targetYaw - yaw) * 0.12;
pitch += (targetPitch - pitch) * 0.12;
radius += (targetRadius - radius) * 0.12;
updateCamera();
updateLabels();
renderer.render(scene, camera);
if (firstFrame) {
firstFrame = false;
document.getElementById("loading").classList.add("ready");
setTimeout(() => document.getElementById("loading").remove(), 450);
}
}
animate();
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
});
</script>
</body>
</html>
```