Prompt specification
Build or customize the Three.js 3D scene "Polar and nonpolar molecular proxies" 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: Polar and nonpolar molecular proxies
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/polar-and-nonpolar-molecular-proxies-x1977
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring polar and nonpolar molecular shapes. Build water-like bent dipole models beside nonpolar chain proxies with clearly labeled partial-charge symbols; distinguish partial charges from complete ionic charges. A 3D cutaway view.
Working Three.js Starter (polar-and-nonpolar-molecular-proxies-x1977):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Molecular Polarity — 3D Cutaway Lab</title>
<style>
:root {
color-scheme: dark;
--bg: #07111f;
--panel: rgba(8, 20, 35, 0.82);
--border: rgba(151, 221, 255, 0.18);
--text: #edf8ff;
--muted: #9db2c5;
--cyan: #6ee7ff;
--coral: #ff7482;
--amber: #ffc66d;
--green: #59e4ad;
--purple: #bd9cff;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background:
radial-gradient(circle at 22% 12%, #122c42 0, transparent 34%),
radial-gradient(circle at 78% 18%, #151d36 0, transparent 30%),
var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system,
BlinkMacSystemFont, "Segoe UI", sans-serif;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
.ui {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
}
.header {
position: absolute;
top: 25px;
left: 28px;
max-width: 510px;
text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}
.eyebrow {
margin-bottom: 8px;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(30px, 4vw, 53px);
line-height: 0.98;
letter-spacing: -0.045em;
}
.header p {
max-width: 470px;
margin: 12px 0 0;
color: #b7c9d9;
font-size: 14px;
line-height: 1.55;
}
.panel {
border: 1px solid var(--border);
border-radius: 16px;
background: var(--panel);
box-shadow:
0 18px 50px rgba(0, 0, 0, 0.24),
inset 0 1px 0 rgba(255, 255, 255, 0.04);
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
.legend {
position: absolute;
top: 24px;
right: 24px;
width: 320px;
padding: 16px;
pointer-events: auto;
}
.legend-title {
margin-bottom: 12px;
color: var(--muted);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.legend-row {
display: grid;
grid-template-columns: 48px 1fr;
gap: 11px;
align-items: start;
padding: 10px 0;
}
.legend-row + .legend-row {
border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.symbol {
display: grid;
place-items: center;
width: 44px;
height: 44px;
border-radius: 12px;
font-size: 22px;
font-weight: 900;
}
.symbol.partial {
border: 1px solid rgba(110, 231, 255, 0.48);
background: rgba(110, 231, 255, 0.09);
color: var(--cyan);
}
.symbol.ionic {
border: 1px solid rgba(89, 228, 173, 0.48);
background: rgba(89, 228, 173, 0.09);
color: var(--green);
}
.legend-row strong {
display: block;
margin: 1px 0 4px;
font-size: 12px;
letter-spacing: 0.04em;
}
.legend-row small {
display: block;
color: var(--muted);
font-size: 11px;
line-height: 1.45;
}
.legend-note {
margin: 8px 0 0;
padding-top: 11px;
border-top: 1px solid rgba(255, 255, 255, 0.08);
color: #8199ae;
font-size: 10px;
line-height: 1.45;
}
.controls {
position: absolute;
bottom: 24px;
left: 50%;
display: flex;
gap: 8px;
padding: 8px;
transform: translateX(-50%);
pointer-events: auto;
}
button {
min-height: 36px;
padding: 0 13px;
border: 1px solid rgba(151, 221, 255, 0.16);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: #dceaf5;
font: inherit;
font-size: 11px;
font-weight: 700;
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease,
transform 160ms ease;
}
button:hover {
border-color: rgba(110, 231, 255, 0.48);
background: rgba(110, 231, 255, 0.1);
}
button:active {
transform: translateY(1px);
}
button.active {
border-color: rgba(255, 198, 109, 0.5);
background: rgba(255, 198, 109, 0.12);
color: #ffe0a5;
}
.inspector {
position: absolute;
right: 24px;
bottom: 24px;
width: 300px;
padding: 15px 16px;
pointer-events: auto;
}
.inspector .kicker {
color: var(--cyan);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.inspector h2 {
margin: 6px 0 7px;
font-size: 16px;
}
.inspector p {
margin: 0;
color: var(--muted);
font-size: 11px;
line-height: 1.55;
}
.help {
position: absolute;
bottom: 30px;
left: 28px;
color: #849caf;
font-size: 10px;
line-height: 1.65;
}
.help strong {
color: #c6d7e4;
}
#loading {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
background: #07111f;
color: var(--cyan);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.18em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 900px) {
.header {
top: 18px;
left: 18px;
max-width: 420px;
}
.header p {
display: none;
}
.legend {
top: 18px;
right: 18px;
width: 260px;
padding: 12px;
}
.legend-row {
grid-template-columns: 39px 1fr;
gap: 8px;
}
.symbol {
width: 36px;
height: 36px;
font-size: 18px;
}
.inspector {
right: 18px;
bottom: 76px;
width: 250px;
}
.controls {
bottom: 14px;
}
.help {
display: none;
}
}
@media (max-width: 620px) {
h1 {
font-size: 30px;
}
.legend {
top: 104px;
right: 12px;
width: 224px;
}
.legend-title,
.legend-note {
display: none;
}
.legend-row {
padding: 7px 0;
}
.legend-row small {
font-size: 9px;
}
.inspector {
display: none;
}
.controls {
width: calc(100% - 20px);
justify-content: center;
gap: 5px;
}
button {
padding: 0 9px;
font-size: 10px;
}
}
</style>
</head>
<body>
<div id="scene"></div>
<div class="ui">
<header class="header">
<div class="eyebrow">Molecular polarity · 3D cutaway lab</div>
<h1>Where charge hides.</h1>
<p>
Polar molecules distribute electron density unevenly, while nonpolar
chains share it more evenly. The foreground ion pair provides a complete
ionic-charge reference.
</p>
</header>
<section class="panel legend" aria-label="Charge legend">
<div class="legend-title">Charge key</div>
<div class="legend-row">
<div class="symbol partial">δ±</div>
<div>
<strong>PARTIAL CHARGE</strong>
<small>
Unequal sharing within a covalent bond. δ− is partially negative;
δ+ is partially positive.
</small>
</div>
</div>
<div class="legend-row">
<div class="symbol ionic">±</div>
<div>
<strong>COMPLETE IONIC CHARGE</strong>
<small>
Near-complete electron transfer. Na⁺ has +1 and Cl⁻ has −1 as
whole ions.
</small>
</div>
</div>
<p class="legend-note">
δ symbols represent fractional charge, not one whole electron.
Click any atom in the scene for more detail.
</p>
</section>
<section class="panel inspector" aria-live="polite">
<div class="kicker">Atom inspector</div>
<h2 id="atom-title">Select an atom</h2>
<p id="atom-detail">
The cutaway front wall is removed by default. Use the controls to
restore it, rotate the chamber, or reset the camera.
</p>
</section>
<div class="panel controls" aria-label="Scene controls">
<button id="shell-button" type="button">Restore front wall</button>
<button id="rotate-button" type="button">Auto rotate: off</button>
<button id="reset-button" type="button">Reset view</button>
</div>
<div class="help">
<strong>Drag</strong> to orbit · <strong>Scroll / pinch</strong> to zoom<br />
<strong>Click</strong> an atom to inspect its charge
</div>
</div>
<div id="loading">Assembling charge field…</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.getElementById("scene");
const loading = document.getElementById("loading");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x07111f);
scene.fog = new THREE.FogExp2(0x07111f, 0.018);
const camera = new THREE.PerspectiveCamera(
42,
innerWidth / innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({
antialias: true,
powerPreference: "high-performance"
});
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbfe9ff, 0x111523, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.8);
keyLight.position.set(-5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 10;
keyLight.shadow.camera.bottom = -10;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 35;
keyLight.shadow.bias = -0.0008;
scene.add(keyLight);
const cyanLight = new THREE.PointLight(0x35cfff, 38, 16, 2);
cyanLight.position.set(-5, 4, 3);
scene.add(cyanLight);
const violetLight = new THREE.PointLight(0x8d75ff, 32, 15, 2);
violetLight.position.set(6, 3, -2);
scene.add(violetLight);
const materials = {
base: new THREE.MeshStandardMaterial({
color: 0x111d2a,
roughness: 0.68,
metalness: 0.28
}),
polarDeck: new THREE.MeshStandardMaterial({
color: 0x0c2935,
roughness: 0.62,
metalness: 0.2
}),
neutralDeck: new THREE.MeshStandardMaterial({
color: 0x1b2530,
roughness: 0.67,
metalness: 0.18
}),
oxygen: new THREE.MeshStandardMaterial({
color: 0xff5968,
emissive: 0x3a050b,
emissiveIntensity: 0.5,
roughness: 0.28,
metalness: 0.08
}),
hydrogen: new THREE.MeshStandardMaterial({
color: 0xeef9ff,
emissive: 0x173b4b,
emissiveIntensity: 0.16,
roughness: 0.24
}),
carbon: new THREE.MeshStandardMaterial({
color: 0x697789,
emissive: 0x101923,
emissiveIntensity: 0.18,
roughness: 0.4,
metalness: 0.22
}),
sodium: new THREE.MeshStandardMaterial({
color: 0xba8cff,
emissive: 0x38176b,
emissiveIntensity: 0.68,
roughness: 0.25,
metalness: 0.18
}),
chlorine: new THREE.MeshStandardMaterial({
color: 0x4be2a3,
emissive: 0x07563b,
emissiveIntensity: 0.58,
roughness: 0.27,
metalness: 0.12
}),
bond: new THREE.MeshStandardMaterial({
color: 0xb7cad6,
roughness: 0.48,
metalness: 0.12
}),
carbonBond: new THREE.MeshStandardMaterial({
color: 0x9eafbd,
roughness: 0.55,
metalness: 0.1
}),
glass: new THREE.MeshPhysicalMaterial({
color: 0x9fdcff,
transparent: true,
opacity: 0.075,
roughness: 0.18,
metalness: 0,
transmission: 0.2,
depthWrite: false,
side: THREE.DoubleSide
}),
cutEdge: new THREE.MeshStandardMaterial({
color: 0xffbd60,
emissive: 0x5b3100,
emissiveIntensity: 0.6,
roughness: 0.35
})
};
const atomMeshes = [];
const animatedMolecules = [];
// -------------------------------------------------------------------------
// Canvas-based labels. These are ordinary Three.js sprites, so no addons are
// required.
// -------------------------------------------------------------------------
function roundedRect(ctx, x, y, width, height, radius) {
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.arcTo(x + width, y, x + width, y + height, radius);
ctx.arcTo(x + width, y + height, x, y + height, radius);
ctx.arcTo(x, y + height, x, y, radius);
ctx.arcTo(x, y, x + width, y, radius);
ctx.closePath();
}
function makeLabel(title, subtitle = "", options = {}) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 210;
const ctx = canvas.getContext("2d");
const color = options.color || "#dff7ff";
const accent = options.accent || color;
const background = options.background || "rgba(6, 18, 31, 0.92)";
const fontSize = options.fontSize || 88;
ctx.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(
ctx,
5,
5,
canvas.width - 10,
canvas.height - 10,
options.radius ?? 38
);
ctx.fillStyle = background;
ctx.fill();
ctx.lineWidth = options.borderWidth || 6;
ctx.strokeStyle = options.border || accent;
ctx.stroke();
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = color;
ctx.font = `800 ${fontSize}px Inter, system-ui, sans-serif`;
if (subtitle) {
ctx.fillText(title, canvas.width / 2, 79);
ctx.fillStyle = options.subColor || accent;
ctx.font = `700 31px Inter, system-ui, sans-serif`;
ctx.fillText(subtitle, canvas.width / 2, 151);
} else {
ctx.fillText(title, canvas.width / 2, canvas.height / 2 + 2);
}
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
texture.magFilter = THREE.LinearFilter;
texture.generateMipmaps = false;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
const width = options.width || 1.2;
sprite.scale.set(width, width / (canvas.width / canvas.height), 1);
sprite.renderOrder = 30;
return sprite;
}
function addEdges(mesh, color = 0x8edfff, opacity = 0.3) {
const edge = new THREE.LineSegments(
new THREE.EdgesGeometry(mesh.geometry),
new THREE.LineBasicMaterial({
color,
transparent: true,
opacity
})
);
edge.renderOrder = 2;
mesh.add(edge);
return edge;
}
function box(width, height, depth, x, y, z, material, parent = scene) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function cylinderBetween(a, b, radius, material, parent) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
const midpoint = new THREE.Vector3()
.addVectors(a, b)
.multiplyScalar(0.5);
const mesh = new THREE.Mesh(
new THREE.CylinderGeometry(radius, radius, length, 20),
material
);
mesh.position.copy(midpoint);
mesh.quaternion.setFromUnitVectors(
new THREE.Vector3(0, 1, 0),
direction.normalize()
);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addAtom(parent, position, radius, material, info) {
const mesh = new THREE.Mesh(
new THREE.SphereGeometry(radius, 32, 24),
material
);
mesh.position.copy(position);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.info = info;
parent.add(mesh);
atomMeshes.push(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Cutaway chamber: back and side walls remain, while the front pane can be
// restored. Amber edges expose the sectioned wall faces.
// -------------------------------------------------------------------------
const chamber = new THREE.Group();
scene.add(chamber);
const base = box(16, 0.46, 8, 0, -0.25, 0, materials.base, chamber);
addEdges(base, 0x8bdfff, 0.2);
const polarDeck = box(
6.75,
0.09,
6.75,
-3.72,
0.025,
0,
materials.polarDeck,
chamber
);
addEdges(polarDeck, 0x62dfff, 0.22);
const neutralDeck = box(
6.75,
0.09,
6.75,
3.72,
0.025,
0,
materials.neutralDeck,
chamber
);
addEdges(neutralDeck, 0xa7b7c8, 0.18);
const gridOptions = {
transparent: true,
opacity: 0.11,
depthWrite: false
};
const leftGrid = new THREE.GridHelper(
6.65,
13,
0x4fd8ff,
0x23556b
);
leftGrid.position.set(-3.72, 0.078, 0);
leftGrid.material = new THREE.LineBasicMaterial(gridOptions);
chamber.add(leftGrid);
const rightGrid = new THREE.GridHelper(
6.65,
13,
0xaec5d7,
0x354554
);
rightGrid.position.set(3.72, 0.078, 0);
rightGrid.material = new THREE.LineBasicMaterial(gridOptions);
chamber.add(rightGrid);
const backWall = box(
15.7,
5.45,
0.14,
0,
2.68,
-3.86,
materials.glass,
chamber
);
backWall.castShadow = false;
addEdges(backWall, 0x70cbe8, 0.22);
const leftWall = box(
0.14,
5.45,
7.75,
-7.83,
2.68,
0,
materials.glass,
chamber
);
leftWall.castShadow = false;
addEdges(leftWall, 0x70cbe8, 0.22);
const rightWall = box(
0.14,
5.45,
7.75,
7.83,
2.68,
0,
materials.glass,
chamber
);
rightWall.castShadow = false;
addEdges(rightWall, 0x70cbe8, 0.22);
// Amber section edges emphasize the intentionally removed front.
box(0.08, 5.45, 0.08, -7.83, 2.68, 3.86, materials.cutEdge, chamber);
box(0.08, 5.45, 0.08, 7.83, 2.68, 3.86, materials.cutEdge, chamber);
box(15.72, 0.07, 0.07, 0, 5.4, 3.86, materials.cutEdge, chamber);
box(15.72, 0.07, 0.07, 0, -0.04, 3.86, materials.cutEdge, chamber);
const frontPaneGroup = new THREE.Group();
scene.add(frontPaneGroup);
const frontPane = box(
15.55,
5.35,
0.08,
0,
2.67,
3.87,
materials.glass,
frontPaneGroup
);
frontPane.castShadow = false;
addEdges(frontPane, 0x8bdfff, 0.18);
frontPaneGroup.visible = false;
// Low divider between the comparison zones.
box(
0.055,
1.3,
4.45,
0.25,
0.69,
-0.75,
new THREE.MeshStandardMaterial({
color: 0x4f7189,
transparent: true,
opacity: 0.35,
roughness: 0.5
}),
chamber
);
const polarHeader = makeLabel(
"POLAR · BENT",
"covalent δ charge • net dipole μ ≠ 0",
{
width: 4.55,
color: "#e8fbff",
accent: "#66e6ff",
border: "rgba(102,230,255,0.65)"
}
);
polarHeader.position.set(-3.65, 4.35, -3.67);
scene.add(polarHeader);
const neutralHeader = makeLabel(
"NONPOLAR · CHAIN PROXY",
"shared more evenly • net dipole μ = 0",
{
width: 4.65,
color: "#eef5fb",
accent: "#b7c8d7",
border: "rgba(183,200,215,0.52)"
}
);
neutralHeader.position.set(3.72, 4.35, -3.67);
scene.add(neutralHeader);
// -------------------------------------------------------------------------
// Polar water-like bent molecules.
// -------------------------------------------------------------------------
function createWater(position, rotation, scale, phase) {
const group = new THREE.Group();
group.position.copy(position);
group.rotation.set(rotation.x, rotation.y, rotation.z);
group.scale.setScalar(scale);
scene.add(group);
const oxygenPosition = new THREE.Vector3(0, 0, 0);
const bondLength = 1.02;
const halfAngle = THREE.MathUtils.degToRad(104.5 / 2);
const h1Position = new THREE.Vector3(
Math.sin(halfAngle) * bondLength,
Math.cos(halfAngle) * bondLength,
0
);
const h2Position = new THREE.Vector3(
Math.sin(halfAngle) * bondLength,
-Math.cos(halfAngle) * bondLength,
0
);
addAtom(
group,
oxygenPosition,
0.4,
materials.oxygen,
{
title: "Oxygen · δ−",
detail:
"Partial negative charge. The O–H bonds pull electron density toward oxygen, but the charge is fractional because the electrons are shared rather than fully transferred."
}
);
addAtom(
group,
h1Position,
0.235,
materials.hydrogen,
{
title: "Hydrogen · δ+",
detail:
"Partial positive charge. Hydrogen is electron-poor in the polar O–H bond. δ+ is a fraction of a positive charge, not a complete +1 ionic charge."
}
);
addAtom(
group,
h2Position,
0.235,
materials.hydrogen,
{
title: "Hydrogen · δ+",
detail:
"Partial positive charge. Hydrogen is electron-poor in the polar O–H bond. δ+ is a fraction of a positive charge, not a complete +1 ionic charge."
}
);
cylinderBetween(
oxygenPosition,
h1Position,
0.095,
materials.bond,
group
);
cylinderBetween(
oxygenPosition,
h2Position,
0.095,
materials.bond,
group
);
const negativeLabel = makeLabel("δ−", "PARTIAL", {
width: 1.04,
color: "#ff8b96",
accent: "#ff7482",
border: "rgba(255,116,130,0.68)",
fontSize: 76
});
negativeLabel.position.set(-0.04, 0.66, 0.12);
group.add(negativeLabel);
const positiveLabelA = makeLabel("δ+", "", {
width: 0.68,
color: "#7cecff",
accent: "#6ee7ff",
border: "rgba(110,231,255,0.68)",
fontSize: 92
});
positiveLabelA.position.copy(h1Position).add(new THREE.Vector3(0.08, 0.31, 0.12));
group.add(positiveLabelA);
const positiveLabelB = makeLabel("δ+", "", {
width: 0.68,
color: "#7cecff",
accent: "#6ee7ff",
border: "rgba(110,231,255,0.68)",
fontSize: 92
});
positiveLabelB.position.copy(h2Position).add(new THREE.Vector3(0.08, -0.31, 0.12));
group.add(positiveLabelB);
// Dipole arrow points from the negative end toward the positive end.
const arrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-0.05, 0, -0.32),
1.22,
0x65e7ff,
0.28,
0.18
);
group.add(arrow);
const muLabel = makeLabel("μ", "", {
width: 0.38,
color: "#8cf0ff",
accent: "#65e7ff",
background: "rgba(5,24,38,0.78)",
fontSize: 95
});
muLabel.position.set(1.32, 0.02, -0.3);
group.add(muLabel);
animatedMolecules.push({
group,
baseY: position.y,
phase,
rotationBase: rotation.y
});
return group;
}
createWater(
new THREE.Vector3(-5.25, 1.58, 0.42),
new THREE.Euler(0.12, -0.28, -0.08),
1.03,
0.2
);
createWater(
new THREE.Vector3(-3.6, 2.4, -1.18),
new THREE.Euler(-0.08, 2.58, 0.13),
0.91,
2.1
);
createWater(
new THREE.Vector3(-2.45, 1.28, 1.02),
new THREE.Euler(0.08, 0.34, -0.1),
0.88,
4.4
);
// -------------------------------------------------------------------------
// Nonpolar chain proxies.
// -------------------------------------------------------------------------
function createChain(position, scale, carbonCount, rotation, phase) {
const group = new THREE.Group();
group.position.copy(position);
group.rotation.copy(rotation);
group.scale.setScalar(scale);
scene.add(group);
const carbons = [];
const spacing = 0.78;
for (let i = 0; i < carbonCount; i++) {
carbons.push(
new THREE.Vector3(
(i - (carbonCount - 1) / 2) * spacing,
i % 2 === 0 ? -0.25 : 0.25,
0
)
);
}
carbons.forEach((carbonPosition, index) => {
addAtom(
group,
carbonPosition,
0.31,
materials.carbon,
{
title: "Carbon · no partial-charge label",
detail:
"This proxy represents an approximately nonpolar carbon chain. Its modeled bond dipoles are balanced, so the molecule has no net dipole moment."
}
);
if (index < carbonCount - 1) {
cylinderBetween(
carbonPosition,
carbons[index + 1],
0.09,
materials.carbonBond,
group
);
}
});
// Approximate tetrahedral hydrogens around the zigzag carbon backbone.
carbons.forEach((carbonPosition, index) => {
const hydrogens = [];
if (index === 0) {
const direction = carbons[1].clone().sub(carbonPosition).normalize();
hydrogens.push(
carbonPosition.clone().addScaledVector(direction, -0.63).add(new THREE.Vector3(0, 0.1, 0.3)),
carbonPosition.clone().addScaledVector(direction, -0.49).add(new THREE.Vector3(0, 0.15, -0.42))
);
} else if (index === carbonCount - 1) {
const direction = carbonPosition.clone().sub(carbons[index - 1]).normalize();
hydrogens.push(
carbonPosition.clone().addScaledVector(direction, 0.63).add(new THREE.Vector3(0, 0.1, 0.3)),
carbonPosition.clone().addScaledVector(direction, 0.49).add(new THREE.Vector3(0, 0.15, -0.42))
);
} else {
const tangent = carbons[index + 1]
.clone()
.sub(carbons[index - 1])
.normalize();
const perpendicular = new THREE.Vector3(
-tangent.y,
tangent.x,
0
).normalize();
hydrogens.push(
carbonPosition
.clone()
.addScaledVector(perpendicular, 0.58)
.add(new THREE.Vector3(0, 0, 0.36)),
carbonPosition
.clone()
.addScaledVector(perpendicular, 0.58)
.add(new THREE.Vector3(0, 0, -0.36))
);
}
hydrogens.forEach((hydrogenPosition) => {
addAtom(
group,
hydrogenPosition,
0.15,
materials.hydrogen,
{
title: "Hydrogen · no partial-charge label",
detail:
"In this nonpolar chain proxy, bond polarity is not presented as a localized δ separation. The modeled bond dipoles cancel, giving a net dipole moment of zero."
}
);
cylinderBetween(
carbonPosition,
hydrogenPosition,
0.052,
materials.carbonBond,
group
);
});
});
const label = makeLabel("NO δ SEPARATION", "equal sharing • μ = 0", {
width: 2.25,
color: "#eff7fd",
accent: "#b9cad8",
border: "rgba(185,202,216,0.55)",
fontSize: 65
});
label.position.set(0, 1.02, 0.05);
group.add(label);
animatedMolecules.push({
group,
baseY: position.y,
phase,
rotationBase: rotation.y
});
return group;
}
createChain(
new THREE.Vector3(4.05, 1.38, 0.54),
1.16,
5,
new THREE.Euler(0.02, -0.16, -0.07),
1.3
);
createChain(
new THREE.Vector3(4.36, 2.52, -1.55),
0.74,
4,
new THREE.Euler(-0.03, 0.34, 0.1),
3.7
);
// -------------------------------------------------------------------------
// Complete ionic-charge reference: Na⁺ and Cl⁻.
// -------------------------------------------------------------------------
const ionicGroup = new THREE.Group();
ionicGroup.position.set(0.1, 0, 2.62);
scene.add(ionicGroup);
const plinth = new THREE.Mesh(
new THREE.CylinderGeometry(1.22, 1.32, 0.2, 64),
new THREE.MeshStandardMaterial({
color: 0x182536,
roughness: 0.42,
metalness: 0.42
})
);
plinth.position.y = 0.16;
plinth.castShadow = true;
plinth.receiveShadow = true;
ionicGroup.add(plinth);
addEdges(plinth, 0xb79cff, 0.25);
const sodiumPosition = new THREE.Vector3(-0.51, 0.64, 0);
const chlorinePosition = new THREE.Vector3(0.51, 0.64, 0);
addAtom(
ionicGroup,
sodiumPosition,
0.34,
materials.sodium,
{
title: "Sodium ion · +1",
detail:
"Complete ionic charge. Sodium has approximately lost one electron, so the ion carries a whole +1 charge. This is not a δ partial charge."
}
);
addAtom(
ionicGroup,
chlorinePosition,
0.34,
materials.chlorine,
{
title: "Chloride ion · −1",
detail:
"Complete ionic charge. Chloride has approximately gained one electron, so the ion carries a whole −1 charge. This is not a δ partial charge."
}
);
const sodiumLabel = makeLabel("Na⁺", "COMPLETE +1", {
width: 1.32,
color: "#d8c5ff",
accent: "#bd9cff",
border: "rgba(189,156,255,0.8)",
background: "rgba(24,13,47,0.94)",
fontSize: 79
});
sodiumLabel.position.copy(sodiumPosition).add(new THREE.Vector3(0, 0.56, 0));
ionicGroup.add(sodiumLabel);
const chlorineLabel = makeLabel("Cl⁻", "COMPLETE −1", {
width: 1.32,
color: "#b8ffe0",
accent: "#59e4ad",
border: "rgba(89,228,173,0.8)",
background: "rgba(7,39,31,0.94)",
fontSize: 79
});
chlorineLabel.position.copy(chlorinePosition).add(new THREE.Vector3(0, 0.56, 0));
ionicGroup.add(chlorineLabel);
const ionicHeading = makeLabel(
"IONIC REFERENCE",
"whole-electron transfer • not δ",
{
width: 2.55,
color: "#f1f7ff",
accent: "#bd9cff",
border: "rgba(189,156,255,0.62)",
fontSize: 62
}
);
ionicHeading.position.set(0, 1.63, 0);
ionicGroup.add(ionicHeading);
const attractionLine = new THREE.Line(
new THREE.BufferGeometry().setFromPoints([
sodiumPosition,
chlorinePosition
]),
new THREE.LineDashedMaterial({
color: 0xbda5ff,
dashSize: 0.12,
gapSize: 0.1,
transparent: true,
opacity: 0.55,
depthWrite: false
})
);
attractionLine.computeLineDistances();
ionicGroup.add(attractionLine);
const cutawayLabel = makeLabel(
"3D CUTAWAY",
"front wall removed",
{
width: 2.2,
color: "#ffe2aa",
accent: "#ffc66d",
border: "rgba(255,198,109,0.58)",
background: "rgba(39,25,9,0.92)",
fontSize: 68
}
);
cutawayLabel.position.set(0.1, 0.23, 3.48);
scene.add(cutawayLabel);
// A broad shadow-receiving floor extends beyond the model.
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x07101b,
roughness: 0.96,
metalness: 0.03
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.505;
floor.receiveShadow = true;
scene.add(floor);
// -------------------------------------------------------------------------
// Direct camera controls — implemented without Three.js addons.
// -------------------------------------------------------------------------
const target = new THREE.Vector3(0, 1.0, 0);
const desired = {
theta: 0.58,
phi: 1.04,
radius: innerWidth / innerHeight < 1.1 ? 22.5 : 18.7
};
const current = {
theta: desired.theta,
phi: desired.phi,
radius: desired.radius
};
let dragging = false;
let pointerId = null;
let previousX = 0;
let previousY = 0;
let dragDistance = 0;
let autoRotate = false;
function updateCamera(delta) {
if (autoRotate && !dragging) {
desired.theta += delta * 0.075;
}
const smoothing = 1 - Math.exp(-delta * 10);
current.theta += (desired.theta - current.theta) * smoothing;
current.phi += (desired.phi - current.phi) * smoothing;
current.radius += (desired.radius - current.radius) * smoothing;
const sinPhi = Math.sin(current.phi);
camera.position.set(
target.x + current.radius * sinPhi * Math.sin(current.theta),
target.y + current.radius * Math.cos(current.phi),
target.z + current.radius * sinPhi * Math.cos(current.theta)
);
camera.lookAt(target);
}
function resetCamera() {
desired.theta = 0.58;
desired.phi = 1.04;
desired.radius = innerWidth / innerHeight < 1.1 ? 22.5 : 18.7;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerId = event.pointerId;
previousX = event.clientX;
previousY = event.clientY;
dragDistance = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.style.cursor = "grabbing";
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging || event.pointerId !== pointerId) {
renderer.domElement.style.cursor = "pointer";
return;
}
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
previousX = event.clientX;
previousY = event.clientY;
dragDistance += Math.abs(dx) + Math.abs(dy);
desired.theta -= dx * 0.006;
desired.phi = THREE.MathUtils.clamp(
desired.phi - dy * 0.005,
0.32,
1.43
);
});
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function inspectAt(clientX, clientY) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(atomMeshes, false);
if (hits.length) {
const info = hits[0].object.userData.info;
document.getElementById("atom-title").textContent = info.title;
document.getElementById("atom-detail").textContent = info.detail;
}
}
function endPointer(event) {
if (!dragging || event.pointerId !== pointerId) {
return;
}
dragging = false;
renderer.domElement.style.cursor = "pointer";
if (renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (dragDistance < 6) {
inspectAt(event.clientX, event.clientY);
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
desired.radius = THREE.MathUtils.clamp(
desired.radius + event.deltaY * 0.012,
11,
29
);
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
// -------------------------------------------------------------------------
// UI controls.
// -------------------------------------------------------------------------
const shellButton = document.getElementById("shell-button");
const rotateButton = document.getElementById("rotate-button");
const resetButton = document.getElementById("reset-button");
shellButton.addEventListener("click", () => {
frontPaneGroup.visible = !frontPaneGroup.visible;
shellButton.textContent = frontPaneGroup.visible
? "Remove front wall"
: "Restore front wall";
shellButton.classList.toggle("active", frontPaneGroup.visible);
});
rotateButton.addEventListener("click", () => {
autoRotate = !autoRotate;
rotateButton.textContent = `Auto rotate: ${autoRotate ? "on" : "off"}`;
rotateButton.classList.toggle("active", autoRotate);
});
resetButton.addEventListener("click", resetCamera);
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetCamera();
}
if (event.code === "Space") {
event.preventDefault();
rotateButton.click();
}
});
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
const minimumRadius = innerWidth / innerHeight < 1.1 ? 22.5 : 18.7;
desired.radius = Math.max(desired.radius, minimumRadius);
});
// -------------------------------------------------------------------------
// Render loop.
// -------------------------------------------------------------------------
const clock = new THREE.Clock();
function animate() {
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
animatedMolecules.forEach((item) => {
item.group.position.y =
item.baseY + Math.sin(elapsed * 0.72 + item.phase) * 0.065;
item.group.rotation.y =
item.rotationBase + Math.sin(elapsed * 0.31 + item.phase) * 0.055;
});
updateCamera(delta);
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
updateCamera(1);
renderer.render(scene, camera);
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 450);
});
</script>
</body>
</html>
```