Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/physx 4.0 #258

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
15 changes: 15 additions & 0 deletions CMakeFiles/3.13.2/CMakeSystem.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(CMAKE_HOST_SYSTEM "Windows-10.0.17134")
set(CMAKE_HOST_SYSTEM_NAME "Windows")
set(CMAKE_HOST_SYSTEM_VERSION "10.0.17134")
set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64")



set(CMAKE_SYSTEM "Windows-10.0.17134")
set(CMAKE_SYSTEM_NAME "Windows")
set(CMAKE_SYSTEM_VERSION "10.0.17134")
set(CMAKE_SYSTEM_PROCESSOR "AMD64")

set(CMAKE_CROSSCOMPILING "FALSE")

set(CMAKE_SYSTEM_LOADED 1)
28 changes: 28 additions & 0 deletions CMakeFiles/3.13.2/VCTargetsPath.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{F3FC6D86-508D-3FB1-96D2-995F08B142EC}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<Platform>x64</Platform>
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props"/>
<PropertyGroup Label="Configuration">
<ConfigurationType>Utility</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props"/>
<ItemDefinitionGroup>
<PostBuildEvent>
<Command>echo VCTargetsPath=$(VCTargetsPath)</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets"/>
</Project>
1 change: 1 addition & 0 deletions CMakeFiles/CMakeOutput.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The system is: Windows - 10.0.17134 - AMD64
26 changes: 13 additions & 13 deletions Source/CMake/Modules/FindPhysX.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ gen_default_lib_search_dirs(PhysX)

if(NOT APPLE)
if(BS_64BIT)
set(BS_PHYSX_SUFFIX _x64)
set(BS_PHYSX_SUFFIX _64)
else()
set(BS_PHYSX_SUFFIX _x86)
set(BS_PHYSX_SUFFIX _86)
endif()
endif()

find_imported_includes(PhysX PxPhysics.h)
if(NOT APPLE)
find_imported_library_shared2(PhysX PhysX3${BS_PHYSX_SUFFIX} PhysX3CHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysX3Common${BS_PHYSX_SUFFIX} PhysX3CommonCHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysX3Cooking${BS_PHYSX_SUFFIX} PhysX3CookingCHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysX3CharacterKinematic${BS_PHYSX_SUFFIX} PhysX3CharacterKinematicCHECKED${BS_PHYSX_SUFFIX})
find_imported_library2(PhysX PhysX3Extensions PhysX3ExtensionsCHECKED)
find_imported_library_shared2(PhysX PhysX${BS_PHYSX_SUFFIX} PhysXCHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysXCommon${BS_PHYSX_SUFFIX} PhysXCommonCHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysXCooking${BS_PHYSX_SUFFIX} PhysXCookingCHECKED${BS_PHYSX_SUFFIX})
find_imported_library_shared2(PhysX PhysXCharacterKinematic_static${BS_PHYSX_SUFFIX} PhysXCharacterKinematicCHECKED_static${BS_PHYSX_SUFFIX})
find_imported_library2(PhysX PhysXExtensions_static${BS_PHYSX_SUFFIX} PhysXExtensionsCHECKED_static${BS_PHYSX_SUFFIX})
else()
find_imported_library(PhysX LowLevel)
find_imported_library(PhysX LowLevelCloth)
find_imported_library(PhysX PhysX3)
find_imported_library(PhysX PhysX3Common)
find_imported_library(PhysX PhysX3Cooking)
find_imported_library(PhysX PhysX3CharacterKinematic)
find_imported_library(PhysX PhysX3Extensions)
find_imported_library(PhysX PhysX)
find_imported_library(PhysX PhysXCommon)
find_imported_library(PhysX PhysXCooking)
find_imported_library(PhysX PhysXCharacterKinematic)
find_imported_library(PhysX PhysXExtensions)
find_imported_library(PhysX PhysXProfileSDK)
find_imported_library(PhysX PvdRuntime)
find_imported_library(PhysX PxTask)
Expand All @@ -43,4 +43,4 @@ endif()

install_dependency_binaries(PhysX)

