3D rendering and animations

Multibody.jl has an automatic 3D-rendering feature that draws a mechanism in 3D. This can be used to create animations of the mechanism's motion from a solution trajectory, as well as to create interactive applications where the evolution of time can be controlled by the user.

The functionality requires the user to load any of the Makie frontend packages, e.g.,

using GLMakie


using CairoMakie

After that, the render function is the main entry point to create 3D renderings. This function has the following methods:

  • render(model, solution): this method creates an animation corresponding to the mechanisms evolution in a simulation trajectory.
  • render(model, solution, t::Real): this method opens an interactive window with the mechanism in the configuration corresponding to the time t.

Rendering API

scene, time = render(model, sol, t::Real; framerate = 30)
path        = render(model, sol, timevec = range(sol.t[1], sol.t[end], step = 1 / framerate); framerate = 30)

Create a 3D animation of a multibody system


  • model: The unsimplified multibody model, i.e., this is the model before any call to structural_simplify.
  • sol: The ODESolution produced by simulating the system using solve
  • t: If a single number t is provided, the mechanism at this time is rendered and a scene is returned together with the time as an Observable. Modify time[] = new_time to change the rendering.
  • timevec: If a vector of times is provided, an animation is created and the path to the file on disk is returned.
  • framerate: Number of frames per second.
  • filename controls the name and the file type of the resulting animation

Camera control

The following keyword arguments are available to control the camera pose: _ x = 0 _ y = 0 _ z = -10 _ R = I(3) The orientation. Use, e.g., R = Rotations.RotXYZ(roll, pitch, yaw) to set the orientation using Euler angles.

did_render::Bool = render!(scene, ::typeof(ComponentConstructor), sys, sol, t)

Each component that can be rendered must have a render! method. This method is called by render for each component in the system.

This method is responsible for drawing the component onto the scene the way it's supposed to look at time t in the solution sol. t is an Observable. It's recommended to follow the pattern

thing = @lift begin
    acces relevant coordinates from sol at time t
    create a geometric object that can be rendered
mesh!(scene, thing; style...)


A boolean indicating whether or not the component performed any rendering. Typically, all custom methods of this function should return true, while the default fallback method is the only one returning false.