1#include <Core/Animation/KeyFramedValue.hpp>
2#include <Core/Animation/Skeleton.hpp>
3#include <Core/Asset/FileData.hpp>
4#include <Core/Asset/GeometryData.hpp>
5#include <Core/Asset/HandleData.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>
10#include <Engine/Data/Texture.hpp>
11#include <Engine/Data/TextureManager.hpp>
12#include <Engine/FrameInfo.hpp>
13#include <Engine/RadiumEngine.hpp>
14#include <Engine/Scene/Component.hpp>
15#include <Engine/Scene/SkeletonBasedAnimationSystem.hpp>
16#include <Engine/Scene/SkeletonComponent.hpp>
17#include <Engine/Scene/SkinningComponent.hpp>
36using namespace Ra::Core::Animation;
45 auto* engine = RadiumEngine::getInstance();
46 auto* texMngr = engine->getTextureManager();
49 auto image = texMngr->loadTextureImage( *resourceDir +
"/Textures/heatmap.png" );
51 m_heatMapTextureHandle = texMngr->addTexture( heatMapTexturePamameters );
55SkeletonBasedAnimationSystem::~SkeletonBasedAnimationSystem() {
56 SkeletonComponent::s_boneMesh.reset();
57 SkeletonComponent::s_boneMaterial.reset();
58 SkeletonComponent::s_boneRenderTechnique.reset();
72 auto animTask = std::make_unique<Core::FunctionTask>(
73 animFunc,
"AnimatorTask_" + animComp->getSkeleton()->getName() );
79 auto animTask = std::make_unique<Core::FunctionTask>(
80 animFunc,
"AnimatorTask_" + animComp->getSkeleton()->getName() );
85 else if (
auto skinComp =
dynamic_cast<SkinningComponent*
>( compEntry.second ) ) {
87 auto skinTask = std::make_unique<Core::FunctionTask>(
88 skinFunc,
"SkinnerTask_" + skinComp->getMeshName() );
90 auto endTask = std::make_unique<Core::FunctionTask>(
91 endFunc,
"SkinnerEndTask_" + skinComp->getMeshName() );
105 const Core::Asset::FileData* fileData ) {
106 auto skelData = fileData->getHandleData();
107 auto animData = fileData->getAnimationData();
112 for (
const auto& skel : skelData ) {
114 component->handleSkeletonLoading( skel );
115 component->handleAnimationLoading( animData );
116 auto [s, e] = component->getAnimationTimeInterval();
117 startTime =
std::min( startTime, s );
119 component->setXray( m_xrayOn );
123 auto engine = RadiumEngine::getInstance();
124 engine->setStartTime( startTime );
125 engine->setEndTime( endTime );
128 auto geomData = fileData->getGeometryData();
129 if ( geomData.size() > 0 && skelData.size() > 0 ) {
130 for (
const auto& geom : geomData ) {
133 auto it =
std::find_if( skelData.begin(), skelData.end(), [&geom](
const auto& skel ) {
134 return std::find_if( skel->getBindMeshes().begin(),
135 skel->getBindMeshes().end(),
136 [&geom]( const auto& meshName ) {
137 return meshName == geom->getName();
138 } ) != skel->getBindMeshes().end();
140 if ( it != skelData.end() ) {
141 const auto& skel = *it;
153void SkeletonBasedAnimationSystem::setXray(
bool on ) {
155 for (
const auto& comp : m_components ) {
157 animComp->setXray( on );
153void SkeletonBasedAnimationSystem::setXray(
bool on ) {
…}
162bool SkeletonBasedAnimationSystem::isXrayOn() {
162bool SkeletonBasedAnimationSystem::isXrayOn() {
…}
166void SkeletonBasedAnimationSystem::toggleSkeleton(
const bool status ) {
167 for (
const auto& comp : m_components ) {
169 animComp->toggleSkeleton( status );
166void SkeletonBasedAnimationSystem::toggleSkeleton(
const bool 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.