diff --git a/assets b/assets
index 068fbb2d..5f3ab8b3 160000
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit 068fbb2d20682dd60f186c82172d7731e60ed7e9
+Subproject commit 5f3ab8b35ddce150e972445fb2894fb9e9637258
diff --git a/include/Engine/Rendering/AnimationSystem.h b/include/Engine/Rendering/AnimationSystem.h
new file mode 100644
index 00000000..fcdcbc92
--- /dev/null
+++ b/include/Engine/Rendering/AnimationSystem.h
@@ -0,0 +1,29 @@
+#ifndef AnimationSystem_h__
+#define AnimationSystem_h__
+
+#include "GLM.h"
+
+#include "Common.h"
+#include "Core/System.h"
+#include "Core/ResourceManager.h"
+#include "Rendering/Model.h"
+#include "Rendering/EAnimationComplete.h"
+#include "Rendering/Skeleton.h"
+
+class AnimationSystem : public PureSystem
+{
+public:
+ AnimationSystem(World* world, EventBroker* eventBroker)
+ : System(world, eventBroker)
+ , PureSystem("Animation")
+ {
+
+ }
+ ~AnimationSystem() { }
+ virtual void UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt) override;
+private:
+
+
+};
+
+#endif
\ No newline at end of file
diff --git a/include/Engine/Rendering/EAnimationComplete.h b/include/Engine/Rendering/EAnimationComplete.h
new file mode 100644
index 00000000..00519a38
--- /dev/null
+++ b/include/Engine/Rendering/EAnimationComplete.h
@@ -0,0 +1,18 @@
+#ifndef Events_AnimationComplete_h__
+#define Events_AnimationComplete_h__
+
+#include "../Core/EventBroker.h"
+#include "../Core/EntityWrapper.h"
+
+namespace Events
+{
+
+struct AnimationComplete : Event
+{
+ EntityWrapper Entity;
+ std::string Name;
+};
+
+}
+
+#endif
diff --git a/include/Engine/Rendering/ModelJob.h b/include/Engine/Rendering/ModelJob.h
index 01f4cca4..32d89293 100644
--- a/include/Engine/Rendering/ModelJob.h
+++ b/include/Engine/Rendering/ModelJob.h
@@ -13,6 +13,7 @@
#include "Camera.h"
#include "../Core/World.h"
#include "../Core/Transform.h"
+#include "Skeleton.h"
struct ModelJob : RenderJob
{
@@ -37,6 +38,14 @@ struct ModelJob : RenderJob
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z;
World = world;
+
+ Skeleton = Model->m_RawModel->m_Skeleton;
+
+ if (world->HasComponent(Entity, "Animation") && Skeleton != nullptr) {
+ auto animationComponent = world->GetComponent(Entity, "Animation");
+ Animation = model->m_RawModel->m_Skeleton->GetAnimation(animationComponent["Name"]);
+ AnimationTime = (double)animationComponent["Time"];
+ }
};
unsigned int TextureID;
@@ -51,6 +60,11 @@ struct ModelJob : RenderJob
float Shininess = 0.f;
glm::vec4 Color;
const ::Model* Model = nullptr;
+ ::Skeleton* Skeleton = nullptr;
+ const ::Skeleton::Animation* Animation = nullptr;
+
+ float AnimationTime = 0.f;
+
glm::vec4 DiffuseColor;
glm::vec4 SpecularColor;
glm::vec4 IncandescenceColor;
diff --git a/include/Engine/Rendering/PickingPass.h b/include/Engine/Rendering/PickingPass.h
index 5fc88982..da3ed31b 100644
--- a/include/Engine/Rendering/PickingPass.h
+++ b/include/Engine/Rendering/PickingPass.h
@@ -1,8 +1,6 @@
#ifndef PickingPass_h__
#define PickingPass_h__
-
-
#include "IRenderer.h"
#include "PickingPassState.h"
#include "FrameBuffer.h"
@@ -10,8 +8,7 @@
#include "Util/UnorderedMapiVec2.h"
#include "../Core/EventBroker.h"
#include "../Core/World.h"
-
-
+#include "Rendering/Skeleton.h"
class PickingPass
{
diff --git a/resources/Schema/Components.xsd b/resources/Schema/Components.xsd
index 12d94611..d663f695 100644
--- a/resources/Schema/Components.xsd
+++ b/resources/Schema/Components.xsd
@@ -23,4 +23,5 @@
+
\ No newline at end of file
diff --git a/resources/Schema/Components/Animation.xml b/resources/Schema/Components/Animation.xml
new file mode 100644
index 00000000..01af2747
--- /dev/null
+++ b/resources/Schema/Components/Animation.xml
@@ -0,0 +1,6 @@
+
+
+
+ 0
+ true
+
\ No newline at end of file
diff --git a/resources/Schema/Components/Animation.xsd b/resources/Schema/Components/Animation.xsd
new file mode 100644
index 00000000..0dd21f29
--- /dev/null
+++ b/resources/Schema/Components/Animation.xsd
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/resources/Schema/Entities/FastWorld.xml b/resources/Schema/Entities/FastWorld.xml
new file mode 100644
index 00000000..68d1dccb
--- /dev/null
+++ b/resources/Schema/Entities/FastWorld.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Models/Core/UnitSphere.mesh
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Crouch Walk
+
+ 32
+
+
+ Models/AssaultAnimated.mesh
+
+
+
+
+
+
+
+
+
+
+ pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew pew
+ Fonts/DroidSans.ttf,60
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/Schema/Entities/RenderingWorld.xml b/resources/Schema/Entities/RenderingWorld.xml
index 796a66f0..e860fd04 100644
--- a/resources/Schema/Entities/RenderingWorld.xml
+++ b/resources/Schema/Entities/RenderingWorld.xml
@@ -8,9 +8,7 @@
-
- ActionCamera
-
+
Models/Camera.mesh
@@ -25,7 +23,9 @@
Camera #2
Fonts/DroidSans.ttf,64
- 0
+
+
+
@@ -64,6 +64,7 @@
Welcome!
Fonts/DroidSans.ttf,1280
+
@@ -79,7 +80,7 @@
-
+
@@ -200,9 +201,7 @@
-
- MainCamera
-
+
Models/Camera.mesh
@@ -219,7 +218,9 @@
Taiwan #1
Fonts/DroidSans.ttf,64
- 0
+
+
+
@@ -257,6 +258,37 @@
+
+
+
+
+ asd
+
+
+
+
+
+
+
+
+
+
+
+
+ running
+
+ 1
+
+
+ Models/Animtest.mesh
+
+
+
+
+
+
+
+
diff --git a/resources/Shaders/Picking.vert.glsl b/resources/Shaders/Picking.vert.glsl
index b2857cea..205a8fdd 100644
--- a/resources/Shaders/Picking.vert.glsl
+++ b/resources/Shaders/Picking.vert.glsl
@@ -3,18 +3,15 @@
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
+uniform mat4 Bones[100];
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 Tangent;
layout(location = 3) in vec3 BiTangent;
layout(location = 4) in vec2 TextureCoords;
-layout(location = 5) in vec4 DiffuseVertexColor;
-layout(location = 6) in vec4 SpecularVertexColor;
-layout(location = 7) in vec4 BoneIndices1;
-layout(location = 8) in vec4 BoneIndices2;
-layout(location = 9) in vec4 BoneWeights1;
-layout(location = 10) in vec4 BoneWeights2;
+layout(location = 5) in vec4 BoneIndices;
+layout(location = 6) in vec4 BoneWeights;
out VertexData{
vec3 Position;
@@ -22,7 +19,14 @@ out VertexData{
void main()
{
- gl_Position = P * V* M * vec4(Position, 1.0);
+ mat4 boneTransform = mat4(1);
+ if(BoneWeights[0] > 0.0f){
+ boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
+ + BoneWeights[1] * Bones[int(BoneIndices[1])]
+ + BoneWeights[2] * Bones[int(BoneIndices[2])]
+ + BoneWeights[3] * Bones[int(BoneIndices[3])];
+ }
- Output.Position = Position;
+ gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
+ Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
}
\ No newline at end of file
diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp
new file mode 100644
index 00000000..2126362f
--- /dev/null
+++ b/src/Engine/Rendering/AnimationSystem.cpp
@@ -0,0 +1,47 @@
+#include "Rendering/AnimationSystem.h"
+
+void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt)
+{
+ if(!entity.HasComponent("Model")) {
+ return;
+ }
+
+ Model* model;
+ try {
+ model = ResourceManager::Load<::Model, true>(entity["Model"]["Resource"]);
+ } catch (const std::exception&) {
+ return;
+ }
+
+
+ Skeleton* skeleton = model->m_RawModel->m_Skeleton;
+ const Skeleton::Animation* animation = skeleton->GetAnimation(animationComponent["Name"]);
+
+ if(animation != nullptr) {
+ double animationSpeed = (double)animationComponent["Speed"];
+
+ if (animationSpeed != 0.0) {
+ double nextTime = (double)animationComponent["Time"] + animationSpeed * dt;
+
+
+ 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 = (std::string)animationComponent["Name"];
+ m_EventBroker->Publish(e);
+ } else {
+ if (glm::abs(nextTime) > animation->Duration) {
+ (double&)animationComponent["Time"] = glm::abs(nextTime) - animation->Duration;
+ } else {
+ (double&)animationComponent["Time"] = nextTime;
+ }
+ }
+ }
+ }
+
+
+
+}
+
diff --git a/src/Engine/Rendering/DrawFinalPass.cpp b/src/Engine/Rendering/DrawFinalPass.cpp
index ca2a9d77..9abf69d3 100644
--- a/src/Engine/Rendering/DrawFinalPass.cpp
+++ b/src/Engine/Rendering/DrawFinalPass.cpp
@@ -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 frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones(
- *animation,
- 0.0f
- );
+
+ if (modelJob->Animation != nullptr) {
+ std::vector frameBones = modelJob->Skeleton->GetFrameBones( *modelJob->Animation, modelJob->AnimationTime);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
}
}
diff --git a/src/Engine/Rendering/PickingPass.cpp b/src/Engine/Rendering/PickingPass.cpp
index 3f8dd9b0..c7e23479 100644
--- a/src/Engine/Rendering/PickingPass.cpp
+++ b/src/Engine/Rendering/PickingPass.cpp
@@ -48,7 +48,7 @@ void PickingPass::Draw(RenderScene& scene)
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
//TODO: Render: Add code for more jobs than modeljobs.
- GLuint ShaderHandle = m_PickingProgram->GetHandle();
+ GLuint shaderHandle = m_PickingProgram->GetHandle();
m_PickingProgram->Bind();
if (scene.ClearDepth) {
@@ -83,10 +83,18 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
- glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
- glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
- glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
- glUniform2fv(glGetUniformLocation(ShaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
+ glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
+ glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
+ glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix()));
+ glUniform2fv(glGetUniformLocation(shaderHandle, "PickingColor"), 1, glm::value_ptr(glm::vec2(pickColor[0], pickColor[1])));
+
+ if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
+
+ if (modelJob->Animation != nullptr) {
+ std::vector frameBones = modelJob->Skeleton->GetFrameBones(*modelJob->Animation, modelJob->AnimationTime);
+ glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
+ }
+ }
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
diff --git a/src/Game/Game.cpp b/src/Game/Game.cpp
index 5de61b8c..5ae5ddd5 100644
--- a/src/Game/Game.cpp
+++ b/src/Game/Game.cpp
@@ -10,6 +10,7 @@
#include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h"
+#include "../Engine/Rendering/AnimationSystem.h"
Game::Game(int argc, char* argv[])
{
@@ -86,6 +87,7 @@ Game::Game(int argc, char* argv[])
// Populate Octree with collidables
++updateOrderLevel;
m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision);
+ m_SystemPipeline->AddSystem(updateOrderLevel);
// Collision and TriggerSystem should update after player.
++updateOrderLevel;
m_SystemPipeline->AddSystem(updateOrderLevel, m_OctreeCollision);