diff --git a/resources/Schema/Entities/BlendTreeTest.xml b/resources/Schema/Entities/BlendTreeTest.xml index 69590ceb..d2c7ead9 100644 --- a/resources/Schema/Entities/BlendTreeTest.xml +++ b/resources/Schema/Entities/BlendTreeTest.xml @@ -68,8 +68,8 @@ Models/Weapons/Blue/AssaultWeaponBlue.mesh - - + + @@ -125,7 +125,7 @@ StandCrouchBlend JumpDashBlend - 0.00067602147306955462 + 1.055110346338068e-57 @@ -135,7 +135,7 @@ StandMovement CrouchMovement - 0 + 0.0069837930620454403 @@ -155,7 +155,7 @@ RunWalkBlend StrafeLRBlend - 0 + 2.4565650245976452e-16 @@ -165,7 +165,7 @@ Walk Run - 1 + 1.2938206818383024e-24 @@ -174,6 +174,9 @@ WalkF + + 1 + true @@ -183,7 +186,7 @@ RunF - + 1 true @@ -198,7 +201,7 @@ Left Right - 0 + 0.033793529385008014 @@ -207,6 +210,9 @@ StrafeLeftF + + 1 + true @@ -216,6 +222,9 @@ StrafeRightF + + 1 + true @@ -243,6 +252,7 @@ MovementBlend Idle + 0 @@ -252,7 +262,7 @@ Walk StrafeLRBlend - 0 + 2.4565650245976452e-16 @@ -262,7 +272,7 @@ Left Right - 0 + 0.033793529385008014 @@ -271,6 +281,9 @@ CrouchStrafeLeftF + + 1 + true @@ -280,6 +293,9 @@ CrouchStrafeRightF + + 1 + true @@ -291,6 +307,9 @@ CrouchWalkF + + 1 + true @@ -318,7 +337,7 @@ Jump DashBlend - 0.01016461050458084 + 1 @@ -340,7 +359,7 @@ DashFBBlend DashLRBlend - 0.99999999999984523 + 0.014621149736541383 @@ -350,7 +369,7 @@ DashForward DashBackward - 0.98238059685988577 + 0.014363533804961248 @@ -386,7 +405,7 @@ DashLeft DashRight - 0.96547196574235861 + 4.3244885367500671e-16 diff --git a/src/Engine/Rendering/AnimationSystem.cpp b/src/Engine/Rendering/AnimationSystem.cpp index 166ecb47..4434e80b 100644 --- a/src/Engine/Rendering/AnimationSystem.cpp +++ b/src/Engine/Rendering/AnimationSystem.cpp @@ -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); + } + } + } } diff --git a/src/Engine/Rendering/AutoBlendQueue.cpp b/src/Engine/Rendering/AutoBlendQueue.cpp index 9f0a7366..e75e33b5 100644 --- a/src/Engine/Rendering/AutoBlendQueue.cpp +++ b/src/Engine/Rendering/AutoBlendQueue.cpp @@ -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++; diff --git a/src/Engine/Rendering/BlendTree.cpp b/src/Engine/Rendering/BlendTree.cpp index 036c3f49..2f74b45e 100644 --- a/src/Engine/Rendering/BlendTree.cpp +++ b/src/Engine/Rendering/BlendTree.cpp @@ -252,16 +252,72 @@ BlendTree::AutoBlendInfo BlendTree::AutoBlendStep(AutoBlendInfo blendInfo) lastNode = currentNode; currentNode = currentNode->Parent; } - - } else if(goalNodes.size() >= 2) { + std::vector sharedParents; + std::vector 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 nodes1 = FindNodesByName(NodeName1);