From 0a5169799f32980e603625c0b60571eaee61f5c6 Mon Sep 17 00:00:00 2001 From: Moddingear Date: Mon, 29 Oct 2018 17:50:55 +0100 Subject: [PATCH 1/5] Added GetSectionAndFaceIndexFromCollisionFaceIndex --- .../Private/RuntimeMesh.cpp | 6 ++++ .../Private/RuntimeMeshData.cpp | 34 +++++++++++++++++++ .../RuntimeMeshComponent/Public/RuntimeMesh.h | 3 ++ .../Public/RuntimeMeshData.h | 2 ++ 4 files changed, 45 insertions(+) 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/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/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 Date: Sat, 3 Nov 2018 18:46:06 +1100 Subject: [PATCH 2/5] 4.20 compat --- .../RuntimeMeshComponent.Build.cs | 53 +++++++------------ .../RuntimeMeshComponentEditor.Build.cs | 52 +++++++----------- 2 files changed, 36 insertions(+), 69 deletions(-) diff --git a/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs b/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs index ec07ad60..b878d575 100644 --- a/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs +++ b/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs @@ -8,49 +8,32 @@ public RuntimeMeshComponent(ReadOnlyTargetRules rules) : base(rules) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponent/Public" - // ... add public include paths required here ... - } - ); - - - PrivateIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponent/Private", - // ... add other private include paths required here ... - } - ); - + if (Target.Version.MinorVersion <= 19) + { + PublicIncludePaths.AddRange( + new string[] { + "RuntimeMeshComponent/Public" + }); + + PrivateIncludePaths.AddRange( + new string[] { + "RuntimeMeshComponent/Private" + }); + } PublicDependencyModuleNames.AddRange( - new string[] - { - "Core", - // ... add other public dependencies that you statically link with here ... - } - ); - + new string[] { + "Core" + }); PrivateDependencyModuleNames.AddRange( - new string[] - { + new string[] { "CoreUObject", "Engine", - // ... add private dependencies that you statically link with here ... + "RenderCore", "ShaderCore", "RHI", - } - ); - - - DynamicallyLoadedModuleNames.AddRange( - new string[] - { - // ... add any modules that your module loads dynamically here ... - } - ); + }); } } diff --git a/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs b/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs index 9d860a9e..ed1b762a 100644 --- a/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs +++ b/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs @@ -8,37 +8,28 @@ public RuntimeMeshComponentEditor(ReadOnlyTargetRules rules) : base(rules) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponentEditor/Public" - // ... add public include paths required here ... - } - ); - - - PrivateIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponentEditor/Private", - // ... add other private include paths required here ... - } - ); - + if (Target.Version.MinorVersion <= 19) + { + PublicIncludePaths.AddRange( + new string[] { + "RuntimeMeshComponentEditor/Public" + }); + + PrivateIncludePaths.AddRange( + new string[] { + "RuntimeMeshComponentEditor/Private" + }); + } PublicDependencyModuleNames.AddRange( - new string[] - { - "Core", - // ... add other public dependencies that you statically link with here ... - - } - ); - + new string[] { + "Core" + }); PrivateDependencyModuleNames.AddRange( - new string[] - { + new string[] { "CoreUObject", - // ... add private dependencies that you statically link with here ... + "Engine", "Slate", "SlateCore", @@ -56,13 +47,6 @@ public RuntimeMeshComponentEditor(ReadOnlyTargetRules rules) : base(rules) "InputCore", "RuntimeMeshComponent", - } - ); - DynamicallyLoadedModuleNames.AddRange( - new string[] - { - // ... add any modules that your module loads dynamically here ... - } - ); + }); } } From d289bc961a9f9a868d3c93772ae865f22e962a99 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 14 Nov 2018 17:55:52 +0100 Subject: [PATCH 3/5] 4.21 compat at least it compiles and starts --- .../RuntimeMeshComponent/Private/RuntimeMeshComponent.cpp | 7 ++++++- Source/RuntimeMeshComponent/Public/RuntimeMeshComponent.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) 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/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(); From d7d5eaaf86a40d6adf4ff114139e99dbdaa37c57 Mon Sep 17 00:00:00 2001 From: Moddingear Date: Fri, 7 Dec 2018 16:51:24 +0100 Subject: [PATCH 4/5] Delete RuntimeMeshComponent.Build.cs --- .../RuntimeMeshComponent.Build.cs | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs diff --git a/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs b/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs deleted file mode 100644 index b878d575..00000000 --- a/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved. - -using UnrealBuildTool; - -public class RuntimeMeshComponent : ModuleRules -{ - public RuntimeMeshComponent(ReadOnlyTargetRules rules) : base(rules) - { - PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - - if (Target.Version.MinorVersion <= 19) - { - PublicIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponent/Public" - }); - - PrivateIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponent/Private" - }); - } - - PublicDependencyModuleNames.AddRange( - new string[] { - "Core" - }); - - PrivateDependencyModuleNames.AddRange( - new string[] { - "CoreUObject", - "Engine", - - "RenderCore", - "ShaderCore", - "RHI", - }); - } -} From 8a1be34ecd6be39c9d9cfa52e28cad896fd5dd64 Mon Sep 17 00:00:00 2001 From: Moddingear Date: Fri, 7 Dec 2018 16:57:08 +0100 Subject: [PATCH 5/5] Merged fixes from MJLaukala --- .../RuntimeMeshComponent.Build.cs | 45 +++++++++++++++++++ .../RuntimeMeshComponentEditor.Build.cs | 41 +++++++++-------- 2 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs diff --git a/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs b/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs new file mode 100644 index 00000000..3589a2fa --- /dev/null +++ b/Source/RuntimeMeshComponent/RuntimeMeshComponent.Build.cs @@ -0,0 +1,45 @@ +// Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved. + +using System.IO; +using UnrealBuildTool; + +public class RuntimeMeshComponent : ModuleRules +{ + public RuntimeMeshComponent(ReadOnlyTargetRules rules) : base(rules) + { + PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); + PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); + + + PublicDependencyModuleNames.AddRange( + new string[] + { + "Core", + // ... add other public dependencies that you statically link with here ... + } + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CoreUObject", + "Engine", + // ... add private dependencies that you statically link with here ... + "RenderCore", + "ShaderCore", + "RHI", + } + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + // ... add any modules that your module loads dynamically here ... + } + ); + } +} \ No newline at end of file diff --git a/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs b/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs index ed1b762a..8e9e702a 100644 --- a/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs +++ b/Source/RuntimeMeshComponentEditor/RuntimeMeshComponentEditor.Build.cs @@ -1,5 +1,6 @@ // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved. +using System.IO; using UnrealBuildTool; public class RuntimeMeshComponentEditor : ModuleRules @@ -8,28 +9,25 @@ public RuntimeMeshComponentEditor(ReadOnlyTargetRules rules) : base(rules) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - if (Target.Version.MinorVersion <= 19) - { - PublicIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponentEditor/Public" - }); + PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public")); + PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private")); - PrivateIncludePaths.AddRange( - new string[] { - "RuntimeMeshComponentEditor/Private" - }); - } PublicDependencyModuleNames.AddRange( - new string[] { - "Core" - }); + new string[] + { + "Core", + // ... add other public dependencies that you statically link with here ... + + } + ); + PrivateDependencyModuleNames.AddRange( - new string[] { + new string[] + { "CoreUObject", - + // ... add private dependencies that you statically link with here ... "Engine", "Slate", "SlateCore", @@ -47,6 +45,13 @@ public RuntimeMeshComponentEditor(ReadOnlyTargetRules rules) : base(rules) "InputCore", "RuntimeMeshComponent", - }); + } + ); + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + // ... add any modules that your module loads dynamically here ... + } + ); } -} +} \ No newline at end of file