几何集合获取每个骨量和速度

问题描述 投票:0回答:1

使用虚幻引擎 5.4.3,我实现了自定义

AGeometryCollectionActor
。我想获取该集合中每个骨骼的质量和速度。以下是我正在尝试做的事情的玩具版本。

自定义几何集合.cpp

#include "GeometryCollection/GeometryCollectionComponent.h"
#include "Runtime/Experimental/Chaos/Private/Chaos/PhysicsObjectInternal.h"

void ACustomGeometryCollection::Tick(float DeltaSeconds)
{
    Super::Tick(DeltaSeconds);

    for (int32 i = 0; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
    {
        // I haven't figured out how to get from any of these to the mass and linear/angular velocity
        Chaos::FPhysicsObject* PhysicsObject = GeometryCollectionComponent->GetPhysicsObjectById(i);
        Chaos::FPBDRigidClusteredParticleHandle* Particle = PhysicsProxy->GetParticle_Internal(i);

        // This gets me the position but doesn't seem to pertain to mass or velocity
        FTransform3f Transform = GeometryCollectionComponent->GetDynamicCollection()->GetTransform(i);
    }
}

此外,我还在

.Build.cs 文件中的依赖模块名称中添加了 "GeometryCollectionEngine"

c++ game-physics unreal-engine5 physics-engine
1个回答
2
投票

这是我的解决方案:

自定义几何集合.cpp

#include "GeometryCollection/GeometryCollectionComponent.h"
#include "Runtime/Experimental/Chaos/Private/Chaos/PhysicsObjectInternal.h"

void ACustomGCActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    FGeometryCollectionPhysicsProxy* PhysicsProxy = GeometryCollectionComponent->GetPhysicsProxy();
    for (int32 i = FirstRealParticleIndex; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
    {
        if (Chaos::FPBDRigidClusteredParticleHandle* Particle = PhysicsProxy->GetParticle_Internal(i))
        {
            const FVector_NetQuantize10 LinearVelocity = Particle->GetV();
            const float Mass = Particle->M();
        }
    }
}

另请参阅:如何计算

FirstRealParticleIndex
如何区分真实粒子和簇(并忽略簇并集粒子)

不要忘记将

"GeometryCollectionEngine"
添加到 .Build.cs 文件中的依赖模块名称中。

© www.soinside.com 2019 - 2024. All rights reserved.