# Makie: Triangle face colour, mesh

I have a question about Makie, when plotting triangulated mesh surfaces is it possible to colour with flat coloured patches?
Like: https://de.mathworks.com/help/matlab/ref/trisurf.html
Compared to the example in: 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

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

Do you have an example?
Tim

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

2 Likes

well this “hack” could be turned into a recipe

2 Likes

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: https://github.com/JuliaIO/MeshIO.jl/blob/69b58518a5ea41ab56b8d87bcae8bff220b34c5c/src/io/stl.jl#L83

``````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]
``````

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?

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

``````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.

1 Like