[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15607] trunk/blender/source/gameengine/ Converter: BGE patch: fix mesh deformation errors with duplicated objects sharing the same mesh in case of 1 ) armature+multiple material 2) shape drivers
Benoit Bolsee
benoit.bolsee at online.be
Wed Jul 16 23:24:54 CEST 2008
Revision: 15607
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15607
Author: ben2610
Date: 2008-07-16 23:24:54 +0200 (Wed, 16 Jul 2008)
Log Message:
-----------
BGE patch: fix mesh deformation errors with duplicated objects sharing the same mesh in case of 1) armature+multiple material 2) shape drivers
Modified Paths:
--------------
trunk/blender/source/gameengine/Converter/BL_ShapeDeformer.cpp
trunk/blender/source/gameengine/Converter/BL_SkinDeformer.cpp
trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h
Modified: trunk/blender/source/gameengine/Converter/BL_ShapeDeformer.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeDeformer.cpp 2008-07-16 16:20:52 UTC (rev 15606)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeDeformer.cpp 2008-07-16 21:24:54 UTC (rev 15607)
@@ -109,6 +109,13 @@
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;
Modified: trunk/blender/source/gameengine/Converter/BL_SkinDeformer.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_SkinDeformer.cpp 2008-07-16 16:20:52 UTC (rev 15606)
+++ trunk/blender/source/gameengine/Converter/BL_SkinDeformer.cpp 2008-07-16 21:24:54 UTC (rev 15607)
@@ -66,7 +66,8 @@
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,32 +99,28 @@
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 the vertex in m_transverts
+ Update();
- // 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();
+ // 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);
- vecVertexArray& vertexarrays = m_pMeshObject->GetVertexCache(mat);
+ // For each array
+ for (i=0; i<vertexarrays.size(); i++) {
+ KX_VertexArray& vertexarray = (*vertexarrays[i]);
- // For each array
- for (i=0; i<vertexarrays.size(); i++) {
- KX_VertexArray& vertexarray = (*vertexarrays[i]);
-
- // For each vertex
- // copy the untransformed data from the original mvert
- for (j=0; j<vertexarray.size(); j++) {
- RAS_TexVert& v = vertexarray[j];
- v.SetXYZ(m_transverts[v.getOrigIndex()]);
- }
+ // For each vertex
+ // copy the untransformed data from the original mvert
+ for (j=0; j<vertexarray.size(); j++) {
+ RAS_TexVert& v = vertexarray[j];
+ v.SetXYZ(m_transverts[v.getOrigIndex()]);
}
}
@@ -153,9 +150,11 @@
/* 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();
- where_is_pose( par_arma );
+ if (!PoseApplied()){
+ m_armobj->ApplyPose();
+ where_is_pose( par_arma );
+ }
/* store verts locally */
VerifyStorage();
@@ -180,7 +179,8 @@
/* 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;
}
Modified: trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h 2008-07-16 16:20:52 UTC (rev 15606)
+++ trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h 2008-07-16 21:24:54 UTC (rev 15607)
@@ -81,10 +81,13 @@
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 @@
ListBase* m_defbase;
float m_obmat[4][4]; // the reference matrix for skeleton deform
bool m_releaseobject;
+ bool m_poseApplied;
};
More information about the Bf-blender-cvs
mailing list