diff --git a/Source/RuntimeMeshComponent/Private/RuntimeMesh.cpp b/Source/RuntimeMeshComponent/Private/RuntimeMesh.cpp index e9d6ee92..8f180a08 100644 --- a/Source/RuntimeMeshComponent/Private/RuntimeMesh.cpp +++ b/Source/RuntimeMeshComponent/Private/RuntimeMesh.cpp @@ -147,6 +147,12 @@ int32 URuntimeMesh::GetSectionIdFromCollisionFaceIndex(int32 FaceIndex) const return GetRuntimeMeshData()->GetSectionFromCollisionFaceIndex(FaceIndex); } +void URuntimeMesh::GetSectionIdAndFaceIndexFromCollisionFaceIndex(int32 FaceIndex, int32 & SectionIndex, int32 & SectionFaceIndex) const +{ + SectionFaceIndex = FaceIndex; + SectionIndex = GetRuntimeMeshData()->GetSectionAndFaceIndexFromCollisionFaceIndex(SectionFaceIndex); +} + void URuntimeMesh::MarkCollisionDirty() { // Flag the collision as dirty diff --git a/Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp b/Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp index f0226f07..57751807 100644 --- a/Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp +++ b/Source/RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp @@ -239,7 +239,7 @@ void URuntimeMeshComponent::PostLoad() } -#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 21 +#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 22 bool URuntimeMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) { @@ -252,6 +252,7 @@ bool URuntimeMeshComponent::GetPhysicsTriMeshData(struct FTriMeshCollisionData* return false; } + bool URuntimeMeshComponent::ContainsPhysicsTriMeshData(bool InUseAllTriData) const { URuntimeMesh* RuntimeMesh = GetRuntimeMesh(); @@ -262,6 +263,10 @@ bool URuntimeMeshComponent::ContainsPhysicsTriMeshData(bool InUseAllTriData) con return false; } +#endif + +#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 21 + UBodySetup* URuntimeMeshComponent::CreateNewBodySetup() { UBodySetup* NewBodySetup = NewObject(this, NAME_None, (IsTemplate() ? RF_Public : RF_NoFlags)); diff --git a/Source/RuntimeMeshComponent/Private/RuntimeMeshData.cpp b/Source/RuntimeMeshComponent/Private/RuntimeMeshData.cpp index 137052bd..c75d719c 100644 --- a/Source/RuntimeMeshComponent/Private/RuntimeMeshData.cpp +++ b/Source/RuntimeMeshComponent/Private/RuntimeMeshData.cpp @@ -1479,6 +1479,40 @@ int32 FRuntimeMeshData::GetSectionFromCollisionFaceIndex(int32 FaceIndex) const return SectionIndex; } +/* +* Gets the section ID from the given face index reference, +* The face index reference then gets set to it's face index in the section. +*/ +int32 FRuntimeMeshData::GetSectionAndFaceIndexFromCollisionFaceIndex(int32& FaceIndex) const +{ + SCOPE_CYCLE_COUNTER(STAT_RuntimeMesh_GetSectionFromCollisionFaceIndex); + + FRuntimeMeshScopeLock Lock(SyncRoot); + + int32 SectionIndex = 0; + + // Look for element that corresponds to the supplied face + int32 TotalFaceCount = 0; + + for (int32 SectionIdx = 0; SectionIdx < MeshSections.Num(); SectionIdx++) + { + const FRuntimeMeshSectionPtr& Section = MeshSections[SectionIdx]; + + if (Section.IsValid() && Section->IsCollisionEnabled()) + { + int32 NumFaces = Section->GetNumIndices() / 3; + + if (FaceIndex < TotalFaceCount + NumFaces) + { + // Grab the material + FaceIndex -= TotalFaceCount; + return SectionIdx; + } + TotalFaceCount += NumFaces; + } + } + return -1; +} class FRuntimeMeshGameThreadTask { diff --git a/Source/RuntimeMeshComponent/Public/RuntimeMesh.h b/Source/RuntimeMeshComponent/Public/RuntimeMesh.h index 7ff0fc41..ae05a6ca 100644 --- a/Source/RuntimeMeshComponent/Public/RuntimeMesh.h +++ b/Source/RuntimeMeshComponent/Public/RuntimeMesh.h @@ -905,6 +905,9 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMesh : public UObject, public IInterface_ UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh") int32 GetSectionIdFromCollisionFaceIndex(int32 FaceIndex) const; + UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh") + void GetSectionIdAndFaceIndexFromCollisionFaceIndex(int32 FaceIndex, int32& SectionIndex, int32& SectionFaceIndex) const; + private: /** Triggers a rebuild of the collision data on the next tick */ diff --git a/Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h b/Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h index 69d754d1..006adfd7 100644 --- a/Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h +++ b/Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h @@ -807,10 +807,12 @@ class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, pu TArray AsyncBodySetupQueue; //~ Begin Interface_CollisionDataProvider Interface +#if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 22 virtual bool GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) override; virtual bool ContainsPhysicsTriMeshData(bool InUseAllTriData) const override; virtual bool WantsNegXTriMesh() override { return false; } //~ End Interface_CollisionDataProvider Interface +#endif #if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 21 UBodySetup* CreateNewBodySetup(); diff --git a/Source/RuntimeMeshComponent/Public/RuntimeMeshData.h b/Source/RuntimeMeshComponent/Public/RuntimeMeshData.h index a6fa2c10..52e03cbf 100644 --- a/Source/RuntimeMeshComponent/Public/RuntimeMeshData.h +++ b/Source/RuntimeMeshComponent/Public/RuntimeMeshData.h @@ -1100,6 +1100,8 @@ class RUNTIMEMESHCOMPONENT_API FRuntimeMeshData : public TSharedFromThis