Prompt specification
Build or customize the Three.js 3D scene "Homologous chromosome pair with marked segments" 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: Homologous chromosome pair with marked segments
Category: Biology & Nature · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/homologous-chromosome-pair-with-marked-segments-x0929
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing a low-poly homologous chromosome pair. Use two unreplicated rod-like chromosomes of matching length, with corresponding loci placed at the same positions and different colors indicating alternative segment identities. Mount them side by side above a neutral display base, leaving enough gap to compare the markings. A small separate diagram may show a replicated chromosome so the pair is not mistaken for two sister chromatids. Use smooth bends but visibly faceted surfaces, restrained labels, and a close oblique camera. Keep the main model static: the purpose is to inspect matching structure and different marked segments before any crossing-over animation is introduced.
Working Three.js Starter (homologous-chromosome-pair-with-marked-segments-x0929):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homologous Chromosome Pair</title>
<style>
:root {
--ink: #252a30;
--muted: #697078;
--panel: rgba(250, 248, 243, 0.90);
--line: rgba(37, 42, 48, 0.13);
--a1: #de7a5f;
--b1: #4f78a3;
--a2: #7067a6;
--b2: #c65d78;
--a3: #78966a;
--b3: #c59a48;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #e9e5dd;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#stage {
position: fixed;
inset: 0;
}
canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
outline: none;
}
canvas.dragging {
cursor: grabbing;
}
.heading {
position: fixed;
top: 24px;
left: 26px;
z-index: 5;
max-width: 340px;
pointer-events: none;
}
.heading h1 {
margin: 0 0 6px;
font-size: clamp(20px, 2vw, 27px);
font-weight: 650;
letter-spacing: -0.035em;
}
.heading p {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.5;
}
.status {
position: fixed;
top: 24px;
right: 24px;
z-index: 5;
padding: 8px 11px;
border: 1px solid var(--line);
border-radius: 999px;
background: rgba(250, 248, 243, 0.72);
color: #59616a;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.13em;
text-transform: uppercase;
pointer-events: none;
}
.legend {
position: fixed;
left: 24px;
bottom: 24px;
z-index: 5;
min-width: 270px;
padding: 14px 16px 13px;
border: 1px solid var(--line);
border-radius: 13px;
background: var(--panel);
box-shadow: 0 10px 35px rgba(44, 49, 55, 0.08);
backdrop-filter: blur(8px);
pointer-events: none;
}
.legend-title {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 18px;
margin-bottom: 11px;
font-size: 12px;
font-weight: 700;
}
.legend-title span {
color: var(--muted);
font-size: 10px;
font-weight: 550;
letter-spacing: 0.02em;
}
.loci {
display: flex;
gap: 16px;
}
.locus {
display: flex;
align-items: center;
gap: 5px;
}
.locus b {
width: 13px;
color: #777d82;
font-size: 10px;
font-weight: 650;
}
.swatch {
width: 26px;
height: 9px;
border-radius: 3px;
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}
.a1 { background: var(--a1); }
.b1 { background: var(--b1); }
.a2 { background: var(--a2); }
.b2 { background: --b2; }
.a3 { background: var(--a3); }
.b3 { background: var(--b3); }
.note {
position: fixed;
right: 24px;
bottom: 24px;
z-index: 5;
display: flex;
align-items: center;
gap: 12px;
color: #656c73;
font-size: 11px;
line-height: 1.45;
text-align: right;
pointer-events: none;
}
.note button {
appearance: none;
border: 1px solid var(--line);
border-radius: 9px;
padding: 8px 11px;
background: var(--panel);
color: var(--ink);
font: inherit;
font-size: 11px;
cursor: pointer;
}
.note button:hover {
background: #fffdf8;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #e9e5dd;
color: #656c73;
font-size: 13px;
transition: opacity 180ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 720px) {
.heading {
top: 18px;
left: 18px;
max-width: 250px;
}
.heading p {
font-size: 11px;
}
.status {
top: 18px;
right: 18px;
font-size: 8px;
}
.legend {
left: 14px;
bottom: 14px;
min-width: 0;
padding: 11px 13px;
}
.note {
right: 14px;
bottom: 14px;
}
.note span {
display: none;
}
}
</style>
</head>
<body>
<div id="stage"></div>
<header class="heading">
<h1>Homologous chromosome pair</h1>
<p>
Two matching, unreplicated rods. Colored sleeves mark corresponding
loci with alternative segment identities.
</p>
</header>
<div class="status">Static comparison · no crossing-over</div>
<section class="legend" aria-label="Legend for corresponding chromosome loci">
<div class="legend-title">
Matching loci
<span>A swatch / B swatch</span>
</div>
<div class="loci">
<div class="locus">
<b>1</b>
<span class="swatch a1"></span>
<span class="swatch b1"></span>
</div>
<div class="locus">
<b>2</b>
<span class="swatch a2"></span>
<span class="swatch b2"></span>
</div>
<div class="locus">
<b>3</b>
<span class="swatch a3"></span>
<span class="swatch b3"></span>
</div>
</div>
</section>
<div class="note">
<span>
Small X at right: replicated chromosome<br>
reference only, not part of the pair
</span>
<button id="reset" type="button">Reset view</button>
</div>
<div id="loading">Loading 3D model…</div>
<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 loading = document.querySelector("#loading");
// ---------------------------------------------------------------------
// Scene and renderer
// ---------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xe9e5dd);
scene.fog = new THREE.Fog(0xe9e5dd, 13, 25);
const camera = new THREE.PerspectiveCamera(
32,
window.innerWidth / window.innerHeight,
0.1,
60
);
const renderer = new THREE.WebGLRenderer({
antialias: 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.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
stage.appendChild(renderer.domElement);
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Static low-poly homologous chromosome pair. Drag to orbit and scroll to zoom."
);
// ---------------------------------------------------------------------
// Lighting
// ---------------------------------------------------------------------
const hemisphere = new THREE.HemisphereLight(
0xfffbf1,
0x87919d,
2.0
);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff9ed, 3.3);
keyLight.position.set(4.5, 7.0, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -5;
keyLight.shadow.camera.near = 0.5;
keyLight.shadow.camera.far = 20;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const fillLight = new THREE.DirectionalLight(0xc4d8f4, 1.15);
fillLight.position.set(-5, 2.5, -3);
scene.add(fillLight);
const rimLight = new THREE.DirectionalLight(0xffdfbd, 0.8);
rimLight.position.set(1, 2, -6);
scene.add(rimLight);
// ---------------------------------------------------------------------
// Display base and floor
// ---------------------------------------------------------------------
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0xdedad2,
roughness: 0.96,
metalness: 0
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -1.86;
floor.receiveShadow = true;
scene.add(floor);
const base = new THREE.Mesh(
new THREE.BoxGeometry(6.7, 0.22, 3.15),
new THREE.MeshStandardMaterial({
color: 0xaaa9a4,
roughness: 0.82,
metalness: 0.02
})
);
base.position.set(0.25, -1.70, 0);
base.castShadow = true;
base.receiveShadow = true;
scene.add(base);
const baseTop = new THREE.Mesh(
new THREE.BoxGeometry(6.54, 0.035, 2.98),
new THREE.MeshStandardMaterial({
color: 0xf0ede6,
roughness: 0.9,
metalness: 0
})
);
baseTop.position.set(0.25, -1.572, 0);
baseTop.receiveShadow = true;
scene.add(baseTop);
const inset = new THREE.Mesh(
new THREE.BoxGeometry(3.35, 0.018, 2.35),
new THREE.MeshStandardMaterial({
color: 0xe5e1d8,
roughness: 0.94,
metalness: 0
})
);
inset.position.set(-0.35, -1.538, 0);
inset.receiveShadow = true;
scene.add(inset);
// Small circular platform for the replicated reference.
const referencePad = new THREE.Mesh(
new THREE.CylinderGeometry(0.72, 0.75, 0.07, 32),
new THREE.MeshStandardMaterial({
color: 0xd9d6cf,
roughness: 0.86,
metalness: 0
})
);
referencePad.position.set(2.46, -1.505, 0.43);
referencePad.castShadow = true;
referencePad.receiveShadow = true;
scene.add(referencePad);
// ---------------------------------------------------------------------
// Low-poly swept geometry
// ---------------------------------------------------------------------
/**
* Builds a faceted tube around a Catmull-Rom curve.
* Parallel transport keeps the cross-section stable through bends.
*/
function buildSweep(
curve,
start,
end,
radiusAt,
{
rings = 48,
radialSegments = 8,
radiusScale = 1
} = {}
) {
const positions = [];
const uvs = [];
const indices = [];
let previousNormal = null;
for (let i = 0; i <= rings; i++) {
const u = THREE.MathUtils.lerp(start, end, i / rings);
const point = curve.getPoint(u);
const tangent = curve.getTangent(u).normalize();
let normal;
if (previousNormal === null) {
const reference =
Math.abs(tangent.z) < 0.9
? new THREE.Vector3(0, 0, 1)
: new THREE.Vector3(1, 0, 0);
normal = new THREE.Vector3()
.crossVectors(tangent, reference)
.normalize();
} else {
normal = previousNormal
.clone()
.addScaledVector(tangent, -previousNormal.dot(tangent));
if (normal.lengthSq() < 1e-8) {
normal = new THREE.Vector3()
.crossVectors(tangent, new THREE.Vector3(0, 0, 1));
}
normal.normalize();
}
previousNormal = normal.clone();
const binormal = new THREE.Vector3()
.crossVectors(tangent, normal)
.normalize();
const radius = radiusAt(u) * radiusScale;
for (let j = 0; j <= radialSegments; j++) {
const angle = (j / radialSegments) * Math.PI * 2;
const radialDirection = normal
.clone()
.multiplyScalar(Math.cos(angle))
.addScaledVector(binormal, Math.sin(angle));
const vertex = point.clone().addScaledVector(radialDirection, radius);
positions.push(vertex.x, vertex.y, vertex.z);
uvs.push(j / radialSegments, u);
}
}
const rowLength = radialSegments + 1;
for (let i = 0; i < rings; i++) {
for (let j = 0; j < radialSegments; j++) {
const a = i * rowLength + j;
const b = (i + 1) * rowLength + j;
const c = (i + 1) * rowLength + j + 1;
const d = i * rowLength + j + 1;
indices.push(a, d, b);
indices.push(b, d, c);
}
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(positions, 3)
);
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.setIndex(indices);
geometry.computeVertexNormals();
return geometry;
}
function addFacetedCaps(group, curve, radiusAt, material) {
const capGeometry = new THREE.SphereGeometry(1, 10, 6);
for (const u of [0, 1]) {
const point = curve.getPoint(u);
const cap = new THREE.Mesh(capGeometry, material);
cap.position.copy(point);
cap.scale.setScalar(radiusAt(u) * 1.015);
cap.castShadow = true;
cap.receiveShadow = true;
group.add(cap);
}
}
// ---------------------------------------------------------------------
// Main homologous pair
// ---------------------------------------------------------------------
const mainPath = new THREE.CatmullRomCurve3(
[
new THREE.Vector3(-0.04, -1.20, 0.00),
new THREE.Vector3(-0.18, -0.83, 0.03),
new THREE.Vector3(-0.04, -0.43, 0.10),
new THREE.Vector3(0.15, 0.00, 0.05),
new THREE.Vector3(0.08, 0.40, -0.03),
new THREE.Vector3(-0.10, 0.78, 0.01),
new THREE.Vector3(0.02, 1.15, 0.00),
new THREE.Vector3(0.00, 1.42, 0.00)
],
false,
"catmullrom",
0.5
);
// A subtle matching centromeric constriction.
function chromosomeRadius(u) {
const endTaper = 0.94 + 0.06 * Math.sin(Math.PI * u);
const centromere =
1 - 0.22 * Math.exp(-Math.pow((u - 0.43) / 0.055, 2));
return 0.205 * endTaper * centromere;
}
const bodyMaterial = new THREE.MeshStandardMaterial({
color: 0xd8cdb8,
roughness: 0.72,
metalness: 0,
flatShading: true
});
const loci = [
{
number: 1,
start: 0.18,
end: 0.29,
a: 0xde7a5f,
b: 0x4f78a3
},
{
number: 2,
start: 0.54,
end: 0.64,
a: 0x7067a6,
b: 0xc65d78
},
{
number: 3,
start: 0.76,
end: 0.86,
a: 0x78966a,
b: 0xc59a48
}
];
function createHomologue(x, useA) {
const group = new THREE.Group();
group.position.x = x;
const body = new THREE.Mesh(
buildSweep(mainPath, 0, 1, chromosomeRadius, {
rings: 52,
radialSegments: 8
}),
bodyMaterial
);
body.castShadow = true;
body.receiveShadow = true;
group.add(body);
addFacetedCaps(group, mainPath, chromosomeRadius, bodyMaterial);
for (const locus of loci) {
const color = useA ? locus.a : locus.b;
const material = new THREE.MeshStandardMaterial({
color,
roughness: 0.58,
metalness: 0,
flatShading: true
});
const sleeve = new THREE.Mesh(
buildSweep(
mainPath,
locus.start,
locus.end,
chromosomeRadius,
{
rings: 16,
radialSegments: 8,
radiusScale: 1.065
}
),
material
);
sleeve.castShadow = true;
sleeve.receiveShadow = true;
group.add(sleeve);
}
scene.add(group);
}
createHomologue(-0.82, true);
createHomologue(0.82, false);
// ---------------------------------------------------------------------
// Small replicated chromosome reference: two joined sister chromatids
// ---------------------------------------------------------------------
const referenceGroup = new THREE.Group();
referenceGroup.position.set(2.46, 0, 0.43);
scene.add(referenceGroup);
const referenceMaterial = new THREE.MeshStandardMaterial({
color: 0xb9b5b6,
roughness: 0.67,
metalness: 0,
flatShading: true
});
const referenceCurves = [
new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.43, -1.47, 0.015),
new THREE.Vector3(-0.25, -1.15, 0.015),
new THREE.Vector3(-0.06, -0.83, 0.015),
new THREE.Vector3(0.10, -0.55, 0.015),
new THREE.Vector3(0.34, -0.17, 0.015)
]),
new THREE.CatmullRomCurve3([
new THREE.Vector3(0.43, -1.47, -0.015),
new THREE.Vector3(0.25, -1.15, -0.015),
new THREE.Vector3(0.06, -0.83, -0.015),
new THREE.Vector3(-0.10, -0.55, -0.015),
new THREE.Vector3(-0.34, -0.17, -0.015)
])
];
for (const curve of referenceCurves) {
const chromatid = new THREE.Mesh(
buildSweep(curve, 0, 1, () => 0.086, {
rings: 28,
radialSegments: 7
}),
referenceMaterial
);
chromatid.castShadow = true;
chromatid.receiveShadow = true;
referenceGroup.add(chromatid);
addFacetedCaps(
referenceGroup,
curve,
() => 0.086,
referenceMaterial
);
}
const centromere = new THREE.Mesh(
new THREE.SphereGeometry(0.105, 10, 6),
referenceMaterial
);
centromere.position.set(0, -0.83, 0);
centromere.castShadow = true;
referenceGroup.add(centromere);
// ---------------------------------------------------------------------
// Canvas sprite labels
// ---------------------------------------------------------------------
function createTextSprite(
text,
{
width = 512,
height = 128,
worldWidth = 1,
worldHeight = 0.25,
color = "#30363d",
background = null,
fontSize = 64
} = {}
) {
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const context = canvas.getContext("2d");
context.clearRect(0, 0, width, height);
if (background) {
context.fillStyle = background;
context.beginPath();
context.roundRect(2, 2, width - 4, height - 4, 22);
context.fill();
}
context.fillStyle = color;
context.font = `650 ${fontSize}px system-ui, sans-serif`;
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, width / 2, height / 2 + 2);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(worldWidth, worldHeight, 1);
sprite.renderOrder = 20;
return sprite;
}
const labelA = createTextSprite("A", {
width: 128,
height: 128,
worldWidth: 0.24,
worldHeight: 0.24,
fontSize: 82
});
labelA.position.set(-0.82, 1.68, 0.12);
scene.add(labelA);
const labelB = createTextSprite("B", {
width: 128,
height: 128,
worldWidth: 0.24,
worldHeight: 0.24,
fontSize: 82
});
labelB.position.set(0.82, 1.68, 0.12);
scene.add(labelB);
for (const locus of loci) {
const midpoint = (locus.start + locus.end) / 2;
const point = mainPath.getPoint(midpoint);
const numberLabel = createTextSprite(String(locus.number), {
width: 128,
height: 128,
worldWidth: 0.15,
worldHeight: 0.15,
color: "#697078",
fontSize: 68
});
numberLabel.position.set(0, point.y + 0.015, 0.29);
scene.add(numberLabel);
}
const replicatedLabel = createTextSprite("REPLICATED", {
width: 512,
height: 128,
worldWidth: 1.18,
worldHeight: 0.295,
color: "#555c64",
background: "rgba(247,244,237,0.82)",
fontSize: 54
});
replicatedLabel.position.set(2.46, -0.01, 0.58);
scene.add(replicatedLabel);
// ---------------------------------------------------------------------
// Direct camera controls; no external control add-ons
// ---------------------------------------------------------------------
const defaultView = {
radius: 8.15,
theta: 0.36,
phi: 1.27
};
const view = { ...defaultView };
const target = new THREE.Vector3(0.22, 0.02, 0);
function updateCamera() {
const sinPhi = Math.sin(view.phi);
camera.position.set(
target.x + view.radius * sinPhi * Math.sin(view.theta),
target.y + view.radius * Math.cos(view.phi),
target.z + view.radius * sinPhi * Math.cos(view.theta)
);
camera.lookAt(target);
renderer.render(scene, camera);
}
function resetView() {
Object.assign(view, defaultView);
updateCamera();
}
let dragging = false;
let previousX = 0;
let previousY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
previousX = event.clientX;
previousY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - previousX;
const deltaY = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
view.theta -= deltaX * 0.006;
view.phi = THREE.MathUtils.clamp(
view.phi + deltaY * 0.005,
0.72,
1.48
);
updateCamera();
});
function endDrag(event) {
dragging = false;
renderer.domElement.classList.remove("dragging");
if (
event.pointerId !== undefined &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", endDrag);
renderer.domElement.addEventListener("pointercancel", endDrag);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
view.radius = THREE.MathUtils.clamp(
view.radius + event.deltaY * 0.006,
6.2,
11.2
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetView);
document.querySelector("#reset").addEventListener("click", resetView);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetView();
} else if (event.key === "ArrowLeft") {
view.theta += 0.08;
updateCamera();
} else if (event.key === "ArrowRight") {
view.theta -= 0.08;
updateCamera();
} else if (event.key === "+" || event.key === "=") {
view.radius = Math.max(6.2, view.radius - 0.35);
updateCamera();
} else if (event.key === "-") {
view.radius = Math.min(11.2, view.radius + 0.35);
updateCamera();
}
});
function resize() {
const width = window.innerWidth;
const height = window.innerHeight;
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(width, height);
camera.aspect = width / height;
camera.updateProjectionMatrix();
updateCamera();
}
window.addEventListener("resize", resize);
resetView();
loading.classList.add("hidden");
window.setTimeout(() => loading.remove(), 220);
</script>
</body>
</html>
```