Blender  V3.3
MaterialExporter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "MaterialExporter.h"
8 #include "COLLADABUUtils.h"
9 #include "collada_internal.h"
10 
11 MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
12  BCExportSettings &export_settings)
13  : COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
14 {
15  /* pass */
16 }
17 
19 {
20  if (hasMaterials(sce)) {
21  openLibrary();
22 
23  MaterialFunctor mf;
25  sce, *this, this->export_settings.get_export_set());
26 
27  closeLibrary();
28  }
29 }
30 
31 bool MaterialsExporter::hasMaterials(Scene *sce)
32 {
33  LinkNode *node;
34  for (node = this->export_settings.get_export_set(); node; node = node->next) {
35  Object *ob = (Object *)node->link;
36  int a;
37  for (a = 0; a < ob->totcol; a++) {
38  Material *ma = BKE_object_material_get(ob, a + 1);
39 
40  /* no material, but check all of the slots */
41  if (!ma) {
42  continue;
43  }
44 
45  return true;
46  }
47  }
48  return false;
49 }
50 
52 {
53  std::string mat_name = encode_xml(id_name(ma));
54  std::string mat_id = get_material_id(ma);
55  std::string eff_id = get_effect_id(ma);
56 
57  openMaterial(mat_id, mat_name);
58  addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, eff_id));
59 
60  closeMaterial();
61 }
std::string EMPTY_STRING
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
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
ccl_gpu_kernel_postfix ccl_global float int int int sw
static unsigned a[3]
Definition: RandGen.cpp:78
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)