egg-optchar -preload

This commit is contained in:
David Rose 2008-08-07 18:25:44 +00:00
parent 0364ebd8b7
commit 4a0bf0d87b
12 changed files with 159 additions and 0 deletions

View File

@ -24,6 +24,9 @@
#include "eggGroupNode.h" #include "eggGroupNode.h"
#include "eggPrimitive.h" #include "eggPrimitive.h"
#include "eggVertexPool.h" #include "eggVertexPool.h"
#include "eggTable.h"
#include "eggGroup.h"
#include "eggAnimPreload.h"
#include "string_utils.h" #include "string_utils.h"
#include "dcast.h" #include "dcast.h"
#include "pset.h" #include "pset.h"
@ -109,6 +112,13 @@ EggOptchar() {
"objects parented to this node will not inherit its animation.", "objects parented to this node will not inherit its animation.",
&EggOptchar::dispatch_flag_groups, NULL, &_flag_groups); &EggOptchar::dispatch_flag_groups, NULL, &_flag_groups);
add_option
("preload", "", 0,
"Add an <AnimPreload> entry for each animation to the model file(s). "
"This can be used at runtime to support asynchronous "
"loading and binding of animation channels.",
&EggOptchar::dispatch_none, &_preload);
add_option add_option
("zero", "joint[,hprxyzijkabc]", 0, ("zero", "joint[,hprxyzijkabc]", 0,
"Zeroes out the animation channels for the named joint. If " "Zeroes out the animation channels for the named joint. If "
@ -258,6 +268,11 @@ run() {
} }
} }
// Add the AnimPreload entries.
if (_preload) {
do_preload();
}
write_eggs(); write_eggs();
} }
} }
@ -1347,6 +1362,65 @@ rename_primitives(EggGroupNode *egg_group, const string &name) {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: EggOptchar::do_preload
// Access: Private
// Description: Generates the preload tables for each model.
////////////////////////////////////////////////////////////////////
void EggOptchar::
do_preload() {
// First, build up the list of AnimPreload entries, one for each
// animation file.
PT(EggGroup) anim_group = new EggGroup("preload");
int num_characters = _collection->get_num_characters();
int ci;
for (ci = 0; ci < num_characters; ++ci) {
EggCharacterData *char_data = _collection->get_character(ci);
int num_models = char_data->get_num_models();
for (int mn = 0; mn < num_models; ++mn) {
EggNode *root = char_data->get_model_root(mn);
if (root->is_of_type(EggTable::get_class_type())) {
// This model represents an animation.
EggData *data = char_data->get_egg_data(mn);
string basename = data->get_egg_filename().get_basename_wo_extension();
PT(EggAnimPreload) anim_preload = new EggAnimPreload(basename);
int mi = char_data->get_model_index(mn);
anim_preload->set_num_frames(char_data->get_num_frames(mi));
double frame_rate = char_data->get_frame_rate(mi);
if (frame_rate != 0.0) {
anim_preload->set_fps(frame_rate);
}
anim_group->add_child(anim_preload);
}
}
}
// Now go back through and copy the preload tables into each of the
// model files.
for (ci = 0; ci < num_characters; ++ci) {
EggCharacterData *char_data = _collection->get_character(ci);
int num_models = char_data->get_num_models();
for (int mn = 0; mn < num_models; ++mn) {
EggNode *root = char_data->get_model_root(mn);
if (root->is_of_type(EggGroup::get_class_type())) {
// This is a model file. Copy in the table.
EggGroup *model_root = DCAST(EggGroup, root);
EggGroup::const_iterator ci;
for (ci = anim_group->begin(); ci != anim_group->end(); ++ci) {
EggAnimPreload *anim_preload = DCAST(EggAnimPreload, *ci);
PT(EggAnimPreload) new_anim_preload = new EggAnimPreload(*anim_preload);
model_root->add_child(new_anim_preload);
}
}
}
}
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
// A call to pystub() to force libpystub.so to be linked in. // A call to pystub() to force libpystub.so to be linked in.
pystub(); pystub();

View File

@ -77,10 +77,12 @@ private:
void do_flag_groups(EggGroupNode *egg_group); void do_flag_groups(EggGroupNode *egg_group);
void rename_primitives(EggGroupNode *egg_group, const string &name); void rename_primitives(EggGroupNode *egg_group, const string &name);
void do_preload();
bool _list_hierarchy; bool _list_hierarchy;
bool _list_hierarchy_v; bool _list_hierarchy_v;
bool _list_hierarchy_p; bool _list_hierarchy_p;
bool _preload;
bool _keep_all; bool _keep_all;
class StringPair { class StringPair {

View File

@ -26,6 +26,17 @@ EggBackPointer::
EggBackPointer() { EggBackPointer() {
} }
////////////////////////////////////////////////////////////////////
// Function: EggBackPointer::get_frame_rate
// Access: Public, Virtual
// Description: Returns the stated frame rate of this particular
// joint, or 0.0 if it doesn't state.
////////////////////////////////////////////////////////////////////
double EggBackPointer::
get_frame_rate() const {
return 0.0;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggBackPointer::extend_to // Function: EggBackPointer::extend_to
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -36,6 +36,7 @@ class EggBackPointer : public TypedObject {
public: public:
EggBackPointer(); EggBackPointer();
virtual double get_frame_rate() const;
virtual int get_num_frames() const=0; virtual int get_num_frames() const=0;
virtual void extend_to(int num_frames); virtual void extend_to(int num_frames);
virtual bool has_vertices() const; virtual bool has_vertices() const;

View File

@ -133,6 +133,28 @@ get_num_frames(int model_index) const {
return max_num_frames; return max_num_frames;
} }
////////////////////////////////////////////////////////////////////
// Function: EggCharacterData::get_frame_rate
// Access: Public
// Description: Returns the stated frame rate of the specified model.
// Similar to get_num_frames().
////////////////////////////////////////////////////////////////////
double EggCharacterData::
get_frame_rate(int model_index) const {
Components::const_iterator ci;
for (ci = _components.begin(); ci != _components.end(); ++ci) {
EggComponentData *component = (*ci);
double frame_rate = component->get_frame_rate(model_index);
if (frame_rate != 0.0) {
// We have a winner. Assume all other components will be
// similar.
return frame_rate;
}
}
return 0.0;
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggCharacterData::check_num_frames // Function: EggCharacterData::check_num_frames
// Access: Public // Access: Public

View File

@ -71,6 +71,7 @@ public:
INLINE EggData *get_egg_data(int n) const; INLINE EggData *get_egg_data(int n) const;
int get_num_frames(int model_index) const; int get_num_frames(int model_index) const;
bool check_num_frames(int model_index); bool check_num_frames(int model_index);
double get_frame_rate(int model_index) const;
INLINE EggJointData *get_root_joint() const; INLINE EggJointData *get_root_joint() const;
INLINE EggJointData *find_joint(const string &name) const; INLINE EggJointData *find_joint(const string &name) const;

View File

@ -118,6 +118,21 @@ extend_to(int model_index, int num_frames) const {
back->extend_to(num_frames); back->extend_to(num_frames);
} }
////////////////////////////////////////////////////////////////////
// Function: EggComponentData::get_frame_rate
// Access: Public, Virtual
// Description: Returns the number of frames of animation for this
// particular component in the indicated model.
////////////////////////////////////////////////////////////////////
double EggComponentData::
get_frame_rate(int model_index) const {
EggBackPointer *back = get_model(model_index);
if (back == (EggBackPointer *)NULL) {
return 0.0;
}
return back->get_frame_rate();
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggComponentData::set_model // Function: EggComponentData::set_model
// Access: Public // Access: Public

View File

@ -45,6 +45,7 @@ public:
int get_num_frames(int model_index) const; int get_num_frames(int model_index) const;
void extend_to(int model_index, int num_frames) const; void extend_to(int model_index, int num_frames) const;
double get_frame_rate(int model_index) const;
virtual void add_back_pointer(int model_index, EggObject *egg_object)=0; virtual void add_back_pointer(int model_index, EggObject *egg_object)=0;
virtual void write(ostream &out, int indent_level = 0) const=0; virtual void write(ostream &out, int indent_level = 0) const=0;

View File

@ -55,6 +55,21 @@ EggMatrixTablePointer(EggObject *object) {
} }
} }
////////////////////////////////////////////////////////////////////
// Function: EggMatrixTablePointer::get_frame_rate
// Access: Public, Virtual
// Description: Returns the stated frame rate of this particular
// joint, or 0.0 if it doesn't state.
////////////////////////////////////////////////////////////////////
double EggMatrixTablePointer::
get_frame_rate() const {
if (_xform == (EggXfmSAnim *)NULL || !_xform->has_fps()) {
return 0.0;
} else {
return _xform->get_fps();
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggMatrixTablePointer::get_num_frames // Function: EggMatrixTablePointer::get_num_frames
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -34,6 +34,7 @@ class EggMatrixTablePointer : public EggJointPointer {
public: public:
EggMatrixTablePointer(EggObject *object); EggMatrixTablePointer(EggObject *object);
virtual double get_frame_rate() const;
virtual int get_num_frames() const; virtual int get_num_frames() const;
virtual void extend_to(int num_frames); virtual void extend_to(int num_frames);
virtual LMatrix4d get_frame(int n) const; virtual LMatrix4d get_frame(int n) const;

View File

@ -28,6 +28,21 @@ EggScalarTablePointer(EggObject *object) {
_data = DCAST(EggSAnimData, object); _data = DCAST(EggSAnimData, object);
} }
////////////////////////////////////////////////////////////////////
// Function: EggScalarTablePointer::get_frame_rate
// Access: Public, Virtual
// Description: Returns the stated frame rate of this particular
// joint, or 0.0 if it doesn't state.
////////////////////////////////////////////////////////////////////
double EggScalarTablePointer::
get_frame_rate() const {
if (_data == (EggSAnimData *)NULL || !_data->has_fps()) {
return 0.0;
} else {
return _data->get_fps();
}
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: EggScalarTablePointer::get_num_frames // Function: EggScalarTablePointer::get_num_frames
// Access: Public, Virtual // Access: Public, Virtual

View File

@ -33,6 +33,7 @@ class EggScalarTablePointer : public EggSliderPointer {
public: public:
EggScalarTablePointer(EggObject *object); EggScalarTablePointer(EggObject *object);
virtual double get_frame_rate() const;
virtual int get_num_frames() const; virtual int get_num_frames() const;
virtual void extend_to(int num_frames); virtual void extend_to(int num_frames);
virtual double get_frame(int n) const; virtual double get_frame(int n) const;