Creating a mesh with Meshes(need to use smoothing-Taubin) and getting afterwards a mesh compatible with Makie

After doing some reading I did not found a way to create a simple mesh giving a set of points and then getting back a compatible mesh that can be plotted with Makie. Let’s say we have the following:

using GLMakie
Θ = LinRange(0, 2π, 100) # 50
Φ = LinRange(0, π, 100)
r = 0.5
x = [r * cos(θ) * sin(ϕ) + 0.1 * rand() for θ in Θ, ϕ in Φ]
y = [r * sin(θ) * sin(ϕ) + 0.1 * rand() for θ in Θ, ϕ in Φ]
z = [r * cos(ϕ) + 0.1 * rand() for θ in Θ, ϕ in Φ]

then, using Makie we can create a mesh:

using GeometryBasics
using Makie: get_dim, surface_normals
function gen_uv(shift, z)
    return vec(map(CartesianIndices(size(z))) do ci
        tup = ((ci[1], ci[2]) .- 1) ./ ((size(z) .* shift) .- 1)
        return Vec2f(reverse(tup))

uv = gen_uv(1.0, z)
uv_buff = Buffer(uv)

function getMesh(x, y, z, uv_buff)
    positions = vec(map(CartesianIndices(z)) do i
            get_dim(x, i, 1, size(z)),
            get_dim(y, i, 2, size(z)),
    faces = decompose(GLTriangleFace, Rect2D(0.0f0, 0.0f0, 1.0f0, 1.0f0), size(z))
    normals = surface_normals(x, y, z)
    vertices = GeometryBasics.meta(positions; uv=uv_buff, normals=normals)
    meshObj = GeometryBasics.Mesh(vertices, faces)
meshSphere = getMesh(x, y, z, uv_buff);
mesh(meshSphere; color=rand(10, 100))

Note that here for color we can simple pass a matrix, that is cool and nice to have.
Now, the goal will be to use

so that we might have a smoother mesh [if this even make sense to do or possible ?]. And then go back to a normal mesh for Makie[GeometryBasics], so that we can continue with plotting (I’m aware of MeshViz).

Any hints/ideas are welcome.


Flux3D.jl trimeshes are great for quickly and easily creating meshes from point clouds, and the reverse.