2017-12-29 08:08:12 +00:00
|
|
|
#include "hecl/ClientProcess.hpp"
|
|
|
|
#include "athena/MemoryReader.hpp"
|
2015-09-09 00:49:20 +00:00
|
|
|
#include "MREA.hpp"
|
2015-09-10 20:30:35 +00:00
|
|
|
#include "SCLY.hpp"
|
2017-02-28 07:31:14 +00:00
|
|
|
#include "PATH.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"
|
2016-08-10 21:54:53 +00:00
|
|
|
#include "zeus/CAABox.hpp"
|
|
|
|
#include "DataSpec/DNACommon/AROTBuilder.hpp"
|
2017-02-24 08:28:44 +00:00
|
|
|
#include "ScriptObjects/ScriptTypes.hpp"
|
2017-12-29 08:08:12 +00:00
|
|
|
#include "hecl/Blender/Connection.hpp"
|
2017-02-24 08:28:44 +00:00
|
|
|
|
2017-02-25 07:59:37 +00:00
|
|
|
extern hecl::SystemString ExeDir;
|
2015-09-27 04:36:15 +00:00
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
namespace DataSpec::DNAMP1
|
2015-09-09 00:49:20 +00:00
|
|
|
{
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
void MREA::ReadBabeDeadToBlender_1_2(hecl::blender::PyOutStream& os,
|
2016-03-04 23:04:53 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-02-24 06:17:17 +00:00
|
|
|
UniqueID32 MREA::GetPATHId(PAKEntryReadStream& rs)
|
|
|
|
{
|
|
|
|
/* Do extract */
|
|
|
|
Header head;
|
|
|
|
head.read(rs);
|
|
|
|
rs.seekAlign32();
|
|
|
|
|
|
|
|
/* Skip to PATH */
|
|
|
|
atUint32 curSec = 0;
|
|
|
|
atUint64 secStart = rs.position();
|
|
|
|
while (curSec != head.pathSecIdx)
|
|
|
|
secStart += head.secSizes[curSec++];
|
|
|
|
if (!head.secSizes[curSec])
|
|
|
|
return {};
|
|
|
|
rs.seek(secStart, athena::Begin);
|
|
|
|
return {rs};
|
|
|
|
}
|
|
|
|
|
2017-12-02 05:50:05 +00:00
|
|
|
/* Collision octree dumper */
|
2017-12-29 08:08:12 +00:00
|
|
|
static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryReader& r,
|
2017-12-02 05:50:05 +00:00
|
|
|
BspNodeType type, const zeus::CAABox& aabb)
|
|
|
|
{
|
|
|
|
if (type == BspNodeType::Branch)
|
|
|
|
{
|
|
|
|
u16 flags = r.readUint16Big();
|
|
|
|
r.readUint16Big();
|
|
|
|
u32 offsets[8];
|
|
|
|
for (int i=0 ; i<8 ; ++i)
|
|
|
|
offsets[i] = r.readUint32Big();
|
|
|
|
u32 dataStart = r.position();
|
|
|
|
for (int i=0 ; i<8 ; ++i)
|
|
|
|
{
|
|
|
|
r.seek(dataStart + offsets[i], athena::Begin);
|
|
|
|
int chFlags = (flags >> (i * 2)) & 0x3;
|
|
|
|
|
|
|
|
zeus::CAABox pos, neg, res;
|
|
|
|
aabb.splitZ(neg, pos);
|
|
|
|
if (i & 4)
|
|
|
|
{
|
|
|
|
zeus::CAABox(pos).splitY(neg, pos);
|
|
|
|
if (i & 2)
|
|
|
|
{
|
|
|
|
zeus::CAABox(pos).splitX(neg, pos);
|
|
|
|
if (i & 1)
|
|
|
|
res = pos;
|
|
|
|
else
|
|
|
|
res = neg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zeus::CAABox(neg).splitX(neg, pos);
|
|
|
|
if (i & 1)
|
|
|
|
res = pos;
|
|
|
|
else
|
|
|
|
res = neg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zeus::CAABox(neg).splitY(neg, pos);
|
|
|
|
if (i & 2)
|
|
|
|
{
|
|
|
|
zeus::CAABox(pos).splitX(neg, pos);
|
|
|
|
if (i & 1)
|
|
|
|
res = pos;
|
|
|
|
else
|
|
|
|
res = neg;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zeus::CAABox(neg).splitX(neg, pos);
|
|
|
|
if (i & 1)
|
|
|
|
res = pos;
|
|
|
|
else
|
|
|
|
res = neg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OutputOctreeNode(os, r, BspNodeType(chFlags), res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (type == BspNodeType::Leaf)
|
|
|
|
{
|
|
|
|
zeus::CVector3f pos = aabb.center();
|
|
|
|
zeus::CVector3f extent = aabb.extents();
|
|
|
|
os.format("obj = bpy.data.objects.new('Leaf', None)\n"
|
|
|
|
"bpy.context.scene.objects.link(obj)\n"
|
|
|
|
"obj.location = (%f,%f,%f)\n"
|
|
|
|
"obj.scale = (%f,%f,%f)\n"
|
|
|
|
"obj.empty_draw_type = 'CUBE'\n"
|
|
|
|
"obj.layers[1] = True\n"
|
|
|
|
"obj.layers[0] = False\n",
|
|
|
|
pos.x, pos.y, pos.z, extent.x, extent.y, extent.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
|
|
|
|
|
|
|
|
/* AROT octree dumper */
|
2017-12-29 08:08:12 +00:00
|
|
|
static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryReader& r,
|
2017-12-02 05:50:05 +00:00
|
|
|
const zeus::CAABox& aabb)
|
|
|
|
{
|
|
|
|
r.readUint16Big();
|
|
|
|
u16 flags = r.readUint16Big();
|
|
|
|
if (flags)
|
|
|
|
{
|
|
|
|
u32 childCount = AROTChildCounts[flags];
|
|
|
|
r.seek(2 * childCount);
|
|
|
|
|
|
|
|
zeus::CAABox Z[2] = {aabb};
|
|
|
|
if ((flags & 0x1) != 0)
|
|
|
|
aabb.splitZ(Z[0], Z[1]);
|
|
|
|
for (int k=0 ; k < 1 + ((flags & 0x1) != 0) ; ++k)
|
|
|
|
{
|
|
|
|
zeus::CAABox Y[2] = {Z[0]};
|
|
|
|
if ((flags & 0x2) != 0)
|
|
|
|
Z[k].splitY(Y[0], Y[1]);
|
|
|
|
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
|
|
|
|
{
|
|
|
|
zeus::CAABox X[2] = {Y[0]};
|
|
|
|
if ((flags & 0x4) != 0)
|
|
|
|
Y[j].splitX(X[0], X[1]);
|
|
|
|
for (int i=0 ; i < 1 + ((flags & 0x4) != 0) ; ++i)
|
|
|
|
{
|
|
|
|
OutputOctreeNode(os, r, X[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zeus::CVector3f pos = aabb.center();
|
|
|
|
zeus::CVector3f extent = aabb.extents();
|
|
|
|
os.format("obj = bpy.data.objects.new('Leaf', None)\n"
|
|
|
|
"bpy.context.scene.objects.link(obj)\n"
|
|
|
|
"obj.location = (%f,%f,%f)\n"
|
|
|
|
"obj.scale = (%f,%f,%f)\n"
|
|
|
|
"obj.empty_draw_type = 'CUBE'\n"
|
|
|
|
"obj.layers[1] = True\n"
|
|
|
|
"obj.layers[0] = False\n",
|
|
|
|
pos.x, pos.y, pos.z, extent.x, extent.y, extent.z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::Token& btok,
|
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-09-30 22:43:19 +00:00
|
|
|
if (!force && outPath.isFile())
|
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();
|
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::Connection& conn = btok.getBlenderConnection();
|
|
|
|
if (!conn.createBlend(outPath, hecl::blender::BlendType::Area))
|
2015-09-09 00:49:20 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Open Py Stream and read sections */
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::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",
|
2016-12-25 01:36:42 +00:00
|
|
|
pakRouter.getBestEntryName(entry, false).c_str());
|
2016-08-12 02:33:38 +00:00
|
|
|
DNACMDL::InitGeomBlenderContext(os, dataSpec.getMasterShaderPath(), true);
|
2015-09-09 00:49:20 +00:00
|
|
|
MaterialSet::RegisterMaterialProps(os);
|
|
|
|
os << "# Clear Scene\n"
|
|
|
|
"for ob in bpy.data.objects:\n"
|
2016-08-09 19:30:23 +00:00
|
|
|
" if ob.type != 'CAMERA':\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 */
|
2017-12-02 05:50:05 +00:00
|
|
|
secStart = rs.position();
|
|
|
|
rs.seek(secStart + head.secSizes[curSec++], athena::Begin);
|
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
|
|
|
|
2017-02-24 08:28:44 +00:00
|
|
|
/* Dump VISI entities */
|
2017-10-22 06:11:22 +00:00
|
|
|
secStart = rs.position();
|
2017-02-24 08:28:44 +00:00
|
|
|
if (head.secSizes[curSec] && rs.readUint32Big() == 'VISI')
|
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
{
|
|
|
|
rs.seek(secStart, athena::Begin);
|
|
|
|
auto visiData = rs.readUBytes(head.secSizes[curSec]);
|
|
|
|
athena::io::FileWriter visiOut(outPath.getWithExtension(_S(".visi"), true).getAbsolutePath());
|
|
|
|
visiOut.writeUBytes(visiData.get(), head.secSizes[curSec]);
|
|
|
|
rs.seek(secStart + 4, athena::Begin);
|
|
|
|
}
|
|
|
|
|
2017-02-24 08:28:44 +00:00
|
|
|
athena::io::YAMLDocWriter visiWriter("VISI");
|
|
|
|
if (auto __vec = visiWriter.enterSubVector("entities"))
|
|
|
|
{
|
2017-04-13 19:28:31 +00:00
|
|
|
rs.seek(18, athena::Current);
|
2017-02-24 08:28:44 +00:00
|
|
|
uint32_t entityCount = rs.readUint32Big();
|
|
|
|
rs.seek(8, athena::Current);
|
|
|
|
for (int i=0 ; i<entityCount ; ++i)
|
|
|
|
{
|
|
|
|
uint32_t entityId = rs.readUint32Big();
|
|
|
|
visiWriter.writeUint16(nullptr, entityId & 0xffff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hecl::ProjectPath visiMetadataPath(outPath.getParentPath(), _S("!visi.yaml"));
|
|
|
|
athena::io::FileWriter visiMetadata(visiMetadataPath.getAbsolutePath());
|
|
|
|
visiWriter.finish(&visiMetadata);
|
|
|
|
}
|
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2016-08-10 02:52:00 +00:00
|
|
|
void MREA::MeshHeader::VisorFlags::setFromBlenderProps(const std::unordered_map<std::string, std::string>& props)
|
|
|
|
{
|
|
|
|
auto search = props.find("retro_disable_enviro_visor");
|
|
|
|
if (search != props.cend() && !search->second.compare("True"))
|
|
|
|
setDisableEnviro(true);
|
|
|
|
search = props.find("retro_disable_thermal_visor");
|
|
|
|
if (search != props.cend() && !search->second.compare("True"))
|
|
|
|
setDisableThermal(true);
|
|
|
|
search = props.find("retro_disable_xray_visor");
|
|
|
|
if (search != props.cend() && !search->second.compare("True"))
|
|
|
|
setDisableXray(true);
|
|
|
|
search = props.find("retro_thermal_level");
|
|
|
|
if (search != props.cend())
|
|
|
|
{
|
|
|
|
if (!search->second.compare("COOL"))
|
|
|
|
setThermalLevel(ThermalLevel::Cool);
|
|
|
|
else if (!search->second.compare("HOT"))
|
|
|
|
setThermalLevel(ThermalLevel::Hot);
|
|
|
|
else if (!search->second.compare("WARM"))
|
|
|
|
setThermalLevel(ThermalLevel::Warm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MREA::Cook(const hecl::ProjectPath& outPath,
|
|
|
|
const hecl::ProjectPath& inPath,
|
2016-08-10 21:54:53 +00:00
|
|
|
const std::vector<DNACMDL::Mesh>& meshes,
|
2016-08-11 19:52:22 +00:00
|
|
|
const ColMesh& cMesh,
|
2018-03-28 08:09:41 +00:00
|
|
|
const std::vector<Light>& lights,
|
|
|
|
hecl::blender::Token& btok,
|
2018-04-07 20:55:57 +00:00
|
|
|
const hecl::blender::Matrix4f* xf,
|
2018-03-28 08:09:41 +00:00
|
|
|
bool pc)
|
2016-08-10 02:52:00 +00:00
|
|
|
{
|
|
|
|
/* Discover area layers */
|
|
|
|
hecl::ProjectPath areaDirPath = inPath.getParentPath();
|
|
|
|
std::vector<hecl::ProjectPath> layerScriptPaths;
|
|
|
|
{
|
|
|
|
hecl::DirectoryEnumerator dEnum(inPath.getParentPath().getAbsolutePath(),
|
|
|
|
hecl::DirectoryEnumerator::Mode::DirsSorted,
|
|
|
|
false, false, true);
|
|
|
|
for (const hecl::DirectoryEnumerator::Entry& ent : dEnum)
|
|
|
|
{
|
2016-10-01 23:20:20 +00:00
|
|
|
hecl::ProjectPath layerScriptPath(areaDirPath, ent.m_name + _S("/!objects.yaml"));
|
2016-09-18 23:47:48 +00:00
|
|
|
if (layerScriptPath.isFile())
|
2016-08-10 02:52:00 +00:00
|
|
|
layerScriptPaths.push_back(std::move(layerScriptPath));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 08:09:41 +00:00
|
|
|
size_t secCount = 1 + meshes.size() * (pc ? 5 : 7); /* (materials, 5/7 fixed model secs) */
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* tally up surfaces */
|
|
|
|
for (const DNACMDL::Mesh& mesh : meshes)
|
|
|
|
secCount += mesh.surfaces.size();
|
|
|
|
|
|
|
|
/* Header */
|
|
|
|
Header head = {};
|
|
|
|
head.magic = 0xDEADBEEF;
|
2018-03-28 08:09:41 +00:00
|
|
|
head.version = pc ? 0x1000F : 0xF;
|
2018-04-07 20:55:57 +00:00
|
|
|
if (xf)
|
|
|
|
{
|
|
|
|
head.localToWorldMtx[0] = xf->val[0];
|
|
|
|
head.localToWorldMtx[1] = xf->val[1];
|
|
|
|
head.localToWorldMtx[2] = xf->val[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
head.localToWorldMtx[0].vec[0] = 1.f;
|
|
|
|
head.localToWorldMtx[1].vec[1] = 1.f;
|
|
|
|
head.localToWorldMtx[2].vec[2] = 1.f;
|
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
head.meshCount = meshes.size();
|
|
|
|
head.geomSecIdx = 0;
|
|
|
|
head.arotSecIdx = secCount++;
|
|
|
|
head.sclySecIdx = secCount++;
|
|
|
|
head.collisionSecIdx = secCount++;
|
|
|
|
head.unkSecIdx = secCount++;
|
|
|
|
head.lightSecIdx = secCount++;
|
|
|
|
head.visiSecIdx = secCount++;
|
|
|
|
head.pathSecIdx = secCount++;
|
|
|
|
head.secCount = secCount;
|
|
|
|
|
|
|
|
std::vector<std::vector<uint8_t>> secs;
|
|
|
|
secs.reserve(secCount + 2);
|
|
|
|
|
|
|
|
/* Header section */
|
|
|
|
{
|
2018-02-22 07:24:51 +00:00
|
|
|
size_t secSz = 0;
|
|
|
|
head.binarySize(secSz);
|
|
|
|
secs.emplace_back(secSz, 0);
|
2016-08-10 02:52:00 +00:00
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
|
|
|
head.write(w);
|
|
|
|
int i = w.position();
|
|
|
|
int end = ROUND_UP_32(i);
|
|
|
|
for (; i<end ; ++i)
|
|
|
|
w.writeByte(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sizes section */
|
|
|
|
secs.emplace_back();
|
|
|
|
|
2016-08-10 21:54:53 +00:00
|
|
|
/* Pre-emptively build full AABB and mesh AABBs in world coords */
|
|
|
|
zeus::CAABox fullAabb;
|
|
|
|
std::vector<zeus::CAABox> meshAabbs;
|
|
|
|
meshAabbs.reserve(meshes.size());
|
|
|
|
|
2016-08-10 02:52:00 +00:00
|
|
|
/* Models */
|
2018-03-28 08:09:41 +00:00
|
|
|
if (pc)
|
|
|
|
{
|
|
|
|
if (!DNACMDL::WriteHMDLMREASecs<HMDLMaterialSet, DNACMDL::SurfaceHeader_2, MeshHeader>
|
2016-08-10 21:54:53 +00:00
|
|
|
(secs, inPath, meshes, fullAabb, meshAabbs))
|
2018-03-28 08:09:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!DNACMDL::WriteMREASecs<MaterialSet, DNACMDL::SurfaceHeader_1, MeshHeader>
|
|
|
|
(secs, inPath, meshes, fullAabb, meshAabbs))
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* AROT */
|
2016-08-10 21:54:53 +00:00
|
|
|
{
|
2017-02-24 08:28:44 +00:00
|
|
|
AROTBuilder arotBuilder;
|
|
|
|
arotBuilder.build(secs, fullAabb, meshAabbs, meshes);
|
2017-12-02 05:50:05 +00:00
|
|
|
|
|
|
|
#if 0
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::Connection& conn = btok.getBlenderConnection();
|
|
|
|
if (!conn.createBlend(inPath.getWithExtension(_S(".octree.blend"), true), hecl::blender::Connection::BlendType::Area))
|
2017-12-02 05:50:05 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Open Py Stream and read sections */
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::PyOutStream os = conn.beginPythonOut(true);
|
2017-12-02 05:50:05 +00:00
|
|
|
os.format("import bpy\n"
|
|
|
|
"import bmesh\n"
|
|
|
|
"from mathutils import Vector\n"
|
|
|
|
"\n"
|
|
|
|
"bpy.context.scene.name = '%s'\n",
|
|
|
|
inPath.getLastComponentUTF8().data());
|
|
|
|
|
|
|
|
athena::io::MemoryReader reader(secs.back().data(), secs.back().size());
|
|
|
|
reader.readUint32Big();
|
|
|
|
reader.readUint32Big();
|
|
|
|
u32 numMeshBitmaps = reader.readUint32Big();
|
|
|
|
u32 meshBitCount = reader.readUint32Big();
|
|
|
|
u32 numNodes = reader.readUint32Big();
|
|
|
|
auto aabbMin = reader.readVec3fBig();
|
|
|
|
auto aabbMax = reader.readVec3fBig();
|
|
|
|
reader.seekAlign32();
|
|
|
|
reader.seek(ROUND_UP_32(meshBitCount) / 8 * numMeshBitmaps + numNodes * 4);
|
|
|
|
zeus::CAABox arotAABB(aabbMin, aabbMax);
|
|
|
|
OutputOctreeNode(os, reader, arotAABB);
|
|
|
|
|
|
|
|
os.centerView();
|
|
|
|
os.close();
|
|
|
|
conn.saveBlend();
|
|
|
|
#endif
|
2016-08-10 21:54:53 +00:00
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* SCLY */
|
2017-02-24 08:28:44 +00:00
|
|
|
DNAMP1::SCLY sclyData = {};
|
2016-08-10 02:52:00 +00:00
|
|
|
{
|
2016-08-13 01:23:27 +00:00
|
|
|
sclyData.fourCC = 'SCLY';
|
2016-08-10 21:54:53 +00:00
|
|
|
sclyData.version = 1;
|
|
|
|
for (const hecl::ProjectPath& layer : layerScriptPaths)
|
2016-08-10 02:52:00 +00:00
|
|
|
{
|
2016-08-22 03:47:48 +00:00
|
|
|
athena::io::FileReader freader(layer.getAbsolutePath());
|
|
|
|
if (!freader.isOpen())
|
2016-08-10 21:54:53 +00:00
|
|
|
continue;
|
2018-02-22 07:24:51 +00:00
|
|
|
if (!athena::io::ValidateFromYAMLStream<DNAMP1::SCLY::ScriptLayer>(freader))
|
2016-08-10 21:54:53 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
athena::io::YAMLDocReader reader;
|
2016-08-22 03:47:48 +00:00
|
|
|
if (!reader.parse(&freader))
|
2016-08-10 21:54:53 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
sclyData.layers.emplace_back();
|
|
|
|
sclyData.layers.back().read(reader);
|
2018-02-22 07:24:51 +00:00
|
|
|
size_t layerSize = 0;
|
|
|
|
sclyData.layers.back().binarySize(layerSize);
|
|
|
|
sclyData.layerSizes.push_back(layerSize);
|
2016-08-10 02:52:00 +00:00
|
|
|
}
|
2016-08-10 21:54:53 +00:00
|
|
|
sclyData.layerCount = sclyData.layers.size();
|
2016-08-10 02:52:00 +00:00
|
|
|
|
2018-02-22 07:24:51 +00:00
|
|
|
size_t secSz = 0;
|
|
|
|
sclyData.binarySize(secSz);
|
|
|
|
secs.emplace_back(secSz, 0);
|
2016-08-10 21:54:53 +00:00
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
|
|
|
sclyData.write(w);
|
2016-08-10 02:52:00 +00:00
|
|
|
}
|
|
|
|
|
2016-08-10 21:54:53 +00:00
|
|
|
|
2016-08-10 02:52:00 +00:00
|
|
|
/* Collision */
|
2016-08-13 19:37:03 +00:00
|
|
|
{
|
|
|
|
DeafBabe collision = {};
|
2016-08-11 19:52:22 +00:00
|
|
|
DeafBabeBuildFromBlender(collision, cMesh);
|
2016-08-10 02:52:00 +00:00
|
|
|
|
2017-12-02 05:50:05 +00:00
|
|
|
#if 0
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::Connection& conn = btok.getBlenderConnection();
|
|
|
|
if (!conn.createBlend(inPath.getWithExtension(_S(".octree.blend"), true), hecl::blender::Connection::BlendType::Area))
|
2017-12-02 05:50:05 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Open Py Stream and read sections */
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::PyOutStream os = conn.beginPythonOut(true);
|
2017-12-02 05:50:05 +00:00
|
|
|
os.format("import bpy\n"
|
|
|
|
"import bmesh\n"
|
|
|
|
"from mathutils import Vector\n"
|
|
|
|
"\n"
|
|
|
|
"bpy.context.scene.name = '%s'\n",
|
|
|
|
inPath.getLastComponentUTF8().data());
|
|
|
|
|
|
|
|
athena::io::MemoryReader reader(collision.bspTree.get(), collision.bspSize);
|
|
|
|
zeus::CAABox colAABB(collision.aabb[0], collision.aabb[1]);
|
|
|
|
OutputOctreeNode(os, reader, collision.rootNodeType, colAABB);
|
|
|
|
|
|
|
|
os.centerView();
|
|
|
|
os.close();
|
|
|
|
conn.saveBlend();
|
|
|
|
#endif
|
|
|
|
|
2018-02-22 07:24:51 +00:00
|
|
|
size_t secSz = 0;
|
|
|
|
collision.binarySize(secSz);
|
|
|
|
secs.emplace_back(secSz, 0);
|
2016-08-11 19:52:22 +00:00
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
|
|
|
collision.write(w);
|
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* Unk */
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
|
|
|
secs.emplace_back(8, 0);
|
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
|
|
|
w.writeUint32Big(1);
|
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* Lights */
|
2017-04-10 06:57:00 +00:00
|
|
|
std::vector<atVec3f> lightsVisi[2];
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
2017-04-10 06:57:00 +00:00
|
|
|
int actualCounts[2] = {};
|
2016-08-11 19:52:22 +00:00
|
|
|
for (const Light& l : lights)
|
|
|
|
if (l.layer == 0 || l.layer == 1)
|
2017-04-10 06:57:00 +00:00
|
|
|
++actualCounts[l.layer];
|
|
|
|
lightsVisi[0].reserve(actualCounts[0]);
|
|
|
|
lightsVisi[1].reserve(actualCounts[1]);
|
2016-08-11 19:52:22 +00:00
|
|
|
|
2017-04-10 06:57:00 +00:00
|
|
|
secs.emplace_back(12 + 65 * (actualCounts[0] + actualCounts[1]), 0);
|
2016-08-11 19:52:22 +00:00
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
|
|
|
w.writeUint32Big(0xBABEDEAD);
|
|
|
|
|
|
|
|
for (int lay=0 ; lay<2 ; ++lay)
|
|
|
|
{
|
|
|
|
int lightCount = 0;
|
|
|
|
for (const Light& l : lights)
|
|
|
|
{
|
|
|
|
if (l.layer == lay)
|
|
|
|
++lightCount;
|
|
|
|
}
|
|
|
|
w.writeUint32Big(lightCount);
|
|
|
|
for (const Light& l : lights)
|
|
|
|
{
|
|
|
|
if (l.layer == lay)
|
|
|
|
{
|
2016-08-13 19:37:03 +00:00
|
|
|
BabeDeadLight light = {};
|
2016-08-11 19:52:22 +00:00
|
|
|
WriteBabeDeadLightFromBlender(light, l);
|
|
|
|
light.write(w);
|
2017-04-10 06:57:00 +00:00
|
|
|
lightsVisi[l.layer].push_back(light.position);
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* VISI */
|
2017-02-24 08:28:44 +00:00
|
|
|
hecl::ProjectPath visiMetadataPath(areaDirPath, _S("!visi.yaml"));
|
2017-02-28 07:31:14 +00:00
|
|
|
bool visiGood = false;
|
2017-02-24 08:28:44 +00:00
|
|
|
if (visiMetadataPath.isFile())
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
2017-02-24 08:28:44 +00:00
|
|
|
athena::io::FileReader visiReader(visiMetadataPath.getAbsolutePath());
|
|
|
|
athena::io::YAMLDocReader r;
|
|
|
|
if (r.parse(&visiReader))
|
|
|
|
{
|
|
|
|
size_t entityCount;
|
|
|
|
std::vector<std::pair<uint16_t, zeus::CAABox>> entities;
|
|
|
|
if (auto __vec = r.enterSubVector("entities", entityCount))
|
|
|
|
{
|
|
|
|
entities.reserve(entityCount);
|
2017-10-22 06:11:22 +00:00
|
|
|
for (size_t i=0 ; i<entityCount ; ++i)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
uint16_t entityId = r.readUint16(nullptr);
|
|
|
|
for (const SCLY::ScriptLayer& layer : sclyData.layers)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
for (const std::unique_ptr<IScriptObject>& obj : layer.objects)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
if ((obj->id & 0xffff) == entityId)
|
|
|
|
{
|
|
|
|
zeus::CAABox entAABB = obj->getVISIAABB(btok);
|
|
|
|
if (!entAABB.invalid())
|
|
|
|
entities.emplace_back(entityId, entAABB);
|
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
// Check if pre-generated visi exists, recycle if able
|
|
|
|
hecl::ProjectPath preVisiPath = inPath.getWithExtension(_S(".visi"), true);
|
|
|
|
if (preVisiPath.getPathType() == hecl::ProjectPath::Type::File)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
athena::io::FileReader preVisiReader(preVisiPath.getAbsolutePath());
|
|
|
|
atUint64 preVisiLen = preVisiReader.length();
|
|
|
|
if (preVisiLen > 26)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
auto preVisiData = preVisiReader.readUBytes(preVisiLen);
|
|
|
|
athena::io::MemoryReader preVisiDataReader(preVisiData.get(), preVisiLen);
|
|
|
|
|
|
|
|
atUint32 preVisiFourCC = preVisiDataReader.readUint32Big();
|
|
|
|
atUint32 preVisiVersion = preVisiDataReader.readUint32Big();
|
|
|
|
preVisiDataReader.readBool();
|
|
|
|
preVisiDataReader.readBool();
|
|
|
|
atUint32 preFeatureCount = preVisiDataReader.readUint32Big();
|
|
|
|
atUint32 preLightsCount = preVisiDataReader.readUint32Big();
|
|
|
|
atUint32 preLayer2LightCount = preVisiDataReader.readUint32Big();
|
|
|
|
atUint32 preEntityCount = preVisiDataReader.readUint32Big();
|
|
|
|
|
|
|
|
if (preVisiFourCC == 'VISI' && preVisiVersion == 2 &&
|
|
|
|
preFeatureCount == meshes.size() + entities.size() &&
|
|
|
|
preLightsCount == lightsVisi[0].size() + lightsVisi[1].size() &&
|
|
|
|
preLayer2LightCount == lightsVisi[1].size() &&
|
|
|
|
preEntityCount == entities.size())
|
|
|
|
{
|
|
|
|
secs.emplace_back(preVisiLen, 0);
|
|
|
|
memcpy(secs.back().data(), preVisiData.get(), preVisiLen);
|
|
|
|
visiGood = true;
|
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
}
|
2017-10-22 06:11:22 +00:00
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
|
2017-12-06 03:26:15 +00:00
|
|
|
#if !WINDOWS_STORE
|
2017-10-22 06:11:22 +00:00
|
|
|
if (!visiGood)
|
|
|
|
{
|
|
|
|
hecl::ProjectPath visiIntOut = outPath.getWithExtension(_S(".visiint"));
|
|
|
|
athena::io::FileWriter w(visiIntOut.getAbsolutePath());
|
|
|
|
w.writeUint32Big(meshes.size());
|
|
|
|
for (const DNACMDL::Mesh& mesh : meshes)
|
2017-02-24 08:28:44 +00:00
|
|
|
{
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeUint32Big(uint32_t(mesh.topology));
|
|
|
|
|
|
|
|
w.writeUint32Big(mesh.pos.size());
|
|
|
|
for (const auto& v : mesh.pos)
|
|
|
|
{
|
2017-12-29 08:08:12 +00:00
|
|
|
atVec3f xfPos = hecl::blender::MtxVecMul4RM(mesh.sceneXf, v);
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeVec3fBig(xfPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
w.writeUint32Big(mesh.surfaces.size());
|
|
|
|
for (const DNACMDL::Mesh::Surface& surf : mesh.surfaces)
|
|
|
|
{
|
|
|
|
w.writeUint32Big(surf.verts.size());
|
|
|
|
for (const DNACMDL::Mesh::Surface::Vert& vert : surf.verts)
|
|
|
|
w.writeUint32Big(vert.iPos);
|
2017-12-29 08:08:12 +00:00
|
|
|
const DNACMDL::Material& mat = mesh.materialSets[0][surf.materialIdx];
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeBool(mat.transparent);
|
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
}
|
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeUint32Big(entities.size());
|
|
|
|
for (const auto& ent : entities)
|
|
|
|
{
|
|
|
|
w.writeUint32Big(ent.first);
|
|
|
|
w.writeVec3fBig(ent.second.min);
|
|
|
|
w.writeVec3fBig(ent.second.max);
|
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
w.writeUint32Big(lightsVisi[0].size() + lightsVisi[1].size());
|
|
|
|
w.writeUint32Big(lightsVisi[1].size());
|
|
|
|
for (const auto& light : lightsVisi[1])
|
|
|
|
w.writeVec3fBig(light);
|
|
|
|
for (const auto& light : lightsVisi[0])
|
|
|
|
w.writeVec3fBig(light);
|
2017-02-24 08:28:44 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
w.close();
|
2017-02-24 08:28:44 +00:00
|
|
|
|
2017-10-22 06:11:22 +00:00
|
|
|
hecl::SystemString VisiGenPath = ExeDir + _S("/visigen");
|
2017-02-24 08:28:44 +00:00
|
|
|
#if _WIN32
|
2017-10-22 06:11:22 +00:00
|
|
|
VisiGenPath += _S(".exe");
|
2017-02-24 08:28:44 +00:00
|
|
|
#endif
|
2017-10-24 03:12:10 +00:00
|
|
|
hecl::SystemChar thrIdx[16];
|
|
|
|
hecl::SNPrintf(thrIdx, 16, _S("%d"), hecl::ClientProcess::GetThreadWorkerIdx());
|
|
|
|
hecl::SystemChar parPid[32];
|
|
|
|
#if _WIN32
|
2017-10-25 07:47:49 +00:00
|
|
|
hecl::SNPrintf(parPid, 32, _S("%lluX"), reinterpret_cast<unsigned long long>(GetCurrentProcess()));
|
2017-10-24 03:12:10 +00:00
|
|
|
#else
|
2017-10-25 07:47:49 +00:00
|
|
|
hecl::SNPrintf(parPid, 32, _S("%lluX"), (unsigned long long)getpid());
|
2017-10-24 03:12:10 +00:00
|
|
|
#endif
|
2017-10-22 06:11:22 +00:00
|
|
|
const hecl::SystemChar* args[] = {VisiGenPath.c_str(),
|
2017-11-13 06:19:18 +00:00
|
|
|
visiIntOut.getAbsolutePath().data(),
|
|
|
|
preVisiPath.getAbsolutePath().data(),
|
2017-10-24 03:12:10 +00:00
|
|
|
thrIdx, parPid, nullptr};
|
2017-10-22 06:11:22 +00:00
|
|
|
if (0 == hecl::RunProcess(VisiGenPath.c_str(), args))
|
|
|
|
{
|
2017-10-27 10:10:32 +00:00
|
|
|
athena::io::FileReader r(preVisiPath.getAbsolutePath());
|
2017-10-22 06:11:22 +00:00
|
|
|
size_t length = r.length();
|
|
|
|
secs.emplace_back(length, 0);
|
|
|
|
r.readBytesToBuf(secs.back().data(), length);
|
2017-10-27 10:10:32 +00:00
|
|
|
visiGood = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Log.report(logvisor::Fatal, _S("Unable to launch %s"), VisiGenPath.c_str());
|
2017-10-22 06:11:22 +00:00
|
|
|
}
|
2017-02-24 08:28:44 +00:00
|
|
|
}
|
2017-12-06 03:26:15 +00:00
|
|
|
#endif
|
2017-02-24 08:28:44 +00:00
|
|
|
}
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
2017-02-28 07:31:14 +00:00
|
|
|
if (!visiGood)
|
|
|
|
secs.emplace_back(4, 0);
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* PATH */
|
2016-08-11 19:52:22 +00:00
|
|
|
{
|
2018-02-25 08:23:27 +00:00
|
|
|
hecl::ProjectPath pathPath(inPath.getParentPath(), _S("!path.blend"));
|
|
|
|
UniqueID32 pathId = pathPath;
|
2016-08-11 19:52:22 +00:00
|
|
|
secs.emplace_back(4, 0);
|
|
|
|
athena::io::MemoryWriter w(secs.back().data(), secs.back().size());
|
2017-02-28 07:31:14 +00:00
|
|
|
pathId.write(w);
|
2016-08-11 19:52:22 +00:00
|
|
|
}
|
2016-08-10 02:52:00 +00:00
|
|
|
|
|
|
|
/* Assemble sizes and add padding */
|
|
|
|
{
|
2018-03-28 08:09:41 +00:00
|
|
|
std::vector<uint8_t>& sizesSec = secs[1];
|
2016-08-12 20:44:13 +00:00
|
|
|
sizesSec.assign((((head.secCount) + 7) & ~7) * 4, 0);
|
|
|
|
athena::io::MemoryWriter w(sizesSec.data(), sizesSec.size());
|
2016-08-10 02:52:00 +00:00
|
|
|
for (auto it = secs.begin() + 2 ; it != secs.end() ; ++it)
|
|
|
|
{
|
|
|
|
std::vector<uint8_t>& sec = *it;
|
|
|
|
int i = sec.size();
|
|
|
|
int end = ROUND_UP_32(i);
|
2016-08-11 19:54:34 +00:00
|
|
|
sec.resize(end);
|
2016-08-10 02:52:00 +00:00
|
|
|
w.writeUint32Big(end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Output all padded sections to file */
|
|
|
|
athena::io::FileWriter writer(outPath.getAbsolutePath());
|
|
|
|
for (const std::vector<uint8_t>& sec : secs)
|
|
|
|
writer.writeUBytes(sec.data(), sec.size());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-09-09 00:49:20 +00:00
|
|
|
}
|