diff options
author | João Araújo <jaraujo98@gmail.com> | 2017-07-26 13:25:24 +0300 |
---|---|---|
committer | João Araújo <jaraujo98@gmail.com> | 2017-07-26 13:25:24 +0300 |
commit | 59908f5eb73670c97c5bb817290a0dac99089900 (patch) | |
tree | 709de097c1fac2ff7b172a8b50dc8a91d7b74860 /source/blender/collada/InstanceWriter.cpp | |
parent | 595f2ca2e06e07acaccc473982bde7a5ed644b50 (diff) | |
parent | edc6bec9d60204cb81d2e7533402630b076d0d32 (diff) |
Merge remote-tracking branch 'origin/master' into gsoc2016-improved_extrusiongsoc2016-improved_extrusion
Diffstat (limited to 'source/blender/collada/InstanceWriter.cpp')
-rw-r--r-- | source/blender/collada/InstanceWriter.cpp | 63 |
1 files changed, 48 insertions, 15 deletions
diff --git a/source/blender/collada/InstanceWriter.cpp b/source/blender/collada/InstanceWriter.cpp index 71371d280df..de1a4075462 100644 --- a/source/blender/collada/InstanceWriter.cpp +++ b/source/blender/collada/InstanceWriter.cpp @@ -32,43 +32,76 @@ #include "COLLADASWInstanceMaterial.h" extern "C" { - #include "BKE_customdata.h" - #include "BKE_material.h" - #include "DNA_mesh_types.h" +#include "BKE_customdata.h" +#include "BKE_material.h" +#include "DNA_mesh_types.h" } #include "InstanceWriter.h" #include "collada_internal.h" #include "collada_utils.h" -void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only) +void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type) { - for (int a = 0; a < ob->totcol; a++) { - Material *ma = give_current_material(ob, a + 1); - - COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList(); + bool all_uv_layers = !active_uv_only; + COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList(); - if (ma) { - std::string matid(get_material_id(ma)); - matid = translate_id(matid); + if (export_texture_type == BC_TEXTURE_TYPE_UV) + { + std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers); + std::set<Image *>::iterator uv_images_iter; + for (uv_images_iter = uv_images.begin(); + uv_images_iter != uv_images.end(); + uv_images_iter++) { + Image *ima = *uv_images_iter; + std::string matid(id_name(ima)); + matid = get_material_id_from_id(matid); std::ostringstream ostr; ostr << matid; COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid)); - + // create <bind_vertex_input> for each uv map Mesh *me = (Mesh *)ob->data; int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE); - + int map_index = 0; - int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) -1; + int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1; for (int b = 0; b < totlayer; b++) { if (!active_uv_only || b == active_uv_index) { char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b); im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++)); } } - + iml.push_back(im); } } + + else { + for (int a = 0; a < ob->totcol; a++) { + Material *ma = give_current_material(ob, a + 1); + if (ma) { + std::string matid(get_material_id(ma)); + matid = translate_id(matid); + std::ostringstream ostr; + ostr << matid; + COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid)); + + // create <bind_vertex_input> for each uv map + Mesh *me = (Mesh *)ob->data; + int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE); + + int map_index = 0; + int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1; + for (int b = 0; b < totlayer; b++) { + if (!active_uv_only || b == active_uv_index) { + char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b); + im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++)); + } + } + + iml.push_back(im); + } + } + } } |