diff --git a/REQUIRE b/REQUIRE index 82c5825..77e6637 100644 --- a/REQUIRE +++ b/REQUIRE @@ -3,7 +3,7 @@ LCMCore 0.1.0 BinDeps 0.4.0 GeometryTypes 0.4 ColorTypes 0.2.0 -Meshing 0.2.0 +Meshing 0.3.0 MeshIO 0.1 FileIO 0.2.2 Rotations 0.5.0 diff --git a/src/DrakeVisualizer.jl b/src/DrakeVisualizer.jl index 439528a..adcbadb 100644 --- a/src/DrakeVisualizer.jl +++ b/src/DrakeVisualizer.jl @@ -6,7 +6,7 @@ using LCMCore using GeometryTypes using FileIO import GeometryTypes: origin, radius, raw -import Meshing +using Meshing: MarchingTetrahedra, MarchingCubes import MeshIO import Rotations: Rotation, Quat import CoordinateTransformations: Transformation, diff --git a/src/contour_meshes.jl b/src/contour_meshes.jl index 53648ae..05978b1 100644 --- a/src/contour_meshes.jl +++ b/src/contour_meshes.jl @@ -1,26 +1,16 @@ +""" +Extract an isosurface from a vector-input function in 3 dimensions and +return it as a mesh. +""" function contour_mesh(f::Function, bounds::HyperRectangle, isosurface_value::Number=0.0, resolution::Real=maximum(widths(bounds))/20.0) - # Extract an isosurface from a vector-input function in 3 dimensions and - # return it as a mesh. This function mostly exists to work around bugs in - # Meshing.jl: specifically its weird handling of non-zero isosurfaces - # and its incorrect mesh point scaling: - # https://github.com/JuliaGeometry/GeometryTypes.jl/issues/49 window_width = widths(bounds) - sdf = SignedDistanceField(x -> f(SVector{3, Float64}(x[1], x[2], x[3])) - isosurface_value, + sdf = SignedDistanceField(x -> f(SVector{3, Float64}(x[1], x[2], x[3])), bounds, resolution) - - # We've already accounted for the isosurface value in the construction of - # the SDF, so we set the iso value here to 0. - mesh = HomogenousMesh(sdf, 0.0) - - # Rescale the mesh points and then construct a new mesh using the rescaled - # points and the original faces. - lb = minimum(bounds) - rescaled_points = Point{3,Float64}[Vec(v-1) ./ (Vec(size(sdf))-1) .* window_width .+ lb for v in vertices(mesh)] - HomogenousMesh(rescaled_points, mesh.faces) + HomogenousMesh(sdf, MarchingTetrahedra(isosurface_value)) end contour_mesh(f::Function,