Skip to content

Commit 06ee6a6

Browse files
committed
basic improvements for docs
1 parent 86fc11c commit 06ee6a6

File tree

5 files changed

+126
-19
lines changed

5 files changed

+126
-19
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,12 @@ jobs:
5656
with:
5757
version: "1.11"
5858
- uses: julia-actions/cache@v2
59-
- run: |
60-
DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs -e '
61-
using Pkg
62-
Pkg.develop(PackageSpec(path=pwd()))
63-
pkg"add MakieCore Makie GLMakie"
64-
Pkg.instantiate()'
65-
- run: DISPLAY=:0 xvfb-run -s '-screen 0 1024x768x24' julia --project=docs docs/make.jl
59+
- name: Configure doc environment
60+
shell: julia --project=docs --color=yes {0}
61+
run: |
62+
using Pkg
63+
Pkg.instantiate()
64+
- run: julia --project=docs docs/make.jl
6665
env:
6766
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6867
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

docs/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[deps]
2+
Bonito = "824d6782-a2ef-11e9-3a09-e5662e0c26f8"
23
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
34
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
5+
Meshing = "e6723b4c-ebff-59f1-b4b7-d97aa5274f73"
6+
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
7+
8+
[sources]
9+
GeometryBasics = {path = "../"}

docs/make.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ using GeometryBasics
55

66
DocMeta.setdocmeta!(GeometryBasics, :DocTestSetup, :(using GeometryBasics); recursive=true)
77

