Implmented GLTF Compile and Load Overhaul #404

Merged
XiaoQiDigipen merged 17 commits from SP3-13-Assets-Manager into main 2023-03-07 23:27:01 +08:00
5 changed files with 98 additions and 30 deletions
Showing only changes of commit f083147806 - Show all commits

View File

@ -61,9 +61,9 @@ namespace SHADE
{
AnimationInterpolation interpolation;
std::vector<PositionKey> positionKeys;
std::vector<RotationKey> rotationKeys;
std::vector<ScaleKey> scaleKeys;
std::vector<PositionKey> positionKeys{};
std::vector<RotationKey> rotationKeys{};
std::vector<ScaleKey> scaleKeys{};
};
struct SH_API SHAnimAsset final : SHAssetData

View File

@ -28,12 +28,6 @@ namespace SHADE
bool hasWeights;
};
struct VertexWeight
{
SHVec4 weights;
SHVec4U joints;
};
struct SH_API SHMeshAsset : SHAssetData
{
std::string name;
@ -44,6 +38,9 @@ namespace SHADE
std::vector<uint32_t> Indices{};
//Variables
std::vector<VertexWeight> VertexWeights{};
std::vector<SHVec4> VertexBoneWeights{};
std::vector<SHVec4U> VertexBoneIndices{};
uint32_t BoneCount;
};
}

View File

@ -1,8 +1,6 @@
#include "SHpch.h"
#include "SHRigAsset.h"
#include <queue>
namespace SHADE
{
SHRigAsset::~SHRigAsset()

View File

@ -39,11 +39,7 @@ namespace SHADE
struct SHRigNodeData
{
std::string name;
std::vector<double>
rotation,
scale,
translation,
matrix;
SHMatrix transform;
SHMatrix inverseBindMatrix;
};

View File

@ -17,6 +17,52 @@
namespace SHADE
{
inline SHVec3 GetVec3FromVector(std::vector<double> const& vec)
{
assert(vec.size() == NODE_COMPONENT_COUNT_TRANSLATION);
return SHVec3{
static_cast<float>(vec[0]),
static_cast<float>(vec[1]),
static_cast<float>(vec[2])
};
}
inline SHVec4 GetVec4FromVector(std::vector<double> const& vec)
{
assert(vec.size() == NODE_COMPONENT_COUNT_ROTATION);
return SHVec4{
static_cast<float>(vec[0]),
static_cast<float>(vec[1]),
static_cast<float>(vec[2]),
static_cast<float>(vec[3])
};
}
inline SHMatrix GetMatrixFromVector(std::vector<double> const& vec)
{
assert(vec.size() == NODE_COMPONENT_COUNT_MATRIX);
return SHMatrix{
static_cast<float>(vec[0]),
static_cast<float>(vec[1]),
static_cast<float>(vec[2]),
static_cast<float>(vec[3]),
static_cast<float>(vec[4]),
static_cast<float>(vec[5]),
static_cast<float>(vec[6]),
static_cast<float>(vec[7]),
static_cast<float>(vec[8]),
static_cast<float>(vec[9]),
static_cast<float>(vec[10]),
static_cast<float>(vec[11]),
static_cast<float>(vec[12]),
static_cast<float>(vec[13]),
static_cast<float>(vec[14]),
static_cast<float>(vec[15])
};
}
void SHModelLoader::ReadHeaders(FileReference file, SHModelAsset& asset)
{
file.read(
@ -57,6 +103,11 @@ namespace SHADE
ReadRigHeader(file, asset.rig.header);
ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection);
ReadRigTree(file, asset.rig.header, asset.rig.root);
for (auto& mesh : asset.meshes)
{
mesh->BoneCount = asset.rig.nodeDataCollection.size();
}
}
}
@ -115,48 +166,64 @@ namespace SHADE
auto& node = data[i];
node.name.resize(header.charCounts[i]);
file.read(
data[i].name.data(),
node.name.data(),
header.charCounts[i]
);
file.read(
reinterpret_cast<char*>(&node.inverseBindMatrix),
sizeof(SHMatrix)
);
NodeDataFlag flag;
file.get(reinterpret_cast<char&>(flag));
SHVec3 scale{ SHVec3::One }, translation{ SHVec3::Zero };
SHVec4 rotation{ SHVec4::UnitW };
SHMatrix matrix{ SHMatrix::Identity };
std::vector<double> carrier;
if (flag & NODE_DATA_ROTATION)
{
node.rotation.resize(NODE_COMPONENT_COUNT_ROTATION);
carrier.resize(NODE_COMPONENT_COUNT_ROTATION);
file.read(
reinterpret_cast<char*>(node.rotation.data()),
reinterpret_cast<char*>(carrier.data()),
sizeof(double) * NODE_COMPONENT_COUNT_ROTATION
);
rotation = GetVec4FromVector(carrier);
}
if (flag & NODE_DATA_SCALE)
{
node.scale.resize(NODE_COMPONENT_COUNT_SCALE);
carrier.resize(NODE_COMPONENT_COUNT_SCALE);
file.read(
reinterpret_cast<char*>(node.scale.data()),
reinterpret_cast<char*>(carrier.data()),
sizeof(double) * NODE_COMPONENT_COUNT_SCALE
);
scale = GetVec3FromVector(carrier);
}
if (flag & NODE_DATA_TRANSLATION)
{
node.translation.resize(NODE_COMPONENT_COUNT_TRANSLATION);
carrier.resize(NODE_COMPONENT_COUNT_TRANSLATION);
file.read(
reinterpret_cast<char*>(node.translation.data()),
reinterpret_cast<char*>(carrier.data()),
sizeof(double) * NODE_COMPONENT_COUNT_TRANSLATION
);
translation = GetVec3FromVector(carrier);
}
if (flag & NODE_DATA_MATRIX)
{
node.matrix.resize(NODE_COMPONENT_COUNT_MATRIX);
carrier.resize(NODE_COMPONENT_COUNT_MATRIX);
file.read(
reinterpret_cast<char*>(node.matrix.data()),
sizeof(double) * NODE_DATA_MATRIX
reinterpret_cast<char*>(carrier.data()),
sizeof(double) * NODE_COMPONENT_COUNT_MATRIX
);
matrix = GetMatrixFromVector(carrier);
}
auto result{ SHMatrix::Transform(translation, rotation, scale) };
}
}
@ -230,8 +297,18 @@ namespace SHADE
if (header.hasWeights)
{
data.VertexWeights.resize(header.vertexCount);
file.read(reinterpret_cast<char*>(data.VertexWeights.data()), sizeof(VertexWeight) * header.vertexCount);
data.VertexBoneIndices.resize(header.vertexCount);
data.VertexBoneWeights.resize(header.vertexCount);
file.read(
reinterpret_cast<char*>(data.VertexBoneWeights.data()),
sizeof(SHVec4) * header.vertexCount
);
file.read(
reinterpret_cast<char*>(data.VertexBoneIndices.data()),
sizeof(SHVec4U) * header.vertexCount
);
}
meshes[i] = &data;