Prompt specification
Build or customize the Three.js 3D scene "Turtle nest chamber beach section" 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: Turtle nest chamber beach section
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/turtle-nest-chamber-beach-section-x0709
Scene Description Prompt:
Make a standalone HTML scene with Three.js from cdnjs that depicts sea-turtle nesting. Model a sandy beach cutaway with a rounded nest chamber and eggs beneath the surface; show a turtle silhouette nearby while keeping the chamber geometry clearly schematic. Stylized solid forms.
Working Three.js Starter (turtle-nest-chamber-beach-section-x0709):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sea Turtle Nesting — Beach Cutaway</title>
<style>
:root {
color-scheme: light;
--ink: #183b38;
--paper: rgba(255, 250, 237, 0.84);
--line: rgba(24, 59, 56, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
color: var(--ink);
background:
radial-gradient(circle at 72% 18%, rgba(255, 255, 255, 0.82), transparent 27%),
linear-gradient(180deg, #d9eeec 0%, #e8efe2 47%, #f2dfbb 100%);
}
#scene {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
outline: none;
}
.hud {
position: fixed;
z-index: 2;
top: 22px;
left: 22px;
width: min(300px, calc(100vw - 44px));
padding: 17px 18px 15px;
border: 1px solid var(--line);
border-radius: 17px;
background: var(--paper);
box-shadow: 0 14px 40px rgba(72, 80, 61, 0.12);
backdrop-filter: blur(12px);
pointer-events: none;
}
.eyebrow {
margin: 0 0 6px;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
opacity: 0.57;
}
h1 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 34px);
font-weight: 500;
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 14px;
font-size: 13px;
line-height: 1.45;
opacity: 0.72;
}
.legend {
display: grid;
gap: 7px;
padding-top: 12px;
border-top: 1px solid var(--line);
font-size: 12px;
}
.legend-item {
display: flex;
align-items: center;
gap: 9px;
}
.swatch {
width: 12px;
height: 12px;
flex: 0 0 auto;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}
.swatch.turtle {
background: #214d46;
}
.swatch.eggs {
background: #fff0cb;
}
.swatch.chamber {
background: #93603d;
}
.controls {
position: fixed;
z-index: 2;
right: 22px;
bottom: 22px;
display: flex;
align-items: center;
gap: 12px;
padding: 9px 11px 9px 14px;
border: 1px solid var(--line);
border-radius: 999px;
background: var(--paper);
box-shadow: 0 10px 30px rgba(72, 80, 61, 0.11);
backdrop-filter: blur(12px);
font-size: 11px;
letter-spacing: 0.015em;
}
.controls span {
white-space: nowrap;
opacity: 0.72;
}
#reset {
appearance: none;
border: 0;
border-radius: 999px;
padding: 8px 12px;
color: #f8f4e8;
background: #244d47;
font: inherit;
font-weight: 700;
cursor: pointer;
transition: transform 150ms ease, background 150ms ease;
}
#reset:hover {
background: #35645c;
transform: translateY(-1px);
}
#reset:active {
transform: translateY(0);
}
@media (max-width: 700px) {
.hud {
top: 12px;
left: 12px;
width: min(260px, calc(100vw - 24px));
padding: 13px 14px;
}
.subtitle {
display: none;
}
.legend {
margin-top: 11px;
}
.controls {
right: 12px;
bottom: 12px;
}
.controls span {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive three-dimensional sea turtle nesting cutaway"></main>
<section class="hud" aria-hidden="true">
<p class="eyebrow">Coastal field study</p>
<h1>Sea-turtle nesting</h1>
<p class="subtitle">
A stylized beach cutaway showing an adult female above a rounded
underground chamber and a clutch of eggs.
</p>
<div class="legend">
<div class="legend-item">
<span class="swatch turtle"></span>
<span>Adult turtle silhouette</span>
</div>
<div class="legend-item">
<span class="swatch eggs"></span>
<span>Nest eggs beneath the surface</span>
</div>
<div class="legend-item">
<span class="swatch chamber"></span>
<span>Schematic rounded chamber</span>
</div>
</div>
</section>
<div class="controls" aria-hidden="true">
<span>Drag to orbit · Scroll to zoom · Right-drag to pan</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, camera, lighting
// ------------------------------------------------------------
const host = document.querySelector("#scene");
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.setClearColor(0x000000, 0);
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",
"Orbitable cutaway of a sea turtle nesting on a sandy beach"
);
host.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xd9ece8, 17, 36);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
70
);
const hemisphere = new THREE.HemisphereLight(
0xf5ffff,
0xb78353,
2.25
);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff0cf, 3.1);
sun.position.set(-4.5, 10, 7.5);
sun.target.position.set(0.5, -0.5, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -10;
sun.shadow.camera.right = 10;
sun.shadow.camera.top = 9;
sun.shadow.camera.bottom = -8;
sun.shadow.camera.near = 0.5;
sun.shadow.camera.far = 30;
sun.shadow.bias = -0.00035;
sun.shadow.normalBias = 0.025;
scene.add(sun, sun.target);
const coolFill = new THREE.DirectionalLight(0x8fcac8, 1.05);
coolFill.position.set(8, 4, -7);
scene.add(coolFill);
// ------------------------------------------------------------
// Shared materials
// ------------------------------------------------------------
const materials = {
sandTop: new THREE.MeshStandardMaterial({
color: 0xe8c582,
roughness: 0.96
}),
sandWall: new THREE.MeshStandardMaterial({
color: 0xd5a45f,
roughness: 1
}),
sandDark: new THREE.MeshStandardMaterial({
color: 0xb87943,
roughness: 1
}),
sandStrata: new THREE.MeshStandardMaterial({
color: 0xb9824c,
roughness: 1
}),
chamber: new THREE.MeshStandardMaterial({
color: 0x865638,
roughness: 1,
side: THREE.BackSide
}),
nestFloor: new THREE.MeshStandardMaterial({
color: 0x9d6a40,
roughness: 1
}),
egg: new THREE.MeshStandardMaterial({
color: 0xffefc8,
roughness: 0.78
}),
eggWarm: new THREE.MeshStandardMaterial({
color: 0xf3dfb5,
roughness: 0.82
}),
turtle: new THREE.MeshStandardMaterial({
color: 0x214d46,
roughness: 0.92,
flatShading: true
}),
turtleShell: new THREE.MeshStandardMaterial({
color: 0x173e39,
roughness: 0.95,
flatShading: true
}),
water: new THREE.MeshStandardMaterial({
color: 0x4ca7aa,
roughness: 0.52,
metalness: 0.02
}),
grass: new THREE.MeshStandardMaterial({
color: 0x577b4f,
roughness: 1,
flatShading: true
}),
pebble: new THREE.MeshStandardMaterial({
color: 0x9b805d,
roughness: 1,
flatShading: true
})
};
// ------------------------------------------------------------
// Geometry helpers
// ------------------------------------------------------------
function addRoundedRectangle(
path,
width,
height,
radius,
centerX = 0,
centerY = 0,
clockwise = false
) {
const r = Math.min(radius, width * 0.5, height * 0.5);
const corners = [
[ width * 0.5 - r, -height * 0.5 + r, -Math.PI * 0.5, 0 ],
[ width * 0.5 - r, height * 0.5 - r, 0, Math.PI * 0.5 ],
[-width * 0.5 + r, height * 0.5 - r, Math.PI * 0.5, Math.PI ],
[-width * 0.5 + r, -height * 0.5 + r, Math.PI, Math.PI * 1.5 ]
];
const points = [];
const segments = 8;
for (const [cx, cy, start, end] of corners) {
for (let i = 0; i <= segments; i++) {
const angle = start + (end - start) * (i / segments);
points.push(
new THREE.Vector2(
centerX + cx + Math.cos(angle) * r,
centerY + cy + Math.sin(angle) * r
)
);
}
}
if (clockwise) points.reverse();
path.moveTo(points[0].x, points[0].y);
for (let i = 1; i < points.length; i++) {
path.lineTo(points[i].x, points[i].y);
}
path.closePath();
return path;
}
function mesh(geometry, material, cast = true, receive = true) {
const object = new THREE.Mesh(geometry, material);
object.castShadow = cast;
object.receiveShadow = receive;
return object;
}
// ------------------------------------------------------------
// Sand cutaway: floor, walls, top slab
// ------------------------------------------------------------
const beach = new THREE.Group();
scene.add(beach);
const base = mesh(
new THREE.BoxGeometry(9.4, 0.42, 5.4),
materials.sandWall
);
base.position.set(0, -2.06, 0);
beach.add(base);
const topSlab = mesh(
new THREE.BoxGeometry(9.4, 0.42, 5.35),
materials.sandTop
);
topSlab.position.set(0, 1.14, -0.02);
beach.add(topSlab);
const leftWall = mesh(
new THREE.BoxGeometry(0.36, 3.2, 5.1),
materials.sandWall
);
leftWall.position.set(-4.52, -0.25, -0.08);
beach.add(leftWall);
const rightWall = mesh(
new THREE.BoxGeometry(0.36, 3.2, 5.1),
materials.sandWall
);
rightWall.position.set(4.52, -0.25, -0.08);
beach.add(rightWall);
const backWall = mesh(
new THREE.BoxGeometry(9.4, 3.2, 0.36),
materials.sandWall
);
backWall.position.set(0, -0.25, -2.45);
beach.add(backWall);
// Front cutaway wall with a genuinely open rounded hole.
const wallShape = new THREE.Shape();
addRoundedRectangle(
wallShape,
9.2,
3.2,
0.16,
0,
-0.25,
false
);
const chamberOpening = new THREE.Path();
addRoundedRectangle(
chamberOpening,
4.55,
2.25,
0.72,
0.75,
-0.43,
true
);
wallShape.holes.push(chamberOpening);
const frontWall = mesh(
new THREE.ExtrudeGeometry(wallShape, {
depth: 0.32,
bevelEnabled: false,
curveSegments: 12
}),
materials.sandWall
);
frontWall.position.z = 2.25;
beach.add(frontWall);
// Raised schematic collar around the cutaway opening.
const collarShape = new THREE.Shape();
addRoundedRectangle(
collarShape,
4.98,
2.68,
0.91,
0.75,
-0.43,
false
);
const collarOpening = new THREE.Path();
addRoundedRectangle(
collarOpening,
4.55,
2.25,
0.72,
0.75,
-0.43,
true
);
collarShape.holes.push(collarOpening);
const collar = mesh(
new THREE.ExtrudeGeometry(collarShape, {
depth: 0.09,
bevelEnabled: false,
curveSegments: 12
}),
materials.sandTop
);
collar.position.z = 2.57;
beach.add(collar);
// Rounded chamber interior. Back faces produce a clean schematic bowl.
const chamber = mesh(
new THREE.SphereGeometry(1, 40, 28),
materials.chamber,
false,
true
);
chamber.position.set(0.75, -0.43, 0.12);
chamber.scale.set(2.62, 1.46, 1.88);
beach.add(chamber);
const nestFloor = mesh(
new THREE.SphereGeometry(1, 28, 18),
materials.nestFloor
);
nestFloor.position.set(0.75, -1.27, 1.28);
nestFloor.scale.set(1.78, 0.13, 0.67);
beach.add(nestFloor);
// Thin strata on the visible right-hand cut face.
for (const y of [-1.15, -0.15, 0.72]) {
const strata = mesh(
new THREE.BoxGeometry(0.025, 0.045, 4.82),
materials.sandStrata,
false,
true
);
strata.position.set(4.705, y, -0.08);
beach.add(strata);
}
// ------------------------------------------------------------
// Eggs
// ------------------------------------------------------------
const eggLayout = [
[-0.45, -0.84, 1.49, -0.20],
[ 0.05, -0.80, 1.56, 0.12],
[ 0.56, -0.85, 1.47, -0.10],
[ 1.08, -0.90, 1.58, 0.18],
[ 1.55, -0.96, 1.48, -0.17],
[-0.12, -1.06, 1.37, 0.13],
[ 0.48, -1.08, 1.39, -0.08],
[ 1.00, -1.09, 1.35, 0.20],
[ 1.55, -1.13, 1.34, -0.14]
];
const eggs = new THREE.Group();
beach.add(eggs);
eggLayout.forEach(([x, y, z, tilt], index) => {
const egg = mesh(
new THREE.SphereGeometry(1, 22, 16),
index % 3 === 0 ? materials.eggWarm : materials.egg
);
egg.position.set(x, y, z);
egg.scale.set(0.215, 0.295, 0.215);
egg.rotation.set(0.10 * tilt, tilt * 0.7, tilt);
eggs.add(egg);
});
// ------------------------------------------------------------
// Adult turtle silhouette
// ------------------------------------------------------------
const turtle = new THREE.Group();
turtle.position.set(-2.62, 1.39, -0.28);
turtle.rotation.y = -0.08;
beach.add(turtle);
const shell = mesh(
new THREE.IcosahedronGeometry(1, 2),
materials.turtleShell
);
shell.position.y = 0.35;
shell.scale.set(0.67, 0.35, 0.87);
turtle.add(shell);
const body = mesh(
new THREE.SphereGeometry(1, 24, 14),
materials.turtle
);
body.position.set(-0.02, 0.16, 0);
body.scale.set(0.60, 0.24, 0.80);
turtle.add(body);
const neck = mesh(
new THREE.SphereGeometry(1, 20, 12),
materials.turtle
);
neck.position.set(0.70, 0.16, 0);
neck.scale.set(0.38, 0.17, 0.23);
turtle.add(neck);
const head = mesh(
new THREE.IcosahedronGeometry(1, 2),
materials.turtle
);
head.position.set(1.02, 0.19, 0);
head.scale.set(0.37, 0.20, 0.24);
turtle.add(head);
function addFlipper(x, z, sx, sy, sz, rotationY) {
const flipper = mesh(
new THREE.IcosahedronGeometry(1, 2),
materials.turtle
);
flipper.position.set(x, 0.055, z);
flipper.scale.set(sx, sy, sz);
flipper.rotation.y = rotationY;
turtle.add(flipper);
}
addFlipper(0.28, 0.61, 0.75, 0.075, 0.27, -0.56);
addFlipper(0.28, -0.61, 0.75, 0.075, 0.27, 0.56);
addFlipper(-0.52, 0.43, 0.48, 0.065, 0.20, -1.05);
addFlipper(-0.52,-0.43, 0.48, 0.065, 0.20, 1.05);
const tail = mesh(
new THREE.ConeGeometry(0.16, 0.48, 7),
materials.turtle
);
tail.position.set(-0.84, 0.10, 0);
tail.rotation.z = Math.PI * 0.5;
turtle.add(tail);
// Restrained shell plates keep the turtle readable as a silhouette.
const platePositions = [
[ 0.00, 0.67, 0.00],
[ 0.29, 0.61, 0.24],
[ 0.29, 0.61, -0.24],
[-0.29, 0.61, 0.24],
[-0.29, 0.61, -0.24]
];
for (const [x, y, z] of platePositions) {
const plate = mesh(
new THREE.IcosahedronGeometry(1, 1),
materials.turtle
);
plate.position.set(x, y, z);
plate.scale.set(0.20, 0.055, 0.17);
plate.rotation.y = Math.atan2(z, x);
turtle.add(plate);
}
// ------------------------------------------------------------
// Surface nest entrance and beach details
// ------------------------------------------------------------
const entrance = mesh(
new THREE.CircleGeometry(1, 48),
materials.sandDark,
false,
true
);
entrance.rotation.x = -Math.PI * 0.5;
entrance.scale.set(0.84, 0.48, 1);
entrance.position.set(0.75, 1.365, -0.12);
beach.add(entrance);
const entranceRim = mesh(
new THREE.TorusGeometry(1, 0.075, 8, 48),
materials.sandTop
);
entranceRim.rotation.x = Math.PI * 0.5;
entranceRim.scale.set(0.91, 0.54, 1);
entranceRim.position.set(0.75, 1.39, -0.12);
beach.add(entranceRim);
// Low, rounded dunes.
const duneData = [
[-2.65, -1.75, 1.50, 0.25, 0.66],
[ 2.70, -1.70, 1.72, 0.23, 0.75],
[ 3.75, 0.95, 1.02, 0.18, 0.48]
];
for (const [x, z, sx, sy, sz] of duneData) {
const dune = mesh(
new THREE.SphereGeometry(1, 28, 16),
materials.sandTop
);
dune.position.set(x, 1.30, z);
dune.scale.set(sx, sy, sz);
beach.add(dune);
}
// Scattered, stylized pebbles.
const pebbleLocations = [
[-4.05, 1.10], [-3.78, -0.55], [-1.55, 1.42],
[-0.85, -1.58], [ 0.05, 1.72], [ 2.55, 1.38],
[ 3.58, 0.10], [ 4.08, -0.95], [ 1.92, -1.73]
];
pebbleLocations.forEach(([x, z], index) => {
const pebble = mesh(
new THREE.DodecahedronGeometry(1, 0),
materials.pebble
);
const size = 0.075 + (index % 3) * 0.025;
pebble.position.set(x, 1.39 + size * 0.25, z);
pebble.scale.set(size * 1.25, size * 0.55, size);
pebble.rotation.set(index * 0.7, index * 1.1, index * 0.4);
beach.add(pebble);
});
// Sparse beach grass at the rear edges.
const grassPositions = [
[-4.12, -1.98], [-4.30, -1.76], [-3.96, -2.08],
[ 3.82, -2.02], [ 4.04, -1.82], [ 3.62, -2.08]
];
for (const [x, z] of grassPositions) {
const blade = mesh(
new THREE.ConeGeometry(0.055, 0.68, 5),
materials.grass
);
blade.position.set(x, 1.62, z);
blade.rotation.z = (x % 0.3) * 0.4;
beach.add(blade);
}
// ------------------------------------------------------------
// Sea and stylized wave marks
// ------------------------------------------------------------
const ocean = mesh(
new THREE.PlaneGeometry(19, 7.5),
materials.water,
false,
false
);
ocean.rotation.x = -Math.PI * 0.5;
ocean.position.set(0, 1.19, -6.48);
scene.add(ocean);
const waves = [];
const waveMaterial = new THREE.MeshBasicMaterial({
color: 0xe4f5ed,
transparent: true,
opacity: 0.56,
depthWrite: false
});
for (let row = 0; row < 6; row++) {
const points = [];
const baseZ = -3.12 - row * 0.68;
for (let i = 0; i <= 10; i++) {
points.push(
new THREE.Vector3(
-8.2 + i * 1.64,
0,
baseZ + Math.sin(i * 1.35 + row * 0.8) * 0.10
)
);
}
const curve = new THREE.CatmullRomCurve3(points);
const wave = new THREE.Mesh(
new THREE.TubeGeometry(curve, 70, 0.027, 5, false),
waveMaterial.clone()
);
wave.position.y = 1.235;
wave.userData.phase = row * 0.63;
scene.add(wave);
waves.push(wave);
}
// A transparent shadow catcher beneath the diorama.
const shadowFloor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 40),
new THREE.ShadowMaterial({
color: 0x65543e,
opacity: 0.17
})
);
shadowFloor.rotation.x = -Math.PI * 0.5;
shadowFloor.position.y = -2.28;
shadowFloor.receiveShadow = true;
scene.add(shadowFloor);
// ------------------------------------------------------------
// Direct camera controls: orbit, zoom, pan, pinch, reset
// ------------------------------------------------------------
const defaultView = {
theta: 0.53,
phi: 1.16,
radius: 14.2,
target: new THREE.Vector3(0, -0.22, 0)
};
const orbit = {
theta: defaultView.theta,
phi: defaultView.phi,
radius: defaultView.radius,
target: defaultView.target.clone()
};
function updateCamera() {
const spherical = new THREE.Spherical(
orbit.radius,
orbit.phi,
orbit.theta
);
camera.position.copy(orbit.target).add(
new THREE.Vector3().setFromSpherical(spherical)
);
camera.lookAt(orbit.target);
camera.updateMatrixWorld();
}
function resetView() {
orbit.theta = defaultView.theta;
orbit.phi = defaultView.phi;
orbit.radius = defaultView.radius;
orbit.target.copy(defaultView.target);
updateCamera();
}
const activePointers = new Map();
let drag = null;
let previousPinchDistance = 0;
const canvas = renderer.domElement;
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("pointerdown", event => {
canvas.setPointerCapture(event.pointerId);
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size === 1) {
drag = {
x: event.clientX,
y: event.clientY,
pan: event.button === 2 || event.shiftKey
};
} else if (activePointers.size === 2) {
const points = [...activePointers.values()];
previousPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
canvas.addEventListener("pointermove", event => {
if (!activePointers.has(event.pointerId)) return;
activePointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
if (activePointers.size >= 2) {
const points = [...activePointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (previousPinchDistance > 0 && distance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * previousPinchDistance / distance,
7.5,
23
);
updateCamera();
}
previousPinchDistance = distance;
return;
}
if (!drag) return;
const dx = event.clientX - drag.x;
const dy = event.clientY - drag.y;
drag.x = event.clientX;
drag.y = event.clientY;
if (drag.pan) {
const right = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 0);
const up = new THREE.Vector3()
.setFromMatrixColumn(camera.matrix, 1);
const panScale = orbit.radius * 0.00125;
orbit.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(up, dy * panScale);
orbit.target.x = THREE.MathUtils.clamp(orbit.target.x, -2.5, 2.5);
orbit.target.y = THREE.MathUtils.clamp(orbit.target.y, -1.1, 1.2);
orbit.target.z = THREE.MathUtils.clamp(orbit.target.z, -1.5, 1.5);
} else {
orbit.theta -= dx * 0.0052;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi + dy * 0.0045,
0.42,
1.48
);
}
updateCamera();
});
function endPointer(event) {
activePointers.delete(event.pointerId);
previousPinchDistance = 0;
if (activePointers.size === 1) {
const remaining = [...activePointers.values()][0];
drag = {
x: remaining.x,
y: remaining.y,
pan: false
};
} else if (activePointers.size === 0) {
drag = null;
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7.5,
23
);
updateCamera();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
// ------------------------------------------------------------
// Resize and render loop
// ------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateCamera();
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const time = clock.getElapsedTime();
for (const wave of waves) {
wave.position.y =
1.235 + Math.sin(time * 0.72 + wave.userData.phase) * 0.012;
wave.material.opacity =
0.49 + Math.sin(time * 0.55 + wave.userData.phase) * 0.07;
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```