@@ -110,25 +110,32 @@ function mesh(primitive::Meshable;
110
110
# triangulation.jl
111
111
faces = decompose (facetype, positions)
112
112
end
113
- attributes = Dict {Symbol, Any} ()
113
+
114
+ # We want to preserve any existing attributes!
115
+ attrs = attributes (primitive)
116
+ # Make sure this doesn't contain position, we'll add position explicitely via meta!
117
+ delete! (attrs, :position )
114
118
115
119
if uv != = nothing
116
- attributes[:uv ] = decompose (UV (uv), primitive)
120
+ # this may overwrite an existing :uv, but will only create a copy
121
+ # if it has a different eltype, otherwise it should replace it
122
+ # with exactly the same instance - which is what we want here
123
+ attrs[:uv ] = decompose (UV (uv), primitive)
117
124
end
118
125
119
126
if normaltype != = nothing
120
127
primitive_normals = normals (primitive)
121
128
if primitive_normals != = nothing
122
- attributes [:normals ] = decompose (normaltype, primitive_normals)
129
+ attrs [:normals ] = decompose (normaltype, primitive_normals)
123
130
else
124
131
# Normals not implemented for primitive, so we calculate them!
125
- n = normals (positions, faces)
132
+ n = normals (positions, faces; normaltype = normaltype )
126
133
if n != = nothing # ok jeez, this is a 2d mesh which cant have normals
127
- attributes [:normals ] = n
134
+ attrs [:normals ] = n
128
135
end
129
136
end
130
137
end
131
- return Mesh (meta (positions; attributes ... ), faces)
138
+ return Mesh (meta (positions; attrs ... ), faces)
132
139
end
133
140
134
141
"""
@@ -231,7 +238,7 @@ Attaches metadata to the coordinates of a mesh
231
238
"""
232
239
function pointmeta (mesh:: Mesh ; meta_data... )
233
240
points = coordinates (mesh)
234
- attr = GeometryBasics . attributes (points)
241
+ attr = attributes (points)
235
242
delete! (attr, :position ) # position == metafree(points)
236
243
# delete overlapping attributes so we can replace with `meta_data`
237
244
foreach (k-> delete! (attr, k), keys (meta_data))
@@ -253,7 +260,7 @@ Returns the new mesh, and the property!
253
260
"""
254
261
function pop_pointmeta (mesh:: Mesh , property:: Symbol )
255
262
points = coordinates (mesh)
256
- attr = GeometryBasics . attributes (points)
263
+ attr = attributes (points)
257
264
delete! (attr, :position ) # position == metafree(points)
258
265
# delete overlapping attributes so we can replace with `meta_data`
259
266
m = pop! (attr, property)
@@ -268,3 +275,7 @@ Attaches metadata to the faces of a mesh
268
275
function facemeta (mesh:: Mesh ; meta_data... )
269
276
return Mesh (coordinates (mesh), meta (faces (mesh); meta_data... ))
270
277
end
278
+
279
+ function attributes (hasmeta:: Mesh )
280
+ return Dict {Symbol, Any} ((name => getproperty (hasmeta, name) for name in propertynames (hasmeta)))
281
+ end
0 commit comments