Prompt specification
Build or customize the Three.js 3D scene "Octopus arm sucker arrangement" 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: Octopus arm sucker arrangement
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/octopus-arm-sucker-arrangement-x0697
Scene Description Prompt:
Create a standalone stylized scene in one HTML file using Three.js from cdnjs. Model a curved octopus arm section with two visible sucker rows beside a small shell; make contact points distinct from the arm's continuous flexible surface.
Working Three.js Starter (octopus-arm-sucker-arrangement-x0697):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Curved Octopus Arm & Shell</title>
<style>
:root {
color-scheme: dark;
--ink: #effffc;
--muted: #9fc3c5;
--accent: #ffb28f;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 72% 24%, #173d49 0%, transparent 42%),
linear-gradient(155deg, #0b2631, #06131f 70%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
outline: none;
}
canvas:active {
cursor: grabbing;
}
.title-card {
position: fixed;
z-index: 2;
top: clamp(22px, 4vw, 52px);
left: clamp(22px, 5vw, 72px);
width: min(410px, calc(100vw - 44px));
pointer-events: none;
text-shadow: 0 2px 24px rgba(0, 0, 0, 0.4);
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 12px;
color: var(--accent);
font-size: 10px;
font-weight: 750;
letter-spacing: 0.25em;
text-transform: uppercase;
}
.eyebrow::before {
width: 28px;
height: 1px;
content: "";
background: currentColor;
}
h1 {
margin: 0;
color: var(--ink);
font-size: clamp(30px, 4.3vw, 58px);
font-weight: 500;
line-height: 0.98;
letter-spacing: -0.045em;
}
.subtitle {
max-width: 330px;
margin: 17px 0 0;
color: var(--muted);
font-size: 12px;
line-height: 1.65;
letter-spacing: 0.025em;
}
.controls {
position: fixed;
z-index: 3;
right: clamp(18px, 3vw, 42px);
bottom: clamp(18px, 3vw, 36px);
display: flex;
align-items: center;
gap: 12px;
color: rgba(229, 255, 252, 0.68);
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.controls span {
padding: 9px 12px;
border: 1px solid rgba(184, 226, 224, 0.14);
border-radius: 999px;
background: rgba(4, 20, 29, 0.48);
backdrop-filter: blur(12px);
}
button {
border: 1px solid rgba(184, 226, 224, 0.18);
border-radius: 999px;
padding: 9px 13px;
color: rgba(229, 255, 252, 0.84);
background: rgba(4, 20, 29, 0.58);
font: inherit;
font-size: 10px;
letter-spacing: 0.12em;
text-transform: uppercase;
cursor: pointer;
backdrop-filter: blur(12px);
transition: border-color 160ms, background 160ms, transform 160ms;
}
button:hover {
border-color: rgba(255, 178, 143, 0.58);
background: rgba(16, 42, 51, 0.78);
transform: translateY(-1px);
}
.legend {
position: fixed;
z-index: 2;
left: clamp(22px, 5vw, 72px);
bottom: clamp(24px, 4vw, 48px);
display: grid;
gap: 7px;
color: rgba(220, 245, 242, 0.55);
font-size: 9px;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
.legend div {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 17px;
height: 5px;
border-radius: 10px;
background: #dd647a;
box-shadow: 0 0 12px rgba(221, 100, 122, 0.35);
}
.swatch.suckers {
background: #ffe1bd;
box-shadow: 0 0 12px rgba(255, 225, 189, 0.35);
}
@media (max-width: 640px) {
.subtitle {
max-width: 270px;
}
.legend {
display: none;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<header class="title-card">
<div class="eyebrow">Abyssal study · 07</div>
<h1>Arm & Shell</h1>
<p class="subtitle">
A stylized cephalopod study: one continuous, flexible arm surface,
paired rows of raised contact points, and a small spiral shell.
</p>
</header>
<aside class="legend" aria-hidden="true">
<div><span class="swatch"></span> Continuous arm surface</div>
<div><span class="swatch suckers"></span> Raised sucker contacts</div>
</aside>
<div class="controls">
<span>Drag to orbit · scroll to zoom</span>
<button id="reset" type="button">Reset view</button>
</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, camera, and lighting
// -------------------------------------------------------------------------
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.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.prepend(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071923);
scene.fog = new THREE.FogExp2(0x071923, 0.027);
const camera = new THREE.PerspectiveCamera(
42,
window.innerWidth / window.innerHeight,
0.1,
80
);
const hemisphere = new THREE.HemisphereLight(0xb7f4ef, 0x311a36, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd0ae, 3.5);
keyLight.position.set(-3.5, 8.5, 6.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -10;
keyLight.shadow.camera.right = 10;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.00025;
keyLight.shadow.normalBias = 0.025;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x71dfe7, 2.35);
rimLight.position.set(6, 4, -7);
scene.add(rimLight);
const shellGlow = new THREE.PointLight(0xff9d78, 11, 8, 2);
shellGlow.position.set(2.4, 2.5, -0.5);
scene.add(shellGlow);
// -------------------------------------------------------------------------
// Small procedural helpers
// -------------------------------------------------------------------------
function seabedHeight(x, z) {
return (
0.075 * Math.sin(x * 0.44) * Math.cos(z * 0.37) +
0.025 * Math.sin(x * 1.1 + z * 0.45)
);
}
function seededRandom(seed) {
let state = seed >>> 0;
return () => {
state = (1664525 * state + 1013904223) >>> 0;
return state / 4294967296;
};
}
function makeMottledTexture() {
const size = 256;
const canvas = document.createElement("canvas");
canvas.width = canvas.height = size;
const context = canvas.getContext("2d");
context.fillStyle = "#ffffff";
context.fillRect(0, 0, size, size);
const random = seededRandom(8172);
for (let i = 0; i < 950; i++) {
const x = random() * size;
const y = random() * size;
const radius = 0.35 + random() * 2.2;
context.fillStyle = `rgba(79, 27, 67, ${0.018 + random() * 0.045})`;
context.beginPath();
context.arc(x, y, radius, 0, Math.PI * 2);
context.fill();
}
const texture = new THREE.CanvasTexture(canvas);
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.colorSpace = THREE.SRGBColorSpace;
texture.anisotropy = Math.min(8, renderer.capabilities.getMaxAnisotropy());
return texture;
}
function makeBubbleTexture() {
const canvas = document.createElement("canvas");
canvas.width = canvas.height = 64;
const context = canvas.getContext("2d");
const gradient = context.createRadialGradient(
27, 25, 2,
32, 32, 28
);
gradient.addColorStop(0, "rgba(255,255,255,0.05)");
gradient.addColorStop(0.62, "rgba(255,255,255,0.04)");
gradient.addColorStop(0.78, "rgba(219,255,252,0.85)");
gradient.addColorStop(1, "rgba(219,255,252,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 64, 64);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
// -------------------------------------------------------------------------
// Seabed
// -------------------------------------------------------------------------
const groundGeometry = new THREE.PlaneGeometry(50, 50, 100, 100);
groundGeometry.rotateX(-Math.PI / 2);
const groundPosition = groundGeometry.attributes.position;
for (let i = 0; i < groundPosition.count; i++) {
const x = groundPosition.getX(i);
const z = groundPosition.getZ(i);
groundPosition.setY(i, seabedHeight(x, z) - 0.13);
}
groundPosition.needsUpdate = true;
groundGeometry.computeVertexNormals();
const ground = new THREE.Mesh(
groundGeometry,
new THREE.MeshStandardMaterial({
color: 0x254b52,
roughness: 0.97,
metalness: 0
})
);
ground.receiveShadow = true;
scene.add(ground);
const groundGlow = new THREE.Mesh(
new THREE.CircleGeometry(6.6, 96),
new THREE.MeshBasicMaterial({
color: 0x80d8cf,
transparent: true,
opacity: 0.035,
depthWrite: false
})
);
groundGlow.rotation.x = -Math.PI / 2;
groundGlow.position.set(-0.2, -0.105, 0.4);
scene.add(groundGlow);
// Scattered low-poly pebbles.
const pebbleCount = 34;
const pebbleGeometry = new THREE.IcosahedronGeometry(1, 1);
const pebbleMaterial = new THREE.MeshStandardMaterial({
color: 0x6d8987,
roughness: 0.95
});
const pebbles = new THREE.InstancedMesh(
pebbleGeometry,
pebbleMaterial,
pebbleCount
);
pebbles.castShadow = true;
pebbles.receiveShadow = true;
const random = seededRandom(49123);
const dummy = new THREE.Object3D();
const pebbleColor = new THREE.Color();
for (let i = 0; i < pebbleCount; i++) {
const angle = random() * Math.PI * 2;
const distance = 3.2 + random() * 8.5;
const x = Math.cos(angle) * distance - 0.2;
const z = Math.sin(angle) * distance + 0.3;
const scale = 0.045 + random() * 0.13;
dummy.position.set(x, seabedHeight(x, z) - 0.11, z);
dummy.rotation.set(random() * Math.PI, random() * Math.PI, random() * Math.PI);
dummy.scale.set(
scale * (0.8 + random() * 0.7),
scale * (0.45 + random() * 0.35),
scale * (0.8 + random() * 0.7)
);
dummy.updateMatrix();
pebbles.setMatrixAt(i, dummy.matrix);
pebbleColor.setHSL(
0.45 + random() * 0.08,
0.10 + random() * 0.10,
0.31 + random() * 0.13
);
pebbles.setColorAt(i, pebbleColor);
}
scene.add(pebbles);
// -------------------------------------------------------------------------
// Continuous curved arm surface
// -------------------------------------------------------------------------
const armCurve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(3.25, 0.27, 2.05),
new THREE.Vector3(2.72, 0.38, 1.45),
new THREE.Vector3(1.72, 0.43, 0.72),
new THREE.Vector3(0.65, 0.58, 0.14),
new THREE.Vector3(-0.55, 0.78, -0.30),
new THREE.Vector3(-2.00, 1.03, -0.42),
new THREE.Vector3(-3.35, 1.15, -0.05),
new THREE.Vector3(-4.50, 0.95, 0.25)
],
false,
"catmullrom",
0.48
);
function armRadius(t) {
return 0.07 + 0.70 * Math.pow(t, 0.72);
}
// This direction keeps the two underside rows visible from the opening view.
const ventralPreference = new THREE.Vector3(0.32, -0.38, 0.87).normalize();
function armFrame(t) {
const point = armCurve.getPointAt(t);
const tangent = armCurve.getTangentAt(t).normalize();
const ventral = ventralPreference
.clone()
.addScaledVector(tangent, -ventralPreference.dot(tangent));
if (ventral.lengthSq() < 0.0001) {
ventral.set(0, -1, 0);
}
ventral.normalize();
const lateral = new THREE.Vector3()
.crossVectors(tangent, ventral)
.normalize();
return { point, tangent, ventral, lateral };
}
function createArmGeometry() {
const lengthSegments = 230;
const radialSegments = 56;
const positions = [];
const colors = [];
const uvs = [];
const indices = [];
const tipColor = new THREE.Color(0xf6ad72);
const middleColor = new THREE.Color(0xdc637b);
const baseColor = new THREE.Color(0x7f3b88);
for (let i = 0; i <= lengthSegments; i++) {
const t = i / lengthSegments;
const { point, ventral, lateral } = armFrame(t);
const radius = armRadius(t);
const surfaceColor = new THREE.Color();
if (t < 0.52) {
surfaceColor.copy(tipColor).lerp(middleColor, t / 0.52);
} else {
surfaceColor
.copy(middleColor)
.lerp(baseColor, (t - 0.52) / 0.48);
}
for (let j = 0; j <= radialSegments; j++) {
const theta = (j / radialSegments) * Math.PI * 2;
const radial = lateral
.clone()
.multiplyScalar(Math.cos(theta))
.addScaledVector(ventral, Math.sin(theta));
const vertex = point.clone().addScaledVector(radial, radius);
positions.push(vertex.x, vertex.y, vertex.z);
const shading = 0.96 + 0.045 * Math.sin(theta * 3.0 + t * 8.0);
const ventralLight = 1.0 + 0.035 * Math.sin(theta);
const color = surfaceColor.clone().multiplyScalar(shading * ventralLight);
colors.push(color.r, color.g, color.b);
uvs.push(t * 3.5, j / radialSegments);
}
}
for (let i = 0; i < lengthSegments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const armTexture = makeMottledTexture();
const armMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
vertexColors: true,
map: armTexture,
bumpMap: armTexture,
bumpScale: 0.018,
roughness: 0.47,
metalness: 0,
clearcoat: 0.28,
clearcoatRoughness: 0.38
});
const arm = new THREE.Mesh(createArmGeometry(), armMaterial);
arm.castShadow = true;
arm.receiveShadow = true;
scene.add(arm);
// Rounded tip.
const tip = new THREE.Mesh(
new THREE.SphereGeometry(0.075, 24, 16),
armMaterial
);
tip.position.copy(armCurve.getPointAt(0));
tip.castShadow = true;
scene.add(tip);
// Visible cut end of the arm section.
const baseFrame = armFrame(1);
const baseOutward = baseFrame.tangent.clone().negate();
const baseQuaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
baseOutward
);
const baseDisc = new THREE.Mesh(
new THREE.CircleGeometry(armRadius(1), 64),
new THREE.MeshPhysicalMaterial({
color: 0x693167,
roughness: 0.6,
clearcoat: 0.15,
side: THREE.DoubleSide
})
);
baseDisc.position
.copy(baseFrame.point)
.addScaledVector(baseOutward, 0.006);
baseDisc.quaternion.copy(baseQuaternion);
baseDisc.receiveShadow = true;
scene.add(baseDisc);
for (const scale of [0.56, 0.28]) {
const ring = new THREE.Mesh(
new THREE.TorusGeometry(
armRadius(1) * scale,
0.028,
8,
64
),
new THREE.MeshStandardMaterial({
color: 0xd78691,
roughness: 0.52
})
);
ring.position
.copy(baseFrame.point)
.addScaledVector(baseOutward, 0.018);
ring.quaternion.copy(baseQuaternion);
scene.add(ring);
}
// -------------------------------------------------------------------------
// Two rows of distinct, raised sucker contacts
// -------------------------------------------------------------------------
const suckerRows = [];
const suckersPerRow = 13;
for (const side of [-1, 1]) {
for (let i = 0; i < suckersPerRow; i++) {
const t = 0.125 + (i / (suckersPerRow - 1)) * 0.735 + side * 0.007;
const { point, ventral, lateral } = armFrame(t);
// The two rows sit on opposite margins of the arm's ventral surface.
const theta = Math.PI / 2 + side * 0.72;
const normal = lateral
.clone()
.multiplyScalar(Math.cos(theta))
.addScaledVector(ventral, Math.sin(theta))
.normalize();
const surfacePoint = point
.clone()
.addScaledVector(normal, armRadius(t) + 0.003);
const size = 0.055 + 0.125 * Math.pow(t, 0.62);
const quaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
normal
);
suckerRows.push({
position: surfacePoint,
quaternion,
size
});
}
}
const suckerRimGeometry = new THREE.TorusGeometry(0.70, 0.24, 12, 28);
const suckerRimMaterial = new THREE.MeshPhysicalMaterial({
color: 0xffe2bd,
roughness: 0.32,
clearcoat: 0.42,
clearcoatRoughness: 0.25
});
const suckerRims = new THREE.InstancedMesh(
suckerRimGeometry,
suckerRimMaterial,
suckerRows.length
);
suckerRims.castShadow = true;
suckerRims.receiveShadow = true;
const suckerCenterGeometry = new THREE.CircleGeometry(1, 28);
const suckerCenterMaterial = new THREE.MeshStandardMaterial({
color: 0x542441,
roughness: 0.68,
side: THREE.DoubleSide
});
const suckerCenters = new THREE.InstancedMesh(
suckerCenterGeometry,
suckerCenterMaterial,
suckerRows.length
);
suckerCenters.receiveShadow = true;
suckerRows.forEach((sucker, index) => {
dummy.position.copy(sucker.position);
dummy.quaternion.copy(sucker.quaternion);
dummy.scale.setScalar(sucker.size);
dummy.updateMatrix();
suckerRims.setMatrixAt(index, dummy.matrix);
dummy.position
.copy(sucker.position)
.addScaledVector(
new THREE.Vector3(0, 0, 1).applyQuaternion(sucker.quaternion),
sucker.size * 0.035
);
dummy.quaternion.copy(sucker.quaternion);
dummy.scale.setScalar(sucker.size * 0.42);
dummy.updateMatrix();
suckerCenters.setMatrixAt(index, dummy.matrix);
});
scene.add(suckerRims, suckerCenters);
// -------------------------------------------------------------------------
// Small spiral shell
// -------------------------------------------------------------------------
function createSpiralShell() {
const group = new THREE.Group();
const lengthSegments = 210;
const radialSegments = 20;
const turns = 2.42;
const maxAngle = turns * Math.PI * 2;
const growth = 0.19;
const positions = [];
const colors = [];
const uvs = [];
const indices = [];
const cream = new THREE.Color(0xffddb3);
const coral = new THREE.Color(0xd97d70);
const inner = new THREE.Color(0x9e5367);
function shellFrame(t) {
const angle = maxAngle * t;
const radius = 0.105 * Math.exp(growth * angle);
const radialDerivative = growth * radius;
const center = new THREE.Vector3(
Math.cos(angle) * radius,
Math.sin(angle) * radius,
0
);
const tangent = new THREE.Vector3(
Math.cos(angle) * radialDerivative - Math.sin(angle) * radius,
Math.sin(angle) * radialDerivative + Math.cos(angle) * radius,
0
).normalize();
const outward = new THREE.Vector3(
Math.cos(angle),
Math.sin(angle),
0
);
const inPlaneNormal = outward
.clone()
.addScaledVector(tangent, -outward.dot(tangent))
.normalize();
const tubeRadius = 0.043 + 0.145 * Math.pow(t, 0.83);
return {
center,
tangent,
inPlaneNormal,
tubeRadius
};
}
for (let i = 0; i <= lengthSegments; i++) {
const t = i / lengthSegments;
const frame = shellFrame(t);
const binormal = new THREE.Vector3(0, 0, 1);
for (let j = 0; j <= radialSegments; j++) {
const phi = (j / radialSegments) * Math.PI * 2;
const vertex = frame.center
.clone()
.addScaledVector(
frame.inPlaneNormal,
Math.cos(phi) * frame.tubeRadius
)
.addScaledVector(
binormal,
Math.sin(phi) * frame.tubeRadius
);
positions.push(vertex.x, vertex.y, vertex.z);
const stripe = 0.5 + 0.5 * Math.sin(maxAngle * t * 4.6);
const color = cream.clone().lerp(coral, stripe * 0.38);
if (t < 0.23) {
color.lerp(inner, (0.23 - t) * 1.4);
}
const lighting = 0.91 + 0.13 * Math.sin(phi);
color.multiplyScalar(lighting);
colors.push(color.r, color.g, color.b);
uvs.push(t * 6, j / radialSegments);
}
}
for (let i = 0; i < lengthSegments; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * (radialSegments + 1) + j;
const b = (i + 1) * (radialSegments + 1) + j;
const c = b + 1;
const d = a + 1;
indices.push(a, b, d, b, c, d);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
const material = new THREE.MeshPhysicalMaterial({
color: 0xffffff,
vertexColors: true,
roughness: 0.38,
metalness: 0,
clearcoat: 0.36,
clearcoatRoughness: 0.25,
side: THREE.DoubleSide
});
const shell = new THREE.Mesh(geometry, material);
shell.castShadow = true;
shell.receiveShadow = true;
group.add(shell);
// Dark aperture and a thick lip at the outer end of the spiral.
const endFrame = shellFrame(1);
const endQuaternion = new THREE.Quaternion().setFromUnitVectors(
new THREE.Vector3(0, 0, 1),
endFrame.tangent
);
const aperture = new THREE.Mesh(
new THREE.CircleGeometry(endFrame.tubeRadius * 0.68, 40),
new THREE.MeshStandardMaterial({
color: 0x67384c,
roughness: 0.7,
side: THREE.DoubleSide
})
);
aperture.position
.copy(endFrame.center)
.addScaledVector(endFrame.tangent, 0.01);
aperture.quaternion.copy(endQuaternion);
group.add(aperture);
const lip = new THREE.Mesh(
new THREE.TorusGeometry(
endFrame.tubeRadius * 0.73,
endFrame.tubeRadius * 0.18,
10,
48
),
material
);
lip.position.copy(aperture.position);
lip.quaternion.copy(endQuaternion);
lip.castShadow = true;
group.add(lip);
group.position.set(3.05, 1.22, -1.35);
group.rotation.set(0.03, -0.24, -0.10);
group.scale.setScalar(0.92);
return group;
}
const shell = createSpiralShell();
scene.add(shell);
// -------------------------------------------------------------------------
// Suspended bubbles
// -------------------------------------------------------------------------
const bubbleCount = 85;
const bubblePositions = new Float32Array(bubbleCount * 3);
const bubbleSpeeds = new Float32Array(bubbleCount);
for (let i = 0; i < bubbleCount; i++) {
bubblePositions[i * 3] = (random() - 0.5) * 17;
bubblePositions[i * 3 + 1] = 0.4 + random() * 7;
bubblePositions[i * 3 + 2] = (random() - 0.5) * 14;
bubbleSpeeds[i] = 0.045 + random() * 0.11;
}
const bubbleGeometry = new THREE.BufferGeometry();
bubbleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(bubblePositions, 3)
);
const bubbleMaterial = new THREE.PointsMaterial({
color: 0xc5fff8,
size: 0.105,
map: makeBubbleTexture(),
transparent: true,
opacity: 0.42,
depthWrite: false,
sizeAttenuation: true
});
const bubbles = new THREE.Points(bubbleGeometry, bubbleMaterial);
scene.add(bubbles);
// -------------------------------------------------------------------------
// Direct, dependency-free camera controls
// -------------------------------------------------------------------------
const target = new THREE.Vector3(-0.25, 0.72, 0.42);
const defaultView = {
theta: 0.60,
phi: 1.12,
radius: 11.4
};
const desired = { ...defaultView };
const current = { ...defaultView };
const spherical = new THREE.Spherical();
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - pointerX;
const deltaY = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
desired.theta -= deltaX * 0.0055;
desired.phi = THREE.MathUtils.clamp(
desired.phi - deltaY * 0.0048,
0.46,
1.43
);
});
function endDrag(event) {
dragging = false;
if (canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius * Math.exp(event.deltaY * 0.001),
6.4,
18
);
},
{ passive: false }
);
function resetView() {
desired.theta = defaultView.theta;
desired.phi = defaultView.phi;
desired.radius = defaultView.radius;
}
document.getElementById("reset").addEventListener("click", resetView);
canvas.addEventListener("dblclick", resetView);
// -------------------------------------------------------------------------
// Animation and responsive handling
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
current.theta += (desired.theta - current.theta) * 0.10;
current.phi += (desired.phi - current.phi) * 0.10;
current.radius += (desired.radius - current.radius) * 0.10;
spherical.set(current.radius, current.phi, current.theta);
camera.position.setFromSpherical(spherical).add(target);
camera.lookAt(target);
const positions = bubbleGeometry.attributes.position;
for (let i = 0; i < bubbleCount; i++) {
let y = positions.getY(i) + bubbleSpeeds[i] * delta;
if (y > 7.6) y = 0.25;
positions.setY(i, y);
positions.setX(
i,
positions.getX(i) + Math.sin(elapsed * 0.45 + i) * 0.00045
);
}
positions.needsUpdate = true;
shellGlow.intensity = 10.5 + Math.sin(elapsed * 0.85) * 0.7;
bubbles.rotation.y = Math.sin(elapsed * 0.08) * 0.035;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
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);
animate();
</script>
</body>
</html>
```