Revision: 20021
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20021
Author: ben2610
Date: 2009-05-01 21:02:23 +0200 (Fri, 01 May 2009)
Log Message:
-----------
BGE: work around a problem with DBVT culling when graphic objects are rescaled.
This happens when objects with very diverse scale are instantiated with
dupligroup. The problem remains when the objects are rescaled during the game.
The effect of the problem is an inefficient culling: objects can have a
bounding box larger than needed. Patch to fix the problem is filed at Bullet
forum.
Modified Paths:
--------------
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-05-01
16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-05-01
19:02:23 UTC (rev 20021)
@@ -331,8 +331,37 @@
}
+static void setGraphicController_recursive(SG_Node* node, bool v)
+{
+ NodeList& children = node->GetSGChildren();
+ for (NodeList::iterator childit =
children.begin();!(childit==children.end());++childit)
+ {
+ SG_Node* childnode = (*childit);
+ KX_GameObject *clientgameobj = static_cast<KX_GameObject*>(
(*childit)->GetSGClientObject());
+ if (clientgameobj != NULL) // This is a GameObject
+ clientgameobj->ActivateGraphicController(v, false);
+
+ // if the childobj is NULL then this may be an inverse parent
link
+ // so a non recursive search should still look down this node.
+ setGraphicController_recursive(childnode, v);
+ }
+}
+
+void KX_GameObject::ActivateGraphicController(bool active, bool recurse)
+{
+ if (m_pGraphicController)
+ {
+ m_pGraphicController->Activate(active);
+ }
+ if (recurse)
+ {
+ setGraphicController_recursive(GetSGNode(), active);
+ }
+}
+
+
CValue* KX_GameObject::GetReplica()
{
KX_GameObject* replica = new KX_GameObject(*this);
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-05-01
16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.h 2009-05-01
19:02:23 UTC (rev 20021)
@@ -385,6 +385,10 @@
{
m_pGraphicController = graphiccontroller;
}
+ /*
+ * @add/remove the graphic controller to the physic system
+ */
+ void ActivateGraphicController(bool active, bool recurse);
/**
* @section Coordinate system manipulation functions
Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2009-05-01 16:59:27 UTC
(rev 20020)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp 2009-05-01 19:02:23 UTC
(rev 20021)
@@ -717,10 +717,13 @@
// set the orientation after position for softbody!
MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() *
gameobj->NodeGetWorldOrientation();
replica->NodeSetLocalOrientation(newori);
-
+ // update scenegraph for entire tree of children
replica->GetSGNode()->UpdateWorldData(0);
replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox());
replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius());
+ // we can now add the graphic controller to the physic engine
+ replica->ActivateGraphicController(true,true);
+
// done with replica
replica->Release();
}
@@ -831,6 +834,8 @@
replica->GetSGNode()->UpdateWorldData(0);
replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
+ // the size is correct, we can add the graphic controller to the physic
engine
+ replica->ActivateGraphicController(true,true);
// now replicate logic
vector<KX_GameObject*>::iterator git;
Modified:
trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
2009-05-01 16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
2009-05-01 19:02:23 UTC (rev 20021)
@@ -118,8 +118,17 @@
replica->m_motionState = motionState;
replica->m_newClientInfo = NULL;
replica->m_handle = NULL;
- m_phyEnv->addCcdGraphicController(replica);
+ // don't add the graphic controller now: work around a bug in Bullet
with rescaling,
+ // (the scale of the controller is not yet defined).
+ //m_phyEnv->addCcdGraphicController(replica);
return replica;
}
+void CcdGraphicController::Activate(bool active)
+{
+ if (active)
+ m_phyEnv->addCcdGraphicController(this);
+ else
+ m_phyEnv->removeCcdGraphicController(this);
+}
Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
2009-05-01 16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
2009-05-01 19:02:23 UTC (rev 20021)
@@ -55,6 +55,10 @@
* Updates the Aabb based on the motion state
*/
virtual bool SetGraphicTransform();
+ /**
+ * Add/remove to environment
+ */
+ virtual void Activate(bool active);
// client info for culling
virtual void* getNewClientInfo() { return m_newClientInfo; }
Modified:
trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
2009-05-01 16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
2009-05-01 19:02:23 UTC (rev 20021)
@@ -579,7 +579,7 @@
void CcdPhysicsEnvironment::addCcdGraphicController(CcdGraphicController* ctrl)
{
- if (m_cullingTree)
+ if (m_cullingTree && !ctrl->getBroadphaseHandle())
{
btVector3 minAabb;
btVector3 maxAabb;
Modified:
trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
2009-05-01 16:59:27 UTC (rev 20020)
+++ trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
2009-05-01 19:02:23 UTC (rev 20021)
@@ -47,6 +47,7 @@
SynchronizeMotionStates ynchronizes dynas, kinematic
and deformable entities (and do 'late binding')
*/
virtual bool SetGraphicTransform()=0;
+ virtual void Activate(bool active=true)=0;
virtual void setLocalAabb(const PHY__Vector3& aabbMin,const
PHY__Vector3& aabbMax)=0;
virtual void setLocalAabb(const float* aabbMin,const float*
aabbMax)=0;
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs