Collada: Exporter now only exports either 'Materials' or 'UV Textures as Materials...
authorGaia Clary <gaia.clary@machinimatrix.org>
Sun, 25 Jun 2017 20:06:04 +0000 (22:06 +0200)
committerGaia Clary <gaia.clary@machinimatrix.org>
Sun, 25 Jun 2017 20:06:42 +0000 (22:06 +0200)
source/blender/collada/EffectExporter.cpp
source/blender/collada/GeometryExporter.cpp
source/blender/collada/ImageExporter.cpp
source/blender/collada/InstanceWriter.cpp
source/blender/collada/MaterialExporter.cpp
source/blender/collada/collada.h
source/blender/editors/io/io_collada.c

index e0c81cfc54bd4059882d9acc39bb67e4806437b2..55dc936939cc9e8be9e3420e74b33210704ae666 100644 (file)
@@ -84,7 +84,7 @@ void EffectsExporter::exportEffects(Scene *sce)
                                closeLibrary();
                }
        }
-       else if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV) {
+       else {
                std::set<Object *> uv_textured_obs = bc_getUVTexturedObjects(sce, !this->export_settings->active_uv_only);
                std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
                if (uv_images.size() > 0) {
@@ -212,8 +212,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
 {
        // create a list of indices to textures of type TEX_IMAGE
        std::vector<int> tex_indices;
-       if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT)
-               createTextureIndices(ma, tex_indices);
+       createTextureIndices(ma, tex_indices);
 
        openEffect(translate_id(id_name(ma)) + "-effect");
        
@@ -347,58 +346,6 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
                }
        }
 
-       int active_uv_layer = -1;
-       std::set<Image *> uv_textures;
-       if (ob->type == OB_MESH && ob->totcol && this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV) {
-               bool active_uv_only = this->export_settings->active_uv_only;
-               Mesh *me     = (Mesh *) ob->data;
-               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 (!active_uv_only || active_uv_layer == i)
-                       {
-                               if (me->pdata.layers[i].type == CD_MTEXPOLY) {
-                                       MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
-                                       MPoly *mpoly = me->mpoly;
-                                       for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
-
-                                               Material *mat = give_current_material(ob, mpoly->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] = &samplers[a];
-                                                               im_samp_map[key] = b;
-                                                               b++;
-                                                               a++;
-                                                               uv_textures.insert(ima);
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               }
-       }
-
        // used as fallback when MTex->uvname is "" (this is pretty common)
        // it is indeed the correct value to use in that case
        std::string active_uv(bc_get_active_uvlayer_name(ob));
@@ -421,21 +368,6 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
                writeTextures(ep, key, sampler, t, ima, uvname);
        }
 
-       if (active_uv_layer > -1) {
-               // Export only UV textures assigned to active UV Layer (sounds reasonable, but is that correct?)
-               std::set<Image *>::iterator uv_t_iter;
-
-               for (uv_t_iter = uv_textures.begin(); uv_t_iter != uv_textures.end(); uv_t_iter++) {
-                       Image *ima = *uv_t_iter;
-                       std::string key(id_name(ima));
-                       key = translate_id(key);
-                       int i = im_samp_map[key];
-                       COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i];
-                       ep.setDiffuse(createTexture(ima, active_uv, sampler), false, "diffuse");
-                       ep.setShaderType(COLLADASW::EffectProfile::PHONG);
-               }
-       }
-
        // performs the actual writing
        ep.addProfileElements();
        bool twoSided = false;
