VTK.js + trame: No textures in local rendering => minimal example for python ?

Hey everyone,

I’m a new and unexperienced user of VTK + Trame for displaying mechnical parts in a browser and
I’m impressed what can be done with just a few lines of code.
So far, I got a working python-code to render my parts coming from a calculation-script,
what is my major topic.
I’m thinking of using Trame + VTK to present/share these results with other
team-members; it would be very handy for them just to open their brower to get a
first impression of these parts.
Local rendering would be pretty useful, because some team-members may be far away.

So far, I got everthing working what I wanted to achieve, except one thing:
textures in local-rendering mode.
I’m likely facing the same trouble that is already described here:

Short description: The skybox and other textures work fine in remote-rendering-mode, but
vanish when switching to local-rendering mode.

I added the textures a little different, but I guess it is the same problem:

jpg_img_reader = vtk.vtkJPEGReader()
jpg_img_reader.SetFileName(‘Feldanker_1.jpg’)
#jpg_img_reader.SetFileName(“http://localhost:8800/html/Feldanker_1.jpg”) # Failed!

Box_texture = vtk.vtkTexture()
Box_texture.SetInputConnection(jpg_img_reader.GetOutputPort())
Box_texture.Modified()

Box_source = vtk.vtkCubeSource()
Box_Mapper = vtk.vtkPolyDataMapper()
Box_Mapper.SetInputConnection(Box_source.GetOutputPort())

Box_Actor = vtk.vtkActor()
Box_Actor.SetMapper(Box_Mapper)
Box_Actor.SetTexture(Box_texture)
Box_Actor.GetProperty().SetDiffuse(0.1)
Box_Actor.GetProperty().SetAmbient(1.0)
plotter.add_actor(Box_Actor)

Skybox = vtk.vtkSkybox()
Skybox.SetTexture(sky_map)
Skybox.SetFloorRight(0, 0, 1)
Skybox.SetProjection(vtk.vtkSkybox.Cube)
plotter.add_actor(Skybox)
....

A similar question to the vanishing textues was asked here a short time ago:

, but it is unclear to me how it was solved.
Going throught the skybox-C+±Examples mentioned there did not help me, some classes
are missing in the python-VTK-package, e.g. there seems to be no vtkHttpDataSetReader.

I understand, that vtk and vtk.js is not 100% the same, but is there a minimal example
for python similar to

to solve the issue with missing textures in the skybox and/or planes in local rendering mode?

Welcome to the community!

Since you are using VTK, you might be ok by using trame-vtklocal with just 2 lines change.

Basically replace trame.widgets.vtk.VtkLocalView by trame.widgets.vtklocal.LocalView.

You will need vtk 9.4+ and trame-vtklocal

pip install "vtk>=9.4.1" trame-vtklocal

You can find a usage example here.

Hey Sebastien,

thank you very much, your example helped me to get the textures to work!
I successfully got cubemaps and HDR to work for the skybox.

Just one more thing: I guess, the addtional window should be synchronized with the browser-window(?) This doesn’t work for me, the second window always freezes, also with the original example-code.

1 Like

You should set your render window to be offscreen, that will prevent that window to even pop-up.

Dear VTK-team,
dear Sebastien,

from older discussion on stack-overflow I got the impression, that local-rendering comes with some limitation, is this any longer true? I’m really happy, that also PBR is availible in local-rendering-mode.

I just want to to say thank you for your help and this great piece of software!

1 Like

Any limitation for local rendering when using VTK/WASM should totally disappear by end of 2025 (:crossed_fingers:). And as you’ve notice we are already pretty far along, but we can still expect some hiccup here and there.

Since VTK is working on moving to WebGPU, it will address a lot of the rendering limitation we currently have in the browser too. Also we are working to add more testing especially targeting our serialization infrastructure for our WASM usage. When those complete, we should reach full parity. And like I said, a lot of that is expected to happen in 2025.