2015-09-09 00:49:20 +00:00
|
|
|
#include "MREA.hpp"
|
2015-09-10 20:30:35 +00:00
|
|
|
#include "SCLY.hpp"
|
2015-09-12 07:13:40 +00:00
|
|
|
#include "DeafBabe.hpp"
|
2015-09-28 05:19:31 +00:00
|
|
|
#include "../DNACommon/BabeDead.hpp"
|
2016-03-04 23:04:53 +00:00
|
|
|
#include "zeus/Math.hpp"
|
2015-09-27 04:36:15 +00:00
|
|
|
|
2016-02-13 09:02:47 +00:00
|
|
|
namespace DataSpec
|
2015-09-09 00:49:20 +00:00
|
|
|
{
|
|
|
|
namespace DNAMP1
|
|
|
|
{
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
void MREA::ReadBabeDeadToBlender_1_2(hecl::BlenderConnection::PyOutStream& os,
|
|
|
|
athena::io::IStreamReader& rs)
|
2015-09-12 07:13:40 +00:00
|
|
|
{
|
|
|
|
atUint32 bdMagic = rs.readUint32Big();
|
|
|
|
if (bdMagic != 0xBABEDEAD)
|
2016-03-04 23:04:53 +00:00
|
|
|
Log.report(logvisor::Fatal, "invalid BABEDEAD magic");
|
2015-09-17 19:50:43 +00:00
|
|
|
os << "bpy.context.scene.render.engine = 'CYCLES'\n"
|
|
|
|
"bpy.context.scene.world.use_nodes = True\n"
|
|
|
|
"bpy.context.scene.render.engine = 'BLENDER_GAME'\n"
|
|
|
|
"bg_node = bpy.context.scene.world.node_tree.nodes['Background']\n";
|
2015-09-12 07:13:40 +00:00
|
|
|
for (atUint32 s=0 ; s<2 ; ++s)
|
|
|
|
{
|
|
|
|
atUint32 lightCount = rs.readUint32Big();
|
|
|
|
for (atUint32 l=0 ; l<lightCount ; ++l)
|
|
|
|
{
|
|
|
|
BabeDeadLight light;
|
|
|
|
light.read(rs);
|
2015-09-28 05:19:31 +00:00
|
|
|
ReadBabeDeadLightToBlender(os, light, s, l);
|
2015-09-12 07:13:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-27 00:19:03 +00:00
|
|
|
void MREA::AddCMDLRigPairs(PAKEntryReadStream& rs,
|
|
|
|
PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
std::unordered_map<UniqueID32, std::pair<UniqueID32, UniqueID32>>& addTo)
|
|
|
|
{
|
|
|
|
/* Do extract */
|
|
|
|
Header head;
|
|
|
|
head.read(rs);
|
|
|
|
rs.seekAlign32();
|
|
|
|
|
|
|
|
/* Skip to SCLY */
|
|
|
|
atUint32 curSec = 0;
|
|
|
|
atUint64 secStart = rs.position();
|
|
|
|
while (curSec != head.sclySecIdx)
|
|
|
|
secStart += head.secSizes[curSec++];
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart, athena::Begin);
|
2015-10-27 00:19:03 +00:00
|
|
|
SCLY scly;
|
|
|
|
scly.read(rs);
|
|
|
|
scly.addCMDLRigPairs(pakRouter, addTo);
|
|
|
|
}
|
|
|
|
|
2015-09-09 00:49:20 +00:00
|
|
|
bool MREA::Extract(const SpecBase& dataSpec,
|
|
|
|
PAKEntryReadStream& rs,
|
2016-03-04 23:04:53 +00:00
|
|
|
const hecl::ProjectPath& outPath,
|
2015-09-09 00:49:20 +00:00
|
|
|
PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
const PAK::Entry& entry,
|
2015-09-10 20:30:35 +00:00
|
|
|
bool force,
|
2016-03-04 23:04:53 +00:00
|
|
|
std::function<void(const hecl::SystemChar*)>)
|
2015-09-09 00:49:20 +00:00
|
|
|
{
|
|
|
|
using RigPair = std::pair<CSKR*, CINF*>;
|
|
|
|
RigPair dummy(nullptr, nullptr);
|
|
|
|
|
2016-03-11 02:56:16 +00:00
|
|
|
hecl::ProjectPath mreaPath;
|
|
|
|
if (pakRouter.isShared())
|
|
|
|
/* Rename MREA for consistency */
|
|
|
|
mreaPath = hecl::ProjectPath(outPath.getParentPath(), _S("!area.blend"));
|
|
|
|
else
|
|
|
|
/* We're not in a world pak, so lets keep the original name */
|
|
|
|
mreaPath = outPath;
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
if (!force && mreaPath.getPathType() == hecl::ProjectPath::Type::File)
|
2015-10-26 02:31:09 +00:00
|
|
|
return true;
|
|
|
|
|
2015-09-09 00:49:20 +00:00
|
|
|
/* Do extract */
|
|
|
|
Header head;
|
|
|
|
head.read(rs);
|
|
|
|
rs.seekAlign32();
|
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::BlenderConnection& conn = hecl::BlenderConnection::SharedConnection();
|
|
|
|
if (!conn.createBlend(mreaPath, hecl::BlenderConnection::BlendType::Area))
|
2015-09-09 00:49:20 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Open Py Stream and read sections */
|
2016-03-04 23:04:53 +00:00
|
|
|
hecl::BlenderConnection::PyOutStream os = conn.beginPythonOut(true);
|
2015-09-09 00:49:20 +00:00
|
|
|
os.format("import bpy\n"
|
|
|
|
"import bmesh\n"
|
2015-09-12 07:13:40 +00:00
|
|
|
"from mathutils import Vector\n"
|
2015-09-09 00:49:20 +00:00
|
|
|
"\n"
|
2015-10-01 00:40:21 +00:00
|
|
|
"bpy.context.scene.name = '%s'\n",
|
2015-09-09 00:49:20 +00:00
|
|
|
pakRouter.getBestEntryName(entry).c_str());
|
|
|
|
DNACMDL::InitGeomBlenderContext(os, dataSpec.getMasterShaderPath());
|
|
|
|
MaterialSet::RegisterMaterialProps(os);
|
|
|
|
os << "# Clear Scene\n"
|
|
|
|
"for ob in bpy.data.objects:\n"
|
|
|
|
" bpy.context.scene.objects.unlink(ob)\n"
|
|
|
|
" bpy.data.objects.remove(ob)\n"
|
2015-09-12 07:13:40 +00:00
|
|
|
"bpy.types.Lamp.retro_layer = bpy.props.IntProperty(name='Retro: Light Layer')\n"
|
2015-09-28 06:16:41 +00:00
|
|
|
"bpy.types.Lamp.retro_origtype = bpy.props.IntProperty(name='Retro: Original Type')\n"
|
2015-09-09 00:49:20 +00:00
|
|
|
"bpy.types.Object.retro_disable_enviro_visor = bpy.props.BoolProperty(name='Retro: Disable in Combat/Scan Visor')\n"
|
|
|
|
"bpy.types.Object.retro_disable_thermal_visor = bpy.props.BoolProperty(name='Retro: Disable in Thermal Visor')\n"
|
|
|
|
"bpy.types.Object.retro_disable_xray_visor = bpy.props.BoolProperty(name='Retro: Disable in X-Ray Visor')\n"
|
|
|
|
"bpy.types.Object.retro_thermal_level = bpy.props.EnumProperty(items=[('COOL', 'Cool', 'Cool Temperature'),"
|
|
|
|
"('HOT', 'Hot', 'Hot Temperature'),"
|
|
|
|
"('WARM', 'Warm', 'Warm Temperature')],"
|
|
|
|
"name='Retro: Thermal Visor Level')\n"
|
|
|
|
"\n";
|
|
|
|
|
|
|
|
/* One shared material set for all meshes */
|
|
|
|
os << "# Materials\n"
|
|
|
|
"materials = []\n"
|
|
|
|
"\n";
|
|
|
|
MaterialSet matSet;
|
|
|
|
atUint64 secStart = rs.position();
|
|
|
|
matSet.read(rs);
|
2015-09-19 01:38:40 +00:00
|
|
|
matSet.readToBlender(os, pakRouter, entry, 0);
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart + head.secSizes[0], athena::Begin);
|
2015-09-09 00:49:20 +00:00
|
|
|
std::vector<DNACMDL::VertexAttributes> vertAttribs;
|
|
|
|
DNACMDL::GetVertexAttributes(matSet, vertAttribs);
|
|
|
|
|
|
|
|
/* Read meshes */
|
|
|
|
atUint32 curSec = 1;
|
2015-10-12 04:41:28 +00:00
|
|
|
for (atUint32 m=0 ; m<head.meshCount ; ++m)
|
2015-09-09 00:49:20 +00:00
|
|
|
{
|
|
|
|
MeshHeader mHeader;
|
|
|
|
secStart = rs.position();
|
|
|
|
mHeader.read(rs);
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart + head.secSizes[curSec++], athena::Begin);
|
2016-01-14 22:42:44 +00:00
|
|
|
curSec += DNACMDL::ReadGeomSectionsToBlender<PAKRouter<PAKBridge>, MaterialSet, RigPair, DNACMDL::SurfaceHeader_1>
|
2015-09-19 01:38:40 +00:00
|
|
|
(os, rs, pakRouter, entry, dummy, true,
|
2015-09-09 00:49:20 +00:00
|
|
|
true, vertAttribs, m, head.secCount, 0, &head.secSizes[curSec]);
|
|
|
|
os.format("obj.retro_disable_enviro_visor = %s\n"
|
|
|
|
"obj.retro_disable_thermal_visor = %s\n"
|
|
|
|
"obj.retro_disable_xray_visor = %s\n"
|
|
|
|
"obj.retro_thermal_level = '%s'\n",
|
|
|
|
mHeader.visorFlags.disableEnviro() ? "True" : "False",
|
|
|
|
mHeader.visorFlags.disableThermal() ? "True" : "False",
|
|
|
|
mHeader.visorFlags.disableXray() ? "True" : "False",
|
|
|
|
mHeader.visorFlags.thermalLevelStr());
|
|
|
|
}
|
|
|
|
|
2015-09-12 07:13:40 +00:00
|
|
|
/* Skip AROT */
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(head.secSizes[curSec++], athena::Current);
|
2015-09-12 07:13:40 +00:00
|
|
|
|
2015-09-10 20:30:35 +00:00
|
|
|
/* Read SCLY layers */
|
|
|
|
secStart = rs.position();
|
|
|
|
SCLY scly;
|
|
|
|
scly.read(rs);
|
|
|
|
scly.exportToLayerDirectories(entry, pakRouter, force);
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart + head.secSizes[curSec++], athena::Begin);
|
2015-09-12 07:13:40 +00:00
|
|
|
|
|
|
|
/* Read collision meshes */
|
|
|
|
DeafBabe collision;
|
|
|
|
secStart = rs.position();
|
|
|
|
collision.read(rs);
|
|
|
|
DeafBabe::BlenderInit(os);
|
|
|
|
collision.sendToBlender(os);
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart + head.secSizes[curSec++], athena::Begin);
|
2015-09-12 07:13:40 +00:00
|
|
|
|
|
|
|
/* Skip unknown section */
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(head.secSizes[curSec++], athena::Current);
|
2015-09-12 07:13:40 +00:00
|
|
|
|
|
|
|
/* Read BABEDEAD Lights as Cycles emissives */
|
|
|
|
secStart = rs.position();
|
|
|
|
ReadBabeDeadToBlender_1_2(os, rs);
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart + head.secSizes[curSec++], athena::Begin);
|
2015-09-12 07:13:40 +00:00
|
|
|
|
2015-09-09 00:49:20 +00:00
|
|
|
/* Origins to center of mass */
|
2015-09-12 07:13:40 +00:00
|
|
|
os << "bpy.context.scene.layers[1] = True\n"
|
|
|
|
"bpy.ops.object.select_by_type(type='MESH')\n"
|
2015-09-09 00:49:20 +00:00
|
|
|
"bpy.ops.object.origin_set(type='ORIGIN_CENTER_OF_MASS')\n"
|
2015-09-12 07:13:40 +00:00
|
|
|
"bpy.ops.object.select_all(action='DESELECT')\n"
|
|
|
|
"bpy.context.scene.layers[1] = False\n";
|
2015-09-09 00:49:20 +00:00
|
|
|
|
2015-10-24 01:23:45 +00:00
|
|
|
/* Link MLVL scene as background */
|
|
|
|
os.linkBackground("//../!world.blend", "World");
|
2015-09-09 00:49:20 +00:00
|
|
|
|
2015-10-24 01:23:45 +00:00
|
|
|
os.centerView();
|
2015-09-09 00:49:20 +00:00
|
|
|
os.close();
|
|
|
|
return conn.saveBlend();
|
|
|
|
}
|
|
|
|
|
2015-10-27 00:19:03 +00:00
|
|
|
void MREA::Name(const SpecBase& dataSpec,
|
|
|
|
PAKEntryReadStream& rs,
|
|
|
|
PAKRouter<PAKBridge>& pakRouter,
|
|
|
|
PAK::Entry& entry)
|
|
|
|
{
|
|
|
|
/* Do extract */
|
|
|
|
Header head;
|
|
|
|
head.read(rs);
|
|
|
|
rs.seekAlign32();
|
|
|
|
|
|
|
|
/* One shared material set for all meshes */
|
|
|
|
atUint64 secStart = rs.position();
|
|
|
|
MaterialSet matSet;
|
|
|
|
matSet.read(rs);
|
2016-03-04 23:04:53 +00:00
|
|
|
matSet.nameTextures(pakRouter, hecl::Format("MREA_%s", entry.id.toString().c_str()).c_str(), -1);
|
|
|
|
rs.seek(secStart + head.secSizes[0], athena::Begin);
|
2015-10-27 00:19:03 +00:00
|
|
|
|
|
|
|
/* Skip to SCLY */
|
|
|
|
atUint32 curSec = 1;
|
|
|
|
secStart = rs.position();
|
|
|
|
while (curSec != head.sclySecIdx)
|
|
|
|
secStart += head.secSizes[curSec++];
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart, athena::Begin);
|
2015-10-27 00:19:03 +00:00
|
|
|
SCLY scly;
|
|
|
|
scly.read(rs);
|
|
|
|
scly.nameIDs(pakRouter);
|
|
|
|
|
|
|
|
/* Skip to PATH */
|
|
|
|
while (curSec != head.pathSecIdx)
|
|
|
|
secStart += head.secSizes[curSec++];
|
2016-03-04 23:04:53 +00:00
|
|
|
rs.seek(secStart, athena::Begin);
|
2015-10-27 00:19:03 +00:00
|
|
|
|
|
|
|
UniqueID32 pathID(rs);
|
2016-03-04 23:04:53 +00:00
|
|
|
const nod::Node* node;
|
2015-10-27 00:19:03 +00:00
|
|
|
PAK::Entry* pathEnt = (PAK::Entry*)pakRouter.lookupEntry(pathID, &node);
|
|
|
|
pathEnt->name = entry.name + "_path";
|
|
|
|
}
|
|
|
|
|
2015-09-09 00:49:20 +00:00
|
|
|
}
|
|
|
|
}
|