Merge remote-tracking branch 'origin/Animations'

This commit is contained in:
2016-01-24 23:06:59 +01:00
15 changed files with 276 additions and 33 deletions
+1 -1
Submodule assets updated: 068fbb2d20...5f3ab8b35d
@@ -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
@@ -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
+14
View File
@@ -13,6 +13,7 @@
#include "Camera.h" #include "Camera.h"
#include "../Core/World.h" #include "../Core/World.h"
#include "../Core/Transform.h" #include "../Core/Transform.h"
#include "Skeleton.h"
struct ModelJob : RenderJob struct ModelJob : RenderJob
{ {
@@ -37,6 +38,14 @@ struct ModelJob : RenderJob
glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1)); glm::vec3 worldpos = glm::vec3(camera->ViewMatrix() * glm::vec4(abspos, 1));
Depth = worldpos.z; Depth = worldpos.z;
World = world; 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; unsigned int TextureID;
@@ -51,6 +60,11 @@ struct ModelJob : RenderJob
float Shininess = 0.f; float Shininess = 0.f;
glm::vec4 Color; glm::vec4 Color;
const ::Model* Model = nullptr; const ::Model* Model = nullptr;
::Skeleton* Skeleton = nullptr;
const ::Skeleton::Animation* Animation = nullptr;
float AnimationTime = 0.f;
glm::vec4 DiffuseColor; glm::vec4 DiffuseColor;
glm::vec4 SpecularColor; glm::vec4 SpecularColor;
glm::vec4 IncandescenceColor; glm::vec4 IncandescenceColor;
+1 -4
View File
@@ -1,8 +1,6 @@
#ifndef PickingPass_h__ #ifndef PickingPass_h__
#define PickingPass_h__ #define PickingPass_h__
#include "IRenderer.h" #include "IRenderer.h"
#include "PickingPassState.h" #include "PickingPassState.h"
#include "FrameBuffer.h" #include "FrameBuffer.h"
@@ -10,8 +8,7 @@
#include "Util/UnorderedMapiVec2.h" #include "Util/UnorderedMapiVec2.h"
#include "../Core/EventBroker.h" #include "../Core/EventBroker.h"
#include "../Core/World.h" #include "../Core/World.h"
#include "Rendering/Skeleton.h"
class PickingPass class PickingPass
{ {
+1
View File
@@ -23,4 +23,5 @@
<xs:include schemaLocation="Components/Team.xsd"/> <xs:include schemaLocation="Components/Team.xsd"/>
<xs:include schemaLocation="Components/UniformScale.xsd"/> <xs:include schemaLocation="Components/UniformScale.xsd"/>
<xs:include schemaLocation="Components/EditorWidget.xsd"/> <xs:include schemaLocation="Components/EditorWidget.xsd"/>
<xs:include schemaLocation="Components/Animation.xsd"/>
</xs:schema> </xs:schema>
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Animation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Animation.xsd">
<Time>0</Time>
<Speed>0</Speed>
<Loop>true</Loop>
</Animation>
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:t="types">
<xs:import schemaLocation="../Types.xsd" namespace="types"/>
<xs:element name="Animation">
<xs:complexType>
<xs:all>
<xs:element name="Name" type="t:string" minOccurs="0"/>
<xs:element name="Time" type="t:double" minOccurs="0"/>
<xs:element name="Speed" type="t:double" minOccurs="0"/>
<xs:element name="Loop" type="t:bool" minOccurs="0"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entity name="GotToGoFast" xmlns:c="components" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Types/Entity.xsd">
<Components>
<c:Transform>
<Position X="0" Y="-0.00432979874" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Model>
<Resource>Models/Core/UnitSphere.mesh</Resource>
<Color A="1" B="1" G="39.2156868" R="392.15686"/>
</c:Model>
<c:RaptorCopter>
<Axis X="1.50000012" Y="-2.20000005" Z="2.10000014"/>
</c:RaptorCopter>
<c:Transform>
<Position X="0" Y="2.87819886" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Animation>
<Name>Crouch Walk</Name>
<Time>701.10570384634161</Time>
<Speed>32</Speed>
</c:Animation>
<c:Model>
<Resource>Models/AssaultAnimated.mesh</Resource>
<Color A="1" B="392156.875" G="1" R="1"/>
</c:Model>
<c:Transform>
<Position X="0" Y="0.5" Z="0"/>
</c:Transform>
</Components>
<Children>
<Entity>
<Components>
<c:Text>
<Content>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 </Content>
<Resource>Fonts/DroidSans.ttf,60</Resource>
<Color A="0" B="0.972549021" G="3.92156863" R="39.2156868"/>
<Alignment>
<Left/>
</Alignment>
</c:Text>
<c:Transform>
<Position X="0.245514169" Y="0.817000031" Z="-0.883219421"/>
<Scale X="0.300000012" Y="0.300000012" Z="1"/>
<Orientation X="0" Y="1.52600002" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
</Children>
</Entity>
<Entity>
<Components>
<c:DirectionalLight/>
<c:Transform/>
</Components>
<Children/>
</Entity>
</Children>
</Entity>
+41 -9
View File
@@ -8,9 +8,7 @@
<Children> <Children>
<Entity> <Entity>
<Components> <Components>
<c:Camera> <c:Camera/>
<Name>ActionCamera</Name>
</c:Camera>
<c:Model> <c:Model>
<Resource>Models/Camera.mesh</Resource> <Resource>Models/Camera.mesh</Resource>
</c:Model> </c:Model>
@@ -25,7 +23,9 @@
<c:Text> <c:Text>
<Content>Camera #2</Content> <Content>Camera #2</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource> <Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>0</Alignment> <Alignment>
<Right/>
</Alignment>
</c:Text> </c:Text>
<c:Transform> <c:Transform>
<Position X="0.700063765" Y="0.310270816" Z="-1"/> <Position X="0.700063765" Y="0.310270816" Z="-1"/>
@@ -64,6 +64,7 @@
<c:Text> <c:Text>
<Content>Welcome!</Content> <Content>Welcome!</Content>
<Resource>Fonts/DroidSans.ttf,1280</Resource> <Resource>Fonts/DroidSans.ttf,1280</Resource>
<Color A="0" B="1" G="7.84313726" R="1"/>
</c:Text> </c:Text>
<c:Transform> <c:Transform>
<Position X="0" Y="0" Z="0.700000048"/> <Position X="0" Y="0" Z="0.700000048"/>
@@ -79,7 +80,7 @@
</c:RaptorCopter> </c:RaptorCopter>
<c:Transform> <c:Transform>
<Position X="0" Y="2.37320328" Z="0"/> <Position X="0" Y="2.37320328" Z="0"/>
<Orientation X="0" Y="8252.15918" Z="0"/> <Orientation X="0" Y="9868.3418" Z="0"/>
</c:Transform> </c:Transform>
</Components> </Components>
<Children> <Children>
@@ -200,9 +201,7 @@
</Entity> </Entity>
<Entity> <Entity>
<Components> <Components>
<c:Camera> <c:Camera/>
<Name>MainCamera</Name>
</c:Camera>
<c:Listener/> <c:Listener/>
<c:Model> <c:Model>
<Resource>Models/Camera.mesh</Resource> <Resource>Models/Camera.mesh</Resource>
@@ -219,7 +218,9 @@
<c:Text> <c:Text>
<Content>Taiwan #1</Content> <Content>Taiwan #1</Content>
<Resource>Fonts/DroidSans.ttf,64</Resource> <Resource>Fonts/DroidSans.ttf,64</Resource>
<Alignment>0</Alignment> <Alignment>
<Right/>
</Alignment>
</c:Text> </c:Text>
<c:Transform> <c:Transform>
<Position X="0.716896772" Y="0.296712071" Z="-1"/> <Position X="0.716896772" Y="0.296712071" Z="-1"/>
@@ -257,6 +258,37 @@
</Components> </Components>
<Children/> <Children/>
</Entity> </Entity>
<Entity>
<Components>
<c:Animation/>
<c:Model>
<Resource>asd</Resource>
<Color A="1" B="1" G="3.92156863" R="1"/>
</c:Model>
<c:Transform>
<Position X="0" Y="0" Z="-6.38434124"/>
<Orientation X="5.046" Y="0" Z="0"/>
</c:Transform>
</Components>
<Children/>
</Entity>
<Entity>
<Components>
<c:Animation>
<Name>running</Name>
<Time>0.93047409991569907</Time>
<Speed>1</Speed>
</c:Animation>
<c:Model>
<Resource>Models/Animtest.mesh</Resource>
<Color A="1" B="11.7647057" G="1" R="11.7647057"/>
</c:Model>
<c:Transform>
<Position X="-1.42184281" Y="1.71298718" Z="-6.31712198"/>
</c:Transform>
</Components>
<Children/>
</Entity>
</Children> </Children>
</Entity> </Entity>
+12 -8
View File
@@ -3,18 +3,15 @@
uniform mat4 M; uniform mat4 M;
uniform mat4 V; uniform mat4 V;
uniform mat4 P; uniform mat4 P;
uniform mat4 Bones[100];
layout(location = 0) in vec3 Position; layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal; layout(location = 1) in vec3 Normal;
layout(location = 2) in vec3 Tangent; layout(location = 2) in vec3 Tangent;
layout(location = 3) in vec3 BiTangent; layout(location = 3) in vec3 BiTangent;
layout(location = 4) in vec2 TextureCoords; layout(location = 4) in vec2 TextureCoords;
layout(location = 5) in vec4 DiffuseVertexColor; layout(location = 5) in vec4 BoneIndices;
layout(location = 6) in vec4 SpecularVertexColor; layout(location = 6) in vec4 BoneWeights;
layout(location = 7) in vec4 BoneIndices1;
layout(location = 8) in vec4 BoneIndices2;
layout(location = 9) in vec4 BoneWeights1;
layout(location = 10) in vec4 BoneWeights2;
out VertexData{ out VertexData{
vec3 Position; vec3 Position;
@@ -22,7 +19,14 @@ out VertexData{
void main() 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;
} }
+47
View File
@@ -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;
}
}
}
}
}
+3 -6
View File
@@ -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 :) //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) { if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running");
if (animation != nullptr) { if (modelJob->Animation != nullptr) {
std::vector<glm::mat4> frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones( std::vector<glm::mat4> frameBones = modelJob->Skeleton->GetFrameBones( *modelJob->Animation, modelJob->AnimationTime);
*animation,
0.0f
);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0])); glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
} }
} }
+13 -5
View File
@@ -48,7 +48,7 @@ void PickingPass::Draw(RenderScene& scene)
PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle()); PickingPassState* state = new PickingPassState(m_PickingBuffer.GetHandle());
//TODO: Render: Add code for more jobs than modeljobs. //TODO: Render: Add code for more jobs than modeljobs.
GLuint ShaderHandle = m_PickingProgram->GetHandle(); GLuint shaderHandle = m_PickingProgram->GetHandle();
m_PickingProgram->Bind(); m_PickingProgram->Bind();
if (scene.ClearDepth) { if (scene.ClearDepth) {
@@ -83,10 +83,18 @@ void PickingPass::Draw(RenderScene& scene)
m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo; m_PickingColorsToEntity[glm::ivec2(pickColor[0], pickColor[1])] = pickInfo;
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix)); 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, "V"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(scene.Camera->ProjectionMatrix())); 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]))); 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<glm::mat4> 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); glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
+2
View File
@@ -10,6 +10,7 @@
#include "Core/EntityFileWriter.h" #include "Core/EntityFileWriter.h"
#include "Game/Systems/CapturePointSystem.h" #include "Game/Systems/CapturePointSystem.h"
#include "Game/Systems/WeaponSystem.h" #include "Game/Systems/WeaponSystem.h"
#include "../Engine/Rendering/AnimationSystem.h"
Game::Game(int argc, char* argv[]) Game::Game(int argc, char* argv[])
{ {
@@ -86,6 +87,7 @@ Game::Game(int argc, char* argv[])
// Populate Octree with collidables // Populate Octree with collidables
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollidableOctreeSystem>(updateOrderLevel, m_OctreeCollision);
m_SystemPipeline->AddSystem<AnimationSystem>(updateOrderLevel);
// Collision and TriggerSystem should update after player. // Collision and TriggerSystem should update after player.
++updateOrderLevel; ++updateOrderLevel;
m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision); m_SystemPipeline->AddSystem<CollisionSystem>(updateOrderLevel, m_OctreeCollision);