Add FindClosestNode to Animated Model

This commit is contained in:
Wojtek Figat
2021-05-13 12:34:42 +02:00
parent 32806e8f4e
commit e267583bad
2 changed files with 28 additions and 0 deletions

View File

@@ -147,6 +147,24 @@ void AnimatedModel::GetNodeTransformation(const StringView& nodeName, Matrix& no
GetNodeTransformation(SkinnedModel ? SkinnedModel->FindNode(nodeName) : -1, nodeTransformation, worldSpace);
}
int32 AnimatedModel::FindClosestNode(const Vector3& location, bool worldSpace) const
{
const Vector3 pos = worldSpace ? _transform.WorldToLocal(location) : location;
int32 result = -1;
float closest = MAX_float;
for (int32 nodeIndex = 0; nodeIndex < GraphInstance.NodesPose.Count(); nodeIndex++)
{
const Vector3 node = GraphInstance.NodesPose[nodeIndex].GetTranslation();
const float dst = Vector3::DistanceSquared(node, pos);
if (dst < closest)
{
closest = dst;
result = nodeIndex;
}
}
return result;
}
#define CHECK_ANIM_GRAPH_PARAM_ACCESS() \
if (!AnimationGraph) \
{ \
@@ -234,6 +252,8 @@ void AnimatedModel::SetParameterValue(const Guid& id, const Variant& value)
LOG(Warning, "Failed to set animated model '{0}' missing parameter '{1}'", ToString(), id.ToString());
}
#undef CHECK_ANIM_GRAPH_PARAM_ACCESS
float AnimatedModel::GetBlendShapeWeight(const StringView& name)
{
for (auto& e : _blendShapes.Weights)