Skip to content

Commit 3728849

Browse files
committed
feat(vtk-wasm): rely on vtk-wasm wheel
1 parent fc63f26 commit 3728849

File tree

9 files changed

+39
-34
lines changed

9 files changed

+39
-34
lines changed

examples/vtk/cone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, server=None):
6161
self.server.state.update(dict(mem_blob=0, mem_vtk=0))
6262
self.html_view = None
6363
self.ui = self._ui()
64-
print(self.ui)
64+
# print(self.ui)
6565

6666
@change("resolution")
6767
def on_resolution_change(self, resolution, **kwargs):

examples/vtk/flow.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def create_vtk_pipeline():
100100
isoActor = vtkActor()
101101
isoActor.SetMapper(isoMapper)
102102
isoActor.GetProperty().SetRepresentationToWireframe()
103-
isoActor.GetProperty().SetOpacity(0.25)
103+
# isoActor.GetProperty().SetLineWidth(2)
104+
isoActor.GetProperty().SetOpacity(0.75)
104105

105106
# Outline
106107

@@ -141,13 +142,10 @@ def __init__(self, server=None):
141142

142143
def _ui(self):
143144
with DivLayout(self.server) as layout:
145+
layout.root.style = "width: 100vw; height: 100vh;"
144146
client.Style("body { margin: 0; }")
145-
self.html_view = vtklocal.LocalView(
146-
self.render_window, style="width: 100vw; height: 100vh;"
147-
)
148-
# vtk_widgets.VtkRemoteView(
149-
# self.render_window, style="width: 100vw; height: 100vh;"
150-
# )
147+
self.html_view = vtklocal.LocalView(self.render_window)
148+
# vtk_widgets.VtkRemoteView(self.render_window)
151149

152150
return layout
153151

examples/vtk/widgets_camera.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_vtk_pipeline(path):
2828
colors = vtkNamedColors()
2929
data_source = None
3030

31-
if Path(path).is_file():
31+
if path is not None and Path(path).is_file():
3232
data_source = vtkXMLPolyDataReader()
3333
data_source.SetFileName(path)
3434
else:

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ packages = find:
2828
include_package_data = True
2929
install_requires =
3030
trame_client
31+
vtk-wasm
3132

3233
[semantic_release]
3334
version_pattern = setup.cfg:version = (\d+\.\d+\.\d+)

trame_vtklocal/module/__init__.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
from pathlib import Path
22
from wslink import register as export_rpc
33
from wslink.websocket import LinkProtocol
4+
from trame_client.utils.web_module import file_with_digest
45

56
from vtkmodules.vtkSerializationManager import vtkObjectManager
7+
import vtk_wasm
68

79
__all__ = [
810
"serve",
911
"scripts",
12+
"module_scripts",
13+
"state",
1014
"vue_use",
1115
"setup",
1216
"get_helper",
1317
]
1418

1519
serve_path = str(Path(__file__).with_name("serve").resolve())
20+
1621
serve = {"__trame_vtklocal": serve_path}
17-
module_scripts = [
18-
"__trame_vtklocal/wasm/vtkWasmSceneManager-9.3.mjs",
19-
]
20-
scripts = [
21-
"__trame_vtklocal/js/trame_vtklocal.umd.js",
22-
]
22+
state = {}
23+
scripts = ["__trame_vtklocal/js/trame_vtklocal.umd.js"]
2324
vue_use = ["trame_vtklocal"]
25+
module_scripts = []
26+
27+
28+
def register_wasm():
29+
global serve, module_scripts, state
30+
BASE_URL = "__trame_vtklocal_wasm"
31+
wasm_path = Path(vtk_wasm.__file__).parent.resolve()
32+
serve[BASE_URL] = str(wasm_path)
33+
for file in wasm_path.glob("vtkWasmSceneManager*"):
34+
if file.name.rfind("-") != len("vtkWasmSceneManager"):
35+
continue # skip digested files
36+
37+
file = file_with_digest(file, digest_size=6)
38+
if file.suffix == ".mjs":
39+
module_scripts.append(f"{BASE_URL}/{file.name}")
40+
41+
if file.suffix == ".wasm":
42+
state[f"{BASE_URL}_name"] = file.name
43+
2444

45+
register_wasm()
2546

2647
# -----------------------------------------------------------------------------
2748
# Protocol

trame_vtklocal/module/serve/wasm/vtkWasmSceneManager-9.3.mjs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Binary file not shown.

vue-components/src/components/VtkLocal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default {
1717
},
1818
setup(props, { emit }) {
1919
const trame = inject("trame");
20+
const wasmFile = trame.state.get("__trame_vtklocal_wasm_name");
2021
const container = ref(null);
2122
const canvas = ref(null);
2223
const client = props.wsClient || trame?.client;
@@ -173,7 +174,7 @@ export default {
173174

174175
onMounted(async () => {
175176
// console.log("vtkLocal::mounted");
176-
sceneManager = await createModule(unref(canvas));
177+
sceneManager = await createModule(unref(canvas), wasmFile);
177178
await update();
178179
// sceneManager.addObserver(props.renderWindow, "StartEvent", (id, eventName) => {
179180
// eventName = sceneManager.UTF8ToString(eventName);

vue-components/src/utils/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
export async function createModule(canvas) {
1+
export async function createModule(canvas, wasmFile) {
22
const module = {
33
canvas,
44
locateFile() {
5-
return "__trame_vtklocal/wasm/vtkWasmSceneManager-9.3.wasm";
5+
return `__trame_vtklocal_wasm/${wasmFile}`;
66
},
77
print() {
88
console.info(Array.prototype.slice.call(arguments).join(" "));

0 commit comments

Comments
 (0)