Revision: 48011
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48011
Author:   aramis_acg
Date:     2012-06-17 16:59:58 +0000 (Sun, 17 Jun 2012)
Log Message:
-----------
- bf_assimp: fix handling of leaf armature nodes. This fixes cases in which the 
leafs would point into the wrong direction. 

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.h

Modified: branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.cpp      
2012-06-17 16:40:16 UTC (rev 48010)
+++ branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.cpp      
2012-06-17 16:59:58 UTC (rev 48011)
@@ -127,6 +127,9 @@
                armature->act_edbone = bone;
        }
 
+       // set bone name
+       BLI_strncpy(bone->name,node->mName.C_Str(),sizeof(bone->name));
+
        float obmat[4][4];
        if(parentNode != NULL)
        {
@@ -156,37 +159,46 @@
        if (parent && totchild == 1) {
                copy_v3_v3(parent->tail, bone->head);
 
-               // not setting BONE_CONNECTED because this would lock child 
bone location with respect to parent
-               // bone->flag |= BONE_CONNECTED;
+               // XXX the code below taken from collada - I'm not sure if it
+               // applies to Assimp, though.
 
                // XXX increase this to prevent "very" small bones?
                const float epsilon = 0.000001f;
 
-       
-               /*// derive leaf bone length
+               // derive leaf bone length
                float length = len_v3v3(parent->head, parent->tail);
-               if ((length < leaf_bone_length || totbone == 0) && length > 
epsilon) {
-                       leaf_bone_length = length;
-               }
 
                // treat zero-sized bone like a leaf bone
                if (length <= epsilon) {
-                       add_leaf_bone(parent_mat, parent, node);
-               } */
+                       setup_leaf_bone(parent);
+               } 
        }
 
        for(unsigned int i = 0; i < node->mNumChildren; ++i) {
                convert_node(node->mChildren[i],bone,node,node->mNumChildren);
        }
 
-       /*
        // in second case it's not a leaf bone, but we handle it the same way
-       if (!children.getCount() || children.getCount() > 1) {
-               add_leaf_bone(mat, bone, node);
-       } */
+       if (node->mNumChildren != 1) {
+               setup_leaf_bone(bone);
+       } 
 }
 
+void ArmatureImporter::setup_leaf_bone(EditBone *bone)
+{
+       // pointing up
+       float vec[3] = {0.0f, 0.0f, 0.1f};
 
+       // if parent: take parent length and direction
+       if (bone->parent) {
+               sub_v3_v3v3(vec, bone->parent->tail, bone->parent->head);
+       }
+
+       copy_v3_v3(bone->tail, bone->head);
+       add_v3_v3v3(bone->tail, bone->head, vec);
+}
+
+
 void ArmatureImporter::convert()
 {
        // first cache world matrices for all nodes

Modified: branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.h        
2012-06-17 16:40:16 UTC (rev 48010)
+++ branches/soc-2012-bratwurst/source/blender/assimp/ArmatureImporter.h        
2012-06-17 16:59:58 UTC (rev 48011)
@@ -54,6 +54,8 @@
        void error(const char* message);
        void verbose(const char* message);
 
+       void setup_leaf_bone(EditBone *bone);
+
        void compute_world_matrix(const aiNode* node, const aiMatrix4x4& 
parentWorld);
        void get_world_matrix(const aiNode* node, float out[4][4]);
 

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to