[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21882] branches/soc-2009-chingachgook/ source/blender/collada: Fixed textures, images import/export.

Chingiz Dyussenov chingiz.ds at gmail.com
Sat Jul 25 16:09:15 CEST 2009


Revision: 21882
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21882
Author:   chingachgook
Date:     2009-07-25 16:09:15 +0200 (Sat, 25 Jul 2009)

Log Message:
-----------
Fixed textures, images import/export.

Modified Paths:
--------------
    branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
    branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-07-25 13:40:59 UTC (rev 21881)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-07-25 14:09:15 UTC (rev 21882)
@@ -18,6 +18,7 @@
 extern "C" 
 {
 #include "BKE_DerivedMesh.h"
+#include "BLI_util.h"
 }
 #include "BKE_scene.h"
 #include "BKE_global.h"
@@ -29,36 +30,36 @@
 
 #include "DocumentExporter.h"
 
-#include <COLLADASWAsset.h>
-#include <COLLADASWLibraryVisualScenes.h>
-#include <COLLADASWNode.h>
-#include <COLLADASWLibraryGeometries.h>
-#include <COLLADASWSource.h>
-#include <COLLADASWInstanceGeometry.h>
-#include <COLLADASWInputList.h>
-#include <COLLADASWPrimitves.h>
-#include <COLLADASWVertices.h>
-#include <COLLADASWLibraryAnimations.h>
-#include <COLLADASWLibraryImages.h>
-#include <COLLADASWLibraryEffects.h>
-#include <COLLADASWImage.h>
-#include <COLLADASWEffectProfile.h>
-#include <COLLADASWColorOrTexture.h>
-#include <COLLADASWParamTemplate.h>
-#include <COLLADASWParamBase.h>
-#include <COLLADASWSurfaceInitOption.h>
-#include <COLLADASWSampler.h>
-#include <COLLADASWScene.h>
-#include <COLLADASWSurface.h>
-#include <COLLADASWTechnique.h>
-#include <COLLADASWTexture.h>
-#include <COLLADASWLibraryMaterials.h>
-#include <COLLADASWBindMaterial.h>
-#include <COLLADASWLibraryCameras.h>
-#include <COLLADASWLibraryLights.h>
-#include <COLLADASWInstanceCamera.h>
-#include <COLLADASWInstanceLight.h>
-#include <COLLADASWCameraOptic.h>
+#include "COLLADASWAsset.h"
+#include "COLLADASWLibraryVisualScenes.h"
+#include "COLLADASWNode.h"
+#include "COLLADASWLibraryGeometries.h"
+#include "COLLADASWSource.h"
+#include "COLLADASWInstanceGeometry.h"
+#include "COLLADASWInputList.h"
+#include "COLLADASWPrimitves.h"
+#include "COLLADASWVertices.h"
+#include "COLLADASWLibraryAnimations.h"
+#include "COLLADASWLibraryImages.h"
+#include "COLLADASWLibraryEffects.h"
+#include "COLLADASWImage.h"
+#include "COLLADASWEffectProfile.h"
+#include "COLLADASWColorOrTexture.h"
+#include "COLLADASWParamTemplate.h"
+#include "COLLADASWParamBase.h"
+#include "COLLADASWSurfaceInitOption.h"
+#include "COLLADASWSampler.h"
+#include "COLLADASWScene.h"
+#include "COLLADASWSurface.h"
+#include "COLLADASWTechnique.h"
+#include "COLLADASWTexture.h"
+#include "COLLADASWLibraryMaterials.h"
+#include "COLLADASWBindMaterial.h"
+#include "COLLADASWLibraryCameras.h"
+#include "COLLADASWLibraryLights.h"
+#include "COLLADASWInstanceCamera.h"
+#include "COLLADASWInstanceLight.h"
+#include "COLLADASWCameraOptic.h"
 
 #include <vector>
 #include <algorithm> // std::find
@@ -706,9 +707,11 @@
 
 				Image *image = mtex->tex->ima;
 				std::string name(id_name(image));
