Utility: Add a better way to attach objects to joints
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
// For conditions of distribution and use, see copyright notice in Config.hpp
|
||||
|
||||
#include <Nazara/Utility/Components/NodeComponent.hpp>
|
||||
#include <Nazara/Utility/Components/SharedSkeletonComponent.hpp>
|
||||
#include <Nazara/Utility/Components/SkeletonComponent.hpp>
|
||||
#include <Nazara/Core/Error.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
@@ -15,4 +17,32 @@ namespace Nz
|
||||
|
||||
Node::SetParent(nodeComponent, keepDerived);
|
||||
}
|
||||
|
||||
void NodeComponent::SetParentJoint(entt::handle entity, const std::string& jointName, bool keepDerived)
|
||||
{
|
||||
SkeletonComponentBase* skeletonComponent = entity.try_get<SkeletonComponent>();
|
||||
if (!skeletonComponent)
|
||||
skeletonComponent = entity.try_get<SharedSkeletonComponent>();
|
||||
|
||||
NazaraAssert(skeletonComponent, "entity doesn't have a SkeletonComponent nor a SharedSkeletonComponent");
|
||||
|
||||
std::size_t jointIndex = skeletonComponent->FindJointByName(jointName);
|
||||
if (jointIndex == Skeleton::InvalidJointIndex)
|
||||
{
|
||||
NazaraError("skeleton has no joint \"" + jointName + "\"");
|
||||
return;
|
||||
}
|
||||
|
||||
Node::SetParent(skeletonComponent->GetAttachedJoint(jointIndex), keepDerived);
|
||||
}
|
||||
|
||||
void NodeComponent::SetParentJoint(entt::handle entity, std::size_t jointIndex, bool keepDerived)
|
||||
{
|
||||
SkeletonComponentBase* skeletonComponent = entity.try_get<SkeletonComponent>();
|
||||
if (!skeletonComponent)
|
||||
skeletonComponent = entity.try_get<SharedSkeletonComponent>();
|
||||
|
||||
NazaraAssert(skeletonComponent, "entity doesn't have a SkeletonComponent nor a SharedSkeletonComponent");
|
||||
Node::SetParent(skeletonComponent->GetAttachedJoint(jointIndex), keepDerived);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user