index 3514f31b881b38071570e225288f98f948f94ad7..b8b1ff7fd95f42412a236b560a3afe21a82f1bf0 100644 (file)
@@ -135,23 +135,23 @@ void GeometryExporter::operator()(Object *ob)
        // Only create Polylists if number of faces > 0
        if (me->totface > 0) {
                // XXX slow
-               if (ob->totcol && this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
-                       for (int a = 0; a < ob->totcol; a++) {
-                               createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
-                       }
-               }
-               else {
-                       std::set<Image *> uv_images = bc_getUVImages(ob, !this->export_settings->active_uv_only);
-                       if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV && uv_images.size() > 0) {
-                               bool all_uv_layers = !this->export_settings->active_uv_only;
-                               std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
-                               createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind);
+               std::set<Image *> uv_images = bc_getUVImages(ob, !this->export_settings->active_uv_only);
+               if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT || uv_images.size() == 0) {
+                       if (ob->totcol) {
+                               for (int a = 0; a < ob->totcol; a++) {
+                                       createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
+                               }
                        }
                        else {
                                int i = 0;
                                createPolylist(i, has_uvs, has_color, ob, me, geom_id, norind);
                        }
                }
+               else {
+                       bool all_uv_layers = !this->export_settings->active_uv_only;
+                       std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
+                       createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind);
+               }
        }
        
        closeMesh();
index c982ca6e84374ac1f0ee373cb9e552d34fd176f8..93be7de62361d500241f5ef6d38de6ecaf794452 100644 (file)
@@ -242,7 +242,7 @@ void ImagesExporter::exportImages(Scene *sce)
        if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
                mf.forEachMaterialInExportSet<ImagesExporter>(sce, *this, this->export_settings->export_set);
        }
-       else if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV) {
+       else {
                export_UV_Images();
        }
 
index 776d9750175c716b08e0a01673989aa8c1480b93..de1a407546276fdb4ba868d8b5a54d349957447b 100644 (file)
@@ -77,7 +77,7 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia
                }
        }
 
-       else if (export_texture_type == BC_TEXTURE_TYPE_MAT) {
+       else {
                for (int a = 0; a < ob->totcol; a++) {
                        Material *ma = give_current_material(ob, a + 1);
                        if (ma) {
index 94e9b7661e4e33dca32d1b1bca37699a9e8ae0c8..6e6cc24be203329648f7641ba55be0096406839c 100644 (file)
@@ -50,8 +50,7 @@ void MaterialsExporter::exportMaterials(Scene *sce)
                }
        }
 
-       else if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV)
-       {
+       else {
                std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
                if (uv_images.size() > 0) {
                        openLibrary();
index 99c749421a4e5b76399240ea787fe83ec38387ed..d31f5a8ba6242ff0bd4f37a1df7266a6b776416d 100644 (file)
@@ -47,9 +47,8 @@ typedef enum BC_export_transformation_type {
 } BC_export_transformation_type;
 
 typedef enum BC_export_texture_type {
-       BC_TEXTURE_TYPE_NONE,
-       BC_TEXTURE_TYPE_UV,
-       BC_TEXTURE_TYPE_MAT
+       BC_TEXTURE_TYPE_MAT,
+       BC_TEXTURE_TYPE_UV
 } BC_export_texture_type;
 
 struct bContext;
index c065c8d78c8ce5e36c60c2ed4793bdc5786c142c..cead08afd6150f9a48c124bed7186813bf5875ec 100644 (file)
@@ -321,9 +321,8 @@ void WM_OT_collada_export(wmOperatorType *ot)
        };
 
        static EnumPropertyItem prop_bc_export_texture_type[] = {
-               { BC_TEXTURE_TYPE_NONE, "none", 0, "No Textures", "Do not export any image based Textures" },
-               { BC_TEXTURE_TYPE_UV, "uv", 0, "UV Textures", "Export UV Textures (Face textures)" },
-               { BC_TEXTURE_TYPE_MAT, "mat", 0, "Material Textures", "Export Material Textures" },
+               { BC_TEXTURE_TYPE_MAT, "mat", 0, "Materials", "Export Materials" },
+               { BC_TEXTURE_TYPE_UV, "uv", 0, "UV Textures", "Export UV Textures (Face textures) as materials" },
                { 0, NULL, 0, NULL, NULL }
        };