Prompt specification
Build or customize the Three.js 3D scene "Pressure-temperature phase-map sculpture" 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: Pressure-temperature phase-map sculpture
Category: Science & Physics · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/pressure-temperature-phase-map-sculpture-x1973
Scene Description Prompt:
A cutaway-style 3D schematic phase map with pressure, temperature, and solid/liquid/gas regions. Three.js from cdnjs, one HTML file.
Working Three.js Starter (pressure-temperature-phase-map-sculpture-x1973):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pressure–Temperature Phase Map</title>
<style>
:root {
--bg: #050b14;
--panel: rgba(10, 21, 35, 0.76);
--panel-border: rgba(151, 205, 235, 0.15);
--text: #eaf7ff;
--muted: #8ea8ba;
--cyan: #51d8ff;
--violet: #a985ff;
--orange: #ffad68;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body::before {
content: "";
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 48% 48%, rgba(32, 89, 125, 0.12), transparent 36%),
radial-gradient(circle at 78% 18%, rgba(125, 79, 199, 0.09), transparent 28%),
linear-gradient(180deg, rgba(4, 10, 18, 0.12), rgba(4, 10, 18, 0.78));
}
#app,
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
cursor: grab;
touch-action: none;
}
#scene canvas.dragging {
cursor: grabbing;
}
header {
position: fixed;
z-index: 10;
top: 28px;
left: 32px;
pointer-events: none;
max-width: 520px;
}
.eyebrow {
display: flex;
align-items: center;
gap: 10px;
color: #82a9bf;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.23em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: var(--cyan);
box-shadow: 0 0 10px rgba(81, 216, 255, 0.65);
}
h1 {
margin: 12px 0 8px;
font-size: clamp(28px, 3.5vw, 48px);
line-height: 0.98;
letter-spacing: -0.045em;
font-weight: 650;
}
h1 span {
color: #829db0;
font-weight: 400;
}
.subtitle {
margin: 0;
color: var(--muted);
font-size: 13px;
line-height: 1.6;
max-width: 430px;
}
.diagram-tag {
display: inline-flex;
align-items: center;
gap: 8px;
margin-top: 14px;
padding: 7px 10px;
border: 1px solid rgba(81, 216, 255, 0.18);
border-radius: 999px;
background: rgba(9, 25, 40, 0.52);
color: #9fc4d8;
font-size: 9px;
font-weight: 700;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.diagram-tag i {
width: 5px;
height: 5px;
border-radius: 50%;
background: var(--cyan);
box-shadow: 0 0 9px var(--cyan);
}
.glass-panel {
border: 1px solid var(--panel-border);
background: var(--panel);
box-shadow:
0 18px 55px rgba(0, 0, 0, 0.25),
inset 0 1px rgba(255, 255, 255, 0.025);
backdrop-filter: blur(18px);
-webkit-backdrop-filter: blur(18px);
}
.legend {
position: fixed;
z-index: 10;
top: 28px;
right: 28px;
width: 238px;
padding: 17px;
border-radius: 16px;
}
.panel-title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 13px;
color: #7f9bad;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.17em;
text-transform: uppercase;
}
.panel-title span:last-child {
color: #547184;
font-size: 8px;
}
.legend-row {
display: grid;
grid-template-columns: 28px 1fr;
gap: 10px;
align-items: center;
padding: 10px 5px;
border-top: 1px solid rgba(151, 205, 235, 0.08);
cursor: default;
transition: background 180ms ease;
}
.legend-row:first-of-type {
border-top: 0;
}
.legend-row:hover {
background: rgba(255, 255, 255, 0.025);
}
.phase-swatch {
position: relative;
width: 27px;
height: 27px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.11);
overflow: hidden;
}
.phase-swatch::after {
content: "";
position: absolute;
inset: 0;
background: repeating-linear-gradient(
135deg,
transparent 0 5px,
rgba(255, 255, 255, 0.14) 5px 6px
);
}
.phase-swatch.solid {
background: linear-gradient(145deg, #1cc7ec, #12617f);
}
.phase-swatch.liquid {
background: linear-gradient(145deg, #aa84ff, #533aa4);
}
.phase-swatch.gas {
background: linear-gradient(145deg, #ffb56f, #a64f2c);
}
.legend-row strong {
display: block;
margin-bottom: 3px;
font-size: 12px;
font-weight: 650;
}
.legend-row small {
display: block;
color: #718b9d;
font-size: 9px;
line-height: 1.35;
}
.probe-panel {
position: fixed;
z-index: 10;
left: 28px;
bottom: 28px;
width: 246px;
padding: 15px 16px;
border-radius: 15px;
}
.probe-grid {
display: grid;
grid-template-columns: 1fr 1fr 1.2fr;
gap: 8px;
margin-top: 12px;
}
.metric {
min-width: 0;
}
.metric small {
display: block;
margin-bottom: 5px;
color: #617c8f;
font-size: 8px;
font-weight: 750;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.metric strong {
display: block;
overflow: hidden;
color: #dff4ff;
font-size: 13px;
font-weight: 650;
text-overflow: ellipsis;
white-space: nowrap;
}
#probe-phase {
color: var(--orange);
}
.toolbar {
position: fixed;
z-index: 12;
right: 28px;
bottom: 28px;
display: flex;
gap: 8px;
padding: 8px;
border-radius: 15px;
}
button {
appearance: none;
border: 1px solid rgba(142, 193, 221, 0.13);
border-radius: 10px;
background: rgba(255, 255, 255, 0.025);
color: #90adbe;
padding: 10px 12px;
font: inherit;
font-size: 9px;
font-weight: 750;
letter-spacing: 0.1em;
text-transform: uppercase;
cursor: pointer;
transition:
color 160ms ease,
border-color 160ms ease,
background 160ms ease;
}
button:hover,
button.active {
color: #e8f8ff;
border-color: rgba(81, 216, 255, 0.38);
background: rgba(81, 216, 255, 0.08);
}
.hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 31px;
transform: translateX(-50%);
color: rgba(132, 164, 184, 0.55);
font-size: 9px;
font-weight: 650;
letter-spacing: 0.12em;
text-transform: uppercase;
pointer-events: none;
white-space: nowrap;
}
#labels {
position: fixed;
inset: 0;
z-index: 5;
pointer-events: none;
transition: opacity 180ms ease;
}
#labels.labels-off {
opacity: 0;
}
.scene-label {
position: absolute;
top: 0;
left: 0;
will-change: transform;
white-space: nowrap;
transition: opacity 120ms ease;
}
.phase-label {
display: flex;
align-items: center;
gap: 8px;
padding: 7px 10px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(5, 13, 23, 0.62);
box-shadow: 0 7px 25px rgba(0, 0, 0, 0.22);
color: #e9f8ff;
font-size: 10px;
font-weight: 750;
letter-spacing: 0.16em;
text-transform: uppercase;
backdrop-filter: blur(8px);
}
.phase-label i {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--color);
box-shadow: 0 0 10px var(--color);
}
.boundary-label {
padding: 4px 7px;
border-radius: 5px;
background: rgba(5, 13, 23, 0.66);
color: #a9c1cf;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.axis-label {
color: #9db8c8;
font-size: 9px;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
.axis-label small {
display: block;
margin-top: 3px;
color: #587286;
font-size: 7px;
letter-spacing: 0.1em;
text-align: center;
}
.tick-label {
color: #587286;
font-size: 7px;
font-weight: 650;
}
.point-label {
padding: 5px 8px;
border-left: 1px solid rgba(255, 255, 255, 0.25);
background: rgba(5, 13, 23, 0.64);
color: #c2d6e2;
font-size: 7px;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
#tooltip {
position: fixed;
z-index: 30;
top: 0;
left: 0;
padding: 8px 11px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(5, 13, 23, 0.88);
color: #e9f8ff;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.09em;
text-transform: uppercase;
pointer-events: none;
opacity: 0;
transform: translate(14px, 14px);
transition: opacity 100ms ease;
backdrop-filter: blur(10px);
}
#tooltip.visible {
opacity: 1;
}
#loading {
position: fixed;
z-index: 50;
inset: 0;
display: grid;
place-items: center;
background: #050b14;
color: #7796a9;
font-size: 10px;
font-weight: 700;
letter-spacing: 0.2em;
text-transform: uppercase;
transition: opacity 400ms ease;
}
#loading.hidden {
opacity: 0;
pointer-events: none;
}
@media (max-width: 800px) {
header {
top: 18px;
left: 18px;
}
.subtitle,
.diagram-tag {
display: none;
}
.legend {
top: 18px;
right: 18px;
width: 170px;
padding: 12px;
}
.legend-row {
grid-template-columns: 24px 1fr;
gap: 8px;
padding: 8px 2px;
}
.legend-row small {
display: none;
}
.phase-swatch {
width: 23px;
height: 23px;
}
.probe-panel {
left: 18px;
bottom: 18px;
width: 210px;
}
.toolbar {
right: 18px;
bottom: 18px;
flex-direction: column;
}
button {
padding: 9px;
font-size: 8px;
}
.hint {
display: none;
}
}
</style>
</head>
<body>
<div id="app">
<div id="scene"></div>
<header>
<div class="eyebrow">Thermodynamics / schematic 01</div>
<h1>Phase map <span>/ cutaway</span></h1>
<p class="subtitle">
A three-dimensional pressure–temperature field separating solid,
liquid, and gas domains.
</p>
<div class="diagram-tag"><i></i> Interactive sectional model</div>
</header>
<aside class="legend glass-panel">
<div class="panel-title">
<span>Phase domains</span>
<span>T–P field</span>
</div>
<div class="legend-row" data-phase="solid">
<div class="phase-swatch solid"></div>
<div>
<strong>Solid</strong>
<small>Low-temperature, ordered domain</small>
</div>
</div>
<div class="legend-row" data-phase="liquid">
<div class="phase-swatch liquid"></div>
<div>
<strong>Liquid</strong>
<small>Compressed intermediate domain</small>
</div>
</div>
<div class="legend-row" data-phase="gas">
<div class="phase-swatch gas"></div>
<div>
<strong>Gas</strong>
<small>High-temperature, low-density domain</small>
</div>
</div>
</aside>
<section class="probe-panel glass-panel">
<div class="panel-title">
<span>Field probe</span>
<span>Click diagram</span>
</div>
<div class="probe-grid">
<div class="metric">
<small>Temperature</small>
<strong id="probe-temp">80</strong>
</div>
<div class="metric">
<small>Pressure</small>
<strong id="probe-pressure">30</strong>
</div>
<div class="metric">
<small>Phase</small>
<strong id="probe-phase">Gas</strong>
</div>
</div>
</section>
<nav class="toolbar glass-panel" aria-label="Diagram controls">
<button id="rotate-button" type="button">Auto rotate</button>
<button id="labels-button" type="button">Labels</button>
<button id="reset-button" type="button">Reset view</button>
</nav>
<div class="hint">Drag to orbit · Scroll to zoom · Click to probe</div>
<div id="labels"></div>
<div id="tooltip"></div>
<div id="loading">Building phase field</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 sceneContainer = document.getElementById("scene");
const labelLayer = document.getElementById("labels");
const tooltip = document.getElementById("tooltip");
const loading = document.getElementById("loading");
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.12;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
sceneContainer.appendChild(renderer.domElement);
renderer.domElement.setAttribute(
"aria-label",
"Interactive three-dimensional pressure-temperature phase diagram"
);
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0x07111d, 0.027);
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
100
);
const orbit = {
target: new THREE.Vector3(0, 2.45, 0.52),
yaw: 0.58,
pitch: 0.48,
radius: 12.7
};
function updateCamera() {
const cp = Math.cos(orbit.pitch);
const sp = Math.sin(orbit.pitch);
const cy = Math.cos(orbit.yaw);
const sy = Math.sin(orbit.yaw);
camera.position.set(
orbit.target.x + orbit.radius * cp * sy,
orbit.target.y + orbit.radius * sp,
orbit.target.z + orbit.radius * cp * cy
);
camera.lookAt(orbit.target);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xb8e7ff, 0x07101a, 2.15);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffffff, 3.2);
keyLight.position.set(5, 10, 8);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(2048, 2048);
keyLight.shadow.camera.left = -9;
keyLight.shadow.camera.right = 9;
keyLight.shadow.camera.top = 9;
keyLight.shadow.camera.bottom = -9;
keyLight.shadow.bias = -0.0003;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x8b72ff, 2.1);
rimLight.position.set(-7, 5, -5);
scene.add(rimLight);
const cyanLight = new THREE.PointLight(0x39caff, 14, 13, 2);
cyanLight.position.set(-3, 4, 5);
scene.add(cyanLight);
const orangeLight = new THREE.PointLight(0xff9550, 10, 12, 2);
orangeLight.position.set(5, 1, 3);
scene.add(orangeLight);
const chart = new THREE.Group();
scene.add(chart);
const bounds = {
minX: -4,
maxX: 4,
minY: 0,
maxY: 5.2
};
const TRIPLE = { x: 0.32, y: 0.42 };
function normalizedToWorld(x, y, z = 0) {
return new THREE.Vector3(
THREE.MathUtils.lerp(bounds.minX, bounds.maxX, x),
THREE.MathUtils.lerp(bounds.minY, bounds.maxY, y),
z
);
}
function sublimationX(y) {
const t = THREE.MathUtils.clamp(y / TRIPLE.y, 0, 1);
return THREE.MathUtils.lerp(0.045, TRIPLE.x, Math.pow(t, 1.16));
}
function fusionX(y) {
const t = THREE.MathUtils.clamp(
(y - TRIPLE.y) / (1 - TRIPLE.y),
0,
1
);
return TRIPLE.x + 0.16 * t;
}
function vaporizationX(y) {
const t = THREE.MathUtils.clamp(
(y - TRIPLE.y) / (1 - TRIPLE.y),
0,
1
);
return TRIPLE.x + 0.36 * Math.pow(t, 0.92);
}
function sampledCurve(yStart, yEnd, xFunction, count = 48) {
const points = [];
for (let i = 0; i <= count; i++) {
const y = THREE.MathUtils.lerp(yStart, yEnd, i / count);
points.push({ x: xFunction(y), y });
}
return points;
}
const sublimation = sampledCurve(0, TRIPLE.y, sublimationX);
const fusion = sampledCurve(TRIPLE.y, 1, fusionX);
const vaporization = sampledCurve(TRIPLE.y, 1, vaporizationX);
const solidPolygon = [
{ x: 0, y: 0 },
...sublimation,
...fusion,
{ x: 0, y: 1 }
];
const liquidPolygon = [
...fusion,
{ x: vaporization[vaporization.length - 1].x, y: 1 },
...[...vaporization].reverse()
];
const gasPolygon = [
...vaporization,
{ x: 1, y: 1 },
{ x: 1, y: 0 },
{ x: sublimation[0].x, y: 0 },
...[...sublimation].reverse()
];
const phaseDefinitions = {
solid: {
name: "Solid",
color: 0x51d8ff,
sideColor: 0x126c89,
depth: 1.15,
polygon: solidPolygon
},
liquid: {
name: "Liquid",
color: 0xa985ff,
sideColor: 0x4e3694,
depth: 1.68,
polygon: liquidPolygon
},
gas: {
name: "Gas",
color: 0xffad68,
sideColor: 0xa55331,
depth: 1.38,
polygon: gasPolygon
}
};
const phaseMeshes = [];
const phaseMaterials = {};
function createPhaseMesh(key, definition) {
const shape = new THREE.Shape();
definition.polygon.forEach((point, index) => {
const world = normalizedToWorld(point.x, point.y);
if (index === 0) {
shape.moveTo(world.x, world.y);
} else {
shape.lineTo(world.x, world.y);
}
});
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: definition.depth,
bevelEnabled: false,
curveSegments: 2,
steps: 1
});
const capMaterial = new THREE.MeshPhysicalMaterial({
color: definition.color,
emissive: definition.color,
emissiveIntensity: 0.055,
metalness: 0.08,
roughness: 0.38,
clearcoat: 0.5,
clearcoatRoughness: 0.3,
transparent: true,
opacity: 0.9,
depthWrite: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: definition.sideColor,
emissive: definition.sideColor,
emissiveIntensity: 0.08,
metalness: 0.16,
roughness: 0.58,
transparent: true,
opacity: 0.83
});
phaseMaterials[key] = { capMaterial, sideMaterial };
const mesh = new THREE.Mesh(geometry, [capMaterial, sideMaterial]);
mesh.castShadow = true;
mesh.receiveShadow = true;
mesh.userData.phase = key;
mesh.userData.definition = definition;
chart.add(mesh);
phaseMeshes.push(mesh);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(geometry, 20),
new THREE.LineBasicMaterial({
color: 0xdff7ff,
transparent: true,
opacity: 0.24
})
);
edges.renderOrder = 5;
chart.add(edges);
}
Object.entries(phaseDefinitions).forEach(([key, definition]) => {
createPhaseMesh(key, definition);
});
const backing = new THREE.Mesh(
new THREE.BoxGeometry(8.22, 5.42, 0.18),
new THREE.MeshStandardMaterial({
color: 0x0a1521,
metalness: 0.35,
roughness: 0.62
})
);
backing.position.set(0, 2.6, -0.13);
backing.receiveShadow = true;
chart.add(backing);
const floor = new THREE.Mesh(
new THREE.PlaneGeometry(24, 18),
new THREE.MeshStandardMaterial({
color: 0x06101a,
roughness: 0.92,
metalness: 0.08,
transparent: true,
opacity: 0.68
})
);
floor.rotation.x = -Math.PI / 2;
floor.position.y = -0.39;
floor.receiveShadow = true;
scene.add(floor);
const grid = new THREE.GridHelper(18, 36, 0x24516a, 0x163246);
grid.position.y = -0.37;
grid.material.transparent = true;
grid.material.opacity = 0.22;
scene.add(grid);
function lineSegments(points, color, opacity = 1) {
const geometry = new THREE.BufferGeometry().setFromPoints(points);
const material = new THREE.LineBasicMaterial({
color,
transparent: opacity < 1,
opacity
});
return new THREE.LineSegments(geometry, material);
}
function intervalsAtY(polygon, y) {
const intersections = [];
for (let i = 0; i < polygon.length; i++) {
const a = polygon[i];
const b = polygon[(i + 1) % polygon.length];
if ((a.y > y) !== (b.y > y)) {
const x =
a.x + ((y - a.y) * (b.x - a.x)) / (b.y - a.y);
intersections.push(x);
}
}
intersections.sort((a, b) => a - b);
const intervals = [];
for (let i = 0; i < intersections.length; i += 2) {
if (intersections[i + 1] !== undefined) {
intervals.push([intersections[i], intersections[i + 1]]);
}
}
return intervals;
}
function addSectionHatching(key, definition) {
const segments = [];
for (let y = 0.075; y < 1; y += 0.15) {
const intervals = intervalsAtY(definition.polygon, y);
intervals.forEach(([start, end]) => {
const dash = 0.065;
const step = 0.115;
for (let x = start; x < end; x += step) {
const x2 = Math.min(x + dash, end);
const p1 = normalizedToWorld(x, y, 0.014);
const p2 = normalizedToWorld(x2, y, 0.014);
segments.push(p1, p2);
}
});
}
const hatch = lineSegments(segments, definition.color, 0.16);
hatch.renderOrder = 6;
chart.add(hatch);
}
Object.entries(phaseDefinitions).forEach(([key, definition]) => {
addSectionHatching(key, definition);
});
function makeBoundaryTube(points, color, radius = 0.026, z = 0.036) {
const worldPoints = points.map((point) =>
normalizedToWorld(point.x, point.y, z)
);
const curve = new THREE.CatmullRomCurve3(
worldPoints,
false,
"centripetal"
);
const geometry = new THREE.TubeGeometry(
curve,
Math.max(40, worldPoints.length * 2),
radius,
7,
false
);
const material = new THREE.MeshBasicMaterial({ color });
const tube = new THREE.Mesh(geometry, material);
tube.renderOrder = 8;
chart.add(tube);
}
makeBoundaryTube(sublimation, 0x9deaff, 0.027);
makeBoundaryTube(fusion, 0xd7c7ff, 0.028);
makeBoundaryTube(vaporization, 0xffd0a0, 0.029);
const chartOutline = lineSegments(
[
new THREE.Vector3(-4, 0, 0.02),
new THREE.Vector3(4, 0, 0.02),
new THREE.Vector3(4, 5.2, 0.02),
new THREE.Vector3(-4, 5.2, 0.02),
new THREE.Vector3(-4, 0, 0.02)
],
0x8eb9cf,
0.48
);
chartOutline.renderOrder = 7;
chart.add(chartOutline);
const triplePosition = normalizedToWorld(TRIPLE.x, TRIPLE.y, 0.085);
const tripleHalo = new THREE.Mesh(
new THREE.TorusGeometry(0.15, 0.014, 8, 64),
new THREE.MeshBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.65
})
);
tripleHalo.position.copy(triplePosition);
chart.add(tripleHalo);
const tripleDot = new THREE.Mesh(
new THREE.SphereGeometry(0.055, 18, 18),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
tripleDot.position.copy(triplePosition);
tripleDot.renderOrder = 10;
chart.add(tripleDot);
const xArrow = new THREE.ArrowHelper(
new THREE.Vector3(1, 0, 0),
new THREE.Vector3(-4.12, -0.19, -0.06),
8.45,
0x7395a9,
0.16,
0.09
);
const yArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 1, 0),
new THREE.Vector3(-4.24, -0.19, -0.06),
5.55,
0x7395a9,
0.16,
0.09
);
const zArrow = new THREE.ArrowHelper(
new THREE.Vector3(0, 0, 1),
new THREE.Vector3(-4.24, -0.19, 0.02),
1.9,
0x58778a,
0.14,
0.08
);
chart.add(xArrow, yArrow, zArrow);
const tickSegments = [];
for (let i = 0; i <= 5; i++) {
const x = THREE.MathUtils.lerp(-4, 4, i / 5);
tickSegments.push(
new THREE.Vector3(x, -0.18, -0.06),
new THREE.Vector3(x, -0.04, -0.06)
);
const y = THREE.MathUtils.lerp(0, 5.2, i / 5);
tickSegments.push(
new THREE.Vector3(-4.23, y, -0.06),
new THREE.Vector3(-4.09, y, -0.06)
);
}
const ticks = lineSegments(tickSegments, 0x66879a, 0.68);
chart.add(ticks);
const labelDefinitions = [];
function addLabel(text, className, worldPosition, html = null) {
const element = document.createElement("div");
element.className = `scene-label ${className}`;
if (html) {
element.innerHTML = html;
} else {
element.textContent = text;
}
labelLayer.appendChild(element);
labelDefinitions.push({
element,
position: worldPosition.clone()
});
return element;
}
addLabel(
"Solid",
"phase-label",
normalizedToWorld(0.15, 0.7, 0.12),
'<i style="--color:#51d8ff"></i>Solid'
);
addLabel(
"Liquid",
"phase-label",
normalizedToWorld(0.55, 0.78, 0.12),
'<i style="--color:#a985ff"></i>Liquid'
);
addLabel(
"Gas",
"phase-label",
normalizedToWorld(0.83, 0.32, 0.12),
'<i style="--color:#ffad68"></i>Gas'
);
addLabel(
"Sublimation",
"boundary-label",
normalizedToWorld(0.16, 0.18, 0.13)
);
addLabel(
"Melting",
"boundary-label",
normalizedToWorld(0.39, 0.56, 0.13)
);
addLabel(
"Vaporization",
"boundary-label",
normalizedToWorld(0.61, 0.9, 0.13)
);
addLabel(
"Triple point",
"point-label",
normalizedToWorld(TRIPLE.x, TRIPLE.y, 0.16)
);
addLabel(
"Temperature",
"axis-label",
new THREE.Vector3(4.38, -0.28, -0.04),
"Temperature<small>normalized T</small>"
);
addLabel(
"Pressure",
"axis-label",
new THREE.Vector3(-4.48, 5.62, -0.04),
"Pressure<small>normalized P</small>"
);
addLabel(
"Section depth",
"axis-label",
new THREE.Vector3(-4.56, -0.28, 1.92),
"Depth<small>cutaway</small>"
);
for (let i = 0; i <= 5; i++) {
const value = i * 20;
addLabel(
String(value),
"tick-label",
new THREE.Vector3(
THREE.MathUtils.lerp(-4, 4, i / 5),
-0.34,
-0.06
)
);
addLabel(
String(value),
"tick-label",
new THREE.Vector3(
-4.38,
THREE.MathUtils.lerp(0, 5.2, i / 5),
-0.06
)
);
}
const probeGroup = new THREE.Group();
const probeRingMaterial = new THREE.MeshBasicMaterial({
color: phaseDefinitions.gas.color,
transparent: true,
opacity: 0.95
});
const probeRing = new THREE.Mesh(
new THREE.TorusGeometry(0.145, 0.018, 8, 48),
probeRingMaterial
);
const probeRingOuter = new THREE.Mesh(
new THREE.TorusGeometry(0.215, 0.008, 8, 48),
new THREE.MeshBasicMaterial({
color: phaseDefinitions.gas.color,
transparent: true,
opacity: 0.35
})
);
const probeDot = new THREE.Mesh(
new THREE.SphereGeometry(0.052, 18, 18),
new THREE.MeshBasicMaterial({ color: 0xffffff })
);
probeGroup.add(probeRing, probeRingOuter, probeDot);
chart.add(probeGroup);
function pointInPolygon(x, y, polygon) {
let inside = false;
for (
let i = 0, j = polygon.length - 1;
i < polygon.length;
j = i++
) {
const a = polygon[i];
const b = polygon[j];
const intersects =
a.y > y !== b.y > y &&
x < ((b.x - a.x) * (y - a.y)) / (b.y - a.y) + a.x;
if (intersects) inside = !inside;
}
return inside;
}
function setProbe(normalizedX, normalizedY) {
const phaseKey = Object.keys(phaseDefinitions).find((key) =>
pointInPolygon(
normalizedX,
normalizedY,
phaseDefinitions[key].polygon
)
);
if (!phaseKey) return;
const definition = phaseDefinitions[phaseKey];
const world = normalizedToWorld(normalizedX, normalizedY, 0.09);
probeGroup.position.copy(world);
probeRingMaterial.color.setHex(definition.color);
probeRingOuter.material.color.setHex(definition.color);
document.getElementById("probe-temp").textContent = Math.round(
normalizedX * 100
);
document.getElementById("probe-pressure").textContent = Math.round(
normalizedY * 100
);
const phaseElement = document.getElementById("probe-phase");
phaseElement.textContent = definition.name;
phaseElement.style.color = `#${definition.color
.toString(16)
.padStart(6, "0")}`;
}
setProbe(0.8, 0.3);
const dustGeometry = new THREE.BufferGeometry();
const dustCount = 140;
const dustPositions = new Float32Array(dustCount * 3);
for (let i = 0; i < dustCount; i++) {
dustPositions[i * 3] = (Math.random() - 0.5) * 20;
dustPositions[i * 3 + 1] = Math.random() * 10 - 1;
dustPositions[i * 3 + 2] = (Math.random() - 0.5) * 11;
}
dustGeometry.setAttribute(
"position",
new THREE.BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0x91bfd1,
size: 0.018,
transparent: true,
opacity: 0.34,
depthWrite: false
})
);
scene.add(dust);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
const probePlane = new THREE.Plane(
new THREE.Vector3(0, 0, 1),
-0.04
);
const planeIntersection = new THREE.Vector3();
let dragging = false;
let pointerDownX = 0;
let pointerDownY = 0;
let previousX = 0;
let previousY = 0;
let pointerTravel = 0;
let autoRotate = false;
function setPointer(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
}
renderer.domElement.addEventListener("pointerdown", (event) => {
dragging = true;
pointerDownX = event.clientX;
pointerDownY = event.clientY;
previousX = event.clientX;
previousY = event.clientY;
pointerTravel = 0;
renderer.domElement.setPointerCapture(event.pointerId);
renderer.domElement.classList.add("dragging");
});
renderer.domElement.addEventListener("pointermove", (event) => {
setPointer(event);
if (dragging) {
const dx = event.clientX - previousX;
const dy = event.clientY - previousY;
pointerTravel += Math.abs(dx) + Math.abs(dy);
orbit.yaw -= dx * 0.006;
orbit.pitch = THREE.MathUtils.clamp(
orbit.pitch + dy * 0.0045,
0.12,
1.25
);
previousX = event.clientX;
previousY = event.clientY;
updateCamera();
return;
}
raycaster.setFromCamera(pointer, camera);
const intersections = raycaster.intersectObjects(phaseMeshes, false);
if (intersections.length) {
const phaseKey = intersections[0].object.userData.phase;
const phaseName = phaseDefinitions[phaseKey].name;
tooltip.textContent = phaseName;
tooltip.style.left = `${event.clientX}px`;
tooltip.style.top = `${event.clientY}px`;
tooltip.classList.add("visible");
renderer.domElement.style.cursor = "crosshair";
} else {
tooltip.classList.remove("visible");
renderer.domElement.style.cursor = "grab";
}
});
renderer.domElement.addEventListener("pointerup", (event) => {
const wasClick =
pointerTravel < 7 &&
Math.abs(event.clientX - pointerDownX) < 7 &&
Math.abs(event.clientY - pointerDownY) < 7;
if (wasClick) {
setPointer(event);
raycaster.setFromCamera(pointer, camera);
if (
raycaster.ray.intersectPlane(
probePlane,
planeIntersection
)
) {
const normalizedX =
(planeIntersection.x - bounds.minX) /
(bounds.maxX - bounds.minX);
const normalizedY =
(planeIntersection.y - bounds.minY) /
(bounds.maxY - bounds.minY);
if (
normalizedX >= 0 &&
normalizedX <= 1 &&
normalizedY >= 0 &&
normalizedY <= 1
) {
setProbe(normalizedX, normalizedY);
}
}
}
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
renderer.domElement.classList.remove("dragging");
});
renderer.domElement.addEventListener("pointerleave", () => {
tooltip.classList.remove("visible");
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
7.4,
18
);
updateCamera();
},
{ passive: false }
);
const rotateButton = document.getElementById("rotate-button");
const labelsButton = document.getElementById("labels-button");
const resetButton = document.getElementById("reset-button");
rotateButton.addEventListener("click", () => {
autoRotate = !autoRotate;
rotateButton.classList.toggle("active", autoRotate);
});
labelsButton.addEventListener("click", () => {
labelLayer.classList.toggle("labels-off");
labelsButton.classList.toggle("active");
});
labelsButton.classList.add("active");
resetButton.addEventListener("click", () => {
orbit.target.set(0, 2.45, 0.52);
orbit.yaw = 0.58;
orbit.pitch = 0.48;
orbit.radius = 12.7;
updateCamera();
});
document.querySelectorAll(".legend-row").forEach((row) => {
row.addEventListener("pointerenter", () => {
const phaseKey = row.dataset.phase;
const materials = phaseMaterials[phaseKey];
materials.capMaterial.emissiveIntensity = 0.22;
materials.sideMaterial.emissiveIntensity = 0.2;
});
row.addEventListener("pointerleave", () => {
const phaseKey = row.dataset.phase;
const materials = phaseMaterials[phaseKey];
materials.capMaterial.emissiveIntensity = 0.055;
materials.sideMaterial.emissiveIntensity = 0.08;
});
});
window.addEventListener("keydown", (event) => {
if (event.key.toLowerCase() === "r") {
resetButton.click();
}
if (event.key.toLowerCase() === "l") {
labelsButton.click();
}
if (event.code === "Space") {
event.preventDefault();
rotateButton.click();
}
});
function updateLabels() {
const width = window.innerWidth;
const height = window.innerHeight;
labelDefinitions.forEach((definition) => {
const projected = definition.position.clone().project(camera);
const visible = projected.z > -1 && projected.z < 1;
const x = (projected.x * 0.5 + 0.5) * width;
const y = (-projected.y * 0.5 + 0.5) * height;
definition.element.style.opacity = visible ? "1" : "0";
definition.element.style.transform =
`translate3d(${x}px, ${y}px, 0) translate(-50%, -50%)`;
});
}
function resize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
}
window.addEventListener("resize", resize);
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const delta = Math.min(clock.getDelta(), 0.05);
const elapsed = clock.elapsedTime;
if (autoRotate && !dragging) {
orbit.yaw += delta * 0.075;
updateCamera();
}
const pulse = 1 + Math.sin(elapsed * 2.7) * 0.12;
tripleHalo.scale.setScalar(pulse);
tripleHalo.material.opacity = 0.48 + Math.sin(elapsed * 2.7) * 0.18;
const probePulse = 1 + Math.sin(elapsed * 3.3) * 0.09;
probeRingOuter.scale.setScalar(probePulse);
dust.rotation.y = elapsed * 0.006;
dust.position.y = Math.sin(elapsed * 0.18) * 0.08;
updateLabels();
renderer.render(scene, camera);
}
animate();
requestAnimationFrame(() => {
loading.classList.add("hidden");
setTimeout(() => loading.remove(), 500);
});
</script>
</body>
</html>
```