Prompt specification
Build or customize the Three.js 3D scene "Shell shelter manipulation sequence" 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: Shell shelter manipulation sequence
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/shell-shelter-manipulation-sequence-x0698
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: shell shelter manipulation sequence. Animate a stylized octopus positioning two shell halves around itself; arms follow separate prescribed curves and release objects only after they reach the intended support surface.
Working Three.js Starter (shell-shelter-manipulation-sequence-x0698):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Octopus Shell Shelter</title>
<style>
:root {
color-scheme: dark;
--panel: rgba(6, 28, 39, 0.76);
--border: rgba(150, 230, 240, 0.22);
--text: #eefbff;
--muted: #9bc2ca;
--cyan: #71e6e0;
--coral: #ff8f87;
--gold: #ffd382;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #092b3a;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
}
.panel {
position: fixed;
z-index: 10;
border: 1px solid var(--border);
background: var(--panel);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#intro {
top: 20px;
left: 20px;
width: min(420px, calc(100vw - 40px));
padding: 18px 20px;
border-radius: 18px;
}
.eyebrow {
margin-bottom: 6px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
}
h1 {
margin: 0;
color: var(--text);
font-size: clamp(22px, 3vw, 32px);
line-height: 1.05;
}
#intro p {
margin: 10px 0 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.toolbar {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 14px;
}
button {
appearance: none;
border: 1px solid rgba(150, 230, 240, 0.25);
border-radius: 999px;
padding: 8px 13px;
background: rgba(255, 255, 255, 0.06);
color: var(--text);
font: inherit;
font-size: 12px;
font-weight: 700;
cursor: pointer;
transition:
background 160ms ease,
transform 160ms ease;
}
button:hover {
background: rgba(113, 230, 224, 0.14);
transform: translateY(-1px);
}
button.primary {
border-color: rgba(113, 230, 224, 0.55);
background: rgba(113, 230, 224, 0.16);
color: #bafffb;
}
label {
display: inline-flex;
align-items: center;
gap: 7px;
min-height: 34px;
padding: 0 12px;
border: 1px solid rgba(150, 230, 240, 0.2);
border-radius: 999px;
color: var(--muted);
font-size: 12px;
cursor: pointer;
}
input {
accent-color: var(--cyan);
}
#timeline {
left: 50%;
bottom: 20px;
width: min(760px, calc(100vw - 40px));
padding: 14px 16px;
border-radius: 18px;
transform: translateX(-50%);
}
.timeline-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
#phase-label {
color: var(--text);
font-size: 13px;
font-weight: 800;
}
#clock {
color: var(--muted);
font-variant-numeric: tabular-nums;
font-size: 12px;
}
.steps {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 10px;
}
.step {
position: relative;
overflow: hidden;
padding: 9px 10px;
border: 1px solid rgba(150, 230, 240, 0.13);
border-radius: 11px;
color: #739ba4;
font-size: 11px;
font-weight: 800;
text-align: center;
text-transform: uppercase;
letter-spacing: 0.06em;
transition: 180ms ease;
}
.step.active {
border-color: rgba(113, 230, 224, 0.55);
background: rgba(113, 230, 224, 0.11);
color: #bafffb;
}
.step.done {
color: var(--cyan);
}
.gates {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
}
.gate {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
min-width: 0;
padding: 8px 10px;
border-radius: 10px;
background: rgba(0, 0, 0, 0.16);
color: var(--muted);
font-size: 11px;
}
.gate strong {
overflow: hidden;
color: var(--text);
font-size: 10px;
letter-spacing: 0.06em;
text-overflow: ellipsis;
text-transform: uppercase;
white-space: nowrap;
}
.lamp {
width: 9px;
height: 9px;
flex: 0 0 auto;
border-radius: 50%;
background: #52727a;
box-shadow: 0 0 0 3px rgba(82, 114, 122, 0.13);
transition: 180ms ease;
}
.gate.transfer .lamp {
background: var(--gold);
box-shadow: 0 0 0 3px rgba(255, 211, 130, 0.13);
}
.gate.supported .lamp {
background: var(--cyan);
box-shadow: 0 0 12px rgba(113, 230, 224, 0.9);
}
#hint {
position: fixed;
right: 20px;
bottom: 20px;
z-index: 8;
color: rgba(220, 247, 250, 0.68);
font-size: 11px;
text-align: right;
pointer-events: none;
}
@media (max-width: 800px) {
#hint {
display: none;
}
#intro {
padding: 14px 16px;
}
#intro p {
display: none;
}
#timeline {
bottom: 10px;
width: calc(100vw - 20px);
}
}
@media (max-width: 520px) {
.gates {
grid-template-columns: 1fr;
}
.steps {
gap: 4px;
}
.step {
padding: 8px 4px;
font-size: 9px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Animated low-poly octopus positioning two shell halves"></canvas>
<section id="intro" class="panel">
<div class="eyebrow">Manipulation study · 01</div>
<h1>Building a shell shelter</h1>
<p>
Two manipulator arms follow separate prescribed paths. Each shell remains
attached until its contact point reaches the mint support surface and its
orientation is aligned.
</p>
<div class="toolbar">
<button id="replay" class="primary" type="button">Replay sequence</button>
<button id="pause" type="button">Pause</button>
<button id="reset-camera" type="button">Reset view</button>
<label>
<input id="show-paths" type="checkbox" checked />
Show paths
</label>
</div>
</section>
<section id="timeline" class="panel">
<div class="timeline-head">
<div id="phase-label">Preparing manipulation</div>
<div id="clock">0.0 / 11.0 s</div>
</div>
<div class="steps">
<div id="step-reach" class="step active">1 · Reach</div>
<div id="step-transfer" class="step">2 · Transfer</div>
<div id="step-release" class="step">3 · Supported release</div>
</div>
<div class="gates">
<div id="gate-left" class="gate">
<strong>Left shell</strong>
<span id="left-readout">Waiting</span>
<span class="lamp"></span>
</div>
<div id="gate-right" class="gate">
<strong>Right shell</strong>
<span id="right-readout">Waiting</span>
<span class="lamp"></span>
</div>
</div>
</section>
<div id="hint">
Drag to orbit · Scroll to zoom<br />
Mint platforms are the intended support surfaces
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const ui = {
replay: document.querySelector("#replay"),
pause: document.querySelector("#pause"),
resetCamera: document.querySelector("#reset-camera"),
showPaths: document.querySelector("#show-paths"),
phaseLabel: document.querySelector("#phase-label"),
clock: document.querySelector("#clock"),
stepReach: document.querySelector("#step-reach"),
stepTransfer: document.querySelector("#step-transfer"),
stepRelease: document.querySelector("#step-release"),
gateLeft: document.querySelector("#gate-left"),
gateRight: document.querySelector("#gate-right"),
leftReadout: document.querySelector("#left-readout"),
rightReadout: document.querySelector("#right-readout")
};
const DURATION = 11;
const UP = new THREE.Vector3(0, 1, 0);
const tempA = new THREE.Vector3();
const tempB = new THREE.Vector3();
const tempC = new THREE.Vector3();
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: 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.1;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x082a39);
scene.fog = new THREE.Fog(0x082a39, 12, 29);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
80
);
const cameraTarget = new THREE.Vector3(0, 1.0, 0);
const cameraState = {
theta: 0.52,
phi: 1.14,
radius: 10.8
};
function updateCamera() {
const { theta, phi, radius } = cameraState;
const sinPhi = Math.sin(phi);
camera.position.set(
cameraTarget.x + radius * sinPhi * Math.sin(theta),
cameraTarget.y + radius * Math.cos(phi),
cameraTarget.z + radius * sinPhi * Math.cos(theta)
);
camera.lookAt(cameraTarget);
}
updateCamera();
// Direct camera controls; no examples/addons modules are used.
let dragging = false;
let pointerX = 0;
let pointerY = 0;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - pointerX;
const dy = event.clientY - pointerY;
pointerX = event.clientX;
pointerY = event.clientY;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.58,
1.43
);
updateCamera();
});
const endDrag = () => {
dragging = false;
};
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", endDrag);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
6.5,
15
);
updateCamera();
},
{ passive: false }
);
ui.resetCamera.addEventListener("click", () => {
cameraState.theta = 0.52;
cameraState.phi = 1.14;
cameraState.radius = 10.8;
updateCamera();
});
// Lighting.
scene.add(new THREE.HemisphereLight(0x9ee7f0, 0x15383a, 2.15));
const keyLight = new THREE.DirectionalLight(0xffe6c6, 3.0);
keyLight.position.set(4, 9, 6);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 8;
keyLight.shadow.camera.bottom = -8;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 25;
keyLight.shadow.bias = -0.0007;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x63dce8, 1.8);
rimLight.position.set(-5, 4, -6);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xff8c78, 7, 9, 2);
warmLight.position.set(-3.5, 2.8, 3.5);
scene.add(warmLight);
// Seabed.
const floorGeometry = new THREE.PlaneGeometry(34, 34, 18, 18);
const floorPosition = floorGeometry.attributes.position;
for (let i = 0; i < floorPosition.count; i++) {
const x = floorPosition.getX(i);
const y = floorPosition.getY(i);
floorPosition.setZ(
i,
Math.sin(x * 0.75) * 0.035 + Math.cos(y * 0.58) * 0.028
);
}
floorGeometry.computeVertexNormals();
const floor = new THREE.Mesh(
floorGeometry,
new THREE.MeshStandardMaterial({
color: 0x24565a,
roughness: 0.96,
metalness: 0,
flatShading: true
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.045;
floor.receiveShadow = true;
scene.add(floor);
const rockGeometry = new THREE.IcosahedronGeometry(1, 0);
const rockMaterials = [
new THREE.MeshStandardMaterial({
color: 0x416b68,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x527775,
roughness: 0.95,
flatShading: true
}),
new THREE.MeshStandardMaterial({
color: 0x355d61,
roughness: 0.95,
flatShading: true
})
];
const rocks = [
[-5.0, 0.23, 2.2, 0.9],
[5.1, 0.28, 1.5, 1.05],
[-4.3, 0.15, -3.0, 0.65],
[4.8, 0.18, -2.8, 0.82],
[-1.7, 0.12, -4.1, 0.48],
[2.1, 0.10, 4.3, 0.44],
[-5.9, 0.12, -0.8, 0.44],
[6.2, 0.13, -0.6, 0.5]
];
rocks.forEach(([x, y, z, scale], index) => {
const rock = new THREE.Mesh(
rockGeometry,
rockMaterials[index % rockMaterials.length]
);
rock.position.set(x, y, z);
rock.scale.set(scale, scale * 0.62, scale * 0.83);
rock.rotation.set(index * 0.4, index * 0.7, index * 0.2);
rock.castShadow = true;
rock.receiveShadow = true;
scene.add(rock);
});
// Low-poly seaweed.
const seaweed = [];
const seaweedMaterial = new THREE.MeshStandardMaterial({
color: 0x2d7868,
roughness: 0.9,
flatShading: true
});
const seaweedPositions = [
[-5.3, -2.4],
[-4.6, 3.7],
[-2.7, -4.3],
[3.0, -4.5],
[5.4, 3.4],
[5.7, -1.8]
];
seaweedPositions.forEach(([x, z], plantIndex) => {
const group = new THREE.Group();
group.position.set(x, 0, z);
for (let blade = 0; blade < 3; blade++) {
const height = 0.75 + blade * 0.18;
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.035, 0.11, height, 5),
seaweedMaterial
);
stem.position.set(
(blade - 1) * 0.12,
height * 0.5,
Math.sin(blade * 2.1) * 0.08
);
stem.rotation.z = (blade - 1) * 0.18;
stem.castShadow = true;
group.add(stem);
}
group.userData.phase = plantIndex * 0.8;
scene.add(group);
seaweed.push(group);
});
// Octopus.
const octopus = new THREE.Group();
scene.add(octopus);
const octopusMaterial = new THREE.MeshStandardMaterial({
color: 0xe87872,
roughness: 0.72,
flatShading: true
});
const octopusLightMaterial = new THREE.MeshStandardMaterial({
color: 0xf39a86,
roughness: 0.78,
flatShading: true
});
const body = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.78, 2),
octopusMaterial
);
body.position.y = 1.05;
body.scale.set(0.94, 0.94, 0.83);
body.castShadow = true;
body.receiveShadow = true;
octopus.add(body);
const mantle = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.61, 2),
octopusLightMaterial
);
mantle.position.set(0, 1.58, -0.05);
mantle.scale.set(0.86, 1.16, 0.78);
mantle.castShadow = true;
mantle.receiveShadow = true;
octopus.add(mantle);
const eyeWhiteMaterial = new THREE.MeshStandardMaterial({
color: 0xfff3d9,
roughness: 0.45
});
const eyeBlackMaterial = new THREE.MeshBasicMaterial({
color: 0x09252b
});
const eyes = [];
[-0.27, 0.27].forEach((x) => {
const eye = new THREE.Mesh(
new THREE.SphereGeometry(0.17, 12, 8),
eyeWhiteMaterial
);
eye.position.set(x, 1.52, 0.62);
eye.scale.z = 0.55;
eye.castShadow = true;
octopus.add(eye);
const pupil = new THREE.Mesh(
new THREE.SphereGeometry(0.073, 10, 7),
eyeBlackMaterial
);
pupil.position.set(x, 1.51, 0.727);
pupil.scale.set(0.78, 1, 0.4);
octopus.add(pupil);
eyes.push(eye);
});
const mouthCurve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.14, 1.26, 0.675),
new THREE.Vector3(0, 1.21, 0.711),
new THREE.Vector3(0.14, 1.26, 0.675)
]);
const mouth = new THREE.Mesh(
new THREE.TubeGeometry(mouthCurve, 10, 0.018, 4, false),
eyeBlackMaterial
);
octopus.add(mouth);
// Low-poly shell-half geometry: a ribbed fan with a raised hinge.
function createShellGeometry() {
const radialSegments = 7;
const angularSegments = 16;
const positions = [];
const colors = [];
const indices = [];
const inner = new THREE.Color(0xf3b592);
const outer = new THREE.Color(0xffd2ad);
const ridge = new THREE.Color(0xd98278);
positions.push(0, 0.015, 0.45);
colors.push(inner.r, inner.g, inner.b);
for (let ring = 1; ring <= radialSegments; ring++) {
const r = ring / radialSegments;
for (let segment = 0; segment <= angularSegments; segment++) {
const theta =
-1.18 + (2.36 * segment) / angularSegments;
const x = Math.sin(theta) * r * 1.12;
const y = Math.cos(theta) * r * 1.32;
const z =
0.48 * (1 - r * r) +
0.055 * Math.cos(theta * 6) * r * (1 - r);
positions.push(x, y, z);
const color = inner.clone().lerp(outer, r * 0.85);
color.lerp(ridge, Math.max(0, Math.cos(theta * 6)) * 0.22);
colors.push(color.r, color.g, color.b);
}
}
for (let segment = 0; segment < angularSegments; segment++) {
const a = 1 + segment;
const b = 1 + segment + 1;
indices.push(0, b, a);
}
for (let ring = 1; ring < radialSegments; ring++) {
const currentStart = 1 + (ring - 1) * (angularSegments + 1);
const nextStart = currentStart + angularSegments + 1;
for (let segment = 0; segment < angularSegments; segment++) {
const a = currentStart + segment;
const b = nextStart + segment;
indices.push(a, b, a + 1, b, b + 1, a + 1);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute(
"color",
new THREE.Float32BufferAttribute(colors, 3)
);
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
const shellGeometry = createShellGeometry();
const shellMaterial = new THREE.MeshStandardMaterial({
vertexColors: true,
roughness: 0.68,
side: THREE.DoubleSide,
flatShading: true
});
function createShell() {
const group = new THREE.Group();
const shell = new THREE.Mesh(shellGeometry, shellMaterial);
shell.castShadow = true;
shell.receiveShadow = true;
group.add(shell);
const ribMaterial = new THREE.LineBasicMaterial({
color: 0x9f5d60,
transparent: true,
opacity: 0.4
});
for (let rib = 0; rib < 7; rib++) {
const theta = -1.05 + (2.1 * rib) / 6;
const points = [];
for (let step = 0; step <= 8; step++) {
const r = 0.08 + (step / 8) * 0.89;
points.push(
new THREE.Vector3(
Math.sin(theta) * r * 1.12,
Math.cos(theta) * r * 1.32,
0.48 * (1 - r * r) +
0.055 * Math.cos(theta * 6) * r * (1 - r) +
0.014
)
);
}
group.add(
new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
ribMaterial
)
);
}
scene.add(group);
return group;
}
// Intended support surfaces.
function createSupport(target, color) {
const group = new THREE.Group();
group.position.set(target.x, 0, target.z);
const base = new THREE.Mesh(
new THREE.CylinderGeometry(0.64, 0.73, 0.2, 10),
new THREE.MeshStandardMaterial({
color: 0x335d61,
roughness: 0.9,
flatShading: true
})
);
base.position.y = 0.1;
base.castShadow = true;
base.receiveShadow = true;
group.add(base);
const surfaceMaterial = new THREE.MeshStandardMaterial({
color,
emissive: color,
emissiveIntensity: 0.13,
roughness: 0.6,
flatShading: true
});
const surface = new THREE.Mesh(
new THREE.CylinderGeometry(0.54, 0.59, 0.04, 10),
surfaceMaterial
);
surface.position.y = 0.22;
surface.receiveShadow = true;
group.add(surface);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.61, 0.023, 5, 24),
new THREE.MeshBasicMaterial({
color,
transparent: true,
opacity: 0.75
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.25;
group.add(ring);
scene.add(group);
return { group, surfaceMaterial, ring };
}
const leftTarget = new THREE.Vector3(-1.48, 0.245, 0.1);
const rightTarget = new THREE.Vector3(1.48, 0.245, -0.1);
const leftSupport = createSupport(leftTarget, 0x67e5cc);
const rightSupport = createSupport(rightTarget, 0x67e5cc);
// Arm construction.
const armSegmentGeometry = new THREE.CylinderGeometry(
0.64,
1,
1,
6,
1,
false
);
const armMaterial = new THREE.MeshStandardMaterial({
color: 0xe97872,
roughness: 0.76,
flatShading: true
});
const suckerMaterial = new THREE.MeshStandardMaterial({
color: 0xffc1a5,
roughness: 0.7,
flatShading: true
});
const suckerGeometry = new THREE.SphereGeometry(0.055, 7, 5);
function createArm(base, direction = null) {
const group = new THREE.Group();
scene.add(group);
const segments = [];
const suckers = [];
const segmentCount = 12;
for (let i = 0; i < segmentCount; i++) {
const segment = new THREE.Mesh(armSegmentGeometry, armMaterial);
segment.castShadow = true;
segment.receiveShadow = true;
group.add(segment);
segments.push(segment);
}
for (let i = 0; i < 5; i++) {
const sucker = new THREE.Mesh(suckerGeometry, suckerMaterial);
sucker.castShadow = true;
group.add(sucker);
suckers.push(sucker);
}
const tip = new THREE.Mesh(
new THREE.IcosahedronGeometry(0.065, 0),
armMaterial
);
tip.castShadow = true;
group.add(tip);
return {
group,
base: base.clone(),
direction: direction
? direction.clone().normalize()
: new THREE.Vector3(0, -1, 0),
segments,
suckers,
tip
};
}
function updateArmMesh(arm, points) {
const segmentCount = arm.segments.length;
for (let i = 0; i < segmentCount; i++) {
const start = points[i];
const end = points[i + 1];
const direction = tempA.copy(end).sub(start);
const length = direction.length();
arm.segments[i].position.copy(start).add(end).multiplyScalar(0.5);
arm.segments[i].quaternion.setFromUnitVectors(
UP,
direction.normalize()
);
const radius = 0.135 * (1 - (0.73 * i) / (segmentCount - 1));
arm.segments[i].scale.set(radius, length, radius);
}
const suckerIndices = [3, 5, 7, 9, 11];
arm.suckers.forEach((sucker, index) => {
const point = points[suckerIndices[index]];
sucker.position.copy(point);
sucker.position.y -= 0.015;
const size = 1 - index * 0.1;
sucker.scale.setScalar(size);
});
arm.tip.position.copy(points[points.length - 1]);
}
function poseArm(arm, tip, control1, control2) {
const curve = new THREE.CubicBezierCurve3(
arm.base.clone(),
control1.clone(),
control2.clone(),
tip.clone()
);
updateArmMesh(arm, curve.getPoints(arm.segments.length));
}
// Six free arms curl protectively at the end.
const idleAngles = [0.12, 0.98, 1.83, 3.72, 4.55, 5.42];
const idleArms = idleAngles.map((angle) => {
const base = new THREE.Vector3(
Math.cos(angle) * 0.55,
0.89,
Math.sin(angle) * 0.48
);
const direction = new THREE.Vector3(
Math.cos(angle),
0,
Math.sin(angle)
);
return createArm(base, direction);
});
// The two shell manipulators have separate Bezier paths.
function createManipulator(options) {
const shellGroup = createShell();
const initQuat = new THREE.Quaternion().setFromEuler(
new THREE.Euler(...options.initialEuler)
);
const finalQuat = new THREE.Quaternion().setFromEuler(
new THREE.Euler(...options.finalEuler)
);
shellGroup.position.copy(options.initialPosition);
shellGroup.quaternion.copy(initQuat);
const grip = options.grip.clone();
const initialTip = options.initialPosition
.clone()
.add(grip.clone().applyQuaternion(initQuat));
const finalTip = options.target
.clone()
.add(grip.clone().applyQuaternion(finalQuat));
const reach = new THREE.CubicBezierCurve3(
options.base.clone(),
options.reachControl1.clone(),
options.reachControl2.clone(),
initialTip.clone()
);
const carry = new THREE.CubicBezierCurve3(
initialTip.clone(),
options.carryControl1.clone(),
options.carryControl2.clone(),
finalTip.clone()
);
const retract = new THREE.CubicBezierCurve3(
finalTip.clone(),
options.retractControl1.clone(),
options.retractControl2.clone(),
options.restTip.clone()
);
const arm = createArm(options.base);
return {
arm,
shellGroup,
initQuat,
finalQuat,
grip,
initialTip,
finalTip,
reach,
carry,
retract,
reachStart: options.reachStart,
reachEnd: options.reachEnd,
carryEnd: options.carryEnd,
target: options.target.clone(),
support: options.support,
released: false,
releaseFlash: 0,
status: "Waiting"
};
}
const leftManipulator = createManipulator({
base: new THREE.Vector3(-0.48, 0.9, 0.38),
grip: new THREE.Vector3(-0.42, 0.96, 0.14),
initialPosition: new THREE.Vector3(-3.25, 0.15, 0.25),
initialEuler: [1.28, 0.22, -0.1],
finalEuler: [0.02, 0.3, -0.055],
target: leftTarget,
support: leftSupport,
reachStart: 1.0,
reachEnd: 2.8,
carryEnd: 6.1,
reachControl1: new THREE.Vector3(-1.25, 1.18, 1.25),
reachControl2: new THREE.Vector3(-2.75, 1.2, 1.85),
carryControl1: new THREE.Vector3(-4.0, 1.8, 1.8),
carryControl2: new THREE.Vector3(-2.65, 2.75, 0.42),
retractControl1: new THREE.Vector3(-2.15, 2.15, 1.0),
retractControl2: new THREE.Vector3(-1.65, 1.0, 1.0),
restTip: new THREE.Vector3(-1.55, 0.31, 0.9)
});
const rightManipulator = createManipulator({
base: new THREE.Vector3(0.48, 0.9, -0.26),
grip: new THREE.Vector3(0.42, 0.96, 0.14),
initialPosition: new THREE.Vector3(3.25, 0.15, -0.25),
initialEuler: [1.18, -0.35, 0.1],
finalEuler: [0.02, -0.3, 0.055],
target: rightTarget,
support: rightSupport,
reachStart: 1.8,
reachEnd: 3.6,
carryEnd: 6.9,
reachControl1: new THREE.Vector3(1.25, 1.04, -1.25),
reachControl2: new THREE.Vector3(2.8, 1.25, -1.85),
carryControl1: new THREE.Vector3(4.1, 1.7, -1.7),
carryControl2: new THREE.Vector3(2.7, 2.7, -0.42),
retractControl1: new THREE.Vector3(2.2, 2.15, -1.0),
retractControl2: new THREE.Vector3(1.65, 1.0, -1.0),
restTip: new THREE.Vector3(1.55, 0.31, -0.9)
});
// Visible diagnostic paths.
const pathGroup = new THREE.Group();
scene.add(pathGroup);
function addPath(curve, color) {
const geometry = new THREE.BufferGeometry().setFromPoints(
curve.getPoints(70)
);
const material = new THREE.LineDashedMaterial({
color,
transparent: true,
opacity: 0.32,
dashSize: 0.12,
gapSize: 0.09,
depthWrite: false
});
const line = new THREE.Line(geometry, material);
line.computeLineDistances();
pathGroup.add(line);
}
addPath(leftManipulator.reach, 0xff8f87);
addPath(leftManipulator.carry, 0xffb097);
addPath(rightManipulator.reach, 0x71e6e0);
addPath(rightManipulator.carry, 0x9bf1ec);
// Bubbles.
const bubbleCount = 80;
const bubblePositions = new Float32Array(bubbleCount * 3);
const bubbleBaseY = new Float32Array(bubbleCount);
const bubbleSpeed = new Float32Array(bubbleCount);
const bubblePhase = new Float32Array(bubbleCount);
for (let i = 0; i < bubbleCount; i++) {
const radius = 3 + Math.random() * 8;
const angle = Math.random() * Math.PI * 2;
bubblePositions[i * 3] = Math.cos(angle) * radius;
bubblePositions[i * 3 + 1] = Math.random() * 6;
bubblePositions[i * 3 + 2] = Math.sin(angle) * radius;
bubbleBaseY[i] = bubblePositions[i * 3 + 1];
bubbleSpeed[i] = 0.12 + Math.random() * 0.22;
bubblePhase[i] = Math.random() * Math.PI * 2;
}
const bubbleGeometry = new THREE.BufferGeometry();
bubbleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(bubblePositions, 3)
);
const bubbles = new THREE.Points(
bubbleGeometry,
new THREE.PointsMaterial({
color: 0xb9f7f4,
size: 0.045,
transparent: true,
opacity: 0.42,
depthWrite: false
})
);
scene.add(bubbles);
let elapsed = 0;
let paused = false;
function smooth(value) {
const t = THREE.MathUtils.clamp(value, 0, 1);
return t * t * (3 - 2 * t);
}
function updateIdleArms(time) {
const finalBlend = smooth((time - 6.8) / 2.8);
idleArms.forEach((arm, index) => {
const base = arm.base.clone();
base.y += Math.sin(time * 2 + index) * 0.018;
const outwardTip = base
.clone()
.addScaledVector(arm.direction, 1.65)
.add(new THREE.Vector3(0, -0.58, 0));
const tangent = new THREE.Vector3(
-arm.direction.z,
0,
arm.direction.x
);
const curledTip = base
.clone()
.addScaledVector(arm.direction, 0.95)
.addScaledVector(tangent, index % 2 === 0 ? 0.34 : -0.34)
.add(new THREE.Vector3(0, -0.03, 0));
const tip = outwardTip.lerp(curledTip, finalBlend);
tip.y += Math.sin(time * 2.2 + index * 1.4) * 0.055;
const control1 = base
.clone()
.addScaledVector(arm.direction, 0.7)
.add(new THREE.Vector3(0, 0.08, 0));
const control2 = tip
.clone()
.addScaledVector(arm.direction, -0.42)
.addScaledVector(tangent, 0.13);
poseArm(arm, tip, control1, control2);
});
}
function updateManipulator(manipulator, time) {
const arm = manipulator.arm;
const shell = manipulator.shellGroup;
if (time < manipulator.reachStart) {
const tip = manipulator.retract.getPoint(1);
poseArm(
arm,
tip,
manipulator.reach.v1,
manipulator.reach.v2
);
manipulator.status = "Waiting";
return;
}
if (time < manipulator.reachEnd) {
const t = smooth(
(time - manipulator.reachStart) /
(manipulator.reachEnd - manipulator.reachStart)
);
const tip = manipulator.reach.getPoint(t);
poseArm(arm, tip, manipulator.reach.v1, manipulator.reach.v2);
manipulator.status = "Reaching";
return;
}
if (!manipulator.released) {
if (time < manipulator.carryEnd) {
const t = smooth(
(time - manipulator.reachEnd) /
(manipulator.carryEnd - manipulator.reachEnd)
);
const tip = manipulator.carry.getPoint(t);
const orientation = manipulator.initQuat.clone().slerp(
manipulator.finalQuat,
t
);
shell.quaternion.copy(orientation);
const gripWorld = manipulator.grip
.clone()
.applyQuaternion(orientation);
shell.position.copy(tip).sub(gripWorld);
// Blend the arm shape from the reach curve into the carry curve.
const shapeBlend = smooth(t / 0.18);
const control1 = manipulator.reach.v1.clone().lerp(
manipulator.carry.v1,
shapeBlend
);
const control2 = manipulator.reach.v2.clone().lerp(
manipulator.carry.v2,
shapeBlend
);
poseArm(arm, tip, control1, control2);
manipulator.status = "Transferring";
return;
}
// Hold at the intended support surface until every release gate passes.
shell.position.copy(manipulator.target);
shell.quaternion.copy(manipulator.finalQuat);
const tip = manipulator.finalTip.clone();
poseArm(arm, tip, manipulator.carry.v1, manipulator.carry.v2);
const contactError = shell.position.distanceTo(manipulator.target);
const orientationError = shell.quaternion.angleTo(
manipulator.finalQuat
);
const tipError = tip.distanceTo(manipulator.finalTip);
const supported =
contactError <= 0.055 &&
orientationError <= 0.035 &&
tipError <= 0.055;
manipulator.contactError = contactError;
if (supported) {
manipulator.released = true;
manipulator.releaseFlash = 1;
manipulator.status = "Released · supported";
} else {
manipulator.status = "Holding for support";
}
return;
}
// After release, only the empty arm retracts. The shell remains on the pad.
const retractT = smooth(
(time - manipulator.carryEnd) / 1.25
);
const tip = manipulator.retract.getPoint(retractT);
const shapeBlend = smooth(retractT / 0.3);
const control1 = manipulator.carry.v1.clone().lerp(
manipulator.retract.v1,
shapeBlend
);
const control2 = manipulator.carry.v2.clone().lerp(
manipulator.retract.v2,
shapeBlend
);
poseArm(arm, tip, control1, control2);
manipulator.status = "Released · arm returning";
}
function updateManipulatorUI(manipulator, readout, gate) {
readout.textContent = manipulator.status;
gate.classList.remove("transfer", "supported");
if (manipulator.released) {
gate.classList.add("supported");
} else if (
manipulator.status === "Transferring" ||
manipulator.status === "Holding for support"
) {
gate.classList.add("transfer");
}
}
function resetSequence() {
elapsed = 0;
[leftManipulator, rightManipulator].forEach((manipulator) => {
manipulator.released = false;
manipulator.releaseFlash = 0;
manipulator.contactError = 0;
manipulator.status = "Waiting";
manipulator.shellGroup.position.copy(
manipulator.reach.v3
.clone()
.sub(
manipulator.grip
.clone()
.applyQuaternion(manipulator.initQuat)
)
);
manipulator.shellGroup.quaternion.copy(manipulator.initQuat);
});
}
ui.replay.addEventListener("click", resetSequence);
ui.pause.addEventListener("click", () => {
paused = !paused;
ui.pause.textContent = paused ? "Resume" : "Pause";
});
ui.showPaths.addEventListener("change", () => {
pathGroup.visible = ui.showPaths.checked;
});
function updateScene(time) {
const bob = Math.sin(time * 2.0) * 0.025;
octopus.position.y = bob;
octopus.rotation.z = Math.sin(time * 0.8) * 0.012;
const blink =
time > 3.0 &&
time < 3.18
? 0.12
: time > 8.6 && time < 8.78
? 0.12
: 1;
eyes.forEach((eye) => {
eye.scale.y = 0.55 * blink;
});
updateIdleArms(time);
updateManipulator(leftManipulator, time);
updateManipulator(rightManipulator, time);
leftManipulator.releaseFlash = Math.max(
0,
leftManipulator.releaseFlash - 0.025
);
rightManipulator.releaseFlash = Math.max(
0,
rightManipulator.releaseFlash - 0.025
);
leftSupport.surfaceMaterial.emissiveIntensity =
0.13 + leftManipulator.releaseFlash * 2.4;
rightSupport.surfaceMaterial.emissiveIntensity =
0.13 + rightManipulator.releaseFlash * 2.4;
leftSupport.ring.material.opacity =
0.75 + leftManipulator.releaseFlash * 0.25;
rightSupport.ring.material.opacity =
0.75 + rightManipulator.releaseFlash * 0.25;
seaweed.forEach((plant) => {
plant.rotation.z =
Math.sin(time * 0.85 + plant.userData.phase) * 0.08;
plant.rotation.x =
Math.cos(time * 0.65 + plant.userData.phase) * 0.035;
});
const positions = bubbleGeometry.attributes.position;
for (let i = 0; i < bubbleCount; i++) {
const y =
((bubbleBaseY[i] + time * bubbleSpeed[i]) % 6.5) + 0.1;
positions.setY(i, y);
positions.setX(
i,
positions.getX(i) +
Math.sin(time * 0.7 + bubblePhase[i]) * 0.001
);
}
positions.needsUpdate = true;
updateManipulatorUI(
leftManipulator,
ui.leftReadout,
ui.gateLeft
);
updateManipulatorUI(
rightManipulator,
ui.rightReadout,
ui.gateRight
);
let phase = 0;
let phaseText = "1 · Reaching for the shells";
if (time >= 3.7 && time < 6.95) {
phase = 1;
phaseText = "2 · Transferring along separate prescribed paths";
} else if (time >= 6.95) {
phase = 2;
phaseText =
leftManipulator.released && rightManipulator.released
? "3 · Shelter secured — shells supported"
: "3 · Verifying support contact";
} else if (time >= 2.9) {
phaseText = "1 · Reaching complete — transport begins";
}
ui.phaseLabel.textContent = phaseText;
ui.clock.textContent = `${Math.min(time, DURATION).toFixed(1)} / ${DURATION.toFixed(1)} s`;
ui.stepReach.className = "step";
ui.stepTransfer.className = "step";
ui.stepRelease.className = "step";
if (phase === 0) {
ui.stepReach.classList.add("active");
} else if (phase === 1) {
ui.stepReach.classList.add("done");
ui.stepTransfer.classList.add("active");
} else {
ui.stepReach.classList.add("done");
ui.stepTransfer.classList.add("done");
ui.stepRelease.classList.add("active");
}
}
function onResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
if (!paused) {
elapsed = Math.min(elapsed + delta, DURATION + 2);
}
updateScene(elapsed);
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```