Revision: 21077
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21077
Author:   chingachgook
Date:     2009-06-22 15:23:13 +0200 (Mon, 22 Jun 2009)

Log Message:
-----------
Multi-texture material export (unfinished).
Import geometry using mesh editor module commented out. Will use blenkernel 
module instead.

Modified Paths:
--------------
    branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/SConscript
    
branches/soc-2009-chingachgook/source/blender/windowmanager/intern/wm_operators.c

Modified: 
branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp  
2009-06-22 11:48:31 UTC (rev 21076)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp  
2009-06-22 13:23:13 UTC (rev 21077)
@@ -4,6 +4,8 @@
 #include "DNA_mesh_types.h"
 #include "DNA_image_types.h"
 #include "DNA_material_types.h"
+#include "DNA_texture_types.h"
+
 extern "C" 
 {
 #include "BKE_DerivedMesh.h"
@@ -22,7 +24,6 @@
 #include <COLLADASWSource.h>
 #include <COLLADASWInstanceGeometry.h>
 #include <COLLADASWInputList.h>
-#include <COLLADASWScene.h>
 #include <COLLADASWPrimitves.h>
 #include <COLLADASWVertices.h>
 #include <COLLADASWLibraryImages.h>
@@ -33,9 +34,11 @@
 #include <COLLADASWParamTemplate.h>
 #include <COLLADASWParamBase.h>
 #include <COLLADASWSurfaceInitOption.h>
-#include <COLLADASWTexture.h>
 #include <COLLADASWSampler.h>
+#include <COLLADASWScene.h>
 #include <COLLADASWSurface.h>
+#include <COLLADASWTechnique.h>
+#include <COLLADASWTexture.h>
 #include <COLLADASWLibraryMaterials.h>
 #include <COLLADASWBindMaterial.h>
 
@@ -188,8 +191,6 @@
                closeLibrary();
        }
 
-       /*----------------------------------------------------------*/
-
        //creates <source> for positions
        void createVertsSource(Scene *sce, COLLADASW::StreamWriter *sw,
                                          std::string geom_name, DerivedMesh 
*dm)
@@ -225,8 +226,6 @@
        
        }
 
-       /*----------------------------------------------------------*/
-       
        //creates <source> for texcoords
        // returns true if mesh has uv data
        bool createTexcoordsSource(Scene *sce, COLLADASW::StreamWriter *sw,
@@ -304,7 +303,6 @@
                return false;
        }
 
-       /*----------------------------------------------------------*/
 
        //creates <source> for normals
        void createNormalsSource(Scene *sce, COLLADASW::StreamWriter *sw,
@@ -338,21 +336,17 @@
                source.finish();
        }
        
-       /*----------------------------------------------------------*/
-       
        std::string getIdBySemantics(std::string geom_name, 
COLLADASW::Semantics type) {
                return geom_name +
                        getSuffixBySemantic(type);
        }
        
-       /*----------------------------------------------------------*/
 
        COLLADASW::URI getUrlBySemantics(std::string geom_name, 
COLLADASW::Semantics type) {
                std::string id(getIdBySemantics(geom_name, type));
                return COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, id);
        }
        
-       /*----------------------------------------------------------*/
 
        int getTriCount(MFace *faces, int totface) {
                int i;
@@ -369,8 +363,6 @@
        }
 };
 
-/*----------------------------------------------------------*/
-
 class SceneExporter: COLLADASW::LibraryVisualScenes
 {
 public:
@@ -406,29 +398,17 @@
                                                COLLADASW::BindMaterial& bm = 
instGeom.getBindMaterial();
                                                
COLLADASW::InstanceMaterialList& iml = bm.getInstanceMaterialList();
                                                std::string matid = 
std::string(ma->id.name);   
-                                               COLLADASW::InstanceMaterial 
im("material-symbol", COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
+                                               /*COLLADASW::InstanceMaterial 
im("material-symbol", COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
+                                               COLLADASW::BindVertexInput 
bvi("myUVs", "TEXCOORD", 1);
+                                               im.push_back(bvi);*/
                                                iml.push_back(im);
                                        }
-                               //XXX hardcoded
-                               /*Image *image = (Image*)G.main->image.first;
-                               
-                               COLLADASW::BindMaterial& bm = 
instGeom.getBindMaterial();
-                               COLLADASW::InstanceMaterialList& iml = 
bm.getInstanceMaterialList();
-                               
-                               std::string matid = std::string(image->id.name) 
+ "-material";
-                               COLLADASW::InstanceMaterial 
im("material-symbol", COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
-                               COLLADASW::BindVertexInput bvi("myUVs", 
"TEXCOORD", 1);
-                               im.push_back(bvi);
-                               iml.push_back(im);*/
-
-                               //
                                instGeom.add();
-                               
                                node.end();
                        }
                        base= base->next;
                }
