collada: change image export: export either UV Textures or Materials. This
authorGaia Clary <gaia.clary@machinimatrix.org>
Sat, 24 Jun 2017 20:09:08 +0000 (22:09 +0200)
committerGaia Clary <gaia.clary@machinimatrix.org>
Sat, 24 Jun 2017 20:16:47 +0000 (22:16 +0200)
avoids wrong texture data when multiple objects are exported. Note: This
commit might possiblyt not work fully. The full feature is added with the
next commit)

14 files changed:
release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_static.py
source/blender/collada/ArmatureExporter.cpp
source/blender/collada/ControllerExporter.cpp
source/blender/collada/EffectExporter.cpp
source/blender/collada/ExportSettings.h
source/blender/collada/ImageExporter.cpp
source/blender/collada/InstanceWriter.cpp
source/blender/collada/MaterialExporter.cpp
source/blender/collada/SceneExporter.cpp
source/blender/collada/collada.cpp
source/blender/collada/collada.h
source/blender/editors/io/io_collada.c
source/blender/makesrna/intern/rna_scene_api.c

index 7825a4d0f328689106fd6e04909a6ef7d874fb33..deb23d76d9153a1e5035db0d7ab41b0a15ef1fc8 100644 (file)
@@ -10,7 +10,7 @@ op.include_armatures = True
 op.include_shapekeys = False
 op.deform_bones_only = True
 op.active_uv_only = True
-op.include_uv_textures = True
+op.export_texture_type_selection = 'uv'
 op.use_texture_copies = True
 op.triangulate = True
 op.use_object_instantiation = False
index 9e2efcaa7275af59db11ffabaaa4611e2c27f371..ca9de8bf00547c5bd70ac6e8418c691158813f34 100644 (file)
@@ -10,7 +10,7 @@ op.include_armatures = False
 op.include_shapekeys = False
 op.deform_bones_only = False
 op.active_uv_only = True
-op.include_uv_textures = True
+op.export_texture_type_selection = 'uv'
 op.use_texture_copies = True
 op.triangulate = True
 op.use_object_instantiation = False
index 9348f3b32851bb0efad43f796d1e753bfc6ff3e2..d2495a8cb9f4dc38d8ad522bb8f94dbab21f8f7c 100644 (file)
@@ -116,7 +116,10 @@ bool ArmatureExporter::add_instance_controller(Object *ob)
                write_bone_URLs(ins, ob_arm, bone);
        }
 
-       InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
+       InstanceWriter::add_material_bindings(ins.getBindMaterial(), 
+               ob, 
+               this->export_settings->active_uv_only,
+               this->export_settings->export_texture_type);
                
        ins.add();
        return true;
index 1c2642e831366ac21fdaa4416e7f5ca5b5ab191d..5cd5e6d271a6d48f4ac6577245c3b75cb7691e74 100644 (file)
@@ -98,7 +98,10 @@ bool ControllerExporter::add_instance_controller(Object *ob)
                write_bone_URLs(ins, ob_arm, bone);
        }
 
-       InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
+       InstanceWriter::add_material_bindings(ins.getBindMaterial(),
+                   ob, 
+                       this->export_settings->active_uv_only,
+                       this->export_settings->export_texture_type);
                
        ins.add();
        return true;
index 76b5114850908ebbb2e27f94bfe291c8c0902b01..4ce88d96888185373247ae43e04c485f38fd7ddd 100644 (file)
@@ -176,7 +176,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->include_material_textures)
+       if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT)
                createTextureIndices(ma, tex_indices);
 
        openEffect(translate_id(id_name(ma)) + "-effect");
@@ -313,7 +313,7 @@ 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->include_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);
index de91f68a492d64fdf6675c098d634fbb39d4da86..6d90edd2f67b5bed349a94dc3c6e61f16f55b665 100644 (file)
@@ -27,7 +27,6 @@
 #ifndef __EXPORTSETTINGS_H__
 #define __EXPORTSETTINGS_H__
 
-#include "collada.h"
 #include "collada.h"
 
 struct ExportSettings {
@@ -42,8 +41,7 @@ public:
        bool deform_bones_only;
 
        bool active_uv_only;
-       bool include_uv_textures;
-       bool include_material_textures;
+       BC_export_texture_type export_texture_type;
        bool use_texture_copies;
 
        bool triangulate;
index aac41e2e93cfa14507091a448f89bbc379712cab..a5ddd3fb990fc441fe8c212839a5ce7fdf51e499 100644 (file)
@@ -232,11 +232,10 @@ void ImagesExporter::exportImages(Scene *sce)
        openLibrary();
 
        MaterialFunctor mf;
-       if (this->export_settings->include_material_textures) {
+       if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
                mf.forEachMaterialInExportSet<ImagesExporter>(sce, *this, this->export_settings->export_set);
        }
-
-       if (this->export_settings->include_uv_textures) {
+       else if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV) {
                export_UV_Images();
        }
 
index 71371d280dfdb75c607b6b293638400413a76a61..87a38ac6295499e10406358e3661bab3d3e46777 100644 (file)
 #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);
@@ -54,20 +54,20 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia
                        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);
                }
        }
