COLLADA conformance: don't write empty libraries for effect, image and animation

This commit is contained in:
Nathan Letwory
2011-03-18 14:06:13 +00:00
parent b4743ccd8f
commit 7e53769d09
5 changed files with 93 additions and 18 deletions

View File

@@ -307,15 +307,19 @@ public:
AnimationExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) { this->sw = sw; } AnimationExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryAnimations(sw) { this->sw = sw; }
void exportAnimations(Scene *sce) void exportAnimations(Scene *sce)
{ {
this->scene = sce; if(hasAnimations(sce)) {
this->scene = sce;
openLibrary(); openLibrary();
forEachObjectInScene(sce, *this); forEachObjectInScene(sce, *this);
closeLibrary(); closeLibrary();
}
} }
// called for each exported object // 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) void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)

View File

@@ -55,15 +55,38 @@ static std::string getActiveUVLayerName(Object *ob)
return ""; return "";
} }
EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw) : COLLADASW::LibraryEffects(sw){} 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) void EffectsExporter::exportEffects(Scene *sce)
{ {
openLibrary(); if(hasEffects(sce)) {
MaterialFunctor mf; openLibrary();
mf.forEachMaterialInScene<EffectsExporter>(sce, *this); MaterialFunctor mf;
mf.forEachMaterialInScene<EffectsExporter>(sce, *this);
closeLibrary(); closeLibrary();
}
} }
void EffectsExporter::operator()(Material *ma, Object *ob) void EffectsExporter::operator()(Material *ma, Object *ob)

View File

@@ -57,10 +57,11 @@ public:
/*COLLADASW::Surface *surface*/); /*COLLADASW::Surface *surface*/);
COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a); COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a);
private:
//returns the array of mtex indices which have image /** Fills the array of mtex indices which have image. Used for exporting images. */
//need this for exporting textures
void createTextureIndices(Material *ma, std::vector<int> &indices); void createTextureIndices(Material *ma, std::vector<int> &indices);
bool hasEffects(Scene *sce);
}; };
#endif #endif

View File

@@ -46,13 +46,40 @@
ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const char* filename) : COLLADASW::LibraryImages(sw), mfilename(filename) 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) void ImagesExporter::exportImages(Scene *sce)
{ {
openLibrary(); if(hasImages(sce)) {
MaterialFunctor mf; openLibrary();
mf.forEachMaterialInScene<ImagesExporter>(sce, *this); MaterialFunctor mf;
mf.forEachMaterialInScene<ImagesExporter>(sce, *this);
closeLibrary(); closeLibrary();
}
} }
void ImagesExporter::operator()(Material *ma, Object *ob) void ImagesExporter::operator()(Material *ma, Object *ob)

View File

@@ -49,6 +49,8 @@ public:
void exportImages(Scene *sce); void exportImages(Scene *sce);
void operator()(Material *ma, Object *ob); void operator()(Material *ma, Object *ob);
private:
bool hasImages(Scene *sce);
}; };
#endif #endif