Blender V4.3
InstanceWriter.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2010-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <sstream>
10#include <string>
11
12#include "COLLADASWInstanceMaterial.h"
13
14#include "BKE_customdata.hh"
15#include "BKE_material.h"
16
17#include "DNA_mesh_types.h"
18
19#include "InstanceWriter.h"
20#include "collada_internal.h"
21#include "collada_utils.h"
22
23void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial &bind_material,
24 Object *ob,
25 bool active_uv_only)
26{
27 for (int a = 0; a < ob->totcol; a++) {
28 Material *ma = BKE_object_material_get(ob, a + 1);
29
30 COLLADASW::InstanceMaterialList &iml = bind_material.getInstanceMaterialList();
31
32 if (ma) {
33 std::string matid(get_material_id(ma));
34 matid = translate_id(matid);
35 std::ostringstream ostr;
36 ostr << matid;
37 COLLADASW::InstanceMaterial im(ostr.str(),
38 COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
39
40 /* Create <bind_vertex_input> for each uv map. */
41 Mesh *mesh = (Mesh *)ob->data;
42
43 int num_layers = CustomData_number_of_layers(&mesh->corner_data, CD_PROP_FLOAT2);
44
45 int map_index = 0;
46 int active_uv_index = CustomData_get_active_layer_index(&mesh->corner_data, CD_PROP_FLOAT2);
47 for (int b = 0; b < num_layers; b++) {
48 if (!active_uv_only || b == active_uv_index) {
49 const char *name = bc_CustomData_get_layer_name(&mesh->corner_data, CD_PROP_FLOAT2, b);
50 im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
51 }
52 }
53
54 iml.push_back(im);
55 }
56 }
57}
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_active_layer_index(const CustomData *data, eCustomDataType type)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
@ CD_PROP_FLOAT2
void add_material_bindings(COLLADASW::BindMaterial &bind_material, Object *ob, bool active_uv_only)
std::string translate_id(const char *idString)
std::string get_material_id(Material *mat)
const char * bc_CustomData_get_layer_name(const CustomData *data, eCustomDataType type, int n)
local_group_size(16, 16) .push_constant(Type b