[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19923] trunk/blender/source/gameengine: BGE mesh modifiers: fix view frustrum culling for mesh with modifiers.

Benoit Bolsee benoit.bolsee at online.be
Sat Apr 25 14:21:00 CEST 2009


Revision: 19923
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19923
Author:   ben2610
Date:     2009-04-25 14:20:59 +0200 (Sat, 25 Apr 2009)

Log Message:
-----------
BGE mesh modifiers: fix view frustrum culling for mesh with modifiers. Update the bounding box based on mesh extent after applying the modifiers.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
    trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h
    trunk/blender/source/gameengine/Converter/BL_ModifierDeformer.cpp
    trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h
    trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
    trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
    trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
    trunk/blender/source/gameengine/Rasterizer/RAS_Deformer.h

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2009-04-25 12:20:59 UTC (rev 19923)
@@ -1298,8 +1298,14 @@
 				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

Modified: trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Converter/BL_MeshDeformer.h	2009-04-25 12:20:59 UTC (rev 19923)
@@ -64,6 +64,7 @@
 	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; };

Modified: trunk/blender/source/gameengine/Converter/BL_ModifierDeformer.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ModifierDeformer.cpp	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Converter/BL_ModifierDeformer.cpp	2009-04-25 12:20:59 UTC (rev 19923)
@@ -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 @@
 			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;
 	}

Modified: trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Converter/BL_SkinDeformer.h	2009-04-25 12:20:59 UTC (rev 19923)
@@ -71,6 +71,11 @@
 	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()) {

Modified: trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp	2009-04-25 12:20:59 UTC (rev 19923)
@@ -759,6 +759,13 @@
 			//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);

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.cpp	2009-04-25 12:20:59 UTC (rev 19923)
@@ -47,12 +47,25 @@
 
 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)
 {
 	btVector3 pos;

Modified: trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Physics/Bullet/CcdGraphicController.h	2009-04-25 12:20:59 UTC (rev 19923)
@@ -38,6 +38,8 @@
 
 	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);

Modified: trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h
===================================================================
--- trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Physics/common/PHY_IGraphicController.h	2009-04-25 12:20:59 UTC (rev 19923)
@@ -47,6 +47,8 @@
 			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;}
 

Modified: trunk/blender/source/gameengine/Rasterizer/RAS_Deformer.h
===================================================================
--- trunk/blender/source/gameengine/Rasterizer/RAS_Deformer.h	2009-04-25 07:17:36 UTC (rev 19922)
+++ trunk/blender/source/gameengine/Rasterizer/RAS_Deformer.h	2009-04-25 12:20:59 UTC (rev 19923)
@@ -44,6 +44,7 @@
 	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()





More information about the Bf-blender-cvs mailing list