BGE: Fixing shape key animations on meshes with no armature.
authorMitchell Stokes <mogurijin@gmail.com>
Fri, 9 May 2014 23:03:54 +0000 (16:03 -0700)
committerMitchell Stokes <mogurijin@gmail.com>
Fri, 9 May 2014 23:03:54 +0000 (16:03 -0700)
Their transverts were not being updated after code changes for
multi-threaded skinning.

source/gameengine/Converter/BL_ShapeDeformer.cpp
source/gameengine/Converter/BL_SkinDeformer.cpp
source/gameengine/Converter/BL_SkinDeformer.h
source/gameengine/Ketsji/KX_Scene.cpp

index 8bb9f850bcf245981c926442e25b7fd7bdeb0381..b9b2732276e970297ef5cdb1a7c01d0f1122177e 100644 (file)
@@ -222,6 +222,9 @@ bool BL_ShapeDeformer::Update(void)
                if (m_recalcNormal)
                        RecalcNormals();
 #endif
+
+               // We also need to handle transverts now (used to be in BL_SkinDeformer::Apply())
+               UpdateTransverts();
                bSkinUpdate = true;
        }
 
index 8e1f51238d5dc190135d77b56a96afbb179d295e..e7137a5c379bf781f2892cb03f783ff26525642f 100644 (file)
@@ -287,6 +287,43 @@ void BL_SkinDeformer::BGEDeformVerts()
        m_copyNormals = true;
 }
 
+void BL_SkinDeformer::UpdateTransverts()
+{
+       RAS_MeshSlot::iterator it;
+       RAS_MeshMaterial *mmat;
+       RAS_MeshSlot *slot;
+       size_t i, nmat, imat;
+
+       if (m_transverts) {
+               // the vertex cache is unique to this deformer, no need to update it
+               // if it wasn't updated! We must update all the materials at once
+               // because we will not get here again for the other material
+               nmat = m_pMeshObject->NumMaterials();
+               for (imat=0; imat<nmat; imat++) {
+                       mmat = m_pMeshObject->GetMeshMaterial(imat);
+                       if (!mmat->m_slots[(void*)m_gameobj])
+                               continue;
+
+                       slot = *mmat->m_slots[(void*)m_gameobj];
+
+                       // for each array
+                       for (slot->begin(it); !slot->end(it); slot->next(it)) {
+                               // for each vertex
+                               // copy the untransformed data from the original mvert
+                               for (i=it.startvertex; i<it.endvertex; i++) {
+                                       RAS_TexVert& v = it.vertex[i];
+                                       v.SetXYZ(m_transverts[v.getOrigIndex()]);
+                                       if (m_copyNormals)
+                                               v.SetNormal(m_transnors[v.getOrigIndex()]);
+                               }
+                       }
+               }
+
+               if (m_copyNormals)
+                       m_copyNormals = false;
+       }
+}
+
 bool BL_SkinDeformer::UpdateInternal(bool shape_applied)
 {
        /* See if the armature has been updated for this frame */
@@ -317,40 +354,10 @@ bool BL_SkinDeformer::UpdateInternal(bool shape_applied)
                m_armobj->RestorePose();
                /* dynamic vertex, cannot use display list */
                m_bDynamic = true;
-               /* indicate that the m_transverts and normals are up to date */
-               RAS_MeshSlot::iterator it;
-               RAS_MeshMaterial *mmat;
-               RAS_MeshSlot *slot;
-               size_t i, nmat, imat;
-
-               if (m_transverts) {
-                       // the vertex cache is unique to this deformer, no need to update it
-                       // if it wasn't updated! We must update all the materials at once
-                       // because we will not get here again for the other material
-                       nmat = m_pMeshObject->NumMaterials();
-                       for (imat=0; imat<nmat; imat++) {
-                               mmat = m_pMeshObject->GetMeshMaterial(imat);
-                               if (!mmat->m_slots[(void*)m_gameobj])
-                                       continue;
-
-                               slot = *mmat->m_slots[(void*)m_gameobj];
-
-                               // for each array
-                               for (slot->begin(it); !slot->end(it); slot->next(it)) {
-                                       // for each vertex
-                                       // copy the untransformed data from the original mvert
-                                       for (i=it.startvertex; i<it.endvertex; i++) {
-                                               RAS_TexVert& v = it.vertex[i];
-                                               v.SetXYZ(m_transverts[v.getOrigIndex()]);
-                                               if (m_copyNormals)
-                                                       v.SetNormal(m_transnors[v.getOrigIndex()]);
-                                       }
-                               }
-                       }
 
-                       if (m_copyNormals)
-                               m_copyNormals = false;
-               }
+               UpdateTransverts();
+
+               /* indicate that the m_transverts and normals are up to date */
                return true;
        }
 
index 7495deb22573e0c200abaed195d5be57e85fd304..79043f60db811b874b85aaa0f33f626c49593e5b 100644 (file)
@@ -114,6 +114,8 @@ protected:
        void BlenderDeformVerts();
        void BGEDeformVerts();
 
+       void UpdateTransverts();
+
 
 #ifdef WITH_CXX_GUARDEDALLOC
        MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_SkinDeformer")
index 4c9fba8a10b5962f048c04de788fbb4dafbebdac..c826f39517ad6145230ad34e8cb500cc40dea889 100644 (file)
@@ -1636,6 +1636,9 @@ static void update_anim_thread_func(TaskPool *pool, void *taskdata, int UNUSED(t
                gameobj->UpdateActionManager(curtime);
                children = gameobj->GetChildren();
 
+               if (gameobj->GetDeformer())
+                       gameobj->GetDeformer()->Update();
+
                for (int j=0; j<children->GetCount(); ++j) {
                        child = (KX_GameObject*)children->GetValue(j);