mirror of
https://github.com/HarbourMasters/Shipwright.git
synced 2025-02-15 06:40:22 -05:00
animation
This commit is contained in:
parent
8a14fea94c
commit
e87ade4ebd
@ -1 +1 @@
|
||||
Subproject commit d8f3c4dd4a46fb46c4f69cd387afadfa711606e9
|
||||
Subproject commit bfb5bc6971f6f39c48a2642c0fa889ad2e6dd81e
|
@ -1 +1 @@
|
||||
Subproject commit 825bd1275bc26a8532f07a887db5141cd635df13
|
||||
Subproject commit a5d269dc484451170183515a079d3419deac3bd5
|
@ -92,6 +92,7 @@ GameInteractorSail* GameInteractorSail::Instance;
|
||||
#include <libultraship/libultraship.h>
|
||||
|
||||
// Resource Types/Factories
|
||||
#include "soh/resource/type/SohResourceType.h"
|
||||
#include "soh/resource/type/Animation.h"
|
||||
#include "soh/resource/type/AudioSample.h"
|
||||
#include "soh/resource/type/AudioSequence.h"
|
||||
@ -319,19 +320,21 @@ OTRGlobals::OTRGlobals() {
|
||||
|
||||
SPDLOG_INFO("Starting Ship of Harkinian version {}", (char*)gBuildVersion);
|
||||
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Animation), std::make_shared<LUS::AnimationFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_PlayerAnimation), std::make_shared<LUS::PlayerAnimationFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Room), std::make_shared<LUS::SceneFactory>()); // Is room scene? maybe?
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_CollisionHeader), std::make_shared<LUS::CollisionHeaderFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Skeleton), std::make_shared<LUS::SkeletonFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_SkeletonLimb), std::make_shared<LUS::SkeletonLimbFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Path), std::make_shared<LUS::PathFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Cutscene), std::make_shared<LUS::CutsceneFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Text), std::make_shared<LUS::TextFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSample), std::make_shared<LUS::AudioSampleFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSoundFont), std::make_shared<LUS::AudioSoundFontFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_AudioSequence), std::make_shared<LUS::AudioSequenceFactory>());
|
||||
context->GetResourceManager()->GetResourceLoader()->RegisterResourceFactory(static_cast<uint32_t>(LUS::ResourceType::SOH_Background), std::make_shared<LUS::BackgroundFactory>());
|
||||
auto loader = context->GetResourceManager()->GetResourceLoader();
|
||||
loader->RegisterResourceFactory(std::make_shared<ResourceFactoryBinaryAnimationV0>(), RESOURCE_FORMAT_BINARY, "SOH_Animation", static_cast<uint32_t>(SohResourceType::SOH_Animation), 0);
|
||||
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_PlayerAnimation), std::make_shared<LUS::PlayerAnimationFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Room), std::make_shared<LUS::SceneFactory>()); // Is room scene? maybe?
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_CollisionHeader), std::make_shared<LUS::CollisionHeaderFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Skeleton), std::make_shared<LUS::SkeletonFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_SkeletonLimb), std::make_shared<LUS::SkeletonLimbFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Path), std::make_shared<LUS::PathFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Cutscene), std::make_shared<LUS::CutsceneFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Text), std::make_shared<LUS::TextFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_AudioSample), std::make_shared<LUS::AudioSampleFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_AudioSoundFont), std::make_shared<LUS::AudioSoundFontFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_AudioSequence), std::make_shared<LUS::AudioSequenceFactory>());
|
||||
loader->RegisterResourceFactory(static_cast<uint32_t>(SohResourceType::SOH_Background), std::make_shared<LUS::BackgroundFactory>());
|
||||
|
||||
gSaveStateMgr = std::make_shared<SaveStateMgr>();
|
||||
gRandomizer = std::make_shared<Randomizer>();
|
||||
|
@ -2,103 +2,91 @@
|
||||
#include "soh/resource/type/Animation.h"
|
||||
#include "spdlog/spdlog.h"
|
||||
|
||||
namespace LUS {
|
||||
std::shared_ptr<IResource>
|
||||
AnimationFactory::ReadResource(std::shared_ptr<ResourceInitData> initData, std::shared_ptr<BinaryReader> reader) {
|
||||
auto resource = std::make_shared<Animation>(initData);
|
||||
std::shared_ptr<ResourceVersionFactory> factory = nullptr;
|
||||
|
||||
switch (resource->GetInitData()->ResourceVersion) {
|
||||
case 0:
|
||||
factory = std::make_shared<AnimationFactoryV0>();
|
||||
break;
|
||||
}
|
||||
|
||||
if (factory == nullptr) {
|
||||
SPDLOG_ERROR("Failed to load Animation with version {}", resource->GetInitData()->ResourceVersion);
|
||||
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryAnimationV0::ReadResource(std::shared_ptr<LUS::File> file) {
|
||||
if (file->InitData->Format != RESOURCE_FORMAT_BINARY) {
|
||||
SPDLOG_ERROR("resource file format does not match factory format.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
factory->ParseFileBinary(reader, resource);
|
||||
if (file->Reader == nullptr) {
|
||||
SPDLOG_ERROR("Failed to load resource: File has Reader ({} - {})", file->InitData->Type,
|
||||
file->InitData->Path);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return resource;
|
||||
}
|
||||
auto animation = std::make_shared<Animation>(file->InitData);
|
||||
|
||||
void LUS::AnimationFactoryV0::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
|
||||
std::shared_ptr<Animation> animation = std::static_pointer_cast<Animation>(resource);
|
||||
|
||||
ResourceVersionFactory::ParseFileBinary(reader, animation);
|
||||
|
||||
AnimationType animType = (AnimationType)reader->ReadUInt32();
|
||||
AnimationType animType = (AnimationType)file->Reader->ReadUInt32();
|
||||
animation->type = animType;
|
||||
|
||||
if (animType == AnimationType::Normal) {
|
||||
// Set frame count
|
||||
animation->animationData.animationHeader.common.frameCount = reader->ReadInt16();
|
||||
animation->animationData.animationHeader.common.frameCount = file->Reader->ReadInt16();
|
||||
|
||||
// Populate frame data
|
||||
uint32_t rotValuesCnt = reader->ReadUInt32();
|
||||
uint32_t rotValuesCnt = file->Reader->ReadUInt32();
|
||||
animation->rotationValues.reserve(rotValuesCnt);
|
||||
for (uint32_t i = 0; i < rotValuesCnt; i++) {
|
||||
animation->rotationValues.push_back(reader->ReadUInt16());
|
||||
animation->rotationValues.push_back(file->Reader->ReadUInt16());
|
||||
}
|
||||
animation->animationData.animationHeader.frameData = (int16_t*)animation->rotationValues.data();
|
||||
|
||||
// Populate joint indices
|
||||
uint32_t rotIndCnt = reader->ReadUInt32();
|
||||
uint32_t rotIndCnt = file->Reader->ReadUInt32();
|
||||
animation->rotationIndices.reserve(rotIndCnt);
|
||||
for (size_t i = 0; i < rotIndCnt; i++) {
|
||||
uint16_t x = reader->ReadUInt16();
|
||||
uint16_t y = reader->ReadUInt16();
|
||||
uint16_t z = reader->ReadUInt16();
|
||||
uint16_t x = file->Reader->ReadUInt16();
|
||||
uint16_t y = file->Reader->ReadUInt16();
|
||||
uint16_t z = file->Reader->ReadUInt16();
|
||||
animation->rotationIndices.push_back(RotationIndex(x, y, z));
|
||||
}
|
||||
animation->animationData.animationHeader.jointIndices = (JointIndex*)animation->rotationIndices.data();
|
||||
|
||||
// Set static index max
|
||||
animation->animationData.animationHeader.staticIndexMax = reader->ReadInt16();
|
||||
animation->animationData.animationHeader.staticIndexMax = file->Reader->ReadInt16();
|
||||
} else if (animType == AnimationType::Curve) {
|
||||
// Read frame count (unused in this animation type)
|
||||
reader->ReadInt16();
|
||||
file->Reader->ReadInt16();
|
||||
|
||||
// Set refIndex
|
||||
uint32_t refArrCnt = reader->ReadUInt32();
|
||||
uint32_t refArrCnt = file->Reader->ReadUInt32();
|
||||
animation->refIndexArr.reserve(refArrCnt);
|
||||
for (uint32_t i = 0; i < refArrCnt; i++) {
|
||||
animation->refIndexArr.push_back(reader->ReadUByte());
|
||||
animation->refIndexArr.push_back(file->Reader->ReadUByte());
|
||||
}
|
||||
animation->animationData.transformUpdateIndex.refIndex = animation->refIndexArr.data();
|
||||
|
||||
// Populate transform data
|
||||
uint32_t transformDataCnt = reader->ReadUInt32();
|
||||
uint32_t transformDataCnt = file->Reader->ReadUInt32();
|
||||
animation->transformDataArr.reserve(transformDataCnt);
|
||||
for (uint32_t i = 0; i < transformDataCnt; i++) {
|
||||
TransformData data;
|
||||
data.unk_00 = reader->ReadUInt16();
|
||||
data.unk_02 = reader->ReadInt16();
|
||||
data.unk_04 = reader->ReadInt16();
|
||||
data.unk_06 = reader->ReadInt16();
|
||||
data.unk_08 = reader->ReadFloat();
|
||||
data.unk_00 = file->Reader->ReadUInt16();
|
||||
data.unk_02 = file->Reader->ReadInt16();
|
||||
data.unk_04 = file->Reader->ReadInt16();
|
||||
data.unk_06 = file->Reader->ReadInt16();
|
||||
data.unk_08 = file->Reader->ReadFloat();
|
||||
|
||||
animation->transformDataArr.push_back(data);
|
||||
}
|
||||
animation->animationData.transformUpdateIndex.transformData = animation->transformDataArr.data();
|
||||
|
||||
// Populate copy values
|
||||
uint32_t copyValuesCnt = reader->ReadUInt32();
|
||||
uint32_t copyValuesCnt = file->Reader->ReadUInt32();
|
||||
animation->copyValuesArr.reserve(copyValuesCnt);
|
||||
for (uint32_t i = 0; i < copyValuesCnt; i++) {
|
||||
animation->copyValuesArr.push_back(reader->ReadInt16());
|
||||
animation->copyValuesArr.push_back(file->Reader->ReadInt16());
|
||||
}
|
||||
animation->animationData.transformUpdateIndex.copyValues = animation->copyValuesArr.data();
|
||||
} else if (animType == AnimationType::Link) {
|
||||
// Read the frame count
|
||||
animation->animationData.linkAnimationHeader.common.frameCount = reader->ReadInt16();
|
||||
animation->animationData.linkAnimationHeader.common.frameCount = file->Reader->ReadInt16();
|
||||
|
||||
// Read the segment pointer (always 32 bit, doesn't adjust for system pointer size)
|
||||
animation->animationData.linkAnimationHeader.segment = (void*)reader->ReadUInt32();
|
||||
animation->animationData.linkAnimationHeader.segment = (void*)file->Reader->ReadUInt32();
|
||||
} else if (animType == AnimationType::Legacy) {
|
||||
SPDLOG_DEBUG("BEYTAH ANIMATION?!");
|
||||
}
|
||||
|
||||
return animation;
|
||||
}
|
||||
} // namespace LUS
|
||||
|
@ -3,15 +3,7 @@
|
||||
#include "Resource.h"
|
||||
#include "ResourceFactory.h"
|
||||
|
||||
namespace LUS {
|
||||
class AnimationFactory : public ResourceFactory {
|
||||
class ResourceFactoryBinaryAnimationV0 : public LUS::ResourceFactory {
|
||||
public:
|
||||
std::shared_ptr<IResource>
|
||||
ReadResource(std::shared_ptr<ResourceInitData> initData, std::shared_ptr<BinaryReader> reader) override;
|
||||
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
|
||||
};
|
||||
|
||||
class AnimationFactoryV0 : public ResourceVersionFactory {
|
||||
public:
|
||||
void ParseFileBinary(std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) override;
|
||||
};
|
||||
}; // namespace LUS
|
||||
|
@ -3,85 +3,83 @@
|
||||
#include "Resource.h"
|
||||
#include <libultraship/libultra/types.h>
|
||||
|
||||
namespace LUS {
|
||||
enum class AnimationType {
|
||||
Normal = 0,
|
||||
Link = 1,
|
||||
Curve = 2,
|
||||
Legacy = 3,
|
||||
};
|
||||
enum class AnimationType {
|
||||
Normal = 0,
|
||||
Link = 1,
|
||||
Curve = 2,
|
||||
Legacy = 3,
|
||||
};
|
||||
|
||||
struct RotationIndex {
|
||||
uint16_t x, y, z;
|
||||
struct RotationIndex {
|
||||
uint16_t x, y, z;
|
||||
|
||||
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) {
|
||||
}
|
||||
};
|
||||
RotationIndex(uint16_t nX, uint16_t nY, uint16_t nZ) : x(nX), y(nY), z(nZ) {
|
||||
}
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/* 0x0000 */ u16 unk_00; // appears to be flags
|
||||
/* 0x0002 */ s16 unk_02;
|
||||
/* 0x0004 */ s16 unk_04;
|
||||
/* 0x0006 */ s16 unk_06;
|
||||
/* 0x0008 */ f32 unk_08;
|
||||
} TransformData; // size = 0xC
|
||||
typedef struct {
|
||||
/* 0x0000 */ u16 unk_00; // appears to be flags
|
||||
/* 0x0002 */ s16 unk_02;
|
||||
/* 0x0004 */ s16 unk_04;
|
||||
/* 0x0006 */ s16 unk_06;
|
||||
/* 0x0008 */ f32 unk_08;
|
||||
} TransformData; // size = 0xC
|
||||
|
||||
typedef struct {
|
||||
/* 0x0000 */ u8* refIndex;
|
||||
/* 0x0004 */ TransformData* transformData;
|
||||
/* 0x0008 */ s16* copyValues;
|
||||
/* 0x000C */ s16 unk_0C;
|
||||
/* 0x000E */ s16 unk_0E;
|
||||
} TransformUpdateIndex; // size = 0x10
|
||||
typedef struct {
|
||||
/* 0x0000 */ u8* refIndex;
|
||||
/* 0x0004 */ TransformData* transformData;
|
||||
/* 0x0008 */ s16* copyValues;
|
||||
/* 0x000C */ s16 unk_0C;
|
||||
/* 0x000E */ s16 unk_0E;
|
||||
} TransformUpdateIndex; // size = 0x10
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ s16 frameCount;
|
||||
} AnimationHeaderCommon;
|
||||
typedef struct {
|
||||
/* 0x00 */ s16 frameCount;
|
||||
} AnimationHeaderCommon;
|
||||
|
||||
// Index into the frame data table.
|
||||
typedef struct {
|
||||
/* 0x00 */ u16 x;
|
||||
/* 0x02 */ u16 y;
|
||||
/* 0x04 */ u16 z;
|
||||
} JointIndex; // size = 0x06
|
||||
// Index into the frame data table.
|
||||
typedef struct {
|
||||
/* 0x00 */ u16 x;
|
||||
/* 0x02 */ u16 y;
|
||||
/* 0x04 */ u16 z;
|
||||
} JointIndex; // size = 0x06
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ AnimationHeaderCommon common;
|
||||
/* 0x04 */ s16* frameData; // "tbl"
|
||||
/* 0x08 */ JointIndex* jointIndices; // "ref_tbl"
|
||||
/* 0x0C */ u16 staticIndexMax;
|
||||
} AnimationHeader; // size = 0x10
|
||||
typedef struct {
|
||||
/* 0x00 */ AnimationHeaderCommon common;
|
||||
/* 0x04 */ s16* frameData; // "tbl"
|
||||
/* 0x08 */ JointIndex* jointIndices; // "ref_tbl"
|
||||
/* 0x0C */ u16 staticIndexMax;
|
||||
} AnimationHeader; // size = 0x10
|
||||
|
||||
typedef struct {
|
||||
/* 0x00 */ AnimationHeaderCommon common;
|
||||
/* 0x04 */ void* segment;
|
||||
} LinkAnimationHeader; // size = 0x8
|
||||
typedef struct {
|
||||
/* 0x00 */ AnimationHeaderCommon common;
|
||||
/* 0x04 */ void* segment;
|
||||
} LinkAnimationHeader; // size = 0x8
|
||||
|
||||
union AnimationData {
|
||||
AnimationHeader animationHeader;
|
||||
LinkAnimationHeader linkAnimationHeader;
|
||||
TransformUpdateIndex transformUpdateIndex;
|
||||
};
|
||||
union AnimationData {
|
||||
AnimationHeader animationHeader;
|
||||
LinkAnimationHeader linkAnimationHeader;
|
||||
TransformUpdateIndex transformUpdateIndex;
|
||||
};
|
||||
|
||||
class Animation : public Resource<AnimationData> {
|
||||
public:
|
||||
using Resource::Resource;
|
||||
class Animation : public LUS::Resource<AnimationData> {
|
||||
public:
|
||||
using Resource::Resource;
|
||||
|
||||
Animation() : Resource(std::shared_ptr<ResourceInitData>()) {}
|
||||
Animation() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
|
||||
|
||||
AnimationData* GetPointer();
|
||||
size_t GetPointerSize();
|
||||
AnimationData* GetPointer();
|
||||
size_t GetPointerSize();
|
||||
|
||||
AnimationType type;
|
||||
AnimationData animationData;
|
||||
AnimationType type;
|
||||
AnimationData animationData;
|
||||
|
||||
// NORMAL
|
||||
std::vector<uint16_t> rotationValues;
|
||||
std::vector<RotationIndex> rotationIndices;
|
||||
// NORMAL
|
||||
std::vector<uint16_t> rotationValues;
|
||||
std::vector<RotationIndex> rotationIndices;
|
||||
|
||||
// CURVE
|
||||
std::vector<uint8_t> refIndexArr;
|
||||
std::vector<TransformData> transformDataArr;
|
||||
std::vector<int16_t> copyValuesArr;
|
||||
};
|
||||
}; // namespace LUS
|
||||
// CURVE
|
||||
std::vector<uint8_t> refIndexArr;
|
||||
std::vector<TransformData> transformDataArr;
|
||||
std::vector<int16_t> copyValuesArr;
|
||||
};
|
||||
|
19
soh/soh/resource/type/SohResourceType.h
Normal file
19
soh/soh/resource/type/SohResourceType.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
enum class SohResourceType {
|
||||
SOH_Animation = 0x4F414E4D, // OANM
|
||||
SOH_PlayerAnimation = 0x4F50414D, // OPAM
|
||||
SOH_Room = 0x4F524F4D, // OROM
|
||||
SOH_CollisionHeader = 0x4F434F4C, // OCOL
|
||||
SOH_Skeleton = 0x4F534B4C, // OSKL
|
||||
SOH_SkeletonLimb = 0x4F534C42, // OSLB
|
||||
SOH_Path = 0x4F505448, // OPTH
|
||||
SOH_Cutscene = 0x4F435654, // OCUT
|
||||
SOH_Text = 0x4F545854, // OTXT
|
||||
SOH_Audio = 0x4F415544, // OAUD
|
||||
SOH_AudioSample = 0x4F534D50, // OSMP
|
||||
SOH_AudioSoundFont = 0x4F534654, // OSFT
|
||||
SOH_AudioSequence = 0x4F534551, // OSEQ
|
||||
SOH_Background = 0x4F424749, // OBGI
|
||||
SOH_SceneCommand = 0x4F52434D, // ORCM
|
||||
};
|
Loading…
Reference in New Issue
Block a user