pose channel -> pose matrix import ( in progress )

This commit is contained in:
2011-06-26 15:35:02 +00:00
parent 10d775df3d
commit 12e5d69af0
3 changed files with 112 additions and 16 deletions

View File

@@ -705,8 +705,8 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
return;
}
/*float irest_dae[4][4];
/*
float irest_dae[4][4];
float rest[4][4], irest[4][4];
if (is_joint) {
@@ -776,6 +776,36 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
ob->rotmode = ROT_MODE_EUL;
}
}
// if (is_joint)
//{
// float mat[4][4];
// float obmat[4][4];
// // object-space
// get_node_mat(obmat, node, NULL, NULL);
// bPoseChannel *chan = get_pose_channel(ob->pose, bone_name);
//
// bArmature * arm = (bArmature *) ob->data;
//
// Bone *cur = get_named_bone( arm , bone_name );
// if (cur->parent){
// COLLADAFW::Node * parent = armature_importer->joint_parent_map.find(node->getUniqueId());
// float[4][4] parent_mat;
// get_node_mat ( parent_mat, parent, NULL, NULL );
// mul_m4_m4m4(mat, obmat, parent_mat);
// bPoseChannel *parchan = get_pose_channel(ob->pose, cur->parent->name);
// if ( parchan && chan)
// mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
// }
// else {
// copy_m4_m4(mat, obmat);
// float invObmat[4][4];
// invert_m4_m4(invObmat, ob->obmat);
// if(pchan)
// mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
// }
//}
}
}

View File

@@ -79,7 +79,7 @@ JointData *ArmatureImporter::get_joint_data(COLLADAFW::Node *node);
}
#endif
void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *parent, int totchild,
float parent_mat[][4], bArmature *arm)
float parent_mat[][4], Object * ob_arm)
{
float mat[4][4];
float obmat[4][4];
@@ -88,19 +88,35 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
get_node_mat(obmat, node, NULL, NULL);
// get world-space
if (parent)
mul_m4_m4m4(mat, obmat, parent_mat);
else
copy_m4_m4(mat, obmat);
EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node));
totbone++;
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, (char*)bc_get_joint_name(node));
if (parent) bone->parent = parent;
// get world-space
if (parent){
mul_m4_m4m4(mat, obmat, parent_mat);
bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parent->name);
if ( parchan && pchan)
mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
}
else {
copy_m4_m4(mat, obmat);
float invObmat[4][4];
invert_m4_m4(invObmat, ob_arm->obmat);
if(pchan)
mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
}
// set head
copy_v3_v3(bone->head, mat[3]);
// set tail, don't set it to head because 0-length bones are not allowed
float vec[3] = {0.0f, 0.5f, 0.0f};
add_v3_v3v3(bone->tail, bone->head, vec);
@@ -130,7 +146,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
COLLADAFW::NodePointerArray& children = node->getChildNodes();
for (unsigned int i = 0; i < children.getCount(); i++) {
create_unskinned_bone( children[i], bone, children.getCount(), mat, arm);
create_unskinned_bone( children[i], bone, children.getCount(), mat, ob_arm);
}
// in second case it's not a leaf bone, but we handle it the same way
@@ -383,16 +399,14 @@ void ArmatureImporter::create_armature_bones( )
check if bones have already been created for a given joint
*/
leaf_bone_length = FLT_MAX;
create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, (bArmature*)ob_arm->data);
create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm);
fix_leaf_bones();
// exit armature edit mode
// set_pose(ob_arm , *ri, NULL, NULL );
//if (joint_parent_map.find((*ri)->getUniqueId()) != joint_parent_map.end() && ob_arm->parent!=NULL)
// ob_arm->parent = joint_parent_map[(*ri)->getUniqueId()];
unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
ED_armature_from_edit(ob_arm);
@@ -523,6 +537,51 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
// is a child of a node (not joint), root should be true since
// this is where we build armature bones from
//void ArmatureImporter::set_pose ( Object * ob_arm , COLLADAFW::Node * root_node , EditBone *parent, float parent_mat[][4])
//{
// char * bone_name = (char *) bc_get_joint_name ( root_node);
// float mat[4][4];
// float obmat[4][4];
//
// bArmature * arm = (bArmature * ) ob_arm-> data ;
// EditBone *edbone = NULL ;
// for (edBone=arm->edbo->first; edBone; edBone=edBone->next){
// bone = get_named_bone_bonechildren (curBone, name);
// if (bone)
// return bone;
// }
//
// // object-space
// get_node_mat(obmat, root_node, NULL, NULL);
//
// //if(*edbone)
// bPoseChannel * pchan = get_pose_channel(ob_arm -> pose , bone_name);
// //else fprintf ( "",
//
// // get world-space
// if (parent){
// mul_m4_m4m4(mat, obmat, parent_mat);
// bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parent->name);
//
// mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
// }
// else {
// copy_m4_m4(mat, obmat);
// float invObmat[4][4];
// invert_m4_m4(invObmat, ob_arm->obmat);
// mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
// }
//
//
//
//
// COLLADAFW::NodePointerArray& children = root_node->getChildNodes();
// for (unsigned int i = 0; i < children.getCount(); i++) {
// set_pose(ob_arm, children[i], edbone, mat);
// }
//
//}
void ArmatureImporter::add_joint(COLLADAFW::Node *node, bool root, Object *parent, Scene *sce)
{
joint_by_uid[node->getUniqueId()] = node;
@@ -657,6 +716,7 @@ bool ArmatureImporter::write_controller(const COLLADAFW::Controller* controller)
return true;
}
COLLADAFW::UniqueId *ArmatureImporter::get_geometry_uid(const COLLADAFW::UniqueId& controller_uid)
{
if (geom_uid_by_controller_uid.find(controller_uid) == geom_uid_by_controller_uid.end())
@@ -703,3 +763,4 @@ bool ArmatureImporter::get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint)
return found;
}

View File

@@ -107,11 +107,14 @@ private:
float parent_mat[][4], bArmature *arm);
void create_unskinned_bone(COLLADAFW::Node *node, EditBone *parent, int totchild,
float parent_mat[][4], bArmature *arm);
float parent_mat[][4], Object * ob_arm);
void add_leaf_bone(float mat[][4], EditBone *bone);
void fix_leaf_bones();
// void set_pose ( Object * ob_arm , COLLADAFW::Node * root_node , EditBone *parent, float parent_mat[][4]);
#if 0
void set_leaf_bone_shapes(Object *ob_arm);
@@ -156,13 +159,15 @@ public:
bool write_controller(const COLLADAFW::Controller* controller);
COLLADAFW::UniqueId *get_geometry_uid(const COLLADAFW::UniqueId& controller_uid);
Object *get_armature_for_joint(COLLADAFW::Node *node);
void get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count);
// gives a world-space mat
bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint);
};
#endif