index 4aece997f72d6ef1962de215a4d788a18a2855de..a91487094fa8be7152abc4c22b2cd3d52022cf4e 100644 (file)
@@ -38,14 +38,41 @@ MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSe
 
 void MaterialsExporter::exportMaterials(Scene *sce)
 {
-       if (hasMaterials(sce)) {
-               openLibrary();
+       if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT)
+       {
+               if (hasMaterials(sce)) {
+                       openLibrary();
 
-               MaterialFunctor mf;
-               mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);
+                       MaterialFunctor mf;
+                       mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);
 
-               closeLibrary();
+                       closeLibrary();
+               }
+       }
+#if 0
+       // Temporary discarded (to keep consistent commits)
+       else if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_UV)
+       {
+               std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
+               if (uv_images.size() > 0) {
+                       openLibrary();
+                       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));
+
+                               openMaterial(get_material_id_from_id(matid), translate_id(matid));
+                               std::string efid = translate_id(matid) + "-effect";
+                               addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));
+                               closeMaterial();
+                       }
+                       closeLibrary();
+               }
        }
+#endif
 }
 
 bool MaterialsExporter::hasMaterials(Scene *sce)
index 30cd6ddf197940f28c2e5819bfd7b20a1bf003cc..739455399313f92477be693a0893b80d7efb0fb0 100644 (file)
@@ -151,7 +151,10 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
                        COLLADASW::InstanceGeometry instGeom(mSW);
                        instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
                        instGeom.setName(translate_id(id_name(ob)));
-                       InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob, this->export_settings->active_uv_only);
+                       InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), 
+                                   ob, 
+                                       this->export_settings->active_uv_only, 
+                                       this->export_settings->export_texture_type);
 
                        instGeom.add();
                }
index bfe3180909b6c98d014ffa1eecc53a27c5506612..024bc4a4a5ca8e10172efd9ea8eb28be6f3a19de 100644 (file)
@@ -80,8 +80,7 @@ int collada_export(Scene *sce,
                    int deform_bones_only,
 
                                   int active_uv_only,
-                                  int include_uv_textures,
-                                  int include_material_textures,
+                                  BC_export_texture_type export_texture_type,
                                   int use_texture_copies,
 
                    int triangulate,
@@ -106,8 +105,7 @@ int collada_export(Scene *sce,
        export_settings.deform_bones_only        = deform_bones_only != 0;
 
        export_settings.active_uv_only           = active_uv_only != 0;
-       export_settings.include_uv_textures      = include_uv_textures != 0;
-       export_settings.include_material_textures= include_material_textures != 0;
+       export_settings.export_texture_type      = export_texture_type;
        export_settings.use_texture_copies       = use_texture_copies != 0;
 
        export_settings.triangulate                = triangulate != 0;
index 8035af59c8b1b39772018a090699f9c65a413d17..99c749421a4e5b76399240ea787fe83ec38387ed 100644 (file)
@@ -46,6 +46,12 @@ typedef enum BC_export_transformation_type {
        BC_TRANSFORMATION_TYPE_TRANSROTLOC
 } BC_export_transformation_type;
 
+typedef enum BC_export_texture_type {
+       BC_TEXTURE_TYPE_NONE,
+       BC_TEXTURE_TYPE_UV,
+       BC_TEXTURE_TYPE_MAT
+} BC_export_texture_type;
+
 struct bContext;
 struct Scene;
 
@@ -74,8 +80,7 @@ int collada_export(struct Scene *sce,
                    int deform_bones_only,
 
                    int active_uv_only,
-                   int include_uv_textures,
-                   int include_material_textures,
+                   BC_export_texture_type export_texture_type,
                    int use_texture_copies,
 
                    int triangulate,
@@ -84,9 +89,9 @@ int collada_export(struct Scene *sce,
                    int sort_by_name,
                    BC_export_transformation_type export_transformation_type,
 
-                                  int open_sim,
-                                  int limit_precision,
-                                  int keep_bind_info);
+                   int open_sim,
+                   int limit_precision,
+                   int keep_bind_info);
 
 #ifdef __cplusplus
 }
index 139c9817437c875e6a97b80e2694bc8893bffcd0..c065c8d78c8ce5e36c60c2ed4793bdc5786c142c 100644 (file)
@@ -87,8 +87,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        int include_shapekeys;
        int deform_bones_only;
 
-       int include_uv_textures;
-       int include_material_textures;
+       int export_texture_type;
        int use_texture_copies;
        int active_uv_only;
 
@@ -139,8 +138,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
        include_shapekeys        = RNA_boolean_get(op->ptr, "include_shapekeys");
        deform_bones_only        = RNA_boolean_get(op->ptr, "deform_bones_only");
 
-       include_uv_textures      = RNA_boolean_get(op->ptr, "include_uv_textures");
-       include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures");
+       export_texture_type      = RNA_enum_get(op->ptr, "export_texture_type_selection");
        use_texture_copies       = RNA_boolean_get(op->ptr, "use_texture_copies");
        active_uv_only           = RNA_boolean_get(op->ptr, "active_uv_only");
 
@@ -169,8 +167,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
                deform_bones_only,
 
                active_uv_only,
-               include_uv_textures,
-               include_material_textures,
+               export_texture_type,
                use_texture_copies,
 
                triangulate,
@@ -241,10 +238,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
        uiItemR(row, imfptr, "active_uv_only", 0, NULL, ICON_NONE);
 
        row = uiLayoutRow(box, false);
-       uiItemR(row, imfptr, "include_uv_textures", 0, NULL, ICON_NONE);
-
-       row = uiLayoutRow(box, false);
-       uiItemR(row, imfptr, "include_material_textures", 0, NULL, ICON_NONE);
+       uiItemR(row, imfptr, "export_texture_type_selection", 0, "", ICON_NONE);
 
        row = uiLayoutRow(box, false);
        uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE);
