Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/gameengine/Converter/KX_BlenderSceneConverter.cpp')
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp146
1 files changed, 36 insertions, 110 deletions
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
index 854e9fe7327..5930d5e90d2 100644
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
@@ -50,7 +50,6 @@
#include "DummyPhysicsEnvironment.h"
-#include "KX_ConvertPhysicsObject.h"
#ifdef WITH_BULLET
#include "CcdPhysicsEnvironment.h"
@@ -190,9 +189,6 @@ KX_BlenderSceneConverter::~KX_BlenderSceneConverter()
}
m_meshobjects.clear();
-#ifdef WITH_BULLET
- KX_ClearBulletSharedShapes();
-#endif
/* free any data that was dynamically loaded */
while (m_DynamicMaggie.size() != 0)
@@ -249,60 +245,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,
class RAS_IRasterizer* rendertools,
class RAS_ICanvas* canvas,
@@ -311,8 +253,9 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
//find out which physics engine
Scene *blenderscene = destinationscene->GetBlenderScene();
+ PHY_IPhysicsEnvironment *phy_env = NULL;
+
e_PhysicsEngine physics_engine = UseBullet;
- bool useDbvtCulling = false;
// hook for registration function during conversion.
m_currentScene = destinationscene;
destinationscene->SetSceneConverter(this);
@@ -321,56 +264,31 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
// when doing threaded conversion, so it's disabled for now.
// SG_SetActiveStage(SG_STAGE_CONVERTER);
- if (blenderscene)
+ switch (blenderscene->gm.physicsEngine)
{
-
- switch (blenderscene->gm.physicsEngine)
+#ifdef WITH_BULLET
+ case WOPHY_BULLET:
{
- case WOPHY_BULLET:
- {
- physics_engine = UseBullet;
- useDbvtCulling = (blenderscene->gm.mode & WO_DBVT_CULLING) != 0;
- break;
- }
- default:
- case WOPHY_NONE:
- {
- physics_engine = UseNone;
- break;
- }
- }
- }
+ SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
+ int visualizePhysics = SYS_GetCommandLineInt(syshandle,"show_physics",0);
- switch (physics_engine)
- {
-#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;
- }
+ phy_env = CcdPhysicsEnvironment::Create(blenderscene, visualizePhysics);
+ physics_engine = UseBullet;
+ break;
+ }
#endif
- default:
- case UseNone:
+ default:
+ case WOPHY_NONE:
+ {
+ // We should probably use some sort of factory here
+ phy_env = new DummyPhysicsEnvironment();
physics_engine = UseNone;
- destinationscene ->SetPhysicsEnvironment(new DummyPhysicsEnvironment());
break;
+ }
}
+ destinationscene->SetPhysicsEnvironment(phy_env);
+
BL_ConvertBlenderObjects(m_maggie,
destinationscene,
m_ketsjiEngine,
@@ -392,12 +310,6 @@ void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene,
//This cache mecanism is buggy so I leave it disable and the memory leak
//that would result from this is fixed in RemoveScene()
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
@@ -1546,6 +1458,20 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene,
{
/* Find a mesh in the current main */
ID *me= static_cast<ID *>(BLI_findstring(&m_maggie->mesh, name, offsetof(ID, name) + 2));
+ Main *from_maggie = m_maggie;
+
+ if (me == NULL) {
+ // The mesh wasn't in the current main, try any dynamic (i.e., LibLoaded) ones
+ vector<Main*>::iterator it;
+
+ for (it = GetMainDynamic().begin(); it != GetMainDynamic().end(); it++) {
+ me = static_cast<ID *>(BLI_findstring(&(*it)->mesh, name, offsetof(ID, name) + 2));
+ from_maggie = *it;
+
+ if (me)
+ break;
+ }
+ }
if (me==NULL) {
printf("Could not be found \"%s\"\n", name);
@@ -1555,10 +1481,10 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene,
/* Watch this!, if its used in the original scene can cause big troubles */
if (me->us > 0) {
printf("Mesh has a user \"%s\"\n", name);
- me = (ID*)BKE_mesh_copy((Mesh*)me);
+ me = (ID*)BKE_mesh_copy_ex(from_maggie, (Mesh*)me);
me->us--;
}
- BLI_remlink(&m_maggie->mesh, me); /* even if we made the copy it needs to be removed */
+ BLI_remlink(&from_maggie->mesh, me); /* even if we made the copy it needs to be removed */
BLI_addtail(&maggie->mesh, me);
@@ -1584,7 +1510,7 @@ RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene* kx_scene,
mat_new->id.flag |= LIB_DOIT;
mat_old->id.us--;
- BLI_remlink(&m_maggie->mat, mat_new);
+ BLI_remlink(&G.main->mat, mat_new); // BKE_material_copy uses G.main, and there is no BKE_material_copy_ex
BLI_addtail(&maggie->mat, mat_new);
mesh->mat[i] = mat_new;