Skip to content

Commit

Permalink
add mesh implemenation with normal using new Meshing.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
sjkelly committed Jun 30, 2024
1 parent f626724 commit a778400
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FileIO = "1"
ForwardDiff = "0.10"
GeometryBasics = "0.4"
LinearAlgebra = "1"
Meshing = "0.5"
Meshing = "0.6, 0.7"
MeshIO = "0.4"
Revise = "3"
Rotations = "1"
Expand Down
70 changes: 34 additions & 36 deletions examples/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

julia_version = "1.10.4"
manifest_format = "2.0"
project_hash = "45f0ef80ca12ef806f32247cd0d5651dd69dc4de"
project_hash = "5711fc8d77eed703586d928736ce229a69d0c5a2"

[[deps.ADTypes]]
git-tree-sha1 = "fa0822e5baee6e23081c2685ae27265dabee23d8"
git-tree-sha1 = "ae44a0c3d68a420d4ac0fa1f7e0c034ccecb6dc5"
uuid = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
version = "1.4.0"
version = "1.5.2"

[deps.ADTypes.extensions]
ADTypesChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -139,14 +139,14 @@ uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
version = "1.5.0"

[[deps.Bijections]]
git-tree-sha1 = "c9b163bd832e023571e86d0b90d9de92a9879088"
git-tree-sha1 = "95f5c7e2d177b7ba1a240b0518038b975d72a8c0"
uuid = "e2ed5e7c-b2de-5872-ae92-c73ca462fb04"
version = "0.1.6"
version = "0.1.7"

[[deps.BitFlags]]
git-tree-sha1 = "2dc09997850d68179b69dafb58ae806167a32b1b"
git-tree-sha1 = "0691e34b3bb8be9307330f88d1a3c3f25466c24d"
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
version = "0.1.8"
version = "0.1.9"

[[deps.Bonito]]
deps = ["Base64", "CodecZlib", "Colors", "Dates", "Deno_jll", "HTTP", "Hyperscript", "LinearAlgebra", "Markdown", "MsgPack", "Observables", "RelocatableFolders", "SHA", "Sockets", "Tables", "ThreadPools", "URIs", "UUIDs", "WidgetsBase"]
Expand Down Expand Up @@ -258,6 +258,11 @@ git-tree-sha1 = "7b8a93dba8af7e3b42fecabf646260105ac373f7"
uuid = "bbf7d656-a473-5ed7-a52c-81e309532950"
version = "0.3.0"

[[deps.CommonWorldInvalidations]]
git-tree-sha1 = "ae52d1c52048455e85a387fbee9be553ec2b68d0"
uuid = "f70d9fcc-98c5-4d4a-abd7-e4cdeebd8ca8"
version = "1.0.0"

[[deps.Compat]]
deps = ["TOML", "UUIDs"]
git-tree-sha1 = "b1c55339b7c6c350ee89f2c1604299660525b248"
Expand Down Expand Up @@ -582,22 +587,16 @@ version = "0.1.6"

[[deps.GeoInterface]]
deps = ["Extents"]
git-tree-sha1 = "801aef8228f7f04972e596b09d4dba481807c913"
git-tree-sha1 = "9fff8990361d5127b770e3454488360443019bb3"
uuid = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
version = "1.3.4"
version = "1.3.5"

[[deps.GeometryBasics]]
deps = ["EarCut_jll", "Extents", "GeoInterface", "IterTools", "LinearAlgebra", "StaticArrays", "StructArrays", "Tables"]
git-tree-sha1 = "b62f2b2d76cee0d61a2ef2b3118cd2a3215d3134"
uuid = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
version = "0.4.11"

[[deps.GeometryTypes]]
deps = ["ColorTypes", "FixedPointNumbers", "LinearAlgebra", "StaticArrays"]
git-tree-sha1 = "d796f7be0383b5416cd403420ce0af083b0f9b28"
uuid = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
version = "0.8.5"

