diff --git a/ext/Render.jl b/ext/Render.jl index 416b8fcb..f0c64958 100644 --- a/ext/Render.jl +++ b/ext/Render.jl @@ -6,6 +6,7 @@ import Multibody.PlanarMechanics as P using Rotations using LinearAlgebra using ModelingToolkit +using ModelingToolkit: get_metadata export render, loop_render using MeshIO, FileIO using StaticArrays @@ -301,10 +302,11 @@ function render(model, sol, if traces !== nothing tvec = range(sol.t[1], stop=sol.t[end], length=500) for frame in traces - (frame.metadata !== nothing) || error("Only frames can be traced in animations.") - if get(frame.metadata, :frame, false) + md = get_metadata(frame) + (md !== nothing) || error("Only frames can be traced in animations.") + if get(md, :frame, false) points = get_trans(sol, frame, tvec) |> Matrix - elseif get(frame.metadata, :frame_2d, false) + elseif get(md, :frame_2d, false) points = get_trans_2d(sol, frame, tvec) |> Matrix else error("Got fishy frame metadata") @@ -374,10 +376,11 @@ function render(model, sol, time::Real; if traces !== nothing tvec = range(sol.t[1], stop=sol.t[end], length=500) for frame in traces - (frame.metadata !== nothing) || error("Only frames can be traced in animations.") - if get(frame.metadata, :frame, false) + md = get_metadata(frame) + (md !== nothing) || error("Only frames can be traced in animations.") + if get(md, :frame, false) points = get_trans(sol, frame, tvec) |> Matrix - elseif get(frame.metadata, :frame_2d, false) + elseif get(md, :frame_2d, false) points = get_trans_2d(sol, frame, tvec) |> Matrix else error("Got fishy frame metadata") @@ -1165,4 +1168,4 @@ function render!(scene, ::typeof(Multibody.CylinderVisualizer), sys, sol, t) true end -end \ No newline at end of file +end diff --git a/src/components.jl b/src/components.jl index 8f9b67d3..984eab4a 100644 --- a/src/components.jl +++ b/src/components.jl @@ -1,9 +1,11 @@ using LinearAlgebra +using ModelingToolkit: get_metadata import ModelingToolkitStandardLibrary function isroot(sys) - sys.metadata isa Dict || return false - get(sys.metadata, :isroot, false) + md = get_metadata(sys) + md isa Dict || return false + get(md, :isroot, false) end purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0] @@ -13,12 +15,13 @@ purple = [0.5019608f0,0.0f0,0.5019608f0,1.0f0] Get the orientation of `sys` as a `RotationMatrix` object. See also [`get_rot`](@ref). `ori(frame).R` is the rotation matrix that rotates a vector from the world coordinate system to the local frame. -For frames, the orientation is stored in the metadata field of the system as `sys.metadata[:orientation]`. +For frames, the orientation is stored in the metadata field of the system as `get_metadata(sys)[:orientation]`. If `varw = true`, the angular velocity variables `w` of the frame is also included in the `RotationMatrix` object, otherwise `w` is derived as the time derivative of `R`. `varw = true` is primarily used when selecting a component as root. """ function ori(sys, varw = false) - if sys.metadata isa Dict && (O = get(sys.metadata, :orientation, nothing)) !== nothing + md = get_metadata(sys) + if md isa Dict && (O = get(md, :orientation, nothing)) !== nothing R = collect(O.R) # Since we are using this function instead of sys.ori, we need to handle namespacing properly as well ns = nameof(sys)