-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html.bak
More file actions
413 lines (355 loc) · 13 KB
/
Copy pathindex.html.bak
File metadata and controls
413 lines (355 loc) · 13 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
</head>
<style>
* {
margin: 0;
padding: 0;
}
/* to remove the top and left whitespace */
html,
body {
width: 100%;
height: 100%;
background-color: white;
}
/* just to be sure these are full screen*/
canvas {
display: block;
height: 100vh;
width: 100vw;
}
#gui {
position: absolute;
top: 0;
left: 0;
background-color: rgba(0, 0, 0, 0.5);
/* border: 1px solid black; */
/* border-radius: 1px; */
/* padding: 100px; */
display: flex;
text-align: center;
flex-direction: column;
justify-content: start;
align-items: center;
font-family: sans-serif;
color: white;
min-width: 250px;
min-height: 500px;
}
/* button {
background-color: white;
color: black;
border: 1px solid black;
border-radius: 5px;
padding: 5px;
font-size: 16px;
} */
button:hover {
background-color: lightgray;
color: white;
}
button:active {
background-color: black;
color: white;
}
.checkbox-container {
display: flex;
flex-direction: row;
align-items: center;
}
.checkbox-label {
margin-right: 10px;
}
.checkbox {
margin-right: 10px;
}
/* To remove the scrollbars */
</style>
<body>
<script src="webgl-debug.js"></script>
<script>
Error.stackTraceLimit = Infinity;
function test() {
console.log("this is a test function!")
}
</script>
<canvas id="canvas"></canvas>
<div id="gui">
<h1>GSplat Viewer</h1>
<!-- <button onclick="">Testing</button> -->
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Show Octtree</label>
<input type="checkbox" class="checkbox" id="show-octtree-checkbox">
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Only Show Octree at Click </label>
<input type="checkbox" class="checkbox" id="only-show-clicks-checkbox">
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Use OctTree for Editing </label>
<input type="checkbox" class="checkbox" id="use-octtree-for-editing-checkbox" checked>
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">View Individual Splats </label>
<input type="checkbox" class="checkbox" id="view-individual-splats-checkbox">
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Do Sorting </label>
<input type="checkbox" class="checkbox" id="do-sorting-checkbox" checked>
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Do Blending </label>
<input type="checkbox" class="checkbox" id="do-blending-checkbox" checked>
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Move Down </label>
<input type="checkbox" class="checkbox" id="move-down-checkbox">
</div>
<div class="checkbox-container">
<label for="checkbox" class="checkbox-label">Detect Collisions With Gizmo</label>
<input type="checkbox" class="checkbox" id="restrict-gizmo-movement-checkbox">
</div>
<div style="margin: 10px 0px;">
<button id="calculate-shadows-btn">Calculate Shadows</button>
</div>
<div style="margin: 10px 0px;">
<button id="recalculate-octtree-btn">Recalculate Octtree</button>
</div>
<div style="margin: 10px 0px;">
<button id="add-shahan-btn">Add Shahan</button>
</div>
<div style="margin: 10px 0px;">
<button id="add-teapot-btn">Add Teapot</button>
</div>
<div style="margin: 10px 0px;">
<button id="split-object-btn">Split Object</button>
</div>
<div style="margin: 10px 0px;">
<span id="collision-detected-span" style="color: rgb(255, 50, 50);"></span>
</div>
<div style="margin: 10px 0px;">
<label for="model-switcher" style="color: white;">Switch Model:</label>
<select id="model-switcher" onchange="switchModel(this.value)"></select>
</div>
</div>
</div>
<script>
function getWebGLContext() {
ctx = WebGLDebugUtils.makeDebugContext(canvas.getContext("webgl2"));
return ctx;
}
function setCollisionDetected() {
document.getElementById("collision-detected-span").innerText = "Collision Detected";
setTimeout(() => {
document.getElementById("collision-detected-span").innerText = "";
}, 1000);
}
function switchModel(url) {
window.location.href = `./?url=${url}`;
}
const MODEL_LIST = [
{ display: "House", file: "./soc_01_polycam.rkyv" },
{ display: "E7 Outdoor", file: "./E7_01_id01-30000.rkyv" },
{ display: "E7 Indoor", file: "./Shahan_03_id01-30000.rkyv" },
{ display: "Grass", file: "./socratica_01_edited.rkyv" },
{ display: "Sci", file: "./sci_01_edited.rkyv" },
{ display: "Shahan", file: "./Shahan_03_id01-30000.cleaned.rkyv" },
// splats/Week-09-Sat-Nov-16-2024.rkyv
// splats/Week-10-Frid-Nov-22-2024-edited.rkyv
{ display: "Week 9 Sat Nov 16", file: "./Week-09-Sat-Nov-16-2024-edited.rkyv" },
{ display: "Week 10 Fri Nov 22", file: "./Week-10-Frid-Nov-22-2024-edited.rkyv" },
];
// Function to populate the dropdown
function populateModelSelector() {
const modelSelect = document.getElementById('model-switcher');
MODEL_LIST.forEach(model => {
const option = document.createElement('option');
option.value = model.file;
option.textContent = model.display;
modelSelect.appendChild(option);
});
}
// Modified window.onload to include populating the dropdown
window.addEventListener('load', function () {
populateModelSelector();
const urlParams = new URLSearchParams(window.location.search);
const currentUrl = urlParams.get('url');
const modelSelect = document.getElementById('model-switcher');
if (currentUrl) {
modelSelect.value = currentUrl;
} else {
modelSelect.value = "./Shahan_03_id01-30000.cleaned.rkyv"; // Default value
}
});
</script>
<script type="module">
const look_speed = 0.05;
const move_speed = 1;
function resizeCanvasToDisplaySize(canvas) {
// https://webgl2fundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html
// Lookup the size the browser is displaying the canvas in CSS pixels.
const displayWidth = canvas.clientWidth;
const displayHeight = canvas.clientHeight;
// Check if the canvas is not the same size.
const needResize = canvas.width !== displayWidth ||
canvas.height !== displayHeight;
if (needResize) {
// Make the canvas the same size
canvas.width = displayWidth;
canvas.height = displayHeight;
}
return needResize;
}
let canvas = document.getElementById("canvas");
resizeCanvasToDisplaySize(canvas);
// Add initialization button to the UI
const initButton = document.createElement('button');
initButton.textContent = 'Initialize WebAssembly';
initButton.style.position = 'absolute';
initButton.style.top = '10px';
initButton.style.right = '10px';
initButton.style.zIndex = '1000';
document.body.appendChild(initButton);
// Add a status message element
const statusMessage = document.createElement('div');
statusMessage.style.position = 'absolute';
statusMessage.style.top = '50px';
statusMessage.style.right = '10px';
statusMessage.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
statusMessage.style.color = 'white';
statusMessage.style.padding = '10px';
statusMessage.style.borderRadius = '5px';
statusMessage.style.zIndex = '1000';
statusMessage.style.maxWidth = '300px';
statusMessage.textContent = 'Click the button above to initialize';
document.body.appendChild(statusMessage);
// Use ES module import syntax to import functionality from the module
// that we have compiled.
//
// Note that the `default` import is an initialization function which
// will "boot" the module and make it ready to use. Currently browsers
// don't support natively imported WebAssembly as an ES module, but
// eventually the manual initialization won't be required!
import init from './pkg/gs_rust.js';
// Function to update status message
function updateStatus(message, isError = false) {
statusMessage.textContent = message;
statusMessage.style.backgroundColor = isError ? 'rgba(255, 0, 0, 0.7)' : 'rgba(0, 0, 0, 0.7)';
console.log(message);
}
// Worker reference
let worker = null;
// Function to initialize WebAssembly
async function initializeWasm() {
try {
updateStatus("Starting WebAssembly initialization...");
// Disable the button during initialization
initButton.disabled = true;
initButton.textContent = 'Initializing...';
// Initialize the WebAssembly module on the main thread
// This is needed to load the module initially
updateStatus("Loading WebAssembly module on main thread...");
await init();
updateStatus("WebAssembly module loaded successfully on main thread");
// Check for multithreading support
const hasSharedArrayBuffer = typeof SharedArrayBuffer !== 'undefined';
const hasAtomics = typeof Atomics !== 'undefined';
const multithreadingSupported = hasSharedArrayBuffer && hasAtomics;
if (!multithreadingSupported) {
updateStatus("Note: Multithreading not supported in this browser (SharedArrayBuffer or Atomics missing)", true);
console.warn("Multithreading not supported: SharedArrayBuffer or Atomics not available");
// Create a worker for single-threaded mode anyway
// This avoids Atomics.wait on main thread issues
createAndInitializeWorker(1);
} else {
// Calculate number of threads based on hardware concurrency
// Limiting to 2 threads for stability during testing
const numThreads = Math.min(navigator.hardwareConcurrency || 4, 2);
updateStatus(`Detected ${navigator.hardwareConcurrency} CPU cores, using ${numThreads} threads`);
// Create and initialize the worker with the thread pool
createAndInitializeWorker(numThreads);
}
} catch (error) {
console.error("Error during initialization:", error);
// Display error to user
initButton.textContent = 'Initialization Failed - Try Again';
initButton.disabled = false;
initButton.style.backgroundColor = 'red';
updateStatus(`Error: ${error.message}`, true);
}
}
// Function to create and initialize the worker
function createAndInitializeWorker(numThreads) {
try {
updateStatus(`Creating worker for thread pool initialization with ${numThreads} threads...`);
// Create the worker
worker = new Worker(new URL('./worker.js', import.meta.url), { type: 'module' });
// Set up message handler for the worker
worker.onmessage = function (e) {
const { status, message, success, threads, stack } = e.data;
switch (status) {
case 'worker_loaded':
updateStatus("Worker loaded successfully");
// Initialize the worker
worker.postMessage({ type: 'init', numThreads });
break;
case 'initializing_wasm':
updateStatus("Worker: Initializing WebAssembly module...");
break;
case 'wasm_initialized':
updateStatus("Worker: WebAssembly module initialized successfully");
break;
case 'initializing_thread_pool':
updateStatus(`Worker: Initializing thread pool with ${threads} threads...`);
break;
case 'thread_pool_initialized':
updateStatus("Worker: Thread pool initialized successfully!");
initButton.textContent = 'Initialized Successfully';
initButton.style.backgroundColor = 'green';
// Hide the status message after a delay
setTimeout(() => {
statusMessage.style.opacity = '0.5';
}, 3000);
// Tell the worker to execute any initial commands
worker.postMessage({ type: 'execute' });
break;
case 'ready_for_commands':
updateStatus("Worker: Ready to execute commands");
break;
case 'error':
console.error("Worker error:", message, stack);
updateStatus(`Worker error: ${message}`, true);
initButton.textContent = 'Initialization Failed - Try Again';
initButton.disabled = false;
initButton.style.backgroundColor = 'red';
break;
default:
console.log("Worker message:", e.data);
}
};
// Handle worker errors
worker.onerror = function (error) {
console.error("Worker error:", error);
updateStatus(`Worker error: ${error.message}`, true);
initButton.textContent = 'Initialization Failed - Try Again';
initButton.disabled = false;
initButton.style.backgroundColor = 'red';
};
} catch (error) {
console.error("Error creating worker:", error);
updateStatus(`Error creating worker: ${error.message}`, true);
initButton.textContent = 'Initialization Failed - Try Again';
initButton.disabled = false;
initButton.style.backgroundColor = 'red';
}
}
// Add click event listener to the initialization button
initButton.addEventListener('click', initializeWasm);
// Don't automatically initialize - wait for user to click the button
console.log("WebAssembly initialization deferred. Click the 'Initialize WebAssembly' button to start.");
</script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css">
</body>
</html>