5 #include "CoreMinimal.h" 22 TArray<FVector2D, TInlineAllocator<RUNTIMEMESH_MAXTEXCOORDS>>
UVs;
30 static const int32 PositionStride = 12;
41 static const int32 ColorStride = 4;
46 TArray<uint8>* PositionStreamData, TArray<uint8>* TangentStreamData, TArray<uint8>* UVStreamData, TArray<uint8>* ColorStreamData,
bool bInIsReadonly =
false);
50 FRuntimeMeshVerticesAccessor(TArray<uint8>* PositionStreamData, TArray<uint8>* TangentStreamData, TArray<uint8>* UVStreamData, TArray<uint8>* ColorStreamData,
bool bInIsReadonly);
52 void Initialize(
bool bInTangentsHighPrecision,
bool bInUVsHighPrecision, int32 bInUVCount);
60 int32 NumVertices()
const;
61 int32 NumUVChannels()
const;
63 void EmptyVertices(int32 Slack = 0);
64 void SetNumVertices(int32 NewNum);
66 int32 AddVertex(FVector InPosition);
68 FVector GetPosition(int32
Index)
const;
69 FVector4 GetNormal(int32 Index)
const;
70 FVector GetTangent(int32 Index)
const;
71 FColor GetColor(int32 Index)
const;
72 FVector2D GetUV(int32 Index, int32 Channel = 0)
const;
75 void SetPosition(int32 Index,
const FVector&
Value);
76 bool SetPositions(
const int32 InsertAtIndex,
const TArray<FVector>& Positions,
const int32 Count,
const bool bSizeToFit);
77 bool SetPositions(
const int32 InsertAtIndex,
const FVector *
const Positions,
const int32 Count,
const bool bSizeToFit);
78 void SetNormal(int32 Index,
const FVector4& Value);
79 void SetTangent(int32 Index,
const FVector& Value);
81 void SetColor(int32 Index,
const FColor& Value);
82 bool SetColors(
const int32 InsertAtIndex,
const TArray<FColor>& Colors,
const int32 Count,
const bool bSizeToFit);
83 bool SetColors(
const int32 InsertAtIndex,
const FColor *
const Colors,
const int32 Count,
const bool bSizeToFit);
84 void SetUV(int32 Index,
const FVector2D& Value);
85 void SetUV(int32 Index, int32 Channel,
const FVector2D& Value);
100 bool SetUVs(
const int32 InsertAtVertexIndex,
const TArray<FVector2D>& UVs,
const int32 CountVertices,
const bool bSizeToFit);
101 bool SetUVs(
const int32 InsertAtVertexIndex,
const TArray<FVector2DHalf>& UVs,
const int32 CountVertices,
const bool bSizeToFit);
117 bool SetUVs(
const int32 InsertAtVertexIndex,
const FVector2D *
const UVs,
const int32 CountVertices,
const bool bSizeToFit);
118 bool SetUVs(
const int32 InsertAtVertexIndex,
const FVector2DHalf *
const UVs,
const int32 CountVertices,
const bool bSizeToFit);
121 void SetTangents(int32 Index, FVector TangentX, FVector TangentY, FVector TangentZ);
130 template<
typename Type>
133 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 20 134 return Input.ToFVector4();
140 template<
typename Type>
143 #if ENGINE_MAJOR_VERSION >= 4 && ENGINE_MINOR_VERSION >= 20 144 return Input.ToFVector();
150 template<
typename Type>
151 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasPosition>
::Type 154 SetPosition(Index, Vertex.Position);
157 template<
typename Type>
158 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasPosition>
::Type 163 template<
typename Type>
164 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasNormal>
::Type 167 SetNormal(Index, ConvertPackedToNormal(Vertex.Normal));
170 template<
typename Type>
171 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasNormal>
::Type 176 template<
typename Type>
177 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasTangent>
::Type 180 SetTangent(Index, ConvertPackedToTangent(Vertex.Tangent));
183 template<
typename Type>
184 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasTangent>
::Type 189 template<
typename Type>
190 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasColor>
::Type 193 SetColor(Index, Vertex.Color);
196 template<
typename Type>
197 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasColor>
::Type 205 template<
typename Type>
206 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV0>
::Type 209 SetUV(Index, 0, Vertex.UV0);
212 template<
typename Type>
213 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV0>
::Type 218 template<
typename Type>
219 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV1>
::Type 222 SetUV(Index, 1, Vertex.UV1);
225 template<
typename Type>
226 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV1>
::Type 231 template<
typename Type>
232 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV2>
::Type 235 SetUV(Index, 2, Vertex.UV2);
238 template<
typename Type>
239 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV2>
::Type 244 template<
typename Type>
245 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV3>
::Type 248 SetUV(Index, 3, Vertex.UV3);
251 template<
typename Type>
252 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV3>
::Type 257 template<
typename Type>
258 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV4>
::Type 261 SetUV(Index, 4, Vertex.UV4);
264 template<
typename Type>
265 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV4>
::Type 270 template<
typename Type>
271 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV5>
::Type 274 SetUV(Index, 5, Vertex.UV5);
277 template<
typename Type>
278 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV5>
::Type 283 template<
typename Type>
284 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV6>
::Type 287 SetUV(Index, 6, Vertex.UV6);
290 template<
typename Type>
291 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV6>
::Type 296 template<
typename Type>
297 typename TEnableIf<FRuntimeMeshVertexTraits<Type>::HasUV7>
::Type 300 SetUV(Index, 7, Vertex.UV7);
303 template<
typename Type>
304 typename TEnableIf<!FRuntimeMeshVertexTraits<Type>::HasUV7>
::Type 314 template<
typename VertexType>
317 SetPositionValue(Index, Vertex);
318 SetNormalValue(Index, Vertex);
319 SetTangentValue(Index, Vertex);
320 SetColorValue(Index, Vertex);
322 SetUV0Value(Index, Vertex);
323 SetUV1Value(Index, Vertex);
324 SetUV2Value(Index, Vertex);
325 SetUV3Value(Index, Vertex);
326 SetUV4Value(Index, Vertex);
327 SetUV5Value(Index, Vertex);
328 SetUV6Value(Index, Vertex);
329 SetUV7Value(Index, Vertex);
332 template<
typename VertexType0>
335 int32 NewIndex = AddSingleVertex();
336 SetVertexProperties(NewIndex, Vertex0);
339 template<
typename VertexType0,
typename VertexType1>
342 int32 NewIndex = AddSingleVertex();
343 SetVertexProperties(NewIndex, Vertex0);
344 SetVertexProperties(NewIndex, Vertex1);
347 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
350 int32 NewIndex = AddSingleVertex();
351 SetVertexProperties(NewIndex, Vertex0);
352 SetVertexProperties(NewIndex, Vertex1);
353 SetVertexProperties(NewIndex, Vertex2);
361 bIsInitialized =
false;
362 PositionStream =
nullptr;
363 TangentStream =
nullptr;
365 ColorStream =
nullptr;
368 int32 AddSingleVertex();
374 inline FVector4 FRuntimeMeshVerticesAccessor::ConvertPackedToNormal<FVector4>(
const FVector4&
Input)
379 inline FVector FRuntimeMeshVerticesAccessor::ConvertPackedToTangent<FVector>(
const FVector&
Input)
399 void Initialize(
bool bIn32BitIndices);
407 int32 NumIndices()
const;
408 void EmptyIndices(int32 Slack = 0);
409 void SetNumIndices(int32 NewNum);
410 int32 AddIndex(int32 NewIndex);
411 int32 AddTriangle(int32 Index0, int32 Index1, int32 Index2);
413 int32 GetIndex(int32
Index)
const;
414 void SetIndex(int32 Index, int32
Value);
415 bool SetIndices(
const int32 InsertAtIndex,
const TArray<uint16>& Indices,
const int32 Count,
const bool bSizeToFit);
416 bool SetIndices(
const int32 InsertAtIndex,
const uint16 *
const Indices,
const int32 Count,
const bool bSizeToFit);
417 bool SetIndices(
const int32 InsertAtIndex,
const TArray<int32>& Indices,
const int32 Count,
const bool bSizeToFit);
418 bool SetIndices(
const int32 InsertAtIndex,
const int32 *
const Indices,
const int32 Count,
const bool bSizeToFit);
422 FORCEINLINE int32
GetIndexStride()
const {
return b32BitIndices ?
sizeof(int32) :
sizeof(uint16); }
426 bIsInitialized =
false;
427 IndexStream =
nullptr;
441 FRuntimeMeshAccessor(
bool bInTangentsHighPrecision,
bool bInUVsHighPrecision, int32 bInUVCount,
bool bIn32BitIndices, TArray<uint8>* PositionStreamData,
442 TArray<uint8>* TangentStreamData, TArray<uint8>* UVStreamData, TArray<uint8>* ColorStreamData, TArray<uint8>* IndexStreamData,
bool bInIsReadonly =
false);
446 FRuntimeMeshAccessor(TArray<uint8>* PositionStreamData, TArray<uint8>* TangentStreamData, TArray<uint8>* UVStreamData, TArray<uint8>* ColorStreamData, TArray<uint8>* IndexStreamData,
bool bInIsReadonly);
448 void Initialize(
bool bInTangentsHighPrecision,
bool bInUVsHighPrecision, int32 bInUVCount,
bool bIn32BitIndices);
453 void CopyTo(
const TSharedPtr<FRuntimeMeshAccessor>& Other,
bool bClearDestination =
false)
const;
478 FRuntimeMeshBuilder(
bool bInTangentsHighPrecision,
bool bInUVsHighPrecision, int32 bInUVCount,
bool bIn32BitIndices);
498 TArray<uint8>* TangentStreamData, TArray<uint8>* UVStreamData, TArray<uint8>* ColorStreamData, TArray<uint8>* IndexStreamData,
FRuntimeMeshLockProvider* InSyncObject,
bool bIsReadonly);
503 void Commit(
bool bNeedsPositionUpdate =
true,
bool bNeedsNormalTangentUpdate =
true,
bool bNeedsColorUpdate =
true,
bool bNeedsUVUpdate =
true,
bool bNeedsIndexUpdate =
true);
504 void Commit(
const FBox& BoundingBox,
bool bNeedsPositionUpdate =
true,
bool bNeedsNormalTangentUpdate =
true,
bool bNeedsColorUpdate =
true,
bool bNeedsUVUpdate =
true,
bool bNeedsIndexUpdate =
true);
513 template<
typename TangentType,
typename UVType,
typename IndexType>
516 bool bIsUsingHighPrecisionUVs;
518 GetUVVertexProperties<UVType>(bIsUsingHighPrecisionUVs,
NumUVChannels);
523 FORCEINLINE TSharedRef<FRuntimeMeshBuilder>
MakeRuntimeMeshBuilder(
bool bUsingHighPrecisionTangents,
bool bUsingHighPrecisionUVs, int32 NumUVs,
bool bUsing32BitIndices)
525 return MakeShared<FRuntimeMeshBuilder>(bUsingHighPrecisionTangents, bUsingHighPrecisionUVs, NumUVs, bUsing32BitIndices);
528 FORCEINLINE TSharedRef<FRuntimeMeshBuilder>
MakeRuntimeMeshBuilder(
const TSharedRef<const FRuntimeMeshAccessor>& StructureToCopy)
530 return MakeShared<FRuntimeMeshBuilder>(StructureToCopy->IsUsingHighPrecisionTangents(), StructureToCopy->IsUsingHighPrecisionUVs(), StructureToCopy->NumUVChannels(), StructureToCopy->IsUsing32BitIndices());
533 FORCEINLINE TSharedRef<FRuntimeMeshBuilder>
MakeRuntimeMeshBuilder(
const TUniquePtr<const FRuntimeMeshAccessor>& StructureToCopy)
535 return MakeShared<FRuntimeMeshBuilder>(StructureToCopy->IsUsingHighPrecisionTangents(), StructureToCopy->IsUsingHighPrecisionUVs(), StructureToCopy->NumUVChannels(), StructureToCopy->IsUsing32BitIndices());
void AddVertexByProperties(const VertexType0 &Vertex0, const VertexType1 &Vertex1)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV6 >::Type SetUV6Value(int32 Index, const Type &Vertex)
TArray< uint8 > * UVStream
bool IsUsing32BitIndices() const
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasColor >::Type SetColorValue(int32 Index, const Type &Vertex)
TArray< uint8 > * TangentStream
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasColor >::Type SetColorValue(int32 Index, const Type &Vertex)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV3 >::Type SetUV3Value(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV3 >::Type SetUV3Value(int32 Index, const Type &Vertex)
TArray< uint8 > * ColorStream
TArray< uint8 > & GetIndexStream()
ESectionUpdateFlags UpdateFlags
TArray< uint8 > & GetUVStream()
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV7 >::Type SetUV7Value(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV5 >::Type SetUV5Value(int32 Index, const Type &Vertex)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV1 >::Type SetUV1Value(int32 Index, const Type &Vertex)
const bool IsReadonly() const
void Initialize(bool bIn32BitIndices)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV2 >::Type SetUV2Value(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV2 >::Type SetUV2Value(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV0 >::Type SetUV0Value(int32 Index, const Type &Vertex)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV5 >::Type SetUV5Value(int32 Index, const Type &Vertex)
FORCEINLINE int32 GetIndexStride() const
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasNormal >::Type SetNormalValue(int32 Index, const Type &Vertex)
TSharedPtr< FRuntimeMeshData, ESPMode::ThreadSafe > FRuntimeMeshDataPtr
TArray< uint8 > PositionStream
FVector4 ConvertPackedToNormal(const Type &Input)
TArray< uint8 > TangentStream
void SetVertexProperties(int32 Index, const VertexType &Vertex)
const bool bTangentHighPrecision
TArray< uint8 > & GetColorStream()
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasTangent >::Type SetTangentValue(int32 Index, const Type &Vertex)
const bool IsUsingHighPrecisionUVs() const
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV4 >::Type SetUV4Value(int32 Index, const Type &Vertex)
const bool IsUsingHighPrecisionTangents() const
FVector ConvertPackedToTangent(const Type &Input)
IMGUI_API void Value(const char *prefix, bool b)
TArray< uint8 > * IndexStream
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV7 >::Type SetUV7Value(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV6 >::Type SetUV6Value(int32 Index, const Type &Vertex)
TArray< FVector2D, TInlineAllocator< RUNTIMEMESH_MAXTEXCOORDS > > UVs
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasPosition >::Type SetPositionValue(int32 Index, const Type &Vertex)
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV4 >::Type SetUV4Value(int32 Index, const Type &Vertex)
void AddVertexByProperties(const VertexType0 &Vertex0, const VertexType1 &Vertex1, const VertexType2 &Vertex2)
void AddVertexByProperties(const VertexType0 &Vertex0)
const bool IsReadonly() const
TArray< uint8 > * PositionStream
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasUV1 >::Type SetUV1Value(int32 Index, const Type &Vertex)
const int32 UVChannelCount
TArray< uint8 > IndexStream
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasPosition >::Type SetPositionValue(int32 Index, const Type &Vertex)
TArray< uint8 > ColorStream
TArray< uint8 > & GetPositionStream()
FRuntimeMeshDataPtr LinkedMeshData
const bool bUVHighPrecision
FORCEINLINE TSharedRef< FRuntimeMeshBuilder > MakeRuntimeMeshBuilder()
TEnableIf< FRuntimeMeshVertexTraits< Type >::HasNormal >::Type SetNormalValue(int32 Index, const Type &Vertex)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasUV0 >::Type SetUV0Value(int32 Index, const Type &Vertex)
TEnableIf<!FRuntimeMeshVertexTraits< Type >::HasTangent >::Type SetTangentValue(int32 Index, const Type &Vertex)
const int32 TangentStride
TSharedPtr< FRuntimeMeshSection, ESPMode::ThreadSafe > FRuntimeMeshSectionPtr
TArray< uint8 > & GetTangentStream()
int32 NumUVChannels() const