COLLADA conformance: don't write empty libraries for effect, image and animation
authorNathan Letwory <nathan@letworyinteractive.com>
Fri, 18 Mar 2011 14:06:13 +0000 (14:06 +0000)
committerNathan Letwory <nathan@letworyinteractive.com>
Fri, 18 Mar 2011 14:06:13 +0000 (14:06 +0000)
source/blender/collada/DocumentExporter.cpp
source/blender/collada/EffectExporter.cpp
source/blender/collada/EffectExporter.h
source/blender/collada/ImageExporter.cpp
source/blender/collada/ImageExporter.h

index f481add98ff3d6ca50432811d489847ab2d91464..00daac6028182d5ec270791dd8e295b940a0db57 100644 (file)
@@ -307,15 +307,19 @@ public:
 
        AnimationExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) { this->sw = sw; }
 
+
+
        void exportAnimations(Scene *sce)
        {
-               this->scene = sce;
+               if(hasAnimations(sce)) {
+                       this->scene = sce;
 
-               openLibrary();
-               
-               forEachObjectInScene(sce, *this);
-               
-               closeLibrary();
+                       openLibrary();
+
+                       forEachObjectInScene(sce, *this);
+
+                       closeLibrary();
+               }
        }
 
        // called for each exported object
@@ -905,6 +909,24 @@ protected:
                        }
                }
        }
+       
+       bool hasAnimations(Scene *sce)
+       {
+               Base *base= (Base*) sce->base.first;
+               while(base) {
+                       Object *ob = base->object;
+                       
+                       FCurve *fcu = 0;
+                       if(ob->adt && ob->adt->action)
+                               fcu = (FCurve*)ob->adt->action->curves.first;
+                               
+                       if ((ob->type == OB_ARMATURE && ob->data) || fcu) {
+                               return true;
+                       }
+                       base= base->next;
+               }
+               return false;
+       }
 };
 
 void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)
index ee0ade53e9923a8affba438ac9892833a9acc7a7..323b90fe1cca07733318a1ab9a1bff7941bab3f4 100644 (file)
@@ -55,15 +55,38 @@ static std::string getActiveUVLayerName(Object *ob)
        return "";
 }
 
-
 EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw) : COLLADASW::LibraryEffects(sw){}
+
+bool EffectsExporter::hasEffects(Scene *sce)
+{
+       Base *base = (Base *)sce->base.first;
+       
+       while(base) {
+               Object *ob= base->object;
+               int a;
+               for(a = 0; a < ob->totcol; a++)
+               {
+                       Material *ma = give_current_material(ob, a+1);
+
+                       // no material, but check all of the slots
+                       if (!ma) continue;
+
+                       return true;
+               }
+               base= base->next;
+       }
+       return false;
+}
+
 void EffectsExporter::exportEffects(Scene *sce)
 {
-       openLibrary();
-       MaterialFunctor mf;
-       mf.forEachMaterialInScene<EffectsExporter>(sce, *this);
+       if(hasEffects(sce)) {
+               openLibrary();
+               MaterialFunctor mf;
+               mf.forEachMaterialInScene<EffectsExporter>(sce, *this);
 
-       closeLibrary();
+               closeLibrary();
+       }
 }
 
 void EffectsExporter::operator()(Material *ma, Object *ob)
index 3a3de95458b5ceb42120a5c2347d1cf9ca26faed..8fe7ef31da4fff7cdd93d0c542c9fd08941f559a 100644 (file)
@@ -57,10 +57,11 @@ public:
                                                                                        /*COLLADASW::Surface *surface*/);
        
        COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a);
-       
-       //returns the array of mtex indices which have image 
-       //need this for exporting textures
+private:
+       /** Fills the array of mtex indices which have image. Used for exporting images. */
        void createTextureIndices(Material *ma, std::vector<int> &indices);
+       
+       bool hasEffects(Scene *sce);
 };
 
 #endif
index a2d9cb15ab17d7401cd937bd0339b4c036f7123c..b7a5ef4c4e453f4303a18147a39dc9b62a98b120 100644 (file)
 ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const char* filename) : COLLADASW::LibraryImages(sw), mfilename(filename)
 {}
 
+bool ImagesExporter::hasImages(Scene *sce)
+{
+       Base *base = (Base *)sce->base.first;
+       
+       while(base) {
+               Object *ob= base->object;
+               int a;
+               for(a = 0; a < ob->totcol; a++)
+               {
+                       Material *ma = give_current_material(ob, a+1);
+
+                       // no material, but check all of the slots
+                       if (!ma) continue;
+                       int b;
+                       for (b = 0; b < MAX_MTEX; b++) {
+                               MTex *mtex = ma->mtex[b];
+                               if (mtex && mtex->tex && mtex->tex->ima) return true;
+                       }
+
+               }
+               base= base->next;
+       }
+       return false;
+}
+
 void ImagesExporter::exportImages(Scene *sce)
 {
-       openLibrary();
-       MaterialFunctor mf;
-       mf.forEachMaterialInScene<ImagesExporter>(sce, *this);
+       if(hasImages(sce)) {
+               openLibrary();
+               MaterialFunctor mf;
+               mf.forEachMaterialInScene<ImagesExporter>(sce, *this);
 
-       closeLibrary();
+               closeLibrary();
+       }
 }
 
 void ImagesExporter::operator()(Material *ma, Object *ob)
index 901e6be3ecbf6b29ece808b9528e0fadc32b497f..04e3010dc7a2bf84fb3b5143da4094184f16e9b9 100644 (file)
@@ -49,6 +49,8 @@ public:
        
        void exportImages(Scene *sce);
        void operator()(Material *ma, Object *ob);
+private:
+       bool hasImages(Scene *sce);
 };
 
 #endif