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 77 additions and 149 deletions
Showing only changes of commit f118c1c2ca - Show all commits

View File

@ -18,71 +18,53 @@
namespace SHADE namespace SHADE
{ {
enum class SHAnimationBehaviour : uint8_t enum class AnimationInterpolation : uint8_t
{ {
DEFAULT = 0x0, DEFAULT = 0x1,
CONSTANT = 0x1, LINEAR = 0x1,
LINEAR = 0x2, STEP = 0x2,
REPEAT = 0x3 CUBICSPLINE = 0x3
};
// Base
struct KeyBase
{
float time;
SHVec3 value;
}; };
// Smallest data containers // Smallest data containers
struct PositionKey struct PositionKey :KeyBase {};
{
float time;
SHVec3 value;
};
struct RotationKey struct RotationKey : KeyBase {};
{
float time;
SHVec4 value;
};
struct ScaleKey struct ScaleKey :KeyBase {};
{
float time;
SHVec3 value;
};
// Headers for read/write // Headers for read/write
struct SHAnimNodeInfo
{
uint32_t charCount;
uint32_t posKeyCount;
uint32_t rotKeyCount;
uint32_t scaKeyCount;
};
struct SHAnimDataHeader struct SHAnimDataHeader
{ {
uint32_t charCount; uint32_t charCount;
uint32_t animNodeCount; uint32_t animNodeCount;
std::vector<SHAnimNodeInfo> nodeHeaders; uint32_t frameCount;
}; };
// Main data containers // Main data containers
struct SHAnimData struct SHAnimNode
{ {
std::string name; std::string name;
SHAnimationBehaviour pre;
SHAnimationBehaviour post;
std::vector<PositionKey> positionKeys; std::vector<PositionKey> positionKeys;
std::vector<RotationKey> rotationKeys; std::vector<RotationKey> rotationKeys;
std::vector<ScaleKey> scaleKeys; std::vector<ScaleKey> scaleKeys;
}; };
struct SH_API SHAnimAsset : SHAssetData struct SH_API SHAnimAsset final : SHAssetData
{ {
std::string name; std::string name;
double duration; double duration{};
double ticksPerSecond; double ticksPerSecond{};
std::vector<SHAnimData> nodeChannels; std::vector<SHAnimNode> nodeChannels{};
//std::vector<aiMeshAnim*> meshChannels;
//std::vector<aiMeshMorphAnim*> morphMeshChannels;
}; };
} }

View File

@ -19,45 +19,31 @@
namespace SHADE namespace SHADE
{ {
constexpr int BONE_INDEX_ALIGHTMENT = 4;
struct SHMeshDataHeader struct SHMeshDataHeader
{ {
uint32_t vertexCount; uint32_t vertexCount;
uint32_t indexCount; uint32_t indexCount;
uint32_t charCount; uint32_t charCount;
uint32_t boneCount; bool hasWeights;
}; };
struct MeshBoneInfo struct VertexWeight
{ {
uint32_t charCount; SHVec4 weights;
uint32_t weightCount; // Size should be same as boneCount SHVec4U joints;
};
struct BoneWeight
{
uint32_t index;
float weight;
};
struct MeshBone
{
std::string name;
SHMatrix offset;
std::vector<BoneWeight> weights;
}; };
struct SH_API SHMeshAsset : SHAssetData struct SH_API SHMeshAsset : SHAssetData
{ {
std::string name; std::string name;
std::vector<SHVec3> VertexPositions; std::vector<SHVec3> VertexPositions{};
std::vector<SHVec3> VertexTangents; std::vector<SHVec3> VertexTangents{};
std::vector<SHVec3> VertexNormals; std::vector<SHVec3> VertexNormals{};
std::vector<SHVec2> VertexTexCoords; std::vector<SHVec2> VertexTexCoords{};
std::vector<uint32_t> Indices; std::vector<uint32_t> Indices{};
std::vector<SHVec4U> VertexBoneIndices;
std::vector<SHVec4> VertexBoneWeights; //Variables
uint32_t BoneCount; std::vector<VertexWeight> VertexWeights{};
}; };
} }

View File

@ -17,31 +17,41 @@
namespace SHADE namespace SHADE
{ {
using NodeDataFlag = unsigned char;
constexpr NodeDataFlag NODE_DATA_ROTATION = 0b0001;
constexpr NodeDataFlag NODE_DATA_SCALE = 0b0010;
constexpr NodeDataFlag NODE_DATA_TRANSLATION = 0b0100;
constexpr NodeDataFlag NODE_DATA_MATRIX = 0b1000;
constexpr size_t NODE_COMPONENT_COUNT_ROTATION{ 4 };
constexpr size_t NODE_COMPONENT_COUNT_SCALE{ 3 };
constexpr size_t NODE_COMPONENT_COUNT_TRANSLATION{ 3 };
constexpr size_t NODE_COMPONENT_COUNT_MATRIX{ 16 };
struct SHRigDataHeader struct SHRigDataHeader
{ {
uint32_t nodeCount; uint32_t nodeCount{};
std::vector<uint32_t> charCounts; uint32_t startNode{};
std::vector<uint32_t> charCounts{};
std::vector<uint32_t> childCount{};
std::vector<NodeDataFlag> dataFlags{};
}; };
struct SHRigNodeData struct SHRigNodeData
{ {
std::string name; std::string name;
SHMatrix transform; std::vector<double>
SHMatrix offset; rotation,
scale,
translation,
matrix;
SHMatrix inverseBindMatrix;
}; };
struct SHRigNodeAsset struct SH_API SHRigAsset final : SHAssetData
{ {
uint32_t idRef;
std::vector<SHRigNodeAsset*> children;
};
struct SH_API SHRigAsset : SHAssetData
{
~SHRigAsset();
SHRigDataHeader header; SHRigDataHeader header;
std::vector<SHRigNodeData> nodeDataCollection; std::vector<SHRigNodeData> nodeDataCollection{};
SHRigNodeAsset* root;
}; };
} }

