Skip to content

Commit 12a820b

Browse files
committed
Fix mesh(::AbstractPolygon) in case faces returns nothing
1 parent 8763f82 commit 12a820b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/meshes.jl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ const GLNormalUVWMesh{Dim} = NormalUVWMesh{Dim,Float32}
8686
const GLNormalUVWMesh2D = GLNormalUVWMesh{2}
8787
const GLNormalUVWMesh3D = GLNormalUVWMesh{3}
8888

89+
function decompose_triangulate_fallback(primitive::Meshable; pointtype, facetype)
90+
positions = decompose(pointtype, primitive)
91+
faces = decompose(facetype, primitive)
92+
# If faces returns nothing for primitive, we try to triangulate!
93+
if faces === nothing
94+
# triangulation.jl
95+
faces = decompose(facetype, positions)
96+
end
97+
return positions, faces
98+
end
99+
89100
"""
90101
mesh(primitive::GeometryPrimitive;
91102
pointtype=Point, facetype=GLTriangle,
@@ -101,13 +112,7 @@ It also only losely correlates to the number of vertices, depending on the algor
101112
function mesh(primitive::Meshable; pointtype=Point, facetype=GLTriangleFace, uv=nothing,
102113
normaltype=nothing)
103114

104-
positions = decompose(pointtype, primitive)
105-
faces = decompose(facetype, primitive)
106-
# If faces returns nothing for primitive, we try to triangulate!
107-
if faces === nothing
108-
# triangulation.jl
109-
faces = decompose(facetype, positions)
110-
end
115+
positions, faces = decompose_triangulate_fallback(primitive; pointtype, facetype)
111116

112117
# We want to preserve any existing attributes!
113118
attrs = attributes(primitive)
@@ -151,8 +156,7 @@ end
151156
function mesh(polygon::AbstractPolygon{Dim,T}; pointtype=Point{Dim,T},
152157
facetype=GLTriangleFace, normaltype=nothing) where {Dim,T}
153158

154-
faces = decompose(facetype, polygon)
155-
positions = decompose(pointtype, polygon)
159+
positions, faces = decompose_triangulate_fallback(polygon; pointtype, facetype)
156160

157161
if normaltype !== nothing
158162
n = normals(positions, faces; normaltype=normaltype)

0 commit comments

Comments
 (0)