TriAxis-Games / RealtimeMeshComponent

Unreal Engine 5 plugin component for rendering runtime generated content.
https://rmc.triaxis.games/
Other
1.58k stars 412 forks source link

v4 Activating complex collision and bDeformable #171

Closed rehven closed 4 years ago

rehven commented 4 years ago

(Apologies for my markdown mess)

Two questions.

  1. I'm struggling to activate complex collision.

`URuntimeMeshProviderStaticMesh* MeshProvider = NewObject(this, TEXT("RuntimeMeshProvider-StaticMesh")); MeshProvider->StaticMesh = VisualMesh->GetStaticMesh(); MeshProvider->ComplexCollisionLOD = 0; MeshProvider->MaxLOD = 0;

    URuntimeMeshProviderCollisionFromRenderable* CollisionProvider = NewObject<URuntimeMeshProviderCollisionFromRenderable>(this, TEXT("RuntimeMeshProvider-Collision"));
    if (MeshProvider && CollisionProvider)
    {
        CollisionProvider->SourceProvider = MeshProvider;
        CollisionProvider->SetRenderableLODForCollision(MeshProvider->MaxLOD);

        for (int i = 0; i < MeshProvider->StaticMesh->GetNumSections(MeshProvider->MaxLOD); i++)
            CollisionProvider->SetRenderableSectionAffectsCollision(i, true);

        FRuntimeMeshCollisionSettings CollisionSettings;
        CollisionSettings.bUseComplexAsSimple = true;
        CollisionSettings.bUseAsyncCooking = true;
        CollisionSettings.CookingMode = ERuntimeMeshCollisionCookingMode::CollisionPerformance;
        CollisionProvider->SetCollisionSettings(CollisionSettings);
        RuntimeMesh->Initialize(CollisionProvider);

        FRuntimeMeshCollisionData CollisionData;
        RuntimeMesh->GetCurrentProviderProxy()->GetCollisionMesh(CollisionData);
        CollisionData.bDeformableMesh = true;
        CollisionData.bFastCook = true;
    }`

The staticmesh has complex collision and it shows in the editor. But when I play, I don't see any collision on the runtime mesh. What am I missing?

  1. I've marked the runtime mesh as bDeformable, because I want to manipulate it per-frame. I do all vertex manipulation in a separate place; in v3, I would use SetPosition via FRuntimeMeshBuilder to update the runtime mesh. Now that v4 allows for complex collision, should I update the mesh vertices and the collision vertices, or update only the mesh vertices then do: RuntimeMesh->GetCurrentProviderProxy()->MarkSectionDirty(0, i); RuntimeMesh->GetCurrentProviderProxy()->MarkCollisionDirty();
Moddingear commented 4 years ago

You should probably import it directly into the RMC instead of using the RMCProviderStaticMesh, afaik this is only meant to display static meshes with the RMC engine. Also you can't modify the collision mesh this way. Sidenote, v3 did also allow for complex collision.

rehven commented 4 years ago

Thanks for the advice. I've been looking through the example project yet I'm failing to fully understand the pipeline; can you point me in a general direction?

As for v3 and complex collision: I'm using RMC for a softbody simulation, combined with Oculus Rift to manually manipulate the softbody. I tried to enable complex collision but I could never get it to update whenever the mesh changed. I though v3 could only do simple collision shapes?

Koderz commented 4 years ago

For this you should probably use the static provider (this is separate from static mesh provider), there's functions to convert an RMC over. The collision from renderable provider isn't meant for that, and the staticmesh provider already implements collision. There have been some bug fixes in collisionfromrenderable though.

If you need further assistance with this, it would be best to join the Discord server as I and others can help much more quickly there!