View File

@ -36,29 +36,12 @@ namespace SHADE
if (asset.header.animCount > 0) if (asset.header.animCount > 0)
{ {
asset.animHeaders.resize(asset.header.animCount); asset.animHeaders.resize(asset.header.animCount);
for (auto i {0}; i < asset.header.animCount; ++i) for (auto& animHeader : asset.animHeaders)
{ {
auto& animHeader = asset.animHeaders[i];
file.read( file.read(
reinterpret_cast<char*>(&animHeader.charCount), reinterpret_cast<char*>(&animHeader),
sizeof(uint32_t) sizeof(animHeader)
); );
file.read(
reinterpret_cast<char*>(&animHeader.animNodeCount),
sizeof(uint32_t)
);
animHeader.nodeHeaders.resize(animHeader.animNodeCount);
for (auto j {0}; j < animHeader.animNodeCount; ++j)
{
auto& nodeHeader = animHeader.nodeHeaders[j];
file.read(
reinterpret_cast<char*>(&nodeHeader),
sizeof(SHAnimNodeInfo)
);
}
} }
} }
} }
@ -73,11 +56,10 @@ namespace SHADE
{ {
ReadRigHeader(file, asset.rig.header); ReadRigHeader(file, asset.rig.header);
ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection); ReadRigData(file, asset.rig.header, asset.rig.nodeDataCollection);
ReadRigTree(file, asset.rig.header, asset.rig.root);
} }
} }
void SHModelLoader::ReadAnimNode(FileReference file, SHAnimNodeInfo const& info, SHAnimData& data) void SHModelLoader::ReadAnimNode(FileReference file, SHAnimDataHeader const& info, SHAnimNode& data)
{ {
data.name.resize(info.charCount); data.name.resize(info.charCount);
file.read( file.read(
@ -85,40 +67,8 @@ namespace SHADE
info.charCount info.charCount
); );
file.read( //TODO read and parse data flags
reinterpret_cast<char*>(&data.pre), //TODO read channels
sizeof(SHAnimationBehaviour)
);
file.read(
reinterpret_cast<char*>(&data.post),
sizeof(SHAnimationBehaviour)
);
uint32_t keySize {0};
file.read(
reinterpret_cast<char*>(&keySize),
sizeof(uint32_t)
);
data.positionKeys.resize(keySize);
data.rotationKeys.resize(keySize);
data.scaleKeys.resize(keySize);
file.read(
reinterpret_cast<char*>(data.positionKeys.data()),
sizeof(PositionKey) * keySize
);
file.read(
reinterpret_cast<char*>(data.rotationKeys.data()),
sizeof(RotationKey) * keySize
);
file.read(
reinterpret_cast<char*>(data.scaleKeys.data()),
sizeof(ScaleKey) * keySize
);
} }
void SHModelLoader::ReadRigHeader(FileReference file, SHRigDataHeader& header) void SHModelLoader::ReadRigHeader(FileReference file, SHRigDataHeader& header)

View File

@ -20,11 +20,11 @@ namespace SHADE
{ {
using FileReference = std::ifstream&; using FileReference = std::ifstream&;
void ReadAnimNode(FileReference file, SHAnimNodeInfo const& info, SHAnimData& data);
void ReadRigHeader(FileReference file, SHRigDataHeader& header); void ReadRigHeader(FileReference file, SHRigDataHeader& header);
void ReadRigData(FileReference file, SHRigDataHeader const& header, std::vector<SHRigNodeData>& data); void ReadRigData(FileReference file, SHRigDataHeader const& header, std::vector<SHRigNodeData>& data);
void ReadRigTree(FileReference file, SHRigDataHeader const& header, SHRigNodeAsset*& root); void ReadAnimNode(FileReference file, SHAnimDataHeader const& info, SHAnimNode& data);
void ReadAnimNode(FileReference file, SHAnimNode& data);
void ReadMeshData(FileReference file, std::vector<SHMeshDataHeader> const& headers, std::vector<SHMeshAsset*>& meshes); void ReadMeshData(FileReference file, std::vector<SHMeshDataHeader> const& headers, std::vector<SHMeshAsset*>& meshes);
void ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers, std::vector<SHAnimAsset*>& anims); void ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers, std::vector<SHAnimAsset*>& anims);