8#include "Containers/Array.h"
11#include "Containers/Set.h"
35static constexpr uint16 MaxRawBoneWeight = std::numeric_limits<uint16>::max();
38static constexpr float MaxRawBoneWeightFloat =
static_cast<float>(std::numeric_limits<uint16>::max());
41static constexpr float InvMaxRawBoneWeightFloat = 1.0f / MaxRawBoneWeightFloat;
45static constexpr float BoneWeightThreshold = InvMaxRawBoneWeightFloat;
79 return A.GetRawWeight() >
B.GetRawWeight();
182 return FString::Printf(
TEXT(
"<%d, %g>"), BoneIndex,
GetWeight());
191 return static_cast<int32>(
static_cast<uint16>(BoneIndex) << 16 | RawWeight);
210static_assert(
sizeof(FBoneWeight) ==
sizeof(
int32),
"FBoneWeight must be 32-bits");
264 WeightThreshold = FMath::Max(WeightThreshold,
static_cast<uint16>(1));
279 return WeightThreshold;
287 bHasDefaultBoneIndex =
true;
295 return DefaultBoneIndex;
302 bHasDefaultBoneIndex =
false;
309 return bHasDefaultBoneIndex;
325 return bBlendZeroInfluence;
330 int32 MaxWeightCount = MaxInlineBoneWeightCount;
331 uint16 WeightThreshold = 1;
333 bool bHasDefaultBoneIndex =
false;
334 bool bBlendZeroInfluence =
true;
373 template<
typename Predicate>
378 template<
typename Predicate>
388template<
typename ContainerAdapter>
398 template<
typename OtherContainerAdapter,
typename CT = ContainerType>
399 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
404 template<
typename CT = ContainerType>
405 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
410 template<
typename CT = ContainerType>
411 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
419 template<
typename CT = ContainerType>
420 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
426 template<
typename CT = ContainerType>
427 inline typename std::enable_if<!std::is_const<CT>::value,
bool>::type
433 template<
typename CT = ContainerType>
434 inline typename std::enable_if<!std::is_const<CT>::value,
bool>::type
440 template<
typename CT = ContainerType>
441 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
451 template<
typename ContainerTypeA,
typename ContainerTypeB,
typename CT = ContainerType>
452 inline typename std::enable_if<!std::is_const<CT>::value,
void>::type
461 return ContainerAdapter::Num(Container);
466 return ContainerAdapter::Get(Container,
Index);
471 return ContainerAdapter::Get(Container,
Index);
478 return Container.IndexOfByPredicate(
494 FString Result(
TEXT(
"["));
500 Result +=
TEXT(
", ");
509 inline void SetBoneWeightsInternal(
513 inline void SortWeights();
514 inline bool CullWeights(
const FBoneWeightsSettings&
InSettings);
517 inline bool Verify()
const;
533 using ContainerType = T;
565 template<
typename Predicate>
571 template<
typename Predicate>
653 template<
typename OtherContainerAdapter>
659 FArrayWrapper W(Result.BoneWeights);
738 FString Result(
TEXT(
"["));
748 BoneWeightArrayT BoneWeights;
753template<
typename ContainerAdapter>
754template<
typename OtherContainerAdapter,
typename CT>
755typename std::enable_if<!std::is_const<CT>::value,
void>::type
765 if (
BW.GetRawWeight() >=
InSettings.GetRawWeightThreshold())
774template<
typename ContainerAdapter>
776typename std::enable_if<!std::is_const<CT>::value,
void>::type
786 if (
BW.GetRawWeight() >=
InSettings.GetRawWeightThreshold())
796template<
typename ContainerAdapter>
798typename std::enable_if<!std::is_const<CT>::value,
void>::type
811 if (
BW.GetRawWeight() >=
InSettings.GetRawWeightThreshold())
821template<
typename ContainerAdapter>
823typename std::enable_if<!std::is_const<CT>::value,
void>::type
834 if (
BW.GetRawWeight() >=
InSettings.GetRawWeightThreshold())
842 int32 WeightIndex = 0;
846 if (
BW.GetRawWeight() >=
InSettings.GetRawWeightThreshold())
848 ContainerAdapter::Set(
Container, WeightIndex++,
BW);
855 if (WeightIndex >
InSettings.GetMaxWeightCount())
860 NormalizeWeights(
InSettings.GetNormalizeType());
864template<
typename ContainerAdapter>
873 if (NumEntries == 0 &&
InSettings.HasDefaultBoneIndex())
880 ContainerAdapter::SetNum(
Container, NumEntries);
886 NormalizeWeights(
InSettings.GetNormalizeType());
889template<
typename ContainerAdapter>
891typename std::enable_if<!std::is_const<CT>::value,
bool>::type
910 ContainerAdapter::Remove(
Container, WeightIndex);
975template<
typename ContainerAdapter>
977typename std::enable_if<!std::is_const<CT>::value,
bool>::type
989 ContainerAdapter::Remove(
Container, WeightIndex);
1005template<
typename ContainerAdapter>
1006template<
typename CT>
1007typename std::enable_if<!std::is_const<CT>::value,
void>::type
1012 NormalizeWeights(
InSettings.GetNormalizeType());
1022template<
typename ContainerAdapter>
1023template<
typename ContainerAdapterA,
typename ContainerAdapterB,
typename CT>
1024typename std::enable_if<!std::is_const<CT>::value,
void>::type
1086 BoneWeights.
Emplace(
BW.GetBoneIndex(), RawWeight);
1091 BoneWeights.
Add(
BW);
1095 int32 IndexA = 0, IndexB = 0;
1105 if (
BWA.GetBoneIndex() ==
BWB.GetBoneIndex())
1109 BoneWeights.
Emplace(
BWA.GetBoneIndex(), RawWeight);
1113 else if (
BWA.GetBoneIndex() <
BWB.GetBoneIndex())
1134 SetBoneWeightsInternal(BoneWeights,
InSettings);
1138template<
typename ContainerAdapter>
1145template<
typename ContainerAdapter>
1146bool TBoneWeights<ContainerAdapter>::CullWeights(
1150 bool bCulled =
false;
1173template<
typename ContainerAdapter>
1174void TBoneWeights<ContainerAdapter>::NormalizeWeights(
1192 FBoneWeight BoneWeight = ContainerAdapter::Get(
Container, 0);
1194 ContainerAdapter::Set(
Container, 0, BoneWeight);
1245template<
typename ContainerAdapter>
1249 if (NumEntries == 0)
1288static auto WeightSortPredicate = [](
const FBoneWeight&
A,
const FBoneWeight&
B) {
1289 return A.GetRawWeight() >
B.GetRawWeight();
1411static inline uint32 GetTypeHash(
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define ensure( InExpression)
Definition AssertionMacros.h:464
uint16 FBoneIndexType
Definition BoneIndices.h:7
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
FArchive & operator<<(FArchive &Ar, FEnvQueryDebugProfileData::FStep &Data)
Definition EnvQueryTypes.cpp:489
#define MAX_TOTAL_INFLUENCES
Definition GPUSkinPublicDefs.h:12
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
Definition Archive.h:1208
virtual void Serialize(void *V, int64 Length)
Definition Archive.h:1689
Definition ArrayView.h:139
constexpr void Sort()
Definition ArrayView.h:773
constexpr SizeType IndexOfByPredicate(Predicate Pred) const
Definition ArrayView.h:644
UE_FORCEINLINE_HINT constexpr ElementType * end() const
Definition ArrayView.h:760
UE_FORCEINLINE_HINT constexpr SizeType Num() const
Definition ArrayView.h:380
UE_FORCEINLINE_HINT constexpr ElementType * begin() const
Definition ArrayView.h:759
TCheckedPointerIterator< const ElementType, SizeType, false > RangedForConstIteratorType
Definition Array.h:3372
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType &&... Args)
Definition Array.h:2561
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void SetNumUninitialized(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2369
UE_FORCEINLINE_HINT void Reserve(SizeType Number)
Definition Array.h:3016
Definition ContainerAllocationPolicies.h:894
Definition BoneWeights.h:48
FString ToString() const
Definition BoneWeights.h:180
bool operator!=(const FBoneWeight &InBoneWeight) const
Definition BoneWeights.h:63
int32 ToInt32() const
Definition BoneWeights.h:189
FBoneWeight(FBoneIndexType InBoneIndex, uint8 InWeight)
Definition BoneWeights.h:89
FBoneWeight(FBoneIndexType InBoneIndex, uint16 InRawWeight)
Definition BoneWeights.h:99
void SetWeight(float InWeight)
Definition BoneWeights.h:134
void Serialize(FArchive &InArchive)
Definition BoneWeights.h:165
uint16 GetRawWeight() const
Definition BoneWeights.h:160
bool operator==(const FBoneWeight &InBoneWeight) const
Definition BoneWeights.h:54
static constexpr uint16 GetMaxRawWeight()
Definition BoneWeights.h:71
FBoneIndexType GetBoneIndex() const
Definition BoneWeights.h:125
static FBoneWeight FromInt32(int32 InBoneWeight)
Definition BoneWeights.h:197
FBoneWeight(FBoneIndexType InBoneIndex, float InWeight)
Definition BoneWeights.h:108
static bool DescSortByWeightPredicate(const FBoneWeight &A, const FBoneWeight &B)
Definition BoneWeights.h:77
uint32 GetTypeHash() const
Definition BoneWeights.h:172
void SetBoneIndex(FBoneIndexType InBoneIndex)
Definition BoneWeights.h:117
float GetWeight() const
Definition BoneWeights.h:143
void SetRawWeight(const uint16 InRawWeight)
Definition BoneWeights.h:151
Definition BoneWeights.h:229
void SetBlendZeroInfluence(bool bInBlendZeroInfluence)
Definition BoneWeights.h:316
FBoneWeightsSettings()=default
void ClearDefaultBoneIndex()
Definition BoneWeights.h:300
void SetDefaultBoneIndex(FBoneIndexType InBoneIndex)
Definition BoneWeights.h:284
FBoneIndexType GetDefaultBoneIndex() const
Definition BoneWeights.h:293
EBoneWeightNormalizeType GetNormalizeType() const
Definition BoneWeights.h:241
bool GetBlendZeroInfluence() const
Definition BoneWeights.h:323
int32 GetMaxWeightCount() const
Definition BoneWeights.h:253
FBoneWeightsSettings & SetWeightThreshold(float InWeightThreshold)
Definition BoneWeights.h:260
FBoneWeightsSettings & SetMaxWeightCount(int32 InMaxWeightCount)
Definition BoneWeights.h:246
FBoneWeightsSettings & SetNormalizeType(EBoneWeightNormalizeType InNormalizeType)
Definition BoneWeights.h:234
bool HasDefaultBoneIndex() const
Definition BoneWeights.h:307
uint16 GetRawWeightThreshold() const
Definition BoneWeights.h:277
float GetWeightThreshold() const
Definition BoneWeights.h:269
A simple container for per-vertex influence of bones and their weights.
Definition BoneWeights.h:526
static FBoneWeights Create(TBoneWeights< OtherContainerAdapter > InBoneWeights, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:654
TArrayView< const FBoneWeight > ToArrayView() const
Definition BoneWeights.h:705
RangedForConstIteratorType begin() const
Definition BoneWeights.h:689
static FBoneWeights Create(const FBoneIndexType InBones[MaxInlineBoneWeightCount], const uint16 InWeights[MaxInlineBoneWeightCount], const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1320
int32 FindWeightIndexByBone(FBoneIndexType InBoneIndex) const
Definition BoneWeights.h:715
int32 GetTypeHash() const
Definition BoneWeights.h:726
bool operator!=(const FBoneWeights &InBoneWeight) const
Definition BoneWeights.h:596
int32 Num() const
Definition BoneWeights.h:695
void Renormalize(const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1313
bool SetBoneWeight(FBoneIndexType InBone, float InWeight, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:612
const FBoneWeight & operator[](int32 Index) const
Definition BoneWeights.h:702
RangedForConstIteratorType end() const
Definition BoneWeights.h:690
void Serialize(FArchive &InArchive)
Definition BoneWeights.h:721
FString ToString() const
Definition BoneWeights.h:736
bool RemoveBoneWeight(FBoneIndexType InBone, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1303
static FBoneWeights Blend(const FBoneWeights &InA, const FBoneWeights &InB, float InBias, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1358
bool SetBoneWeight(FBoneWeight InBoneWeight, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1293
bool operator==(const FBoneWeights &InBoneWeight) const
Definition BoneWeights.h:587
Definition BoneWeights.h:390
typename ContainerAdapter::ContainerType ContainerType
Definition BoneWeights.h:392
std::enable_if<!std::is_const< CT >::value, void >::type SetBoneWeights(const FBoneIndexType InBones[MaxInlineBoneWeightCount], const uint16 InInfluences[MaxInlineBoneWeightCount], const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:824
FString ToString() const
Definition BoneWeights.h:492
FBoneWeight Get(int32 Index) const
Definition BoneWeights.h:464
std::enable_if<!std::is_const< CT >::value, void >::type SetBoneWeights(TArrayView< const FBoneWeight > BoneWeights, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:777
int32 Num() const
Definition BoneWeights.h:459
std::enable_if<!std::is_const< CT >::value, bool >::type RemoveBoneWeight(FBoneIndexType InBoneIndex, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:978
std::enable_if<!std::is_const< CT >::value, void >::type Renormalize(const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:1008
std::enable_if<!std::is_const< CT >::value, void >::type Blend(const TBoneWeights< ContainerTypeA > &InBoneWeightsA, const TBoneWeights< ContainerTypeB > &InBoneWeightsB, float InBias, const FBoneWeightsSettings &InSettings={})
FBoneWeight operator[](int32 Index) const
Definition BoneWeights.h:469
std::enable_if<!std::is_const< CT >::value, void >::type SetBoneWeights(const FBoneIndexType *InBones, const float *InInfluences, int32 NumEntries, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:799
std::enable_if<!std::is_const< CT >::value, bool >::type AddBoneWeight(FBoneWeight InBoneWeight, const FBoneWeightsSettings &InSettings={})
Definition BoneWeights.h:892
TBoneWeights(ContainerType &InContainer)
Definition BoneWeights.h:394
int32 FindWeightIndexByBone(FBoneIndexType InBoneIndex) const
Definition BoneWeights.h:474
int32 GetTypeHash() const
Definition BoneWeights.h:482
std::enable_if<!std::is_const< CT >::value, void >::type SetBoneWeights(const TBoneWeights< OtherContainerAdapter > &InBoneWeights, const FBoneWeightsSettings &InSettings={})
TBoneWeights implementation.
Definition BoneWeights.h:756
UE_STRING_CLASS & Append(const CharType *Str, int32 Count)
Definition UnrealString.h.inl:417
Definition AngularLimit.cpp:6
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
EBoneWeightNormalizeType
Definition BoneWeights.h:216
Definition AdvancedWidgetsModule.cpp:13
U16 Index
Definition radfft.cpp:71
static constexpr UE_FORCEINLINE_HINT T Clamp(const T X, const T MinValue, const T MaxValue)
Definition UnrealMathUtility.h:592
static UE_FORCEINLINE_HINT bool IsNearlyZero(float Value, float ErrorTolerance=UE_SMALL_NUMBER)
Definition UnrealMathUtility.h:407
Definition NumericLimits.h:41
Definition BoneWeights.h:341
Definition BoneWeights.h:340
static FBoneWeight Get(const ContainerType &InContainer, int32 InIndex)
Definition BoneWeights.h:356
static void Set(ContainerType &InContainer, int32 InIndex, FBoneWeight InBoneWeight)
Definition BoneWeights.h:361
static void Remove(ContainerType &InContainer, int32 InIndex)
Definition BoneWeights.h:369
static int32 Num(const ContainerType &InContainer)
Definition BoneWeights.h:351
static int32 IndexOf(const ContainerType &InContainer, Predicate InPredicate)
Definition BoneWeights.h:379
static void SetNum(ContainerType &InContainer, int32 InNum)
Definition BoneWeights.h:347
static void Sort(ContainerType &InContainer, Predicate InPredicate)
Definition BoneWeights.h:374
static void Add(ContainerType &InContainer, FBoneWeight InBoneWeight)
Definition BoneWeights.h:365