Commit d99340d8 authored by Janis Born's avatar Janis Born

fix calculate_point_normals for meshes with arbitrary face valence

parent b6bfd323
......@@ -49,15 +49,9 @@ def calculate_point_normals(vertices, face_indices):
fn = calculate_face_normals(v, f).values
vi = np.ravel(f)
fi = np.repeat(np.arange(f.shape[0]), 3, axis=0)
fi = np.repeat(np.arange(f.shape[0]), f.shape[1], axis=0)
vn = np.zeros_like(v)
np.add.at(vn, vi, fn[fi])
# faster, but requires SciPy:
# fv_matrix_rows = np.ravel(f)
# fv_matrix_cols = np.repeat(np.arange(f.shape[0]), 3, axis=0)
# fv_matrix = sp.sparse.coo_matrix((np.ones_like(fv_matrix_rows), (fv_matrix_rows, fv_matrix_cols)))
# vn = fv_matrix @ fn
np.add.at(vn, vi[vi >= 0], (fn[fi])[vi >= 0])
vn /= np.linalg.norm(vn, axis=1)[:, np.newaxis]
return PointAttribute(vn)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment