c++unreal-engine4unreal-engine5unreal

Unreal Engine 5 geometry collection particle's world location?


I've built a custom Geometry Collection that needs to get the absolute world location of each of the particles. But so far, I've only got the relative translation of the particle. So in the following code, before the geometry collection has broken apart from the original rest collection, all the particle translations are [0, 0, 0]:

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

    for (int32 i = 0; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
    {
        // This is the translation relative to the original resting location 
        UE::Math::TVector<float> T = GeometryCollectionComponent->GetDynamicCollection()->GetTransform(i).GetTranslation();
    }
}

I think I am on the right track with Particle->GetP() or Particle->GetX(). Also I've noticed that the particle at index 0 has some special behavior.


Solution

  • The answer is Particle->GetX():

    void ACustomGCActor::Tick(float DeltaTime)
    {
        Super::Tick(DeltaTime);
    
        const FGeometryCollectionPhysicsProxy* PhysicsProxy = GeometryCollectionComponent->GetPhysicsProxy();
        // Skip particle 0 which is the root
        for (int32 i = 1; i < GeometryCollectionComponent->GetDynamicCollection()->GetNumTransforms(); ++i)
        {
            if (Chaos::FPBDRigidClusteredParticleHandle* Particle = PhysicsProxy->GetParticle_Internal(i))
            {
                // This is the world location
                Chaos::TVector<double, 3> Location = Particle->GetX();
            }
        }
    }
    

    Also, it was necessary to ignore the particle at index 0; this appears to be the root.