Drake
Drake C++ Documentation
MeshcatAnimation Class Reference

Detailed Description

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
 
MeshcatAnimationoperator= (const MeshcatAnimation &)=delete
 
 MeshcatAnimation (MeshcatAnimation &&)=delete
 
MeshcatAnimationoperator= (MeshcatAnimation &&)=delete
 

Friends

class Meshcat
 

Member Enumeration Documentation

◆ LoopMode

enum LoopMode
Enumerator
kLoopOnce 

Plays the clip once.

kLoopRepeat 

Plays the clip with the chosen number of repetitions, each time jumping from the end of the clip directly to its beginning.

kLoopPingPong 

Plays the clip with the chosen number of repetitions, alternately playing forward and backward.

Constructor & Destructor Documentation

◆ MeshcatAnimation() [1/3]

MeshcatAnimation ( const MeshcatAnimation )
delete

◆ MeshcatAnimation() [2/3]

◆ MeshcatAnimation() [3/3]

MeshcatAnimation ( double  frames_per_second = 64.0)
explicit

Constructs the animation object.

Parameters
frames_per_seconda positive integer specifying the timing at which the frames are played back.

◆ ~MeshcatAnimation()

Member Function Documentation

◆ autoplay()

bool autoplay ( ) const

◆ clamp_when_finished()

bool clamp_when_finished ( ) const

◆ frame()

int frame ( double  time) const

Uses the frame rate to convert from time to the frame number, using std::floor.

Precondition
timestart_time().

◆ frames_per_second()

double frames_per_second ( ) const

Returns the frame rate at which the animation will be played back.

◆ get_javascript_type()

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.

◆ get_key_frame()

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.

Template Parameters
TOne of bool, double, or vector<double>

◆ loop_mode()

LoopMode loop_mode ( ) const

◆ operator=() [1/2]

MeshcatAnimation& operator= ( MeshcatAnimation &&  )
delete

◆ operator=() [2/2]

MeshcatAnimation& operator= ( const MeshcatAnimation )
delete

◆ repetitions()

int repetitions ( ) const

◆ set_autoplay()

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.

◆ set_clamp_when_finished()

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).

◆ set_loop_mode()

void set_loop_mode ( LoopMode  mode)

Sets the loop behavior on play.

See also
LoopMode for details. The default is kLoopRepeat.

◆ set_repetitions()

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.

◆ set_start_time()

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.

◆ SetProperty() [1/3]

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.

See also
Meshcat::SetProperty.
Parameters
framea non-negative integer indicating the frame at which this transform is applied.
patha "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics.
propertythe string name of the property to set
valuethe new value.
Exceptions
std::exceptionif this path/property has already been set with a different type.

◆ SetProperty() [2/3]

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.

See also
Meshcat::SetProperty.
Parameters
framea non-negative integer indicating the frame at which this transform is applied.
patha "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics.
propertythe string name of the property to set
valuethe new value.
Exceptions
std::exceptionif this path/property has already been set with a different type.

◆ SetProperty() [3/3]

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.

See also
Meshcat::SetProperty.
Parameters
framea non-negative integer indicating the frame at which this transform is applied.
patha "/"-delimited string indicating the path in the scene tree. See Meshcat paths and the scene tree for the semantics.
propertythe string name of the property to set
valuethe new value.
Exceptions
std::exceptionif this path/property has already been set with a different type.

◆ SetTransform()

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.

See also
Meshcat::SetTransform.
Parameters
framea non-negative integer indicating the frame at which this transform is applied.
patha "/"-delimited string indicating the path in the scene tree. See Meshcat paths for the semantics.
X_ParentPaththe relative transform from the path to its immediate parent.
Exceptions
std::exceptionif the position or quaternion properties of this path have already been set to an incorrect type.

◆ start_time()

double start_time ( ) const

Friends And Related Function Documentation

◆ Meshcat

friend class Meshcat
friend

The documentation for this class was generated from the following file: