Path: blob/master/thirdparty/jolt_physics/Jolt/Skeleton/Skeleton.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/Core/Reference.h>7#include <Jolt/Core/Result.h>8#include <Jolt/ObjectStream/SerializableObject.h>910JPH_NAMESPACE_BEGIN1112class StreamIn;13class StreamOut;1415/// Resource that contains the joint hierarchy for a skeleton16class JPH_EXPORT Skeleton : public RefTarget<Skeleton>17{18JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Skeleton)1920public:21using SkeletonResult = Result<Ref<Skeleton>>;2223/// Declare internal structure for a joint24class Joint25{26JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, Joint)2728public:29Joint() = default;30Joint(const string_view &inName, const string_view &inParentName, int inParentJointIndex) : mName(inName), mParentName(inParentName), mParentJointIndex(inParentJointIndex) { }3132String mName; ///< Name of the joint33String mParentName; ///< Name of parent joint34int mParentJointIndex = -1; ///< Index of parent joint (in mJoints) or -1 if it has no parent35};3637using JointVector = Array<Joint>;3839///@name Access to the joints40///@{41const JointVector & GetJoints() const { return mJoints; }42JointVector & GetJoints() { return mJoints; }43int GetJointCount() const { return (int)mJoints.size(); }44const Joint & GetJoint(int inJoint) const { return mJoints[inJoint]; }45Joint & GetJoint(int inJoint) { return mJoints[inJoint]; }46uint AddJoint(const string_view &inName, const string_view &inParentName = string_view()) { mJoints.emplace_back(inName, inParentName, -1); return (uint)mJoints.size() - 1; }47uint AddJoint(const string_view &inName, int inParentIndex) { mJoints.emplace_back(inName, inParentIndex >= 0? mJoints[inParentIndex].mName : String(), inParentIndex); return (uint)mJoints.size() - 1; }48///@}4950/// Find joint by name51int GetJointIndex(const string_view &inName) const;5253/// Fill in parent joint indices based on name54void CalculateParentJointIndices();5556/// Many of the algorithms that use the Skeleton class require that parent joints are in the mJoints array before their children.57/// This function returns true if this is the case, false if not.58bool AreJointsCorrectlyOrdered() const;5960/// Saves the state of this object in binary form to inStream.61void SaveBinaryState(StreamOut &inStream) const;6263/// Restore the state of this object from inStream.64static SkeletonResult sRestoreFromBinaryState(StreamIn &inStream);6566private:67/// Joints68JointVector mJoints;69};7071JPH_NAMESPACE_END727374