1#include <Engine/Scene/SkeletonBasedAnimationSystem.hpp>
5#include <Core/Asset/FileData.hpp>
6#include <Core/Math/Math.hpp>
7#include <Core/Resources/Resources.hpp>
8#include <Core/Tasks/Task.hpp>
9#include <Core/Tasks/TaskQueue.hpp>
11#include <Engine/Data/Texture.hpp>
12#include <Engine/Data/TextureManager.hpp>
13#include <Engine/FrameInfo.hpp>
14#include <Engine/RadiumEngine.hpp>
15#include <Engine/Scene/SkeletonComponent.hpp>
16#include <Engine/Scene/SkinningComponent.hpp>
18using namespace Ra::Core::Animation;
27 auto* engine = RadiumEngine::getInstance();
28 auto* texMngr = engine->getTextureManager();
31 auto image = texMngr->loadTextureImage( *resourceDir +
"/Textures/heatmap.png" );
33 m_heatMapTextureHandle = texMngr->addTexture( heatMapTexturePamameters );
37SkeletonBasedAnimationSystem::~SkeletonBasedAnimationSystem() {
38 SkeletonComponent::s_boneMesh.reset();
39 SkeletonComponent::s_boneMaterial.reset();
40 SkeletonComponent::s_boneRenderTechnique.reset();
54 auto animTask = std::make_unique<Core::FunctionTask>(
55 animFunc,
"AnimatorTask_" + animComp->getSkeleton()->getName() );
61 auto animTask = std::make_unique<Core::FunctionTask>(
62 animFunc,
"AnimatorTask_" + animComp->getSkeleton()->getName() );
67 else if (
auto skinComp =
dynamic_cast<SkinningComponent*
>( compEntry.second ) ) {
69 auto skinTask = std::make_unique<Core::FunctionTask>(
70 skinFunc,
"SkinnerTask_" + skinComp->getMeshName() );
72 auto endTask = std::make_unique<Core::FunctionTask>(
73 endFunc,
"SkinnerEndTask_" + skinComp->getMeshName() );
87 const Core::Asset::FileData* fileData ) {
88 auto skelData = fileData->getHandleData();
89 auto animData = fileData->getAnimationData();
94 for (
const auto& skel : skelData ) {
96 component->handleSkeletonLoading( skel );
97 component->handleAnimationLoading( animData );
98 auto [s, e] = component->getAnimationTimeInterval();
99 startTime =
std::min( startTime, s );
101 component->setXray( m_xrayOn );
105 auto engine = RadiumEngine::getInstance();
106 engine->setStartTime( startTime );
107 engine->setEndTime( endTime );
110 auto geomData = fileData->getGeometryData();
111 if ( geomData.size() > 0 && skelData.size() > 0 ) {
112 for (
const auto& geom : geomData ) {
115 auto it =
std::find_if( skelData.begin(), skelData.end(), [&geom](
const auto& skel ) {
116 return std::find_if( skel->getBindMeshes().begin(),
117 skel->getBindMeshes().end(),
118 [&geom]( const auto& meshName ) {
119 return meshName == geom->getName();
120 } ) != skel->getBindMeshes().end();
122 if ( it != skelData.end() ) {
123 const auto& skel = *it;
135void SkeletonBasedAnimationSystem::setXray(
bool on ) {
137 for (
const auto& comp : m_components ) {
139 animComp->setXray( on );
144bool SkeletonBasedAnimationSystem::isXrayOn() {
148void SkeletonBasedAnimationSystem::toggleSkeleton(
const bool status ) {
149 for (
const auto& comp : m_components ) {
151 animComp->toggleSkeleton( status );
This class allows tasks to be registered and then executed in parallel on separate threads.
void addPendingDependency(const std::string &predecessors, TaskId successor)
void addDependency(TaskId predecessor, TaskId successor)
TaskId registerTask(std::unique_ptr< Task > task)
An entity is an scene element. It ties together components with a transform.
SkeletonBasedAnimationSystem()
Create a new animation system.
void handleAssetLoading(Entity *entity, const Core::Asset::FileData *fileData) override
Loads Skeletons and Animations from a file data into the givn Entity.
void generateTasks(Core::TaskQueue *taskQueue, const FrameInfo &frameInfo) override
Creates a task for each AnimationComponent to update skeleton display.
void update(Scalar time)
Updates the skeleton pose as the pose corresponding to time time.
void updateDisplay()
Updates the skeleton display.
The SkinningComponent class is responsible for applying Geometric Skinning Methods on an animated obj...
void endSkinning()
Update internal data and update the skinned mesh.
void handleSkinDataLoading(const Core::Asset::HandleData *data, const std::string &meshName)
@ LBS
Linear Blend Skinning.
void skin()
Apply the Skinning Method and update the SkinningFrameData.
std::vector< std::pair< const Entity *, Component * > > m_components
List of active components.
virtual void registerComponent(const Entity *entity, Component *component)
std::enable_if<!std::numeric_limits< T >::is_integer, bool >::type areApproxEqual(T x, T y, T espilonBoostFactor=T(10))
Compare two numbers such that |x-y| < espilon*epsilonBoostFactor.
optional< std::string > getRadiumResourcesPath()
Get the path of Radium internal resources.
hepler function to manage enum as underlying types in VariableSet
Describes the sampler and image of a texture.
Structure passed to each system before they fill the task queue.
Scalar m_animationTime
The current animation time.