-
+				char *ima_name;
+				BLI_split_dirfile_basic(image->name, NULL, ima_name);
+				
 				if (find(mImages.begin(), mImages.end(), name) == mImages.end()) {
-					COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(image->name)), name, "");
+					COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(ima_name)), name, "");
 					img.add(mSW);
 
 					mImages.push_back(name);

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-07-25 13:40:59 UTC (rev 21881)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-07-25 14:09:15 UTC (rev 21882)
@@ -41,6 +41,7 @@
 #include "ED_keyframing.h"
 #include "BKE_fcurve.h"
 #include "BKE_depsgraph.h"
+#include "BLI_util.h"
 }
 #include "BKE_armature.h"
 #include "BKE_mesh.h"
@@ -49,6 +50,7 @@
 #include "BKE_object.h"
 #include "BKE_image.h"
 #include "BKE_material.h"
+#include "BKE_utildefines.h"
 
 #include "BLI_arithb.h"
 #include "BLI_listbase.h"
@@ -141,9 +143,6 @@
 	std::map<COLLADAFW::UniqueId, Material*> uid_effect_map;
 	std::map<COLLADAFW::UniqueId, Camera*> uid_camera_map;
 	std::map<COLLADAFW::UniqueId, Lamp*> uid_lamp_map;
-	// maps for skinning
-	//std::map<COLLADAFW::UniqueId, bArmature*> uid_controller_map;
-	//std::map<COLLADAFW::UniqueId, Bone*> uid_joint_map;
 	std::map<COLLADAFW::UniqueId, COLLADAFW::UniqueId> skinid_meshid_map;
 	// maps for assigning textures to uv layers
 	std::map<COLLADAFW::TextureMapId, char*> set_layername_map;
@@ -322,32 +321,36 @@
 		// replace ob->data freeing the old one
 		Mesh *old_mesh = (Mesh*)ob->data;
 
-		const COLLADAFW::UniqueId& geom_uid = geom->getInstanciatedObjectId();
+		const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId();
+	 
 		// checking if node instanciates controller or geometry
 		if (isController) {
-			if (skinid_meshid_map.find(geom_uid) == skinid_meshid_map.end()) {
+			if (skinid_meshid_map.find(*geom_uid) == skinid_meshid_map.end()) {
 				fprintf(stderr, "Couldn't find a mesh UID by controller's UID.\n");
 				return NULL;
 			}
-			set_mesh(ob, uid_mesh_map[skinid_meshid_map[geom_uid]]);
+			geom_uid = &skinid_meshid_map[*geom_uid];
 		}
 		else {
-			if (uid_mesh_map.find(geom_uid) == uid_mesh_map.end()) {
+			if (uid_mesh_map.find(*geom_uid) == uid_mesh_map.end()) {
 				// XXX report to user
 				// this could happen if a mesh was not created
 				// (e.g. if it contains unsupported geometry)
 				fprintf(stderr, "Couldn't find a mesh by UID.\n");
 				return NULL;
 			}
-			set_mesh(ob, uid_mesh_map[geom_uid]);
 		}
+
+		set_mesh(ob, uid_mesh_map[*geom_uid]);
+
 		
 		if (old_mesh->id.us == 0) free_libblock(&G.main->mesh, old_mesh);
 		
 		Mesh *me = (Mesh*)ob->data;
-		MTex *mtex = NULL;
+		MTex *diffuse_mtex = NULL;
 		MTFace *tface = NULL;
-		char *layername = CustomData_get_layer_name(&me->fdata, CD_MTFACE, 0);
+		char layername[100];
+		bool first_time = true;
 		
 		// assign material indices to mesh faces
 		for (int k = 0; k < geom->getMaterialBindings().getCount(); k++) {
@@ -378,28 +381,26 @@
 				std::vector<MTex*> mtexes = index_mtex_map[tex_index];
 				std::vector<MTex*>::iterator it;
 				for (it = mtexes.begin(); it != mtexes.end(); it++) {
-					mtex = *it;
+					MTex *mtex = *it;
 					strcpy(mtex->uvname, uvname);
+					if (mtex->mapto == MAP_COL) {
+						diffuse_mtex = mtex;
+						if (first_time) {
+							tface = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE, mtex->uvname);
+							strcpy(layername, diffuse_mtex->uvname);
+							first_time = false;
+						}
+						else if (strcmp(diffuse_mtex->uvname, layername) != 0) {
+							tface = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE, mtex->uvname);
+							strcpy(layername, diffuse_mtex->uvname);
+						}
+					}
 				}	
 			}
