UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DynamicMeshComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreMinimal.h"
11#include "TransformTypes.h"
12#include "Async/Future.h"
13#include "UDynamicMesh.h"
15
16#include "Misc/ScopeLock.h"
17#include "Tasks/Task.h"
18#include "Util/ProgressCancel.h"
19#include "DistanceFieldAtlas.h"
20
21#include "DynamicMeshComponent.generated.h"
22
23// predecl
24struct FMeshDescription;
25
29
36{
37public:
38 virtual ~IRenderMeshPostProcessor() = default;
39
41};
42
43
45UENUM()
55
56
57template<typename DataType>
59{
60 std::atomic<int> JobCounter = 0;
61 bool bIsShuttingDown = false;
62
67
76
79
80 // This function will be called w/ the data computed by a job
81 // when it finishes, if it is still valid
82 // Note this method will be run from a background thread, and should be thread-safe!
84
86 {
87 // OnComputeCompleted function must be set to something
89
90 if (!ensure(bIsShuttingDown == false))
91 {
92 return;
93 }
94
95 JobCounter++;
96 int CurrentTimestamp = JobCounter;
97
98 // cancel any existing jobs and clear them out if they have returned
99 {
101 for (int32 k = 0; k < PendingJobs.Num(); ++k)
102 {
103 PendingJobs[k]->bCancelled = true;
104 if (PendingJobs[k]->bHasCompleted)
105 {
106 PendingJobs.RemoveAtSwap(k, 1, EAllowShrinking::No);
107 k--; // reconsider element that was just swapped in to this position
108 }
109 }
110 }
111
112 // set up the new job
114 FComputeJob* JobPtr = NewJob.Get();
116 FProgressCancel* ProgressPtr = NewJob->Progress.Get();
117 NewJob->Progress->CancelF = [this, JobPtr]() { return bIsShuttingDown || JobPtr->bCancelled; };
118 NewJob->JobTimestamp = CurrentTimestamp;
119
120 // launch it
121 NewJob->Task = UE::Tasks::Launch(DebugName,
122 [this, JobWork, JobPtr]() {
123 // TODO: limit the number of in-progress active jobs
124 TUniquePtr<DataType> Result = JobWork( *JobPtr->Progress );
125 if (JobPtr->JobTimestamp == this->JobCounter && JobPtr->bCancelled == false)
126 {
127 if (!bIsShuttingDown && this->OnComputeCompleted)
128 {
129 this->OnComputeCompleted(MoveTemp(Result));
130 }
131 }
132 JobPtr->bHasCompleted = true;
133 },
136
137 // add new job
138 {
141 }
142 }
143
144
146 {
147 bIsShuttingDown = true;
149 for (int32 k = 0; k < PendingJobs.Num(); ++k)
150 {
151 UE::Tasks::Wait({PendingJobs[k]->Task});
152 }
153 }
154
155};
156
157
158
170UCLASS(hidecategories = (LOD), meta = (BlueprintSpawnableComponent), ClassGroup = Rendering, MinimalAPI)
172{
174
175
176
177 //===============================================================================================================
178 // Mesh Access. Usage via GetDynamicMesh() or SetMesh()/ProcessMesh()/EditMesh() is preferred, the GetMesh()
179 // pointer access exist largely to support existing code from before UDynamicMesh was added.
180public:
185 virtual FDynamicMesh3* GetMesh() override { return MeshObject ? MeshObject->GetMeshPtr() : nullptr; }
186
191 virtual const FDynamicMesh3* GetMesh() const override { return MeshObject ? MeshObject->GetMeshPtr() : nullptr; }
192
196 //UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
197 virtual UDynamicMesh* GetDynamicMesh() override { return MeshObject; }
198
204 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
205 GEOMETRYFRAMEWORK_API void SetDynamicMesh(UDynamicMesh* NewMesh);
206
211
215 GEOMETRYFRAMEWORK_API virtual void ProcessMesh(TFunctionRef<void(const UE::Geometry::FDynamicMesh3&)> ProcessFunc) const;
216
222
227 GEOMETRYFRAMEWORK_API virtual void ApplyTransform(const FTransform3d& Transform, bool bInvert) override;
228
229
234 bool IsEditable() const { return bIsEditable; }
235 void SetIsEditable(bool bInIsEditable) { bIsEditable = bInIsEditable; }
236
237
241 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
248 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
250
251protected:
256 UPROPERTY(Instanced)
257 TObjectPtr<UDynamicMesh> MeshObject;
258
259
260
261
262 //===============================================================================================================
263 // RenderBuffer Update API. These functions can be used by external code (and internally in some places)
264 // to tell the Component that the Mesh data has been modified in some way, and that the RenderBuffers in the RenderProxy
265 // need to be updated (or rebuilt entirely). On large meshes a full rebuild is expensive, so there are quite a few
266 // variants that can be used to minimize the amount of data updated in different situations.
267 //
268public:
273 GEOMETRYFRAMEWORK_API virtual void NotifyMeshUpdated() override;
274
280
285 GEOMETRYFRAMEWORK_API void FastNotifyPositionsUpdated(bool bNormals = false, bool bColors = false, bool bUVs = false);
286
292
298
304
310
316
322
330
340
341
342 //===============================================================================================================
343 // RenderBuffer Update Blueprint API.
344public:
345
355 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component|Rendering", DisplayName = "Notify Mesh Updated")
357
366 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component|Rendering", DisplayName = "Notify Vertex Attributes Updated")
368 bool bPositions = true,
369 bool bNormals = true,
370 bool bUVs = true,
371 bool bColors = true);
372
373 //===============================================================================================================
374 // Change Support. These changes are primarily used for Undo/Redo, however there is no strict assumption
375 // about this internally, objects of these change types could also be used to perform more structured editing.
376 // (Note that these functions simply forward the change events to the child UDynamicMesh, which will
377 // post a mesh-change event that
378 //
379public:
383 GEOMETRYFRAMEWORK_API virtual void ApplyChange(const FMeshVertexChange* Change, bool bRevert) override;
384
388 GEOMETRYFRAMEWORK_API virtual void ApplyChange(const FMeshChange* Change, bool bRevert) override;
389
393 GEOMETRYFRAMEWORK_API virtual void ApplyChange(const FMeshReplacementChange* Change, bool bRevert) override;
394
398 FSimpleMulticastDelegate OnMeshChanged;
399
405
412
420
423
424protected:
426 bool bInvalidateProxyOnChange = true;
427
430
433
438 bool bIsEditable = true;
439
440private:
444 UPROPERTY()
446
447
448
449 //===============================================================================================================
450 // Support for specifying per-triangle colors as vertex colors. This allows external code to dynamically override
451 // the vertex colors on the rendered mesh. The lambda that is passed is held for the lifetime of the Component and
452 // must remain valid. A Material that uses the vertex colors must be applied, otherwise setting this override will
453 // have no visible effect. If the colors change externally, FastNotifyColorsUpdated() can be used to do the
454 // minimal vertex buffer updates necessary in the RenderProxy
455 //
456public:
460
463
466
470
473
475 GEOMETRYFRAMEWORK_API FColor GetGroupColor(const FDynamicMesh3* Mesh, int TriangleID) const;
476
477
478 //===============================================================================================================
479 // Support for Vertex Color remapping/filtering. This allows external code to modulate the existing
480 // Vertex Colors on the rendered mesh. The remapping is only applied to FVector4f Color Overlay attribute buffers.
481 // The lambda that is passed is held for the lifetime of the Component and
482 // must remain valid. If the Vertex Colors are modified, FastNotifyColorsUpdated() can be used to do the
483 // minimal vertex buffer updates necessary in the RenderProxy
484public:
488
491
494
498
501
502
503
504 //===============================================================================================================
505 // Support for Secondary triangle index buffers. When this is configured, then triangles identified
506 // by the filtering predicate function will be placed in a second set of RenderBuffers at the SceneProxy level.
507 // This can be combined with the SecondaryRenderMaterial support in UBaseDynamicMeshComponent to draw
508 // that triangle set with a different material, to efficiently accomplish UI features like highlighting a
509 // subset of mesh triangles.
510 //
511public:
518
523
525 TUniqueFunction<bool(const FDynamicMesh3*, int32)> SecondaryTriFilterFunc = nullptr;
526
527
528
529
530 //===============================================================================================================
531 // Support for a Render Decomposition, which is basically a segmentation of the mesh triangles into
532 // subsets which will be turned into separate RenderBuffers in the Render Proxy. If this is configured,
533 // then various of the FastNotifyXYZUpdated() functions above will only need to rebuild the RenderBuffers
534 // that include affected triangles. The FMeshRenderDecomposition implementation has various options for
535 // building decompositions based on material, spatial clustering, etc.
536 //
537public:
543
546
547
548
549
550 //===============================================================================================================
551 // IRenderMeshPostProcessor Support. If a RenderMesh Postprocessor is configured, then instead of directly
552 // passing the internal mesh to the RenderProxy, IRenderMeshPostProcessor::PostProcess is applied to populate
553 // the internal RenderMesh which is passed instead. This allows things like Displacement or Subdivision to be
554 // done on-the-fly at the rendering level (which is potentially more efficient).
555 //
556public:
561
566
571
575
576
577
578
579 //===============================================================================================================
580 // Support for Component attachment change notifications via delegates. Standard UE
581 // Actor/Component hierarchy does not generally provide these capabilities, but in some use
582 // cases (eg procedural mesh Actors) we need to know things like when the Component set inside
583 // an Actor is modified.
584public:
586
592
593
594
595 //===============================================================================================================
596 // Material Set API. DynamicMeshComponent supports changing the Material Set dynamically, even at Runtime.
597public:
598
605 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
607
615 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
616 GEOMETRYFRAMEWORK_API bool ValidateMaterialSlots(bool bCreateIfMissing = true, bool bDeleteExtraSlots = true);
617
618
619 //===============================================================================================================
620 // Triangle-Vertex Tangents support. The default behavior is to use the provided external Tangents.
621 // If TangentsType == EDynamicMeshComponentTangentsMode::ExternallyProvided, the Tangent and Bitangent attributes of
622 // the FDynamicMesh3 AttributeSet are used at the SceneProxy level, the Component is not involved
623 // If TangentsType == EDynamicMeshComponentTangentsMode::AutoCalculated, the Tangents are computed internally using
624 // a fast MikkT approximation via FMeshTangentsf. They will be recomputed when the mesh is modified, however
625 // they are *not* recomputed when using the Fast Update functions above (in that case InvalidateAutoCalculatedTangents()
626 // can be used to force recomputation)
627 // If TangentsType == EDynamicMeshComponentTangentsMode::NoTangents, the Component will not use Tangents, which will
628 // lead to incorrect rendering for any material with Normal Maps and some other shaders.
629 //
630private:
631 // Default what the 'Default' tangent type should map to
633
634public:
635 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
637
638 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
640 {
642 }
643
644private:
645 // pure version of GetTangentsType, so it can be used as a getter below (getters must be BlueprintPure)
646 UFUNCTION(BlueprintCallable, BlueprintPure, BlueprintInternalUseOnly, Category = "Dynamic Mesh Component")
648 {
649 return GetTangentsType();
650 }
651
652public:
653
656
659
660protected:
662 UPROPERTY(EditAnywhere, BlueprintReadWrite, BlueprintSetter=SetTangentsType, BlueprintGetter=GetTangentsTypePure, Category = "Dynamic Mesh Component|Rendering")
664
667
669 UE::Geometry::FMeshTangentsf AutoCalculatedTangents;
670
672
673
674 //===============================================================================================================
675 //
676 // Distance Field Support
677 //
679 UE_DEPRECATED(5.6, "Dynamic Mesh distance field support has been deprecated")
681 UE_DEPRECATED(5.6, "Dynamic Mesh distance field support has been deprecated")
683 UE_DEPRECATED(5.6, "Dynamic Mesh distance field support has been deprecated")
685 UE_DEPRECATED(5.6, "Dynamic Mesh distance field support has been deprecated")
687 UE_DEPRECATED(5.6, "Dynamic Mesh distance field support has been deprecated")
689
690
691
692 //===============================================================================================================
693 //
694 // Physics APIs
695 //
696public:
700 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
702
708 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
709 GEOMETRYFRAMEWORK_API void SetComplexAsSimpleCollisionEnabled(bool bEnabled, bool bImmediateUpdate = true);
710
715 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
716 GEOMETRYFRAMEWORK_API void SetDeferredCollisionUpdatesEnabled(bool bEnabled, bool bImmediateUpdate = true);
717
718
719 GEOMETRYFRAMEWORK_API virtual bool GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) override;
721 GEOMETRYFRAMEWORK_API virtual bool ContainsPhysicsTriMeshData(bool InUseAllTriData) const override;
722 GEOMETRYFRAMEWORK_API virtual bool WantsNegXTriMesh() override;
723
725 virtual const UBodySetup* GetBodySetup() const { return MeshBodySetup; }
727 GEOMETRYFRAMEWORK_API virtual UBodySetup* GetBodySetup() override;
728
733 UFUNCTION(BlueprintCallable, Category = "Dynamic Mesh Component")
734 GEOMETRYFRAMEWORK_API virtual void UpdateCollision(bool bOnlyIfPending = true);
735
737 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dynamic Mesh Component|Collision")
739
747
749 {
750 return AggGeom;
751 }
752
758
763 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Dynamic Mesh Component|Collision")
765
770 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dynamic Mesh Component|Collision");
772
774 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dynamic Mesh Component|Collision");
776
778 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Dynamic Mesh Component|Collision");
780
788
790 UPROPERTY(Instanced)
792
793 GEOMETRYFRAMEWORK_API virtual void InvalidatePhysicsData();
795
798
800
801 //
802 // standard Component internals, for computing bounds and managing the SceneProxy
803 //
804
806 UE::Geometry::FAxisAlignedBox3d LocalBounds;
807
810
811 //
812 // Internals for managing collision representation and setup
813 //
814
816 UPROPERTY(EditAnywhere, Category = BodySetup, meta = (DisplayName = "Primitives", NoResetToDefault))
817 struct FKAggregateGeom AggGeom;
818
822
824 GEOMETRYFRAMEWORK_API virtual void FinishPhysicsAsyncCook(bool bSuccess, UBodySetup* FinishedBodySetup);
825
827
830
835 GEOMETRYFRAMEWORK_API virtual void NotifyMaterialSetUpdated();
836
843 bool bProxyValid = false;
844
853
854 virtual FBaseDynamicMeshSceneProxy* GetBaseSceneProxy() override { return (FBaseDynamicMeshSceneProxy*)GetCurrentSceneProxy(); }
855
860
861
866
867 //~ Begin UPrimitiveComponent Interface.
868 GEOMETRYFRAMEWORK_API virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
869
870 //~ USceneComponent Interface.
871 GEOMETRYFRAMEWORK_API virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
872 GEOMETRYFRAMEWORK_API virtual void OnChildAttached(USceneComponent* ChildComponent) override;
873 GEOMETRYFRAMEWORK_API virtual void OnChildDetached(USceneComponent* ChildComponent) override;
874
875 //~ UObject Interface.
876 GEOMETRYFRAMEWORK_API virtual void Serialize(FArchive& Ar) override;
877 GEOMETRYFRAMEWORK_API virtual void PostLoad() override; // called after load
878 GEOMETRYFRAMEWORK_API virtual void PostEditImport() override; // called after duplicate/copy
879 GEOMETRYFRAMEWORK_API virtual void BeginDestroy() override;
880#if WITH_EDITOR
881 GEOMETRYFRAMEWORK_API void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
882#endif
883
884public:
887
888
889private:
890 // Internal helper to be called when mesh data is updated
892
894
895};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define ensure( InExpression)
Definition AssertionMacros.h:464
EDynamicMeshComponentTangentsMode
Definition BaseDynamicMeshComponent.h:48
EMeshRenderAttributeFlags
Definition BaseDynamicMeshComponent.h:29
ECollisionTraceFlag
Definition BodySetupEnums.h:11
bool bSuccess
Definition ConvexDecomposition3.cpp:819
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define DECLARE_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:58
#define DECLARE_MULTICAST_DELEGATE_ThreeParams(DelegateName, Param1Type, Param2Type, Param3Type)
Definition DelegateCombinations.h:67
EDynamicMeshComponentRenderUpdateMode
Definition DynamicMeshComponent.h:47
return true
Definition ExternalRpcRegistry.cpp:601
@ Vertex
Definition MetalRHIPrivate.h:223
const bool
Definition NetworkReplayStreaming.h:178
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition Archive.h:1208
Definition BaseDynamicMeshSceneProxy.h:39
Definition IDelegateInstance.h:14
Definition DistanceFieldAtlas.h:241
Definition DynamicMeshSceneProxy.h:23
Definition MeshChange.h:32
Definition MeshRegionChange.h:11
Definition MeshRenderDecomposition.h:20
Definition MeshReplacementChange.h:27
Definition MeshVertexChange.h:22
Definition PrimitiveSceneProxy.h:296
Definition ProgressCancel.h:187
Definition ScopeLock.h:141
Definition Interface_CollisionDataProvider.h:23
Definition DynamicMeshComponent.h:36
virtual ~IRenderMeshPostProcessor()=default
virtual void ProcessMesh(const FDynamicMesh3 &Mesh, FDynamicMesh3 &OutRenderMesh)=0
Definition Array.h:670
Definition EnumAsByte.h:22
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition Future.h:393
Definition SharedPointer.h:692
Definition FunctionFwd.h:19
Definition UniquePtr.h:107
Definition BaseDynamicMeshComponent.h:130
virtual FDynamicMesh3 * GetMesh()
Definition BaseDynamicMeshComponent.h:150
virtual void NotifyMeshUpdated()
Definition BaseDynamicMeshComponent.h:187
virtual UDynamicMesh * GetDynamicMesh()
Definition BaseDynamicMeshComponent.h:177
Definition BodySetup.h:128
Definition UDynamicMesh.h:123
Definition DynamicMesh3.h:108
Definition MeshTangents.h:76
Definition MaterialInterface.h:296
virtual ENGINE_API void BeginDestroy() override
Definition MeshComponent.cpp:559
ENGINE_API FBox CalcBounds(const FVector &P0, const FVector &P1, const FVector &P2, const FVector &P3)
Definition BezierUtilities.cpp:26
TTask< TInvokeResult_T< TaskBodyType > > Launch(const TCHAR *DebugName, TaskBodyType &&TaskBody, ETaskPriority Priority=ETaskPriority::Normal, EExtendedTaskPriority ExtendedPriority=EExtendedTaskPriority::None, ETaskFlags Flags=ETaskFlags::None)
Definition Task.h:266
bool Wait(const TaskCollectionType &Tasks, FTimespan InTimeout=FTimespan::MaxValue())
Definition Task.h:381
Definition AdvancedWidgetsModule.cpp:13
@ false
Definition radaudio_common.h:23
Definition Color.h:486
Definition UDynamicMesh.h:69
Definition AggregateGeom.h:24
Definition MeshDescription.h:94
Definition UnrealType.h:6865
Definition Interface_CollisionDataProviderCore.h:68
Definition Interface_CollisionDataProviderCore.h:28
Definition DynamicMeshComponent.h:69
bool bCancelled
Definition DynamicMeshComponent.h:73
bool bHasCompleted
Definition DynamicMeshComponent.h:74
TUniquePtr< FProgressCancel > Progress
Definition DynamicMeshComponent.h:72
int JobTimestamp
Definition DynamicMeshComponent.h:71
UE::Tasks::FTask Task
Definition DynamicMeshComponent.h:70
Definition DynamicMeshComponent.h:59
TArray< TUniquePtr< FComputeJob > > PendingJobs
Definition DynamicMeshComponent.h:77
bool bIsShuttingDown
Definition DynamicMeshComponent.h:61
void LaunchJob(const TCHAR *DebugName, TFunction< TUniquePtr< DataType >(FProgressCancel &Progress)> JobWork)
Definition DynamicMeshComponent.h:85
FCriticalSection PendingJobsLock
Definition DynamicMeshComponent.h:78
~TAsyncComponentDataComputeQueue()
Definition DynamicMeshComponent.h:63
std::atomic< int > JobCounter
Definition DynamicMeshComponent.h:60
TFunction< void(TUniquePtr< DataType > NewData)> OnComputeCompleted
Definition DynamicMeshComponent.h:83
void WaitForAllJobsDuringShutdown()
Definition DynamicMeshComponent.h:145
Definition ObjectPtr.h:488
Definition BoxSphereBounds.h:25