diff options
Diffstat (limited to 'source/gameengine')
20 files changed, 73 insertions, 52 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 6e6531c9b5f..980aa1d47b1 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -404,7 +404,6 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, int alw { // convert and add scene sceneconverter->ConvertScene( - startscenename, startscene, dictionaryobject, keyboarddevice, @@ -717,7 +716,6 @@ extern "C" void StartKetsjiShellSimulation(struct wmWindow *win, { // convert and add scene sceneconverter->ConvertScene( - startscenename, startscene, dictionaryobject, keyboarddevice, diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 4309ca6c1ff..2ff9d38dee4 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -325,7 +325,6 @@ bool ConvertMaterial( MFace* mface, MCol* mmcol, int lightlayer, - Object* blenderobj, MTF_localLayer *layers, bool glslmat) { @@ -751,11 +750,11 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* // Determine if we need to make a skinned mesh if (mesh->dvert || mesh->key || ((blenderobj->gameflag & OB_SOFT_BODY) != 0) || BL_ModifierDeformer::HasCompatibleDeformer(blenderobj)) { - meshobj = new BL_SkinMeshObject(mesh, lightlayer); + meshobj = new BL_SkinMeshObject(mesh); skinMesh = true; } else - meshobj = new RAS_MeshObject(mesh, lightlayer); + meshobj = new RAS_MeshObject(mesh); // Extract avaiable layers MTF_localLayer *layers = new MTF_localLayer[MAX_MTFACE]; @@ -860,7 +859,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools* if (!bl_mat) bl_mat = new BL_Material(); ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol, - lightlayer, blenderobj, layers, converter->GetGLSLMaterials()); + lightlayer, layers, converter->GetGLSLMaterials()); visible = ((bl_mat->ras_mode & POLY_VIS)!=0); collider = ((bl_mat->ras_mode & COLLIDER)!=0); @@ -1686,8 +1685,7 @@ static KX_GameObject *gameobject_from_blenderobject( Object *ob, KX_Scene *kxscene, RAS_IRenderTools *rendertools, - KX_BlenderSceneConverter *converter, - Scene *blenderscene) + KX_BlenderSceneConverter *converter) { KX_GameObject *gameobj = NULL; @@ -1747,7 +1745,7 @@ static KX_GameObject *gameobject_from_blenderobject( if (bHasModifier) { BL_ModifierDeformer *dcont = new BL_ModifierDeformer((BL_DeformableGameObject *)gameobj, - blenderscene, ob, (BL_SkinMeshObject *)meshobj); + kxscene->GetBlenderScene(), ob, (BL_SkinMeshObject *)meshobj); ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont); if (bHasShapeKey && bHasArmature) dcont->LoadShapeDrivers(ob->parent); @@ -1786,7 +1784,7 @@ static KX_GameObject *gameobject_from_blenderobject( kxscene, KX_Scene::m_callbacks, ob, - blenderscene // handle + kxscene->GetBlenderScene() // handle ); /* Get the current pose from the armature object and apply it as the rest pose */ break; @@ -1900,7 +1898,6 @@ KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist){ // convert blender objects into ketsji gameobjects void BL_ConvertBlenderObjects(struct Main* maggie, - const STR_String& scenename, KX_Scene* kxscene, KX_KetsjiEngine* ketsjiEngine, e_PhysicsEngine physics_engine, @@ -1913,7 +1910,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, ) { - Scene *blenderscene = converter->GetBlenderSceneForName(scenename); + Scene *blenderscene = kxscene->GetBlenderScene(); // for SETLOOPER Scene *sce; Base *base; @@ -2005,8 +2002,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, base->object, kxscene, rendertools, - converter, - blenderscene); + converter); bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0; bool addobj=true; @@ -2195,8 +2191,7 @@ void BL_ConvertBlenderObjects(struct Main* maggie, blenderobject, kxscene, rendertools, - converter, - blenderscene); + converter); // this code is copied from above except that // object from groups are never in active layer diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.h b/source/gameengine/Converter/BL_BlenderDataConversion.h index 48f08fb357b..bf733b748e2 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.h +++ b/source/gameengine/Converter/BL_BlenderDataConversion.h @@ -37,7 +37,6 @@ class RAS_MeshObject* BL_ConvertMesh(struct Mesh* mesh,struct Object* lightobj,class RAS_IRenderTools* rendertools,class KX_Scene* scene, class KX_BlenderSceneConverter *converter); void BL_ConvertBlenderObjects(struct Main* maggie, - const STR_String& scenename, class KX_Scene* kxscene, class KX_KetsjiEngine* ketsjiEngine, e_PhysicsEngine physics_engine, diff --git a/source/gameengine/Converter/BL_SkinMeshObject.cpp b/source/gameengine/Converter/BL_SkinMeshObject.cpp index 0a18296f261..4eb01df410b 100644 --- a/source/gameengine/Converter/BL_SkinMeshObject.cpp +++ b/source/gameengine/Converter/BL_SkinMeshObject.cpp @@ -46,8 +46,8 @@ #include "BL_SkinMeshObject.h" #include "BL_DeformableGameObject.h" -BL_SkinMeshObject::BL_SkinMeshObject(Mesh* mesh, int lightlayer) - : RAS_MeshObject (mesh, lightlayer) +BL_SkinMeshObject::BL_SkinMeshObject(Mesh* mesh) + : RAS_MeshObject (mesh) { m_bDeformed = true; diff --git a/source/gameengine/Converter/BL_SkinMeshObject.h b/source/gameengine/Converter/BL_SkinMeshObject.h index 8544a2b958c..e2d0e37664d 100644 --- a/source/gameengine/Converter/BL_SkinMeshObject.h +++ b/source/gameengine/Converter/BL_SkinMeshObject.h @@ -46,7 +46,7 @@ protected: vector<int> m_cacheWeightIndex; public: - BL_SkinMeshObject(Mesh* mesh, int lightlayer); + BL_SkinMeshObject(Mesh* mesh); ~BL_SkinMeshObject(); void UpdateBuckets(void* clientobj, double* oglmatrix, diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp index 9e0a710f44f..776a3528d89 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp @@ -242,15 +242,14 @@ struct BlenderDebugDraw : public btIDebugDraw #endif -void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, - class KX_Scene* destinationscene, +void KX_BlenderSceneConverter::ConvertScene(class KX_Scene* destinationscene, PyObject* dictobj, class SCA_IInputDevice* keyinputdev, class RAS_IRenderTools* rendertools, class RAS_ICanvas* canvas) { //find out which physics engine - Scene *blenderscene = GetBlenderSceneForName(scenename); + Scene *blenderscene = destinationscene->GetBlenderScene(); e_PhysicsEngine physics_engine = UseBullet; bool useDbvtCulling = false; @@ -331,7 +330,6 @@ void KX_BlenderSceneConverter::ConvertScene(const STR_String& scenename, } BL_ConvertBlenderObjects(m_maggie, - scenename, destinationscene, m_ketsjiEngine, physics_engine, diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h index b65f49c2b59..c47055803c8 100644 --- a/source/gameengine/Converter/KX_BlenderSceneConverter.h +++ b/source/gameengine/Converter/KX_BlenderSceneConverter.h @@ -92,7 +92,6 @@ public: * dictobj: python dictionary (for pythoncontrollers) */ virtual void ConvertScene( - const STR_String& scenename, class KX_Scene* destinationscene, PyObject* dictobj, class SCA_IInputDevice* keyinputdev, diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp index ea812a71fdd..b6fc7f1dbba 100644 --- a/source/gameengine/Converter/KX_ConvertActuators.cpp +++ b/source/gameengine/Converter/KX_ConvertActuators.cpp @@ -638,7 +638,10 @@ void BL_ConvertActuators(char* maggiename, = new KX_SCA_ReplaceMeshActuator( gameobj, tmpmesh, - scene + scene, + (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX)==0, + (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS)!=0 + ); baseact = tmpreplaceact; diff --git a/source/gameengine/GameLogic/SCA_IScene.h b/source/gameengine/GameLogic/SCA_IScene.h index b641efc6ee1..79d922a998e 100644 --- a/source/gameengine/GameLogic/SCA_IScene.h +++ b/source/gameengine/GameLogic/SCA_IScene.h @@ -55,7 +55,7 @@ public: //virtual void DelayedReleaseObject(class CValue* gameobj)=0; virtual void ReplaceMesh(class CValue* gameobj, - void* meshobj)=0; + void* meshobj, bool use_gfx, bool use_phys)=0; std::vector<SCA_DebugProp*>& GetDebugProperties(); void AddDebugProperty(class CValue* debugprop, const STR_String &name); diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 75688a63530..170b7405145 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1388,7 +1388,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS}, {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS}, - {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_O}, + {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_VARARGS}, {"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS}, {"reinstancePhysicsMesh", (PyCFunction)KX_GameObject::sPyReinstancePhysicsMesh,METH_VARARGS}, @@ -1466,15 +1466,21 @@ bool KX_GameObject::ConvertPythonVectorArgs(PyObject* args, } */ -PyObject* KX_GameObject::PyReplaceMesh(PyObject* value) +PyObject* KX_GameObject::PyReplaceMesh(PyObject* args) { KX_Scene *scene = KX_GetActiveScene(); - RAS_MeshObject* new_mesh; + + PyObject *value; + int use_gfx= 1, use_phys= 0; + RAS_MeshObject *new_mesh; + + if (!PyArg_ParseTuple(args,"O|ii:replaceMesh", &value, &use_gfx, &use_phys)) + return NULL; if (!ConvertPythonToMesh(value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject")) return NULL; - scene->ReplaceMesh(this, new_mesh); + scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys); Py_RETURN_NONE; } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 118e17128f0..b235464259f 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -849,7 +849,7 @@ public: KX_PYMETHOD_VARARGS(KX_GameObject,GetMesh); KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId); KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames); - KX_PYMETHOD_O(KX_GameObject,ReplaceMesh); + KX_PYMETHOD_VARARGS(KX_GameObject,ReplaceMesh); KX_PYMETHOD_NOARGS(KX_GameObject,EndObject); KX_PYMETHOD_DOC(KX_GameObject,rayCastTo); KX_PYMETHOD_DOC(KX_GameObject,rayCast); diff --git a/source/gameengine/Ketsji/KX_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h index 3709fa8c784..5c2c0bc0ad2 100644 --- a/source/gameengine/Ketsji/KX_ISceneConverter.h +++ b/source/gameengine/Ketsji/KX_ISceneConverter.h @@ -47,7 +47,7 @@ public: destinationscene: pass an empty scene, everything goes into this dictobj: python dictionary (for pythoncontrollers) */ - virtual void ConvertScene(const STR_String& scenename, + virtual void ConvertScene( class KX_Scene* destinationscene, PyObject* dictobj, class SCA_IInputDevice* keyinputdev, diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index cc0f50d9e7a..3ae899cbe5f 100644 --- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp +++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp @@ -1599,8 +1599,7 @@ KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename) scenename, scene); - m_sceneconverter->ConvertScene(scenename, - tmpscene, + m_sceneconverter->ConvertScene(tmpscene, m_pythondictionary, m_keyboarddevice, m_rendertools, diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp index 2884bb76565..a19b18bf0e0 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp @@ -88,6 +88,8 @@ PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = { PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = { KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh), + KX_PYATTRIBUTE_BOOL_RW ("useDisplayMesh", KX_SCA_ReplaceMeshActuator, m_use_gfx), + KX_PYATTRIBUTE_BOOL_RW ("usePhysicsMesh", KX_SCA_ReplaceMeshActuator, m_use_phys), { NULL } //Sentinel }; @@ -156,11 +158,15 @@ KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, instantReplaceMesh, KX_SCA_ReplaceMeshActuator::KX_SCA_ReplaceMeshActuator(SCA_IObject *gameobj, class RAS_MeshObject *mesh, - SCA_IScene* scene) : + SCA_IScene* scene, + bool use_gfx, + bool use_phys) : SCA_IActuator(gameobj), m_mesh(mesh), - m_scene(scene) + m_scene(scene), + m_use_gfx(use_gfx), + m_use_phys(use_phys) { } /* End of constructor */ @@ -182,7 +188,8 @@ bool KX_SCA_ReplaceMeshActuator::Update() if (bNegativeEvent) return false; // do nothing on negative events - if (m_mesh) m_scene->ReplaceMesh(GetParent(),m_mesh); + if (m_mesh || m_use_phys) /* NULL mesh is ok if were updating physics */ + m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys); return false; } @@ -204,7 +211,7 @@ CValue* KX_SCA_ReplaceMeshActuator::GetReplica() void KX_SCA_ReplaceMeshActuator::InstantReplaceMesh() { - if (m_mesh) m_scene->ReplaceMesh(GetParent(),m_mesh); + if (m_mesh) m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys); } /* eof */ diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h index 6a68bd88cc5..ae2c0d2d6ce 100644 --- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h @@ -50,12 +50,17 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator // mesh reference (mesh to replace) RAS_MeshObject* m_mesh; SCA_IScene* m_scene; + bool m_use_phys; + bool m_use_gfx; public: KX_SCA_ReplaceMeshActuator( SCA_IObject* gameobj, RAS_MeshObject *mesh, - SCA_IScene* scene); + SCA_IScene* scene, + bool use_gfx, + bool use_phys + ); ~KX_SCA_ReplaceMeshActuator( ); @@ -69,7 +74,6 @@ class KX_SCA_ReplaceMeshActuator : public SCA_IActuator void InstantReplaceMesh(); - /* python api */ static PyObject* pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 51f5276e075..8c88d55f24c 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -1017,17 +1017,18 @@ int KX_Scene::NewRemoveObject(class CValue* gameobj) -void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) +void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool use_phys) { KX_GameObject* gameobj = static_cast<KX_GameObject*>(obj); RAS_MeshObject* mesh = static_cast<RAS_MeshObject*>(meshobj); - if(!gameobj || !mesh) - { - std::cout << "warning: invalid object, mesh will not be replaced" << std::endl; + if(!gameobj) { + std::cout << "KX_Scene::ReplaceMesh Warning: invalid object, doing nothing" << std::endl; return; } + if(use_gfx && mesh != NULL) + { gameobj->RemoveMeshes(); gameobj->AddMesh(mesh); @@ -1156,6 +1157,11 @@ void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj) } gameobj->AddMeshUser(); + } + + if(use_phys) { /* update the new assigned mesh with the physics mesh */ + KX_ReInstanceBulletShapeFromMesh(gameobj, NULL, use_gfx?NULL:mesh); + } } KX_Camera* KX_Scene::FindCamera(KX_Camera* cam) diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 2792f1f5fe4..d94eac0c6e2 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -323,7 +323,7 @@ public: int NewRemoveObject(CValue* gameobj); void ReplaceMesh(CValue* gameobj, - void* meshobj); + void* meshob, bool use_gfx, bool use_phys); /** * @section Logic stuff * Initiate an update of the logic system. diff --git a/source/gameengine/PyDoc/GameTypes.py b/source/gameengine/PyDoc/GameTypes.py index 6a554a7c42e..b1d1ce71173 100644 --- a/source/gameengine/PyDoc/GameTypes.py +++ b/source/gameengine/PyDoc/GameTypes.py @@ -1642,10 +1642,14 @@ class KX_GameObject(SCA_IObject): Delete this object, can be used inpace of the EndObject Actuator. The actual removal of the object from the scene is delayed. """ - def replaceMesh(mesh): + def replaceMesh(mesh, useDisplayMesh=True, usePhysicsMesh=False): """ Replace the mesh of this object with a new mesh. This works the same was as the actuator. @type mesh: L{KX_MeshProxy} or mesh name + @type useDisplayMesh: bool + @param useDisplayMesh: when enabled the display mesh will be replaced (optional argument). + @type usePhysicsMesh: bool + @param usePhysicsMesh: when enabled the physics mesh will be replaced (optional argument). """ def getVisible(): """ @@ -3791,6 +3795,11 @@ class KX_SCA_ReplaceMeshActuator(SCA_IActuator): @ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one Set to None to disable actuator @type mesh: L{KX_MeshProxy} or None if no mesh is set + + @ivar useDisplayMesh: when true the displayed mesh is replaced. + @type useDisplayMesh: boolean + @ivar usePhysicsMesh: when true the physics mesh is replaced. + @type usePhysicsMesh: boolean """ def setMesh(name): """ diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index 0ae6ad9d7ea..0995d5acdd5 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -90,9 +90,8 @@ struct RAS_MeshObject::fronttoback STR_String RAS_MeshObject::s_emptyname = ""; -RAS_MeshObject::RAS_MeshObject(Mesh* mesh, int lightlayer) - : //m_lightlayer(lightlayer), - m_bModified(true), +RAS_MeshObject::RAS_MeshObject(Mesh* mesh) + : m_bModified(true), m_bMeshModified(true), m_mesh(mesh), m_bDeformed(false) diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index bf9c0f7b682..f34546a8ff7 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -55,7 +55,6 @@ class RAS_MeshObject { private: unsigned int m_debugcolor; - //int m_lightlayer; bool m_bModified; bool m_bMeshModified; @@ -77,7 +76,7 @@ protected: public: // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime) - RAS_MeshObject(Mesh* mesh, int lightlayer); + RAS_MeshObject(Mesh* mesh); virtual ~RAS_MeshObject(); |