7a8f968738
Signed-off-by: Chris Burel <burelc@amazon.com>
100 lines
2.5 KiB
C++
100 lines
2.5 KiB
C++
/*
|
|
* Copyright (c) Contributors to the Open 3D Engine Project.
|
|
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
|
*
|
|
*/
|
|
|
|
// include the required headers
|
|
#include "MorphSetupInstance.h"
|
|
#include "MorphSetup.h"
|
|
#include <EMotionFX/Source/Allocators.h>
|
|
|
|
namespace EMotionFX
|
|
{
|
|
AZ_CLASS_ALLOCATOR_IMPL(MorphSetupInstance, DeformerAllocator, 0)
|
|
|
|
|
|
// default constructor
|
|
MorphSetupInstance::MorphSetupInstance()
|
|
: BaseObject()
|
|
{
|
|
Init(nullptr);
|
|
}
|
|
|
|
|
|
// constructor
|
|
MorphSetupInstance::MorphSetupInstance(MorphSetup* morphSetup)
|
|
{
|
|
Init(morphSetup);
|
|
}
|
|
|
|
|
|
// destructor
|
|
MorphSetupInstance::~MorphSetupInstance()
|
|
{
|
|
}
|
|
|
|
|
|
// create
|
|
MorphSetupInstance* MorphSetupInstance::Create()
|
|
{
|
|
return aznew MorphSetupInstance();
|
|
}
|
|
|
|
|
|
// extended create
|
|
MorphSetupInstance* MorphSetupInstance::Create(MorphSetup* morphSetup)
|
|
{
|
|
return aznew MorphSetupInstance(morphSetup);
|
|
}
|
|
|
|
|
|
// initialize the setup instance
|
|
void MorphSetupInstance::Init(MorphSetup* morphSetup)
|
|
{
|
|
// don't do anything if we there is no morph setup
|
|
if (morphSetup == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// allocate the number of morph targets
|
|
const size_t numMorphTargets = morphSetup->GetNumMorphTargets();
|
|
mMorphTargets.resize(numMorphTargets);
|
|
|
|
// update the ID values
|
|
for (uint32 i = 0; i < numMorphTargets; ++i)
|
|
{
|
|
mMorphTargets[i].SetID(morphSetup->GetMorphTarget(i)->GetID());
|
|
}
|
|
}
|
|
|
|
|
|
// try to locate the morph target by ID
|
|
size_t MorphSetupInstance::FindMorphTargetIndexByID(uint32 id) const
|
|
{
|
|
// try to locate the morph target with the given ID
|
|
const auto foundElement = AZStd::find_if(mMorphTargets.begin(), mMorphTargets.end(), [id](const MorphTarget& morphTarget)
|
|
{
|
|
return morphTarget.GetID() == id;
|
|
});
|
|
return foundElement != mMorphTargets.end() ? AZStd::distance(mMorphTargets.begin(), foundElement) : InvalidIndex;
|
|
}
|
|
|
|
|
|
MorphSetupInstance::MorphTarget* MorphSetupInstance::FindMorphTargetByID(uint32 id)
|
|
{
|
|
const size_t index = FindMorphTargetIndexByID(id);
|
|
if (index != InvalidIndex)
|
|
{
|
|
return &mMorphTargets[index];
|
|
}
|
|
else
|
|
{
|
|
return nullptr;
|
|
}
|
|
}
|
|
} // namespace EMotionFX
|