Represents a single character, as read and collected from several models and animation files. More...
#include "eggCharacterData.h"
Public Member Functions | |
EggCharacterData (EggCharacterCollection *collection) | |
void | add_model (int model_index, EggNode *model_root, EggData *egg_data) |
Indicates that the given model_index (with the indicated model_root) is associated with this character. More... | |
bool | check_num_frames (int model_index) |
Walks through each component and ensures that all have the same number of frames of animation (except for those that contain 0 or 1 frames, of course). More... | |
void | choose_optimal_hierarchy () |
Chooses the best possible parent joint for each of the joints in the hierarchy, based on the score computed by EggJointData::score_reparent_to(). More... | |
bool | do_reparent () |
Begins the process of restructuring the joint hierarchy according to the previous calls to reparent_to() on various joints. More... | |
size_t | estimate_db_size () const |
Returns the estimated amount of memory, in megabytes, that will be required to perform the do_reparent() operation. More... | |
EggJointData * | find_joint (const std::string &name) const |
Returns the first joint found with the indicated name, or NULL if no joint has that name. More... | |
EggSliderData * | find_slider (const std::string &name) const |
Returns the slider with the indicated name, or NULL if no slider has that name. More... | |
EggComponentData * | get_component (int n) const |
Returns the nth joint or slider in the character. More... | |
EggData * | get_egg_data (int n) const |
Returns the EggData representing the egg file that defined this particular model. More... | |
double | get_frame_rate (int model_index) const |
Returns the stated frame rate of the specified model. More... | |
EggJointData * | get_joint (int n) const |
Returns the nth joint in the character joint hierarchy. More... | |
int | get_model_index (int n) const |
Returns the model_index of the nth model associated with this character. More... | |
EggNode * | get_model_root (int n) const |
Returns the model_root of the nth model associated with this character. More... | |
int | get_num_components () const |
Returns the total number of joints and sliders in the character. More... | |
int | get_num_frames (int model_index) const |
Returns the number of frames of animation of the indicated model. More... | |
int | get_num_joints () const |
Returns the total number of joints in the character joint hierarchy. More... | |
int | get_num_models () const |
Returns the total number of models associated with this character. More... | |
int | get_num_sliders () const |
Returns the number of sliders in the character slider list. More... | |
EggJointData * | get_root_joint () const |
Returns the root joint of the character hierarchy. More... | |
EggSliderData * | get_slider (int n) const |
Returns the nth slider in the character slider list. More... | |
EggJointData * | make_new_joint (const std::string &name, EggJointData *parent) |
Creates a new joint as a child of the indicated joint and returns it. More... | |
EggSliderData * | make_slider (const std::string &name) |
Returns the slider matching the indicated name. More... | |
void | rename_char (const std::string &name) |
Renames all of the models in the character data to the indicated name. More... | |
virtual void | write (std::ostream &out, int indent_level=0) const |
Public Member Functions inherited from Namable | |
Namable (const std::string &initial_name="") | |
void | clear_name () |
Resets the Namable's name to empty. More... | |
const std::string & | get_name () const |
bool | has_name () const |
Returns true if the Namable has a nonempty name set, false if the name is empty. More... | |
void | output (std::ostream &out) const |
Outputs the Namable. More... | |
void | set_name (const std::string &name) |
Friends | |
class | EggCharacterCollection |
Additional Inherited Members | |
Static Public Member Functions inherited from Namable | |
static TypeHandle | get_class_type () |
static void | init_type () |
Public Attributes inherited from Namable | |
get_name | |
set_name | |
Represents a single character, as read and collected from several models and animation files.
This contains a hierarchy of EggJointData nodes representing the skeleton, as well as a list of EggSliderData nodes representing the morph channels for the character.
This is very similar to the Character class from Panda, in that it's capable of associating skeleton-morph animation channels with models and calculating the vertex position for each frame. To some degree, it duplicates the functionality of Character. However, it differs in one fundamental principle: it is designed to be a non-real-time operation, working directly on the Egg structures as they are, instead of first boiling the Egg data into native Panda Geom tables for real-time animation. Because of this, it is (a) double-precision instead of single precision, (b) capable of generating modified Egg files, and (c) about a hundred times slower than the Panda Character class.
The data in this structure is normally filled in by the EggCharacterCollection class.
Definition at line 52 of file eggCharacterData.h.
Indicates that the given model_index (with the indicated model_root) is associated with this character.
This is normally called by the EggCharacterCollection class as new models are discovered.
A "model" here is either a character model (or one LOD of a character model), or a character animation file: in either case, a hierarchy of joints.
Definition at line 85 of file eggCharacterData.cxx.
Referenced by EggCharacterCollection::add_egg().
bool EggCharacterData::check_num_frames | ( | int | model_index | ) |
Walks through each component and ensures that all have the same number of frames of animation (except for those that contain 0 or 1 frames, of course).
Returns true if all are valid, false if there is a discreprency (in which case the shorter component are extended).
Definition at line 144 of file eggCharacterData.cxx.
References EggComponentData::extend_to(), and EggComponentData::get_num_frames().
Referenced by EggCharacterCollection::check_errors().
void EggCharacterData::choose_optimal_hierarchy | ( | ) |
Chooses the best possible parent joint for each of the joints in the hierarchy, based on the score computed by EggJointData::score_reparent_to().
This is a fairly expensive operation that involves lots of recomputing of transforms across the hierarchy.
The joints are not actually reparented yet, but the new_parent of each joint is set. Call do_reparent() to actually perform the suggested reparenting operation.
Definition at line 294 of file eggCharacterData.cxx.
References get_root_joint(), and EggJointData::score_reparent_to().
bool EggCharacterData::do_reparent | ( | ) |
Begins the process of restructuring the joint hierarchy according to the previous calls to reparent_to() on various joints.
This will reparent the joint hierachy in all models as requested, while adjusting the transforms as appropriate so that each joint retains the same net transform across all frames that it had before the operation. Returns true on success, false on failure.
Definition at line 183 of file eggCharacterData.cxx.
size_t EggCharacterData::estimate_db_size | ( | ) | const |
Returns the estimated amount of memory, in megabytes, that will be required to perform the do_reparent() operation.
This is used mainly be EggCharacterDb to decide up front whether to store this data in-RAM or on- disk.
Definition at line 378 of file eggCharacterData.cxx.
References get_num_frames().
|
inline |
Returns the first joint found with the indicated name, or NULL if no joint has that name.
Definition at line 80 of file eggCharacterData.I.
References EggJointData::find_joint().
EggSliderData * EggCharacterData::find_slider | ( | const std::string & | name | ) | const |
Returns the slider with the indicated name, or NULL if no slider has that name.
Definition at line 341 of file eggCharacterData.cxx.
|
inline |
Returns the nth joint or slider in the character.
This can be used to walk linearly through all joints and sliders in the character when you don't care about making a distinction between the two; it returns the same objects that can also be discovered via get_slider() and get_root_joint().
Definition at line 147 of file eggCharacterData.I.
|
inline |
Returns the EggData representing the egg file that defined this particular model.
Note that one egg file might contain multiple models.
Definition at line 59 of file eggCharacterData.I.
Referenced by EggCharacterCollection::check_errors().
double EggCharacterData::get_frame_rate | ( | int | model_index | ) | const |
Returns the stated frame rate of the specified model.
Similar to get_num_frames().
Definition at line 123 of file eggCharacterData.cxx.
References EggComponentData::get_frame_rate().
|
inline |
Returns the nth joint in the character joint hierarchy.
This returns all of the joints in the hierarchy in an arbitrary ordering.
Definition at line 110 of file eggCharacterData.I.
Referenced by EggCharacterCollection::check_errors().
|
inline |
Returns the model_index of the nth model associated with this character.
This model_index may be used to ask questions about the particular model from the EggCharacterCollection object, or from the individual EggJointData and EggSliderData objects.
A "model" here is either a character model (or one LOD of a character model), or a character animation file: in either case, a hierarchy of joints.
Definition at line 37 of file eggCharacterData.I.
Referenced by EggCharacterCollection::check_errors().
|
inline |
Returns the model_root of the nth model associated with this character.
This is the node at which the character, animation bundle, or LOD officially began within its particular egg file.
Definition at line 49 of file eggCharacterData.I.
|
inline |
Returns the total number of joints and sliders in the character.
Definition at line 136 of file eggCharacterData.I.
int EggCharacterData::get_num_frames | ( | int | model_index | ) | const |
Returns the number of frames of animation of the indicated model.
This is more reliable than asking a particular joint or slider of the animation for its number of frames, since a particular joint may have only 1 frame (if it is unanimated), even though the overall animation has many frames.
Definition at line 100 of file eggCharacterData.cxx.
References EggComponentData::get_num_frames().
Referenced by estimate_db_size().
|
inline |
Returns the total number of joints in the character joint hierarchy.
Definition at line 101 of file eggCharacterData.I.
Referenced by EggCharacterCollection::check_errors().
|
inline |
Returns the total number of models associated with this character.
A "model" here is either a character model (or one LOD of a character model), or a character animation file: in either case, a hierarchy of joints.
Definition at line 22 of file eggCharacterData.I.
Referenced by EggCharacterCollection::check_errors().
|
inline |
Returns the number of sliders in the character slider list.
Definition at line 119 of file eggCharacterData.I.
|
inline |
Returns the root joint of the character hierarchy.
This root joint does not represent an actual joint in the hierarchy, but instead is a fictitious joint that is the parent of all the top joints in the hierarchy (since the hierarchy may actually contain zero or more top joints).
Definition at line 71 of file eggCharacterData.I.
Referenced by EggCharacterCollection::add_egg(), and choose_optimal_hierarchy().
|
inline |
Returns the nth slider in the character slider list.
Definition at line 127 of file eggCharacterData.I.
|
inline |
Creates a new joint as a child of the indicated joint and returns it.
The new joint will be initialized to the identity transform, so that in inherits the net transform of the indicated parent joint.
Definition at line 90 of file eggCharacterData.I.
EggSliderData * EggCharacterData::make_slider | ( | const std::string & | name | ) |
Returns the slider matching the indicated name.
If no such slider exists already, creates a new one.
Definition at line 356 of file eggCharacterData.cxx.
References EggCharacterCollection::make_slider_data().
void EggCharacterData::rename_char | ( | const std::string & | name | ) |
Renames all of the models in the character data to the indicated name.
This is the name that is used to identify unique skeleton hierarchies; if you set two different models to the same name, they will be loaded together as if they are expected to have the same skeleton hierarchy.
Definition at line 66 of file eggCharacterData.cxx.