Prompt specification
Build or customize the Three.js 3D scene "Bacterial shape comparison mounts" 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: Bacterial shape comparison mounts
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/bacterial-shape-comparison-mounts-x0801
Scene Description Prompt:
Display low-poly spherical, rod-like, and curved bacteria as schematic morphology examples, without inferring species or harmfulness. Three.js from cdnjs, one HTML file.
Working Three.js Starter (bacterial-shape-comparison-mounts-x0801):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bacterial Morphology — Schematic Examples</title>
<style>
:root {
--ink: #173a39;
--muted: #58716f;
--panel: rgba(255, 255, 255, 0.72);
--border: rgba(34, 83, 78, 0.13);
--spherical: #38aa9b;
--rod: #eb786d;
--curved: #7772cf;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
body {
color: var(--ink);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
background:
radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.92), transparent 34%),
radial-gradient(circle at 87% 78%, rgba(190, 222, 224, 0.58), transparent 37%),
linear-gradient(145deg, #f1f8f6 0%, #e7f1f0 52%, #dcebec 100%);
}
body::before {
content: "";
position: fixed;
inset: 0;
z-index: 0;
pointer-events: none;
opacity: 0.28;
background-image: radial-gradient(rgba(29, 78, 73, 0.12) 0.7px, transparent 0.7px);
background-size: 22px 22px;
mask-image: linear-gradient(to bottom, transparent, black 25%, black 75%, transparent);
}
#stage {
position: fixed;
inset: 0;
z-index: 1;
}
#stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
cursor: grab;
}
#stage canvas.dragging {
cursor: grabbing;
}
.hero {
position: fixed;
z-index: 3;
top: 28px;
left: 32px;
right: 32px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 28px;
pointer-events: none;
}
.title-block {
max-width: 650px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
margin: 0 0 10px;
color: #4d716d;
font-size: 0.72rem;
font-weight: 750;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 23px;
height: 2px;
border-radius: 2px;
background: var(--spherical);
}
h1 {
margin: 0;
font-size: clamp(2.25rem, 5vw, 4.65rem);
font-weight: 690;
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 570px;
margin: 15px 0 0;
color: var(--muted);
font-size: clamp(0.88rem, 1.3vw, 1.02rem);
line-height: 1.55;
}
.disclaimer {
display: inline-flex;
align-items: center;
gap: 9px;
margin-top: 14px;
padding: 8px 11px;
border: 1px solid var(--border);
border-radius: 999px;
color: #456662;
background: rgba(255, 255, 255, 0.56);
backdrop-filter: blur(12px);
font-size: 0.75rem;
font-weight: 650;
letter-spacing: 0.01em;
}
.disclaimer::before {
content: "";
flex: 0 0 auto;
width: 8px;
height: 8px;
border: 2px solid #5a8f87;
border-radius: 50%;
box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}
.toolbar {
display: flex;
flex-direction: column;
align-items: flex-end;
gap: 10px;
pointer-events: auto;
}
.tool-row {
display: flex;
gap: 8px;
}
button {
appearance: none;
border: 1px solid var(--border);
border-radius: 12px;
padding: 10px 13px;
color: #315a56;
background: var(--panel);
box-shadow: 0 8px 24px rgba(32, 77, 72, 0.08);
backdrop-filter: blur(14px);
font: inherit;
font-size: 0.76rem;
font-weight: 700;
cursor: pointer;
transition:
transform 150ms ease,
background 150ms ease,
border-color 150ms ease;
}
button:hover {
transform: translateY(-1px);
border-color: rgba(34, 83, 78, 0.26);
background: rgba(255, 255, 255, 0.9);
}
button:active {
transform: translateY(0);
}
button:focus-visible,
canvas:focus-visible {
outline: 3px solid rgba(56, 170, 155, 0.35);
outline-offset: 3px;
}
.control-hint {
color: #5e7774;
font-size: 0.72rem;
font-weight: 620;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
}
.legend {
position: fixed;
z-index: 3;
left: 50%;
bottom: 22px;
display: grid;
grid-template-columns: repeat(3, minmax(160px, 1fr));
gap: 9px;
width: min(650px, calc(100vw - 30px));
transform: translateX(-50%);
pointer-events: none;
}
.legend-card {
display: flex;
align-items: center;
gap: 11px;
min-width: 0;
padding: 12px 13px;
border: 1px solid var(--border);
border-radius: 15px;
background: rgba(255, 255, 255, 0.67);
box-shadow: 0 12px 32px rgba(35, 76, 73, 0.08);
backdrop-filter: blur(16px);
}
.shape-icon {
position: relative;
flex: 0 0 auto;
width: 34px;
height: 34px;
border-radius: 12px;
background: color-mix(in srgb, var(--shape) 15%, white);
}
.shape-icon::before {
content: "";
position: absolute;
inset: 8px;
background: var(--shape);
}
.spherical .shape-icon::before {
border-radius: 50%;
clip-path: polygon(50% 0, 92% 24%, 100% 65%, 67% 100%, 24% 92%, 0 53%, 13% 17%);
}
.rod .shape-icon::before {
width: 23px;
height: 11px;
inset: 11px 5px;
border-radius: 999px;
transform: rotate(-18deg);
}
.curved .shape-icon::before {
inset: 7px;
border: 7px solid var(--shape);
border-right-color: transparent;
border-radius: 50%;
transform: rotate(-28deg);
}
.legend-copy {
min-width: 0;
}
.legend-copy strong {
display: block;
font-size: 0.82rem;
line-height: 1.2;
}
.legend-copy small {
display: block;
margin-top: 2px;
overflow: hidden;
color: var(--muted);
font-size: 0.68rem;
line-height: 1.25;
text-overflow: ellipsis;
white-space: nowrap;
}
.footer-note {
position: fixed;
z-index: 2;
right: 24px;
bottom: 25px;
color: rgba(55, 88, 85, 0.65);
font-size: 0.67rem;
letter-spacing: 0.04em;
pointer-events: none;
}
@media (max-width: 900px) {
.footer-note {
display: none;
}
}
@media (max-width: 700px) {
.hero {
top: 18px;
left: 18px;
right: 18px;
display: block;
}
h1 {
font-size: clamp(2.15rem, 11vw, 3.25rem);
}
.subtitle {
max-width: 92%;
margin-top: 10px;
font-size: 0.83rem;
}
.disclaimer {
margin-top: 10px;
font-size: 0.68rem;
}
.toolbar {
flex-direction: row;
align-items: center;
justify-content: space-between;
margin-top: 12px;
}
.control-hint {
max-width: 145px;
text-align: right;
}
button {
padding: 8px 10px;
font-size: 0.68rem;
}
.legend {
bottom: 12px;
gap: 6px;
width: calc(100vw - 20px);
}
.legend-card {
justify-content: center;
gap: 7px;
padding: 10px 7px;
}
.shape-icon {
width: 29px;
height: 29px;
border-radius: 9px;
}
.legend-copy small {
display: none;
}
.legend-copy strong {
font-size: 0.7rem;
}
}
@media (max-height: 620px) {
.subtitle,
.footer-note {
display: none;
}
.legend-card {
padding-top: 8px;
padding-bottom: 8px;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="hero">
<div class="title-block">
<p class="eyebrow">Microbiology visual guide</p>
<h1>Bacterial morphology</h1>
<p class="subtitle">
Low-poly schematic examples of broadly rounded, elongated, and bent forms.
</p>
<div class="disclaimer">
Schematic geometry only — species and harmfulness are not inferred.
</div>
</div>
<div class="toolbar">
<div class="control-hint">Drag to orbit · Scroll or pinch to zoom</div>
<div class="tool-row">
<button id="resetButton" type="button">Reset view</button>
<button id="motionButton" type="button" aria-pressed="false">Pause motion</button>
</div>
</div>
</header>
<section class="legend" aria-label="Morphology categories">
<article class="legend-card spherical" style="--shape: var(--spherical)">
<span class="shape-icon" aria-hidden="true"></span>
<div class="legend-copy">
<strong>Spherical</strong>
<small>Rounded outline</small>
</div>
</article>
<article class="legend-card rod" style="--shape: var(--rod)">
<span class="shape-icon" aria-hidden="true"></span>
<div class="legend-copy">
<strong>Rod-like</strong>
<small>Elongated, rounded ends</small>
</div>
</article>
<article class="legend-card curved" style="--shape: var(--curved)">
<span class="shape-icon" aria-hidden="true"></span>
<div class="legend-copy">
<strong>Curved</strong>
<small>Bent or hooked profile</small>
</div>
</article>
</section>
<div class="footer-note">Illustrative shape categories · not taxonomic identification</div>
<noscript>This visualization requires JavaScript and WebGL.</noscript>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const stage = document.querySelector("#stage");
const resetButton = document.querySelector("#resetButton");
const motionButton = document.querySelector("#motionButton");
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.08;
renderer.domElement.setAttribute(
"aria-label",
"Interactive low-poly examples of spherical, rod-like, and curved bacterial forms"
);
renderer.domElement.tabIndex = 0;
stage.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.fog = new THREE.Fog(0xe8f2ef, 14, 26);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const cameraTarget = new THREE.Vector3(0, 0.45, 0);
const cameraState = {
theta: 0.08,
phi: 1.14,
radius: 9.2
};
const hemisphere = new THREE.HemisphereLight(0xffffff, 0x72948e, 2.1);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(4.5, 8, 6);
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0xc6eaff, 1.7);
rimLight.position.set(-6, 3.5, -5);
scene.add(rimLight);
const warmLight = new THREE.PointLight(0xffdfc6, 0.75, 18);
warmLight.position.set(3, 2, 5);
scene.add(warmLight);
const specimenGroups = [];
const pedestalGroups = [];
function makeFacetedMesh(geometry, color, edgeColor, edgeThreshold = 24) {
const group = new THREE.Group();
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.5,
metalness: 0.025,
flatShading: true
});
const mesh = new THREE.Mesh(geometry, material);
group.add(mesh);
const edgeMaterial = new THREE.LineBasicMaterial({
color: edgeColor,
transparent: true,
opacity: 0.17,
depthWrite: false
});
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, edgeThreshold),
edgeMaterial
);
edges.scale.setScalar(1.006);
group.add(edges);
return group;
}
function makeCapsuleGeometry(radius, halfLength, radialSegments = 10, capSegments = 4) {
const points = [];
for (let i = 0; i <= capSegments; i++) {
const angle = -Math.PI / 2 + (i / capSegments) * (Math.PI / 2);
points.push(
new THREE.Vector2(
Math.max(0, radius * Math.cos(angle)),
-halfLength + radius * Math.sin(angle)
)
);
}
points.push(new THREE.Vector2(radius, halfLength));
for (let i = 1; i <= capSegments; i++) {
const angle = (i / capSegments) * (Math.PI / 2);
points.push(
new THREE.Vector2(
radius * Math.cos(angle),
halfLength + radius * Math.sin(angle)
)
);
}
return new THREE.LatheGeometry(points, radialSegments);
}
function makePedestal(accentColor) {
const group = new THREE.Group();
const shadowMaterial = new THREE.MeshBasicMaterial({
color: 0x315d58,
transparent: true,
opacity: 0.065,
depthWrite: false
});
const shadow = new THREE.Mesh(new THREE.CircleGeometry(1.08, 40), shadowMaterial);
shadow.rotation.x = -Math.PI / 2;
shadow.scale.set(1, 0.56, 1);
shadow.position.y = -0.695;
group.add(shadow);
const baseMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.78,
metalness: 0,
transparent: true,
opacity: 0.72
});
const base = new THREE.Mesh(
new THREE.CylinderGeometry(1.24, 1.36, 0.13, 12, 1),
baseMaterial
);
base.position.y = -0.69;
group.add(base);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(1.12, 0.015, 6, 64),
new THREE.MeshBasicMaterial({
color: accentColor,
transparent: true,
opacity: 0.62
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.615;
group.add(ring);
return group;
}
// Spherical example
const sphere = makeFacetedMesh(
new THREE.IcosahedronGeometry(0.94, 1),
0x38aa9b,
0x155f58,
18
);
sphere.position.set(-3.15, 1.12, 0);
sphere.rotation.set(0.08, -0.3, 0.12);
scene.add(sphere);
specimenGroups.push({ group: sphere, baseY: 1.12, phase: 0.2 });
// Rod-like example
const rod = makeFacetedMesh(
makeCapsuleGeometry(0.36, 0.7, 10, 4),
0xeb786d,
0x7d302b,
25
);
rod.position.set(0, 1.2, 0);
rod.rotation.set(0.08, 0.18, -1.28);
scene.add(rod);
specimenGroups.push({ group: rod, baseY: 1.2, phase: 2.1 });
// Curved example
const curve = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-1.08, 0.2, 0),
new THREE.Vector3(-0.75, 0.78, 0.04),
new THREE.Vector3(-0.08, 1.02, -0.03),
new THREE.Vector3(0.6, 0.73, 0.04),
new THREE.Vector3(0.79, 0.08, 0),
new THREE.Vector3(0.34, -0.56, -0.04),
new THREE.Vector3(-0.28, -0.68, 0)
],
false,
"catmullrom",
0.5
);
const curved = makeFacetedMesh(
new THREE.TubeGeometry(curve, 32, 0.34, 7, false),
0x7772cf,
0x38336f,
23
);
curved.position.set(3.15, 1.13, 0);
curved.rotation.set(0.05, -0.12, -0.08);
scene.add(curved);
specimenGroups.push({ group: curved, baseY: 1.13, phase: 4.3 });
// Individual display pedestals
const accentColors = [0x38aa9b, 0xeb786d, 0x7772cf];
for (let i = 0; i < 3; i++) {
const pedestal = makePedestal(accentColors[i]);
scene.add(pedestal);
pedestalGroups.push(pedestal);
}
const reducedMotion = window.matchMedia(
"(prefers-reduced-motion: reduce)"
).matches;
let motionEnabled = !reducedMotion;
let narrowLayout = window.innerWidth <= 700;
function baseRadius() {
return narrowLayout ? 12.6 : 9.2;
}
function updateMotionButton() {
motionButton.textContent = motionEnabled ? "Pause motion" : "Play motion";
motionButton.setAttribute("aria-pressed", String(!motionEnabled));
}
function layoutScene() {
narrowLayout = window.innerWidth <= 700;
const spacing = narrowLayout ? 1.95 : 3.15;
const specimenScale = narrowLayout ? 0.78 : 1;
const pedestalScale = narrowLayout ? 0.78 : 1;
specimenGroups.forEach((item, index) => {
item.group.position.x = (index - 1) * spacing;
item.group.scale.setScalar(specimenScale);
});
pedestalGroups.forEach((pedestal, index) => {
pedestal.position.x = (index - 1) * spacing;
pedestal.scale.setScalar(pedestalScale);
});
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
cameraState.radius = baseRadius();
updateCamera();
}
function updateCamera() {
const spherical = new THREE.Spherical(
cameraState.radius,
cameraState.phi,
cameraState.theta
);
camera.position.setFromSpherical(spherical).add(cameraTarget);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraState.theta = 0.08;
cameraState.phi = 1.14;
cameraState.radius = baseRadius();
updateCamera();
}
resetButton.addEventListener("click", resetCamera);
motionButton.addEventListener("click", () => {
motionEnabled = !motionEnabled;
updateMotionButton();
});
updateMotionButton();
layoutScene();
// Custom camera controls implemented without addons.
const pointers = new Map();
let previousPinchDistance = 0;
const canvas = renderer.domElement;
function pointerDistance() {
const values = [...pointers.values()];
if (values.length < 2) return 0;
return Math.hypot(
values[0].x - values[1].x,
values[0].y - values[1].y
);
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.pointerType === "mouse") return;
canvas.setPointerCapture(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
previousPinchDistance = pointerDistance();
canvas.classList.add("dragging");
});
canvas.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const previous = pointers.get(event.pointerId);
pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
if (pointers.size === 1) {
const dx = event.clientX - previous.x;
const dy = event.clientY - previous.y;
cameraState.theta -= dx * 0.006;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.005,
0.55,
1.52
);
updateCamera();
} else if (pointers.size === 2) {
const distance = pointerDistance();
if (previousPinchDistance > 0 && distance > 0) {
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius * (previousPinchDistance / distance),
7,
17
);
updateCamera();
}
previousPinchDistance = distance;
}
});
function endPointer(event) {
pointers.delete(event.pointerId);
previousPinchDistance = pointerDistance();
if (pointers.size === 0) {
canvas.classList.remove("dragging");
}
}
canvas.addEventListener("pointerup", endPointer);
canvas.addEventListener("pointercancel", endPointer);
canvas.addEventListener("lostpointercapture", endPointer);
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
7,
17
);
updateCamera();
},
{ passive: false }
);
canvas.addEventListener("dblclick", resetCamera);
canvas.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
cameraState.theta += 0.09;
break;
case "ArrowRight":
cameraState.theta -= 0.09;
break;
case "ArrowUp":
cameraState.phi = Math.max(0.55, cameraState.phi - 0.07);
break;
case "ArrowDown":
cameraState.phi = Math.min(1.52, cameraState.phi + 0.07);
break;
case "+":
case "=":
cameraState.radius = Math.max(7, cameraState.radius - 0.6);
break;
case "-":
case "_":
cameraState.radius = Math.min(17, cameraState.radius + 0.6);
break;
case "Home":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
window.addEventListener("resize", () => {
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
layoutScene();
});
const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (motionEnabled) {
specimenGroups[0].group.rotation.y += delta * 0.2;
specimenGroups[0].group.rotation.x =
0.08 + Math.sin(elapsed * 0.45) * 0.035;
specimenGroups[1].group.rotation.y += delta * 0.12;
specimenGroups[1].group.rotation.z =
-1.28 + Math.sin(elapsed * 0.55) * 0.025;
specimenGroups[2].group.rotation.y += delta * 0.09;
specimenGroups[2].group.rotation.z =
-0.08 + Math.sin(elapsed * 0.4) * 0.025;
specimenGroups.forEach((item) => {
item.group.position.y =
item.baseY + Math.sin(elapsed * 0.8 + item.phase) * 0.055;
});
}
renderer.render(scene, camera);
});
</script>
</body>
</html>
```