diff options
author | Benoit Bolsee <benoit.bolsee@online.be> | 2009-11-25 01:44:29 +0300 |
---|---|---|
committer | Benoit Bolsee <benoit.bolsee@online.be> | 2009-11-25 01:44:29 +0300 |
commit | 5b722b1e8755c2d3b0c981087f3016f16a2b891a (patch) | |
tree | ece1d250a7e8cb72b9f393d394a1edb684dbf577 /source/gameengine/Converter | |
parent | 6c55047b4019a3491934bae38bbf229e6b0e6a48 (diff) |
BGE: replace mesh works for Soft Body (including reinstantiation of physics soft body mesh).
Even a static mesh can be used as replacement: the mesh
will be instantiated with the soft body settings of the
object. The position and orientation of the soft body
is preserved after the replacement.
Known limitation: the velocity of the soft body is reset
aftet the replacement. This is because soft body don't
have a well defined velocity.
Diffstat (limited to 'source/gameengine/Converter')
-rw-r--r-- | source/gameengine/Converter/BL_BlenderDataConversion.cpp | 26 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_MeshDeformer.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_MeshDeformer.h | 4 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ModifierDeformer.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ModifierDeformer.h | 4 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ShapeDeformer.cpp | 2 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_ShapeDeformer.h | 4 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_SkinDeformer.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_SkinDeformer.h | 4 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_SkinMeshObject.cpp | 156 | ||||
-rw-r--r-- | source/gameengine/Converter/BL_SkinMeshObject.h | 67 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_SoftBodyDeformer.cpp | 120 | ||||
-rw-r--r-- | source/gameengine/Converter/KX_SoftBodyDeformer.h | 102 |
13 files changed, 247 insertions, 252 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index c171ba89683..d837b2c4466 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -89,11 +89,11 @@ #include "BKE_global.h" #include "BKE_object.h" #include "BKE_scene.h" -#include "BL_SkinMeshObject.h" #include "BL_ModifierDeformer.h" #include "BL_ShapeDeformer.h" #include "BL_SkinDeformer.h" #include "BL_MeshDeformer.h" +#include "KX_SoftBodyDeformer.h" //#include "BL_ArmatureController.h" #include "BlenderWorldInfo.h" @@ -720,7 +720,6 @@ bool ConvertMaterial( RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, KX_BlenderSceneConverter *converter) { RAS_MeshObject *meshobj; - bool skinMesh = false; int lightlayer = blenderobj ? blenderobj->lay:(1<<20)-1; // all layers if no object. if ((meshobj = converter->FindGameMesh(mesh/*, ob->lay*/)) != NULL) @@ -743,14 +742,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, tangent = (float(*)[3])dm->getFaceDataArray(dm, CD_TANGENT); } - // Determine if we need to make a skinned mesh - if (blenderobj && (mesh->dvert || mesh->key || ((blenderobj->gameflag & OB_SOFT_BODY) != 0) || BL_ModifierDeformer::HasCompatibleDeformer(blenderobj))) - { - meshobj = new BL_SkinMeshObject(mesh); - skinMesh = true; - } - else - meshobj = new RAS_MeshObject(mesh); + meshobj = new RAS_MeshObject(mesh); // Extract avaiable layers MTF_localLayer *layers = new MTF_localLayer[MAX_MTFACE]; @@ -877,7 +869,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, if (kx_blmat == NULL) kx_blmat = new KX_BlenderMaterial(); - kx_blmat->Initialize(scene, bl_mat, skinMesh); + kx_blmat->Initialize(scene, bl_mat); polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat); } else { @@ -1736,30 +1728,34 @@ static KX_GameObject *gameobject_from_blenderobject( bool bHasDvert = mesh->dvert != NULL && ob->defbase.first; bool bHasArmature = (ob->parent && ob->parent->type == OB_ARMATURE && ob->partype==PARSKEL && bHasDvert); bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob); + bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY)); if (bHasModifier) { BL_ModifierDeformer *dcont = new BL_ModifierDeformer((BL_DeformableGameObject *)gameobj, - kxscene->GetBlenderScene(), ob, (BL_SkinMeshObject *)meshobj); + kxscene->GetBlenderScene(), ob, meshobj); ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); if (bHasShapeKey && bHasArmature) dcont->LoadShapeDrivers(ob->parent); } else if (bHasShapeKey) { // not that we can have shape keys without dvert! BL_ShapeDeformer *dcont = new BL_ShapeDeformer((BL_DeformableGameObject*)gameobj, - ob, (BL_SkinMeshObject*)meshobj); + ob, meshobj); ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); if (bHasArmature) dcont->LoadShapeDrivers(ob->parent); } else if (bHasArmature) { BL_SkinDeformer *dcont = new BL_SkinDeformer((BL_DeformableGameObject*)gameobj, - ob, (BL_SkinMeshObject*)meshobj); + ob, meshobj); ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); } else if (bHasDvert) { // this case correspond to a mesh that can potentially deform but not with the // object to which it is attached for the moment. A skin mesh was created in // BL_ConvertMesh() so must create a deformer too! BL_MeshDeformer *dcont = new BL_MeshDeformer((BL_DeformableGameObject*)gameobj, - ob, (BL_SkinMeshObject*)meshobj); + ob, meshobj); + ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); + } else if (bHasSoftBody) { + KX_SoftBodyDeformer *dcont = new KX_SoftBodyDeformer(meshobj, (BL_DeformableGameObject*)gameobj); ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); } diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp index 0abc344a844..516100394f6 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.cpp +++ b/source/gameengine/Converter/BL_MeshDeformer.cpp @@ -41,7 +41,7 @@ #include "RAS_IPolygonMaterial.h" #include "BL_DeformableGameObject.h" #include "BL_MeshDeformer.h" -#include "BL_SkinMeshObject.h" +#include "RAS_MeshObject.h" #include "DNA_mesh_types.h" #include "DNA_meshdata_types.h" diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h index 1749d438d21..0a8c34992e2 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.h +++ b/source/gameengine/Converter/BL_MeshDeformer.h @@ -50,7 +50,7 @@ public: virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map); BL_MeshDeformer(BL_DeformableGameObject *gameobj, struct Object* obj, - class BL_SkinMeshObject *meshobj ): + class RAS_MeshObject *meshobj ): m_pMeshObject(meshobj), m_bmesh((struct Mesh*)(obj->data)), m_transverts(0), @@ -73,7 +73,7 @@ public: // virtual void InitDeform(double time){}; protected: - class BL_SkinMeshObject* m_pMeshObject; + class RAS_MeshObject* m_pMeshObject; struct Mesh* m_bmesh; // this is so m_transverts doesn't need to be converted diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp index 0cdca74fea5..dfdc53acdf9 100644 --- a/source/gameengine/Converter/BL_ModifierDeformer.cpp +++ b/source/gameengine/Converter/BL_ModifierDeformer.cpp @@ -36,7 +36,7 @@ #include "GEN_Map.h" #include "STR_HashedString.h" #include "RAS_IPolygonMaterial.h" -#include "BL_SkinMeshObject.h" +#include "RAS_MeshObject.h" #include "PHY_IGraphicController.h" //#include "BL_ArmatureController.h" diff --git a/source/gameengine/Converter/BL_ModifierDeformer.h b/source/gameengine/Converter/BL_ModifierDeformer.h index 5cc84c7d1e4..ef3a074630f 100644 --- a/source/gameengine/Converter/BL_ModifierDeformer.h +++ b/source/gameengine/Converter/BL_ModifierDeformer.h @@ -50,7 +50,7 @@ public: BL_ModifierDeformer(BL_DeformableGameObject *gameobj, Scene *scene, Object *bmeshobj, - BL_SkinMeshObject *mesh) + RAS_MeshObject *mesh) : BL_ShapeDeformer(gameobj,bmeshobj, mesh), m_lastModifierUpdate(-1), @@ -65,7 +65,7 @@ public: struct Scene *scene, struct Object *bmeshobj_old, struct Object *bmeshobj_new, - class BL_SkinMeshObject *mesh, + class RAS_MeshObject *mesh, bool release_object, BL_ArmatureObject* arma = NULL) : diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp index 9b6d3f61705..c1761637d4e 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.cpp +++ b/source/gameengine/Converter/BL_ShapeDeformer.cpp @@ -36,7 +36,7 @@ #include "GEN_Map.h" #include "STR_HashedString.h" #include "RAS_IPolygonMaterial.h" -#include "BL_SkinMeshObject.h" +#include "RAS_MeshObject.h" //#include "BL_ArmatureController.h" #include "DNA_armature_types.h" diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h index ca3770d4006..46db0f71f6c 100644 --- a/source/gameengine/Converter/BL_ShapeDeformer.h +++ b/source/gameengine/Converter/BL_ShapeDeformer.h @@ -45,7 +45,7 @@ class BL_ShapeDeformer : public BL_SkinDeformer public: BL_ShapeDeformer(BL_DeformableGameObject *gameobj, Object *bmeshobj, - BL_SkinMeshObject *mesh) + RAS_MeshObject *mesh) : BL_SkinDeformer(gameobj,bmeshobj, mesh), m_lastShapeUpdate(-1) @@ -56,7 +56,7 @@ public: BL_ShapeDeformer(BL_DeformableGameObject *gameobj, struct Object *bmeshobj_old, struct Object *bmeshobj_new, - class BL_SkinMeshObject *mesh, + class RAS_MeshObject *mesh, bool release_object, bool recalc_normal, BL_ArmatureObject* arma = NULL) diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp index ecc45b2da1a..ea7242b0225 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.cpp +++ b/source/gameengine/Converter/BL_SkinDeformer.cpp @@ -35,7 +35,7 @@ #include "GEN_Map.h" #include "STR_HashedString.h" #include "RAS_IPolygonMaterial.h" -#include "BL_SkinMeshObject.h" +#include "RAS_MeshObject.h" //#include "BL_ArmatureController.h" #include "DNA_armature_types.h" @@ -59,7 +59,7 @@ extern "C"{ BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj, struct Object *bmeshobj, - class BL_SkinMeshObject *mesh, + class RAS_MeshObject *mesh, BL_ArmatureObject* arma) : // BL_MeshDeformer(gameobj, bmeshobj, mesh), @@ -77,7 +77,7 @@ BL_SkinDeformer::BL_SkinDeformer( BL_DeformableGameObject *gameobj, 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, + class RAS_MeshObject *mesh, bool release_object, bool recalc_normal, BL_ArmatureObject* arma) : diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h index 9c6f5db2b95..28f2d0bf644 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.h +++ b/source/gameengine/Converter/BL_SkinDeformer.h @@ -55,14 +55,14 @@ public: BL_SkinDeformer(BL_DeformableGameObject *gameobj, struct Object *bmeshobj, - class BL_SkinMeshObject *mesh, + class RAS_MeshObject *mesh, BL_ArmatureObject* arma = NULL); /* this second constructor is needed for making a mesh deformable on the fly. */ BL_SkinDeformer(BL_DeformableGameObject *gameobj, struct Object *bmeshobj_old, struct Object *bmeshobj_new, - class BL_SkinMeshObject *mesh, + class RAS_MeshObject *mesh, bool release_object, bool recalc_normal, BL_ArmatureObject* arma = NULL); diff --git a/source/gameengine/Converter/BL_SkinMeshObject.cpp b/source/gameengine/Converter/BL_SkinMeshObject.cpp deleted file mode 100644 index 4eb01df410b..00000000000 --- a/source/gameengine/Converter/BL_SkinMeshObject.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - * Deformer that supports armature skinning - */ - -#ifdef WIN32 -#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning -#endif //WIN32 - -#include "MEM_guardedalloc.h" - -#include "DNA_key_types.h" -#include "DNA_mesh_types.h" -#include "DNA_meshdata_types.h" - -#include "RAS_BucketManager.h" -#include "RAS_IPolygonMaterial.h" - -#include "KX_GameObject.h" - -#include "BL_SkinMeshObject.h" -#include "BL_DeformableGameObject.h" - -BL_SkinMeshObject::BL_SkinMeshObject(Mesh* mesh) - : RAS_MeshObject (mesh) -{ - m_bDeformed = true; - - if (m_mesh && m_mesh->key) - { - KeyBlock *kb; - int count=0; - // initialize weight cache for shape objects - // count how many keys in this mesh - for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) - count++; - m_cacheWeightIndex.resize(count,-1); - } -} - -BL_SkinMeshObject::~BL_SkinMeshObject() -{ - if (m_mesh && m_mesh->key) - { - KeyBlock *kb; - // remove the weight cache to avoid memory leak - for(kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next) { - if(kb->weights) - MEM_freeN(kb->weights); - kb->weights= NULL; - } - } -} - -void BL_SkinMeshObject::UpdateBuckets(void* clientobj,double* oglmatrix,bool useObjectColor,const MT_Vector4& rgbavec, bool visible, bool culled) -{ - list<RAS_MeshMaterial>::iterator it; - list<RAS_MeshSlot*>::iterator sit; - - for(it = m_materials.begin();it!=m_materials.end();++it) { - if(!it->m_slots[clientobj]) - continue; - - RAS_MeshSlot *slot = *it->m_slots[clientobj]; - slot->SetDeformer(((BL_DeformableGameObject*)clientobj)->GetDeformer()); - } - - RAS_MeshObject::UpdateBuckets(clientobj, oglmatrix, useObjectColor, rgbavec, visible, culled); -} - -static int get_def_index(Object* ob, const char* vgroup) -{ - bDeformGroup *curdef; - int index = 0; - - for (curdef = (bDeformGroup*)ob->defbase.first; curdef; curdef=(bDeformGroup*)curdef->next, index++) - if (!strcmp(curdef->name, vgroup)) - return index; - - return -1; -} - -void BL_SkinMeshObject::CheckWeightCache(Object* obj) -{ - KeyBlock *kb; - int kbindex, defindex; - MDeformVert *dvert= NULL; - int totvert, i, j; - float *weights; - - if (!m_mesh->key) - return; - - for(kbindex=0, kb= (KeyBlock*)m_mesh->key->block.first; kb; kb= (KeyBlock*)kb->next, kbindex++) - { - // first check the cases where the weight must be cleared - if (kb->vgroup[0] == 0 || - m_mesh->dvert == NULL || - (defindex = get_def_index(obj, kb->vgroup)) == -1) { - if (kb->weights) { - MEM_freeN(kb->weights); - kb->weights = NULL; - } - m_cacheWeightIndex[kbindex] = -1; - } else if (m_cacheWeightIndex[kbindex] != defindex) { - // a weight array is required but the cache is not matching - if (kb->weights) { - MEM_freeN(kb->weights); - kb->weights = NULL; - } - - dvert= m_mesh->dvert; - totvert= m_mesh->totvert; - - weights= (float*)MEM_callocN(totvert*sizeof(float), "weights"); - - for (i=0; i < totvert; i++, dvert++) { - for(j=0; j<dvert->totweight; j++) { - if (dvert->dw[j].def_nr == defindex) { - weights[i]= dvert->dw[j].weight; - break; - } - } - } - kb->weights = weights; - m_cacheWeightIndex[kbindex] = defindex; - } - } -} - - diff --git a/source/gameengine/Converter/BL_SkinMeshObject.h b/source/gameengine/Converter/BL_SkinMeshObject.h deleted file mode 100644 index 838c6c3cb95..00000000000 --- a/source/gameengine/Converter/BL_SkinMeshObject.h +++ /dev/null @@ -1,67 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#ifndef __BL_SKINMESHOBJECT -#define __BL_SKINMESHOBJECT - -#ifdef WIN32 -#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning -#endif //WIN32 - -#include "RAS_MeshObject.h" -#include "RAS_Deformer.h" -#include "RAS_IPolygonMaterial.h" - -#include "BL_MeshDeformer.h" - -class BL_SkinMeshObject : public RAS_MeshObject -{ -protected: - vector<int> m_cacheWeightIndex; - -public: - BL_SkinMeshObject(Mesh* mesh); - ~BL_SkinMeshObject(); - - void UpdateBuckets(void* clientobj, double* oglmatrix, - bool useObjectColor, const MT_Vector4& rgbavec, bool visible, bool culled); - - // for shape keys, - void CheckWeightCache(struct Object* obj); - - -#ifdef WITH_CXX_GUARDEDALLOC -public: - void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_SkinMeshObject"); } - void operator delete( void *mem ) { MEM_freeN(mem); } -#endif -}; - -#endif - diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.cpp b/source/gameengine/Converter/KX_SoftBodyDeformer.cpp new file mode 100644 index 00000000000..bee8751548a --- /dev/null +++ b/source/gameengine/Converter/KX_SoftBodyDeformer.cpp @@ -0,0 +1,120 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifdef WIN32 +#pragma warning (disable : 4786) +#endif //WIN32 + +#include "MT_assert.h" + +#include "KX_ConvertPhysicsObject.h" +#include "KX_SoftBodyDeformer.h" +#include "RAS_MeshObject.h" +#include "GEN_Map.h" +#include "GEN_HashedPtr.h" + +#ifdef USE_BULLET + +#include "CcdPhysicsEnvironment.h" +#include "CcdPhysicsController.h" +#include "BulletSoftBody/btSoftBody.h" + +#include "KX_BulletPhysicsController.h" +#include "btBulletDynamicsCommon.h" + +void KX_SoftBodyDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map) +{ + void **h_obj = (*map)[m_gameobj]; + + if (h_obj) { + m_gameobj = (BL_DeformableGameObject*)(*h_obj); + m_pMeshObject = m_gameobj->GetMesh(0); + } else { + m_gameobj = NULL; + m_pMeshObject = NULL; + } +} + +bool KX_SoftBodyDeformer::Apply(class RAS_IPolyMaterial *polymat) +{ + KX_BulletPhysicsController* ctrl = (KX_BulletPhysicsController*) m_gameobj->GetPhysicsController(); + if (!ctrl) + return false; + + btSoftBody* softBody= ctrl->GetSoftBody(); + if (!softBody) + return false; + + //printf("apply\n"); + RAS_MeshSlot::iterator it; + RAS_MeshMaterial *mmat; + RAS_MeshSlot *slot; + size_t i; + + // 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. + mmat = m_pMeshObject->GetMeshMaterial(polymat); + if(!mmat->m_slots[(void*)m_gameobj]) + return true; + + slot = *mmat->m_slots[(void*)m_gameobj]; + + // for each array + for(slot->begin(it); !slot->end(it); slot->next(it)) + { + btSoftBody::tNodeArray& nodes(softBody->m_nodes); + + int index = 0; + for(i=it.startvertex; i<it.endvertex; i++,index++) { + RAS_TexVert& v = it.vertex[i]; + btAssert(v.getSoftBodyIndex() >= 0); + + MT_Point3 pt ( + nodes[v.getSoftBodyIndex()].m_x.getX(), + nodes[v.getSoftBodyIndex()].m_x.getY(), + nodes[v.getSoftBodyIndex()].m_x.getZ()); + v.SetXYZ(pt); + + MT_Vector3 normal ( + nodes[v.getSoftBodyIndex()].m_n.getX(), + nodes[v.getSoftBodyIndex()].m_n.getY(), + nodes[v.getSoftBodyIndex()].m_n.getZ()); + v.SetNormal(normal); + + } + } + return true; +} + +#endif diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.h b/source/gameengine/Converter/KX_SoftBodyDeformer.h new file mode 100644 index 00000000000..b55b2a745c0 --- /dev/null +++ b/source/gameengine/Converter/KX_SoftBodyDeformer.h @@ -0,0 +1,102 @@ +/** + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef KX_SOFTBODYDEFORMER +#define KX_SOFTBODYDEFORMER + +#ifdef WIN32 +#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning +#endif //WIN32 + +#include "RAS_Deformer.h" +#include "BL_DeformableGameObject.h" +#include <vector> + + +class KX_SoftBodyDeformer : public RAS_Deformer +{ + class RAS_MeshObject* m_pMeshObject; + class BL_DeformableGameObject* m_gameobj; + +public: + KX_SoftBodyDeformer(RAS_MeshObject* pMeshObject,BL_DeformableGameObject* gameobj) + :m_pMeshObject(pMeshObject), + m_gameobj(gameobj) + { + //printf("KX_SoftBodyDeformer\n"); + }; + + virtual ~KX_SoftBodyDeformer() + { + //printf("~KX_SoftBodyDeformer\n"); + }; + virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*map); + virtual bool Apply(class RAS_IPolyMaterial *polymat); + virtual bool Update(void) + { + //printf("update\n"); + m_bDynamic = true; + return true;//?? + } + virtual bool UpdateBuckets(void) + { + // this is to update the mesh slots outside the rasterizer, + // no need to do it for this deformer, it's done in any case in Apply() + return false; + } + + virtual RAS_Deformer *GetReplica() + { + KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(*this); + deformer->ProcessReplica(); + return deformer; + } + virtual void ProcessReplica() + { + // we have two pointers to deal with but we cannot do it now, will be done in Relink + m_bDynamic = false; + } + virtual bool SkipVertexTransform() + { + return true; + } + +protected: + //class RAS_MeshObject *m_pMesh; + +#ifdef WITH_CXX_GUARDEDALLOC +public: + void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, "GE:BL_ShapeDeformer"); } + void operator delete( void *mem ) { MEM_freeN(mem); } +#endif +}; + + +#endif + |