BGE mesh modifiers: fix view frustrum culling for mesh with modifiers. Update the...
authorBenoit Bolsee <benoit.bolsee@online.be>
Sat, 25 Apr 2009 12:20:59 +0000 (12:20 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Sat, 25 Apr 2009 12:20:59 +0000 (12:20 +0000)
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/BL_MeshDeformer.h
source/gameengine/Converter/BL_ModifierDeformer.cpp
source/gameengine/Converter/BL_SkinDeformer.h
source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
source/gameengine/Physics/Bullet/CcdGraphicController.cpp
source/gameengine/Physics/Bullet/CcdGraphicController.h
source/gameengine/Physics/common/PHY_IGraphicController.h
source/gameengine/Rasterizer/RAS_Deformer.h

index 84b7407..b2f2832 100644 (file)
@@ -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
index 3494442..d175461 100644 (file)
@@ -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; };
index c313155..3c4c0c5 100644 (file)
@@ -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;
        }
index ee24058..0a7b607 100644 (file)
@@ -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()) {
index f4f8ec9..700c5f3 100644 (file)
@@ -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);
index caf18fd..2d1f841 100644 (file)
@@ -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)
 {
index 8faa094..8f44a62 100644 (file)
@@ -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);
index 36b8a97..8acc5c2 100644 (file)
@@ -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;}
 
index 5a6bab4..fe081dd 100644 (file)
@@ -44,6 +44,7 @@ public:
        virtual void Relink(GEN_Map<class GEN_HashedPtr, void*>*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()