UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MRMeshComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// MR stands for Mixed Reality, but this component could possibly have more general use.
4// It was specifically designed to support the case for Augmented Reality world mesh detection. Where a device scans the real world and provides a mesh representing the geometry
5// of the real world environment. This mesh is expected to arrive in chunks called 'bricks' over time and for bricks to be added, removed, or updated.
6// We provide the ability to render the mesh, to generate collision from it, and to generate ai navigation data on that collision.
7// We do not intend to support using the MRMesh as a physics body that could be moved.
8// It is somewhat similar to ProceduralMeshComponent.
9
10#pragma once
11
12#include "CoreMinimal.h"
15#include "PackedNormal.h"
16#include "MRMeshBufferDefines.h"
17
18#include "MRMeshComponent.generated.h"
19
20class UMaterial;
24
27
29{
30public:
32 {
33 // Optionally subclass and use receipt. For example: to release the buffers FSendBrickDataArgs has references to.
34 virtual ~FBrickDataReceipt() {}
35 };
36
39 {
40 // Note: many members are references! Be aware of the lifetime of the underlying data. FBrickDataReceipt is intended to help manage that.
42 const FBrickId BrickId = 0;
49 };
50
51 virtual void SetConnected(bool value) = 0;
52 virtual bool IsConnected() const = 0;
53
54 virtual void SendRelativeTransform(const FTransform& Transform) = 0;
55 virtual void SendBrickData(FSendBrickDataArgs Args) = 0;
56 virtual void Clear() = 0;
57 virtual void ClearAllBrickData() = 0;
58};
59
60// Because physics cooking uses GetOuter() to get the IInterface_CollisionDataProvider and provides no way to determine which physics body it
61// is currently working on we are wrapping each body in this Holder so that it can be the Outer and provide the correct data.
64{
65public:
67
69 void Update(const IMRMesh::FSendBrickDataArgs& Args);
70 void AbortCook();
71 void ReleaseArgData();
72 void Cleanup();
73
74 //~ Begin Interface_CollisionDataProvider Interface
75 virtual bool GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) override;
76 virtual bool GetTriMeshSizeEstimates(struct FTriMeshCollisionDataEstimates& OutTriMeshEstimates, bool bInUseAllTriData) const override;
77 virtual bool ContainsPhysicsTriMeshData(bool InUseAllTriData) const override;
78 virtual bool WantsNegXTriMesh() override { return false; }
79 //~ End Interface_CollisionDataProvider Interface
80
82 void FinishPhysicsAsyncCook(bool bSuccess, UBodySetup* FinishedBodySetup);
83
86
88 FBodyInstance BodyInstance;
89
90 // Hold references to the bulk data which is owned externally, like FSendBrickDataArgs. The receipt keeps the references valid.
91 TSharedPtr<IMRMesh::FBrickDataReceipt, ESPMode::ThreadSafe> BrickDataReceipt;
92 IMRMesh::FBrickId BrickId = 0;
93 const TArray<FVector3f>* PositionData = nullptr;
94 const TArray<MRMESH_INDEX_TYPE>* Indices = nullptr;
96
97 bool bCookInProgress = false;
98};
99
100
101
102DECLARE_MULTICAST_DELEGATE_TwoParams(FOnMRMeshBrickDataUpdatedDelegate, const UMRMeshComponent*, const IMRMesh::FSendBrickDataArgs&);
103
104UCLASS(hideCategories=(Physics), meta = (BlueprintSpawnableComponent), ClassGroup = Rendering, MinimalAPI)
105class UMRMeshComponent : public UPrimitiveComponent, public IMRMesh
106{
107public:
108 friend class FMRMeshProxy;
109
111
112 MRMESH_API virtual void BeginPlay() override;
113 MRMESH_API void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
114
115 UFUNCTION(BlueprintPure, Category = "Mesh Reconstruction")
116 bool IsConnected() const override { return bConnected; }
117
118 void SetConnected(bool value) override { bConnected = value; }
119 virtual void SendRelativeTransform(const FTransform& Transform) override { SetRelativeTransform(Transform); }
120
124 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
126
130 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
132
133 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
134 MRMESH_API void Clear() override;
135
136 // UPrimitiveComponent.. public BP function needs to stay public to avoid nativization errors. (RR)
137 MRMESH_API virtual void SetMaterial(int32 ElementIndex, class UMaterialInterface* InMaterial) override;
138 MRMESH_API virtual class UMaterialInterface* GetMaterial(int32 ElementIndex) const override;
139
140 // Set the wireframe material.
141 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
143
145 MRMESH_API void UpdateMesh(const FVector& InLocation, const FQuat& InRotation, const FVector& Scale, TArray<FVector>& Vertices, TArray<MRMESH_INDEX_TYPE>& Indices, TArray<FVector2D> UVData = {}, TArray<FPackedNormal> TangentXZData = {}, TArray<FColor> ColorData = {});
146 MRMESH_API void UpdateMesh(const FVector& InLocation, const FQuat& InRotation, const FVector& Scale, TArray<FVector3f>& Vertices, TArray<MRMESH_INDEX_TYPE>& Indices, TArray<FVector2D> UVData = {}, TArray<FPackedNormal> TangentXZData = {}, TArray<FColor> ColorData = {});
147
148 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
149 MRMESH_API void SetEnableMeshOcclusion(bool bEnable);
150
151 UFUNCTION(BlueprintPure, Category = "Mesh Reconstruction")
152 bool GetEnableMeshOcclusion() const { return bEnableOcclusion; }
153
154 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
155 MRMESH_API void SetUseWireframe(bool bUseWireframe);
156
157 UFUNCTION(BlueprintPure, Category = "Mesh Reconstruction")
158 bool GetUseWireframe() const { return bUseWireframe; }
159
160 UFUNCTION(BlueprintCallable, Category = "Mesh Reconstruction")
161 MRMESH_API void SetWireframeColor(const FLinearColor& InColor);
162
163 UFUNCTION(BlueprintPure, Category = "Mesh Reconstruction")
164 const FLinearColor& GetWireframeColor() const { return WireframeColor; }
165
167
169
170protected:
171 MRMESH_API virtual void OnActorEnableCollisionChanged() override;
172 MRMESH_API virtual void UpdatePhysicsToRBChannels() override;
173public:
174 MRMESH_API virtual void SetCollisionObjectType(ECollisionChannel Channel) override;
177 MRMESH_API virtual void SetCollisionResponseToChannels(const FCollisionResponseContainer& NewResponses) override;
178 MRMESH_API virtual void SetCollisionEnabled(ECollisionEnabled::Type NewType) override;
179 MRMESH_API virtual void SetCollisionProfileName(FName InCollisionProfileName, bool bUpdateOverlaps=true) override;
180
181 MRMESH_API virtual void SetWalkableSlopeOverride(const FWalkableSlopeOverride& NewOverride) override;
182
184 void SetEnableNavMesh(bool bEnable) { bUpdateNavMeshOnMeshUpdate = bEnable; }
186
188 DECLARE_EVENT(UMRMeshComponent, FOnClear);
189 FOnClear& OnClear() { return OnClearEvent; }
190
191private:
192 //~ UPrimitiveComponent
193 MRMESH_API virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
194 MRMESH_API virtual void GetUsedMaterials(TArray<UMaterialInterface*>& OutMaterials, bool bGetDebugMaterials = false) const override;
195 MRMESH_API virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
196 MRMESH_API virtual bool DoCustomNavigableGeometryExport(FNavigableGeometryExport& GeomExport) const override;
197
198 //~ UPrimitiveComponent
199 //~ UActorComponent
200 MRMESH_API virtual bool ShouldCreatePhysicsState() const override;
201 MRMESH_API virtual void SendRenderDynamicData_Concurrent() override;
202 //~ UActorComponent
203
204 //~ IMRMesh
205 MRMESH_API virtual void SendBrickData(FSendBrickDataArgs Args) override;
206 MRMESH_API virtual void ClearAllBrickData() override;
207 //~ IMRMesh
208
209private:
211
212 MRMESH_API void RemoveBodyInstance(int32 BodyIndex);
214
216
217 UPROPERTY(EditAnywhere, Category = Appearance)
219
220 UPROPERTY(EditAnywhere, Category = Appearance)
221 TObjectPtr<UMaterialInterface> WireframeMaterial;
222
224 UPROPERTY(EditAnywhere, Category = Appearance)
225 bool bCreateMeshProxySections = true;
226
228 UPROPERTY(EditAnywhere, Category = MRMesh)
229 bool bUpdateNavMeshOnMeshUpdate = true;
230
231 bool bNavMeshUpdateSuggested = false;
232
234 UPROPERTY(EditAnywhere, Category = MRMesh)
235 bool bNeverCreateCollisionMesh = false;
236
241 bool bUseAsyncCooking = true;
242
243 bool bConnected = false;
244
246 bool bEnableOcclusion;
248 bool bUseWireframe;
249
251
252 FLinearColor WireframeColor = FLinearColor::White;
253
255
256
257 // Collision/Physics data
260
261 // This array is parallel to BodyHolders
263};
EUpdateTransformFlags
Definition ActorComponent.h:95
bool bSuccess
Definition ConvexDecomposition3.cpp:819
EForceInit
Definition CoreMiscDefines.h:154
@ ForceInit
Definition CoreMiscDefines.h:155
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
#define DECLARE_STATS_GROUP(GroupDesc, GroupId, GroupCat)
Definition Stats.h:689
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:58
#define DECLARE_EVENT(OwningType, EventName)
Definition DelegateCombinations.h:32
ETeleportType
Definition EngineTypes.h:2401
ECollisionChannel
Definition EngineTypes.h:1088
ECollisionResponse
Definition EngineTypes.h:1240
#define DEFINE_LOG_CATEGORY_STATIC(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:380
#define MRMESH_INDEX_TYPE
Definition MRMeshBufferDefines.h:32
UE::Math::TBox< double > FBox
Definition MathFwd.h:55
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
ESPMode
Definition SharedPointerFwd.h:12
Definition BaseMeshReconstructorModule.h:13
Definition MRMeshComponent.cpp:174
Definition NameTypes.h:617
Definition PrimitiveSceneProxy.h:296
Definition Interface_CollisionDataProvider.h:23
Definition MRMeshComponent.h:29
uint64 FBrickId
Definition MRMeshComponent.h:37
virtual void SendRelativeTransform(const FTransform &Transform)=0
virtual void SendBrickData(FSendBrickDataArgs Args)=0
virtual void ClearAllBrickData()=0
virtual void Clear()=0
virtual void SetConnected(bool value)=0
virtual bool IsConnected() const =0
Definition Array.h:670
Definition SharedPointer.h:692
Definition BodySetup.h:128
Definition MRMeshComponent.h:64
virtual bool WantsNegXTriMesh() override
Definition MRMeshComponent.h:78
Definition MaterialInterface.h:296
virtual class UMaterial * GetMaterial() PURE_VIRTUAL(UMaterialInterface
Definition MaterialInterface.h:482
Definition Material.h:432
Definition MeshReconstructorBase.h:26
Definition Object.h:95
Type
Definition EngineTypes.h:1573
Type
Definition EngineTypes.h:3431
@ false
Definition radaudio_common.h:23
Definition BodyInstance.h:320
Definition EngineTypes.h:1339
Definition DynamicMeshBuilder.h:26
Definition Color.h:48
static CORE_API const FLinearColor White
Definition Color.h:456
Definition NavigationSystemHelpers.h:25
Definition Interface_CollisionDataProviderCore.h:68
Definition Interface_CollisionDataProviderCore.h:28
Definition EngineTypes.h:3483
Definition MRMeshComponent.h:32
virtual ~FBrickDataReceipt()
Definition MRMeshComponent.h:34
Definition MRMeshComponent.h:39
const FBox Bounds
Definition MRMeshComponent.h:48
const TArray< FVector2D > & UVData
Definition MRMeshComponent.h:44
const TArray< FVector3f > & PositionData
Definition MRMeshComponent.h:43
const TArray< MRMESH_INDEX_TYPE > & Indices
Definition MRMeshComponent.h:47
const FBrickId BrickId
Definition MRMeshComponent.h:42
TSharedPtr< FBrickDataReceipt, ESPMode::ThreadSafe > BrickDataReceipt
Definition MRMeshComponent.h:41
const TArray< FColor > & ColorData
Definition MRMeshComponent.h:46
const TArray< FPackedNormal > & TangentXZData
Definition MRMeshComponent.h:45
Definition ObjectPtr.h:488
Definition BoxSphereBounds.h:25