make sure triangulate_rings does not create triangles with no area
This commit is contained in:
parent
0b4964f629
commit
c9b9c8b38d
2 changed files with 12 additions and 3 deletions
|
@ -20,7 +20,7 @@ class WavefrontEngine(Base3DEngine):
|
|||
vertices_lookup = {vertex: i for i, vertex in enumerate(vertices, start=1)}
|
||||
|
||||
normals = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).reshape((-1, 3))
|
||||
normals = normals / np.maximum(1, np.amax(np.absolute(normals), axis=1)).reshape((-1, 1))
|
||||
normals = normals / np.amax(np.absolute(normals), axis=1).reshape((-1, 1))
|
||||
normals = tuple(set(tuple(normal) for normal in normals))
|
||||
normals_lookup = {normal: i for i, normal in enumerate(normals, start=1)}
|
||||
|
||||
|
@ -50,7 +50,7 @@ class WavefrontEngine(Base3DEngine):
|
|||
if not facets.size:
|
||||
continue
|
||||
normals = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).reshape((-1, 3))
|
||||
normals = normals / np.maximum(1, np.amax(np.absolute(normals), axis=1)).reshape((-1, 1))
|
||||
normals = normals / np.amax(np.absolute(normals), axis=1).reshape((-1, 1))
|
||||
normals = tuple(normals_lookup[tuple(normal)] for normal in normals)
|
||||
result += ((b'g %s_%d_%d\n' % (subgroup.encode(), i, j)) +
|
||||
(b'usemtl %s\n' % subgroup.encode()) +
|
||||
|
|
|
@ -44,7 +44,16 @@ def triangulate_rings(rings, holes=None):
|
|||
info.set_holes(np.rint(np.array(holes)*1000))
|
||||
|
||||
mesh = triangle.build(info, quality_meshing=False)
|
||||
return np.rint(np.array(mesh.points)).astype(np.int32), np.array(mesh.elements, dtype=np.uint32)
|
||||
|
||||
mesh_points = np.rint(np.array(mesh.points)).astype(np.int32)
|
||||
mesh_elements = np.array(mesh.elements, dtype=np.uint32)
|
||||
|
||||
# remove triangles with no area
|
||||
facets = np.dstack((np.zeros(mesh_elements.shape), mesh_points[mesh_elements]))
|
||||
ok_index = np.cross(facets[:, 1] - facets[:, 0], facets[:, 2] - facets[:, 1]).max(axis=1) != 0
|
||||
mesh_elements = mesh_elements[ok_index]
|
||||
|
||||
return mesh_points, mesh_elements
|
||||
|
||||
|
||||
def _triangulate_polygon(polygon: Polygon, keep_holes=False):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue