Revision: 21620
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21620
Author:   chingachgook
Date:     2009-07-16 09:56:17 +0200 (Thu, 16 Jul 2009)

Log Message:
-----------
*Exporter handles empty objects.
*Added textures import.
TODO:
Fix images import. 

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-16 07:11:46 UTC (rev 21619)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp  
2009-07-16 07:56:17 UTC (rev 21620)
@@ -575,7 +575,7 @@
                COLLADASW::Node node(mSW);
                std::string ob_name(id_name(ob));
                node.start();
-
+               
                node.addTranslate(ob->loc[0], ob->loc[1], ob->loc[2]);
                
                // when animation time comes, replace a single <rotate> with 3, 
one for each axis
@@ -632,6 +632,9 @@
                        COLLADASW::InstanceLight instLa(mSW, 
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, ob_name));
                        instLa.add();
                }
+               // empty object
+               else if (ob->type == OB_EMPTY) {
+               }
                
                // write node for child object
                Base *b = (Base*) sce->base.first;
@@ -639,7 +642,7 @@
                        
                        Object *cob = b->object;
                        
-                       if ((cob->type == OB_MESH || cob->type == OB_CAMERA || 
cob->type == OB_LAMP) && cob->parent == ob) {
+                       if ((cob->type == OB_MESH || cob->type == OB_CAMERA || 
cob->type == OB_LAMP || cob->type == OB_EMPTY) && cob->parent == ob) {
                                // write node...
                                writeNodes(cob, sce);
                        }
@@ -655,7 +658,7 @@
                while(base) {
                        Object *ob = base->object;
                        
-                       if ((ob->type == OB_MESH || ob->type == OB_CAMERA || 
ob->type == OB_LAMP) && !ob->parent) {
+                       if ((ob->type == OB_MESH || ob->type == OB_CAMERA || 
ob->type == OB_LAMP || ob->type == OB_EMPTY) && !ob->parent) {
                                // write nodes....
                                writeNodes(ob, sce);
                                

Modified: 
branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-07-16 07:11:46 UTC (rev 21619)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-07-16 07:56:17 UTC (rev 21620)
@@ -12,6 +12,7 @@
 #include "COLLADAFWEffect.h"
 #include "COLLADAFWGeometry.h"
 #include "COLLADAFWMesh.h"
+#include "COLLADAFWMeshPrimitive.h"
 #include "COLLADAFWMeshVertexData.h"
 #include "COLLADAFWFloatOrDoubleArray.h"
 #include "COLLADAFWArrayPrimitiveType.h"
@@ -24,6 +25,10 @@
 #include "COLLADAFWRotate.h"
 #include "COLLADAFWAnimationCurve.h"
 #include "COLLADAFWAnimationList.h"
+#include "COLLADAFWSkinController.h"
+#include "COLLADAFWColorOrTexture.h"
+#include "COLLADAFWSampler.h"
+#include "COLLADAFWTypes.h"
 
 #include "COLLADASaxFWLLoader.h"
 
@@ -33,6 +38,8 @@
 #include "BKE_main.h"
 #include "BKE_customdata.h"
 #include "BKE_library.h"
+#include "BKE_texture.h"
+#include "DNA_texture_types.h"
 }
 #include "BKE_mesh.h"
 #include "BKE_global.h"
@@ -47,6 +54,7 @@
 #include "DNA_meshdata_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_material_types.h"
+//#include "DNA_texture_types.h"
 
 #include "DocumentImporter.h"
 
@@ -56,6 +64,7 @@
 
 // #define COLLADA_DEBUG
 
+char *CustomData_get_layer_name(const struct CustomData *data, int type, int 
n);
 
 const char *primTypeToStr(COLLADAFW::MeshPrimitive::PrimitiveType type)
 {
@@ -96,6 +105,13 @@
        return "UNKNOWN";
 }
 
+/*
+
+  COLLADA Importer limitations:
+
+  - no multiple scene import, all objects are added to active scene
+
+ */
 /** Class that needs to be implemented by a writer. 
        IMPORTANT: The write functions are called in arbitrary order.*/
 class Writer: public COLLADAFW::IWriter
@@ -108,9 +124,12 @@
        bContext *mContext;
 
        std::map<COLLADAFW::UniqueId, Mesh*> uid_mesh_map; // geometry unique 
id-to-mesh map
+       std::map<COLLADAFW::UniqueId, Image*> uid_image_map;
        std::map<COLLADAFW::UniqueId, Material*> uid_material_map;
        std::map<COLLADAFW::UniqueId, Material*> uid_effect_map;
-
+       // maps for assigning textures to uv layers
+       std::map<COLLADAFW::TextureMapId, char*> set_layername_map;
+       std::map<COLLADAFW::TextureMapId, std::vector<MTex*> > index_mtex_map;
        // this structure is used to assign material indices to faces
        // when materials are assigned to an object
        struct Primitive {
@@ -149,7 +168,8 @@
                // TODO need also for angle conversion, time conversion...
        };
 
-       class UVDataWrapper {
+       class UVDataWrapper
+       {
                COLLADAFW::MeshVertexData *mVData;
        public:
                UVDataWrapper(COLLADAFW::MeshVertexData& vdata) : mVData(&vdata)
@@ -273,104 +293,136 @@
                // XXX could store the scene id, but do nothing for now
                return true;
        }
-
-       void writeNode (COLLADAFW::Node *node, Scene *sce, Object *parent_ob = 
NULL)
+       
+       // bind early created mesh to object, assign materials and textures
+       Object *create_mesh_object(Object *ob, Scene *sce, COLLADAFW::Node 
*node,
+                                                          
COLLADAFW::InstanceGeometry *geom)
        {
-               // XXX linking object with the first <instance_geometry>, 
though a node may have more of them...
-               // TODO: join multiple <instance_...> meshes into 1, and link 
object with it
-               COLLADAFW::InstanceGeometryPointerArray &geom = 
node->getInstanceGeometries();
-               COLLADAFW::InstanceCameraPointerArray &camera = 
node->getInstanceCameras();
-               COLLADAFW::InstanceLightPointerArray &lamp = 
node->getInstanceLights();
-               COLLADAFW::InstanceControllerPointerArray &controller = 
node->getInstanceControllers();
-               COLLADAFW::InstanceNodePointerArray &inst_node = 
node->getInstanceNodes();
-               Object *ob;
-               int k;
+               ob = add_object(sce, OB_MESH);
                
-               // if node has <instance_geometries> - connect mesh with object
-               // XXX currently only one <instance_geometry> in a node is 
supported
-               if (geom.getCount() != 0) {
+               const std::string& id = node->getOriginalId();
+               if (id.length())
+                       rename_id(&ob->id, (char*)id.c_str());
+               
+               const COLLADAFW::UniqueId& geom_uid = 
geom->getInstanciatedObjectId();
+               if (uid_mesh_map.find(geom_uid) == uid_mesh_map.end()) {
+                       // XXX report to user
+                       // this could happen if a mesh was not created
+                       // (e.g. if it contains unsupported geometry)
+                       fprintf(stderr, "Couldn't find a mesh by UID.\n");
+                       // delete created object
+                       free_object(ob);
+                       return NULL;
+               }
+               // replace ob->data freeing the old one
+               Mesh *old_mesh = (Mesh*)ob->data;
+               set_mesh(ob, uid_mesh_map[geom_uid]);
+               if (old_mesh->id.us == 0) free_libblock(&G.main->mesh, 
old_mesh);
+               
+               // assign materials to object
+               // assign material indices to mesh faces
+               for (int k = 0; k < geom->getMaterialBindings().getCount(); 
k++) {
                        
-                       ob = add_object(sce, OB_MESH);
+                       const COLLADAFW::UniqueId& mat_uid = 
geom->getMaterialBindings()[k].getReferencedMaterial();
+                       // check if material was properly written to map
+                       if (uid_material_map.find(mat_uid) == 
uid_material_map.end()) {
+                               fprintf(stderr, "Cannot find material by 
UID.\n");
+                               continue;
+                       }
                        
-                       const std::string& id = node->getOriginalId();
-                       if (id.length())
-                               rename_id(&ob->id, (char*)id.c_str());
+                       // assign textures to uv layers
+                       // bvi_array "bind_vertex_input array"
+                       
COLLADAFW::InstanceGeometry::TextureCoordinateBindingArray& bvi_array = 
+                               
geom->getMaterialBindings()[k].getTextureCoordinateBindingArray();
                        
-                       const COLLADAFW::UniqueId& geom_uid = 
geom[0]->getInstanciatedObjectId();
-                       if (uid_mesh_map.find(geom_uid) == uid_mesh_map.end()) {
-                               // XXX report to user
-                               // this could happen if a mesh was not created
-                               // (e.g. if it contains unsupported geometry)
-                               fprintf(stderr, "Couldn't find a mesh by 
UID.\n");
-                               // delete created object
-                               free_object(ob);
-                               return;
-                       }
-                       // replace ob->data freeing the old one
-                       Mesh *old_mesh = (Mesh*)ob->data;
-                       set_mesh(ob, uid_mesh_map[geom_uid]);
-                       if (old_mesh->id.us == 0) free_libblock(&G.main->mesh, 
old_mesh);
-                       
-                       // assign materials to object
-                       // assign material indices to mesh faces
-                       for (k = 0; k < 
geom[0]->getMaterialBindings().getCount(); k++) {
+                       for (int l = 0; l < bvi_array.getCount(); l++) {
                                
-                               const COLLADAFW::UniqueId& mat_uid =
-                                       
geom[0]->getMaterialBindings()[k].getReferencedMaterial();
+                               COLLADAFW::TextureMapId tex_index = 
bvi_array[l].textureMapId;
+                               size_t set_index = bvi_array[l].setIndex;
+                               char *layername = set_layername_map[set_index];
                                
-                               if (uid_material_map.find(mat_uid) == 
uid_material_map.end()) {
-                                       
-                                       fprintf(stderr, "Cannot find material 
by UID.\n");
+                               // check if mtexes were properly added to vector
+                               if (index_mtex_map.find(tex_index) == 
index_mtex_map.end()) {
+                                       fprintf(stderr, "Cannot find vector of 
mtexes by texture map id.\n");
                                        continue;
                                }
+                               std::vector<MTex*> mtexes = 
index_mtex_map[tex_index];
+                               std::vector<MTex*>::iterator it;
+                               for (it = mtexes.begin(); it != mtexes.end(); 
it++) {
+                                       MTex *mtex = *it;
+                                       strcpy(mtex->uvname, layername);
+                               }       
+                       }
+                       
+                       assign_material(ob, uid_material_map[mat_uid], 
ob->totcol + 1);
+                       
+                       MaterialIdPrimitiveArrayMap& mat_prim_map = 
geom_uid_mat_mapping_map[geom_uid];
+                       COLLADAFW::MaterialId mat_id = 
geom->getMaterialBindings()[k].getMaterialId();
+                       
+                       // if there's geometry that uses this material,
+                       // set mface->mat_nr=k for each face in that geometry
+                       if (mat_prim_map.find(mat_id) != mat_prim_map.end()) {
                                
-                               assign_material(ob, uid_material_map[mat_uid], 
ob->totcol + 1);
+                               std::vector<Primitive>& prims = 
mat_prim_map[mat_id];
                                
-                               MaterialIdPrimitiveArrayMap& mat_prim_map = 
geom_uid_mat_mapping_map[geom_uid];
-                               COLLADAFW::MaterialId mat_id = 
geom[0]->getMaterialBindings()[k].getMaterialId();
+                               std::vector<Primitive>::iterator it;
                                
-                               // if there's geometry that uses this material,
-                               // set mface->mat_nr=k for each face in that 
geometry
-                               if (mat_prim_map.find(mat_id) != 
mat_prim_map.end()) {
+                               for (it = prims.begin(); it != prims.end(); 
it++) {
+                                       Primitive& prim = *it;
                                        
-                                       std::vector<Primitive>& prims = 
mat_prim_map[mat_id];
-                                       
-                                       std::vector<Primitive>::iterator it;
-                                       
-                                       for (it = prims.begin(); it != 
prims.end(); it++) {
-                                               Primitive& prim = *it;
-                                               
-                                               int l = 0;
-                                               while (l++ < prim.totface) {
-                                                       prim.mface->mat_nr = k;
-                                                       prim.mface++;
-                                               }
+                                       int l = 0;
+                                       while (l++ < prim.totface) {
+                                               prim.mface->mat_nr = k;
+                                               prim.mface++;
                                        }
                                }
                        }
                }
-               // checking of all other possible instances
+               return ob;
+       }
+       
+       void write_node (COLLADAFW::Node *node, Scene *sce, Object *parent_ob = 
NULL)
+       {
+               // XXX linking object with the first <instance_geometry>, 
though a node may have more of them...

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to