Struggling with lighting on GLMakie Meshes

Can anyone point me to an up to date resource on lighting meshes in GLMakie?

Whatever I try at the moment results in a completely flat color, with no way to percieve depth.

Try:

using GeometryBasics

Makie.mesh(normal_mesh(your_flat_mesh))

Thanks for getting back to me. I’ve now tried that, but I’m still getting the same.

Any other ideas? I can try to put together a minimal example if that will help

Yeah if that doesn’t work, I’ll need a minimal example!

lighting

beautiful makie

I follow above docs ,make some plots

It looks like there is indeed some lighting in your plot. Did you try changing lightposition, specular, or diffuse?

An update. I’ve partially figured out the problem: when I load an .stl file using FileIO, the loaded mesh has normal vectors all [0.0, 0.0, 0.0]. Therefore calling normal_mesh does nothing, as it believes the normals are already defined.

I can avoid the problem by using .OBJ files that I have of the mesh, instead of STLs.

I don’t know if this applies to all STLs, or only some.

Here is a minimal example, although I can’t seem to upload the .stl or .obj files here…

using ColorTypes: RGBA
using GLMakie
using GeometryBasics
using FileIO
using StaticArrays

Makie.inline!(false)
fig = Figure()
ax1 = Axis3(fig[1, 1]; aspect = :data, title=".stl")
ax2 = Axis3(fig[1, 2]; aspect = :data, title=".obj")

# Doesn't work
m1 = normal_mesh(FileIO.load("./link1.stl"))
m2 = normal_mesh(FileIO.load("./link1.obj"))

mesh!(ax1, m1; color = RGBAf(1.0, 1.0, 1.0, 1.0))
mesh!(ax2, m2; color = RGBAf(1.0, 1.0, 1.0, 1.0))
display(fig)

Note: calling normal mesh in the previous example has no effect. It can be omitted for the same result.

Ah that’s weird, not sure if that’s a problem in the .stl file or in MeshIO.
You can do:

m = FileIO.load("./link1.stl")
normal_mesh(GeometryBasics.Mesh(coordinates(m), faces(m)))
1 Like