RuntimeMeshLibrary.h
Go to the documentation of this file.
1 // Copyright 2016-2018 Chris Conway (Koderz). All Rights Reserved.
2 
3 #pragma once
4 
5 #include "CoreMinimal.h"
7 #include "Kismet/BlueprintFunctionLibrary.h"
8 #include "RuntimeMeshBuilder.h"
9 #include "RuntimeMeshBlueprint.h"
10 #include "RuntimeMeshLibrary.generated.h"
11 
15 UCLASS()
16 class RUNTIMEMESHCOMPONENT_API URuntimeMeshLibrary : public UBlueprintFunctionLibrary
17 {
18  GENERATED_BODY()
19 
20 public:
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);
28 
29  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
30  static void CalculateTangentsForMeshPacked(TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices, const TArray<int32>& Triangles, bool bCreateSmoothNormals = true);
31 
32  static void CalculateTangentsForMesh(TArray<FRuntimeMeshVertexSimple>& Vertices, const TArray<int32>& Triangles, bool bCreateSmoothNormals = true);
33 
34  static void CalculateTangentsForMesh(const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor, bool bCreateSmoothNormals = true);
35 
36 
37 
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);
41 
42  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
43  static TArray<int32> GenerateTessellationIndexBufferPacked(const TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices, const TArray<int32>& Triangles);
44 
45  static TArray<int32> GenerateTessellationIndexBuffer(const TArray<FRuntimeMeshVertexSimple>& Vertices, const TArray<int32>& Triangles);
46 
47  static TArray<int32> GenerateTessellationIndexBuffer(const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor);
48 
49  static void GenerateTessellationIndexBuffer(const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor, const TSharedPtr<FRuntimeMeshIndicesAccessor>& OutTessellationIndices);
50 
51 
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);
56 
57  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
58  static void GetStaticMeshSectionPacked(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshBlueprintVertexSimple>& Vertices, TArray<int32>& Triangles);
59 
60  static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshVertexSimple>& Vertices, TArray<int32>& Triangles);
61 
62  static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<FRuntimeMeshVertexSimple>& Vertices, TArray<int32>& Triangles, TArray<int32>& AdjacencyTriangles);
63 
64  static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor);
65 
66  static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, const TSharedPtr<FRuntimeMeshAccessor>& MeshAccessor, const TSharedPtr<FRuntimeMeshIndicesAccessor>& TessellationIndicesAccessor);
67 
68  template<typename VertexType0, typename IndexType>
69  static void GetStaticMeshSection(UStaticMesh* InMesh, int32 LODIndex, int32 SectionIndex, TArray<VertexType0>& Vertices, TArray<IndexType>& Triangles) {
70  Vertices.Empty();
71  Triangles.Empty();
72 
73  GetStaticMeshSection(InMesh, LODIndex, SectionIndex, 1,
74  [&Vertices](FVector Position, FVector TangentX, FVector TangentY, FVector TangentZ) -> int32
75  {
76  return Vertices.Add(VertexType0(Position, TangentX, TangentY, TangentZ));
77  },
78  [&Vertices](int32 Index, int32 UVIndex, FVector2D UV)
79  {
80  check(UVIndex == 0);
81  Vertices[Index].UV0 = UV;
82  },
83  [&Vertices](int32 Index, FColor Color)
84  {
85  Vertices[Index].Color = Color;
86  },
87  [&Triangles](int32 Index)
88  {
89  Triangles.Add(Index);
90  },
91  [](int32 Index)
92  {
93 
94  });
95  };
96 
97 
99  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
100  static void CopyStaticMeshToRuntimeMesh(UStaticMeshComponent* StaticMeshComponent, int32 LODIndex, URuntimeMesh* RuntimeMesh, bool bCreateCollision);
101 
103  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
104  static void CopyStaticMeshToRuntimeMeshComponent(UStaticMeshComponent* StaticMeshComponent, int32 LODIndex, URuntimeMeshComponent* RuntimeMeshComponent, bool bCreateCollision);
105 
106 
107  UFUNCTION(BlueprintCallable, Category = "Components|RuntimeMesh")
108  static void CopyCollisionFromStaticMesh(UStaticMesh* StaticMesh, URuntimeMesh* RuntimeMesh);
109 
110  static void CopyCollisionFromStaticMesh(UStaticMeshComponent* StaticMeshComponent, URuntimeMesh* RuntimeMesh)
111  {
112  CopyCollisionFromStaticMesh(StaticMeshComponent->GetStaticMesh(), RuntimeMesh);
113  }
114 
115 private:
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);
118 
119 
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);
123 
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);
127 
128 };
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
Definition: model-views.h:260
struct Index Index
Definition: sqlite3.c:11789


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:41