How to do backface culling when rendering Mesh3d


Is there an option in Mesh3d that toggles rendering of backfaces? I.e. faces whose normals point away from the camera (showing its backface). This is a standard openGL/webGL feature, so I wonder if plotly has a way to enable it if it’s not currently supported.


1 Like

Hi @danielyan86129

are you referring to this?

In my experience it sometimes helps, playing with the lightning (example code from one of my experiments):

    # update lightning

Thanks for the reply @AIMPED. Let me explain more:
Take a house viewed from far outside as an example, and I’m using MeshLab to demo the renderings. If we choose to render all faces, we only see its outside “walls”, like this:

In fact the walls have normals pointing not towards the eye, but away from us, aka back-faces. This is because the “wall” is just the other side of the same faces that also represent the interior geometry. To reveal the interior geometry, a standard technique is asking GL to cull those faces, which exposes all interior faces whose normals point towards us, i.e. front-faces:

In order to do this I think plotly should be able to take in vertex/face normals as additional input. Let me know if this makes sense.

Hi @danielyan86129 ,

now I think I understood your question :wink:

Unfortunately I have no direct answer to it. I did not find any reference to this in the help. As I understand, the mesh3D uses Delaunay triangulation which in your case you had to control the normal of the triangles, right? I am not sure if you can do so.

Did you yet try to show your data in a mesh3D ?

Yes I’m able to render my mesh using Mesh3D:

As you can see the interior is fully blocked by the outside walls. On the other hand I can do back-face culling with TriMesh built-in rendering easily:

I really hope Plotly can add this support (@AIMPED Could you maybe @ the person who drives 3d rendering features in Plotly?)

the mesh3D uses Delaunay triangulation

Delaunay triangulation is not involved in rendering a triangle mesh. In fact, it’s an algorithm that generates triangle mesh from a point cloud, so it sits more on the pre-processing side. I know Mesh3D can run it automatically to “mesh” the point cloud as a convenience provided for the user.

you had to control the normal of the triangles, right?

Ideally, from the API side, Plotly can expose “normals” parameter and a flag for “back-face culling”, sth like:

    # existing params,

This way during runtime, plotly internally passes the normals and back-face culling flag to underlying rendering engine, e.g. WebGL, which knows which faces are back-faces based on their normals and the current camera.

Ahh, I thought your mesh was based on a point cloud, but since you are using trimesh you already have your mesh.

In the past I messed around with VTK for displaying mesh structures, but my experience is very limited. Mabe it helps.

At least there is a property for culling:

1 Like

Thanks. Yea VTK is very powerful so this definitely looks plausible there. I didn’t know Dash has so many C++ visualization libs integrated already. That’s going to be very handy later when I need them.