Prompt specification
Build or customize the Three.js 3D scene "Crystal seed and lattice-face model" 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: Crystal seed and lattice-face model
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/crystal-seed-and-lattice-face-model-x1945
Scene Description Prompt:
I'd like to see this as a cutaway Three.js scene: crystal seed and lattice-face model. Build a small seed crystal with visible growth faces and surrounding symbolic solute units; distinguish the repeating lattice from the macroscopic outline. Use cdnjs and return one self-contained HTML file.
Working Three.js Starter (crystal-seed-and-lattice-face-model-x1945):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Crystal Seed — Cutaway Lattice Study</title>
<style>
:root {
color-scheme: dark;
--ink: #dff8ff;
--muted: #8da8b9;
--cyan: #57ddff;
--violet: #c47cff;
--amber: #ffbc62;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 66% 36%, #142b43 0%, #091523 38%, #040811 78%, #02050b 100%);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
outline: none;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
box-shadow: inset 0 0 140px 32px rgba(0, 0, 0, .58);
background: linear-gradient(180deg, rgba(10, 25, 40, .08), transparent 28%);
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
}
.panel {
position: absolute;
border: 1px solid rgba(136, 216, 255, .17);
background: linear-gradient(135deg, rgba(7, 19, 32, .78), rgba(6, 13, 24, .48));
box-shadow: 0 16px 50px rgba(0, 0, 0, .24);
backdrop-filter: blur(14px);
-webkit-backdrop-filter: blur(14px);
}
#title-panel {
top: 24px;
left: 24px;
width: min(390px, calc(100vw - 48px));
padding: 18px 20px 17px;
border-radius: 4px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 9px;
color: var(--cyan);
font-size: 10px;
font-weight: 700;
letter-spacing: .2em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 22px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 9px rgba(87, 221, 255, .8);
}
h1 {
margin: 10px 0 7px;
color: var(--ink);
font-size: clamp(20px, 2.4vw, 29px);
font-weight: 560;
letter-spacing: -.035em;
}
#title-panel p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
letter-spacing: .035em;
}
#legend {
left: 24px;
bottom: 24px;
width: 260px;
padding: 15px 17px;
border-radius: 4px;
}
.legend-title {
margin-bottom: 11px;
color: #718e9f;
font-size: 9px;
font-weight: 700;
letter-spacing: .19em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 25px 1fr;
align-items: center;
gap: 10px;
margin-top: 9px;
color: #bdd3df;
font-size: 10px;
letter-spacing: .09em;
text-transform: uppercase;
}
.swatch {
position: relative;
width: 24px;
height: 10px;
}
.swatch.face::before {
content: "";
position: absolute;
inset: 1px 3px;
border: 1px solid #79dfff;
background: rgba(74, 183, 235, .22);
transform: skewY(-12deg);
}
.swatch.lattice::before {
content: "";
position: absolute;
left: 2px;
top: 1px;
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--violet);
box-shadow: 8px 2px 0 var(--cyan), 4px 7px 0 var(--violet), 15px 7px 0 var(--cyan);
}
.swatch.solute::before {
content: "";
position: absolute;
left: 9px;
top: 0;
width: 7px;
height: 7px;
border: 1px solid var(--amber);
transform: rotate(45deg);
box-shadow: -8px 4px 0 -2px #081321, 8px 4px 0 -2px #081321,
-8px 4px 0 -1px var(--amber), 8px 4px 0 -1px var(--amber);
}
.swatch.envelope::before {
content: "";
position: absolute;
left: 0;
right: 0;
top: 4px;
border-top: 1px dashed rgba(215, 248, 255, .7);
}
#controls {
top: 24px;
right: 24px;
padding: 10px 13px;
border-radius: 4px;
color: #a8c1cf;
font-size: 9px;
font-weight: 650;
letter-spacing: .16em;
text-transform: uppercase;
pointer-events: auto;
cursor: pointer;
transition: border-color .2s, color .2s, background .2s;
}
#controls:hover {
color: #e8fbff;
border-color: rgba(87, 221, 255, .55);
background: rgba(18, 47, 68, .72);
}
#hint {
position: absolute;
right: 25px;
bottom: 25px;
color: rgba(171, 201, 216, .66);
font-size: 9px;
letter-spacing: .13em;
text-transform: uppercase;
}
#leaders {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
pointer-events: none;
overflow: visible;
}
#leaders line {
stroke-width: 1;
stroke-dasharray: 3 5;
opacity: .62;
}
.callout {
position: absolute;
z-index: 3;
min-width: 126px;
padding: 8px 10px 8px 28px;
border-left: 1px solid rgba(132, 226, 255, .45);
color: #cceaf3;
background: linear-gradient(90deg, rgba(5, 16, 27, .78), rgba(5, 16, 27, .15));
font-size: 9px;
font-weight: 650;
letter-spacing: .14em;
line-height: 1.35;
text-transform: uppercase;
white-space: nowrap;
text-shadow: 0 1px 8px #000;
}
.callout::before {
content: "";
position: absolute;
left: -3px;
top: 50%;
width: 5px;
height: 5px;
border-radius: 50%;
background: currentColor;
box-shadow: 0 0 9px currentColor;
transform: translateY(-50%);
}
.callout span {
display: block;
margin-bottom: 2px;
color: #6d93a5;
font-size: 8px;
letter-spacing: .18em;
}
#ann-growth { color: #7ce4ff; }
#ann-lattice { color: #d096ff; }
#ann-solute { color: #ffc873; }
@media (max-width: 700px) {
#title-panel {
top: 14px;
left: 14px;
width: calc(100vw - 28px);
padding: 14px 16px;
}
#legend {
left: 14px;
bottom: 14px;
width: 220px;
padding: 12px 14px;
}
#controls {
top: auto;
right: 14px;
bottom: 14px;
}
#hint { display: none; }
.callout, #leaders { display: none; }
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive cutaway crystal seed and repeating lattice"></canvas>
<div id="vignette"></div>
<div id="hud">
<section id="title-panel" class="panel">
<div class="eyebrow">Crystallization study / section 01</div>
<h1>Seed Crystal / Lattice Cutaway</h1>
<p>Macroscopic growth faces are shown as a translucent envelope. The repeating atomic network and symbolic solute clusters remain visually distinct.</p>
</section>
<section id="legend" class="panel">
<div class="legend-title">Visual encoding</div>
<div class="legend-row"><span class="swatch face"></span>Growth faces</div>
<div class="legend-row"><span class="swatch lattice"></span>Repeating lattice</div>
<div class="legend-row"><span class="swatch solute"></span>Symbolic solute</div>
<div class="legend-row"><span class="swatch envelope"></span>Full envelope ghost</div>
</section>
<button id="controls" type="button">Reset view</button>
<div id="hint">Drag to orbit · Wheel to zoom · Double-click to reset</div>
<svg id="leaders" aria-hidden="true">
<line id="line-growth"></line>
<line id="line-lattice"></line>
<line id="line-solute"></line>
</svg>
<div id="ann-growth" class="callout"><span>01 / morphology</span>Growth face</div>
<div id="ann-lattice" class="callout"><span>02 / atomic repeat</span>Lattice network</div>
<div id="ann-solute" class="callout"><span>03 / solution</span>Solute unit</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.85));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0x050914, 0);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x050914, 0.027);
const camera = new THREE.PerspectiveCamera(
38,
window.innerWidth / window.innerHeight,
0.1,
40
);
const target = new THREE.Vector3(0, 0.18, 0);
const orbit = {
azimuth: 0.66,
polar: 1.17,
radius: 8.15
};
function updateCamera() {
const horizontal = orbit.radius * Math.sin(orbit.polar);
camera.position.set(
target.x + horizontal * Math.sin(orbit.azimuth),
target.y + orbit.radius * Math.cos(orbit.polar),
target.z + horizontal * Math.cos(orbit.azimuth)
);
camera.lookAt(target);
}
updateCamera();
scene.add(new THREE.HemisphereLight(0x9edcff, 0x06101a, 2.0));
const keyLight = new THREE.DirectionalLight(0xd9f4ff, 3.2);
keyLight.position.set(4, 7, 5);
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x35cfff, 22, 9, 2);
cyanLight.position.set(-3.5, 1.0, 2.5);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x9e55ff, 18, 8, 2);
violetLight.position.set(2.8, 0.3, -3.4);
scene.add(violetLight);
const warmLight = new THREE.PointLight(0xffa53f, 7, 4.5, 2);
warmLight.position.set(1.5, -0.5, 1.8);
scene.add(warmLight);
const DEG = Math.PI / 180;
const BASE_Y = -1.22;
const SHOULDER_Y = 0.82;
const APEX_Y = 2.15;
const BASE_R = 1.08;
const SHOULDER_R = 1.28;
// The omitted sector runs from 315° through 15° to 75°, facing the camera.
const angles = [15, 75, 135, 195, 255, 315];
const retainedEdges = [1, 2, 3, 4];
function crystalPoint(angle, radius, y) {
return new THREE.Vector3(
Math.cos(angle * DEG) * radius,
y,
Math.sin(angle * DEG) * radius
);
}
const baseRing = angles.map(a => crystalPoint(a, BASE_R, BASE_Y));
const shoulderRing = angles.map(a => crystalPoint(a, SHOULDER_R, SHOULDER_Y));
const baseCenter = new THREE.Vector3(0, BASE_Y, 0);
const apex = new THREE.Vector3(0, APEX_Y, 0);
function makePolygonGeometry(points, uvPoints = null) {
const positions = [];
const uvs = [];
for (let i = 1; i < points.length - 1; i++) {
const triangle = [points[0], points[i], points[i + 1]];
const triangleUV = uvPoints
? [uvPoints[0], uvPoints[i], uvPoints[i + 1]]
: [
new THREE.Vector2(0, 0),
new THREE.Vector2(1, 0),
new THREE.Vector2(1, 1)
];
for (const p of triangle) positions.push(p.x, p.y, p.z);
for (const uv of triangleUV) uvs.push(uv.x, uv.y);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
geometry.setAttribute("uv", new THREE.Float32BufferAttribute(uvs, 2));
geometry.computeVertexNormals();
return geometry;
}
function addSegments(parent, pairs, material, renderOrder = 0) {
const positions = [];
for (const [a, b] of pairs) {
positions.push(a.x, a.y, a.z, b.x, b.y, b.z);
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(positions, 3));
const lines = new THREE.LineSegments(geometry, material);
lines.renderOrder = renderOrder;
parent.add(lines);
return lines;
}
function radialOffset(point, amount = 0.008) {
const radial = new THREE.Vector3(point.x, 0, point.z);
if (radial.lengthSq() > 0) radial.normalize().multiplyScalar(amount);
return point.clone().add(radial);
}
const macro = new THREE.Group();
scene.add(macro);
const facePalette = [
0x3999dc, 0x4d82dc, 0x45b8c6,
0x647ed9, 0x4aa9dc, 0x7771d6
];
function growthMaterial(color, opacity) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.27,
metalness: 0.18,
emissive: new THREE.Color(color).multiplyScalar(0.13),
emissiveIntensity: 0.45,
transparent: true,
opacity,
side: THREE.DoubleSide,
depthWrite: false,
polygonOffset: true,
polygonOffsetFactor: 1,
polygonOffsetUnits: 1
});
}
const contourMaterial = new THREE.LineBasicMaterial({
color: 0x9cecff,
transparent: true,
opacity: 0.18,
depthWrite: false,
depthTest: false
});
retainedEdges.forEach((index, faceIndex) => {
const next = (index + 1) % angles.length;
const color = facePalette[faceIndex];
const lowerGeometry = makePolygonGeometry(
[baseRing[index], baseRing[next], shoulderRing[next], shoulderRing[index]],
[
new THREE.Vector2(0, 0),
new THREE.Vector2(1, 0),
new THREE.Vector2(1, 1),
new THREE.Vector2(0, 1)
]
);
const lowerFace = new THREE.Mesh(
lowerGeometry,
growthMaterial(color, 0.38)
);
lowerFace.renderOrder = 1;
macro.add(lowerFace);
const upperFace = new THREE.Mesh(
makePolygonGeometry([
shoulderRing[index],
shoulderRing[next],
apex
]),
growthMaterial(color, 0.49)
);
upperFace.renderOrder = 1;
macro.add(upperFace);
// Fine terrace contours make the broad faces read as growth faces.
const terracePairs = [];
for (const t of [0.18, 0.36, 0.54, 0.72, 0.86]) {
for (let u = 0; u < 1; u += 0.125) {
const p0 = new THREE.Vector3().lerpVectors(
new THREE.Vector3().lerpVectors(baseRing[index], baseRing[next], u),
new THREE.Vector3().lerpVectors(shoulderRing[index], shoulderRing[next], u),
t
);
const p1 = new THREE.Vector3().lerpVectors(
new THREE.Vector3().lerpVectors(baseRing[index], baseRing[next], u + 0.125),
new THREE.Vector3().lerpVectors(shoulderRing[index], shoulderRing[next], u + 0.125),
t
);
terracePairs.push([radialOffset(p0), radialOffset(p1)]);
}
}
terracePairs.push([
radialOffset(baseRing[index]),
radialOffset(shoulderRing[next])
]);
for (const t of [0.28, 0.5, 0.72]) {
for (let u = 0; u < 1; u += 0.125) {
const p0 = new THREE.Vector3().lerpVectors(
apex,
new THREE.Vector3().lerpVectors(shoulderRing[index], shoulderRing[next], u),
t
);
const p1 = new THREE.Vector3().lerpVectors(
apex,
new THREE.Vector3().lerpVectors(shoulderRing[index], shoulderRing[next], u + 0.125),
t
);
terracePairs.push([radialOffset(p0, 0.012), radialOffset(p1, 0.012)]);
}
}
addSegments(macro, terracePairs, contourMaterial, 5);
});
// A dark, retained base emphasizes that the object is a sectioned solid.
const basePositions = [];
for (const index of retainedEdges) {
const next = (index + 1) % angles.length;
const triangle = [baseCenter, baseRing[index], baseRing[next]];
for (const p of triangle) basePositions.push(p.x, p.y, p.z);
}
const baseGeometry = new THREE.BufferGeometry();
baseGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(basePositions, 3)
);
baseGeometry.computeVertexNormals();
const baseMesh = new THREE.Mesh(
baseGeometry,
new THREE.MeshStandardMaterial({
color: 0x0a3049,
roughness: 0.55,
metalness: 0.1,
emissive: 0x062236,
emissiveIntensity: 0.3,
transparent: true,
opacity: 0.44,
side: THREE.DoubleSide,
depthWrite: false
})
);
baseMesh.renderOrder = 1;
macro.add(baseMesh);
// Procedural section hatch, used only on the two radial cut planes.
const hatchCanvas = document.createElement("canvas");
hatchCanvas.width = 256;
hatchCanvas.height = 256;
const hatchContext = hatchCanvas.getContext("2d");
hatchContext.fillStyle = "#08283c";
hatchContext.fillRect(0, 0, 256, 256);
hatchContext.strokeStyle = "rgba(112, 225, 255, .34)";
hatchContext.lineWidth = 2;
for (let x = -256; x < 512; x += 28) {
hatchContext.beginPath();
hatchContext.moveTo(x, 0);
hatchContext.lineTo(x + 256, 256);
hatchContext.stroke();
}
hatchContext.strokeStyle = "rgba(184, 117, 255, .13)";
hatchContext.lineWidth = 1;
for (let x = -256; x < 512; x += 28) {
hatchContext.beginPath();
hatchContext.moveTo(x + 10, 0);
hatchContext.lineTo(x + 266, 256);
hatchContext.stroke();
}
const hatchTexture = new THREE.CanvasTexture(hatchCanvas);
hatchTexture.colorSpace = THREE.SRGBColorSpace;
hatchTexture.wrapS = hatchTexture.wrapT = THREE.RepeatWrapping;
hatchTexture.repeat.set(1.5, 1.5);
hatchTexture.anisotropy = renderer.capabilities.getMaxAnisotropy();
for (const [cutIndex, opacity] of [[1, 0.56], [5, 0.38]]) {
const cutGeometry = makePolygonGeometry(
[baseCenter, baseRing[cutIndex], shoulderRing[cutIndex], apex],
[
new THREE.Vector2(0.05, 0.05),
new THREE.Vector2(0.96, 0.05),
new THREE.Vector2(0.9, 0.62),
new THREE.Vector2(0.05, 0.98)
]
);
const cutFace = new THREE.Mesh(
cutGeometry,
new THREE.MeshStandardMaterial({
map: hatchTexture,
color: 0x9ceaff,
emissive: 0x0b435e,
emissiveIntensity: 0.38,
roughness: 0.5,
metalness: 0.05,
transparent: true,
opacity,
side: THREE.DoubleSide,
depthWrite: false
})
);
cutFace.renderOrder = 2;
macro.add(cutFace);
}
// Bright active edges describe the retained macroscopic boundary.
const activePairs = [];
for (const index of retainedEdges) {
const next = (index + 1) % angles.length;
activePairs.push([baseRing[index], baseRing[next]]);
activePairs.push([shoulderRing[index], shoulderRing[next]]);
}
for (const index of retainedEdges) {
activePairs.push([baseRing[index], shoulderRing[index]]);
activePairs.push([shoulderRing[index], apex]);
}
for (const index of [1, 5]) {
activePairs.push([baseCenter, baseRing[index]]);
}
addSegments(
macro,
activePairs,
new THREE.LineBasicMaterial({
color: 0xd9f8ff,
transparent: true,
opacity: 0.88,
depthWrite: false
}),
7
);
// Dashed ghost of the complete envelope distinguishes morphology from lattice.
const ghostPairs = [];
for (let i = 0; i < angles.length; i++) {
const j = (i + 1) % angles.length;
ghostPairs.push([baseRing[i], baseRing[j]]);
ghostPairs.push([shoulderRing[i], shoulderRing[j]]);
ghostPairs.push([baseRing[i], shoulderRing[i]]);
ghostPairs.push([shoulderRing[i], apex]);
}
const ghostMaterial = new THREE.LineDashedMaterial({
color: 0xa9d6e8,
transparent: true,
opacity: 0.18,
dashSize: 0.075,
gapSize: 0.052,
depthWrite: false
});
const ghost = addSegments(macro, ghostPairs, ghostMaterial, 0);
ghost.computeLineDistances();
// ------------------------------------------------------------------
// Repeating three-dimensional lattice: offset layer network.
// ------------------------------------------------------------------
const lattice = new THREE.Group();
scene.add(lattice);
const layerHeights = [-1.00, -0.54, -0.08, 0.38, 0.84, 1.28, 1.66];
const gridStep = 0.43;
const latticeLayers = [];
function radiusAt(y) {
if (y <= SHOULDER_Y) {
const t = (y - BASE_Y) / (SHOULDER_Y - BASE_Y);
return THREE.MathUtils.lerp(BASE_R, SHOULDER_R, t) - 0.075;
}
return SHOULDER_R * (APEX_Y - y) / (APEX_Y - SHOULDER_Y) - 0.075;
}
for (let layerIndex = 0; layerIndex < layerHeights.length; layerIndex++) {
const y = layerHeights[layerIndex];
const layer = [];
const lookup = new Map();
const limit = radiusAt(y);
for (let ix = -2; ix <= 2; ix++) {
for (let iz = -2; iz <= 2; iz++) {
const x = ix * gridStep;
const z = iz * gridStep;
if (Math.hypot(x, z) <= limit) {
const entry = { x, y, z, ix, iz };
layer.push(entry);
lookup.set(`${ix},${iz}`, entry);
}
}
}
latticeLayers.push({ y, layer, lookup });
}
const sameLayerPairs = [];
const crossLayerPairs = [];
latticeLayers.forEach((current, layerIndex) => {
for (const node of current.layer) {
const right = current.lookup.get(`${node.ix + 1},${node.iz}`);
const up = current.lookup.get(`${node.ix},${node.iz + 1}`);
if (right) {
sameLayerPairs.push([
new THREE.Vector3(node.x, node.y, node.z),
new THREE.Vector3(right.x, right.y, right.z)
]);
}
if (up) {
sameLayerPairs.push([
new THREE.Vector3(node.x, node.y, node.z),
new THREE.Vector3(up.x, up.y, up.z)
]);
}
if (layerIndex < latticeLayers.length - 1) {
const next = latticeLayers[layerIndex + 1].lookup;
for (const [dx, dz] of [[-1, 0], [0, -1], [0, 1], [1, 0]]) {
const diagonal = next.get(`${node.ix + dx},${node.iz + dz}`);
if (diagonal) {
crossLayerPairs.push([
new THREE.Vector3(node.x, node.y, node.z),
new THREE.Vector3(diagonal.x, diagonal.y, diagonal.z)
]);
}
}
}
}
});
addSegments(
lattice,
sameLayerPairs,
new THREE.LineBasicMaterial({
color: 0x4eddec,
transparent: true,
opacity: 0.43,
depthWrite: false
}),
3
);
addSegments(
lattice,
crossLayerPairs,
new THREE.LineBasicMaterial({
color: 0xb57aff,
transparent: true,
opacity: 0.36,
depthWrite: false
}),
3
);
const allLatticeNodes = latticeLayers.flatMap(layer => layer.layer);
const nodeGeometry = new THREE.IcosahedronGeometry(0.037, 0);
const nodeMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.98
});
const nodeMesh = new THREE.InstancedMesh(
nodeGeometry,
nodeMaterial,
allLatticeNodes.length
);
const nodeDummy = new THREE.Object3D();
allLatticeNodes.forEach((node, index) => {
nodeDummy.position.set(node.x, node.y, node.z);
nodeDummy.scale.setScalar(index % 7 === 0 ? 1.35 : 1);
nodeDummy.updateMatrix();
nodeMesh.setMatrixAt(index, nodeDummy.matrix);
const color = (node.ix + node.iz + Math.round(node.y * 10)) % 3;
nodeMesh.setColorAt(
index,
new THREE.Color(
color === 0 ? 0xd391ff :
color === 1 ? 0x6ee7ff :
0xf2eaff
)
);
});
nodeMesh.instanceMatrix.needsUpdate = true;
if (nodeMesh.instanceColor) nodeMesh.instanceColor.needsUpdate = true;
nodeMesh.computeBoundingSphere();
nodeMesh.renderOrder = 4;
lattice.add(nodeMesh);
// A face-local lattice patch connects the atomistic model to the crystal face.
const patchIndex = 1;
const patchNext = 2;
const patchPoints = [];
const patchPairs = [];
const patchRows = [];
for (let row = 0; row < 4; row++) {
const t = 0.18 + row * 0.2;
const rowPoints = [];
for (let column = 0; column < 5; column++) {
const u = 0.14 + column * 0.18;
const bottom = new THREE.Vector3().lerpVectors(
baseRing[patchIndex], baseRing[patchNext], u
);
const top = new THREE.Vector3().lerpVectors(
shoulderRing[patchIndex], shoulderRing[patchNext], u
);
const point = new THREE.Vector3().lerpVectors(bottom, top, t);
point.add(new THREE.Vector3(point.x, 0, point.z).normalize().multiplyScalar(0.018));
rowPoints.push(point);
}
patchRows.push(rowPoints);
}
patchRows.forEach((row, rowIndex) => {
row.forEach((point, columnIndex) => {
patchPoints.push(point);
if (columnIndex < row.length - 1) patchPairs.push([point, row[columnIndex + 1]]);
if (rowIndex < patchRows.length - 1) {
patchPairs.push([point, patchRows[rowIndex + 1][columnIndex]]);
}
});
});
const patchGeometry = new THREE.BufferGeometry().setFromPoints(patchPoints);
const patchPointsMesh = new THREE.Points(
patchGeometry,
new THREE.PointsMaterial({
color: 0xe19aff,
size: 0.045,
sizeAttenuation: true,
transparent: true,
opacity: 0.82,
depthTest: false,
depthWrite: false
})
);
patchPointsMesh.renderOrder = 8;
macro.add(patchPointsMesh);
addSegments(
macro,
patchPairs,
new THREE.LineBasicMaterial({
color: 0xd38aff,
transparent: true,
opacity: 0.38,
depthTest: false,
depthWrite: false
}),
8
);
// Warm seed nucleus at the center of the repeating network.
const seed = new THREE.Group();
seed.position.set(0, -0.28, 0.06);
scene.add(seed);
const seedCore = new THREE.Mesh(
new THREE.OctahedronGeometry(0.31, 0),
new THREE.MeshPhysicalMaterial({
color: 0xfff0c8,
emissive: 0xff9f3f,
emissiveIntensity: 1.35,
roughness: 0.18,
metalness: 0.28,
transparent: true,
opacity: 0.94
})
);
seedCore.renderOrder = 6;
seed.add(seedCore);
const seedEdges = new THREE.LineSegments(
new THREE.EdgesGeometry(seedCore.geometry),
new THREE.LineBasicMaterial({
color: 0xfff6dc,
transparent: true,
opacity: 0.82
})
);
seedEdges.renderOrder = 7;
seed.add(seedEdges);
const seedLight = new THREE.PointLight(0xffb34f, 3.2, 4.2, 2);
seed.add(seedLight);
function makeGlowTexture() {
const glowCanvas = document.createElement("canvas");
glowCanvas.width = 128;
glowCanvas.height = 128;
const context = glowCanvas.getContext("2d");
const gradient = context.createRadialGradient(64, 64, 0, 64, 64, 64);
gradient.addColorStop(0, "rgba(255,190,100,.72)");
gradient.addColorStop(0.22, "rgba(255,157,54,.28)");
gradient.addColorStop(1, "rgba(255,130,20,0)");
context.fillStyle = gradient;
context.fillRect(0, 0, 128, 128);
const texture = new THREE.CanvasTexture(glowCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
return texture;
}
const seedHalo = new THREE.Sprite(
new THREE.SpriteMaterial({
map: makeGlowTexture(),
color: 0xffc570,
transparent: true,
opacity: 0.52,
blending: THREE.AdditiveBlending,
depthTest: false,
depthWrite: false
})
);
seedHalo.scale.set(1.45, 1.45, 1);
seedHalo.renderOrder = 5;
seed.add(seedHalo);
// ------------------------------------------------------------------
// Symbolic solute units: an octahedral core with four satellite nodes.
// ------------------------------------------------------------------
const soluteCoreGeometry = new THREE.OctahedronGeometry(0.115, 0);
const soluteNodeGeometry = new THREE.IcosahedronGeometry(0.047, 0);
const soluteCoreMaterial = new THREE.MeshStandardMaterial({
color: 0xffc061,
emissive: 0xff861f,
emissiveIntensity: 1.0,
roughness: 0.25,
metalness: 0.35
});
const soluteNodeMaterial = new THREE.MeshStandardMaterial({
color: 0xffdd9b,
emissive: 0xb85a13,
emissiveIntensity: 0.75,
roughness: 0.3,
metalness: 0.25
});
const satelliteOffsets = [
new THREE.Vector3(0.20, 0.00, 0.00),
new THREE.Vector3(-0.20, 0.00, 0.00),
new THREE.Vector3(0.00, 0.17, 0.12),
new THREE.Vector3(0.00, -0.17, -0.12)
];
function createSoluteUnit(position, scale, phase) {
const group = new THREE.Group();
group.position.copy(position);
group.scale.setScalar(scale);
group.rotation.set(phase * 0.4, phase * 0.7, phase * 0.2);
const core = new THREE.Mesh(soluteCoreGeometry, soluteCoreMaterial);
core.renderOrder = 4;
group.add(core);
const bondPairs = [];
for (const offset of satelliteOffsets) {
const satellite = new THREE.Mesh(soluteNodeGeometry, soluteNodeMaterial);
satellite.position.copy(offset);
satellite.renderOrder = 4;
group.add(satellite);
bondPairs.push([new THREE.Vector3(), offset]);
}
addSegments(
group,
bondPairs,
new THREE.LineBasicMaterial({
color: 0xffbd63,
transparent: true,
opacity: 0.52
}),
3
);
scene.add(group);
return {
group,
baseY: position.y,
phase,
speed: 0.16 + (phase % 1) * 0.12
};
}
const solutePositions = [
new THREE.Vector3(2.42, -0.55, 1.48),
new THREE.Vector3(-2.28, -0.75, 1.12),
new THREE.Vector3(2.08, 0.72, -1.85),
new THREE.Vector3(-2.35, 0.42, -1.48),
new THREE.Vector3(1.92, 1.32, -0.88),
new THREE.Vector3(-1.72, 1.38, 1.72),
new THREE.Vector3(2.78, -1.00, -0.38),
new THREE.Vector3(-2.72, -1.04, -0.58),
new THREE.Vector3(0.30, -0.62, 2.86),
new THREE.Vector3(0.38, 1.62, -2.58)
];
const soluteUnits = solutePositions.map((position, index) =>
createSoluteUnit(
position,
0.76 + (index % 3) * 0.13,
0.8 + index * 1.37
)
);
// Fine dashed paths suggest transport around the seed.
for (let ringIndex = 0; ringIndex < 3; ringIndex++) {
const points = [];
const radius = 2.35 + ringIndex * 0.34;
const phase = ringIndex * 1.8;
for (let i = 0; i <= 180; i++) {
const t = i / 180 * Math.PI * 2;
points.push(new THREE.Vector3(
Math.cos(t) * radius,
-0.55 + 0.52 * Math.sin(t * 2 + phase) + 0.16 * Math.sin(t * 3),
Math.sin(t) * radius * 0.78
));
}
const curve = new THREE.Line(
new THREE.BufferGeometry().setFromPoints(points),
new THREE.LineDashedMaterial({
color: 0xffb84d,
transparent: true,
opacity: 0.14,
dashSize: 0.08,
gapSize: 0.12,
depthWrite: false
})
);
curve.computeLineDistances();
scene.add(curve);
}
// Laboratory plinth and reference grid.
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(2.15, 2.28, 0.12, 96),
new THREE.MeshStandardMaterial({
color: 0x081521,
roughness: 0.72,
metalness: 0.24,
transparent: true,
opacity: 0.8
})
);
plinth.position.y = -1.30;
scene.add(plinth);
const platformRing = new THREE.Mesh(
new THREE.TorusGeometry(2.19, 0.012, 8, 160),
new THREE.MeshBasicMaterial({
color: 0x54d7ff,
transparent: true,
opacity: 0.48
})
);
platformRing.rotation.x = Math.PI / 2;
platformRing.position.y = -1.225;
scene.add(platformRing);
const grid = new THREE.GridHelper(9, 45, 0x2b88a8, 0x18364a);
grid.position.y = -1.37;
grid.material.transparent = true;
grid.material.opacity = 0.18;
grid.material.depthWrite = false;
scene.add(grid);
// ------------------------------------------------------------------
// Direct camera interaction; no external controls module is used.
// ------------------------------------------------------------------
let dragging = false;
let lastX = 0;
let lastY = 0;
let lastInteraction = performance.now();
function resetView() {
orbit.azimuth = 0.66;
orbit.polar = 1.17;
orbit.radius = 8.15;
target.set(0, 0.18, 0);
lastInteraction = performance.now();
updateCamera();
}
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastX = event.clientX;
lastY = event.clientY;
lastInteraction = performance.now();
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastX;
const dy = event.clientY - lastY;
lastX = event.clientX;
lastY = event.clientY;
orbit.azimuth -= dx * 0.005;
orbit.polar = THREE.MathUtils.clamp(
orbit.polar - dy * 0.005,
0.52,
1.46
);
lastInteraction = performance.now();
});
function stopDragging(event) {
dragging = false;
if (event && canvas.hasPointerCapture(event.pointerId)) {
canvas.releasePointerCapture(event.pointerId);
}
}
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("wheel", event => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius + event.deltaY * 0.006,
5.2,
13.5
);
lastInteraction = performance.now();
}, { passive: false });
canvas.addEventListener("dblclick", resetView);
document.querySelector("#controls").addEventListener("click", resetView);
// ------------------------------------------------------------------
// Screen-space callouts.
// ------------------------------------------------------------------
const annotationData = [
{
element: document.querySelector("#ann-growth"),
line: document.querySelector("#line-growth"),
anchor: crystalPoint(105, 1.02, -0.16),
offset: [-184, -76],
color: "#7ce4ff"
},
{
element: document.querySelector("#ann-lattice"),
line: document.querySelector("#line-lattice"),
anchor: new THREE.Vector3(0.12, 0.10, 0.14),
offset: [-178, 77],
color: "#d096ff"
},
{
element: document.querySelector("#ann-solute"),
line: document.querySelector("#line-solute"),
anchor: soluteUnits[0].group.position.clone(),
offset: [78, -48],
color: "#ffc873"
}
];
function updateAnnotations() {
if (window.innerWidth <= 700) return;
const width = window.innerWidth;
const height = window.innerHeight;
for (const annotation of annotationData) {
const projected = annotation.anchor.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
annotation.element.style.display = visible ? "block" : "none";
annotation.line.style.display = visible ? "block" : "none";
if (!visible) continue;
const screenX = (projected.x * 0.5 + 0.5) * width;
const screenY = (-projected.y * 0.5 + 0.5) * height;
const labelX = THREE.MathUtils.clamp(
screenX + annotation.offset[0],
18,
width - 180
);
const labelY = THREE.MathUtils.clamp(
screenY + annotation.offset[1],
86,
height - 52
);
annotation.element.style.left = `${labelX}px`;
annotation.element.style.top = `${labelY}px`;
annotation.line.setAttribute("x1", screenX);
annotation.line.setAttribute("y1", screenY);
annotation.line.setAttribute("x2", labelX + 9);
annotation.line.setAttribute("y2", labelY + 12);
annotation.line.setAttribute("stroke", annotation.color);
}
}
function onResize() {
const width = window.innerWidth;
const height = window.innerHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.85));
renderer.setSize(width, height);
}
window.addEventListener("resize", onResize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const time = clock.getElapsedTime();
if (!dragging && performance.now() - lastInteraction > 5000) {
orbit.azimuth += 0.00035;
}
updateCamera();
seed.rotation.y = time * 0.24;
seed.rotation.x = Math.sin(time * 0.37) * 0.13;
const pulse = 1 + Math.sin(time * 2.1) * 0.08;
seedHalo.scale.set(1.45 * pulse, 1.45 * pulse, 1);
seedCore.material.emissiveIntensity = 1.25 + Math.sin(time * 2.1) * 0.14;
for (const unit of soluteUnits) {
unit.group.rotation.y = unit.phase + time * unit.speed;
unit.group.rotation.x = Math.sin(time * 0.45 + unit.phase) * 0.26;
unit.group.position.y =
unit.baseY + Math.sin(time * 0.8 + unit.phase) * 0.075;
}
lattice.scale.setScalar(1 + Math.sin(time * 1.25) * 0.0025);
updateAnnotations();
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>
```