egg-optchar -rename

This commit is contained in:
David Rose 2009-04-29 00:19:10 +00:00
parent 1bef9dd94a
commit 74c56a9487
10 changed files with 95 additions and 0 deletions

View File

@ -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

View File

@ -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;

View File

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

View File

@ -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;

View File

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

View File

@ -45,6 +45,8 @@ public:
virtual EggJointPointer *make_new_joint(const string &name);
virtual void set_name(const string &name);
private:
PT(EggGroup) _joint;

View File

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

View File

@ -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;

View File

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

View File

@ -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;