/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ #include "AnimGraphTransitionConditionFixture.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace EMotionFX { void AnimGraphTransitionConditionFixture::SetUp() { SystemComponentFixture::SetUp(); // This test sets up an anim graph with 2 motions, each of which is 1 // second long. There is a transition from the first to the second that // triggers when the first is complete, and takes 0.5 seconds to // transition, and an identical one going the other way. During the // transition, the weights of the motion states should add up to 1. m_actor = ActorFactory::CreateAndInit(1); m_animGraph = AnimGraphFactory::Create(); m_stateMachine = m_animGraph->GetRootStateMachine(); m_motionNodeA = m_animGraph->GetMotionNodeA(); m_motionNodeB = m_animGraph->GetMotionNodeB(); m_transition = aznew AnimGraphStateTransition(); m_transition->SetSourceNode(m_motionNodeA); m_transition->SetTargetNode(m_motionNodeB); m_stateMachine->AddTransition(m_transition); m_motionSet = aznew MotionSet("testMotionSet"); for (int nodeIndex = 0; nodeIndex < 2; ++nodeIndex) { // The motion set keeps track of motions by their name. Each motion // within the motion set must have a unique name. AZStd::string motionId = AZStd::string::format("testSkeletalMotion%i", nodeIndex); SkeletalMotion* motion = SkeletalMotion::Create(motionId.c_str()); motion->SetMaxTime(1.0f); // 0.73 seconds would trigger frame 44 when sampling at 60 fps. The // event will be seen as triggered inside a motion condition, but a // frame later, at frame 45. motion->GetEventTable()->AddTrack(MotionEventTrack::Create("TestEventTrack", motion)); AZStd::shared_ptr data = EMotionFX::GetEventManager().FindOrCreateEventData("TestEvent", "TestParameter"); AZStd::shared_ptr rangeData = EMotionFX::GetEventManager().FindOrCreateEventData("TestRangeEvent", "TestParameter"); motion->GetEventTable()->FindTrackByName("TestEventTrack")->AddEvent(0.73f, data); motion->GetEventTable()->FindTrackByName("TestEventTrack")->AddEvent(0.65f, 0.95f, rangeData); MotionSet::MotionEntry* motionEntry = aznew MotionSet::MotionEntry(motion->GetName(), motion->GetName(), motion); m_motionSet->AddMotionEntry(motionEntry); AnimGraphMotionNode* motionNode = (nodeIndex == 0) ? m_motionNodeA : m_motionNodeB; motionNode->SetName(motionId.c_str()); motionNode->AddMotionId(motionId.c_str()); // Disable looping of the motion nodes. motionNode->SetLoop(false); } // Allow subclasses to create any additional nodes before the animgraph is activated. AddNodesToAnimGraph(); m_animGraph->InitAfterLoading(); m_actorInstance = ActorInstance::Create(m_actor.get()); m_animGraphInstance = AnimGraphInstance::Create(m_animGraph.get(), m_actorInstance, m_motionSet); m_actorInstance->SetAnimGraphInstance(m_animGraphInstance); } void AnimGraphTransitionConditionFixture::TearDown() { delete m_motionSet; m_motionSet = nullptr; if (m_actorInstance) { m_actorInstance->Destroy(); m_actorInstance = nullptr; } SystemComponentFixture::TearDown(); } } // namespace EMotionFX