Create navigation paths from one animated node to another animated node
johannesugb opened this issue · 0 comments
In preparation for supporting bounds for animated meshlets (such as those described in Issues #118), a method shall be implemented that generates navigation paths from one origin-node along a given skeleton towards a target-node. (This will be used to transform bounding boxes into the space of a different bone.)
Proceed as follows:
For a given selection of models and mesh indices, when being animated, the ID of the underlying animation-node can be retrieved like follows within a custom callback passed to gvk::animation::animate
:
std::vector<uint32_t> boneMatToAniNode;
curEntry.mAnimation.animate(curEntry.mClip, curEntry.mClip.start_time(), [&spaceForBoneMatrices, &inverseBindPoseMatrices, &boneMatToAniNode, &inverseMeshRootMatrices, &intoBoneSpaceMatrices](
gvk::mesh_bone_info aInfo,
const glm::mat4& aInverseMeshRootMatrix,
const glm::mat4& aTransformMatrix,
const glm::mat4& aInverseBindPoseMatrix,
const glm::mat4& aLocalTransformMatrix,
size_t aAnimatedNodeIndex,
size_t aBoneMeshTargetIndex,
double aAnimationTimeInTicks) {
size_t bmi = aInfo.mGlobalBoneIndexOffset + aInfo.mMeshLocalBoneIndex;
// Store the animation node index this bone matrix is assigned to
// (This means that this animation node is the last one in the bone hierarchy
// which is relevant for modifying the bone's position. Hence, from this
// animation_node, it is safe to write the bone matrix.)
boneMatToAniNode[bmi] = static_cast<uint32_t>(aAnimatedNodeIndex);
}
);
Maaayyybe the part about computing bmi
is not the most beautiful one => Please think about it and if a better/better-understandable, but still generic approach can be implemented.
The aAnimatedNodeIndex
refers to an index into the vector gvk::animation::mAnimationData
, which can be retrieved with gvk::animation::get_animated_nodes
.
Each element of that vector is a gvk::animated_node
entry, which---among other data---contains the index of its animated parent node animated_node::mAnimatedParentIndex
.
The algorithm that creates a path from node n_o
to node n_t
would proceed as follows:
- For a given animated node origin
n_o
, get its node-index, and build the whole animated-parent-chain up to the root node (which has nomAnimatedParentIndex
anymore) and store that chain in a collectionc_o
. - For a given animated node target
n_t
, get its node-index, and build the whole animated-parent-chain up to the root node (which has nomAnimatedParentIndex
anymore) and store that chain in a collectionc_t
. - Start at the leaf node of
c_o
and move up the hierarchy until an index has been reached that can also be found withinc_t
. This index represents the common parent node ofn_o
andn_t
(or it can also ben_t
itself) - If such a common parent node could not be found, perform the search the other way round: starting from the leaf node in
c_t
and move up the hierarchy until an index has been reached that can also be found withinc_o
. (This handles the cases wheren_o
is a parent ofn_t
) - Construct the path from
n_o
ton_t
based on the information gathered above by creating a vector that contains all animated node indices along the way. The result vector's first element is the index ofn_o
, and its last element is the index ofn_t
. - If no path could be found (because the user specified invalid node indices or whatever), throw exceptions with meaningful messages.
Definition of done:
- The algorithm described above has been implemented and added to class
gvk::animation
. - The implemented functionality is well documented and the Contribution Guidelines have been followed.