2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 15:44:56 +00:00
This commit is contained in:
Jack Andersen
2017-05-29 09:56:36 -10:00
13 changed files with 322 additions and 25 deletions

View File

@@ -2,13 +2,14 @@
#include "AROTBuilder.hpp"
#include "DataSpec/DNAMP1/DeafBabe.hpp"
#include "DataSpec/DNAMP2/DeafBabe.hpp"
#include "DataSpec/DNAMP1/DCLN.hpp"
#include <inttypes.h>
namespace DataSpec
{
template<class DEAFBABE>
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db)
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db, bool isDcln, atInt32 idx)
{
os << "material_index = []\n"
"col_bm = bmesh.new()\n";
@@ -50,8 +51,12 @@ void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFB
db.insertNoClimb(os);
os << "col_mesh = bpy.data.meshes.new('CMESH')\n"
"col_bm.to_mesh(col_mesh)\n"
if (isDcln)
os.format("col_mesh = bpy.data.meshes.new('CMESH_%i')\n", idx);
else
os << "col_mesh = bpy.data.meshes.new('CMESH')\n";
os << "col_bm.to_mesh(col_mesh)\n"
"col_mesh_obj = bpy.data.objects.new(col_mesh.name, col_mesh)\n"
"\n"
"for mat_name in material_index:\n"
@@ -61,18 +66,22 @@ void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFB
"bpy.context.scene.objects.link(col_mesh_obj)\n"
"bpy.context.scene.objects.active = col_mesh_obj\n"
"bpy.ops.object.mode_set(mode='EDIT')\n"
"bpy.ops.mesh.tris_convert_to_quads(materials=True)\n"
"bpy.ops.mesh.tris_convert_to_quads()\n"
"bpy.ops.object.mode_set(mode='OBJECT')\n"
"bpy.context.scene.objects.active = None\n"
"col_mesh_obj.layers[1] = True\n"
"col_mesh_obj.layers[0] = False\n"
"col_mesh_obj.draw_type = 'SOLID'\n"
"bpy.context.scene.objects.active = None\n";
if (!isDcln)
os << "col_mesh_obj.layers[1] = True\n"
"col_mesh_obj.layers[0] = False\n";
os << "col_mesh_obj.draw_type = 'SOLID'\n"
"col_mesh_obj.game.physics_type = 'STATIC'\n"
"\n";
}
template void DeafBabeSendToBlender<DNAMP1::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP1::DeafBabe& db);
template void DeafBabeSendToBlender<DNAMP2::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP2::DeafBabe& db);
template void DeafBabeSendToBlender<DNAMP1::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP1::DeafBabe& db, bool isDcln, atInt32 idx);
template void DeafBabeSendToBlender<DNAMP2::DeafBabe>(hecl::BlenderConnection::PyOutStream& os, const DNAMP2::DeafBabe& db, bool isDcln, atInt32 idx);
template void DeafBabeSendToBlender<DNAMP1::DCLN::Collision>(hecl::BlenderConnection::PyOutStream& os, const DNAMP1::DCLN::Collision& db, bool isDcln, atInt32 idx);
template<class DEAFBABE>
void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh)

View File

@@ -15,7 +15,7 @@ enum class BspNodeType : atUint32
};
template<class DEAFBABE>
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db);
void DeafBabeSendToBlender(hecl::BlenderConnection::PyOutStream& os, const DEAFBABE& db, bool isDcln = false, atInt32 idx = -1);
template<class DEAFBABE>
void DeafBabeBuildFromBlender(DEAFBABE& db, const hecl::BlenderConnection::DataStream::ColMesh& colMesh);

View File

