Utility: Add a better way to attach objects to joints
This commit is contained in:
@@ -22,6 +22,8 @@ namespace Nz
|
||||
~NodeComponent() = default;
|
||||
|
||||
void SetParent(entt::handle entity, bool keepDerived = false);
|
||||
void SetParentJoint(entt::handle entity, const std::string& jointName, bool keepDerived = false);
|
||||
void SetParentJoint(entt::handle entity, std::size_t jointIndex, bool keepDerived = false);
|
||||
using Node::SetParent;
|
||||
|
||||
NodeComponent& operator=(const NodeComponent&) = default;
|
||||
|
||||
@@ -23,12 +23,11 @@ namespace Nz
|
||||
SharedSkeletonComponent(SharedSkeletonComponent&& sharedSkeletalComponent) noexcept;
|
||||
~SharedSkeletonComponent() = default;
|
||||
|
||||
const Joint& GetAttachedJoint(std::size_t jointIndex) const override;
|
||||
|
||||
SharedSkeletonComponent& operator=(const SharedSkeletonComponent& sharedSkeletalComponent);
|
||||
SharedSkeletonComponent& operator=(SharedSkeletonComponent&& sharedSkeletalComponent) noexcept;
|
||||
|
||||
private:
|
||||
const Skeleton& GetAttachedSkeleton() const override;
|
||||
inline bool IsAttachedSkeletonOutdated() const;
|
||||
void OnReferenceJointsInvalidated(const Skeleton* skeleton);
|
||||
void SetSkeletonParent(Node* parent);
|
||||
|
||||
@@ -23,11 +23,13 @@ namespace Nz
|
||||
SkeletonComponent(SkeletonComponent&& skeletalComponent) noexcept = default;
|
||||
~SkeletonComponent() = default;
|
||||
|
||||
const Joint& GetAttachedJoint(std::size_t jointIndex) const override;
|
||||
Node* GetRootNode();
|
||||
|
||||
SkeletonComponent& operator=(const SkeletonComponent&) = delete;
|
||||
SkeletonComponent& operator=(SkeletonComponent&& skeletalComponent) noexcept = default;
|
||||
|
||||
private:
|
||||
const Skeleton& GetAttachedSkeleton() const override;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace Nz
|
||||
SkeletonComponentBase(SkeletonComponentBase&&) noexcept = default;
|
||||
~SkeletonComponentBase() = default;
|
||||
|
||||
virtual const Joint& GetAttachedJoint(std::size_t jointIndex) const = 0;
|
||||
inline std::size_t FindJointByName(const std::string& jointName) const;
|
||||
|
||||
inline const Joint& GetAttachedJoint(std::size_t jointIndex) const;
|
||||
inline const std::shared_ptr<Skeleton>& GetSkeleton() const;
|
||||
|
||||
SkeletonComponentBase& operator=(const SkeletonComponentBase&) = default;
|
||||
@@ -29,6 +31,8 @@ namespace Nz
|
||||
protected:
|
||||
SkeletonComponentBase(std::shared_ptr<Skeleton> skeleton);
|
||||
|
||||
virtual const Skeleton& GetAttachedSkeleton() const = 0;
|
||||
|
||||
std::shared_ptr<Skeleton> m_referenceSkeleton;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,6 +12,16 @@ namespace Nz
|
||||
{
|
||||
}
|
||||
|
||||
inline std::size_t SkeletonComponentBase::FindJointByName(const std::string& jointName) const
|
||||
{
|
||||
return m_referenceSkeleton->GetJointIndex(jointName);
|
||||
}
|
||||
|
||||
inline const Joint& SkeletonComponentBase::GetAttachedJoint(std::size_t jointIndex) const
|
||||
{
|
||||
return *GetAttachedSkeleton().GetJoint(jointIndex);
|
||||
}
|
||||
|
||||
inline const std::shared_ptr<Skeleton>& SkeletonComponentBase::GetSkeleton() const
|
||||
{
|
||||
return m_referenceSkeleton;
|
||||
|
||||
Reference in New Issue
Block a user