Utility: Add a better way to attach objects to joints

This commit is contained in:
SirLynix
2022-08-30 18:31:04 +02:00
parent 45c947faf1
commit 7949c57f16
9 changed files with 67 additions and 20 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
};
}

View File

@@ -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;
};
}

View File

@@ -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;