Modia3D is a Julia package that adds a multibody program and 3D shapes for visualization and collision handling to the Modia Modeling Language. It is then, for example, possible to model the 3D mechanical part of a robot with Modia3D and the electrical motors and gearboxes that are driving the joints with the Modia language. Collision handling with elastic response calculation is performed for shapes that are defined with a contact material and have a convex geometry or are approximated by the convex hull of a concave geometry. For more details, see the Modia3D Tutorial.
Modia3D supports currently tree-structured multibody systems, but does not (yet) support kinematic loops.
Example videos:
- Rattleback - wikipedia explanation (video in glb format, Modia3D code)
- YouBot robots gripping a workpiece (Modia3D code)
- Billiard table with 16 balls (Modia3D code)
- Mobile with 8 levels (Modia3D code - recursive definition)
Modia3D requires Julia 1.7 or later and is installed with
julia> ]add Modia3D
It is advised to also install Modia and at least one Modia plot package (for details see Installation of Modia).
Note, Modia3D reexports the following definitions
using Modia
using Unitful
using DifferentialEquations
using SignalTables
- and exports functions
CVODE_BDF
andIDA
of Sundials.jl.
As a result, it is usually sufficient to have using Modia3D
in a model to utilize the relevant
functionalities of these packages.
Modia3D has various 3D animation features:
-
With
world = Object3D(feature=Scene(animationFile="filename.json"))
the animation produced during a simulation run is exported in three.js JSON Object Scene format. The generated file can be imported into the open source web app three.js editor and use all the features of three.js, for example to export in the widely used glb format (the binary version of the glTF format) and use any glb viewer (for example 3D-Viewer of Windows). -
With the default option
world = Object3D(feature=Scene(enableVisualization=true))
the DLR Visualization Library (see the many examples from various research and industrial projects) is used, if installed, for online animation (during simulation), replays (after simulation), and the generation of mpg4-videos. This library is available as (free) Community Edition and as (commercial) Professional Edition (Web page to request download of DLR Visualization Library). After download, make the library available in the following way:- Set Julia environment variable
ENV["DLR_VISUALIZATION"] = "<path-to-library>/Visualization/Extras/SimVis"
or add it to the Julia startup.jl file. Make sure that the SimVis executable under this directory has execution rights. For example in Linux with command:chmod ug+x <path-to-library>/Visualization/Extras/SimVis/linux/SimVis
- Set Julia environment variable
In order to speed up startup, a sysimage can be generated by executing the following commands (may take several minutes):
julia
using Modia3D
include("$(Modia3D.path)/create_Modia3D_sysimage.jl")
exit()
This will generate a file Modia3D_sysimage.dll
(on Windows) or Modia3D_sysimage.so
(otherwise) in your
current working directory that includes all packages of your current project and the following packages
(these packages are added to your current project, if not yet included):
- Modia, Modia3D, ModiaPlot_PyPlot, PackageCompiler, Revise
Start julia with this sysimage in the following way:
julia -JModia3D_sysimage.dll (on Windows)
julia -JModia3D_sysimage.so (otherwise)
The benefit is that using Modia3D
is nearly immediatedly executed (instead of > 30 seconds).
The drawback is that create_Modia3D_sysimage.jl
has to be newly executed, whenever
new package versions are used in your environment.
Andrea Neumayr,
Martin Otter and
Gerhard Hippmann,
DLR - Institute of System Dynamics and Control
License: MIT (expat)