# Interactive change of mesh plot

**URL:** <https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [October 17, 2024, 11:23pm UTC](https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435 "2024-10-17T23:23:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IvanSpirandelli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ivanspirandelli/32/212718_2.png) [@IvanSpirandelli](https://discourse.julialang.org/u/IvanSpirandelli)\
**Post date:** [October 17, 2024, 11:23pm UTC](https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435/1 "2024-10-17T23:23:36Z")

</div>

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:

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

---

<div class="post-metadata">

**Author:** ![ederag](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ederag/32/4106_2.png) [@ederag](https://discourse.julialang.org/u/ederag)\
**Post date:** [October 18, 2024, 2:05pm UTC](https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435/2 "2024-10-18T14:05:29Z")

</div>

Welcome !  
You’d have more chances to get help with an [MWE](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)  
(your snippet fails with “ERROR: UndefVarError: `meshdata` not defined”,  
so it’s impossible to jump quickly to solving your actual issue).

---

<div class="post-metadata">

**Author:** ![IvanSpirandelli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ivanspirandelli/32/212718_2.png) [@IvanSpirandelli](https://discourse.julialang.org/u/IvanSpirandelli)\
**Post date:** [October 21, 2024, 10:24pm UTC](https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435/3 "2024-10-21T22:24:28Z")

</div>

Hi @ederag,

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

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![IvanSpirandelli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ivanspirandelli/32/212718_2.png) [@IvanSpirandelli](https://discourse.julialang.org/u/IvanSpirandelli)\
**Post date:** [October 21, 2024, 10:33pm UTC](https://discourse.julialang.org/t/interactive-change-of-mesh-plot/121435/4 "2024-10-21T22:33:01Z")

</div>

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

```julia
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)

```
