[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47897] branches/soc-2012-bratwurst/source /blender/assimp: - bf_assimp: proper handling of smooth flag -- set ME_SMOOTH whenever assimp' s output normals for a face's vertices are not uniform.

Alexander Gessler alexander.gessler at gmx.net
Thu Jun 14 14:56:46 CEST 2012


Revision: 47897
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47897
Author:   aramis_acg
Date:     2012-06-14 12:56:38 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
- bf_assimp: proper handling of smooth flag -- set ME_SMOOTH whenever assimp's output normals for a face's vertices are not uniform.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h

Modified: branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp	2012-06-14 12:43:21 UTC (rev 47896)
+++ branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.cpp	2012-06-14 12:56:38 UTC (rev 47897)
@@ -152,6 +152,33 @@
 }
 
 
+// taken from collada/meshimporter.cpp
+bool MeshImporter::flat_face(const unsigned int *nind, unsigned int count, const aiVector3D* normals)
+{
+	float a[3], b[3];
+
+	a[0] = normals[nind[0]].x;
+	a[1] = normals[nind[0]].y;
+	a[2] = normals[nind[0]].z;
+	normalize_v3(a);
+
+	for (int i = 1; i < count; i++) {
+		b[0] = normals[nind[i]].x;
+		b[1] = normals[nind[i]].y;
+		b[2] = normals[nind[i]].z;
+		normalize_v3(b);
+
+		float dp = dot_v3v3(a, b);
+
+		if (dp < 0.99999f || dp > 1.00001f) {
+			return false;
+		}
+	}
+
+	return true;
+}
+
+
 // allocate mtfaces for the given + 'extra' faces
 void MeshImporter::allocate_face_data(unsigned int extra)
 {
@@ -292,14 +319,14 @@
 
 	MFace *mface = mesh->mface;
 	unsigned int face_index = 0;
-	//unsigned int index = 0;
 
 	std::vector<unsigned int> tri;
 
-
 	for (std::vector<const aiMesh*>::const_iterator it = in_meshes.begin(), end = in_meshes.end(); it != end; ++it) {
 		const aiMesh& m = **it;
 
+		const bool has_normals = m.mNormals != NULL;
+
 		MFace* const start = mface;
 		unsigned int mesh_face_index_start = face_index;
 
@@ -326,15 +353,13 @@
 				}
 
 				test_index_face(mface, &mesh->fdata, face_index, f.mNumIndices);
-				/*
-				if (mp_has_normals) {
-					if (!flat_face(nind, nor, f.mNumIndices)) {
+				
+				if (has_normals) {
+					if (!flat_face(f.mIndices,f.mNumIndices,m.mNormals)) {
 						mface->flag |= ME_SMOOTH;
 					}
+				} 
 
-					nind += f.mNumIndices;
-				} */
-
 				mface++;
 				face_index++;				
 			}
@@ -365,21 +390,17 @@
 					}
 
 					test_index_face(mface, &mesh->fdata, face_index, 3);
-					/*
-					if (mp_has_normals) {
-						unsigned int ntri[3] = {nind[tri[v]], nind[tri[v + 1]], nind[tri[v + 2]]};
-
-						if (!flat_face(ntri, nor, 3))
+			
+					if (has_normals) {
+						
+						if (!flat_face(tri_indices, 3, m.mNormals)) {
 							mface->flag |= ME_SMOOTH;
-					} */
+						}
+					} 
 
 					mface++;
 					face_index++;
 				}
-
-				/*
-				if (mp_has_normals)
-					nind += vcount; */
 			}
 		}
 

Modified: branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h	2012-06-14 12:43:21 UTC (rev 47896)
+++ branches/soc-2012-bratwurst/source/blender/assimp/MeshImporter.h	2012-06-14 12:56:38 UTC (rev 47897)
@@ -74,6 +74,8 @@
 	int triangulate_poly(const unsigned int* indices, int totvert, MVert* verts, std::vector<unsigned int>& tri);
 
 	void assign_textures_to_face(const MFace& fac, MTFace& tfac,unsigned int assimp_mat_id, unsigned int uv_index);
+
+	bool flat_face(const unsigned int *nind, unsigned int count, const aiVector3D* normals);
 	
 public:
 




More information about the Bf-blender-cvs mailing list