@@ -124,15 +124,19 @@ Polygon triangluation!
124
124
"""
125
125
function mesh (polygon:: AbstractVector{P} ; pointtype= P, facetype= GLTriangleFace,
126
126
normaltype= nothing , nvertices= nothing ) where {P<: AbstractPoint{2} }
127
+
127
128
faces = decompose (facetype, polygon)
128
129
positions = decompose (pointtype, polygon)
130
+
129
131
if nvertices != = nothing
130
132
error (" Resampling polygon not supported!" )
131
133
end
134
+
132
135
if normaltype != = nothing
133
136
n = normals (positions, faces; normaltype= normaltype)
134
137
positions = meta (positions; normals= n)
135
138
end
139
+
136
140
return Mesh (positions, faces)
137
141
end
138
142
@@ -215,3 +219,40 @@ function decompose(::UV{T}, mesh::Mesh) where {T}
215
219
error (" Mesh doesn't have UV texture coordinates" )
216
220
end
217
221
end
222
+
223
+ """
224
+ pointmeta(mesh::Mesh; meta_data...)
225
+
226
+ Attaches metadata to the coordinates of a mesh
227
+ """
228
+ function pointmeta (mesh:: Mesh ; meta_data... )
229
+ points = coordinates (mesh)
230
+ attr = GeometryBasics. attributes (points)
231
+ delete! (attr, :position ) # position == metafree(points)
232
+ # delete overlapping attributes so we can replace with `meta_data`
233
+ foreach (k-> delete! (attr, k), keys (meta_data))
234
+ return Mesh (meta (metafree (points); attr... , meta_data... ), faces (mesh))
235
+ end
236
+
237
+ """
238
+ pop_pointmeta(mesh::Mesh, property::Symbol)
239
+ Remove `property` from point metadata.
240
+ Returns the new mesh, and the property!
241
+ """
242
+ function pop_pointmeta (mesh:: Mesh , property:: Symbol )
243
+ points = coordinates (mesh)
244
+ attr = GeometryBasics. attributes (points)
245
+ delete! (attr, :position ) # position == metafree(points)
246
+ # delete overlapping attributes so we can replace with `meta_data`
247
+ m = pop! (attr, property)
248
+ return Mesh (meta (metafree (points); attr... ), faces (mesh)), m
249
+ end
250
+
251
+ """
252
+ facemeta(mesh::Mesh; meta_data...)
253
+
254
+ Attaches metadata to the faces of a mesh
255
+ """
256
+ function facemeta (mesh:: Mesh ; meta_data... )
257
+ return Mesh (coordinates (mesh), meta (faces (mesh); meta_data... ))
258
+ end
0 commit comments