diff options
author | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-07-24 21:28:39 +0300 |
---|---|---|
committer | Porteries Tristan <republicthunderbolt9@gmail.com> | 2015-07-25 10:43:06 +0300 |
commit | 9939c189001566e1cfdbb09ecffdec177920b31a (patch) | |
tree | 6251a2acf318ace7329b937492a85e90bffcabfb /source | |
parent | e301cf3ec2cb8caa544032238cf7a1e7bb5e2523 (diff) |
BGE: Fix T35288 Touch/Ray/Mouse sensor and Constraint actuator with material check doesn't work.
Now we look at all materials instead of the first. So m_auxilary_info is useless and removed.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Converter/BL_BlenderDataConversion.cpp | 10 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ClientObjectInfo.h | 9 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_ConstraintActuator.cpp | 17 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 34 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_RaySensor.cpp | 45 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_TouchSensor.cpp | 41 |
6 files changed, 91 insertions, 65 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp index 49eb2256b47..33c4ffd9a0c 100644 --- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp +++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp @@ -1391,16 +1391,6 @@ static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj, if ((blenderobject->gameflag & OB_RECORD_ANIMATION) != 0) gameobj->SetRecordAnimation(true); - // store materialname in auxinfo, needed for touchsensors - if (meshobj) - { - const STR_String& matname=meshobj->GetMaterialName(0); - gameobj->getClientInfo()->m_auxilary_info = (matname.Length() ? (void*)(matname.ReadPtr()+2) : NULL); - } else - { - gameobj->getClientInfo()->m_auxilary_info = 0; - } - delete shapeprops; delete smmaterial; if (dm) { diff --git a/source/gameengine/Ketsji/KX_ClientObjectInfo.h b/source/gameengine/Ketsji/KX_ClientObjectInfo.h index e947eb4be6d..81ae5b58009 100644 --- a/source/gameengine/Ketsji/KX_ClientObjectInfo.h +++ b/source/gameengine/Ketsji/KX_ClientObjectInfo.h @@ -52,19 +52,16 @@ struct KX_ClientObjectInfo OBACTORSENSOR } m_type; KX_GameObject* m_gameobject; - void* m_auxilary_info; std::list<SCA_ISensor*> m_sensors; public: - KX_ClientObjectInfo(KX_GameObject *gameobject, clienttype type = STATIC, void *auxilary_info = NULL) : + KX_ClientObjectInfo(KX_GameObject *gameobject, clienttype type = STATIC) : m_type(type), - m_gameobject(gameobject), - m_auxilary_info(auxilary_info) + m_gameobject(gameobject) {} KX_ClientObjectInfo(const KX_ClientObjectInfo ©) : m_type(copy.m_type), - m_gameobject(copy.m_gameobject), - m_auxilary_info(copy.m_auxilary_info) + m_gameobject(copy.m_gameobject) { } diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index e5662b54b83..e07660cef72 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -41,6 +41,7 @@ #include "KX_GameObject.h" #include "KX_RayCast.h" #include "KX_PythonInit.h" // KX_GetActiveScene +#include "RAS_MeshObject.h" #include <stdio.h> @@ -129,15 +130,17 @@ bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo *client, KX_RayCast *resu } else { - if (m_option & KX_ACT_CONSTRAINT_MATERIAL) - { - if (client->m_auxilary_info) - { - bFound = !strcmp(m_property.Ptr(), ((char*)client->m_auxilary_info)); + if (m_option & KX_ACT_CONSTRAINT_MATERIAL) { + for (unsigned int i = 0; i < m_hitObject->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = m_hitObject->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + bFound = strcmp(m_property.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (bFound) + break; + } } } - else - { + else { bFound = m_hitObject->GetProperty(m_property) != NULL; } } diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index c3c693ed55f..46f27e1a2df 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -42,6 +42,7 @@ #include "RAS_FramingManager.h" #include "RAS_ICanvas.h" #include "RAS_IRasterizer.h" +#include "RAS_MeshObject.h" #include "SCA_IScene.h" #include "KX_Scene.h" #include "KX_Camera.h" @@ -165,15 +166,17 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *r } else { - if (m_bFindMaterial) - { - if (client_info->m_auxilary_info) - { - bFound = (m_propertyname== ((char*)client_info->m_auxilary_info)); + if (m_bFindMaterial) { + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (bFound) + break; + } } } - else - { + else { bFound = hitKXObj->GetProperty(m_propertyname) != NULL; } } @@ -197,6 +200,8 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *r */ bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client) { + KX_GameObject *hitKXObj = client->m_gameobject; + if (client->m_type > KX_ClientObjectInfo::ACTOR) { // Unknown type of object, skip it. @@ -208,14 +213,21 @@ bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client) { if (m_bFindMaterial) { - // not quite correct: an object may have multiple material - // should check all the material and not only the first one - if (!client->m_auxilary_info || (m_propertyname != ((char*)client->m_auxilary_info))) + bool found = false; + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (found) + break; + } + } + if (!found) return false; } else { - if (client->m_gameobject->GetProperty(m_propertyname) == NULL) + if (hitKXObj->GetProperty(m_propertyname) == NULL) return false; } } diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp index 0f47dfd922b..c97d233a67b 100644 --- a/source/gameengine/Ketsji/KX_RaySensor.cpp +++ b/source/gameengine/Ketsji/KX_RaySensor.cpp @@ -46,6 +46,7 @@ #include "PHY_IPhysicsEnvironment.h" #include "PHY_IPhysicsController.h" #include "DNA_sensor_types.h" +#include "RAS_MeshObject.h" #include <stdio.h> @@ -111,6 +112,7 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void KX_GameObject* hitKXObj = client->m_gameobject; bool bFound = false; + bool hitMaterial = false; if (m_propertyname.Length() == 0) { @@ -118,15 +120,19 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void } else { - if (m_bFindMaterial) - { - if (client->m_auxilary_info) - { - bFound = (m_propertyname== ((char*)client->m_auxilary_info)); + if (m_bFindMaterial) { + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (bFound) { + hitMaterial = true; + break; + } + } } } - else - { + else { bFound = hitKXObj->GetProperty(m_propertyname) != NULL; } } @@ -143,7 +149,7 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void m_hitNormal[1] = result->m_hitNormal[1]; m_hitNormal[2] = result->m_hitNormal[2]; - m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : ""); + m_hitMaterial = hitMaterial; } // no multi-hit search yet return true; @@ -154,6 +160,8 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void */ bool KX_RaySensor::NeedRayCast(KX_ClientObjectInfo *client) { + KX_GameObject *hitKXObj = client->m_gameobject; + if (client->m_type > KX_ClientObjectInfo::ACTOR) { // Unknown type of object, skip it. @@ -163,16 +171,21 @@ bool KX_RaySensor::NeedRayCast(KX_ClientObjectInfo *client) } if (m_bXRay && m_propertyname.Length() != 0) { - if (m_bFindMaterial) - { - // not quite correct: an object may have multiple material - // should check all the material and not only the first one - if (!client->m_auxilary_info || (m_propertyname != ((char*)client->m_auxilary_info))) + if (m_bFindMaterial) { + bool found = false; + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (found) + break; + } + } + if (!found) return false; } - else - { - if (client->m_gameobject->GetProperty(m_propertyname) == NULL) + else { + if (hitKXObj->GetProperty(m_propertyname) == NULL) return false; } } diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp index 5cb1d5f3620..593d3e844e8 100644 --- a/source/gameengine/Ketsji/KX_TouchSensor.cpp +++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp @@ -41,6 +41,8 @@ #include "PHY_IPhysicsController.h" +#include "RAS_MeshObject.h" + #include <iostream> #include "PHY_IPhysicsEnvironment.h" @@ -219,14 +221,17 @@ bool KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2) bool found = m_touchedpropname.IsEmpty(); if (!found) { - if (m_bFindMaterial) - { - if (client_info->m_auxilary_info) - { - found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info)); + if (m_bFindMaterial) { + for (unsigned int i = 0; i < otherobj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = otherobj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + found = strcmp(m_touchedpropname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (found) + break; + } } - } else - { + } + else { found = (otherobj->GetProperty(m_touchedpropname) != NULL); } } @@ -255,16 +260,22 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll { bool found = m_touchedpropname.IsEmpty(); + bool hitMaterial = false; if (!found) { - if (m_bFindMaterial) - { - if (client_info->m_auxilary_info) - { - found = (!strcmp(m_touchedpropname.Ptr(), (char*)client_info->m_auxilary_info)); + if (m_bFindMaterial) { + for (unsigned int i = 0; i < gameobj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = gameobj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + found = strcmp(m_touchedpropname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (found) { + hitMaterial = true; + break; + } + } } - } else - { + } + else { found = (gameobj->GetProperty(m_touchedpropname) != NULL); } } @@ -278,7 +289,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll } m_bTriggered = true; m_hitObject = gameobj; - m_hitMaterial = (client_info->m_auxilary_info ? (char*)client_info->m_auxilary_info : ""); + m_hitMaterial = hitMaterial; //printf("KX_TouchSensor::HandleCollision\n"); } |