MAPA/MAPU bug fixes

This commit is contained in:
Jack Andersen 2017-03-20 11:15:00 -10:00
parent c8e22a6873
commit 5a6e40c5aa
4 changed files with 74 additions and 51 deletions

View File

@ -13,6 +13,8 @@ namespace DataSpec
namespace DNAMAPA
{
static logvisor::Module Log("DNAMAPA");
void MAPA::read(athena::io::IStreamReader& __dna_reader)
{
/* magic */
@ -147,14 +149,14 @@ bool ReadMAPAToBlender(hecl::BlenderConnection& conn,
int moIdx = 0;
for (const std::unique_ptr<MAPA::IMappableObject>& mo : mapa.mappableObjects)
{
const MAPA::MappableObjectMP1_2* moMP12 = dynamic_cast<const MAPA::MappableObjectMP1_2*>(mo.get());
if (moMP12)
if (mapa.version < 5)
{
const MAPA::MappableObjectMP1_2* moMP12 = static_cast<const MAPA::MappableObjectMP1_2*>(mo.get());
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"
"obj.retro_mappable_sclyid = '0x%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"
@ -168,14 +170,14 @@ bool ReadMAPAToBlender(hecl::BlenderConnection& conn,
++moIdx;
continue;
}
const MAPA::MappableObjectMP3* moMP3 = dynamic_cast<const MAPA::MappableObjectMP3*>(mo.get());
if (moMP3)
else
{
const MAPA::MappableObjectMP3* moMP3 = static_cast<const MAPA::MappableObjectMP3*>(mo.get());
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"
"obj.retro_mappable_sclyid = '0x%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"
@ -342,6 +344,13 @@ template bool ReadMAPAToBlender<PAKRouter<DNAMP3::PAKBridge>>
template <typename MAPAType>
bool Cook(const hecl::BlenderConnection::DataStream::MapArea& mapaIn, const hecl::ProjectPath& out)
{
if (mapaIn.verts.size() >= 256)
{
Log.report(logvisor::Error, _S("MAPA %s vertex range exceeded [%d/%d]"),
out.getRelativePath().c_str(), mapaIn.verts.size(), 255);
return false;
}
MAPAType mapa;
mapa.magic = 0xDEADD00D;
mapa.version = MAPAType::Version();
@ -351,7 +360,6 @@ bool Cook(const hecl::BlenderConnection::DataStream::MapArea& mapaIn, const hecl
aabb.accumulateBounds(vert.val);
mapa.header = std::make_unique<typename MAPAType::Header>();
memset((void*)mapa.header.get(), 0, sizeof(typename MAPAType::Header));
typename MAPAType::Header& header = static_cast<typename MAPAType::Header&>(*mapa.header);
header.unknown1 = 0;
header.unknown2 = 1;
@ -383,7 +391,7 @@ bool Cook(const hecl::BlenderConnection::DataStream::MapArea& mapaIn, const hecl
for (const auto& mo : mapa.mappableObjects)
offsetCur = mo->binarySize(offsetCur);
offsetCur += mapa.vertices.size() * 12;
offsetCur += mapaIn.surfaces.size() * sizeof(DNAMAPA::MAPA::SurfaceHeader);
offsetCur += mapaIn.surfaces.size() * 32;
mapa.surfaceHeaders.reserve(mapaIn.surfaces.size());
mapa.surfaces.reserve(mapaIn.surfaces.size());
@ -405,26 +413,36 @@ bool Cook(const hecl::BlenderConnection::DataStream::MapArea& mapaIn, const hecl
for (auto it = itBegin ; it != itEnd ; ++it)
prim.indices.push_back(it->val);
surf.borderCount = 1;
surf.borders.emplace_back();
DNAMAPA::MAPA::Surface::Border& border = surf.borders.back();
border.indexCount = surfIn.borderCount;
border.indices.reserve(surfIn.borderCount);
auto it2Begin = mapaIn.indices.begin() + surfIn.borderStart.val;
auto it2End = itBegin + surfIn.borderCount;
for (auto it = it2Begin ; it != it2End ; ++it)
border.indices.push_back(it->val);
surf.borderCount = surfIn.borders.size();
surf.borders.reserve(surfIn.borders.size());
for (const auto& borderIn : surfIn.borders)
{
surf.borders.emplace_back();
DNAMAPA::MAPA::Surface::Border& border = surf.borders.back();
border.indexCount = borderIn.second.val;
border.indices.reserve(borderIn.second.val);
auto it2Begin = mapaIn.indices.begin() + borderIn.first.val;
auto it2End = it2Begin + borderIn.second.val;
for (auto it = it2Begin ; it != it2End ; ++it)
border.indices.push_back(it->val);
}
surfHead.normal = surfIn.normal.val;
surfHead.centroid = surfIn.centerOfMass;
surfHead.polyOff = offsetCur;
offsetCur = prim.binarySize(offsetCur + 4);
surfHead.edgeOff = offsetCur;
offsetCur = border.binarySize(offsetCur + 4);
offsetCur += 4;
for (const auto& border : surf.borders)
offsetCur = border.binarySize(offsetCur);
}
athena::io::FileWriter f(out.getAbsolutePath());
mapa.write(f);
int64_t rem = f.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
f.writeBytes((atInt8*)"\xff", 1);
return true;
}

View File

@ -25,12 +25,12 @@ struct MAPA : BigDNA
struct HeaderMP1 : IMAPAHeader
{
DECL_DNA
Value<atUint32> unknown1;
Value<atUint32> unknown2;
Value<atVec3f> boundingBox[2];
Value<atUint32> moCount;
Value<atUint32> vtxCount;
Value<atUint32> surfCount;
Value<atUint32> unknown1 = 0;
Value<atUint32> unknown2 = 0;
Value<atVec3f> boundingBox[2] = {};
Value<atUint32> moCount = 0;
Value<atUint32> vtxCount = 0;
Value<atUint32> surfCount = 0;
virtual atUint32 mappableObjectCount() const { return moCount;}
virtual atUint32 vertexCount() const { return vtxCount; }
virtual atUint32 surfaceCount() const { return surfCount; }
@ -39,15 +39,15 @@ struct MAPA : BigDNA
struct HeaderMP2 : IMAPAHeader
{
DECL_DNA
Value<atUint32> unknown1;
Value<atUint32> unknown2;
Value<atVec3f> boundingBox[2];
Value<atUint32> unknown3;
Value<atUint32> unknown4;
Value<atUint32> unknown5;
Value<atUint32> moCount;
Value<atUint32> vtxCount;
Value<atUint32> surfCount;
Value<atUint32> unknown1 = 0;
Value<atUint32> unknown2 = 0;
Value<atVec3f> boundingBox[2] = {};
Value<atUint32> unknown3 = 0;
Value<atUint32> unknown4 = 0;
Value<atUint32> unknown5 = 0;
Value<atUint32> moCount = 0;
Value<atUint32> vtxCount = 0;
Value<atUint32> surfCount = 0;
atUint32 mappableObjectCount() const { return moCount;}
atUint32 vertexCount() const { return vtxCount; }
atUint32 surfaceCount() const { return surfCount; }
@ -56,18 +56,18 @@ struct MAPA : BigDNA
struct HeaderMP3 : IMAPAHeader
{
DECL_DNA
Value<atUint32> unknown1;
Value<atUint32> unknown2;
Value<atVec3f> boundingBox[2];
Value<atUint32> unknown3;
Value<atUint32> unknown4;
Value<atUint32> unknown5;
Value<atUint32> unknown6;
Value<atUint32> moCount;
Value<atUint32> vtxCount;
Value<atUint32> surfCount;
Value<atUint32> internalNameLength;
Value<atUint32> unknown7;
Value<atUint32> unknown1 = 0;
Value<atUint32> unknown2 = 0;
Value<atVec3f> boundingBox[2] = {};
Value<atUint32> unknown3 = 0;
Value<atUint32> unknown4 = 0;
Value<atUint32> unknown5 = 0;
Value<atUint32> unknown6 = 0;
Value<atUint32> moCount = 0;
Value<atUint32> vtxCount = 0;
Value<atUint32> surfCount = 0;
Value<atUint32> internalNameLength = 0;
Value<atUint32> unknown7 = 0;
String<DNA_COUNT(internalNameLength)> internalName;
atUint32 mappableObjectCount() const { return moCount;}
atUint32 vertexCount() const { return vtxCount; }
@ -118,9 +118,9 @@ struct MAPA : BigDNA
Value<Type> type;
Value<atUint32> unknown1;
Value<atUint32> sclyId;
Seek<DNA_COUNT(4), athena::Current> seek1;
Value<atInt32> seek1 = -1;
Value<atVec4f> transformMtx[3];
Seek<DNA_COUNT(0x10), athena::Current> seek2;
Value<atInt32> seek2[4] = {-1, -1, -1, -1};
virtual ~MappableObjectMP1_2() {}
};
@ -131,9 +131,9 @@ struct MAPA : BigDNA
Value<atUint32> unknown1;
Value<atUint32> sclyId;
Buffer<DNA_COUNT(0x10)> unknownHash;
Seek<DNA_COUNT(4), athena::Current> seek1;
Value<atInt32> seek1 = -1;
Value<atVec4f> transformMtx[3];
Seek<DNA_COUNT(0x10), athena::Current> seek2;
Value<atInt32> seek2[4] = {-1, -1, -1, -1};
virtual ~MappableObjectMP3() {}
};

View File

@ -91,7 +91,8 @@ bool ReadMAPUToBlender(hecl::BlenderConnection& conn,
os.centerView();
os.close();
return conn.saveBlend();
conn.saveBlend();
return true;
}
template bool ReadMAPUToBlender<PAKRouter<DNAMP1::PAKBridge>>
@ -144,6 +145,10 @@ bool MAPU::Cook(const hecl::BlenderConnection::DataStream::MapUniverse& mapuIn,
athena::io::FileWriter f(out.getAbsolutePath());
mapu.write(f);
int64_t rem = f.position() % 32;
if (rem)
for (int64_t i=0 ; i<32-rem ; ++i)
f.writeBytes((atInt8*)"\xff", 1);
return true;
}

2
hecl

@ -1 +1 @@
Subproject commit 5d11c53fea3e554c8c93a8c055edcc22dedaa084
Subproject commit 63980109fd91e72b4ec668918879af2779255c27