Implmented GLTF Compile and Load Overhaul #404
|
@ -132,19 +132,19 @@ 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 int BONE_IDX = rig->GetNodeIndex(node);
|
||||
SHMatrix transformMatrix = node->TransformMatrix;
|
||||
const auto& CHANNELS = currClip->GetChannels();
|
||||
if (BONE_IDX < CHANNELS.size())
|
||||
{
|
||||
const auto& CHANNEL = CHANNELS[BONE_IDX];
|
||||
transformMatrix = SHMatrix::Transform
|
||||
(
|
||||
getInterpolatedValue(CHANNEL.PositionKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL.RotationKeyFrames, closestFrameIndex, poseTime),
|
||||
getInterpolatedValue(CHANNEL.ScaleKeyFrames, closestFrameIndex, poseTime)
|
||||
);
|
||||
}
|
||||
//const int BONE_IDX = rig->GetNodeIndex(node);
|
||||
//const auto& CHANNELS = currClip->GetChannels();
|
||||
//if (BONE_IDX < CHANNELS.size())
|
||||
//{
|
||||
// const auto& CHANNEL = CHANNELS[BONE_IDX];
|
||||
// transformMatrix = SHMatrix::Transform
|
||||
// (
|
||||
// getInterpolatedValue(CHANNEL.PositionKeyFrames, closestFrameIndex, poseTime),
|
||||
// getInterpolatedValue(CHANNEL.RotationKeyFrames, closestFrameIndex, poseTime),
|
||||
// getInterpolatedValue(CHANNEL.ScaleKeyFrames, closestFrameIndex, poseTime)
|
||||
// );
|
||||
//}
|
||||
|
||||
// Apply parent's transformation
|
||||
transformMatrix = transformMatrix * parentMatrix;
|
||||
|
|
|
@ -120,8 +120,10 @@ namespace SHADE
|
|||
|
||||
// Fill the node with data
|
||||
const auto& NODE_DATA = asset.nodeDataCollection.at(sourceNode->idRef);
|
||||
newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.inverseBindMatrix);
|
||||
newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform);
|
||||
//newNode->OffsetMatrix = SHMatrix::Transpose(NODE_DATA.inverseBindMatrix);
|
||||
//newNode->TransformMatrix = SHMatrix::Transpose(NODE_DATA.transform);
|
||||
newNode->OffsetMatrix = NODE_DATA.inverseBindMatrix;
|
||||
newNode->TransformMatrix = NODE_DATA.transform;
|
||||
|
||||
// Populate maps
|
||||
if (!NODE_DATA.name.empty())
|
||||
|
|
|
@ -108,6 +108,8 @@ namespace SHADE
|
|||
{
|
||||
mesh->BoneCount = asset.rig.nodeDataCollection.size();
|
||||
}
|
||||
|
||||
//BuildTransformMatrices(asset.rig);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,6 +140,26 @@ namespace SHADE
|
|||
);
|
||||
}
|
||||
|
||||
void SHModelLoader::BuildTransformMatrices(SHRigAsset& rig)
|
||||
{
|
||||
std::queue<SHRigNodeAsset const*> nodeQueue;
|
||||
nodeQueue.push(rig.root);
|
||||
|
||||
while(!nodeQueue.empty())
|
||||
{
|
||||
auto& current = nodeQueue.front();
|
||||
nodeQueue.pop();
|
||||
auto& parentData {rig.nodeDataCollection[current->idRef]};
|
||||
|
||||
for (auto const& child: current->children)
|
||||
{
|
||||
nodeQueue.push(child);
|
||||
auto& childData {rig.nodeDataCollection[child->idRef]};
|
||||
childData.transform = childData.transform * parentData.transform;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SHModelLoader::ReadRigHeader(FileReference file, SHRigDataHeader& header)
|
||||
{
|
||||
file.read(
|
||||
|
@ -174,7 +196,7 @@ namespace SHADE
|
|||
reinterpret_cast<char*>(&node.inverseBindMatrix),
|
||||
sizeof(SHMatrix)
|
||||
);
|
||||
node.inverseBindMatrix = SHMatrix::Transpose(node.inverseBindMatrix);
|
||||
node.inverseBindMatrix = node.inverseBindMatrix;
|
||||
|
||||
NodeDataFlag flag;
|
||||
file.get(reinterpret_cast<char&>(flag));
|
||||
|
@ -214,20 +236,21 @@ namespace SHADE
|
|||
translation = GetVec3FromVector(carrier);
|
||||
}
|
||||
|
||||
//if (flag & NODE_DATA_MATRIX)
|
||||
//{
|
||||
// carrier.resize(NODE_COMPONENT_COUNT_MATRIX);
|
||||
// file.read(
|
||||
// reinterpret_cast<char*>(carrier.data()),
|
||||
// sizeof(double) * NODE_COMPONENT_COUNT_MATRIX
|
||||
// );
|
||||
// matrix = GetMatrixFromVector(carrier);
|
||||
//}
|
||||
if (flag & NODE_DATA_MATRIX)
|
||||
{
|
||||
carrier.resize(NODE_COMPONENT_COUNT_MATRIX);
|
||||
file.read(
|
||||
reinterpret_cast<char*>(carrier.data()),
|
||||
sizeof(double) * NODE_COMPONENT_COUNT_MATRIX
|
||||
);
|
||||
matrix = GetMatrixFromVector(carrier);
|
||||
}
|
||||
|
||||
//matrix *= SHMatrix::Transform(translation, rotation, scale);
|
||||
matrix *= SHMatrix::Translate(translation) * SHMatrix::Rotate(rotation) * SHMatrix::Scale(scale);
|
||||
//result = SHMatrix::Transpose(result);
|
||||
node.transform = matrix;
|
||||
//node.transform = SHMatrix::Inverse(node.inverseBindMatrix);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace SHADE
|
|||
void ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers, std::vector<SHAnimAsset*>& anims);
|
||||
void ReadAnimNode(FileReference file, uint32_t frameCount, SHAnimNode& data);
|
||||
|
||||
void BuildTransformMatrices(SHRigAsset& rig);
|
||||
|
||||
void ReadHeaders(FileReference file, SHModelAsset& asset);
|
||||
void ReadData(FileReference file, SHModelAsset& asset);
|
||||
public:
|
||||
|
|
|
@ -107,7 +107,6 @@ constexpr std::string_view EXTENSIONS[] = {
|
|||
"dummy",
|
||||
SCRIPT_EXTENSION,
|
||||
FONT_EXTENSION,
|
||||
AUDIO_WAV_EXTENSION,
|
||||
AUDIO_BANK_EXTENSION
|
||||
};
|
||||
|
||||
|
|
|
@ -162,6 +162,7 @@ namespace SHADE
|
|||
{
|
||||
assetCollection.emplace(asset.id, asset);
|
||||
}
|
||||
|
||||
if (file.name == asset.name)
|
||||
{
|
||||
AssetPath path{ file.path };
|
||||
|
|
Loading…
Reference in New Issue