BlendQueues fully working

This commit is contained in:
viktorljung
2016-03-03 23:20:13 +01:00
parent 68332102ea
commit e3fbd2082c
8 changed files with 99 additions and 66 deletions
+57 -44
View File
@@ -148,11 +148,11 @@ void AnimationSystem::UpdateWeights(double dt)
bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
{
if(!e.RootNode.Valid()) {
if (!e.RootNode.Valid()) {
return false;
}
if(!e.RootNode.HasComponent("Model")) {
if (!e.RootNode.HasComponent("Model")) {
return false;
}
@@ -179,7 +179,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
EntityWrapper subTreeRoot = blendTree->GetSubTreeRoot(e.NodeName);
if(!subTreeRoot.Valid()) {
if (!subTreeRoot.Valid()) {
return false;
}
@@ -193,16 +193,18 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
abj.BlendInfo.NodeName = e.NodeName;
abj.BlendInfo.progress = 0.0;
abj.BlendInfo.Start = e.Start;
abj.BlendInfo.SingleBlend = e.SingleLevelBlend;
if (e.Restart) {
EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName);
if (nodeEntity.Valid()) {
if (nodeEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]);
EntityWrapper nodeEntity = subTreeRoot.FirstChildByName(e.NodeName); // more than one
if (nodeEntity.Valid()) {
if (nodeEntity.HasComponent("Animation")) {
const Skeleton::Animation* animation = skeleton->GetAnimation(nodeEntity["Animation"]["AnimationName"]);
(bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse;
if (e.Restart) {
if (animation != nullptr) {
if (e.Restart) {
(bool&)nodeEntity["Animation"]["Reverse"] = e.Reverse;
if (e.Reverse) {
(double&)nodeEntity["Animation"]["Time"] = animation->Duration;
} else {
@@ -439,27 +441,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
aeb.RootNode = entity;
aeb.Start = true;
aeb.Restart = true;
m_EventBroker->Publish(aeb);
}
}
}
} else if (e.Command == "Stand") {
auto blendComponents = m_World->GetComponents("BlendAdditive");
if (blendComponents == nullptr) {
return false;
}
for (auto& bc : *blendComponents) {
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandMovement";
aeb.RootNode = entity;
aeb.Start = true;
aeb.Restart = true;
aeb.SingleLevelBlend = true;
m_EventBroker->Publish(aeb);
}
}
@@ -526,27 +508,15 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
/* {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.1;
aeb.NodeName = "Right";
aeb.RootNode = entity;
aeb.Start = true;
m_EventBroker->Publish(aeb);
}*/
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "Right";
aeb.RootNode = entity;
aeb.Start = true;
aeb.Restart = false;
aeb.AnimationEntity = entity.FirstChildByName("DashRight");
aeb.Delay = -0.3;
m_EventBroker->Publish(aeb);
}
}
}
} else if (e.Command == "ForwardTest") {
@@ -570,8 +540,51 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
}
}
}
} else if (e.Command == "BackwardTest") {
auto blendComponents = m_World->GetComponents("BlendAdditive");
if (blendComponents == nullptr) {
return false;
}
for (auto& bc : *blendComponents) {
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.1;
aeb.NodeName = "Walk";
aeb.RootNode = entity;
aeb.Start = true;
aeb.Reverse = true;
m_EventBroker->Publish(aeb);
}
}
}
} else if (e.Value == 0.f) {
if (e.Command == "Crouch") {
auto blendComponents = m_World->GetComponents("BlendAdditive");
if (blendComponents == nullptr) {
return false;
}
for (auto& bc : *blendComponents) {
EntityWrapper entity = EntityWrapper(m_World, bc.EntityID);
if (entity.Name() == "Assault") {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.3;
aeb.NodeName = "StandMovement";
aeb.RootNode = entity;
aeb.Start = true;
aeb.Restart = true;
aeb.SingleLevelBlend = true;
m_EventBroker->Publish(aeb);
}
}
}
}
}
}
+7 -2
View File
@@ -54,6 +54,11 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end(); it++) {
auto next = std::next(it, 1);
if (it->BlendJob.BlendInfo.NodeName == autoBlendJob.BlendInfo.NodeName) {
(*it) = blendNode;
}
if (next != m_BlendQueue.end()) {
if (it->StartTime >= blendNode.StartTime && next->StartTime <= blendNode.StartTime) {
LOG_INFO("Inserted %s between %s and %s", blendNode.BlendJob.BlendInfo.NodeName.c_str(), it->BlendJob.BlendInfo.NodeName.c_str(), next->BlendJob.BlendInfo.NodeName.c_str());
@@ -83,11 +88,11 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
void AutoBlendQueue::UpdateTime(double dt)
{
for (auto it = m_BlendQueue.begin(); it != m_BlendQueue.end();) {
it->EndTime -= dt;
it->StartTime -= dt;
if (it->EndTime <= 0) {
it = m_BlendQueue.erase(it);
} else {
it->EndTime -= dt;
it->StartTime -= dt;
it++;
}
}
+8 -2
View File
@@ -27,6 +27,7 @@ BlendTree::BlendTree(EntityWrapper ModelEntity, Skeleton* skeleton)
m_Root->Parent = nullptr;
m_Root->Type = NodeType::Blend;
m_Root->Weight = (double)ModelEntity["Blend"]["Weight"];
m_Root->SubTreeRoot = (bool)ModelEntity["Blend"]["SubTreeRoot"];
(double&)ModelEntity["Blend"]["Weight"] = glm::clamp((double)ModelEntity["Blend"]["Weight"], 0.0, 1.0);
m_Root->Child[0] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose1"], ModelEntity);
m_Root->Child[1] = FillTreeByName(m_Root, (std::string)ModelEntity["Blend"]["Pose2"], ModelEntity);
@@ -132,6 +133,7 @@ BlendTree::Node* BlendTree::FillTreeByName(Node* parentNode, std::string name, E
node->Type = NodeType::Blend;
(double&)childEntity["Blend"]["Weight"] = glm::clamp((double)childEntity["Blend"]["Weight"], 0.0, 1.0);
node->Weight = (double)childEntity["Blend"]["Weight"];
node->SubTreeRoot = (bool)childEntity["Blend"]["SubTreeRoot"];
//if (node->Weight < 1.f && node->Weight > 0.f) {
node->Child[0] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose1"], childEntity);
node->Child[1] = FillTreeByName(node, (std::string)childEntity["Blend"]["Pose2"], childEntity);
@@ -251,6 +253,10 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
lastNode = currentNode;
currentNode = currentNode->Parent;
if (blendInfo.SingleBlend) {
break;
}
}
} else if(goalNodes.size() >= 2) {
std::vector<Node*> sharedParents;
@@ -380,8 +386,8 @@ EntityWrapper BlendTree::GetSubTreeRoot(std::string nodeName)
std::vector<Node*> subTreeRoots;
for (auto it = nodes.begin(); it != nodes.end(); it++) {
Node* currentNode = (*it);
while (currentNode->Parent->Type == NodeType::Blend) {
Node* currentNode = (*it)->Parent;
while (!currentNode->SubTreeRoot) {
currentNode = currentNode->Parent;
}
subTreeRoots.push_back(currentNode);