From b167a3c0fc2efb3a8b419df62cb1f19c98581a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pl=C3=BBt?= Date: Thu, 3 Aug 2023 11:40:42 +0200 Subject: [PATCH] Makie mesh! bug workaround --- TODO.md | 18 ++++++++++++------ src/ConstructiveGeometry.jl | 13 ++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 4ce2fbe..b1efda2 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,15 @@ # 1d paths * Composed operators! - * use `AbstractGeometry{1}` for this! * concrete subtypes include segments, circular arcs, splines, loop closing + * use `AbstractGeometry{1}` for this! * allow moves to be relative as well as absolute + * allow symbolic centering of cubes etc. + * ellipsoids (`sphere(a,b,c)`) * circular arc: defined either by angle+center+radius, sagitta+endpoints... * meshing methods produce polylines * concrete type for polyline * operators 1d ↔ 2d: border, interior + * fill holes (in 2d and in 3d) * `path_extrude(surface, profile) => path_extrude(∂surface)` * `path(element1, element2, ...)` # Bug fixes @@ -68,8 +71,8 @@ For MeshIO: stl needs - [ ] overload `extrude()` (for paths, angles, numbers) - [ ] move doc examples to `WGLMakie` - [ ] remove `ConvexHull.jl` dependency (use method from `igl` instead?) - - [ ] `linear_extrude` / `prism` ? - - [ ] `rotate_extrude` / `revolution` ? + - [x] `linear_extrude` / `prism` ? + - [x] `rotate_extrude` / `revolution` ? - [ ] replace ad-hoc `plot` methods by correct `Makie` interface - [x] make meshing type-stable - [x] update `iglwrap` and use latest version @@ -88,9 +91,12 @@ For MeshIO: stl needs - [ ] document how to extend (e.g. new object type) # New features ## Geometry - - [ ] `multiply`: dispose copies of a mesh (better than `union` because + - [x] `multiply`: dispose copies of a mesh (better than `union` because we compute the child mesh only once) + - [ ] `symmetrize(m, s...) = union(s..., mirror(m, s...))` + find some easy syntax allowing also `symmetrize(m)*s` - [ ] replace `attributes` by a pointer to the original colored object; this could allow detecting edges etc. + - [ ] and detected edges would be protected from decimation - [x] `refine`: shorten all edges until no longer than given length - [ ] 2d (just divide edges) - [x] 3d (split triangles) @@ -144,10 +150,10 @@ For MeshIO: stl needs - OpenSCAD: `src/FreetypeRenderer.cc`, `::render` function - [ ] use `Pango` for text and `FreeType` for fonts - [x] Bézier curves (used as path for `path_extrude`, `stroke`, `polygon`) - - [ ] `symmetrize(m, s...) = union(s..., mirror(m, s...))` - find some easy syntax allowing also `symmetrize(m)*s` - [ ] 2d Minkowski difference ## Misc. + - [ ] use snap rounding from CGAL to re-introduce our own mesh boolean + functions? - [x] `surface(volume)` = instantiate as a mesh (avoids recomputation) - [ ] `plot(...; zoom=...)` ## Attachments diff --git a/src/ConstructiveGeometry.jl b/src/ConstructiveGeometry.jl index 8d1b14f..8bdb086 100644 --- a/src/ConstructiveGeometry.jl +++ b/src/ConstructiveGeometry.jl @@ -2450,6 +2450,9 @@ Base.show(io::IO, ::MIME"image/svg+xml", s::AbstractGeometry{2}) = # TODO: figure out how to rewrite the following using native Makie recipes @inline plot(g::AbstractGeometry; kwargs...) = plot(fullmesh(g); kwargs...) @inline plot(g::FullMesh; kwargs...) = plot!(Makie.Scene(), g; kwargs...) +# TODO: this is a workaround for a possible Makie bug — `mesh!` plots +# nothing, while `mesh()` works correctly: +@inline Makie_mesh_bang(::SceneLike, a...; kw...) = Makie.mesh(a...; kw...) function plot!(scene::SceneLike, m::FullMesh; kwargs...) rawmain = raw(m.main) @@ -2476,9 +2479,9 @@ function plot!(scene::SceneLike, m::TriangleMesh; kwargs...) end fmat = collect(1:size(vmat, 1)) attr = [ a[fld1(i,3)] for i in 1:size(vmat, 1)] - Makie.mesh!(scene, vmat, fmat, color=attr; # opaque! + Makie_mesh_bang(scene, vmat, fmat, color=attr; # opaque! lightposition=Makie.Vec3f0(5e3,1e3, 10e3), kwargs... ) - return scene +# return scene end function plot!(scene::SceneLike, m::TriangleMesh{<:Real,Nothing}; @@ -2488,7 +2491,7 @@ function plot!(scene::SceneLike, m::TriangleMesh{<:Real,Nothing}; v = TriangleMeshes.vertices(m); f = TriangleMeshes.faces(m); vmat = [ p[j] for p in v, j in 1:3 ] fmat = [ q[j] for q in f, j in 1:3 ] - Makie.mesh!(scene, vmat, fmat; transparency=true, + Makie_mesh_bang(scene, vmat, fmat; transparency=true, lightposition=Makie.Vec3f0(5e3,1e3,10e3), kwargs...) end @@ -2509,10 +2512,10 @@ function plot!(scene::SceneLike, p::Shapes.PolygonXor; v = Shapes.vertices(p) tri = Shapes.triangulate(p) m = [ t[j] for t in tri, j in 1:3 ] - Makie.mesh!(scene, v, m, + Makie_mesh_bang(scene, v, m, specular=Makie.Vec3f0(0,0,0), diffuse=Makie.Vec3f0(0,0,0), color=color; kwargs...) - return scene +# return scene end # OpenSCAD output««1