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

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