[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22119] branches/soc-2009-chingachgook/ source/blender/collada: * Commented out converter of polygons to triangles - it's not working yet.

Chingiz Dyussenov chingiz.ds at gmail.com
Sat Aug 1 14:49:39 CEST 2009


Revision: 22119
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22119
Author:   chingachgook
Date:     2009-08-01 14:49:39 +0200 (Sat, 01 Aug 2009)

Log Message:
-----------
* Commented out converter of polygons to triangles - it's not working yet.
* Fixed textures export. 
TODO:
* Fix lights 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-08-01 11:04:59 UTC (rev 22118)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentExporter.cpp	2009-08-01 12:49:39 UTC (rev 22119)
@@ -52,7 +52,7 @@
 #include "COLLADASWSurfaceInitOption.h"
 #include "COLLADASWSampler.h"
 #include "COLLADASWScene.h"
-// #include "COLLADASWSurface.h"
+//#include "COLLADASWSurface.h"
 #include "COLLADASWTechnique.h"
 #include "COLLADASWTexture.h"
 #include "COLLADASWLibraryMaterials.h"
@@ -982,7 +982,7 @@
 	}
 };
 
-#if 0
+
 class EffectsExporter: COLLADASW::LibraryEffects
 {
 public:
@@ -1062,9 +1062,10 @@
 
 		// create <sampler> and <surface> for each image
 		COLLADASW::Sampler samplers[MAX_MTEX];
-		COLLADASW::Surface surfaces[MAX_MTEX];
-		void *samp_surf[MAX_MTEX][2];
-
+		//COLLADASW::Surface surfaces[MAX_MTEX];
+		//void *samp_surf[MAX_MTEX][2];
+		void *samp_surf[MAX_MTEX][1];
+		
 		// image to index to samp_surf map
 		// samp_surf[index] stores 2 pointers, sampler and surface
 		std::map<std::string, int> im_samp_map;
@@ -1073,29 +1074,30 @@
 		for (a = 0, b = 0; a < tex_indices.size(); a++) {
 			MTex *t = ma->mtex[tex_indices[a]];
 			Image *ima = t->tex->ima;
-
+			
 			std::string key(id_name(ima));
 
 			// create only one <sampler>/<surface> pair for each unique image
 			if (im_samp_map.find(key) == im_samp_map.end()) {
 				//<newparam> <surface> <init_from>
-				COLLADASW::Surface surface(COLLADASW::Surface::SURFACE_TYPE_2D,
-										   key + COLLADASW::Surface::SURFACE_SID_SUFFIX);
-				COLLADASW::SurfaceInitOption sio(COLLADASW::SurfaceInitOption::INIT_FROM);
-				sio.setImageReference(key);
-				surface.setInitOption(sio);
-
+			// 	COLLADASW::Surface surface(COLLADASW::Surface::SURFACE_TYPE_2D,
+// 										   key + COLLADASW::Surface::SURFACE_SID_SUFFIX);
+// 				COLLADASW::SurfaceInitOption sio(COLLADASW::SurfaceInitOption::INIT_FROM);
+// 				sio.setImageReference(key);
+// 				surface.setInitOption(sio);
+				
 				//<newparam> <sampler> <source>
 				COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
-										   key + COLLADASW::Surface::SURFACE_SID_SUFFIX);
-
+										   key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
+										   key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
+				sampler.setImageId(key);
 				// copy values to arrays since they will live longer
 				samplers[a] = sampler;
-				surfaces[a] = surface;
-
+				//surfaces[a] = surface;
+				
 				// store pointers so they can be used later when we create <texture>s
 				samp_surf[b][0] = &samplers[a];
-				samp_surf[b][1] = &surfaces[a];
+				//samp_surf[b][1] = &surfaces[a];
 				
 				im_samp_map[key] = b;
 				b++;
@@ -1112,34 +1114,34 @@
 			MTex *t = ma->mtex[tex_indices[a]];
 			Image *ima = t->tex->ima;
 
-			// we assume map input is always TEXTCO_UV
+			// we assume map input is always TEXCO_UV
 
 			std::string key(id_name(ima));
 			int i = im_samp_map[key];
 			COLLADASW::Sampler *sampler = (COLLADASW::Sampler*)samp_surf[i][0];
-			COLLADASW::Surface *surface = (COLLADASW::Surface*)samp_surf[i][1];
+			//COLLADASW::Surface *surface = (COLLADASW::Surface*)samp_surf[i][1];
 
 			std::string uvname = strlen(t->uvname) ? t->uvname : active_uv;
 
 			// color
 			if (t->mapto & MAP_COL) {
-				ep.setDiffuse(createTexture(ima, uvname, sampler, surface));
+				ep.setDiffuse(createTexture(ima, uvname, sampler));
 			}
 			// ambient
 			if (t->mapto & MAP_AMB) {
-				ep.setAmbient(createTexture(ima, uvname, sampler, surface));
+				ep.setAmbient(createTexture(ima, uvname, sampler));
 			}
 			// specular
 			if (t->mapto & MAP_SPEC) {
-				ep.setSpecular(createTexture(ima, uvname, sampler, surface));
+				ep.setSpecular(createTexture(ima, uvname, sampler));
 			}
 			// emission
 			if (t->mapto & MAP_EMIT) {
-				ep.setEmission(createTexture(ima, uvname, sampler, surface));
+				ep.setEmission(createTexture(ima, uvname, sampler));
 			}
 			// reflective
 			if (t->mapto & MAP_REF) {
-				ep.setReflective(createTexture(ima, uvname, sampler, surface));
+				ep.setReflective(createTexture(ima, uvname, sampler));
 			}
 		}
 		// performs the actual writing
@@ -1150,13 +1152,13 @@
 	
 	COLLADASW::ColorOrTexture createTexture(Image *ima,
 											std::string& uv_layer_name,
-											COLLADASW::Sampler *sampler,
-											COLLADASW::Surface *surface)
+											COLLADASW::Sampler *sampler
+											/*COLLADASW::Surface *surface*/)
 	{
 		
 		COLLADASW::Texture texture(id_name(ima));
 		texture.setTexcoord(uv_layer_name);
-		texture.setSurface(*surface);
+		//texture.setSurface(*surface);
 		texture.setSampler(*sampler);
 		
 		COLLADASW::ColorOrTexture cot(texture);
@@ -1183,7 +1185,6 @@
 		}
 	}
 };
