Skip to content

Commit 82dd5ce

Browse files
committed
export clear_faceviews & update FaceView docstring
1 parent b33f82d commit 82dd5ce

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

docs/src/meshes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ As a minimal example consider a mesh that is just one triangle, i.e. 3 position
5353
Let's say we want to add a flat color to the triangle.
5454
In this case we only have one color, but our face refers to 3 different vertices (3 different positions).
5555
To avoid duplicating the color data, we can instead define a new triangle face `TriangleFace(1)` and add the color attribute as a `FaceView([color], [TriangleFace(1)])`.
56-
If we ever need the mesh to be defined with just one common set of faces, i.e. no FaceView and appropriately duplicated vertex data, we can use `GeometryBasics.clear_faceviews(mesh)` to generate it.
56+
If we ever need the mesh to be defined with just one common set of faces, i.e. no FaceView and appropriately duplicated vertex data, we can use `clear_faceviews(mesh)` to generate it.
5757

5858
On a larger scale this can be useful for memory and performance reason, e.g. when you do calculations with vertex attributes.
5959
It can also simplify some definitions, like for example `Rect3`.

src/GeometryBasics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export AbstractFace, TriangleFace, QuadFace, GLTriangleFace
4141
export OffsetInteger, ZeroIndex, OneIndex, GLIndex
4242
export decompose, coordinates, faces, normals, decompose_uv, decompose_normals,
4343
texturecoordinates, vertex_attributes
44+
export clear_faceviews
4445
export face_normals
4546
export Tesselation, Normal, UV, UVW
4647
export AbstractMesh, Mesh, MetaMesh, FaceView

src/basic_types.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,20 @@ Base.length(mpt::MultiPoint) = length(mpt.points)
382382
"""
383383
FaceView(data, faces)
384384
385-
A FaceView is alternative to passing a vertex attribute directly to a mesh. It
386-
bundles `data` with a different set of `faces` which replace the default faces
387-
of a mesh. Doing this allows you to have the `data` in a different order from
388-
vertices in the mesh, potentially avoiding duplication.
385+
A FaceView is an alternative to passing a vertex attributes directly to a mesh.
386+
It bundles `data` with a new set of `faces` which may index that data differently
387+
from the faces defined in a mesh. This can be useful to avoid duplication of data.
388+
389+
For example, `data` can be defined per face by giving each face just one (repeated)
390+
index:
391+
```julia
392+
per_face_normals = FaceView(
393+
normals, # one per face
394+
FT.(eachindex(normals)) # with FT = facetype(mesh)
395+
)
396+
```
397+
398+
To remove `FaceView`s from a mesh, e.g. for rendering, use `clear_faceviews(mesh)`.
389399
390400
You can get the data of a FaceView with `values(faceview)` and the faces with
391401
`faces(faceview)`.

0 commit comments

Comments
 (0)