Skip to content

Commit

Permalink
Merge 776c92f into 9288534
Browse files Browse the repository at this point in the history
  • Loading branch information
janbruedigam authored Apr 12, 2023
2 parents 9288534 + 776c92f commit b13e97a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/visuals/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
color: RGBA
name: unique identifier for mechanism
"""
function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=Visualizer(),
function visualize(mechanism::Mechanism, storage::Storage{T,N};
vis::Visualizer=Visualizer(),
framerate=60, # Inf for 1/timestep
build::Bool=true,
show_joint=false,
joint_radius=0.1,
Expand All @@ -32,7 +34,9 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=
vis, show_joint, show_contact, show_frame, color, name, visualize_floor)

# Create animations
framerate = Int64(round(1/mechanism.timestep))
timestep_max = 1/framerate
time_factor = Int64(maximum([1;floor(timestep_max/mechanism.timestep)]))
framerate = Int64(round(1/(mechanism.timestep*time_factor)))
(animation === nothing) && (animation =
MeshCat.Animation(Dict{MeshCat.SceneTrees.Path,MeshCat.AnimationClip}(), framerate))

Expand All @@ -47,7 +51,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=
showshape = true
end

animate_node!(storage, id, shape, animation, subvisshape, showshape)
animate_node!(storage, id, shape, animation, subvisshape, showshape, time_factor)

if show_joint
for (jd, joint) in enumerate(mechanism.joints)
Expand All @@ -63,7 +67,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=
subvisshape = vis[name][:joints][Symbol(joint.name, "__id_$(jd)")]
showshape = true
end
animate_node!(storage, id, joint_shape, animation, subvisshape, showshape)
animate_node!(storage, id, joint_shape, animation, subvisshape, showshape, time_factor)
end
end
end
Expand All @@ -84,7 +88,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=
subvisshape = vis[name][:contacts][Symbol(contact.name, "__id_$(jd)")]
showshape = true
end
animate_node!(storage, id, contact_shape, animation, subvisshape, showshape)
animate_node!(storage, id, contact_shape, animation, subvisshape, showshape, time_factor)
end
end
end
Expand All @@ -94,7 +98,7 @@ function visualize(mechanism::Mechanism, storage::Storage{T,N}; vis::Visualizer=
visshape = convert_shape(frame_shape)
subvisshape = vis[name][:frames][Symbol(body.name, "__id_$id")]
showshape = true
animate_node!(storage, id, frame_shape, animation, subvisshape, showshape)
animate_node!(storage, id, frame_shape, animation, subvisshape, showshape, time_factor)
end
end

Expand Down Expand Up @@ -319,13 +323,15 @@ function set_node!(x, q, id, shape, shapevisualizer, showshape)
return
end

function animate_node!(storage::Storage{T,N}, id, shape, animation, shapevisualizer, showshape) where {T,N}
for i=1:N
function animate_node!(storage::Storage{T,N}, id, shape, animation, shapevisualizer, showshape, time_factor) where {T,N}
frame_id = 1
for i=1:time_factor:N
x = storage.x[id][i]
q = storage.q[id][i]
atframe(animation, i) do
atframe(animation, frame_id) do
set_node!(x, q, id, shape, shapevisualizer, showshape)
end
frame_id += 1
end
return
end
Expand Down

0 comments on commit b13e97a

Please sign in to comment.