2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2010-10-06 13:21:08 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup collada
|
2011-02-27 20:30:35 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-10-06 13:21:08 +00:00
|
|
|
#include "MaterialExporter.h"
|
2010-10-24 07:55:56 +00:00
|
|
|
#include "COLLADABUUtils.h"
|
2010-10-06 13:21:08 +00:00
|
|
|
#include "collada_internal.h"
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
|
2019-05-23 12:17:17 +02:00
|
|
|
BCExportSettings &export_settings)
|
2019-04-17 06:17:24 +02:00
|
|
|
: COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
|
2012-06-20 16:43:48 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* pass */
|
2012-06-12 22:05:33 +00:00
|
|
|
}
|
2010-10-06 13:21:08 +00:00
|
|
|
|
2011-09-07 18:23:30 +00:00
|
|
|
void MaterialsExporter::exportMaterials(Scene *sce)
|
2010-10-06 13:21:08 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
if (hasMaterials(sce)) {
|
|
|
|
|
openLibrary();
|
2010-10-06 13:21:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
MaterialFunctor mf;
|
|
|
|
|
mf.forEachMaterialInExportSet<MaterialsExporter>(
|
2019-05-23 12:17:17 +02:00
|
|
|
sce, *this, this->export_settings.get_export_set());
|
2010-10-06 13:21:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
closeLibrary();
|
|
|
|
|
}
|
2011-07-28 00:08:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool MaterialsExporter::hasMaterials(Scene *sce)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
LinkNode *node;
|
2019-05-23 12:17:17 +02:00
|
|
|
for (node = this->export_settings.get_export_set(); node; node = node->next) {
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *ob = (Object *)node->link;
|
|
|
|
|
int a;
|
|
|
|
|
for (a = 0; a < ob->totcol; a++) {
|
|
|
|
|
Material *ma = give_current_material(ob, a + 1);
|
2011-07-28 00:08:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
// no material, but check all of the slots
|
|
|
|
|
if (!ma)
|
|
|
|
|
continue;
|
2011-07-28 00:08:03 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2010-10-06 13:21:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MaterialsExporter::operator()(Material *ma, Object *ob)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
std::string mat_name = encode_xml(id_name(ma));
|
|
|
|
|
std::string mat_id = get_material_id(ma);
|
|
|
|
|
std::string eff_id = get_effect_id(ma);
|
2010-10-06 13:21:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
openMaterial(mat_id, mat_name);
|
|
|
|
|
addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, eff_id));
|
2010-10-06 13:21:08 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
closeMaterial();
|
2010-10-06 13:21:08 +00:00
|
|
|
}
|