Skip to content

Commit

Permalink
feat(vtk-wasm): rely on vtk-wasm wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Mar 18, 2024
1 parent fc63f26 commit 3728849
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 34 deletions.
2 changes: 1 addition & 1 deletion examples/vtk/cone.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, server=None):
self.server.state.update(dict(mem_blob=0, mem_vtk=0))
self.html_view = None
self.ui = self._ui()
print(self.ui)
# print(self.ui)

@change("resolution")
def on_resolution_change(self, resolution, **kwargs):
Expand Down
12 changes: 5 additions & 7 deletions examples/vtk/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def create_vtk_pipeline():
isoActor = vtkActor()
isoActor.SetMapper(isoMapper)
isoActor.GetProperty().SetRepresentationToWireframe()
isoActor.GetProperty().SetOpacity(0.25)
# isoActor.GetProperty().SetLineWidth(2)
isoActor.GetProperty().SetOpacity(0.75)

# Outline

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

def _ui(self):
with DivLayout(self.server) as layout:
layout.root.style = "width: 100vw; height: 100vh;"
client.Style("body { margin: 0; }")
self.html_view = vtklocal.LocalView(
self.render_window, style="width: 100vw; height: 100vh;"
)
# vtk_widgets.VtkRemoteView(
# self.render_window, style="width: 100vw; height: 100vh;"
# )
self.html_view = vtklocal.LocalView(self.render_window)
# vtk_widgets.VtkRemoteView(self.render_window)

return layout

Expand Down
2 changes: 1 addition & 1 deletion examples/vtk/widgets_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_vtk_pipeline(path):
colors = vtkNamedColors()
data_source = None

if Path(path).is_file():
if path is not None and Path(path).is_file():
data_source = vtkXMLPolyDataReader()
data_source.SetFileName(path)
else:
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ packages = find:
include_package_data = True
install_requires =
trame_client
vtk-wasm

[semantic_release]
version_pattern = setup.cfg:version = (\d+\.\d+\.\d+)
33 changes: 27 additions & 6 deletions trame_vtklocal/module/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
from pathlib import Path
from wslink import register as export_rpc
from wslink.websocket import LinkProtocol
from trame_client.utils.web_module import file_with_digest

from vtkmodules.vtkSerializationManager import vtkObjectManager
import vtk_wasm

__all__ = [
"serve",
"scripts",
"module_scripts",
"state",
"vue_use",
"setup",
"get_helper",
]

serve_path = str(Path(__file__).with_name("serve").resolve())

serve = {"__trame_vtklocal": serve_path}
module_scripts = [
"__trame_vtklocal/wasm/vtkWasmSceneManager-9.3.mjs",
]
scripts = [
"__trame_vtklocal/js/trame_vtklocal.umd.js",
]
state = {}
scripts = ["__trame_vtklocal/js/trame_vtklocal.umd.js"]
vue_use = ["trame_vtklocal"]
module_scripts = []


def register_wasm():
global serve, module_scripts, state
BASE_URL = "__trame_vtklocal_wasm"
wasm_path = Path(vtk_wasm.__file__).parent.resolve()
serve[BASE_URL] = str(wasm_path)
for file in wasm_path.glob("vtkWasmSceneManager*"):
if file.name.rfind("-") != len("vtkWasmSceneManager"):
continue # skip digested files

file = file_with_digest(file, digest_size=6)
if file.suffix == ".mjs":
module_scripts.append(f"{BASE_URL}/{file.name}")

if file.suffix == ".wasm":
state[f"{BASE_URL}_name"] = file.name


register_wasm()

# -----------------------------------------------------------------------------
# Protocol
Expand Down
16 changes: 0 additions & 16 deletions trame_vtklocal/module/serve/wasm/vtkWasmSceneManager-9.3.mjs

This file was deleted.

Binary file not shown.
3 changes: 2 additions & 1 deletion vue-components/src/components/VtkLocal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
},
setup(props, { emit }) {
const trame = inject("trame");
const wasmFile = trame.state.get("__trame_vtklocal_wasm_name");
const container = ref(null);
const canvas = ref(null);
const client = props.wsClient || trame?.client;
Expand Down Expand Up @@ -173,7 +174,7 @@ export default {

onMounted(async () => {
// console.log("vtkLocal::mounted");
sceneManager = await createModule(unref(canvas));
sceneManager = await createModule(unref(canvas), wasmFile);
await update();
// sceneManager.addObserver(props.renderWindow, "StartEvent", (id, eventName) => {
// eventName = sceneManager.UTF8ToString(eventName);
Expand Down
4 changes: 2 additions & 2 deletions vue-components/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export async function createModule(canvas) {
export async function createModule(canvas, wasmFile) {
const module = {
canvas,
locateFile() {
return "__trame_vtklocal/wasm/vtkWasmSceneManager-9.3.wasm";
return `__trame_vtklocal_wasm/${wasmFile}`;
},
print() {
console.info(Array.prototype.slice.call(arguments).join(" "));
Expand Down

0 comments on commit 3728849

Please sign in to comment.