-			mtex = NULL;
-			// find and save texture mapped to diffuse
-			for (l = 0; l < 18; l++) {
-				if (ma->mtex[l] != NULL && ma->mtex[l]->mapto == MAP_COL)
-					mtex = ma->mtex[l];
-			}
-			// get mtface for first uv layer
-			if (tface == NULL && mtex != NULL)
-				tface = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE, mtex->uvname);
-			// get mtface for next uv layer
-			else if(layername != NULL && mtex != NULL && strcmp(layername, mtex->uvname) != 0) {
-				tface = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE, mtex->uvname);
-				layername = mtex->uvname;
-			}
 			
 			assign_material(ob, ma, ob->totcol + 1);
 			
-			MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[geom_uid];
+			MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid];
 			COLLADAFW::MaterialId mat_id = geom->getMaterialBindings()[k].getMaterialId();
 			
 			// if there's geometry that uses this material,
@@ -416,9 +417,11 @@
 					while (l++ < prim.totface) {
 						prim.mface->mat_nr = k;
 						prim.mface++;
-						if (mtex != NULL && tface != NULL) {
-							tface->tpage = (Image*)mtex->tex->ima;
+						// if tface was set
+						// bind image to tface
+						if (tface) {
 							tface->mode = TF_TEX;
+							tface->tpage = (Image*)diffuse_mtex->tex->ima;
 							tface++;
 						}
 					}
@@ -791,7 +794,7 @@
 
 		// count totface
 		int totface = cmesh->getFacesCount();
-
+		
 		// allocate faces
 		me->mface = (MFace*)CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, totface);
 		me->totface = totface;
@@ -850,7 +853,7 @@
 					
 					set_face_indices(mface, indices, false);
 					indices += 3;
-
+					
 					for (k = 0; k < totuvset; k++) {
 						// get mtface by face index and uv set index
 						MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
@@ -866,7 +869,7 @@
 			else if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) {
 				COLLADAFW::Polygons *mpvc =	(COLLADAFW::Polygons*)mp;
 				COLLADAFW::Polygons::VertexCountArray& vcounta = mpvc->getGroupedVerticesVertexCountArray();
-
+				
 				for (j = 0; j < prim_totface; j++) {
 
 					// face
@@ -925,24 +928,21 @@
 	{
 		COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray();
 		COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()];
-		
-		if (sampler->getSamplerType() == COLLADAFW::Sampler::SAMPLER_TYPE_2D) {
 			
-			const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage();
-			
-			if (uid_image_map.find(ima_uid) == uid_image_map.end()) {
-				fprintf(stderr, "Couldn't find an image by UID.\n");
-				return NULL;
-			}
-			
-		    ma->mtex[i] = add_mtex();
-			ma->mtex[i]->texco = TEXCO_UV;
-			ma->mtex[i]->tex = add_texture("texture");
-			ma->mtex[i]->tex->type = TEX_IMAGE;
-			ma->mtex[i]->tex->ima = uid_image_map[ima_uid];
-			index_mtex_map[ctex.getTextureMapId()].push_back(ma->mtex[i]);
-			return ma->mtex[i];
+		const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage();
+		
+		if (uid_image_map.find(ima_uid) == uid_image_map.end()) {
+			fprintf(stderr, "Couldn't find an image by UID.\n");
+			return NULL;
 		}
+		
+		ma->mtex[i] = add_mtex();
+		ma->mtex[i]->texco = TEXCO_UV;
+		ma->mtex[i]->tex = add_texture("texture");
+		ma->mtex[i]->tex->type = TEX_IMAGE;
+		ma->mtex[i]->tex->ima = uid_image_map[ima_uid];
+		index_mtex_map[ctex.getTextureMapId()].push_back(ma->mtex[i]);
+		return ma->mtex[i];
 	}
 
 	/** When this method is called, the writer must write the effect.
@@ -1103,8 +1103,15 @@
 		@return The writer should return true, if writing succeeded, false otherwise.*/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list