Specialize PATH by PAKBridge

This commit is contained in:
Jack Andersen 2020-04-08 19:46:40 -10:00
parent df229671c4
commit 73f245ee27
12 changed files with 79 additions and 109 deletions

View File

@ -1,6 +1,9 @@
#include "AROTBuilder.hpp" #include "AROTBuilder.hpp"
#include "hecl/Blender/Connection.hpp" #include "hecl/Blender/Connection.hpp"
#include "../DNAMP1/PATH.hpp" #include "PATH.hpp"
#include "DataSpec/DNAMP1/DNAMP1.hpp"
#include "DataSpec/DNAMP2/DNAMP2.hpp"
#include "DataSpec/DNAMP3/DNAMP3.hpp"
namespace DataSpec { namespace DataSpec {
logvisor::Module Log("AROTBuilder"); logvisor::Module Log("AROTBuilder");
@ -272,8 +275,8 @@ void AROTBuilder::Node::pathCountNodesAndLookups(size_t& nodeCount, size_t& look
} }
} }
template <uint32_t PathVer> template <class PAKBridge>
void AROTBuilder::Node::pathWrite(DNAPATH::PATH<PathVer>& path, const zeus::CAABox& curAABB) { void AROTBuilder::Node::pathWrite(DNAPATH::PATH<PAKBridge>& path, const zeus::CAABox& curAABB) {
if (childNodes.empty()) { if (childNodes.empty()) {
auto& n = path.octree.emplace_back(); auto& n = path.octree.emplace_back();
n.isLeaf = 1; n.isLeaf = 1;
@ -306,9 +309,9 @@ void AROTBuilder::Node::pathWrite(DNAPATH::PATH<PathVer>& path, const zeus::CAAB
} }
} }
template void AROTBuilder::Node::pathWrite<4>(DNAPATH::PATH<4>& path, const zeus::CAABox& curAABB); template void AROTBuilder::Node::pathWrite(DNAPATH::PATH<DNAMP1::PAKBridge>& path, const zeus::CAABox& curAABB);
template void AROTBuilder::Node::pathWrite<6>(DNAPATH::PATH<6>& path, const zeus::CAABox& curAABB); template void AROTBuilder::Node::pathWrite(DNAPATH::PATH<DNAMP2::PAKBridge>& path, const zeus::CAABox& curAABB);
template void AROTBuilder::Node::pathWrite<7>(DNAPATH::PATH<7>& path, const zeus::CAABox& curAABB); template void AROTBuilder::Node::pathWrite(DNAPATH::PATH<DNAMP3::PAKBridge>& path, const zeus::CAABox& curAABB);
void AROTBuilder::build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb, void AROTBuilder::build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb,
const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes) { const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes) {
@ -403,8 +406,8 @@ std::pair<std::unique_ptr<uint8_t[]>, uint32_t> AROTBuilder::buildCol(const ColM
return {std::move(ret), totalSize}; return {std::move(ret), totalSize};
} }
template <uint32_t PathVer> template <class PAKBridge>
void AROTBuilder::buildPath(DNAPATH::PATH<PathVer>& path) { void AROTBuilder::buildPath(DNAPATH::PATH<PAKBridge>& path) {
/* Accumulate total AABB and gather region boxes */ /* Accumulate total AABB and gather region boxes */
std::vector<zeus::CAABox> regionBoxes; std::vector<zeus::CAABox> regionBoxes;
regionBoxes.reserve(path.regions.size()); regionBoxes.reserve(path.regions.size());
@ -427,8 +430,8 @@ void AROTBuilder::buildPath(DNAPATH::PATH<PathVer>& path) {
rootNode.pathWrite(path, fullAABB); rootNode.pathWrite(path, fullAABB);
} }
template void AROTBuilder::buildPath<4>(DNAPATH::PATH<4>& path); template void AROTBuilder::buildPath(DNAPATH::PATH<DNAMP1::PAKBridge>& path);
template void AROTBuilder::buildPath<6>(DNAPATH::PATH<6>& path); template void AROTBuilder::buildPath(DNAPATH::PATH<DNAMP2::PAKBridge>& path);
template void AROTBuilder::buildPath<7>(DNAPATH::PATH<7>& path); template void AROTBuilder::buildPath(DNAPATH::PATH<DNAMP3::PAKBridge>& path);
} // namespace DataSpec } // namespace DataSpec

