Files
UnrealEngineUWP/Engine/Source/Runtime/AnimationCore/Public/BoneIndices.h
nicholas frechette 068c565a2c Use correct bone indices when using the new LOD pose API
Adding comments and clarifications
Minor tweaks

#rb Thomas.Sarkanen

[CL 28413374 by nicholas frechette in ue5-main branch]
2023-10-03 10:23:37 -04:00

187 lines
5.4 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
typedef uint16 FBoneIndexType;
struct FBoneIndexBase
{
FBoneIndexBase() : BoneIndex(INDEX_NONE) {}
FORCEINLINE int32 GetInt() const { return BoneIndex; }
FORCEINLINE bool IsRootBone() const { return BoneIndex == 0; }
FORCEINLINE bool IsValid() const { return BoneIndex != INDEX_NONE; }
FORCEINLINE explicit operator int32() const { return BoneIndex; }
FORCEINLINE explicit operator bool() const { return IsValid(); }
friend FORCEINLINE uint32 GetTypeHash(const FBoneIndexBase& Index) { return GetTypeHash(Index.BoneIndex); }
protected:
int32 BoneIndex;
};
FORCEINLINE int32 GetIntFromComp(const int32 InComp)
{
return InComp;
}
FORCEINLINE int32 GetIntFromComp(const FBoneIndexBase& InComp)
{
return InComp.GetInt();
}
template<class RealBoneIndexType>
struct FBoneIndexWithOperators : public FBoneIndexBase
{
// BoneIndexType
FORCEINLINE friend bool operator==(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) == GetIntFromComp(Rhs);
}
#if !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
FORCEINLINE friend bool operator!=(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) != GetIntFromComp(Rhs);
}
#endif // !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
FORCEINLINE friend bool operator>(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) > GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator>=(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) >= GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator<(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) < GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator<=(const RealBoneIndexType& Lhs, const RealBoneIndexType& Rhs)
{
return GetIntFromComp(Lhs) <= GetIntFromComp(Rhs);
}
// FBoneIndexType
FORCEINLINE friend bool operator==(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) == GetIntFromComp(Rhs);
}
#if !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
FORCEINLINE friend bool operator!=(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) != GetIntFromComp(Rhs);
}
#endif // !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
FORCEINLINE friend bool operator>(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) > GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator>=(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) >= GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator<(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) < GetIntFromComp(Rhs);
}
FORCEINLINE friend bool operator<=(const RealBoneIndexType& Lhs, const int32 Rhs)
{
return GetIntFromComp(Lhs) <= GetIntFromComp(Rhs);
}
#if !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
FORCEINLINE friend bool operator==(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs == Lhs;
}
FORCEINLINE friend bool operator!=(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs != Lhs;
}
FORCEINLINE friend bool operator>(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs < Lhs;
}
FORCEINLINE friend bool operator>=(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs <= Lhs;
}
FORCEINLINE friend bool operator<(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs > Lhs;
}
FORCEINLINE friend bool operator<=(const int32 Lhs, const RealBoneIndexType& Rhs)
{
return Rhs >= Lhs;
}
#endif // !PLATFORM_COMPILER_HAS_GENERATED_COMPARISON_OPERATORS
RealBoneIndexType& operator++()
{
++BoneIndex;
return *((RealBoneIndexType*)this);
}
RealBoneIndexType& operator--()
{
--BoneIndex;
return *((RealBoneIndexType*)this);
}
const RealBoneIndexType& operator=(const RealBoneIndexType& Rhs)
{
BoneIndex = Rhs.BoneIndex;
return Rhs;
}
};
// This represents a compact pose bone index. A compact pose is held by a bone container and can have a different ordering than either the skeleton or skeletal mesh.
struct FCompactPoseBoneIndex : public FBoneIndexWithOperators < FCompactPoseBoneIndex >
{
public:
explicit FCompactPoseBoneIndex(int32 InBoneIndex) { BoneIndex = InBoneIndex; }
};
// This represents a skeletal mesh bone index which may differ from the skeleton bone index it corresponds to.
struct FMeshPoseBoneIndex : public FBoneIndexWithOperators < FMeshPoseBoneIndex >
{
public:
explicit FMeshPoseBoneIndex(int32 InBoneIndex) { BoneIndex = InBoneIndex; }
};
// This represents a skeleton bone index which may differ from the skeletal mesh bone index it corresponds to.
struct FSkeletonPoseBoneIndex : public FBoneIndexWithOperators < FSkeletonPoseBoneIndex >
{
public:
explicit FSkeletonPoseBoneIndex(int32 InBoneIndex) { BoneIndex = InBoneIndex; }
};
template <typename ValueType>
struct TCompactPoseBoneIndexMapKeyFuncs : public TDefaultMapKeyFuncs<const FCompactPoseBoneIndex, ValueType, false>
{
static FORCEINLINE FCompactPoseBoneIndex GetSetKey(TPair<FCompactPoseBoneIndex, ValueType> const& Element) { return Element.Key; }
static FORCEINLINE uint32 GetKeyHash(FCompactPoseBoneIndex const& Key) { return GetTypeHash(Key.GetInt()); }
static FORCEINLINE bool Matches(FCompactPoseBoneIndex const& A, FCompactPoseBoneIndex const& B) { return (A.GetInt() == B.GetInt()); }
};