-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.js
65 lines (58 loc) · 1.62 KB
/
init.js
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
let pyodide = null;
const files = [
"__init__.py",
"colormap.py",
"compute.wgsl",
"eval.wgsl",
"gpu.py",
"input_handler.py",
"main.py",
"mesh.py",
"shader.wgsl",
"uniforms.py",
"utils.py",
];
async function reload() {
try {
pyodide.FS.mkdir("webgpu");
} catch {}
for (var file of files) {
const data = await (
await fetch(`./webgpu/${file}`, { method: "GET", cache: "no-cache" })
).text();
pyodide.FS.writeFile("webgpu/" + file, data);
}
await pyodide.runPythonAsync(
"import webgpu.main; await webgpu.main.reload();",
);
}
async function main() {
console.log("loading pyodide", performance.now());
// const blob = await (await fetch("./pyodide/snapshot.bin")).blob();
// const decompressor = new DecompressionStream('gzip');
// const stream = blob.stream().pipeThrough(decompressor);
// const response = new Response(stream);
// return await response.arrayBuffer();
pyodide = await loadPyodide({
// _loadSnapshot: blob.arrayBuffer(),
});
pyodide.setDebug(true);
console.log("loaded pyodide", performance.now());
console.log(pyodide);
await pyodide.loadPackage(["netgen", "ngsolve", "packaging", "numpy"]);
console.log("loaded netgen", performance.now());
try {
const socket = new WebSocket("ws://localhost:6789");
socket.addEventListener("open", function (event) {
console.log("WebSocket connection opened");
});
socket.addEventListener("message", function (event) {
console.log("Message from server ", event.data);
reload();
});
} catch {
console.log("WebSocket connection failed");
}
reload();
}
main();