forked from bartvdbraak/blender
BGE patch: fix mesh deformation errors with duplicated objects sharing the same mesh in case of 1) armature+multiple material 2) shape drivers
This commit is contained in:
parent
7ef48296fc
commit
dbfc5f6b71
@ -109,6 +109,13 @@ bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
|
||||
vector<IpoCurve*>::iterator it;
|
||||
void *poin;
|
||||
int type;
|
||||
// the shape drivers use the bone matrix as input. Must
|
||||
// update the matrix now
|
||||
Object* par_arma = m_armobj->GetArmatureObject();
|
||||
m_armobj->ApplyPose();
|
||||
where_is_pose( par_arma );
|
||||
PoseApplied(true);
|
||||
|
||||
for (it=m_shapeDrivers.begin(); it!=m_shapeDrivers.end(); it++) {
|
||||
// no need to set a specific time: this curve has a driver
|
||||
IpoCurve *icu = *it;
|
||||
|
@ -66,7 +66,8 @@ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj,
|
||||
m_armobj(arma),
|
||||
m_lastArmaUpdate(-1),
|
||||
m_defbase(&bmeshobj->defbase),
|
||||
m_releaseobject(false)
|
||||
m_releaseobject(false),
|
||||
m_poseApplied(false)
|
||||
{
|
||||
Mat4CpyMat4(m_obmat, bmeshobj->obmat);
|
||||
};
|
||||
@ -98,20 +99,17 @@ BL_SkinDeformer::~BL_SkinDeformer()
|
||||
m_armobj->Release();
|
||||
}
|
||||
|
||||
bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *)
|
||||
bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
|
||||
{
|
||||
size_t i, j;
|
||||
|
||||
if (!Update())
|
||||
// no need to update the cache
|
||||
return false;
|
||||
|
||||
// Update all materials at once, so we can do the above update test
|
||||
// without ending up with some materials not updated
|
||||
for(RAS_MaterialBucket::Set::iterator mit = m_pMeshObject->GetFirstMaterial();
|
||||
mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
|
||||
RAS_IPolyMaterial *mat = (*mit)->GetPolyMaterial();
|
||||
// update the vertex in m_transverts
|
||||
Update();
|
||||
|
||||
// The vertex cache can only be updated for this deformer:
|
||||
// Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
|
||||
// share the same mesh (=the same cache). As the rendering is done per polymaterial
|
||||
// cycling through the objects, the entire mesh cache cannot be updated in one shot.
|
||||
vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
|
||||
|
||||
// For each array
|
||||
@ -125,7 +123,6 @@ bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *)
|
||||
v.SetXYZ(m_transverts[v.getOrigIndex()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -153,9 +150,11 @@ bool BL_SkinDeformer::Update(void)
|
||||
|
||||
/* XXX note: where_is_pose() (from BKE_armature.h) calculates all matrices needed to start deforming */
|
||||
/* but it requires the blender object pointer... */
|
||||
|
||||
Object* par_arma = m_armobj->GetArmatureObject();
|
||||
if (!PoseApplied()){
|
||||
m_armobj->ApplyPose();
|
||||
where_is_pose( par_arma );
|
||||
}
|
||||
|
||||
/* store verts locally */
|
||||
VerifyStorage();
|
||||
@ -180,7 +179,8 @@ bool BL_SkinDeformer::Update(void)
|
||||
|
||||
/* Update the current frame */
|
||||
m_lastArmaUpdate=m_armobj->GetLastFrame();
|
||||
|
||||
/* reset for next frame */
|
||||
PoseApplied(false);
|
||||
/* indicate that the m_transverts and normals are up to date */
|
||||
return true;
|
||||
}
|
||||
|
@ -81,10 +81,13 @@ public:
|
||||
virtual ~BL_SkinDeformer();
|
||||
bool Update (void);
|
||||
bool Apply (class RAS_IPolyMaterial *polymat);
|
||||
bool PoseApplied()
|
||||
{ return m_poseApplied; }
|
||||
void PoseApplied(bool applied)
|
||||
{ m_poseApplied = applied; }
|
||||
bool PoseUpdated(void)
|
||||
{
|
||||
if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) {
|
||||
m_armobj->ApplyPose();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -102,6 +105,7 @@ protected:
|
||||
ListBase* m_defbase;
|
||||
float m_obmat[4][4]; // the reference matrix for skeleton deform
|
||||
bool m_releaseobject;
|
||||
bool m_poseApplied;
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user