Browse Source

Fix a weight normalization issue

Josh Engebretson 10 years ago
parent
commit
8e9cd2477e
1 changed files with 18 additions and 1 deletions
  1. 18 1
      Source/ToolCore/Import/OpenAssetUtils.cpp

+ 18 - 1
Source/ToolCore/Import/OpenAssetUtils.cpp

@@ -336,7 +336,10 @@ bool GetBlendData(OutModel& model, aiMesh* mesh, PODVector<unsigned>& boneMappin
                 blendIndices[vertex].Push(i);
                 blendIndices[vertex].Push(i);
                 blendWeights[vertex].Push(bone->mWeights[j].mWeight);
                 blendWeights[vertex].Push(bone->mWeights[j].mWeight);
                 if (blendWeights[vertex].Size() > 4)
                 if (blendWeights[vertex].Size() > 4)
-                    ErrorExit("More than 4 bone influences on vertex");
+                {
+                    errorMessage = "More than 4 bone influences on vertex";
+                    return false;
+                }
             }
             }
         }
         }
     }
     }
@@ -366,6 +369,20 @@ bool GetBlendData(OutModel& model, aiMesh* mesh, PODVector<unsigned>& boneMappin
         }
         }
     }
     }
 
 
+    // Normalize weights now if necessary
+    for (unsigned i = 0; i < blendWeights.Size(); ++i)
+    {
+        float sum = 0.0f;
+        for (unsigned j = 0; j < blendWeights[i].Size(); ++j)
+            sum += blendWeights[i][j];
+        if (sum != 1.0f && sum != 0.0f)
+        {
+            for (unsigned j = 0; j < blendWeights[i].Size(); ++j)
+                blendWeights[i][j] /= sum;
+        }
+    }
+
+
     return true;
     return true;
 }
 }