5 #include "Components/MeshComponent.h" 9 #include "PhysicsEngine/ConvexElem.h" 11 #include "Interfaces/Interface_CollisionDataProvider.h" 12 #include "RuntimeMeshComponent.generated.h" 15 enum class ERuntimeMeshSetAction : uint8
17 Create
UMETA(DisplayName =
"Created new section"),
18 Update
UMETA(DisplayName =
"Updated section"),
19 Remove
UMETA(DisplayName =
"Removed section"),
25 UCLASS(HideCategories = (Object, LOD), Meta = (BlueprintSpawnableComponent))
26 class RUNTIMEMESHCOMPONENT_API URuntimeMeshComponent : public UMeshComponent, public IInterface_CollisionDataProvider
32 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = RuntimeMesh, Meta = (AllowPrivateAccess = "true", DisplayName = "Runtime Mesh"))
35 void EnsureHasRuntimeMesh();
42 URuntimeMeshComponent(const FObjectInitializer& ObjectInitializer);
45 UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
48 return RuntimeMeshReference;
52 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
55 EnsureHasRuntimeMesh();
57 return RuntimeMeshReference;
67 return GetOrCreateRuntimeMesh()->GetRuntimeMeshData();
70 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
71 bool ShouldSerializeMeshData()
73 return GetRuntimeMesh() ? GetRuntimeMesh()->ShouldSerializeMeshData() :
false;
76 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
77 void SetShouldSerializeMeshData(
bool bShouldSerialize)
79 GetOrCreateRuntimeMesh()->SetShouldSerializeMeshData(bShouldSerialize);
82 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", Meta = (AllowPrivateAccess =
"true", DisplayName =
"Get Mobility"))
89 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", Meta = (AllowPrivateAccess =
"true", DisplayName =
"Set Mobility"))
97 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
101 void CreateMeshSection(int32 SectionIndex,
bool bWantsHighPrecisionTangents,
bool bWantsHighPrecisionUVs, int32 NumUVs,
bool bWants32BitIndices,
bool bCreateCollision,
EUpdateFrequency UpdateFrequency =
EUpdateFrequency::Average)
103 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionIndex, bWantsHighPrecisionTangents, bWantsHighPrecisionUVs, NumUVs, bWants32BitIndices, bCreateCollision, UpdateFrequency);
114 template<
typename VertexType0,
typename IndexType>
115 ERuntimeMeshSetAction SetMeshSection(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<IndexType>& InTriangles,
bool bCreateCollision =
false,
118 if (GetOrCreateRuntimeMeshData()->DoesSectionExist(SectionIndex)) {
119 if (InVertices0.Num() == 0) {
120 ClearMeshSection(SectionIndex);
121 return ERuntimeMeshSetAction::Remove;
124 UpdateMeshSection(SectionIndex, InVertices0, InTriangles, UpdateFlags);
125 return ERuntimeMeshSetAction::Update;
128 else if (InVertices0.Num() != 0) {
129 CreateMeshSection(SectionIndex, InVertices0, InTriangles, bCreateCollision, UpdateFrequency, UpdateFlags);
130 return ERuntimeMeshSetAction::Create;
132 return ERuntimeMeshSetAction::None;
140 ERuntimeMeshSetAction SetMeshSection(int32 SectionId,
const TSharedPtr<FRuntimeMeshBuilder>& MeshData,
bool bCreateCollision =
false,
143 if (GetOrCreateRuntimeMeshData()->DoesSectionExist(SectionId)) {
144 if (MeshData->NumIndices() == 0) {
145 GetOrCreateRuntimeMeshData()->ClearMeshSection(SectionId);
146 return ERuntimeMeshSetAction::Remove;
149 GetOrCreateRuntimeMeshData()->UpdateMeshSection(SectionId, MeshData, UpdateFlags);
150 return ERuntimeMeshSetAction::Update;
153 else if (MeshData->NumIndices() != 0) {
154 GetOrCreateRuntimeMeshData()->CreateMeshSection(SectionId, MeshData, bCreateCollision, UpdateFrequency, UpdateFlags);
155 return ERuntimeMeshSetAction::Create;
157 return ERuntimeMeshSetAction::None;
165 ERuntimeMeshSetAction SetMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
const TArray<FVector>& Normals,
166 const TArray<FVector2D>& UV0,
const TArray<FColor>& Colors,
const TArray<FRuntimeMeshTangent>& Tangents,
bool bCreateCollision =
false,
168 bool bUseHighPrecisionTangents =
false,
bool bUseHighPrecisionUVs =
true)
170 if (GetOrCreateRuntimeMeshData()->DoesSectionExist(SectionIndex)) {
171 if (Vertices.Num() == 0) {
172 GetOrCreateRuntimeMeshData()->ClearMeshSection(SectionIndex);
173 return ERuntimeMeshSetAction::Remove;
176 UpdateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, UpdateFlags);
177 return ERuntimeMeshSetAction::Update;
180 else if (Vertices.Num() != 0) {
181 CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, bCreateCollision,
182 UpdateFrequency, UpdateFlags, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
183 return ERuntimeMeshSetAction::Create;
185 return ERuntimeMeshSetAction::None;
193 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Set Mesh Section", AutoCreateRefTerm =
"Normals,Tangents,UV0,UV1,Colors"))
194 ERuntimeMeshSetAction SetMeshSection_Blueprint(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
195 const TArray<
FRuntimeMeshTangent>& Tangents, const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FLinearColor>& Colors,
196 bool bCreateCollision = false,
bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false,
199 if (DoesSectionExist(SectionIndex)) {
200 if (Vertices.Num() == 0) {
201 ClearMeshSection(SectionIndex);
202 return ERuntimeMeshSetAction::Remove;
205 UpdateMeshSection_Blueprint(SectionIndex, Vertices, Triangles, Normals, Tangents, UV0, UV1, Colors,
206 bCalculateNormalTangent, bShouldCreateHardTangents, bGenerateTessellationTriangles);
207 return ERuntimeMeshSetAction::Update;
210 else if (Vertices.Num() != 0) {
211 CreateMeshSection_Blueprint(SectionIndex, Vertices, Triangles, Normals, Tangents, UV0, UV1, Colors, bCreateCollision,
212 bCalculateNormalTangent, bShouldCreateHardTangents, bGenerateTessellationTriangles, UpdateFrequency, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
213 return ERuntimeMeshSetAction::Create;
215 return ERuntimeMeshSetAction::None;
223 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Set Mesh Section Packed", AutoCreateRefTerm =
"Normals,Tangents,UV0,UV1,Colors"))
224 ERuntimeMeshSetAction SetMeshSectionPacked_Blueprint(int32 SectionIndex, const TArray<
FRuntimeMeshBlueprintVertexSimple>& Vertices, const TArray<int32>& Triangles,
225 bool bCreateCollision = false,
bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false,
EUpdateFrequency UpdateFrequency =
EUpdateFrequency::Average,
226 bool bUseHighPrecisionTangents = false,
bool bUseHighPrecisionUVs = true)
228 if (DoesSectionExist(SectionIndex)) {
229 if (Vertices.Num() == 0) {
230 ClearMeshSection(SectionIndex);
231 return ERuntimeMeshSetAction::Remove;
234 UpdateMeshSectionPacked_Blueprint(SectionIndex, Vertices, Triangles, bCalculateNormalTangent, bShouldCreateHardTangents,
235 bGenerateTessellationTriangles);
236 return ERuntimeMeshSetAction::Update;
239 else if (Vertices.Num() != 0) {
240 CreateMeshSectionPacked_Blueprint(SectionIndex, Vertices, Triangles, bCreateCollision, bCalculateNormalTangent, bShouldCreateHardTangents,
241 bGenerateTessellationTriangles, UpdateFrequency, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
242 return ERuntimeMeshSetAction::Create;
244 return ERuntimeMeshSetAction::None;
250 template<
typename VertexType0,
typename IndexType>
251 FORCEINLINE
void CreateMeshSection(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<IndexType>& InTriangles,
bool bCreateCollision =
false,
254 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionIndex, InVertices0, InTriangles, bCreateCollision, UpdateFrequency, UpdateFlags);
257 template<
typename VertexType0,
typename IndexType>
258 FORCEINLINE
void CreateMeshSection(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<IndexType>& InTriangles,
const FBox& BoundingBox,
261 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionIndex, InVertices0, InTriangles, BoundingBox, bCreateCollision, UpdateFrequency, UpdateFlags);
264 template<
typename VertexType0,
typename VertexType1,
typename IndexType>
265 FORCEINLINE
void CreateMeshSectionDualBuffer(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<IndexType>& InTriangles,
bool bCreateCollision =
false,
268 GetOrCreateRuntimeMesh()->CreateMeshSectionDualBuffer(SectionIndex, InVertices0, InVertices1, InTriangles, bCreateCollision, UpdateFrequency, UpdateFlags);
271 template<
typename VertexType0,
typename VertexType1,
typename IndexType>
272 FORCEINLINE
void CreateMeshSectionDualBuffer(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<IndexType>& InTriangles,
const FBox& BoundingBox,
275 GetOrCreateRuntimeMesh()->CreateMeshSectionDualBuffer(SectionIndex, InVertices0, InVertices1, InTriangles, BoundingBox, bCreateCollision, UpdateFrequency, UpdateFlags);
278 template<
typename VertexType0,
typename VertexType1,
typename VertexType2,
typename IndexType>
279 FORCEINLINE
void CreateMeshSectionTripleBuffer(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2, TArray<IndexType>& InTriangles,
282 GetOrCreateRuntimeMesh()->CreateMeshSectionTripleBuffer(SectionIndex, InVertices0, InVertices1, InVertices2, InTriangles, bCreateCollision, UpdateFrequency, UpdateFlags);
285 template<
typename VertexType0,
typename VertexType1,
typename VertexType2,
typename IndexType>
286 FORCEINLINE
void CreateMeshSectionTripleBuffer(int32 SectionIndex, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2, TArray<IndexType>& InTriangles,
289 GetOrCreateRuntimeMesh()->CreateMeshSectionTripleBuffer(SectionIndex, InVertices0, InVertices1, InVertices2, InTriangles, BoundingBox, bCreateCollision, UpdateFrequency, UpdateFlags);
298 template<
typename VertexType0>
299 FORCEINLINE
void UpdateMeshSection(int32 SectionId, TArray<VertexType0>& InVertices0,
302 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionId, InVertices0, UpdateFlags);
305 template<
typename VertexType0>
306 FORCEINLINE
void UpdateMeshSection(int32 SectionId, TArray<VertexType0>& InVertices0,
309 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionId, InVertices0, BoundingBox, UpdateFlags);
312 template<
typename VertexType0,
typename IndexType>
313 FORCEINLINE
void UpdateMeshSection(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<IndexType>& InTriangles,
316 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionId, InVertices0, InTriangles, UpdateFlags);
319 template<
typename VertexType0,
typename IndexType>
320 FORCEINLINE
void UpdateMeshSection(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<IndexType>& InTriangles,
323 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionId, InVertices0, InTriangles, BoundingBox, UpdateFlags);
326 template<
typename VertexType0,
typename VertexType1>
327 FORCEINLINE
void UpdateMeshSectionDualBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1,
330 GetOrCreateRuntimeMesh()->UpdateMeshSectionDualBuffer(SectionId, InVertices0, InVertices1, UpdateFlags);
333 template<
typename VertexType0,
typename VertexType1>
334 FORCEINLINE
void UpdateMeshSectionDualBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1,
337 GetOrCreateRuntimeMesh()->UpdateMeshSectionDualBuffer(SectionId, InVertices0, InVertices1, BoundingBox, UpdateFlags);
340 template<
typename VertexType0,
typename VertexType1,
typename IndexType>
341 FORCEINLINE
void UpdateMeshSectionDualBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1,
344 GetOrCreateRuntimeMesh()->UpdateMeshSectionDualBuffer(SectionId, InVertices0, InVertices1, InTriangles, UpdateFlags);
347 template<
typename VertexType0,
typename VertexType1,
typename IndexType>
348 FORCEINLINE
void UpdateMeshSectionDualBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<IndexType>& InTriangles,
351 GetOrCreateRuntimeMesh()->UpdateMeshSectionDualBuffer(SectionId, InVertices0, InVertices1, InTriangles, BoundingBox, UpdateFlags);
354 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
355 FORCEINLINE
void UpdateMeshSectionTripleBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2,
358 GetOrCreateRuntimeMesh()->UpdateMeshSectionTripleBuffer(SectionId, InVertices0, InVertices1, InVertices2, UpdateFlags);
361 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
362 FORCEINLINE
void UpdateMeshSectionTripleBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2,
365 GetOrCreateRuntimeMesh()->UpdateMeshSectionTripleBuffer(SectionId, InVertices0, InVertices1, InVertices2, BoundingBox, UpdateFlags);
368 template<
typename VertexType0,
typename VertexType1,
typename VertexType2,
typename IndexType>
369 FORCEINLINE
void UpdateMeshSectionTripleBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2,
372 GetOrCreateRuntimeMesh()->UpdateMeshSectionTripleBuffer(SectionId, InVertices0, InVertices1, InVertices2, InTriangles, UpdateFlags);
375 template<
typename VertexType0,
typename VertexType1,
typename VertexType2,
typename IndexType>
376 FORCEINLINE
void UpdateMeshSectionTripleBuffer(int32 SectionId, TArray<VertexType0>& InVertices0, TArray<VertexType1>& InVertices1, TArray<VertexType2>& InVertices2,
379 GetOrCreateRuntimeMesh()->UpdateMeshSectionTripleBuffer(SectionId, InVertices0, InVertices1, InVertices2, InTriangles, BoundingBox, UpdateFlags);
386 template<
typename VertexType>
387 UE_DEPRECATED(3.0,
"UpdateMeshSection for dual buffer sections deprecated. Please use UpdateMeshSectionDualBuffer instead.")
390 UpdateMeshSectionDualBuffer(SectionIndex, VertexPositions, VertexData, UpdateFlags);
394 template<
typename VertexType>
395 UE_DEPRECATED(3.0,
"UpdateMeshSection for dual buffer sections deprecated. Please use UpdateMeshSectionDualBuffer instead.")
398 UpdateMeshSectionDualBuffer(SectionIndex, VertexPositions, VertexData, BoundingBox, UpdateFlags);
402 template<
typename VertexType>
403 UE_DEPRECATED(3.0,
"UpdateMeshSection for dual buffer sections deprecated. Please use UpdateMeshSectionDualBuffer instead.")
406 UpdateMeshSectionDualBuffer(SectionIndex, VertexPositions, VertexData, Triangles, UpdateFlags);
410 template<
typename VertexType>
411 UE_DEPRECATED(3.0,
"UpdateMeshSection for dual buffer sections deprecated. Please use UpdateMeshSectionDualBuffer instead.")
412 void UpdateMeshSection(int32 SectionIndex, TArray<FVector>& VertexPositions, TArray<VertexType>& VertexData, TArray<int32>& Triangles, const FBox& BoundingBox,
ESectionUpdateFlags UpdateFlags =
ESectionUpdateFlags::None)
414 UpdateMeshSectionDualBuffer(SectionIndex, VertexPositions, VertexData, Triangles, BoundingBox, UpdateFlags);
421 template<
typename VertexType0>
424 GetOrCreateRuntimeMesh()->UpdateMeshSectionPrimaryBuffer(SectionId, InVertices0, UpdateFlags);
427 template<
typename VertexType0>
430 GetOrCreateRuntimeMesh()->UpdateMeshSectionPrimaryBuffer(SectionId, InVertices0, BoundingBox, UpdateFlags);
433 template<
typename VertexType1>
436 GetOrCreateRuntimeMesh()->UpdateMeshSectionSecondaryBuffer(SectionId, InVertices1, UpdateFlags);
439 template<
typename VertexType2>
442 GetOrCreateRuntimeMesh()->UpdateMeshSectionTertiaryBuffer(SectionId, InVertices2, UpdateFlags);
445 template<
typename IndexType>
448 GetOrCreateRuntimeMesh()->UpdateMeshSectionTriangles(SectionId, InTriangles, UpdateFlags);
453 FORCEINLINE
void CreateMeshSection(int32 SectionId,
const TSharedPtr<FRuntimeMeshBuilder>& MeshData,
bool bCreateCollision =
false,
456 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionId, MeshData, bCreateCollision, UpdateFrequency, UpdateFlags);
459 FORCEINLINE
void CreateMeshSectionByMove(int32 SectionId,
const TSharedPtr<FRuntimeMeshBuilder>& MeshData,
bool bCreateCollision =
false,
462 GetOrCreateRuntimeMesh()->CreateMeshSectionByMove(SectionId, MeshData, bCreateCollision, UpdateFrequency, UpdateFlags);
465 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
469 GetOrCreateRuntimeMesh()->CreateMeshSectionFromBuilder(SectionId, MeshData, bCreateCollision, UpdateFrequency);
476 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionId, MeshData, UpdateFlags);
481 GetOrCreateRuntimeMesh()->UpdateMeshSectionByMove(SectionId, MeshData, UpdateFlags);
484 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
487 GetOrCreateRuntimeMesh()->UpdateMeshSectionFromBuilder(SectionId, MeshData);
493 check(IsInGameThread());
494 return GetOrCreateRuntimeMesh()->BeginSectionUpdate(SectionId, UpdateFlags);
497 TUniquePtr<FRuntimeMeshScopedUpdater> GetSectionReadonly(int32 SectionId)
499 check(IsInGameThread());
500 return GetOrCreateRuntimeMesh()->GetSectionReadonly(SectionId);
505 FORCEINLINE
void CreateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
const TArray<FVector>& Normals,
506 const TArray<FVector2D>& UV0,
const TArray<FColor>& Colors,
const TArray<FRuntimeMeshTangent>& Tangents,
bool bCreateCollision =
false,
508 bool bUseHighPrecisionTangents =
false,
bool bUseHighPrecisionUVs =
true)
510 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, bCreateCollision,
511 UpdateFrequency, UpdateFlags, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
514 FORCEINLINE
void CreateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
const TArray<FVector>& Normals,
515 const TArray<FVector2D>& UV0,
const TArray<FVector2D>& UV1,
const TArray<FColor>& Colors,
const TArray<FRuntimeMeshTangent>& Tangents,
517 bool bUseHighPrecisionTangents =
false,
bool bUseHighPrecisionUVs =
true)
519 GetOrCreateRuntimeMesh()->CreateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, UV1, Colors, Tangents, bCreateCollision,
520 UpdateFrequency, UpdateFlags, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
524 FORCEINLINE
void UpdateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<FVector>& Normals,
const TArray<FVector2D>& UV0,
527 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionIndex, Vertices, Normals, UV0, Colors, Tangents, UpdateFlags);
530 FORCEINLINE
void UpdateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<FVector>& Normals,
const TArray<FVector2D>& UV0,
533 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionIndex, Vertices, Normals, UV0, UV1, Colors, Tangents, UpdateFlags);
536 FORCEINLINE
void UpdateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
const TArray<FVector>& Normals,
539 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, Colors, Tangents, UpdateFlags);
542 FORCEINLINE
void UpdateMeshSection(int32 SectionIndex,
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
const TArray<FVector>& Normals,
545 GetOrCreateRuntimeMesh()->UpdateMeshSection(SectionIndex, Vertices, Triangles, Normals, UV0, UV1, Colors, Tangents, UpdateFlags);
550 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Create Mesh Section", AutoCreateRefTerm =
"Normals,Tangents,UV0,UV1,Colors"))
551 void CreateMeshSection_Blueprint(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
552 const TArray<
FRuntimeMeshTangent>& Tangents, const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FLinearColor>& Colors,
553 bool bCreateCollision = false,
bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false,
556 GetOrCreateRuntimeMesh()->CreateMeshSection_Blueprint(SectionIndex, Vertices, Triangles, Normals, Tangents, UV0, UV1, Colors, bCreateCollision,
557 bCalculateNormalTangent, bShouldCreateHardTangents, bGenerateTessellationTriangles, UpdateFrequency, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
560 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Update Mesh Section", AutoCreateRefTerm =
"Triangles,Normals,Tangents,UV0,UV1,Colors"))
561 void UpdateMeshSection_Blueprint(int32 SectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles, const TArray<FVector>& Normals,
562 const TArray<
FRuntimeMeshTangent>& Tangents, const TArray<FVector2D>& UV0, const TArray<FVector2D>& UV1, const TArray<FLinearColor>& Colors,
563 bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false)
565 GetOrCreateRuntimeMesh()->UpdateMeshSection_Blueprint(SectionIndex, Vertices, Triangles, Normals, Tangents, UV0, UV1, Colors, bCalculateNormalTangent, bShouldCreateHardTangents, bGenerateTessellationTriangles);
568 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Create Mesh Section Packed", AutoCreateRefTerm =
"Normals,Tangents,UV0,UV1,Colors"))
570 bool bCreateCollision = false,
bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false,
EUpdateFrequency UpdateFrequency =
EUpdateFrequency::Average,
571 bool bUseHighPrecisionTangents = false,
bool bUseHighPrecisionUVs = true)
573 GetOrCreateRuntimeMesh()->CreateMeshSectionPacked_Blueprint(SectionIndex, Vertices, Triangles, bCreateCollision, bCalculateNormalTangent, bShouldCreateHardTangents,
574 bGenerateTessellationTriangles, UpdateFrequency, bUseHighPrecisionTangents, bUseHighPrecisionUVs);
577 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (DisplayName =
"Update Mesh Section Packed", AutoCreateRefTerm =
"Triangles,Normals,Tangents,UV0,UV1,Colors"))
579 bool bCalculateNormalTangent = false,
bool bShouldCreateHardTangents = false,
bool bGenerateTessellationTriangles = false)
581 GetOrCreateRuntimeMesh()->UpdateMeshSectionPacked_Blueprint(SectionIndex, Vertices, Triangles, bCalculateNormalTangent, bShouldCreateHardTangents, bGenerateTessellationTriangles);
590 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
591 void ClearMeshSection(int32 SectionIndex)
595 Mesh->ClearMeshSection(SectionIndex);
600 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
601 void ClearAllMeshSections()
605 Mesh->ClearAllMeshSections();
611 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
612 void SetSectionMaterial(int32 SectionId, UMaterialInterface* Material)
616 Mesh->SetSectionMaterial(SectionId, Material);
620 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
621 UMaterialInterface* GetSectionMaterial(int32 SectionId)
625 return Mesh->GetSectionMaterial(SectionId);
631 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
632 FBox GetSectionBoundingBox(int32 SectionIndex)
636 return Mesh->GetSectionBoundingBox(SectionIndex);
638 return FBox(EForceInit::ForceInitToZero);
642 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
643 void SetMeshSectionVisible(int32 SectionIndex,
bool bNewVisibility)
647 Mesh->SetMeshSectionVisible(SectionIndex, bNewVisibility);
652 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
653 bool IsMeshSectionVisible(int32 SectionIndex)
const 657 return Mesh->IsMeshSectionVisible(SectionIndex);
664 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
665 void SetMeshSectionCastsShadow(int32 SectionIndex,
bool bNewCastsShadow)
669 Mesh->SetMeshSectionCastsShadow(SectionIndex, bNewCastsShadow);
674 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
675 bool IsMeshSectionCastingShadows(int32 SectionIndex)
const 679 return Mesh->IsMeshSectionCastingShadows(SectionIndex);
686 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
687 void SetMeshSectionCollisionEnabled(int32 SectionIndex,
bool bNewCollisionEnabled)
691 Mesh->SetMeshSectionCollisionEnabled(SectionIndex, bNewCollisionEnabled);
696 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
697 bool IsMeshSectionCollisionEnabled(int32 SectionIndex)
701 return Mesh->IsMeshSectionCollisionEnabled(SectionIndex);
708 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
709 int32 GetNumSections()
const 713 return Mesh->GetNumSections();
719 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
720 bool DoesSectionExist(int32 SectionIndex)
const 724 return Mesh->DoesSectionExist(SectionIndex);
730 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
731 int32 GetAvailableSectionIndex()
const 735 return Mesh->GetAvailableSectionIndex();
748 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
749 void SetMeshCollisionSection(int32 CollisionSectionIndex, const TArray<FVector>& Vertices, const TArray<int32>& Triangles)
751 GetOrCreateRuntimeMesh()->SetMeshCollisionSection(CollisionSectionIndex, Vertices, Triangles);
754 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
755 void ClearMeshCollisionSection(int32 CollisionSectionIndex)
757 GetOrCreateRuntimeMesh()->ClearMeshCollisionSection(CollisionSectionIndex);
760 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
761 void ClearAllMeshCollisionSections()
763 GetOrCreateRuntimeMesh()->ClearAllMeshCollisionSections();
768 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
769 int32 AddConvexCollisionSection(TArray<FVector> ConvexVerts)
771 return GetOrCreateRuntimeMesh()->AddConvexCollisionSection(ConvexVerts);
774 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
775 void SetConvexCollisionSection(int32 ConvexSectionIndex, TArray<FVector> ConvexVerts)
777 GetOrCreateRuntimeMesh()->SetConvexCollisionSection(ConvexSectionIndex, ConvexVerts);
780 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
781 void ClearConvexCollisionSection(int32 ConvexSectionIndex)
783 GetOrCreateRuntimeMesh()->ClearConvexCollisionSection(ConvexSectionIndex);
786 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
787 void ClearAllConvexCollisionSections()
789 GetOrCreateRuntimeMesh()->ClearAllConvexCollisionSections();
792 void SetCollisionConvexMeshes(
const TArray<TArray<FVector>>& ConvexMeshes)
794 GetOrCreateRuntimeMesh()->SetCollisionConvexMeshes(ConvexMeshes);
798 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
801 return GetOrCreateRuntimeMesh()->AddCollisionBox(NewBox);
804 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
807 GetOrCreateRuntimeMesh()->RemoveCollisionBox(Index);
810 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
811 void ClearCollisionBoxes()
813 GetOrCreateRuntimeMesh()->ClearCollisionBoxes();
816 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
819 GetOrCreateRuntimeMesh()->SetCollisionBoxes(NewBoxes);
823 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
826 return GetOrCreateRuntimeMesh()->AddCollisionSphere(NewSphere);
829 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
830 void RemoveCollisionSphere(int32 Index)
832 GetOrCreateRuntimeMesh()->RemoveCollisionSphere(Index);
835 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
836 void ClearCollisionSpheres()
838 GetOrCreateRuntimeMesh()->ClearCollisionSpheres();
841 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
844 GetOrCreateRuntimeMesh()->SetCollisionSpheres(NewSpheres);
848 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
851 return GetOrCreateRuntimeMesh()->AddCollisionCapsule(NewCapsule);
854 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
855 void RemoveCollisionCapsule(int32 Index)
857 GetOrCreateRuntimeMesh()->RemoveCollisionCapsule(Index);
860 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
861 void ClearCollisionCapsules()
863 GetOrCreateRuntimeMesh()->ClearCollisionCapsules();
866 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
869 GetOrCreateRuntimeMesh()->SetCollisionCapsules(NewCapsules);
874 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
875 void CookCollisionNow()
877 GetOrCreateRuntimeMesh()->CookCollisionNow();
880 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
881 void SetCollisionUseComplexAsSimple(
bool bNewValue)
883 GetOrCreateRuntimeMesh()->SetCollisionUseComplexAsSimple(bNewValue);
886 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
887 bool IsCollisionUsingComplexAsSimple()
889 check(IsInGameThread());
890 return GetRuntimeMesh() !=
nullptr ? GetRuntimeMesh()->IsCollisionUsingComplexAsSimple() :
true;
893 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
894 void SetCollisionUseAsyncCooking(
bool bNewValue)
896 GetOrCreateRuntimeMesh()->SetCollisionUseAsyncCooking(bNewValue);
899 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
900 bool IsCollisionUsingAsyncCooking()
902 check(IsInGameThread());
903 return GetRuntimeMesh() !=
nullptr ? GetRuntimeMesh()->IsCollisionUsingAsyncCooking() :
false;
906 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
909 GetOrCreateRuntimeMesh()->SetCollisionMode(NewMode);
916 virtual FBoxSphereBounds CalcBounds(
const FTransform& LocalToWorld)
const override;
917 virtual bool IsSupportedForNetworking()
const override 924 virtual FPrimitiveSceneProxy* CreateSceneProxy()
override;
925 virtual class UBodySetup* GetBodySetup()
override;
930 UFUNCTION(BlueprintCallable)
931 bool IsAsyncCollisionCookingPending() const;
933 UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
934 int32 GetSectionIdFromCollisionFaceIndex(int32 FaceIndex) const;
936 UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
937 void GetSectionIdAndFaceIdFromCollisionFaceIndex(int32 FaceIndex, int32& SectionIndex, int32& SectionFaceIndex) const;
939 virtual UMaterialInterface* GetMaterialFromCollisionFaceIndex(int32 FaceIndex, int32& SectionIndex) const override;
944 virtual int32 GetNumMaterials() const override;
945 virtual
void GetUsedMaterials(TArray<UMaterialInterface*>& OutMaterials,
bool bGetDebugMaterials = false) const override;
946 virtual UMaterialInterface* GetMaterial(int32 ElementIndex) const override;
947 virtual UMaterialInterface* GetOverrideMaterial(int32 ElementIndex) const;
953 virtual
void Serialize(FArchive& Ar) override;
957 virtual
void PostLoad() override;
962 void NewCollisionMeshReceived();
963 void NewBoundsReceived();
964 void ForceProxyRecreate();
966 void SendSectionCreation(int32 SectionIndex);
967 void SendSectionPropertiesUpdate(int32 SectionIndex);
973 UBodySetup* BodySetup;
977 TArray<UBodySetup*> AsyncBodySetupQueue;
979 #if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 22 980 virtual bool GetPhysicsTriMeshData(
struct FTriMeshCollisionData* CollisionData,
bool InUseAllTriData)
override;
981 virtual bool ContainsPhysicsTriMeshData(
bool InUseAllTriData)
const override;
982 virtual bool WantsNegXTriMesh()
override {
return false; }
986 #if ENGINE_MAJOR_VERSION == 4 && ENGINE_MINOR_VERSION < 21 987 UBodySetup* CreateNewBodySetup();
988 void FinishPhysicsAsyncCook(UBodySetup* FinishedBodySetup);
990 void UpdateCollision(
bool bForceCookNow);
typedef void(APIENTRY *GLDEBUGPROC)(GLenum source
TSharedRef< FRuntimeMeshData, ESPMode::ThreadSafe > FRuntimeMeshDataRef
static const textual_icon check
ERuntimeMeshCollisionCookingMode