MREA generation fixes

This commit is contained in:
Jack Andersen 2016-08-13 09:37:03 -10:00
parent c89005f9c3
commit abcb9c2424
5 changed files with 32 additions and 13 deletions

View File

@ -2,8 +2,9 @@
namespace DataSpec namespace DataSpec
{ {
logvisor::Module Log("AROTBuilder");
#define AROT_MAX_LEVEL 11 /* These go to 11 */ #define AROT_MAX_LEVEL 7
static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 }; static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
@ -51,6 +52,9 @@ bool AROTBuilder::Node::addChild(int level, const zeus::CAABox& curAabb, const z
} }
if (inX[0] ^ inX[1]) if (inX[0] ^ inX[1])
flags |= 0x1; flags |= 0x1;
if (!flags)
childNodes.clear();
} }
return true; return true;
} }
@ -63,6 +67,9 @@ void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPo
{ {
sz += 1; sz += 1;
poolIdx = bmpPool.addIndices(childIndices); poolIdx = bmpPool.addIndices(childIndices);
if (poolIdx > 65535)
Log.report(logvisor::Fatal, "AROT bitmap exceeds 16-bit node addressing; area too complex");
if (childNodes.size()) if (childNodes.size())
{ {
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
@ -77,7 +84,7 @@ void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPo
} }
uint32_t childCount = AROTChildCounts[flags]; uint32_t childCount = AROTChildCounts[flags];
nodeOff = curOff; nodeOff = curOff;
nodeSz += childCount * 2; nodeSz = childCount * 2 + 4;
curOff += nodeSz; curOff += nodeSz;
idxRefs += childCount; idxRefs += childCount;
} }
@ -114,6 +121,9 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx)
if (childNodes.size()) if (childNodes.size())
{ {
int curIdx = nodeIdx + 1; int curIdx = nodeIdx + 1;
if (curIdx > 65535)
Log.report(logvisor::Fatal, "AROT node exceeds 16-bit node addressing; area too complex");
int childIndices[8]; int childIndices[8];
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
@ -177,6 +187,7 @@ void AROTBuilder::Node::colSize(size_t& totalSz)
} }
else else
{ {
totalSz += 36;
for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i) for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
{ {
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
@ -197,8 +208,15 @@ void AROTBuilder::Node::writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB
{ {
if (childNodes.empty()) if (childNodes.empty())
{ {
*reinterpret_cast<zeus::CVector3f*>(ptr) = curAABB.min; zeus::CAABox swapAABB = curAABB;
*reinterpret_cast<zeus::CVector3f*>(ptr + 12) = curAABB.max; swapAABB.min[0] = hecl::SBig(swapAABB.min[0]);
swapAABB.min[1] = hecl::SBig(swapAABB.min[1]);
swapAABB.min[2] = hecl::SBig(swapAABB.min[2]);
swapAABB.max[0] = hecl::SBig(swapAABB.max[0]);
swapAABB.max[1] = hecl::SBig(swapAABB.max[1]);
swapAABB.max[2] = hecl::SBig(swapAABB.max[2]);
*reinterpret_cast<zeus::CVector3f*>(ptr) = swapAABB.min;
*reinterpret_cast<zeus::CVector3f*>(ptr + 12) = swapAABB.max;
athena::io::MemoryWriter w(ptr + 24, INT32_MAX); athena::io::MemoryWriter w(ptr + 24, INT32_MAX);
w.writeUint16Big(childIndices.size()); w.writeUint16Big(childIndices.size());
for (int idx : childIndices) for (int idx : childIndices)
@ -222,11 +240,12 @@ void AROTBuilder::Node::writeColNodes(uint8_t*& ptr, const zeus::CAABox& curAABB
if (thisFlags) if (thisFlags)
{ {
*pflags |= thisFlags << (idx * 2); *pflags |= thisFlags << (idx * 2);
offsets[idx] = thisOffset - nodeOff; offsets[idx] = hecl::SBig(uint32_t(thisOffset - nodeOff - 36));
} }
} }
} }
} }
*pflags = hecl::SBig(*pflags);
ptr += 36; ptr += 36;
zeus::CAABox X[2]; zeus::CAABox X[2];

View File

@ -126,10 +126,10 @@ void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataS
db.triMatsCount = colMesh.trianges.size(); db.triMatsCount = colMesh.trianges.size();
db.triangleEdgesCount = colMesh.trianges.size() * 3; db.triangleEdgesCount = colMesh.trianges.size() * 3;
db.unk1 = 0; db.unk1 = 0x1000000;
db.length = db.binarySize(0) - 8; db.length = db.binarySize(0) - 8;
db.magic = 0xDEAFBABE; db.magic = 0xDEAFBABE;
db.version = 0; db.version = 3;
db.aabb[0] = colMesh.aabbMin; db.aabb[0] = colMesh.aabbMin;
db.aabb[1] = colMesh.aabbMax; db.aabb[1] = colMesh.aabbMax;
} }

View File

@ -336,7 +336,7 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
/* SCLY */ /* SCLY */
{ {
DNAMP1::SCLY sclyData; DNAMP1::SCLY sclyData = {};
sclyData.fourCC = 'SCLY'; sclyData.fourCC = 'SCLY';
sclyData.version = 1; sclyData.version = 1;
for (const hecl::ProjectPath& layer : layerScriptPaths) for (const hecl::ProjectPath& layer : layerScriptPaths)
@ -372,8 +372,8 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
/* Collision */ /* Collision */
{ {
DeafBabe collision; DeafBabe collision = {};
DeafBabeBuildFromBlender(collision, cMesh); DeafBabeBuildFromBlender(collision, cMesh);
secs.emplace_back(collision.binarySize(0), 0); secs.emplace_back(collision.binarySize(0), 0);
@ -414,7 +414,7 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
{ {
if (l.layer == lay) if (l.layer == lay)
{ {
BabeDeadLight light; BabeDeadLight light = {};
WriteBabeDeadLightFromBlender(light, l); WriteBabeDeadLightFromBlender(light, l);
light.write(w); light.write(w);
} }

2
hecl

@ -1 +1 @@
Subproject commit 7535cb1a2ff157cc759473ad272daa861e340e32 Subproject commit d50aeab9f16b3b6c06125316022fa7398024c68d

@ -1 +1 @@
Subproject commit eea8bd42fc4c6854636ea6d1d08ae3ba76596f40 Subproject commit 4efe7e48480f99f74da4fc8f546a09c7cb529485