@@ -10,7 +10,7 @@ Base.ndims(::AbstractGeometry{Dim}) where {Dim} = Dim
10
10
"""
11
11
Polytope{Dim, T} <: AbstractGeometry{Dim, T}
12
12
13
- A Polytope is the generalization of a Polygon to higher dimensions, i.e. a
13
+ A Polytope is the generalization of a Polygon to higher dimensions, i.e. a
14
14
geometric object consisting of flat faces.
15
15
16
16
A `Polygon` and `Ngon` are both 2D `Polytope`s. A `Simplex` is the simplest
@@ -22,7 +22,7 @@ abstract type AbstractPolygon{Dim,T} <: Polytope{Dim,T} end
22
22
"""
23
23
AbstractFace{N_indices, T} <: StaticVector{N_indices, T}
24
24
25
- Parent type for all face types. The standard face type is typically a
25
+ Parent type for all face types. The standard face type is typically a
26
26
`GLTriangleFace = NgonFace{3, GLIndex}`.
27
27
"""
28
28
abstract type AbstractFace{N,T} <: StaticVector{N,T} end
@@ -109,7 +109,7 @@ Base.:(==)(f1::FT, f2::FT) where {FT <: AbstractFace{2}} = minmax(f1.data...) ==
109
109
Base. hash (f:: AbstractFace{2} , h:: UInt ) = hash (minmax (f. data... ), h)
110
110
111
111
function Base.:(== )(f1:: FT , f2:: FT ) where {FT <: AbstractFace{3} }
112
- return (f1. data == f2. data) || (f1. data == (f2[2 ], f2[3 ], f2[1 ])) ||
112
+ return (f1. data == f2. data) || (f1. data == (f2[2 ], f2[3 ], f2[1 ])) ||
113
113
(f1. data == (f2[3 ], f2[1 ], f2[2 ]))
114
114
end
115
115
function Base. hash (f:: AbstractFace{3} , h:: UInt )
@@ -347,6 +347,7 @@ struct LineString{Dim, T<:Real} <: AbstractGeometry{Dim, T}
347
347
points:: Vector{Point{Dim, T}}
348
348
end
349
349
Base. length (ls:: LineString ) = length (coordinates (ls))
350
+ Base.:(== )(a:: LineString , b:: LineString ) = a. points == b. points
350
351
coordinates (ls:: LineString ) = ls. points
351
352
352
353
struct MultiLineString{Dim, T<: Real } <: AbstractGeometry{Dim, T}
@@ -382,7 +383,7 @@ Base.length(mpt::MultiPoint) = length(mpt.points)
382
383
"""
383
384
FaceView(data, faces)
384
385
385
- A FaceView is an alternative to passing a vertex attribute directly to a mesh.
386
+ A FaceView is an alternative to passing a vertex attribute directly to a mesh.
386
387
It bundles `data` with a new set of `faces` which may index that data differently
387
388
from the faces defined in a mesh. This can be useful to avoid duplication in `data`.
388
389
@@ -395,7 +396,7 @@ per_face_normals = FaceView(
395
396
)
396
397
```
397
398
398
- If you need a mesh with strictly per-vertex data, e.g. for rendering, you can use
399
+ If you need a mesh with strictly per-vertex data, e.g. for rendering, you can use
399
400
`expand_faceviews(mesh)` to convert every vertex attribute to be per-vertex. This
400
401
will duplicate data and reorder faces as needed.
401
402
@@ -457,7 +458,7 @@ function verify(fs::AbstractVector{FT}, fv::FaceView, name = nothing) where {FT
457
458
return true
458
459
end
459
460
460
- # Dodgy definitions... (since attributes can be FaceView or Array it's often
461
+ # Dodgy definitions... (since attributes can be FaceView or Array it's often
461
462
# useful to treat a FaceView like the vertex data it contains)
462
463
Base. length (x:: FaceView ) = length (values (x))
463
464
# Base.iterate(x::FaceView) = iterate(values(x))
485
486
"""
486
487
AbstractMesh
487
488
488
- An abstract mesh is a collection of Polytope elements (Simplices / Ngons). The
489
- connections are defined via faces(mesh) and the coordinates of the elements are
489
+ An abstract mesh is a collection of Polytope elements (Simplices / Ngons). The
490
+ connections are defined via faces(mesh) and the coordinates of the elements are
490
491
returned by coordinates(mesh).
491
492
"""
492
493
abstract type AbstractMesh{Dim, T} <: AbstractGeometry{Dim, T} end
@@ -504,9 +505,9 @@ struct Mesh{...}
504
505
end
505
506
```
506
507
507
- A vertex typically carries multiple distinct pieces of data, e.g. a position,
508
- a normal, a texture coordinate, etc. We call those pieces of data vertex
509
- attributes. The `vertex_attributes` field contains the name and a collection
508
+ A vertex typically carries multiple distinct pieces of data, e.g. a position,
509
+ a normal, a texture coordinate, etc. We call those pieces of data vertex
510
+ attributes. The `vertex_attributes` field contains the name and a collection
510
511
`<: AbstractVector` or `<: FaceView` for each attribute. The n-th element of that
511
512
collection is the value of the corresponding attribute for the n-th vertex.
512
513
@@ -517,27 +518,27 @@ vertex_attributes[:normal] = [normal1, normal2, normal3, ...]
517
518
...
518
519
```
519
520
520
- A `NamedTuple` is used here to allow different meshes to carry different vertex
521
- attributes while also keeping things type stable. The constructor enforces a
521
+ A `NamedTuple` is used here to allow different meshes to carry different vertex
522
+ attributes while also keeping things type stable. The constructor enforces a
522
523
few restrictions:
523
524
- The first attribute must be named `position` and must have a `Point{PositionDim, PositionType}` eltype.
524
- - Each vertex attribute must refer to the same number of vertices. (All vertex attributes defined by
525
+ - Each vertex attribute must refer to the same number of vertices. (All vertex attributes defined by
525
526
AbstractVector must match in length. For FaceViews, the number of faces needs to match.)
526
527
527
- See also: [`vertex_attributes`](@ref), [`coordinates`](@ref), [`normals`](@ref),
528
- [`texturecoordinates`](@ref), [`decompose`](@ref), [`FaceView`](@ref),
528
+ See also: [`vertex_attributes`](@ref), [`coordinates`](@ref), [`normals`](@ref),
529
+ [`texturecoordinates`](@ref), [`decompose`](@ref), [`FaceView`](@ref),
529
530
[`expand_faceviews`](@ref)
530
531
531
- The `faces` field is a collection `<: AbstractVector{FaceType}` containing faces
532
+ The `faces` field is a collection `<: AbstractVector{FaceType}` containing faces
532
533
that describe how vertices are connected. Typically these are `(GL)TriangleFace`s
533
534
or `QuadFace`s, but they can be any collection of vertex indices `<: AbstractFace`.
534
535
535
536
See also: [`faces`](@ref), [`decompose`](@ref)
536
537
537
- The `views` field can be used to separate the mesh into mutliple submeshes. Each
538
- submesh is described by a "view" into the `faces` vector, i.e. submesh n uses
539
- `mesh.faces[mesh.views[n]]`. A `Mesh` can be constructed without `views`, which
540
- results in an empty `views` vector.
538
+ The `views` field can be used to separate the mesh into mutliple submeshes. Each
539
+ submesh is described by a "view" into the `faces` vector, i.e. submesh n uses
540
+ `mesh.faces[mesh.views[n]]`. A `Mesh` can be constructed without `views`, which
541
+ results in an empty `views` vector.
541
542
542
543
See also: [`merge`](@ref), [`split_mesh`](@ref)
543
544
"""
@@ -554,7 +555,7 @@ struct Mesh{
554
555
views:: Vector{UnitRange{Int}}
555
556
556
557
function Mesh (
557
- vertex_attributes:: NamedTuple{Names, VAT} ,
558
+ vertex_attributes:: NamedTuple{Names, VAT} ,
558
559
fs:: FVT ,
559
560
views:: Vector{UnitRange{Int}} = UnitRange{Int}[]
560
561
) where {
@@ -625,7 +626,7 @@ texturecoordinates(mesh::Mesh) = hasproperty(mesh, :uv) ? mesh.uv : nothing
625
626
"""
626
627
vertex_attributes(mesh::Mesh)
627
628
628
- Returns a dictionairy containing the vertex attributes of the given mesh.
629
+ Returns a dictionairy containing the vertex attributes of the given mesh.
629
630
Mutating these will change the mesh.
630
631
"""
631
632
vertex_attributes (mesh:: Mesh ) = getfield (mesh, :vertex_attributes )
@@ -634,7 +635,7 @@ Base.getindex(mesh::Mesh, i::Integer) = mesh.position[mesh.faces[i]]
634
635
Base. length (mesh:: Mesh ) = length (mesh. faces)
635
636
636
637
function Base.:(== )(a:: Mesh , b:: Mesh )
637
- return (a. vertex_attributes == b. vertex_attributes) &&
638
+ return (a. vertex_attributes == b. vertex_attributes) &&
638
639
(faces (a) == faces (b)) && (a. views == b. views)
639
640
end
640
641
@@ -654,17 +655,17 @@ end
654
655
655
656
Constructs a mesh from the given arguments.
656
657
657
- If `positions` are given explicitly, they are merged with other vertex attributes
658
+ If `positions` are given explicitly, they are merged with other vertex attributes
658
659
under the name `position`. Otherwise they must be part of `attributes`. If `faces`
659
660
are not given `attributes.position` must be a FaceView.
660
661
661
- Any other vertex attribute can be either an `AbstractVector` or a `FaceView`
662
+ Any other vertex attribute can be either an `AbstractVector` or a `FaceView`
662
663
thereof. Every vertex attribute that is an `AbstractVector` must be sufficiently
663
664
large to be indexable by `mesh.faces`. Every vertex attribute that is a `FaceView`
664
665
must contain similar faces to `mesh.faces`, i.e. contain the same number of faces
665
666
and have faces of matching length.
666
667
667
- `views` can be defined optionally to implicitly split the mesh into multi
668
+ `views` can be defined optionally to implicitly split the mesh into multi
668
669
sub-meshes. This is done by providing ranges for indexing faces which correspond
669
670
to the sub-meshes. By default this is left empty.
670
671
"""
@@ -673,7 +674,7 @@ function Mesh(faces::AbstractVector{<:AbstractFace}; views::Vector{UnitRange{Int
673
674
end
674
675
675
676
function Mesh (points:: AbstractVector{Point{Dim, T}} ,
676
- faces:: AbstractVector{<:AbstractFace} ;
677
+ faces:: AbstractVector{<:AbstractFace} ;
677
678
views = UnitRange{Int}[], kwargs... ) where {Dim, T}
678
679
va = (position = points, kwargs... )
679
680
return Mesh (va, faces, views)
@@ -716,13 +717,13 @@ Constructs a MetaMesh either from another `mesh` or by constructing another mesh
716
717
with the given `positions` and `faces`. Any keyword arguments given will be
717
718
stored in the `meta` field in `MetaMesh`.
718
719
719
- This struct is meant to be used for storage of non-vertex data. Any vertex
720
- related data should be stored as a vertex attribute in `Mesh`. One example of such
720
+ This struct is meant to be used for storage of non-vertex data. Any vertex
721
+ related data should be stored as a vertex attribute in `Mesh`. One example of such
721
722
data is material data, which is defined per view in `mesh.views`, i.e. per submesh.
722
723
723
- The metadata added to the MetaMesh can be manipulated with Dict-like operations
724
- (getindex, setindex!, get, delete, keys, etc). Vertex attributes can be accessed
725
- via fields and the same getters as mesh. The mesh itself can be retrieved with
724
+ The metadata added to the MetaMesh can be manipulated with Dict-like operations
725
+ (getindex, setindex!, get, delete, keys, etc). Vertex attributes can be accessed
726
+ via fields and the same getters as mesh. The mesh itself can be retrieved with
726
727
`Mesh(metamesh)`.
727
728
"""
728
729
function MetaMesh (mesh:: AbstractMesh ; kwargs... )
0 commit comments