Prompt specification
Build or customize the Three.js 3D scene "Reusable bottle maintenance tray" 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: Reusable bottle maintenance tray
Category: Everyday & Industrial · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/reusable-bottle-maintenance-tray-x0263
Scene Description Prompt:
Stylized bottle lids, removable seals, and cleaning brushes; each seal fits its groove before closure. Three.js from cdnjs, one HTML file.
Working Three.js Starter (reusable-bottle-maintenance-tray-x0263):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Seal Studio — Bottle Closure System</title>
<style>
:root {
color-scheme: dark;
--ink: #f5f4ee;
--muted: #a7b2b8;
--panel: rgba(17, 28, 35, 0.78);
--line: rgba(255, 255, 255, 0.13);
--accent: #ff806c;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 50% 38%, #263945 0%, #14232d 43%, #0b141b 100%);
color: var(--ink);
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background:
linear-gradient(180deg, rgba(255,255,255,0.035), transparent 25%),
radial-gradient(circle at center, transparent 38%, rgba(4, 9, 13, 0.55) 100%);
z-index: 2;
}
button {
font: inherit;
}
#stage {
position: fixed;
inset: 0;
z-index: 1;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
outline: none;
}
#stage canvas.dragging {
cursor: grabbing;
}
.header {
position: fixed;
top: 30px;
left: 34px;
z-index: 5;
pointer-events: none;
}
.brand {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 24px;
color: #dce4e7;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.2em;
text-transform: uppercase;
}
.brand-mark {
display: grid;
grid-template-columns: repeat(2, 6px);
gap: 3px;
}
.brand-mark i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--accent);
}
.brand-mark i:nth-child(2),
.brand-mark i:nth-child(3) {
opacity: 0.38;
}
.header h1 {
max-width: 420px;
margin: 0;
font-size: clamp(32px, 4.2vw, 61px);
font-weight: 540;
line-height: 0.98;
letter-spacing: -0.055em;
}
.header h1 em {
color: var(--accent);
font-family: Georgia, serif;
font-weight: 400;
}
.header p {
max-width: 350px;
margin: 18px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.65;
}
.inspector {
position: fixed;
top: 30px;
right: 34px;
z-index: 5;
width: 270px;
padding: 20px;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 24px 80px rgba(0,0,0,0.18);
backdrop-filter: blur(18px);
}
.eyebrow {
display: flex;
justify-content: space-between;
align-items: center;
color: #8f9ca3;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow b {
color: var(--accent);
font-weight: 800;
}
.inspector h2 {
margin: 18px 0 5px;
font-size: 26px;
font-weight: 560;
letter-spacing: -0.04em;
}
.inspector .subtitle {
margin: 0 0 17px;
color: var(--muted);
font-size: 12px;
}
.swatches {
display: flex;
gap: 7px;
margin-bottom: 18px;
}
.swatches span {
width: 25px;
height: 25px;
border: 3px solid rgba(255,255,255,0.11);
border-radius: 50%;
box-shadow: 0 0 0 1px rgba(255,255,255,0.12);
}
.mechanism {
padding-top: 15px;
border-top: 1px solid var(--line);
}
.mechanism strong {
display: block;
margin-bottom: 6px;
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mechanism p {
margin: 0;
color: #9eabb1;
font-size: 11px;
line-height: 1.55;
}
.status {
display: flex;
gap: 9px;
align-items: flex-start;
margin-top: 18px;
color: #b7c1c5;
font-size: 11px;
line-height: 1.45;
}
.status-dot {
flex: 0 0 auto;
width: 7px;
height: 7px;
margin-top: 4px;
border-radius: 50%;
background: var(--accent);
box-shadow: 0 0 0 5px rgba(255,128,108,0.1);
}
.products {
position: fixed;
left: 34px;
bottom: 29px;
z-index: 6;
display: flex;
gap: 9px;
}
.product-card {
width: 154px;
min-height: 86px;
padding: 13px 14px;
border: 1px solid var(--line);
border-radius: 15px;
color: var(--ink);
background: rgba(17, 28, 35, 0.68);
backdrop-filter: blur(16px);
cursor: pointer;
text-align: left;
transition:
transform 180ms ease,
border-color 180ms ease,
background 180ms ease;
}
.product-card:hover {
transform: translateY(-3px);
border-color: rgba(255,255,255,0.27);
}
.product-card.active {
border-color: var(--card-accent);
background: rgba(29, 43, 51, 0.9);
box-shadow: inset 0 -2px 0 var(--card-accent);
}
.card-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 9px;
}
.card-dots {
display: flex;
gap: 4px;
}
.card-dots i {
width: 8px;
height: 8px;
border-radius: 50%;
}
.card-number {
color: #77858c;
font-size: 9px;
letter-spacing: 0.12em;
}
.product-card strong {
display: block;
margin-bottom: 3px;
font-size: 13px;
font-weight: 650;
}
.product-card small {
display: block;
color: #87969d;
font-size: 10px;
}
.controls {
position: fixed;
right: 34px;
bottom: 29px;
z-index: 6;
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
max-width: 465px;
}
.control {
min-height: 41px;
padding: 0 15px;
border: 1px solid var(--line);
border-radius: 12px;
color: #dbe2e4;
background: rgba(17, 28, 35, 0.76);
backdrop-filter: blur(16px);
cursor: pointer;
font-size: 11px;
font-weight: 650;
transition:
transform 150ms ease,
border-color 150ms ease,
opacity 150ms ease,
background 150ms ease;
}
.control:hover:not(:disabled) {
transform: translateY(-2px);
border-color: rgba(255,255,255,0.3);
background: rgba(37, 52, 61, 0.9);
}
.control.primary {
border-color: transparent;
color: #182027;
background: var(--accent);
}
.control:disabled {
cursor: default;
opacity: 0.32;
}
.gesture-note {
position: fixed;
left: 50%;
bottom: 33px;
z-index: 4;
transform: translateX(-50%);
color: rgba(217,225,228,0.45);
font-size: 9px;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
}
.world-label {
position: fixed;
z-index: 4;
display: flex;
align-items: center;
gap: 7px;
padding: 6px 9px 6px 6px;
border: 1px solid rgba(255,255,255,0.14);
border-radius: 999px;
color: #dbe3e5;
background: rgba(11, 20, 27, 0.7);
backdrop-filter: blur(10px);
font-size: 9px;
font-weight: 750;
letter-spacing: 0.12em;
pointer-events: none;
transform: translate(-50%, -50%);
transition: opacity 150ms ease;
}
.world-label span {
display: grid;
width: 20px;
height: 20px;
place-items: center;
border-radius: 50%;
color: #142027;
background: #dfe7e9;
font-size: 8px;
}
.world-label.seal span {
background: #ff806c;
}
.world-label.groove span {
background: #88d6c1;
}
@media (max-width: 900px) {
.inspector {
top: 24px;
right: 24px;
width: 225px;
}
.header {
top: 24px;
left: 24px;
}
.header p {
display: none;
}
.products {
left: 24px;
bottom: 86px;
}
.controls {
right: 24px;
bottom: 24px;
}
.gesture-note {
display: none;
}
}
@media (max-width: 650px) {
.header {
top: 18px;
left: 18px;
}
.brand {
margin-bottom: 13px;
}
.header h1 {
max-width: 230px;
font-size: 34px;
}
.inspector {
top: 18px;
right: 18px;
width: 142px;
padding: 13px;
border-radius: 14px;
}
.inspector h2 {
margin-top: 12px;
font-size: 19px;
}
.inspector .subtitle,
.mechanism,
.swatches {
display: none;
}
.status {
margin-top: 10px;
font-size: 9px;
}
.products {
left: 14px;
right: 14px;
bottom: 81px;
overflow-x: auto;
padding-bottom: 3px;
scrollbar-width: none;
}
.products::-webkit-scrollbar {
display: none;
}
.product-card {
flex: 0 0 132px;
min-height: 75px;
padding: 10px 12px;
}
.card-top {
margin-bottom: 6px;
}
.controls {
right: 14px;
bottom: 14px;
left: 14px;
justify-content: center;
max-width: none;
}
.control {
flex: 1 1 auto;
min-width: 92px;
padding: 0 10px;
font-size: 10px;
}
.world-label {
display: none;
}
}
</style>
</head>
<body>
<main id="stage" aria-label="Interactive 3D bottle closure demonstration"></main>
<header class="header">
<div class="brand">
<span class="brand-mark" aria-hidden="true">
<i></i><i></i><i></i><i></i>
</span>
Seal Studio
</div>
<h1>A perfect fit,<br><em>every time.</em></h1>
<p>
Removable seals, precision grooves, and cleaning brushes designed as one
considered closure system.
</p>
</header>
<aside class="inspector" aria-live="polite">
<div class="eyebrow">
<span>Selected system</span>
<b id="productNumber">02 / 03</b>
</div>
<h2 id="productName">Facet</h2>
<p class="subtitle" id="productSubtitle">Low-profile · ribbed grip</p>
<div class="swatches" aria-label="Product colors">
<span id="swatchBody"></span>
<span id="swatchLid"></span>
<span id="swatchSeal"></span>
</div>
<div class="mechanism">
<strong>Groove-lock closure</strong>
<p>
The flexible seal seats inside the molded neck groove before the rigid
lid captures it.
</p>
</div>
<div class="status" role="status">
<span class="status-dot"></span>
<span id="statusText">Exploded view. Fit the seal into the groove first.</span>
</div>
</aside>
<div class="world-label" id="lidLabel"><span>01</span> LID</div>
<div class="world-label seal" id="sealLabel"><span>02</span> SEAL</div>
<div class="world-label groove" id="grooveLabel"><span>03</span> GROOVE</div>
<nav class="products" aria-label="Select a closure system">
<button class="product-card" data-index="0" style="--card-accent:#ff806c">
<span class="card-top">
<span class="card-dots">
<i style="background:#7ed8bd"></i>
<i style="background:#ff806c"></i>
</span>
<span class="card-number">01</span>
</span>
<strong>Ripple</strong>
<small>Soft-touch · rounded profile</small>
</button>
<button class="product-card active" data-index="1" style="--card-accent:#f6c84c">
<span class="card-top">
<span class="card-dots">
<i style="background:#8bb8ff"></i>
<i style="background:#f6c84c"></i>
</span>
<span class="card-number">02</span>
</span>
<strong>Facet</strong>
<small>Low-profile · ribbed grip</small>
</button>
<button class="product-card" data-index="2" style="--card-accent:#9c7af1">
<span class="card-top">
<span class="card-dots">
<i style="background:#f4a48f"></i>
<i style="background:#9c7af1"></i>
</span>
<span class="card-number">03</span>
</span>
<strong>Petal</strong>
<small>Wide seal · ergonomic top</small>
</button>
</nav>
<div class="controls" aria-label="Assembly controls">
<button class="control primary" id="fitButton">↓ Fit seal</button>
<button class="control" id="closeButton" disabled>↓ Close lid</button>
<button class="control" id="brushButton">↔ Brush groove</button>
<button class="control" id="openButton" disabled>↑ Open</button>
</div>
<div class="gesture-note">Drag to orbit · Scroll to zoom · Click a system</div>
<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.getElementById("stage");
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0x13222c, 10, 24);
const camera = new THREE.PerspectiveCamera(
36,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 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.18;
renderer.domElement.setAttribute(
"aria-label",
"3D exploded view of bottle lids, removable seals, and cleaning brushes"
);
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xe9f4ff, 0x29352d, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1dc, 4.1);
keyLight.position.set(5.5, 9, 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 = 10;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 24;
keyLight.shadow.bias = -0.00035;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0x7baaff, 2.1);
fillLight.position.set(-6, 4.5, 2);
scene.add(fillLight);
const rimLight = new THREE.PointLight(0xff806c, 18, 12, 2);
rimLight.position.set(-2.5, 4.5, -3.5);
scene.add(rimLight);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0x132029,
roughness: 0.88,
metalness: 0.04
});
const floor = new THREE.Mesh(
new THREE.CircleGeometry(11.5, 96),
floorMaterial
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.035;
floor.receiveShadow = true;
scene.add(floor);
const floorRingMaterial = new THREE.MeshBasicMaterial({
color: 0x7893a0,
transparent: true,
opacity: 0.12,
depthWrite: false
});
const floorRing = new THREE.Mesh(
new THREE.TorusGeometry(7.8, 0.012, 8, 160),
floorRingMaterial
);
floorRing.rotation.x = Math.PI / 2;
floorRing.position.y = -0.02;
scene.add(floorRing);
const productData = [
{
name: "Ripple",
subtitle: "Soft-touch · rounded profile",
body: 0x7ed8bd,
lid: 0xff806c,
seal: 0xfff0d4,
accent: "#ff806c",
gripCount: 36
},
{
name: "Facet",
subtitle: "Low-profile · ribbed grip",
body: 0x8bb8ff,
lid: 0xf6c84c,
seal: 0xf4f0e6,
accent: "#f6c84c",
gripCount: 28
},
{
name: "Petal",
subtitle: "Wide seal · ergonomic top",
body: 0xf4a48f,
lid: 0x9c7af1,
seal: 0x77d6e6,
accent: "#9c7af1",
gripCount: 32
}
];
const productGroups = [];
function makePhysicalMaterial(color, options = {}) {
return new THREE.MeshPhysicalMaterial({
color,
roughness: 0.34,
metalness: 0.02,
clearcoat: 0.35,
clearcoatRoughness: 0.28,
...options
});
}
function addMesh(parent, geometry, material, position) {
const mesh = new THREE.Mesh(geometry, material);
if (position) mesh.position.set(...position);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createBottleBody(data) {
const group = new THREE.Group();
const bodyMaterial = makePhysicalMaterial(data.body, {
roughness: 0.3,
clearcoat: 0.58,
clearcoatRoughness: 0.2
});
const points = [
new THREE.Vector2(0, 0.08),
new THREE.Vector2(0.66, 0.08),
new THREE.Vector2(0.89, 0.18),
new THREE.Vector2(1.01, 0.42),
new THREE.Vector2(1.03, 1.92),
new THREE.Vector2(1.0, 2.18),
new THREE.Vector2(0.86, 2.42),
new THREE.Vector2(0.65, 2.65),
new THREE.Vector2(0.64, 2.78)
];
addMesh(
group,
new THREE.LatheGeometry(points, 72),
bodyMaterial
);
const ridgeMaterial = makePhysicalMaterial(data.body, {
roughness: 0.42,
clearcoat: 0.15
});
[0.66, 1.02, 1.38].forEach((height) => {
const ridge = addMesh(
group,
new THREE.TorusGeometry(1.025, 0.018, 10, 72),
ridgeMaterial,
[0, height, 0]
);
ridge.rotation.x = Math.PI / 2;
});
const logoMaterial = makePhysicalMaterial(data.seal, {
roughness: 0.42,
metalness: 0.08
});
const logo = addMesh(
group,
new THREE.TorusGeometry(0.19, 0.034, 12, 48),
logoMaterial,
[0, 1.63, 1.025]
);
const logoDot = addMesh(
group,
new THREE.CircleGeometry(0.045, 24),
logoMaterial,
[0, 1.63, 1.035]
);
logoDot.castShadow = false;
const neckMaterial = makePhysicalMaterial(data.body, {
roughness: 0.27,
clearcoat: 0.55
});
addMesh(
group,
new THREE.CylinderGeometry(0.67, 0.67, 0.48, 72, 1, true),
neckMaterial,
[0, 3.0, 0]
);
const lip = addMesh(
group,
new THREE.TorusGeometry(0.67, 0.043, 14, 72),
neckMaterial,
[0, 3.24, 0]
);
lip.rotation.x = Math.PI / 2;
const grooveMaterial = new THREE.MeshStandardMaterial({
color: 0x1c3034,
roughness: 0.52,
metalness: 0.05,
emissive: data.seal,
emissiveIntensity: 0.04
});
const groove = addMesh(
group,
new THREE.TorusGeometry(0.67, 0.036, 14, 72),
grooveMaterial,
[0, 3.02, 0]
);
groove.rotation.x = Math.PI / 2;
const inner = addMesh(
group,
new THREE.CircleGeometry(0.61, 64),
new THREE.MeshBasicMaterial({ color: 0x102128 }),
[0, 3.225, 0]
);
inner.rotation.x = -Math.PI / 2;
inner.castShadow = false;
return { group, grooveMaterial };
}
function createLid(data) {
const group = new THREE.Group();
const lidMaterial = makePhysicalMaterial(data.lid, {
roughness: 0.3,
clearcoat: 0.48,
clearcoatRoughness: 0.24
});
const sideMaterial = makePhysicalMaterial(data.lid, {
roughness: 0.42,
clearcoat: 0.18
});
const undersideMaterial = makePhysicalMaterial(0x26343a, {
roughness: 0.72,
metalness: 0.08
});
addMesh(
group,
new THREE.CylinderGeometry(0.82, 0.86, 0.58, 72),
sideMaterial,
[0, 0.29, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.83, 0.83, 0.075, 72),
lidMaterial,
[0, 0.615, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.69, 0.69, 0.15, 64, 1, true),
undersideMaterial,
[0, -0.035, 0]
);
const band = addMesh(
group,
new THREE.TorusGeometry(0.843, 0.028, 10, 72),
lidMaterial,
[0, 0.48, 0]
);
band.rotation.x = Math.PI / 2;
const gripGeometry = new THREE.BoxGeometry(0.075, 0.39, 0.105);
for (let i = 0; i < data.gripCount; i++) {
const angle = (i / data.gripCount) * Math.PI * 2;
const radius = 0.84;
const grip = addMesh(
group,
gripGeometry,
sideMaterial,
[
Math.sin(angle) * radius,
0.28,
Math.cos(angle) * radius
]
);
grip.rotation.y = angle;
grip.rotation.z = Math.sin(angle * 2) * 0.015;
}
const emblem = addMesh(
group,
new THREE.TorusGeometry(0.22, 0.027, 10, 48),
makePhysicalMaterial(data.seal, {
roughness: 0.4,
metalness: 0.05
}),
[0, 0.667, 0]
);
emblem.rotation.x = Math.PI / 2;
const emblemCenter = addMesh(
group,
new THREE.CylinderGeometry(0.08, 0.08, 0.025, 32),
makePhysicalMaterial(data.seal, {
roughness: 0.4
}),
[0, 0.681, 0]
);
emblemCenter.castShadow = false;
return group;
}
function createSeal(data) {
const group = new THREE.Group();
const sealMaterial = makePhysicalMaterial(data.seal, {
roughness: 0.62,
metalness: 0,
clearcoat: 0.12,
clearcoatRoughness: 0.5
});
const ring = addMesh(
group,
new THREE.TorusGeometry(0.64, 0.075, 18, 80),
sealMaterial
);
ring.rotation.x = Math.PI / 2;
const accent = addMesh(
group,
new THREE.TorusGeometry(0.64, 0.024, 10, 80),
makePhysicalMaterial(data.lid, {
roughness: 0.5
}),
[0, 0.058, 0]
);
accent.rotation.x = Math.PI / 2;
return group;
}
function createBrush(data) {
const group = new THREE.Group();
const handleMaterial = makePhysicalMaterial(data.lid, {
roughness: 0.38,
clearcoat: 0.34
});
const darkMaterial = makePhysicalMaterial(0x26343a, {
roughness: 0.68
});
const bristleMaterial = makePhysicalMaterial(data.seal, {
roughness: 0.78,
metalness: 0
});
addMesh(
group,
new THREE.CylinderGeometry(0.095, 0.13, 1.15, 28),
handleMaterial,
[0, 1.08, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.16, 0.16, 0.12, 32),
darkMaterial,
[0, 0.48, 0]
);
addMesh(
group,
new THREE.CylinderGeometry(0.39, 0.39, 0.10, 48),
darkMaterial,
[0, 0.40, 0]
);
const bristleGeometry = new THREE.CylinderGeometry(
0.021,
0.028,
0.42,
8
);
for (let i = 0; i < 24; i++) {
const angle = (i / 24) * Math.PI * 2;
const radius = i < 8 ? 0.08 : 0.28;
const bristle = addMesh(
group,
bristleGeometry,
bristleMaterial,
[
Math.sin(angle) * radius,
0.18,
Math.cos(angle) * radius
]
);
bristle.rotation.z = Math.sin(angle) * 0.08;
bristle.rotation.x = Math.cos(angle) * 0.08;
}
[0.82, 1.08, 1.34].forEach((height) => {
const grip = addMesh(
group,
new THREE.TorusGeometry(0.12, 0.018, 8, 32),
darkMaterial,
[0, height, 0]
);
grip.rotation.x = Math.PI / 2;
});
const cap = addMesh(
group,
new THREE.CylinderGeometry(0.135, 0.115, 0.14, 28),
handleMaterial,
[0, 1.71, 0]
);
cap.rotation.z = 0.04;
return group;
}
function createProduct(data, index) {
const group = new THREE.Group();
group.position.x = (index - 1) * 3.9;
const bottle = createBottleBody(data);
const lid = createLid(data);
const seal = createSeal(data);
const brush = createBrush(data);
lid.position.y = 4.62;
seal.position.y = 3.80;
brush.position.set(1.38, 0.06, 0.02);
brush.rotation.z = -0.055;
group.add(bottle.group, lid, seal, brush);
const pedestalRing = new THREE.Mesh(
new THREE.TorusGeometry(1.26, 0.012, 8, 96),
new THREE.MeshBasicMaterial({
color: data.body,
transparent: true,
opacity: 0.27,
depthWrite: false
})
);
pedestalRing.rotation.x = Math.PI / 2;
pedestalRing.position.y = -0.01;
group.add(pedestalRing);
group.traverse((object) => {
object.userData.productIndex = index;
});
const product = {
index,
data,
group,
lid,
seal,
brush,
grooveMaterial: bottle.grooveMaterial,
brushHome: brush.position.clone()
};
productGroups.push(product);
scene.add(group);
return product;
}
productData.forEach(createProduct);
let selected = 1;
let phase = "exploded";
let brushAnimation = null;
const timers = [];
const fitButton = document.getElementById("fitButton");
const closeButton = document.getElementById("closeButton");
const brushButton = document.getElementById("brushButton");
const openButton = document.getElementById("openButton");
const statusText = document.getElementById("statusText");
const productName = document.getElementById("productName");
const productSubtitle = document.getElementById("productSubtitle");
const productNumber = document.getElementById("productNumber");
const swatchBody = document.getElementById("swatchBody");
const swatchLid = document.getElementById("swatchLid");
const swatchSeal = document.getElementById("swatchSeal");
const productButtons = [...document.querySelectorAll(".product-card")];
function later(delay, callback) {
const timer = window.setTimeout(callback, delay);
timers.push(timer);
}
function clearTimers() {
timers.forEach((timer) => clearTimeout(timer));
timers.length = 0;
}
function updateInspector() {
const data = productData[selected];
productName.textContent = data.name;
productSubtitle.textContent = data.subtitle;
productNumber.textContent = `0${selected + 1} / 03`;
swatchBody.style.background = `#${data.body.toString(16).padStart(6, "0")}`;
swatchLid.style.background = `#${data.lid.toString(16).padStart(6, "0")}`;
swatchSeal.style.background = `#${data.seal.toString(16).padStart(6, "0")}`;
productButtons.forEach((button, index) => {
button.classList.toggle("active", index === selected);
button.setAttribute("aria-pressed", String(index === selected));
});
}
function updateUI() {
fitButton.disabled = phase !== "exploded";
closeButton.disabled = phase !== "seated";
openButton.disabled = phase !== "closed";
brushButton.disabled =
Boolean(brushAnimation) ||
!["exploded", "seated"].includes(phase);
if (phase === "exploded") {
fitButton.textContent = "↓ Fit seal";
closeButton.textContent = "↓ Close lid";
openButton.textContent = "↑ Open";
statusText.textContent =
"Exploded view. Fit the seal into the groove first.";
} else if (phase === "fitting") {
fitButton.textContent = "↓ Fitting seal…";
statusText.textContent =
"The removable seal is descending into the molded neck groove.";
} else if (phase === "seated") {
fitButton.textContent = "✓ Seal fitted";
closeButton.textContent = "↓ Close lid";
statusText.textContent =
"The seal is seated. Its profile matches the groove exactly.";
} else if (phase === "closing") {
closeButton.textContent = "↓ Closing…";
statusText.textContent =
"The lid is closing over the seated seal.";
} else if (phase === "closed") {
closeButton.textContent = "✓ Lid closed";
openButton.textContent = "↑ Open";
statusText.textContent =
"Closure complete. The lid now captures the removable seal.";
} else if (phase === "opening") {
statusText.textContent = "Opening the lid before releasing the seal.";
} else if (phase === "exploding") {
statusText.textContent = "The fitted seal is being lifted from the groove.";
}
}
const orbit = {
yaw: 0.37,
pitch: 0.13,
radius: window.innerWidth < 650 ? 9.1 : 8.2,
target: new THREE.Vector3(0, 2.52, 0),
targetGoal: new THREE.Vector3(0, 2.52, 0)
};
function selectProduct(index) {
if (index < 0 || index >= productGroups.length) return;
clearTimers();
selected = index;
phase = "exploded";
brushAnimation = null;
const product = productGroups[selected];
product.brush.position.copy(product.brushHome);
product.brush.rotation.set(0, 0, -0.055);
orbit.targetGoal.x = product.group.position.x;
orbit.targetGoal.y = 2.52;
updateInspector();
updateUI();
}
productButtons.forEach((button) => {
button.addEventListener("click", () => {
selectProduct(Number(button.dataset.index));
});
});
fitButton.addEventListener("click", () => {
if (phase !== "exploded") return;
phase = "fitting";
updateUI();
later(1050, () => {
phase = "seated";
updateUI();
});
});
closeButton.addEventListener("click", () => {
if (phase !== "seated") return;
phase = "closing";
updateUI();
later(1000, () => {
phase = "closed";
updateUI();
});
});
openButton.addEventListener("click", () => {
if (phase !== "closed") return;
phase = "opening";
updateUI();
later(600, () => {
phase = "exploding";
updateUI();
later(520, () => {
phase = "exploded";
updateUI();
});
});
});
brushButton.addEventListener("click", () => {
if (brushAnimation) return;
brushAnimation = {
start: performance.now(),
duration: 2600
};
updateUI();
statusText.textContent =
"The flexible brush is cleaning the neck groove before seal fitting.";
});
const pointer = new THREE.Vector2();
const raycaster = new THREE.Raycaster();
let dragging = false;
let dragMoved = false;
let lastX = 0;
let lastY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
dragMoved = false;
lastX = event.clientX;
lastY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
if (Math.abs(event.clientX - lastX) + Math.abs(event.clientY - lastY) > 2) {
dragMoved = true;
}
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.004,
-0.08,
0.52
);
lastX = event.clientX;
lastY = event.clientY;
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (!dragMoved) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(productGroups, true);
if (hits.length) {
selectProduct(hits[0].object.userData.productIndex);
}
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
5.2,
11.5
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", () => {
orbit.yaw = 0.37;
orbit.pitch = 0.13;
orbit.radius = window.innerWidth < 650 ? 9.1 : 8.2;
});
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
function damp(current, target, lambda, delta) {
return THREE.MathUtils.lerp(
current,
target,
1 - Math.exp(-lambda * delta)
);
}
function smoothstep(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updateBrushAnimation(now) {
if (!brushAnimation) return;
const product = productGroups[selected];
const progress = (now - brushAnimation.start) / brushAnimation.duration;
const home = product.brushHome;
const approach = new THREE.Vector3(0, 3.10, 0.63);
const working = new THREE.Vector3(0, 3.10, 0.08);
if (progress < 0.22) {
const t = smoothstep(progress / 0.22);
product.brush.position.lerpVectors(home, approach, t);
product.brush.rotation.z = -0.055 * (1 - t) - 0.08 * t;
} else if (progress < 0.65) {
const t = (progress - 0.22) / 0.43;
product.brush.position.copy(approach);
product.brush.position.x = Math.sin(t * Math.PI * 8) * 0.17;
product.brush.position.z = THREE.MathUtils.lerp(0.63, 0.08, t);
product.brush.position.y = 3.10 + Math.sin(t * Math.PI * 10) * 0.025;
product.brush.rotation.z = -0.08 + Math.sin(t * Math.PI * 8) * 0.035;
} else if (progress < 1) {
const t = smoothstep((progress - 0.65) / 0.35);
product.brush.position.lerpVectors(working, home, t);
product.brush.rotation.z = -0.08 * (1 - t) - 0.055 * t;
} else {
product.brush.position.copy(home);
product.brush.rotation.set(0, 0, -0.055);
brushAnimation = null;
if (phase === "exploded") {
statusText.textContent =
"Groove cleaned. Fit the removable seal into the clean channel.";
} else if (phase === "seated") {
statusText.textContent =
"The seal is seated. Its profile matches the groove exactly.";
}
updateUI();
}
}
const lidLabel = document.getElementById("lidLabel");
const sealLabel = document.getElementById("sealLabel");
const grooveLabel = document.getElementById("grooveLabel");
const projected = new THREE.Vector3();
function positionLabel(element, worldPosition) {
projected.copy(worldPosition).project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
Math.abs(projected.x) < 1.2 &&
Math.abs(projected.y) < 1.2;
element.style.opacity = visible ? "1" : "0";
element.style.left = `${(projected.x * 0.5 + 0.5) * window.innerWidth}px`;
element.style.top = `${(-projected.y * 0.5 + 0.5) * window.innerHeight}px`;
}
const clock = new THREE.Clock();
function animate(now) {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
updateBrushAnimation(now);
productGroups.forEach((product) => {
const active = product.index === selected;
let lidTarget = 4.62;
let sealTarget = 3.80;
if (active) {
if (["fitting", "seated"].includes(phase)) {
sealTarget = 3.02;
} else if (["closing", "closed"].includes(phase)) {
lidTarget = 3.27;
sealTarget = 3.02;
} else if (["opening"].includes(phase)) {
lidTarget = 4.62;
sealTarget = 3.02;
} else if (phase === "exploding") {
lidTarget = 4.62;
sealTarget = 3.80;
}
}
product.lid.position.y = damp(
product.lid.position.y,
lidTarget,
phase === "closing" ? 6.4 : 7.2,
delta
);
product.seal.position.y = damp(
product.seal.position.y,
sealTarget,
phase === "fitting" ? 7.5 : 7.2,
delta
);
let grooveIntensity = 0.035;
if (active && phase === "seated") {
grooveIntensity = 0.46 + Math.sin(elapsed * 5.5) * 0.12;
} else if (active && phase === "closed") {
grooveIntensity = 0.12;
} else if (active && brushAnimation) {
grooveIntensity = 0.72 + Math.sin(elapsed * 9) * 0.16;
}
product.grooveMaterial.emissiveIntensity = damp(
product.grooveMaterial.emissiveIntensity,
grooveIntensity,
8,
delta
);
const sealPulse =
active && phase === "seated"
? 1 + Math.sin(elapsed * 5.5) * 0.012
: 1;
product.seal.scale.setScalar(sealPulse);
product.lid.rotation.y = Math.sin(elapsed * 0.35 + product.index) * 0.025;
});
orbit.target.x = damp(
orbit.target.x,
orbit.targetGoal.x,
4.8,
delta
);
orbit.target.y = damp(
orbit.target.y,
orbit.targetGoal.y,
4.8,
delta
);
const horizontalRadius =
Math.cos(orbit.pitch) * orbit.radius;
camera.position.set(
orbit.target.x + Math.sin(orbit.yaw) * horizontalRadius,
orbit.target.y + Math.sin(orbit.pitch) * orbit.radius,
orbit.target.z + Math.cos(orbit.yaw) * horizontalRadius
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
const activeProduct = productGroups[selected];
positionLabel(
lidLabel,
new THREE.Vector3(
activeProduct.group.position.x + 0.55,
activeProduct.lid.position.y + 0.64,
0
)
);
positionLabel(
sealLabel,
new THREE.Vector3(
activeProduct.group.position.x - 0.72,
activeProduct.seal.position.y,
0
)
);
positionLabel(
grooveLabel,
new THREE.Vector3(
activeProduct.group.position.x + 0.63,
3.02,
0
)
);
renderer.render(scene, camera);
}
renderer.setAnimationLoop(animate);
updateInspector();
updateUI();
resize();
</script>
</body>
</html>
```