Blender V4.3
MaterialExporter.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2002-2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "MaterialExporter.h"
10#include "COLLADABUUtils.h"
11#include "collada_internal.h"
12
13MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw,
14 BCExportSettings &export_settings)
15 : COLLADASW::LibraryMaterials(sw), export_settings(export_settings)
16{
17 /* pass */
18}
19
21{
22 if (hasMaterials(sce)) {
23 openLibrary();
24
27 sce, *this, this->export_settings.get_export_set());
28
29 closeLibrary();
30 }
31}
32
33bool MaterialsExporter::hasMaterials(Scene *sce)
34{
36 for (node = this->export_settings.get_export_set(); node; node = node->next) {
37 Object *ob = (Object *)node->link;
38 int a;
39 for (a = 0; a < ob->totcol; a++) {
40 Material *ma = BKE_object_material_get(ob, a + 1);
41
42 /* no material, but check all of the slots */
43 if (!ma) {
44 continue;
45 }
46
47 return true;
48 }
49 }
50 return false;
51}
52
54{
55 std::string mat_name = encode_xml(id_name(ma));
56 std::string mat_id = get_material_id(ma);
57 std::string eff_id = get_effect_id(ma);
58
59 openMaterial(mat_id, mat_name);
60 addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, eff_id));
61
62 closeMaterial();
63}
struct Material * BKE_object_material_get(struct Object *ob, short act)
void operator()(Material *ma, Object *ob)
MaterialsExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
void exportMaterials(Scene *sce)
std::string encode_xml(const std::string &xml)
std::string get_material_id(Material *mat)
std::string get_effect_id(Material *mat)
std::string id_name(void *id)
OperationNode * node
void forEachMaterialInExportSet(Scene *sce, Functor &f, LinkNode *export_set)