Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2010-02-04 00:41:03 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2010-02-04 00:41:03 +0300
commit0020de72e45cae82561e07e284c520170e5e3ea8 (patch)
treeee7a23bfc47d2edaa7ec5d6fcb666c7f28ec28cd /source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
parent02d9da1d5d0387238014e7737b76c87cd520b754 (diff)
BGE: Optimize Soft body conversion: don't create BVH structure.
A btBvhTriangleMeshShape object is created when converting a mesh to physics, also in case of Soft body although the soft body will not use it (it only uses the mesh interface). This patch keeps this system for compatibility with the KX converter but avoids the creation of the BVH structure, which consumes a lots of CPU. This should speed up significantly the conversion of large mesh to softbody. A secondary optimization is that the sharing of shapeInfo is extended to rigid body using gImpact. Before it was only active between static body and soft body.
Diffstat (limited to 'source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp')
-rw-r--r--source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp24
1 files changed, 14 insertions, 10 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
index bae32c74d1a..c693913a3a1 100644
--- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
+++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
@@ -97,6 +97,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
bool isbulletdyna = false;
bool isbulletsensor = false;
+ bool useGimpact = false;
CcdConstructionInfo ci;
class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
@@ -121,7 +122,8 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
shapeInfo->m_radius = objprop->m_radius;
isbulletdyna = objprop->m_dyna;
isbulletsensor = objprop->m_sensor;
-
+ useGimpact = ((isbulletdyna || isbulletsensor) && !objprop->m_softbody);
+
ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
btCollisionShape* bm = 0;
@@ -178,24 +180,22 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
}
case KX_BOUNDPOLYTOPE:
{
- shapeInfo->SetMesh(meshobj, dm,true,false);
+ shapeInfo->SetMesh(meshobj, dm,true);
bm = shapeInfo->CreateBulletShape(ci.m_margin);
break;
}
case KX_BOUNDMESH:
{
- bool useGimpact = ((ci.m_mass || isbulletsensor) && !objprop->m_softbody);
-
// mesh shapes can be shared, check first if we already have a shape on that mesh
- class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false,useGimpact);
+ class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false);
if (sharedShapeInfo != NULL)
{
- delete shapeInfo;
+ shapeInfo->Release();
shapeInfo = sharedShapeInfo;
shapeInfo->AddRef();
} else
{
- shapeInfo->SetMesh(meshobj, dm, false,useGimpact);
+ shapeInfo->SetMesh(meshobj, dm, false);
}
// Soft bodies require welding. Only avoid remove doubles for non-soft bodies!
@@ -204,7 +204,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
shapeInfo->setVertexWeldingThreshold1(objprop->m_soft_welding); //todo: expose this to the UI
}
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
+ bm = shapeInfo->CreateBulletShape(ci.m_margin, useGimpact, !objprop->m_softbody);
//should we compute inertia for dynamic shape?
//bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
@@ -218,7 +218,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
if (!bm)
{
delete motionstate;
- delete shapeInfo;
+ shapeInfo->Release();
return;
}
@@ -268,6 +268,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
compoundShape->calculateLocalInertia(mass,localInertia);
rigidbody->setMassProps(mass,localInertia);
}
+ shapeInfo->Release();
// delete motionstate as it's not used
delete motionstate;
return;
@@ -284,6 +285,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
// now replace the shape
bm = compoundShape;
+ shapeInfo->Release();
shapeInfo = compoundShapeInfo;
}
@@ -395,6 +397,7 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj,
ci.m_contactProcessingThreshold = objprop->m_contactProcessingThreshold;//todo: expose this in advanced settings, just like margin, default to 10000 or so
ci.m_bSoft = objprop->m_softbody;
ci.m_bSensor = isbulletsensor;
+ ci.m_bGimpact = useGimpact;
MT_Vector3 scaling = gameobj->NodeGetWorldScaling();
ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]);
KX_BulletPhysicsController* physicscontroller = new KX_BulletPhysicsController(ci,isbulletdyna,isbulletsensor,objprop->m_hasCompoundChildren);
@@ -544,7 +547,8 @@ bool KX_ReInstanceBulletShapeFromMesh(KX_GameObject *gameobj, KX_GameObject *fro
shapeInfo->UpdateMesh(from_gameobj, from_meshobj);
/* create the new bullet mesh */
- btCollisionShape* bm= shapeInfo->CreateBulletShape(spc->getConstructionInfo().m_margin);
+ CcdConstructionInfo& cci = spc->getConstructionInfo();
+ btCollisionShape* bm= shapeInfo->CreateBulletShape(cci.m_margin, cci.m_bGimpact, !cci.m_bSoft);
spc->ReplaceControllerShape(bm);
return true;