Interactive change of mesh plot

I have a situation in which I have vector with mesh data, a
Vector{Tuple{Vector{Point{3, Float32}}, Matrix{Int64}, Vector{Float64}}}
containing vertices, faces and colors for a sequence of meshes I’d like to plot interactively.

I am currently trying this as follows:

f = Figure(fontsize = 12)
sl_i = Slider(f[2, 1], range = 1:length(meshdata), startvalue = 1)
x = sl_i.value
i_sc = LScene(f[1, 1])
vertices, faces, colors = @lift(meshdata[$x][1]), @lift(meshdata[$x][2]), @lift(meshdata[$x][3])
mesh!(i_sc, vertices, faces, color = colors)

This somewhat works but I get an occasional error when sliding because of what I assume are synchronicity problems.

Is there a way to circumvent this?

Thanks a lot

Ivan

Welcome !
You’d have more chances to get help with an MWE
(your snippet fails with “ERROR: UndefVarError: meshdata not defined”,
so it’s impossible to jump quickly to solving your actual issue).

Hi @ederag,

good suggestion. Attached is a MWE causing the error I encounter:

using Random
using GLMakie

f = Figure(fontsize = 12)
n_meshes = 10

#Slider
sl_i = Slider(f[2, 1], range = 1:n_meshes, startvalue = 1)
x = sl_i.value

#meshes
vertices = [[Point3f(rand(3)) for _ in 1:rand(250:500)] for _ in 1:n_meshes]
faces = [permutedims(hcat([shuffle(1:length(vertices[i]))[1:3] for _ in 1:rand(350:700)]...)) for i in 1:n_meshes]
colors = [rand(length(vertices[i])) for i in 1:n_meshes]
l_vs, l_fs, l_cs = @lift(vertices[$x]), @lift(faces[$x]), @lift(colors[$x])

i_sc = LScene(f[1, 1])
mesh!(i_sc, l_vs, l_fs, color = l_cs, colorrange = (0.0, 1.0), colormap = :magma)

display(f)

I solved it by constructing GeometryBasics.Meshes out of the data, before lifting them. Like so:

using Random
using GLMakie
using GeometryBasics

f = Figure(fontsize = 12)

#Slider
n_meshes = 10
sl_i = Slider(f[2, 1], range = 1:n_meshes, startvalue = 1)
x = sl_i.value

vertices = [[Point3f(rand(3)) for _ in 1:rand(250:500)] for _ in 1:n_meshes]
faces = [[TriangleFace(shuffle(1:length(vertices[i]))[1:3]) for _ in 1:rand(350:700)] for i in 1:n_meshes]
meshes = [GeometryBasics.Mesh(vertices[i], faces[i]) for i in 1:n_meshes]
colors = [rand(length(vertices[i])) for i in 1:n_meshes]

i_sc = LScene(f[1, 1])
l_ms, l_cs = @lift(meshes[$x]), @lift(colors[$x])
mesh!(i_sc, l_ms, color = l_cs, colorrange = (0.0, 1.0), colormap = :magma)

display(f)
1 Like