8-
makedocs(format=Documenter.HTML(prettyurls=get(ENV, "CI", "false") == "true"),
9-
sitename="GeometryBasics.jl",
10-
pages=[
11-
"index.md",
8+
makedocs(; sitename="GeometryBasics.jl",
9+
format=Documenter.HTML(; prettyurls=false, size_threshold=3000000,
10+
example_size_threshold=3000000),
11+
pages=["index.md",
1212
"primitives.md",
1313
"polygons.md",
1414
"meshes.md",
1515
"decomposition.md",
1616
"boundingboxes.md",
1717
"static_array_types.md",
18-
"api.md",
19-
],
18+
"api.md"],
2019
modules=[GeometryBasics])
2120

22-
deploydocs(repo="github.com/JuliaGeometry/GeometryBasics.jl.git", push_preview=true)
21+
deploydocs(; repo="github.com/JuliaGeometry/GeometryBasics.jl.git", push_preview=true)

docs/src/meshes.md

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Meshes
22

3+
```@setup 1
4+
using Bonito
5+
Page()
6+
```
7+
38
GeometryBasics defines two mesh types to work with - `Mesh` and `MetaMesh`
49

510
## Mesh
@@ -17,6 +22,48 @@ You can get data from a mesh using a few interface functions:
1722

1823
You can also grab the contents of `mesh.vertex_attributes` as if they were fields of the `Mesh`, e.g. `mesh.position` works.
1924

25+
### Custom Attributes
26+
27+
Meshes support arbitrary custom attributes beyond the standard position, normal, and UV coordinates. You can attach per-vertex or per-face data like material properties, identifiers, or computed values. These are stored in `mesh.vertex_attributes` and accessed using the same interface.
28+
29+
```julia
30+
using GeometryBasics
31+
32+
# Define custom data type
33+
struct Material
34+
emissivity::Float64
35+
absorptivity::Float64
36+
reflectivity::Float64
37+
end
38+
39+
# Create mesh with custom attributes
40+
points = [Point3f(0,0,0), Point3f(1,0,0), Point3f(0,1,0), Point3f(0,0,1)]
41+
faces = [TriangleFace(1,2,3), TriangleFace(1,2,4), TriangleFace(1,3,4), TriangleFace(2,3,4)]
42+
43+
materials = [
44+
Material(0.1, 0.8, 0.1),
45+
Material(0.2, 0.7, 0.1),
46+
Material(0.0, 0.9, 0.1),
47+
Material(0.3, 0.6, 0.1)
48+
]
49+
50+
face_names = ["bottom", "side1", "side2", "top"]
51+
52+
# Use per_face to create FaceViews for per-face attributes
53+
mesh = GeometryBasics.mesh(
54+
points,
55+
faces,
56+
material=per_face(materials, faces),
57+
face_name=per_face(face_names, faces)
58+
)
59+
60+
# Access custom attributes
61+
mesh.material[2] # Get material of second face
62+
mesh.face_name[1] # Get name of first face
63+
```
64+
65+
This pattern is useful for physical simulations, rendering with material properties, or tagging mesh regions for analysis.
66+
2067
### FaceView
2168

2269

@@ -47,6 +94,40 @@ per_face
4794
MetaMesh
4895
```
4996

97+
`MetaMesh` wraps a `Mesh` and allows you to attach global metadata that applies to the entire mesh rather than individual vertices or faces. This is useful for storing information like source file paths, transformation matrices, object identifiers, or simulation parameters.
98+
99+
```julia
100+
using GeometryBasics
101+
102+
# Create a basic mesh
103+
points = [Point3f(0,0,0), Point3f(1,0,0), Point3f(0,1,0)]
104+
faces = [TriangleFace(1,2,3)]
105+
mesh = GeometryBasics.mesh(points, faces; attribute=rand(3))
106+
107+
# Wrap with MetaMesh and add global metadata
108+
meta_mesh = MetaMesh(mesh, source_file="model.obj", object_id=42, scale=1.5)
109+
110+
# Access metadata
111+
meta_mesh[:source_file] # "model.obj"
112+
meta_mesh[:object_id] # 42
113+
meta_mesh.attribute # access vertex attributes via getproperty
114+
# The underlying mesh is still accessible
115+
meta_mesh.mesh
116+
```
117+
118+
You can combine `MetaMesh` for global properties with per-face/per-vertex attributes for complete geometric and metadata representation:
119+
120+
```julia
121+
# Create mesh with both per-face attributes and global metadata
122+
mesh = GeometryBasics.mesh(
123+
points, faces,
124+
material=per_face(materials, faces),
125+
normal=face_normals(points, faces)
126+
)
127+
128+
meta_mesh = MetaMesh(mesh, gltf_file="spacecraft.gltf", mass=150.0)
129+
```
130+
50131
## How to create a mesh
51132

52133
### GeometryBasics
@@ -66,13 +147,33 @@ Note that this doesn't remove any data (e.g. hidden or duplicate vertices), and
66147

67148
### Meshing.jl
68149

150+
```@example 1
151+
using Meshing
152+
using GeometryBasics
153+
using WGLMakie
154+
using LinearAlgebra
155+
156+
gyroid(v) = cos(v[1])*sin(v[2])+cos(v[2])*sin(v[3])+cos(v[3])*sin(v[1])
157+
gyroid_shell(v) = max(gyroid(v)-0.4,-gyroid(v)-0.4)
158+
xr,yr,zr = ntuple(_->LinRange(0,pi*4,50),3)
159+
160+
A = [gyroid_shell((x,y,z)) for x in xr, y in yr, z in zr]
161+
# generate directly using GeometryBasics API
162+
# Rect specifies the sampling intervals
163+
vts, fcs = isosurface(A, MarchingCubes())
164+
# view with Makie
165+
fcs = TriangleFace{Int}.(fcs)
166+
vts = Point3d.(vts)
167+
Makie.mesh(GeometryBasics.Mesh(vts, fcs), color=[norm(v) for v in vts])
168+
```
169+
69170
### MeshIO.jl
70171

71172
The [`MeshIO.jl`](https://github.com/JuliaIO/MeshIO.jl) package provides load/save support for several file formats which store meshes.
72173

73-
```@example
74-
using GLMakie, GLMakie.FileIO, GeometryBasics
174+
```@example 1
175+
using WGLMakie, GeometryBasics
75176
76-
m = load(GLMakie.assetpath("cat.obj"))
77-
GLMakie.mesh(m; color=load(GLMakie.assetpath("diffusemap.png")), axis=(; show_axis=false))
177+
m = Makie.loadasset("cat.obj")
178+
Makie.mesh(m; color=Makie.loadasset("diffusemap.png"), axis=(; show_axis=false))
78179
```

src/basic_types.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ faces(x::FaceView) = x.faces
380380
Base.values(x::FaceView) = x.data
381381
facetype(x::FaceView) = eltype(x.faces)
382382
Base.getindex(x::FaceView, f::AbstractFace) = getindex(values(x), f)
383+
Base.getindex(x::FaceView, i::Integer) = x.data[i]
383384
Base.isempty(x::FaceView) = isempty(values(x))
384385
Base.:(==)(a::FaceView, b::FaceView) = (values(a) == values(b)) && (faces(a) == faces(b))
385386

@@ -763,17 +764,18 @@ function MetaMesh(points::AbstractVector{<:Point}, faces::AbstractVector{<:Abstr
763764
MetaMesh(Mesh(points, faces), Dict{Symbol, Any}(kwargs))
764765
end
765766

766-
767767
@inline function Base.hasproperty(mesh::MetaMesh, field::Symbol)
768768
return hasfield(MetaMesh, field) || hasproperty(getfield(mesh, :mesh), field)
769769
end
770+
770771
@inline function Base.getproperty(mesh::MetaMesh, field::Symbol)
771772
if hasfield(MetaMesh, field)
772773
return getfield(mesh, field)
773774
else
774775
return getproperty(getfield(mesh, :mesh), field)
775776
end
776777
end
778+
777779
@inline function Base.propertynames(mesh::MetaMesh)
778780
return (fieldnames(MetaMesh)..., propertynames(getfield(mesh, :mesh))...)
779781
end

0 commit comments

Comments
 (0)