Black Lives Matter. Please consider donating to Black Girls Code today.

Visualize 3D models saved as Wavefront .OBJ files

Hello. What would be an optimal way to visualize 3D objects saved as Wavefront .OBJ files ?
Wavefront .OBJ file wikipedia
Say, I can read the .OBJ files with the PyWavefront package, but what would be the next steps?
Any suggestions?
Or probably there are other file formats for 3D modeling, which would be a better choice to work with
Thank you.

Hi @vasily,

I think you could get most of the way there using the mesh3d trace type. This allows you to specify the x/y/z coordinates of a vertex list, and then arrays of the i/j/k indices into the vertex lists to define the triangles.

I’m not very familiar with the details of the obj format, but from looking the the wikipedia link briefly, it looks like wafefront files support arbitrary polygons, whereas mesh3d only supports triangles. So one thing you may need to do is triangulate the polygons.

Another consideration is that mesh3d support coloring on a per triangle basis using facecolor and it won’t support all of the texture options that obj files have.

Hope that helps get you started!



Take a look at this notebook, I posted for a similar question addressed here a while ago:

1 Like

Thank you @empet and @jmmease for your reply!
I was expecting something like that - just wondering if I was missing some key standard approaches.
@jmmease I appreciate your comments and suggestions!
@empet Somehow I did not find your post. Thank you for your notes! It is very helpful.

“OBJ export options for isosurface engine and volume”

I am quite familiar with .OBJ format. And I think this ticket is related to improting the OBJ files into Plotly ecosystem, possibly as a new trace type?
@alexcjohnson also cc: @maxt

I made a python package to import wavefront obj files into 3dmesh.
A work in progress (part of a larger project) but it works!
[](http://pypi link )

Thank you for this idea,
ust question please. In case we have the *.mtl file for the texture can we loaded in the plotting figure

This sound extremly useful. I have two questions. First, if we use obj-files to visualise date by color, is there a way to change the colors? Secondly, if each corner in the triangle represent a value, would it be possible to create gradients to shoe this?



Do you associate the date to vertices or to faces?

Mesh3d has a property, intensity, that can be a list of values associated either to vertices or to faces.
These values are colormapped i.e. mapped to the colors of a colorscale.
By default the intensities are associated to vertices. When the intensity list has the length equal to the number of faces then setting intensitymode='cell', the values associated to faces are colormapped.
In these subplots the vertex intensities are set in the left plot, while in the second, the face intensities.

      Another property is  vertexcolor,  that can be an array/list of  rgb color codes (like this 'rgb(213,29,84)')  or hexcolors.

An instance of Mesh3d is then defined as follows:

go.Mesh3d(x=X, y=Y, z=Z,
          i=I, j=J, k=K,

Similar you can give facecolor as a list of rgb color codes.
For a complete description of the class go.Mesh3d, see []( .

@maxt In addition to great info mentioned by @empet,
various coloring options are presented in this demo.