AnimationSystem working
This commit is contained in:
@@ -7,25 +7,29 @@ void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& a
|
||||
}
|
||||
|
||||
Model* model = ResourceManager::Load<Model>(entity["Model"]["Resource"]);
|
||||
//Skeleton* skeleton = model->m_Skeleton;
|
||||
//auto animation == skeleton->GetAnimation(animation["Name"]);
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["Name"]);
|
||||
|
||||
double animationSpeed = (double)animationComponent["Speed"];
|
||||
|
||||
if( animationSpeed != 0.0) {
|
||||
double nextTime = (double)animationComponent["Time"] + animationSpeed * dt;
|
||||
|
||||
if (!animationComponent["Loop"] && glm::abs(nextTime) > animation->Duration) {
|
||||
|
||||
if (!(bool)animationComponent["Loop"] && glm::abs(nextTime) > animation->Duration) {
|
||||
(double&)animationComponent["Time"] = glm::sign(nextTime) * animation->Duration;
|
||||
(double&)animationComponent["Speed"] = 0.0;
|
||||
Events::AnimationComplete e;
|
||||
e.Entity = entity;
|
||||
// e.Name = animationComponent->Name;
|
||||
e.Name = (std::string)animationComponent["Name"];
|
||||
m_EventBroker->Publish(e);
|
||||
} else {
|
||||
(double&)animationComponent["Time"] = nextTime;
|
||||
if (glm::abs(nextTime) > animation->Duration) {
|
||||
(double&)animationComponent["Time"] = glm::abs(nextTime) - animation->Duration;
|
||||
} else {
|
||||
(double&)animationComponent["Time"] = nextTime;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -96,12 +96,9 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
|
||||
//TODO: Fixa så att modelsJobs kan spela upp olika animationer och så att den kan få in en tid istället för 1.0f - Hälsningar Johan och Andreas :)
|
||||
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running");
|
||||
if (animation != nullptr) {
|
||||
std::vector<glm::mat4> frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones(
|
||||
*animation,
|
||||
0.0f
|
||||
);
|
||||
|
||||
if (modelJob->Animation != nullptr) {
|
||||
std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones( *modelJob->Animation, modelJob->AnimationTime);
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user