Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Meshing.jl examples for v0.7 #260

Merged
merged 5 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Colors = "0.9, 0.10, 0.11, 0.12, 0.13"
CoordinateTransformations = "0.5, 0.6"
DocStringExtensions = "0.5, 0.6, 0.7, 0.8, 0.9"
FFMPEG = "0.2, 0.3, 0.4"
GeometryBasics = "0.3, 0.4, 0.5"
GeometryBasics = "0.3, 0.4"
HTTP = "1"
MeshIO = "0.4"
Meshing = "0.5, 0.6"
Meshing = "0.7"
MsgPack = "1"
Parameters = "0.10, 0.11, 0.12, 0.13"
PrecompileTools = "1"
Expand Down
14 changes: 10 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,17 @@ setobject!(vis, PointCloud(verts, colors))

```julia
# Visualize a mesh from the level set of a function
using Meshing: MarchingTetrahedra
using GeometryBasics: Mesh, HyperRectangle
using Meshing: MarchingTetrahedra, isosurface
using GeometryBasics:
Mesh,
TriangleFace,
Vec,
Point
nhz2 marked this conversation as resolved.
Show resolved Hide resolved
xr,yr,zr = ntuple(_->LinRange(-1,1,50),3)
nhz2 marked this conversation as resolved.
Show resolved Hide resolved
f = x -> sum(sin, 5 * x)
mesh = Mesh(f, HyperRectangle(Vec(-1, -1, -1), Vec(2, 2, 2)),
MarchingTetrahedra())
sdf = [f(Vec(x,y,z)) for x in xr, y in yr, z in zr]
vts, fcs = isosurface(sdf, MarchingTetrahedra(), xr, yr, zr)
mesh = Mesh(Point.(vts), TriangleFace.(fcs))
setobject!(vis, mesh,
MeshPhongMaterial(color=RGBA{Float32}(1, 0, 0, 0.5)))
```
Expand Down
4 changes: 2 additions & 2 deletions notebooks/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ MeshIO = "7269a6da-0436-5bbc-96c2-40638cbb6118"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"

[compat]
Colors = "0.9, 0.10, 0.11, 0.12"
Colors = "0.9, 0.10, 0.11, 0.12, 0.13"
FileIO = "1"
GeometryBasics = "0.3, 0.4"
Meshing = "0.5, 0.6"
Meshing = "0.7"
MeshIO = "0.4"
10 changes: 6 additions & 4 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"using MeshCat\n",
"using CoordinateTransformations\n",
"using Rotations\n",
"using GeometryBasics: HyperRectangle, Vec, Point, Mesh\n",
"using GeometryBasics: HyperRectangle, Vec, Point, Mesh, TriangleFace\n",
nhz2 marked this conversation as resolved.
Show resolved Hide resolved
"using Colors: RGBA, RGB"
]
},
Expand Down Expand Up @@ -384,10 +384,12 @@
"# Those two pieces of information are all we need to construct a mesh geometry.\n",
"\n",
"# Using `Meshing.jl`, we can construct a mesh directly from our function:\n",
"using Meshing: MarchingCubes\n",
"using Meshing: MarchingTetrahedra, isosurface\n",
"\n",
"bounds = HyperRectangle(lower_bound, upper_bound - lower_bound)\n",
"mesh = Mesh(f, bounds, MarchingCubes())\n",
"xr,yr,zr = ntuple(i->LinRange(lower_bound[i], upper_bound[i],50),3)\n",
"sdf = [f(Vec(x,y,z)) for x in xr, y in yr, z in zr]\n",
"vts, fcs = isosurface(sdf, MarchingTetrahedra(), xr, yr, zr)\n",
"mesh = Mesh(Point.(vts), TriangleFace.(fcs))\n",
"\n",
"# And now we can load that geometry into the visualizer\n",
"setobject!(vis, mesh)"
Expand Down
Loading