Kramer84 / pyfqmr-Fast-Quadric-Mesh-Reduction

Mesh triangle reduction using quadrics

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add normals to mesh

FreakTheMighty opened this issue · comments

I noticed that vertex, faces, and vertex color can be passed in for decimation. It it possible to also pass in vertex normals?

Hi @FreakTheMighty! No, passing vertex normals to the C++ source code is not implemented and it would only add a layer of complexity if the data contained in the vertex normals needs to be converted to the classic face/vertex inputs. This should be done using other tools I think.

If you are only interested in getting the vertex normals post decimation, it shouldn't be difficult to calculate them using only the vertex and face arrays. Like averaging the normals of each face connected to some vertex.

Concerning the vertex colors, they are passed as an argument in the setMesh method, but only as a reminder that passing and tracking vertex colors is still to be implemented as seen in this issue .

The algorithm does not require the normals, as these can be inferred from the winding-order and the cross-product of the edges.

Trimesh provides the option to include vertex normals when you define a mesh. You can use mean_vertex_normals to recompute normals:

import pyfqmr
import trimesh as tr
bunny = tr.load_mesh('./example/Stanford_Bunny_sample.stl')
mesh_simplifier = pyfqmr.Simplify()
mesh_simplifier.setMesh(bunny.vertices, bunny.faces)
mesh_simplifier.simplify_mesh(target_count = 1000, aggressiveness=7, preserve_border=True, verbose=10)
vtx, fc, normals = mesh_simplifier.getMesh()
mesh = tr.Trimesh(vertices=vtx,faces=fc)
mesh.export("~/simple.obj")
norm = tr.geometry.mean_vertex_normals(len(mesh.vertices), mesh.faces,mesh.face_normals)
mesh = tr.Trimesh(vertices=vtx,faces=fc, vertex_normals=norm)
mesh.export("~/simple_w_normals.obj", include_normals=true)