Blender  V3.3
MaterialExporter.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include <string>
10 #include <vector>
11 
12 #include "COLLADASWLibraryMaterials.h"
13 #include "COLLADASWStreamWriter.h"
14 
15 #include "BKE_material.h"
16 
17 #include "DNA_material_types.h"
18 #include "DNA_object_types.h"
19 #include "DNA_scene_types.h"
20 
21 #include "ExportSettings.h"
22 #include "GeometryExporter.h"
23 #include "Materials.h"
24 #include "collada_internal.h"
25 
26 class MaterialsExporter : COLLADASW::LibraryMaterials {
27  public:
28  MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
29  void exportMaterials(Scene *sce);
30  void operator()(Material *ma, Object *ob);
31 
32  private:
33  bool hasMaterials(Scene *sce);
34  BCExportSettings &export_settings;
35 };
36 
37 // used in forEachMaterialInScene
38 template<class Functor> class ForEachMaterialFunctor {
39  std::vector<std::string>
40  mMat; /* contains list of material names, to avoid duplicate calling of f */
41  Functor *f;
42 
43  public:
44  ForEachMaterialFunctor(Functor *f) : f(f)
45  {
46  }
47 
48  void operator()(Object *ob)
49  {
50  int a;
51  for (a = 0; a < ob->totcol; a++) {
52 
53  Material *ma = BKE_object_material_get(ob, a + 1);
54 
55  if (!ma) {
56  continue;
57  }
58 
59  std::string translated_id = translate_id(id_name(ma));
60  if (find(mMat.begin(), mMat.end(), translated_id) == mMat.end()) {
61  (*this->f)(ma, ob);
62 
63  mMat.push_back(translated_id);
64  }
65  }
66  }
67 };
68 
70  /* calls f for each unique material linked to each object in sce
71  * f should have */
72  // void operator()(Material *ma)
73  template<class Functor>
74  void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
75  {
77  GeometryFunctor gf;
79  }
80 };
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
Object is a sort of wrapper for general info.
ForEachMaterialFunctor(Functor *f)
void operator()(Object *ob)
void operator()(Material *ma, Object *ob)
MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void exportMaterials(Scene *sce)
std::string translate_id(const char *idString)
std::string id_name(void *id)
ccl_gpu_kernel_postfix ccl_global float int int int sw
static unsigned a[3]
Definition: RandGen.cpp:78
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)