summaryrefslogtreecommitdiff
path: root/src/factories/sm64/AnimationFactory.cpp
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-03-28 22:19:27 -0600
committerKiritoDv <kiritodev01@gmail.com>2024-03-28 22:19:27 -0600
commit42d95d50fd6f8d41db71ff7f42d1260df84c1c1d (patch)
tree511fa7ace7500edafb8ea1ab87135faa2c8db376 /src/factories/sm64/AnimationFactory.cpp
parenta7d7acdc4219d474597960b55fea06b06e1911ad (diff)
WIP Collision factoryfeature/sm64-collision
Diffstat (limited to 'src/factories/sm64/AnimationFactory.cpp')
-rw-r--r--src/factories/sm64/AnimationFactory.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/src/factories/sm64/AnimationFactory.cpp b/src/factories/sm64/AnimationFactory.cpp
index 1b4070d..3174cd5 100644
--- a/src/factories/sm64/AnimationFactory.cpp
+++ b/src/factories/sm64/AnimationFactory.cpp
@@ -1,6 +1,10 @@
#include "AnimationFactory.h"
+
+#include <utils/Decompressor.h>
#include "spdlog/spdlog.h"
+#define ANIM_INDEX_COUNT(boneCount) ((boneCount) + 1) * 2 * 6
+
ExportResult SM64::AnimationBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
const auto anim = std::static_pointer_cast<AnimationData>(raw);
@@ -29,11 +33,7 @@ ExportResult SM64::AnimationBinaryExporter::Export(std::ostream &write, std::sha
}
std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
- auto headerNode = GetSafeNode<YAML::Node>(node, "header");
- auto valuesNode = GetSafeNode<YAML::Node>(node, "values");
- auto indexNode = GetSafeNode<YAML::Node>(node, "indices");
-
- LUS::BinaryReader header(reinterpret_cast<char *>(buffer.data()) + GetSafeNode<uint32_t>(headerNode, "offset"), GetSafeNode<uint32_t>(headerNode, "size"));
+ auto header = Decompressor::AutoDecode(node, buffer).GetReader();
header.SetEndianness(LUS::Endianness::Big);
auto flags = header.ReadInt16();
@@ -42,26 +42,27 @@ std::optional<std::shared_ptr<IParsedData>> SM64::AnimationFactory::parse(std::v
auto loopStart = header.ReadInt16();
auto loopEnd = header.ReadInt16();
auto unusedBoneCount = header.ReadInt16();
- header.ReadUInt32();
- header.ReadUInt32();
+ auto valuesAddr = header.ReadUInt32();
+ auto indicesAddr = header.ReadUInt32();
auto length = header.ReadUInt32();
- LUS::BinaryReader indices(reinterpret_cast<char*>(buffer.data()) + GetSafeNode<uint32_t>(indexNode, "offset"), GetSafeNode<uint32_t>(indexNode, "size"));
- indices.SetEndianness(LUS::Endianness::Big);
- size_t indexLength = GetSafeNode<uint32_t>(indexNode, "size") / sizeof(int16_t);
- std::vector<int16_t> indicesData;
- for (size_t i = 0; i < indexLength; i++) {
- indicesData.push_back(indices.ReadInt16());
- }
+ auto values = Decompressor::AutoDecodeByOffset(valuesAddr, indicesAddr - valuesAddr, buffer).GetReader();
+ values.SetEndianness(LUS::Endianness::Big);
- LUS::BinaryReader values(reinterpret_cast<char*>(buffer.data()) + GetSafeNode<uint32_t>(valuesNode, "offset"), GetSafeNode<uint32_t>(valuesNode, "size"));
- values.SetEndianness(LUS::Endianness::Big);
- size_t entries = GetSafeNode<uint32_t>(valuesNode, "size") / sizeof(uint16_t);
std::vector<uint16_t> valuesData;
- for (size_t i = 0; i < entries; i++) {
+ for (size_t i = 0; i < values.GetLength() / sizeof(uint16_t); i++) {
valuesData.push_back(values.ReadUInt16());
}
+ auto indicesCount = ANIM_INDEX_COUNT(unusedBoneCount);
+ auto indices = Decompressor::AutoDecodeByOffset(indicesAddr, indicesCount * sizeof(int16_t), buffer).GetReader();
+ indices.SetEndianness(LUS::Endianness::Big);
+
+ std::vector<int16_t> indicesData;
+ for (size_t i = 0; i < indicesCount; i++) {
+ indicesData.push_back(indices.ReadInt16());
+ }
+
SPDLOG_INFO("Flags: {}", flags);
SPDLOG_INFO("Anim-Y Trans Divisor: {}", animYTransDivisor);
SPDLOG_INFO("Start Frame: {}", startFrame);