diff --git a/src/Libraries/MeshCompiler.cpp b/src/Libraries/MeshCompiler.cpp index 5bf674c..b3fdaab 100644 --- a/src/Libraries/MeshCompiler.cpp +++ b/src/Libraries/MeshCompiler.cpp @@ -174,7 +174,7 @@ namespace SH_COMP head.animNodeCount = anim.nodeChannels.size(); head.nodeHeaders.resize(head.animNodeCount); - for (auto j{0}; i < head.animNodeCount; ++j) + for (auto j{0}; j < head.animNodeCount; ++j) { auto const& animNode = anim.nodeChannels[j]; auto& nodeHeader = head.nodeHeaders[j]; @@ -233,18 +233,104 @@ namespace SH_COMP void MeshCompiler::WriteAnimHeader(FileReference file, AnimDataHeader const& header) { + auto constexpr intSize = sizeof(uint32_t); + + file.write( + reinterpret_cast(&header.charCount), + intSize + ); + + file.write( + reinterpret_cast(&header.animNodeCount), + intSize + ); + + file.write( + reinterpret_cast(header.nodeHeaders.data()), + sizeof(AnimNodeInfo) * header.nodeHeaders.size() + ); } - void MeshCompiler::WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData& data) + void MeshCompiler::WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData const& data) { + file.write( + data.name.data(), + header.charCount + ); + + file.write( + reinterpret_cast(&data.duration), + sizeof(double) + ); + + file.write( + reinterpret_cast(&data.ticksPerSecond), + sizeof(double) + ); + + for (auto i{0}; i < header.animNodeCount; ++i) + { + WriteAnimNode(file, header.nodeHeaders[i], data.nodeChannels[i]); + } + } + + void MeshCompiler::WriteAnimNode(FileReference file, AnimNodeInfo const& info, AnimNode const& node) + { + file.write( + node.name.data(), + info.charCount + ); + + file.write( + reinterpret_cast(&node.pre), + sizeof(AnimationBehaviour) + ); + + file.write( + reinterpret_cast(&node.post), + sizeof(AnimationBehaviour) + ); + + file.write( + reinterpret_cast(node.positionKeys.data()), + sizeof(PositionKey) * node.positionKeys.size() + ); + + file.write( + reinterpret_cast(node.rotationKeys.data()), + sizeof(RotationKey) * node.rotationKeys.size() + ); + + file.write( + reinterpret_cast(node.scaleKeys.data()), + sizeof(ScaleKey) * node.scaleKeys.size() + ); } void MeshCompiler::WriteHeaders(FileReference file, ModelConstRef asset) { + for (auto const& header : asset.meshHeaders) + { + WriteMeshHeader(file, header); + } + + for (auto const& header : asset.animHeaders) + { + WriteAnimHeader(file, header); + } } void MeshCompiler::WriteData(FileReference file, ModelConstRef asset) { + for (auto i {0}; i < asset.meshes.size(); ++i) + { + WriteMeshData(file, asset.meshHeaders[i], asset.meshes[i]); + } + + for (auto i {0}; i < asset.anims.size(); ++i) + { + WriteAnimData(file, asset.animHeaders[i], asset.anims[i]); + } } void MeshCompiler::ParseAnimations(aiScene const& scene, std::vector& anims) noexcept @@ -357,12 +443,8 @@ namespace SH_COMP sizeof(asset.header) ); - // Write Meshes - for (auto i {0}; i < asset.meshHeaders.size(); ++i) - { - WriteMeshHeader(file, asset.meshHeaders[i]); - WriteMeshData(file, asset.meshHeaders[i], asset.meshes[i]); - } + WriteHeaders(file, asset); + WriteData(file, asset); file.close(); } diff --git a/src/Libraries/MeshCompiler.h b/src/Libraries/MeshCompiler.h index 4ba0955..da9f2b6 100644 --- a/src/Libraries/MeshCompiler.h +++ b/src/Libraries/MeshCompiler.h @@ -43,7 +43,8 @@ namespace SH_COMP static void WriteMeshData(FileReference file, MeshDataHeader const& header, MeshData const& asset); static void WriteAnimHeader(FileReference file, AnimDataHeader const& header); - static void WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData cosnt& data); + static void WriteAnimData(FileReference file, AnimDataHeader const& header, AnimData const& data); + static void WriteAnimNode(FileReference file, AnimNodeInfo const& info, AnimNode const& node); static void WriteHeaders(FileReference file, ModelConstRef asset); static void WriteData(FileReference file, ModelConstRef asset); diff --git a/src/Types/AnimationAsset.h b/src/Types/AnimationAsset.h index b69f907..ce97348 100644 --- a/src/Types/AnimationAsset.h +++ b/src/Types/AnimationAsset.h @@ -63,23 +63,24 @@ namespace SH_COMP struct AnimNode { std::string name; + AnimationBehaviour pre; + AnimationBehaviour post; + std::vector positionKeys; std::vector rotationKeys; std::vector scaleKeys; - AnimationBehaviour pre; - AnimationBehaviour post; }; struct AnimData { std::string name; + double duration; + double ticksPerSecond; + std::vector nodeChannels; //std::vector meshChannels; //std::vector morphMeshChannels; - - double duration; - double ticksPerSecond; }; } \ No newline at end of file