如何在 UE4 中为 PhysX 定义 World Bound?
How to Define World Bound for PhysX in UE4?
我正在尝试对我的 ue4 项目使用 PxBroadPhaseType::eMBP
算法。
如文件所述:
PxBroadPhaseType::eMBP is a new algorithm introduced in PhysX 3.3. It is an alternative broad-phase algorithm that does not suffer from the same performance issues as eSAP when all objects are moving or when inserting large numbers of objects. However its generic performance when many objects are sleeping might be inferior to eSAP, and it requires users to define world bounds in order to work.
但是我在哪里可以定义世界边界呢?我在 PxSceneDesc 或 PxScene 中找不到这样的变量。
关注这篇文章:https://wessamfathi.com/2018/04/17/the-case-of-million-collision-bodies/ 在我看来,您需要定义 PxBroadPhaseRegion 并将它们添加到您的场景中。
if (UPhysicsSettings::Get()->bEnableMBPForBroadphase)
{
PSceneDesc.broadPhaseType = PxBroadPhaseType::eMBP;
}
bool bIsValid = PSceneDesc.isValid();
if (!bIsValid)
{
UE_LOG(LogPhysics, Log, TEXT("Invalid PSceneDesc"));
}
// Create scene, and add to map
PxScene* PScene = GPhysXSDK->createScene(PSceneDesc);
if (UPhysicsSettings::Get()->bEnableMBPForBroadphase && PScene->getBroadPhaseType())
{
TArray<PxBounds3> Regions;
const uint32 SubDivs = UPhysicsSettings::Get()->MBPRegionSubdiv;
Regions.SetNumUninitialized(SubDivs * SubDivs);
const PxBounds3 LevelBounds = PxBounds3::centerExtents(PxVec3(PxZero), U2PVector(UPhysicsSettings::Get()->MBPWorldBounds));
PxU32 Num = PxBroadPhaseExt::createRegionsFromWorldBounds(Regions.GetData(), LevelBounds, SubDivs, 2);
check(Num == SubDivs * SubDivs);
for (const PxBounds3& Bounds : Regions)
{
PxBroadPhaseRegion Region;
Region.bounds = Bounds;
Region.userData = nullptr;
PScene->addBroadPhaseRegion(Region);
}
}
我正在尝试对我的 ue4 项目使用 PxBroadPhaseType::eMBP
算法。
如文件所述:
PxBroadPhaseType::eMBP is a new algorithm introduced in PhysX 3.3. It is an alternative broad-phase algorithm that does not suffer from the same performance issues as eSAP when all objects are moving or when inserting large numbers of objects. However its generic performance when many objects are sleeping might be inferior to eSAP, and it requires users to define world bounds in order to work.
但是我在哪里可以定义世界边界呢?我在 PxSceneDesc 或 PxScene 中找不到这样的变量。
关注这篇文章:https://wessamfathi.com/2018/04/17/the-case-of-million-collision-bodies/ 在我看来,您需要定义 PxBroadPhaseRegion 并将它们添加到您的场景中。
if (UPhysicsSettings::Get()->bEnableMBPForBroadphase)
{
PSceneDesc.broadPhaseType = PxBroadPhaseType::eMBP;
}
bool bIsValid = PSceneDesc.isValid();
if (!bIsValid)
{
UE_LOG(LogPhysics, Log, TEXT("Invalid PSceneDesc"));
}
// Create scene, and add to map
PxScene* PScene = GPhysXSDK->createScene(PSceneDesc);
if (UPhysicsSettings::Get()->bEnableMBPForBroadphase && PScene->getBroadPhaseType())
{
TArray<PxBounds3> Regions;
const uint32 SubDivs = UPhysicsSettings::Get()->MBPRegionSubdiv;
Regions.SetNumUninitialized(SubDivs * SubDivs);
const PxBounds3 LevelBounds = PxBounds3::centerExtents(PxVec3(PxZero), U2PVector(UPhysicsSettings::Get()->MBPWorldBounds));
PxU32 Num = PxBroadPhaseExt::createRegionsFromWorldBounds(Regions.GetData(), LevelBounds, SubDivs, 2);
check(Num == SubDivs * SubDivs);
for (const PxBounds3& Bounds : Regions)
{
PxBroadPhaseRegion Region;
Region.bounds = Bounds;
Region.userData = nullptr;
PScene->addBroadPhaseRegion(Region);
}
}