From 9581603cd87cee64addaf210c40bc721fd5cdc58 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 22 Jul 2003 19:40:37 +0000 Subject: [PATCH] uniquify component names, add -drop --- pandatool/src/egg-optchar/eggOptchar.cxx | 48 ++++++++++++++++--- pandatool/src/egg-optchar/eggOptchar.h | 1 + .../eggcharbase/eggCharacterCollection.cxx | 7 ++- .../src/eggcharbase/eggCharacterCollection.h | 2 + .../src/eggcharbase/eggComponentData.cxx | 18 +++++-- pandatool/src/eggcharbase/eggComponentData.h | 6 ++- 6 files changed, 69 insertions(+), 13 deletions(-) diff --git a/pandatool/src/egg-optchar/eggOptchar.cxx b/pandatool/src/egg-optchar/eggOptchar.cxx index 815c4f2462..1baa56101a 100644 --- a/pandatool/src/egg-optchar/eggOptchar.cxx +++ b/pandatool/src/egg-optchar/eggOptchar.cxx @@ -77,6 +77,11 @@ EggOptchar() { "not appear to be needed by the animation.", &EggOptchar::dispatch_vector_string_comma, NULL, &_keep_components); + add_option + ("drop", "joint[,joint...]", 0, + "Removes the named joints or sliders, even if they appear to be needed.", + &EggOptchar::dispatch_vector_string_comma, NULL, &_drop_components); + add_option ("expose", "joint[,joint...]", 0, "Expose the named joints by flagging them with a DCS attribute, so " @@ -295,6 +300,7 @@ void EggOptchar:: determine_removed_components() { typedef pset Names; Names keep_names; + Names drop_names; Names expose_names; Names names_used; @@ -302,6 +308,9 @@ determine_removed_components() { for (si = _keep_components.begin(); si != _keep_components.end(); ++si) { keep_names.insert(*si); } + for (si = _drop_components.begin(); si != _drop_components.end(); ++si) { + drop_names.insert(*si); + } for (si = _expose_components.begin(); si != _expose_components.end(); ++si) { keep_names.insert(*si); expose_names.insert(*si); @@ -329,6 +338,11 @@ determine_removed_components() { user_data->_flags |= EggOptcharUserData::F_expose; } + } else if (drop_names.find(name) != drop_names.end()) { + // Remove this component by user request. + names_used.insert(name); + user_data->_flags |= EggOptcharUserData::F_remove; + } else { // Remove this component if it's unanimated or empty. if ((user_data->_flags & (EggOptcharUserData::F_static | EggOptcharUserData::F_empty)) != 0) { @@ -343,13 +357,19 @@ determine_removed_components() { for (si = _keep_components.begin(); si != _keep_components.end(); ++si) { const string &name = (*si); if (names_used.find(name) == names_used.end()) { - nout << "No such joint: " << name << "\n"; + nout << "No such component: " << name << "\n"; + } + } + for (si = _drop_components.begin(); si != _drop_components.end(); ++si) { + const string &name = (*si); + if (names_used.find(name) == names_used.end()) { + nout << "No such component: " << name << "\n"; } } for (si = _expose_components.begin(); si != _expose_components.end(); ++si) { const string &name = (*si); if (names_used.find(name) == names_used.end()) { - nout << "No such joint: " << name << "\n"; + nout << "No such component: " << name << "\n"; } } } @@ -410,6 +430,7 @@ process_joints() { int num_static = 0; int num_empty = 0; int num_identity = 0; + int num_other = 0; int num_kept = 0; for (int i = 0; i < num_joints; i++) { @@ -429,6 +450,8 @@ process_joints() { num_static++; } else if ((user_data->_flags & EggOptcharUserData::F_empty) != 0) { num_empty++; + } else { + num_other++; } removed_any = true; @@ -448,10 +471,23 @@ process_joints() { nout << char_data->get_name() << ": keeping " << num_joints << " joints.\n"; } else { - nout << char_data->get_name() << ": of " << num_joints - << " joints, removing " << num_identity << " identity, " - << num_static << " unanimated, and " << num_empty - << " empty joints, leaving " << num_kept << ".\n"; + nout << setw(5) << num_joints + << " original joints in " << char_data->get_name() + << "\n"; + if (num_identity != 0) { + nout << setw(5) << num_identity << " identity joints\n"; + } + if (num_static != 0) { + nout << setw(5) << num_static << " unanimated joints\n"; + } + if (num_empty != 0) { + nout << setw(5) << num_empty << " empty joints\n"; + } + if (num_other != 0) { + nout << setw(5) << num_other << " other joints\n"; + } + nout << " ----\n" + << setw(5) << num_kept << " joints remaining\n\n"; } } diff --git a/pandatool/src/egg-optchar/eggOptchar.h b/pandatool/src/egg-optchar/eggOptchar.h index 21ab4eab0c..4381c60cbb 100644 --- a/pandatool/src/egg-optchar/eggOptchar.h +++ b/pandatool/src/egg-optchar/eggOptchar.h @@ -89,6 +89,7 @@ private: StringPairs _zero_channels; vector_string _keep_components; + vector_string _drop_components; vector_string _expose_components; double _vref_quantum; diff --git a/pandatool/src/eggcharbase/eggCharacterCollection.cxx b/pandatool/src/eggcharbase/eggCharacterCollection.cxx index fb7966c300..090c49da98 100644 --- a/pandatool/src/eggcharbase/eggCharacterCollection.cxx +++ b/pandatool/src/eggcharbase/eggCharacterCollection.cxx @@ -40,7 +40,9 @@ // Description: //////////////////////////////////////////////////////////////////// EggCharacterCollection:: -EggCharacterCollection() { +EggCharacterCollection() : + _component_names("_", "joint_") +{ _next_model_index = 0; } @@ -601,8 +603,9 @@ void EggCharacterCollection:: found_egg_match(EggCharacterData *char_data, EggJointData *joint_data, EggNode *egg_node, int egg_index, int model_index) { if (egg_node->has_name()) { - joint_data->add_name(egg_node->get_name()); + joint_data->add_name(egg_node->get_name(), _component_names); } + egg_node->set_name(joint_data->get_name()); joint_data->add_back_pointer(model_index, egg_node); if (egg_node->is_of_type(EggGroupNode::get_class_type())) { diff --git a/pandatool/src/eggcharbase/eggCharacterCollection.h b/pandatool/src/eggcharbase/eggCharacterCollection.h index 971c3fc35b..3e686e3ce2 100644 --- a/pandatool/src/eggcharbase/eggCharacterCollection.h +++ b/pandatool/src/eggcharbase/eggCharacterCollection.h @@ -26,6 +26,7 @@ #include "eggData.h" #include "eggNode.h" #include "pointerTo.h" +#include "nameUniquifier.h" class EggTable; class EggAttributes; @@ -78,6 +79,7 @@ public: typedef pvector Characters; Characters _characters; Characters _characters_by_model_index; + NameUniquifier _component_names; private: bool scan_hierarchy(EggNode *egg_node); diff --git a/pandatool/src/eggcharbase/eggComponentData.cxx b/pandatool/src/eggcharbase/eggComponentData.cxx index dd991625eb..d3a902a1cd 100644 --- a/pandatool/src/eggcharbase/eggComponentData.cxx +++ b/pandatool/src/eggcharbase/eggComponentData.cxx @@ -64,9 +64,16 @@ EggComponentData:: // that will be accepted by matched_name(). //////////////////////////////////////////////////////////////////// void EggComponentData:: -add_name(const string &name) { - if (!has_name()) { - set_name(name); +add_name(const string &name, NameUniquifier &uniquifier) { + if (_names.insert(name).second) { + // This is a new name for this component. + if (!has_name()) { + set_name(uniquifier.add_name(name)); + if (get_name() != name) { + nout << "Warning: renamed " << name << " to " << get_name() + << " to avoid naming conflict.\n"; + } + } } } @@ -79,7 +86,10 @@ add_name(const string &name) { //////////////////////////////////////////////////////////////////// bool EggComponentData:: matches_name(const string &name) const { - return false; + if (name == get_name()) { + return true; + } + return (_names.find(name) != _names.end()); } //////////////////////////////////////////////////////////////////// diff --git a/pandatool/src/eggcharbase/eggComponentData.h b/pandatool/src/eggcharbase/eggComponentData.h index 1c063f0d24..a67bd19405 100644 --- a/pandatool/src/eggcharbase/eggComponentData.h +++ b/pandatool/src/eggcharbase/eggComponentData.h @@ -23,10 +23,12 @@ #include "eggObject.h" #include "namable.h" +#include "pset.h" class EggCharacterCollection; class EggCharacterData; class EggBackPointer; +class NameUniquifier; //////////////////////////////////////////////////////////////////// // Class : EggComponentData @@ -42,7 +44,7 @@ public: EggCharacterData *char_data); virtual ~EggComponentData(); - void add_name(const string &name); + void add_name(const string &name, NameUniquifier &uniquifier); bool matches_name(const string &name) const; int get_num_frames(int model_index) const; @@ -63,6 +65,8 @@ protected: typedef pvector BackPointers; BackPointers _back_pointers; + typedef pset Names; + Names _names; EggCharacterCollection *_collection; EggCharacterData *_char_data;