Motive Animation System
An open source project by FPL.
 All Classes Functions Variables Typedefs Friends Pages
motive::AnimTable Class Reference

Hold animation lists for several object types. More...

#include <anim_table.h>

Detailed Description

Hold animation lists for several object types.

A list of lists of animations.

The outer list is indexed by object, the meaning of which is set by the user, but is most likely an enum for the character being animated (e.g. turtle, zombie, happy person, tall person, etc.).

The inner list is indexed by anim_idx, the meaning of which is also set by the user, but is most likely an enum for the action being animated (e.g. idle, walk forward, jump, etc.).

Duplicate animations are only loaded once. This allows different objects to use the same animations without any memory overhead.

Public Types

typedef std::vector< std::string > ListFileNames
 
typedef std::vector
< ListFileNames > 
TableFileNames
 
typedef const char * LoadFn (const char *file_name, std::string *scratch_buf)
 

Public Member Functions

bool InitFromFlatBuffers (const AnimTableFb &table_fb, LoadFn *load_fn)
 
bool InitFromFlatBuffers (const AnimListFb &list_fb, LoadFn *load_fn)
 
bool InitFromAnimFileNames (const TableFileNames &table_names, LoadFn *load_fn)
 
bool InitFromAnimFileNames (const ListFileNames &list_names, LoadFn *load_fn)
 Load the AnimTable for only one object.
 
const RigAnimQuery (int object, int anim_idx) const
 
const RigAnimQueryByName (const char *anim_name) const
 
const RigAnimDefiningAnim (int object) const
 Return animation that defines the complete rig of this object.
 
int NumObjects () const
 
int NumAnims (int object) const
 
int NumUniqueAnims () const
 

Member Typedef Documentation

typedef const char* motive::AnimTable::LoadFn(const char *file_name, std::string *scratch_buf)

Callback that loads file_name and returns a pointer to the raw data. Optionally, the function can load the file into scratch_buf, and then return scratch_buf.c_str(). If the load fails, should return nullptr.

Note: Motive does not make assumptions on file io, so the caller must provide this function.

Member Function Documentation

bool motive::AnimTable::InitFromAnimFileNames ( const TableFileNames &  table_names,
LoadFn load_fn 
)

Load the AnimTable specified in the vector of vectors. The top level vector represents the object index. The bottom level vector represents the anim_idx.

bool motive::AnimTable::InitFromFlatBuffers ( const AnimTableFb &  table_fb,
LoadFn load_fn 
)

Load the AnimTable specified in the FlatBuffer params. For each animation in the AnimTable, load_fn is called to get the to load the individual animation files, if they're not embedded in table_fb. If they are embedded then load_fn can be nullptr. table_fb can be discarded after this call.

bool motive::AnimTable::InitFromFlatBuffers ( const AnimListFb &  list_fb,
LoadFn load_fn 
)

Load the animations specified in the FlatBuffer list_fb. All of the loaded animations are for object 0.

int motive::AnimTable::NumAnims ( int  object) const
inline

Return size of the bottom-most vector. Recall that AnimTable is a vector of vectors.

int motive::AnimTable::NumObjects ( ) const
inline

Return size of the top-most vector. Recall that AnimTable is a vector of vectors.

int motive::AnimTable::NumUniqueAnims ( ) const
inline

Return the number of animations for which we've allocated memory. Internally, we avoid duplicating animations.

const RigAnim* motive::AnimTable::Query ( int  object,
int  anim_idx 
) const
inline

Get an animation by index. This is fast and is the preferred way to look up an animation.

Parameters
objectAn enum defined by the caller specifying the object type. For example, if you want separate animations lists for cats and dogs, then object=0 could be cats, and object=1 could be dogs. The enum should run consecutively from 0 to number of object types -1.
anim_idxAn enum defined by the caller specifying the index into the animation list for object. If your cat can run and sleep, then you might make run=0 and sleep=1. Enum should run consecutively from 0 to the number of animations - 1. No need for the number of animations to match between objects.
const RigAnim* motive::AnimTable::QueryByName ( const char *  anim_name) const
inline

Get an animation by name. This is slow and should be avoided when possible.


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