Mutli texture rendering with obj + mlt + multiple jpgs

I have a 3D mesh in OBJ format created by a commercial stereophotogrammetry setup. It has an associated .mtl file and a couple JPGs for texture. My collaborators need to use texture to annotate some curves/points on these meshes in Slicer. Texture Model and similar python scripts work great when you have only 1 JPG file as a texture (and 1 array in the OBJ file for texture coordinates) but I was unable to replicate it with multiple textures.

I was also unsuccessful in implementing a python script (in and out of Slicer) for multi-texture rendering - where I read JPGs one by one, create vtkTexture objects, and use MapDataArrayToMultiTextureAttribute function from vtkPolyDataMapper. I tried EdgeClamping, changing texture coordinates from -1 to 1.1, different blending modes etc. No hope. If I use additive blending, then overlapping regions get very bright, if I “replace” option then only the last texture file is shown. In short, I’ve tried lots of combinations but nothing worked.

Then I found vtkOBJImporter class - I know, it does exactly what I need. It reads the .mtl and .jpgs and creates a beautiful vtkActor with the right texture mapping. It was like magic after days of reading texture blending and edge clamping. Now, my question is, how can I use this in Slicer? vtkOBJImporter gives me a RendererWindow (which I can put into a vtkRenderWindowInteractor outside the Slicer) but Slicer has its own renderWindow and renderer and interactor etc. Can I replace them? Can I get Actors and Mappers from Importer and push into Slicer’s renderer?

Any help with multi-texture rendering in Slicer would be appreciated. I really think the second option with vtkOBJImporter is simpler but if you have pointers on multi-texture blending I can provide data and code.

Thanks!

1 Like

It is good to know that VTK can now import multi-textured OBJ files correctly.

You can add actors directly in the Slicer render window (see examples in the script repository), but that would not be usable for much (you would see the model but could not interact with it, you would need to add it to each view, implement slice intersections, etc.).

Since multi-textured models are so rare, I don’t think we will add support for them in Models module. But you should be able to easily convert such a mesh by reading using vtkOBJImporter then immediately writing it to a single-texture VTP using vtkSingleVTPExporter.

This all should not take more than a few lines of code, but even that could be hard to figure out for users. So, it would be nice if you could add this feature to TextureModel module. For example, add a “Import multiple textures” checkbox and if it is checked then run the OBJ through import & single VTP export and use this generated VTP file as input.

1 Like

Thanks Andras, that’s a great idea.
It works for my data and I will add it to TextureModel module.

1 Like

Dear ezgimercan:
I’m interested in reading multi-texture obj files through python like you. But after reading the article, the textures loading is still not very well. Is there any github code for me to learn VTK load multiple textures? thank you very much.

Sincerely,
Yen-Hong Chen

Hi Yen-Hong,
You can see my updates to Texture Model module (included in Slicer IGT extension) here:

2 Likes