5 #include "CoreMinimal.h" 7 #include "Kismet/BlueprintFunctionLibrary.h" 10 #include "RuntimeMeshLibrary.generated.h" 25 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (AutoCreateRefTerm =
"UVs"))
26 static void CalculateTangentsForMesh(
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
27 TArray<FVector>& Normals,
const TArray<FVector2D>& UVs, TArray<FRuntimeMeshTangent>& Tangents,
bool bCreateSmoothNormals =
true);
29 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
30 static void CalculateTangentsForMeshPacked(TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices,
const TArray<int32>& Triangles,
bool bCreateSmoothNormals =
true);
32 static void CalculateTangentsForMesh(TArray<FRuntimeMeshVertexSimple>& Vertices,
const TArray<int32>& Triangles,
bool bCreateSmoothNormals =
true);
34 static void CalculateTangentsForMesh(
const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor,
bool bCreateSmoothNormals =
true);
38 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (AutoCreateRefTerm =
"UVs"))
39 static TArray<int32> GenerateTessellationIndexBuffer(
const TArray<FVector>& Vertices,
const TArray<int32>& Triangles,
40 TArray<FVector>& Normals,
const TArray<FVector2D>& UVs, TArray<FRuntimeMeshTangent>& Tangents);
42 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
43 static TArray<int32> GenerateTessellationIndexBufferPacked(
const TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices,
const TArray<int32>& Triangles);
45 static TArray<int32> GenerateTessellationIndexBuffer(
const TArray<FRuntimeMeshVertexSimple>& Vertices,
const TArray<int32>& Triangles);
47 static TArray<int32> GenerateTessellationIndexBuffer(
const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor);
49 static void GenerateTessellationIndexBuffer(
const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor,
const TSharedPtr<FRuntimeMeshIndicesAccessor>& OutTessellationIndices);
53 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh", meta = (AutoCreateRefTerm =
"UVs"))
54 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FVector>& Vertices, TArray<int32>& Triangles,
55 TArray<FVector>& Normals, TArray<FVector2D>& UVs, TArray<FColor>& Colors, TArray<FRuntimeMeshTangent>& Tangents);
57 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
58 static void GetStaticMeshSectionPacked(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices, TArray<int32>& Triangles);
60 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshVertexSimple>& Vertices, TArray<int32>& Triangles);
62 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshVertexSimple>& Vertices, TArray<int32>& Triangles, TArray<int32>& AdjacencyTriangles);
64 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex,
const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor);
66 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex,
const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor,
const TSharedPtr<FRuntimeMeshIndicesAccessor>& TessellationIndicesAccessor);
68 template<
typename VertexType0,
typename IndexType>
69 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<VertexType0>& Vertices, TArray<IndexType>& Triangles) {
73 GetStaticMeshSection(InMesh, LODIndex, SectionIndex, 1,
74 [&Vertices](FVector Position, FVector TangentX, FVector TangentY, FVector TangentZ) -> int32
76 return Vertices.Add(VertexType0(Position, TangentX, TangentY, TangentZ));
78 [&Vertices](int32
Index, int32 UVIndex, FVector2D UV)
81 Vertices[
Index].UV0 = UV;
87 [&Triangles](int32
Index)
99 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
100 static void CopyStaticMeshToRuntimeMesh(UStaticMeshComponent* StaticMeshComponent, int32 LODIndex,
URuntimeMesh* RuntimeMesh,
bool bCreateCollision);
103 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
104 static void CopyStaticMeshToRuntimeMeshComponent(UStaticMeshComponent* StaticMeshComponent, int32 LODIndex, URuntimeMeshComponent* RuntimeMeshComponent,
bool bCreateCollision);
107 UFUNCTION(BlueprintCallable, Category =
"Components|RuntimeMesh")
108 static void CopyCollisionFromStaticMesh(UStaticMesh* StaticMesh,
URuntimeMesh* RuntimeMesh);
112 CopyCollisionFromStaticMesh(StaticMeshComponent->GetStaticMesh(), RuntimeMesh);
116 static void CalculateTangentsForMesh(TFunction<int32(int32
Index)> IndexAccessor, TFunction<FVector(int32 Index)> VertexAccessor, TFunction<FVector2D(int32 Index)> UVAccessor,
117 TFunction<
void(int32 Index, FVector TangentX, FVector TangentY, FVector TangentZ)> TangentSetter, int32 NumVertices, int32 NumUVs, int32 NumIndices,
bool bCreateSmoothNormals);
120 static int32 GetNewIndexForOldVertIndex(
const FPositionVertexBuffer* PosBuffer,
const FStaticMeshVertexBuffer* VertBuffer,
const FColorVertexBuffer*
ColorBuffer,
121 TMap<int32, int32>& MeshToSectionVertMap, int32 VertexIndex, int32 NumUVChannels, TFunction<int32(FVector Position, FVector TangentX, FVector TangentY, FVector TangentZ)> VertexCreator,
122 TFunction<
void(int32 VertexIndex, int32 UVIndex, FVector2D UV)> UVSetter, TFunction<
void(int32 VertexIndex, FColor
Color)> ColorSetter);
124 static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, int32 NumSupportedUVs,
125 TFunction<int32(FVector Position, FVector TangentX, FVector TangentY, FVector TangentZ)> VertexCreator,
126 TFunction<
void(int32 VertexIndex, int32 UVIndex, FVector2D UV)> UVSetter, TFunction<
void(int32 VertexIndex, FColor Color)> ColorSetter, TFunction<
void(int32)> IndexCreator, TFunction<
void(int32)> AdjacencyIndexCreator);
static void CopyCollisionFromStaticMesh(UStaticMeshComponent *StaticMeshComponent, URuntimeMesh *RuntimeMesh)
static void GetStaticMeshSection(UStaticMesh *InMesh, int32 LODIndex, int32 SectionIndex, TArray< VertexType0 > &Vertices, TArray< IndexType > &Triangles)
static const textual_icon check