View File

@ -8,7 +8,7 @@
namespace DataSpec { namespace DataSpec {
namespace DNAPATH { namespace DNAPATH {
template <atUint32 PathVer> template <class PAKBridge>
struct PATH; struct PATH;
} }
@ -44,15 +44,15 @@ struct AROTBuilder {
void writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB); void writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB);
void pathCountNodesAndLookups(size_t& nodeCount, size_t& lookupCount); void pathCountNodesAndLookups(size_t& nodeCount, size_t& lookupCount);
template <uint32_t PathVer> template <class PAKBridge>
void pathWrite(DNAPATH::PATH<PathVer>& path, const zeus::CAABox& curAABB); void pathWrite(DNAPATH::PATH<PAKBridge>& path, const zeus::CAABox& curAABB);
} rootNode; } rootNode;
void build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb, void build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAABox& fullAabb,
const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes); const std::vector<zeus::CAABox>& meshAabbs, const std::vector<DNACMDL::Mesh>& meshes);
std::pair<std::unique_ptr<uint8_t[]>, uint32_t> buildCol(const ColMesh& mesh, BspNodeType& rootOut); std::pair<std::unique_ptr<uint8_t[]>, uint32_t> buildCol(const ColMesh& mesh, BspNodeType& rootOut);
template <uint32_t PathVer> template <class PAKBridge>
void buildPath(DNAPATH::PATH<PathVer>& path); void buildPath(DNAPATH::PATH<PAKBridge>& path);
}; };
} // namespace DataSpec } // namespace DataSpec

View File

@ -24,9 +24,9 @@ static void OutputOctreeNode(hecl::blender::PyOutStream& os, int idx, const zeus
} }
#endif #endif
template <atUint32 Ver> template <class PAKBridge>
void PATH<Ver>::sendToBlender(hecl::blender::Connection& conn, std::string_view entryName, const zeus::CMatrix4f* xf, void PATH<PAKBridge>::sendToBlender(hecl::blender::Connection& conn, std::string_view entryName,
const std::string& areaPath) { const zeus::CMatrix4f* xf, const std::string& areaPath) {
/* Open Py Stream and read sections */ /* Open Py Stream and read sections */
hecl::blender::PyOutStream os = conn.beginPythonOut(true); hecl::blender::PyOutStream os = conn.beginPythonOut(true);
os << "import bpy\n" os << "import bpy\n"
@ -176,9 +176,33 @@ void PATH<Ver>::sendToBlender(hecl::blender::Connection& conn, std::string_view
os.close(); os.close();
} }
template <atUint32 Ver> template <class PAKBridge>
bool PATH<Ver>::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, const PathMesh& mesh, bool PATH<PAKBridge>::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
hecl::blender::Token& btok) { PAKRouter<PAKBridge>& pakRouter, const typename PAKBridge::PAKType::Entry& entry,
bool force, hecl::blender::Token& btok,
std::function<void(const hecl::SystemChar*)> fileChanged) {
PATH path;
path.read(rs);
hecl::blender::Connection& conn = btok.getBlenderConnection();
if (!conn.createBlend(outPath, hecl::blender::BlendType::PathMesh))
return false;
std::string areaPath;
for (const auto& ent : hecl::DirectoryEnumerator(outPath.getParentPath().getAbsolutePath())) {
if (hecl::StringUtils::BeginsWith(ent.m_name, _SYS_STR("!area_"))) {
areaPath = hecl::SystemUTF8Conv(ent.m_name).str();
break;
}
}
const zeus::CMatrix4f* xf = pakRouter.lookupMAPATransform(entry.id);
path.sendToBlender(conn, pakRouter.getBestEntryName(entry, false), xf, areaPath);
return conn.saveBlend();
}
template <class PAKBridge>
bool PATH<PAKBridge>::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, const PathMesh& mesh,
hecl::blender::Token& btok) {
athena::io::MemoryReader r(mesh.data.data(), mesh.data.size()); athena::io::MemoryReader r(mesh.data.data(), mesh.data.size());
PATH path; PATH path;
path.read(r); path.read(r);
@ -217,8 +241,8 @@ bool PATH<Ver>::Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath&
return true; return true;
} }
template struct PATH<4>; template struct PATH<DataSpec::DNAMP1::PAKBridge>;
template struct PATH<6>; template struct PATH<DataSpec::DNAMP2::PAKBridge>;
template struct PATH<7>; template struct PATH<DataSpec::DNAMP3::PAKBridge>;
} // namespace DataSpec::DNAPATH } // namespace DataSpec::DNAPATH

