uniquify component names, add -drop

This commit is contained in:
David Rose 2003-07-22 19:40:37 +00:00
parent 12503cef70
commit 9581603cd8
6 changed files with 69 additions and 13 deletions

View File

@ -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<string> 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";
}
}

View File

@ -89,6 +89,7 @@ private:
StringPairs _zero_channels;
vector_string _keep_components;
vector_string _drop_components;
vector_string _expose_components;
double _vref_quantum;

View File

@ -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())) {

View File

@ -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<EggCharacterData *> Characters;
Characters _characters;
Characters _characters_by_model_index;
NameUniquifier _component_names;
private:
bool scan_hierarchy(EggNode *egg_node);

View File

@ -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());
}
////////////////////////////////////////////////////////////////////

View File

@ -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<EggBackPointer *> BackPointers;
BackPointers _back_pointers;
typedef pset<string> Names;
Names _names;
EggCharacterCollection *_collection;
EggCharacterData *_char_data;