00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "xFileAnimationSet.h"
00016 #include "xFileToEggConverter.h"
00017 #include "config_xfile.h"
00018 #include "eggGroup.h"
00019 #include "eggTable.h"
00020 #include "eggData.h"
00021 #include "eggXfmSAnim.h"
00022 #include "dcast.h"
00023
00024
00025
00026
00027
00028
00029 XFileAnimationSet::
00030 XFileAnimationSet() {
00031 _frame_rate = 0.0;
00032 }
00033
00034
00035
00036
00037
00038
00039 XFileAnimationSet::
00040 ~XFileAnimationSet() {
00041 }
00042
00043
00044
00045
00046
00047
00048
00049 bool XFileAnimationSet::
00050 create_hierarchy(XFileToEggConverter *converter) {
00051
00052
00053 EggTable *table = new EggTable(get_name());
00054 converter->get_egg_data()->add_child(table);
00055 EggTable *bundle = new EggTable(converter->_char_name);
00056 table->add_child(bundle);
00057 bundle->set_table_type(EggTable::TT_bundle);
00058
00059
00060
00061 EggTable *skeleton = new EggTable("<skeleton>");
00062 bundle->add_child(skeleton);
00063
00064
00065 mirror_table(converter, converter->get_dart_node(), skeleton);
00066
00067
00068 JointData::const_iterator ji;
00069 for (ji = _joint_data.begin(); ji != _joint_data.end(); ++ji) {
00070 const string &joint_name = (*ji).first;
00071 const FrameData &table = (*ji).second;
00072
00073 EggXfmSAnim *anim_table = get_table(joint_name);
00074 if (anim_table == (EggXfmSAnim *)NULL) {
00075 xfile_cat.warning()
00076 << "Frame " << joint_name << ", named by animation data, not defined.\n";
00077 } else {
00078
00079 FrameEntries::const_iterator fi;
00080 for (fi = table._entries.begin(); fi != table._entries.end(); ++fi) {
00081 anim_table->add_data((*fi).get_mat(table._flags));
00082 }
00083 anim_table->optimize();
00084 }
00085 }
00086
00087
00088 Tables::iterator ti;
00089 for (ti = _tables.begin(); ti != _tables.end(); ++ti) {
00090 EggXfmSAnim *anim_table = (*ti).second._table;
00091 EggGroup *joint = (*ti).second._joint;
00092 if (anim_table->empty() && joint != (EggGroup *)NULL) {
00093
00094 anim_table->add_data(joint->get_transform3d());
00095 }
00096 anim_table->optimize();
00097 if (_frame_rate != 0.0) {
00098 anim_table->set_fps(_frame_rate);
00099 }
00100 }
00101
00102 return true;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 EggXfmSAnim *XFileAnimationSet::
00112 get_table(const string &joint_name) const {
00113 Tables::const_iterator ti;
00114 ti = _tables.find(joint_name);
00115 if (ti != _tables.end()) {
00116 return (*ti).second._table;
00117 }
00118 return NULL;
00119 }
00120
00121
00122
00123
00124
00125
00126
00127 XFileAnimationSet::FrameData &XFileAnimationSet::
00128 create_frame_data(const string &joint_name) {
00129 return _joint_data[joint_name];
00130 }
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 void XFileAnimationSet::
00141 mirror_table(XFileToEggConverter *converter,
00142 EggGroup *model_node, EggTable *anim_node) {
00143 EggGroupNode::iterator gi;
00144 for (gi = model_node->begin(); gi != model_node->end(); ++gi) {
00145 EggNode *child = (*gi);
00146 if (child->is_of_type(EggGroup::get_class_type())) {
00147 EggGroup *group = DCAST(EggGroup, child);
00148 if (group->get_group_type() == EggGroup::GT_joint) {
00149
00150 EggTable *new_table = new EggTable(group->get_name());
00151 anim_node->add_child(new_table);
00152 CoordinateSystem cs =
00153 converter->get_egg_data()->get_coordinate_system();
00154 EggXfmSAnim *xform = new EggXfmSAnim("xform", cs);
00155 new_table->add_child(xform);
00156 xform->set_fps(converter->_frame_rate);
00157 TablePair &table_pair = _tables[group->get_name()];
00158 table_pair._table = xform;
00159 table_pair._joint = group;
00160
00161
00162 mirror_table(converter, group, new_table);
00163
00164 } else {
00165
00166 mirror_table(converter, group, anim_node);
00167 }
00168 }
00169 }
00170 }