-
+               
                //</visual_scene></library_visual_scenes>
                closeVisualScene();
 
@@ -436,7 +416,6 @@
        }
 };
 
-/*----------------------------------------------------------*/
 //class for exporting images
 class ImagesExporter: COLLADASW::LibraryImages
 {
@@ -462,8 +441,6 @@
        
 };
 
-/*----------------------------------------------------------*/
-
 class EffectsExporter: COLLADASW::LibraryEffects
 {
 public:
@@ -476,55 +453,79 @@
                while(ma) {
                        
                        openEffect(std::string(ma->id.name) + "-effect");
-                       COLLADASW::EffectProfile ep(mSW);
-                       ep.setProfileType(COLLADASW::EffectProfile::COMMON);
-                       //open <profile_common>
-                       ep.openProfile();
-                       
 
-                       ep.closeProfile();
-                       ma = (Material*) ma->id.next;
-                       /*      Image *image = (Image*)G.main->image.first;
-               while(image) {
-                       
-                       openEffect(std::string(image->id.name) + "-effect");
                        COLLADASW::EffectProfile ep(mSW);
+                       
                        ep.setProfileType(COLLADASW::EffectProfile::COMMON);
+
                        //open <profile_common>
                        ep.openProfile();
                        
-                       //<newparam> <surface> <init_from>
-                       COLLADASW::Surface 
surface(COLLADASW::Surface::SURFACE_TYPE_2D, image->id.name + 
COLLADASW::Surface::SURFACE_SID_SUFFIX);
-                       COLLADASW::SurfaceInitOption 
sio(COLLADASW::SurfaceInitOption::INIT_FROM);
-                       sio.setImageReference(image->id.name);
-                       surface.setInitOption(sio);
+                       std::vector<int> mtexindices = countmtex(ma);
                        
-                       //<newparam> <sampler> <source>
-                       COLLADASW::Sampler 
sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D, image->id.name + 
COLLADASW::Surface::SURFACE_SID_SUFFIX);
+                       for (int a = 0; a < mtexindices.size(); a++){
+                               //<newparam> <surface> <init_from>
+                               Image *ima = ma->mtex[mtexindices[a]]->tex->ima;
+                               COLLADASW::Surface 
surface(COLLADASW::Surface::SURFACE_TYPE_2D,
+                                                                               
   ima->id.name + COLLADASW::Surface::SURFACE_SID_SUFFIX);
+                               COLLADASW::SurfaceInitOption 
sio(COLLADASW::SurfaceInitOption::INIT_FROM);
+                               sio.setImageReference(ima->id.name);
+                               surface.setInitOption(sio);
+
+                               //<newparam> <sampler> <source>
+                               COLLADASW::Sampler 
sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
+                                                                               
   ima->id.name + COLLADASW::Surface::SURFACE_SID_SUFFIX);
+
+                               //<lambert> <diffuse> <texture> 
+                               COLLADASW::Texture texture(ima->id.name);
+                               texture.setTexcoord("myUVs");
+                               texture.setSurface(surface);
+                               texture.setSampler(sampler);
+
+                               //<texture>
+                               COLLADASW::ColorOrTexture cot(texture);
+                               ep.setDiffuse(cot, true, "");
+                               
ep.setShaderType(COLLADASW::EffectProfile::LAMBERT);
+
+                               //todo add or find generator of technique sids
+                               //performs the actual writing
+                               ep.addProfileElements();
+                               ep.closeTechnique();
+                               //COLLADASW::Technique technique(mSW);
+                               //technique.closeTechnique();
+                               
+                       }
                        
-                       //<lambert> <diffuse> <texture> 
-                       COLLADASW::Texture texture(image->id.name);
-                       texture.setTexcoord("myUVs");
-                       texture.setSurface(surface);
-                       texture.setSampler(sampler);
-                       
-                       COLLADASW::ColorOrTexture cot(texture);
-                       ep.setDiffuse(cot, true, "");
-                       ep.setShaderType(COLLADASW::EffectProfile::LAMBERT);
-                       //performs the actual writing
-                       ep.addProfileElements();
                        ep.closeProfile();
-                       closeEffect();
-                       image = (Image*)image->id.next;
-               }*/
+                       ma = (Material*) ma->id.next;
                }
                
                closeLibrary();
 
        }
