Merge pull request #2 from inspectredc/more-importers

more importers
This commit is contained in:
Lywx 2024-04-06 18:00:52 -06:00 committed by GitHub
commit ccd2d17a7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 244 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "libultraship/src/Context.h"
#include "resource/type/ResourceType.h"
#include "resource/importers/AnimFactory.h"
#include "resource/importers/ColPolyFactory.h"
#include "resource/importers/EnvSettingsFactory.h"
#include "resource/importers/HitboxFactory.h"
#include "resource/importers/LimbFactory.h"
@ -13,6 +14,8 @@
#include "resource/importers/ScriptCommandFactory.h"
#include "resource/importers/ScriptFactory.h"
#include "resource/importers/SkeletonFactory.h"
#include "resource/importers/Vec3fFactory.h"
#include "resource/importers/Vec3sFactory.h"
#include <Fast3D/gfx_pc.h>
#include <Fast3D/gfx_rendering_api.h>
@ -59,6 +62,9 @@ GameEngine::GameEngine() {
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryHitboxV0>(), RESOURCE_FORMAT_BINARY, "Hitbox", static_cast<uint32_t>(SF64::ResourceType::Hitbox), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptV0>(), RESOURCE_FORMAT_BINARY, "Script", static_cast<uint32_t>(SF64::ResourceType::Script), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryScriptCMDV0>(), RESOURCE_FORMAT_BINARY, "ScriptCMD", static_cast<uint32_t>(SF64::ResourceType::ScriptCmd), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryColPolyV0>(), RESOURCE_FORMAT_BINARY, "ColPoly", static_cast<uint32_t>(SF64::ResourceType::ColPoly), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3fV0>(), RESOURCE_FORMAT_BINARY, "Vec3f", static_cast<uint32_t>(SF64::ResourceType::Vec3f), 0);
loader->RegisterResourceFactory(std::make_shared<SF64::ResourceFactoryBinaryVec3sV0>(), RESOURCE_FORMAT_BINARY, "Vec3s", static_cast<uint32_t>(SF64::ResourceType::Vec3s), 0);
}
void GameEngine::Create(){

View File

@ -0,0 +1,33 @@
#include "ColPolyFactory.h"
#include "../type/ColPoly.h"
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryColPolyV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto colPoly = std::make_shared<ColPoly>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto colPolysCount = reader->ReadUInt32();
SPDLOG_INFO("ColPolyCount: {}", colPolysCount);
for (uint32_t i = 0; i < colPolysCount; i++) {
uint16_t triX = reader->ReadUInt16();
uint16_t triY = reader->ReadUInt16();
uint16_t triZ = reader->ReadUInt16();
Vec3s tri = {triX, triY, triZ};
uint16_t normX = reader->ReadUInt16();
uint16_t normY = reader->ReadUInt16();
uint16_t normZ = reader->ReadUInt16();
Vec3s norm = {normX, normY, normZ};
uint32_t dist = reader->ReadInt32();
colPoly->mColPolys.emplace_back(tri, 0, norm, 0, dist);
}
return colPoly;
}
} // namespace LUS

View File

@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryColPolyV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS

View File

@ -0,0 +1,27 @@
#include "Vec3fFactory.h"
#include "../type/Vec3fArray.h"
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryVec3fV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto vec = std::make_shared<Vec3fArray>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto vecCount = reader->ReadUInt32();
SPDLOG_INFO("Vec3f Count: {}", vecCount);
for (uint32_t i = 0; i < vecCount; i++) {
auto x = reader->ReadFloat();
auto y = reader->ReadFloat();
auto z = reader->ReadFloat();
vec->mData.emplace_back(x, y, z);
}
return vec;
}
} // namespace LUS

View File

@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryVec3fV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS

View File

