From f6114dc3594d3df14eb5ffedad8ba0f0a7896062 Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Mon, 9 Oct 2017 16:23:19 +0200 Subject: [PATCH] UPBGE: Cleanup BL_BlenderDataConversion.[cpp/h]. This cleanup contains: - uncrusity pass - remove extra class/struct keyword - remove pre definition of variable - clean comments --- .../Converter/BL_BlenderDataConversion.cpp | 1496 ++++++++--------- .../Converter/BL_BlenderDataConversion.h | 30 +- .../Converter/BL_ConvertSensors.cpp | 6 +- .../gameengine/GameLogic/SCA_IInputDevice.h | 4 - source/gameengine/Launcher/LA_Launcher.cpp | 4 +- .../Physics/Bullet/CcdPhysicsEnvironment.cpp | 48 +- .../Physics/Bullet/CcdPhysicsEnvironment.h | 2 +- .../Physics/Common/PHY_IPhysicsEnvironment.h | 2 +- .../Physics/Dummy/DummyPhysicsEnvironment.h | 2 +- 9 files changed, 744 insertions(+), 850 deletions(-) diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 71e989d1c76b..efda8774c66b 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -51,26 +51,35 @@ #include #include -#include "BL_BlenderDataConversion.h" #include "MT_Transform.h" #include "MT_MinMax.h" -#include "GPU_texture.h" - #include "PHY_Pro.h" #include "PHY_IPhysicsEnvironment.h" +#ifdef WITH_BULLET +# include "CcdPhysicsEnvironment.h" +# include "CcdGraphicController.h" +#endif + #include "RAS_MeshObject.h" #include "RAS_Rasterizer.h" #include "RAS_ILightObject.h" -#include "BL_ConvertActuators.h" -#include "BL_ConvertControllers.h" -#include "BL_ConvertSensors.h" +#include "RAS_ICanvas.h" +#include "RAS_Vertex.h" +#include "RAS_BucketManager.h" +#include "RAS_BoundingBoxManager.h" +#include "RAS_IPolygonMaterial.h" + +#include "SG_Node.h" +#include "SG_BBox.h" + #include "SCA_LogicManager.h" #include "SCA_TimeEventManager.h" +#include "KX_SoftBodyDeformer.h" #include "KX_ClientObjectInfo.h" #include "KX_Scene.h" #include "KX_GameObject.h" @@ -80,42 +89,46 @@ #include "KX_FontObject.h" #include "KX_LodManager.h" #include "KX_PythonComponent.h" - -#include "RAS_ICanvas.h" -#include "RAS_Vertex.h" -#include "RAS_BucketManager.h" -#include "RAS_BoundingBoxManager.h" -#include "RAS_IPolygonMaterial.h" +#include "KX_WorldInfo.h" #include "KX_BlenderMaterial.h" #include "KX_TextureRendererManager.h" -#include "BL_Texture.h" +#include "KX_Globals.h" +#include "KX_PyConstraintBinding.h" +#include "KX_KetsjiEngine.h" +#include "KX_SG_NodeRelationships.h" +#include "KX_SG_BoneParentNodeRelationship.h" +#include "KX_MotionState.h" +#include "KX_NavMeshObject.h" +#include "KX_ObstacleSimulation.h" -#include "BKE_main.h" -#include "BKE_global.h" -#include "BKE_object.h" -#include "BKE_python_component.h" +#include "BL_BlenderDataConversion.h" #include "BL_ModifierDeformer.h" #include "BL_ShapeDeformer.h" #include "BL_SkinDeformer.h" #include "BL_MeshDeformer.h" -#include "KX_SoftBodyDeformer.h" -#include "BLI_utildefines.h" -#include "BLI_listbase.h" - -#include "KX_WorldInfo.h" - -#include "KX_KetsjiEngine.h" +#include "BL_Texture.h" #include "BL_BlenderSceneConverter.h" +#include "BL_ConvertActuators.h" +#include "BL_ConvertControllers.h" +#include "BL_ConvertSensors.h" +#include "BL_ConvertProperties.h" +#include "BL_ArmatureObject.h" +#include "BL_DeformableGameObject.h" -#include "KX_Globals.h" -#include "KX_PyConstraintBinding.h" +#include "CM_Message.h" + +#include "GPU_texture.h" -/* This little block needed for linking to Blender... */ +// This little block needed for linking to Blender... #ifdef WIN32 #include "BLI_winstuff.h" #endif -/* This list includes only data type definitions */ +#include "BLI_utildefines.h" +#include "BLI_listbase.h" +#include "BLI_math.h" +#include "BLI_threads.h" + #include "DNA_object_types.h" #include "DNA_material_types.h" #include "DNA_texture_types.h" @@ -143,52 +156,28 @@ #include "MEM_guardedalloc.h" +#include "BKE_main.h" +#include "BKE_global.h" +#include "BKE_object.h" +#include "BKE_python_component.h" #include "BKE_key.h" #include "BKE_mesh.h" -#include "BLI_math.h" - extern "C" { -#include "BKE_scene.h" -#include "BKE_customdata.h" -#include "BKE_cdderivedmesh.h" -#include "BKE_DerivedMesh.h" -#include "BKE_material.h" /* give_current_material */ -#include "BKE_image.h" -#include "IMB_imbuf_types.h" -#include "BKE_displist.h" - -extern Material defmaterial; /* material.c */ +# include "BKE_scene.h" +# include "BKE_customdata.h" +# include "BKE_cdderivedmesh.h" +# include "BKE_DerivedMesh.h" +# include "BKE_material.h" // Needed for give_current_material. +# include "BKE_image.h" +# include "IMB_imbuf_types.h" +# include "BKE_displist.h" + +extern Material defmaterial; } #include "wm_event_types.h" -/* end of blender include block */ - -#include "BL_ConvertProperties.h" - -#include "SG_Node.h" -#include "SG_BBox.h" -#include "KX_SG_NodeRelationships.h" -#include "KX_SG_BoneParentNodeRelationship.h" - -#ifdef WITH_BULLET -#include "CcdPhysicsEnvironment.h" -#include "CcdGraphicController.h" -#endif - -#include "KX_MotionState.h" - -#include "BL_ArmatureObject.h" -#include "BL_DeformableGameObject.h" - -#include "KX_NavMeshObject.h" -#include "KX_ObstacleSimulation.h" - -#include "CM_Message.h" - -#include "BLI_threads.h" - // For construction to find shared vertices. struct BL_SharedVertex { RAS_IDisplayArray *array; @@ -218,156 +207,146 @@ class BL_SharedVertexPredicate } }; -static std::map create_translate_table() -{ - std::map m; - - /* The reverse table. In order to not confuse ourselves, we */ - /* immediately convert all events that come in to KX codes. */ - m[LEFTMOUSE ] = SCA_IInputDevice::LEFTMOUSE; - m[MIDDLEMOUSE ] = SCA_IInputDevice::MIDDLEMOUSE; - m[RIGHTMOUSE ] = SCA_IInputDevice::RIGHTMOUSE; - m[WHEELUPMOUSE ] = SCA_IInputDevice::WHEELUPMOUSE; - m[WHEELDOWNMOUSE ] = SCA_IInputDevice::WHEELDOWNMOUSE; - m[MOUSEX ] = SCA_IInputDevice::MOUSEX; - m[MOUSEY ] = SCA_IInputDevice::MOUSEY; - - // standard keyboard - - m[AKEY ] = SCA_IInputDevice::AKEY; - m[BKEY ] = SCA_IInputDevice::BKEY; - m[CKEY ] = SCA_IInputDevice::CKEY; - m[DKEY ] = SCA_IInputDevice::DKEY; - m[EKEY ] = SCA_IInputDevice::EKEY; - m[FKEY ] = SCA_IInputDevice::FKEY; - m[GKEY ] = SCA_IInputDevice::GKEY; - m[HKEY ] = SCA_IInputDevice::HKEY_; - m[IKEY ] = SCA_IInputDevice::IKEY; - m[JKEY ] = SCA_IInputDevice::JKEY; - m[KKEY ] = SCA_IInputDevice::KKEY; - m[LKEY ] = SCA_IInputDevice::LKEY; - m[MKEY ] = SCA_IInputDevice::MKEY; - m[NKEY ] = SCA_IInputDevice::NKEY; - m[OKEY ] = SCA_IInputDevice::OKEY; - m[PKEY ] = SCA_IInputDevice::PKEY; - m[QKEY ] = SCA_IInputDevice::QKEY; - m[RKEY ] = SCA_IInputDevice::RKEY; - m[SKEY ] = SCA_IInputDevice::SKEY; - m[TKEY ] = SCA_IInputDevice::TKEY; - m[UKEY ] = SCA_IInputDevice::UKEY; - m[VKEY ] = SCA_IInputDevice::VKEY; - m[WKEY ] = SCA_IInputDevice::WKEY; - m[XKEY ] = SCA_IInputDevice::XKEY; - m[YKEY ] = SCA_IInputDevice::YKEY; - m[ZKEY ] = SCA_IInputDevice::ZKEY; - - m[ZEROKEY ] = SCA_IInputDevice::ZEROKEY; - m[ONEKEY ] = SCA_IInputDevice::ONEKEY; - m[TWOKEY ] = SCA_IInputDevice::TWOKEY; - m[THREEKEY ] = SCA_IInputDevice::THREEKEY; - m[FOURKEY ] = SCA_IInputDevice::FOURKEY; - m[FIVEKEY ] = SCA_IInputDevice::FIVEKEY; - m[SIXKEY ] = SCA_IInputDevice::SIXKEY; - m[SEVENKEY ] = SCA_IInputDevice::SEVENKEY; - m[EIGHTKEY ] = SCA_IInputDevice::EIGHTKEY; - m[NINEKEY ] = SCA_IInputDevice::NINEKEY; - - m[CAPSLOCKKEY ] = SCA_IInputDevice::CAPSLOCKKEY; - - m[LEFTCTRLKEY ] = SCA_IInputDevice::LEFTCTRLKEY; - m[LEFTALTKEY ] = SCA_IInputDevice::LEFTALTKEY; - m[RIGHTALTKEY ] = SCA_IInputDevice::RIGHTALTKEY; - m[RIGHTCTRLKEY ] = SCA_IInputDevice::RIGHTCTRLKEY; - m[RIGHTSHIFTKEY ] = SCA_IInputDevice::RIGHTSHIFTKEY; - m[LEFTSHIFTKEY ] = SCA_IInputDevice::LEFTSHIFTKEY; - - m[ESCKEY ] = SCA_IInputDevice::ESCKEY; - m[TABKEY ] = SCA_IInputDevice::TABKEY; - m[RETKEY ] = SCA_IInputDevice::RETKEY; - m[SPACEKEY ] = SCA_IInputDevice::SPACEKEY; - m[LINEFEEDKEY ] = SCA_IInputDevice::LINEFEEDKEY; - m[BACKSPACEKEY ] = SCA_IInputDevice::BACKSPACEKEY; - m[DELKEY ] = SCA_IInputDevice::DELKEY; - m[SEMICOLONKEY ] = SCA_IInputDevice::SEMICOLONKEY; - m[PERIODKEY ] = SCA_IInputDevice::PERIODKEY; - m[COMMAKEY ] = SCA_IInputDevice::COMMAKEY; - m[QUOTEKEY ] = SCA_IInputDevice::QUOTEKEY; - m[ACCENTGRAVEKEY ] = SCA_IInputDevice::ACCENTGRAVEKEY; - m[MINUSKEY ] = SCA_IInputDevice::MINUSKEY; - m[SLASHKEY ] = SCA_IInputDevice::SLASHKEY; - m[BACKSLASHKEY ] = SCA_IInputDevice::BACKSLASHKEY; - m[EQUALKEY ] = SCA_IInputDevice::EQUALKEY; - m[LEFTBRACKETKEY ] = SCA_IInputDevice::LEFTBRACKETKEY; - m[RIGHTBRACKETKEY ] = SCA_IInputDevice::RIGHTBRACKETKEY; - - m[LEFTARROWKEY ] = SCA_IInputDevice::LEFTARROWKEY; - m[DOWNARROWKEY ] = SCA_IInputDevice::DOWNARROWKEY; - m[RIGHTARROWKEY ] = SCA_IInputDevice::RIGHTARROWKEY; - m[UPARROWKEY ] = SCA_IInputDevice::UPARROWKEY; - - m[PAD2 ] = SCA_IInputDevice::PAD2; - m[PAD4 ] = SCA_IInputDevice::PAD4; - m[PAD6 ] = SCA_IInputDevice::PAD6; - m[PAD8 ] = SCA_IInputDevice::PAD8; - - m[PAD1 ] = SCA_IInputDevice::PAD1; - m[PAD3 ] = SCA_IInputDevice::PAD3; - m[PAD5 ] = SCA_IInputDevice::PAD5; - m[PAD7 ] = SCA_IInputDevice::PAD7; - m[PAD9 ] = SCA_IInputDevice::PAD9; - - m[PADPERIOD ] = SCA_IInputDevice::PADPERIOD; - m[PADSLASHKEY ] = SCA_IInputDevice::PADSLASHKEY; - m[PADASTERKEY ] = SCA_IInputDevice::PADASTERKEY; - - m[PAD0 ] = SCA_IInputDevice::PAD0; - m[PADMINUS ] = SCA_IInputDevice::PADMINUS; - m[PADENTER ] = SCA_IInputDevice::PADENTER; - m[PADPLUSKEY ] = SCA_IInputDevice::PADPLUSKEY; - - - m[F1KEY ] = SCA_IInputDevice::F1KEY; - m[F2KEY ] = SCA_IInputDevice::F2KEY; - m[F3KEY ] = SCA_IInputDevice::F3KEY; - m[F4KEY ] = SCA_IInputDevice::F4KEY; - m[F5KEY ] = SCA_IInputDevice::F5KEY; - m[F6KEY ] = SCA_IInputDevice::F6KEY; - m[F7KEY ] = SCA_IInputDevice::F7KEY; - m[F8KEY ] = SCA_IInputDevice::F8KEY; - m[F9KEY ] = SCA_IInputDevice::F9KEY; - m[F10KEY ] = SCA_IInputDevice::F10KEY; - m[F11KEY ] = SCA_IInputDevice::F11KEY; - m[F12KEY ] = SCA_IInputDevice::F12KEY; - m[F13KEY ] = SCA_IInputDevice::F13KEY; - m[F14KEY ] = SCA_IInputDevice::F14KEY; - m[F15KEY ] = SCA_IInputDevice::F15KEY; - m[F16KEY ] = SCA_IInputDevice::F16KEY; - m[F17KEY ] = SCA_IInputDevice::F17KEY; - m[F18KEY ] = SCA_IInputDevice::F18KEY; - m[F19KEY ] = SCA_IInputDevice::F19KEY; - - m[OSKEY ] = SCA_IInputDevice::OSKEY; - - m[PAUSEKEY ] = SCA_IInputDevice::PAUSEKEY; - m[INSERTKEY ] = SCA_IInputDevice::INSERTKEY; - m[HOMEKEY ] = SCA_IInputDevice::HOMEKEY; - m[PAGEUPKEY ] = SCA_IInputDevice::PAGEUPKEY; - m[PAGEDOWNKEY ] = SCA_IInputDevice::PAGEDOWNKEY; - m[ENDKEY ] = SCA_IInputDevice::ENDKEY; - - return m; -} - -static std::map gReverseKeyTranslateTable = create_translate_table(); +/* The reverse table. In order to not confuse ourselves, we + * immediately convert all events that come in to KX codes. */ +static std::map gReverseKeyTranslateTable = { + {LEFTMOUSE, SCA_IInputDevice::LEFTMOUSE}, + {MIDDLEMOUSE, SCA_IInputDevice::MIDDLEMOUSE}, + {RIGHTMOUSE, SCA_IInputDevice::RIGHTMOUSE}, + {WHEELUPMOUSE, SCA_IInputDevice::WHEELUPMOUSE}, + {WHEELDOWNMOUSE, SCA_IInputDevice::WHEELDOWNMOUSE}, + {MOUSEMOVE, SCA_IInputDevice::MOUSEX}, + {ACTIONMOUSE, SCA_IInputDevice::MOUSEY}, + // Standard keyboard. + {AKEY, SCA_IInputDevice::AKEY}, + {BKEY, SCA_IInputDevice::BKEY}, + {CKEY, SCA_IInputDevice::CKEY}, + {DKEY, SCA_IInputDevice::DKEY}, + {EKEY, SCA_IInputDevice::EKEY}, + {FKEY, SCA_IInputDevice::FKEY}, + {GKEY, SCA_IInputDevice::GKEY}, + {HKEY, SCA_IInputDevice::HKEY_}, + {IKEY, SCA_IInputDevice::IKEY}, + {JKEY, SCA_IInputDevice::JKEY}, + {KKEY, SCA_IInputDevice::KKEY}, + {LKEY, SCA_IInputDevice::LKEY}, + {MKEY, SCA_IInputDevice::MKEY}, + {NKEY, SCA_IInputDevice::NKEY}, + {OKEY, SCA_IInputDevice::OKEY}, + {PKEY, SCA_IInputDevice::PKEY}, + {QKEY, SCA_IInputDevice::QKEY}, + {RKEY, SCA_IInputDevice::RKEY}, + {SKEY, SCA_IInputDevice::SKEY}, + {TKEY, SCA_IInputDevice::TKEY}, + {UKEY, SCA_IInputDevice::UKEY}, + {VKEY, SCA_IInputDevice::VKEY}, + {WKEY, SCA_IInputDevice::WKEY}, + {XKEY, SCA_IInputDevice::XKEY}, + {YKEY, SCA_IInputDevice::YKEY}, + {ZKEY, SCA_IInputDevice::ZKEY}, + + {ZEROKEY, SCA_IInputDevice::ZEROKEY}, + {ONEKEY, SCA_IInputDevice::ONEKEY}, + {TWOKEY, SCA_IInputDevice::TWOKEY}, + {THREEKEY, SCA_IInputDevice::THREEKEY}, + {FOURKEY, SCA_IInputDevice::FOURKEY}, + {FIVEKEY, SCA_IInputDevice::FIVEKEY}, + {SIXKEY, SCA_IInputDevice::SIXKEY}, + {SEVENKEY, SCA_IInputDevice::SEVENKEY}, + {EIGHTKEY, SCA_IInputDevice::EIGHTKEY}, + {NINEKEY, SCA_IInputDevice::NINEKEY}, + + {CAPSLOCKKEY, SCA_IInputDevice::CAPSLOCKKEY}, + + {LEFTCTRLKEY, SCA_IInputDevice::LEFTCTRLKEY}, + {LEFTALTKEY, SCA_IInputDevice::LEFTALTKEY}, + {RIGHTALTKEY, SCA_IInputDevice::RIGHTALTKEY}, + {RIGHTCTRLKEY, SCA_IInputDevice::RIGHTCTRLKEY}, + {RIGHTSHIFTKEY, SCA_IInputDevice::RIGHTSHIFTKEY}, + {LEFTSHIFTKEY, SCA_IInputDevice::LEFTSHIFTKEY}, + + {ESCKEY, SCA_IInputDevice::ESCKEY}, + {TABKEY, SCA_IInputDevice::TABKEY}, + {RETKEY, SCA_IInputDevice::RETKEY}, + {SPACEKEY, SCA_IInputDevice::SPACEKEY}, + {LINEFEEDKEY, SCA_IInputDevice::LINEFEEDKEY}, + {BACKSPACEKEY, SCA_IInputDevice::BACKSPACEKEY}, + {DELKEY, SCA_IInputDevice::DELKEY}, + {SEMICOLONKEY, SCA_IInputDevice::SEMICOLONKEY}, + {PERIODKEY, SCA_IInputDevice::PERIODKEY}, + {COMMAKEY, SCA_IInputDevice::COMMAKEY}, + {QUOTEKEY, SCA_IInputDevice::QUOTEKEY}, + {ACCENTGRAVEKEY, SCA_IInputDevice::ACCENTGRAVEKEY}, + {MINUSKEY, SCA_IInputDevice::MINUSKEY}, + {SLASHKEY, SCA_IInputDevice::SLASHKEY}, + {BACKSLASHKEY, SCA_IInputDevice::BACKSLASHKEY}, + {EQUALKEY, SCA_IInputDevice::EQUALKEY}, + {LEFTBRACKETKEY, SCA_IInputDevice::LEFTBRACKETKEY}, + {RIGHTBRACKETKEY, SCA_IInputDevice::RIGHTBRACKETKEY}, + + {LEFTARROWKEY, SCA_IInputDevice::LEFTARROWKEY}, + {DOWNARROWKEY, SCA_IInputDevice::DOWNARROWKEY}, + {RIGHTARROWKEY, SCA_IInputDevice::RIGHTARROWKEY}, + {UPARROWKEY, SCA_IInputDevice::UPARROWKEY}, + + {PAD2, SCA_IInputDevice::PAD2}, + {PAD4, SCA_IInputDevice::PAD4}, + {PAD6, SCA_IInputDevice::PAD6}, + {PAD8, SCA_IInputDevice::PAD8}, + + {PAD1, SCA_IInputDevice::PAD1}, + {PAD3, SCA_IInputDevice::PAD3}, + {PAD5, SCA_IInputDevice::PAD5}, + {PAD7, SCA_IInputDevice::PAD7}, + {PAD9, SCA_IInputDevice::PAD9}, + + {PADPERIOD, SCA_IInputDevice::PADPERIOD}, + {PADSLASHKEY, SCA_IInputDevice::PADSLASHKEY}, + {PADASTERKEY, SCA_IInputDevice::PADASTERKEY}, + + {PAD0, SCA_IInputDevice::PAD0}, + {PADMINUS, SCA_IInputDevice::PADMINUS}, + {PADENTER, SCA_IInputDevice::PADENTER}, + {PADPLUSKEY, SCA_IInputDevice::PADPLUSKEY}, + + {F1KEY, SCA_IInputDevice::F1KEY}, + {F2KEY, SCA_IInputDevice::F2KEY}, + {F3KEY, SCA_IInputDevice::F3KEY}, + {F4KEY, SCA_IInputDevice::F4KEY}, + {F5KEY, SCA_IInputDevice::F5KEY}, + {F6KEY, SCA_IInputDevice::F6KEY}, + {F7KEY, SCA_IInputDevice::F7KEY}, + {F8KEY, SCA_IInputDevice::F8KEY}, + {F9KEY, SCA_IInputDevice::F9KEY}, + {F10KEY, SCA_IInputDevice::F10KEY}, + {F11KEY, SCA_IInputDevice::F11KEY}, + {F12KEY, SCA_IInputDevice::F12KEY}, + {F13KEY, SCA_IInputDevice::F13KEY}, + {F14KEY, SCA_IInputDevice::F14KEY}, + {F15KEY, SCA_IInputDevice::F15KEY}, + {F16KEY, SCA_IInputDevice::F16KEY}, + {F17KEY, SCA_IInputDevice::F17KEY}, + {F18KEY, SCA_IInputDevice::F18KEY}, + {F19KEY, SCA_IInputDevice::F19KEY}, + + {OSKEY, SCA_IInputDevice::OSKEY}, + + {PAUSEKEY, SCA_IInputDevice::PAUSEKEY}, + {INSERTKEY, SCA_IInputDevice::INSERTKEY}, + {HOMEKEY, SCA_IInputDevice::HOMEKEY}, + {PAGEUPKEY, SCA_IInputDevice::PAGEUPKEY}, + {PAGEDOWNKEY, SCA_IInputDevice::PAGEDOWNKEY}, + {ENDKEY, SCA_IInputDevice::ENDKEY} +}; -SCA_IInputDevice::SCA_EnumInputs ConvertKeyCode(int key_code) +SCA_IInputDevice::SCA_EnumInputs BL_ConvertKeyCode(int key_code) { return gReverseKeyTranslateTable[key_code]; } -static void GetUvRgba(const RAS_MeshObject::LayerList& layers, std::vector& uvLayers, std::vector& colorLayers, - unsigned short uvCount, unsigned short colorCount, - unsigned int loop, MT_Vector2 uvs[RAS_Texture::MaxUnits], unsigned int rgba[RAS_IVertex::MAX_UNIT]) +static void BL_GetUvRgba(const RAS_MeshObject::LayerList& layers, std::vector& uvLayers, std::vector& colorLayers, + unsigned short uvCount, unsigned short colorCount, + unsigned int loop, MT_Vector2 uvs[RAS_Texture::MaxUnits], unsigned int rgba[RAS_IVertex::MAX_UNIT]) { // No need to initialize layers to zero as all the converted layer are all the layers needed. @@ -378,8 +357,7 @@ static void GetUvRgba(const RAS_MeshObject::LayerList& layers, std::vectorid.name; - // Always ensure that the name of a material start with "MA" prefix due to video texture name check. - if (name.empty()) { - name = "MA"; - } - - KX_BlenderMaterial *kx_blmat = new KX_BlenderMaterial(mat, name, lightlayer); + KX_BlenderMaterial *mat = converter.FindMaterial(ma); - return kx_blmat; -} + if (!mat) { + std::string name = ma->id.name; + // Always ensure that the name of a material start with "MA" prefix due to video texture name check. + if (name.empty()) { + name = "MA"; + } -static RAS_MaterialBucket *material_from_mesh(Material *ma, int lightlayer, KX_Scene *scene, BL_BlenderSceneConverter& converter) -{ - KX_BlenderMaterial* mat = converter.FindMaterial(ma); + mat = new KX_BlenderMaterial(ma, name, lightlayer); - if (!mat) { - mat = ConvertMaterial(ma, lightlayer); // this is needed to free up memory afterwards. converter.RegisterMaterial(mat, ma); } @@ -437,20 +409,20 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, int lightlayer, KX_S // see if a bucket was reused or a new one was created // this way only one KX_BlenderMaterial object has to exist per bucket bool bucketCreated; - RAS_MaterialBucket* bucket = scene->FindBucket(mat, bucketCreated); + RAS_MaterialBucket *bucket = scene->FindBucket(mat, bucketCreated); return bucket; } /* blenderobj can be nullptr, make sure its checked for */ -RAS_MeshObject* BL_ConvertMesh(Mesh *me, Object *blenderobj, KX_Scene *scene, BL_BlenderSceneConverter& converter) +RAS_MeshObject *BL_ConvertMesh(Mesh *me, Object *blenderobj, KX_Scene *scene, BL_BlenderSceneConverter& converter) { RAS_MeshObject *meshobj; - const int lightlayer = blenderobj ? blenderobj->lay : (1 << 20) -1; // all layers if no object. + const int lightlayer = blenderobj ? blenderobj->lay : (1 << 20) - 1; // all layers if no object. // Without checking names, we get some reuse we don't want that can cause // problems with material LoDs. - if (blenderobj && ((meshobj = converter.FindGameMesh(me/*, ob->lay*/)) != nullptr)) { + if (blenderobj && ((meshobj = converter.FindGameMesh(me)) != nullptr)) { const std::string bge_name = meshobj->GetName(); const std::string blender_name = ((ID *)blenderobj->data)->name + 2; if (bge_name == blender_name) { @@ -508,7 +480,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh *me, Object *blenderobj, KX_Scene *scene, BL ma = &defmaterial; } - RAS_MaterialBucket *bucket = material_from_mesh(ma, lightlayer, scene, converter); + RAS_MaterialBucket *bucket = BL_ConvertMaterial(ma, lightlayer, scene, converter); RAS_MeshMaterial *meshmat = meshobj->AddMaterial(bucket, i, vertformat); RAS_IPolyMaterial *mat = meshmat->GetBucket()->GetPolyMaterial(); @@ -526,7 +498,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh *me, Object *blenderobj, KX_Scene *scene, BL } void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vector& mats, - const RAS_MeshObject::LayersInfo& layersInfo) + const RAS_MeshObject::LayersInfo& layersInfo) { const MVert *mverts = dm->getVertArray(dm); const int totverts = dm->getNumVerts(dm); @@ -539,7 +511,7 @@ void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vectorloopData, CD_NORMAL) == -1) { dm->calcLoopNormals(dm, (me->flag & ME_AUTOSMOOTH), me->smoothresh); } - const float (*normals)[3] = (float (*)[3])dm->getLoopDataArray(dm, CD_NORMAL); + const float (*normals)[3] = (float(*)[3])dm->getLoopDataArray(dm, CD_NORMAL); float (*tangent)[4] = nullptr; if (layersInfo.uvCount > 0) { @@ -598,13 +570,13 @@ void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vectorCreateVertex(pt, uvs, tan, rgba, no); BL_SharedVertexList& sharedList = sharedMap[vertid]; BL_SharedVertexList::iterator it = std::find_if(sharedList.begin(), sharedList.end(), - BL_SharedVertexPredicate(vertex, array)); + BL_SharedVertexPredicate(vertex, array)); unsigned int offset; if (it != sharedList.end()) { @@ -655,105 +627,90 @@ void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vectorm_mass = blenderobject->mass; - -// This needs to be fixed in blender. For now, we use: - -// in Blender, inertia stands for the size value which is equivalent to -// the sphere radius - shapeProps->m_inertia = blenderobject->formfactor; - + + shapeProps.m_mass = blenderobject->mass; + + /* This needs to be fixed in blender. For now, we use: + * in Blender, inertia stands for the size value which is equivalent to + * the sphere radius + */ + shapeProps.m_inertia = blenderobject->formfactor; + BLI_assert(0.0f <= blenderobject->damping && blenderobject->damping <= 1.0f); BLI_assert(0.0f <= blenderobject->rdamping && blenderobject->rdamping <= 1.0f); - - shapeProps->m_lin_drag = 1.0f - blenderobject->damping; - shapeProps->m_ang_drag = 1.0f - blenderobject->rdamping; - - shapeProps->m_friction_scaling = MT_Vector3(blenderobject->anisotropicFriction); - shapeProps->m_do_anisotropic = ((blenderobject->gameflag & OB_ANISOTROPIC_FRICTION) != 0); - - shapeProps->m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0; - shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0; - -// velocity clamping XXX - shapeProps->m_clamp_vel_min = blenderobject->min_vel; - shapeProps->m_clamp_vel_max = blenderobject->max_vel; - shapeProps->m_clamp_angvel_min = blenderobject->min_angvel; - shapeProps->m_clamp_angvel_max = blenderobject->max_angvel; - -// Character physics properties - shapeProps->m_step_height = blenderobject->step_height; - shapeProps->m_jump_speed = blenderobject->jump_speed; - shapeProps->m_fall_speed = blenderobject->fall_speed; - shapeProps->m_max_jumps = blenderobject->max_jumps; - - shapeProps->m_restitution = blenderobject->reflect; - shapeProps->m_friction = blenderobject->friction; - shapeProps->m_rollingFriction = blenderobject->rolling_friction; - shapeProps->m_fh_spring = blenderobject->fh; - shapeProps->m_fh_damping = blenderobject->xyfrict; - shapeProps->m_fh_distance = blenderobject->fhdist; - shapeProps->m_fh_normal = (blenderobject->dynamode & OB_FH_NOR) != 0; - return shapeProps; -} + shapeProps.m_lin_drag = 1.0f - blenderobject->damping; + shapeProps.m_ang_drag = 1.0f - blenderobject->rdamping; + + shapeProps.m_friction_scaling = MT_Vector3(blenderobject->anisotropicFriction); + shapeProps.m_do_anisotropic = ((blenderobject->gameflag & OB_ANISOTROPIC_FRICTION) != 0); + + shapeProps.m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0; + shapeProps.m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0; -////////////////////////////////////////////////////// + // Velocity clamping. + shapeProps.m_clamp_vel_min = blenderobject->min_vel; + shapeProps.m_clamp_vel_max = blenderobject->max_vel; + shapeProps.m_clamp_angvel_min = blenderobject->min_angvel; + shapeProps.m_clamp_angvel_max = blenderobject->max_angvel; + // Character physics properties. + shapeProps.m_step_height = blenderobject->step_height; + shapeProps.m_jump_speed = blenderobject->jump_speed; + shapeProps.m_fall_speed = blenderobject->fall_speed; + shapeProps.m_max_jumps = blenderobject->max_jumps; -static void BL_CreateGraphicObjectNew(KX_GameObject* gameobj, - KX_Scene* kxscene, - bool isActive, - e_PhysicsEngine physics_engine) + shapeProps.m_restitution = blenderobject->reflect; + shapeProps.m_friction = blenderobject->friction; + shapeProps.m_rollingFriction = blenderobject->rolling_friction; + shapeProps.m_fh_spring = blenderobject->fh; + shapeProps.m_fh_damping = blenderobject->xyfrict; + shapeProps.m_fh_distance = blenderobject->fhdist; + shapeProps.m_fh_normal = (blenderobject->dynamode & OB_FH_NOR) != 0; + + return shapeProps; +} + +static void BL_CreateGraphicObjectNew(KX_GameObject *gameobj, KX_Scene *kxscene, bool isActive, e_PhysicsEngine physics_engine) { - switch (physics_engine) - { + switch (physics_engine) { #ifdef WITH_BULLET - case UseBullet: + case UseBullet: { - CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment(); + CcdPhysicsEnvironment *env = (CcdPhysicsEnvironment *)kxscene->GetPhysicsEnvironment(); BLI_assert(env); - PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode()); - CcdGraphicController* ctrl = new CcdGraphicController(env, motionstate); + PHY_IMotionState *motionstate = new KX_MotionState(gameobj->GetSGNode()); + CcdGraphicController *ctrl = new CcdGraphicController(env, motionstate); gameobj->SetGraphicController(ctrl); ctrl->SetNewClientInfo(gameobj->getClientInfo()); if (isActive) { // add first, this will create the proxy handle, only if the object is visible - if (gameobj->GetVisible()) + if (gameobj->GetVisible()) { env->AddCcdGraphicController(ctrl); + } } + break; } - break; #endif - default: - break; + default: + { + break; + } } } -static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, - struct Object* blenderobject, - RAS_MeshObject* meshobj, - KX_Scene* kxscene, - int activeLayerBitInfo, - BL_BlenderSceneConverter& converter, - bool processCompoundChildren - ) +static void BL_CreatePhysicsObjectNew(KX_GameObject *gameobj, Object *blenderobject, RAS_MeshObject *meshobj, + KX_Scene *kxscene, int activeLayerBitInfo, BL_BlenderSceneConverter& converter, bool processCompoundChildren) { - //SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/ - //int userigidbody = SYS_GetCommandLineInt(syshandle,"norigidbody",0); - //bool bRigidBody = (userigidbody == 0); - - // object has physics representation? + // Object has physics representation? if (!(blenderobject->gameflag & OB_COLLISION)) { - // Respond to all collisions so that Near sensors work on No Collision - // objects. + // Respond to all collisions so that Near sensors work on No Collision objects. gameobj->SetUserCollisionGroup(0xffff); gameobj->SetUserCollisionMask(0xffff); return; @@ -769,13 +726,11 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, // Pretend for compound parent or child if the object has compound option and use a physics type with solid shape. if ((blenderobject->gameflag & (OB_CHILD)) && (blenderobject->gameflag & (OB_DYNAMIC | OB_COLLISION | OB_RIGID_BODY)) && - !(blenderobject->gameflag & OB_SOFT_BODY)) - { + !(blenderobject->gameflag & OB_SOFT_BODY)) { hasCompoundChildren = true; while (parent) { if ((parent->gameflag & OB_CHILD) && (parent->gameflag & (OB_COLLISION | OB_DYNAMIC | OB_RIGID_BODY)) && - !(parent->gameflag & OB_SOFT_BODY)) - { + !(parent->gameflag & OB_SOFT_BODY)) { // Found a parent in the tree with compound shape. isCompoundChild = true; /* The object is not a parent compound shape if it has a parent @@ -791,23 +746,22 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, return; } - PHY_ShapeProps* shapeprops = - CreateShapePropsFromBlenderObject(blenderobject); + const PHY_ShapeProps shapeprops = BL_CreateShapePropsFromBlenderObject(blenderobject); - class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode()); + PHY_IMotionState *motionstate = new KX_MotionState(gameobj->GetSGNode()); - kxscene->GetPhysicsEnvironment()->ConvertObject(converter, gameobj, meshobj, kxscene, shapeprops, motionstate, activeLayerBitInfo, isCompoundChild, hasCompoundChildren); + PHY_IPhysicsEnvironment *phyenv = kxscene->GetPhysicsEnvironment(); + phyenv->ConvertObject(converter, gameobj, meshobj, kxscene, shapeprops, motionstate, activeLayerBitInfo, + isCompoundChild, hasCompoundChildren); - bool isActor = (blenderobject->gameflag & OB_ACTOR)!=0; + bool isActor = (blenderobject->gameflag & OB_ACTOR) != 0; bool isSensor = (blenderobject->gameflag & OB_SENSOR) != 0; gameobj->getClientInfo()->m_type = (isSensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) : (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC; - - delete shapeprops; } -static KX_LodManager *lodmanager_from_blenderobject(Object *ob, KX_Scene *scene, BL_BlenderSceneConverter& converter) +static KX_LodManager *BL_LodManagerFromBlenderObject(Object *ob, KX_Scene *scene, BL_BlenderSceneConverter& converter) { if (BLI_listbase_count_ex(&ob->lodlevels, 2) <= 1) { return nullptr; @@ -823,11 +777,10 @@ static KX_LodManager *lodmanager_from_blenderobject(Object *ob, KX_Scene *scene, return lodManager; } -static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_Rasterizer *rasterizer, BL_BlenderSceneConverter& converter) +static KX_LightObject *BL_GameLightFromBlenderLamp(Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_Rasterizer *rasterizer) { RAS_ILightObject *lightobj = rasterizer->CreateLight(); - KX_LightObject *gamelight; - + lightobj->m_att1 = la->att1; lightobj->m_att2 = (la->mode & LA_QUAD) ? la->att2 : 0.0f; lightobj->m_coeff_const = la->coeff_const; @@ -857,33 +810,42 @@ static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int l lightobj->m_nodiffuse = (la->mode & LA_NO_DIFF) != 0; lightobj->m_nospecular = (la->mode & LA_NO_SPEC) != 0; - if (la->type == LA_SUN) { - lightobj->m_type = RAS_ILightObject::LIGHT_SUN; - } - else if (la->type == LA_SPOT) { - lightobj->m_type = RAS_ILightObject::LIGHT_SPOT; - } - else if (la->type == LA_HEMI) { - lightobj->m_type = RAS_ILightObject::LIGHT_HEMI; - } - else { - lightobj->m_type = RAS_ILightObject::LIGHT_NORMAL; + switch (la->type) { + case LA_SUN: + { + lightobj->m_type = RAS_ILightObject::LIGHT_SUN; + break; + } + case LA_SPOT: + { + lightobj->m_type = RAS_ILightObject::LIGHT_SPOT; + break; + } + case LA_HEMI: + { + lightobj->m_type = RAS_ILightObject::LIGHT_HEMI; + break; + } + default: + { + lightobj->m_type = RAS_ILightObject::LIGHT_NORMAL; + } } - gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rasterizer, lightobj); + KX_LightObject *gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rasterizer, lightobj); gamelight->SetShowShadowFrustum((la->mode & LA_SHOW_SHADOW_BOX) && (la->mode & LA_SHAD_RAY)); return gamelight; } -static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, BL_BlenderSceneConverter& converter) +static KX_Camera *BL_GameCameraFromBlenderCamera(Object *ob, KX_Scene *kxscene) { - Camera* ca = static_cast(ob->data); + Camera *ca = static_cast(ob->data); RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->sensor_y, ca->sensor_fit, ca->shiftx, ca->shifty, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist); KX_Camera *gamecamera; - - gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata); + + gamecamera = new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata); gamecamera->SetName(ca->id.name + 2); gamecamera->SetShowCameraFrustum(ca->gameflag & GAME_CAM_SHOW_FRUSTUM); @@ -892,7 +854,7 @@ static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, BL_Blen if (ca->gameflag & GAME_CAM_OVERRIDE_CULLING) { if (kxscene->GetOverrideCullingCamera()) { CM_Warning("\"" << gamecamera->GetName() << "\" sets for culling override whereas \"" - << kxscene->GetOverrideCullingCamera()->GetName() << "\" is already used for culling override."); + << kxscene->GetOverrideCullingCamera()->GetName() << "\" is already used for culling override."); } else { kxscene->SetOverrideCullingCamera(gamecamera); @@ -902,171 +864,162 @@ static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, BL_Blen return gamecamera; } -static KX_GameObject *gameobject_from_blenderobject(Object *ob, KX_Scene *kxscene, RAS_Rasterizer *rendertools, - BL_BlenderSceneConverter &converter) +static KX_GameObject *BL_GameObjectFromBlenderObject(Object *ob, KX_Scene *kxscene, RAS_Rasterizer *rendertools, + BL_BlenderSceneConverter &converter) { KX_GameObject *gameobj = nullptr; Scene *blenderscene = kxscene->GetBlenderScene(); - + switch (ob->type) { - case OB_LAMP: - { - KX_LightObject* gamelight = gamelight_from_blamp(ob, static_cast(ob->data), ob->lay, kxscene, rendertools, converter); - gameobj = gamelight; - gamelight->AddRef(); - kxscene->GetLightList()->Add(gamelight); + case OB_LAMP: + { + KX_LightObject *gamelight = BL_GameLightFromBlenderLamp(static_cast(ob->data), ob->lay, kxscene, rendertools); + gameobj = gamelight; + gamelight->AddRef(); + kxscene->GetLightList()->Add(gamelight); - break; - } - - case OB_CAMERA: - { - KX_Camera* gamecamera = gamecamera_from_bcamera(ob, kxscene, converter); - gameobj = gamecamera; - - //don't add a reference: the camera list in kxscene->m_cameras is not released at the end - //gamecamera->AddRef(); - kxscene->GetCameraList()->Add(CM_AddRef(gamecamera)); - - break; - } - - case OB_MESH: - { - Mesh* mesh = static_cast(ob->data); - RAS_MeshObject* meshobj = BL_ConvertMesh(mesh,ob,kxscene,converter); - - // needed for python scripting - kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj); + break; + } - if (ob->gameflag & OB_NAVMESH) + case OB_CAMERA: { - gameobj = new KX_NavMeshObject(kxscene,KX_Scene::m_callbacks); - gameobj->AddMesh(meshobj); + KX_Camera *gamecamera = BL_GameCameraFromBlenderCamera(ob, kxscene); + gameobj = gamecamera; + + kxscene->GetCameraList()->Add(CM_AddRef(gamecamera)); + break; } - gameobj = new BL_DeformableGameObject(kxscene, KX_Scene::m_callbacks); - - // set transformation - gameobj->AddMesh(meshobj); - - // gather levels of detail - KX_LodManager *lodManager = lodmanager_from_blenderobject(ob, kxscene, converter); - gameobj->SetLodManager(lodManager); - if (lodManager) { - lodManager->Release(); - } + case OB_MESH: + { + Mesh *mesh = static_cast(ob->data); + RAS_MeshObject *meshobj = BL_ConvertMesh(mesh, ob, kxscene, converter); + + // needed for python scripting + kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(), meshobj); + + if (ob->gameflag & OB_NAVMESH) { + gameobj = new KX_NavMeshObject(kxscene, KX_Scene::m_callbacks); + gameobj->AddMesh(meshobj); + break; + } - // for all objects: check whether they want to - // respond to updates - bool ignoreActivityCulling = - ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING)!=0); - gameobj->SetIgnoreActivityCulling(ignoreActivityCulling); - gameobj->SetOccluder((ob->gameflag & OB_OCCLUDER) != 0, false); - - // two options exists for deform: shape keys and armature - // only support relative shape key - bool bHasShapeKey = mesh->key != nullptr && mesh->key->type==KEY_RELATIVE; - bool bHasDvert = mesh->dvert != nullptr && ob->defbase.first; - bool bHasArmature = (BL_ModifierDeformer::HasArmatureDeformer(ob) && ob->parent && ob->parent->type == OB_ARMATURE && bHasDvert); - bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob); + BL_DeformableGameObject *deformableGameObj = new BL_DeformableGameObject(kxscene, KX_Scene::m_callbacks); + gameobj = deformableGameObj; + + // set transformation + gameobj->AddMesh(meshobj); + + // gather levels of detail + KX_LodManager *lodManager = BL_LodManagerFromBlenderObject(ob, kxscene, converter); + gameobj->SetLodManager(lodManager); + if (lodManager) { + lodManager->Release(); + } + + // For all objects: check whether they want to respond to updates. + bool ignoreActivityCulling = ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING) != 0); + gameobj->SetIgnoreActivityCulling(ignoreActivityCulling); + gameobj->SetOccluder((ob->gameflag & OB_OCCLUDER) != 0, false); + + // Two options exists for deform: shape keys and armature. Only support relative shape key. + bool bHasShapeKey = (mesh->key != nullptr && mesh->key->type == KEY_RELATIVE); + bool bHasDvert = (mesh->dvert != nullptr && ob->defbase.first); + bool bHasArmature = (BL_ModifierDeformer::HasArmatureDeformer(ob) && ob->parent && ob->parent->type == OB_ARMATURE && bHasDvert); + bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob); #ifdef WITH_BULLET - bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY)); + bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY)); #endif - RAS_Deformer *deformer = nullptr; - BL_DeformableGameObject *deformableGameObj = (BL_DeformableGameObject *)gameobj; + RAS_Deformer *deformer = nullptr; + if (bHasModifier) { + deformer = new BL_ModifierDeformer(deformableGameObj, kxscene->GetBlenderScene(), ob, meshobj); + } + else if (bHasShapeKey) { + // not that we can have shape keys without dvert! + deformer = new BL_ShapeDeformer(deformableGameObj, ob, meshobj); + } + else if (bHasArmature) { + deformer = new BL_SkinDeformer(deformableGameObj, ob, meshobj, nullptr); + } + else if (bHasDvert) { + // this case correspond to a mesh that can potentially deform but not with the + // object to which it is attached for the moment. A skin mesh was created in + // BL_ConvertMesh() so must create a deformer too! + deformer = new BL_MeshDeformer(deformableGameObj, ob, meshobj); + } +#ifdef WITH_BULLET + else if (bHasSoftBody) { + deformer = new KX_SoftBodyDeformer(meshobj, deformableGameObj); + } +#endif - if (bHasModifier) { - deformer = new BL_ModifierDeformer(deformableGameObj, kxscene->GetBlenderScene(), ob, meshobj); - } - else if (bHasShapeKey) { - // not that we can have shape keys without dvert! - deformer = new BL_ShapeDeformer(deformableGameObj, ob, meshobj); - } - else if (bHasArmature) { - deformer = new BL_SkinDeformer(deformableGameObj, ob, meshobj, nullptr); - } - else if (bHasDvert) { - // this case correspond to a mesh that can potentially deform but not with the - // object to which it is attached for the moment. A skin mesh was created in - // BL_ConvertMesh() so must create a deformer too! - deformer = new BL_MeshDeformer(deformableGameObj, ob, meshobj); + if (deformer) { + deformableGameObj->SetDeformer(deformer); + } + break; } -#ifdef WITH_BULLET - else if (bHasSoftBody) { - deformer = new KX_SoftBodyDeformer(meshobj, deformableGameObj); + + case OB_ARMATURE: + { + bArmature *arm = (bArmature *)ob->data; + gameobj = new BL_ArmatureObject(kxscene, KX_Scene::m_callbacks, ob, kxscene->GetBlenderScene(), arm->gevertdeformer); + + kxscene->AddAnimatedObject(gameobj); + + break; } -#endif - if (deformer) { - deformableGameObj->SetDeformer(deformer); + case OB_EMPTY: + { + gameobj = new KX_EmptyObject(kxscene, KX_Scene::m_callbacks); + + break; } - break; - } - - case OB_ARMATURE: - { - bArmature *arm = (bArmature*)ob->data; - gameobj = new BL_ArmatureObject( - kxscene, - KX_Scene::m_callbacks, - ob, - kxscene->GetBlenderScene(), // handle - arm->gevertdeformer - ); - - kxscene->AddAnimatedObject(gameobj); - - break; - } - - case OB_EMPTY: - { - gameobj = new KX_EmptyObject(kxscene,KX_Scene::m_callbacks); - // set transformation - break; - } - case OB_FONT: - { - bool do_color_management = BKE_scene_check_color_management_enabled(blenderscene); - /* font objects have no bounding box */ - KX_FontObject *fontobj = new KX_FontObject(kxscene,KX_Scene::m_callbacks, rendertools, kxscene->GetBoundingBoxManager(), ob, do_color_management); - gameobj = fontobj; + case OB_FONT: + { + bool do_color_management = BKE_scene_check_color_management_enabled(blenderscene); + // Font objects have no bounding box. + KX_FontObject *fontobj = new KX_FontObject(kxscene, KX_Scene::m_callbacks, rendertools, + kxscene->GetBoundingBoxManager(), ob, do_color_management); + gameobj = fontobj; - kxscene->GetFontList()->Add(CM_AddRef(fontobj)); - break; - } + kxscene->GetFontList()->Add(CM_AddRef(fontobj)); + break; + } #ifdef THREADED_DAG_WORKAROUND - case OB_CURVE: - { - if (ob->curve_cache == nullptr) { - BKE_displist_make_curveTypes(blenderscene, ob, false); + case OB_CURVE: + { + if (ob->curve_cache == nullptr) { + BKE_displist_make_curveTypes(blenderscene, ob, false); + } } - } #endif } - if (gameobj) - { + if (gameobj) { gameobj->SetLayer(ob->lay); gameobj->SetBlenderObject(ob); gameobj->SetObjectColor(MT_Vector4(ob->col)); - /* set the visibility state based on the objects render option in the outliner */ - if (ob->restrictflag & OB_RESTRICT_RENDER) gameobj->SetVisible(0, 0); + // Set the visibility state based on the objects render option in the outliner. + if (ob->restrictflag & OB_RESTRICT_RENDER) { + gameobj->SetVisible(false, false); + } } + return gameobj; } -struct parentChildLink { - struct Object* m_blenderchild; - SG_Node* m_gamechildnode; +struct BL_ParentChildLink { + struct Object *m_blenderchild; + SG_Node *m_gamechildnode; }; -static bPoseChannel *get_active_posechannel2(Object *ob) + +static bPoseChannel *BL_GetActivePoseChannel(Object *ob) { bArmature *arm= (bArmature*)ob->data; bPoseChannel *pchan; @@ -1080,7 +1033,7 @@ static bPoseChannel *get_active_posechannel2(Object *ob) return nullptr; } -static ListBase *get_active_constraints2(Object *ob) +static ListBase *BL_GetActiveConstraint(Object *ob) { if (!ob) return nullptr; @@ -1089,7 +1042,7 @@ static ListBase *get_active_constraints2(Object *ob) if (ob->mode & OB_MODE_POSE) { bPoseChannel *pchan; - pchan = get_active_posechannel2(ob); + pchan = BL_GetActivePoseChannel(ob); if (pchan) return &pchan->constraints; } @@ -1099,20 +1052,8 @@ static ListBase *get_active_constraints2(Object *ob) return nullptr; } -static void UNUSED_FUNCTION(print_active_constraints2)(Object *ob) //not used, use to debug -{ - bConstraint* curcon; - ListBase* conlist = get_active_constraints2(ob); - - if (conlist) { - for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { - CM_Debug(curcon->type); - } - } -} - // Copy base layer to object layer like in BKE_scene_set_background -static void blenderSceneSetBackground(Scene *blenderscene) +static void BL_SetBlenderSceneBackground(Scene *blenderscene) { Scene *it; Base *base; @@ -1169,7 +1110,7 @@ static void BL_ConvertComponentsObject(KX_GameObject *gameobj, Object *blenderob } // Lastly make sure we have a class and it's an appropriate sub type - if (!PyType_Check(cls) || !PyObject_IsSubclass(cls, (PyObject*)&KX_PythonComponent::Type)) { + if (!PyType_Check(cls) || !PyObject_IsSubclass(cls, (PyObject *)&KX_PythonComponent::Type)) { CM_Error(pc->module << "." << pc->name << " is not a KX_PythonComponent subclass"); pc = pc->next; continue; @@ -1205,30 +1146,27 @@ static void BL_ConvertComponentsObject(KX_GameObject *gameobj, Object *blenderob /* helper for BL_ConvertBlenderObjects, avoids code duplication * note: all var names match args are passed from the caller */ -static void bl_ConvertBlenderObject_Single( - BL_BlenderSceneConverter& converter, - Object *blenderobject, - std::vector &vec_parent_child, - CListValue *logicbrick_conversionlist, - CListValue *objectlist, CListValue *inactivelist, - CListValue *sumolist, - KX_Scene* kxscene, KX_GameObject* gameobj, - SCA_LogicManager* logicmgr, SCA_TimeEventManager* timemgr, - bool isInActiveLayer - ) +static void bl_ConvertBlenderObject_Single(BL_BlenderSceneConverter& converter, + Object *blenderobject, + std::vector &vec_parent_child, + CListValue *logicbrick_conversionlist, + CListValue *objectlist, CListValue *inactivelist, + CListValue *sumolist, + KX_Scene *kxscene, KX_GameObject *gameobj, + SCA_LogicManager *logicmgr, SCA_TimeEventManager *timemgr, + bool isInActiveLayer) { - MT_Vector3 pos( - blenderobject->loc[0]+blenderobject->dloc[0], - blenderobject->loc[1]+blenderobject->dloc[1], - blenderobject->loc[2]+blenderobject->dloc[2] - ); + const MT_Vector3 pos( + blenderobject->loc[0] + blenderobject->dloc[0], + blenderobject->loc[1] + blenderobject->dloc[1], + blenderobject->loc[2] + blenderobject->dloc[2]); MT_Matrix3x3 rotation; float rotmat[3][3]; BKE_object_rot_to_mat3(blenderobject, rotmat, false); - rotation.setValue3x3((float*)rotmat); + rotation.setValue3x3((float *)rotmat); - MT_Vector3 scale(blenderobject->size); + const MT_Vector3 scale(blenderobject->size); gameobj->NodeSetLocalPosition(pos); gameobj->NodeSetLocalOrientation(rotation); @@ -1237,47 +1175,44 @@ static void bl_ConvertBlenderObject_Single( sumolist->Add(CM_AddRef(gameobj)); - BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer); + BL_ConvertProperties(blenderobject, gameobj, timemgr, kxscene, isInActiveLayer); gameobj->SetName(blenderobject->id.name + 2); - // update children/parent hierarchy - if (blenderobject->parent != 0) - { - // blender has an additional 'parentinverse' offset in each object - SG_Callbacks callback(nullptr,nullptr,nullptr,KX_Scene::KX_ScenegraphUpdateFunc,KX_Scene::KX_ScenegraphRescheduleFunc); - SG_Node* parentinversenode = new SG_Node(nullptr,kxscene,callback); + // Update children/parent hierarchy. + if (blenderobject->parent != 0) { + // Blender has an additional 'parentinverse' offset in each object. + SG_Callbacks callback(nullptr, nullptr, nullptr, KX_Scene::KX_ScenegraphUpdateFunc, KX_Scene::KX_ScenegraphRescheduleFunc); + SG_Node *parentinversenode = new SG_Node(nullptr, kxscene, callback); - // define a normal parent relationship for this node. - KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New(); + // Define a normal parent relationship for this node. + KX_NormalParentRelation *parent_relation = KX_NormalParentRelation::New(); parentinversenode->SetParentRelation(parent_relation); - parentChildLink pclink; + BL_ParentChildLink pclink; pclink.m_blenderchild = blenderobject; pclink.m_gamechildnode = parentinversenode; vec_parent_child.push_back(pclink); - float* fl = (float*) blenderobject->parentinv; - MT_Transform parinvtrans(fl); + float *fl = (float *)blenderobject->parentinv; + const MT_Transform parinvtrans(fl); parentinversenode->SetLocalPosition(parinvtrans.getOrigin()); - // problem here: the parent inverse transform combines scaling and rotation - // in the basis but the scenegraph needs separate rotation and scaling. - // This is not important for OpenGL (it uses 4x4 matrix) but it is important - // for the physic engine that needs a separate scaling - //parentinversenode->SetLocalOrientation(parinvtrans.getBasis()); - // Extract the rotation and the scaling from the basis + // Extract the rotation and the scaling from the basis. MT_Matrix3x3 ori(parinvtrans.getBasis()); MT_Vector3 x(ori.getColumn(0)); MT_Vector3 y(ori.getColumn(1)); MT_Vector3 z(ori.getColumn(2)); - MT_Vector3 parscale(x.length(), y.length(), z.length()); - if (!MT_fuzzyZero(parscale[0])) + const MT_Vector3 parscale(x.length(), y.length(), z.length()); + if (!MT_fuzzyZero(parscale[0])) { x /= parscale[0]; - if (!MT_fuzzyZero(parscale[1])) + } + if (!MT_fuzzyZero(parscale[1])) { y /= parscale[1]; - if (!MT_fuzzyZero(parscale[2])) + } + if (!MT_fuzzyZero(parscale[2])) { z /= parscale[2]; + } ori.setColumn(0, x); ori.setColumn(1, y); ori.setColumn(2, z); @@ -1287,48 +1222,43 @@ static void bl_ConvertBlenderObject_Single( parentinversenode->AddChild(gameobj->GetSGNode()); } - // needed for python scripting - logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj); + // Needed for python scripting. + logicmgr->RegisterGameObjectName(gameobj->GetName(), gameobj); - // needed for group duplication + // Needed for group duplication. logicmgr->RegisterGameObj(blenderobject, gameobj); - for (int i = 0; i < gameobj->GetMeshCount(); i++) + for (int i = 0; i < gameobj->GetMeshCount(); i++) { logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject); + } converter.RegisterGameObject(gameobj, blenderobject); - // this was put in rapidly, needs to be looked at more closely - // only draw/use objects in active 'blender' layers logicbrick_conversionlist->Add(CM_AddRef(gameobj)); - if (isInActiveLayer) - { + // Only draw/use objects in active 'blender' layers. + if (isInActiveLayer) { objectlist->Add(CM_AddRef(gameobj)); - //tf.Add(gameobj->GetSGNode()); gameobj->NodeUpdateGS(0); gameobj->AddMeshUser(); } - else - { - //we must store this object otherwise it will be deleted - //at the end of this function if it is not a root object + else { + // We must store this object otherwise it will be deleted at the end of this function if it is not a root object. inactivelist->Add(CM_AddRef(gameobj)); } } -// convert blender objects into ketsji gameobjects -void BL_ConvertBlenderObjects(struct Main* maggie, - KX_Scene* kxscene, - KX_KetsjiEngine* ketsjiEngine, - e_PhysicsEngine physics_engine, - RAS_Rasterizer* rendertools, - RAS_ICanvas* canvas, - BL_BlenderSceneConverter& converter, - bool alwaysUseExpandFraming, - bool libloading - ) +/// Convert blender objects into ketsji gameobjects. +void BL_ConvertBlenderObjects(struct Main *maggie, + KX_Scene *kxscene, + KX_KetsjiEngine *ketsjiEngine, + e_PhysicsEngine physics_engine, + RAS_Rasterizer *rendertools, + RAS_ICanvas *canvas, + BL_BlenderSceneConverter& converter, + bool alwaysUseExpandFraming, + bool libloading) { #define BL_CONVERTBLENDEROBJECT_SINGLE \ @@ -1345,19 +1275,13 @@ void BL_ConvertBlenderObjects(struct Main* maggie, Scene *blenderscene = kxscene->GetBlenderScene(); - // for SETLOOPER - Scene *sce_iter; - Base *base; - - // Get the frame settings of the canvas. - // Get the aspect ratio of the canvas as designed by the user. - RAS_FrameSettings::RAS_FrameType frame_type; - int aspect_width; - int aspect_height; - std::set grouplist; // list of groups to be converted - std::set allblobj; // all objects converted - std::set groupobj; // objects from groups (never in active layer) + // List of groups to be converted + std::set grouplist; + // All objects converted. + std::set allblobj; + // Objects from groups (never in active layer). + std::set groupobj; /* We have to ensure that group definitions are only converted once * push all converted group members to this set. @@ -1365,41 +1289,50 @@ void BL_ConvertBlenderObjects(struct Main* maggie, * and both are on the active layer. */ CListValue *convertedlist = new CListValue(); + + // Get the frame settings of the canvas. + // Get the aspect ratio of the canvas as designed by the user. + RAS_FrameSettings::RAS_FrameType frame_type; + int aspect_width; + int aspect_height; + if (alwaysUseExpandFraming) { frame_type = RAS_FrameSettings::e_frame_extend; aspect_width = canvas->GetWidth(); aspect_height = canvas->GetHeight(); - } else { + } + else { if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_BARS) { frame_type = RAS_FrameSettings::e_frame_bars; - } else if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_EXTEND) { + } + else if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_EXTEND) { frame_type = RAS_FrameSettings::e_frame_extend; - } else { + } + else { frame_type = RAS_FrameSettings::e_frame_scale; } - + aspect_width = (int)(blenderscene->r.xsch * blenderscene->r.xasp); aspect_height = (int)(blenderscene->r.ysch * blenderscene->r.yasp); } - + RAS_FrameSettings frame_settings( frame_type, blenderscene->gm.framing.col[0], blenderscene->gm.framing.col[1], blenderscene->gm.framing.col[2], aspect_width, - aspect_height - ); + aspect_height); kxscene->SetFramingType(frame_settings); - kxscene->SetGravity(MT_Vector3(0,0, -blenderscene->gm.gravity)); - - /* set activity culling parameters */ - kxscene->SetActivityCulling( (blenderscene->gm.mode & WO_ACTIVITY_CULLING) != 0); + kxscene->SetGravity(MT_Vector3(0.0f, 0.0f, -blenderscene->gm.gravity)); + + // Set activity culling parameters. + kxscene->SetActivityCulling((blenderscene->gm.mode & WO_ACTIVITY_CULLING) != 0); kxscene->SetActivityCullingRadius(blenderscene->gm.activityBoxRadius); kxscene->SetDbvtCulling((blenderscene->gm.mode & WO_DBVT_CULLING) != 0); - - // no occlusion culling by default + + // No occlusion culling by default. kxscene->SetDbvtOcclusionRes(0); if (blenderscene->gm.lodflag & SCE_LOD_USE_HYST) { @@ -1407,52 +1340,52 @@ void BL_ConvertBlenderObjects(struct Main* maggie, kxscene->SetLodHysteresisValue(blenderscene->gm.scehysteresis); } - // convert world - KX_WorldInfo* worldinfo = new KX_WorldInfo(blenderscene, blenderscene->world); + // Convert world. + KX_WorldInfo *worldinfo = new KX_WorldInfo(blenderscene, blenderscene->world); worldinfo->UpdateWorldSettings(rendertools); worldinfo->UpdateBackGround(rendertools); kxscene->SetWorldInfo(worldinfo); int activeLayerBitInfo = blenderscene->lay; - - // list of all object converted, active and inactive + + // List of all object converted, active and inactive. CListValue *sumolist = new CListValue(); - - std::vector vec_parent_child; - + + std::vector vec_parent_child; + CListValue *objectlist = kxscene->GetObjectList(); CListValue *inactivelist = kxscene->GetInactiveList(); CListValue *parentlist = kxscene->GetRootParentList(); - - SCA_LogicManager* logicmgr = kxscene->GetLogicManager(); - SCA_TimeEventManager* timemgr = kxscene->GetTimeEventManager(); - + + SCA_LogicManager *logicmgr = kxscene->GetLogicManager(); + SCA_TimeEventManager *timemgr = kxscene->GetTimeEventManager(); + CListValue *logicbrick_conversionlist = new CListValue(); - // Convert actions to actionmap + // Convert actions to actionmap. bAction *curAct; - for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next) - { + for (curAct = (bAction *)maggie->action.first; curAct; curAct = (bAction *)curAct->id.next) { logicmgr->RegisterActionName(curAct->id.name + 2, curAct); } - blenderSceneSetBackground(blenderscene); + BL_SetBlenderSceneBackground(blenderscene); - // Let's support scene set. - // Beware of name conflict in linked data, it will not crash but will create confusion - // in Python scripting and in certain actuators (replace mesh). Linked scene *should* have - // no conflicting name for Object, Object data and Action. - for (SETLOOPER(blenderscene, sce_iter, base)) - { - Object* blenderobject = base->object; + /* Let's support scene set. + * Beware of name conflict in linked data, it will not crash but will create confusion + * in Python scripting and in certain actuators (replace mesh). Linked scene *should* have + * no conflicting name for Object, Object data and Action. + */ + Scene *sce_iter; + Base *base; + for (SETLOOPER(blenderscene, sce_iter, base)) { + Object *blenderobject = base->object; allblobj.insert(blenderobject); - KX_GameObject* gameobj = gameobject_from_blenderobject(base->object, kxscene, rendertools, converter); + KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(base->object, kxscene, rendertools, converter); - bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0; - if (gameobj) - { - /* macro calls object conversion funcs */ + bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) != 0; + if (gameobj) { + // Macro calls object conversion funcs. BL_CONVERTBLENDEROBJECT_SINGLE; if (gameobj->IsDupliGroup()) { @@ -1471,50 +1404,38 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - if (!grouplist.empty()) - { - // now convert the group referenced by dupli group object - // keep track of all groups already converted - std::set allgrouplist = grouplist; - std::set tempglist; - // recurse - while (!grouplist.empty()) - { - std::set::iterator git; + if (!grouplist.empty()) { + /* Now convert the group referenced by dupli group object + * keep track of all groups already converted. */ + std::set allgrouplist = grouplist; + std::set tempglist; + while (!grouplist.empty()) { tempglist.clear(); tempglist.swap(grouplist); - for (git=tempglist.begin(); git!=tempglist.end(); git++) - { - Group* group = *git; - GroupObject* go; - for (go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next) - { - Object* blenderobject = go->ob; - if (converter.FindGameObject(blenderobject) == nullptr) - { + for (Group *group : tempglist) { + for (GroupObject *go = (GroupObject *)group->gobject.first; go; go = (GroupObject *)go->next) { + Object *blenderobject = go->ob; + if (!converter.FindGameObject(blenderobject)) { allblobj.insert(blenderobject); groupobj.insert(blenderobject); - KX_GameObject* gameobj = gameobject_from_blenderobject(blenderobject, kxscene, rendertools, converter); + KX_GameObject *gameobj = BL_GameObjectFromBlenderObject(blenderobject, kxscene, rendertools, converter); bool isInActiveLayer = false; if (gameobj) { /* Insert object to the constraint game object list * so we can check later if there is a instance in the scene or * an instance and its actual group definition. */ - convertedlist->Add((KX_GameObject*)gameobj->AddRef()); + convertedlist->Add(CM_AddRef(gameobj)); - /* macro calls object conversion funcs */ + // Macro calls object conversion funcs. BL_CONVERTBLENDEROBJECT_SINGLE; - if (gameobj->IsDupliGroup()) - { - if (allgrouplist.insert(blenderobject->dup_group).second) - { + if (gameobj->IsDupliGroup()) { + if (allgrouplist.insert(blenderobject->dup_group).second) { grouplist.insert(blenderobject->dup_group); } } - /* see comment above re: mem leaks */ gameobj->Release(); } } @@ -1523,198 +1444,185 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - // non-camera objects not supported as camera currently + // Non-camera objects not supported as camera currently. if (blenderscene->camera && blenderscene->camera->type == OB_CAMERA) { - KX_Camera *gamecamera= (KX_Camera*) converter.FindGameObject(blenderscene->camera); - - if (gamecamera) + KX_Camera *gamecamera = static_cast(converter.FindGameObject(blenderscene->camera)); + if (gamecamera) { kxscene->SetActiveCamera(gamecamera); + } } - // Set up armatures - std::set::iterator oit; - for (oit=allblobj.begin(); oit!=allblobj.end(); oit++) - { - Object* blenderobj = *oit; - if (blenderobj->type==OB_MESH) { - Mesh *me = (Mesh*)blenderobj->data; - + // Set up armatures. + for (Object *blenderobj : allblobj) { + if (blenderobj->type == OB_MESH) { + Mesh *me = (Mesh *)blenderobj->data; + if (me->dvert) { - BL_DeformableGameObject *obj = (BL_DeformableGameObject*)converter.FindGameObject(blenderobj); + BL_DeformableGameObject *obj = static_cast(converter.FindGameObject(blenderobj)); - if (obj && BL_ModifierDeformer::HasArmatureDeformer(blenderobj) && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE) { + if (obj && BL_ModifierDeformer::HasArmatureDeformer(blenderobj) && blenderobj->parent && blenderobj->parent->type == OB_ARMATURE) { KX_GameObject *par = converter.FindGameObject(blenderobj->parent); - if (par && obj->GetDeformer()) - ((BL_SkinDeformer*)obj->GetDeformer())->SetArmature((BL_ArmatureObject*) par); + if (par && obj->GetDeformer()) { + ((BL_SkinDeformer *)obj->GetDeformer())->SetArmature((BL_ArmatureObject *)par); + } } } } } - - // create hierarchy information - std::vector::iterator pcit; - - for (pcit = vec_parent_child.begin();!(pcit==vec_parent_child.end());++pcit) - { - - struct Object* blenderchild = pcit->m_blenderchild; - struct Object* blenderparent = blenderchild->parent; - KX_GameObject* parentobj = converter.FindGameObject(blenderparent); - KX_GameObject* childobj = converter.FindGameObject(blenderchild); + + // Create hierarchy information. + for (const BL_ParentChildLink& link : vec_parent_child) { + + Object *blenderchild = link.m_blenderchild; + Object *blenderparent = blenderchild->parent; + KX_GameObject *parentobj = converter.FindGameObject(blenderparent); + KX_GameObject *childobj = converter.FindGameObject(blenderchild); BLI_assert(childobj); - if (!parentobj || objectlist->SearchValue(childobj) != objectlist->SearchValue(parentobj)) - { - // special case: the parent and child object are not in the same layer. - // This weird situation is used in Apricot for test purposes. - // Resolve it by not converting the child + if (!parentobj || objectlist->SearchValue(childobj) != objectlist->SearchValue(parentobj)) { + /* Special case: the parent and child object are not in the same layer. + * This weird situation is used in Apricot for test purposes. + * Resolve it by not converting the child + */ childobj->GetSGNode()->DisconnectFromParent(); - delete pcit->m_gamechildnode; - // Now destroy the child object but also all its descendent that may already be linked - // Remove the child reference in the local list! - // Note: there may be descendents already if the children of the child were processed - // by this loop before the child. In that case, we must remove the children also + delete link.m_gamechildnode; + /* Now destroy the child object but also all its descendent that may already be linked + * Remove the child reference in the local list! + * Note: there may be descendents already if the children of the child were processed + * by this loop before the child. In that case, we must remove the children also + */ CListValue *childrenlist = childobj->GetChildrenRecursive(); // The returned list by GetChildrenRecursive is not owned by anyone and must not own items, so no AddRef(). childrenlist->Add(childobj); for (KX_GameObject *obj : childrenlist) { - if (sumolist->RemoveValue(obj)) + if (sumolist->RemoveValue(obj)) { obj->Release(); - if (logicbrick_conversionlist->RemoveValue(obj)) + } + if (logicbrick_conversionlist->RemoveValue(obj)) { obj->Release(); + } if (convertedlist->RemoveValue(obj)) { obj->Release(); } } childrenlist->Release(); - - // now destroy recursively - converter.UnregisterGameObject(childobj); // removing objects during conversion make sure this runs too + + converter.UnregisterGameObject(childobj); kxscene->RemoveObject(childobj); - + continue; } - switch (blenderchild->partype) - { + switch (blenderchild->partype) { case PARVERT1: { - // creat a new vertex parent relationship for this node. - KX_VertexParentRelation * vertex_parent_relation = KX_VertexParentRelation::New(); - pcit->m_gamechildnode->SetParentRelation(vertex_parent_relation); + // Create a new vertex parent relationship for this node. + KX_VertexParentRelation *vertex_parent_relation = KX_VertexParentRelation::New(); + link.m_gamechildnode->SetParentRelation(vertex_parent_relation); break; } case PARSLOW: { - // creat a new slow parent relationship for this node. - KX_SlowParentRelation * slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf); - pcit->m_gamechildnode->SetParentRelation(slow_parent_relation); + // Create a new slow parent relationship for this node. + KX_SlowParentRelation *slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf); + link.m_gamechildnode->SetParentRelation(slow_parent_relation); break; } case PARBONE: { - // parent this to a bone + // Parent this to a bone. Bone *parent_bone = BKE_armature_find_bone_name(BKE_armature_from_object(blenderchild->parent), blenderchild->parsubstr); if (parent_bone) { KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone); - pcit->m_gamechildnode->SetParentRelation(bone_parent_relation); + link.m_gamechildnode->SetParentRelation(bone_parent_relation); } - + break; } - case PARSKEL: // skinned - ignore - break; - case PAROBJECT: - case PARVERT3: default: - // unhandled + { + // Unhandled. break; + } } - - parentobj-> GetSGNode()->AddChild(pcit->m_gamechildnode); + + parentobj->GetSGNode()->AddChild(link.m_gamechildnode); } vec_parent_child.clear(); - - // find 'root' parents (object that has not parents in SceneGraph) + + // Find 'root' parents (object that has not parents in SceneGraph). for (KX_GameObject *gameobj : sumolist) { - if (gameobj->GetSGNode()->GetSGParent() == 0) { + if (!gameobj->GetSGNode()->GetSGParent()) { parentlist->Add(CM_AddRef(gameobj)); - gameobj->NodeUpdateGS(0); + gameobj->NodeUpdateGS(0.0); } } - // create graphic controller for culling - if (kxscene->GetDbvtCulling()) - { + // Create graphic controller for culling. + if (kxscene->GetDbvtCulling()) { bool occlusion = false; for (KX_GameObject *gameobj : sumolist) { // The object can be culled ? if (gameobj->GetMeshCount() || gameobj->GetGameObjectType() == SCA_IObject::OBJ_TEXT) { bool isactive = objectlist->SearchValue(gameobj); BL_CreateGraphicObjectNew(gameobj, kxscene, isactive, physics_engine); - if (gameobj->GetOccluder()) + if (gameobj->GetOccluder()) { occlusion = true; + } } } - if (occlusion) + if (occlusion) { kxscene->SetDbvtOcclusionRes(blenderscene->gm.occlusionRes); + } } - if (blenderscene->world) + + if (blenderscene->world) { kxscene->GetPhysicsEnvironment()->SetNumTimeSubSteps(blenderscene->gm.physubstep); + } - // now that the scenegraph is complete, let's instantiate the deformers. - // We need that to create reusable derived mesh and physic shapes + /* Now that the scenegraph is complete, let's instantiate the deformers. + * We need that to create reusable derived mesh and physic shapes. + */ for (KX_GameObject *gameobj : sumolist) { - if (gameobj->GetDeformer()) + if (gameobj->GetDeformer()) { gameobj->GetDeformer()->UpdateBuckets(); + } } - // Set up armature constraints and shapekey drivers + // Set up armature constraints and shapekey drivers. for (KX_GameObject *gameobj : sumolist) { if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) { - BL_ArmatureObject *armobj = (BL_ArmatureObject*)gameobj; + BL_ArmatureObject *armobj = static_cast(gameobj); armobj->LoadConstraints(converter); CListValue *children = armobj->GetChildren(); for (KX_GameObject *child : children) { - BL_ShapeDeformer *deform = dynamic_cast(child->GetDeformer()); - if (deform) - deform->LoadShapeDrivers(armobj); + BL_ShapeDeformer *deformer = dynamic_cast(child->GetDeformer()); + if (deformer) { + deformer->LoadShapeDrivers(armobj); + } } children->Release(); } } - bool processCompoundChildren = false; - // create physics information - for (KX_GameObject *gameobj : sumolist) { - struct Object* blenderobject = gameobj->GetBlenderObject(); - int nummeshes = gameobj->GetMeshCount(); - RAS_MeshObject* meshobj = 0; - if (nummeshes > 0) - { - meshobj = gameobj->GetMesh(0); - } - int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; - BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren); - } - - processCompoundChildren = true; - // create physics information - for (KX_GameObject *gameobj : sumolist) { - struct Object* blenderobject = gameobj->GetBlenderObject(); - int nummeshes = gameobj->GetMeshCount(); - RAS_MeshObject* meshobj = 0; - if (nummeshes > 0) - { - meshobj = gameobj->GetMesh(0); + // Create physics information. + for (unsigned short i = 0; i < 2; ++i) { + const bool processCompoundChildren = (i == 1); + for (KX_GameObject *gameobj : sumolist) { + Object *blenderobject = gameobj->GetBlenderObject(); + const unsigned short nummeshes = gameobj->GetMeshCount(); + RAS_MeshObject *meshobj = nullptr; + if (nummeshes > 0) { + meshobj = gameobj->GetMesh(0); + } + int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; + BL_CreatePhysicsObjectNew(gameobj, blenderobject, meshobj, kxscene, layerMask, converter, processCompoundChildren); } - int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0; - BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren); } // Look at every material texture and ask to create realtime cube map. @@ -1783,36 +1691,39 @@ void BL_ConvertBlenderObjects(struct Main* maggie, } } - // create physics joints + // Create physics joints. for (KX_GameObject *gameobj : sumolist) { PHY_IPhysicsEnvironment *physEnv = kxscene->GetPhysicsEnvironment(); - struct Object *blenderobject = gameobj->GetBlenderObject(); - ListBase *conlist = get_active_constraints2(blenderobject); - bConstraint *curcon; + Object *blenderobject = gameobj->GetBlenderObject(); + ListBase *conlist = BL_GetActiveConstraint(blenderobject); - if (!conlist) + if (!conlist) { continue; + } - for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { - if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT) + for (bConstraint *curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) { + if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT) { continue; + } bRigidBodyJointConstraint *dat = (bRigidBodyJointConstraint *)curcon->data; - - /* Skip if no target or a child object is selected or constraints are deactivated */ - if (!dat->tar || dat->child || (curcon->flag & CONSTRAINT_OFF)) + + // Skip if no target or a child object is selected or constraints are deactivated. + if (!dat->tar || dat->child || (curcon->flag & CONSTRAINT_OFF)) { continue; + } - /* Store constraints of grouped and instanced objects for all layers */ + // Store constraints of grouped and instanced objects for all layers. gameobj->AddConstraint(dat); /** if it's during libload we only add constraints in the object but * doesn't create it. Constraint will be replicated later in scene->MergeScene */ - if (libloading) + if (libloading) { continue; + } - /* Skipped already converted constraints. + /* Skipped already converted constraints. * This will happen when a group instance is made from a linked group instance * and both are on the active layer. */ if (convertedlist->FindValue(gameobj->GetName())) { @@ -1821,70 +1732,69 @@ void BL_ConvertBlenderObjects(struct Main* maggie, KX_GameObject *gotar = sumolist->FindValue(dat->tar->id.name + 2); - if (gotar && (gotar->GetLayer()&activeLayerBitInfo) && gotar->GetPhysicsController() && - (gameobj->GetLayer()&activeLayerBitInfo) && gameobj->GetPhysicsController()) - { + if (gotar && (gotar->GetLayer() & activeLayerBitInfo) && gotar->GetPhysicsController() && + (gameobj->GetLayer() & activeLayerBitInfo) && gameobj->GetPhysicsController()) { physEnv->SetupObjectConstraints(gameobj, gotar, dat); } } } - //create object representations for obstacle simulation - KX_ObstacleSimulation* obssimulation = kxscene->GetObstacleSimulation(); - if (obssimulation) - { + // Create object representations for obstacle simulation. + KX_ObstacleSimulation *obssimulation = kxscene->GetObstacleSimulation(); + if (obssimulation) { for (KX_GameObject *gameobj : objectlist) { - struct Object* blenderobject = gameobj->GetBlenderObject(); - if (blenderobject->gameflag & OB_HASOBSTACLE) - { + Object *blenderobject = gameobj->GetBlenderObject(); + if (blenderobject->gameflag & OB_HASOBSTACLE) { obssimulation->AddObstacleForObj(gameobj); } } } - //process navigation mesh objects + // Process navigation mesh objects. for (KX_GameObject *gameobj : objectlist) { - struct Object* blenderobject = gameobj->GetBlenderObject(); - if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH)) - { - KX_NavMeshObject* navmesh = static_cast(gameobj); - navmesh->SetVisible(0, true); + Object *blenderobject = gameobj->GetBlenderObject(); + if (blenderobject->type == OB_MESH && (blenderobject->gameflag & OB_NAVMESH)) { + KX_NavMeshObject *navmesh = static_cast(gameobj); + navmesh->SetVisible(false, true); navmesh->BuildNavMesh(); - if (obssimulation) + if (obssimulation) { obssimulation->AddObstaclesForNavMesh(navmesh); + } } } for (KX_GameObject *gameobj : inactivelist) { - struct Object* blenderobject = gameobj->GetBlenderObject(); - if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH)) - { - KX_NavMeshObject* navmesh = static_cast(gameobj); - navmesh->SetVisible(0, true); + Object *blenderobject = gameobj->GetBlenderObject(); + if (blenderobject->type == OB_MESH && (blenderobject->gameflag & OB_NAVMESH)) { + KX_NavMeshObject *navmesh = static_cast(gameobj); + navmesh->SetVisible(false, true); } } - // convert logic bricks, sensors, controllers and actuators + // Convert logic bricks, sensors, controllers and actuators. for (KX_GameObject *gameobj : logicbrick_conversionlist) { - struct Object* blenderobj = gameobj->GetBlenderObject(); + Object *blenderobj = gameobj->GetBlenderObject(); int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; - bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; - BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,converter); + bool isInActiveLayer = (blenderobj->lay & layerMask) != 0; + BL_ConvertActuators(maggie->name, blenderobj, gameobj, logicmgr, kxscene, ketsjiEngine, layerMask, isInActiveLayer, converter); } + for (KX_GameObject *gameobj : logicbrick_conversionlist) { - struct Object* blenderobj = gameobj->GetBlenderObject(); + Object *blenderobj = gameobj->GetBlenderObject(); int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; - bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; - BL_ConvertControllers(blenderobj,gameobj,logicmgr, layerMask,isInActiveLayer,converter, libloading); + bool isInActiveLayer = (blenderobj->lay & layerMask) != 0; + BL_ConvertControllers(blenderobj, gameobj, logicmgr, layerMask, isInActiveLayer, converter, libloading); } + for (KX_GameObject *gameobj : logicbrick_conversionlist) { - struct Object* blenderobj = gameobj->GetBlenderObject(); + Object *blenderobj = gameobj->GetBlenderObject(); int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0; - bool isInActiveLayer = (blenderobj->lay & layerMask)!=0; - BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,canvas,converter); - // set the init state to all objects - gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state); + bool isInActiveLayer = (blenderobj->lay & layerMask) != 0; + BL_ConvertSensors(blenderobj, gameobj, logicmgr, kxscene, ketsjiEngine, layerMask, isInActiveLayer, canvas, converter); + // Set the init state to all objects. + gameobj->SetInitState((blenderobj->init_state) ? blenderobj->init_state : blenderobj->state); } - // apply the initial state to controllers, only on the active objects as this registers the sensors + + // Apply the initial state to controllers, only on the active objects as this registers the sensors. for (KX_GameObject *gameobj : objectlist) { gameobj->ResetState(); } @@ -1895,24 +1805,20 @@ void BL_ConvertBlenderObjects(struct Main* maggie, BL_ConvertComponentsObject(gameobj, blenderobj); } - // cleanup converted set of group objects + // Cleanup converted set of group objects. convertedlist->Release(); sumolist->Release(); logicbrick_conversionlist->Release(); - - // Calculate the scene btree - - // too slow - commented out. - //kxscene->SetNodeTree(tf.MakeTree()); - - // instantiate dupli group, we will loop trough the object - // that are in active layers. Note that duplicating group - // has the effect of adding objects at the end of objectlist. - // Only loop through the first part of the list. + + /* Instantiate dupli group, we will loop trough the object + * that are in active layers. Note that duplicating group + * has the effect of adding objects at the end of objectlist. + * Only loop through the first part of the list. + */ int objcount = objectlist->GetCount(); for (unsigned int i = 0; i < objcount; ++i) { - KX_GameObject* gameobj = objectlist->GetValue(i); - if (gameobj->IsDupliGroup()) - { + KX_GameObject *gameobj = objectlist->GetValue(i); + if (gameobj->IsDupliGroup()) { kxscene->DupliGroupRecurse(gameobj, 0); } } diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.h b/source/gameengine/Converter/BL_BlenderDataConversion.h index 87e571efddd9..e842afab095a 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.h +++ b/source/gameengine/Converter/BL_BlenderDataConversion.h @@ -36,19 +36,17 @@ #include "KX_PhysicsEngineEnums.h" #include "SCA_IInputDevice.h" -struct Material; -struct Mesh; -struct DerivedMesh; -struct Object; -struct Main; class RAS_Rasterizer; class RAS_ICanvas; class KX_KetsjiEngine; class KX_Scene; class BL_BlenderSceneConverter; +struct Mesh; +struct DerivedMesh; +struct Object; +struct Main; -struct BL_MeshMaterial -{ +struct BL_MeshMaterial { RAS_IDisplayArray *array; RAS_MaterialBucket *bucket; bool visible; @@ -59,18 +57,12 @@ struct BL_MeshMaterial RAS_MeshObject *BL_ConvertMesh(Mesh *mesh, Object *lightobj, KX_Scene *scene, BL_BlenderSceneConverter& converter); void BL_ConvertDerivedMeshToArray(DerivedMesh *dm, Mesh *me, const std::vector& mats, - const RAS_MeshObject::LayersInfo& layersInfo); + const RAS_MeshObject::LayersInfo& layersInfo); -void BL_ConvertBlenderObjects(Main *maggie, - KX_Scene *kxscene, - KX_KetsjiEngine *ketsjiEngine, - e_PhysicsEngine physics_engine, - RAS_Rasterizer *rendertools, - RAS_ICanvas *canvas, - BL_BlenderSceneConverter& sceneconverter, - bool alwaysUseExpandFraming, - bool libloading=false); +void BL_ConvertBlenderObjects(Main *maggie, KX_Scene *kxscene, KX_KetsjiEngine *ketsjiEngine, e_PhysicsEngine physics_engine, + RAS_Rasterizer *rendertools, RAS_ICanvas *canvas, BL_BlenderSceneConverter& sceneconverter, + bool alwaysUseExpandFraming, bool libloading); -SCA_IInputDevice::SCA_EnumInputs ConvertKeyCode(int key_code); +SCA_IInputDevice::SCA_EnumInputs BL_ConvertKeyCode(int key_code); -#endif /* __BL_BLENDERDATACONVERSION_H__ */ +#endif // __BL_BLENDERDATACONVERSION_H__ diff --git a/source/gameengine/Converter/BL_ConvertSensors.cpp b/source/gameengine/Converter/BL_ConvertSensors.cpp index 13982c38f4ca..70be6634c8eb 100644 --- a/source/gameengine/Converter/BL_ConvertSensors.cpp +++ b/source/gameengine/Converter/BL_ConvertSensors.cpp @@ -255,9 +255,9 @@ void BL_ConvertSensors(struct Object* blenderobject, if (eventmgr) { gamesensor = new SCA_KeyboardSensor(eventmgr, - ConvertKeyCode(blenderkeybdsensor->key), - ConvertKeyCode(blenderkeybdsensor->qual), - ConvertKeyCode(blenderkeybdsensor->qual2), + BL_ConvertKeyCode(blenderkeybdsensor->key), + BL_ConvertKeyCode(blenderkeybdsensor->qual), + BL_ConvertKeyCode(blenderkeybdsensor->qual2), (blenderkeybdsensor->type == SENS_ALL_KEYS), blenderkeybdsensor->targetName, blenderkeybdsensor->toggleName, diff --git a/source/gameengine/GameLogic/SCA_IInputDevice.h b/source/gameengine/GameLogic/SCA_IInputDevice.h index 2f9aba8ccf2d..c74c9ab08e86 100644 --- a/source/gameengine/GameLogic/SCA_IInputDevice.h +++ b/source/gameengine/GameLogic/SCA_IInputDevice.h @@ -35,10 +35,6 @@ #include "SCA_InputEvent.h" #include -// #include - -#define MOUSEX MOUSEMOVE -#define MOUSEY ACTIONMOUSE class SCA_IInputDevice { diff --git a/source/gameengine/Launcher/LA_Launcher.cpp b/source/gameengine/Launcher/LA_Launcher.cpp index 7644794d294c..2a1666d01c93 100644 --- a/source/gameengine/Launcher/LA_Launcher.cpp +++ b/source/gameengine/Launcher/LA_Launcher.cpp @@ -166,7 +166,7 @@ void LA_Launcher::InitEngine() // Setup python console keys used as shortcut. for (unsigned short i = 0; i < 4; ++i) { if (gm.pythonkeys[i] != EVENT_NONE) { - m_pythonConsole.keys.push_back(ConvertKeyCode(gm.pythonkeys[i])); + m_pythonConsole.keys.push_back(BL_ConvertKeyCode(gm.pythonkeys[i])); } } m_pythonConsole.use = (gm.flag & GAME_PYTHON_CONSOLE); @@ -249,7 +249,7 @@ void LA_Launcher::InitEngine() DEV_Joystick::Init(); - m_ketsjiEngine->SetExitKey(ConvertKeyCode(gm.exitkey)); + m_ketsjiEngine->SetExitKey(BL_ConvertKeyCode(gm.exitkey)); #ifdef WITH_PYTHON CValue::SetDeprecationWarnings(nodepwarnings); #else diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp index a30d5bee27df..f4b392f8750e 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp @@ -2688,7 +2688,7 @@ CcdPhysicsEnvironment *CcdPhysicsEnvironment::Create(Scene *blenderscene, bool v } void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, KX_GameObject *gameobj, RAS_MeshObject *meshobj, - KX_Scene *kxscene, PHY_ShapeProps *shapeprops, PHY_IMotionState *motionstate, + KX_Scene *kxscene, const PHY_ShapeProps& shapeprops, PHY_IMotionState *motionstate, int activeLayerBitInfo, bool isCompoundChild, bool hasCompoundChildren) { Object *blenderobject = gameobj->GetBlenderObject(); @@ -2736,15 +2736,15 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) != 0) ? 0.0f : 1.0f, ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) != 0) ? 0.0f : 1.0f); ci.m_localInertiaTensor = btVector3(0.0f, 0.0f, 0.0f); - ci.m_mass = isbulletdyna ? shapeprops->m_mass : 0.0f; - ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min; - ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max; - ci.m_clamp_angvel_min = shapeprops->m_clamp_angvel_min; - ci.m_clamp_angvel_max = shapeprops->m_clamp_angvel_max; - ci.m_stepHeight = isbulletchar ? shapeprops->m_step_height : 0.0f; - ci.m_jumpSpeed = isbulletchar ? shapeprops->m_jump_speed : 0.0f; - ci.m_fallSpeed = isbulletchar ? shapeprops->m_fall_speed : 0.0f; - ci.m_maxJumps = isbulletchar ? shapeprops->m_max_jumps : 0; + ci.m_mass = isbulletdyna ? shapeprops.m_mass : 0.0f; + ci.m_clamp_vel_min = shapeprops.m_clamp_vel_min; + ci.m_clamp_vel_max = shapeprops.m_clamp_vel_max; + ci.m_clamp_angvel_min = shapeprops.m_clamp_angvel_min; + ci.m_clamp_angvel_max = shapeprops.m_clamp_angvel_max; + ci.m_stepHeight = isbulletchar ? shapeprops.m_step_height : 0.0f; + ci.m_jumpSpeed = isbulletchar ? shapeprops.m_jump_speed : 0.0f; + ci.m_fallSpeed = isbulletchar ? shapeprops.m_fall_speed : 0.0f; + ci.m_maxJumps = isbulletchar ? shapeprops.m_max_jumps : 0; //mmm, for now, take this for the size of the dynamicobject // Blender uses inertia for radius of dynamic object @@ -3077,26 +3077,26 @@ void CcdPhysicsEnvironment::ConvertObject(BL_BlenderSceneConverter& converter, K ci.m_collisionShape = bm; ci.m_shapeInfo = shapeInfo; - ci.m_friction = shapeprops->m_friction;//tweak the friction a bit, so the default 0.5 works nice - ci.m_rollingFriction = shapeprops->m_rollingFriction; - ci.m_restitution = shapeprops->m_restitution; + ci.m_friction = shapeprops.m_friction;//tweak the friction a bit, so the default 0.5 works nice + ci.m_rollingFriction = shapeprops.m_rollingFriction; + ci.m_restitution = shapeprops.m_restitution; ci.m_physicsEnv = this; // drag / damping is inverted - ci.m_linearDamping = 1.0f - shapeprops->m_lin_drag; - ci.m_angularDamping = 1.0f - shapeprops->m_ang_drag; + ci.m_linearDamping = 1.0f - shapeprops.m_lin_drag; + ci.m_angularDamping = 1.0f - shapeprops.m_ang_drag; //need a bit of damping, else system doesn't behave well - ci.m_inertiaFactor = shapeprops->m_inertia / 0.4f;//defaults to 0.4, don't want to change behavior + ci.m_inertiaFactor = shapeprops.m_inertia / 0.4f;//defaults to 0.4, don't want to change behavior - ci.m_do_anisotropic = shapeprops->m_do_anisotropic; - ci.m_anisotropicFriction = ToBullet(shapeprops->m_friction_scaling); + ci.m_do_anisotropic = shapeprops.m_do_anisotropic; + ci.m_anisotropicFriction = ToBullet(shapeprops.m_friction_scaling); //do Fh, do Rot Fh - ci.m_do_fh = shapeprops->m_do_fh; - ci.m_do_rot_fh = shapeprops->m_do_rot_fh; - ci.m_fh_damping = shapeprops->m_fh_damping; - ci.m_fh_distance = shapeprops->m_fh_distance; - ci.m_fh_normal = shapeprops->m_fh_normal; - ci.m_fh_spring = shapeprops->m_fh_spring; + ci.m_do_fh = shapeprops.m_do_fh; + ci.m_do_rot_fh = shapeprops.m_do_rot_fh; + ci.m_fh_damping = shapeprops.m_fh_damping; + ci.m_fh_distance = shapeprops.m_fh_distance; + ci.m_fh_normal = shapeprops.m_fh_normal; + ci.m_fh_spring = shapeprops.m_fh_spring; ci.m_collisionFilterGroup = (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) : diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h index fab2afaf4bf8..597960440c49 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h +++ b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h @@ -258,7 +258,7 @@ class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment KX_GameObject *gameobj, RAS_MeshObject *meshobj, KX_Scene *kxscene, - PHY_ShapeProps *shapeprops, + const PHY_ShapeProps& shapeprops, PHY_IMotionState *motionstate, int activeLayerBitInfo, bool isCompoundChild, diff --git a/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h index ef0369f6c700..596530f61f7c 100644 --- a/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h +++ b/source/gameengine/Physics/Common/PHY_IPhysicsEnvironment.h @@ -232,7 +232,7 @@ class PHY_IPhysicsEnvironment KX_GameObject *gameobj, RAS_MeshObject *meshobj, KX_Scene *kxscene, - PHY_ShapeProps *shapeprops, + const PHY_ShapeProps& shapeprops, PHY_IMotionState *motionstate, int activeLayerBitInfo, bool isCompoundChild, diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h index 23955a5a7019..35a335f1ecc9 100644 --- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h +++ b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h @@ -122,7 +122,7 @@ class DummyPhysicsEnvironment : public PHY_IPhysicsEnvironment KX_GameObject *gameobj, RAS_MeshObject *meshobj, KX_Scene *kxscene, - PHY_ShapeProps *shapeprops, + const PHY_ShapeProps& shapeprops, PHY_IMotionState *motionstate, int activeLayerBitInfo, bool isCompoundChild,