Added BlendTree that stores and blends multiple animations

This commit is contained in:
viktorljung
2016-02-22 15:58:38 +01:00
parent 3c9c95cff4
commit abd36c81f8
20 changed files with 641 additions and 453 deletions
+16 -17
View File
@@ -2,57 +2,56 @@
void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt)
{
if(!entity.HasComponent("Model")) {
return;
}
EntityWrapper parent = entity.FirstParentWithComponent("Model");
Model* model;
try {
model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]);
model = ResourceManager::Load<::Model, true>(parent["Model"]["Resource"]);
} catch (const std::exception&) {
return;
}
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
if(skeleton == nullptr) {
if (skeleton == nullptr) {
return;
}
for (int i = 1; i <= 3; i++) {
const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName" + std::to_string(i)]);
for (int i = 1; i <= 1; i++) {
const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["AnimationName"]);
if (animation == nullptr) {
continue;;
}
double animationSpeed = (double)animationComponent["Speed" + std::to_string(i)];
double animationSpeed = (double)animationComponent["Speed"];
if (animationSpeed != 0.0) {
double nextTime = (double)animationComponent["Time" + std::to_string(i)] + animationSpeed * dt;
double nextTime = (double)animationComponent["Time"] + animationSpeed * dt;
if (!(bool)animationComponent["Loop" + std::to_string(i)]) {
if (!(bool)animationComponent["Loop"]) {
if (nextTime > animation->Duration) {
nextTime = animation->Duration;
Events::AnimationComplete e;
e.Entity = entity;
e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)];
e.Name = (std::string)animationComponent["AnimationName"];
m_EventBroker->Publish(e);
} else if (nextTime < 0) {
Events::AnimationComplete e;
e.Entity = entity;
e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)];
e.Name = (std::string)animationComponent["AnimationName"];
m_EventBroker->Publish(e);
nextTime = 0;
}
(double&)animationComponent["Speed" + std::to_string(i)] = 0.0;
(double&)animationComponent["Speed"] = 0.0;
} else {
if (nextTime > animation->Duration) {
Events::AnimationComplete e;
e.Entity = entity;
e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)];
e.Name = (std::string)animationComponent["AnimationName"];
m_EventBroker->Publish(e);
while(nextTime > animation->Duration) {
@@ -61,7 +60,7 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
} else if (nextTime < 0) {
Events::AnimationComplete e;
e.Entity = entity;
e.Name = (std::string)animationComponent["AnimationName" + std::to_string(i)];
e.Name = (std::string)animationComponent["AnimationName"];
m_EventBroker->Publish(e);
while (nextTime < 0) {
@@ -70,7 +69,7 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
}
}
(double&)animationComponent["Time" + std::to_string(i)] = nextTime;
(double&)animationComponent["Time"] = nextTime;
}
}
}