-       
+
+       //returns the array of mtex indices which have image 
+       //I need this for exporting textures
+       std::vector<int> countmtex(Material *ma)
+       {
+               std::vector<int> mtexindices;
+               for (int a = 0; a < 18; a++){
+                       if (!ma->mtex[a]){
+                               continue;
+                       }
+                       Tex *tex = ma->mtex[a]->tex;
+                       if(!tex){
+                               continue;
+                       }
+                       Image *ima = tex->ima;
+                       if(!ima){
+                               continue;
+                       }
+                       mtexindices.push_back(a);
+               }
+               return mtexindices;
+       }
 };
-/*----------------------------------------------------------*/
 
 class MaterialsExporter: COLLADASW::LibraryMaterials
 {
@@ -546,28 +547,11 @@
                        
                        ma = (Material*) ma->id.next;
                }
-               closeLibrary();
-               
-               /*
-                 Image *image = (Image*)G.main->image.first;
-                 while(image) {
-                 
-                 openMaterial(std::string(image->id.name) + "-material");
-                 std::string efid = std::string(image->id.name) + "-effect";
-                 
addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));
-                 closeMaterial();
-                 image = (Image*)image->id.next;
-                 }
-               */
-               
+               closeLibrary(); 
        }
-       
-       
 };
 
 
-/*----------------------------------------------------------*/
-
 void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)
 {
        COLLADABU::NativeString native_filename =
@@ -613,8 +597,6 @@
 
 }
 
-/*----------------------------------------------------------*/
-
 void DocumentExporter::exportScenes(const char* filename)
 {
 }

Modified: 
branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-06-22 11:48:31 UTC (rev 21076)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp  
2009-06-22 13:23:13 UTC (rev 21077)
@@ -11,23 +11,28 @@
 #include "COLLADAFWMaterial.h"
 #include "COLLADAFWGeometry.h"
 #include "COLLADAFWMesh.h"
+#include "COLLADAFWFloatOrDoubleArray.h"
+#include "COLLADAFWArrayPrimitiveType.h"
 
 #include "COLLADASaxFWLLoader.h"
 
+// TODO move "extern C" into header files
 extern "C" 
 {
 #include "BKE_main.h"
 #include "BKE_mesh.h"
 #include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_image.h"
+#include "BKE_material.h"
+}
 
 #include "DNA_object_types.h"
 
-#include "ED_object.h"
-
 #include "DocumentImporter.h"
-}
 
 
+
 /** Class that needs to be implemented by a writer. 
        IMPORTANT: The write functions are called in arbitrary order.*/
 class Writer: public COLLADAFW::IWriter
@@ -83,6 +88,12 @@
        */
        virtual void cancel(const COLLADAFW::String& errorMessage)
        {
+               // TODO: if possible show error info
+               //
+               // Should we get rid of invisible Meshes that were created so 
far
+               // or maybe create objects at coordinate space origin?
+               //
+               // The latter sounds better.
        }
 
        /** This is the method called. The writer hast to prepare to receive 
data.*/
@@ -95,6 +106,20 @@
        {
                // using mVisualScenes, do:
                // - write <node> data to Objects: materials, transforms, etc.
+
+               // TODO: import materials (<instance_material> inside 
<instance_geometry>) and textures
+
+               std::vector<COLLADAFW::VisualScene>::iterator it = 
mVisualScenes.begin();
+               for (; it != mVisualScenes.end(); it++) {
+                       COLLADAFW::VisualScene &visscene = *it;
+
+                       // create new blender scene
+
+                       // create Objects from <node>s inside this 
<visual_scene>
+

@@ 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