4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 #if defined(WIN32) && !defined(FREE_WINDOWS)
31 #pragma warning (disable : 4786)
34 #include "MT_assert.h"
36 #include "KX_ConvertPhysicsObject.h"
37 #include "KX_SoftBodyDeformer.h"
38 #include "RAS_MeshObject.h"
40 #include "GEN_HashedPtr.h"
44 #include "CcdPhysicsEnvironment.h"
45 #include "CcdPhysicsController.h"
46 #include "BulletSoftBody/btSoftBody.h"
48 #include "KX_BulletPhysicsController.h"
49 #include "btBulletDynamicsCommon.h"
51 void KX_SoftBodyDeformer::Relink(GEN_Map<class GEN_HashedPtr, void*>*map)
53 void **h_obj = (*map)[m_gameobj];
56 m_gameobj = (BL_DeformableGameObject*)(*h_obj);
57 m_pMeshObject = m_gameobj->GetMesh(0);
64 bool KX_SoftBodyDeformer::Apply(class RAS_IPolyMaterial *polymat)
66 KX_BulletPhysicsController* ctrl = (KX_BulletPhysicsController*) m_gameobj->GetPhysicsController();
70 btSoftBody* softBody= ctrl->GetSoftBody();
75 RAS_MeshSlot::iterator it;
76 RAS_MeshMaterial *mmat;
80 // update the vertex in m_transverts
83 // The vertex cache can only be updated for this deformer:
84 // Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
85 // share the same mesh (=the same cache). As the rendering is done per polymaterial
86 // cycling through the objects, the entire mesh cache cannot be updated in one shot.
87 mmat = m_pMeshObject->GetMeshMaterial(polymat);
88 if(!mmat->m_slots[(void*)m_gameobj])
91 slot = *mmat->m_slots[(void*)m_gameobj];
94 for(slot->begin(it); !slot->end(it); slot->next(it))
96 btSoftBody::tNodeArray& nodes(softBody->m_nodes);
99 for(i=it.startvertex; i<it.endvertex; i++,index++) {
100 RAS_TexVert& v = it.vertex[i];
101 btAssert(v.getSoftBodyIndex() >= 0);
104 nodes[v.getSoftBodyIndex()].m_x.getX(),
105 nodes[v.getSoftBodyIndex()].m_x.getY(),
106 nodes[v.getSoftBodyIndex()].m_x.getZ());
110 nodes[v.getSoftBodyIndex()].m_n.getX(),
111 nodes[v.getSoftBodyIndex()].m_n.getY(),
112 nodes[v.getSoftBodyIndex()].m_n.getZ());