Visualize 3D mesh with texture



Hi all,

I am trying to visualize 3D CAD objects in Julia. Context: I have a CAD model for a spacecraft and I want to display it in my Julia application.

So far, I can convert the native CAD file into an .stl or .obj file, and load it and visualize with GLVisualize (although the result is not a crisp “clean” mesh, but that’s a different story), and I think I should also be able to do that via MayaVi, although I haven’t figured it out yet. PyCall with MayaVi

What I would like to be able to do is also load and display the texture that is encoded in the OBJ file to go from a monochrone mesh display to the native colored CAD model

Any insight on if there is a way to accomplish that today with Julia?


Can you save it as .ply?

FYI: I am finalizing a module that uses VTK through PyCall to read, write and visualize all the following formats: vtk, vtu, vtp, vts, vtr, vti, vtm, pvd (no visualization yet), ply, stl. It can also write colored x3d files. I also just tested some 3ds file visualization function in VTK and I might add it before the announcement. Of all the listed formats, only 3ds, ply and x3d are colored, and only ply can be read back to a vtkPolyData with the color as a data array, as far as I know. I tested the obj reader in VTK and it doesn’t seem to properly read the material library, maybe I am missing something. Anyways, the documentation for my module should be out in a few days at most. The module also can give you a VTK data PyObject that can seamlessly interface with any VTK filter or MayaVI function you like, hopefully! Stay tuned!


that was actually part of GLVisualize at some point, until a rewrote complicated things and I removed it, since nobody was using it anyways!
Fun fact: the actual problem is how to represent the mesh type and correctly parse the material library of the obj!
Rendering is just a two line change to my current code!

although the result is not a crisp “clean” mesh, but that’s a different story

Are you talking about the anti-aliasing?


It does not appear so. We are using Fusion 360 for the CAD and the export formats are: iges, sat, smt, step, dwg, dxf, stl, fbx, sketchup, obj (as far as I know) – you did mention stl in your list of supported formats, but I am not sure if STL files include color/texture information.

I’ll definitely check out VTKDataIO.jl tho, it sounds quite interesting.


Ah! Yes, that seems to be the bottle neck as if I manually load the mesh using Meshes.jl or MeshIO.jl, I see that the homogeneous mesh that is created only has geometrical properties, no information about the colors or materials.

Now that I’ve looked more into it, I see that another problem on my end is that Fusion 360, a.k.a Autodesk, does not export UV or texture, so there is that…

As for my comment about the crisp clean mesh, here is what I’m referring to:

I may not be using GLVisualize properly…to generate that rendering, I essentially took the example script rotate_obj.jl, killed the rotation to make sure that was not the problem, and subbed in my obj file. Am I missing something?



Blender can take in obj or fbx and change it to 3ds. You can also check there what is exported exactly from Fusion 360 to see if it is a problem in the exporter or the importer that you are having, or both! STL doesn’t support color or texture as far as I know. I think any other computer graphics software like 3ds Max or Maya should also be able to do the same thing as Blender.


Cool, thanks for the input – definitely useful once I figure out the rest, as it seems that the Fusion 360 exporter does not support material/color. Users have been asking for it for ages but it does not appear to be a high priority item on their list…


Ahhh, yeah that looks wrong! This is either a problem with MeshIO (corrupting some faces?), or it’s something I just recently fixed!


Yea, I’m not sure.
I just did Pkg.Update() and I have – I think – all the latest versions of the packages, including the master of GLVisualize, from Pkg.status():

  • GLVisualize 0.3.0+ master

But to no avail. I’m gonna try to load up the OBJ file into Blender to see if the issue is with the Fusion 360 exporter or Julia


Sorry, I should have been more explicit… it’s not on any tagged version :frowning:


I came across a Fusion 360 plugin to export models into PLY files – should it actually work – I should then able to use your package to render it, correct? I’ll give it a spin


Ahhh I see – and excuse my lack of knowledge here but that means until it is tagged, or released, or whatever appropriate technical terms I am missing, it is not accessible to the common people ;), right?


Can you share that .obj file? Or, if not, any other .obj file which doesn’t render properly for you? We can try loading it with DrakeVisualizer.jl which uses the MeshIO loading functions but not the GLVisualize rendering functions. That would help determine if it’s something wrong in MeshIO (possibly something I did with my recent updates to that package).


Correct, if the RGB colors are included in the .ply file when exported by your software.


@mohamed82008, that is awesome, please keep working on this project :slight_smile: it will definitely be very useful to many of us. I was always looking for VTK read/write in Julia. Hopefully at some point you can drop the Python dependency as well?


Thanks for your words!

I don’t think dropping the Python dependency completely is a wise move especially that by IO, I also mean the simple visualization and rendering aspect which I think is best left to VTK. For instance, direct visualization of files might be something of use, in which case there is no need to go from Julia to VTK, it can all be done in VTK.

However, making readers and writers purely in Julia certainly seems like the right way of doing things especially that it is mostly just reading and writing XML files for which there are tools in Julia. I am presonally not so much of a purist myself, so I wouldn’t go too far just to get rid of the Python dependency but any pull request that doesn’t mess with the remaining use cases is certainly more than welcome :slight_smile:

Btw VTK is also used for writing vtp files which WriteVTK doesn’t support. I also adapted the vtm and pvd writing codes from WriteVTK to enable them to reference other vtp files, so the dependency is quite rooted in the reading and writing code.


That is probably the depth-fighting issue, I believe setting the near clip and far clip to sensible values
will solve this.

try setting the near clip to 10% of norm(eyeposition-lookat) and the far clip to 300% of that

the Light position is probably also wrong this is why the shading doesn’t look good.


@TsurHerman Yes, Simon solved the rendering issue for me, my mesh dimensions not being normalized between -1/+1, the default settings for the camera were not adequate,

push!(window.cameras[:perspective].nearclip, 2f0)

Your solution might even better as it could take care of it regardless of the absolute dimensions of the objects


I was able to export my spacecraft model in FBX from Fusion360, import in Blender and export as 3DS… and visualize it with VTKDataIO in colors! :slight_smile: Not exactly the most streamlined process yet, but at least I’m getting somewhere. The interacting with the model is pretty slow (rotating, zooming, …) and I think that’s because the model is quite heavy.
I tried to play witth OBJ/MTL in case it would help with performance but I too am having issue with VTK interpreting the MTL file. Odd.

To be continued…


I am glad it worked!

You can consider reducing the poly count if all you want is a colored visualization and/or you have many straight faces which are excessively split into many triangles. You can do this in VTK using vtkDecimatePro, vtkQuadricClustering, or vtkQuadricDecimation (just pulled them off from the docs, I didn’t test them myself). Or in Blender, you can also use the decimate modifier if you don’t mind abit of manual work or if you know how to write Blender scripts, there are plenty of videos on youtube about Blender.

Edited to add: Perhaps Blender is a better option so you don’t lose your precious colors!