[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48487] branches/soc-2012-bratwurst/source /blender/collada: Export Armature fix.
Sukhitha Jayathilake
pr.jayathilake at gmail.com
Mon Jul 2 11:34:30 CEST 2012
Revision: 48487
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48487
Author: phabtar
Date: 2012-07-02 09:34:13 +0000 (Mon, 02 Jul 2012)
Log Message:
-----------
Export Armature fix.
Instead of exporting pose_mat, exporting arm_mat now.
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp
branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp 2012-07-02 09:07:34 UTC (rev 48486)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp 2012-07-02 09:34:13 UTC (rev 48487)
@@ -187,12 +187,12 @@
node.setNodeName(node_name);
node.setNodeSid(node_sid);
-//#if 1
+#if 0
if (bone->childbase.first == NULL || BLI_countlist(&(bone->childbase)) >= 2) {
add_blender_leaf_bone( bone, ob_arm , node );
}
else{
-//#endif
+#endif
node.start();
add_bone_transform(ob_arm, bone, node);
@@ -240,12 +240,11 @@
}
node.end();
}
- }
- else {
- for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
- add_bone_node(child, ob_arm, sce, se, child_objects);
+ else {
+ for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
+ add_bone_node(child, ob_arm, sce, se, child_objects);
+ }
}
- }
}
//#if 1
@@ -275,22 +274,26 @@
if (bone->parent) {
// get bone-space matrix from parent pose
- bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name);
-
+ /*bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name);
float invpar[4][4];
invert_m4_m4(invpar, parchan->pose_mat);
- mult_m4_m4m4(mat, invpar, pchan->pose_mat);
+ mult_m4_m4m4(mat, invpar, pchan->pose_mat);*/
+
+ float invpar[4][4];
+ invert_m4_m4(invpar, bone->parent->arm_mat);
+ mult_m4_m4m4(mat, invpar, bone->arm_mat);
+
}
else {
//pose mat is object space
- copy_m4_m4(mat, pchan->pose_mat);
- // Why? Joint's localspace is still it's parent node
- //get world-space from armature-space
- //mult_m4_m4m4(mat, ob_arm->obmat, pchan->pose_mat);
+ //copy_m4_m4(mat, pchan->pose_mat);
+
+ //New change: export bone->arm_mat
+ copy_m4_m4(mat, bone->arm_mat);
}
// SECOND_LIFE_COMPATIBILITY
-// if (export_settings->second_life) {
+ if (export_settings->second_life) {
// Remove rotations vs armature from transform
// parent_rest_rot * mat * irest_rot
float temp[4][4];
@@ -306,7 +309,7 @@
mult_m4_m4m4(mat, temp, mat);
}
-// }
+ }
TransformWriter::add_node_transform(node, mat, NULL);
}
Modified: branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp 2012-07-02 09:07:34 UTC (rev 48486)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp 2012-07-02 09:34:13 UTC (rev 48487)
@@ -96,9 +96,6 @@
if (parent) bone->parent = parent;
- float angle = 0;
-
- // get world-space
if (parent) {
mult_m4_m4m4(mat, parent_mat, obmat);
}
@@ -106,16 +103,17 @@
copy_m4_m4(mat, obmat);
}
- mult_m4_m4m4(mat, ob_arm->obmat , mat);
- float loc[3], size[3], rot[3][3];
- mat4_to_loc_rot_size(loc, rot, size, obmat);
- mat3_to_vec_roll(rot, NULL, &angle);
+ ////mult_m4_m4m4(mat, ob_arm->obmat , mat);
+ float loc[3], size[3], rot[3][3], angle;
+ float vec[3] = {0.0f, 0.5f, 0.0f};
+ mat4_to_loc_rot_size(loc, rot, size, mat);
+ mat3_to_vec_roll(rot, vec, &angle);
bone->roll = angle;
+
// 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);
// set parent tail
@@ -146,10 +144,11 @@
create_unskinned_bone(children[i], bone, children.getCount(), mat, ob_arm);
}
+ //XXX - leaf bones are also handled above.
// in second case it's not a leaf bone, but we handle it the same way
- if (!children.getCount() || children.getCount() > 1) {
+ /*if (!children.getCount() || children.getCount() > 1) {
add_leaf_bone(mat, bone, node);
- }
+ }*/
finished_joints.push_back(node);
@@ -186,12 +185,12 @@
// get world-space
if (parent)
- mult_m4_m4m4(mat, parent_mat, obmat);
+ mult_m4_m4m4(mat, parent_mat, mat);
else
copy_m4_m4(mat, obmat);
float loc[3], size[3], rot[3][3], angle;
- mat4_to_loc_rot_size(loc, rot, size, obmat);
+ mat4_to_loc_rot_size(loc, rot, size, mat);
mat3_to_vec_roll(rot, NULL, &angle);
bone->roll = angle;
}
@@ -414,19 +413,13 @@
for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
if (get_armature_for_joint(*ri) != NULL) continue;
- //add armature object for current joint
- //Object *ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
-
Object *ob_arm = joint_parent_map[(*ri)->getUniqueId()];
if (!ob_arm)
continue;
-
- //ob_arm->type = OB_ARMATURE;
+
ED_armature_to_edit(ob_arm);
- // min_angle = 360.0f; // minimum angle between bone head-tail and a row of bone matrix
-
// create unskinned bones
/*
* TODO:
@@ -434,17 +427,19 @@
*/
leaf_bone_length = FLT_MAX;
create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm);
+
+ //leaf bone tails are derived from the matrix, so no need of this.
+ //fix_leaf_bones();
- fix_leaf_bones();
-
// exit armature edit mode
unskinned_armature_map[(*ri)->getUniqueId()] = ob_arm;
ED_armature_from_edit(ob_arm);
+
+ //This serves no purpose, as pose is automatically reset later, in BKE_where_is_bone()
+ //set_pose(ob_arm, *ri, NULL, NULL);
- set_pose(ob_arm, *ri, NULL, NULL);
-
ED_armature_edit_free(ob_arm);
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
}
@@ -597,14 +592,16 @@
}
else {
+
copy_m4_m4(mat, obmat);
float invObmat[4][4];
invert_m4_m4(invObmat, ob_arm->obmat);
mult_m4_m4m4(pchan->pose_mat, invObmat, mat);
+
}
- mat4_to_axis_angle(ax, &angle, mat);
- pchan->bone->roll = angle;
+ ///*mat4_to_axis_angle(ax, &angle, mat);
+ //pchan->bone->roll = angle;*/
COLLADAFW::NodePointerArray& children = root_node->getChildNodes();
More information about the Bf-blender-cvs
mailing list