Skip to content

Commit

Permalink
UPBGE: Fix normal update of BGE skin deformer.
Browse files Browse the repository at this point in the history
Previously the BGE deformer computation for skin defomers was
computing wrongly the normal for two reasons:

- The normal and position of each wasn't intialized. This is solved
  by copying the normals and position in the function
  BL_MeshDeformer::VerifyStorage no matter what.

- The normals was multiplied by the bone matrix each frame and not
  the "delta" bone matrix. To solve this issue the original unmodified
  normal is multiplied by the bone matrix and copied in the final normal.
  • Loading branch information
panzergame committed Oct 23, 2016
1 parent 051dc49 commit c1012ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 5 additions & 0 deletions source/gameengine/Converter/BL_MeshDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,10 @@ void BL_MeshDeformer::VerifyStorage()
m_transnors = new float[m_bmesh->totvert][3];
m_tvtot = m_bmesh->totvert;
}

for (unsigned int v = 0; v < m_bmesh->totvert; v++) {
copy_v3_v3(m_transverts[v], m_bmesh->mvert[v].co);
normal_short_to_float_v3(m_transnors[v], m_bmesh->mvert[v].no);
}
}

9 changes: 2 additions & 7 deletions source/gameengine/Converter/BL_SkinDeformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ void BL_SkinDeformer::BGEDeformVerts()
for (int i = 0; i < m_bmesh->totvert; ++i, dv++) {
float contrib = 0.0f, weight, max_weight = -1.0f;
bPoseChannel *pchan = NULL;
Eigen::Vector3f normorg(m_bmesh->mvert[i].no[0], m_bmesh->mvert[i].no[1], m_bmesh->mvert[i].no[2]);
Eigen::Map<Eigen::Vector3f> norm = Eigen::Vector3f::Map(m_transnors[i]);
Eigen::Vector4f vec(0.0f, 0.0f, 0.0f, 1.0f);
Eigen::Vector4f co(m_transverts[i][0],
Expand Down Expand Up @@ -289,7 +290,7 @@ void BL_SkinDeformer::BGEDeformVerts()
}

// Update Vertex Normal
norm = norm_chan_mat.topLeftCorner<3, 3>() * norm;
norm = norm_chan_mat.topLeftCorner<3, 3>() * normorg;

co.noalias() += vec / contrib;
co[3] = 1.0f; // Make sure we have a 1 for the w component!
Expand Down Expand Up @@ -371,12 +372,6 @@ bool BL_SkinDeformer::UpdateInternal(bool shape_applied)
if (!shape_applied) {
/* store verts locally */
VerifyStorage();

/* duplicate */
for (int v = 0; v < m_bmesh->totvert; v++) {
copy_v3_v3(m_transverts[v], m_bmesh->mvert[v].co);
normal_short_to_float_v3(m_transnors[v], m_bmesh->mvert[v].no);
}
}

m_armobj->ApplyPose();
Expand Down

0 comments on commit c1012ab

Please sign in to comment.