Prompt specification
Build or customize the Three.js 3D scene "Tadpole and frog body comparison" 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: Tadpole and frog body comparison
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/tadpole-and-frog-body-comparison-x0689
Scene Description Prompt:
Compare a stylized tadpole and young frog as separate models, highlighting tails and limbs. Three.js from cdnjs, one HTML file.
Working Three.js Starter (tadpole-and-frog-body-comparison-x0689):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tadpole to Froglet — Three.js Comparison</title>
<style>
:root {
--bg: #07151d;
--panel: rgba(10, 29, 38, 0.78);
--panel-solid: #0b202a;
--text: #edf9f7;
--muted: #91abb0;
--cyan: #59e4e8;
--amber: #ffbd59;
--green: #83df79;
--line: rgba(135, 226, 226, 0.42);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas.dragging {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 10;
top: 22px;
left: 26px;
right: 26px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
pointer-events: none;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(28px, 4vw, 52px);
font-weight: 760;
letter-spacing: -0.055em;
line-height: 0.98;
text-shadow: 0 5px 24px rgba(0, 0, 0, 0.35);
}
.subtitle {
max-width: 520px;
margin: 11px 0 0;
color: var(--muted);
font-size: 14px;
line-height: 1.5;
}
.tools {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
align-items: center;
gap: 9px;
pointer-events: auto;
}
.legend,
.tool-button {
border: 1px solid rgba(145, 204, 208, 0.18);
background: var(--panel);
color: var(--text);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
backdrop-filter: blur(12px);
}
.legend {
display: flex;
align-items: center;
gap: 15px;
padding: 10px 13px;
border-radius: 999px;
color: #c7d9da;
font-size: 12px;
}
.legend span {
display: inline-flex;
align-items: center;
gap: 7px;
white-space: nowrap;
}
.dot {
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
}
.dot.cyan {
background: var(--cyan);
box-shadow: 0 0 12px rgba(89, 228, 232, 0.8);
}
.dot.amber {
background: var(--amber);
box-shadow: 0 0 12px rgba(255, 189, 89, 0.7);
}
.tool-button {
min-height: 36px;
padding: 8px 12px;
border-radius: 999px;
cursor: pointer;
font-size: 12px;
transition:
background 160ms ease,
border-color 160ms ease,
transform 160ms ease;
}
.tool-button:hover {
background: rgba(18, 49, 59, 0.94);
border-color: rgba(89, 228, 232, 0.4);
transform: translateY(-1px);
}
#labels {
position: fixed;
z-index: 5;
inset: 0;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.hidden {
opacity: 0;
}
#leaders {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
}
.leader {
fill: none;
stroke-width: 1.4;
stroke-dasharray: 4 5;
opacity: 0.75;
}
.anchor-dot {
stroke-width: 1.5;
fill: rgba(7, 21, 29, 0.82);
}
.callout {
position: absolute;
width: 190px;
padding: 11px 13px 12px;
border: 1px solid rgba(153, 214, 216, 0.18);
border-left: 3px solid var(--accent);
border-radius: 10px;
background: rgba(8, 28, 37, 0.9);
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
transform: translate(-50%, -100%);
backdrop-filter: blur(10px);
}
.callout strong {
display: block;
color: #f3fffd;
font-size: 13px;
line-height: 1.25;
}
.callout small {
display: block;
margin-top: 4px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.model-label {
position: absolute;
min-width: 175px;
padding: 10px 15px;
border: 1px solid rgba(145, 204, 208, 0.15);
border-radius: 12px;
background: rgba(7, 23, 31, 0.82);
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
text-align: center;
transform: translate(-50%, 8px);
backdrop-filter: blur(10px);
}
.model-label .name {
display: block;
color: var(--accent);
font-size: 14px;
font-weight: 800;
letter-spacing: 0.03em;
}
.model-label .description {
display: block;
margin-top: 3px;
color: #9db6b9;
font-size: 11px;
}
.footer {
position: fixed;
z-index: 10;
left: 50%;
bottom: 19px;
display: flex;
align-items: center;
gap: 9px;
color: rgba(191, 218, 219, 0.67);
font-size: 11px;
letter-spacing: 0.03em;
pointer-events: none;
transform: translateX(-50%);
white-space: nowrap;
}
.footer .mouse {
display: inline-grid;
width: 20px;
height: 27px;
place-items: center;
border: 1px solid rgba(191, 218, 219, 0.38);
border-radius: 9px;
}
@media (max-width: 760px) {
.topbar {
top: 16px;
left: 16px;
right: 16px;
}
.subtitle {
max-width: 270px;
font-size: 12px;
}
.legend {
display: none;
}
.tool-button {
padding: 7px 9px;
font-size: 11px;
}
.callout {
width: 145px;
padding: 8px 9px;
}
.callout small {
display: none;
}
.callout strong {
font-size: 11px;
}
.model-label {
min-width: 138px;
padding: 8px 10px;
}
.model-label .name {
font-size: 12px;
}
.model-label .description {
font-size: 9px;
}
.footer {
bottom: 12px;
}
}
@media (max-width: 480px) {
h1 {
font-size: 29px;
}
.subtitle {
max-width: 220px;
}
.tools {
max-width: 110px;
}
.tool-button {
background: rgba(10, 29, 38, 0.75);
}
}
</style>
</head>
<body>
<div id="scene"></div>
<header class="topbar">
<div>
<div class="eyebrow">Developmental comparison</div>
<h1>From swimmer<br />to hopper</h1>
<p class="subtitle">
Two separate models show how a tadpole’s dominant tail develops into a
froglet with four functional limbs and only a small residual tail.
</p>
</div>
<div class="tools">
<div class="legend" aria-label="Highlight legend">
<span><i class="dot cyan"></i>Tail structures</span>
<span><i class="dot amber"></i>Limbs and buds</span>
</div>
<button class="tool-button" id="toggleLabels" type="button">
Hide labels
</button>
<button class="tool-button" id="resetView" type="button">
Reset view
</button>
</div>
</header>
<div id="labels">
<svg id="leaders" aria-hidden="true">
<line id="leader-tad-tail" class="leader" stroke="#59e4e8"></line>
<circle id="dot-tad-tail" class="anchor-dot" stroke="#59e4e8" r="5"></circle>
<line id="leader-tad-buds" class="leader" stroke="#ffbd59"></line>
<circle id="dot-tad-buds" class="anchor-dot" stroke="#ffbd59" r="5"></circle>
<line id="leader-frog-limbs" class="leader" stroke="#ffbd59"></line>
<circle id="dot-frog-limbs" class="anchor-dot" stroke="#ffbd59" r="5"></circle>
<line id="leader-frog-tail" class="leader" stroke="#59e4e8"></line>
<circle id="dot-frog-tail" class="anchor-dot" stroke="#59e4e8" r="5"></circle>
</svg>
<div
id="callout-tad-tail"
class="callout"
style="--accent: #59e4e8"
>
<strong>Long finned tail</strong>
<small>The tadpole’s main swimming structure</small>
</div>
<div
id="callout-tad-buds"
class="callout"
style="--accent: #ffbd59"
>
<strong>Early hind-limb buds</strong>
<small>The first visible signs of legs</small>
</div>
<div
id="callout-frog-limbs"
class="callout"
style="--accent: #ffbd59"
>
<strong>Four developed limbs</strong>
<small>Forelimbs and folded hind legs</small>
</div>
<div
id="callout-frog-tail"
class="callout"
style="--accent: #59e4e8"
>
<strong>Short residual tail</strong>
<small>Much smaller than the tadpole’s tail</small>
</div>
<div
id="model-tadpole"
class="model-label"
style="--accent: #59e4e8"
>
<span class="name">Tadpole</span>
<span class="description">Tail-led swimmer</span>
</div>
<div
id="model-frog"
class="model-label"
style="--accent: #83df79"
>
<span class="name">Young frog</span>
<span class="description">Four-limbed juvenile</span>
</div>
</div>
<div class="footer">
<span class="mouse">↕</span>
<span>Drag to orbit · Scroll to zoom</span>
</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, and camera
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07151d);
scene.fog = new THREE.Fog(0x07151d, 10, 23);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
50
);
const renderer = new THREE.WebGLRenderer({
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.12;
document.querySelector("#scene").appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xc5f6ff, 0x14242b, 2.2);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xf6fff2, 3.1);
keyLight.position.set(-3.5, 7, 5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -8;
keyLight.shadow.camera.right = 8;
keyLight.shadow.camera.top = 7;
keyLight.shadow.camera.bottom = -4;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 22;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x36dce4, 16, 9, 2);
cyanLight.position.set(-4, 2.5, 3);
scene.add(cyanLight);
const amberLight = new THREE.PointLight(0xffac55, 13, 8, 2);
amberLight.position.set(4, 2.4, 2.5);
scene.add(amberLight);
// -------------------------------------------------------------------------
// Shared geometry and materials
// -------------------------------------------------------------------------
const unitSphere = new THREE.SphereGeometry(1, 32, 20);
const materials = {
tadBody: new THREE.MeshStandardMaterial({
color: 0x55bd72,
roughness: 0.43,
metalness: 0.02
}),
tadHead: new THREE.MeshStandardMaterial({
color: 0x71d17e,
roughness: 0.46,
metalness: 0.01
}),
frogBody: new THREE.MeshStandardMaterial({
color: 0x73c95e,
roughness: 0.5,
metalness: 0.01
}),
frogHead: new THREE.MeshStandardMaterial({
color: 0x8ad86c,
roughness: 0.48,
metalness: 0.01
}),
belly: new THREE.MeshStandardMaterial({
color: 0xe8e99b,
roughness: 0.7
}),
eye: new THREE.MeshStandardMaterial({
color: 0xf4e895,
roughness: 0.24
}),
eyeGreen: new THREE.MeshStandardMaterial({
color: 0xb9df79,
roughness: 0.3
}),
black: new THREE.MeshStandardMaterial({
color: 0x071014,
roughness: 0.28
}),
white: new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.18
}),
tail: new THREE.MeshStandardMaterial({
color: 0x4ee7ea,
emissive: 0x087d89,
emissiveIntensity: 0.55,
roughness: 0.28,
metalness: 0.03,
transparent: true,
opacity: 0.76,
side: THREE.DoubleSide,
depthWrite: false
}),
tailCore: new THREE.MeshStandardMaterial({
color: 0x7cffff,
emissive: 0x0b9daa,
emissiveIntensity: 0.6,
roughness: 0.3,
transparent: true,
opacity: 0.94,
side: THREE.DoubleSide
}),
limb: new THREE.MeshStandardMaterial({
color: 0xffb64f,
emissive: 0x9a3d06,
emissiveIntensity: 0.27,
roughness: 0.46
}),
spot: new THREE.MeshStandardMaterial({
color: 0x347f45,
roughness: 0.7
}),
pedestal: new THREE.MeshStandardMaterial({
color: 0x102d38,
roughness: 0.76,
metalness: 0.08
}),
pedestalTop: new THREE.MeshStandardMaterial({
color: 0x153945,
roughness: 0.62,
metalness: 0.12
}),
floor: new THREE.MeshStandardMaterial({
color: 0x071920,
roughness: 0.94,
metalness: 0.02
})
};
function ellipsoid(parent, position, scale, material) {
const mesh = new THREE.Mesh(unitSphere, material);
mesh.position.set(...position);
mesh.scale.set(...scale);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function segmentBetween(parent, a, b, radiusA, radiusB, material) {
const start = new THREE.Vector3(...a);
const end = new THREE.Vector3(...b);
const direction = end.clone().sub(start);
const length = direction.length();
const geometry = new THREE.CylinderGeometry(
radiusB,
radiusA,
length,
14,
1
);
const mesh = new THREE.Mesh(geometry, material);
mesh.position.copy(start).add(end).multiplyScalar(0.5);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function joint(parent, position, radius, material) {
return ellipsoid(parent, position, [radius, radius, radius], material);
}
function mouthCurve(parent, points, radius = 0.016) {
const curve = new THREE.CatmullRomCurve3(
points.map((point) => new THREE.Vector3(...point))
);
const geometry = new THREE.TubeGeometry(curve, 28, radius, 8, false);
const mesh = new THREE.Mesh(geometry, materials.black);
mesh.castShadow = true;
parent.add(mesh);
return mesh;
}
function addEye(parent, position, scale, irisMaterial = materials.eye) {
ellipsoid(parent, position, scale, irisMaterial);
const [x, y, z] = position;
const pupilDepth = z + scale[2] * 0.78;
ellipsoid(
parent,
[x, y, pupilDepth],
[scale[0] * 0.39, scale[1] * 0.63, scale[2] * 0.48],
materials.black
);
ellipsoid(
parent,
[x - scale[0] * 0.13, y + scale[1] * 0.25, pupilDepth + scale[2] * 0.32],
[scale[0] * 0.11, scale[1] * 0.13, scale[2] * 0.15],
materials.white
);
}
// -------------------------------------------------------------------------
// Animated tail geometry
// -------------------------------------------------------------------------
function makeFin(length, width, zOffset, material) {
const segments = 42;
const positions = new Float32Array((segments + 1) * 2 * 3);
const indices = [];
for (let i = 0; i < segments; i++) {
const a = i * 2;
const b = i * 2 + 1;
const c = (i + 1) * 2;
const d = (i + 1) * 2 + 1;
indices.push(a, b, c, b, d, c);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.BufferAttribute(positions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
geometry.setIndex(indices);
const mesh = new THREE.Mesh(geometry, material);
mesh.castShadow = true;
mesh.frustumCulled = false;
return {
geometry,
mesh,
length,
width,
zOffset,
segments
};
}
function makeTailSystem(length, broadWidth, phase) {
const group = new THREE.Group();
const broad = makeFin(length, broadWidth, 0, materials.tail);
const core = makeFin(length, 0.055, 0.035, materials.tailCore);
group.add(broad.mesh, core.mesh);
const linePositions = new Float32Array((length > 1 ? 43 : 43) * 3);
const lineGeometry = new THREE.BufferGeometry();
lineGeometry.setAttribute(
"position",
new THREE.BufferAttribute(linePositions, 3).setUsage(
THREE.DynamicDrawUsage
)
);
const line = new THREE.Line(
lineGeometry,
new THREE.LineBasicMaterial({
color: 0xa8ffff,
transparent: true,
opacity: 0.85
})
);
line.frustumCulled = false;
group.add(line);
return {
group,
broad,
core,
line,
lineGeometry,
length,
phase
};
}
function updateFin(fin, time, amplitude) {
const array = fin.geometry.attributes.position.array;
const segments = fin.segments;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const wave =
Math.sin(time * 2.35 - t * 4.4 + fin.phase) *
0.13 *
t *
amplitude;
const centerY = -0.15 * t + wave;
const z =
Math.sin(time * 1.55 - t * 3.2 + fin.phase) *
0.025 *
t;
const envelope = Math.pow(Math.sin(Math.PI * t), 0.72);
const halfWidth =
(0.065 + fin.width * envelope) * (1 - 0.18 * t);
const offset = i * 6;
array[offset] = t * fin.length;
array[offset + 1] = centerY + halfWidth;
array[offset + 2] = z + fin.zOffset;
array[offset + 3] = t * fin.length;
array[offset + 4] = centerY - halfWidth;
array[offset + 5] = z + fin.zOffset;
}
fin.geometry.attributes.position.needsUpdate = true;
fin.geometry.computeVertexNormals();
}
function updateTail(system, time, amplitude) {
updateFin(system.broad, time, amplitude);
updateFin(system.core, time, amplitude);
const array = system.lineGeometry.attributes.position.array;
const segments = system.broad.segments;
for (let i = 0; i <= segments; i++) {
const t = i / segments;
const wave =
Math.sin(time * 2.35 - t * 4.4 + system.phase) *
0.13 *
t *
amplitude;
const centerY = -0.15 * t + wave;
const z =
Math.sin(time * 1.55 - t * 3.2 + system.phase) *
0.025 *
t;
array[i * 3] = t * system.length;
array[i * 3 + 1] = centerY;
array[i * 3 + 2] = z + 0.065;
}
system.lineGeometry.attributes.position.needsUpdate = true;
}
// -------------------------------------------------------------------------
// Tadpole model
// -------------------------------------------------------------------------
const tadpole = new THREE.Group();
scene.add(tadpole);
const tadBody = ellipsoid(
tadpole,
[0, 1.22, 0],
[0.7, 0.53, 0.49],
materials.tadBody
);
ellipsoid(
tadpole,
[-0.38, 1.28, 0],
[0.53, 0.46, 0.47],
materials.tadHead
);
ellipsoid(
tadpole,
[-0.14, 0.99, 0.42],
[0.47, 0.25, 0.09],
materials.belly
);
addEye(tadpole, [-0.52, 1.55, 0.38], [0.15, 0.17, 0.085]);
addEye(tadpole, [-0.11, 1.57, 0.41], [0.15, 0.17, 0.085]);
mouthCurve(tadpole, [
[-0.77, 1.2, 0.435],
[-0.58, 1.14, 0.49],
[-0.37, 1.19, 0.495]
]);
// Three subtle gill marks.
for (let i = 0; i < 3; i++) {
const x = -0.02 + i * 0.085;
mouthCurve(
tadpole,
[
[x, 1.39, 0.47],
[x + 0.03, 1.28, 0.49],
[x + 0.02, 1.17, 0.46]
],
0.009
);
}
// Early hind-limb buds, highlighted in amber.
ellipsoid(
tadpole,
[0.47, 1.02, 0.31],
[0.16, 0.105, 0.115],
materials.limb
);
ellipsoid(
tadpole,
[0.48, 1.0, -0.29],
[0.15, 0.1, 0.105],
materials.limb
);
ellipsoid(
tadpole,
[0.59, 0.98, 0.34],
[0.09, 0.065, 0.065],
materials.limb
);
const tadTail = makeTailSystem(1.85, 0.3, 0);
tadTail.group.position.set(0.47, 1.16, 0);
tadpole.add(tadTail.group);
// -------------------------------------------------------------------------
// Young frog model
// -------------------------------------------------------------------------
const frog = new THREE.Group();
scene.add(frog);
const frogBody = ellipsoid(
frog,
[0.12, 1.02, 0],
[0.77, 0.59, 0.59],
materials.frogBody
);
ellipsoid(
frog,
[-0.43, 1.37, 0],
[0.72, 0.47, 0.58],
materials.frogHead
);
ellipsoid(
frog,
[-0.34, 0.94, 0.49],
[0.53, 0.34, 0.1],
materials.belly
);
addEye(
frog,
[-0.59, 1.79, 0.36],
[0.25, 0.26, 0.2],
materials.eyeGreen
);
addEye(
frog,
[-0.04, 1.81, 0.35],
[0.25, 0.26, 0.2],
materials.eyeGreen
);
mouthCurve(
frog,
[
[-0.95, 1.29, 0.48],
[-0.69, 1.21, 0.57],
[-0.39, 1.24, 0.59],
[-0.06, 1.31, 0.53]
],
0.018
);
// Nostrils.
ellipsoid(frog, [-0.67, 1.47, 0.57], [0.035, 0.025, 0.018], materials.black);
ellipsoid(frog, [-0.29, 1.47, 0.58], [0.035, 0.025, 0.018], materials.black);
// Subtle dorsal markings.
const frogSpots = [
[0.29, 1.33, 0.49, 0.075],
[0.03, 1.42, 0.53, 0.06],
[-0.65, 1.56, 0.47, 0.05],
[0.42, 1.13, 0.48, 0.06],
[-0.15, 1.55, 0.53, 0.045]
];
frogSpots.forEach(([x, y, z, size]) => {
ellipsoid(frog, [x, y, z], [size, size * 0.68, 0.018], materials.spot);
});
// Near forelimb.
const nearFore = [
[-0.08, 1.12, 0.39],
[-0.47, 0.78, 0.56],
[-0.77, 0.42, 0.65],
[-0.94, 0.31, 0.67]
];
for (let i = 0; i < nearFore.length - 1; i++) {
segmentBetween(
frog,
nearFore[i],
nearFore[i + 1],
0.12 - i * 0.015,
0.105 - i * 0.015,
materials.limb
);
}
joint(frog, nearFore[1], 0.12, materials.limb);
joint(frog, nearFore[2], 0.1, materials.limb);
joint(frog, nearFore[3], 0.105, materials.limb);
// Front toes.
segmentBetween(frog, [-0.94, 0.31, 0.67], [-1.16, 0.23, 0.75], 0.045, 0.025, materials.limb);
segmentBetween(frog, [-0.94, 0.31, 0.67], [-1.14, 0.22, 0.64], 0.045, 0.025, materials.limb);
segmentBetween(frog, [-0.94, 0.31, 0.67], [-1.08, 0.22, 0.54], 0.045, 0.025, materials.limb);
// Far forelimb.
const farFore = [
[-0.04, 1.1, -0.38],
[-0.39, 0.8, -0.51],
[-0.69, 0.44, -0.57],
[-0.86, 0.34, -0.58]
];
for (let i = 0; i < farFore.length - 1; i++) {
segmentBetween(
frog,
farFore[i],
farFore[i + 1],
0.105 - i * 0.012,
0.09 - i * 0.012,
materials.limb
);
}
joint(frog, farFore[2], 0.095, materials.limb);
joint(frog, farFore[3], 0.095, materials.limb);
// Near folded hind leg.
const nearHind = [
[0.53, 0.98, 0.41],
[0.98, 0.57, 0.61],
[0.58, 0.3, 0.81],
[0.18, 0.19, 0.82]
];
for (let i = 0; i < nearHind.length - 1; i++) {
segmentBetween(
frog,
nearHind[i],
nearHind[i + 1],
0.19 - i * 0.025,
0.17 - i * 0.025,
materials.limb
);
}
joint(frog, nearHind[1], 0.18, materials.limb);
joint(frog, nearHind[2], 0.145, materials.limb);
joint(frog, nearHind[3], 0.12, materials.limb);
// Hind toes.
segmentBetween(frog, [0.18, 0.19, 0.82], [-0.05, 0.12, 0.92], 0.055, 0.028, materials.limb);
segmentBetween(frog, [0.18, 0.19, 0.82], [0.01, 0.11, 0.8], 0.055, 0.028, materials.limb);
segmentBetween(frog, [0.18, 0.19, 0.82], [0.03, 0.12, 0.67], 0.055, 0.028, materials.limb);
// Far folded hind leg.
const farHind = [
[0.53, 0.96, -0.4],
[0.92, 0.59, -0.58],
[0.53, 0.32, -0.77],
[0.12, 0.21, -0.78]
];
for (let i = 0; i < farHind.length - 1; i++) {
segmentBetween(
frog,
farHind[i],
farHind[i + 1],
0.175 - i * 0.023,
0.155 - i * 0.023,
materials.limb
);
}
joint(frog, farHind[1], 0.165, materials.limb);
joint(frog, farHind[2], 0.135, materials.limb);
joint(frog, farHind[3], 0.11, materials.limb);
// Short residual tail.
const frogTail = makeTailSystem(0.93, 0.145, 1.15);
frogTail.group.position.set(0.67, 0.98, -0.02);
frog.add(frogTail.group);
// -------------------------------------------------------------------------
// Display bases and environment
// -------------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(40, 30),
materials.floor
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.055;
floor.receiveShadow = true;
scene.add(floor);
const bases = [];
function makeBase(x, accent) {
const group = new THREE.Group();
group.position.x = x;
const cylinder = new THREE.Mesh(
new THREE.CylinderGeometry(1.07, 1.15, 0.2, 48),
materials.pedestal
);
cylinder.position.y = 0.045;
cylinder.castShadow = true;
cylinder.receiveShadow = true;
group.add(cylinder);
const top = new THREE.Mesh(
new THREE.CylinderGeometry(1.035, 1.035, 0.025, 48),
materials.pedestalTop
);
top.position.y = 0.157;
top.receiveShadow = true;
group.add(top);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.06, 0.014, 8, 96),
new THREE.MeshBasicMaterial({
color: accent,
transparent: true,
opacity: 0.48
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = 0.175;
group.add(ring);
scene.add(group);
bases.push(group);
return group;
}
makeBase(-2.15, 0x59e4e8);
makeBase(2.15, 0x83df79);
// Small floating particles suggest an aquatic environment.
const bubbleCount = 120;
const bubblePositions = new Float32Array(bubbleCount * 3);
for (let i = 0; i < bubbleCount; i++) {
bubblePositions[i * 3] = (Math.random() - 0.5) * 13;
bubblePositions[i * 3 + 1] = Math.random() * 6;
bubblePositions[i * 3 + 2] = (Math.random() - 0.5) * 8 - 1;
}
const bubbleGeometry = new THREE.BufferGeometry();
bubbleGeometry.setAttribute(
"position",
new THREE.BufferAttribute(bubblePositions, 3)
);
const bubbles = new THREE.Points(
bubbleGeometry,
new THREE.PointsMaterial({
color: 0x8fe9ea,
size: 0.025,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
scene.add(bubbles);
// -------------------------------------------------------------------------
// Label anchors
// -------------------------------------------------------------------------
function makeAnchor(parent, position) {
const anchor = new THREE.Object3D();
anchor.position.set(...position);
parent.add(anchor);
return anchor;
}
const anchors = {
tadTail: makeAnchor(tadpole, [2.12, 1.02, 0.02]),
tadBuds: makeAnchor(tadpole, [0.51, 1.02, 0.36]),
frogLimbs: makeAnchor(frog, [0.58, 0.48, 0.78]),
frogTail: makeAnchor(frog, [1.48, 0.89, 0])
};
const labels = {
tadpole: document.querySelector("#model-tadpole"),
frog: document.querySelector("#model-frog")
};
const callouts = [
{
element: document.querySelector("#callout-tad-tail"),
line: document.querySelector("#leader-tad-tail"),
dot: document.querySelector("#dot-tad-tail"),
anchor: anchors.tadTail,
dx: -125,
dy: -76
},
{
element: document.querySelector("#callout-tad-buds"),
line: document.querySelector("#leader-tad-buds"),
dot: document.querySelector("#dot-tad-buds"),
anchor: anchors.tadBuds,
dx: -103,
dy: -89
},
{
element: document.querySelector("#callout-frog-limbs"),
line: document.querySelector("#leader-frog-limbs"),
dot: document.querySelector("#dot-frog-limbs"),
anchor: anchors.frogLimbs,
dx: 104,
dy: 38
},
{
element: document.querySelector("#callout-frog-tail"),
line: document.querySelector("#leader-frog-tail"),
dot: document.querySelector("#dot-frog-tail"),
anchor: anchors.frogTail,
dx: 103,
dy: -77
}
];
const projected = new THREE.Vector3();
function projectObject(object) {
projected.copy(object.getWorldPosition(new THREE.Vector3()));
projected.project(camera);
return {
x: (projected.x * 0.5 + 0.5) * window.innerWidth,
y: (-projected.y * 0.5 + 0.5) * window.innerHeight
};
}
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
const narrow = width < 760;
callouts.forEach((callout) => {
const point = projectObject(callout.anchor);
const desiredX = point.x + (narrow ? callout.dx * 0.54 : callout.dx);
const desiredY = point.y + (narrow ? callout.dy * 0.78 : callout.dy);
const labelX = THREE.MathUtils.clamp(
desiredX,
narrow ? 86 : 110,
width - (narrow ? 86 : 110)
);
const labelY = THREE.MathUtils.clamp(
desiredY,
126,
height - 76
);
callout.element.style.left = `${labelX}px`;
callout.element.style.top = `${labelY}px`;
callout.line.setAttribute("x1", point.x);
callout.line.setAttribute("y1", point.y);
callout.line.setAttribute("x2", labelX);
callout.line.setAttribute("y2", labelY);
callout.dot.setAttribute("cx", point.x);
callout.dot.setAttribute("cy", point.y);
});
const tadLabelPoint = projectObject(
makeTemporaryAnchor(tadpole, [0, 0.15, 0.83])
);
const frogLabelPoint = projectObject(
makeTemporaryAnchor(frog, [0, 0.15, 0.83])
);
labels.tadpole.style.left = `${tadLabelPoint.x}px`;
labels.tadpole.style.top = `${tadLabelPoint.y}px`;
labels.frog.style.left = `${frogLabelPoint.x}px`;
labels.frog.style.top = `${frogLabelPoint.y}px`;
}
// Avoid adding anchor objects every frame.
const tadLabelAnchor = new THREE.Object3D();
tadLabelAnchor.position.set(0, 0.15, 0.83);
tadpole.add(tadLabelAnchor);
const frogLabelAnchor = new THREE.Object3D();
frogLabelAnchor.position.set(0, 0.15, 0.83);
frog.add(frogLabelAnchor);
function makeTemporaryAnchor(parent, position) {
const anchor = new THREE.Object3D();
anchor.position.set(...position);
parent.add(anchor);
parent.remove(anchor);
return anchor;
}
// Replace temporary label calls with the persistent anchors.
updateLabels = function () {
const width = window.innerWidth;
const height = window.innerHeight;
const narrow = width < 760;
callouts.forEach((callout) => {
const point = projectObject(callout.anchor);
const desiredX = point.x + (narrow ? callout.dx * 0.54 : callout.dx);
const desiredY = point.y + (narrow ? callout.dy * 0.78 : callout.dy);
const labelX = THREE.MathUtils.clamp(
desiredX,
narrow ? 86 : 110,
width - (narrow ? 86 : 110)
);
const labelY = THREE.MathUtils.clamp(
desiredY,
126,
height - 76
);
callout.element.style.left = `${labelX}px`;
callout.element.style.top = `${labelY}px`;
callout.line.setAttribute("x1", point.x);
callout.line.setAttribute("y1", point.y);
callout.line.setAttribute("x2", labelX);
callout.line.setAttribute("y2", labelY);
callout.dot.setAttribute("cx", point.x);
callout.dot.setAttribute("cy", point.y);
});
const tadLabelPoint = projectObject(tadLabelAnchor);
const frogLabelPoint = projectObject(frogLabelAnchor);
labels.tadpole.style.left = `${tadLabelPoint.x}px`;
labels.tadpole.style.top = `${tadLabelPoint.y}px`;
labels.frog.style.left = `${frogLabelPoint.x}px`;
labels.frog.style.top = `${frogLabelPoint.y}px`;
};
// -------------------------------------------------------------------------
// Custom orbit controls — no addon imports
// -------------------------------------------------------------------------
const controls = {
yaw: 0,
pitch: 0.3,
distance: 9.4,
target: new THREE.Vector3(0, 1.12, 0),
touched: false
};
function updateCamera() {
const horizontal = Math.cos(controls.pitch) * controls.distance;
camera.position.set(
controls.target.x + Math.sin(controls.yaw) * horizontal,
controls.target.y + Math.sin(controls.pitch) * controls.distance,
controls.target.z + Math.cos(controls.yaw) * horizontal
);
camera.lookAt(controls.target);
}
let dragging = false;
let pointerX = 0;
let pointerY = 0;
const canvas = renderer.domElement;
canvas.addEventListener("pointerdown", (event) => {
dragging = true;
controls.touched = true;
pointerX = event.clientX;
pointerY = event.clientY;
canvas.classList.add("dragging");
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;
controls.yaw -= dx * 0.006;
controls.pitch = THREE.MathUtils.clamp(
controls.pitch + dy * 0.0045,
0.08,
0.72
);
updateCamera();
});
function endDrag(event) {
dragging = false;
canvas.classList.remove("dragging");
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", endDrag);
canvas.addEventListener("pointercancel", endDrag);
canvas.addEventListener("lostpointercapture", () => {
dragging = false;
canvas.classList.remove("dragging");
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
controls.touched = true;
controls.distance = THREE.MathUtils.clamp(
controls.distance + event.deltaY * 0.008,
6.4,
18
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetView);
document.querySelector("#resetView").addEventListener("click", resetView);
const labelsContainer = document.querySelector("#labels");
const toggleLabels = document.querySelector("#toggleLabels");
toggleLabels.addEventListener("click", () => {
const hidden = labelsContainer.classList.toggle("hidden");
toggleLabels.textContent = hidden ? "Show labels" : "Hide labels";
});
function resetView() {
controls.yaw = 0;
controls.pitch = 0.3;
controls.touched = false;
layout();
}
// -------------------------------------------------------------------------
// Responsive layout
// -------------------------------------------------------------------------
function layout() {
const width = window.innerWidth;
const height = window.innerHeight;
const narrow = width < 760;
const spread = narrow ? 1.6 : 2.15;
tadpole.position.set(-spread, 0.16, 0);
frog.position.set(2.15 - (2.15 - spread), 0.16, 0);
// The frog remains on the right while the tadpole moves closer on mobile.
frog.position.x = spread;
bases[0].position.x = -spread;
bases[1].position.x = spread;
camera.aspect = width / height;
camera.fov = narrow ? 58 : 38;
camera.updateProjectionMatrix();
if (!controls.touched) {
controls.distance = narrow ? 14.2 : 9.4;
}
renderer.setSize(width, height);
updateCamera();
}
window.addEventListener("resize", layout);
// -------------------------------------------------------------------------
// Animation
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
updateTail(tadTail, time, 1);
updateTail(frogTail, time * 0.78, 0.38);
// Gentle breathing.
const frogBreath = 1 + Math.sin(time * 1.75) * 0.012;
frogBody.scale.y = 0.59 * frogBreath;
const tadBreath = 1 + Math.sin(time * 1.55 + 1.2) * 0.008;
tadBody.scale.y = 0.53 * tadBreath;
bubbles.rotation.y = Math.sin(time * 0.09) * 0.08;
bubbles.position.y = Math.sin(time * 0.22) * 0.08;
renderer.render(scene, camera);
updateLabels();
}
layout();
animate();
</script>
</body>
</html>
```