# Makie: Triangle face colour, mesh

**URL:** <https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011>\
**Category:** Visualization\
**Created:** [November 26, 2018, 11:57am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011 "2018-11-26T11:57:20Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [November 26, 2018, 11:57am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/1 "2018-11-26T11:57:20Z")

</div>

I have a question about Makie, when plotting triangulated mesh surfaces is it possible to colour with flat coloured patches?  
Like: [Triangular surface plot - MATLAB trisurf - MathWorks Deutschland](https://de.mathworks.com/help/matlab/ref/trisurf.html)  
Compared to the example in: [http://makie.juliaplots.org/stable/examples-mesh.html](http://makie.juliaplots.org/stable/examples-mesh.html)  
I.e. the colour vector defines the colour of each triangles face and not each triangle’s edge points.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![edljk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/edljk/32/2429_2.png) [@edljk](https://discourse.julialang.org/u/edljk)\
**Post date:** [November 26, 2018, 9:19pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/2 "2018-11-26T21:19:20Z")

</div>

You can obtain flat coloured patches by a naive duplication of nodes to ensure that every triangle has different (eventually duplicated) vertices.

---

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [November 26, 2018, 9:41pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/3 "2018-11-26T21:41:23Z")

</div>

Do you have an example?  
Tim

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [November 27, 2018, 5:31am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/4 "2018-11-27T05:31:25Z")

</div>

That seems like a hack. Sounds like something that should be easily implemented (if it isn’t already).

---

<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:** [November 27, 2018, 7:57am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/5 "2018-11-27T07:57:42Z")

</div>

well this “hack” could be turned into a recipe 😉

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [November 27, 2018, 2:35pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/6 "2018-11-27T14:35:00Z")

</div>

Does the problem start because the mesh objects don’t support per-face attributes? I’m not sure if that’s actually the case, but I remember reading this comment: [MeshIO.jl/stl.jl at 69b58518a5ea41ab56b8d87bcae8bff220b34c5c · JuliaIO/MeshIO.jl · GitHub](https://github.com/JuliaIO/MeshIO.jl/blob/69b58518a5ea41ab56b8d87bcae8bff220b34c5c/src/io/stl.jl#L83)

```julia
normals[i*3+1] = NormalType(normal...)
normals[i*3+2] = normals[i*3+1] # hurts, but we need per vertex normals
normals[i*3+3] = normals[i*3+1]

```

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [August 15, 2019, 4:04pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/7 "2019-08-15T16:04:25Z")

</div>

Any developments on this? I’m looking for the same feature right now.

I wrote some code to remove duplicate vertices from the meshes generated by Meshing.jl; now it seems like I have to implement the reverse operation?

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [August 15, 2019, 4:11pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/8 "2019-08-15T16:11:15Z")

</div>

The code is not complicated but I agree with @dpsanders, this should be a convenience method from the package

```julia
function _explode_vertices(vertices, faces)
    new_vertices = similar(vertices, 0)
    new_faces = similar(faces, 0)
    for (i, face) in enumerate(faces)
        for vertex in vertices[face]
            push!(new_vertices, vertex)
        end
        push!(new_faces, Triangle(3i - 2:3i...))
    end
    return new_vertices, new_faces
end
newmesh = GLNormalMesh(_explode_vertices(oldmesh.vertices, oldmesh.faces)...)

```

feel free to upstream this code under current Meshing.jl license.

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [March 6, 2024, 10:33am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/9 "2024-03-06T10:33:16Z")

</div>

Sorry to revive this, but is there a new (more built-in) approach to this ?

---

<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:** [March 6, 2024, 11:52am UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/10 "2024-03-06T11:52:31Z")

</div>

The `viz` recipe in Meshes.jl handles colors per face or per vertex. It is all documented:

```julia
using Meshes
import GLMakie as Mke

g = CartesianGrid(10, 10)

viz(g, color = 1:10*10) # face colors
viz(g, color = 1:11*11) # vertex colors

```

![image](https://global.discourse-cdn.com/julialang/original/3X/0/c/0cd831238c25a78d0f20e25e59036d64d02d1594.png)  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/7/f7d1b3f09c81cb66b6db5c0f2c9051f8433382fb.png)

---

<div class="post-metadata">

**Author:** ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)\
**Post date:** [March 7, 2024, 5:06pm UTC](https://discourse.julialang.org/t/makie-triangle-face-colour-mesh/18011/11 "2024-03-07T17:06:13Z")

</div>

Thanks @juliohm, I knew that Meshes could do it, but I wonder if @sdanisch or another Makie developper can explain if this is a GLMakie (or OpenGL even) limitation that forbids having this built-in, or something else.
