Revision: 21475
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21475
Author:   chingachgook
Date:     2009-07-10 08:55:05 +0200 (Fri, 10 Jul 2009)

Log Message:
-----------
Added export objects hierarchy.

Modified Paths:
--------------
    branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp

Modified: 
branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp  
2009-07-10 04:25:49 UTC (rev 21474)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp  
2009-07-10 06:55:05 UTC (rev 21475)
@@ -7,6 +7,9 @@
 #include "DNA_texture_types.h"
 #include "DNA_camera_types.h"
 #include "DNA_lamp_types.h"
+#include "DNA_anim_types.h"
+#include "DNA_action_types.h"
+#include "DNA_curve_types.h"
 
 extern "C" 
 {
@@ -30,6 +33,7 @@
 #include <COLLADASWInputList.h>
 #include <COLLADASWPrimitves.h>
 #include <COLLADASWVertices.h>
+#include <COLLADASWLibraryAnimations.h>
 #include <COLLADASWLibraryImages.h>
 #include <COLLADASWLibraryEffects.h>
 #include <COLLADASWImage.h>
@@ -59,6 +63,8 @@
 // This function assumes that quat is normalized.
 // The following document was used as reference:
 // 
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
+
+
 void QuatToAxisAngle(float *q, float *axis, float *angle)
 {
        // quat to axis angle
@@ -110,18 +116,34 @@
 template<class Functor>
 void forEachMeshObjectInScene(Scene *sce, Functor &f)
 {
+       
        Base *base= (Base*) sce->base.first;
        while(base) {
                Object *ob = base->object;
-                       
+               
                if (ob->type == OB_MESH && ob->data) {
                        f(ob);
                }
                base= base->next;
+               
        }
 }
 
 template<class Functor>
+void forEachObjectWithAnimationInScene(Scene *sce, Functor &f)
+{
+       Base *base= (Base*) sce->base.first;
+       while(base) {
+               Object *ob = base->object;
+                       
+               if (ob->adt && ob->data) {
+                       f(ob);
+               }
+               base= base->next;
+       }
+}
+
+template<class Functor>
 void forEachCameraObjectInScene(Scene *sce, Functor &f)
 {
        Base *base= (Base*) sce->base.first;
@@ -531,10 +553,11 @@
                openVisualScene(id_name(sce), "");
 
                // write <node>s
-               forEachMeshObjectInScene(sce, *this);
-               forEachCameraObjectInScene(sce, *this);
-               forEachLampObjectInScene(sce, *this);
-               
+               //forEachMeshObjectInScene(sce, *this);
+               //forEachCameraObjectInScene(sce, *this);
+               //forEachLampObjectInScene(sce, *this);
+               exportHierarchy(sce);
+
                // </visual_scene> </library_visual_scenes>
                closeVisualScene();
 
@@ -542,7 +565,9 @@
        }
 
        // called for each object
-       void operator()(Object *ob) {
+       //void operator()(Object *ob) {
+       void writeNodes(Object *ob, Scene *sce) {
+               
                COLLADASW::Node node(mSW);
                std::string ob_name(id_name(ob));
                node.start();
@@ -603,9 +628,37 @@
                        instLa.add();
                }
                
+               // write node for child object
+               Base *b = (Base*) sce->base.first;
+               while(b) {
+                       
+                       Object *cob = b->object;
+                       
+                       if ((cob->type == OB_MESH || cob->type == OB_CAMERA || 
cob->type == OB_LAMP) && cob->parent == ob) {
+                               // write node...
+                               writeNodes(cob, sce);
+                       }
+                       b = b->next;
+               }
+               
                node.end();
        }
 
+       void exportHierarchy(Scene *sce)
+       {
+               Base *base= (Base*) sce->base.first;
+               while(base) {
+                       Object *ob = base->object;
+                       
+                       if ((ob->type == OB_MESH || ob->type == OB_CAMERA || 
ob->type == OB_LAMP) && !ob->parent) {
+                               // write nodes....
+                               writeNodes(ob, sce);
+                               
+                       }
+                       base= base->next;
+               }
+       }
+
 };
 
 class ImagesExporter: COLLADASW::LibraryImages
@@ -959,6 +1012,46 @@
        }
 };
 
+class AnimationsExporter: COLLADASW::LibraryAnimations
+{
+public:
+       AnimationsExporter(COLLADASW::StreamWriter *sw): 
COLLADASW::LibraryAnimations(sw) {}
+       void exportAnimation(Scene *sce)
+       {
+               openLibrary();
+               
+               forEachObjectWithAnimationInScene(sce, *this);
+               
+               closeLibrary();
+       }
+       void operator() (Object *ob) 
+       {
+               
+               AnimData *adt = ob->adt;
+               NlaTrack *nlt;
+               NlaStrip *strip;
+               FCurve *fcu;            
+               
+               // iterate over all nla tracks
+               for (nlt = (NlaTrack*)adt->nla_tracks.first; nlt; nlt = 
nlt->next) {
+                       
+                       // iterate over all nla strips of current nla track
+                       for (strip = (NlaStrip*)nlt->strips.first; strip; strip 
= strip->next) {
+                               bAction *act = strip->act;
+                               // iterate over all fcurves of current nla 
strip's action
+                               for (fcu = (FCurve*)act->curves.first; fcu; fcu 
= fcu->next) {
+                                       // write <animation> for each fcurve
+                                       // each fcurve represents one axis of 
loc/rot/scale
+                                       // through fcurve I can take intangents 
and outtangents
+                                       // but how do I get objects 
loc/rot/scale data at specific time
+                                       
+                               }
+                       }
+               }
+               
+       }
+};
+
 void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)
 {
        COLLADABU::NativeString native_filename =

Modified: 
branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-07-10 04:25:49 UTC (rev 21474)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-07-10 06:55:05 UTC (rev 21475)
@@ -144,7 +144,8 @@
                {
                        //int uv_coords_index = 
mVData->getInputInfosArray()[uv_set_index]->getCount() * uv_set_index + 
uv_index * 2;
                        int uv_coords_index = uv_index * 2;
-//                     int uv_coords_index = mVData->getLength(uv_set_index) * 
uv_set_index + uv_index * 2;
+                       //int uv_coords_index = mVData->getLength(uv_set_index) 
* uv_set_index + uv_index * 2;
+                       
                        switch(mVData->getType()) {
                        case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
                                {
@@ -164,8 +165,6 @@
                                        break;
                                }
                        }
-                       //uv[0] = mVData;
-                       //uv[1] = ...;
                }
        };
 
@@ -429,13 +428,16 @@
                        0
                };
 
-               if (quad) uv_indices[3] = index_list.getIndex(index + 3);
+               //if (quad) uv_indices[3] = index_list.getIndex(index + 3);
 
                uvs.getUV(uv_set_index, uv_indices[0], mtface->uv[0]);
                uvs.getUV(uv_set_index, uv_indices[1], mtface->uv[1]);
                uvs.getUV(uv_set_index, uv_indices[2], mtface->uv[2]);
 
-               if (quad) uvs.getUV(uv_set_index, uv_indices[3], mtface->uv[3]);
+               if (quad) {
+                       uv_indices[3] = index_list.getIndex(index + 3);
+                       uvs.getUV(uv_set_index, uv_indices[3], mtface->uv[3]);
+               }
        }
 
        /** When this method is called, the writer must write the geometry.


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

Reply via email to