@@ -11,7 +11,7 @@ Note, that this can be an `Int` or `Tuple{Int, Int}``, when the primitive is gri
11
11
It also only losely correlates to the number of vertices, depending on the algorithm used.
12
12
#TODO: find a better number here!
13
13
"""
14
- function mesh (primitive:: AbstractGeometry ; pointtype= Point, facetype= GLTriangleFace)
14
+ function mesh (primitive:: AbstractGeometry ; pointtype= Point, facetype= GLTriangleFace, vertex_attributes ... )
15
15
positions = decompose (pointtype, primitive)
16
16
_f = faces (primitive)
17
17
# If faces returns nothing for primitive, we try to triangulate!
@@ -25,11 +25,11 @@ function mesh(primitive::AbstractGeometry; pointtype=Point, facetype=GLTriangleF
25
25
else
26
26
f = decompose (facetype, _f)
27
27
end
28
- return Mesh (positions, f)
28
+ return Mesh (positions, f; vertex_attributes ... )
29
29
end
30
30
31
- const SimpleMesh{N, T, FT} = Mesh{N, T, Vector{Point{N, T}}, Vector{FT}}
32
- const TriangleMesh {N} = SimpleMesh{N, Float32, GLTriangleFace}
31
+ const SimpleMesh{N, T, FT} = Mesh{N, T, FT, ( :position ,), Tuple{ Vector{Point{N, T} }}, Vector{FT}}
32
+ const SimpleTriangleMesh {N} = SimpleMesh{N, Float32, GLTriangleFace}
33
33
34
34
"""
35
35
mesh(polygon::AbstractVector{P}; pointtype=P, facetype=GLTriangleFace,
@@ -58,7 +58,7 @@ function triangle_mesh(primitive::Mesh{N}) where {N}
58
58
end
59
59
end
60
60
61
- function triangle_mesh (primitive:: Union{AbstractGeometry{N}, AbstractVector{<: Point{N}}} ; nvertices = nothing ):: TriangleMesh {N} where {N}
61
+ function triangle_mesh (primitive:: Union{AbstractGeometry{N}, AbstractVector{<: Point{N}}} ; nvertices = nothing ):: SimpleTriangleMesh {N} where {N}
62
62
if nvertices != = nothing
63
63
@warn (" nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`" )
64
64
primitive = Tesselation (primitive, nvertices)
@@ -67,25 +67,26 @@ function triangle_mesh(primitive::Union{AbstractGeometry{N}, AbstractVector{<: P
67
67
end
68
68
69
69
function uv_mesh (primitive:: AbstractGeometry{N,T} ) where {N,T}
70
- m = triangle_mesh (primitive)
71
- return MetaMesh (m, (uv= decompose_uv (primitive),))
70
+ return mesh (primitive, uv = decompose_uv (primitive), pointtype= Point{N,Float32}, facetype= GLTriangleFace)
72
71
end
73
72
74
73
function uv_normal_mesh (primitive:: AbstractGeometry{N} ) where {N}
75
- m = triangle_mesh (primitive)
76
- return MetaMesh (m, (uv= decompose_uv (primitive), normals= decompose_normals (m)))
74
+ return mesh (
75
+ primitive, uv = decompose_uv (primitive), normals = decompose_normals (primitive),
76
+ pointtype= Point{N,Float32}, facetype= GLTriangleFace)
77
77
end
78
78
79
79
function normal_mesh (points:: AbstractVector{<:Point} ,
80
80
faces:: AbstractVector{<:AbstractFace} )
81
81
_points = decompose (Point3f, points)
82
82
_faces = decompose (GLTriangleFace, faces)
83
- return MetaMesh ( Mesh (_points, _faces), ( normals= normals (_points, _faces), ))
83
+ return Mesh (_faces, position = _points, normals = normals (_points, _faces))
84
84
end
85
85
86
86
function normal_mesh (primitive:: AbstractGeometry{N} ) where {N}
87
- m = triangle_mesh (primitive)
88
- return MetaMesh (m, (normals= decompose_normals (m),))
87
+ return mesh (
88
+ primitive, normals = decompose_normals (primitive),
89
+ pointtype= Point{N,Float32}, facetype= GLTriangleFace)
89
90
end
90
91
91
92
"""
@@ -164,59 +165,56 @@ function map_coordinates!(f, mesh::AbstractMesh)
164
165
return mesh
165
166
end
166
167
167
- function add_meta (mesh:: MetaMesh ; kw... )
168
- return MetaMesh (Mesh (mesh), (; meta (mesh)... , kw... ))
169
- end
170
-
171
- function add_meta (mesh:: Mesh ; kw... )
172
- return MetaMesh (mesh, (; meta (mesh)... , kw... ))
173
- end
174
-
175
- # I didn't find a simple way to remove a field from a namedtuple in a type stable way without
176
- # a generated function..
177
- @generated function pop (nt:: NamedTuple{Names, Values} , :: Val{name} ) where {Names, Values, name}
178
- if ! (name in Names)
179
- return :(throw (Base. KeyError ($ (QuoteNode (name)))))
180
- else
181
- names = filter (x-> x != = name, Names)
182
- nt = map (names) do name
183
- :($ name = nt.$ (name))
184
- end
185
- return :((; $ (nt... )), nt.$ (name))
186
- end
187
- end
168
+ # TODO :
169
+ add_meta (m, kw... ) = error (" TODO" )
170
+ pop_meta (m, kw... ) = error (" TODO" )
171
+ # function add_meta(mesh::MetaMesh; kw...)
172
+ # return MetaMesh(Mesh(mesh), (; meta(mesh)..., kw...))
173
+ # end
188
174
189
- function pop_meta (mesh:: MetaMesh , name:: Symbol )
190
- new_meta, value = pop (meta (mesh), Val (name))
191
- return MetaMesh (mesh, new_meta), value
192
- end
175
+ # function add_meta(mesh::Mesh; kw...)
176
+ # return MetaMesh(mesh, (; meta(mesh)..., kw...))
177
+ # end
193
178
179
+ # # I didn't find a simple way to remove a field from a namedtuple in a type stable way without
180
+ # # a generated function..
181
+ # @generated function pop(nt::NamedTuple{Names, Values}, ::Val{name}) where {Names, Values, name}
182
+ # if !(name in Names)
183
+ # return :(throw(Base.KeyError($(QuoteNode(name)))))
184
+ # else
185
+ # names = filter(x-> x !== name, Names)
186
+ # nt = map(names) do name
187
+ # :($name = nt.$(name))
188
+ # end
189
+ # return :((; $(nt...)), nt.$(name))
190
+ # end
191
+ # end
194
192
195
- function Base . get (f, mesh:: MetaMesh , key :: Symbol )
196
- hasproperty (mesh, key) && return getproperty ( mesh, key )
197
- return f ()
198
- end
193
+ # function pop_meta( mesh::MetaMesh, name ::Symbol)
194
+ # new_meta, value = pop(meta( mesh), Val(name) )
195
+ # return MetaMesh(mesh, new_meta), value
196
+ # end
199
197
200
- function Base. show (io:: IO , :: MIME"text/plain" , mesh:: Mesh{N, T} ) where {N, T}
201
- FT = eltype (faces (mesh))
202
- println (io, " Mesh{$N , $T , $(FT) }" )
203
- println (io, " vertices: " , length (coordinates (mesh)))
204
- println (io, " faces: " , length (faces (mesh)), " $(FT) " )
198
+ function Base. show (io:: IO , :: MIME"text/plain" , mesh:: Mesh{N, T, FT} ) where {N, T, FT}
199
+ println (io, " Mesh{$N , $T , $FT }" )
200
+ println (io, " faces: " , length (faces (mesh)))
201
+ for (name, attrib) in pairs (vertex_attributes (mesh))
202
+ println (io, " vertex $(name) : " , length (attrib))
203
+ end
205
204
end
206
205
207
- function Base. show (io:: IO , mesh:: Mesh{N, T} ) where {N, T}
208
- FT = eltype (faces (mesh))
206
+ function Base. show (io:: IO , :: Mesh{N, T, FT} ) where {N, T, FT}
209
207
print (io, " Mesh{$N , $T , $(FT) }(...)" )
210
208
end
211
209
212
210
function Base. show (io:: IO , :: MIME"text/plain" , mesh:: MetaMesh{N, T} ) where {N, T}
213
211
FT = eltype (faces (mesh))
214
212
println (io, " MetaMesh{$N , $T , $(FT) }" )
215
- println (io, " vertices: " , length (coordinates (mesh)))
216
- println (io, " faces: " , length (faces (mesh)), " $(FT) " )
217
- for (k, v) in pairs (meta (mesh))
218
- println (io, " " , k, " : " , length (v), " $(eltype (v)) " )
213
+ println (io, " faces: " , length (faces (mesh)))
214
+ for (name, attrib) in pairs (vertex_attributes (mesh))
215
+ println (io, " vertex $(name) : " , length (attrib))
219
216
end
217
+ println (io, " meta: " , keys (mesh. meta))
220
218
end
221
219
222
220
function Base. show (io:: IO , mesh:: MetaMesh{N, T} ) where {N, T}
0 commit comments