diff --git a/pandatool/src/egg-optchar/eggOptchar.cxx b/pandatool/src/egg-optchar/eggOptchar.cxx index aeb0ff92c0..0cbf62cbbb 100644 --- a/pandatool/src/egg-optchar/eggOptchar.cxx +++ b/pandatool/src/egg-optchar/eggOptchar.cxx @@ -157,6 +157,11 @@ EggOptchar() { "joint will inherit the same net transform as its parent.", &EggOptchar::dispatch_vector_string_pair, NULL, &_new_joints); + add_option + ("rename", "joint,newjoint", 0, + "Renames the indicated joint, if present, to the given name.", + &EggOptchar::dispatch_vector_string_pair, NULL, &_rename_joints); + if (FFTCompressor::is_compression_available()) { add_option ("optimal", "", 0, @@ -262,6 +267,8 @@ run() { // morph sliders can simply be removed, while static sliders need // to be applied to the vertices and then removed. + rename_joints(); + // Quantize the vertex memberships. We call this even if // _vref_quantum is 0, because this also normalizes the vertex // memberships. @@ -1357,6 +1364,42 @@ do_flag_groups(EggGroupNode *egg_group) { } } +//////////////////////////////////////////////////////////////////// +// Function: EggOptchar::rename_joints +// Access: Private +// Description: Rename all the joints named with the -rename +// command-line option. +//////////////////////////////////////////////////////////////////// +void EggOptchar:: +rename_joints() { + for (StringPairs::iterator spi = _rename_joints.begin(); + spi != _rename_joints.end(); + ++spi) { + const StringPair &sp = (*spi); + int num_characters = _collection->get_num_characters(); + int ci; + for (ci = 0; ci < num_characters; ++ci) { + EggCharacterData *char_data = _collection->get_character(ci); + EggJointData *joint = char_data->find_joint(sp._a); + if (joint != (EggJointData *)NULL) { + nout << "Renaming joint " << sp._a << " to " << sp._b << "\n"; + joint->set_name(sp._b); + + int num_models = joint->get_num_models(); + for (int mn = 0; mn < num_models; ++mn) { + if (joint->has_model(mn)) { + EggBackPointer *model = joint->get_model(mn); + model->set_name(sp._b); + } + } + + } else { + nout << "Couldn't find joint " << sp._a << "\n"; + } + } + } +} + //////////////////////////////////////////////////////////////////// // Function: EggOptchar::rename_primitives // Access: Private diff --git a/pandatool/src/egg-optchar/eggOptchar.h b/pandatool/src/egg-optchar/eggOptchar.h index 16834b532d..8f05d3cd78 100644 --- a/pandatool/src/egg-optchar/eggOptchar.h +++ b/pandatool/src/egg-optchar/eggOptchar.h @@ -76,6 +76,7 @@ private: void quantize_vertex(EggVertex *egg_vertex); void do_flag_groups(EggGroupNode *egg_group); + void rename_joints(); void rename_primitives(EggGroupNode *egg_group, const string &name); void do_preload(); void do_defpose(); @@ -95,6 +96,7 @@ private: StringPairs _new_joints; StringPairs _reparent_joints; StringPairs _zero_channels; + StringPairs _rename_joints; vector_string _keep_components; vector_string _drop_components; diff --git a/pandatool/src/eggcharbase/eggBackPointer.cxx b/pandatool/src/eggcharbase/eggBackPointer.cxx index 0537ee0d9b..8fb0326cad 100644 --- a/pandatool/src/eggcharbase/eggBackPointer.cxx +++ b/pandatool/src/eggcharbase/eggBackPointer.cxx @@ -60,3 +60,12 @@ bool EggBackPointer:: has_vertices() const { return false; } + +//////////////////////////////////////////////////////////////////// +// Function: EggBackPointer::set_name +// Access: Public, Virtual +// Description: Applies the indicated name change to the egg file. +//////////////////////////////////////////////////////////////////// +void EggBackPointer:: +set_name(const string &name) { +} diff --git a/pandatool/src/eggcharbase/eggBackPointer.h b/pandatool/src/eggcharbase/eggBackPointer.h index 2d752a6678..7cbd02c7dc 100644 --- a/pandatool/src/eggcharbase/eggBackPointer.h +++ b/pandatool/src/eggcharbase/eggBackPointer.h @@ -41,6 +41,8 @@ public: virtual void extend_to(int num_frames); virtual bool has_vertices() const; + virtual void set_name(const string &name); + public: static TypeHandle get_class_type() { return _type_handle; diff --git a/pandatool/src/eggcharbase/eggJointNodePointer.cxx b/pandatool/src/eggcharbase/eggJointNodePointer.cxx index c74122f88a..aebc02f830 100644 --- a/pandatool/src/eggcharbase/eggJointNodePointer.cxx +++ b/pandatool/src/eggcharbase/eggJointNodePointer.cxx @@ -229,3 +229,13 @@ make_new_joint(const string &name) { _joint->add_child(new_joint); return new EggJointNodePointer(new_joint); } + +//////////////////////////////////////////////////////////////////// +// Function: EggJointNodePointer::set_name +// Access: Public, Virtual +// Description: Applies the indicated name change to the egg file. +//////////////////////////////////////////////////////////////////// +void EggJointNodePointer:: +set_name(const string &name) { + _joint->set_name(name); +} diff --git a/pandatool/src/eggcharbase/eggJointNodePointer.h b/pandatool/src/eggcharbase/eggJointNodePointer.h index 6d6d67dc7d..b3815f4696 100644 --- a/pandatool/src/eggcharbase/eggJointNodePointer.h +++ b/pandatool/src/eggcharbase/eggJointNodePointer.h @@ -45,6 +45,8 @@ public: virtual EggJointPointer *make_new_joint(const string &name); + virtual void set_name(const string &name); + private: PT(EggGroup) _joint; diff --git a/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx b/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx index 6eebc2ddad..74612f5c42 100644 --- a/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx +++ b/pandatool/src/eggcharbase/eggMatrixTablePointer.cxx @@ -314,3 +314,13 @@ make_new_joint(const string &name) { return new EggMatrixTablePointer(new_table); } + +//////////////////////////////////////////////////////////////////// +// Function: EggMatrixTablePointer::set_name +// Access: Public, Virtual +// Description: Applies the indicated name change to the egg file. +//////////////////////////////////////////////////////////////////// +void EggMatrixTablePointer:: +set_name(const string &name) { + _table->set_name(name); +} diff --git a/pandatool/src/eggcharbase/eggMatrixTablePointer.h b/pandatool/src/eggcharbase/eggMatrixTablePointer.h index 17bae5f61f..3089c6fe6f 100644 --- a/pandatool/src/eggcharbase/eggMatrixTablePointer.h +++ b/pandatool/src/eggcharbase/eggMatrixTablePointer.h @@ -51,6 +51,8 @@ public: virtual EggJointPointer *make_new_joint(const string &name); + virtual void set_name(const string &name); + private: PT(EggTable) _table; PT(EggXfmSAnim) _xform; diff --git a/pandatool/src/eggcharbase/eggScalarTablePointer.cxx b/pandatool/src/eggcharbase/eggScalarTablePointer.cxx index a3f8cf83cb..aabaafd7a6 100644 --- a/pandatool/src/eggcharbase/eggScalarTablePointer.cxx +++ b/pandatool/src/eggcharbase/eggScalarTablePointer.cxx @@ -97,3 +97,16 @@ get_frame(int n) const { nassertr(n >= 0 && n < get_num_frames(), 0.0); return _data->get_value(n); } + +//////////////////////////////////////////////////////////////////// +// Function: EggScalarTablePointer::set_name +// Access: Public, Virtual +// Description: Applies the indicated name change to the egg file. +//////////////////////////////////////////////////////////////////// +void EggScalarTablePointer:: +set_name(const string &name) { + // Actually, let's not rename the slider table (yet), because we + // haven't written the code to rename all of the morph targets. + + // _data->set_name(name); +} diff --git a/pandatool/src/eggcharbase/eggScalarTablePointer.h b/pandatool/src/eggcharbase/eggScalarTablePointer.h index 6d97249b9b..c587cbe71a 100644 --- a/pandatool/src/eggcharbase/eggScalarTablePointer.h +++ b/pandatool/src/eggcharbase/eggScalarTablePointer.h @@ -38,6 +38,8 @@ public: virtual void extend_to(int num_frames); virtual double get_frame(int n) const; + virtual void set_name(const string &name); + private: PT(EggSAnimData) _data;