mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 09:23:03 -04:00
uniquify component names, add -drop
This commit is contained in:
parent
12503cef70
commit
9581603cd8
@ -77,6 +77,11 @@ EggOptchar() {
|
|||||||
"not appear to be needed by the animation.",
|
"not appear to be needed by the animation.",
|
||||||
&EggOptchar::dispatch_vector_string_comma, NULL, &_keep_components);
|
&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
|
add_option
|
||||||
("expose", "joint[,joint...]", 0,
|
("expose", "joint[,joint...]", 0,
|
||||||
"Expose the named joints by flagging them with a DCS attribute, so "
|
"Expose the named joints by flagging them with a DCS attribute, so "
|
||||||
@ -295,6 +300,7 @@ void EggOptchar::
|
|||||||
determine_removed_components() {
|
determine_removed_components() {
|
||||||
typedef pset<string> Names;
|
typedef pset<string> Names;
|
||||||
Names keep_names;
|
Names keep_names;
|
||||||
|
Names drop_names;
|
||||||
Names expose_names;
|
Names expose_names;
|
||||||
Names names_used;
|
Names names_used;
|
||||||
|
|
||||||
@ -302,6 +308,9 @@ determine_removed_components() {
|
|||||||
for (si = _keep_components.begin(); si != _keep_components.end(); ++si) {
|
for (si = _keep_components.begin(); si != _keep_components.end(); ++si) {
|
||||||
keep_names.insert(*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) {
|
for (si = _expose_components.begin(); si != _expose_components.end(); ++si) {
|
||||||
keep_names.insert(*si);
|
keep_names.insert(*si);
|
||||||
expose_names.insert(*si);
|
expose_names.insert(*si);
|
||||||
@ -329,6 +338,11 @@ determine_removed_components() {
|
|||||||
user_data->_flags |= EggOptcharUserData::F_expose;
|
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 {
|
} else {
|
||||||
// Remove this component if it's unanimated or empty.
|
// Remove this component if it's unanimated or empty.
|
||||||
if ((user_data->_flags & (EggOptcharUserData::F_static | EggOptcharUserData::F_empty)) != 0) {
|
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) {
|
for (si = _keep_components.begin(); si != _keep_components.end(); ++si) {
|
||||||
const string &name = (*si);
|
const string &name = (*si);
|
||||||
if (names_used.find(name) == names_used.end()) {
|
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) {
|
for (si = _expose_components.begin(); si != _expose_components.end(); ++si) {
|
||||||
const string &name = (*si);
|
const string &name = (*si);
|
||||||
if (names_used.find(name) == names_used.end()) {
|
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_static = 0;
|
||||||
int num_empty = 0;
|
int num_empty = 0;
|
||||||
int num_identity = 0;
|
int num_identity = 0;
|
||||||
|
int num_other = 0;
|
||||||
int num_kept = 0;
|
int num_kept = 0;
|
||||||
|
|
||||||
for (int i = 0; i < num_joints; i++) {
|
for (int i = 0; i < num_joints; i++) {
|
||||||
@ -429,6 +450,8 @@ process_joints() {
|
|||||||
num_static++;
|
num_static++;
|
||||||
} else if ((user_data->_flags & EggOptcharUserData::F_empty) != 0) {
|
} else if ((user_data->_flags & EggOptcharUserData::F_empty) != 0) {
|
||||||
num_empty++;
|
num_empty++;
|
||||||
|
} else {
|
||||||
|
num_other++;
|
||||||
}
|
}
|
||||||
removed_any = true;
|
removed_any = true;
|
||||||
|
|
||||||
@ -448,10 +471,23 @@ process_joints() {
|
|||||||
nout << char_data->get_name() << ": keeping " << num_joints
|
nout << char_data->get_name() << ": keeping " << num_joints
|
||||||
<< " joints.\n";
|
<< " joints.\n";
|
||||||
} else {
|
} else {
|
||||||
nout << char_data->get_name() << ": of " << num_joints
|
nout << setw(5) << num_joints
|
||||||
<< " joints, removing " << num_identity << " identity, "
|
<< " original joints in " << char_data->get_name()
|
||||||
<< num_static << " unanimated, and " << num_empty
|
<< "\n";
|
||||||
<< " empty joints, leaving " << num_kept << ".\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";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ private:
|
|||||||
StringPairs _zero_channels;
|
StringPairs _zero_channels;
|
||||||
|
|
||||||
vector_string _keep_components;
|
vector_string _keep_components;
|
||||||
|
vector_string _drop_components;
|
||||||
vector_string _expose_components;
|
vector_string _expose_components;
|
||||||
|
|
||||||
double _vref_quantum;
|
double _vref_quantum;
|
||||||
|
@ -40,7 +40,9 @@
|
|||||||
// Description:
|
// Description:
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
EggCharacterCollection::
|
EggCharacterCollection::
|
||||||
EggCharacterCollection() {
|
EggCharacterCollection() :
|
||||||
|
_component_names("_", "joint_")
|
||||||
|
{
|
||||||
_next_model_index = 0;
|
_next_model_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,8 +603,9 @@ void EggCharacterCollection::
|
|||||||
found_egg_match(EggCharacterData *char_data, EggJointData *joint_data,
|
found_egg_match(EggCharacterData *char_data, EggJointData *joint_data,
|
||||||
EggNode *egg_node, int egg_index, int model_index) {
|
EggNode *egg_node, int egg_index, int model_index) {
|
||||||
if (egg_node->has_name()) {
|
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);
|
joint_data->add_back_pointer(model_index, egg_node);
|
||||||
|
|
||||||
if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
if (egg_node->is_of_type(EggGroupNode::get_class_type())) {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "eggData.h"
|
#include "eggData.h"
|
||||||
#include "eggNode.h"
|
#include "eggNode.h"
|
||||||
#include "pointerTo.h"
|
#include "pointerTo.h"
|
||||||
|
#include "nameUniquifier.h"
|
||||||
|
|
||||||
class EggTable;
|
class EggTable;
|
||||||
class EggAttributes;
|
class EggAttributes;
|
||||||
@ -78,6 +79,7 @@ public:
|
|||||||
typedef pvector<EggCharacterData *> Characters;
|
typedef pvector<EggCharacterData *> Characters;
|
||||||
Characters _characters;
|
Characters _characters;
|
||||||
Characters _characters_by_model_index;
|
Characters _characters_by_model_index;
|
||||||
|
NameUniquifier _component_names;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool scan_hierarchy(EggNode *egg_node);
|
bool scan_hierarchy(EggNode *egg_node);
|
||||||
|
@ -64,9 +64,16 @@ EggComponentData::
|
|||||||
// that will be accepted by matched_name().
|
// that will be accepted by matched_name().
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void EggComponentData::
|
void EggComponentData::
|
||||||
add_name(const string &name) {
|
add_name(const string &name, NameUniquifier &uniquifier) {
|
||||||
if (!has_name()) {
|
if (_names.insert(name).second) {
|
||||||
set_name(name);
|
// 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::
|
bool EggComponentData::
|
||||||
matches_name(const string &name) const {
|
matches_name(const string &name) const {
|
||||||
return false;
|
if (name == get_name()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return (_names.find(name) != _names.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -23,10 +23,12 @@
|
|||||||
|
|
||||||
#include "eggObject.h"
|
#include "eggObject.h"
|
||||||
#include "namable.h"
|
#include "namable.h"
|
||||||
|
#include "pset.h"
|
||||||
|
|
||||||
class EggCharacterCollection;
|
class EggCharacterCollection;
|
||||||
class EggCharacterData;
|
class EggCharacterData;
|
||||||
class EggBackPointer;
|
class EggBackPointer;
|
||||||
|
class NameUniquifier;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Class : EggComponentData
|
// Class : EggComponentData
|
||||||
@ -42,7 +44,7 @@ public:
|
|||||||
EggCharacterData *char_data);
|
EggCharacterData *char_data);
|
||||||
virtual ~EggComponentData();
|
virtual ~EggComponentData();
|
||||||
|
|
||||||
void add_name(const string &name);
|
void add_name(const string &name, NameUniquifier &uniquifier);
|
||||||
bool matches_name(const string &name) const;
|
bool matches_name(const string &name) const;
|
||||||
|
|
||||||
int get_num_frames(int model_index) const;
|
int get_num_frames(int model_index) const;
|
||||||
@ -63,6 +65,8 @@ protected:
|
|||||||
typedef pvector<EggBackPointer *> BackPointers;
|
typedef pvector<EggBackPointer *> BackPointers;
|
||||||
BackPointers _back_pointers;
|
BackPointers _back_pointers;
|
||||||
|
|
||||||
|
typedef pset<string> Names;
|
||||||
|
Names _names;
|
||||||
|
|
||||||
EggCharacterCollection *_collection;
|
EggCharacterCollection *_collection;
|
||||||
EggCharacterData *_char_data;
|
EggCharacterData *_char_data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user