Finalizing.
authorSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>
Tue, 16 Aug 2011 16:03:37 +0000 (16:03 +0000)
committerSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>
Tue, 16 Aug 2011 16:03:37 +0000 (16:03 +0000)
source/blender/collada/AnimationExporter.cpp
source/blender/collada/AnimationExporter.h
source/blender/collada/AnimationImporter.cpp
source/blender/collada/AnimationImporter.h
source/blender/collada/ArmatureExporter.cpp
source/blender/collada/ArmatureImporter.cpp
source/blender/collada/DocumentImporter.cpp

index a777f4ae98477af90adff7b150fef41186e43b4c..d2ff369c6132d0a2601bf886c583b334b1cffc23 100644 (file)
@@ -61,13 +61,14 @@ void AnimationExporter::exportAnimations(Scene *sce)
                bool isMatAnim = false;
         if(ob->adt && ob->adt->action)      
                {
-                       if ( ob->type == OB_ARMATURE )
+                       //transform matrix export for bones are temporarily disabled here.
+                       /*if ( ob->type == OB_ARMATURE )
                        {
                                bArmature *arm = (bArmature*)ob->data;
                                for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
                                        bake_bone_animation(ob, bone);
                            
-                       }
+                       }*/
                        fcu = (FCurve*)ob->adt->action->curves.first;
                    while (fcu) {
                        transformName = extract_transform_name( fcu->rna_path );
@@ -988,8 +989,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
        std::string AnimationExporter::get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
        {
                std::string tm_name;
-        bool is_rotation =false;
-               // when given rna_path, determine tm_type from it
+        // when given rna_path, determine tm_type from it
                if (rna_path) {
                        char *name = extract_transform_name(rna_path);
 
@@ -1033,6 +1033,57 @@ void AnimationExporter::exportAnimations(Scene *sce)
 
                return std::string("");
        }
+       
+       std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
+       {
+               std::string tm_name;
+        // when given rna_path, determine tm_type from it
+               if (rna_path) {
+                       char *name = extract_transform_name(rna_path);
+
+                   if (!strcmp(name, "lens"))
+                               tm_type = 0;
+            else if (!strcmp(name, "ortho_scale"))
+                               tm_type = 1;
+                       else if (!strcmp(name, "clip_end"))
+                               tm_type = 2;
+                       else if (!strcmp(name, "clip_start"))
+                               tm_type = 3;
+                       
+                       else
+                               tm_type = -1;
+               }
+
+               switch (tm_type) {
+               case 0:
+                       tm_name = "xfov";
+                       break;
+               case 1:
+                       tm_name = "xmag";
+                       break;
+               case 2:
+                       tm_name = "zfar";
+                       break;
+               case 3:
+                       tm_name = "znear";
+                       break;
+               
+               default:
+                       tm_name = "";
+                       break;
+               }
+       
+               if (tm_name.size()) {
+                       if (axis_name != "")
+                               return tm_name + "." + std::string(axis_name);
+                       else 
+                               return tm_name;
+               }
+
+               return std::string("");
+       }
+
+    // Assign sid of the animated parameter or transform 
        // for rotation, axis name is always appended and the value of append_axis is ignored
        std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
        {
@@ -1137,6 +1188,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
                return dot ? (dot + 1) : rna_path;
        }
 
+       //find keyframes of all the objects animations
        void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
        {
                FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
@@ -1154,38 +1206,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
                std::sort(fra.begin(), fra.end());
        }
 
-
-       void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
-       {
-               FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
-
-               for (; fcu; fcu = fcu->next) {
-                       if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
-                               continue;
-
-                       char *name = extract_transform_name(fcu->rna_path);
-                       if (!strcmp(name, tm_name)) {
-                               for (unsigned int i = 0; i < fcu->totvert; i++) {
-                                       float f = fcu->bezt[i].vec[1][0];     //
-                                       if (std::find(fra.begin(), fra.end(), f) == fra.end())   
-                                               fra.push_back(f);
-                               }
-                       }
-               }
-
-               // keep the keys in ascending order
-               std::sort(fra.begin(), fra.end());
-       }
-
-       void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
-       {
-               if (rotmode > 0)
-                       find_frames(ob, fra, prefix, "rotation_euler");
-               else if (rotmode == ROT_MODE_QUAT)
-                       find_frames(ob, fra, prefix, "rotation_quaternion");
-               /*else if (rotmode == ROT_MODE_AXISANGLE)
-                       ;*/
-       }
+        
 
        // enable fcurves driving a specific bone, disable all the rest
        // if bone_name = NULL enable all fcurves
@@ -1218,13 +1239,17 @@ void AnimationExporter::exportAnimations(Scene *sce)
                        Object *ob = base->object;
                        
                        FCurve *fcu = 0;
+                       //Check for object transform animations
                        if(ob->adt && ob->adt->action)      
                                fcu = (FCurve*)ob->adt->action->curves.first;
+                       //Check for Lamp parameter animations
                        else if( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
                                fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
+                       //Check for Camera parameter animations
                        else if( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
                                fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
                        
+                       //Check Material Effect parameter animations.
                    for(int a = 0; a < ob->totcol; a++)
                        {
                                Material *ma = give_current_material(ob, a+1);
@@ -1240,3 +1265,36 @@ void AnimationExporter::exportAnimations(Scene *sce)
                }
                return false;
        }
+
+       //------------------------------- Not used in the new system.--------------------------------------------------------
+       void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra, const char *prefix, int rotmode)
+       {
+               if (rotmode > 0)
+                       find_frames(ob, fra, prefix, "rotation_euler");
+               else if (rotmode == ROT_MODE_QUAT)
+                       find_frames(ob, fra, prefix, "rotation_quaternion");
+               /*else if (rotmode == ROT_MODE_AXISANGLE)
+                       ;*/
+       }
+
+       void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
+       {
+               FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
+
+               for (; fcu; fcu = fcu->next) {
+                       if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
+                               continue;
+
+                       char *name = extract_transform_name(fcu->rna_path);
+                       if (!strcmp(name, tm_name)) {
+                               for (unsigned int i = 0; i < fcu->totvert; i++) {
+                                       float f = fcu->bezt[i].vec[1][0];     //
+                                       if (std::find(fra.begin(), fra.end(), f) == fra.end())   
+                                               fra.push_back(f);
+                               }
+                       }
+               }
+
+               // keep the keys in ascending order
+               std::sort(fra.begin(), fra.end());
+       }
index 6cf3207b8a05ce8a4476bb8ce37872fcd871c0c2..e1b03b969dc12facb683c4de3e2383f45f6e8d90 100644 (file)
@@ -143,7 +143,7 @@ protected:
        // for rotation, axis name is always appended and the value of append_axis is ignored
        std::string get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis);
        std::string get_light_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis);
-       
+       std::string get_camera_param_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis);
        void find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name);
        void find_frames(Object *ob, std::vector<float> &fra);
 
