game engine: implement hitMaterial for collision and ray sensors
Reviewed By: moguri, kupoman Differential Revision: https://developer.blender.org/D167
This commit is contained in:
@@ -51,6 +51,12 @@ base class --- :class:`SCA_ISensor`
|
|||||||
|
|
||||||
:type: list [x, y, z]
|
:type: list [x, y, z]
|
||||||
|
|
||||||
|
.. attribute:: hitMaterial
|
||||||
|
|
||||||
|
The material of the object in the face hit by the ray. (read-only).
|
||||||
|
|
||||||
|
:type: string
|
||||||
|
|
||||||
.. attribute:: rayDirection
|
.. attribute:: rayDirection
|
||||||
|
|
||||||
The direction from the ray (in worldcoordinates). (read-only).
|
The direction from the ray (in worldcoordinates). (read-only).
|
||||||
|
|||||||
@@ -39,3 +39,9 @@ base class --- :class:`SCA_ISensor`
|
|||||||
|
|
||||||
:type: :class:`CListValue` of :class:`KX_GameObject`
|
:type: :class:`CListValue` of :class:`KX_GameObject`
|
||||||
|
|
||||||
|
.. attribute:: hitMaterial
|
||||||
|
|
||||||
|
The material of the object in the face hit by the ray. (read-only).
|
||||||
|
|
||||||
|
:type: string
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,8 @@ KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr,
|
|||||||
m_bXRay(bXRay),
|
m_bXRay(bXRay),
|
||||||
m_distance(distance),
|
m_distance(distance),
|
||||||
m_scene(ketsjiScene),
|
m_scene(ketsjiScene),
|
||||||
m_axis(axis)
|
m_axis(axis),
|
||||||
|
m_hitMaterial("")
|
||||||
|
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
@@ -144,6 +143,7 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void
|
|||||||
m_hitNormal[1] = result->m_hitNormal[1];
|
m_hitNormal[1] = result->m_hitNormal[1];
|
||||||
m_hitNormal[2] = result->m_hitNormal[2];
|
m_hitNormal[2] = result->m_hitNormal[2];
|
||||||
|
|
||||||
|
m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : "");
|
||||||
}
|
}
|
||||||
// no multi-hit search yet
|
// no multi-hit search yet
|
||||||
return true;
|
return true;
|
||||||
@@ -356,6 +356,7 @@ PyAttributeDef KX_RaySensor::Attributes[] = {
|
|||||||
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
|
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
|
||||||
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
|
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
|
||||||
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
|
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
|
||||||
|
KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_RaySensor, m_hitMaterial),
|
||||||
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject),
|
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject),
|
||||||
{ NULL } //Sentinel
|
{ NULL } //Sentinel
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ class KX_RaySensor : public SCA_ISensor
|
|||||||
SCA_IObject* m_hitObject;
|
SCA_IObject* m_hitObject;
|
||||||
float m_hitNormal[3];
|
float m_hitNormal[3];
|
||||||
float m_rayDirection[3];
|
float m_rayDirection[3];
|
||||||
|
STR_String m_hitMaterial;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KX_RaySensor(class SCA_EventManager* eventmgr,
|
KX_RaySensor(class SCA_EventManager* eventmgr,
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj
|
|||||||
:SCA_ISensor(gameobj,eventmgr),
|
:SCA_ISensor(gameobj,eventmgr),
|
||||||
m_touchedpropname(touchedpropname),
|
m_touchedpropname(touchedpropname),
|
||||||
m_bFindMaterial(bFindMaterial),
|
m_bFindMaterial(bFindMaterial),
|
||||||
m_bTouchPulse(bTouchPulse)
|
m_bTouchPulse(bTouchPulse),
|
||||||
|
m_hitMaterial("")
|
||||||
/*m_sumoObj(sumoObj),*/
|
/*m_sumoObj(sumoObj),*/
|
||||||
{
|
{
|
||||||
// KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
|
// KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
|
||||||
@@ -281,6 +282,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
|
|||||||
}
|
}
|
||||||
m_bTriggered = true;
|
m_bTriggered = true;
|
||||||
m_hitObject = gameobj;
|
m_hitObject = gameobj;
|
||||||
|
m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : "");
|
||||||
//printf("KX_TouchSensor::HandleCollision\n");
|
//printf("KX_TouchSensor::HandleCollision\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,6 +326,7 @@ PyAttributeDef KX_TouchSensor::Attributes[] = {
|
|||||||
KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,false,KX_TouchSensor,m_touchedpropname),
|
KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,false,KX_TouchSensor,m_touchedpropname),
|
||||||
KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
|
KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
|
||||||
KX_PYATTRIBUTE_BOOL_RW("usePulseCollision",KX_TouchSensor,m_bTouchPulse),
|
KX_PYATTRIBUTE_BOOL_RW("usePulseCollision",KX_TouchSensor,m_bTouchPulse),
|
||||||
|
KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_TouchSensor, m_hitMaterial),
|
||||||
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_TouchSensor, pyattr_get_object_hit),
|
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_TouchSensor, pyattr_get_object_hit),
|
||||||
KX_PYATTRIBUTE_RO_FUNCTION("hitObjectList", KX_TouchSensor, pyattr_get_object_hit_list),
|
KX_PYATTRIBUTE_RO_FUNCTION("hitObjectList", KX_TouchSensor, pyattr_get_object_hit_list),
|
||||||
{ NULL } //Sentinel
|
{ NULL } //Sentinel
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ protected:
|
|||||||
|
|
||||||
SCA_IObject* m_hitObject;
|
SCA_IObject* m_hitObject;
|
||||||
class CListValue* m_colliders;
|
class CListValue* m_colliders;
|
||||||
|
STR_String m_hitMaterial;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KX_TouchSensor(class SCA_EventManager* eventmgr,
|
KX_TouchSensor(class SCA_EventManager* eventmgr,
|
||||||
|
|||||||
Reference in New Issue
Block a user