0

我正在尝试PxBroadPhaseType::eMBP为我的 ue4 项目使用算法。

如文件所述:

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

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

4

1 回答 1

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);
    }
}
于 2018-11-21T18:31:45.533 回答