-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
220 lines (196 loc) · 6.59 KB
/
index.html
File metadata and controls
220 lines (196 loc) · 6.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Interactive 3D Scalars</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- model-viewer (web component for GLB) -->
<script type="module"
src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
<!-- MathJax (LaTeX in the title) -->
<script>
window.MathJax = {
tex: { inlineMath: [['\\(', '\\)'], ['$', '$']] },
startup: { typeset: false } // we will trigger typesetting manually
};
</script>
<script id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<style>
:root { --maxw: 1200px; --accent: #2563eb; }
* { box-sizing: border-box; }
body {
margin: 0; background: #fff; color: #111;
font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
display: flex; flex-direction: column; align-items: center;
}
header, main { width: 100%; max-width: var(--maxw); }
header {
padding: 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.group { display: inline-flex; gap: 8px; align-items: center; }
.pill {
appearance: none; border: 1.5px solid #d1d5db; background: #fff; color: #111;
padding: 6px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
transition: all .15s ease;
}
.pill:hover { border-color: #9ca3af; }
.pill.active {
color: #fff; background: var(--accent); border-color: var(--accent);
box-shadow: 0 1px 2px rgb(0 0 0 / .08);
}
label.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 15px; }
#title {
margin: 6px auto 10px; text-align: center; font-weight: 600; font-size: 22px;
min-height: 28px; /* keeps layout steady while switching */
}
#status {
text-align: center; min-height: 20px; font-size: 14px; margin-bottom: 6px;
}
#status.loading { color: #0a7; }
#status.err { color: #c026d3; } /* gentle magenta for errors */
model-viewer {
width: 100%; height: 68vh; background: #fff; border-radius: 10px;
outline: 2px solid #dbeafe; outline-offset: 4px;
}
.legend-wrap {
display: flex; flex-direction: column; align-items: center;
margin: 12px 0 24px;
}
.legend { width: min(900px, 95%); height: auto; display: block; }
@media (max-width: 900px) {
model-viewer { height: 60vh; }
}
</style>
</head>
<body>
<header>
<div class="group" id="scalarButtons">
<button class="pill" data-scalar="kappa">κ</button>
<button class="pill" data-scalar="gradB">∇|B|</button>
<button class="pill" data-scalar="jdia">J<sub>dia</sub></button>
</div>
<label class="chk">
<input type="checkbox" id="arrowsChk">
Arrows
</label>
</header>
<main>
<div id="title"></div>
<div id="status"></div>
<model-viewer id="mv"
camera-controls auto-rotate exposure="1.0" shadow-intensity="0.5"
disable-occlusion
ar ia-label="3D scalar field">
</model-viewer>
<div class="legend-wrap">
<img id="legend" class="legend" src="" alt="Colorbar">
</div>
</main>
<script>
// --- File map + LaTeX labels (use String.raw so backslashes are clean) ---
const MODELS = {
kappa: {
base: "kappa_eq1.glb",
arrows: "kappa_q_eq1.glb",
legend: "kappa_eq1_colorbar.png",
label: String.raw`\(\kappa\)`
},
gradB: {
base: "gradB_eq1.glb",
arrows: "gradB_q_eq1.glb",
legend: "gradB_eq1_colorbar.png",
label: String.raw`\(\nabla |B|\)`
},
jdia: {
base: "jdia_eq1.glb",
arrows: "jdia_q_eq1.glb",
legend: "jdia_eq1_colorbar.png",
label: String.raw`\(J_{\mathrm{dia}}\)`
}
};
// --- UI refs ---
const mv = document.getElementById('mv');
const legend = document.getElementById('legend');
const titleDiv = document.getElementById('title');
const statusDiv = document.getElementById('status');
const arrowsChk = document.getElementById('arrowsChk');
const pills = [...document.querySelectorAll('#scalarButtons .pill')];
// --- State ---
let scalar = 'kappa'; // default
let arrows = false;
function setStatus(msg = '', cls = '') {
statusDiv.className = cls ? cls : '';
statusDiv.textContent = msg;
}
// Highlight active scalar button
function refreshPills() {
pills.forEach(btn => {
btn.classList.toggle('active', btn.dataset.scalar === scalar);
});
}
// Disable controls while loading
function setControlsDisabled(disabled) {
pills.forEach(b => b.disabled = disabled);
arrowsChk.disabled = disabled;
}
// After the model loads, force double-sided materials (no backface culling)
function makeDoubleSided() {
try {
const mdl = mv.model;
if (mdl?.materials) {
for (const m of mdl.materials) m.doubleSided = true;
}
} catch {}
}
function update() {
const cfg = MODELS[scalar];
const src = arrows ? cfg.arrows : cfg.base;
// UI bits
refreshPills();
legend.src = cfg.legend;
// Set LaTeX title and typeset it
titleDiv.innerHTML = cfg.label;
queueMicrotask(() => {
if (window.MathJax?.typesetPromise) {
MathJax.typesetClear?.([titleDiv]);
MathJax.typesetPromise([titleDiv]).catch(()=>{});
}
});
// Start loading
setControlsDisabled(true);
setStatus('Loading…', 'loading');
const onLoad = () => {
makeDoubleSided();
setStatus('',''); // clear message
setControlsDisabled(false);
};
const onError = (e) => {
// Minimal, user-friendly error
setStatus('Failed to display model', 'err');
setControlsDisabled(false);
// (optional) console for debugging
console.error('model-viewer load error', e?.detail || e);
};
mv.addEventListener('load', onLoad, { once: true });
mv.addEventListener('error', onError, { once: true });
// Assign source last
mv.src = src /* + '?v=1' */; // uncomment version if you hit cache issues
}
// --- Wire up controls ---
pills.forEach(btn => {
btn.addEventListener('click', () => {
scalar = btn.dataset.scalar;
update();
});
});
arrowsChk.addEventListener('change', () => {
arrows = arrowsChk.checked;
update();
});
// Initial UI
refreshPills();
update();
</script>
</body>
</html>