使用虚幻引擎 5.4.3,我实现了自定义
AGeometryCollectionActor
。我想获得该集合中每个骨骼的质量和速度。以下是我正在尝试做的事情的玩具版本。
#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"
这是我的解决方案:
#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 = 0; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
{
if (Chaos::FPBDRigidClusteredParticleHandle* Particle = PhysicsProxy->GetParticle_Internal(i))
{
const FVector_NetQuantize10 LinearVelocity = Particle->GetV();
const float Mass = Particle->M();
}
}
}
此外,我还在
.Build.cs 文件中的依赖模块名称中添加了"GeometryCollectionEngine"