[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22192] branches/soc-2009-chingachgook/ source/blender/collada: Copies textures to the directory where exported file is.

Chingiz Dyussenov chingiz.ds at gmail.com
Mon Aug 3 20:24:29 CEST 2009


Revision: 22192
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22192
Author:   chingachgook
Date:     2009-08-03 20:24:29 +0200 (Mon, 03 Aug 2009)

Log Message:
-----------
Copies textures to the directory where exported file is.

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-08-03 17:56:38 UTC (rev 22191)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-08-03 18:24:29 UTC (rev 22192)
@@ -21,6 +21,7 @@
 {
 #include "BKE_DerivedMesh.h"
 #include "BLI_util.h"
+#include "BLI_fileops.h"
 }
 #include "BKE_scene.h"
 #include "BKE_global.h"
@@ -28,6 +29,8 @@
 #include "BKE_material.h"
 #include "BKE_action.h" // pose functions
 #include "BKE_armature.h"
+#include "BKE_image.h"
+#include "BKE_utildefines.h"
 
 #include "BLI_arithb.h"
 #include "BLI_string.h"
@@ -1246,9 +1249,10 @@
 
 class ImagesExporter: COLLADASW::LibraryImages
 {
+	const char *mfilename;
 	std::vector<std::string> mImages; // contains list of written images, to avoid duplicates
 public:
-	ImagesExporter(COLLADASW::StreamWriter *sw) : COLLADASW::LibraryImages(sw)
+	ImagesExporter(COLLADASW::StreamWriter *sw, const char* filename) : COLLADASW::LibraryImages(sw), mfilename(filename)
 	{}
 	
 	void exportImages(Scene *sce)
@@ -1269,9 +1273,16 @@
 
 				Image *image = mtex->tex->ima;
 				std::string name(id_name(image));
-				char *ima_name;
-				BLI_split_dirfile_basic(image->name, NULL, ima_name);
+				char ima_name[FILE_MAX];
+				char dir[FILE_MAX];
 				
+				BLI_split_dirfile_basic(mfilename, dir, NULL);
+				BKE_get_image_export_path(image, dir, NULL, NULL, ima_name, sizeof(ima_name));
+				
+				if (BLI_copy_fileops(image->name, dir) != 0) {
+					fprintf(stderr, "Cannot copy image to file's directory. \n");
+				}
+				
 				if (find(mImages.begin(), mImages.end(), name) == mImages.end()) {
 					COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(ima_name)), name, "");
 					img.add(mSW);
@@ -1851,7 +1862,7 @@
 	le.exportLights(sce);
 
 	// <library_images>
-	ImagesExporter ie(&sw);
+	ImagesExporter ie(&sw, filename);
 	ie.exportImages(sce);
 	
 	// <library_effects>

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-08-03 17:56:38 UTC (rev 22191)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-08-03 18:24:29 UTC (rev 22192)
@@ -1234,7 +1234,6 @@
 	int triangulate(int *indices, int vcount, MVert *verts, std::vector<unsigned int>& tri)
 	{
 		ListBase dispbase = {NULL, NULL};
-		ListBase trisbase = {NULL, NULL};
 		DispList *dl;
 		float *vert;
 		int i = 0;
@@ -1256,12 +1255,12 @@
 			vert[0] = mvert->co[0];
 			vert[1] = mvert->co[1];
 			vert[2] = mvert->co[2];
-			fprintf(stderr, "%.1f %.1f %.1f \n", mvert->co[0], mvert->co[1], mvert->co[2]);
+			//fprintf(stderr, "%.1f %.1f %.1f \n", mvert->co[0], mvert->co[1], mvert->co[2]);
 		}
 		
-		filldisplist(&dispbase, &trisbase);
+		filldisplist(&dispbase, &dispbase);
 
-		dl = (DispList*)trisbase.first;
+		dl = (DispList*)dispbase.first;
 		int tottri = dl->parts;
 		int *index = dl->index;
 		
@@ -1270,18 +1269,63 @@
 		}
 
 		freedisplist(&dispbase);
-		freedisplist(&trisbase);
 
 		return tottri;
 	}
 	
