How to display moving objects in Makie.jl

Thanks a lot for your example code!

But it will not solve my problem. One problem is that the length of the cylinders that I need is varying, depending on the ball distances. And there is no cylinder object in Makie that has length and diameter as parameters.

The following code works, and is good enough for me for now, but as you said it has a lot of overhead:

# globals
const SCALE = 1.2 
const KITE = FileIO.load("data/kite.obj")
const PARTICLES = Vector{AbstractPlotting.Mesh}(undef, SEGMENTS+1)
const SEGS      = Vector{AbstractPlotting.Mesh}(undef, SEGMENTS)
const KITE_MESH = Vector{MeshScatter{Tuple{Vector{Point{3, Float32}}}}}(undef, 1)
const init      = [false]

# draw the kite power system, consisting of the tether and the kite
function draw_system(scene, state)
    # loop over the particles of the main tether and render them as spheres
    for i in range(1, length=length(state.X))
        if init[1] 
            delete!(scene.scene, PARTICLES[i])
        end
        particle = mesh!(scene, Sphere(Point3f0(state.X[i], state.Y[i], state.Z[i]), 0.07 * SCALE), color=:yellow)
        PARTICLES[i] = particle
    end

    end_point = Point3f0(0,0,0)
    # loop over the springs of the main tether and render them as cylinders
    for i in range(1, length=length(state.X) - 1)
        if init[1] 
            delete!(scene.scene, SEGS[i])
        end
        start_point = Point3f0(state.X[i], state.Y[i], state.Z[i])
        end_point  = Point3f0(state.X[i+1], state.Y[i+1], state.Z[i+1])
        segment = mesh!(scene, Cylinder(start_point, end_point, Float32(0.035 * SCALE)), color=:yellow)
        SEGS[i] = segment
    end

    # rot = Quaternionf0(1, 0, -1, 0)
    # # kite.rot = rot3d(vec3(0, -1, 0), vec3(1, 0, 0), vec3(0, 0, -1), x, y, z)
    # # render the kite
    if init[1]
        delete!(scene.scene,  KITE_MESH[1])
    end
    KITE_MESH[1] = meshscatter!(scene, end_point, marker=KITE, markersize = 0.5, rotations = Vec3f0.(0, -1, 0), color=:blue)
    init[1] = true
end
1 Like