@@ -11,7 +11,7 @@ Note, that this can be an `Int` or `Tuple{Int, Int}``, when the primitive is gri
1111It also only losely correlates to the number of vertices, depending on the algorithm used.
1212#TODO: find a better number here!
1313"""
14- function mesh (primitive:: AbstractGeometry ; pointtype= Point, facetype= GLTriangleFace)
14+ function mesh (primitive:: AbstractGeometry ; pointtype= Point, facetype= GLTriangleFace, vertex_attributes ... )
1515 positions = decompose (pointtype, primitive)
1616 _f = faces (primitive)
1717 # If faces returns nothing for primitive, we try to triangulate!
@@ -25,11 +25,11 @@ function mesh(primitive::AbstractGeometry; pointtype=Point, facetype=GLTriangleF
2525 else
2626 f = decompose (facetype, _f)
2727 end
28- return Mesh (positions, f)
28+ return Mesh (positions, f; vertex_attributes ... )
2929end
3030
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}
3333
3434"""
3535 mesh(polygon::AbstractVector{P}; pointtype=P, facetype=GLTriangleFace,
@@ -58,7 +58,7 @@ function triangle_mesh(primitive::Mesh{N}) where {N}
5858 end
5959end
6060
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}
6262 if nvertices != = nothing
6363 @warn (" nvertices argument deprecated. Wrap primitive in `Tesselation(primitive, nvertices)`" )
6464 primitive = Tesselation (primitive, nvertices)
@@ -67,25 +67,26 @@ function triangle_mesh(primitive::Union{AbstractGeometry{N}, AbstractVector{<: P
6767end
6868
6969function 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)
7271end
7372
7473function 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)
7777end
7878
7979function normal_mesh (points:: AbstractVector{<:Point} ,
8080 faces:: AbstractVector{<:AbstractFace} )
8181 _points = decompose (Point3f, points)
8282 _faces = decompose (GLTriangleFace, faces)
83- return MetaMesh ( Mesh (_points, _faces), ( normals= normals (_points, _faces), ))
83+ return Mesh (_faces, position = _points, normals = normals (_points, _faces))
8484end
8585
8686function 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)
8990end
9091
9192"""
@@ -164,59 +165,56 @@ function map_coordinates!(f, mesh::AbstractMesh)
164165 return mesh
165166end
166167
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
188174
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
193178
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
194192
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
199197
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
205204end
206205
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}
209207 print (io, " Mesh{$N , $T , $(FT) }(...)" )
210208end
211209
212210function Base. show (io:: IO , :: MIME"text/plain" , mesh:: MetaMesh{N, T} ) where {N, T}
213211 FT = eltype (faces (mesh))
214212 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))
219216 end
217+ println (io, " meta: " , keys (mesh. meta))
220218end
221219
222220function Base. show (io:: IO , mesh:: MetaMesh{N, T} ) where {N, T}
0 commit comments