mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
This version gets rid of the pseuodo joints and works much better with the existing tools.
This commit is contained in:
parent
766fb18472
commit
fea7746011
@ -42,13 +42,14 @@ SoftNodeDesc(SoftNodeDesc *parent, const string &name) :
|
||||
_parent->_children.push_back(this);
|
||||
}
|
||||
|
||||
// set the _parentJoint to Null
|
||||
_parentJoint = NULL;
|
||||
|
||||
fullname = NULL;
|
||||
|
||||
numTexLoc = 0;
|
||||
numTexGlb = 0;
|
||||
|
||||
no_pseudo = FALSE;
|
||||
|
||||
uScale = NULL;
|
||||
vScale = NULL;
|
||||
uOffset = NULL;
|
||||
@ -146,7 +147,8 @@ get_model() const {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool SoftNodeDesc::
|
||||
is_joint() const {
|
||||
return _joint_type == JT_joint || _joint_type == JT_pseudo_joint;
|
||||
// return _joint_type == JT_joint || _joint_type == JT_pseudo_joint;
|
||||
return _joint_type == JT_joint;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -308,6 +310,47 @@ is_partial(char *search_prefix) {
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Function: SoftNodeTree::set_parentJoint
|
||||
// Access: Public
|
||||
// Description: Go through the ancestors and figure out who is the
|
||||
// immediate _parentJoint of this node
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
void SoftNodeDesc::
|
||||
set_parentJoint(SAA_Scene *scene, SoftNodeDesc *lastJoint) {
|
||||
if (is_junk())
|
||||
return;
|
||||
//set its parent joint to the lastJoint
|
||||
_parentJoint = lastJoint;
|
||||
softegg_cat.spam() << get_name() << ": parent joint set to :" << lastJoint;
|
||||
if (lastJoint)
|
||||
softegg_cat.spam() << "(" << lastJoint->get_name() << ")";
|
||||
softegg_cat.spam() << endl;
|
||||
|
||||
// is this node a joint?
|
||||
SAA_Boolean isSkeleton = false;
|
||||
if (has_model())
|
||||
SAA_modelIsSkeleton( scene, get_model(), &isSkeleton );
|
||||
|
||||
// if name has "joint" in it
|
||||
const char *name = get_name().c_str();
|
||||
if (isSkeleton || strstr(name, "joint") != NULL) {
|
||||
lastJoint = this;
|
||||
}
|
||||
if ( _parentJoint && strstr( _parentJoint->get_name().c_str(), "scale" ) != NULL ) {
|
||||
_parentJoint = lastJoint = NULL;
|
||||
//lastJoint = stec._tree._root;
|
||||
softegg_cat.spam() << "scale joint flag set!\n";
|
||||
}
|
||||
|
||||
// look in the children
|
||||
Children::const_iterator ci;
|
||||
for (ci = _children.begin(); ci != _children.end(); ++ci) {
|
||||
SoftNodeDesc *child = (*ci);
|
||||
child->set_parentJoint(scene, lastJoint);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: SoftNodeDesc::check_pseudo_joints
|
||||
// Access: Private
|
||||
@ -318,7 +361,7 @@ is_partial(char *search_prefix) {
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void SoftNodeDesc::
|
||||
check_pseudo_joints(bool joint_above) {
|
||||
if (_joint_type == JT_joint_parent && joint_above && !no_pseudo) {
|
||||
if (_joint_type == JT_joint_parent && joint_above) {
|
||||
// This is one such node: it is the parent of a joint
|
||||
// (JT_joint_parent is set), and it is the child of a joint
|
||||
// (joint_above is set).
|
||||
@ -353,7 +396,7 @@ check_pseudo_joints(bool joint_above) {
|
||||
bool all_joints = true;
|
||||
for (ci = _children.begin(); ci != _children.end(); ++ci) {
|
||||
SoftNodeDesc *child = (*ci);
|
||||
if (child->_joint_type == JT_joint_parent && !no_pseudo) {
|
||||
if (child->_joint_type == JT_joint_parent) {
|
||||
child->_joint_type = JT_pseudo_joint;
|
||||
softegg_cat.debug() << "pseudo " << child->get_name() << " case2 by parent " << get_name() << "\n";
|
||||
} else if (child->_joint_type == JT_none || child->_joint_type == JT_junk) {
|
||||
@ -363,7 +406,7 @@ check_pseudo_joints(bool joint_above) {
|
||||
|
||||
if (all_joints || any_joints) {
|
||||
// Finally, if all children or at least one is a joint, then we are too.
|
||||
if (_joint_type == JT_joint_parent && !no_pseudo) {
|
||||
if (_joint_type == JT_joint_parent) {
|
||||
_joint_type = JT_pseudo_joint;
|
||||
softegg_cat.debug() << "pseudo " << get_name() << " case3\n";
|
||||
}
|
||||
@ -386,13 +429,13 @@ get_transform(SAA_Scene *scene, EggGroup *egg_group, bool global) {
|
||||
int scale_joint = 0;
|
||||
|
||||
/*
|
||||
if ( strstr( _parent->get_name().c_str(), "scale" ) != NULL ) {
|
||||
if ( _parentJoint && strstr( _parentJoint->get_name().c_str(), "scale" ) != NULL ) {
|
||||
scale_joint = 1;
|
||||
softegg_cat.spam() << "scale joint flag set!\n";
|
||||
}
|
||||
*/
|
||||
|
||||
if (!global && _parent->is_joint() && !stec.flatten && !scale_joint) {
|
||||
if (!global && _parentJoint && !stec.flatten && !scale_joint) {
|
||||
|
||||
SAA_modelGetMatrix( scene, get_model(), SAA_COORDSYS_LOCAL, matrix );
|
||||
softegg_cat.debug() << get_name() << " using local matrix :parent ";
|
||||
@ -404,7 +447,11 @@ get_transform(SAA_Scene *scene, EggGroup *egg_group, bool global) {
|
||||
|
||||
}
|
||||
|
||||
softegg_cat.debug() << _parent->get_name() << endl;
|
||||
if (_parentJoint)
|
||||
softegg_cat.debug() << _parentJoint->get_name() << endl;
|
||||
else
|
||||
softegg_cat.debug() << _parentJoint << endl;
|
||||
|
||||
|
||||
softegg_cat.spam() << "model matrix = " << matrix[0][0] << " " << matrix[0][1] << " " << matrix[0][2] << " " << matrix[0][3] << "\n";
|
||||
softegg_cat.spam() << "model matrix = " << matrix[1][0] << " " << matrix[1][1] << " " << matrix[1][2] << " " << matrix[1][3] << "\n";
|
||||
@ -449,7 +496,7 @@ get_joint_transform(SAA_Scene *scene, EggGroup *egg_group, EggXfmSAnim *anim, b
|
||||
int scale_joint = 0;
|
||||
|
||||
/*
|
||||
if ( strstr( _parent->get_name().c_str(), "scale" ) != NULL ) {
|
||||
if ( _parentJoint && strstr( _parentJoint->get_name().c_str(), "scale" ) != NULL ) {
|
||||
scale_joint = 1;
|
||||
softegg_cat.spam() << "scale joint flag set!\n";
|
||||
}
|
||||
@ -457,7 +504,7 @@ get_joint_transform(SAA_Scene *scene, EggGroup *egg_group, EggXfmSAnim *anim, b
|
||||
|
||||
softegg_cat.spam() << "\n\nanimating child " << name << endl;
|
||||
|
||||
if (_parent->is_joint() && !stec.flatten && !scale_joint ) {
|
||||
if (_parentJoint && !stec.flatten && !scale_joint ) {
|
||||
softegg_cat.debug() << "using local matrix\n";
|
||||
|
||||
//get SAA orientation
|
||||
|
@ -64,6 +64,7 @@ public:
|
||||
bool is_partial(char *search_prefix);
|
||||
|
||||
SoftNodeDesc *_parent;
|
||||
SoftNodeDesc *_parentJoint; // keep track of who is your parent joint
|
||||
typedef pvector< PT(SoftNodeDesc) > Children;
|
||||
Children _children;
|
||||
|
||||
@ -74,6 +75,8 @@ private:
|
||||
void check_junk(bool parent_junk);
|
||||
void check_pseudo_joints(bool joint_above);
|
||||
|
||||
void set_parentJoint(SAA_Scene *scene, SoftNodeDesc *lastJoint);
|
||||
|
||||
SAA_ModelType type;
|
||||
|
||||
SAA_Elem *_model;
|
||||
@ -100,8 +103,6 @@ public:
|
||||
|
||||
const char *fullname;
|
||||
|
||||
bool no_pseudo;
|
||||
|
||||
int numTri;
|
||||
// int numShapes;
|
||||
int numTexLoc;
|
||||
|
@ -211,6 +211,9 @@ build_complete_hierarchy(SAA_Scene &scene, SAA_Database &database) {
|
||||
// check the nodes that are pseudo joints
|
||||
_root->check_pseudo_joints(false);
|
||||
|
||||
// find _parentJoint for each node
|
||||
_root->set_parentJoint(&scene, NULL);
|
||||
|
||||
return all_ok;
|
||||
}
|
||||
#if 0
|
||||
@ -360,13 +363,13 @@ get_egg_group(SoftNodeDesc *node_desc) {
|
||||
egg_group->set_group_type(EggGroup::GT_joint);
|
||||
}
|
||||
|
||||
if (!node_desc->_parent || node_desc->_parent == _root) {
|
||||
if (!node_desc->_parentJoint || node_desc->_parentJoint == _root) {
|
||||
// The parent is the root.
|
||||
softegg_cat.spam() << "came hereeeee\n";
|
||||
_egg_root->add_child(egg_group);
|
||||
} else {
|
||||
// The parent is another node.
|
||||
EggGroup *parent_egg_group = get_egg_group(node_desc->_parent);
|
||||
EggGroup *parent_egg_group = get_egg_group(node_desc->_parentJoint);
|
||||
parent_egg_group->add_child(egg_group);
|
||||
}
|
||||
|
||||
@ -406,13 +409,13 @@ get_egg_table(SoftNodeDesc *node_desc) {
|
||||
node_desc->_anim->set_fps(_fps);
|
||||
egg_table->add_child(node_desc->_anim);
|
||||
|
||||
if (!node_desc->_parent || node_desc->_parent == _root) {
|
||||
if (!node_desc->_parentJoint || node_desc->_parentJoint == _root) {
|
||||
// if (!node_desc->_parent->is_joint()) {
|
||||
// The parent is not a joint; put it at the top.
|
||||
_skeleton_node->add_child(egg_table);
|
||||
} else {
|
||||
// The parent is another joint.
|
||||
EggTable *parent_egg_table = get_egg_table(node_desc->_parent);
|
||||
EggTable *parent_egg_table = get_egg_table(node_desc->_parentJoint);
|
||||
parent_egg_table->add_child(egg_table);
|
||||
}
|
||||
|
||||
@ -441,7 +444,7 @@ get_egg_anim(SoftNodeDesc *node_desc) {
|
||||
// Description: Sets joint information for MNILL node
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void SoftNodeTree::
|
||||
handle_null(SAA_Scene *scene, SoftNodeDesc *node_desc, char *node_name) {
|
||||
handle_null(SAA_Scene *scene, SoftNodeDesc *node_desc, const char *node_name) {
|
||||
const char *name = node_name;
|
||||
SAA_AlgorithmType algo;
|
||||
SAA_Elem *model = node_desc->get_model();
|
||||
@ -473,6 +476,7 @@ handle_null(SAA_Scene *scene, SoftNodeDesc *node_desc, char *node_name) {
|
||||
// MakeJoint( &scene, lastJoint, lastAnim, model, name );
|
||||
node_desc->set_joint();
|
||||
softegg_cat.spam() << " animating Standard null!!!\n";
|
||||
softegg_cat.spam() << "isSkeleton: " << isSkeleton << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -505,23 +509,25 @@ build_node(SAA_Scene *scene, SAA_Elem *model) {
|
||||
node_name = name;
|
||||
|
||||
SoftNodeDesc *node_desc = r_build_node(NULL, node_name);
|
||||
if (stec.notPseudoName && !strcmp(name, stec.notPseudoName)) {
|
||||
node_desc->no_pseudo = true;
|
||||
softegg_cat.debug() << "set no_pseudo" << endl;
|
||||
}
|
||||
|
||||
node_desc->fullname = fullname;
|
||||
node_desc->set_model(model);
|
||||
SAA_modelIsSkeleton( scene, model, &isSkeleton );
|
||||
if (isSkeleton || (strstr(node_desc->get_name().c_str(), "joint") != NULL))
|
||||
node_desc->set_joint();
|
||||
|
||||
// find out what type of node we're dealing with
|
||||
SAA_modelGetType( scene, node_desc->get_model(), &type );
|
||||
|
||||
if (type == SAA_MJNT || isSkeleton || (strstr(node_desc->get_name().c_str(), "joint") != NULL))
|
||||
node_desc->set_joint();
|
||||
|
||||
// treat the MNILL differently, because it needs to detect and set some joints
|
||||
if (type == SAA_MNILL)
|
||||
handle_null(scene, node_desc, name);
|
||||
|
||||
if (node_desc->is_joint())
|
||||
softegg_cat.spam() << "type: " << type << " isSkeleton: " << isSkeleton << endl;
|
||||
|
||||
// get to the children
|
||||
SAA_modelGetNbChildren( scene, model, &numChildren );
|
||||
softegg_cat.spam() << " Model " << node_name << " children: " << numChildren << endl;
|
||||
|
||||
@ -541,17 +547,23 @@ build_node(SAA_Scene *scene, SAA_Elem *model) {
|
||||
softegg_cat.spam() << " building child " << thisChild << "...";
|
||||
|
||||
SoftNodeDesc *node_child = r_build_node(node_desc, node_name);
|
||||
if (stec.notPseudoName && !strcmp(node_name.c_str(), stec.notPseudoName)) {
|
||||
node_child->no_pseudo = true;
|
||||
softegg_cat.debug() << "set no_pseudo" << endl;
|
||||
}
|
||||
|
||||
node_child->fullname = fullname;
|
||||
node_child->set_model(&children[thisChild]);
|
||||
|
||||
// if (strstr(name, "joint") != NULL)
|
||||
SAA_modelIsSkeleton( scene, &children[thisChild], &isSkeleton );
|
||||
if (isSkeleton || (strstr(node_child->get_name().c_str(), "joint") != NULL))
|
||||
|
||||
// find out what type of node we're dealing with
|
||||
SAA_modelGetType( scene, node_child->get_model(), &type );
|
||||
|
||||
if (type == SAA_MJNT || isSkeleton || (strstr(node_child->get_name().c_str(), "joint") != NULL))
|
||||
node_child->set_joint();
|
||||
|
||||
// treat the MNILL differently, because it needs to detect and set some joints
|
||||
if (type == SAA_MNILL)
|
||||
handle_null(scene, node_child, node_name.c_str());
|
||||
|
||||
if (node_child->is_joint())
|
||||
softegg_cat.spam() << "type: " << type << " isSkeleton: " << isSkeleton << endl;
|
||||
}
|
||||
}
|
||||
return node_desc;
|
||||
|
@ -41,7 +41,7 @@ public:
|
||||
SoftNodeTree();
|
||||
SoftNodeDesc *build_node(SAA_Scene *scene, SAA_Elem *model);
|
||||
bool build_complete_hierarchy(SAA_Scene &scene, SAA_Database &database);
|
||||
void handle_null(SAA_Scene *scene, SoftNodeDesc *node_desc, char *node_name);
|
||||
void handle_null(SAA_Scene *scene, SoftNodeDesc *node_desc, const char *node_name);
|
||||
// bool build_selected_hierarchy(SAA_Scene *s, SAA_Database *d, char *scene_name);
|
||||
|
||||
int get_num_nodes() const;
|
||||
|
@ -202,8 +202,7 @@ ShowOpts()
|
||||
" -c - Cancel morph conversion.\n"
|
||||
" -C - Cancel duv conversion.\n"
|
||||
" -D - Don't make the output model a character.\n"
|
||||
" -o <prefix>- Convert only models with given prefix.\n"
|
||||
" -E <name> - Don't make the specified node a pseudo node.\n";
|
||||
" -o <prefix>- Convert only models with given prefix.\n";
|
||||
|
||||
// EggBase::ShowOpts();
|
||||
}
|
||||
@ -221,7 +220,6 @@ bool SoftToEggConverter::
|
||||
DoGetopts(int &argc, char **&argv) {
|
||||
bool okflag = true;
|
||||
int i = 0;
|
||||
notPseudoName = NULL;
|
||||
softegg_cat.info() << "argc " << argc << "\n";
|
||||
if (argc <2) {
|
||||
Usage();
|
||||
@ -447,14 +445,6 @@ HandleGetopts(int &idx, int argc, char **argv)
|
||||
++idx;
|
||||
break;
|
||||
|
||||
case 'E': // Don't make this node pseudo.
|
||||
if ( strcmp( argv[idx+1], "" ) ) {
|
||||
notPseudoName = argv[idx+1];
|
||||
softegg_cat.info() << "Don't make the following node pseudo: " << notPseudoName << endl;
|
||||
}
|
||||
++idx;
|
||||
break;
|
||||
|
||||
case 'f': /// Set animation frame rate.
|
||||
if ( strcmp( argv[idx+1], "" ) ) {
|
||||
anim_rate = atoi(argv[idx+1]);
|
||||
@ -842,6 +832,11 @@ convert_char_chan() {
|
||||
|
||||
for (i = 0; i < num_nodes; i++) {
|
||||
SoftNodeDesc *node_desc = _tree.get_node(i);
|
||||
|
||||
if (node_desc->is_partial(search_prefix)) {
|
||||
softegg_cat.debug() << endl;
|
||||
continue;
|
||||
}
|
||||
if (node_desc->is_joint()) {
|
||||
softegg_cat.spam() << "-----joint " << node_desc->get_name() << "\n";
|
||||
EggXfmSAnim *anim = _tree.get_egg_anim(node_desc);
|
||||
@ -858,6 +853,9 @@ convert_char_chan() {
|
||||
// easier to read.
|
||||
for (i = 0; i < num_nodes; i++) {
|
||||
SoftNodeDesc *node_desc = _tree.get_node(i);
|
||||
if (node_desc->is_partial(search_prefix))
|
||||
continue;
|
||||
|
||||
if (node_desc->is_joint()) {
|
||||
_tree.get_egg_anim(node_desc)->optimize();
|
||||
}
|
||||
|
@ -100,14 +100,14 @@ private:
|
||||
string _program_name;
|
||||
bool _from_selection;
|
||||
|
||||
SoftNodeTree _tree;
|
||||
|
||||
SI_Error result;
|
||||
SAA_Elem model;
|
||||
SAA_Database database;
|
||||
|
||||
public:
|
||||
|
||||
SoftNodeTree _tree;
|
||||
|
||||
SAA_Scene scene;
|
||||
|
||||
char *_getopts;
|
||||
@ -128,7 +128,6 @@ public:
|
||||
char *tex_path;
|
||||
char *tex_filename;
|
||||
char *search_prefix;
|
||||
char *notPseudoName;
|
||||
|
||||
int nurbs_step;
|
||||
int anim_start;
|
||||
|
Loading…
x
Reference in New Issue
Block a user