Various tweaks
This commit is contained in:
@@ -58,9 +58,7 @@ API_STRUCT(NoDefault) struct FLAXENGINE_API Collision
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The total impulse applied to this contact pair to resolve the collision.
|
/// The total impulse applied to this contact pair to resolve the collision.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>The total impulse is obtained by summing up impulses applied at all contact points in this collision pair.</remarks>
|
||||||
/// The total impulse is obtained by summing up impulses applied at all contact points in this collision pair.
|
|
||||||
/// </remarks>
|
|
||||||
API_FIELD() Vector3 Impulse;
|
API_FIELD() Vector3 Impulse;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -87,9 +85,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the relative linear velocity of the two colliding objects.
|
/// Gets the relative linear velocity of the two colliding objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>Can be used to detect stronger collisions. </remarks>
|
||||||
/// Can be used to detect stronger collisions.
|
|
||||||
/// </remarks>
|
|
||||||
Vector3 GetRelativeVelocity() const
|
Vector3 GetRelativeVelocity() const
|
||||||
{
|
{
|
||||||
return ThisVelocity - OtherVelocity;
|
return ThisVelocity - OtherVelocity;
|
||||||
|
|||||||
@@ -228,9 +228,7 @@ class QueryFilterPhysX : public PxQueryFilterCallback
|
|||||||
// Check mask
|
// Check mask
|
||||||
const PxFilterData shapeFilter = shape->getQueryFilterData();
|
const PxFilterData shapeFilter = shape->getQueryFilterData();
|
||||||
if ((filterData.word0 & shapeFilter.word0) == 0)
|
if ((filterData.word0 & shapeFilter.word0) == 0)
|
||||||
{
|
|
||||||
return PxQueryHitType::eNONE;
|
return PxQueryHitType::eNONE;
|
||||||
}
|
|
||||||
|
|
||||||
// Check if skip triggers
|
// Check if skip triggers
|
||||||
const bool hitTriggers = filterData.word2 != 0;
|
const bool hitTriggers = filterData.word2 != 0;
|
||||||
@@ -483,8 +481,10 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define PxHitFlagEmpty (PxHitFlags)0
|
||||||
|
#define SCENE_QUERY_FLAGS (PxHitFlag::ePOSITION | PxHitFlag::eNORMAL | PxHitFlag::eFACE_INDEX | PxHitFlag::eUV)
|
||||||
|
|
||||||
#define SCENE_QUERY_SETUP(blockSingle) auto scenePhysX = (ScenePhysX*)scene; if (scene == nullptr) return false; \
|
#define SCENE_QUERY_SETUP(blockSingle) auto scenePhysX = (ScenePhysX*)scene; if (scene == nullptr) return false; \
|
||||||
const PxHitFlags hitFlags = PxHitFlag::ePOSITION | PxHitFlag::eNORMAL | PxHitFlag::eUV; \
|
|
||||||
PxQueryFilterData filterData; \
|
PxQueryFilterData filterData; \
|
||||||
filterData.flags |= PxQueryFlag::ePREFILTER; \
|
filterData.flags |= PxQueryFlag::ePREFILTER; \
|
||||||
filterData.data.word0 = layerMask; \
|
filterData.data.word0 = layerMask; \
|
||||||
@@ -1735,8 +1735,6 @@ void PhysicsBackend::EndSimulateScene(void* scene)
|
|||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_CPU_NAMED("Physics.SendEvents");
|
PROFILE_CPU_NAMED("Physics.SendEvents");
|
||||||
|
|
||||||
scenePhysX->EventsCallback.CollectResults();
|
|
||||||
scenePhysX->EventsCallback.SendTriggerEvents();
|
scenePhysX->EventsCallback.SendTriggerEvents();
|
||||||
scenePhysX->EventsCallback.SendCollisionEvents();
|
scenePhysX->EventsCallback.SendCollisionEvents();
|
||||||
scenePhysX->EventsCallback.SendJointEvents();
|
scenePhysX->EventsCallback.SendJointEvents();
|
||||||
@@ -1880,14 +1878,14 @@ bool PhysicsBackend::RayCast(void* scene, const Vector3& origin, const Vector3&
|
|||||||
{
|
{
|
||||||
SCENE_QUERY_SETUP(true);
|
SCENE_QUERY_SETUP(true);
|
||||||
PxRaycastBuffer buffer;
|
PxRaycastBuffer buffer;
|
||||||
return scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter);
|
return scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, PxHitFlagEmpty, filterData, &QueryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBackend::RayCast(void* scene, const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
bool PhysicsBackend::RayCast(void* scene, const Vector3& origin, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||||
{
|
{
|
||||||
SCENE_QUERY_SETUP(true);
|
SCENE_QUERY_SETUP(true);
|
||||||
PxRaycastBuffer buffer;
|
PxRaycastBuffer buffer;
|
||||||
if (!scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_SINGLE();
|
SCENE_QUERY_COLLECT_SINGLE();
|
||||||
return true;
|
return true;
|
||||||
@@ -1897,7 +1895,7 @@ bool PhysicsBackend::RayCastAll(void* scene, const Vector3& origin, const Vector
|
|||||||
{
|
{
|
||||||
SCENE_QUERY_SETUP(false);
|
SCENE_QUERY_SETUP(false);
|
||||||
DynamicHitBuffer<PxRaycastHit> buffer;
|
DynamicHitBuffer<PxRaycastHit> buffer;
|
||||||
if (!scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->raycast(C2P(origin - scenePhysX->Origin), C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_ALL();
|
SCENE_QUERY_COLLECT_ALL();
|
||||||
return true;
|
return true;
|
||||||
@@ -1908,7 +1906,7 @@ bool PhysicsBackend::BoxCast(void* scene, const Vector3& center, const Vector3&
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxBoxGeometry geometry(C2P(halfExtents));
|
const PxBoxGeometry geometry(C2P(halfExtents));
|
||||||
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter);
|
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, PxHitFlagEmpty, filterData, &QueryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBackend::BoxCast(void* scene, const Vector3& center, const Vector3& halfExtents, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
bool PhysicsBackend::BoxCast(void* scene, const Vector3& center, const Vector3& halfExtents, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||||
@@ -1916,7 +1914,7 @@ bool PhysicsBackend::BoxCast(void* scene, const Vector3& center, const Vector3&
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxBoxGeometry geometry(C2P(halfExtents));
|
const PxBoxGeometry geometry(C2P(halfExtents));
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_SINGLE();
|
SCENE_QUERY_COLLECT_SINGLE();
|
||||||
return true;
|
return true;
|
||||||
@@ -1927,7 +1925,7 @@ bool PhysicsBackend::BoxCastAll(void* scene, const Vector3& center, const Vector
|
|||||||
SCENE_QUERY_SETUP_SWEEP();
|
SCENE_QUERY_SETUP_SWEEP();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxBoxGeometry geometry(C2P(halfExtents));
|
const PxBoxGeometry geometry(C2P(halfExtents));
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_ALL();
|
SCENE_QUERY_COLLECT_ALL();
|
||||||
return true;
|
return true;
|
||||||
@@ -1938,7 +1936,7 @@ bool PhysicsBackend::SphereCast(void* scene, const Vector3& center, const float
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
||||||
const PxSphereGeometry geometry(radius);
|
const PxSphereGeometry geometry(radius);
|
||||||
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter);
|
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, PxHitFlagEmpty, filterData, &QueryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBackend::SphereCast(void* scene, const Vector3& center, const float radius, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
bool PhysicsBackend::SphereCast(void* scene, const Vector3& center, const float radius, const Vector3& direction, RayCastHit& hitInfo, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||||
@@ -1946,7 +1944,7 @@ bool PhysicsBackend::SphereCast(void* scene, const Vector3& center, const float
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
||||||
const PxSphereGeometry geometry(radius);
|
const PxSphereGeometry geometry(radius);
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_SINGLE();
|
SCENE_QUERY_COLLECT_SINGLE();
|
||||||
return true;
|
return true;
|
||||||
@@ -1957,7 +1955,7 @@ bool PhysicsBackend::SphereCastAll(void* scene, const Vector3& center, const flo
|
|||||||
SCENE_QUERY_SETUP_SWEEP();
|
SCENE_QUERY_SETUP_SWEEP();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
const PxTransform pose(C2P(center - scenePhysX->Origin));
|
||||||
const PxSphereGeometry geometry(radius);
|
const PxSphereGeometry geometry(radius);
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_ALL();
|
SCENE_QUERY_COLLECT_ALL();
|
||||||
return true;
|
return true;
|
||||||
@@ -1968,7 +1966,7 @@ bool PhysicsBackend::CapsuleCast(void* scene, const Vector3& center, const float
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
||||||
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter);
|
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, PxHitFlagEmpty, filterData, &QueryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBackend::CapsuleCast(void* scene, const Vector3& center, const float radius, const float height, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
bool PhysicsBackend::CapsuleCast(void* scene, const Vector3& center, const float radius, const float height, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||||
@@ -1976,7 +1974,7 @@ bool PhysicsBackend::CapsuleCast(void* scene, const Vector3& center, const float
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_SINGLE();
|
SCENE_QUERY_COLLECT_SINGLE();
|
||||||
return true;
|
return true;
|
||||||
@@ -1987,7 +1985,7 @@ bool PhysicsBackend::CapsuleCastAll(void* scene, const Vector3& center, const fl
|
|||||||
SCENE_QUERY_SETUP_SWEEP();
|
SCENE_QUERY_SETUP_SWEEP();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
const PxCapsuleGeometry geometry(radius, height * 0.5f);
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_ALL();
|
SCENE_QUERY_COLLECT_ALL();
|
||||||
return true;
|
return true;
|
||||||
@@ -1999,7 +1997,7 @@ bool PhysicsBackend::ConvexCast(void* scene, const Vector3& center, const Collis
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||||
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter);
|
return scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, PxHitFlagEmpty, filterData, &QueryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsBackend::ConvexCast(void* scene, const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
bool PhysicsBackend::ConvexCast(void* scene, const Vector3& center, const CollisionData* convexMesh, const Vector3& scale, const Vector3& direction, RayCastHit& hitInfo, const Quaternion& rotation, const float maxDistance, uint32 layerMask, bool hitTriggers)
|
||||||
@@ -2008,7 +2006,7 @@ bool PhysicsBackend::ConvexCast(void* scene, const Vector3& center, const Collis
|
|||||||
SCENE_QUERY_SETUP_SWEEP_1();
|
SCENE_QUERY_SETUP_SWEEP_1();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_SINGLE();
|
SCENE_QUERY_COLLECT_SINGLE();
|
||||||
return true;
|
return true;
|
||||||
@@ -2020,7 +2018,7 @@ bool PhysicsBackend::ConvexCastAll(void* scene, const Vector3& center, const Col
|
|||||||
SCENE_QUERY_SETUP_SWEEP();
|
SCENE_QUERY_SETUP_SWEEP();
|
||||||
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
const PxTransform pose(C2P(center - scenePhysX->Origin), C2P(rotation));
|
||||||
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
const PxConvexMeshGeometry geometry((PxConvexMesh*)convexMesh->GetConvex(), PxMeshScale(C2P(scale)));
|
||||||
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, hitFlags, filterData, &QueryFilter))
|
if (!scenePhysX->Scene->sweep(geometry, pose, C2P(direction), maxDistance, buffer, SCENE_QUERY_FLAGS, filterData, &QueryFilter))
|
||||||
return false;
|
return false;
|
||||||
SCENE_QUERY_COLLECT_ALL();
|
SCENE_QUERY_COLLECT_ALL();
|
||||||
return true;
|
return true;
|
||||||
@@ -2608,9 +2606,8 @@ bool PhysicsBackend::RayCastShape(void* shape, const Vector3& position, const Qu
|
|||||||
auto shapePhysX = (PxShape*)shape;
|
auto shapePhysX = (PxShape*)shape;
|
||||||
const Vector3 sceneOrigin = SceneOrigins[shapePhysX->getActor() ? shapePhysX->getActor()->getScene() : nullptr];
|
const Vector3 sceneOrigin = SceneOrigins[shapePhysX->getActor() ? shapePhysX->getActor()->getScene() : nullptr];
|
||||||
const PxTransform trans(C2P(position - sceneOrigin), C2P(orientation));
|
const PxTransform trans(C2P(position - sceneOrigin), C2P(orientation));
|
||||||
const PxHitFlags hitFlags = (PxHitFlags)0;
|
|
||||||
PxRaycastHit hit;
|
PxRaycastHit hit;
|
||||||
if (PxGeometryQuery::raycast(C2P(origin - sceneOrigin), C2P(direction), shapePhysX->getGeometry(), trans, maxDistance, hitFlags, 1, &hit) != 0)
|
if (PxGeometryQuery::raycast(C2P(origin - sceneOrigin), C2P(direction), shapePhysX->getGeometry(), trans, maxDistance, PxHitFlagEmpty, 1, &hit) != 0)
|
||||||
{
|
{
|
||||||
resultHitDistance = hit.distance;
|
resultHitDistance = hit.distance;
|
||||||
return true;
|
return true;
|
||||||
@@ -2623,9 +2620,8 @@ bool PhysicsBackend::RayCastShape(void* shape, const Vector3& position, const Qu
|
|||||||
auto shapePhysX = (PxShape*)shape;
|
auto shapePhysX = (PxShape*)shape;
|
||||||
const Vector3 sceneOrigin = SceneOrigins[shapePhysX->getActor() ? shapePhysX->getActor()->getScene() : nullptr];
|
const Vector3 sceneOrigin = SceneOrigins[shapePhysX->getActor() ? shapePhysX->getActor()->getScene() : nullptr];
|
||||||
const PxTransform trans(C2P(position - sceneOrigin), C2P(orientation));
|
const PxTransform trans(C2P(position - sceneOrigin), C2P(orientation));
|
||||||
const PxHitFlags hitFlags = PxHitFlag::ePOSITION | PxHitFlag::eNORMAL | PxHitFlag::eFACE_INDEX | PxHitFlag::eUV;
|
|
||||||
PxRaycastHit hit;
|
PxRaycastHit hit;
|
||||||
if (PxGeometryQuery::raycast(C2P(origin - sceneOrigin), C2P(direction), shapePhysX->getGeometry(), trans, maxDistance, hitFlags, 1, &hit) == 0)
|
if (PxGeometryQuery::raycast(C2P(origin - sceneOrigin), C2P(direction), shapePhysX->getGeometry(), trans, maxDistance, SCENE_QUERY_FLAGS, 1, &hit) == 0)
|
||||||
return false;
|
return false;
|
||||||
P2C(hit, hitInfo);
|
P2C(hit, hitInfo);
|
||||||
hitInfo.Point += sceneOrigin;
|
hitInfo.Point += sceneOrigin;
|
||||||
|
|||||||
@@ -38,10 +38,6 @@ void SimulationEventCallback::Clear()
|
|||||||
BrokenJoints.Clear();
|
BrokenJoints.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimulationEventCallback::CollectResults()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void SimulationEventCallback::SendCollisionEvents()
|
void SimulationEventCallback::SendCollisionEvents()
|
||||||
{
|
{
|
||||||
for (auto& c : RemovedCollisions)
|
for (auto& c : RemovedCollisions)
|
||||||
@@ -132,7 +128,6 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c
|
|||||||
//const PxU32 flippedContacts = (pair.flags & PxContactPairFlag::eINTERNAL_CONTACTS_ARE_FLIPPED);
|
//const PxU32 flippedContacts = (pair.flags & PxContactPairFlag::eINTERNAL_CONTACTS_ARE_FLIPPED);
|
||||||
const bool hasImpulses = pair.flags.isSet(PxContactPairFlag::eINTERNAL_HAS_IMPULSES);
|
const bool hasImpulses = pair.flags.isSet(PxContactPairFlag::eINTERNAL_HAS_IMPULSES);
|
||||||
const bool hasPostVelocities = !pair.flags.isSet(PxContactPairFlag::eACTOR_PAIR_LOST_TOUCH);
|
const bool hasPostVelocities = !pair.flags.isSet(PxContactPairFlag::eACTOR_PAIR_LOST_TOUCH);
|
||||||
PxU32 nbContacts = 0;
|
|
||||||
PxVec3 totalImpulse(0.0f);
|
PxVec3 totalImpulse(0.0f);
|
||||||
|
|
||||||
c.ThisActor = static_cast<PhysicsColliderActor*>(pair.shapes[0]->userData);
|
c.ThisActor = static_cast<PhysicsColliderActor*>(pair.shapes[0]->userData);
|
||||||
@@ -144,29 +139,25 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract contact points
|
// Extract contact points
|
||||||
|
c.ContactsCount = 0;
|
||||||
while (i.hasNextPatch())
|
while (i.hasNextPatch())
|
||||||
{
|
{
|
||||||
i.nextPatch();
|
i.nextPatch();
|
||||||
while (i.hasNextContact() && nbContacts < COLLISION_NAX_CONTACT_POINTS)
|
while (i.hasNextContact() && c.ContactsCount < COLLISION_NAX_CONTACT_POINTS)
|
||||||
{
|
{
|
||||||
i.nextContact();
|
i.nextContact();
|
||||||
|
|
||||||
const PxVec3 point = i.getContactPoint();
|
const PxVec3 point = i.getContactPoint();
|
||||||
const PxVec3 normal = i.getContactNormal();
|
const PxVec3 normal = i.getContactNormal();
|
||||||
if (hasImpulses)
|
if (hasImpulses)
|
||||||
totalImpulse += normal * impulses[nbContacts];
|
totalImpulse += normal * impulses[c.ContactsCount];
|
||||||
|
|
||||||
//PxU32 internalFaceIndex0 = flippedContacts ? iter.getFaceIndex1() : iter.getFaceIndex0();
|
ContactPoint& contact = c.Contacts[c.ContactsCount++];
|
||||||
//PxU32 internalFaceIndex1 = flippedContacts ? iter.getFaceIndex0() : iter.getFaceIndex1();
|
|
||||||
|
|
||||||
ContactPoint& contact = c.Contacts[nbContacts];
|
|
||||||
contact.Point = P2C(point);
|
contact.Point = P2C(point);
|
||||||
contact.Normal = P2C(normal);
|
contact.Normal = P2C(normal);
|
||||||
contact.Separation = i.getSeparation();
|
contact.Separation = i.getSeparation();
|
||||||
|
|
||||||
nbContacts++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c.Impulse = P2C(totalImpulse);
|
||||||
|
|
||||||
// Extract velocities
|
// Extract velocities
|
||||||
c.ThisVelocity = c.OtherVelocity = Vector3::Zero;
|
c.ThisVelocity = c.OtherVelocity = Vector3::Zero;
|
||||||
@@ -183,9 +174,6 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.ContactsCount = nbContacts;
|
|
||||||
c.Impulse = P2C(totalImpulse);
|
|
||||||
|
|
||||||
if (pair.flags & PxContactPairFlag::eACTOR_PAIR_HAS_FIRST_TOUCH)
|
if (pair.flags & PxContactPairFlag::eACTOR_PAIR_HAS_FIRST_TOUCH)
|
||||||
{
|
{
|
||||||
NewCollisions.Add(c);
|
NewCollisions.Add(c);
|
||||||
|
|||||||
@@ -49,11 +49,6 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Generates the new/old/removed collisions and a valid trigger pairs.
|
|
||||||
/// </summary>
|
|
||||||
void CollectResults();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sends the collision events to the managed objects.
|
/// Sends the collision events to the managed objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Physical materials are used to define the response of a physical object when interacting dynamically with the world.
|
/// Physical materials are used to define the response of a physical object when interacting dynamically with the world.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
API_CLASS(Attributes = "ContentContextMenu(\"New/Physics/Physical Material\")") class FLAXENGINE_API PhysicalMaterial final : public ISerializable
|
API_CLASS(Attributes = "ContentContextMenu(\"New/Physics/Physical Material\")")
|
||||||
|
class FLAXENGINE_API PhysicalMaterial final : public ISerializable
|
||||||
{
|
{
|
||||||
API_AUTO_SERIALIZATION();
|
API_AUTO_SERIALIZATION();
|
||||||
DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial);
|
DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial);
|
||||||
|
|||||||
@@ -151,17 +151,17 @@ API_STRUCT() struct RayCastHit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD() float Distance;
|
API_FIELD() float Distance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The point in the world space where ray hit the collider.
|
||||||
|
/// </summary>
|
||||||
|
API_FIELD() Vector3 Point;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The index of the face that was hit. Valid only for convex mesh (polygon index), triangle mesh (triangle index) and height field (triangle index).
|
/// The index of the face that was hit. Valid only for convex mesh (polygon index), triangle mesh (triangle index) and height field (triangle index).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="CollisionData.GetModelTriangle" />
|
/// <seealso cref="CollisionData.GetModelTriangle" />
|
||||||
API_FIELD() uint32 FaceIndex;
|
API_FIELD() uint32 FaceIndex;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The point in the world space where ray hit the collider.
|
|
||||||
/// </summary>
|
|
||||||
API_FIELD() Vector3 Point;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The barycentric coordinates of hit triangle. Valid only for triangle mesh and height field.
|
/// The barycentric coordinates of hit triangle. Valid only for triangle mesh and height field.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1431,7 +1431,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
|||||||
Transform srcNode = data.Skeleton.Nodes[nodeIndex].LocalTransform;
|
Transform srcNode = data.Skeleton.Nodes[nodeIndex].LocalTransform;
|
||||||
auto& node = data.Skeleton.Nodes[nodeIndex];
|
auto& node = data.Skeleton.Nodes[nodeIndex];
|
||||||
if (auto* channel = animation.GetChannel(node.Name))
|
if (auto* channel = animation.GetChannel(node.Name))
|
||||||
channel->Evaluate(frame, &srcNode, false);
|
channel->Evaluate((float)frame, &srcNode, false);
|
||||||
pose.Nodes[nodeIndex] = srcNode;
|
pose.Nodes[nodeIndex] = srcNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1439,7 +1439,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
|||||||
key = Float3::Zero;
|
key = Float3::Zero;
|
||||||
for (int32 nodeIndex = 0; nodeIndex < nodes; nodeIndex++)
|
for (int32 nodeIndex = 0; nodeIndex < nodes; nodeIndex++)
|
||||||
key += pose.GetNodeModelTransformation(data.Skeleton, nodeIndex).Translation;
|
key += pose.GetNodeModelTransformation(data.Skeleton, nodeIndex).Translation;
|
||||||
key /= nodes;
|
key /= (float)nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate skeleton center of mass movement over the animation frames
|
// Calculate skeleton center of mass movement over the animation frames
|
||||||
@@ -1448,7 +1448,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
|||||||
for (int32 frame = 0; frame < frames; frame++)
|
for (int32 frame = 0; frame < frames; frame++)
|
||||||
{
|
{
|
||||||
auto& key = rootChannel.Position[frame];
|
auto& key = rootChannel.Position[frame];
|
||||||
key.Time = frame;
|
key.Time = (float)frame;
|
||||||
key.Value = centerOfMass[frame] - centerOfMassRefPose;
|
key.Value = centerOfMass[frame] - centerOfMassRefPose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1494,7 +1494,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& data, Options& option
|
|||||||
Transform srcNode = data.Skeleton.Nodes[nodeIndex].LocalTransform;
|
Transform srcNode = data.Skeleton.Nodes[nodeIndex].LocalTransform;
|
||||||
auto& node = data.Skeleton.Nodes[nodeIndex];
|
auto& node = data.Skeleton.Nodes[nodeIndex];
|
||||||
if (auto* channel = animation.GetChannel(node.Name))
|
if (auto* channel = animation.GetChannel(node.Name))
|
||||||
channel->Evaluate(frame, &srcNode, false);
|
channel->Evaluate((float)frame, &srcNode, false);
|
||||||
pose.Nodes[nodeIndex] = srcNode;
|
pose.Nodes[nodeIndex] = srcNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user