Animation export id bone animation + armature importer cleanup.

This commit is contained in:
2011-08-17 20:15:40 +00:00
parent e86e922f5b
commit a46f36c9b6
2 changed files with 41 additions and 27 deletions

View File

@@ -66,6 +66,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
//transform matrix export for bones are temporarily disabled here. //transform matrix export for bones are temporarily disabled here.
if ( ob->type == OB_ARMATURE ) if ( ob->type == OB_ARMATURE )
{ {
if (!ob->data) return;
bArmature *arm = (bArmature*)ob->data; bArmature *arm = (bArmature*)ob->data;
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
write_bone_animation_matrix(ob, bone); write_bone_animation_matrix(ob, bone);
@@ -363,10 +364,18 @@ void AnimationExporter::exportAnimations(Scene *sce)
bArmature *arm = (bArmature*)ob_arm->data; bArmature *arm = (bArmature*)ob_arm->data;
int flag = arm->flag; int flag = arm->flag;
std::vector<float> fra; std::vector<float> fra;
char prefix[256]; //char prefix[256];
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone->name); FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
while(fcu)
{
std::string bone_name = getObjectBoneName(ob_arm,fcu);
int val = BLI_strcasecmp((char*)bone_name.c_str(),bone->name);
if(val==0) break;
fcu = fcu->next;
}
if(!(fcu)) return;
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name); bPoseChannel *pchan = get_pose_channel(ob_arm->pose, bone->name);
if (!pchan) if (!pchan)
return; return;

View File

