Spelling Cleanup
[blender.git] / source / gameengine / Ketsji / KX_ConvertPhysicsObjects.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
29  *  \ingroup ketsji
30  */
31
32 #if defined(WIN32) && !defined(FREE_WINDOWS)
33 #pragma warning (disable : 4786)
34 #endif
35
36 #include "MT_assert.h"
37
38 #include "KX_SoftBodyDeformer.h"
39 #include "KX_ConvertPhysicsObject.h"
40 #include "BL_DeformableGameObject.h"
41 #include "RAS_MeshObject.h"
42 #include "KX_Scene.h"
43 #include "BL_System.h"
44
45 #include "PHY_Pro.h" //todo cleanup
46 #include "KX_ClientObjectInfo.h"
47
48 #include "CTR_Map.h"
49 #include "CTR_HashedPtr.h"
50
51 #include "KX_PhysicsEngineEnums.h"
52 #include "PHY_Pro.h"
53
54 #include "KX_MotionState.h" // bridge between motionstate and scenegraph node
55
56 extern "C"{
57         #include "BKE_DerivedMesh.h"
58 }
59
60 #ifdef USE_BULLET
61 #include "BulletSoftBody/btSoftBody.h"
62
63 #include "CcdPhysicsEnvironment.h"
64 #include "CcdPhysicsController.h"
65 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
66
67 #include "KX_BulletPhysicsController.h"
68 #include "btBulletDynamicsCommon.h"
69
70                                                         #ifdef WIN32
71 #if _MSC_VER >= 1310
72 //only use SIMD Hull code under Win32
73 //#define TEST_HULL 1
74 #ifdef TEST_HULL
75 #define USE_HULL 1
76 //#define TEST_SIMD_HULL 1
77
78 #include "NarrowPhaseCollision/Hull.h"
79 #endif //#ifdef TEST_HULL
80
81 #endif //_MSC_VER 
82 #endif //WIN32
83
84
85
86 // forward declarations
87
88 void    KX_ConvertBulletObject( class   KX_GameObject* gameobj,
89         class   RAS_MeshObject* meshobj,
90         struct  DerivedMesh* dm,
91         class   KX_Scene* kxscene,
92         struct  PHY_ShapeProps* shapeprops,
93         struct  PHY_MaterialProps*      smmaterial,
94         struct  KX_ObjectProperties*    objprop)
95 {
96
97         CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
98         assert(env);
99         
100
101         bool isbulletdyna = false;
102         bool isbulletsensor = false;
103         bool useGimpact = false;
104         CcdConstructionInfo ci;
105         class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
106         class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
107
108         
109         if (!objprop->m_dyna)
110         {
111                 ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
112         }
113         if (objprop->m_ghost)
114         {
115                 ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
116         }
117
118         ci.m_MotionState = motionstate;
119         ci.m_gravity = btVector3(0,0,0);
120         ci.m_localInertiaTensor =btVector3(0,0,0);
121         ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f;
122         ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min;
123         ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max;
124         ci.m_margin = objprop->m_margin;
125         shapeInfo->m_radius = objprop->m_radius;
126         isbulletdyna = objprop->m_dyna;
127         isbulletsensor = objprop->m_sensor;
128         useGimpact = ((isbulletdyna || isbulletsensor) && !objprop->m_softbody);
129
130         ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
131         
132         btCollisionShape* bm = 0;
133
134         switch (objprop->m_boundclass)
135         {
136         case KX_BOUNDSPHERE:
137                 {
138                         //float radius = objprop->m_radius;
139                         //btVector3 inertiaHalfExtents (
140                         //      radius,
141                         //      radius,
142                         //      radius);
143                         
144                         //blender doesn't support multisphere, but for testing:
145
146                         //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
147                         shapeInfo->m_shapeType = PHY_SHAPE_SPHERE;
148                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
149                         break;
150                 };
151         case KX_BOUNDBOX:
152                 {
153                         shapeInfo->m_halfExtend.setValue(
154                                 objprop->m_boundobject.box.m_extends[0],
155                                 objprop->m_boundobject.box.m_extends[1],
156                                 objprop->m_boundobject.box.m_extends[2]);
157
158                         shapeInfo->m_halfExtend /= 2.0;
159                         shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute();
160                         shapeInfo->m_shapeType = PHY_SHAPE_BOX;
161                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
162                         break;
163                 };
164         case KX_BOUNDCYLINDER:
165                 {
166                         shapeInfo->m_halfExtend.setValue(
167                                 objprop->m_boundobject.c.m_radius,
168                                 objprop->m_boundobject.c.m_radius,
169                                 objprop->m_boundobject.c.m_height * 0.5f
170                         );
171                         shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER;
172                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
173                         break;
174                 }
175
176         case KX_BOUNDCONE:
177                 {
178                         shapeInfo->m_radius = objprop->m_boundobject.c.m_radius;
179                         shapeInfo->m_height = objprop->m_boundobject.c.m_height;
180                         shapeInfo->m_shapeType = PHY_SHAPE_CONE;
181                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
182                         break;
183                 }
184         case KX_BOUNDPOLYTOPE:
185                 {
186                         shapeInfo->SetMesh(meshobj, dm,true);
187                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
188                         break;
189                 }
190         case KX_BOUNDCAPSULE:
191                 {
192                         shapeInfo->m_radius = objprop->m_boundobject.c.m_radius;
193                         shapeInfo->m_height = objprop->m_boundobject.c.m_height;
194                         shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE;
195                         bm = shapeInfo->CreateBulletShape(ci.m_margin);
196                         break;
197                 }
198         case KX_BOUNDMESH:
199                 {
200                         // mesh shapes can be shared, check first if we already have a shape on that mesh
201                         class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false);
202                         if (sharedShapeInfo != NULL) 
203                         {
204                                 shapeInfo->Release();
205                                 shapeInfo = sharedShapeInfo;
206                                 shapeInfo->AddRef();
207                         } else
208                         {
209                                 shapeInfo->SetMesh(meshobj, dm, false);
210                         }
211
212                         // Soft bodies require welding. Only avoid remove doubles for non-soft bodies!
213                         if (objprop->m_softbody)
214                         {
215                                 shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
216                         }
217
218                         bm = shapeInfo->CreateBulletShape(ci.m_margin, useGimpact, !objprop->m_softbody);
219                         //should we compute inertia for dynamic shape?
220                         //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
221
222                         break;
223                 }
224         case KX_BOUND_DYN_MESH:
225                 /* do nothing */
226                 break;
227         }
228
229
230 //      ci.m_localInertiaTensor.setValue(0.1f,0.1f,0.1f);
231
232         if (!bm)
233         {
234                 delete motionstate;
235                 shapeInfo->Release();
236                 return;
237         }
238
239         //bm->setMargin(ci.m_margin);
240
241
242                 if (objprop->m_isCompoundChild)
243                 {
244                         //find parent, compound shape and add to it
245                         //take relative transform into account!
246                         KX_BulletPhysicsController* parentCtrl = (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController();
247                         assert(parentCtrl);
248                         CcdShapeConstructionInfo* parentShapeInfo = parentCtrl->GetShapeInfo();
249                         btRigidBody* rigidbody = parentCtrl->GetRigidBody();
250                         btCollisionShape* colShape = rigidbody->getCollisionShape();
251                         assert(colShape->isCompound());
252                         btCompoundShape* compoundShape = (btCompoundShape*)colShape;
253
254                         // compute the local transform from parent, this may include several node in the chain
255                         SG_Node* gameNode = gameobj->GetSGNode();
256                         SG_Node* parentNode = objprop->m_dynamic_parent->GetSGNode();
257                         // relative transform
258                         MT_Vector3 parentScale = parentNode->GetWorldScaling();
259                         parentScale[0] = MT_Scalar(1.0)/parentScale[0];
260                         parentScale[1] = MT_Scalar(1.0)/parentScale[1];
261                         parentScale[2] = MT_Scalar(1.0)/parentScale[2];
262                         MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale;
263                         MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed();
264                         MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale);
265                         MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation();
266
267                         shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]);
268                         bm->setLocalScaling(shapeInfo->m_childScale);
269                         shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]);
270                         float rot[12];
271                         relativeRot.getValue(rot);
272                         shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot);
273
274                         parentShapeInfo->AddShape(shapeInfo);   
275                         compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
276                         //do some recalc?
277                         //recalc inertia for rigidbody
278                         if (!rigidbody->isStaticOrKinematicObject())
279                         {
280                                 btVector3 localInertia;
281                                 float mass = 1.f/rigidbody->getInvMass();
282                                 compoundShape->calculateLocalInertia(mass,localInertia);
283                                 rigidbody->setMassProps(mass,localInertia);
284                         }
285                         shapeInfo->Release();
286                         // delete motionstate as it's not used
287                         delete motionstate;
288                         return;
289                 }
290
291                 if (objprop->m_hasCompoundChildren)
292                 {
293                         // create a compound shape info
294                         CcdShapeConstructionInfo *compoundShapeInfo = new CcdShapeConstructionInfo();
295                         compoundShapeInfo->m_shapeType = PHY_SHAPE_COMPOUND;
296                         compoundShapeInfo->AddShape(shapeInfo);
297                         // create the compound shape manually as we already have the child shape
298                         btCompoundShape* compoundShape = new btCompoundShape();
299                         compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
300                         // now replace the shape
301                         bm = compoundShape;
302                         shapeInfo->Release();
303                         shapeInfo = compoundShapeInfo;
304                 }
305
306
307
308
309
310
311 #ifdef TEST_SIMD_HULL
312         if (bm->IsPolyhedral())
313         {
314                 PolyhedralConvexShape* polyhedron = static_cast<PolyhedralConvexShape*>(bm);
315                 if (!polyhedron->m_optionalHull)
316                 {
317                         //first convert vertices in 'Point3' format
318                         int numPoints = polyhedron->GetNumVertices();
319                         Point3* points = new Point3[numPoints+1];
320                         //first 4 points should not be co-planar, so add central point to satisfy MakeHull
321                         points[0] = Point3(0.f,0.f,0.f);
322                         
323                         btVector3 vertex;
324                         for (int p=0;p<numPoints;p++)
325                         {
326                                 polyhedron->GetVertex(p,vertex);
327                                 points[p+1] = Point3(vertex.getX(),vertex.getY(),vertex.getZ());
328                         }
329
330                         Hull* hull = Hull::MakeHull(numPoints+1,points);
331                         polyhedron->m_optionalHull = hull;
332                 }
333
334         }
335 #endif //TEST_SIMD_HULL
336
337
338         ci.m_collisionShape = bm;
339         ci.m_shapeInfo = shapeInfo;
340         ci.m_friction = smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice
341         ci.m_restitution = smmaterial->m_restitution;
342         ci.m_physicsEnv = env;
343         // drag / damping is inverted
344         ci.m_linearDamping = 1.f - shapeprops->m_lin_drag;
345         ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
346         //need a bit of damping, else system doesn't behave well
347         ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behavior
348         
349         ci.m_do_anisotropic = shapeprops->m_do_anisotropic;
350         ci.m_anisotropicFriction.setValue(shapeprops->m_friction_scaling[0],shapeprops->m_friction_scaling[1],shapeprops->m_friction_scaling[2]);
351
352
353 //////////
354         //do Fh, do Rot Fh
355         ci.m_do_fh = shapeprops->m_do_fh;
356         ci.m_do_rot_fh = shapeprops->m_do_rot_fh;
357         ci.m_fh_damping = smmaterial->m_fh_damping;
358         ci.m_fh_distance = smmaterial->m_fh_distance;
359         ci.m_fh_normal = smmaterial->m_fh_normal;
360         ci.m_fh_spring = smmaterial->m_fh_spring;
361         ci.m_radius = objprop->m_radius;
362         
363         
364         ///////////////////
365         ci.m_gamesoftFlag = objprop->m_gamesoftFlag;
366         ci.m_soft_linStiff = objprop->m_soft_linStiff;
367         ci.m_soft_angStiff = objprop->m_soft_angStiff;          /* angular stiffness 0..1 */
368         ci.m_soft_volume= objprop->m_soft_volume;                       /* volume preservation 0..1 */
369
370         ci.m_soft_viterations= objprop->m_soft_viterations;             /* Velocities solver iterations */
371         ci.m_soft_piterations= objprop->m_soft_piterations;             /* Positions solver iterations */
372         ci.m_soft_diterations= objprop->m_soft_diterations;             /* Drift solver iterations */
373         ci.m_soft_citerations= objprop->m_soft_citerations;             /* Cluster solver iterations */
374
375         ci.m_soft_kSRHR_CL= objprop->m_soft_kSRHR_CL;           /* Soft vs rigid hardness [0,1] (cluster only) */
376         ci.m_soft_kSKHR_CL= objprop->m_soft_kSKHR_CL;           /* Soft vs kinetic hardness [0,1] (cluster only) */
377         ci.m_soft_kSSHR_CL= objprop->m_soft_kSSHR_CL;           /* Soft vs soft hardness [0,1] (cluster only) */
378         ci.m_soft_kSR_SPLT_CL= objprop->m_soft_kSR_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
379
380         ci.m_soft_kSK_SPLT_CL= objprop->m_soft_kSK_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
381         ci.m_soft_kSS_SPLT_CL= objprop->m_soft_kSS_SPLT_CL;     /* Soft vs rigid impulse split [0,1] (cluster only) */
382         ci.m_soft_kVCF= objprop->m_soft_kVCF;                   /* Velocities correction factor (Baumgarte) */
383         ci.m_soft_kDP= objprop->m_soft_kDP;                     /* Damping coefficient [0,1] */
384
385         ci.m_soft_kDG= objprop->m_soft_kDG;                     /* Drag coefficient [0,+inf] */
386         ci.m_soft_kLF= objprop->m_soft_kLF;                     /* Lift coefficient [0,+inf] */
387         ci.m_soft_kPR= objprop->m_soft_kPR;                     /* Pressure coefficient [-inf,+inf] */
388         ci.m_soft_kVC= objprop->m_soft_kVC;                     /* Volume conversation coefficient [0,+inf] */
389
390         ci.m_soft_kDF= objprop->m_soft_kDF;                     /* Dynamic friction coefficient [0,1] */
391         ci.m_soft_kMT= objprop->m_soft_kMT;                     /* Pose matching coefficient [0,1] */
392         ci.m_soft_kCHR= objprop->m_soft_kCHR;                   /* Rigid contacts hardness [0,1] */
393         ci.m_soft_kKHR= objprop->m_soft_kKHR;                   /* Kinetic contacts hardness [0,1] */
394
395         ci.m_soft_kSHR= objprop->m_soft_kSHR;                   /* Soft contacts hardness [0,1] */
396         ci.m_soft_kAHR= objprop->m_soft_kAHR;                   /* Anchors hardness [0,1] */
397         ci.m_soft_collisionflags= objprop->m_soft_collisionflags;       /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
398         ci.m_soft_numclusteriterations= objprop->m_soft_numclusteriterations;   /* number of iterations to refine collision clusters*/
399
400         ////////////////////
401         ci.m_collisionFilterGroup = 
402                 (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) :
403                 (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : 
404                 short(CcdConstructionInfo::StaticFilter);
405         ci.m_collisionFilterMask = 
406                 (isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) :
407                 (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : 
408                 short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
409         ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody;
410         
411         ci.m_contactProcessingThreshold = objprop->m_contactProcessingThreshold;//todo: expose this in advanced settings, just like margin, default to 10000 or so
412         ci.m_bSoft = objprop->m_softbody;
413         ci.m_bSensor = isbulletsensor;
414         ci.m_bGimpact = useGimpact;
415         MT_Vector3 scaling = gameobj->NodeGetWorldScaling();
416         ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]);
417         KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,isbulletsensor,objprop->m_hasCompoundChildren);
418         // shapeInfo is reference counted, decrement now as we don't use it anymore
419         if (shapeInfo)
420                 shapeInfo->Release();
421
422         gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
423         // don't add automatically sensor object, they are added when a collision sensor is registered
424         if (!isbulletsensor && objprop->m_in_active_layer)
425         {
426                 env->addCcdPhysicsController( physicscontroller);
427         }
428         physicscontroller->setNewClientInfo(gameobj->getClientInfo());          
429         {
430                 btRigidBody* rbody = physicscontroller->GetRigidBody();
431
432                 if (rbody)
433                 {
434                         if (objprop->m_angular_rigidbody)
435                         {
436                                 btVector3 linearFactor(
437                                         objprop->m_lockXaxis? 0 : 1,
438                                         objprop->m_lockYaxis? 0 : 1,
439                                         objprop->m_lockZaxis? 0 : 1);
440                                 btVector3 angularFactor(
441                                         objprop->m_lockXRotaxis? 0 : 1,
442                                         objprop->m_lockYRotaxis? 0 : 1,
443                                         objprop->m_lockZRotaxis? 0 : 1);
444                                 rbody->setLinearFactor(linearFactor);
445                                 rbody->setAngularFactor(angularFactor);
446                         }
447
448                         if (rbody && objprop->m_disableSleeping)
449                         {
450                                 rbody->setActivationState(DISABLE_DEACTIVATION);
451                         }
452                 }
453         }
454
455         CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0;
456         physicscontroller->setParentCtrl(parentCtrl);
457
458         
459         //Now done directly in ci.m_collisionFlags so that it propagates to replica
460         //if (objprop->m_ghost)
461         //{
462         //      rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
463         //}
464         
465         if (objprop->m_dyna && !objprop->m_angular_rigidbody)
466         {
467                 /*
468                 //setting the inertia could achieve similar results to constraint the up
469                 //but it is prone to instability, so use special 'Angular' constraint
470                 btVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal();
471                 inertia.setX(0.f);
472                 inertia.setZ(0.f);
473
474                 physicscontroller->GetRigidBody()->setInvInertiaDiagLocal(inertia);
475                 physicscontroller->GetRigidBody()->updateInertiaTensor();
476                 */
477
478                 //env->createConstraint(physicscontroller,0,PHY_ANGULAR_CONSTRAINT,0,0,0,0,0,1);
479         
480                 //Now done directly in ci.m_bRigid so that it propagates to replica
481                 //physicscontroller->GetRigidBody()->setAngularFactor(0.f);
482                 ;
483         }
484
485         bool isActor = objprop->m_isactor;
486         gameobj->getClientInfo()->m_type = 
487                 (isbulletsensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) :
488                 (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
489         // store materialname in auxinfo, needed for touchsensors
490         if (meshobj)
491         {
492                 const STR_String& matname=meshobj->GetMaterialName(0);
493                 gameobj->getClientInfo()->m_auxilary_info = (matname.Length() ? (void*)(matname.ReadPtr()+2) : NULL);
494         } else
495         {
496                 gameobj->getClientInfo()->m_auxilary_info = 0;
497         }
498
499
500         gameobj->GetSGNode()->AddSGController(physicscontroller);
501
502         STR_String materialname;
503         if (meshobj)
504                 materialname = meshobj->GetMaterialName(0);
505
506         physicscontroller->SetObject(gameobj->GetSGNode());
507
508 #if 0
509         ///test for soft bodies
510         if (objprop->m_softbody && physicscontroller)
511         {
512                 btSoftBody* softBody = physicscontroller->GetSoftBody();
513                 if (softBody && gameobj->GetMesh(0))//only the first mesh, if any
514                 {
515                         //should be a mesh then, so add a soft body deformer
516                         KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer( gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
517                         gameobj->SetDeformer(softbodyDeformer);
518                 }
519         }
520 #endif
521
522 }
523
524
525 void    KX_ClearBulletSharedShapes()
526 {
527 }
528
529 /* Refresh the physics object from either an object or a mesh.
530  * gameobj must be valid
531  * from_gameobj and from_meshobj can be NULL
532  * 
533  * when setting the mesh, the following vars get priority
534  * 1) from_meshobj - creates the phys mesh from RAS_MeshObject
535  * 2) from_gameobj - creates the phys mesh from the DerivedMesh where possible, else the RAS_MeshObject
536  * 3) gameobj - update the phys mesh from DerivedMesh or RAS_MeshObject
537  * 
538  * Most of the logic behind this is in shapeInfo->UpdateMesh(...)
539  */
540 bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj)
541 {
542         KX_BulletPhysicsController      *spc= static_cast<KX_BulletPhysicsController*>((gameobj->GetPhysicsController()));
543         CcdShapeConstructionInfo        *shapeInfo;
544
545         /* if this is the child of a compound shape this can happen
546          * dont support compound shapes for now */
547         if(spc==NULL)
548                 return false;
549         
550         shapeInfo = spc->GetShapeInfo();
551         
552         if(shapeInfo->m_shapeType != PHY_SHAPE_MESH/* || spc->GetSoftBody()*/)
553                 return false;
554         
555         spc->DeleteControllerShape();
556         
557         if(from_gameobj==NULL && from_meshobj==NULL)
558                 from_gameobj= gameobj;
559         
560         /* updates the arrays used for making the new bullet mesh */
561         shapeInfo->UpdateMesh(from_gameobj, from_meshobj);
562
563         /* create the new bullet mesh */
564         CcdConstructionInfo& cci = spc->getConstructionInfo();
565         btCollisionShape* bm= shapeInfo->CreateBulletShape(cci.m_margin, cci.m_bGimpact, !cci.m_bSoft);
566
567         spc->ReplaceControllerShape(bm);
568         return true;
569 }
570 #endif // USE_BULLET