2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-10 22:27:42 +00:00

Merge branch 'master' of ssh://git.axiodl.com:6431/AxioDL/urde into mp2-fixes

This commit is contained in:
Jack Andersen
2020-04-09 13:04:37 -10:00
547 changed files with 14594 additions and 11618 deletions

View File

@@ -1,15 +1,19 @@
#include "AROTBuilder.hpp"
#include <algorithm>
#include <array>
#include "hecl/Blender/Connection.hpp"
#include "PATH.hpp"
namespace DataSpec {
logvisor::Module Log("AROTBuilder");
#define AROT_MAX_LEVEL 10
#define AROT_MIN_SUBDIV 10.f
#define AROT_MIN_MODELS 8
#define COLLISION_MIN_NODE_TRIANGLES 8
#define PATH_MIN_NODE_REGIONS 16
constexpr s32 AROT_MAX_LEVEL = 10;
constexpr s32 AROT_MIN_MODELS = 8;
constexpr s32 COLLISION_MIN_NODE_TRIANGLES = 8;
constexpr s32 PATH_MIN_NODE_REGIONS = 16;
constexpr float AROT_MIN_SUBDIV = 10.f;
static zeus::CAABox SplitAABB(const zeus::CAABox& aabb, int i) {
zeus::CAABox pos, neg;
@@ -128,7 +132,9 @@ size_t AROTBuilder::BitmapPool::addIndices(const std::set<int>& indices) {
return m_pool.size() - 1;
}
static const uint32_t AROTChildCounts[] = {0, 2, 2, 4, 2, 4, 4, 8};
constexpr std::array<uint32_t, 8> AROTChildCounts{
0, 2, 2, 4, 2, 4, 4, 8,
};
void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPool, size_t& curOff) {
sz += 1;
@@ -176,7 +182,7 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx) {
if (curIdx > 65535)
Log.report(logvisor::Fatal, fmt("AROT node exceeds 16-bit node addressing; area too complex"));
int childIndices[8];
std::array<int, 8> childIndices;
for (int k = 0; k < 1 + ((compSubdivs & 0x4) != 0); ++k) {
for (int j = 0; j < 1 + ((compSubdivs & 0x2) != 0); ++j) {
@@ -280,17 +286,16 @@ void AROTBuilder::Node::pathWrite(DNAPATH::PATH<PAKBridge>& path, const zeus::CA
n.aabb[0] = curAABB.min;
n.aabb[1] = curAABB.max;
n.centroid = curAABB.center();
for (int i = 0; i < 8; ++i)
n.children[i] = 0xffffffff;
std::fill(std::begin(n.children), std::end(n.children), 0xFFFFFFFF);
n.regionCount = childIndices.size();
n.regionStart = path.octreeRegionLookup.size();
for (int r : childIndices)
path.octreeRegionLookup.push_back(r);
} else {
atUint32 children[8];
for (int i = 0; i < 8; ++i) {
std::array<atUint32, 8> children;
for (size_t i = 0; i < children.size(); ++i) {
/* Head recursion (first node will be a leaf) */
childNodes[i].pathWrite(path, SplitAABB(curAABB, i));
childNodes[i].pathWrite(path, SplitAABB(curAABB, static_cast<int>(i)));
children[i] = path.octree.size() - 1;
}
@@ -299,8 +304,7 @@ void AROTBuilder::Node::pathWrite(DNAPATH::PATH<PAKBridge>& path, const zeus::CA
n.aabb[0] = curAABB.min;
n.aabb[1] = curAABB.max;
n.centroid = curAABB.center();
for (int i = 0; i < 8; ++i)
n.children[i] = children[i];
std::copy(children.cbegin(), children.cend(), std::begin(n.children));
n.regionCount = 0;
n.regionStart = 0;
}
@@ -346,18 +350,20 @@ void AROTBuilder::build(std::vector<std::vector<uint8_t>>& secs, const zeus::CAA
auto bmpIt = bmp.cbegin();
if (bmpIt != bmp.cend()) {
int curIdx = 0;
for (size_t w = 0; w < bmpWordCount; ++w) {
for (int b = 0; b < 32; ++b) {
for (size_t word = 0; word < bmpWordCount; ++word) {
for (u32 b = 0; b < 32; ++b) {
if (*bmpIt == curIdx) {
bmpWords[w] |= 1 << b;
bmpWords[word] |= 1U << b;
++bmpIt;
if (bmpIt == bmp.cend())
if (bmpIt == bmp.cend()) {
break;
}
}
++curIdx;
}
if (bmpIt == bmp.cend())
if (bmpIt == bmp.cend()) {
break;
}
}
}
@@ -381,10 +387,10 @@ std::pair<std::unique_ptr<uint8_t[]>, uint32_t> AROTBuilder::buildCol(const ColM
triBoxes.reserve(mesh.trianges.size());
for (const ColMesh::Triangle& tri : mesh.trianges) {
zeus::CAABox& aabb = triBoxes.emplace_back();
for (int e = 0; e < 3; ++e) {
const ColMesh::Edge& edge = mesh.edges[tri.edges[e]];
for (int v = 0; v < 2; ++v) {
const auto& vert = mesh.verts[edge.verts[v]];
for (const u32 edgeIdx : tri.edges) {
const ColMesh::Edge& edge = mesh.edges[edgeIdx];
for (const u32 vertIdx : edge.verts) {
const auto& vert = mesh.verts[vertIdx];
aabb.accumulateBounds(zeus::CVector3f(vert));
}
}