Przeglądaj źródła

# use a more or less heuristic approach to fix the face winding order automatically. Overall things look much better now and normals are 100% right for most models.

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@987 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
aramis_acg 14 lat temu
rodzic
commit
f3bd6ac49b
1 zmienionych plików z 20 dodań i 0 usunięć
  1. 20 0
      code/IFCLoader.cpp

+ 20 - 0
code/IFCLoader.cpp

@@ -734,8 +734,25 @@ void ProcessExtrudedAreaSolid(const IFC::IfcExtrudedAreaSolid& solid, TempMesh&
 	aiMatrix4x4 trafo;
 	ConvertAxisPlacement(trafo, solid.Position,conv);
 
+	aiVector3D vavg;
 	BOOST_FOREACH(aiVector3D& v, result.verts) {
 		v *= trafo;
+		vavg += v;
+	}
+
+	// fixup face orientation.
+	vavg /= static_cast<float>( result.verts.size() );
+
+	size_t c = 0;
+	BOOST_FOREACH(unsigned int cnt, result.vertcnt) {
+		if (cnt>2){
+			const aiVector3D& thisvert = result.verts[c];
+			const aiVector3D normal((thisvert-result.verts[c+1])^(thisvert-result.verts[c+2]));
+			if (normal*(thisvert-vavg) < 0) {
+				std::reverse(result.verts.begin()+c,result.verts.begin()+cnt+c);
+			}
+		}
+		c += cnt;
 	}
 
 	IFCImporter::LogDebug("generate mesh procedurally by extrusion (IfcExtrudedAreaSolid)");
@@ -1188,6 +1205,7 @@ void ProcessSpatialStructures(ConversionData& conv)
 		}
 	}
 
+	
 	for(;range.first != range.second; ++range.first) {
 		const IFC::IfcSpatialStructureElement* const prod = (*range.first).second->ToPtr<IFC::IfcSpatialStructureElement>();
 		if(!prod) {
@@ -1215,6 +1233,8 @@ void ProcessSpatialStructures(ConversionData& conv)
 			}
 		}
 	}
+
+
 	IFCImporter::ThrowException("Failed to determine primary site element");
 }