metaforce/DataSpec/DNAMP1/DCLN.hpp

121 lines
3.7 KiB
C++
Raw Permalink Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2018-10-14 20:16:21 +00:00
#include "athena/Types.hpp"
2018-06-29 20:21:36 +00:00
#include "DataSpec/DNACommon/DeafBabe.hpp"
#include "DataSpec/DNACommon/PAK.hpp"
#include "DataSpec/DNACommon/OBBTreeBuilder.hpp"
#include "DNAMP1.hpp"
#include "DeafBabe.hpp"
2017-10-17 06:05:23 +00:00
#define DCLN_DUMP_OBB 0
2018-12-08 05:30:43 +00:00
namespace DataSpec::DNAMP1 {
2018-12-08 05:30:43 +00:00
struct DCLN : BigDNA {
using Mesh = hecl::blender::ColMesh;
2017-10-17 05:51:53 +00:00
2018-12-08 05:30:43 +00:00
AT_DECL_DNA
Value<atUint32> colCount;
struct Collision : BigDNA {
using Material = DeafBabe::Material;
using Edge = DeafBabe::Edge;
using Triangle = DeafBabe::Triangle;
2018-12-08 05:30:43 +00:00
AT_DECL_DNA
Value<atUint32> magic;
Value<atUint32> version;
Value<atUint32> memSize;
Value<atUint32> materialCount;
Vector<Material, AT_DNA_COUNT(materialCount)> materials;
Value<atUint32> vertMatsCount;
Vector<atUint8, AT_DNA_COUNT(vertMatsCount)> vertMats;
Value<atUint32> edgeMatsCount;
Vector<atUint8, AT_DNA_COUNT(edgeMatsCount)> edgeMats;
Value<atUint32> triMatsCount;
Vector<atUint8, AT_DNA_COUNT(triMatsCount)> triMats;
Value<atUint32> edgeVertsCount;
Vector<Edge, AT_DNA_COUNT(edgeVertsCount)> edgeVertConnections;
Value<atUint32> triangleEdgesCount;
Vector<Triangle, AT_DNA_COUNT(triangleEdgesCount / 3)> triangleEdgeConnections;
Value<atUint32> vertCount;
Vector<atVec3f, AT_DNA_COUNT(vertCount)> verts;
struct Node : BigDNA {
AT_DECL_EXPLICIT_DNA
struct LeafData : BigDNA {
2018-02-22 07:24:51 +00:00
AT_DECL_DNA
2018-12-08 05:30:43 +00:00
Value<atUint32> triangleIndexCount;
Vector<atUint16, AT_DNA_COUNT(triangleIndexCount)> triangleIndices;
size_t getMemoryUsage() const { return (((triangleIndices.size() * 2) + 16) + 3) & ~3; }
};
Value<atVec4f> xf[3];
Value<atVec3f> halfExtent;
Value<bool> isLeaf;
std::unique_ptr<LeafData> leafData;
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
size_t getMemoryUsage() const {
size_t ret = 80;
if (isLeaf)
ret += leafData->getMemoryUsage();
else {
ret += left->getMemoryUsage();
ret += right->getMemoryUsage();
}
return (ret + 3) & ~3;
}
2017-10-17 05:51:53 +00:00
2017-10-17 06:05:23 +00:00
#if DCLN_DUMP_OBB
2018-12-08 05:30:43 +00:00
void sendToBlender(hecl::blender::PyOutStream& os) const;
2017-10-17 06:05:23 +00:00
#endif
};
2018-12-08 05:30:43 +00:00
Node root;
size_t getMemoryUsage() const { return root.getMemoryUsage(); }
2018-12-08 05:30:43 +00:00
/* Dummy MP2 member */
void insertNoClimb(hecl::blender::PyOutStream&) const {}
};
2018-12-08 05:30:43 +00:00
Vector<Collision, AT_DNA_COUNT(colCount)> collision;
2018-12-08 05:30:43 +00:00
void sendToBlender(hecl::blender::Connection& conn, std::string_view entryName);
2018-12-08 05:30:43 +00:00
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);
2017-10-17 05:51:53 +00:00
2018-12-08 05:30:43 +00:00
static bool Cook(const hecl::ProjectPath& outPath, const std::vector<Mesh>& meshes);
};
template <class Op>
void DCLN::Collision::Node::Enumerate(typename Op::StreamT& s) {
2019-08-27 03:02:31 +00:00
Do<Op>(athena::io::PropId{"xf[0]"}, xf[0], s);
Do<Op>(athena::io::PropId{"xf[1]"}, xf[1], s);
Do<Op>(athena::io::PropId{"xf[2]"}, xf[2], s);
Do<Op>(athena::io::PropId{"halfExtent"}, halfExtent, s);
Do<Op>(athena::io::PropId{"isLeaf"}, isLeaf, s);
if (isLeaf) {
if (!leafData) {
leafData = std::make_unique<LeafData>();
}
2019-08-27 03:02:31 +00:00
Do<Op>(athena::io::PropId{"leafData"}, *leafData, s);
} else {
if (!left) {
left = std::make_unique<Node>();
}
2019-08-27 03:02:31 +00:00
Do<Op>(athena::io::PropId{"left"}, *left, s);
if (!right) {
right = std::make_unique<Node>();
}
2019-08-27 03:02:31 +00:00
Do<Op>(athena::io::PropId{"right"}, *right, s);
}
}
AT_SPECIALIZE_DNA(DCLN::Collision::Node)
2018-12-08 05:30:43 +00:00
} // namespace DataSpec::DNAMP1