Prompt specification
Build or customize the Three.js 3D scene "Condensation bead-covered bottle" 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: Condensation bead-covered bottle
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/condensation-bead-covered-bottle-x1213
Scene Description Prompt:
Please make a low-poly Three.js scene in one standalone HTML file using cdnjs. Model a chilled bottle with water droplets on its outer surface and a separate liquid interior; make clear that visible condensation forms outside the bottle.
Working Three.js Starter (condensation-bead-covered-bottle-x1213):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chilled Bottle — Exterior Condensation</title>
<style>
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #071820;
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: #eaffff;
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 52% 43%, transparent 38%, rgba(1, 8, 12, 0.42) 100%);
}
#hud {
position: fixed;
top: 26px;
left: 28px;
width: min(360px, calc(100vw - 56px));
pointer-events: none;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.55);
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin-bottom: 10px;
color: #8ee9ef;
font-size: 11px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
.cold-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #bffaff;
box-shadow: 0 0 14px #71e9ff;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 52px);
line-height: 0.95;
letter-spacing: -0.045em;
font-weight: 850;
}
#hud p {
max-width: 330px;
margin: 14px 0 0;
color: rgba(224, 250, 252, 0.72);
font-size: 13px;
line-height: 1.55;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 17px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
padding: 7px 10px;
border: 1px solid rgba(154, 232, 239, 0.17);
border-radius: 999px;
background: rgba(3, 18, 25, 0.48);
backdrop-filter: blur(8px);
color: rgba(231, 253, 255, 0.84);
font-size: 10px;
font-weight: 700;
letter-spacing: 0.04em;
}
.swatch {
width: 9px;
height: 9px;
border-radius: 50%;
}
.swatch.drop {
background: #e7ffff;
border: 1px solid #91edf4;
box-shadow: 0 0 8px rgba(143, 238, 246, 0.7);
}
.swatch.liquid {
background: #24b4cf;
border: 1px solid #62d8e9;
}
#reset {
position: fixed;
top: 24px;
right: 24px;
padding: 10px 14px;
border: 1px solid rgba(169, 240, 247, 0.22);
border-radius: 999px;
background: rgba(4, 20, 28, 0.62);
color: #d9fbff;
font: inherit;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.05em;
cursor: pointer;
backdrop-filter: blur(10px);
transition: background 160ms ease, border-color 160ms ease;
}
#reset:hover {
background: rgba(15, 52, 64, 0.78);
border-color: rgba(169, 240, 247, 0.48);
}
#hint {
position: fixed;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
padding: 8px 13px;
border-radius: 999px;
background: rgba(3, 16, 22, 0.46);
color: rgba(219, 249, 251, 0.58);
font-size: 10px;
letter-spacing: 0.08em;
pointer-events: none;
white-space: nowrap;
backdrop-filter: blur(8px);
}
@media (max-width: 600px) {
#hud {
top: 18px;
left: 18px;
}
#hud p {
max-width: 250px;
font-size: 11px;
}
.legend {
max-width: 250px;
}
#reset {
top: 18px;
right: 18px;
}
#hint {
bottom: 14px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div id="vignette"></div>
<section id="hud" aria-label="Scene information">
<div class="eyebrow">
<span class="cold-dot"></span>
Surface temperature · 04°C
</div>
<h1>CHILL<br />BOTTLE</h1>
<p>
Moisture condenses on the bottle’s outer skin. The pale beads sit
outside the glass, while the blue volume below is a separate liquid mesh.
</p>
<div class="legend">
<span><i class="swatch drop"></i> Exterior condensation</span>
<span><i class="swatch liquid"></i> Separate liquid interior</span>
</div>
</section>
<button id="reset" type="button">Reset view</button>
<div id="hint">DRAG TO ORBIT · SCROLL TO ZOOM · DOUBLE-CLICK TO RESET</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const resetButton = document.getElementById("reset");
// ------------------------------------------------------------------
// Renderer and scene
// ------------------------------------------------------------------
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
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;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly chilled water bottle with exterior condensation"
);
sceneHost.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071820);
scene.fog = new THREE.FogExp2(0x071820, 0.035);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
100
);
// ------------------------------------------------------------------
// Lighting
// ------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xd9fbff,
0x142a31,
1.85
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xf2ffff, 3.6);
keyLight.position.set(4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -4;
keyLight.shadow.camera.right = 4;
keyLight.shadow.camera.top = 5;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 18;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x43c8ef, 3.0);
rimLight.position.set(-4, 2.5, -4.5);
scene.add(rimLight);
const fillLight = new THREE.DirectionalLight(0xa9eaff, 1.15);
fillLight.position.set(-4, 1, 5);
scene.add(fillLight);
const innerGlow = new THREE.PointLight(0x30d9e8, 2.2, 3.2, 2);
innerGlow.position.set(0, -0.05, 0);
scene.add(innerGlow);
// ------------------------------------------------------------------
// Ground, wet patch, and contact shadow
// ------------------------------------------------------------------
const ground = new THREE.Mesh(
new THREE.CircleGeometry(9, 64),
new THREE.MeshStandardMaterial({
color: 0x102b32,
roughness: 0.7,
metalness: 0.06
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -1.62;
ground.receiveShadow = true;
scene.add(ground);
const contactShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.95, 48),
new THREE.MeshBasicMaterial({
color: 0x00070a,
transparent: true,
opacity: 0.38,
depthWrite: false
})
);
contactShadow.rotation.x = -Math.PI / 2;
contactShadow.scale.set(1.1, 0.72, 1);
contactShadow.position.y = -1.611;
contactShadow.renderOrder = 0;
scene.add(contactShadow);
const wetPatch = new THREE.Mesh(
new THREE.CircleGeometry(1.65, 48),
new THREE.MeshPhysicalMaterial({
color: 0x73dce7,
roughness: 0.08,
metalness: 0,
transparent: true,
opacity: 0.12,
transmission: 0.18,
thickness: 0.03,
clearcoat: 1,
clearcoatRoughness: 0.04,
depthWrite: false
})
);
wetPatch.rotation.x = -Math.PI / 2;
wetPatch.position.y = -1.603;
wetPatch.renderOrder = 1;
scene.add(wetPatch);
// ------------------------------------------------------------------
// Bottle group
// ------------------------------------------------------------------
const bottleGroup = new THREE.Group();
scene.add(bottleGroup);
// A closed, faceted profile revolved into a low-poly bottle shell.
const profile = [
[0.00, -1.58],
[0.58, -1.58],
[0.69, -1.51],
[0.75, -1.36],
[0.76, -1.15],
[0.76, 0.70],
[0.74, 0.86],
[0.68, 1.02],
[0.49, 1.16],
[0.34, 1.30],
[0.32, 1.45],
[0.32, 1.63],
[0.00, 1.63]
].map(([radius, y]) => new THREE.Vector2(radius, y));
const bottleGeometry = new THREE.LatheGeometry(profile, 28);
const glassMaterial = new THREE.MeshPhysicalMaterial({
color: 0x8de4dc,
roughness: 0.12,
metalness: 0,
transparent: true,
opacity: 0.29,
transmission: 0.18,
thickness: 0.16,
ior: 1.45,
clearcoat: 1,
clearcoatRoughness: 0.06,
side: THREE.DoubleSide,
depthWrite: false,
flatShading: true
});
const glassBottle = new THREE.Mesh(bottleGeometry, glassMaterial);
glassBottle.renderOrder = 3;
bottleGroup.add(glassBottle);
// Fine cyan edge lines emphasize the deliberately faceted geometry.
const bottleEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(bottleGeometry, 16),
new THREE.LineBasicMaterial({
color: 0xb8fbff,
transparent: true,
opacity: 0.13,
depthWrite: false
})
);
bottleEdges.renderOrder = 4;
bottleGroup.add(bottleEdges);
// ------------------------------------------------------------------
// Separate liquid interior
// ------------------------------------------------------------------
const liquidMaterial = new THREE.MeshPhysicalMaterial({
color: 0x20a8c5,
roughness: 0.17,
metalness: 0,
transparent: true,
opacity: 0.76,
transmission: 0.06,
thickness: 0.75,
ior: 1.333,
attenuationColor: new THREE.Color(0x087e9b),
attenuationDistance: 1.8,
clearcoat: 0.65,
clearcoatRoughness: 0.12,
depthWrite: true
});
const liquidBody = new THREE.Mesh(
new THREE.CylinderGeometry(0.65, 0.68, 1.72, 32, 1, false),
liquidMaterial
);
liquidBody.position.y = -0.45;
liquidBody.renderOrder = 1;
bottleGroup.add(liquidBody);
// A distinct upper surface makes the fill level easy to read.
const liquidSurface = new THREE.Mesh(
new THREE.CircleGeometry(0.65, 32),
new THREE.MeshPhysicalMaterial({
color: 0x76e7eb,
roughness: 0.06,
metalness: 0,
transparent: true,
opacity: 0.88,
transmission: 0.06,
thickness: 0.08,
ior: 1.333,
clearcoat: 1,
clearcoatRoughness: 0.03,
side: THREE.DoubleSide,
depthWrite: false
})
);
liquidSurface.rotation.x = -Math.PI / 2;
liquidSurface.position.y = 0.417;
liquidSurface.renderOrder = 2;
bottleGroup.add(liquidSurface);
// ------------------------------------------------------------------
// Low-poly cap and bottle details
// ------------------------------------------------------------------
const cap = new THREE.Mesh(
new THREE.CylinderGeometry(0.405, 0.39, 0.28, 24, 1, false),
new THREE.MeshStandardMaterial({
color: 0x163743,
roughness: 0.38,
metalness: 0.18,
flatShading: true
})
);
cap.position.y = 1.72;
cap.castShadow = true;
bottleGroup.add(cap);
const capRing = new THREE.Mesh(
new THREE.TorusGeometry(0.393, 0.025, 6, 24),
new THREE.MeshStandardMaterial({
color: 0x4e8390,
roughness: 0.3,
metalness: 0.32
})
);
capRing.rotation.x = Math.PI / 2;
capRing.position.y = 1.58;
bottleGroup.add(capRing);
const glassRing = new THREE.Mesh(
new THREE.TorusGeometry(0.69, 0.025, 6, 32),
new THREE.MeshPhysicalMaterial({
color: 0xa4f4ef,
roughness: 0.1,
transparent: true,
opacity: 0.5,
transmission: 0.2,
depthWrite: false
})
);
glassRing.rotation.x = Math.PI / 2;
glassRing.position.y = -1.34;
glassRing.renderOrder = 4;
bottleGroup.add(glassRing);
// ------------------------------------------------------------------
// Procedural curved label
// ------------------------------------------------------------------
function makeLabelTexture() {
const canvas = document.createElement("canvas");
canvas.width = 1024;
canvas.height = 512;
const ctx = canvas.getContext("2d");
ctx.clearRect(0, 0, canvas.width, canvas.height);
function roundedRect(x, y, w, h, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + w - radius, y);
ctx.quadraticCurveTo(x + w, y, x + w, y + radius);
ctx.lineTo(x + w, y + h - radius);
ctx.quadraticCurveTo(x + w, y + h, x + w - radius, y + h);
ctx.lineTo(x + radius, y + h);
ctx.quadraticCurveTo(x, y + h, x, y + h - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
}
const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
gradient.addColorStop(0, "#effbf4");
gradient.addColorStop(1, "#cce9e6");
roundedRect(20, 20, 984, 472, 54);
ctx.fillStyle = gradient;
ctx.fill();
ctx.lineWidth = 9;
ctx.strokeStyle = "#53aeba";
ctx.stroke();
ctx.fillStyle = "#123b48";
ctx.font = "900 126px system-ui, sans-serif";
ctx.textAlign = "center";
ctx.fillText("GLACIER", 512, 168);
ctx.fillStyle = "#357b88";
ctx.font = "700 34px system-ui, sans-serif";
ctx.letterSpacing = "8px";
ctx.fillText("PURE WATER", 512, 224);
ctx.beginPath();
ctx.arc(512, 337, 83, 0, Math.PI * 2);
ctx.fillStyle = "#123b48";
ctx.fill();
ctx.fillStyle = "#bffaff";
ctx.font = "800 52px system-ui, sans-serif";
ctx.fillText("04°", 512, 352);
// A simple snowflake icon.
ctx.strokeStyle = "#123b48";
ctx.lineWidth = 6;
ctx.lineCap = "round";
for (let i = 0; i < 3; i++) {
const angle = (i * Math.PI) / 3;
const dx = Math.cos(angle);
const dy = Math.sin(angle);
ctx.beginPath();
ctx.moveTo(512 - dx * 95, 337 - dy * 95);
ctx.lineTo(512 + dx * 95, 337 + dy * 95);
ctx.stroke();
for (const side of [-1, 1]) {
const bx = 512 + dx * 70 * side;
const by = 337 + dy * 70 * side;
const branchAngle = angle + side * 0.65;
ctx.beginPath();
ctx.moveTo(bx, by);
ctx.lineTo(
bx + Math.cos(branchAngle) * 28,
by + Math.sin(branchAngle) * 28
);
ctx.stroke();
}
}
ctx.fillStyle = "#397985";
ctx.font = "700 25px system-ui, sans-serif";
ctx.fillText("CHILLED • 500 mL • BOTTLE 04", 512, 456);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = renderer.capabilities.getMaxAnisotropy();
return texture;
}
const labelThetaStart = -2.15;
const labelThetaLength = 4.3;
const label = new THREE.Mesh(
new THREE.CylinderGeometry(
0.773,
0.773,
0.76,
40,
1,
true,
labelThetaStart,
labelThetaLength
),
new THREE.MeshStandardMaterial({
map: makeLabelTexture(),
transparent: true,
alphaTest: 0.08,
roughness: 0.86,
metalness: 0,
side: THREE.DoubleSide
})
);
label.position.y = 0.05;
label.castShadow = true;
bottleGroup.add(label);
// ------------------------------------------------------------------
// Exterior condensation
//
// Every bead is positioned directly against the bottle's OUTER radius.
// The liquid body above remains a separate, smaller mesh.
// ------------------------------------------------------------------
function bodyRadiusAt(y) {
if (y < -1.36) {
return THREE.MathUtils.lerp(0.69, 0.75, (y + 1.51) / 0.15);
}
if (y <= 0.70) return 0.76;
if (y <= 0.86) return THREE.MathUtils.lerp(0.76, 0.74, (y - 0.70) / 0.16);
if (y <= 1.02) return THREE.MathUtils.lerp(0.74, 0.68, (y - 0.86) / 0.16);
return 0.68;
}
function isOnLabel(theta, y) {
if (y < -0.33 || y > 0.43) return false;
const relative =
((theta - labelThetaStart) % (Math.PI * 2) + Math.PI * 2) %
(Math.PI * 2);
return relative <= labelThetaLength;
}
const dropletCount = 210;
const dropletGeometry = new THREE.SphereGeometry(1, 6, 4);
const dropletMaterial = new THREE.MeshPhysicalMaterial({
color: 0xe8ffff,
roughness: 0.04,
metalness: 0.01,
transparent: true,
opacity: 0.82,
transmission: 0.24,
thickness: 0.07,
ior: 1.333,
clearcoat: 1,
clearcoatRoughness: 0.015,
depthWrite: false,
flatShading: true
});
const droplets = new THREE.InstancedMesh(
dropletGeometry,
dropletMaterial,
dropletCount
);
droplets.instanceMatrix.setUsage(THREE.StaticDrawUsage);
droplets.frustumCulled = false;
droplets.renderOrder = 6;
bottleGroup.add(droplets);
const highlightCount = dropletCount;
const highlights = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 5, 3),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.9,
depthWrite: false
}),
highlightCount
);
highlights.instanceMatrix.setUsage(THREE.StaticDrawUsage);
highlights.frustumCulled = false;
highlights.renderOrder = 7;
bottleGroup.add(highlights);
const dummy = new THREE.Object3D();
const highlightDummy = new THREE.Object3D();
for (let i = 0; i < dropletCount; i++) {
const theta = Math.random() * Math.PI * 2;
// More droplets around the lower body, with a smaller shoulder cluster.
const y =
Math.random() < 0.76
? -1.28 + Math.random() * 1.96
: 0.68 + Math.random() * 0.33;
const size = 0.017 + Math.pow(Math.random(), 2.25) * 0.043;
const rareLargeDrop = Math.random() > 0.91 ? 1.3 : 1;
const width = size * (0.82 + Math.random() * 0.18) * rareLargeDrop;
const height =
size *
(1 + Math.random() * 1.65) *
rareLargeDrop *
(y > 0.84 ? 0.75 : 1);
const surfaceRadius =
bodyRadiusAt(y) + (isOnLabel(theta, y) ? 0.018 : 0.004);
const centerRadius = surfaceRadius + width * 0.28;
const x = Math.sin(theta) * centerRadius;
const z = Math.cos(theta) * centerRadius;
dummy.position.set(x, y, z);
dummy.scale.set(width, height, width);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
droplets.setMatrixAt(i, dummy.matrix);
// Tiny white facets act as highlights on the transparent beads.
const radial = new THREE.Vector3(
Math.sin(theta),
0,
Math.cos(theta)
);
highlightDummy.position
.copy(dummy.position)
.addScaledVector(radial, width * 0.56);
highlightDummy.position.y += height * 0.26;
highlightDummy.scale.setScalar(Math.max(0.0035, size * 0.15));
highlightDummy.updateMatrix();
highlights.setMatrixAt(i, highlightDummy.matrix);
}
droplets.instanceMatrix.needsUpdate = true;
highlights.instanceMatrix.needsUpdate = true;
// A few condensation drops have fallen onto the surface around the bottle.
const floorDropCount = 26;
const floorDrops = new THREE.InstancedMesh(
new THREE.SphereGeometry(1, 6, 4),
new THREE.MeshPhysicalMaterial({
color: 0xcff9fb,
roughness: 0.08,
transparent: true,
opacity: 0.68,
transmission: 0.18,
thickness: 0.04,
ior: 1.333,
clearcoat: 1,
depthWrite: false,
flatShading: true
}),
floorDropCount
);
floorDrops.frustumCulled = false;
floorDrops.renderOrder = 6;
for (let i = 0; i < floorDropCount; i++) {
const angle = Math.random() * Math.PI * 2;
const distance = 0.9 + Math.random() * 1.15;
const size = 0.025 + Math.random() * 0.055;
dummy.position.set(
Math.sin(angle) * distance,
-1.604,
Math.cos(angle) * distance
);
dummy.scale.set(size, size * 0.22, size);
dummy.rotation.set(0, 0, 0);
dummy.updateMatrix();
floorDrops.setMatrixAt(i, dummy.matrix);
}
floorDrops.instanceMatrix.needsUpdate = true;
scene.add(floorDrops);
// ------------------------------------------------------------------
// Custom orbit controls, implemented without Three.js addons
// ------------------------------------------------------------------
const controls = {
target: new THREE.Vector3(0, 0.12, 0),
radius: 7.9,
theta: 0.63,
phi: 1.28,
minRadius: 4.4,
maxRadius: 10.5
};
function updateCamera() {
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 resetCamera() {
controls.target.set(0, 0.12, 0);
controls.radius = 7.9;
controls.theta = 0.63;
controls.phi = 1.28;
updateCamera();
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
controls.theta -= dx * 0.006;
controls.phi = THREE.MathUtils.clamp(
controls.phi - dy * 0.005,
0.48,
1.5
);
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.radius = THREE.MathUtils.clamp(
controls.radius * Math.exp(event.deltaY * 0.001),
controls.minRadius,
controls.maxRadius
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key === "ArrowLeft") {
controls.theta += 0.08;
} else if (event.key === "ArrowRight") {
controls.theta -= 0.08;
} else if (event.key === "ArrowUp") {
controls.phi = Math.max(0.48, controls.phi - 0.05);
} else if (event.key === "ArrowDown") {
controls.phi = Math.min(1.5, controls.phi + 0.05);
} else if (event.key === "+" || event.key === "=") {
controls.radius = Math.max(controls.minRadius, controls.radius - 0.35);
} else if (event.key === "-") {
controls.radius = Math.min(controls.maxRadius, controls.radius + 0.35);
} else {
return;
}
updateCamera();
});
updateCamera();
// ------------------------------------------------------------------
// Resize and animation
// ------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const elapsed = clock.getElapsedTime();
// Subtle idle motion keeps the faceted bottle and droplets readable.
bottleGroup.rotation.y = -0.07 + Math.sin(elapsed * 0.23) * 0.065;
liquidSurface.position.y = 0.417 + Math.sin(elapsed * 0.8) * 0.005;
rimLight.position.x = -4 + Math.sin(elapsed * 0.18) * 0.6;
rimLight.position.z = -4.5 + Math.cos(elapsed * 0.18) * 0.5;
renderer.render(scene, camera);
});
</script>
</body>
</html>
```