【问题标题】:How to Define World Bound for PhysX in UE4?如何在 UE4 中为 PhysX 定义 World Bound?
【发布时间】:2023-03-27 13:07:01
【问题描述】:

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

如文件所述:

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

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

【问题讨论】:

    标签: physx


    【解决方案1】:

    在这篇文章之后: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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 2014-10-10
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      相关资源
      最近更新 更多