Implmented GLTF Compile and Load Overhaul #404
|
@ -24,11 +24,11 @@ namespace SHADE
|
|||
, totalTime { static_cast<float>(asset.duration) / static_cast<int>(asset.ticksPerSecond) }
|
||||
{
|
||||
// Populate keyframes
|
||||
int channelIdx = 0;
|
||||
for (const auto& channel : asset.nodeChannels)
|
||||
{
|
||||
// Create a channel
|
||||
Channel newChannel;
|
||||
newChannel.Name = std::string(channel.name);
|
||||
newChannel.PositionKeyFrames.reserve(channel.positionKeys.size());
|
||||
newChannel.RotationKeyFrames.reserve(channel.rotationKeys.size());
|
||||
newChannel.ScaleKeyFrames.reserve(channel.scaleKeys.size());
|
||||
|
@ -51,6 +51,9 @@ namespace SHADE
|
|||
|
||||
// Insert the channel
|
||||
channels.emplace_back(std::move(newChannel));
|
||||
|
||||
// Go to next channel
|
||||
++channelIdx;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ namespace SHADE
|
|||
/// </summary>
|
||||
struct Channel
|
||||
{
|
||||
std::string Name;
|
||||
std::vector<SHAnimationKeyFrame<SHVec3>> PositionKeyFrames;
|
||||
std::vector<SHAnimationKeyFrame<SHQuaternion>> RotationKeyFrames;
|
||||
std::vector<SHAnimationKeyFrame<SHVec3>> ScaleKeyFrames;
|
||||
|
|
|
@ -89,16 +89,7 @@ namespace SHADE
|
|||
currClip = newClip;
|
||||
secsPerTick = 1.0f / currClip->GetTicksPerSecond();
|
||||
|
||||
// Build channel map
|
||||
channelMap.clear();
|
||||
if (currClip)
|
||||
{
|
||||
for (const auto& channel : currClip->GetChannels())
|
||||
{
|
||||
channelMap.emplace(channel.Name, &channel);
|
||||
}
|
||||
}
|
||||
|
||||
// Set to initial pose
|
||||
if (rig && rig->GetRootNode() && currClip)
|
||||
{
|
||||
updatePoseWithClip(0.0f);
|
||||
|
@ -141,16 +132,17 @@ namespace SHADE
|
|||
void SHAnimatorComponent::updatePoseWithClip(int closestFrameIndex, float poseTime, Handle<SHRigNode> node, const SHMatrix& parentMatrix)
|
||||
{
|
||||
// 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;
|
||||
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
|
||||
(
|
||||
getInterpolatedValue(CHANNEL->PositionKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL->RotationKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL->ScaleKeyFrames, closestFrameIndex, poseTime)
|
||||
getInterpolatedValue(CHANNEL.PositionKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL.RotationKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL.ScaleKeyFrames, closestFrameIndex, poseTime)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -134,8 +134,6 @@ namespace SHADE
|
|||
float secsPerTick = 0.0f;
|
||||
// Buffer
|
||||
std::vector<SHMatrix> boneMatrices;
|
||||
// Caches
|
||||
std::unordered_map<std::string, const SHAnimationClip::Channel*> channelMap;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
|
|
@ -120,7 +120,7 @@ namespace SHADE
|
|||
|
||||
// Fill the node with data
|
||||
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);
|
||||
|
||||
// Populate maps
|
||||
|
|
Loading…
Reference in New Issue