-#endif
 
 class MaterialsExporter: COLLADASW::LibraryMaterials
 {
@@ -1556,11 +1557,9 @@
 	ImagesExporter ie(&sw);
 	ie.exportImages(sce);
 	
-#if 0
 	// <library_effects>
 	EffectsExporter ee(&sw);
 	ee.exportEffects(sce);
-#endif
 	
 	// <library_materials>
 	MaterialsExporter me(&sw);

Modified: branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp
===================================================================
--- branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-08-01 11:04:59 UTC (rev 22118)
+++ branches/soc-2009-chingachgook/source/blender/collada/DocumentImporter.cpp	2009-08-01 12:49:39 UTC (rev 22119)
@@ -49,6 +49,7 @@
 #include "BKE_fcurve.h"
 #include "BKE_depsgraph.h"
 #include "BLI_util.h"
+#include "BKE_displist.h"
 }
 #include "BKE_armature.h"
 #include "BKE_mesh.h"
@@ -973,7 +974,27 @@
 		mface->v2 = mface->v3;
 		mface->v3 = 0;
 	}
+	
+	void set_face_uv(MTFace *mtface, UVDataWrapper &uvs, int uv_set_index,
+					 COLLADAFW::IndexList& index_list, unsigned int *tris_indices)
+	{
+		int uv_indices[4][2];
 
+		// per face vertex indices, this means for quad we have 4 indices, not 8
+		COLLADAFW::UIntValuesArray& indices = index_list.getIndices();
+
+		// make indices into FloatOrDoubleArray
+		for (int i = 0; i < 3; i++) {
+			int uv_index = indices[tris_indices[i]];
+			uv_indices[i][0] = uv_index * 2;
+			uv_indices[i][1] = uv_index * 2 + 1;
+		}
+
+		uvs.getUV(uv_set_index, uv_indices[0], mtface->uv[0]);
+		uvs.getUV(uv_set_index, uv_indices[1], mtface->uv[1]);
+		uvs.getUV(uv_set_index, uv_indices[2], mtface->uv[2]);
+	}
+
 	void set_face_uv(MTFace *mtface, UVDataWrapper &uvs, int uv_set_index,
 					COLLADAFW::IndexList& index_list, int index, bool quad)
 	{
@@ -1060,8 +1081,8 @@
 				
 				for(int j = 0; j < vca.getCount(); j++){
 					int count = vca[j];
-					if (count != 3 && count != 4) {
-						fprintf(stderr, "Primitive %s in %s has at least one face with vertex count > 4 or < 3\n",
+					if (count < 3 || count > 4) {
+						fprintf(stderr, "Primitive %s in %s has at least one face with vertex count < 3 or > 4\n",
 								type_str, name);
 						return false;
 					}
@@ -1113,7 +1134,51 @@
 			}
 		}
 	}
+	
+	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;
+		
+		dispbase.first = dispbase.last = NULL;
+		
+		dl = (DispList*)MEM_callocN(sizeof(DispList), "poly disp");
+		BLI_addtail(&dispbase, dl);
+		dl->type = DL_INDEX3;
+		dl->nr = vcount;
+		dl->type = DL_POLY;
+		dl->parts = 1;
+		dl->col = 0;
+		dl->verts = vert = (float*)MEM_callocN( sizeof(float) * 3 * vcount, "dl verts");
+		dl->index = (int*)MEM_callocN(sizeof(int) * 3 * vcount, "dl index");
+		
+		for (i = 0; i < vcount; ++i, vert += 3) {
+			MVert *mvert = &verts[indices[i]];
+			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]);
+		}
+		
+		filldisplist(&dispbase, &trisbase);
 
