Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00032 #if defined(WIN32) && !defined(FREE_WINDOWS) 00033 #pragma warning (disable : 4786) 00034 #endif 00035 00036 #include "MT_assert.h" 00037 00038 #include "KX_SoftBodyDeformer.h" 00039 #include "KX_ConvertPhysicsObject.h" 00040 #include "BL_DeformableGameObject.h" 00041 #include "RAS_MeshObject.h" 00042 #include "KX_Scene.h" 00043 #include "BL_System.h" 00044 00045 #include "PHY_Pro.h" //todo cleanup 00046 #include "KX_ClientObjectInfo.h" 00047 00048 #include "CTR_Map.h" 00049 #include "CTR_HashedPtr.h" 00050 00051 #include "KX_PhysicsEngineEnums.h" 00052 #include "PHY_Pro.h" 00053 00054 #include "KX_MotionState.h" // bridge between motionstate and scenegraph node 00055 00056 extern "C"{ 00057 #include "BKE_DerivedMesh.h" 00058 } 00059 00060 #ifdef USE_BULLET 00061 #include "BulletSoftBody/btSoftBody.h" 00062 00063 #include "CcdPhysicsEnvironment.h" 00064 #include "CcdPhysicsController.h" 00065 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 00066 00067 #include "KX_BulletPhysicsController.h" 00068 #include "btBulletDynamicsCommon.h" 00069 00070 #ifdef WIN32 00071 #if _MSC_VER >= 1310 00072 //only use SIMD Hull code under Win32 00073 //#define TEST_HULL 1 00074 #ifdef TEST_HULL 00075 #define USE_HULL 1 00076 //#define TEST_SIMD_HULL 1 00077 00078 #include "NarrowPhaseCollision/Hull.h" 00079 #endif //#ifdef TEST_HULL 00080 00081 #endif //_MSC_VER 00082 #endif //WIN32 00083 00084 00085 00086 // forward declarations 00087 00088 void KX_ConvertBulletObject( class KX_GameObject* gameobj, 00089 class RAS_MeshObject* meshobj, 00090 struct DerivedMesh* dm, 00091 class KX_Scene* kxscene, 00092 struct PHY_ShapeProps* shapeprops, 00093 struct PHY_MaterialProps* smmaterial, 00094 struct KX_ObjectProperties* objprop) 00095 { 00096 00097 CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment(); 00098 assert(env); 00099 00100 00101 bool isbulletdyna = false; 00102 bool isbulletsensor = false; 00103 bool useGimpact = false; 00104 CcdConstructionInfo ci; 00105 class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode()); 00106 class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo(); 00107 00108 00109 if (!objprop->m_dyna) 00110 { 00111 ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT; 00112 } 00113 if (objprop->m_ghost) 00114 { 00115 ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; 00116 } 00117 00118 ci.m_MotionState = motionstate; 00119 ci.m_gravity = btVector3(0,0,0); 00120 ci.m_localInertiaTensor =btVector3(0,0,0); 00121 ci.m_mass = objprop->m_dyna ? shapeprops->m_mass : 0.f; 00122 ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min; 00123 ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max; 00124 ci.m_margin = objprop->m_margin; 00125 shapeInfo->m_radius = objprop->m_radius; 00126 isbulletdyna = objprop->m_dyna; 00127 isbulletsensor = objprop->m_sensor; 00128 useGimpact = ((isbulletdyna || isbulletsensor) && !objprop->m_softbody); 00129 00130 ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f); 00131 00132 btCollisionShape* bm = 0; 00133 00134 switch (objprop->m_boundclass) 00135 { 00136 case KX_BOUNDSPHERE: 00137 { 00138 //float radius = objprop->m_radius; 00139 //btVector3 inertiaHalfExtents ( 00140 // radius, 00141 // radius, 00142 // radius); 00143 00144 //blender doesn't support multisphere, but for testing: 00145 00146 //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1); 00147 shapeInfo->m_shapeType = PHY_SHAPE_SPHERE; 00148 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00149 break; 00150 }; 00151 case KX_BOUNDBOX: 00152 { 00153 shapeInfo->m_halfExtend.setValue( 00154 objprop->m_boundobject.box.m_extends[0], 00155 objprop->m_boundobject.box.m_extends[1], 00156 objprop->m_boundobject.box.m_extends[2]); 00157 00158 shapeInfo->m_halfExtend /= 2.0; 00159 shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute(); 00160 shapeInfo->m_shapeType = PHY_SHAPE_BOX; 00161 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00162 break; 00163 }; 00164 case KX_BOUNDCYLINDER: 00165 { 00166 shapeInfo->m_halfExtend.setValue( 00167 objprop->m_boundobject.c.m_radius, 00168 objprop->m_boundobject.c.m_radius, 00169 objprop->m_boundobject.c.m_height * 0.5f 00170 ); 00171 shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER; 00172 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00173 break; 00174 } 00175 00176 case KX_BOUNDCONE: 00177 { 00178 shapeInfo->m_radius = objprop->m_boundobject.c.m_radius; 00179 shapeInfo->m_height = objprop->m_boundobject.c.m_height; 00180 shapeInfo->m_shapeType = PHY_SHAPE_CONE; 00181 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00182 break; 00183 } 00184 case KX_BOUNDPOLYTOPE: 00185 { 00186 shapeInfo->SetMesh(meshobj, dm,true); 00187 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00188 break; 00189 } 00190 case KX_BOUNDCAPSULE: 00191 { 00192 shapeInfo->m_radius = objprop->m_boundobject.c.m_radius; 00193 shapeInfo->m_height = objprop->m_boundobject.c.m_height; 00194 shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE; 00195 bm = shapeInfo->CreateBulletShape(ci.m_margin); 00196 break; 00197 } 00198 case KX_BOUNDMESH: 00199 { 00200 // mesh shapes can be shared, check first if we already have a shape on that mesh 00201 class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false); 00202 if (sharedShapeInfo != NULL) 00203 { 00204 shapeInfo->Release(); 00205 shapeInfo = sharedShapeInfo; 00206 shapeInfo->AddRef(); 00207 } else 00208 { 00209 shapeInfo->SetMesh(meshobj, dm, false); 00210 } 00211 00212 // Soft bodies require welding. Only avoid remove doubles for non-soft bodies! 00213 if (objprop->m_softbody) 00214 { 00215 shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI 00216 } 00217 00218 bm = shapeInfo->CreateBulletShape(ci.m_margin, useGimpact, !objprop->m_softbody); 00219 //should we compute inertia for dynamic shape? 00220 //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor); 00221 00222 break; 00223 } 00224 case KX_BOUND_DYN_MESH: 00225 /* do nothing */ 00226 break; 00227 } 00228 00229 00230 // ci.m_localInertiaTensor.setValue(0.1f,0.1f,0.1f); 00231 00232 if (!bm) 00233 { 00234 delete motionstate; 00235 shapeInfo->Release(); 00236 return; 00237 } 00238 00239 //bm->setMargin(ci.m_margin); 00240 00241 00242 if (objprop->m_isCompoundChild) 00243 { 00244 //find parent, compound shape and add to it 00245 //take relative transform into account! 00246 KX_BulletPhysicsController* parentCtrl = (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController(); 00247 assert(parentCtrl); 00248 CcdShapeConstructionInfo* parentShapeInfo = parentCtrl->GetShapeInfo(); 00249 btRigidBody* rigidbody = parentCtrl->GetRigidBody(); 00250 btCollisionShape* colShape = rigidbody->getCollisionShape(); 00251 assert(colShape->isCompound()); 00252 btCompoundShape* compoundShape = (btCompoundShape*)colShape; 00253 00254 // compute the local transform from parent, this may include several node in the chain 00255 SG_Node* gameNode = gameobj->GetSGNode(); 00256 SG_Node* parentNode = objprop->m_dynamic_parent->GetSGNode(); 00257 // relative transform 00258 MT_Vector3 parentScale = parentNode->GetWorldScaling(); 00259 parentScale[0] = MT_Scalar(1.0)/parentScale[0]; 00260 parentScale[1] = MT_Scalar(1.0)/parentScale[1]; 00261 parentScale[2] = MT_Scalar(1.0)/parentScale[2]; 00262 MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale; 00263 MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed(); 00264 MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale); 00265 MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation(); 00266 00267 shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]); 00268 bm->setLocalScaling(shapeInfo->m_childScale); 00269 shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]); 00270 float rot[12]; 00271 relativeRot.getValue(rot); 00272 shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot); 00273 00274 parentShapeInfo->AddShape(shapeInfo); 00275 compoundShape->addChildShape(shapeInfo->m_childTrans,bm); 00276 //do some recalc? 00277 //recalc inertia for rigidbody 00278 if (!rigidbody->isStaticOrKinematicObject()) 00279 { 00280 btVector3 localInertia; 00281 float mass = 1.f/rigidbody->getInvMass(); 00282 compoundShape->calculateLocalInertia(mass,localInertia); 00283 rigidbody->setMassProps(mass,localInertia); 00284 } 00285 shapeInfo->Release(); 00286 // delete motionstate as it's not used 00287 delete motionstate; 00288 return; 00289 } 00290 00291 if (objprop->m_hasCompoundChildren) 00292 { 00293 // create a compound shape info 00294 CcdShapeConstructionInfo *compoundShapeInfo = new CcdShapeConstructionInfo(); 00295 compoundShapeInfo->m_shapeType = PHY_SHAPE_COMPOUND; 00296 compoundShapeInfo->AddShape(shapeInfo); 00297 // create the compound shape manually as we already have the child shape 00298 btCompoundShape* compoundShape = new btCompoundShape(); 00299 compoundShape->addChildShape(shapeInfo->m_childTrans,bm); 00300 // now replace the shape 00301 bm = compoundShape; 00302 shapeInfo->Release(); 00303 shapeInfo = compoundShapeInfo; 00304 } 00305 00306 00307 00308 00309 00310 00311 #ifdef TEST_SIMD_HULL 00312 if (bm->IsPolyhedral()) 00313 { 00314 PolyhedralConvexShape* polyhedron = static_cast<PolyhedralConvexShape*>(bm); 00315 if (!polyhedron->m_optionalHull) 00316 { 00317 //first convert vertices in 'Point3' format 00318 int numPoints = polyhedron->GetNumVertices(); 00319 Point3* points = new Point3[numPoints+1]; 00320 //first 4 points should not be co-planar, so add central point to satisfy MakeHull 00321 points[0] = Point3(0.f,0.f,0.f); 00322 00323 btVector3 vertex; 00324 for (int p=0;p<numPoints;p++) 00325 { 00326 polyhedron->GetVertex(p,vertex); 00327 points[p+1] = Point3(vertex.getX(),vertex.getY(),vertex.getZ()); 00328 } 00329 00330 Hull* hull = Hull::MakeHull(numPoints+1,points); 00331 polyhedron->m_optionalHull = hull; 00332 } 00333 00334 } 00335 #endif //TEST_SIMD_HULL 00336 00337 00338 ci.m_collisionShape = bm; 00339 ci.m_shapeInfo = shapeInfo; 00340 ci.m_friction = smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice 00341 ci.m_restitution = smmaterial->m_restitution; 00342 ci.m_physicsEnv = env; 00343 // drag / damping is inverted 00344 ci.m_linearDamping = 1.f - shapeprops->m_lin_drag; 00345 ci.m_angularDamping = 1.f - shapeprops->m_ang_drag; 00346 //need a bit of damping, else system doesn't behave well 00347 ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behaviour 00348 00349 ci.m_do_anisotropic = shapeprops->m_do_anisotropic; 00350 ci.m_anisotropicFriction.setValue(shapeprops->m_friction_scaling[0],shapeprops->m_friction_scaling[1],shapeprops->m_friction_scaling[2]); 00351 00352 00354 //do Fh, do Rot Fh 00355 ci.m_do_fh = shapeprops->m_do_fh; 00356 ci.m_do_rot_fh = shapeprops->m_do_rot_fh ; 00357 ci.m_fh_damping = smmaterial->m_fh_damping; 00358 ci.m_fh_distance = smmaterial->m_fh_distance; 00359 ci.m_fh_normal = smmaterial->m_fh_normal; 00360 ci.m_fh_spring = smmaterial->m_fh_spring; 00361 ci.m_radius = objprop->m_radius; 00362 00363 00365 ci.m_gamesoftFlag = objprop->m_gamesoftFlag; 00366 ci.m_soft_linStiff = objprop->m_soft_linStiff; 00367 ci.m_soft_angStiff = objprop->m_soft_angStiff; /* angular stiffness 0..1 */ 00368 ci.m_soft_volume= objprop->m_soft_volume; /* volume preservation 0..1 */ 00369 00370 ci.m_soft_viterations= objprop->m_soft_viterations; /* Velocities solver iterations */ 00371 ci.m_soft_piterations= objprop->m_soft_piterations; /* Positions solver iterations */ 00372 ci.m_soft_diterations= objprop->m_soft_diterations; /* Drift solver iterations */ 00373 ci.m_soft_citerations= objprop->m_soft_citerations; /* Cluster solver iterations */ 00374 00375 ci.m_soft_kSRHR_CL= objprop->m_soft_kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */ 00376 ci.m_soft_kSKHR_CL= objprop->m_soft_kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */ 00377 ci.m_soft_kSSHR_CL= objprop->m_soft_kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */ 00378 ci.m_soft_kSR_SPLT_CL= objprop->m_soft_kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */ 00379 00380 ci.m_soft_kSK_SPLT_CL= objprop->m_soft_kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */ 00381 ci.m_soft_kSS_SPLT_CL= objprop->m_soft_kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */ 00382 ci.m_soft_kVCF= objprop->m_soft_kVCF; /* Velocities correction factor (Baumgarte) */ 00383 ci.m_soft_kDP= objprop->m_soft_kDP; /* Damping coefficient [0,1] */ 00384 00385 ci.m_soft_kDG= objprop->m_soft_kDG; /* Drag coefficient [0,+inf] */ 00386 ci.m_soft_kLF= objprop->m_soft_kLF; /* Lift coefficient [0,+inf] */ 00387 ci.m_soft_kPR= objprop->m_soft_kPR; /* Pressure coefficient [-inf,+inf] */ 00388 ci.m_soft_kVC= objprop->m_soft_kVC; /* Volume conversation coefficient [0,+inf] */ 00389 00390 ci.m_soft_kDF= objprop->m_soft_kDF; /* Dynamic friction coefficient [0,1] */ 00391 ci.m_soft_kMT= objprop->m_soft_kMT; /* Pose matching coefficient [0,1] */ 00392 ci.m_soft_kCHR= objprop->m_soft_kCHR; /* Rigid contacts hardness [0,1] */ 00393 ci.m_soft_kKHR= objprop->m_soft_kKHR; /* Kinetic contacts hardness [0,1] */ 00394 00395 ci.m_soft_kSHR= objprop->m_soft_kSHR; /* Soft contacts hardness [0,1] */ 00396 ci.m_soft_kAHR= objprop->m_soft_kAHR; /* Anchors hardness [0,1] */ 00397 ci.m_soft_collisionflags= objprop->m_soft_collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */ 00398 ci.m_soft_numclusteriterations= objprop->m_soft_numclusteriterations; /* number of iterations to refine collision clusters*/ 00399 00401 ci.m_collisionFilterGroup = 00402 (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) : 00403 (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) : 00404 short(CcdConstructionInfo::StaticFilter); 00405 ci.m_collisionFilterMask = 00406 (isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) : 00407 (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) : 00408 short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter); 00409 ci.m_bRigid = objprop->m_dyna && objprop->m_angular_rigidbody; 00410 00411 ci.m_contactProcessingThreshold = objprop->m_contactProcessingThreshold;//todo: expose this in advanced settings, just like margin, default to 10000 or so 00412 ci.m_bSoft = objprop->m_softbody; 00413 ci.m_bSensor = isbulletsensor; 00414 ci.m_bGimpact = useGimpact; 00415 MT_Vector3 scaling = gameobj->NodeGetWorldScaling(); 00416 ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]); 00417 KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,isbulletsensor,objprop->m_hasCompoundChildren); 00418 // shapeInfo is reference counted, decrement now as we don't use it anymore 00419 if (shapeInfo) 00420 shapeInfo->Release(); 00421 00422 gameobj->SetPhysicsController(physicscontroller,isbulletdyna); 00423 // don't add automatically sensor object, they are added when a collision sensor is registered 00424 if (!isbulletsensor && objprop->m_in_active_layer) 00425 { 00426 env->addCcdPhysicsController( physicscontroller); 00427 } 00428 physicscontroller->setNewClientInfo(gameobj->getClientInfo()); 00429 { 00430 btRigidBody* rbody = physicscontroller->GetRigidBody(); 00431 00432 if (rbody) 00433 { 00434 if (objprop->m_angular_rigidbody) 00435 { 00436 btVector3 linearFactor( 00437 objprop->m_lockXaxis? 0 : 1, 00438 objprop->m_lockYaxis? 0 : 1, 00439 objprop->m_lockZaxis? 0 : 1); 00440 btVector3 angularFactor( 00441 objprop->m_lockXRotaxis? 0 : 1, 00442 objprop->m_lockYRotaxis? 0 : 1, 00443 objprop->m_lockZRotaxis? 0 : 1); 00444 rbody->setLinearFactor(linearFactor); 00445 rbody->setAngularFactor(angularFactor); 00446 } 00447 00448 if (rbody && objprop->m_disableSleeping) 00449 { 00450 rbody->setActivationState(DISABLE_DEACTIVATION); 00451 } 00452 } 00453 } 00454 00455 CcdPhysicsController* parentCtrl = objprop->m_dynamic_parent ? (KX_BulletPhysicsController*)objprop->m_dynamic_parent->GetPhysicsController() : 0; 00456 physicscontroller->setParentCtrl(parentCtrl); 00457 00458 00459 //Now done directly in ci.m_collisionFlags so that it propagates to replica 00460 //if (objprop->m_ghost) 00461 //{ 00462 // rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); 00463 //} 00464 00465 if (objprop->m_dyna && !objprop->m_angular_rigidbody) 00466 { 00467 /* 00468 //setting the inertia could achieve similar results to constraint the up 00469 //but it is prone to instability, so use special 'Angular' constraint 00470 btVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal(); 00471 inertia.setX(0.f); 00472 inertia.setZ(0.f); 00473 00474 physicscontroller->GetRigidBody()->setInvInertiaDiagLocal(inertia); 00475 physicscontroller->GetRigidBody()->updateInertiaTensor(); 00476 */ 00477 00478 //env->createConstraint(physicscontroller,0,PHY_ANGULAR_CONSTRAINT,0,0,0,0,0,1); 00479 00480 //Now done directly in ci.m_bRigid so that it propagates to replica 00481 //physicscontroller->GetRigidBody()->setAngularFactor(0.f); 00482 ; 00483 } 00484 00485 bool isActor = objprop->m_isactor; 00486 gameobj->getClientInfo()->m_type = 00487 (isbulletsensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) : 00488 (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC; 00489 // store materialname in auxinfo, needed for touchsensors 00490 if (meshobj) 00491 { 00492 const STR_String& matname=meshobj->GetMaterialName(0); 00493 gameobj->getClientInfo()->m_auxilary_info = (matname.Length() ? (void*)(matname.ReadPtr()+2) : NULL); 00494 } else 00495 { 00496 gameobj->getClientInfo()->m_auxilary_info = 0; 00497 } 00498 00499 00500 gameobj->GetSGNode()->AddSGController(physicscontroller); 00501 00502 STR_String materialname; 00503 if (meshobj) 00504 materialname = meshobj->GetMaterialName(0); 00505 00506 physicscontroller->SetObject(gameobj->GetSGNode()); 00507 00508 #if 0 00509 00510 if (objprop->m_softbody && physicscontroller) 00511 { 00512 btSoftBody* softBody = physicscontroller->GetSoftBody(); 00513 if (softBody && gameobj->GetMesh(0))//only the first mesh, if any 00514 { 00515 //should be a mesh then, so add a soft body deformer 00516 KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer( gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj); 00517 gameobj->SetDeformer(softbodyDeformer); 00518 } 00519 } 00520 #endif 00521 00522 } 00523 00524 00525 void KX_ClearBulletSharedShapes() 00526 { 00527 } 00528 00529 /* Refresh the physics object from either an object or a mesh. 00530 * gameobj must be valid 00531 * from_gameobj and from_meshobj can be NULL 00532 * 00533 * when setting the mesh, the following vars get priority 00534 * 1) from_meshobj - creates the phys mesh from RAS_MeshObject 00535 * 2) from_gameobj - creates the phys mesh from the DerivedMesh where possible, else the RAS_MeshObject 00536 * 3) gameobj - update the phys mesh from DerivedMesh or RAS_MeshObject 00537 * 00538 * Most of the logic behind this is in shapeInfo->UpdateMesh(...) 00539 */ 00540 bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) 00541 { 00542 KX_BulletPhysicsController *spc= static_cast<KX_BulletPhysicsController*>((gameobj->GetPhysicsController())); 00543 CcdShapeConstructionInfo *shapeInfo; 00544 00545 /* if this is the child of a compound shape this can happen 00546 * dont support compound shapes for now */ 00547 if(spc==NULL) 00548 return false; 00549 00550 shapeInfo = spc->GetShapeInfo(); 00551 00552 if(shapeInfo->m_shapeType != PHY_SHAPE_MESH/* || spc->GetSoftBody()*/) 00553 return false; 00554 00555 spc->DeleteControllerShape(); 00556 00557 if(from_gameobj==NULL && from_meshobj==NULL) 00558 from_gameobj= gameobj; 00559 00560 /* updates the arrays used for making the new bullet mesh */ 00561 shapeInfo->UpdateMesh(from_gameobj, from_meshobj); 00562 00563 /* create the new bullet mesh */ 00564 CcdConstructionInfo& cci = spc->getConstructionInfo(); 00565 btCollisionShape* bm= shapeInfo->CreateBulletShape(cci.m_margin, cci.m_bGimpact, !cci.m_bSoft); 00566 00567 spc->ReplaceControllerShape(bm); 00568 return true; 00569 } 00570 #endif // USE_BULLET