Exporting normals from opend3d or trimesh for plotly Mesh3d

Hi Plotlyers,

I am trying to export normals to vertexes of a 3d mesh created in opend3d in a format suitable to Mesh3d (i,j,k vectors).

I have a working mesh computer with the Poisson method from which I extract the vertexes coordinates and the normals to the vertexes

poisson_mesh, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=9, width=0, scale=4, linear_fit=False)

xgo=np.asarray(poisson_mesh.vertices).T[0]
ygo=np.asarray(poisson_mesh.vertices).T[1]
zgo=np.asarray(poisson_mesh.vertices).T[2]

tigo=np.asarray(poisson_mesh.vertex_normals).T[0]
tjgo=np.asarray(poisson_mesh.vertex_normals).T[1]
tkgo=np.asarray(poisson_mesh.vertex_normals).T[2]

upon plotting these into plotly there is just an empty plot:

fig4 = go.Figure(go.Mesh3d(x=xgo, y=ygo, z=zgo, 
                             i=tigo, j=tjgo, k=tkgo, 
                              intensity=dgo,
                             colorscale="Viridis",
                           colorbar_len=0.75,
                           flatshading=True,
                           lighting=dict(ambient=0.5,
                                         diffuse=1,
                                         fresnel=4,        
                                         specular=0.5,
                                         roughness=0.05,
                                         facenormalsepsilon=0,
                                         vertexnormalsepsilon=0),
                          lightposition=dict(x=100,
                                             y=100,
                                            z=1000)))
fig4.update_layout(width=800, height=800)
fig4.show()

just the coordinates and perhaps the parameter alphahull=3.5 (without i,j,k) are giving the desired plot.
The shape of each x, y and z is n, as well as the shape of i, j and k, and according to the docs that’s ok. How can I check the condition {i[m], j[m], k[m]} together represent face m (triangle m) in the mesh, where i[m] = n points to the triplet {x[n], y[n], z[n]}? Is this a convention across different libraries?

I tried to pass all the o3d through trimesh:

tri_mesh_pois = trimesh.Trimesh(np.asarray(poisson_mesh.vertices), np.asarray(poisson_mesh.triangles),vertex_normals=np.asarray(poisson_mesh.vertex_normals))

ti=tri_mesh_pois.vertex_normals.T[0]
tj=tri_mesh_pois.vertex_normals.T[1]
tk=tri_mesh_pois.vertex_normals.T[2]

the shape is the same, the numbers are different (I think they have been automatically normalised), but using these new normals doesnΒ΄t solve the problem: still no plot.

Any suggestion?

Hi @giammi56

The arrays i, j, k do not represent the normal coordinates. For each n, i[n] j[n] k[n] are the indices in the array of vertices of the points that define the nth triangle.

To be able to define an instance of the class go.Mesh3d you don’t need the normals.

If

poisson_mesh density=  o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(pcd, depth=9, width=0, scale=4, linear_fit=False)

then you can get the reconstructed mesh vertices and triangles as follows:

tigo, tjgo, tkgo= np.asarray(poisson_mesh.triangles).T
xgo, ygo, zgo= np.asarray(poisson_mesh.vertices).T

Thank you, it is working just perfectly!