AnimationSystem base WIP
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
#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"
|
||||||
|
|
||||||
|
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
|
||||||
@@ -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>
|
||||||
@@ -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>
|
||||||
@@ -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.obj</Resource>
|
<Resource>Models/Camera.obj</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"/>
|
||||||
@@ -79,7 +79,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="8903.9668" Z="0"/>
|
||||||
</c:Transform>
|
</c:Transform>
|
||||||
</Components>
|
</Components>
|
||||||
<Children>
|
<Children>
|
||||||
@@ -200,9 +200,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.obj</Resource>
|
<Resource>Models/Camera.obj</Resource>
|
||||||
@@ -219,7 +217,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 +257,34 @@
|
|||||||
</Components>
|
</Components>
|
||||||
<Children/>
|
<Children/>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
<Entity>
|
||||||
|
<Components>
|
||||||
|
<c:Animation/>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Arm.dae</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/>
|
||||||
|
<c:Model>
|
||||||
|
<Resource>Models/Sid_Flying.dae</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"/>
|
||||||
|
<Orientation X="4.66500044" Y="3.14159203" Z="0"/>
|
||||||
|
</c:Transform>
|
||||||
|
</Components>
|
||||||
|
<Children/>
|
||||||
|
</Entity>
|
||||||
</Children>
|
</Children>
|
||||||
|
|
||||||
</Entity>
|
</Entity>
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#include "Rendering/AnimationSystem.h"
|
||||||
|
|
||||||
|
void AnimationSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& animationComponent, double dt)
|
||||||
|
{
|
||||||
|
if(!entity.HasComponent("Model")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Model* model = ResourceManager::Load<Model>(entity["Model"]["Resource"]);
|
||||||
|
//Skeleton* skeleton = model->m_Skeleton;
|
||||||
|
//auto animation == skeleton->GetAnimation(animation["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) {
|
||||||
|
(double&)animationComponent["Time"] = glm::sign(nextTime) * animation->Duration;
|
||||||
|
(double&)animationComponent["Speed"] = 0.0;
|
||||||
|
Events::AnimationComplete e;
|
||||||
|
e.Entity = entity;
|
||||||
|
// e.Name = animationComponent->Name;
|
||||||
|
m_EventBroker->Publish(e);
|
||||||
|
} else {
|
||||||
|
(double&)animationComponent["Time"] = nextTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user