diff options
| author | Louis <35883445+louist103@users.noreply.github.com> | 2024-01-29 23:46:57 -0500 |
|---|---|---|
| committer | louist103 <35883445+louist103@users.noreply.github.com> | 2024-03-02 12:13:15 -0500 |
| commit | 2c959105cd720930303f5e3aa67a5c0871b070f8 (patch) | |
| tree | 3d278f9e12093bed1642f2542d1b2e68cc3e84d0 | |
| parent | a86929b240164af481fe1fca2d0ac19c5f206be4 (diff) | |
CKeyFrame Exporter
| -rw-r--r-- | OTRExporter/CKeyFrameExporter.cpp | 103 | ||||
| -rw-r--r-- | OTRExporter/CKeyFrameExporter.h | 18 | ||||
| -rw-r--r-- | OTRExporter/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | OTRExporter/Main.cpp | 4 |
4 files changed, 126 insertions, 1 deletions
diff --git a/OTRExporter/CKeyFrameExporter.cpp b/OTRExporter/CKeyFrameExporter.cpp new file mode 100644 index 0000000..9b3320a --- /dev/null +++ b/OTRExporter/CKeyFrameExporter.cpp @@ -0,0 +1,103 @@ +#include "CKeyFrameExporter.h"
+#include "DisplayListExporter.h"
+#include "Globals.h"
+#include "spdlog/spdlog.h"
+
+// The Win32 API defines this function for its own uses.
+#ifdef FindResource
+#undef FindResource
+#endif
+
+void OTRExporter_CKeyFrameSkel::Save(ZResource* res, const fs::path& outPath, BinaryWriter* writer) {
+ ZKeyFrameSkel* skel = (ZKeyFrameSkel*)res;
+ ZKeyFrameLimbList* list = skel->limbList.get();
+
+ WriteHeader(res, outPath, writer, LUS::ResourceType::TSH_CKeyFrameSkel);
+
+ writer->Write(skel->limbCount);
+ writer->Write(skel->dListCount);
+ writer->Write((uint8_t)skel->limbType);
+ writer->Write(list->numLimbs);
+
+
+ for (size_t i = 0; i < list->limbs.size(); i++) {
+ ZKeyFrameLimb* limb = list->limbs[i];
+ std::string name = "";
+ if (GETSEGOFFSET(limb->dlist) != SEGMENTED_NULL) {
+ bool found = Globals::Instance->GetSegmentedPtrName(GETSEGOFFSET(limb->dlist), res->parent, "", name,
+ res->parent->workerID);
+
+ if (!found) {
+ ZDisplayList* dl = (ZDisplayList*)res->parent->FindResource(limb->dlist & 0x00FFFFFF);
+ if (dl != nullptr) {
+ name = dl->GetName();
+ found = true;
+ }
+ }
+ if (found) {
+ if (name.at(0) == '&')
+ name.erase(0, 1);
+
+ name = OTRExporter_DisplayList::GetPathToRes(res, name);
+ } else {
+ spdlog::error("Texture not found: 0x{:X}", limb->dlist);
+ //writer->Write("");
+ name = "";
+ }
+ }
+ writer->Write(name);
+ writer->Write(limb->numChildren);
+ writer->Write(limb->flags);
+
+ if (skel->limbType == ZKeyframeSkelType::Normal) {
+ ZKeyFrameStandardLimb* stdLimb = (ZKeyFrameStandardLimb*)limb;
+
+ writer->Write(stdLimb->translation.x);
+ writer->Write(stdLimb->translation.y);
+ writer->Write(stdLimb->translation.z);
+ } else {
+ ZKeyFrameFlexLimb* flexLimb = (ZKeyFrameFlexLimb*)limb;
+
+ writer->Write(flexLimb->callbackIndex);
+ }
+ }
+}
+
+void OTRExporter_CKeyFrameAnim::Save(ZResource* res, const fs::path& outPath, BinaryWriter* writer) {
+ ZKeyFrameAnim* anim = (ZKeyFrameAnim*)res;
+
+ WriteHeader(res, outPath, writer, LUS::ResourceType::TSH_CKeyFrameAnim);
+
+ writer->Write((uint8_t)anim->skel->limbType);
+ if (anim->skel->limbType == ZKeyframeSkelType::Normal) {
+ writer->Write((uint32_t)anim->bitFlags.size());
+ for (const auto b : anim->bitFlags) {
+ writer->Write(b);
+ }
+ } else {
+ writer->Write((uint32_t)anim->bitFlagsFLex.size());
+ for (const auto b : anim->bitFlagsFLex) {
+ writer->Write(b);
+ }
+ }
+
+ writer->Write((uint32_t)anim->keyFrames.size());
+ for (const auto k : anim->keyFrames) {
+ writer->Write(k.frame);
+ writer->Write(k.value);
+ writer->Write(k.velocity);
+ }
+
+ writer->Write((uint32_t)anim->kfNums.size());
+ for (const auto kf : anim->kfNums) {
+ writer->Write(kf);
+ }
+
+ writer->Write((uint32_t)anim->presentValues.size());
+ for (const auto pv : anim->presentValues) {
+ writer->Write(pv);
+ }
+
+ writer->Write(anim->unk_10);
+ writer->Write(anim->duration);
+}
diff --git a/OTRExporter/CKeyFrameExporter.h b/OTRExporter/CKeyFrameExporter.h new file mode 100644 index 0000000..1c690e7 --- /dev/null +++ b/OTRExporter/CKeyFrameExporter.h @@ -0,0 +1,18 @@ +#pragma once
+
+#include "ZResource.h"
+#include "ZCKeyFrame.h"
+#include "ZCkeyFrameAnim.h"
+#include "Exporter.h"
+#include <utils/BinaryWriter.h>
+
+class OTRExporter_CKeyFrameSkel : public OTRExporter
+{
+public:
+ virtual void Save(ZResource* res, const fs::path& outPath, BinaryWriter* writer) override;
+};
+
+class OTRExporter_CKeyFrameAnim : public OTRExporter {
+ public:
+ virtual void Save(ZResource* res, const fs::path& outPath, BinaryWriter* writer) override;
+};
diff --git a/OTRExporter/CMakeLists.txt b/OTRExporter/CMakeLists.txt index 12e11fe..f7b89fd 100644 --- a/OTRExporter/CMakeLists.txt +++ b/OTRExporter/CMakeLists.txt @@ -9,6 +9,7 @@ set(Header_Files "AudioExporter.h"
"BackgroundExporter.h"
"BlobExporter.h"
+ "CKeyFrameExporter.h"
"CollisionExporter.h"
"command_macros_base.h"
"CutsceneExporter.h"
@@ -40,6 +41,7 @@ set(Source_Files "BackgroundExporter.cpp"
"BlobExporter.cpp"
"CollisionExporter.cpp"
+ "CKeyFrameExporter.cpp"
"CutsceneExporter.cpp"
"DisplayListExporter.cpp"
"Exporter.cpp"
diff --git a/OTRExporter/Main.cpp b/OTRExporter/Main.cpp index 42bfe76..99e8693 100644 --- a/OTRExporter/Main.cpp +++ b/OTRExporter/Main.cpp @@ -19,6 +19,7 @@ #include "MtxExporter.h" #include "AudioExporter.h" #include "TextureAnimationExporter.h" +#include "CKeyFrameExporter.h" #include <Globals.h> #include <Utils/DiskFile.h> #include <Utils/Directory.h> @@ -390,7 +391,8 @@ void ImportExporters() exporterSet->exporters[ZResourceType::Mtx] = new OTRExporter_MtxExporter(); exporterSet->exporters[ZResourceType::Audio] = new OTRExporter_Audio(); exporterSet->exporters[ZResourceType::TextureAnimation] = new OTRExporter_TextureAnimation(); - + exporterSet->exporters[ZResourceType::KeyFrameSkel] = new OTRExporter_CKeyFrameSkel(); + exporterSet->exporters[ZResourceType::KeyFrameAnimation] = new OTRExporter_CKeyFrameAnim(); Globals::AddExporter("OTR", exporterSet); InitVersionInfo(); |
