如何在UE4中为PhysX定义世界界限?

时间:2018-08-29 07:06:42

标签: physx

我正在为我的ue4项目使用PxBroadPhaseType::eMBP alogrithm。

如文档所述:

  

PxBroadPhaseType :: eMBP是PhysX 3.3中引入的新算法。它是一种替代性的广相算法,当所有对象都移动或插入大量对象时,不会遇到与eSAP相同的性能问题。但是,当许多对象处于休眠状态时,它的通用性能可能不如eSAP,并且它要求用户定义世界范围才能工作。

但是我在哪里可以定义世界范围?我在PxSceneDesc或PxScene中找不到这样的变量。

1 个答案:

答案 0 :(得分:0)

本文紧随其后: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);
    }
}