View File

@ -2,17 +2,20 @@
#include "DataSpec/DNACommon/DNACommon.hpp" #include "DataSpec/DNACommon/DNACommon.hpp"
#include "DataSpec/DNACommon/PAK.hpp" #include "DataSpec/DNACommon/PAK.hpp"
#include "DataSpec/DNAMP1/DNAMP1.hpp"
#include "DataSpec/DNAMP2/DNAMP2.hpp"
#include "DataSpec/DNAMP3/DNAMP3.hpp"
namespace DataSpec::DNAPATH { namespace DataSpec::DNAPATH {
template <atUint32 Ver> template <class PAKBridge>
struct RegionPointers {}; struct RegionPointers {};
template <> template <>
struct RegionPointers<4> : BigDNA { struct RegionPointers<DataSpec::DNAMP1::PAKBridge> : BigDNA {
AT_DECL_DNA AT_DECL_DNA
Value<atUint32> regionIdxPtr; Value<atUint32> regionIdxPtr;
}; };
template <> template <>
struct RegionPointers<6> : BigDNA { struct RegionPointers<DataSpec::DNAMP2::PAKBridge> : BigDNA {
AT_DECL_DNA AT_DECL_DNA
Value<atUint32> unk0; Value<atUint32> unk0;
Value<atUint32> unk1; Value<atUint32> unk1;
@ -20,7 +23,7 @@ struct RegionPointers<6> : BigDNA {
Value<atUint32> regionIdxPtr; Value<atUint32> regionIdxPtr;
}; };
template <> template <>
struct RegionPointers<7> : BigDNA { struct RegionPointers<DataSpec::DNAMP3::PAKBridge> : BigDNA {
AT_DECL_DNA AT_DECL_DNA
Value<atUint32> unk0; Value<atUint32> unk0;
Value<atUint32> unk1; Value<atUint32> unk1;
@ -28,8 +31,9 @@ struct RegionPointers<7> : BigDNA {
Value<atUint32> regionIdxPtr; Value<atUint32> regionIdxPtr;
}; };
template <atUint32 Ver> template <class PAKBridge>
struct AT_SPECIALIZE_PARMS(4, 6, 7) PATH : BigDNA { struct AT_SPECIALIZE_PARMS(DataSpec::DNAMP1::PAKBridge, DataSpec::DNAMP2::PAKBridge, DataSpec::DNAMP3::PAKBridge) PATH
: BigDNA {
using PathMesh = hecl::blender::PathMesh; using PathMesh = hecl::blender::PathMesh;
AT_DECL_DNA AT_DECL_DNA
@ -66,7 +70,7 @@ struct AT_SPECIALIZE_PARMS(4, 6, 7) PATH : BigDNA {
Value<atUint32> regionIdx; Value<atUint32> regionIdx;
Value<atVec3f> centroid; Value<atVec3f> centroid;
Value<atVec3f> aabb[2]; Value<atVec3f> aabb[2];
Value<RegionPointers<Ver>> pointers; Value<RegionPointers<PAKBridge>> pointers;
}; };
Value<atUint32> regionCount; Value<atUint32> regionCount;
Vector<Region, AT_DNA_COUNT(regionCount)> regions; Vector<Region, AT_DNA_COUNT(regionCount)> regions;
@ -93,7 +97,11 @@ struct AT_SPECIALIZE_PARMS(4, 6, 7) PATH : BigDNA {
void sendToBlender(hecl::blender::Connection& conn, std::string_view entryName, const zeus::CMatrix4f* xf, void sendToBlender(hecl::blender::Connection& conn, std::string_view entryName, const zeus::CMatrix4f* xf,
const std::string& areaPath); const std::string& areaPath);
static bool Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, static bool Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
const PathMesh& mesh, hecl::blender::Token& btok); PAKRouter<PAKBridge>& pakRouter, const typename PAKBridge::PAKType::Entry& entry, bool force,
hecl::blender::Token& btok, std::function<void(const hecl::SystemChar*)> fileChanged);
static bool Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath, const PathMesh& mesh,
hecl::blender::Token& btok);
}; };
} // namespace DataSpec::DNAMP1 } // namespace DataSpec::DNAPATH

