Modified SHAnimator and SHRig to use new model formats

This commit is contained in:
Kah Wei 2023-03-03 17:11:33 +08:00
parent f083147806
commit f9ae0c10ce
5 changed files with 13 additions and 21 deletions

View File

@ -24,11 +24,11 @@ namespace SHADE
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) } , totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
{ {
// Populate keyframes // Populate keyframes
int channelIdx = 0;
for (const auto& channel : asset.nodeChannels) for (const auto& channel : asset.nodeChannels)
{ {
// Create a channel // Create a channel
Channel newChannel; Channel newChannel;
newChannel.Name = std::string(channel.name);
newChannel.PositionKeyFrames.reserve(channel.positionKeys.size()); newChannel.PositionKeyFrames.reserve(channel.positionKeys.size());
newChannel.RotationKeyFrames.reserve(channel.rotationKeys.size()); newChannel.RotationKeyFrames.reserve(channel.rotationKeys.size());
newChannel.ScaleKeyFrames.reserve(channel.scaleKeys.size()); newChannel.ScaleKeyFrames.reserve(channel.scaleKeys.size());
@ -51,6 +51,9 @@ namespace SHADE
// Insert the channel // Insert the channel
channels.emplace_back(std::move(newChannel)); channels.emplace_back(std::move(newChannel));
// Go to next channel
++channelIdx;
} }
} }

View File

@ -46,7 +46,6 @@ namespace SHADE
/// </summary> /// </summary>
struct Channel struct Channel
{ {
std::string Name;
std::vector<SHAnimationKeyFrame<SHVec3>> PositionKeyFrames; std::vector<SHAnimationKeyFrame<SHVec3>> PositionKeyFrames;
std::vector<SHAnimationKeyFrame<SHQuaternion>> RotationKeyFrames; std::vector<SHAnimationKeyFrame<SHQuaternion>> RotationKeyFrames;
std::vector<SHAnimationKeyFrame<SHVec3>> ScaleKeyFrames; std::vector<SHAnimationKeyFrame<SHVec3>> ScaleKeyFrames;

View File

@ -89,16 +89,7 @@ namespace SHADE
currClip = newClip; currClip = newClip;
secsPerTick = 1.0f / currClip->GetTicksPerSecond(); secsPerTick = 1.0f / currClip->GetTicksPerSecond();
// Build channel map // Set to initial pose
channelMap.clear();
if (currClip)
{
for (const auto& channel : currClip->GetChannels())
{
channelMap.emplace(channel.Name, &channel);
}
}
if (rig && rig->GetRootNode() && currClip) if (rig && rig->GetRootNode() && currClip)
{ {
updatePoseWithClip(0.0f); updatePoseWithClip(0.0f);
@ -141,16 +132,17 @@ namespace SHADE
void SHAnimatorComponent::updatePoseWithClip(int closestFrameIndex, float poseTime, Handle<SHRigNode> node, const SHMatrix& parentMatrix) void SHAnimatorComponent::updatePoseWithClip(int closestFrameIndex, float poseTime, Handle<SHRigNode> node, const SHMatrix& parentMatrix)
{ {
// Check if there is a channel for this node // Check if there is a channel for this node
const std::string& BONE_NAME = rig->GetName(node); const int BONE_IDX = rig->GetNodeIndex(node);
SHMatrix transformMatrix = node->TransformMatrix; SHMatrix transformMatrix = node->TransformMatrix;
if (channelMap.contains(BONE_NAME)) const auto& CHANNELS = currClip->GetChannels();
if (CHANNELS.size() < BONE_IDX)
{ {
const auto CHANNEL = channelMap[BONE_NAME]; const auto& CHANNEL = CHANNELS[BONE_IDX];
transformMatrix = SHMatrix::Transform transformMatrix = SHMatrix::Transform
( (
getInterpolatedValue(CHANNEL->PositionKeyFrames, closestFrameIndex, poseTime), getInterpolatedValue(CHANNEL.PositionKeyFrames, closestFrameIndex, poseTime),
getInterpolatedValue(CHANNEL->RotationKeyFrames, closestFrameIndex, poseTime), getInterpolatedValue(CHANNEL.RotationKeyFrames, closestFrameIndex, poseTime),
getInterpolatedValue(CHANNEL->ScaleKeyFrames, closestFrameIndex, poseTime) getInterpolatedValue(CHANNEL.ScaleKeyFrames, closestFrameIndex, poseTime)
); );
} }

View File

@ -134,8 +134,6 @@ namespace SHADE
float secsPerTick = 0.0f; float secsPerTick = 0.0f;
// Buffer // Buffer
std::vector<SHMatrix> boneMatrices; std::vector<SHMatrix> boneMatrices;
// Caches
std::unordered_map<std::string, const SHAnimationClip::Channel*> channelMap;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */

View File

@ -120,7 +120,7 @@ namespace SHADE
// Fill the node with data // Fill the node with data
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef); const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.offset); newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.inverseBindMatrix);
newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform); newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform);
// Populate maps // Populate maps