Can now blend non unique nodes

This commit is contained in:
viktorljung
2016-03-03 21:20:55 +01:00
parent a3494b92c8
commit 68332102ea
4 changed files with 168 additions and 20 deletions
+75 -2
View File
@@ -371,7 +371,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
if (entity.Name() == "Assault") {
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.35;
aeb.Duration = 0.25;
aeb.NodeName = "Jump";
aeb.RootNode = entity;
aeb.Start = true;
@@ -380,7 +380,7 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
}
{
Events::AutoAnimationBlend aeb;
aeb.Duration = 0.6;
aeb.Duration = 0.3;
aeb.NodeName = "StandCrouchBlend";
aeb.RootNode = entity;
aeb.Start = true;
@@ -496,6 +496,79 @@ bool AnimationSystem::OnInputCommand(const Events::InputCommand& e)
}
}
}
} else if (e.Command == "LeftTest") {
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 = "Left";
aeb.RootNode = entity;
aeb.Start = true;
m_EventBroker->Publish(aeb);
}
}
}
} else if (e.Command == "RightTest") {
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 = "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") {
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;
m_EventBroker->Publish(aeb);
}
}
}
}
+1 -1
View File
@@ -85,7 +85,7 @@ 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) {
if (it->EndTime <= 0) {
it = m_BlendQueue.erase(it);
} else {
it++;
+59 -3
View File
@@ -252,16 +252,72 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo)
lastNode = currentNode;
currentNode = currentNode->Parent;
}
} else if(goalNodes.size() >= 2) {
std::vector<Node*> sharedParents;
std::vector<Node*> nodes = goalNodes;
for (auto it = nodes.begin(); it != nodes.end(); it++) {
auto next = std::next(it, 1);
if (next != nodes.end()) {
Node* commonParent = FirstCommonParent((*it), (*next));
sharedParents.push_back(commonParent);
(*next) = commonParent;
nodes.erase(it);
it = nodes.begin();
}
}
for (auto it = goalNodes.begin(); it != goalNodes.end(); it++) {
Node* currentNode = (*it)->Parent;
Node* lastNode = (*it);
while (currentNode != nullptr) {
if (!currentNode->Entity.HasComponent("Blend")) {
return blendInfo;
}
bool ShouldBreak = false;
for (auto it = sharedParents.begin(); it != sharedParents.end(); it++) {
if(currentNode == (*it)) {
ShouldBreak = true;
}
}
if(ShouldBreak) {
break;
}
double startWeight;
if (blendInfo.StartWeights.find(currentNode->Entity) != blendInfo.StartWeights.end()) {
startWeight = blendInfo.StartWeights.at(currentNode->Entity);
} else {
startWeight = currentNode->Weight;
blendInfo.StartWeights[currentNode->Entity] = startWeight;
}
double goalWeight;
if (currentNode->Child[0] == lastNode) {
goalWeight = 0.0;
} else if (currentNode->Child[1] == lastNode) {
goalWeight = 1.0;
}
double weight = ((goalWeight - startWeight) * blendInfo.progress) + startWeight;
(double&)currentNode->Entity["Blend"]["Weight"] = weight;
currentNode->Weight = weight;
lastNode = currentNode;
currentNode = currentNode->Parent;
}
}
}
return blendInfo;
}
BlendTree::Node* BlendTree::GetCommonParent(std::string NodeName1, std::string NodeName2)
{
std::vector<Node*> nodes1 = FindNodesByName(NodeName1);