View File

@ -49,7 +49,7 @@ set(DNAMP1_SOURCES
ANIM.cpp ANIM.cpp
CINF.cpp CINF.cpp
EVNT.cpp EVNT.cpp
PATH.cpp PATH.hpp
CMDL.hpp CMDL.cpp CMDL.hpp CMDL.cpp
CMDLMaterials.cpp CMDLMaterials.cpp
DCLN.cpp DCLN.cpp

View File

@ -1,27 +0,0 @@
#include "DataSpec/DNAMP1/PATH.hpp"
#include "DataSpec/DNACommon/AROTBuilder.hpp"
#include "hecl/Blender/Connection.hpp"
namespace DataSpec::DNAMP1 {
bool PATH::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
std::function<void(const hecl::SystemChar*)> fileChanged) {
PATH path;
path.read(rs);
hecl::blender::Connection& conn = btok.getBlenderConnection();
if (!conn.createBlend(outPath, hecl::blender::BlendType::PathMesh))
return false;
std::string areaPath;
for (const auto& ent : hecl::DirectoryEnumerator(outPath.getParentPath().getAbsolutePath())) {
if (hecl::StringUtils::BeginsWith(ent.m_name, _SYS_STR("!area_"))) {
areaPath = hecl::SystemUTF8Conv(ent.m_name).str();
break;
}
}
const zeus::CMatrix4f* xf = pakRouter.lookupMAPATransform(entry.id);
path.sendToBlender(conn, pakRouter.getBestEntryName(entry, false), xf, areaPath);
return conn.saveBlend();
}
}

View File

@ -1,11 +1,6 @@
#pragma once #pragma once
#include "DataSpec/DNACommon/PATH.hpp" #include "DataSpec/DNACommon/PATH.hpp"
#include "DataSpec/DNAMP1/DNAMP1.hpp"
namespace DataSpec::DNAMP1 { namespace DataSpec::DNAMP1 {
struct PATH : DNAPATH::PATH<4> { using PATH = DNAPATH::PATH<PAKBridge>;
static bool Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath, } // namespace DataSpec::DNAMP1
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
std::function<void(const hecl::SystemChar*)> fileChanged);
};
} // namespace DataSpec::DNAMP1

View File

