Blender  V2.93
MaterialExporter.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "MaterialExporter.h"
22 #include "COLLADABUUtils.h"
23 #include "collada_internal.h"
24 
25 MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
26  BCExportSettings &export_settings)
27  : COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
28 {
29  /* pass */
30 }
31 
33 {
34  if (hasMaterials(sce)) {
35  openLibrary();
36 
37  MaterialFunctor mf;
39  sce, *this, this->export_settings.get_export_set());
40 
41  closeLibrary();
42  }
43 }
44 
45 bool MaterialsExporter::hasMaterials(Scene *sce)
46 {
47  LinkNode *node;
48  for (node = this->export_settings.get_export_set(); node; node = node->next) {
49  Object *ob = (Object *)node->link;
50  int a;
51  for (a = 0; a < ob->totcol; a++) {
52  Material *ma = BKE_object_material_get(ob, a + 1);
53 
54  /* no material, but check all of the slots */
55  if (!ma) {
56  continue;
57  }
58 
59  return true;
60  }
61  }
62  return false;
63 }
64 
66 {
67  std::string mat_name = encode_xml(id_name(ma));
68  std::string mat_id = get_material_id(ma);
69  std::string eff_id = get_effect_id(ma);
70 
71  openMaterial(mat_id, mat_name);
72  addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, eff_id));
73 
74  closeMaterial();
75 }
std::string EMPTY_STRING
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
void operator()(Material *ma, Object *ob)
MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void exportMaterials(Scene *sce)
std::string get_material_id(Material *mat)
std::string encode_xml(std::string xml)
std::string get_effect_id(Material *mat)
std::string id_name(void *id)
OperationNode * node
static unsigned a[3]
Definition: RandGen.cpp:92
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)