+		dl = (DispList*)trisbase.first;
+		int tottri = dl->parts;
+		int *index = dl->index;
+		
+		for (i = 0; i < tottri * 3; i++, index++) {
+			tri.push_back(*index);
+		}
+
+		freedisplist(&dispbase);
+		freedisplist(&trisbase);
+
+		return tottri;
+	}
+	
 	// TODO: import uv set names
 	void read_faces(COLLADAFW::Mesh *mesh, Mesh *me)
 	{
@@ -1195,30 +1260,71 @@
 				COLLADAFW::Polygons::VertexCountArray& vcounta = mpvc->getGroupedVerticesVertexCountArray();
 				
 				for (j = 0; j < prim_totface; j++) {
-
+					
 					// face
 					int vcount = vcounta[j];
-
-					set_face_indices(mface, indices, vcount == 4);
-					indices += vcount;
-					
-					// do the trick if needed
-					if (vcount == 4 && mface->v4 == 0)
-						rotate_face_indices(mface);
-
-					// set mtface for each uv set
-					// it is assumed that all primitives have equal number of UV sets
-
-					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);
-						set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, mface->v4 != 0);
+					if (vcount == 3 || vcount == 4) {
+						
+						set_face_indices(mface, indices, vcount == 4);
+						indices += vcount;
+						
+						// do the trick if needed
+						if (vcount == 4 && mface->v4 == 0)
+							rotate_face_indices(mface);
+						
+						
+						// set mtface for each uv set
+						// it is assumed that all primitives have equal number of UV sets
+						
+						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);
+							set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, mface->v4 != 0);
+						}
+						
+						index += mface->v4 ? 4 : 3;
+						mface++;
+						face_index++;
+						prim.totface++;
+						
 					}
-
-					index += mface->v4 ? 4 : 3;
-					mface++;
-					face_index++;
-					prim.totface++;
+					/*else {
+						// create triangles using PolyFill
+						int *temp_indices = (int*)MEM_callocN(sizeof(int) * vcount, "");
+						
+						for (k = 0; k < vcount; k++) {
+							temp_indices[k] = indices[k];
+						}
+						
+						std::vector<unsigned int> tri;
+						
+						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]];

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list