From b991b32458cdccb19a203e7ba4ca6b5780aad6cb Mon Sep 17 00:00:00 2001 From: Benoit Bolsee Date: Sat, 25 Apr 2009 12:20:59 +0000 Subject: BGE mesh modifiers: fix view frustrum culling for mesh with modifiers. Update the bounding box based on mesh extent after applying the modifiers. --- .../gameengine/Converter/BL_BlenderDataConversion.cpp | 8 +++++++- source/gameengine/Converter/BL_MeshDeformer.h | 1 + source/gameengine/Converter/BL_ModifierDeformer.cpp | 9 +++++++++ source/gameengine/Converter/BL_SkinDeformer.h | 5 +++++ source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 7 +++++++ .../gameengine/Physics/Bullet/CcdGraphicController.cpp | 17 +++++++++++++++-- source/gameengine/Physics/Bullet/CcdGraphicController.h | 2 ++ .../gameengine/Physics/common/PHY_IGraphicController.h | 2 ++ source/gameengine/Rasterizer/RAS_Deformer.h | 1 + 9 files changed, 49 insertions(+), 3 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 84b7407aacf..b2f283220a0 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1298,8 +1298,14 @@ void BL_CreateGraphicObjectNew(KX_GameObject* gameobj, gameobj->SetGraphicController(ctrl); ctrl->setNewClientInfo(gameobj->getClientInfo()); ctrl->setLocalAabb(localAabbMin, localAabbMax); - if (isActive) + if (isActive) { + // add first, this will create the proxy handle env->addCcdGraphicController(ctrl); + // update the mesh if there is a deformer, this will also update the bounding box for modifiers + RAS_Deformer* deformer = gameobj->GetDeformer(); + if (deformer) + deformer->UpdateBuckets(); + } } break; #endif diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h index 34944421b28..d1754618df2 100644 --- a/source/gameengine/Converter/BL_MeshDeformer.h +++ b/source/gameengine/Converter/BL_MeshDeformer.h @@ -64,6 +64,7 @@ public: virtual void SetSimulatedTime(double time){}; virtual bool Apply(class RAS_IPolyMaterial *mat); virtual bool Update(void){ return false; }; + virtual bool UpdateBuckets(void){ return false; }; virtual RAS_Deformer* GetReplica(){return NULL;}; virtual void ProcessReplica() { }; struct Mesh* GetMesh() { return m_bmesh; }; diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp index c3131559a6f..3c4c0c5caad 100644 --- a/source/gameengine/Converter/BL_ModifierDeformer.cpp +++ b/source/gameengine/Converter/BL_ModifierDeformer.cpp @@ -37,6 +37,7 @@ #include "STR_HashedString.h" #include "RAS_IPolygonMaterial.h" #include "BL_SkinMeshObject.h" +#include "PHY_IGraphicController.h" //#include "BL_ArmatureController.h" #include "DNA_armature_types.h" @@ -132,6 +133,14 @@ bool BL_ModifierDeformer::Update(void) m_dm->release(m_dm); } m_dm = dm; + /* update the graphic controller */ + PHY_IGraphicController *ctrl = m_gameobj->GetGraphicController(); + if (ctrl) { + float min_r[3], max_r[3]; + INIT_MINMAX(min_r, max_r); + m_dm->getMinMax(m_dm, min_r, max_r); + ctrl->setLocalAabb(min_r, max_r); + } m_lastModifierUpdate=m_gameobj->GetLastFrame(); bShapeUpdate = true; } diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h index ee240588851..0a7b60788f9 100644 --- a/source/gameengine/Converter/BL_SkinDeformer.h +++ b/source/gameengine/Converter/BL_SkinDeformer.h @@ -71,6 +71,11 @@ public: virtual ~BL_SkinDeformer(); bool Update (void); bool Apply (class RAS_IPolyMaterial *polymat); + bool UpdateBuckets(void) + { + // update the deformer and all the mesh slots; Apply() does it well, so just call it. + return Apply(NULL); + } bool PoseUpdated(void) { if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) { diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index f4f8ec9f91b..700c5f304e7 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -759,6 +759,13 @@ void KX_ConvertODEEngineObject(KX_GameObject* gameobj, //printf("update\n"); return true;//?? } + virtual bool UpdateBuckets(void) + { + // this is to update the mesh slots outside the rasterizer, + // no need to do it for this deformer, it's done in any case in Apply() + return false; + } + virtual RAS_Deformer *GetReplica() { KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(*this); diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.cpp b/source/gameengine/Physics/Bullet/CcdGraphicController.cpp index caf18fd28ba..2d1f841af0c 100644 --- a/source/gameengine/Physics/Bullet/CcdGraphicController.cpp +++ b/source/gameengine/Physics/Bullet/CcdGraphicController.cpp @@ -47,11 +47,24 @@ void CcdGraphicController::setLocalAabb(const btVector3& aabbMin,const btVector3 void CcdGraphicController::setLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax) { - m_localAabbMin = btVector3(aabbMin[0],aabbMin[1],aabbMin[2]); - m_localAabbMax = btVector3(aabbMax[0],aabbMax[1],aabbMax[2]); + m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]); + m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]); SetGraphicTransform(); } +void CcdGraphicController::setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax) +{ + m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]); + m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]); + SetGraphicTransform(); +} + +void CcdGraphicController::setLocalAabb(const float* aabbMin,const float* aabbMax) +{ + m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]); + m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]); + SetGraphicTransform(); +} void CcdGraphicController::getAabb(btVector3& aabbMin, btVector3& aabbMax) { diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.h b/source/gameengine/Physics/Bullet/CcdGraphicController.h index 8faa0944313..8f44a623371 100644 --- a/source/gameengine/Physics/Bullet/CcdGraphicController.h +++ b/source/gameengine/Physics/Bullet/CcdGraphicController.h @@ -38,6 +38,8 @@ public: void setLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax); void setLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax); + virtual void setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax); + virtual void setLocalAabb(const float aabbMin[3],const float aabbMax[3]); PHY_IMotionState* GetMotionState() { return m_motionState; } void getAabb(btVector3& aabbMin, btVector3& aabbMax); diff --git a/source/gameengine/Physics/common/PHY_IGraphicController.h b/source/gameengine/Physics/common/PHY_IGraphicController.h index 36b8a978e87..8acc5c2f9d3 100644 --- a/source/gameengine/Physics/common/PHY_IGraphicController.h +++ b/source/gameengine/Physics/common/PHY_IGraphicController.h @@ -47,6 +47,8 @@ class PHY_IGraphicController : public PHY_IController SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding') */ virtual bool SetGraphicTransform()=0; + virtual void setLocalAabb(const PHY__Vector3& aabbMin,const PHY__Vector3& aabbMax)=0; + virtual void setLocalAabb(const float* aabbMin,const float* aabbMax)=0; virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate) {return 0;} diff --git a/source/gameengine/Rasterizer/RAS_Deformer.h b/source/gameengine/Rasterizer/RAS_Deformer.h index 5a6bab4c82d..fe081dd4aa5 100644 --- a/source/gameengine/Rasterizer/RAS_Deformer.h +++ b/source/gameengine/Rasterizer/RAS_Deformer.h @@ -44,6 +44,7 @@ public: virtual void Relink(GEN_Map*map)=0; virtual bool Apply(class RAS_IPolyMaterial *polymat)=0; virtual bool Update(void)=0; + virtual bool UpdateBuckets(void)=0; virtual RAS_Deformer *GetReplica()=0; virtual void ProcessReplica()=0; virtual bool SkipVertexTransform() -- cgit v1.2.3