# Data Structures for 3D mesh

**URL:** <https://discourse.julialang.org/t/data-structures-for-3d-mesh/53051>\
**Category:** New to Julia\
**Tags:** plotting\
**Created:** [January 8, 2021, 4:38pm UTC](https://discourse.julialang.org/t/data-structures-for-3d-mesh/53051 "2021-01-08T16:38:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akalinin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/akalinin/32/20163_2.png) [@akalinin](https://discourse.julialang.org/u/akalinin)\
**Post date:** [January 8, 2021, 4:38pm UTC](https://discourse.julialang.org/t/data-structures-for-3d-mesh/53051/1 "2021-01-08T16:38:53Z")

</div>

I want to plot 3D triangular mesh in Julia. “JuliaPlots/Makie.jl” package looks good for this purposes and I visited the “JuliaPlots/MakieGallery.jl/blob/master/examples/examples3d.jl” for some examples. And probably the code

```julia
mesh1 = normal_mesh(geometry)

```

construct a mesh. So I tried to expect what is the “normal\_mesh” method ans see…

```julia
# 2 methods for generic function "normal_mesh":
  [1] normal_mesh(primitive::Union{AbstractPolygon{N,T}, GeometryPrimitive{N,T}, AbstractArray{var"#s21",1} where var"#s21"<:AbstractPoint{N,T}, GeometryBasics.Mesh{N,T,Element,V} where V<:AbstractArray{Element,1} where Element<:Polytope{N,T}, Tesselation{N,T,Primitive,NGrid} where NGrid where Primitive} where T; nvertices) where N in GeometryBasics

```

For me it is difficult to understand all this types hierarchy. Typically for 3D mesh I used only two flat arrays with vertices and triangles. Do we have something similar in Julia or I need to construct a mesh like in the example with full hierarchy of types?

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [January 8, 2021, 5:51pm UTC](https://discourse.julialang.org/t/data-structures-for-3d-mesh/53051/2 "2021-01-08T17:51:42Z")

</div>

Take a look at Meshes.jl: [https://github.com/JuliaGeometry/Meshes.jl](https://github.com/JuliaGeometry/Meshes.jl)

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [January 8, 2021, 6:10pm UTC](https://discourse.julialang.org/t/data-structures-for-3d-mesh/53051/3 "2021-01-08T18:10:19Z")

</div>

I know the types in GeometryBasics are pretty off-putting, but it’s actually pretty easy to construct a mesh:

```julia
julia> rect = Rect(Vec(0.0, 0.0), Vec(1.0, 1.0))
# decompose the rectangle into two triangular faces
julia> rect_faces = decompose(TriangleFace{Int}, rect)
2-element Array{NgonFace{3,Int64},1}:
 TriangleFace(1, 2, 4)
 TriangleFace(1, 4, 3)

# decompose the rectangle into four vertices
julia> rect_vertices = decompose(Point{2, Float64}, rect)
4-element Array{Point{2,Float64},1}:
 [0.0, 0.0]
 [1.0, 0.0]
 [0.0, 1.0]
 [1.0, 1.0]

# combine the vertices and faces into a triangle mesh
julia> mesh = Mesh(rect_vertices, rect_faces)

```

A face is just a type for wrapping indices:

```julia
TriangleFace(1, 2, 3) -> indices [1,2,3]

```

You can also reinterpret existing index arrays to TriangleFace