end_find_package(PhysX PhysX3${BS_PHYSX_SUFFIX})
end_find_package(PhysX PhysX${BS_PHYSX_SUFFIX})
36 changes: 21 additions & 15 deletions Source/Plugins/bsfPhysX/BsPhysX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ namespace bs
{
void onWake(PxActor** actors, PxU32 count) override { /* Do nothing */ }
void onSleep(PxActor** actors, PxU32 count) override { /* Do nothing */ }
void onAdvance(const PxRigidBody *const *bodyBuffer, const PxTransform *poseBuffer, const PxU32 count) override { /* Do nothing */ }

void onTrigger(PxTriggerPair* pairs, PxU32 count) override
{
Expand Down Expand Up @@ -191,6 +192,9 @@ namespace bs

void onContact(const PxContactPairHeader& pairHeader, const PxContactPair* pairs, PxU32 count) override
{
const PxU32 bufferSize = 64;
PxContactPairPoint contacts[bufferSize];

for (PxU32 i = 0; i < count; i++)
{
const PxContactPair& pair = pairs[i];
Expand Down Expand Up @@ -220,17 +224,19 @@ namespace bs
event.type = type;

PxU32 contactCount = pair.contactCount;
const PxU8* stream = pair.contactStream;
//const PxU8* stream = pair.contactStream;
const PxU32 stream = pair.extractContacts(contacts, bufferSize);
PxU16 streamSize = pair.contactStreamSize;

if (contactCount > 0 && streamSize > 0)
{
PxU32 contactIdx = 0;
PxContactStreamIterator iter((PxU8*)stream, streamSize);
PxContactStreamIterator iter(pair.contactPatches,pair.contactPoints, pair.getInternalFaceIndices(), pair.patchCount, pair.contactCount);

stream += ((streamSize + 15) & ~15);
//stream += ((streamSize + 15) & ~15);

const PxReal* impulses = reinterpret_cast<const PxReal*>(stream);
const PxReal* impulses = pair.contactImpulses;
PxU32 flippedContacts = (pair.flags & PxContactPairFlag::eINTERNAL_CONTACTS_ARE_FLIPPED);
PxU32 hasImpulses = (pair.flags & PxContactPairFlag::eINTERNAL_HAS_IMPULSES);

while (iter.hasNextPatch())
Expand All @@ -240,15 +246,14 @@ namespace bs
{
iter.nextContact();

PxVec3 pointIter = iter.getContactPoint();

ContactPoint point;
point.position = fromPxVector(iter.getContactPoint());
point.separation = iter.getSeparation();
point.normal = fromPxVector(iter.getContactNormal());

if (hasImpulses)
point.impulse = impulses[contactIdx];
else
point.impulse = 0.0f;
point.impulse = hasImpulses ? impulses[contactIdx] : 0.0f;

event.points.push_back(point);

Expand Down Expand Up @@ -491,7 +496,7 @@ namespace bs
sceneDesc.broadPhaseCallback = &gPhysXBroadphaseCallback;

// Optionally: eENABLE_KINEMATIC_STATIC_PAIRS, eENABLE_KINEMATIC_PAIRS, eENABLE_PCM
sceneDesc.flags = PxSceneFlag::eENABLE_ACTIVETRANSFORMS;
sceneDesc.flags = PxSceneFlag::eENABLE_ACTIVE_ACTORS;

if (input.flags.isSet(PhysicsFlag::CCD_Enable))
sceneDesc.flags |= PxSceneFlag::eENABLE_CCD;
Expand Down Expand Up @@ -542,19 +547,20 @@ namespace bs

// Update rigidbodies with new transforms
PxU32 numActiveTransforms;
const PxActiveTransform* activeTransforms = mScene->getActiveTransforms(numActiveTransforms);
PxActor** activeActors = mScene->getActiveActors(numActiveTransforms);

for (PxU32 i = 0; i < numActiveTransforms; i++)
{
Rigidbody* rigidbody = static_cast<Rigidbody*>(activeTransforms[i].userData);
Rigidbody* rigidbody = static_cast<Rigidbody*>(activeActors[i]->userData);

// Note: This should never happen, as actors gets their userData set to null when they're destroyed. However
// in some cases PhysX seems to keep those actors alive for a frame or few, and reports their state here. Until
// I find out why I need to perform this check.
if(activeTransforms[i].actor->userData == nullptr)
if(activeActors[i]->userData == nullptr)
continue;

const PxTransform& transform = activeTransforms[i].actor2World;
//const PxTransform& transform = activeActors[i]->getGlobalPose();
const PxTransform& transform = (PxTransform&)activeActors[i]->userData;

// Note: Make this faster, avoid dereferencing Rigidbody and attempt to access pos/rot destination directly,
// use non-temporal writes
Expand Down Expand Up @@ -1059,10 +1065,10 @@ namespace bs
PxRaycastHit hitInfo;
PxU32 maxHits = 1;
bool anyHit = false;
PxHitFlags hitFlags = PxHitFlag::eDEFAULT | PxHitFlag::eUV;
PxHitFlags hitFlags = PxHitFlag::eDEFAULT | PxHitFlag::eUV | PxHitFlag::eMESH_ANY;
PxU32 hitCount = PxGeometryQuery::raycast(toPxVector(origin), toPxVector(unitDir),
shape->getGeometry().any(), transform,
maxDist, hitFlags, maxHits, &hitInfo, anyHit);
maxDist, hitFlags, maxHits, &hitInfo);

if(hitCount > 0)
parseHit(hitInfo, hit);
Expand Down
6 changes: 3 additions & 3 deletions Source/Plugins/bsfPhysX/BsPhysXCharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ namespace bs
bool canCollide = gPhysics().isCollisionEnabled(colliderLayer, getLayer());

if(canCollide)
return PxSceneQueryHitType::eBLOCK;
return PxQueryHitType::eBLOCK;

return PxSceneQueryHitType::eNONE;
return PxQueryHitType::eNONE;
}

PxQueryHitType::Enum PhysXCharacterController::postFilter(const PxFilterData& filterData,
const PxQueryHit& hit)
{
return PxSceneQueryHitType::eBLOCK;
return PxQueryHitType::eBLOCK;
}

bool PhysXCharacterController::filter(const PxController& a, const PxController& b)
Expand Down
4 changes: 2 additions & 2 deletions Source/Plugins/bsfPhysX/BsPhysXMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace bs
}

// Try inflating the convex mesh
convexDesc.flags |= PxConvexFlag::eINFLATE_CONVEX;
//convexDesc.flags |= PxConvexFlag::eINFLATE_CONVEX; // TODO: Add this back once issue is solved
if (cooking->cookConvexMesh(convexDesc, output))
{
size = output.getSize();
Expand Down Expand Up @@ -78,7 +78,7 @@ namespace bs
convexDesc.points.count = 8;
convexDesc.points.stride = sizeof(Vector3);
convexDesc.points.data = &aabbVerts[0];
convexDesc.flags &= ~PxConvexFlag::eINFLATE_CONVEX;
//convexDesc.flags &= ~PxConvexFlag::eINFLATE_CONVEX; // TODO: Add this back once issue is solved

if (cooking->cookConvexMesh(convexDesc, output))
{
Expand Down