[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38169] trunk/blender/source/blender/ collada: [#27854] Collada import doesn't handle UVW mapping

Nathan Letwory nathan at letworyinteractive.com
Wed Jul 6 23:37:32 CEST 2011


Revision: 38169
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38169
Author:   jesterking
Date:     2011-07-06 21:37:31 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
[#27854] Collada import doesn't handle UVW mapping
Reported by David Roy
Patch by Brecht van Lommel

UV import code wasn't taking possible stride into account (always assuming stride==2), thus reading UV coords totally wrong.

Modified Paths:
--------------
    trunk/blender/source/blender/collada/MeshImporter.cpp
    trunk/blender/source/blender/collada/MeshImporter.h

Modified: trunk/blender/source/blender/collada/MeshImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/MeshImporter.cpp	2011-07-06 20:26:56 UTC (rev 38168)
+++ trunk/blender/source/blender/collada/MeshImporter.cpp	2011-07-06 21:37:31 UTC (rev 38169)
@@ -144,15 +144,18 @@
 }
 #endif
 
-void UVDataWrapper::getUV(int uv_index[2], float *uv)
+void UVDataWrapper::getUV(int uv_index, float *uv)
 {
+	int stride = mVData->getStride(0);
+	if(stride==0) stride = 2;
+
 	switch(mVData->getType()) {
 	case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
 		{
 			COLLADAFW::ArrayPrimitiveType<float>* values = mVData->getFloatValues();
 			if (values->empty()) return;
-			uv[0] = (*values)[uv_index[0]];
-			uv[1] = (*values)[uv_index[1]];
+			uv[0] = (*values)[uv_index*stride];
+			uv[1] = (*values)[uv_index*stride + 1];
 			
 		}
 		break;
@@ -160,8 +163,8 @@
 		{
 			COLLADAFW::ArrayPrimitiveType<double>* values = mVData->getDoubleValues();
 			if (values->empty()) return;
-			uv[0] = (float)(*values)[uv_index[0]];
-			uv[1] = (float)(*values)[uv_index[1]];
+			uv[0] = (float)(*values)[uv_index*stride];
+			uv[1] = (float)(*values)[uv_index*stride + 1];
 			
 		}
 		break;
@@ -197,54 +200,36 @@
 void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
 				 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_indices[0], mtface->uv[0]);
-	uvs.getUV(uv_indices[1], mtface->uv[1]);
-	uvs.getUV(uv_indices[2], mtface->uv[2]);
+	uvs.getUV(indices[tris_indices[0]], mtface->uv[0]);
+	uvs.getUV(indices[tris_indices[1]], mtface->uv[1]);
+	uvs.getUV(indices[tris_indices[2]], mtface->uv[2]);
 }
 
 void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
 				COLLADAFW::IndexList& index_list, int index, bool quad)
 {
-	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 < (quad ? 4 : 3); i++) {
-		int uv_index = indices[index + i];
-		uv_indices[i][0] = uv_index * 2;
-		uv_indices[i][1] = uv_index * 2 + 1;
-	}
+	uvs.getUV(indices[index + 0], mtface->uv[0]);
+	uvs.getUV(indices[index + 1], mtface->uv[1]);
+	uvs.getUV(indices[index + 2], mtface->uv[2]);
 
-	uvs.getUV(uv_indices[0], mtface->uv[0]);
-	uvs.getUV(uv_indices[1], mtface->uv[1]);
-	uvs.getUV(uv_indices[2], mtface->uv[2]);
+	if (quad) uvs.getUV(indices[index + 3], mtface->uv[3]);
 
-	if (quad) uvs.getUV(uv_indices[3], mtface->uv[3]);
-
 #ifdef COLLADA_DEBUG
 	/*if (quad) {
 		fprintf(stderr, "face uv:\n"
-				"((%d, %d), (%d, %d), (%d, %d), (%d, %d))\n"
+				"((%d, %d, %d, %d))\n"
 				"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
 
-				uv_indices[0][0], uv_indices[0][1],
-				uv_indices[1][0], uv_indices[1][1],
-				uv_indices[2][0], uv_indices[2][1],
-				uv_indices[3][0], uv_indices[3][1],
+				indices[index + 0],
+				indices[index + 1],
+				indices[index + 2],
+				indices[index + 3],
 
 				mtface->uv[0][0], mtface->uv[0][1],
 				mtface->uv[1][0], mtface->uv[1][1],
@@ -253,12 +238,12 @@
 	}
 	else {
 		fprintf(stderr, "face uv:\n"
-				"((%d, %d), (%d, %d), (%d, %d))\n"
+				"((%d, %d, %d))\n"
 				"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
 
-				uv_indices[0][0], uv_indices[0][1],
-				uv_indices[1][0], uv_indices[1][1],
-				uv_indices[2][0], uv_indices[2][1],
+				indices[index + 0],
+				indices[index + 1],
+				indices[index + 2],
 
 				mtface->uv[0][0], mtface->uv[0][1],
 				mtface->uv[1][0], mtface->uv[1][1],

Modified: trunk/blender/source/blender/collada/MeshImporter.h
===================================================================
--- trunk/blender/source/blender/collada/MeshImporter.h	2011-07-06 20:26:56 UTC (rev 38168)
+++ trunk/blender/source/blender/collada/MeshImporter.h	2011-07-06 21:37:31 UTC (rev 38169)
@@ -69,7 +69,7 @@
 	void print();
 #endif
 
-	void getUV(int uv_index[2], float *uv);
+	void getUV(int uv_index, float *uv);
 };
 
 class MeshImporter : public MeshImporterBase




More information about the Bf-blender-cvs mailing list