Blender  V2.93
MaterialExporter.h
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 #pragma once
22 
23 #include <string>
24 #include <vector>
25 
26 #include "COLLADASWLibraryMaterials.h"
27 #include "COLLADASWStreamWriter.h"
28 
29 #include "BKE_material.h"
30 
31 #include "DNA_material_types.h"
32 #include "DNA_object_types.h"
33 #include "DNA_scene_types.h"
34 
35 #include "ExportSettings.h"
36 #include "GeometryExporter.h"
37 #include "Materials.h"
38 #include "collada_internal.h"
39 
40 class MaterialsExporter : COLLADASW::LibraryMaterials {
41  public:
42  MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
43  void exportMaterials(Scene *sce);
44  void operator()(Material *ma, Object *ob);
45 
46  private:
47  bool hasMaterials(Scene *sce);
48  BCExportSettings &export_settings;
49 };
50 
51 // used in forEachMaterialInScene
52 template<class Functor> class ForEachMaterialFunctor {
53  std::vector<std::string>
54  mMat; /* contains list of material names, to avoid duplicate calling of f */
55  Functor *f;
56 
57  public:
58  ForEachMaterialFunctor(Functor *f) : f(f)
59  {
60  }
61 
62  void operator()(Object *ob)
63  {
64  int a;
65  for (a = 0; a < ob->totcol; a++) {
66 
67  Material *ma = BKE_object_material_get(ob, a + 1);
68 
69  if (!ma) {
70  continue;
71  }
72 
73  std::string translated_id = translate_id(id_name(ma));
74  if (find(mMat.begin(), mMat.end(), translated_id) == mMat.end()) {
75  (*this->f)(ma, ob);
76 
77  mMat.push_back(translated_id);
78  }
79  }
80  }
81 };
82 
84  /* calls f for each unique material linked to each object in sce
85  * f should have */
86  // void operator()(Material *ma)
87  template<class Functor>
88  void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
89  {
91  GeometryFunctor gf;
93  }
94 };
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:697
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)
static unsigned a[3]
Definition: RandGen.cpp:92
void forEachMeshObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)