15 #include "animBundleMaker.h"
16 #include "config_egg2pg.h"
19 #include "eggAnimData.h"
20 #include "eggSAnimData.h"
21 #include "eggXfmAnimData.h"
22 #include "eggXfmSAnim.h"
23 #include "eggGroupNode.h"
24 #include "animBundle.h"
25 #include "animBundleNode.h"
26 #include "animChannelMatrixXfmTable.h"
27 #include "animChannelScalarTable.h"
35 AnimBundleMaker(
EggTable *root) : _root(root) {
40 _ok_num_frames =
true;
46 <<
"AnimBundle " << _root->get_name()
47 <<
" specifies contradictory frame rates.\n";
48 }
else if (_fps == 0.0f) {
50 <<
"AnimBundle " << _root->get_name()
51 <<
" does not specify a frame rate.\n";
55 if (!_ok_num_frames) {
57 <<
"AnimBundle " << _root->get_name()
58 <<
" specifies contradictory number of frames.\n";
82 EggTable::const_iterator ci;
83 for (ci = _root->begin(); ci != _root->end(); ++ci) {
84 if ((*ci)->is_of_type(EggTable::get_class_type())) {
86 build_hierarchy(child, bundle);
102 void AnimBundleMaker::
103 inspect_tree(
EggNode *egg_node) {
104 if (egg_node->
is_of_type(EggAnimData::get_class_type())) {
107 if (egg_anim->has_fps()) {
110 }
else if (_fps != egg_anim->
get_fps()) {
112 _fps = min(_fps, (PN_stdfloat)egg_anim->
get_fps());
118 if (egg_node->
is_of_type(EggXfmSAnim::get_class_type())) {
121 if (egg_anim->has_fps()) {
124 }
else if (_fps != egg_anim->
get_fps()) {
126 _fps = min(_fps, (PN_stdfloat)egg_anim->
get_fps());
132 if (egg_node->
is_of_type(EggSAnimData::get_class_type())) {
137 if (num_frames > 1) {
138 if (_num_frames == 1) {
139 _num_frames = num_frames;
140 }
else if (_num_frames != num_frames) {
142 _num_frames = min(_num_frames, num_frames);
143 _ok_num_frames =
false;
148 if (egg_node->
is_of_type(EggXfmAnimData::get_class_type())) {
153 if (num_frames > 1) {
154 if (_num_frames == 1) {
155 _num_frames = num_frames;
156 }
else if (_num_frames != num_frames) {
158 _num_frames = min(_num_frames, num_frames);
159 _ok_num_frames =
false;
164 if (egg_node->
is_of_type(EggGroupNode::get_class_type())) {
167 EggGroupNode::const_iterator ci;
168 for (ci = group->begin(); ci != group->end(); ++ci) {
181 void AnimBundleMaker::
189 EggTable::const_iterator ci;
190 for (ci = egg_table->begin(); ci != egg_table->end(); ++ci) {
191 if ((*ci)->get_name() ==
"xform") {
192 if (this_node == NULL) {
193 this_node = create_xfm_channel((*ci), egg_table->get_name(), parent);
196 <<
"Duplicate xform table under node "
197 << egg_table->get_name() <<
"\n";
204 if (this_node == NULL) {
205 this_node =
new AnimGroup(parent, egg_table->get_name());
210 for (ci = egg_table->begin(); ci != egg_table->end(); ++ci) {
211 if ((*ci)->get_name() ==
"xform") {
213 }
else if ((*ci)->is_of_type(EggSAnimData::get_class_type())) {
215 create_s_channel(egg_anim, egg_anim->get_name(), this_node);
217 }
else if ((*ci)->is_of_type(EggTable::get_class_type())) {
219 build_hierarchy(child, this_node);
232 create_s_channel(
EggSAnimData *egg_anim,
const string &name,
239 PTA_stdfloat new_data = PTA_stdfloat::empty_array(egg_anim->
get_num_rows(),
240 table->get_class_type());
242 new_data[i] = (PN_stdfloat)egg_anim->
get_value(i);
259 create_xfm_channel(
EggNode *egg_node,
const string &name,
261 if (egg_node->
is_of_type(EggXfmAnimData::get_class_type())) {
264 return create_xfm_channel(&new_anim, name, parent);
266 }
else if (egg_node->
is_of_type(EggXfmSAnim::get_class_type())) {
268 return create_xfm_channel(egg_anim, name, parent);
272 <<
"Inappropriate node named xform under node "
285 create_xfm_channel(
EggXfmSAnim *egg_anim,
const string &name,
298 EggXfmSAnim::const_iterator ci;
299 for (ci = egg_anim->begin(); ci != egg_anim->end(); ++ci) {
300 if ((*ci)->is_of_type(EggSAnimData::get_class_type())) {
303 if (child->get_name().empty()) {
305 <<
"Unnamed subtable of <Xfm$Anim_S$> " << name
308 char table_id = child->get_name()[0];
310 if (child->get_name().length() > 1 ||
313 <<
"Unexpected table name " << child->get_name()
314 <<
", child of " << name <<
"\n";
318 <<
"Duplicate table definition for " << table_id
319 <<
" under " << name <<
"\n";
325 PTA_stdfloat new_data=PTA_stdfloat::empty_array(child->
get_num_rows(),
326 table->get_class_type());
328 new_data[i] = (PN_stdfloat)child->
get_value(i);
bool has_table(char table_id) const
Returns true if the indicated subtable has been assigned.
This is the root of an AnimChannel hierarchy.
A base class for nodes in the hierarchy that are not leaf nodes.
An animation channel that issues a scalar each frame, read from a table such as might have been read ...
static bool is_valid_id(char table_id)
Returns true if the given letter is one of the nine valid table id's.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
Corresponding to an <S$Anim> entry, this stores a single column of numbers, for instance for a morph ...
void sort_descendants()
Sorts the children nodes at each level of the hierarchy into alphabetical order.
double get_fps() const
This is only valid if has_fps() returns true.
void set_table(const CPTA_stdfloat &table)
Assigns the data table.
This is the base class for AnimChannel and AnimBundle.
This corresponds to an <Xfm$Anim_S$> entry, which is a collection of up to nine <S$Anim> entries that...
A base class for EggSAnimData and EggXfmAnimData, which contain rows and columns of numbers...
Corresponding to an <Xfm$Anim> entry, this stores a two-dimensional table with up to nine columns...
void optimize_to_standard_order()
Optimizes the table by collapsing redundant sub-tables, and simultaneously ensures that the order str...
void set_table(char table_id, const CPTA_stdfloat &table)
Assigns the indicated table.
int get_num_rows() const
Returns the number of rows in the table.
A base class for things that may be directly added into the egg hierarchy.
double get_fps() const
This is only valid if has_fps() returns true.
An animation channel that issues a matrix each frame, read from a table such as might have been read ...
This is a node that contains a pointer to an AnimBundle.
int get_num_rows() const
Returns the number of rows in the table.
double get_value(int row) const
Returns the value at the indicated row.