Revision: 48456
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48456
Author:   phabtar
Date:     2012-06-30 19:15:18 +0000 (Sat, 30 Jun 2012)
Log Message:
-----------
Armature Import Fix. 

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp
    branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp
    branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp
    branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.h
    branches/soc-2012-bratwurst/source/blender/collada/TransformWriter.cpp

Modified: 
branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp     
2012-06-30 18:24:28 UTC (rev 48455)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureExporter.cpp     
2012-06-30 19:15:18 UTC (rev 48456)
@@ -187,58 +187,59 @@
                node.setNodeName(node_name);
                node.setNodeSid(node_sid);
 
-#if 0
+//#if 1 
                if (bone->childbase.first == NULL || 
BLI_countlist(&(bone->childbase)) >= 2) {
                        add_blender_leaf_bone( bone, ob_arm , node );
                }
-               else {
-#endif
-               node.start();
+               else{
+//#endif
+                       node.start();
 
-               add_bone_transform(ob_arm, bone, node);
+                       add_bone_transform(ob_arm, bone, node);
 
-               // Write nodes of childobjects, remove written objects from list
-               std::list<Object *>::iterator i = child_objects.begin();
+                       // Write nodes of childobjects, remove written objects 
from list
+                       std::list<Object *>::iterator i = child_objects.begin();
 
-               while (i != child_objects.end()) {
-                       if ((*i)->partype == PARBONE && (0 == 
strcmp((*i)->parsubstr, bone->name))) {
-                               float backup_parinv[4][4];
-                               copy_m4_m4(backup_parinv, (*i)->parentinv);
+                       while (i != child_objects.end()) {
+                               if ((*i)->partype == PARBONE && (0 == 
strcmp((*i)->parsubstr, bone->name))) {
+                                       float backup_parinv[4][4];
+                                       copy_m4_m4(backup_parinv, 
(*i)->parentinv);
 
-                               // crude, temporary change to parentinv
-                               // so transform gets exported correctly.
+                                       // crude, temporary change to parentinv
+                                       // so transform gets exported correctly.
 
-                               // Add bone tail- translation... don't know why
-                               // bone parenting is against the tail of a bone
-                               // and not it's head, seems arbitrary.
-                               (*i)->parentinv[3][1] += bone->length;
+                                       // Add bone tail- translation... don't 
know why
+                                       // bone parenting is against the tail 
of a bone
+                                       // and not it's head, seems arbitrary.
+                                       (*i)->parentinv[3][1] += bone->length;
 
-                               // SECOND_LIFE_COMPATIBILITY
-                               // TODO: when such objects are animated as
-                               // single matrix the tweak must be applied
-                               // to the result.
-                               if (export_settings->second_life) {
-                                       // tweak objects parentinverse to match 
compatibility
-                                       float temp[4][4];
+                                       // SECOND_LIFE_COMPATIBILITY
+                                       // TODO: when such objects are animated 
as
+                                       // single matrix the tweak must be 
applied
+                                       // to the result.
+                                       if (export_settings->second_life) {
+                                               // tweak objects parentinverse 
to match compatibility
+                                               float temp[4][4];
 
-                                       copy_m4_m4(temp, bone->arm_mat);
-                                       temp[3][0] = temp[3][1] = temp[3][2] = 
0.0f;
+                                               copy_m4_m4(temp, bone->arm_mat);
+                                               temp[3][0] = temp[3][1] = 
temp[3][2] = 0.0f;
 
-                                       mult_m4_m4m4((*i)->parentinv, temp, 
(*i)->parentinv);
-                               }
+                                               mult_m4_m4m4((*i)->parentinv, 
temp, (*i)->parentinv);
+                                       }
 
-                               se->writeNodes(*i, sce);
+                                       se->writeNodes(*i, sce);
 
-                               copy_m4_m4((*i)->parentinv, backup_parinv);
-                               child_objects.erase(i++);
+                                       copy_m4_m4((*i)->parentinv, 
backup_parinv);
+                                       child_objects.erase(i++);
+                               }
+                               else i++;
                        }
-                       else i++;
-               }
 
-               for (Bone *child = (Bone *)bone->childbase.first; child; child 
= child->next) {
-                       add_bone_node(child, ob_arm, sce, se, child_objects);
+                       for (Bone *child = (Bone *)bone->childbase.first; 
child; child = child->next) {
+                               add_bone_node(child, ob_arm, sce, se, 
child_objects);
+                       }
+                       node.end();
                }
-               node.end();
        }
        else {
                for (Bone *child = (Bone *)bone->childbase.first; child; child 
= child->next) {
@@ -247,7 +248,7 @@
        }
 }
 
-#if 0
+//#if 1
 void ArmatureExporter::add_blender_leaf_bone(Bone *bone, Object *ob_arm, 
COLLADASW::Node& node)
 {
        node.start();
@@ -258,13 +259,13 @@
        node.addExtraTechniqueParameter("blender", "tip_y", bone->tail[1]);
        node.addExtraTechniqueParameter("blender", "tip_z", bone->tail[2]);
        
-       for (Bone *child = (Bone *)bone->childbase.first; child; child = 
child->next) {
+       /*for (Bone *child = (Bone *)bone->childbase.first; child; child = 
child->next) {
                add_bone_node(child, ob_arm, sce, se, child_objects);
-       }
+       }*/
        node.end();
        
 }
-#endif
+//#endif
 
 void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, 
COLLADASW::Node& node)
 {
@@ -273,7 +274,7 @@
        float mat[4][4];
 
        if (bone->parent) {
-               // get bone-space matrix from armature-space
+               // get bone-space matrix from parent pose
                bPoseChannel *parchan = 
BKE_pose_channel_find_name(ob_arm->pose, bone->parent->name);
 
                float invpar[4][4];
@@ -281,6 +282,7 @@
                mult_m4_m4m4(mat, invpar, pchan->pose_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
@@ -288,7 +290,7 @@
        }
 
        // 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];
@@ -304,7 +306,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-06-30 18:24:28 UTC (rev 48455)
+++ branches/soc-2012-bratwurst/source/blender/collada/ArmatureImporter.cpp     
2012-06-30 19:15:18 UTC (rev 48456)
@@ -101,12 +101,12 @@
        // get world-space
        if (parent) {
                mult_m4_m4m4(mat, parent_mat, obmat);
-
        }
        else {
                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);

Modified: 
branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp     
2012-06-30 18:24:28 UTC (rev 48455)
+++ branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.cpp     
2012-06-30 19:15:18 UTC (rev 48456)
@@ -421,19 +421,10 @@
        bool read_transform = true;
 
        ExtraTags *et = getExtraTags(node->getUniqueId());
-    
-       
 
        std::vector<Object *> *objects_done = new std::vector<Object *>();
     
        if (is_joint) {
-               if (par) {
-                       Object *empty = par;
-                       par = bc_add_object(sce, OB_ARMATURE, NULL);
-                       bc_set_parent(par, empty->parent, mContext);
-                       //remove empty : todo
-                       object_map.insert(std::make_pair<COLLADAFW::UniqueId, 
Object *>(parent_node->getUniqueId(), par));
-               }
                armature_importer.add_joint(node, parent_node == NULL || 
parent_node->getType() != COLLADAFW::Node::JOINT, par, sce);
        }
        else {
@@ -496,7 +487,11 @@
                // if node is empty - create empty object
                // XXX empty node may not mean it is empty object, not sure 
about this
                if ( (geom_done + camera_done + lamp_done + controller_done + 
inst_done) < 1) {
-                       ob = bc_add_object(sce, OB_EMPTY, NULL);
+                       //Check if Object is armature, by checking if immediate 
child is a JOINT node.
+                       if(is_armature(node))
+                               ob = bc_add_object(sce, OB_ARMATURE, NULL);
+                       else ob = bc_add_object(sce, OB_EMPTY, NULL);
+
                        objects_done->push_back(ob);
                }
                
@@ -1192,3 +1187,14 @@
        return true;
 }
 
+bool DocumentImporter::is_armature(COLLADAFW::Node *node){
+       COLLADAFW::NodePointerArray &child_nodes = node->getChildNodes();
+       for (unsigned int i = 0; i < child_nodes.getCount(); i++) {     
+               if(child_nodes[i]->getType() == COLLADAFW::Node::JOINT) return 
true;
+               else continue;
+       }
+    
+       //no child is JOINT
+       return false;
+
+}

Modified: branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.h       
2012-06-30 18:24:28 UTC (rev 48455)
+++ branches/soc-2012-bratwurst/source/blender/collada/DocumentImporter.h       
2012-06-30 19:15:18 UTC (rev 48456)
@@ -130,8 +130,10 @@
        /** Get an extisting ExtraTags for uid */
        ExtraTags* getExtraTags(const COLLADAFW::UniqueId &uid);
 
+       bool is_armature(COLLADAFW::Node * node);
 
 
+
 private:
 
        /** Current import stage we're in. */

Modified: branches/soc-2012-bratwurst/source/blender/collada/TransformWriter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/collada/TransformWriter.cpp      
2012-06-30 18:24:28 UTC (rev 48455)
+++ branches/soc-2012-bratwurst/source/blender/collada/TransformWriter.cpp      
2012-06-30 19:15:18 UTC (rev 48456)
@@ -126,7 +126,6 @@
 
 void TransformWriter::add_transform(COLLADASW::Node& node, float loc[3], float 
rot[3], float scale[3])
 {
-       node.addTranslate("location", loc[0], loc[1], loc[2]);
 #if 0
        node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2]));
        node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1]));
@@ -135,6 +134,7 @@
        node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
        node.addRotateY("rotationY", RAD2DEGF(rot[1]));
        node.addRotateX("rotationX", RAD2DEGF(rot[0]));
+       node.addScale("scale", scale[0], scale[1], scale[2]);
+       node.addTranslate("location", loc[0], loc[1], loc[2]);
 
-       node.addScale("scale", scale[0], scale[1], scale[2]);
 }

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

Reply via email to