2
0
Эх сурвалжийг харах

Merge pull request #1210 from rmitton/sib-normals

Fix for faceted normals in SIB files
Kim Kulling 8 жил өмнө
parent
commit
eb8b00617a
1 өөрчлөгдсөн 12 нэмэгдсэн , 7 устгасан
  1. 12 7
      code/SIBImporter.cpp

+ 12 - 7
code/SIBImporter.cpp

@@ -391,7 +391,7 @@ static void ConnectFaces(SIBMesh* mesh)
             // with non-2-manifold surfaces, but then so does Silo to begin with.
             if (edge.faceA == 0xffffffff)
                 edge.faceA = static_cast<uint32_t>(faceIdx);
-            else
+            else if (edge.faceB == 0xffffffff)
                 edge.faceB = static_cast<uint32_t>(faceIdx);
 
             prev = next;
@@ -435,12 +435,17 @@ static aiVector3D CalculateVertexNormal(SIBMesh* mesh, uint32_t faceIdx, uint32_
                 {
                     SIBEdge& edge = GetEdge(mesh, posA, posB);
 
-                    // Move to whichever side we didn't just come from.
-                    if (!edge.creased) {
-                        if (edge.faceA != prevFaceIdx && edge.faceA != faceIdx)
-                            nextFaceIdx = edge.faceA;
-                        else if (edge.faceB != prevFaceIdx && edge.faceB != faceIdx)
-                            nextFaceIdx = edge.faceB;
+                    // Non-manifold meshes can produce faces which share
+                    // positions but have no edge entry, so check it.
+                    if (edge.faceA == faceIdx || edge.faceB == faceIdx)
+                    {
+                        // Move to whichever side we didn't just come from.
+                        if (!edge.creased) {
+                            if (edge.faceA != prevFaceIdx && edge.faceA != faceIdx && edge.faceA != 0xffffffff)
+                                nextFaceIdx = edge.faceA;
+                            else if (edge.faceB != prevFaceIdx && edge.faceB != faceIdx && edge.faceB != 0xffffffff)
+                                nextFaceIdx = edge.faceB;
+                        }
                     }
                 }