@ -23,7 +23,7 @@ set(DNAMP2_SOURCES
MREA.cpp MREA.cpp
MAPA.hpp MAPA.hpp
MAPU.hpp MAPU.hpp
PATH.hpp PATH.cpp PATH.hpp
AFSM.hpp AFSM.hpp
STRG.hpp STRG.cpp) STRG.hpp STRG.cpp)

View File

@ -1,26 +0,0 @@
#include "DataSpec/DNAMP2/PATH.hpp"
#include "hecl/Blender/Connection.hpp"
namespace DataSpec::DNAMP2 {
bool PATH::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
std::function<void(const hecl::SystemChar*)> fileChanged) {
PATH path;
path.read(rs);
hecl::blender::Connection& conn = btok.getBlenderConnection();
if (!conn.createBlend(outPath, hecl::blender::BlendType::PathMesh))
return false;
std::string areaPath;
for (const auto& ent : hecl::DirectoryEnumerator(outPath.getParentPath().getAbsolutePath())) {
if (hecl::StringUtils::BeginsWith(ent.m_name, _SYS_STR("!area_"))) {
areaPath = hecl::SystemUTF8Conv(ent.m_name).str();
break;
}
}
const zeus::CMatrix4f* xf = pakRouter.lookupMAPATransform(entry.id);
path.sendToBlender(conn, pakRouter.getBestEntryName(entry, false), xf, areaPath);
return conn.saveBlend();
}
}

View File

@ -1,14 +1,6 @@
#pragma once #pragma once
#include "DataSpec/DNACommon/PATH.hpp" #include "DataSpec/DNACommon/PATH.hpp"
#include "DataSpec/DNAMP2/DNAMP2.hpp"
namespace DataSpec::DNAMP2 { namespace DataSpec::DNAMP2 {
struct PATH : DNAPATH::PATH<6> { using PATH = DNAPATH::PATH<PAKBridge>;
static bool Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath, } // namespace DataSpec::DNAMP2
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
std::function<void(const hecl::SystemChar*)> fileChanged);
static bool Cook(const hecl::ProjectPath& outPath, const hecl::ProjectPath& inPath,
const PathMesh& mesh, hecl::blender::Token& btok);
};
}

View File

@ -661,7 +661,7 @@ struct SpecMP1 : SpecBase {
hecl::blender::Token& btok, FCookProgress progress) override { hecl::blender::Token& btok, FCookProgress progress) override {
PathMesh mesh = ds.compilePathMesh(); PathMesh mesh = ds.compilePathMesh();
ds.close(); ds.close();
DNAPATH::PATH<4>::Cook(out, in, mesh, btok); DNAMP1::PATH::Cook(out, in, mesh, btok);
} }
void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast, void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,

View File

@ -6,6 +6,7 @@
#include "DNAMP2/MLVL.hpp" #include "DNAMP2/MLVL.hpp"
#include "DNAMP2/STRG.hpp" #include "DNAMP2/STRG.hpp"
#include "DNAMP2/AGSC.hpp" #include "DNAMP2/AGSC.hpp"
#include "DNAMP2/PATH.hpp"
#include "DNAMP2/MAPA.hpp" #include "DNAMP2/MAPA.hpp"
#include "DNAMP1/CSNG.hpp" #include "DNAMP1/CSNG.hpp"
#include "DNACommon/MAPU.hpp" #include "DNACommon/MAPU.hpp"
@ -291,7 +292,7 @@ struct SpecMP2 : SpecBase {
hecl::blender::Token& btok, FCookProgress progress) override { hecl::blender::Token& btok, FCookProgress progress) override {
PathMesh mesh = ds.compilePathMesh(); PathMesh mesh = ds.compilePathMesh();
ds.close(); ds.close();
DNAPATH::PATH<6>::Cook(out, in, mesh, btok); DNAMP2::PATH::Cook(out, in, mesh, btok);
} }
void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast, void cookActor(const hecl::ProjectPath& out, const hecl::ProjectPath& in, BlendStream& ds, bool fast,