Collada: fixed export when 'active UV Layer only' was selected
authorGaia Clary <gaia.clary@machinimatrix.org>
Wed, 15 Aug 2012 22:08:22 +0000 (22:08 +0000)
committerGaia Clary <gaia.clary@machinimatrix.org>
Wed, 15 Aug 2012 22:08:22 +0000 (22:08 +0000)
source/blender/collada/EffectExporter.cpp
source/blender/collada/GeometryExporter.cpp
source/blender/collada/ImageExporter.cpp
source/blender/collada/InstanceWriter.cpp

index 2d9ccc3e3ef5ad84f2cdc93440bff4d22e23007d..dd59fb9fb910dbfc07c01e0699179cfcd20ad482 100644 (file)
@@ -313,42 +313,48 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
 
        std::set<Image *> uv_textures;
        if (ob->type == OB_MESH && ob->totcol && this->export_settings->include_uv_textures) {
+               bool active_uv_only = this->export_settings->active_uv_only;
                Mesh *me     = (Mesh *) ob->data;
+               int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
+
                BKE_mesh_tessface_ensure(me);
                for (int i = 0; i < me->pdata.totlayer; i++) {
-                       if (me->pdata.layers[i].type == CD_MTEXPOLY) {
-                               MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
-                               MFace *mface = me->mface;
-                               for (int j = 0; j < me->totpoly; j++, mface++, txface++) {
-
-                                       Material *mat = give_current_material(ob, mface->mat_nr + 1);
-                                       if (mat != ma) 
-                                               continue;
-
-                                       Image *ima = txface->tpage;
-                                       if (ima == NULL)
-                                               continue;
-
-
-                                       bool not_in_list = uv_textures.find(ima)==uv_textures.end();
-                                       if (not_in_list) {
-                                               std::string name = id_name(ima);
-                                               std::string key(name);
-                                               key = translate_id(key);
-
-                                               // create only one <sampler>/<surface> pair for each unique image
-                                               if (im_samp_map.find(key) == im_samp_map.end()) {
-                                                       //<newparam> <sampler> <source>
-                                                       COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
-                                                                                                          key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
-                                                                                                          key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
-                                                       sampler.setImageId(key);
-                                                       samplers[a] = sampler;
-                                                       samp_surf[b][0] = &samplers[a];
-                                                       im_samp_map[key] = b;
-                                                       b++;
-                                                       a++;
-                                                       uv_textures.insert(ima);
+                       if (!active_uv_only || active_uv_layer == i)
+                       {
+                               if (me->pdata.layers[i].type == CD_MTEXPOLY) {
+                                       MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
+                                       MFace *mface = me->mface;
+                                       for (int j = 0; j < me->totpoly; j++, mface++, txface++) {
+
+                                               Material *mat = give_current_material(ob, mface->mat_nr + 1);
+                                               if (mat != ma) 
+                                                       continue;
+
+                                               Image *ima = txface->tpage;
+                                               if (ima == NULL)
+                                                       continue;
+
+
+                                               bool not_in_list = uv_textures.find(ima)==uv_textures.end();
+                                               if (not_in_list) {
+                                                       std::string name = id_name(ima);
+                                                       std::string key(name);
+                                                       key = translate_id(key);
+
+                                                       // create only one <sampler>/<surface> pair for each unique image
+                                                       if (im_samp_map.find(key) == im_samp_map.end()) {
+                                                               //<newparam> <sampler> <source>
+                                                               COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
+                                                                                                                  key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
+                                                                                                                  key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
+                                                               sampler.setImageId(key);
+                                                               samplers[a] = sampler;
+                                                               samp_surf[b][0] = &samplers[a];
+                                                               im_samp_map[key] = b;
+                                                               b++;
+                                                               a++;
+                                                               uv_textures.insert(ima);
+                                                       }
                                                }
                                        }
                                }
index 29ffcf53ee96467f8282f9a83dcd655f1e455b34..c7ad2ff39754404e8e37189989b7422ceb014155 100644 (file)
@@ -279,15 +279,18 @@ void GeometryExporter::createPolylist(short material_index,
                
        // if mesh has uv coords writes <input> for TEXCOORD
        int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
-
+       int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1;
        for (i = 0; i < num_layers; i++) {
-               // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
-               COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
-                                       makeUrl(makeTexcoordSourceId(geom_id, i)),
-                                       2, // offset always 2, this is only until we have optimized UV sets
-                                       i  // set number equals UV map index
-                                       );
-               til.push_back(input3);
+               if (!this->export_settings->active_uv_only || i == active_uv_index) {
+
+                       // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
+                       COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
+                                                                       makeUrl(makeTexcoordSourceId(geom_id, i)),
+                                                                       2, // offset always 2, this is only until we have optimized UV sets
+                                                                       i  // set number equals UV map index
+                                                                       );
+                       til.push_back(input3);
+               }
        }
 
        if (has_color) {
index 206dc09fe8b214d29bf1a8a56ff3af3e8d8bcce6..66dcec7d8e4d36e58eb6e5fd33bcae6652fa4cd6 100644 (file)
@@ -151,25 +151,31 @@ void ImagesExporter::export_UV_Images()
 {
        std::set<Image *> uv_textures;
        LinkNode *node;
-       bool use_copies = this->export_settings->use_texture_copies;
+       bool use_texture_copies = this->export_settings->use_texture_copies;
+       bool active_uv_only     = this->export_settings->active_uv_only;
+
        for (node = this->export_settings->export_set; node; node = node->next) {
                Object *ob = (Object *)node->link;
                if (ob->type == OB_MESH && ob->totcol) {
                        Mesh *me     = (Mesh *) ob->data;
                        BKE_mesh_tessface_ensure(me);
+                       int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
                        for (int i = 0; i < me->pdata.totlayer; i++) {
                                if (me->pdata.layers[i].type == CD_MTEXPOLY) {
-                                       MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
-                                       for (int j = 0; j < me->totpoly; j++, txface++) {
-
-                                               Image *ima = txface->tpage;
-                                               if (ima == NULL)
-                                                       continue;
-
-                                               bool not_in_list = uv_textures.find(ima) == uv_textures.end();
-                                               if (not_in_list) {
-                                                               uv_textures.insert(ima);
-                                                               export_UV_Image(ima, use_copies);
+                                       if (!active_uv_only || active_uv_layer == i)
+                                       {
+                                               MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
+                                               for (int j = 0; j < me->totpoly; j++, txface++) {
+
+                                                       Image *ima = txface->tpage;
+                                                       if (ima == NULL)
+                                                               continue;
+
+                                                       bool not_in_list = uv_textures.find(ima) == uv_textures.end();
+                                                       if (not_in_list) {
+                                                                       uv_textures.insert(ima);
+                                                                       export_UV_Image(ima, use_texture_copies);
+                                                       }
                                                }
                                        }
                                }
index be45d5295e5d9a4c6daf392aa74f4d27eae4698b..71371d280dfdb75c607b6b293638400413a76a61 100644 (file)
@@ -63,7 +63,7 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia
                        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, map_index);
+                                       char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
                                        im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
                                }
                        }