# How to rotate mesh using observables in Makie?

**URL:** <https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [May 15, 2025, 7:56pm UTC](https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047 "2025-05-15T19:56:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmo](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@jmo](https://discourse.julialang.org/u/jmo)\
**Post date:** [May 15, 2025, 7:56pm UTC](https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047/1 "2025-05-15T19:56:47Z")

</div>

My aim is to rotate/translate a few objects (STL) in 3D visualizing a running simulation. And Makie seems to be the way to do it. I started simple with just trying to rotate a cube using an observable updated every 100 ms. However, without success.

The code below runs, a cube is displayed, the observable and the meshplot.transformation is updating but no rotation is visible.

How is this supposed to be done?

```julia
using GLMakie
#using Makie
using GeometryBasics
#using StaticArrays
GLMakie.activate!() 
fig = Figure()
ax = Axis3(fig[1, 1]; aspect = :data)
cube = HyperRectangle(Vec3f(-1, -1, -1), Vec3f(2, 2, 2))
meshplot = mesh!(ax, cube, color = :lightblue, transparency = false)
linesegments!(ax, [Point3f(0,0,0), Point3f(2,0,0)], color=:red) # x-axis
linesegments!(ax, [Point3f(0,0,0), Point3f(0,2,0)], color=:green) # y-axis
linesegments!(ax, [Point3f(0,0,0), Point3f(0,0,2)], color=:blue) # z-axis
angle = Observable(0.0)
on(angle) do θ
    mat = Makie.rotationmatrix_y(Float32(θ))
    meshplot.transformation = Transformation(mat)
    @show meshplot.transformation
end
@async while isopen(fig.scene)
    angle[] += 0.03f0
    println(angle[])
    sleep(1/20)
end
fig

```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 15, 2025, 9:56pm UTC](https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047/2 "2025-05-15T21:56:06Z")

</div>

I think `transformation` is only used at plot creation, and afterwards you cannot update it directly anymore.

[Transformations | Makie](https://docs.makie.org/stable/reference/generic/transformations#transformation-Attribute) says:

> The transformation attribute controls how the `Transformation` object is initialized. It is processed once during plot construction and then removed.

You can call `rotate!` with an optional `Accum` argument to accumulate incremental rotations, it’s described at the top of the linked page

---

<div class="post-metadata">

**Author:** ![asinghvi17](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asinghvi17/32/8272_2.png) [@asinghvi17](https://discourse.julialang.org/u/asinghvi17)\
**Post date:** [May 15, 2025, 10:42pm UTC](https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047/3 "2025-05-15T22:42:38Z")

</div>

Yeah, for this particular case you should probably call `rotate!(Accum, plot, rotation...)` and `translate!(Accum, plot, translation...)` to mutate the model matrices.

If you have some more complex transformation you can always update `plot.transformation.model[]`. That will let you do shear etc.

---

<div class="post-metadata">

**Author:** ![jmo](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@jmo](https://discourse.julialang.org/u/jmo)\
**Post date:** [May 16, 2025, 12:03pm UTC](https://discourse.julialang.org/t/how-to-rotate-mesh-using-observables-in-makie/129047/4 "2025-05-16T12:03:59Z")

</div>

I missed that Transformation() is for initialization only. `rotate!(meshplot, Float32(θ))` works as intended. Many thanks!
