WIP Load new model asset structure

This commit is contained in:
Xiao Qi 2023-03-01 17:56:37 +08:00
parent bc17479284
commit f118c1c2ca
5 changed files with 77 additions and 149 deletions

View File

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

View File

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

View File

@ -17,31 +17,41 @@
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
{
uint32_t nodeCount;
std::vector<uint32_t> charCounts;
uint32_t nodeCount{};
uint32_t startNode{};
std::vector<uint32_t> charCounts{};
std::vector<uint32_t> childCount{};
std::vector<NodeDataFlag> dataFlags{};
};
struct SHRigNodeData
{
std::string name;
SHMatrix transform;
SHMatrix offset;
std::vector<double>
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;
std::vector<SHRigNodeData> nodeDataCollection;
SHRigNodeAsset* root;
std::vector<SHRigNodeData> nodeDataCollection{};
};
}

View File

@ -36,29 +36,12 @@ namespace SHADE
if (asset.header.animCount > 0)
{
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(
reinterpret_cast<char*>(&animHeader.charCount),
sizeof(uint32_t)
reinterpret_cast<char*>(&animHeader),
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);
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);
file.read(
@ -85,40 +67,8 @@ namespace SHADE
info.charCount
);
file.read(
reinterpret_cast<char*>(&data.pre),
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
);
//TODO read and parse data flags
//TODO read channels
}
void SHModelLoader::ReadRigHeader(FileReference file, SHRigDataHeader& header)

View File

@ -20,11 +20,11 @@ namespace SHADE
{
using FileReference = std::ifstream&;
void ReadAnimNode(FileReference file, SHAnimNodeInfo const& info, SHAnimData& data);
void ReadRigHeader(FileReference file, SHRigDataHeader& header);
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 ReadAnimData(FileReference file, std::vector<SHAnimDataHeader> const& headers, std::vector<SHAnimAsset*>& anims);