5 #include "Engine/Engine.h" 6 #include "Components/MeshComponent.h" 7 #include "Runtime/Launch/Resources/Version.h" 8 #include "Stats/Stats.h" 9 #include "HAL/CriticalSection.h" 10 #include "RuntimeMeshCore.generated.h" 15 #define RUNTIMEMESH_MAXTEXCOORDS MAX_TEXCOORDS 17 #define RUNTIMEMESH_ENABLE_DEBUG_RENDERING (!(UE_BUILD_SHIPPING || UE_BUILD_TEST) || WITH_EDITOR) 44 const static FGuid
GUID = FGuid(0xEE48714B, 0x8A2C4652, 0x98BE40E6, 0xCB7EF0E6);
54 enum { IsValidIndexType =
false };
55 enum { Is32Bit =
false };
61 enum { IsValidIndexType =
true };
62 enum { Is32Bit =
false };
68 enum { IsValidIndexType =
true };
69 enum { Is32Bit =
true };
75 enum { IsValidIndexType =
true };
76 enum { Is32Bit =
true };
109 Average
UMETA(DisplayName =
"Average"),
111 Frequent
UMETA(DisplayName =
"Frequent"),
113 Infrequent
UMETA(DisplayName =
"Infrequent")
162 CollisionPerformance
UMETA(DisplayName =
"Collision Performance"),
168 CookingPerformance
UMETA(DisplayName =
"Cooking Performance"),
177 USTRUCT(BlueprintType)
183 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Tangent)
187 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Tangent)
191 : TangentX(1.
f, 0.
f, 0.
f)
192 , bFlipTangentY(false)
197 , bFlipTangentY(bInFlipTangentY)
201 : TangentX(InTangentX)
202 , bFlipTangentY(bInFlipTangentY)
205 void ModifyNormal(FVector4& Normal)
const { Normal.W = bFlipTangentY ? -1 : 1; }
206 void ModifyNormal(FPackedNormal& Normal)
const { Normal.Vector.W = bFlipTangentY ? 0 : MAX_uint8; }
207 void ModifyNormal(FPackedRGBA16N& Normal)
const { Normal.W = bFlipTangentY ? 0 : MAX_uint16; }
235 : Offset(InOffset), Stride(InStride), Type(InType) { }
237 bool IsValid()
const {
return Offset >= 0 && Stride >= 0 && Type != EVertexElementType::VET_None; }
248 int32 TypeValue =
static_cast<int32
>(Element.
Type);
250 Element.
Type =
static_cast<EVertexElementType
>(TypeValue);
256 #define RUNTIMEMESH_VERTEXSTREAMCOMPONENT(VertexType, Member, MemberType) \ 257 FRuntimeMeshVertexStreamStructureElement(STRUCT_OFFSET(VertexType,Member),sizeof(VertexType),MemberType) 265 TArray<FRuntimeMeshVertexStreamStructureElement, TInlineAllocator<RUNTIMEMESH_MAXTEXCOORDS>>
UVs;
271 bool HasAnyElements()
const;
275 uint8 CalculateStride()
const;
277 bool IsValid()
const;
288 Ar << Structure.
Color;
304 template<
typename VertexType>
307 return VertexType::GetVertexStructure();
333 virtual void Lock(
bool bIgnoreThreadIfNullLock =
false) = 0;
334 virtual void Unlock() = 0;
347 virtual void Lock(
bool bIgnoreThreadIfNullLock =
false)
override 349 bIsIgnoringLock = bIgnoreThreadIfNullLock;
350 if (!bIgnoreThreadIfNullLock)
352 check(IsInGameThread());
357 if (!bIsIgnoringLock)
359 check(IsInGameThread());
373 virtual void Lock(
bool bIgnoreThreadIfNullLock =
false)
override { SyncObject.Lock(); }
374 virtual void Unlock()
override { SyncObject.Unlock(); }
397 if (!bIsAlreadyLocked)
399 SynchObject->
Lock(bIgnoreThreadIfNullLock);
403 FRuntimeMeshScopeLock(
const TUniquePtr<FRuntimeMeshLockProvider>& InSyncObject,
bool bIsAlreadyLocked =
false,
bool bIgnoreThreadIfNullLock =
false)
404 : SynchObject(InSyncObject.
Get())
407 if (!bIsAlreadyLocked)
409 SynchObject->
Lock(bIgnoreThreadIfNullLock);
424 SynchObject =
nullptr;
449 template<
typename C, C>
struct ChT;
454 template<
typename C>
static char(&PositionCheck(...))[2];
459 template<
typename C>
static char(&NormalCheck(...))[2];
464 template<
typename C>
static char(&TangentCheck(...))[2];
469 template<
typename C>
static char(&ColorCheck(...))[2];
474 template<
typename C>
static char(&UV0Check(...))[2];
479 template<
typename C>
static char(&UV1Check(...))[2];
484 template<
typename C>
static char(&UV2Check(...))[2];
489 template<
typename C>
static char(&UV3Check(...))[2];
494 template<
typename C>
static char(&UV4Check(...))[2];
499 template<
typename C>
static char(&UV5Check(...))[2];
504 template<
typename C>
static char(&UV6Check(...))[2];
509 template<
typename C>
static char(&UV7Check(...))[2];
511 template<
typename A,
typename B>
523 template<
bool HasNormal,
bool HasTangent,
typename Type>
529 template<
typename Type>
535 template<
bool HasNormal,
typename Type>
541 template<
bool HasUV0,
typename Type>
547 template<
typename Type>
555 static const bool HasPosition =
sizeof(PositionCheck<DerivedPosition>(0)) == 2;
556 static const bool HasNormal =
sizeof(NormalCheck<DerivedNormal>(0)) == 2;
557 static const bool HasTangent =
sizeof(TangentCheck<DerivedTangent>(0)) == 2;
558 static const bool HasColor =
sizeof(ColorCheck<DerivedColor>(0)) == 2;
559 static const bool HasUV0 =
sizeof(UV0Check<DerivedUV0>(0)) == 2;
560 static const bool HasUV1 =
sizeof(UV1Check<DerivedUV1>(0)) == 2;
561 static const bool HasUV2 =
sizeof(UV2Check<DerivedUV2>(0)) == 2;
562 static const bool HasUV3 =
sizeof(UV3Check<DerivedUV3>(0)) == 2;
563 static const bool HasUV4 =
sizeof(UV4Check<DerivedUV4>(0)) == 2;
564 static const bool HasUV5 =
sizeof(UV5Check<DerivedUV5>(0)) == 2;
565 static const bool HasUV6 =
sizeof(UV6Check<DerivedUV6>(0)) == 2;
566 static const bool HasUV7 =
sizeof(UV7Check<DerivedUV7>(0)) == 2;
567 static const int32 NumUVChannels =
586 template<
typename VertexType0>
591 template<
typename VertexType0,
typename VertexType1>
596 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
604 template<
typename VertexType0>
609 template<
typename VertexType0,
typename VertexType1>
614 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
622 template<
typename VertexType0>
627 template<
typename VertexType0,
typename VertexType1>
632 template<
typename VertexType0,
typename VertexType1,
typename VertexType2>
void ModifyNormal(FPackedNormal &Normal) const
virtual void Unlock() override
FRuntimeMeshTangent(float X, float Y, float Z, bool bInFlipTangentY=false)
bool operator==(const plane &lhs, const plane &rhs)
bool operator!=(failed, failed)
virtual ~FRuntimeMeshMutexLockProvider()
virtual bool IsThreadSafe() const override
static bool IsUsingHighPrecisionTangents()
void ModifyNormal(FVector4 &Normal) const
FRuntimeMeshScopeLock(const TUniquePtr< FRuntimeMeshLockProvider > &InSyncObject, bool bIsAlreadyLocked=false, bool bIgnoreThreadIfNullLock=false)
ENUM_CLASS_FLAGS(ERuntimeMeshBuffersToUpdate)
FRuntimeMeshVertexStreamStructureElement Position
static bool IsUsingHighPrecisionTangents()
FRuntimeMeshVertexStreamStructure GetStreamStructure< FColor >()
virtual void Lock(bool bIgnoreThreadIfNullLock=false) override
std::ostream & operator<<(std::ostream &os, const textual_icon &i)
FRuntimeMeshLockProvider * SynchObject
FRuntimeMeshVertexStreamStructureElement Normal
virtual void Lock(bool bIgnoreThreadIfNullLock=false)=0
FRuntimeMeshTangent(FVector InTangentX, bool bInFlipTangentY=false)
FRuntimeMeshScopeLock(const FRuntimeMeshLockProvider *InSyncObject, bool bIsAlreadyLocked=false, bool bIgnoreThreadIfNullLock=false)
void ModifyNormal(FPackedRGBA16N &Normal) const
FRuntimeMeshVertexStreamStructureElement(uint8 InOffset, uint8 InStride, EVertexElementType InType)
static bool IsUsingHighPrecisionUVs()
UTexture2D * Get(TUniquePtr< T > &Dtex)
static const FRuntimeMeshVertexStreamStructure GetVertexStructure()
TArray< FRuntimeMeshVertexStreamStructureElement, TInlineAllocator< RUNTIMEMESH_MAXTEXCOORDS > > UVs
static const textual_icon check
FRuntimeMeshVertexStreamStructure GetStreamStructure< FVector >()
IMGUI_API void Value(const char *prefix, bool b)
static bool IsUsingHighPrecisionUVs()
virtual ~FRuntimeMeshLockProvider()
virtual void Unlock() override
virtual void Lock(bool bIgnoreThreadIfNullLock=false) override
virtual ~FRuntimeMeshNullLockProvider()
DECLARE_STATS_GROUP(TEXT("RuntimeMesh"), STATGROUP_RuntimeMesh, STATCAT_Advanced)
FRuntimeMeshVertexStreamStructureElement Color
static bool IsUsingHighPrecisionUVs()
ERuntimeMeshBuffersToUpdate
virtual bool IsThreadSafe() const
FRuntimeMeshMutexLockProvider()
FCriticalSection SyncObject
FRuntimeMeshVertexStreamStructure GetStreamStructure()
FRuntimeMeshScopeLock & operator=(FRuntimeMeshScopeLock &InScopeLock)
ERuntimeMeshCollisionCookingMode
static bool IsUsingHighPrecisionTangents()
FRuntimeMeshVertexStreamStructureElement()
FRuntimeMeshVertexStreamStructureElement Tangent
FRuntimeMeshNullLockProvider()