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

**URL:** <https://discourse.julialang.org/t/creating-a-mesh-with-meshes-need-to-use-smoothing-taubin-and-getting-afterwards-a-mesh-compatible-with-makie/81029>\
**Category:** General Usage\
**Tags:** plotting, makie, meshes\
**Created:** [May 13, 2022, 3:33pm UTC](https://discourse.julialang.org/t/creating-a-mesh-with-meshes-need-to-use-smoothing-taubin-and-getting-afterwards-a-mesh-compatible-with-makie/81029 "2022-05-13T15:33:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [May 13, 2022, 3:33pm UTC](https://discourse.julialang.org/t/creating-a-mesh-with-meshes-need-to-use-smoothing-taubin-and-getting-afterwards-a-mesh-compatible-with-makie/81029/1 "2022-05-13T15:33:14Z")

</div>

After doing some [reading](https://juliageometry.github.io/Meshes.jl/dev/) 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:

```plaintext
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 Φ]
surface(x,y,z)

```

 ![Screenshot 2022-05-13 at 16.56.54](https://global.discourse-cdn.com/julialang/original/3X/e/1/e1fb92d7c9ffe62ccfe0736c30d34e131168bfa0.png)

then, using Makie we can create a mesh:

```plaintext
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))
    end)
end

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

function getMesh(x, y, z, uv_buff)
    positions = vec(map(CartesianIndices(z)) do i
        GeometryBasics.Point{3,Float32}(
            get_dim(x, i, 1, size(z)),
            get_dim(y, i, 2, size(z)),
            z[i])
    end)
    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)
    meshObj
end
meshSphere = getMesh(x, y, z, uv_buff);
mesh(meshSphere; color=rand(10, 100))

```

 ![Screenshot 2022-05-13 at 17.24.22](https://global.discourse-cdn.com/julialang/original/3X/e/5/e530b74f9dfe601577729b540c4caf9339113016.png)

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

[https://juliageometry.github.io/Meshes.jl/dev/algorithms/smoothing.html#Taubin](https://juliageometry.github.io/Meshes.jl/dev/algorithms/smoothing.html#Taubin)

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.

cheers!

---

<div class="post-metadata">

**Author:** ![kool7d](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kool7d/32/3608_2.png) [@kool7d](https://discourse.julialang.org/u/kool7d)\
**Post date:** [May 15, 2022, 1:34am UTC](https://discourse.julialang.org/t/creating-a-mesh-with-meshes-need-to-use-smoothing-taubin-and-getting-afterwards-a-mesh-compatible-with-makie/81029/2 "2022-05-15T01:34:03Z")

</div>

[Flux3D.jl trimeshes](https://fluxml.ai/Flux3D.jl/dev/rep/trimesh/) are great for quickly and easily creating meshes from point clouds, and the reverse.