[[deps.Gettext_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Libiconv_jll", "Pkg", "XML2_jll"]
git-tree-sha1 = "9b02998aba7bf074d14de89f9d37ca24a1a0b046"
Expand Down Expand Up @@ -1024,10 +1023,9 @@ uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.2+1"

[[deps.Meshing]]
deps = ["GeometryBasics", "GeometryTypes", "StaticArrays"]
git-tree-sha1 = "b32d34f3e3ca44391ca7261ca4eb96af71e022b9"
path = "/Users/sjkelly/.julia/dev/Meshing"
uuid = "e6723b4c-ebff-59f1-b4b7-d97aa5274f73"
version = "0.5.7"
version = "0.7.0"

[[deps.Missings]]
deps = ["DataAPI"]
Expand Down Expand Up @@ -1435,9 +1433,9 @@ version = "0.3.8"

[[deps.SciMLStructures]]
deps = ["ArrayInterface"]
git-tree-sha1 = "6ab4beaf88dcdd2639bead916f2347f81dcacd0e"
git-tree-sha1 = "cfdd1200d150df1d3c055cc72ee6850742e982d7"
uuid = "53ae85a6-f571-4167-b2af-e1d143709226"
version = "1.3.0"
version = "1.4.1"

[[deps.Scratch]]
deps = ["Dates"]
Expand Down Expand Up @@ -1525,9 +1523,9 @@ version = "0.1.1"

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"]
git-tree-sha1 = "6e00379a24597be4ae1ee6b2d882e15392040132"
git-tree-sha1 = "20833c5b7f7edf0e5026f23db7f268e4f23ec577"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.9.5"
version = "1.9.6"
weakdeps = ["ChainRulesCore", "Statistics"]

[deps.StaticArrays.extensions]
Expand Down Expand Up @@ -1603,15 +1601,15 @@ version = "0.2.1"

[[deps.SymbolicUtils]]
deps = ["AbstractTrees", "Bijections", "ChainRulesCore", "Combinatorics", "ConstructionBase", "DataStructures", "DocStringExtensions", "DynamicPolynomials", "IfElse", "LabelledArrays", "LinearAlgebra", "MultivariatePolynomials", "NaNMath", "Setfield", "SparseArrays", "SpecialFunctions", "StaticArrays", "SymbolicIndexingInterface", "TermInterface", "TimerOutputs", "Unityper"]
git-tree-sha1 = "79813de27af70906d223fbd89ad90dba3d88a2b0"
git-tree-sha1 = "cc049913a449be8c7ac00979831f26891e01add2"
uuid = "d1185830-fcd6-423d-90d6-eec64667417b"
version = "2.0.2"
version = "2.1.0"

[[deps.Symbolics]]
deps = ["ADTypes", "ArrayInterface", "Bijections", "ConstructionBase", "DataStructures", "DiffRules", "Distributions", "DocStringExtensions", "DomainSets", "DynamicPolynomials", "ForwardDiff", "IfElse", "LaTeXStrings", "LambertW", "Latexify", "Libdl", "LinearAlgebra", "LogExpFunctions", "MacroTools", "Markdown", "NaNMath", "PrecompileTools", "RecipesBase", "Reexport", "Requires", "RuntimeGeneratedFunctions", "SciMLBase", "Setfield", "SparseArrays", "SpecialFunctions", "StaticArrays", "SymbolicIndexingInterface", "SymbolicLimits", "SymbolicUtils", "TermInterface"]
git-tree-sha1 = "3669f8eba2720c595e16b038f33cb880c12ef7f7"
deps = ["ADTypes", "ArrayInterface", "Bijections", "CommonWorldInvalidations", "ConstructionBase", "DataStructures", "DiffRules", "Distributions", "DocStringExtensions", "DomainSets", "DynamicPolynomials", "ForwardDiff", "IfElse", "LaTeXStrings", "LambertW", "Latexify", "Libdl", "LinearAlgebra", "LogExpFunctions", "MacroTools", "Markdown", "NaNMath", "PrecompileTools", "RecipesBase", "Reexport", "Requires", "RuntimeGeneratedFunctions", "SciMLBase", "Setfield", "SparseArrays", "SpecialFunctions", "StaticArraysCore", "SymbolicIndexingInterface", "SymbolicLimits", "SymbolicUtils", "TermInterface"]
git-tree-sha1 = "8539a734b448ca27707709c62420b1bf115ed7d9"
uuid = "0c5d862f-8b57-4792-8d23-62f2024744c7"
version = "5.30.3"
version = "5.33.0"

[deps.Symbolics.extensions]
SymbolicsGroebnerExt = "Groebner"
Expand Down Expand Up @@ -1681,9 +1679,9 @@ uuid = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
version = "0.5.24"

[[deps.TranscodingStreams]]
git-tree-sha1 = "a947ea21087caba0a798c5e494d0bb78e3a1a3a0"
git-tree-sha1 = "d73336d81cafdc277ff45558bb7eaa2b04a8e472"
uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa"
version = "0.10.9"
version = "0.10.10"
weakdeps = ["Random", "Test"]

[deps.TranscodingStreams.extensions]
Expand Down Expand Up @@ -1749,15 +1747,15 @@ version = "1.0.0"

[[deps.XML2_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Zlib_jll"]
git-tree-sha1 = "52ff2af32e591541550bd753c0da8b9bc92bb9d9"
git-tree-sha1 = "d9717ce3518dc68a99e6b96300813760d887a01d"
uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
version = "2.12.7+0"
version = "2.13.1+0"

[[deps.XSLT_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "Pkg", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "91844873c4085240b95e795f692c4cec4d805f8a"
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libgcrypt_jll", "Libgpg_error_jll", "Libiconv_jll", "XML2_jll", "Zlib_jll"]
git-tree-sha1 = "a54ee957f4c86b526460a720dbc882fa5edcbefc"
uuid = "aed1982a-8fda-507f-9586-7b0439959a61"
version = "1.1.34+0"
version = "1.1.41+0"

[[deps.Xorg_libX11_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Xorg_libxcb_jll", "Xorg_xtrans_jll"]
Expand Down Expand Up @@ -1797,9 +1795,9 @@ version = "0.1.1+0"

[[deps.Xorg_libxcb_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "XSLT_jll", "Xorg_libXau_jll", "Xorg_libXdmcp_jll", "Xorg_libpthread_stubs_jll"]
git-tree-sha1 = "b4bfde5d5b652e22b9c790ad00af08b6d042b97d"
git-tree-sha1 = "bcd466676fef0878338c61e655629fa7bbc69d8e"
uuid = "c7cfdc94-dc32-55de-ac96-5a1b8d977c5b"
version = "1.15.0+0"
version = "1.17.0+0"

[[deps.Xorg_xtrans_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl"]
Expand Down
1 change: 1 addition & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
HCubature = "19dc6840-f33b-545b-b366-655c7e3ffd49"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Meshing = "e6723b4c-ebff-59f1-b4b7-d97aa5274f73"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand Down
10 changes: 6 additions & 4 deletions examples/gyroid.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Revise
using Descartes: Gyroid, Cuboid, PolarWarp, Cylinder
using GeometryBasics: Mesh, HyperRectangle
using Descartes: Gyroid, Cuboid, PolarWarp, Cylinder, FRep
using GeometryBasics: GeometryBasics, mesh, HyperRectangle
using Meshing
using StaticArrays

holes = [[0,0,0], [15, 0, 0], [7.5, 7.5, 0]]

Expand All @@ -9,8 +11,8 @@ p = intersect(PolarWarp(Gyroid(0.5), 200), Cuboid([50,50,50]))

h = HyperRectangle(p)

m = Mesh(p)
@time m = mesh(p; samples=(200,200,200))

using WGLMakie
WGLMakie.activate!(resize_to=:body)
mesh(m)
WGLMakie.mesh(m)
16 changes: 11 additions & 5 deletions src/meshes.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
function (::Type{MT})(primitives::AbstractPrimitive...;
function GeometryBasics.mesh(primitives::AbstractPrimitive...;
samples=(128,128,128),
algorithm=MarchingCubes(),
adf=false) where {MT <: AbstractMesh}
algorithm=MarchingCubes())

f(x) = FRep(primitives[1], x)
meshes = Vector{MT}(undef, length(primitives))
meshes = Vector{Mesh}(undef, length(primitives))
for i = 1:length(primitives)
b = HyperRectangle(primitives[i])
meshes[i] = MT(x -> FRep(primitives[i], x), b, samples, algorithm)
rng = range.(b.origin, b.origin.+ b.widths)
@show rng
sdf(v) = FRep(primitives[i], SVector(v...))
vts, fcs = isosurface(sdf, algorithm, rng[1], rng[2], rng[3]; samples)
_points = map(GeometryBasics.Point, vts)
_faces = map(v -> GeometryBasics.TriangleFace{GeometryBasics.OneIndex}(v), fcs)
normals = map(v -> GeometryBasics.Vec3f(gradient(sdf, SVector(v...))...), vts)
meshes[i] = GeometryBasics.Mesh(GeometryBasics.meta(_points; normals=normals), _faces)
end
return merge(meshes)
end
Expand Down
4 changes: 2 additions & 2 deletions test/meshes.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

@testset "Meshing" begin
c = Mesh(translate([4,5,6])Cuboid([1,2,3]))
c = mesh(translate([4,5,6])Cuboid([1,2,3]))
@test_broken length(c.vertices) == 7638
@test_broken length(c.faces) == 15272

Expand All @@ -12,7 +12,7 @@
u = Shell(0.5)RadiusedCSGUnion(1,c2, cyl1)
u2 = CSGDiff(u, Cuboid([2,2,2]))

m = Mesh(u2)
m = mesh(u2)
@test_broken length(m.vertices) == 86406
@test_broken length(m.faces) == 172678
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Combinatorics
using FileIO
using MeshIO

using GeometryBasics: Mesh, HyperRectangle
using GeometryBasics: mesh, HyperRectangle

primitives_array = [Sphere(1), Cuboid([1,2,3]), Cylinder(3,4)]
operations_array = [CSGUnion, CSGIntersect, CSGDiff]
Expand Down

0 comments on commit a778400

Please sign in to comment.