mirror of https://github.com/AxioDL/metaforce.git
Initial PATH extraction support
This commit is contained in:
parent
e4ff23c279
commit
96662eb47c
|
@ -16,7 +16,7 @@ struct AT_SPECIALIZE_PARMS(DataSpec::UniqueID32, DataSpec::UniqueID64) DGRP : Bi
|
|||
{
|
||||
AT_DECL_DNA_YAML
|
||||
DNAFourCC type;
|
||||
IDType id;
|
||||
Value<IDType> id;
|
||||
};
|
||||
|
||||
Vector<ObjectTag, DNA_COUNT(dependCount)> depends;
|
||||
|
|
|
@ -104,7 +104,7 @@ struct AT_SPECIALIZE_PARMS(DataSpec::UniqueID32, DataSpec::UniqueID64) FONT : Bi
|
|||
Value<atUint32> unknown4;
|
||||
Value<atUint32> fontSize; // in points
|
||||
String<-1> name;
|
||||
IDType textureId;
|
||||
Value<IDType> textureId;
|
||||
Value<atUint32> textureFormat;
|
||||
Value<atUint32> glyphCount;
|
||||
std::vector<std::unique_ptr<IGlyph>> glyphs;
|
||||
|
|
|
@ -69,7 +69,7 @@ struct AT_SPECIALIZE_PARMS(DataSpec::UniqueID32, DataSpec::UniqueID64) FSM2 : Bi
|
|||
String<-1> name;
|
||||
Value<atUint32> unknownCount;
|
||||
Vector<CommonStruct, DNA_COUNT(unknownCount)> unknown;
|
||||
IDType fsmId;
|
||||
Value<IDType> fsmId;
|
||||
};
|
||||
|
||||
Vector<State, DNA_COUNT(stateCount)> states;
|
||||
|
@ -134,7 +134,7 @@ struct AT_SPECIALIZE_PARMS(DataSpec::UniqueID32, DataSpec::UniqueID64) FSM2 : Bi
|
|||
Value<atUint32> unknown4;
|
||||
Value<atUint32> unknown5Count;
|
||||
Vector<CommonStruct, DNA_COUNT(unknown5Count)> unknown5;
|
||||
IDType fsmId;
|
||||
Value<IDType> fsmId;
|
||||
};
|
||||
|
||||
Vector<State, DNA_COUNT(stateCount)> states;
|
||||
|
|
|
@ -472,6 +472,8 @@ std::string PAKRouter<BRIDGETYPE>::getBestEntryName(const EntryType& entry, bool
|
|||
return "!area";
|
||||
else if (entry.type == FOURCC('MAPA'))
|
||||
return "!map";
|
||||
else if (entry.type == FOURCC('PATH'))
|
||||
return "!path";
|
||||
}
|
||||
|
||||
bool named;
|
||||
|
@ -501,6 +503,8 @@ std::string PAKRouter<BRIDGETYPE>::getBestEntryName(const IDType& entry, bool st
|
|||
return "!area";
|
||||
else if (e->type == FOURCC('MAPA'))
|
||||
return "!map";
|
||||
else if (e->type == FOURCC('PATH'))
|
||||
return "!path";
|
||||
}
|
||||
|
||||
bool named;
|
||||
|
|
|
@ -50,6 +50,7 @@ set(DNAMP1_SOURCES
|
|||
ANIM.cpp
|
||||
CINF.cpp
|
||||
EVNT.cpp
|
||||
PATH.cpp
|
||||
CMDL.hpp CMDL.cpp
|
||||
CMDLMaterials.cpp
|
||||
DCLN.cpp
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "AGSC.hpp"
|
||||
#include "CSNG.hpp"
|
||||
#include "DCLN.hpp"
|
||||
#include "PATH.hpp"
|
||||
|
||||
#include "../DNACommon/Tweaks/TweakWriter.hpp"
|
||||
#include "Tweaks/CTweakPlayerRes.hpp"
|
||||
|
@ -272,6 +273,21 @@ void PAKBridge::addCMDLRigPairs(PAKRouter<PAKBridge>& pakRouter,
|
|||
}
|
||||
}
|
||||
|
||||
void PAKBridge::addPATHToMREA(PAKRouter<PAKBridge>& pakRouter,
|
||||
std::unordered_map<UniqueID32, UniqueID32>& pathToMrea) const
|
||||
{
|
||||
for (const std::pair<UniqueID32, PAK::Entry>& entry : m_pak.m_entries)
|
||||
{
|
||||
if (entry.second.type == FOURCC('MREA'))
|
||||
{
|
||||
PAKEntryReadStream rs = entry.second.beginReadStream(m_node);
|
||||
UniqueID32 pathID = MREA::GetPATHId(rs);
|
||||
if (pathID)
|
||||
pathToMrea[pathID] = entry.first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static const atVec4f BottomRow = {0.f, 0.f, 0.f, 1.f};
|
||||
|
||||
void PAKBridge::addMAPATransforms(PAKRouter<PAKBridge>& pakRouter,
|
||||
|
@ -294,6 +310,20 @@ void PAKBridge::addMAPATransforms(PAKRouter<PAKBridge>& pakRouter,
|
|||
|
||||
for (const MLVL::Area& area : mlvl.areas)
|
||||
{
|
||||
{
|
||||
/* Get PATH transform */
|
||||
const nod::Node* areaNode;
|
||||
const PAK::Entry* areaEntry = pakRouter.lookupEntry(area.areaMREAId, &areaNode);
|
||||
PAKEntryReadStream rs = areaEntry->beginReadStream(*areaNode);
|
||||
UniqueID32 pathId = MREA::GetPATHId(rs);
|
||||
if (pathId)
|
||||
addTo[pathId] = zeus::CMatrix4f(
|
||||
area.transformMtx[0],
|
||||
area.transformMtx[1],
|
||||
area.transformMtx[2],
|
||||
BottomRow).transposed();
|
||||
}
|
||||
|
||||
hecl::ProjectPath areaDirPath = pakRouter.getWorking(area.areaMREAId).getParentPath();
|
||||
if (area.areaNameId)
|
||||
pathOverrides[area.areaNameId] = hecl::ProjectPath(areaDirPath, _S("!name.yaml"));
|
||||
|
@ -361,6 +391,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK& pak, const PAK::En
|
|||
return {MAPA::Extract, {_S(".blend")}, 4};
|
||||
case SBIG('MAPU'):
|
||||
return {MAPU::Extract, {_S(".blend")}, 5};
|
||||
case SBIG('PATH'):
|
||||
return {PATH::Extract, {_S(".blend")}, 5};
|
||||
case SBIG('PART'):
|
||||
return {DNAParticle::ExtractGPSM<UniqueID32>, {_S(".gpsm.yaml")}};
|
||||
case SBIG('ELSC'):
|
||||
|
|
|
@ -37,6 +37,9 @@ public:
|
|||
std::unordered_map<UniqueID32, std::pair<UniqueID32, UniqueID32>>& addTo,
|
||||
std::unordered_map<UniqueID32, std::pair<UniqueID32, std::string>>& cskrCinfToAncs) const;
|
||||
|
||||
void addPATHToMREA(PAKRouter<PAKBridge>& pakRouter,
|
||||
std::unordered_map<UniqueID32, UniqueID32>& pathToMrea) const;
|
||||
|
||||
void addMAPATransforms(PAKRouter<PAKBridge>& pakRouter,
|
||||
std::unordered_map<UniqueID32, zeus::CMatrix4f>& addTo,
|
||||
std::unordered_map<UniqueID32, hecl::ProjectPath>& pathOverrides) const;
|
||||
|
|
|
@ -58,6 +58,24 @@ void MREA::AddCMDLRigPairs(PAKEntryReadStream& rs,
|
|||
scly.addCMDLRigPairs(pakRouter, addTo);
|
||||
}
|
||||
|
||||
UniqueID32 MREA::GetPATHId(PAKEntryReadStream& rs)
|
||||
{
|
||||
/* Do extract */
|
||||
Header head;
|
||||
head.read(rs);
|
||||
rs.seekAlign32();
|
||||
|
||||
/* Skip to PATH */
|
||||
atUint32 curSec = 0;
|
||||
atUint64 secStart = rs.position();
|
||||
while (curSec != head.pathSecIdx)
|
||||
secStart += head.secSizes[curSec++];
|
||||
if (!head.secSizes[curSec])
|
||||
return {};
|
||||
rs.seek(secStart, athena::Begin);
|
||||
return {rs};
|
||||
}
|
||||
|
||||
/* Collision octree dumper */
|
||||
static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryReader& r,
|
||||
BspNodeType type, const zeus::CAABox& aabb)
|
||||
|
|
|
@ -106,6 +106,8 @@ struct MREA
|
|||
PAKRouter<PAKBridge>& pakRouter,
|
||||
std::unordered_map<UniqueID32, std::pair<UniqueID32, UniqueID32>>& addTo);
|
||||
|
||||
static UniqueID32 GetPATHId(PAKEntryReadStream& rs);
|
||||
|
||||
static bool Extract(const SpecBase& dataSpec,
|
||||
PAKEntryReadStream& rs,
|
||||
const hecl::ProjectPath& outPath,
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
#include "PATH.hpp"
|
||||
#include "hecl/Blender/Connection.hpp"
|
||||
#include <unordered_set>
|
||||
|
||||
namespace DataSpec::DNAMP1
|
||||
{
|
||||
|
||||
void PATH::sendToBlender(hecl::blender::Connection& conn, std::string_view entryName,
|
||||
const zeus::CMatrix4f* xf)
|
||||
{
|
||||
/* Open Py Stream and read sections */
|
||||
hecl::blender::PyOutStream os = conn.beginPythonOut(true);
|
||||
os.format("import bpy\n"
|
||||
"import bmesh\n"
|
||||
"from mathutils import Vector, Matrix\n"
|
||||
"\n"
|
||||
"material_dict = {}\n"
|
||||
"material_index = []\n"
|
||||
"def select_material(data):\n"
|
||||
" if data in material_index:\n"
|
||||
" return material_index.index(data)\n"
|
||||
" elif data in material_dict:\n"
|
||||
" material_index.append(data)\n"
|
||||
" return len(material_index)-1\n"
|
||||
" else:\n"
|
||||
" mat = bpy.data.materials.new(data)\n"
|
||||
" material_dict[data] = mat\n"
|
||||
" material_index.append(data)\n"
|
||||
" return len(material_index)-1\n"
|
||||
"\n"
|
||||
"bpy.context.scene.name = '%s'\n"
|
||||
"# Clear Scene\n"
|
||||
"for ob in bpy.data.objects:\n"
|
||||
" if ob.type != 'CAMERA':\n"
|
||||
" bpy.context.scene.objects.unlink(ob)\n"
|
||||
" bpy.data.objects.remove(ob)\n"
|
||||
"\n"
|
||||
"bm = bmesh.new()\n",
|
||||
entryName.data());
|
||||
|
||||
for (const Node& n : nodes)
|
||||
os.format("bm.verts.new((%f,%f,%f))\n",
|
||||
n.position.vec[0], n.position.vec[1], n.position.vec[2]);
|
||||
|
||||
os << "bm.verts.ensure_lookup_table()\n";
|
||||
|
||||
std::unordered_set<u32> uset;
|
||||
FILE* fp = fopen("/Users/jacko/Desktop/PATHMats.txt", "a");
|
||||
fprintf(fp, "%s\n", conn.getBlendPath().getRelativePathUTF8().data());
|
||||
|
||||
for (const Region& r : regions)
|
||||
{
|
||||
os << "tri_verts = []\n";
|
||||
for (int i=0 ; i<r.nodeCount ; ++i)
|
||||
os.format("tri_verts.append(bm.verts[%u])\n", r.nodeStart + i);
|
||||
|
||||
zeus::CVector3f centroid = r.centroid;
|
||||
if (xf)
|
||||
centroid = xf->multiplyOneOverW(centroid);
|
||||
os.format("face = bm.faces.get(tri_verts)\n"
|
||||
"if face is None:\n"
|
||||
" face = bm.faces.new(tri_verts)\n"
|
||||
" face.normal_flip()\n"
|
||||
"face.material_index = select_material('0x%08X')\n"
|
||||
"face.smooth = False\n"
|
||||
"hobj = bpy.data.objects.new('Height', None)\n"
|
||||
"hobj.location = (%f,%f,%f)\n"
|
||||
"hobj.layers[1] = True\n"
|
||||
"bpy.context.scene.objects.link(hobj)\n"
|
||||
"\n", r.flags, centroid.v[0], centroid.v[1], centroid.v[2] + r.height);
|
||||
|
||||
if (uset.find(r.flags) == uset.end())
|
||||
{
|
||||
fprintf(fp, "%08X\n", r.flags);
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
os << "path_mesh = bpy.data.meshes.new('PATH')\n"
|
||||
"bm.to_mesh(path_mesh)\n"
|
||||
"path_mesh_obj = bpy.data.objects.new(path_mesh.name, path_mesh)\n"
|
||||
"\n"
|
||||
"for mat_name in material_index:\n"
|
||||
" mat = material_dict[mat_name]\n"
|
||||
" path_mesh.materials.append(mat)\n"
|
||||
"\n"
|
||||
"bpy.context.scene.objects.link(path_mesh_obj)\n"
|
||||
"path_mesh_obj.draw_type = 'SOLID'\n"
|
||||
"path_mesh_obj.game.physics_type = 'STATIC'\n"
|
||||
"path_mesh_obj.layers[1] = True\n"
|
||||
"bpy.context.scene.hecl_path_obj = path_mesh_obj.name\n"
|
||||
"\n"
|
||||
"for ar in bpy.context.screen.areas:\n"
|
||||
" for sp in ar.spaces:\n"
|
||||
" if sp.type == 'VIEW_3D':\n"
|
||||
" sp.viewport_shade = 'SOLID'\n";
|
||||
|
||||
if (xf)
|
||||
{
|
||||
const zeus::CMatrix4f& w = *xf;
|
||||
os.format("mtx = Matrix(((%f,%f,%f,%f),(%f,%f,%f,%f),(%f,%f,%f,%f),(0.0,0.0,0.0,1.0)))\n"
|
||||
"mtxd = mtx.decompose()\n"
|
||||
"path_mesh_obj.rotation_mode = 'QUATERNION'\n"
|
||||
"path_mesh_obj.location = mtxd[0]\n"
|
||||
"path_mesh_obj.rotation_quaternion = mtxd[1]\n"
|
||||
"path_mesh_obj.scale = mtxd[2]\n",
|
||||
w.m[0][0], w.m[1][0], w.m[2][0], w.m[3][0],
|
||||
w.m[0][1], w.m[1][1], w.m[2][1], w.m[3][1],
|
||||
w.m[0][2], w.m[1][2], w.m[2][2], w.m[3][2]);
|
||||
}
|
||||
|
||||
os.linkBackground("//!area.blend");
|
||||
os.centerView();
|
||||
os.close();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
const zeus::CMatrix4f* xf = pakRouter.lookupMAPATransform(entry.id);
|
||||
path.sendToBlender(conn, pakRouter.getBestEntryName(entry, false), xf);
|
||||
return conn.saveBlend();
|
||||
}
|
||||
|
||||
bool PATH::Cook(const hecl::ProjectPath& outPath,
|
||||
const hecl::ProjectPath& inPath,
|
||||
const PathMesh& mesh,
|
||||
hecl::blender::Connection* conn)
|
||||
{
|
||||
PATH path;
|
||||
|
||||
athena::io::FileWriter w(outPath.getAbsolutePath());
|
||||
path.write(w);
|
||||
int64_t rem = w.position() % 32;
|
||||
if (rem)
|
||||
for (int64_t i=0 ; i<32-rem ; ++i)
|
||||
w.writeUByte(0xff);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,11 +2,15 @@
|
|||
#define __DNACOMMON_PATH_HPP__
|
||||
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
#include "DNAMP1.hpp"
|
||||
|
||||
namespace DataSpec
|
||||
namespace DataSpec::DNAMP1
|
||||
{
|
||||
struct PATH : BigDNA
|
||||
{
|
||||
using PathMesh = hecl::blender::PathMesh;
|
||||
|
||||
AT_DECL_DNA
|
||||
Value<atUint32> version;
|
||||
|
||||
|
@ -66,6 +70,23 @@ struct PATH : BigDNA
|
|||
};
|
||||
Value<atUint32> octreeNodeCount;
|
||||
Vector<OctreeNode, DNA_COUNT(octreeNodeCount)> octree;
|
||||
|
||||
void sendToBlender(hecl::blender::Connection& conn, std::string_view entryName,
|
||||
const zeus::CMatrix4f* xf);
|
||||
|
||||
static bool 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);
|
||||
|
||||
static bool Cook(const hecl::ProjectPath& outPath,
|
||||
const hecl::ProjectPath& inPath,
|
||||
const PathMesh& mesh,
|
||||
hecl::blender::Connection* conn = nullptr);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit 3ad5f6dee2e5a7742700d8e16124d39c62a49eca
|
||||
Subproject commit c6ebab72a5738c616cd18b7fbe59f3f802b6fdd8
|
2
specter
2
specter
|
@ -1 +1 @@
|
|||
Subproject commit 5c6e64c53f831b405e23dc2a105a16259dc5a076
|
||||
Subproject commit c6069bbf540ebe2ca1f1f112c33e5a169214f18d
|
Loading…
Reference in New Issue