| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/Reference.h> |
| 8 |
#include <Jolt/Core/Result.h> |
| 9 |
#include <Jolt/ObjectStream/SerializableObject.h> |
| 10 |
|
| 11 |
JPH_NAMESPACE_BEGIN |
| 12 |
|
| 13 |
class StreamIn; |
| 14 |
class StreamOut; |
| 15 |
|
| 16 |
|
| 17 |
class JPH_EXPORT Skeleton : public RefTarget<Skeleton> |
| 18 |
{ |
| 19 |
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Skeleton) |
| 20 |
|
| 21 |
public: |
| 22 |
using SkeletonResult = Result<Ref<Skeleton>>; |
| 23 |
|
| 24 |
|
| 25 |
class Joint |
| 26 |
{ |
| 27 |
JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Joint) |
| 28 |
|
| 29 |
public: |
| 30 |
Joint() = default; |
| 31 |
Joint(const string_view &inName, const string_view &inParentName, int inParentJointIndex) : mName(inName), mParentName(inParentName), mParentJointIndex(inParentJointIndex) { } |
| 32 |
|
| 33 |
String mName; |
| 34 |
String mParentName; |
| 35 |
int mParentJointIndex = -1; |
| 36 |
}; |
| 37 |
|
| 38 |
using JointVector = Array<Joint>; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
const JointVector & GetJoints() const { return mJoints; } |
| 43 |
JointVector & GetJoints() { return mJoints; } |
| 44 |
int GetJointCount() const { return (int)mJoints.size(); } |
| 45 |
const Joint & GetJoint(int inJoint) const { return mJoints[inJoint]; } |
| 46 |
Joint & GetJoint(int inJoint) { return mJoints[inJoint]; } |
| 47 |
uint AddJoint(const string_view &inName, const string_view &inParentName = string_view()) { mJoints.emplace_back(inName, inParentName, -1); return (uint)mJoints.size() - 1; } |
| 48 |
uint AddJoint(const string_view &inName, int inParentIndex) { mJoints.emplace_back(inName, inParentIndex >= 0? mJoints[inParentIndex].mName : String(), inParentIndex); return (uint)mJoints.size() - 1; } |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
int GetJointIndex(const string_view &inName) const; |
| 53 |
|
| 54 |
|
| 55 |
void CalculateParentJointIndices(); |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
bool AreJointsCorrectlyOrdered() const; |
| 60 |
|
| 61 |
|
| 62 |
void SaveBinaryState(StreamOut &inStream) const; |
| 63 |
|
| 64 |
|
| 65 |
static SkeletonResult sRestoreFromBinaryState(StreamIn &inStream); |
| 66 |
|
| 67 |
private: |
| 68 |
|
| 69 |
JointVector mJoints; |
| 70 |
}; |
| 71 |
|
| 72 |
JPH_NAMESPACE_END |