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