Blender V4.3
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
9#pragma once
10
11#include <string>
12#include <vector>
13
14#include "COLLADASWLibraryMaterials.h"
15#include "COLLADASWStreamWriter.h"
16
17#include "BKE_material.h"
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 "Materials.h"
26#include "collada_internal.h"
27
28class MaterialsExporter : COLLADASW::LibraryMaterials {
29 public:
30 MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings);
31 void exportMaterials(Scene *sce);
32 void operator()(Material *ma, Object *ob);
33
34 private:
35 bool hasMaterials(Scene *sce);
36 BCExportSettings &export_settings;
37};
38
39/* Used in `forEachMaterialInScene`. */
40template<class Functor> class ForEachMaterialFunctor {
41 std::vector<std::string>
42 mMat; /* contains list of material names, to avoid duplicate calling of f */
43 Functor *f;
44
45 public:
46 ForEachMaterialFunctor(Functor *f) : f(f) {}
47
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 {
79 }
80};
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct 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)