@ -0,0 +1,27 @@
#include "Vec3sFactory.h"
#include "../type/Vec3sArray.h"
#include "spdlog/spdlog.h"
namespace SF64 {
std::shared_ptr<LUS::IResource> ResourceFactoryBinaryVec3sV0::ReadResource(std::shared_ptr<LUS::File> file) {
if (!FileHasValidFormatAndReader(file)) {
return nullptr;
}
auto vec = std::make_shared<Vec3sArray>(file->InitData);
auto reader = std::get<std::shared_ptr<LUS::BinaryReader>>(file->Reader);
auto vecCount = reader->ReadUInt32();
SPDLOG_INFO("Vec3s Count: {}", vecCount);
for (uint32_t i = 0; i < vecCount; i++) {
auto x = reader->ReadInt16();
auto y = reader->ReadInt16();
auto z = reader->ReadInt16();
vec->mData.emplace_back(x, y, z);
}
return vec;
}
} // namespace LUS

View File

@ -0,0 +1,11 @@
#pragma once
#include "Resource.h"
#include "ResourceFactoryBinary.h"
namespace SF64 {
class ResourceFactoryBinaryVec3sV0 : public LUS::ResourceFactoryBinary {
public:
std::shared_ptr<LUS::IResource> ReadResource(std::shared_ptr<LUS::File> file) override;
};
}; // namespace LUS

View File

@ -0,0 +1,11 @@
#include "ColPoly.h"
namespace SF64 {
ColPolyData* ColPoly::GetPointer() {
return mColPolys.data();
}
size_t ColPoly::GetPointerSize() {
return sizeof(mColPolys);
}
}

View File

@ -0,0 +1,33 @@
#pragma once
#include <cstdint>
#include <Resource.h>
#include <libultraship/libultra/types.h>
namespace SF64 {
struct Vec3s {
int16_t x, y, z;
};
struct ColPolyData {
/* 0x00 */ Vec3s tri;
/* 0x06 */ int16_t unk_06;
/* 0x08 */ Vec3s norm;
/* 0x0E */ int16_t unk_0E;
/* 0x10 */ int32_t dist;
ColPolyData(Vec3s tri, int16_t unk_06, Vec3s norm, int16_t unk_0E, int32_t dist) : tri(std::move(tri)), unk_06(unk_06), norm(std::move(norm)), unk_0E(unk_0E), dist(dist) {}
}; // size = 0x14
class ColPoly : public LUS::Resource<ColPolyData> {
public:
using Resource::Resource;
ColPoly() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
ColPolyData* GetPointer();
size_t GetPointerSize();
std::vector<ColPolyData> mColPolys;
};
}

View File

@ -14,5 +14,7 @@ enum class ResourceType {
ScriptCmd = 0x53434D44, // SCMD
Hitbox = 0x48544258, // HTBX
ObjectInit = 0x4F42494E, // OBIN
Vec3f = 0x56433346, // VC3F
Vec3s = 0x56433353, // VC3S
};
} // namespace SOH

View File

@ -0,0 +1,11 @@
#include "Vec3fArray.h"
namespace SF64 {
Vec3fData* Vec3fArray::GetPointer() {
return mData.data();
}
size_t Vec3fArray::GetPointerSize() {
return sizeof(mData);
}
}

View File

@ -0,0 +1,25 @@
#pragma once
#include <cstdint>
#include <Resource.h>
#include <libultraship/libultra/types.h>
namespace SF64 {
struct Vec3fData {
float x, y, z;
Vec3fData(float x, float y, float z) : x(x), y(y), z(z) {}
};
class Vec3fArray : public LUS::Resource<Vec3fData> {
public:
using Resource::Resource;
Vec3fArray() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
Vec3fData* GetPointer();
size_t GetPointerSize();
std::vector<Vec3fData> mData;
};
}

View File

@ -0,0 +1,11 @@
#include "Vec3sArray.h"
namespace SF64 {
Vec3sData* Vec3sArray::GetPointer() {
return mData.data();
}
size_t Vec3sArray::GetPointerSize() {
return sizeof(mData);
}
}

View File

@ -0,0 +1,25 @@
#pragma once
#include <cstdint>
#include <Resource.h>
#include <libultraship/libultra/types.h>
namespace SF64 {
struct Vec3sData {
int16_t x, y, z;
Vec3sData(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) {}
};
class Vec3sArray : public LUS::Resource<Vec3sData> {
public:
using Resource::Resource;
Vec3sArray() : Resource(std::shared_ptr<LUS::ResourceInitData>()) {}
Vec3sData* GetPointer();
size_t GetPointerSize();
std::vector<Vec3sData> mData;
};
}