@@ -321,9 +315,16 @@ void WM_OT_collada_export(wmOperatorType *ot)
        };
 
        static EnumPropertyItem prop_bc_export_transformation_type[] = {
-               {BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use <matrix> to specify transformations"},
-               {BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use <translate>, <rotate>, <scale> to specify transformations"},
-               {0, NULL, 0, NULL, NULL}
+               { BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use <matrix> to specify transformations" },
+               { BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use <translate>, <rotate>, <scale> to specify transformations" },
+               { 0, NULL, 0, NULL, NULL }
+       };
+
+       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" },
+               { 0, NULL, 0, NULL, NULL }
        };
 
        ot->name = "Export COLLADA";
@@ -368,16 +369,9 @@ void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_boolean(func, "deform_bones_only", 0, "Deform Bones only",
                        "Only export deforming bones with armatures");
 
-
        RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map",
                        "Export only the selected UV Map");
 
-       RNA_def_boolean(func, "include_uv_textures", 0, "Include UV Textures",
-                       "Export textures assigned to the object UV Maps");
-
-       RNA_def_boolean(func, "include_material_textures", 0, "Include Material Textures",
-                       "Export textures assigned to the object Materials");
-
        RNA_def_boolean(func, "use_texture_copies", 1, "Copy",
                        "Copy textures to same folder where the .dae file is exported");
 
@@ -394,11 +388,20 @@ void WM_OT_collada_export(wmOperatorType *ot)
        RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name",
                        "Sort exported data by Object name");
 
+
        RNA_def_int(func, "export_transformation_type", 0, INT_MIN, INT_MAX,
-                   "Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
+               "Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
 
        RNA_def_enum(func, "export_transformation_type_selection", prop_bc_export_transformation_type, 0,
-                    "Transform", "Transformation type for translation, scale and rotation");
+               "Transform", "Transformation type for translation, scale and rotation");
+
+
+       RNA_def_int(func, "export_texture_type", 0, INT_MIN, INT_MAX,
+               "Texture Type", "Type for exported Textures (UV or MAT)", INT_MIN, INT_MAX);
+
+       RNA_def_enum(func, "export_texture_type_selection", prop_bc_export_texture_type, 0,
+               "Texture Type", "Type for exported Textures (UV or MAT)");
+
 
        RNA_def_boolean(func, "open_sim", 0, "Export to SL/OpenSim",
                        "Compatibility mode for SL, OpenSim and other compatible online worlds");
index a80e4c60127b335e731784dd7ab7cc32766d190d..2619d231adcaca39e21766ee2ee7a68c1dd0162c 100644 (file)
@@ -280,8 +280,7 @@ static void rna_Scene_collada_export(
         int include_shapekeys,
         int deform_bones_only,
         int active_uv_only,
-        int include_uv_textures,
-        int include_material_textures,
+               int export_texture_type,
         int use_texture_copies,
         int triangulate,
         int use_object_instantiation,
@@ -305,8 +304,7 @@ static void rna_Scene_collada_export(
                deform_bones_only,
 
                active_uv_only,
-               include_uv_textures,
-               include_material_textures,
+               export_texture_type,
                use_texture_copies,
 
                triangulate,
@@ -403,11 +401,8 @@ void RNA_api_scene(StructRNA *srna)
 
        RNA_def_boolean(func, "active_uv_only", false, "Only Selected UV Map", "Export only the selected UV Map");
 
-       RNA_def_boolean(func, "include_uv_textures", false,
-                       "Include UV Textures", "Export textures assigned to the object UV Maps");
-
-       RNA_def_boolean(func, "include_material_textures", false,
-                       "Include Material Textures", "Export textures assigned to the object Materials");
+       RNA_def_int(func, "export_texture_type", 0, INT_MIN, INT_MAX,
+               "Texture Type", "Type for exported Textures (UV or MAT)", INT_MIN, INT_MAX);
 
        RNA_def_boolean(func, "use_texture_copies", true,
                        "Copy", "Copy textures to same folder where the .dae file is exported");