forked from bartvdbraak/blender
BGE Cleanup: Reducing KX_BlenderSceneConverter's dependence on Bullet.
* Moving the BlenderDebugDraw (derived from btIDebugDraw) from KX_BlenderSceneConverter to CcdPhysicsEnvironment * Moving CcdPhysicsEnvironment initialization to CcdPhysicsEnvironment (this could probably be cleaned up some more with some sort of factory, or at least moving code to CcdPhysicsEnvironment's constructor) * Simplifying physics environment initialization (went from two switches to one)
This commit is contained in:
parent
3442a658fc
commit
89c61b20f0
@ -246,60 +246,6 @@ Scene *KX_BlenderSceneConverter::GetBlenderSceneForName(const STR_String& name)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_BULLET
|
|
||||||
|
|
||||||
#include "LinearMath/btIDebugDraw.h"
|
|
||||||
|
|
||||||
|
|
||||||
struct BlenderDebugDraw : public btIDebugDraw
|
|
||||||
{
|
|
||||||
BlenderDebugDraw () :
|
|
||||||
m_debugMode(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int m_debugMode;
|
|
||||||
|
|
||||||
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
|
|
||||||
{
|
|
||||||
if (m_debugMode >0)
|
|
||||||
{
|
|
||||||
MT_Vector3 kxfrom(from[0],from[1],from[2]);
|
|
||||||
MT_Vector3 kxto(to[0],to[1],to[2]);
|
|
||||||
MT_Vector3 kxcolor(color[0],color[1],color[2]);
|
|
||||||
|
|
||||||
KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void reportErrorWarning(const char* warningString)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color)
|
|
||||||
{
|
|
||||||
//not yet
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void setDebugMode(int debugMode)
|
|
||||||
{
|
|
||||||
m_debugMode = debugMode;
|
|
||||||
}
|
|
||||||
virtual int getDebugMode() const
|
|
||||||
{
|
|
||||||
return m_debugMode;
|
|
||||||
}
|
|
||||||
///todo: find out if Blender can do this
|
|
||||||
virtual void draw3dText(const btVector3& location,const char* textString)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
|
void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
|
||||||
class RAS_IRasterizer* rendertools,
|
class RAS_IRasterizer* rendertools,
|
||||||
class RAS_ICanvas* canvas,
|
class RAS_ICanvas* canvas,
|
||||||
@ -308,8 +254,9 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
|
|||||||
//find out which physics engine
|
//find out which physics engine
|
||||||
Scene *blenderscene = destinationscene->GetBlenderScene();
|
Scene *blenderscene = destinationscene->GetBlenderScene();
|
||||||
|
|
||||||
|
PHY_IPhysicsEnvironment *phy_env = NULL;
|
||||||
|
|
||||||
e_PhysicsEngine physics_engine = UseBullet;
|
e_PhysicsEngine physics_engine = UseBullet;
|
||||||
bool useDbvtCulling = false;
|
|
||||||
// hook for registration function during conversion.
|
// hook for registration function during conversion.
|
||||||
m_currentScene = destinationscene;
|
m_currentScene = destinationscene;
|
||||||
destinationscene->SetSceneConverter(this);
|
destinationscene->SetSceneConverter(this);
|
||||||
@ -318,55 +265,30 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
|
|||||||
// when doing threaded conversion, so it's disabled for now.
|
// when doing threaded conversion, so it's disabled for now.
|
||||||
// SG_SetActiveStage(SG_STAGE_CONVERTER);
|
// SG_SetActiveStage(SG_STAGE_CONVERTER);
|
||||||
|
|
||||||
if (blenderscene)
|
switch (blenderscene->gm.physicsEngine)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_BULLET
|
||||||
switch (blenderscene->gm.physicsEngine)
|
case WOPHY_BULLET:
|
||||||
{
|
{
|
||||||
case WOPHY_BULLET:
|
SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
|
||||||
{
|
int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0);
|
||||||
physics_engine = UseBullet;
|
|
||||||
useDbvtCulling = (blenderscene->gm.mode & WO_DBVT_CULLING) != 0;
|
phy_env = CcdPhysicsEnvironment::Create(blenderscene, visualizePhysics);
|
||||||
break;
|
physics_engine = UseBullet;
|
||||||
}
|
break;
|
||||||
default:
|
}
|
||||||
case WOPHY_NONE:
|
#endif
|
||||||
{
|
default:
|
||||||
physics_engine = UseNone;
|
case WOPHY_NONE:
|
||||||
break;
|
{
|
||||||
}
|
// We should probably use some sort of factory here
|
||||||
|
phy_env = new DummyPhysicsEnvironment();
|
||||||
|
physics_engine = UseNone;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (physics_engine)
|
destinationscene->SetPhysicsEnvironment(phy_env);
|
||||||
{
|
|
||||||
#ifdef WITH_BULLET
|
|
||||||
case UseBullet:
|
|
||||||
{
|
|
||||||
CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment(useDbvtCulling);
|
|
||||||
ccdPhysEnv->SetDebugDrawer(new BlenderDebugDraw());
|
|
||||||
ccdPhysEnv->SetDeactivationLinearTreshold(blenderscene->gm.lineardeactthreshold);
|
|
||||||
ccdPhysEnv->SetDeactivationAngularTreshold(blenderscene->gm.angulardeactthreshold);
|
|
||||||
ccdPhysEnv->SetDeactivationTime(blenderscene->gm.deactivationtime);
|
|
||||||
|
|
||||||
SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
|
|
||||||
int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0);
|
|
||||||
if (visualizePhysics)
|
|
||||||
ccdPhysEnv->SetDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_DrawConstraintLimits|btIDebugDraw::DBG_DrawConstraints);
|
|
||||||
|
|
||||||
//todo: get a button in blender ?
|
|
||||||
//disable / enable debug drawing (contact points, aabb's etc)
|
|
||||||
//ccdPhysEnv->setDebugMode(1);
|
|
||||||
destinationscene->SetPhysicsEnvironment(ccdPhysEnv);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
case UseNone:
|
|
||||||
physics_engine = UseNone;
|
|
||||||
destinationscene ->SetPhysicsEnvironment(new DummyPhysicsEnvironment());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
BL_ConvertBlenderObjects(m_maggie,
|
BL_ConvertBlenderObjects(m_maggie,
|
||||||
destinationscene,
|
destinationscene,
|
||||||
@ -389,12 +311,6 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
|
|||||||
//This cache mecanism is buggy so I leave it disable and the memory leak
|
//This cache mecanism is buggy so I leave it disable and the memory leak
|
||||||
//that would result from this is fixed in RemoveScene()
|
//that would result from this is fixed in RemoveScene()
|
||||||
m_map_mesh_to_gamemesh.clear();
|
m_map_mesh_to_gamemesh.clear();
|
||||||
|
|
||||||
#ifndef WITH_BULLET
|
|
||||||
/* quiet compiler warning */
|
|
||||||
(void)useDbvtCulling;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function removes all entities stored in the converter for that scene
|
// This function removes all entities stored in the converter for that scene
|
||||||
|
@ -40,10 +40,14 @@ subject to the following restrictions:
|
|||||||
#include "PHY_IMotionState.h"
|
#include "PHY_IMotionState.h"
|
||||||
#include "PHY_ICharacter.h"
|
#include "PHY_ICharacter.h"
|
||||||
#include "KX_GameObject.h"
|
#include "KX_GameObject.h"
|
||||||
|
#include "KX_PythonInit.h" // for KX_RasterizerDrawDebugLine
|
||||||
#include "RAS_MeshObject.h"
|
#include "RAS_MeshObject.h"
|
||||||
#include "RAS_Polygon.h"
|
#include "RAS_Polygon.h"
|
||||||
#include "RAS_TexVert.h"
|
#include "RAS_TexVert.h"
|
||||||
|
|
||||||
|
#include "DNA_scene_types.h"
|
||||||
|
#include "DNA_world_types.h"
|
||||||
|
|
||||||
#define CCD_CONSTRAINT_DISABLE_LINKED_COLLISION 0x80
|
#define CCD_CONSTRAINT_DISABLE_LINKED_COLLISION 0x80
|
||||||
|
|
||||||
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
#ifdef NEW_BULLET_VEHICLE_SUPPORT
|
||||||
@ -2895,3 +2899,63 @@ void CcdPhysicsEnvironment::ExportFile(const char* filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct BlenderDebugDraw : public btIDebugDraw
|
||||||
|
{
|
||||||
|
BlenderDebugDraw () :
|
||||||
|
m_debugMode(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int m_debugMode;
|
||||||
|
|
||||||
|
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
|
||||||
|
{
|
||||||
|
if (m_debugMode >0)
|
||||||
|
{
|
||||||
|
MT_Vector3 kxfrom(from[0],from[1],from[2]);
|
||||||
|
MT_Vector3 kxto(to[0],to[1],to[2]);
|
||||||
|
MT_Vector3 kxcolor(color[0],color[1],color[2]);
|
||||||
|
|
||||||
|
KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void reportErrorWarning(const char* warningString)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color)
|
||||||
|
{
|
||||||
|
//not yet
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void setDebugMode(int debugMode)
|
||||||
|
{
|
||||||
|
m_debugMode = debugMode;
|
||||||
|
}
|
||||||
|
virtual int getDebugMode() const
|
||||||
|
{
|
||||||
|
return m_debugMode;
|
||||||
|
}
|
||||||
|
///todo: find out if Blender can do this
|
||||||
|
virtual void draw3dText(const btVector3& location,const char* textString)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
CcdPhysicsEnvironment *CcdPhysicsEnvironment::Create(Scene *blenderscene, bool visualizePhysics)
|
||||||
|
{
|
||||||
|
CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment((blenderscene->gm.mode & WO_DBVT_CULLING) != 0);
|
||||||
|
ccdPhysEnv->SetDebugDrawer(new BlenderDebugDraw());
|
||||||
|
ccdPhysEnv->SetDeactivationLinearTreshold(blenderscene->gm.lineardeactthreshold);
|
||||||
|
ccdPhysEnv->SetDeactivationAngularTreshold(blenderscene->gm.angulardeactthreshold);
|
||||||
|
ccdPhysEnv->SetDeactivationTime(blenderscene->gm.deactivationtime);
|
||||||
|
|
||||||
|
if (visualizePhysics)
|
||||||
|
ccdPhysEnv->SetDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_DrawConstraintLimits|btIDebugDraw::DBG_DrawConstraints);
|
||||||
|
|
||||||
|
return ccdPhysEnv;
|
||||||
|
}
|
||||||
|
@ -260,6 +260,8 @@ protected:
|
|||||||
|
|
||||||
void MergeEnvironment(PHY_IPhysicsEnvironment *other_env);
|
void MergeEnvironment(PHY_IPhysicsEnvironment *other_env);
|
||||||
|
|
||||||
|
static CcdPhysicsEnvironment *Create(struct Scene *blenderscene, bool visualizePhysics);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user