[Bf-blender-cvs] [a2a301bdb96] master: collada: change image export: export either UV Textures or Materials. This 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)

Gaia Clary noreply at git.blender.org
Sat Jun 24 22:17:18 CEST 2017


Commit: a2a301bdb96387b5b70ef82e5e9329ce1b5b5c75
Author: Gaia Clary
Date:   Sat Jun 24 22:09:08 2017 +0200
Branches: master
https://developer.blender.org/rBa2a301bdb96387b5b70ef82e5e9329ce1b5b5c75

collada: change image export: export either UV Textures or Materials. This
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)

===================================================================

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

===================================================================

diff --git a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
index 7825a4d0f32..deb23d76d91 100644
--- a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
+++ b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_rigged.py
@@ -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
diff --git a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_static.py b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_static.py
index 9e2efcaa727..ca9de8bf005 100644
--- a/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_static.py
+++ b/release/scripts/presets/operator/wm.collada_export/sl_plus_open_sim_static.py
@@ -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
diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp
index 9348f3b3285..d2495a8cb9f 100644
--- a/source/blender/collada/ArmatureExporter.cpp
+++ b/source/blender/collada/ArmatureExporter.cpp
@@ -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;
diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp
index 1c2642e8313..5cd5e6d271a 100644
--- a/source/blender/collada/ControllerExporter.cpp
+++ b/source/blender/collada/ControllerExporter.cpp
@@ -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;
diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp
index 76b51148509..4ce88d96888 100644
--- a/source/blender/collada/EffectExporter.cpp
+++ b/source/blender/collada/EffectExporter.cpp
@@ -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);
diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h
index de91f68a492..6d90edd2f67 100644
--- a/source/blender/collada/ExportSettings.h
+++ b/source/blender/collada/ExportSettings.h
@@ -28,7 +28,6 @@
 #define __EXPORTSETTINGS_H__
 
 #include "collada.h"
-#include "collada.h"
 
 struct ExportSettings {
 public:
@@ -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;
diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp
index aac41e2e93c..a5ddd3fb990 100644
--- a/source/blender/collada/ImageExporter.cpp
+++ b/source/blender/collada/ImageExporter.cpp
@@ -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();
 	}
 
diff --git a/source/blender/collada/InstanceWriter.cpp b/source/blender/collada/InstanceWriter.cpp
index 71371d280df..87a38ac6295 100644
--- a/source/blender/collada/InstanceWriter.cpp
+++ b/source/blender/collada/InstanceWriter.cpp
@@ -32,16 +32,16 @@
 #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);
 		}
 	}
diff --git a/source/blender/collada/MaterialExporter.cpp b/source/blender/collada/MaterialExporter.cpp
index 4aece997f72..a91487094fa 100644
--- a/source/blender/collada/MaterialExporter.cpp
+++ b/source/blender/collada/MaterialExporter.cpp
@@ -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)
diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp
index 30cd6ddf197..73945539931 100644
--- a/source/blender/collada/SceneExporter.cpp
+++ b/source/blender/collada/SceneExporter.cpp
@@ -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();
 		}
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index bfe3180909b..024bc4a4a5c 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -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        = defor

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list