@@ -19,6 +19,9 @@ make_dnalist(liblist DNAMP1
FRME
SAVW
HINT
MazeSeeds
SnowForces
DCLN
Tweaks/CTweakGame
Tweaks/CTweakParticle
Tweaks/CTweakPlayer

184
DataSpec/DNAMP1/DCLN.hpp Normal file
View File

@@ -0,0 +1,184 @@
#ifndef __DNAMP1_DCLN_HPP__
#define __DNAMP1_DCLN_HPP__
#include "../DNACommon/DeafBabe.hpp"
#include "../DNACommon/PAK.hpp"
#include "DNAMP1.hpp"
#include "DeafBabe.hpp"
namespace DataSpec
{
namespace DNAMP1
{
struct DCLN : BigDNA
{
DECL_DNA
Value<atUint32> colCount;
struct Collision : BigDNA
{
using Material = DeafBabe::Material;
using Edge = DeafBabe::Edge;
using Triangle = DeafBabe::Triangle;
DECL_DNA
Value<atUint32> magic;
Value<atUint32> version;
Value<atUint32> memSize;
Value<atUint32> materialCount;
Vector<Material, DNA_COUNT(materialCount)> materials;
Value<atUint32> vertMatsCount;
Vector<atUint8, DNA_COUNT(vertMatsCount)> vertMats;
Value<atUint32> edgeMatsCount;
Vector<atUint8, DNA_COUNT(edgeMatsCount)> edgeMats;
Value<atUint32> triMatsCount;
Vector<atUint8, DNA_COUNT(triMatsCount)> triMats;
Value<atUint32> edgeVertsCount;
Vector<Edge, DNA_COUNT(edgeVertsCount)> edgeVertConnections;
Value<atUint32> triangleEdgesCount;
Vector<Triangle, DNA_COUNT(triangleEdgesCount / 3)> triangleEdgeConnections;
Value<atUint32> vertCount;
Vector<atVec3f, DNA_COUNT(vertCount)> verts;
struct LeafData : BigDNA
{
DECL_DNA
Value<atUint32> edgeIndexCount;
Vector<atUint16, DNA_COUNT(edgeIndexCount)> edgeIndices;
size_t getMemoryUsage() const { return (((edgeIndices.size() * 2) + 16) + 3) & ~3; }
};
struct Node : BigDNA
{
Delete _d;
Value<atVec4f> xf[3];
Value<atVec3f> origin;
Value<bool> isLeaf;
std::unique_ptr<LeafData> leafData;
std::unique_ptr<Node> left;
std::unique_ptr<Node> right;
void read(athena::io::IStreamReader & __dna_reader)
{
xf[0] = __dna_reader.readVec4fBig();
xf[1] = __dna_reader.readVec4fBig();
xf[2] = __dna_reader.readVec4fBig();
origin = __dna_reader.readVec3fBig();
isLeaf = __dna_reader.readBool();
if (isLeaf)
{
leafData.reset(new LeafData);
leafData->read(__dna_reader);
}
else
{
left.reset(new Node);
left->read(__dna_reader);
right.reset(new Node);
right->read(__dna_reader);
}
}
void write(athena::io::IStreamWriter & __dna_writer) const
{
__dna_writer.writeVec4fBig(xf[0]);
__dna_writer.writeVec4fBig(xf[1]);
__dna_writer.writeVec4fBig(xf[2]);
__dna_writer.writeVec3fBig(origin);
__dna_writer.writeBool(isLeaf);
if (isLeaf && leafData)
leafData->write(__dna_writer);
else if (!isLeaf && left && right)
{
left->write(__dna_writer);
right->write(__dna_writer);
}
}
size_t binarySize(size_t __isz) const
{
__isz += 61;
if (isLeaf && leafData)
__isz = leafData->binarySize(__isz);
else if (!isLeaf && left && right)
{
__isz = left->binarySize(__isz);
__isz = right->binarySize(__isz);
}
return __isz;
}
size_t getMemoryUsage() const
{
size_t ret = 80;
if (isLeaf)
ret += leafData->getMemoryUsage();
else
{
ret += left->getMemoryUsage();
ret += right->getMemoryUsage();
}
return (ret + 3) & ~3;
}
};
Node root;
size_t getMemoryUsage()
{
return root.getMemoryUsage();
}
/* Dummy MP2 member */
void insertNoClimb(hecl::BlenderConnection::PyOutStream&) const {}
};
Vector<Collision, DNA_COUNT(colCount)> collision;
void sendToBlender(hecl::BlenderConnection& conn, const std::string& entryName)
{
/* Open Py Stream and read sections */
hecl::BlenderConnection::PyOutStream os = conn.beginPythonOut(true);
os.format("import bpy\n"
"import bmesh\n"
"from mathutils import Vector\n"
"\n"
"bpy.context.scene.name = '%s'\n"
"# Clear Scene\n"
"for ob in bpy.data.objects:\n"
" if ob.type != 'CAMERA':\n"
" bpy.context.scene.objects.unlink(ob)\n"
" bpy.data.objects.remove(ob)\n",
entryName.c_str());
DeafBabe::BlenderInit(os);
atInt32 idx = 0;
for (const Collision& col : collision)
DeafBabeSendToBlender(os, col, true, idx++);
os.centerView();
os.close();
}
static bool Extract(const SpecBase& dataSpec,
PAKEntryReadStream& rs,
const hecl::ProjectPath& outPath,
PAKRouter<PAKBridge>& pakRouter,
const PAK::Entry& entry,
bool force,
hecl::BlenderToken& btok,
std::function<void(const hecl::SystemChar*)> fileChanged)
{
DCLN dcln;
dcln.read(rs);
hecl::BlenderConnection& conn = btok.getBlenderConnection();
if (!conn.createBlend(outPath, hecl::BlenderConnection::BlendType::Mesh))
return false;
dcln.sendToBlender(conn, pakRouter.getBestEntryName(entry, false));
return conn.saveBlend();
}
};
}
}
#endif // __DNAMP1_DCLN_HPP__

View File

@@ -26,6 +26,7 @@
#include "FRME.hpp"
#include "AGSC.hpp"
#include "CSNG.hpp"
#include "DCLN.hpp"
#include "../DNACommon/Tweaks/TweakWriter.hpp"
#include "Tweaks/CTweakPlayerRes.hpp"
@@ -42,6 +43,8 @@
#include "Tweaks/CTweakParticle.hpp"
#include "Tweaks/CTweakGuiColors.hpp"
#include "Tweaks/CTweakPlayerGun.hpp"
#include "MazeSeeds.hpp"
#include "SnowForces.hpp"
namespace DataSpec
{
@@ -348,6 +351,8 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK& pak, const PAK::En
return {FRME::Extract, {_S(".blend")}, 2};
case SBIG('CMDL'):
return {CMDL::Extract, {_S(".blend")}, 1, CMDL::Name};
case SBIG('DCLN'):
return {DCLN::Extract, {_S(".blend")}};
case SBIG('ANCS'):
return {ANCS::Extract, {_S(".yaml"), _S(".blend")}, 2};
case SBIG('MLVL'):
@@ -381,6 +386,7 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK& pak, const PAK::En
case SBIG('ATBL'):
return {DNAAudio::ATBL::Extract, {_S(".yaml")}};
case SBIG('CTWK'):
case SBIG('DUMB'):
{
bool named;
std::string name = pak.bestEntryName(entry, named);
@@ -414,6 +420,10 @@ ResExtractor<PAKBridge> PAKBridge::LookupExtractor(const PAK& pak, const PAK::En
return {ExtractTweak<CTweakGuiColors>, {_S(".yaml")}};
if (!name.compare("PlayerGun"))
return {ExtractTweak<CTweakPlayerGun>, {_S(".yaml")}};
if (!name.compare("DUMB_MazeSeeds"))
return {ExtractTweak<MazeSeeds>, {_S(".yaml")}};
if (!name.compare("DUMB_SnowForces"))
return {ExtractTweak<SnowForces>, {_S(".yaml")}};
}
break;
}

View File

@@ -0,0 +1,20 @@
#ifndef __DNAMP1_MAZESEEDS_HPP__
#define __DNAMP1_MAZESEEDS_HPP__
#include <vector>
#include "DNAMP1.hpp"
namespace DataSpec
{
namespace DNAMP1
{
struct MazeSeeds : BigYAML
{
DECL_YAML
Value<atUint32> seeds[300];
};
}
}
#endif // __DNAMP1_MAZESEEDS_HPP__

View File

@@ -0,0 +1,27 @@
#ifndef __DNAMP1_SNOWFORCES_HPP__
#define __DNAMP1_SNOWFORCES_HPP__
#include <vector>
#include "DNAMP1.hpp"
namespace DataSpec
{
namespace DNAMP1
{
struct SnowForces : BigYAML
{
DECL_YAML
struct Force : BigYAML
{
DECL_YAML
Value<float> gravity;
Value<float> wind;
};
Value<Force> forces[256];
};
}
}
#endif // __DNAMP1_SNOWFORCES_HPP__

View File

@@ -40,6 +40,8 @@
#include "DNAMP1/Tweaks/CTweakParticle.hpp"
#include "DNAMP1/Tweaks/CTweakGuiColors.hpp"
#include "DNAMP1/Tweaks/CTweakPlayerGun.hpp"
#include "DNAMP1/MazeSeeds.hpp"
#include "DNAMP1/SnowForces.hpp"
#include "hecl/ClientProcess.hpp"
@@ -468,6 +470,10 @@ struct SpecMP1 : SpecBase
return true;
else if (!strcmp(classType, DNAMP1::EVNT::DNAType()))
return true;
else if (!strcmp(classType, DNAMP1::MazeSeeds::DNAType()))
return true;
else if (!strcmp(classType, DNAMP1::SnowForces::DNAType()))
return true;
else if (!strcmp(classType, "ATBL"))
return true;
else if (!strcmp(classType, "MP1OriginalIDs"))
@@ -641,6 +647,12 @@ struct SpecMP1 : SpecBase
resTag.type = SBIG('CTWK');
return true;
}
else if (!strcmp(className, DataSpec::DNAMP1::MazeSeeds::DNAType()) ||
!strcmp(className, DataSpec::DNAMP1::SnowForces::DNAType()))
{
resTag.type = SBIG('DUMB');
return true;
}
else if (!strcmp(className, DataSpec::DNAMP1::HINT::DNAType()))
{
resTag.type = SBIG('HINT');
@@ -948,6 +960,18 @@ struct SpecMP1 : SpecBase
pControl.read(reader);
WriteTweak(pControl, out);
}
else if (!classStr.compare(DNAMP1::MazeSeeds::DNAType()))
{
DNAMP1::MazeSeeds mSeeds;
mSeeds.read(reader);
WriteTweak(mSeeds, out);
}
else if (!classStr.compare(DNAMP1::MazeSeeds::DNAType()))
{
DNAMP1::SnowForces sForces;
sForces.read(reader);
WriteTweak(sForces, out);
}
else if (!classStr.compare(DNAMP1::HINT::DNAType()))
{
DNAMP1::HINT::Cook(in, out);