An interface for recording/playback animations in Meshcat.
Use Meshcat::SetAnimation to publish a MeshcatAnimation to the visualizer.
Currently, an animation consists of (only) transforms and properties that are set at a particular integer frame number. Although we do not support calls to SetObject/Delete in an animation, you can consider using SetProperty(frame, path, "visible", true/false)
in your animation to make the object appear or disappear at a particular frame.
#include <drake/geometry/meshcat_animation.h>
Public Types | |
enum | LoopMode { kLoopOnce = 2200, kLoopRepeat = 2201, kLoopPingPong = 2202 } |
Public Member Functions | |
MeshcatAnimation (double frames_per_second=64.0) | |
Constructs the animation object. More... | |
~MeshcatAnimation () | |
double | frames_per_second () const |
Returns the frame rate at which the animation will be played back. More... | |
int | frame (double time) const |
Uses the frame rate to convert from time to the frame number, using std::floor. More... | |
double | start_time () const |
bool | autoplay () const |
LoopMode | loop_mode () const |
int | repetitions () const |
bool | clamp_when_finished () const |
void | set_start_time (double time) |
Set the start time of the animation. More... | |
void | set_autoplay (bool play) |
Set the behavior when the animation is first sent to the visualizer. More... | |
void | set_loop_mode (LoopMode mode) |
Sets the loop behavior on play. More... | |
void | set_repetitions (int repetitions) |
Sets the number of repetitions of the animation each time it is played. More... | |
void | set_clamp_when_finished (bool clamp) |
Sets the behavior at the end of the animation. More... | |
void | SetTransform (int frame, std::string_view path, const math::RigidTransformd &X_ParentPath) |
Set the RigidTransform at frame in the animation for a given path in the the scene tree. More... | |
void | SetProperty (int frame, std::string_view path, std::string_view property, bool value) |
Sets a single named property of the object at the given path at the specified frame in the animation. More... | |
void | SetProperty (int frame, std::string_view path, std::string_view property, double value) |
Sets a single named property of the object at the given path at the specified frame in the animation. More... | |
void | SetProperty (int frame, std::string_view path, std::string_view property, const std::vector< double > &value) |
Sets a single named property of the object at the given path at the specified frame in the animation. More... | |
template<typename T > | |
std::optional< T > | get_key_frame (int frame, std::string_view path, std::string_view property) const |
Returns the value information for a particular path/property at a particular frame if a value of type T has been set, otherwise returns std::nullopt. More... | |
std::string | get_javascript_type (std::string_view path, std::string_view property) const |
Returns the javascript type for a particular path/property, or the empty string if nothing has been set. More... | |
Does not allow copy, move, or assignment | |
MeshcatAnimation (const MeshcatAnimation &)=delete | |
MeshcatAnimation & | operator= (const MeshcatAnimation &)=delete |
MeshcatAnimation (MeshcatAnimation &&)=delete | |
MeshcatAnimation & | operator= (MeshcatAnimation &&)=delete |
Friends | |
class | Meshcat |
enum LoopMode |
|
delete |
|
delete |
|
explicit |
Constructs the animation object.
frames_per_second | a positive integer specifying the timing at which the frames are played back. |
~MeshcatAnimation | ( | ) |
bool autoplay | ( | ) | const |
bool clamp_when_finished | ( | ) | const |
Uses the frame rate to convert from time to the frame number, using std::floor.
time
≥ start_time(). double frames_per_second | ( | ) | const |
Returns the frame rate at which the animation will be played back.
std::string get_javascript_type | ( | std::string_view | path, |
std::string_view | property | ||
) | const |
Returns the javascript type for a particular path/property, or the empty string if nothing has been set.
This method is intended primarily for testing.
std::optional<T> get_key_frame | ( | int | frame, |
std::string_view | path, | ||
std::string_view | property | ||
) | const |
Returns the value information for a particular path/property at a particular frame if a value of type T has been set, otherwise returns std::nullopt.
This method is intended primarily for testing.
T | One of bool , double , or vector<double> |
LoopMode loop_mode | ( | ) | const |
|
delete |
|
delete |
int repetitions | ( | ) | const |
void set_autoplay | ( | bool | play | ) |
Set the behavior when the animation is first sent to the visualizer.
The animation will play immediately iff play
is true. The default is true.
void set_clamp_when_finished | ( | bool | clamp | ) |
Sets the behavior at the end of the animation.
If true, then the animation will automatically be paused on its last frame. If false, the scene will be reset to before the animation. The default is true.
Note: This setting has no impact if the action is interrupted (it has only an effect if its last loop has really finished).
void set_loop_mode | ( | LoopMode | mode | ) |
Sets the loop behavior on play.
void set_repetitions | ( | int | repetitions | ) |
Sets the number of repetitions of the animation each time it is played.
This number has no effect when the loop mode is set to kLoopOnce. repetitions
must be a positive integer. The default value is 1.
void set_start_time | ( | double | time | ) |
Set the start time of the animation.
This is only for convenience; it is used in the frame() method to allow callers to look up the frame number based on the current time, the start time, and the frame rate. It is not passed to Meshcat. It does not change any frames that have previously been set. The default is zero.
void SetProperty | ( | int | frame, |
std::string_view | path, | ||
std::string_view | property, | ||
bool | value | ||
) |
Sets a single named property of the object at the given path
at the specified frame
in the animation.
frame | a non-negative integer indicating the frame at which this transform is applied. |
path | a "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics. |
property | the string name of the property to set |
value | the new value. |
std::exception | if this path/property has already been set with a different type. |
Sets a single named property of the object at the given path
at the specified frame
in the animation.
frame | a non-negative integer indicating the frame at which this transform is applied. |
path | a "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics. |
property | the string name of the property to set |
value | the new value. |
std::exception | if this path/property has already been set with a different type. |
void SetProperty | ( | int | frame, |
std::string_view | path, | ||
std::string_view | property, | ||
const std::vector< double > & | value | ||
) |
Sets a single named property of the object at the given path
at the specified frame
in the animation.
frame | a non-negative integer indicating the frame at which this transform is applied. |
path | a "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics. |
property | the string name of the property to set |
value | the new value. |
std::exception | if this path/property has already been set with a different type. |
void SetTransform | ( | int | frame, |
std::string_view | path, | ||
const math::RigidTransformd & | X_ParentPath | ||
) |
Set the RigidTransform at frame
in the animation for a given path
in the the scene tree.
frame | a non-negative integer indicating the frame at which this transform is applied. |
path | a "/"-delimited string indicating the path in the scene tree. See Meshcat paths for the semantics. |
X_ParentPath | the relative transform from the path to its immediate parent. |
std::exception | if the position or quaternion properties of this path have already been set to an incorrect type. |
double start_time | ( | ) | const |
|
friend |