Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2008-04-05 17:33:08 +0400
committerBenoit Bolsee <benoit.bolsee@online.be>2008-04-05 17:33:08 +0400
commitcc33fcfe7b76aa8370cace83859d085b42304d48 (patch)
treebd01c8aeb131267892ddaf5df8b14755c3dde831 /source/gameengine
parent0eb018919a193a4d868f90e21601eba383a82e60 (diff)
Commit patch #2439: Mesh replacement in BGE will react properly to armature deform
Changing the mesh of an object that has a deform controller (armature) is now properly handled. The new mesh must have vertex groups matching the armature bones. In simple terms, the new mesh must deform correctly when you assign it to the object in Blender and you test the action. It will deform the same when you replace the object mesh during the game.
Diffstat (limited to 'source/gameengine')
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.cpp26
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.h15
2 files changed, 30 insertions, 11 deletions
diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp
index e9ec6f9116b..6bc623b645c 100644
--- a/source/gameengine/Converter/BL_SkinDeformer.cpp
+++ b/source/gameengine/Converter/BL_SkinDeformer.cpp
@@ -60,11 +60,35 @@ extern "C"{
#define __NLA_DEFNORMALS
//#undef __NLA_DEFNORMALS
+
+BL_SkinDeformer::BL_SkinDeformer(
+ struct Object *bmeshobj_old, // Blender object that owns the new mesh
+ struct Object *bmeshobj_new, // Blender object that owns the original mesh
+ class BL_SkinMeshObject *mesh,
+ bool release_object,
+ BL_ArmatureObject* arma) :
+ BL_MeshDeformer(bmeshobj_old, mesh),
+ m_armobj(arma),
+ m_lastUpdate(-1),
+ m_defbase(&bmeshobj_old->defbase),
+ m_releaseobject(release_object)
+ {
+ Mat4CpyMat4(m_obmat, bmeshobj_old->obmat);
+ m_restoremat = true;
+ // this is needed to ensure correct deformation of mesh:
+ // the deformation is done with Blender's armature_deform_verts() function
+ // that takes an object as parameter and not a mesh. The object matrice is used
+ // in the calculation, so we must force the same matrice to simulate a pure replacement of mesh
+ Mat4CpyMat4(bmeshobj_old->obmat, bmeshobj_new->obmat);
+ }
+
BL_SkinDeformer::~BL_SkinDeformer()
{
if(m_releaseobject && m_armobj)
m_armobj->Release();
-};
+ if (m_restoremat)
+ Mat4CpyMat4(m_objMesh->obmat, m_obmat);
+}
/* XXX note, this __NLA_OLDDEFORM define seems to be obsolete */
diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h
index 74adc6c2943..b4e55018604 100644
--- a/source/gameengine/Converter/BL_SkinDeformer.h
+++ b/source/gameengine/Converter/BL_SkinDeformer.h
@@ -72,7 +72,8 @@ public:
m_armobj(arma),
m_lastUpdate(-1),
m_defbase(&bmeshobj->defbase),
- m_releaseobject(false)
+ m_releaseobject(false),
+ m_restoremat(false)
{
};
@@ -81,15 +82,7 @@ public:
struct Object *bmeshobj_new,
class BL_SkinMeshObject *mesh,
bool release_object,
- BL_ArmatureObject* arma = NULL)
- : //
- BL_MeshDeformer(bmeshobj_old, mesh),
- m_armobj(arma),
- m_lastUpdate(-1),
- m_defbase(&bmeshobj_old->defbase),
- m_releaseobject(release_object)
- {
- };
+ BL_ArmatureObject* arma = NULL);
virtual void ProcessReplica();
virtual RAS_Deformer *GetReplica();
@@ -102,6 +95,8 @@ protected:
float m_time;
double m_lastUpdate;
ListBase* m_defbase;
+ float m_obmat[4][4]; // the original object matrice in case of dynamic mesh replacement
+ bool m_restoremat;
bool m_releaseobject;
};