mirror of https://github.com/AxioDL/metaforce.git
temporary ID dumping hard-coded
This commit is contained in:
parent
fb11af23c6
commit
fa8b48d43e
|
@ -73,6 +73,7 @@ public:
|
|||
}
|
||||
|
||||
UniqueID32() = default;
|
||||
UniqueID32(Athena::io::IStreamReader& reader) {read(reader);}
|
||||
UniqueID32(const char* hexStr)
|
||||
{
|
||||
char copy[9];
|
||||
|
@ -111,6 +112,7 @@ public:
|
|||
}
|
||||
|
||||
UniqueID64() = default;
|
||||
UniqueID64(Athena::io::IStreamReader& reader) {read(reader);}
|
||||
UniqueID64(const char* hexStr)
|
||||
{
|
||||
char copy[17];
|
||||
|
|
|
@ -1,4 +1,192 @@
|
|||
#ifndef __DNACOMMON_MAPA_HPP__
|
||||
#define __DNACOMMON_MAPA_HPP__
|
||||
|
||||
#include "DNACommon.hpp"
|
||||
#include "GX.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
namespace DNAMAPA
|
||||
{
|
||||
|
||||
template <typename PAKRouter, typename MAPA>
|
||||
bool ReadMAPAToBlender(HECL::BlenderConnection& conn,
|
||||
const MAPA& mapa,
|
||||
const HECL::ProjectPath& outPath,
|
||||
PAKRouter& pakRouter,
|
||||
const typename PAKRouter::EntryType& entry,
|
||||
bool force)
|
||||
{
|
||||
/* Rename MAPA for consistency */
|
||||
HECL::ProjectPath mapaPath(outPath.getParentPath(), _S("!map.blend"));
|
||||
if (!force && mapaPath.getPathType() == HECL::ProjectPath::PT_FILE)
|
||||
return true;
|
||||
|
||||
if (!conn.createBlend(mapaPath, HECL::BlenderConnection::TypeMapArea))
|
||||
return false;
|
||||
HECL::BlenderConnection::PyOutStream os = conn.beginPythonOut(true);
|
||||
|
||||
os << "import bpy, bmesh\n"
|
||||
"from mathutils import Matrix\n"
|
||||
"\n"
|
||||
"bpy.types.Object.retro_mappable_type = bpy.props.IntProperty(name='Retro: MAPA object type', default=-1)\n"
|
||||
"bpy.types.Object.retro_mappable_unk = bpy.props.IntProperty(name='Retro: MAPA object unk')\n"
|
||||
"bpy.types.Object.retro_mappable_sclyid = bpy.props.StringProperty(name='Retro: MAPA object SCLY ID')\n"
|
||||
"\n"
|
||||
"# Clear Scene\n"
|
||||
"for ob in bpy.data.objects:\n"
|
||||
" bpy.context.scene.objects.unlink(ob)\n"
|
||||
" bpy.data.objects.remove(ob)\n"
|
||||
"\n"
|
||||
"def add_triangle(bm, verts):\n"
|
||||
" verts = [bm.verts[vi] for vi in verts]\n"
|
||||
" face = bm.faces.get(verts)\n"
|
||||
" if face:\n"
|
||||
" face = face.copy()\n"
|
||||
" bm.verts.ensure_lookup_table()\n"
|
||||
" face.normal_flip()\n"
|
||||
" else:\n"
|
||||
" bm.faces.new(verts)\n"
|
||||
"\n"
|
||||
"def add_border(bm, verts):\n"
|
||||
" verts = [bm.verts[vi] for vi in verts]\n"
|
||||
" edge = bm.edges.get(verts)\n"
|
||||
" edge.seam = True\n"
|
||||
"\n";
|
||||
|
||||
os.format("bpy.context.scene.name = 'MAPA_%s'\n",
|
||||
entry.id.toString().c_str());
|
||||
|
||||
/* Add empties representing MappableObjects */
|
||||
int moIdx = 0;
|
||||
for (const typename MAPA::MappableObject& mo : mapa.mappableObjects)
|
||||
{
|
||||
os.format("obj = bpy.data.objects.new('MAPOBJ_%02d', None)\n"
|
||||
"bpy.context.scene.objects.link(obj)\n"
|
||||
"obj.retro_mappable_type = %d\n"
|
||||
"obj.retro_mappable_unk = %d\n"
|
||||
"obj.retro_mappable_sclyid = '%08X'\n"
|
||||
"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"
|
||||
"obj.rotation_mode = 'QUATERNION'\n"
|
||||
"obj.location = mtxd[0]\n"
|
||||
"obj.rotation_quaternion = mtxd[1]\n"
|
||||
"obj.scale = mtxd[2]\n",
|
||||
moIdx, mo.type, mo.unknown1, mo.sclyId,
|
||||
mo.transformMtx[0].vec[0], mo.transformMtx[0].vec[1], mo.transformMtx[0].vec[2], mo.transformMtx[0].vec[3],
|
||||
mo.transformMtx[1].vec[0], mo.transformMtx[1].vec[1], mo.transformMtx[1].vec[2], mo.transformMtx[1].vec[3],
|
||||
mo.transformMtx[2].vec[0], mo.transformMtx[2].vec[1], mo.transformMtx[2].vec[2], mo.transformMtx[2].vec[3]);
|
||||
++moIdx;
|
||||
}
|
||||
|
||||
os << "# Begin bmesh\n"
|
||||
"bm = bmesh.new()\n"
|
||||
"\n";
|
||||
|
||||
/* Read in verts */
|
||||
for (const atVec3f& vert : mapa.vertices)
|
||||
os.format("bm.verts.new((%f,%f,%f))\n",
|
||||
vert.vec[0], vert.vec[1], vert.vec[2]);
|
||||
os << "bm.verts.ensure_lookup_table()\n";
|
||||
|
||||
/* Read in surfaces */
|
||||
for (const typename MAPA::Surface& surf : mapa.surfaces)
|
||||
{
|
||||
for (const typename MAPA::Surface::Primitive& prim : surf.primitives)
|
||||
{
|
||||
auto iit = prim.indices.cbegin();
|
||||
|
||||
/* 3 Prim Verts to start */
|
||||
int c = 0;
|
||||
unsigned int primVerts[3] =
|
||||
{
|
||||
*iit++,
|
||||
*iit++,
|
||||
*iit++
|
||||
};
|
||||
|
||||
if (GX::Primitive(prim.type) == GX::TRIANGLESTRIP)
|
||||
{
|
||||
atUint8 flip = 0;
|
||||
for (int v=0 ; v<prim.indexCount-2 ; ++v)
|
||||
{
|
||||
if (flip)
|
||||
{
|
||||
os.format("add_triangle(bm, (%u,%u,%u))\n",
|
||||
primVerts[c%3],
|
||||
primVerts[(c+2)%3],
|
||||
primVerts[(c+1)%3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
os.format("add_triangle(bm, (%u,%u,%u))\n",
|
||||
primVerts[c%3],
|
||||
primVerts[(c+1)%3],
|
||||
primVerts[(c+2)%3]);
|
||||
}
|
||||
flip ^= 1;
|
||||
|
||||
bool peek = (v >= prim.indexCount - 3);
|
||||
|
||||
/* Advance one prim vert */
|
||||
if (peek)
|
||||
primVerts[c%3] = *iit;
|
||||
else
|
||||
primVerts[c%3] = *iit++;
|
||||
++c;
|
||||
}
|
||||
}
|
||||
else if (GX::Primitive(prim.type) == GX::TRIANGLES)
|
||||
{
|
||||
for (int v=0 ; v<prim.indexCount ; v+=3)
|
||||
{
|
||||
os.format("add_triangle(bm, (%u,%u,%u))\n",
|
||||
primVerts[0],
|
||||
primVerts[1],
|
||||
primVerts[2]);
|
||||
|
||||
/* Break if done */
|
||||
if (v+3 >= prim.indexCount)
|
||||
break;
|
||||
|
||||
/* Advance 3 Prim Verts */
|
||||
for (int pv=0 ; pv<3 ; ++pv)
|
||||
primVerts[pv] = *iit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const typename MAPA::Surface::Border& border : surf.borders)
|
||||
{
|
||||
auto iit = border.indices.cbegin();
|
||||
for (int i=0 ; i<border.indexCount-1 ; ++i)
|
||||
{
|
||||
os.format("add_border(bm, (%u,%u))\n",
|
||||
*iit, *(iit+1));
|
||||
++iit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
os << "mesh = bpy.data.meshes.new('MAP')\n"
|
||||
"obj = bpy.data.objects.new(mesh.name, mesh)\n"
|
||||
"bm.to_mesh(mesh)\n"
|
||||
"bpy.context.scene.objects.link(obj)\n"
|
||||
"bm.free()\n";
|
||||
|
||||
/* World background */
|
||||
HECL::ProjectPath worldBlend(outPath.getParentPath().getParentPath(), "!world.blend");
|
||||
if (worldBlend.getPathType() == HECL::ProjectPath::PT_FILE)
|
||||
os.linkBackground("//../!world.blend", "World");
|
||||
|
||||
os.centerView();
|
||||
os.close();
|
||||
conn.saveBlend();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __DNACOMMON_MAPA_HPP__
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
m_pos += pos;
|
||||
else if (origin == Athena::End)
|
||||
m_pos = m_sz + pos;
|
||||
if (m_pos >= m_sz)
|
||||
if (m_pos > m_sz)
|
||||
LogDNACommon.report(LogVisor::FatalError, "PAK stream cursor overrun");
|
||||
}
|
||||
atUint64 position() const {return m_pos;}
|
||||
|
@ -309,6 +309,43 @@ public:
|
|||
progress(++count / bridgesSz);
|
||||
++bridgeIdx;
|
||||
}
|
||||
|
||||
/* TEMP: CSV dump */
|
||||
FILE* fp = HECL::Fopen(_S("/home/jacko/Desktop/mp_res.txt"), _S("w"));
|
||||
for (const auto& entry : m_uniqueEntries)
|
||||
{
|
||||
const EntryType* ent = entry.second.second;
|
||||
fprintf(fp, "%s\t0x%s\t\t", ent->type.toString().c_str(), entry.first.toString().c_str());
|
||||
switch (ent->unique.m_type)
|
||||
{
|
||||
case UniqueResult::UNIQUE_NOTFOUND:
|
||||
case UniqueResult::UNIQUE_PAK:
|
||||
{
|
||||
const HECL::ProjectPath& pakPath = m_bridgePaths[entry.second.first].first;
|
||||
fprintf(fp, _S("%s\n"), pakPath.getLastComponent());
|
||||
break;
|
||||
}
|
||||
case UniqueResult::UNIQUE_LEVEL:
|
||||
fprintf(fp, _S("%s\n"), ent->unique.m_levelName->c_str());
|
||||
break;
|
||||
case UniqueResult::UNIQUE_AREA:
|
||||
fprintf(fp, _S("%s/%s\n"), ent->unique.m_levelName->c_str(), ent->unique.m_areaName->c_str());
|
||||
break;
|
||||
case UniqueResult::UNIQUE_LAYER:
|
||||
fprintf(fp, _S("%s/%s/%s\n"), ent->unique.m_levelName->c_str(), ent->unique.m_areaName->c_str(), ent->unique.m_layerName->c_str());
|
||||
break;
|
||||
default:
|
||||
fprintf(fp, "\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
for (const auto& entry : m_sharedEntries)
|
||||
{
|
||||
const EntryType* ent = entry.second.second;
|
||||
fprintf(fp, "%s\t0x%s\t\t\n", ent->type.toString().c_str(), entry.first.toString().c_str());
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
void enterPAKBridge(const BRIDGETYPE& pakBridge)
|
||||
|
@ -505,23 +542,33 @@ public:
|
|||
float fsz = sz;
|
||||
for (unsigned w=0 ; count<sz ; ++w)
|
||||
{
|
||||
for (const auto& item : m_pak->m_idMap)
|
||||
for (const auto& item : m_pak->m_firstEntries)
|
||||
{
|
||||
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*item.second);
|
||||
ResExtractor<BRIDGETYPE> extractor = BRIDGETYPE::LookupExtractor(*item);
|
||||
if (extractor.weight != w)
|
||||
continue;
|
||||
|
||||
std::string bestName = getBestEntryName(*item.second);
|
||||
std::string bestName = getBestEntryName(*item);
|
||||
HECL::SystemStringView bestNameView(bestName);
|
||||
float thisFac = ++count / fsz;
|
||||
progress(bestNameView.sys_str().c_str(), thisFac);
|
||||
|
||||
HECL::ProjectPath working = getWorking(item.second, extractor);
|
||||
/* TODO: Position after extracted item */
|
||||
HECL::ProjectPath cooked = getCooked(item);
|
||||
if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item->beginReadStream(*m_node);
|
||||
FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb"));
|
||||
fwrite(s.data(), 1, s.length(), fout);
|
||||
fclose(fout);
|
||||
}
|
||||
|
||||
HECL::ProjectPath working = getWorking(item, extractor);
|
||||
if (extractor.func_a) /* Doesn't need PAKRouter access */
|
||||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
PAKEntryReadStream s = item->beginReadStream(*m_node);
|
||||
extractor.func_a(s, working);
|
||||
}
|
||||
}
|
||||
|
@ -529,25 +576,14 @@ public:
|
|||
{
|
||||
if (force || working.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
extractor.func_b(m_dataSpec, s, working, *this, *item.second, force,
|
||||
PAKEntryReadStream s = item->beginReadStream(*m_node);
|
||||
extractor.func_b(m_dataSpec, s, working, *this, *item, force,
|
||||
[&progress, thisFac](const HECL::SystemChar* update)
|
||||
{
|
||||
progress(update, thisFac);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract original cooked copy AFTER working so timestamps make
|
||||
* the original a valid cached item */
|
||||
HECL::ProjectPath cooked = getCooked(item.second);
|
||||
if (force || cooked.getPathType() == HECL::ProjectPath::PT_NONE)
|
||||
{
|
||||
PAKEntryReadStream s = item.second->beginReadStream(*m_node);
|
||||
FILE* fout = HECL::Fopen(cooked.getAbsolutePath().c_str(), _S("wb"));
|
||||
fwrite(s.data(), 1, s.length(), fout);
|
||||
fclose(fout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "CMDL.hpp"
|
||||
#include "ANCS.hpp"
|
||||
#include "MREA.hpp"
|
||||
#include "MAPA.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
@ -77,9 +78,11 @@ void PAKBridge::build()
|
|||
{
|
||||
Level& level = m_levelDeps[entry.id];
|
||||
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
MLVL mlvl;
|
||||
{
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
mlvl.read(rs);
|
||||
}
|
||||
#if HECL_UCS2
|
||||
level.name = HECL::UTF8ToWide(m_pak.bestEntryName(entry));
|
||||
#else
|
||||
|
@ -88,6 +91,19 @@ void PAKBridge::build()
|
|||
level.areas.reserve(mlvl.areaCount);
|
||||
unsigned layerIdx = 0;
|
||||
|
||||
/* Make MAPW available to lookup MAPAs */
|
||||
const PAK::Entry* worldMapEnt = m_pak.lookupEntry(mlvl.worldMap);
|
||||
std::vector<UniqueID32> mapw;
|
||||
if (worldMapEnt)
|
||||
{
|
||||
PAKEntryReadStream rs = worldMapEnt->beginReadStream(m_node);
|
||||
rs.seek(8, Athena::Current);
|
||||
atUint32 areaCount = rs.readUint32Big();
|
||||
mapw.reserve(areaCount);
|
||||
for (atUint32 i=0 ; i<areaCount ; ++i)
|
||||
mapw.emplace_back(rs);
|
||||
}
|
||||
|
||||
/* Index areas */
|
||||
unsigned ai = 0;
|
||||
for (const MLVL::Area& area : mlvl.areas)
|
||||
|
@ -98,16 +114,18 @@ void PAKBridge::build()
|
|||
if (areaNameEnt)
|
||||
{
|
||||
STRG areaName;
|
||||
{
|
||||
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
|
||||
areaName.read(rs);
|
||||
}
|
||||
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
|
||||
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (areaDeps.name.size() && iswblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && iswspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#else
|
||||
while (areaDeps.name.size() && isblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && isspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#endif
|
||||
}
|
||||
|
@ -120,7 +138,7 @@ void PAKBridge::build()
|
|||
#endif
|
||||
}
|
||||
HECL::SystemChar num[16];
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai);
|
||||
areaDeps.name = num + areaDeps.name;
|
||||
|
||||
areaDeps.layers.reserve(area.depLayerCount-1);
|
||||
|
@ -133,10 +151,10 @@ void PAKBridge::build()
|
|||
layer.active = layerFlags.flags >> (l-1) & 0x1;
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (layer.name.size() && iswblank(layer.name.back()))
|
||||
while (layer.name.size() && iswspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#else
|
||||
while (layer.name.size() && isblank(layer.name.back()))
|
||||
while (layer.name.size() && isspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#endif
|
||||
HECL::SNPrintf(num, 16, layer.active ? _S("%02ua ") : _S("%02u "), l-1);
|
||||
|
@ -146,10 +164,13 @@ void PAKBridge::build()
|
|||
for (; r<area.depLayers[l] ; ++r)
|
||||
layer.resources.emplace(area.deps[r].id);
|
||||
}
|
||||
areaDeps.resources.reserve(area.depCount - r);
|
||||
areaDeps.resources.reserve(area.depCount - r + 2);
|
||||
for (; r<area.depCount ; ++r)
|
||||
areaDeps.resources.emplace(area.deps[r].id);
|
||||
areaDeps.resources.emplace(area.areaMREAId);
|
||||
if (mapw.size() > ai)
|
||||
areaDeps.resources.emplace(mapw[ai]);
|
||||
++ai;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -198,6 +219,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK::Entry& entry)
|
|||
return {nullptr, MLVL::Extract, {_S(".blend")}, 3};
|
||||
case SBIG('MREA'):
|
||||
return {nullptr, MREA::Extract, {_S(".blend")}, 4};
|
||||
case SBIG('MAPA'):
|
||||
return {nullptr, MAPA::Extract, {_S(".blend")}, 4};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "../DNACommon/DNACommon.hpp"
|
||||
#include "../DNACommon/PAK.hpp"
|
||||
#include "../DNACommon/MAPA.hpp"
|
||||
#include "DNAMP1.hpp"
|
||||
|
||||
namespace Retro
|
||||
{
|
||||
|
@ -25,14 +27,36 @@ struct MAPA : BigDNA
|
|||
struct MappableObject : BigDNA
|
||||
{
|
||||
DECL_DNA
|
||||
Value<atUint32> type;
|
||||
enum Type : atUint32
|
||||
{
|
||||
MOBlueDoor = 0,
|
||||
MOShieldDoor = 1,
|
||||
MOIceDoor = 2,
|
||||
MOWaveDoor = 3,
|
||||
MOPlasmaDoor = 4,
|
||||
MOBigDoor1 = 5,
|
||||
MOBigDoor2 = 6,
|
||||
MOIceDoorCeiling = 7,
|
||||
MOIceDoorFloor = 8,
|
||||
MOWaveDoorCeiling = 9,
|
||||
MOWaveDoorFloor = 10,
|
||||
MOIceDoorFloor2 = 13,
|
||||
MOWaveDoorFloor2 = 14,
|
||||
MODownArrowYellow = 27, /* Maintenance Tunnel */
|
||||
MOUpArrowYellow = 28, /* Phazon Processing Center */
|
||||
MODownArrowGreen = 29, /* Elevator A */
|
||||
MOUpArrowGreen = 30, /* Elite Control Access */
|
||||
MODownArrowRed = 31, /* Elevator B */
|
||||
MOUpArrowRed = 32, /* Fungal Hall Access */
|
||||
MOTransportLift = 33,
|
||||
MOSaveStation = 34,
|
||||
MOMissileStation = 37
|
||||
};
|
||||
Value<Type> type;
|
||||
Value<atUint32> unknown1;
|
||||
Value<atUint16> unknown2;
|
||||
Value<atUint16> id;
|
||||
Value<atUint32> sclyId;
|
||||
Seek<DNA_COUNT(4), Athena::Current> seek1;
|
||||
Value<atVec4f> transform1;
|
||||
Value<atVec4f> transform2;
|
||||
Value<atVec4f> transform3;
|
||||
Value<atVec4f> transformMtx[3];
|
||||
Seek<DNA_COUNT(0x10), Athena::Current> seek2;
|
||||
};
|
||||
Vector<MappableObject, DNA_COUNT(mappableObjectCount)> mappableObjects;
|
||||
|
@ -42,9 +66,9 @@ struct MAPA : BigDNA
|
|||
{
|
||||
DECL_DNA
|
||||
Value<atVec3f> normal;
|
||||
Value<atVec3f> center;
|
||||
Value<atUint32> start;
|
||||
Value<atUint32> end;
|
||||
Value<atVec3f> centroid;
|
||||
Value<atUint32> polyOff;
|
||||
Value<atUint32> edgeOff;
|
||||
};
|
||||
|
||||
Vector<SurfaceHeader, DNA_COUNT(surfaceCount)> surfaceHeaders;
|
||||
|
@ -58,7 +82,7 @@ struct MAPA : BigDNA
|
|||
DECL_DNA
|
||||
Value<atUint32> type;
|
||||
Value<atUint32> indexCount;
|
||||
Vector<atUint32, DNA_COUNT(indexCount)> indices;
|
||||
Vector<atUint8, DNA_COUNT(indexCount)> indices;
|
||||
Align<4> align;
|
||||
};
|
||||
Vector<Primitive, DNA_COUNT(primitiveCount)> primitives;
|
||||
|
@ -67,13 +91,27 @@ struct MAPA : BigDNA
|
|||
{
|
||||
DECL_DNA
|
||||
Value<atUint32> indexCount;
|
||||
Vector<atUint32, DNA_COUNT(indexCount)> indices;
|
||||
Vector<atUint8, DNA_COUNT(indexCount)> indices;
|
||||
Align<4> align;
|
||||
};
|
||||
Vector<Border, DNA_COUNT(borderCount)> borders;
|
||||
};
|
||||
|
||||
Vector<Surface, DNA_COUNT(surfaceCount)> surfaces;
|
||||
|
||||
static bool Extract(const SpecBase& dataSpec,
|
||||
PAKEntryReadStream& rs,
|
||||
const HECL::ProjectPath& outPath,
|
||||
PAKRouter<PAKBridge>& pakRouter,
|
||||
const PAK::Entry& entry,
|
||||
bool force,
|
||||
std::function<void(const HECL::SystemChar*)> fileChanged)
|
||||
{
|
||||
MAPA mapa;
|
||||
mapa.read(rs);
|
||||
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
|
||||
return DNAMAPA::ReadMAPAToBlender(conn, mapa, outPath, pakRouter, entry, force);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,9 @@ struct MLVL : BigYAML
|
|||
{
|
||||
MLVL mlvl;
|
||||
mlvl.read(rs);
|
||||
FILE* fp = HECL::Fopen(outPath.getWithExtension(_S(".yaml"), true).getAbsolutePath().c_str(), _S("w"));
|
||||
mlvl.toYAMLFile(fp);
|
||||
fclose(fp);
|
||||
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
|
||||
return DNAMLVL::ReadMLVLToBlender(conn, mlvl, outPath, pakRouter,
|
||||
entry, force, fileChanged);
|
||||
|
|
|
@ -46,13 +46,18 @@ bool MREA::Extract(const SpecBase& dataSpec,
|
|||
using RigPair = std::pair<CSKR*, CINF*>;
|
||||
RigPair dummy(nullptr, nullptr);
|
||||
|
||||
/* Rename MREA for consistency */
|
||||
HECL::ProjectPath mreaPath(outPath.getParentPath(), _S("!area.blend"));
|
||||
if (!force && mreaPath.getPathType() == HECL::ProjectPath::PT_FILE)
|
||||
return true;
|
||||
|
||||
/* Do extract */
|
||||
Header head;
|
||||
head.read(rs);
|
||||
rs.seekAlign32();
|
||||
|
||||
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
|
||||
if (!conn.createBlend(outPath, HECL::BlenderConnection::TypeArea))
|
||||
if (!conn.createBlend(mreaPath, HECL::BlenderConnection::TypeArea))
|
||||
return false;
|
||||
|
||||
/* Open Py Stream and read sections */
|
||||
|
|
|
@ -27,6 +27,8 @@ void PAK::read(Athena::io::IStreamReader& reader)
|
|||
atUint32 count = reader.readUint32Big();
|
||||
m_entries.clear();
|
||||
m_entries.reserve(count);
|
||||
m_firstEntries.clear();
|
||||
m_firstEntries.reserve(count);
|
||||
m_idMap.clear();
|
||||
m_idMap.reserve(count);
|
||||
for (atUint32 e=0 ; e<count ; ++e)
|
||||
|
@ -38,7 +40,14 @@ void PAK::read(Athena::io::IStreamReader& reader)
|
|||
ent.compressed = 2;
|
||||
}
|
||||
for (Entry& entry : m_entries)
|
||||
{
|
||||
auto search = m_idMap.find(entry.id);
|
||||
if (search == m_idMap.end())
|
||||
{
|
||||
m_firstEntries.push_back(&entry);
|
||||
m_idMap[entry.id] = &entry;
|
||||
}
|
||||
}
|
||||
|
||||
m_nameMap.clear();
|
||||
m_nameMap.reserve(nameCount);
|
||||
|
|
|
@ -48,6 +48,7 @@ struct PAK : BigDNA
|
|||
|
||||
std::vector<NameEntry> m_nameEntries;
|
||||
std::vector<Entry> m_entries;
|
||||
std::vector<Entry*> m_firstEntries;
|
||||
std::unordered_map<UniqueID32, Entry*> m_idMap;
|
||||
std::unordered_map<std::string, Entry*> m_nameMap;
|
||||
|
||||
|
|
|
@ -74,9 +74,11 @@ void PAKBridge::build()
|
|||
{
|
||||
Level& level = m_levelDeps[entry.id];
|
||||
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
MLVL mlvl;
|
||||
{
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
mlvl.read(rs);
|
||||
}
|
||||
#if HECL_UCS2
|
||||
level.name = HECL::UTF8ToWide(m_pak.bestEntryName(entry));
|
||||
#else
|
||||
|
@ -85,6 +87,19 @@ void PAKBridge::build()
|
|||
level.areas.reserve(mlvl.areaCount);
|
||||
unsigned layerIdx = 0;
|
||||
|
||||
/* Make MAPW available to lookup MAPAs */
|
||||
const DNAMP1::PAK::Entry* worldMapEnt = m_pak.lookupEntry(mlvl.worldMap);
|
||||
std::vector<UniqueID32> mapw;
|
||||
if (worldMapEnt)
|
||||
{
|
||||
PAKEntryReadStream rs = worldMapEnt->beginReadStream(m_node);
|
||||
rs.seek(8, Athena::Current);
|
||||
atUint32 areaCount = rs.readUint32Big();
|
||||
mapw.reserve(areaCount);
|
||||
for (atUint32 i=0 ; i<areaCount ; ++i)
|
||||
mapw.emplace_back(rs);
|
||||
}
|
||||
|
||||
/* Index areas */
|
||||
unsigned ai = 0;
|
||||
for (const MLVL::Area& area : mlvl.areas)
|
||||
|
@ -95,16 +110,18 @@ void PAKBridge::build()
|
|||
if (areaNameEnt)
|
||||
{
|
||||
STRG areaName;
|
||||
{
|
||||
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
|
||||
areaName.read(rs);
|
||||
}
|
||||
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
|
||||
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (areaDeps.name.size() && iswblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && iswspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#else
|
||||
while (areaDeps.name.size() && isblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && isspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#endif
|
||||
}
|
||||
|
@ -125,7 +142,7 @@ void PAKBridge::build()
|
|||
}
|
||||
}
|
||||
HECL::SystemChar num[16];
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai);
|
||||
areaDeps.name = num + areaDeps.name;
|
||||
|
||||
areaDeps.layers.reserve(area.depLayerCount-1);
|
||||
|
@ -138,10 +155,10 @@ void PAKBridge::build()
|
|||
layer.active = layerFlags.flags >> (l-1) & 0x1;
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (layer.name.size() && iswblank(layer.name.back()))
|
||||
while (layer.name.size() && iswspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#else
|
||||
while (layer.name.size() && isblank(layer.name.back()))
|
||||
while (layer.name.size() && isspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#endif
|
||||
HECL::SNPrintf(num, 16, layer.active ? _S("%02ua ") : _S("%02u "), l-1);
|
||||
|
@ -151,10 +168,13 @@ void PAKBridge::build()
|
|||
for (; r<area.depLayers[l] ; ++r)
|
||||
layer.resources.emplace(area.deps[r].id);
|
||||
}
|
||||
areaDeps.resources.reserve(area.depCount - r);
|
||||
areaDeps.resources.reserve(area.depCount - r + 2);
|
||||
for (; r<area.depCount ; ++r)
|
||||
areaDeps.resources.emplace(area.deps[r].id);
|
||||
areaDeps.resources.emplace(area.areaMREAId);
|
||||
if (mapw.size() > ai)
|
||||
areaDeps.resources.emplace(mapw[ai]);
|
||||
++ai;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,12 +161,17 @@ bool MREA::Extract(const SpecBase& dataSpec,
|
|||
const HECL::ProjectPath& outPath,
|
||||
PAKRouter<PAKBridge>& pakRouter,
|
||||
const DNAMP1::PAK::Entry& entry,
|
||||
bool,
|
||||
bool force,
|
||||
std::function<void(const HECL::SystemChar*)>)
|
||||
{
|
||||
using RigPair = std::pair<CSKR*, CINF*>;
|
||||
RigPair dummy(nullptr, nullptr);
|
||||
|
||||
/* Rename MREA for consistency */
|
||||
HECL::ProjectPath mreaPath(outPath.getParentPath(), _S("!area.blend"));
|
||||
if (!force && mreaPath.getPathType() == HECL::ProjectPath::PT_FILE)
|
||||
return true;
|
||||
|
||||
/* Do extract */
|
||||
Header head;
|
||||
head.read(rs);
|
||||
|
@ -186,7 +191,7 @@ bool MREA::Extract(const SpecBase& dataSpec,
|
|||
|
||||
/* Start up blender connection */
|
||||
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
|
||||
if (!conn.createBlend(outPath, HECL::BlenderConnection::TypeArea))
|
||||
if (!conn.createBlend(mreaPath, HECL::BlenderConnection::TypeArea))
|
||||
return false;
|
||||
|
||||
/* Open Py Stream and read sections */
|
||||
|
|
|
@ -83,9 +83,11 @@ void PAKBridge::build()
|
|||
{
|
||||
Level& level = m_levelDeps[entry.id];
|
||||
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
MLVL mlvl;
|
||||
{
|
||||
PAKEntryReadStream rs = entry.beginReadStream(m_node);
|
||||
mlvl.read(rs);
|
||||
}
|
||||
#if HECL_UCS2
|
||||
level.name = HECL::UTF8ToWide(m_pak.bestEntryName(entry));
|
||||
#else
|
||||
|
@ -94,6 +96,19 @@ void PAKBridge::build()
|
|||
level.areas.reserve(mlvl.areaCount);
|
||||
unsigned layerIdx = 0;
|
||||
|
||||
/* Make MAPW available to lookup MAPAs */
|
||||
const PAK::Entry* worldMapEnt = m_pak.lookupEntry(mlvl.worldMap);
|
||||
std::vector<UniqueID64> mapw;
|
||||
if (worldMapEnt)
|
||||
{
|
||||
PAKEntryReadStream rs = worldMapEnt->beginReadStream(m_node);
|
||||
rs.seek(8, Athena::Current);
|
||||
atUint32 areaCount = rs.readUint32Big();
|
||||
mapw.reserve(areaCount);
|
||||
for (atUint32 i=0 ; i<areaCount ; ++i)
|
||||
mapw.emplace_back(rs);
|
||||
}
|
||||
|
||||
/* Index areas */
|
||||
unsigned ai = 0;
|
||||
auto layerFlagsIt = mlvl.layerFlags.begin();
|
||||
|
@ -104,16 +119,18 @@ void PAKBridge::build()
|
|||
if (areaNameEnt)
|
||||
{
|
||||
STRG areaName;
|
||||
{
|
||||
PAKEntryReadStream rs = areaNameEnt->beginReadStream(m_node);
|
||||
areaName.read(rs);
|
||||
}
|
||||
areaDeps.name = areaName.getSystemString(FOURCC('ENGL'), 0);
|
||||
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (areaDeps.name.size() && iswblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && iswspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#else
|
||||
while (areaDeps.name.size() && isblank(areaDeps.name.back()))
|
||||
while (areaDeps.name.size() && isspace(areaDeps.name.back()))
|
||||
areaDeps.name.pop_back();
|
||||
#endif
|
||||
}
|
||||
|
@ -134,7 +151,7 @@ void PAKBridge::build()
|
|||
}
|
||||
}
|
||||
HECL::SystemChar num[16];
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai++);
|
||||
HECL::SNPrintf(num, 16, _S("%02u "), ai);
|
||||
areaDeps.name = num + areaDeps.name;
|
||||
|
||||
const MLVL::LayerFlags& areaLayers = *layerFlagsIt++;
|
||||
|
@ -149,10 +166,10 @@ void PAKBridge::build()
|
|||
layer.active = areaLayers.flags >> l & 0x1;
|
||||
/* Trim possible trailing whitespace */
|
||||
#if HECL_UCS2
|
||||
while (layer.name.size() && iswblank(layer.name.back()))
|
||||
while (layer.name.size() && iswspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#else
|
||||
while (layer.name.size() && isblank(layer.name.back()))
|
||||
while (layer.name.size() && isspace(layer.name.back()))
|
||||
layer.name.pop_back();
|
||||
#endif
|
||||
HECL::SNPrintf(num, 16, layer.active ? _S("%02ua ") : _S("%02u "), l-1);
|
||||
|
@ -166,8 +183,11 @@ void PAKBridge::build()
|
|||
{
|
||||
PAKEntryReadStream ars = areaEntry->beginReadStream(m_node);
|
||||
MREA::ExtractLayerDeps(ars, areaDeps);
|
||||
areaDeps.resources.emplace(area.areaMREAId);
|
||||
}
|
||||
areaDeps.resources.emplace(area.areaMREAId);
|
||||
if (mapw.size() > ai)
|
||||
areaDeps.resources.emplace(mapw[ai]);
|
||||
++ai;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,12 +71,17 @@ bool MREA::Extract(const SpecBase& dataSpec,
|
|||
const HECL::ProjectPath& outPath,
|
||||
PAKRouter<PAKBridge>& pakRouter,
|
||||
const PAK::Entry& entry,
|
||||
bool,
|
||||
bool force,
|
||||
std::function<void(const HECL::SystemChar*)>)
|
||||
{
|
||||
using RigPair = std::pair<CSKR*, CINF*>;
|
||||
RigPair dummy(nullptr, nullptr);
|
||||
|
||||
/* Rename MREA for consistency */
|
||||
HECL::ProjectPath mreaPath(outPath.getParentPath(), _S("!area.blend"));
|
||||
if (!force && mreaPath.getPathType() == HECL::ProjectPath::PT_FILE)
|
||||
return true;
|
||||
|
||||
/* Do extract */
|
||||
Header head;
|
||||
head.read(rs);
|
||||
|
@ -99,7 +104,7 @@ bool MREA::Extract(const SpecBase& dataSpec,
|
|||
|
||||
/* Start up blender connection */
|
||||
HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection();
|
||||
if (!conn.createBlend(outPath, HECL::BlenderConnection::TypeArea))
|
||||
if (!conn.createBlend(mreaPath, HECL::BlenderConnection::TypeArea))
|
||||
return false;
|
||||
|
||||
/* Open Py Stream and read sections */
|
||||
|
@ -267,7 +272,7 @@ bool MREA::ExtractLayerDeps(PAKEntryReadStream& rs, PAKBridge::Level::Area& area
|
|||
for (; r<deps.depLayers[l] ; ++r)
|
||||
layer.resources.emplace(deps.deps[r].id);
|
||||
}
|
||||
areaOut.resources.reserve(deps.depCount - r);
|
||||
areaOut.resources.reserve(deps.depCount - r + 2);
|
||||
for (; r<deps.depCount ; ++r)
|
||||
areaOut.resources.emplace(deps.deps[r].id);
|
||||
|
||||
|
|
|
@ -35,6 +35,8 @@ void PAK::read(Athena::io::IStreamReader& reader)
|
|||
atUint32 count = reader.readUint32Big();
|
||||
m_entries.clear();
|
||||
m_entries.reserve(count);
|
||||
m_firstEntries.clear();
|
||||
m_firstEntries.reserve(count);
|
||||
m_idMap.clear();
|
||||
m_idMap.reserve(count);
|
||||
for (atUint32 e=0 ; e<count ; ++e)
|
||||
|
@ -44,7 +46,14 @@ void PAK::read(Athena::io::IStreamReader& reader)
|
|||
m_entries.back().offset += dataOffset;
|
||||
}
|
||||
for (Entry& entry : m_entries)
|
||||
{
|
||||
auto search = m_idMap.find(entry.id);
|
||||
if (search == m_idMap.end())
|
||||
{
|
||||
m_firstEntries.push_back(&entry);
|
||||
m_idMap[entry.id] = &entry;
|
||||
}
|
||||
}
|
||||
|
||||
m_nameMap.clear();
|
||||
m_nameMap.reserve(nameCount);
|
||||
|
|
|
@ -57,6 +57,7 @@ struct PAK : BigDNA
|
|||
|
||||
std::vector<NameEntry> m_nameEntries;
|
||||
std::vector<Entry> m_entries;
|
||||
std::vector<Entry*> m_firstEntries;
|
||||
std::unordered_map<UniqueID64, Entry*> m_idMap;
|
||||
std::unordered_map<std::string, Entry*> m_nameMap;
|
||||
|
||||
|
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit f2870c135dc8f7d3b5c582b94474fcc4c5268049
|
||||
Subproject commit 046c0194f8b9d22449d4b853397e86783fa14770
|
Loading…
Reference in New Issue