Blender  V3.3
InstanceWriter.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <sstream>
8 #include <string>
9 
10 #include "COLLADASWInstanceMaterial.h"
11 
12 #include "BKE_customdata.h"
13 #include "BKE_material.h"
14 
15 #include "DNA_mesh_types.h"
16 
17 #include "InstanceWriter.h"
18 #include "collada_internal.h"
19 #include "collada_utils.h"
20 
21 void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial &bind_material,
22  Object *ob,
23  bool active_uv_only)
24 {
25  for (int a = 0; a < ob->totcol; a++) {
26  Material *ma = BKE_object_material_get(ob, a + 1);
27 
28  COLLADASW::InstanceMaterialList &iml = bind_material.getInstanceMaterialList();
29 
30  if (ma) {
31  std::string matid(get_material_id(ma));
32  matid = translate_id(matid);
33  std::ostringstream ostr;
34  ostr << matid;
35  COLLADASW::InstanceMaterial im(ostr.str(),
36  COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
37 
38  // create <bind_vertex_input> for each uv map
39  Mesh *me = (Mesh *)ob->data;
40 
41  int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
42 
43  int map_index = 0;
44  int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV);
45  for (int b = 0; b < num_layers; b++) {
46  if (!active_uv_only || b == active_uv_index) {
47  char *name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, b);
48  im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
49  }
50  }
51 
52  iml.push_back(im);
53  }
54  }
55 }
std::string EMPTY_STRING
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_active_layer_index(const struct CustomData *data, int type)
int CustomData_number_of_layers(const struct CustomData *data, int type)
General operations, lookup, etc. for materials.
struct Material * BKE_object_material_get(struct Object *ob, short act)
Definition: material.c:687
@ CD_MLOOPUV
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)
char * bc_CustomData_get_layer_name(const CustomData *data, int type, int n)
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
CustomData ldata
void * data