+	int count_new_tris(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris)
+	{
+		COLLADAFW::MeshPrimitiveArray& prim_arr = mesh->getMeshPrimitives();
+		int i, j, k;
+		
+		for (i = 0; i < prim_arr.getCount(); i++) {
+			
+			COLLADAFW::MeshPrimitive *mp = prim_arr[i];
+			int type = mp->getPrimitiveType();
+			size_t prim_totface = mp->getFaceCount();
+			unsigned int *indices = mp->getPositionIndices().getData();
+			
+			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++) {
+					
+					int vcount = vcounta[j];
+					
+					if (vcount > 4) {
+						// create triangles using PolyFill
+						int *temp_indices = (int*)MEM_callocN(sizeof(int) * vcount, "face_index");
+						
+						for (k = 0; k < vcount; k++) {
+							temp_indices[k] = indices[k];
+						}
+						
+						std::vector<unsigned int> tri;
+						
+						int totri = triangulate(temp_indices, vcount, me->mvert, tri);
+						new_tris += totri - 1;
+						MEM_freeN(temp_indices);
+						indices += vcount;
+					}
+					else if (vcount == 4 || vcount == 3) {
+						indices += vcount;
+					}
+				}
+			}
+		}
+		return new_tris;
+	}
+	
 	// TODO: import uv set names
-	void read_faces(COLLADAFW::Mesh *mesh, Mesh *me)
+	void read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris)
 	{
 		int i;
-
+		
 		// allocate faces
-		me->totface = mesh->getFacesCount();
+		me->totface = mesh->getFacesCount() + new_tris;
 		me->mface = (MFace*)CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
 		
 		// allocate UV layers
@@ -1384,9 +1428,9 @@
 						prim.totface++;
 						
 					}
-					/*else {
+					else {
 						// create triangles using PolyFill
-						int *temp_indices = (int*)MEM_callocN(sizeof(int) * vcount, "");
+						int *temp_indices = (int*)MEM_callocN(sizeof(int) * vcount, "face_index");
 						
 						for (k = 0; k < vcount; k++) {
 							temp_indices[k] = indices[k];
@@ -1394,22 +1438,22 @@
 						
 						std::vector<unsigned int> tri;
 						
-						triangulate(temp_indices, vcount, me->mvert, tri);
+						int totri = triangulate(temp_indices, vcount, me->mvert, tri);
 						
 						for (k = 0; k < tri.size() / 3; k++) {
 							unsigned int tris_indices[3];
 							tris_indices[0] = temp_indices[tri[k * 3]];
 							tris_indices[1] = temp_indices[tri[k * 3 + 1]];
 							tris_indices[2] = temp_indices[tri[k * 3 + 2]];
-							fprintf(stderr, "%u %u %u \n", tris_indices[0], tris_indices[1], tris_indices[2]);
+							//fprintf(stderr, "%u %u %u \n", tris_indices[0], tris_indices[1], tris_indices[2]);
 							set_face_indices(mface, tris_indices, false);
 							
-// 							for (int l = 0; l < totuvset; l++) {
-// 								// get mtface by face index and uv set index
-// 								MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, l);
-// 								set_face_uv(&mtface[face_index], uvs, l, *index_list_array[l], tris_indices);
+							for (int l = 0; l < totuvset; l++) {
+								// get mtface by face index and uv set index
+								MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, l);
+								set_face_uv(&mtface[face_index], uvs, l, *index_list_array[l], tris_indices);
 								
-// 							}
+							}
 							
 							mface++;
 							face_index++;
@@ -1420,7 +1464,6 @@
 						indices += vcount;
 						MEM_freeN(temp_indices);
 					}
-					*/
 				}
 			}
 			
@@ -1620,7 +1663,7 @@
 		}
 		
 		COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh*)geom;
-
+		
 		if (!is_nice_mesh(mesh)) {
 			fprintf(stderr, "Ignoring mesh %s\n", get_dae_name(mesh));
 			return true;
@@ -1632,11 +1675,15 @@
 		// store the Mesh pointer to link it later with an Object
 		this->uid_mesh_map[mesh->getUniqueId()] = me;
 		
+		int new_tris = 0;
+		
 		read_vertices(mesh, me);
 
-		read_faces(mesh, me);
+		//new_tris = count_new_tris(mesh, me, new_tris);
 		
- 		mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
+		read_faces(mesh, me, new_tris);
+		
+ 		//mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
 // 		make_edges(me, 0);
 
 		return true;





More information about the Bf-blender-cvs mailing list