@@ -93,16 +93,16 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node)); EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node));
totbone++; totbone++;
bPoseChannel *pchan = get_pose_channel(ob_arm->pose, (char*)bc_get_joint_name(node)); bPoseChannel *pchan = get_pose_channel(ob_arm->pose, (char*)bc_get_joint_name(node));
if (parent) bone->parent = parent; if (parent) bone->parent = parent;
float ax[3];
float angle = 0; float angle = 0;
// get world-space // get world-space
if (parent){ if (parent){
mul_m4_m4m4(mat, obmat, parent_mat); mul_m4_m4m4(mat, obmat, parent_mat);
} }
else { else {
@@ -116,7 +116,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
// set head // set head
copy_v3_v3(bone->head, mat[3]); copy_v3_v3(bone->head, mat[3]);
// set tail, don't set it to head because 0-length bones are not allowed // set tail, don't set it to head because 0-length bones are not allowed
float vec[3] = {0.0f, 0.5f, 0.0f}; float vec[3] = {0.0f, 0.5f, 0.0f};
add_v3_v3v3(bone->tail, bone->head, vec); add_v3_v3v3(bone->tail, bone->head, vec);
@@ -127,7 +127,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
// not setting BONE_CONNECTED because this would lock child bone location with respect to parent // not setting BONE_CONNECTED because this would lock child bone location with respect to parent
// bone->flag |= BONE_CONNECTED; // bone->flag |= BONE_CONNECTED;
// XXX increase this to prevent "very" small bones? // XXX increase this to prevent "very" small bones?
const float epsilon = 0.000001f; const float epsilon = 0.000001f;
@@ -166,6 +166,10 @@ void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBo
float mat[4][4]; float mat[4][4];
// TODO rename from Node "name" attrs later
EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
totbone++;
if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) { if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) {
// get original world-space matrix // get original world-space matrix
invert_m4_m4(mat, joint_inv_bind_mat); invert_m4_m4(mat, joint_inv_bind_mat);
@@ -182,12 +186,14 @@ void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBo
mul_m4_m4m4(mat, obmat, parent_mat); mul_m4_m4m4(mat, obmat, parent_mat);
else else
copy_m4_m4(mat, obmat); copy_m4_m4(mat, obmat);
float loc[3], size[3], rot[3][3] , angle;
mat4_to_loc_rot_size( loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle );
bone->roll=angle;
} }
// TODO rename from Node "name" attrs later
EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
totbone++;
if (parent) bone->parent = parent; if (parent) bone->parent = parent;
// set head // set head
@@ -264,8 +270,8 @@ void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW:
leaf.bone = bone; leaf.bone = bone;
copy_m4_m4(leaf.mat, mat); copy_m4_m4(leaf.mat, mat);
BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name)); BLI_strncpy(leaf.name, bone->name, sizeof(leaf.name));
TagsMap::iterator etit; TagsMap::iterator etit;
ExtraTags *et = 0; ExtraTags *et = 0;
etit = uid_tags_map.find(node->getUniqueId().toAscii()); etit = uid_tags_map.find(node->getUniqueId().toAscii());
if(etit != uid_tags_map.end()) if(etit != uid_tags_map.end())
@@ -277,7 +283,7 @@ void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW:
et->setData("tip_y",&y); et->setData("tip_y",&y);
et->setData("tip_z",&z); et->setData("tip_z",&z);
float vec[3] = {x,y,z}; float vec[3] = {x,y,z};
copy_v3_v3(leaf.bone->tail, leaf.bone->head); copy_v3_v3(leaf.bone->tail, leaf.bone->head);
add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec); add_v3_v3v3(leaf.bone->tail, leaf.bone->head, vec);
leaf_bones.push_back(leaf); leaf_bones.push_back(leaf);
} }
@@ -292,7 +298,7 @@ void ArmatureImporter::fix_leaf_bones( )
// pointing up // pointing up
float vec[3] = {0.0f, 0.0f, 1.0f}; float vec[3] = {0.0f, 0.0f, 1.0f};
mul_v3_fl(vec, leaf_bone_length); mul_v3_fl(vec, leaf_bone_length);
copy_v3_v3(leaf.bone->tail, leaf.bone->head); copy_v3_v3(leaf.bone->tail, leaf.bone->head);
@@ -396,10 +402,10 @@ void ArmatureImporter::create_armature_bones( )
{ {
std::vector<COLLADAFW::Node*>::iterator ri; std::vector<COLLADAFW::Node*>::iterator ri;
//if there is an armature created for root_joint next root_joint //if there is an armature created for root_joint next root_joint
for (ri = root_joints.begin(); ri != root_joints.end(); ri++) { for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
if ( get_armature_for_joint(*ri) != NULL ) continue; if ( get_armature_for_joint(*ri) != NULL ) continue;
//add armature object for current joint //add armature object for current joint
//Object *ob_arm = add_object(scene, OB_ARMATURE); //Object *ob_arm = add_object(scene, OB_ARMATURE);
Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()]; Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()];
@@ -413,7 +419,7 @@ void ArmatureImporter::create_armature_bones( )
TODO: TODO:
check if bones have already been created for a given joint check if bones have already been created for a given joint
*/ */
leaf_bone_length = FLT_MAX; leaf_bone_length = FLT_MAX;
create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm); create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm);
//fix_leaf_bones(); //fix_leaf_bones();
@@ -545,7 +551,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB|OB_RECALC_DATA); DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB|OB_RECALC_DATA);
// set_leaf_bone_shapes(ob_arm); // set_leaf_bone_shapes(ob_arm);
// set_euler_rotmode(); // set_euler_rotmode();
} }
@@ -572,7 +578,7 @@ void ArmatureImporter::set_pose ( Object * ob_arm , COLLADAFW::Node * root_node
// get world-space // get world-space
if (parentname){ if (parentname){
mul_m4_m4m4(mat, obmat, parent_mat); mul_m4_m4m4(mat, obmat, parent_mat);
bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parentname); bPoseChannel *parchan = get_pose_channel(ob_arm->pose, parentname);
mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat); mul_m4_m4m4(pchan->pose_mat, mat , parchan->pose_mat);
@@ -581,12 +587,12 @@ void ArmatureImporter::set_pose ( Object * ob_arm , COLLADAFW::Node * root_node
else { else {
copy_m4_m4(mat, obmat); copy_m4_m4(mat, obmat);
float invObmat[4][4]; float invObmat[4][4];
invert_m4_m4(invObmat, ob_arm->obmat); invert_m4_m4(invObmat, ob_arm->obmat);
mul_m4_m4m4(pchan->pose_mat, mat, invObmat); mul_m4_m4m4(pchan->pose_mat, mat, invObmat);
} }
mat4_to_axis_angle(ax,&angle,mat); mat4_to_axis_angle(ax,&angle,mat);
pchan->bone->roll = angle; pchan->bone->roll = angle;
@@ -651,10 +657,9 @@ void ArmatureImporter::make_armatures(bContext *C)
// free memory stolen from SkinControllerData // free memory stolen from SkinControllerData
skin.free(); skin.free();
} }
//for bones without skins //for bones without skins
create_armature_bones(); create_armature_bones();
} }
#if 0 #if 0
@@ -761,7 +766,7 @@ Object *ArmatureImporter::get_armature_for_joint(COLLADAFW::Node *node)
void ArmatureImporter::set_tags_map(TagsMap & tagsMap) void ArmatureImporter::set_tags_map(TagsMap & tagsMap)
{ {
this->uid_tags_map = tagsMap; this->uid_tags_map = tagsMap;
} }
void ArmatureImporter::get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count) void ArmatureImporter::get_rna_path_for_joint(COLLADAFW::Node *node, char *joint_path, size_t count)