Prompt specification
Build or customize the Three.js 3D scene "Mineral property comparison table" 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: Mineral property comparison table
Category: Space & Earth · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/mineral-property-comparison-table-x1164
Scene Description Prompt:
Make a low-poly Three.js scene in a self-contained HTML file using cdnjs: mineral property comparison table. Provide switches for a symbolic scratch test and cleavage-plane reveal on sample blocks; explain the properties independently and label all mechanical outcomes illustrative.
Working Three.js Starter (mineral-property-comparison-table-x1164):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Mineral Property Comparison</title>
<style>
:root {
color-scheme: dark;
--bg: #071019;
--panel: #0d1a26;
--panel-2: #102331;
--panel-3: #142a38;
--line: rgba(164, 211, 224, 0.15);
--text: #edf7f7;
--muted: #91a9b3;
--cyan: #5de7dc;
--cyan-soft: rgba(93, 231, 220, 0.12);
--amber: #ffbd66;
--amber-soft: rgba(255, 189, 102, 0.12);
--green: #9ee5bd;
--radius: 18px;
}
* {
box-sizing: border-box;
}
html {
background: var(--bg);
}
body {
margin: 0;
min-width: 320px;
color: var(--text);
background:
radial-gradient(circle at 12% 5%, rgba(62, 142, 151, 0.13), transparent 30rem),
radial-gradient(circle at 88% 10%, rgba(120, 86, 177, 0.11), transparent 32rem),
var(--bg);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
line-height: 1.5;
}
button,
input {
font: inherit;
}
button {
color: inherit;
}
.app {
width: min(1600px, calc(100% - 32px));
margin: 0 auto;
padding: 28px 0 42px;
}
.page-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 24px;
margin-bottom: 20px;
}
.eyebrow {
margin-bottom: 7px;
color: var(--cyan);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.16em;
text-transform: uppercase;
}
h1 {
max-width: 850px;
margin: 0;
font-size: clamp(2rem, 4vw, 4.2rem);
line-height: 0.98;
letter-spacing: -0.055em;
}
.subtitle {
max-width: 760px;
margin: 13px 0 0;
color: var(--muted);
font-size: 1rem;
}
.illustrative-badge {
flex: 0 0 auto;
max-width: 265px;
padding: 11px 14px;
border: 1px solid rgba(255, 189, 102, 0.3);
border-radius: 999px;
color: #ffd69d;
background: var(--amber-soft);
font-size: 0.72rem;
font-weight: 800;
letter-spacing: 0.08em;
text-align: center;
text-transform: uppercase;
}
.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(460px, 560px);
gap: 18px;
align-items: start;
}
.card {
overflow: hidden;
border: 1px solid var(--line);
border-radius: var(--radius);
background: linear-gradient(145deg, rgba(17, 37, 49, 0.96), rgba(9, 21, 31, 0.98));
box-shadow: 0 22px 70px rgba(0, 0, 0, 0.24);
}
.scene-card {
position: relative;
}
.scene-toolbar {
position: relative;
z-index: 5;
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
min-height: 76px;
padding: 14px 16px;
border-bottom: 1px solid var(--line);
background: rgba(10, 24, 34, 0.88);
}
.scene-heading {
min-width: 170px;
}
.scene-heading strong {
display: block;
font-size: 0.95rem;
}
.scene-heading span {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 0.75rem;
}
.switches {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
.switch {
display: inline-flex;
align-items: center;
gap: 9px;
min-height: 42px;
padding: 7px 11px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
color: #c9d9de;
cursor: pointer;
user-select: none;
font-size: 0.8rem;
font-weight: 700;
}
.switch:hover {
border-color: rgba(93, 231, 220, 0.32);
}
.switch input {
position: absolute;
width: 1px;
height: 1px;
opacity: 0;
pointer-events: none;
}
.switch-track {
position: relative;
width: 36px;
height: 20px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.18);
border-radius: 999px;
background: #1b303d;
transition: 160ms ease;
}
.switch-track::after {
position: absolute;
top: 3px;
left: 3px;
width: 12px;
height: 12px;
border-radius: 50%;
background: #a8b9bf;
content: "";
transition: 160ms ease;
}
.switch input:checked + .switch-track {
border-color: rgba(93, 231, 220, 0.55);
background: rgba(93, 231, 220, 0.2);
}
.switch input:checked + .switch-track::after {
left: 19px;
background: var(--cyan);
box-shadow: 0 0 12px rgba(93, 231, 220, 0.7);
}
.switch input:focus-visible + .switch-track {
outline: 2px solid var(--cyan);
outline-offset: 3px;
}
.stage {
position: relative;
height: clamp(510px, 68vh, 720px);
overflow: hidden;
background: #091722;
}
.stage canvas {
display: block;
width: 100%;
height: 100%;
outline: none;
touch-action: none;
}
.stage canvas:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: -3px;
}
.scene-legend {
position: absolute;
z-index: 3;
right: 14px;
bottom: 14px;
width: min(340px, calc(100% - 28px));
padding: 12px 14px;
border: 1px solid var(--line);
border-radius: 13px;
background: rgba(6, 17, 26, 0.82);
backdrop-filter: blur(12px);
pointer-events: none;
}
.legend-row {
display: flex;
align-items: center;
gap: 8px;
color: #d4e4e8;
font-size: 0.75rem;
font-weight: 700;
}
.legend-row + .legend-row {
margin-top: 7px;
}
.legend-swatch {
width: 23px;
height: 4px;
flex: 0 0 auto;
border-radius: 99px;
background: var(--amber);
box-shadow: 0 0 8px rgba(255, 189, 102, 0.55);
}
.legend-swatch.plane {
height: 10px;
border: 1px solid var(--cyan);
background: rgba(93, 231, 220, 0.18);
box-shadow: none;
}
.legend-note {
margin-top: 9px;
padding-top: 8px;
border-top: 1px solid var(--line);
color: #a8bdc4;
font-size: 0.68rem;
line-height: 1.45;
}
.camera-help {
position: absolute;
z-index: 3;
bottom: 15px;
left: 15px;
max-width: 230px;
padding: 8px 10px;
border: 1px solid var(--line);
border-radius: 10px;
color: #a8bdc4;
background: rgba(6, 17, 26, 0.72);
backdrop-filter: blur(10px);
font-size: 0.68rem;
pointer-events: none;
}
.camera-help button {
display: block;
margin-top: 5px;
padding: 0;
border: 0;
color: var(--cyan);
background: transparent;
cursor: pointer;
font-size: 0.7rem;
font-weight: 800;
}
.loading {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
padding: 30px;
color: var(--muted);
background: #091722;
text-align: center;
font-size: 0.9rem;
}
.loading.hidden {
display: none;
}
.data-column {
display: grid;
gap: 18px;
}
.details-card,
.table-card {
padding: 18px;
}
.section-kicker {
margin: 0 0 5px;
color: var(--cyan);
font-size: 0.68rem;
font-weight: 800;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.selected-header {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 15px;
}
.mineral-swatch {
width: 45px;
height: 45px;
flex: 0 0 auto;
border: 1px solid rgba(255, 255, 255, 0.2);
border-radius: 13px;
background: var(--green);
box-shadow: inset -8px -8px 18px rgba(0, 0, 0, 0.16);
}
.selected-header h2 {
margin: 0;
font-size: 1.5rem;
line-height: 1.05;
letter-spacing: -0.035em;
}
.formula {
margin-top: 4px;
color: var(--muted);
font-size: 0.78rem;
}
.fact-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin-bottom: 15px;
}
.fact {
padding: 10px;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.025);
}
.fact small {
display: block;
color: var(--muted);
font-size: 0.64rem;
font-weight: 800;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.fact strong {
display: block;
margin-top: 3px;
font-size: 1rem;
}
.property-notes {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 9px;
}
.property-note {
padding: 12px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.022);
}
.property-note h3 {
display: flex;
align-items: center;
gap: 7px;
margin: 0 0 6px;
font-size: 0.78rem;
}
.property-note h3::before {
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--cyan);
content: "";
}
.property-note p {
margin: 0;
color: #a9bec5;
font-size: 0.72rem;
line-height: 1.55;
}
.independence-note {
margin: 13px 0 0;
padding: 11px 12px;
border-left: 3px solid var(--cyan);
border-radius: 0 10px 10px 0;
color: #a9bec5;
background: var(--cyan-soft);
font-size: 0.71rem;
}
.independence-note strong {
color: #d9f9f5;
}
.table-header {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 12px;
margin-bottom: 11px;
}
.table-header h2 {
margin: 0;
font-size: 1.15rem;
letter-spacing: -0.025em;
}
.table-header p {
max-width: 210px;
margin: 0;
color: var(--muted);
font-size: 0.68rem;
text-align: right;
}
.table-scroll {
overflow-x: auto;
border: 1px solid var(--line);
border-radius: 12px;
}
table {
width: 100%;
min-width: 680px;
border-collapse: collapse;
font-size: 0.71rem;
}
th,
td {
padding: 10px 9px;
border-bottom: 1px solid var(--line);
text-align: left;
vertical-align: top;
}
th {
color: #8faab4;
background: rgba(255, 255, 255, 0.025);
font-size: 0.61rem;
font-weight: 800;
letter-spacing: 0.055em;
text-transform: uppercase;
}
tbody tr {
cursor: pointer;
transition: background 140ms ease;
}
tbody tr:hover,
tbody tr.selected {
background: rgba(93, 231, 220, 0.075);
}
tbody tr.selected td:first-child {
box-shadow: inset 3px 0 var(--cyan);
}
tbody tr:last-child td {
border-bottom: 0;
}
td strong {
display: block;
color: #e9f5f5;
font-size: 0.75rem;
}
td small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 0.63rem;
}
.hardness-number {
font-size: 1rem;
font-weight: 850;
}
.outcome-list {
display: grid;
gap: 4px;
}
.outcome-chip {
display: inline-block;
width: max-content;
padding: 3px 6px;
border-radius: 6px;
font-size: 0.61rem;
font-weight: 800;
white-space: nowrap;
}
.outcome-chip.scratch {
color: #ffd59b;
background: var(--amber-soft);
}
.outcome-chip.plane {
color: #a7f4ed;
background: var(--cyan-soft);
}
.table-footnote {
margin: 10px 0 0;
color: #91a9b3;
font-size: 0.66rem;
line-height: 1.5;
}
.table-footnote strong {
color: #ffd59b;
}
.page-footer {
display: flex;
justify-content: space-between;
gap: 20px;
margin-top: 18px;
padding: 0 3px;
color: #718993;
font-size: 0.68rem;
}
@media (max-width: 1150px) {
.layout {
grid-template-columns: 1fr;
}
.data-column {
grid-template-columns: 1fr 1fr;
}
}
@media (max-width: 760px) {
.app {
width: min(100% - 18px, 1600px);
padding-top: 18px;
}
.page-header {
display: block;
}
.illustrative-badge {
display: inline-block;
max-width: none;
margin-top: 15px;
}
.scene-toolbar {
align-items: flex-start;
flex-direction: column;
}
.switches {
width: 100%;
justify-content: flex-start;
}
.data-column {
grid-template-columns: 1fr;
}
.property-notes {
grid-template-columns: 1fr;
}
.stage {
height: 570px;
}
.camera-help {
bottom: 155px;
}
.page-footer {
display: block;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.001ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="page-header">
<div>
<p class="eyebrow">Interactive mineral bench · Lesson 04</p>
<h1>Mineral property comparison</h1>
<p class="subtitle">
Compare hardness, cleavage, luster, and streak as independent properties.
Use the switches to reveal symbolic mechanical annotations on three low-poly specimens.
</p>
</div>
<div class="illustrative-badge">
Schematic scene<br />Mechanical outcomes are illustrative
</div>
</header>
<main class="layout">
<section class="card scene-card" aria-label="Interactive Three.js mineral comparison">
<div class="scene-toolbar">
<div class="scene-heading">
<strong>Specimen bench</strong>
<span id="sceneSelection">Selected specimen: Talc</span>
</div>
<div class="switches" aria-label="Scene annotation switches">
<label class="switch">
<input id="scratchToggle" type="checkbox" checked />
<span class="switch-track" aria-hidden="true"></span>
<span>Symbolic scratch</span>
</label>
<label class="switch">
<input id="cleavageToggle" type="checkbox" checked />
<span class="switch-track" aria-hidden="true"></span>
<span>Cleavage planes</span>
</label>
</div>
</div>
<div
id="stage"
class="stage"
aria-label="Three-dimensional mineral specimens. Drag to orbit, scroll to zoom, and select a specimen."
>
<div id="loading" class="loading">Loading the Three.js specimen bench…</div>
</div>
<div class="camera-help">
Drag to orbit · wheel or pinch to zoom · click a specimen
<button id="resetCamera" type="button">Reset camera</button>
</div>
<div class="scene-legend">
<div class="legend-row">
<span class="legend-swatch"></span>
Symbolic scratch tool: Mohs H ≈ 3.5
</div>
<div class="legend-row">
<span class="legend-swatch plane"></span>
Schematic cleavage-plane overlay
</div>
<div class="legend-note">
Every scratch mark, non-mark, tool interaction, and plane overlay is
illustrative only. No abrasion, collision, or fracture physics is calculated.
</div>
</div>
</section>
<aside class="data-column" aria-label="Mineral properties and comparison">
<section class="card details-card">
<p class="section-kicker">Selected specimen</p>
<div class="selected-header">
<div
id="mineralSwatch"
class="mineral-swatch"
style="background: #9ee5bd"
aria-hidden="true"
></div>
<div>
<h2 id="detailName">Talc</h2>
<div id="detailFormula" class="formula">Mg₃Si₄O₁₀(OH)₂ · pale green</div>
</div>
</div>
<div class="fact-grid">
<div class="fact">
<small>Mohs hardness</small>
<strong id="detailHardness">1</strong>
</div>
<div class="fact">
<small>Cleavage</small>
<strong id="detailCleavageShort">1 direction</strong>
</div>
<div class="fact">
<small>Streak</small>
<strong id="detailStreakShort">White</strong>
</div>
</div>
<div id="propertyNotes" class="property-notes" aria-live="polite">
<article class="property-note">
<h3>Hardness</h3>
<p id="hardnessNote"></p>
</article>
<article class="property-note">
<h3>Cleavage</h3>
<p id="cleavageNote"></p>
</article>
<article class="property-note">
<h3>Luster</h3>
<p id="lusterNote"></p>
</article>
<article class="property-note">
<h3>Streak</h3>
<p id="streakNote"></p>
</article>
</div>
<p class="independence-note">
<strong>Independent properties:</strong>
a mineral can have a hard surface, poor cleavage, glassy luster, and a
different-colored streak. These descriptors should not be inferred from
one another.
</p>
</section>
<section class="card table-card">
<div class="table-header">
<div>
<p class="section-kicker">Side-by-side</p>
<h2>Comparison table</h2>
</div>
<p>Select a row to focus its specimen and notes.</p>
</div>
<div class="table-scroll">
<table>
<thead>
<tr>
<th scope="col">Mineral</th>
<th scope="col">Hardness</th>
<th scope="col">Cleavage</th>
<th scope="col">Luster</th>
<th scope="col">Streak</th>
<th scope="col">Illustrative overlays</th>
</tr>
</thead>
<tbody id="mineralRows">
<tr data-index="0" tabindex="0" class="selected" aria-label="Select talc">
<td>
<strong>Talc</strong>
<small>Mg₃Si₄O₁₀(OH)₂</small>
</td>
<td><span class="hardness-number">1</span></td>
<td>
Perfect in one direction
<small>Basal planes</small>
</td>
<td>Pearly to greasy</td>
<td>White</td>
<td>
<div class="outcome-list">
<span class="outcome-chip scratch">Scratch mark*</span>
<span class="outcome-chip plane">1 plane shown*</span>
</div>
</td>
</tr>
<tr data-index="1" tabindex="0" aria-label="Select calcite">
<td>
<strong>Calcite</strong>
<small>CaCO₃</small>
</td>
<td><span class="hardness-number">3</span></td>
<td>
Perfect in three directions
<small>Angles are not 90°</small>
</td>
<td>Vitreous</td>
<td>White</td>
<td>
<div class="outcome-list">
<span class="outcome-chip scratch">Scratch mark*</span>
<span class="outcome-chip plane">3 planes shown*</span>
</div>
</td>
</tr>
<tr data-index="2" tabindex="0" aria-label="Select fluorite">
<td>
<strong>Fluorite</strong>
<small>CaF₂</small>
</td>
<td><span class="hardness-number">4</span></td>
<td>
Perfect in four directions
<small>Octahedral planes</small>
</td>
<td>Vitreous</td>
<td>White</td>
<td>
<div class="outcome-list">
<span class="outcome-chip scratch">No scratch mark*</span>
<span class="outcome-chip plane">4 planes shown*</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="table-footnote">
<strong>* Illustrative only.</strong>
The scratch convention uses a symbolic H ≈ 3.5 reference tool:
talc and calcite receive a schematic mark; fluorite does not.
Plane counts summarize the minerals’ characteristic cleavage directions.
The Mohs scale is ordinal, and real scratches can vary with direction,
impurities, and technique.
</p>
</section>
</aside>
</main>
<footer class="page-footer">
<span>Teaching visualization · selected values are representative specimen data.</span>
<span>Three.js core only · no physics engine or examples/addons</span>
</footer>
</div>
<script type="module">
const loadingElement = document.getElementById("loading");
try {
const THREE = await import(
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js"
);
startScene(THREE);
} catch (error) {
console.error(error);
loadingElement.textContent =
"The Three.js scene could not be loaded. Check your network connection and WebGL support.";
}
function startScene(THREE) {
const stage = document.getElementById("stage");
const resetCameraButton = document.getElementById("resetCamera");
const scratchToggle = document.getElementById("scratchToggle");
const cleavageToggle = document.getElementById("cleavageToggle");
const minerals = [
{
name: "Talc",
formula: "Mg₃Si₄O₁₀(OH)₂",
colorText: "pale green",
hardness: 1,
cleavageShort: "1 direction",
cleavage: "Perfect in one direction",
luster: "Pearly to greasy",
streak: "White",
planes: 1,
scratchShown: true,
accent: 0x9ee5bd,
cssAccent: "#9ee5bd",
hardnessNote:
"At Mohs 1, talc is the softest mineral in this comparison. It can be scratched by harder minerals; the symbolic H ≈ 3.5 tool therefore leaves a schematic mark.",
cleavageNote:
"Talc has one perfect cleavage direction. It tends to separate along broad basal planes rather than splintering through many unrelated directions.",
lusterNote:
"Its surface commonly appears pearly to greasy. Luster describes reflected light and is assessed independently of hardness and cleavage.",
streakNote:
"The powdered mineral gives a white streak. Streak is the color of the powder and can differ from the color of the intact specimen."
},
{
name: "Calcite",
formula: "CaCO₃",
colorText: "colorless to white",
hardness: 3,
cleavageShort: "3 directions",
cleavage: "Perfect in three directions",
luster: "Vitreous",
streak: "White",
planes: 3,
scratchShown: true,
accent: 0xe9dec2,
cssAccent: "#e9dec2",
hardnessNote:
"Calcite has Mohs hardness 3. It is harder than talc but softer than fluorite in this set, so the symbolic H ≈ 3.5 tool produces a schematic scratch mark.",
cleavageNote:
"Calcite breaks perfectly in three directions whose angles are not 90°. Its rhombohedral cleavage is a distinct property, not a consequence of its hardness.",
lusterNote:
"Fresh calcite commonly has a vitreous, or glass-like, luster. Surface weathering can change the appearance without changing the underlying mineral.",
streakNote:
"Calcite produces a white streak even when the larger crystal appears colorless or is stained. Powder color is evaluated separately from body color."
},
{
name: "Fluorite",
formula: "CaF₂",
colorText: "purple",
hardness: 4,
cleavageShort: "4 directions",
cleavage: "Perfect in four directions",
luster: "Vitreous",
streak: "White",
planes: 4,
scratchShown: false,
accent: 0xa88af0,
cssAccent: "#a88af0",
hardnessNote:
"Fluorite has Mohs hardness 4 and resists the symbolic H ≈ 3.5 tool in this teaching convention. The scene therefore shows no scratch mark; this is not a simulated abrasion test.",
cleavageNote:
"Fluorite has four perfect cleavage directions associated with octahedral forms. The four translucent sheets are a schematic orientation guide, not actual fractures.",
lusterNote:
"Fluorite commonly has a vitreous luster. Its bright surface appearance is independent of how readily it cleaves or how hard it is.",
streakNote:
"The powdered mineral gives a white streak, which may contrast with the purple or green color of the larger specimen."
}
];
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x091722);
scene.fog = new THREE.Fog(0x091722, 10, 20);
const camera = new THREE.PerspectiveCamera(38, 1, 0.1, 50);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.12;
renderer.domElement.tabIndex = 0;
renderer.domElement.setAttribute(
"aria-label",
"Interactive 3D mineral specimens. Use arrow keys to orbit and plus or minus to zoom."
);
stage.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xbdefff, 0x17202a, 2.25);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xfff1d7, 4.2);
keyLight.position.set(-4.5, 7, 5.5);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -6;
keyLight.shadow.camera.right = 6;
keyLight.shadow.camera.top = 6;
keyLight.shadow.camera.bottom = -6;
keyLight.shadow.bias = -0.0005;
scene.add(keyLight);
const rimLight = new THREE.PointLight(0x65d9e6, 18, 13, 2);
rimLight.position.set(4, 3.2, -3.5);
scene.add(rimLight);
const purpleLight = new THREE.PointLight(0x9670e8, 10, 9, 2);
purpleLight.position.set(-4, 1.8, -2);
scene.add(purpleLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(30, 30),
new THREE.MeshStandardMaterial({
color: 0x0c1d27,
roughness: 0.96,
metalness: 0.02
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.18;
ground.receiveShadow = true;
scene.add(ground);
const grid = new THREE.GridHelper(16, 32, 0x3d8990, 0x24404d);
grid.position.y = -0.165;
grid.material.transparent = true;
grid.material.opacity = 0.16;
scene.add(grid);
const orbit = {
theta: 0.35,
phi: 1.08,
radius: 9.4,
target: new THREE.Vector3(0, 0.72, 0)
};
function updateCamera() {
const sinPhi = Math.sin(orbit.phi);
camera.position.set(
orbit.target.x + orbit.radius * sinPhi * Math.sin(orbit.theta),
orbit.target.y + orbit.radius * Math.cos(orbit.phi),
orbit.target.z + orbit.radius * sinPhi * Math.cos(orbit.theta)
);
camera.lookAt(orbit.target);
}
function resetCamera() {
orbit.theta = 0.35;
orbit.phi = 1.08;
orbit.radius = 9.4;
updateCamera();
}
updateCamera();
resetCameraButton.addEventListener("click", resetCamera);
function roundedRect(context, x, y, width, height, radius) {
const r = Math.min(radius, width / 2, height / 2);
context.beginPath();
context.moveTo(x + r, y);
context.lineTo(x + width - r, y);
context.quadraticCurveTo(x + width, y, x + width, y + r);
context.lineTo(x + width, y + height - r);
context.quadraticCurveTo(
x + width,
y + height,
x + width - r,
y + height
);
context.lineTo(x + r, y + height);
context.quadraticCurveTo(x, y + height, x, y + height - r);
context.lineTo(x, y + r);
context.quadraticCurveTo(x, y, x + r, y);
context.closePath();
}
function createNameSprite(mineral) {
const canvas = document.createElement("canvas");
canvas.width = 640;
canvas.height = 144;
const context = canvas.getContext("2d");
context.clearRect(0, 0, canvas.width, canvas.height);
roundedRect(context, 4, 4, 632, 136, 22);
context.fillStyle = "rgba(6, 18, 27, 0.88)";
context.fill();
context.strokeStyle = "rgba(185, 230, 235, 0.24)";
context.lineWidth = 2;
context.stroke();
context.fillStyle = `#${mineral.accent.toString(16).padStart(6, "0")}`;
context.fillRect(25, 24, 8, 95);
context.fillStyle = "#f1fbfb";
context.font = "800 42px system-ui, sans-serif";
context.textBaseline = "middle";
context.fillText(
`${mineral.name.toUpperCase()} · H ${mineral.hardness}`,
54,
52
);
context.fillStyle = "#9fb7bf";
context.font = "500 25px system-ui, sans-serif";
context.fillText(mineral.formula, 54, 99);
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(1.95, 0.44, 1);
sprite.renderOrder = 30;
return sprite;
}
function createOutcomeSprite(mineral) {
const canvas = document.createElement("canvas");
canvas.width = 900;
canvas.height = 190;
const context = canvas.getContext("2d");
const texture = new THREE.CanvasTexture(canvas);
texture.colorSpace = THREE.SRGBColorSpace;
const material = new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false,
depthWrite: false
});
const sprite = new THREE.Sprite(material);
sprite.scale.set(2.25, 0.475, 1);
sprite.renderOrder = 31;
function update(scratchEnabled, cleavageEnabled) {
context.clearRect(0, 0, canvas.width, canvas.height);
const visible = scratchEnabled || cleavageEnabled;
sprite.visible = visible;
if (!visible) {
texture.needsUpdate = true;
return;
}
roundedRect(context, 4, 4, 892, 182, 22);
context.fillStyle = "rgba(7, 21, 30, 0.91)";
context.fill();
context.strokeStyle = "rgba(93, 231, 220, 0.62)";
context.lineWidth = 3;
context.stroke();
context.textAlign = "center";
context.textBaseline = "middle";
context.fillStyle = "#5de7dc";
context.font = "800 25px system-ui, sans-serif";
context.fillText("ILLUSTRATIVE OUTCOME", 450, 48);
const details = [];
if (scratchEnabled) {
details.push(
mineral.scratchShown ? "scratch mark" : "no scratch mark"
);
}
if (cleavageEnabled) {
details.push(
`${mineral.planes} cleavage plane${
mineral.planes === 1 ? "" : "s"
}`
);
}
context.fillStyle = "#eefafa";
context.font = "750 34px system-ui, sans-serif";
context.fillText(details.join(" · "), 450, 112);
context.fillStyle = "#a4bbc2";
context.font = "600 20px system-ui, sans-serif";
context.fillText("schematic annotation — not a measurement", 450, 157);
texture.needsUpdate = true;
}
update(scratchToggle.checked, cleavageToggle.checked);
return { sprite, update };
}
function createBlockGeometry() {
const shape = new THREE.Shape();
shape.moveTo(-0.57, -0.5);
shape.lineTo(0.49, -0.5);
shape.lineTo(0.68, -0.32);
shape.lineTo(0.68, 0.32);
shape.lineTo(0.49, 0.5);
shape.lineTo(-0.49, 0.5);
shape.lineTo(-0.68, 0.32);
shape.lineTo(-0.68, -0.32);
shape.closePath();
const geometry = new THREE.ExtrudeGeometry(shape, {
depth: 0.82,
bevelEnabled: true,
bevelThickness: 0.055,
bevelSize: 0.055,
bevelOffset: 0,
bevelSegments: 1,
steps: 1,
curveSegments: 1
});
geometry.computeBoundingBox();
const center = new THREE.Vector3();
geometry.boundingBox.getCenter(center);
geometry.translate(-center.x, -center.y, -center.z);
geometry.computeVertexNormals();
return geometry;
}
const sharedBlockGeometry = createBlockGeometry();
const pickableMeshes = [];
const tests = [];
function createCleavageGroup(mineral, index) {
const group = new THREE.Group();
group.visible = false;
const planeMaterials = [];
const lineMaterials = [];
function addPlane(width, height, rotation) {
const planeGeometry = new THREE.PlaneGeometry(width, height);
const planeMaterial = new THREE.MeshBasicMaterial({
color: 0x5de7dc,
transparent: true,
opacity: 0,
side: THREE.DoubleSide,
depthTest: false,
depthWrite: false
});
const plane = new THREE.Mesh(planeGeometry, planeMaterial);
plane.rotation.set(...rotation);
plane.renderOrder = 20;
group.add(plane);
const edgeGeometry = new THREE.EdgesGeometry(planeGeometry);
const edgeMaterial = new THREE.LineBasicMaterial({
color: 0x91fff5,
transparent: true,
opacity: 0,
depthTest: false,
depthWrite: false
});
const edges = new THREE.LineSegments(edgeGeometry, edgeMaterial);
edges.rotation.set(...rotation);
edges.renderOrder = 21;
group.add(edges);
planeMaterials.push(planeMaterial);
lineMaterials.push(edgeMaterial);
}
if (index === 0) {
// One schematic basal plane.
addPlane(1.58, 1.36, [Math.PI / 2, 0, 0]);
} else if (index === 1) {
// Three schematic rhombohedral directions; angles are not 90°.
addPlane(1.62, 1.35, [0, 0, 0]);
addPlane(1.62, 1.35, [-0.78, 0.62, 0.16]);
addPlane(1.62, 1.35, [0.82, -0.56, -0.2]);
} else {
// Four schematic octahedral directions.
addPlane(1.62, 1.35, [0, 0, 0]);
addPlane(1.62, 1.35, [Math.PI / 2, 0, 0]);
addPlane(1.62, 1.35, [0, Math.PI / 4, 0]);
addPlane(1.62, 1.35, [Math.PI / 2, Math.PI / 4, 0]);
}
return { group, planeMaterials, lineMaterials };
}
function createScratchTool() {
const group = new THREE.Group();
const metal = new THREE.MeshStandardMaterial({
color: 0xd9e6e8,
metalness: 0.8,
roughness: 0.24,
flatShading: true
});
const grip = new THREE.MeshStandardMaterial({
color: 0x213442,
metalness: 0.35,
roughness: 0.55,
flatShading: true
});
const tip = new THREE.Mesh(
new THREE.ConeGeometry(0.055, 0.18, 6),
new THREE.MeshStandardMaterial({
color: 0xffbd66,
emissive: 0x6e3b08,
emissiveIntensity: 0.65,
metalness: 0.7,
roughness: 0.25,
flatShading: true
})
);
tip.rotation.x = -Math.PI / 2;
tip.position.z = 0.09;
group.add(tip);
const shaft = new THREE.Mesh(
new THREE.CylinderGeometry(0.032, 0.042, 0.36, 6),
metal
);
shaft.rotation.x = -Math.PI / 2;
shaft.position.z = 0.36;
group.add(shaft);
const handle = new THREE.Mesh(
new THREE.CylinderGeometry(0.065, 0.07, 0.19, 6),
grip
);
handle.rotation.x = -Math.PI / 2;
handle.position.z = 0.61;
group.add(handle);
group.visible = false;
return group;
}
function createScratchMark() {
const curve = new THREE.CatmullRomCurve3([
new THREE.Vector3(-0.29, 0.12, 0.416),
new THREE.Vector3(-0.15, 0.055, 0.418),
new THREE.Vector3(-0.02, 0.125, 0.419),
new THREE.Vector3(0.12, 0.06, 0.418),
new THREE.Vector3(0.27, 0.115, 0.417)
]);
const material = new THREE.MeshBasicMaterial({
color: 0xffb14e,
transparent: true,
opacity: 0,
depthTest: false,
depthWrite: false
});
const mark = new THREE.Mesh(
new THREE.TubeGeometry(curve, 24, 0.012, 5, false),
material
);
mark.renderOrder = 25;
return mark;
}
const xPositions = [-2.45, 0, 2.45];
const rotations = [-0.22, 0.08, 0.28];
minerals.forEach((mineral, index) => {
const root = new THREE.Group();
root.position.set(xPositions[index], 0.55, 0);
root.rotation.y = rotations[index];
scene.add(root);
const pedestal = new THREE.Mesh(
new THREE.CylinderGeometry(0.88, 0.98, 0.16, 10),
new THREE.MeshStandardMaterial({
color: 0x172c39,
metalness: 0.22,
roughness: 0.66,
flatShading: true
})
);
pedestal.position.set(xPositions[index], -0.08, 0);
pedestal.castShadow = true;
pedestal.receiveShadow = true;
scene.add(pedestal);
const capMaterial = new THREE.MeshStandardMaterial({
color: mineral.accent,
roughness: index === 1 ? 0.38 : 0.62,
metalness: index === 2 ? 0.12 : 0.03,
emissive: mineral.accent,
emissiveIntensity: 0.025,
flatShading: true
});
const sideMaterial = new THREE.MeshStandardMaterial({
color: new THREE.Color(mineral.accent).multiplyScalar(0.7),
roughness: 0.76,
metalness: 0.02,
emissive: mineral.accent,
emissiveIntensity: 0.018,
flatShading: true
});
const block = new THREE.Mesh(sharedBlockGeometry, [
capMaterial,
sideMaterial
]);
block.castShadow = true;
block.receiveShadow = true;
block.userData.mineralIndex = index;
root.add(block);
pickableMeshes.push(block);
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(sharedBlockGeometry, 24),
new THREE.LineBasicMaterial({
color: 0xffffff,
transparent: true,
opacity: 0.17,
depthWrite: false
})
);
root.add(edges);
const ring = new THREE.Mesh(
new THREE.TorusGeometry(0.72, 0.025, 6, 48),
new THREE.MeshBasicMaterial({
color: mineral.accent,
transparent: true,
opacity: 0.16,
depthWrite: false
})
);
ring.rotation.x = Math.PI / 2;
ring.position.y = -0.5;
root.add(ring);
const nameSprite = createNameSprite(mineral);
nameSprite.position.set(xPositions[index], 1.85, 0);
scene.add(nameSprite);
const cleavage = createCleavageGroup(mineral, index);
root.add(cleavage.group);
const outcome = createOutcomeSprite(mineral);
outcome.sprite.position.set(xPositions[index], 1.32, 0);
scene.add(outcome.sprite);
const tool = createScratchTool();
root.add(tool);
const mark = createScratchMark();
root.add(mark);
tests.push({
mineral,
root,
block,
ring,
cleavage,
outcome,
tool,
mark
});
});
let selectedIndex = 0;
function selectMineral(index) {
selectedIndex = index;
const mineral = minerals[index];
tests.forEach((test, testIndex) => {
const isSelected = testIndex === index;
test.ring.material.opacity = isSelected ? 0.95 : 0.14;
test.ring.material.color.set(test.mineral.accent);
test.block.material.forEach((material) => {
material.emissive.set(test.mineral.accent);
material.emissiveIntensity = isSelected ? 0.15 : 0.022;
});
});
document.getElementById("sceneSelection").textContent =
`Selected specimen: ${mineral.name}`;
document.getElementById("mineralSwatch").style.background =
mineral.cssAccent;
document.getElementById("detailName").textContent = mineral.name;
document.getElementById("detailFormula").textContent =
`${mineral.formula} · ${mineral.colorText}`;
document.getElementById("detailHardness").textContent = mineral.hardness;
document.getElementById("detailCleavageShort").textContent =
mineral.cleavageShort;
document.getElementById("detailStreakShort").textContent = mineral.streak;
document.getElementById("hardnessNote").textContent =
mineral.hardnessNote;
document.getElementById("cleavageNote").textContent =
mineral.cleavageNote;
document.getElementById("lusterNote").textContent = mineral.lusterNote;
document.getElementById("streakNote").textContent = mineral.streakNote;
document.querySelectorAll("#mineralRows tr").forEach((row, rowIndex) => {
row.classList.toggle("selected", rowIndex === index);
});
}
document.querySelectorAll("#mineralRows tr").forEach((row) => {
const index = Number(row.dataset.index);
row.addEventListener("click", () => selectMineral(index));
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
event.preventDefault();
selectMineral(index);
}
});
});
selectMineral(0);
let scratchStart = performance.now();
let cleavageStart = performance.now();
scratchToggle.addEventListener("change", () => {
if (scratchToggle.checked) {
scratchStart = performance.now();
}
tests.forEach((test) => {
test.tool.visible = scratchToggle.checked;
test.outcome.update(
scratchToggle.checked,
cleavageToggle.checked
);
});
});
cleavageToggle.addEventListener("change", () => {
if (cleavageToggle.checked) {
cleavageStart = performance.now();
}
tests.forEach((test) => {
test.cleavage.group.visible = cleavageToggle.checked;
test.outcome.update(
scratchToggle.checked,
cleavageToggle.checked
);
});
});
// Camera controls are implemented directly; no examples/addons are used.
const raycaster = new THREE.Raycaster();
const pointerNdc = new THREE.Vector2();
const pointers = new Map();
let moved = false;
let pinchDistance = null;
function pickMineral(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointerNdc.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointerNdc.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointerNdc, camera);
const intersections = raycaster.intersectObjects(
pickableMeshes,
false
);
if (intersections.length) {
selectMineral(intersections[0].object.userData.mineralIndex);
}
}
renderer.domElement.addEventListener("pointerdown", (event) => {
event.preventDefault();
renderer.domElement.focus({ preventScroll: true });
if (pointers.size === 0) {
moved = false;
}
pointers.set(event.pointerId, {
x: event.clientX,
y: event.clientY
});
renderer.domElement.setPointerCapture(event.pointerId);
if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchDistance = Math.hypot(a.x - b.x, a.y - b.y);
moved = true;
}
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!pointers.has(event.pointerId)) return;
const pointer = pointers.get(event.pointerId);
const deltaX = event.clientX - pointer.x;
const deltaY = event.clientY - pointer.y;
pointer.x = event.clientX;
pointer.y = event.clientY;
if (pointers.size === 1) {
if (Math.abs(deltaX) + Math.abs(deltaY) > 0) {
moved = true;
}
orbit.theta -= deltaX * 0.006;
orbit.phi = THREE.MathUtils.clamp(
orbit.phi - deltaY * 0.005,
0.43,
1.39
);
updateCamera();
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
const nextDistance = Math.hypot(a.x - b.x, a.y - b.y);
if (pinchDistance && nextDistance > 0) {
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * (pinchDistance / nextDistance),
5.7,
13.5
);
updateCamera();
}
pinchDistance = nextDistance;
}
});
function endPointer(event) {
const shouldPick = pointers.size === 1 && !moved;
pointers.delete(event.pointerId);
if (
renderer.domElement.hasPointerCapture &&
renderer.domElement.hasPointerCapture(event.pointerId)
) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
if (shouldPick) {
pickMineral(event);
}
if (pointers.size < 2) {
pinchDistance = null;
}
}
renderer.domElement.addEventListener("pointerup", endPointer);
renderer.domElement.addEventListener("pointercancel", endPointer);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
orbit.radius = THREE.MathUtils.clamp(
orbit.radius * Math.exp(event.deltaY * 0.001),
5.7,
13.5
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
renderer.domElement.addEventListener("keydown", (event) => {
let handled = true;
switch (event.key) {
case "ArrowLeft":
orbit.theta -= 0.1;
break;
case "ArrowRight":
orbit.theta += 0.1;
break;
case "ArrowUp":
orbit.phi = THREE.MathUtils.clamp(orbit.phi - 0.08, 0.43, 1.39);
break;
case "ArrowDown":
orbit.phi = THREE.MathUtils.clamp(orbit.phi + 0.08, 0.43, 1.39);
break;
case "+":
case "=":
orbit.radius = Math.max(5.7, orbit.radius - 0.5);
break;
case "-":
case "_":
orbit.radius = Math.min(13.5, orbit.radius + 0.5);
break;
case "Home":
resetCamera();
break;
default:
handled = false;
}
if (handled) {
event.preventDefault();
updateCamera();
}
});
function resize() {
const width = stage.clientWidth;
const height = stage.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resize);
resizeObserver.observe(stage);
resize();
function easeOutCubic(value) {
return 1 - Math.pow(1 - value, 3);
}
function animate(now) {
requestAnimationFrame(animate);
const scratchElapsed = (now - scratchStart) / 1000;
const cleavageProgress = cleavageToggle.checked
? THREE.MathUtils.clamp((now - cleavageStart) / 520, 0, 1)
: 0;
tests.forEach((test, index) => {
const cleavageEase = easeOutCubic(cleavageProgress);
test.cleavage.group.visible = cleavageToggle.checked;
test.cleavage.group.scale.setScalar(0.86 + 0.14 * cleavageEase);
test.cleavage.planeMaterials.forEach((material) => {
material.opacity = 0.145 * cleavageEase;
});
test.cleavage.lineMaterials.forEach((material) => {
material.opacity = 0.74 * cleavageEase;
});
test.tool.visible = scratchToggle.checked;
const delayedStart = index * 0.32;
const rawProgress = THREE.MathUtils.clamp(
(scratchElapsed - delayedStart) / 1.2,
0,
1
);
const progress = easeOutCubic(rawProgress);
test.tool.position.x = THREE.MathUtils.lerp(
-0.49,
0.49,
progress
);
test.tool.position.z = 0.445;
test.tool.position.y = test.mineral.scratchShown
? 0.075 + Math.sin(progress * Math.PI) * 0.012
: 0.075 + Math.sin(progress * Math.PI) * 0.065;
test.mark.visible = scratchToggle.checked;
test.mark.material.opacity =
test.mineral.scratchShown && rawProgress > 0.43
? THREE.MathUtils.clamp((rawProgress - 0.43) * 4, 0, 1)
: 0;
test.ring.material.opacity =
index === selectedIndex
? 0.76 + Math.sin(now * 0.003) * 0.16
: 0.13;
});
renderer.render(scene, camera);
}
loadingElement.classList.add("hidden");
requestAnimationFrame(animate);
}
</script>
</body>
</html>
```