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

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

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

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

@ -46,13 +46,40 @@
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)

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