index 0549f133031fd2db75233d5ad0bd971754c446f2..29bd0bd93b7b6b66a92758954c3cb9b828811112 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory, Sukhitha Jayathilake.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
index 9aec7df1099948b41db51d7d08e5565da4b059ff..fbb53ceedb622c564d8ef7e58447e630dbb6357b 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory , Sukhitha Jayathilake.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
index 6849e4de7ddfb58fa613762e700b17a5ad19cfd6..b033c780530645504c3a1485ab368b5418a2511f 100644 (file)
@@ -224,7 +224,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
                mul_m4_m4m4(mat, pchan->pose_mat, ob_arm->obmat);
        }
 
-       TransformWriter::add_node_transform(node, mat, NULL);
+       TransformWriter::add_node_transform(node, mat,NULL );
 }
 
 std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob)
index 7a3c6a0644f98fc33a1f0d30648a157e5237a451..7acae995396c5a2667409bf5eff3722ccfee235c 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory.
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Nathan Letwory, Sukhitha jayathilake.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
@@ -37,6 +37,7 @@
 #include "BKE_action.h"
 #include "BKE_depsgraph.h"
 #include "BKE_object.h"
+#include "BKE_armature.h"
 #include "BLI_string.h"
 #include "ED_armature.h"
 
@@ -97,28 +98,21 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
 
        if (parent) bone->parent = parent;
     float ax[3];
-       float angle = NULL;
+       float angle = 0;
 
        // 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);
-               mat4_to_axis_angle(ax,&angle,mat);
-               bone->roll = angle;
+
        }
        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);
-          mat4_to_axis_angle(ax,&angle,mat);
-          bone->roll = angle;
-       }
-       
 
+       }
+       float loc[3], size[3], rot[3][3];
+       mat4_to_loc_rot_size( loc, rot, size, obmat);
+       mat3_to_vec_roll(rot, NULL, &angle );
+       bone->roll=angle;
        // set head
        copy_v3_v3(bone->head, mat[3]);
    
@@ -130,10 +124,10 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
        // set parent tail
        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 increase this to prevent "very" small bones?
                const float epsilon = 0.000001f;
 
index a4d1c1b451f8249686295d9256f2ee3ed7710ca4..f6c985626db633d695e9776ce67778f3b031c429 100644 (file)
@@ -410,15 +410,18 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
                while (geom_done < geom.getCount()) {
                        ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
                                                                                                  material_texture_mapping_map);
-                       ++geom_done;
+                       if ( ob != NULL )
+                               ++geom_done;
                }
                while (camera_done < camera.getCount()) {
                        ob = create_camera_object(camera[camera_done], sce);
-                       ++camera_done;
+                       if ( ob != NULL )
+                               ++camera_done;
                }
                while (lamp_done < lamp.getCount()) {
                        ob = create_lamp_object(lamp[lamp_done], sce);
-                       ++lamp_done;
+                       if ( ob != NULL )
+                               ++lamp_done;
                }
                while (controller_done < controller.getCount()) {
                        COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry*)controller[controller_done];