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