Prompt specification
Build or customize the Three.js 3D scene "Wetting versus beading sample" 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: Wetting versus beading sample
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/wetting-versus-beading-sample-x0610
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring rainwear and water-repellent fabric. Compare two fabric tiles under identical droplet streams; water beads on one and spreads on the other according to a clearly labeled simplified surface model. Low-poly.
Working Three.js Starter (wetting-versus-beading-sample-x0610):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Rainwear Surface Lab</title>
<style>
:root {
color-scheme: dark;
--ink: #e9f4f5;
--muted: #91a8af;
--panel: rgba(9, 20, 26, 0.78);
--line: rgba(180, 221, 228, 0.16);
--bead: #70e4f2;
--spread: #f2b66d;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071117;
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: var(--ink);
}
button,
canvas {
-webkit-tap-highlight-color: transparent;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 43%, transparent 34%, rgba(2, 8, 12, 0.34) 100%),
linear-gradient(180deg, rgba(2, 8, 12, 0.26), transparent 28%, transparent 70%, rgba(2, 8, 12, 0.38));
}
.grain {
position: fixed;
inset: 0;
pointer-events: none;
opacity: 0.035;
background-image:
repeating-radial-gradient(circle at 20% 30%, #fff 0 0.6px, transparent 0.8px 4px),
repeating-radial-gradient(circle at 80% 70%, #fff 0 0.5px, transparent 0.8px 5px);
background-size: 8px 9px, 11px 13px;
}
header {
position: fixed;
top: 26px;
left: 30px;
z-index: 5;
max-width: 590px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 11px;
color: #b6c9ce;
font: 700 10px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
letter-spacing: 0.19em;
text-transform: uppercase;
}
.live-dot {
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--bead);
box-shadow: 0 0 12px rgba(112, 228, 242, 0.8);
animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% { opacity: 0.45; transform: scale(0.85); }
50% { opacity: 1; transform: scale(1.08); }
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 55px);
font-weight: 720;
line-height: 0.96;
letter-spacing: -0.055em;
}
h1 span {
color: #7f9aa2;
font-weight: 420;
}
header p {
max-width: 510px;
margin: 13px 0 0;
color: #9fb4ba;
font-size: 13px;
line-height: 1.55;
}
.top-right {
position: fixed;
top: 25px;
right: 28px;
z-index: 8;
display: flex;
align-items: flex-start;
gap: 18px;
}
.conditions {
min-width: 220px;
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 8px;
background: rgba(6, 17, 23, 0.62);
backdrop-filter: blur(12px);
}
.conditions-title {
margin-bottom: 8px;
color: #718b93;
font: 700 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.condition-row {
display: flex;
justify-content: space-between;
gap: 22px;
padding: 3px 0;
color: #8ea5ac;
font: 600 10px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.condition-row strong {
color: #dcebed;
font-weight: 650;
}
.controls {
display: flex;
gap: 7px;
pointer-events: auto;
}
button {
height: 36px;
padding: 0 13px;
border: 1px solid rgba(174, 215, 222, 0.22);
border-radius: 6px;
background: rgba(11, 27, 34, 0.82);
color: #d7e6e8;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 160ms ease;
}
button:hover {
border-color: rgba(112, 228, 242, 0.6);
background: rgba(20, 46, 55, 0.92);
}
button.active {
border-color: var(--spread);
color: var(--spread);
}
.camera-hint {
position: fixed;
top: 93px;
right: 29px;
z-index: 5;
color: rgba(167, 190, 196, 0.62);
font: 600 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.comparison {
position: fixed;
left: 50%;
bottom: 22px;
z-index: 6;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 18px;
width: min(1080px, calc(100% - 40px));
transform: translateX(-50%);
pointer-events: none;
}
.card {
position: relative;
overflow: hidden;
min-height: 172px;
padding: 16px 18px 14px;
border: 1px solid var(--line);
border-radius: 10px;
background:
linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 48%),
var(--panel);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.24);
backdrop-filter: blur(16px);
}
.card::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 4px;
height: 100%;
background: var(--accent);
box-shadow: 0 0 22px var(--accent);
}
.card.bead {
--accent: var(--bead);
}
.card.spread {
--accent: var(--spread);
}
.card-head {
display: flex;
align-items: center;
gap: 11px;
}
.index {
display: grid;
place-items: center;
width: 34px;
height: 34px;
border: 1px solid color-mix(in srgb, var(--accent) 60%, transparent);
border-radius: 50%;
color: var(--accent);
font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.card h2 {
margin: 0;
font-size: 15px;
line-height: 1;
letter-spacing: 0.075em;
}
.subtitle {
margin-top: 5px;
color: #829ba2;
font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.angle {
margin-left: auto;
color: var(--accent);
font: 750 25px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: -0.05em;
}
.angle small {
display: block;
margin-top: 5px;
color: #718a91;
font-size: 8px;
letter-spacing: 0.12em;
text-align: right;
text-transform: uppercase;
}
.model {
display: flex;
align-items: center;
gap: 10px;
margin-top: 13px;
padding: 9px 10px;
border: 1px solid rgba(172, 211, 218, 0.1);
border-radius: 5px;
background: rgba(0, 0, 0, 0.12);
}
.model-label {
color: #708991;
font: 700 8px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.model code {
margin-left: auto;
color: #dcebed;
font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.model code em {
color: var(--accent);
font-style: normal;
}
.metrics {
display: flex;
gap: 24px;
margin-top: 12px;
}
.metric {
display: flex;
align-items: baseline;
gap: 6px;
}
.metric b {
color: var(--ink);
font: 750 16px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.metric span {
color: #718a91;
font: 600 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.model-note {
position: fixed;
left: 50%;
bottom: 205px;
z-index: 5;
transform: translateX(-50%);
color: rgba(163, 186, 192, 0.6);
font: 600 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.11em;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
#error {
position: fixed;
inset: 0;
z-index: 20;
display: none;
place-items: center;
padding: 30px;
background: #071117;
color: #dcebed;
text-align: center;
}
@media (max-width: 860px) {
header {
top: 18px;
left: 18px;
max-width: 440px;
}
h1 {
font-size: 34px;
}
header p {
max-width: 370px;
font-size: 11px;
}
.top-right {
top: 17px;
right: 17px;
}
.conditions,
.camera-hint {
display: none;
}
.comparison {
bottom: 12px;
width: calc(100% - 24px);
gap: 9px;
}
.card {
min-height: 151px;
padding: 13px;
}
.model {
margin-top: 10px;
padding: 7px;
}
.model-label {
max-width: 82px;
}
.model-note {
bottom: 174px;
}
}
@media (max-width: 580px) {
header {
top: 14px;
left: 14px;
}
.eyebrow {
margin-bottom: 7px;
font-size: 8px;
}
h1 {
font-size: 28px;
}
header p {
display: none;
}
.controls {
gap: 5px;
}
button {
height: 32px;
padding: 0 9px;
font-size: 8px;
}
.comparison {
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.card {
min-height: 142px;
padding: 10px;
}
.card-head {
gap: 7px;
}
.index {
width: 25px;
height: 25px;
font-size: 10px;
}
.card h2 {
font-size: 11px;
}
.subtitle {
font-size: 7px;
}
.angle {
font-size: 18px;
}
.model {
display: block;
margin-top: 8px;
}
.model-label,
.model code {
display: block;
max-width: none;
margin: 0;
}
.model code {
margin-top: 5px;
font-size: 9px;
}
.metrics {
gap: 9px;
margin-top: 9px;
}
.metric {
display: block;
}
.metric b {
font-size: 13px;
}
.metric span {
display: block;
margin-top: 3px;
font-size: 6px;
}
.model-note {
display: none;
}
}
</style>
</head>
<body>
<div id="scene" aria-label="Interactive Three.js rainwear fabric comparison"></div>
<div class="vignette"></div>
<div class="grain"></div>
<header>
<div class="eyebrow">
<span class="live-dot"></span>
Material response / rainwear test 04
</div>
<h1>Rainwear <span>under pressure.</span></h1>
<p>
Two ripstop fabric tiles receive identical droplet streams.
One retains compact beads; the other develops a spreading wet film.
</p>
</header>
<div class="top-right">
<div class="conditions" aria-label="Test conditions">
<div class="conditions-title">Locked test input</div>
<div class="condition-row">
<span>Flow</span>
<strong>5.5 drops / sec</strong>
</div>
<div class="condition-row">
<span>Droplet</span>
<strong>Ø 2.4 mm</strong>
</div>
<div class="condition-row">
<span>Impacts</span>
<strong id="impactCount">000</strong>
</div>
</div>
<div class="controls">
<button id="pauseButton" type="button">Pause</button>
<button id="resetButton" type="button">Reset</button>
</div>
</div>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
<div class="model-note">
Illustrative contact-angle rule · simplified surface model · not CFD
</div>
<div class="comparison">
<section class="card bead" aria-label="Beading fabric results">
<div class="card-head">
<div class="index">A</div>
<div>
<h2>BEADING</h2>
<div class="subtitle">DWR-coated rainwear shell</div>
</div>
<div class="angle">
112°
<small>contact angle</small>
</div>
</div>
<div class="model">
<div class="model-label">Simplified<br />surface model</div>
<code><em>θ ≥ 90°</em> → r(t) = r₀</code>
</div>
<div class="metrics">
<div class="metric">
<b id="beadCount">0</b>
<span>beads held</span>
</div>
<div class="metric">
<b>CAP</b>
<span>surface state</span>
</div>
</div>
</section>
<section class="card spread" aria-label="Spreading fabric results">
<div class="card-head">
<div class="index">B</div>
<div>
<h2>SPREADING</h2>
<div class="subtitle">Untreated hydrophilic shell</div>
</div>
<div class="angle">
38°
<small>contact angle</small>
</div>
</div>
<div class="model">
<div class="model-label">Simplified<br />surface model</div>
<code><em>θ < 90°</em> → r(t) = r₀ + kΔt</code>
</div>
<div class="metrics">
<div class="metric">
<b id="spreadRadius">0.00</b>
<span>mean radius</span>
</div>
<div class="metric">
<b id="wetCoverage">0%</b>
<span>wet coverage</span>
</div>
</div>
</section>
</div>
<div id="error">
<div>
<h2>WebGL could not start.</h2>
<p>Please open this file in a browser with hardware acceleration enabled.</p>
</div>
</div>
<noscript>This scene requires JavaScript.</noscript>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const host = document.getElementById("scene");
const errorPanel = document.getElementById("error");
let renderer;
try {
renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
} catch (error) {
console.error(error);
errorPanel.style.display = "grid";
throw error;
}
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.setClearColor(0x071117, 1);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071117);
scene.fog = new THREE.FogExp2(0x071117, 0.026);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraState = {
yaw: 0,
pitch: 0.42,
distance: 12.2,
target: new THREE.Vector3(0, 2.0, 0)
};
function updateCamera() {
const aspect = window.innerWidth / window.innerHeight;
const portraitFit = aspect < 0.95
? Math.min(1.78, 1 + (0.95 - aspect) * 1.9)
: 1;
const distance = cameraState.distance * portraitFit;
const cosPitch = Math.cos(cameraState.pitch);
camera.position.set(
cameraState.target.x + Math.sin(cameraState.yaw) * cosPitch * distance,
cameraState.target.y + Math.sin(cameraState.pitch) * distance,
cameraState.target.z + Math.cos(cameraState.yaw) * cosPitch * distance
);
camera.lookAt(cameraState.target);
}
// Lighting
scene.add(new THREE.HemisphereLight(0xc8efff, 0x071017, 1.6));
const key = new THREE.DirectionalLight(0xffffff, 3.1);
key.position.set(-4.5, 8.5, 6.5);
key.castShadow = true;
key.shadow.mapSize.set(1024, 1024);
key.shadow.camera.left = -8;
key.shadow.camera.right = 8;
key.shadow.camera.top = 9;
key.shadow.camera.bottom = -5;
key.shadow.camera.near = 0.5;
key.shadow.camera.far = 25;
key.shadow.bias = -0.0008;
scene.add(key);
const rim = new THREE.DirectionalLight(0x6ab9d1, 1.6);
rim.position.set(6, 5, -7);
scene.add(rim);
const leftAccent = new THREE.PointLight(0x65e4ff, 12, 8, 2);
leftAccent.position.set(-4.5, 4.8, 2.3);
scene.add(leftAccent);
const rightAccent = new THREE.PointLight(0xffaa55, 9, 7, 2);
rightAccent.position.set(4.6, 4.4, 1.6);
scene.add(rightAccent);
// Procedural ripstop texture
function makeRipstopTexture() {
const canvas = document.createElement("canvas");
canvas.width = 256;
canvas.height = 256;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#425761";
ctx.fillRect(0, 0, 256, 256);
// Fine woven fibers
for (let y = 0; y < 256; y += 4) {
ctx.strokeStyle = y % 8 === 0
? "rgba(211,239,241,0.09)"
: "rgba(5,20,27,0.09)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(0, y + 0.5);
ctx.lineTo(256, y + 0.5);
ctx.stroke();
}
for (let x = 0; x < 256; x += 4) {
ctx.strokeStyle = x % 8 === 0
? "rgba(211,239,241,0.08)"
: "rgba(5,20,27,0.08)";
ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(x + 0.5, 0);
ctx.lineTo(x + 0.5, 256);
ctx.stroke();
}
// Reinforcing ripstop grid
for (let i = 0; i <= 256; i += 32) {
ctx.strokeStyle = "rgba(185,225,230,0.18)";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(i + 0.5, 0);
ctx.lineTo(i + 0.5, 256);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(0, i + 0.5);
ctx.lineTo(256, i + 0.5);
ctx.stroke();
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.repeat.set(2.4, 2.2);
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
const ripstopTexture = makeRipstopTexture();
// Shared materials and low-poly geometry
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0x172830,
roughness: 0.72,
metalness: 0.16,
flatShading: true
});
const frameMaterial = new THREE.MeshStandardMaterial({
color: 0x253a43,
roughness: 0.48,
metalness: 0.48,
flatShading: true
});
const metalMaterial = new THREE.MeshStandardMaterial({
color: 0x4b626b,
roughness: 0.38,
metalness: 0.7,
flatShading: true
});
const darkMetalMaterial = new THREE.MeshStandardMaterial({
color: 0x101c22,
roughness: 0.58,
metalness: 0.52,
flatShading: true
});
const baseFabricColor = new THREE.Color(0xb4c6ca);
const wetFabricColor = new THREE.Color(0x718e97);
function makeFabricMaterial() {
return new THREE.MeshStandardMaterial({
color: baseFabricColor,
map: ripstopTexture,
roughness: 0.94,
metalness: 0,
flatShading: true
});
}
function addBox(parent, size, position, material, castShadow = true) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(size[0], size[1], size[2]),
material
);
mesh.position.set(position[0], position[1], position[2]);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makePlaque(text, accent) {
const canvas = document.createElement("canvas");
canvas.width = 512;
canvas.height = 112;
const ctx = canvas.getContext("2d");
ctx.fillStyle = "rgba(6,16,21,0.94)";
ctx.fillRect(0, 0, 512, 112);
ctx.strokeStyle = accent;
ctx.lineWidth = 3;
ctx.strokeRect(2, 2, 508, 108);
ctx.fillStyle = accent;
ctx.fillRect(16, 16, 7, 80);
ctx.fillStyle = "#dcebed";
ctx.font = "700 33px monospace";
ctx.textBaseline = "middle";
ctx.fillText(text, 43, 57);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return new THREE.Mesh(
new THREE.PlaneGeometry(1.72, 0.36),
new THREE.MeshBasicMaterial({
map: texture,
transparent: true,
side: THREE.DoubleSide
})
);
}
function makeFabricGeometry() {
let geometry = new THREE.PlaneGeometry(3.34, 2.84, 10, 8);
geometry.rotateX(-Math.PI / 2);
geometry = geometry.toNonIndexed();
const positions = geometry.attributes.position;
for (let i = 0; i < positions.count; i++) {
const x = positions.getX(i);
const z = positions.getZ(i);
const y =
Math.sin(x * 7.1 + z * 3.2) * 0.009 +
Math.cos(z * 8.4 - x * 2.3) * 0.006;
positions.setY(i, y);
}
geometry.computeVertexNormals();
return geometry;
}
function buildTile(xPosition, plaqueText, accentColor) {
const group = new THREE.Group();
group.position.x = xPosition;
scene.add(group);
// Support plinth
addBox(
group,
[2.78, 1.14, 2.23],
[0, 0.57, 0],
bodyMaterial
);
addBox(
group,
[2.92, 0.10, 2.36],
[0, 0.05, 0],
darkMetalMaterial
);
// Tile body
addBox(
group,
[3.58, 0.32, 3.02],
[0, 1.30, 0],
bodyMaterial
);
// Fabric surface
const fabric = new THREE.Mesh(
makeFabricGeometry(),
makeFabricMaterial()
);
fabric.position.y = 1.468;
fabric.receiveShadow = true;
group.add(fabric);
// Metal edge rails
addBox(group, [3.63, 0.075, 0.075], [0, 1.48, 1.50], frameMaterial);
addBox(group, [3.63, 0.075, 0.075], [0, 1.48, -1.50], frameMaterial);
addBox(group, [0.075, 0.075, 3.03], [-1.79, 1.48, 0], frameMaterial);
addBox(group, [0.075, 0.075, 3.03], [1.79, 1.48, 0], frameMaterial);
// Corner fasteners
const boltGeometry = new THREE.CylinderGeometry(0.035, 0.035, 0.035, 6);
const boltMaterial = new THREE.MeshStandardMaterial({
color: 0x8ca0a5,
roughness: 0.4,
metalness: 0.72,
flatShading: true
});
for (const bx of [-1.65, 1.65]) {
for (const bz of [-1.37, 1.37]) {
const bolt = new THREE.Mesh(boltGeometry, boltMaterial);
bolt.position.set(bx, 1.525, bz);
bolt.castShadow = true;
group.add(bolt);
}
}
// Front plaque
const plaque = makePlaque(plaqueText, accentColor);
plaque.position.set(0, 1.29, 1.516);
group.add(plaque);
// Emitter stand
const stand = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.09, 3.0, 6),
darkMetalMaterial
);
stand.position.set(0, 2.95, -1.22);
stand.castShadow = true;
group.add(stand);
const arm = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.065, 1.32, 6),
metalMaterial
);
arm.rotation.x = Math.PI / 2;
arm.position.set(0, 4.45, -0.61);
arm.castShadow = true;
group.add(arm);
const nozzle = new THREE.Mesh(
new THREE.ConeGeometry(0.18, 0.32, 6),
metalMaterial
);
nozzle.rotation.z = Math.PI;
nozzle.position.set(0, 4.22, 0.02);
nozzle.castShadow = true;
group.add(nozzle);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.115, 0.025, 4, 8),
new THREE.MeshStandardMaterial({
color: accentColor,
emissive: accentColor,
emissiveIntensity: 0.42,
roughness: 0.28,
metalness: 0.35,
flatShading: true
})
);
ring.rotation.x = Math.PI / 2;
ring.position.set(0, 4.075, 0.02);
group.add(ring);
return {
group,
fabric,
surfaceY: 1.505,
beads: [],
patches: []
};
}
const leftTile = buildTile(-2.15, "A / BEADING", "#70e4f2");
const rightTile = buildTile(2.15, "B / SPREADING", "#f2b66d");
// Floor and grid
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(24, 18),
new THREE.MeshStandardMaterial({
color: 0x0b171d,
roughness: 0.96,
metalness: 0.04
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.012;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(24, 24, 0x35515c, 0x20343c);
grid.position.y = 0.005;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
// Low-poly droplet resources
const dropGeometry = new THREE.IcosahedronGeometry(1, 1);
const glintGeometry = new THREE.IcosahedronGeometry(1, 0);
const fallingMaterial = new THREE.MeshStandardMaterial({
color: 0xa9edff,
emissive: 0x174d60,
emissiveIntensity: 0.52,
roughness: 0.16,
metalness: 0.04,
transparent: true,
opacity: 0.9,
flatShading: true
});
const beadMaterial = new THREE.MeshStandardMaterial({
color: 0x70e4f2,
emissive: 0x0b4a58,
emissiveIntensity: 0.58,
roughness: 0.1,
metalness: 0.06,
transparent: true,
opacity: 0.91,
flatShading: true
});
const glintMaterial = new THREE.MeshBasicMaterial({
color: 0xf3feff,
transparent: true,
opacity: 0.82
});
const ringGeometry = new THREE.RingGeometry(0.08, 0.115, 12);
ringGeometry.rotateX(-Math.PI / 2);
// Deterministic random streams
let randomState = 0x04c0ffee;
function random() {
randomState = (randomState * 1664525 + 1013904223) >>> 0;
return randomState / 4294967296;
}
let effectRandomState = 0x91a7b2c3;
function effectRandom() {
effectRandomState =
(effectRandomState * 1664525 + 1013904223) >>> 0;
return effectRandomState / 4294967296;
}
const fallingDrops = [];
const impactEffects = [];
let simulationTime = 0;
let nextSpawnTime = 0;
let impactCount = 0;
let paused = false;
const spawnInterval = 1 / 5.5;
function createFallingMesh() {
const mesh = new THREE.Mesh(dropGeometry, fallingMaterial);
mesh.castShadow = true;
scene.add(mesh);
return mesh;
}
function spawnDrop(initialY = null) {
// These coordinates are shared by both tiles, guaranteeing identical input.
const localX = (random() - 0.5) * 1.35;
const localZ = (random() - 0.5) * 1.05;
const speed = 2.34 + random() * 0.18;
const y = initialY === null ? 4.01 : initialY;
const leftMesh = createFallingMesh();
const rightMesh = createFallingMesh();
leftMesh.position.set(leftTile.group.position.x + localX, y, localZ);
rightMesh.position.set(rightTile.group.position.x + localX, y, localZ);
leftMesh.scale.set(0.068, 0.14, 0.068);
rightMesh.scale.copy(leftMesh.scale);
fallingDrops.push({
localX,
localZ,
y,
speed,
leftMesh,
rightMesh
});
}
function makeBeadVisual(x, z, radius) {
const group = new THREE.Group();
group.position.set(x, leftTile.surfaceY + radius * 0.78, z);
const bead = new THREE.Mesh(dropGeometry, beadMaterial);
bead.scale.setScalar(radius);
bead.castShadow = true;
group.add(bead);
const glint = new THREE.Mesh(glintGeometry, glintMaterial);
glint.position.set(-radius * 0.28, radius * 0.55, radius * 0.64);
glint.scale.setScalar(radius * 0.16);
group.add(glint);
leftTile.group.add(group);
leftTile.beads.push({ group, radius });
}
function addBead(x, z, radius) {
let nearby = null;
for (const bead of leftTile.beads) {
const dx = bead.group.position.x - x;
const dz = bead.group.position.z - z;
if (dx * dx + dz * dz < 0.055) {
nearby = bead;
break;
}
}
if (nearby) {
leftTile.group.remove(nearby.group);
leftTile.beads.splice(leftTile.beads.indexOf(nearby), 1);
x = (x + nearby.group.position.x) * 0.5;
z = (z + nearby.group.position.z) * 0.5;
radius = Math.min(0.22, Math.sqrt(nearby.radius ** 2 + radius ** 2) * 1.04);
}
makeBeadVisual(x, z, radius);
if (leftTile.beads.length > 38) {
const old = leftTile.beads.shift();
leftTile.group.remove(old.group);
}
}
function makePatchGeometry() {
const segments = 11;
const positions = [0, 0, 0];
const indices = [];
for (let i = 0; i < segments; i++) {
const angle = (i / segments) * Math.PI * 2;
const radius = 0.78 + effectRandom() * 0.27;
positions.push(
Math.cos(angle) * radius,
0,
Math.sin(angle) * radius
);
}
for (let i = 0; i < segments; i++) {
const a = i + 1;
const b = ((i + 1) % segments) + 1;
indices.push(0, a, b);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function addPatch(x, z, radius) {
let nearby = null;
for (const patch of rightTile.patches) {
const dx = patch.mesh.position.x - x;
const dz = patch.mesh.position.z - z;
if (dx * dx + dz * dz < 0.06) {
nearby = patch;
break;
}
}
if (nearby) {
rightTile.group.remove(nearby.mesh);
rightTile.patches.splice(rightTile.patches.indexOf(nearby), 1);
x = (x + nearby.mesh.position.x) * 0.5;
z = (z + nearby.mesh.position.z) * 0.5;
radius = Math.min(0.63, Math.sqrt(nearby.target ** 2 + radius ** 2));
}
const material = new THREE.MeshStandardMaterial({
color: 0x4bc7e8,
emissive: 0x0c4051,
emissiveIntensity: 0.24,
roughness: 0.08,
metalness: 0.02,
transparent: true,
opacity: 0.1,
depthWrite: false,
side: THREE.DoubleSide,
flatShading: true
});
const mesh = new THREE.Mesh(makePatchGeometry(), material);
mesh.position.set(
x,
rightTile.surfaceY + 0.012 + rightTile.patches.length * 0.00025,
z
);
mesh.scale.set(0.045, 1, 0.045);
mesh.renderOrder = 2;
rightTile.group.add(mesh);
rightTile.patches.push({
mesh,
material,
target: radius,
age: 0
});
if (rightTile.patches.length > 26) {
const old = rightTile.patches.shift();
rightTile.group.remove(old.mesh);
old.material.dispose();
}
}
function createSpreadRing(x, z) {
const material = new THREE.MeshBasicMaterial({
color: 0x71ddf6,
transparent: true,
opacity: 0.65,
depthWrite: false,
side: THREE.DoubleSide
});
const mesh = new THREE.Mesh(ringGeometry, material);
mesh.position.set(x, rightTile.surfaceY + 0.021, z);
mesh.scale.setScalar(0.5);
rightTile.group.add(mesh);
impactEffects.push({
mesh,
material,
age: 0,
duration: 0.48
});
}
function impactDrop(drop) {
// Model A: theta >= 90 degrees, compact radius remains constant.
addBead(
drop.localX,
drop.localZ,
0.105 + effectRandom() * 0.032
);
// Model B: theta < 90 degrees, radius increases after contact.
const radius = 0.26 + effectRandom() * 0.16;
addPatch(drop.localX, drop.localZ, radius);
createSpreadRing(drop.localX, drop.localZ);
impactCount++;
}
function updateFalling(dt) {
simulationTime += dt;
while (simulationTime >= nextSpawnTime) {
spawnDrop();
nextSpawnTime += spawnInterval;
}
for (let i = fallingDrops.length - 1; i >= 0; i--) {
const drop = fallingDrops[i];
drop.y -= drop.speed * dt;
drop.leftMesh.position.y = drop.y;
drop.rightMesh.position.y = drop.y;
const stretch = 1 + Math.sin(simulationTime * 9 + i) * 0.07;
drop.leftMesh.scale.set(0.068, 0.14 * stretch, 0.068);
drop.rightMesh.scale.copy(drop.leftMesh.scale);
if (drop.y <= leftTile.surfaceY + 0.045) {
impactDrop(drop);
scene.remove(drop.leftMesh);
scene.remove(drop.rightMesh);
fallingDrops.splice(i, 1);
}
}
}
function updateSurface(dt) {
// Compact beads remain nearly spherical.
for (const bead of leftTile.beads) {
const settle = Math.min(1, bead.group.userData.age || 0);
bead.group.userData.age = settle + dt;
bead.group.scale.y = 1 - Math.sin(Math.min(1, settle) * Math.PI) * 0.08;
}
// Spreading model: radius grows after impact and overlapping films coalesce.
for (const patch of rightTile.patches) {
patch.age += dt;
const progress = Math.min(1, patch.age / 0.72);
const eased = 1 - Math.pow(1 - progress, 3);
const size = 0.045 + (patch.target - 0.045) * eased;
patch.mesh.scale.set(size, 1, size);
patch.material.opacity = 0.12 + eased * 0.31;
}
for (let i = impactEffects.length - 1; i >= 0; i--) {
const effect = impactEffects[i];
effect.age += dt;
const progress = Math.min(1, effect.age / effect.duration);
effect.mesh.scale.setScalar(0.5 + progress * 3.4);
effect.material.opacity = (1 - progress) * 0.62;
if (progress >= 1) {
rightTile.group.remove(effect.mesh);
effect.material.dispose();
impactEffects.splice(i, 1);
}
}
}
const beadCountElement = document.getElementById("beadCount");
const spreadRadiusElement = document.getElementById("spreadRadius");
const wetCoverageElement = document.getElementById("wetCoverage");
const impactCountElement = document.getElementById("impactCount");
function updateStatistics() {
beadCountElement.textContent = String(leftTile.beads.length).padStart(2, "0");
const totalRadius = rightTile.patches.reduce(
(sum, patch) => sum + patch.target,
0
);
const meanRadius = rightTile.patches.length
? totalRadius / rightTile.patches.length
: 0;
const estimatedArea = rightTile.patches.reduce(
(sum, patch) => sum + Math.PI * patch.target * patch.target,
0
);
// 0.72 accounts approximately for overlapping low-poly patches.
const coverage = Math.min(
92,
(estimatedArea / (3.34 * 2.84)) * 100 * 0.72
);
spreadRadiusElement.textContent = meanRadius.toFixed(2);
wetCoverageElement.textContent = `${Math.round(coverage)}%`;
impactCountElement.textContent = String(impactCount).padStart(3, "0");
const wetFactor = (coverage / 100) * 0.58;
rightTile.fabric.material.color.copy(baseFabricColor).lerp(wetFabricColor, wetFactor);
rightTile.fabric.material.roughness = 0.94 - wetFactor * 0.24;
}
function resetSimulation() {
for (const drop of fallingDrops) {
scene.remove(drop.leftMesh);
scene.remove(drop.rightMesh);
}
fallingDrops.length = 0;
for (const bead of leftTile.beads) {
leftTile.group.remove(bead.group);
}
leftTile.beads.length = 0;
for (const patch of rightTile.patches) {
rightTile.group.remove(patch.mesh);
patch.material.dispose();
}
rightTile.patches.length = 0;
for (const effect of impactEffects) {
rightTile.group.remove(effect.mesh);
effect.material.dispose();
}
impactEffects.length = 0;
simulationTime = 0;
nextSpawnTime = 0;
impactCount = 0;
randomState = 0x04c0ffee;
effectRandomState = 0x91a7b2c3;
rightTile.fabric.material.color.copy(baseFabricColor);
rightTile.fabric.material.roughness = 0.94;
// Begin with several drops already in flight for an immediate comparison.
for (let i = 0; i < 7; i++) {
spawnDrop(4.01 - i * 0.43);
}
updateStatistics();
}
// Direct camera controls, implemented without Three.js addons.
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
cameraState.yaw = THREE.MathUtils.clamp(
cameraState.yaw - deltaX * 0.004,
-0.48,
0.48
);
cameraState.pitch = THREE.MathUtils.clamp(
cameraState.pitch + deltaY * 0.003,
0.2,
0.72
);
});
function endDrag(event) {
dragging = false;
if (
event.pointerType !== "mouse" &&
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();
cameraState.distance = THREE.MathUtils.clamp(
cameraState.distance + event.deltaY * 0.008,
9.5,
15
);
},
{ passive: false }
);
const pauseButton = document.getElementById("pauseButton");
const resetButton = document.getElementById("resetButton");
pauseButton.addEventListener("click", () => {
paused = !paused;
pauseButton.textContent = paused ? "Resume" : "Pause";
pauseButton.classList.toggle("active", paused);
});
resetButton.addEventListener("click", resetSimulation);
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", onResize);
resetSimulation();
updateCamera();
const clock = new THREE.Clock();
let statisticsTimer = 0;
renderer.setAnimationLoop(() => {
const dt = Math.min(clock.getDelta(), 0.05);
if (!paused) {
updateFalling(dt);
updateSurface(dt);
}
statisticsTimer += dt;
if (statisticsTimer > 0.12) {
updateStatistics();
statisticsTimer = 0;
}
updateCamera();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```