代码之家  ›  专栏  ›  技术社区  ›  Noah Zuo

如何定义UE4中PhysX的世界范围?

  •  0
  • Noah Zuo  · 技术社区  · 7 年前

    我想用 PxBroadPhaseType::eMBP 我的ue4项目。

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

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

    1 回复  |  直到 7 年前
        1
  •  0
  •   GuillaumeGwi    7 年前

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