forked from bartvdbraak/blender
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.
This commit is contained in:
parent
0eb018919a
commit
cc33fcfe7b
@ -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 */
|
||||
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user