2016-03-02 07:29:19 +00:00
|
|
|
#include "MLVL.hpp"
|
|
|
|
#include "../DNAMP1/MLVL.hpp"
|
|
|
|
#include "../DNAMP2/MLVL.hpp"
|
|
|
|
#include "../DNAMP3/MLVL.hpp"
|
2017-12-29 08:08:12 +00:00
|
|
|
#include "hecl/Blender/Connection.hpp"
|
2016-03-02 07:29:19 +00:00
|
|
|
|
2017-12-29 08:08:12 +00:00
|
|
|
namespace DataSpec::DNAMLVL
|
2016-03-02 07:29:19 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
template <class PAKRouter, typename MLVL>
|
2017-12-29 08:08:12 +00:00
|
|
|
bool ReadMLVLToBlender(hecl::blender::Connection& conn,
|
2016-03-02 07:29:19 +00:00
|
|
|
const MLVL& mlvl,
|
2016-03-05 00:03:41 +00:00
|
|
|
const hecl::ProjectPath& outPath,
|
2016-03-02 07:29:19 +00:00
|
|
|
PAKRouter& pakRouter,
|
|
|
|
const typename PAKRouter::EntryType& entry,
|
|
|
|
bool force,
|
2016-03-05 00:03:41 +00:00
|
|
|
std::function<void(const hecl::SystemChar*)> fileChanged)
|
2016-03-02 07:29:19 +00:00
|
|
|
{
|
2018-10-14 20:16:21 +00:00
|
|
|
hecl::ProjectPath blendPath = outPath.getWithExtension(_SYS_STR(".blend"), true);
|
2016-10-01 02:57:09 +00:00
|
|
|
if (!force && blendPath.isFile())
|
2016-03-02 07:29:19 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
/* Create World Blend */
|
2017-12-29 08:08:12 +00:00
|
|
|
if (!conn.createBlend(blendPath, hecl::blender::BlendType::World))
|
2016-03-02 07:29:19 +00:00
|
|
|
return false;
|
2017-12-29 08:08:12 +00:00
|
|
|
hecl::blender::PyOutStream os = conn.beginPythonOut(true);
|
2016-03-02 07:29:19 +00:00
|
|
|
os.format("import bpy\n"
|
|
|
|
"import bmesh\n"
|
|
|
|
"from mathutils import Matrix\n"
|
|
|
|
"\n"
|
|
|
|
"bpy.context.scene.name = 'World'\n"
|
|
|
|
"\n"
|
|
|
|
"# 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");
|
2016-03-02 07:29:19 +00:00
|
|
|
|
|
|
|
/* Insert area empties */
|
|
|
|
int areaIdx = 0;
|
|
|
|
for (const auto& area : mlvl.areas)
|
|
|
|
{
|
|
|
|
const typename PAKRouter::EntryType* mreaEntry = pakRouter.lookupEntry(area.areaMREAId);
|
2017-11-13 06:19:18 +00:00
|
|
|
hecl::SystemUTF8Conv areaDirName(*mreaEntry->unique.m_areaName);
|
2016-03-02 07:29:19 +00:00
|
|
|
|
|
|
|
os.AABBToBMesh(area.aabb[0], area.aabb[1]);
|
|
|
|
os.format("box_mesh = bpy.data.meshes.new('''%s''')\n"
|
|
|
|
"bm.to_mesh(box_mesh)\n"
|
|
|
|
"bm.free()\n"
|
|
|
|
"box = bpy.data.objects.new(box_mesh.name, box_mesh)\n"
|
|
|
|
"bpy.context.scene.objects.link(box)\n"
|
|
|
|
"mtx = Matrix(((%f,%f,%f,%f),(%f,%f,%f,%f),(%f,%f,%f,%f),(0.0,0.0,0.0,1.0)))\n"
|
|
|
|
"mtxd = mtx.decompose()\n"
|
|
|
|
"box.rotation_mode = 'QUATERNION'\n"
|
|
|
|
"box.location = mtxd[0]\n"
|
|
|
|
"box.rotation_quaternion = mtxd[1]\n"
|
|
|
|
"box.scale = mtxd[2]\n",
|
2017-11-13 06:19:18 +00:00
|
|
|
areaDirName.str().data(),
|
2016-03-02 07:29:19 +00:00
|
|
|
area.transformMtx[0].vec[0], area.transformMtx[0].vec[1], area.transformMtx[0].vec[2], area.transformMtx[0].vec[3],
|
|
|
|
area.transformMtx[1].vec[0], area.transformMtx[1].vec[1], area.transformMtx[1].vec[2], area.transformMtx[1].vec[3],
|
|
|
|
area.transformMtx[2].vec[0], area.transformMtx[2].vec[1], area.transformMtx[2].vec[2], area.transformMtx[2].vec[3]);
|
|
|
|
|
|
|
|
/* Insert dock planes */
|
|
|
|
int dockIdx = 0;
|
|
|
|
for (const auto& dock : area.docks)
|
|
|
|
{
|
|
|
|
os << "bm = bmesh.new()\n";
|
2016-03-05 00:03:41 +00:00
|
|
|
zeus::CVector3f pvAvg;
|
2016-03-02 07:29:19 +00:00
|
|
|
for (const atVec3f& pv : dock.planeVerts)
|
|
|
|
pvAvg += pv;
|
2017-12-18 02:54:50 +00:00
|
|
|
pvAvg /= zeus::CVector3f(dock.planeVerts.size());
|
2016-03-02 07:29:19 +00:00
|
|
|
int idx = 0;
|
|
|
|
for (const atVec3f& pv : dock.planeVerts)
|
|
|
|
{
|
2016-03-05 00:03:41 +00:00
|
|
|
zeus::CVector3f pvRel = zeus::CVector3f(pv) - pvAvg;
|
2016-03-02 07:29:19 +00:00
|
|
|
os.format("bm.verts.new((%f,%f,%f))\n"
|
|
|
|
"bm.verts.ensure_lookup_table()\n",
|
|
|
|
pvRel[0], pvRel[1], pvRel[2]);
|
|
|
|
if (idx)
|
|
|
|
os << "bm.edges.new((bm.verts[-2], bm.verts[-1]))\n";
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
os << "bm.edges.new((bm.verts[-1], bm.verts[0]))\n";
|
|
|
|
os.format("dockMesh = bpy.data.meshes.new('DOCK_%02d_%02d')\n", areaIdx, dockIdx);
|
|
|
|
os << "dockObj = bpy.data.objects.new(dockMesh.name, dockMesh)\n"
|
|
|
|
"bpy.context.scene.objects.link(dockObj)\n"
|
|
|
|
"bm.to_mesh(dockMesh)\n"
|
|
|
|
"bm.free()\n"
|
|
|
|
"dockObj.parent = box\n";
|
|
|
|
os.format("dockObj.location = (%f,%f,%f)\n",
|
|
|
|
pvAvg[0], pvAvg[1], pvAvg[2]);
|
|
|
|
++dockIdx;
|
|
|
|
}
|
|
|
|
++areaIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
os.centerView();
|
|
|
|
os.close();
|
|
|
|
conn.saveBlend();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template bool ReadMLVLToBlender<PAKRouter<DNAMP1::PAKBridge>, DNAMP1::MLVL>
|
2017-12-29 08:08:12 +00:00
|
|
|
(hecl::blender::Connection& conn,
|
2016-03-02 07:29:19 +00:00
|
|
|
const DNAMP1::MLVL& mlvl,
|
2016-03-05 00:03:41 +00:00
|
|
|
const hecl::ProjectPath& outPath,
|
2016-03-02 07:29:19 +00:00
|
|
|
PAKRouter<DNAMP1::PAKBridge>& pakRouter,
|
2016-03-08 20:29:59 +00:00
|
|
|
const PAKRouter<DNAMP1::PAKBridge>::EntryType& entry,
|
2016-03-02 07:29:19 +00:00
|
|
|
bool force,
|
2016-03-05 00:03:41 +00:00
|
|
|
std::function<void(const hecl::SystemChar*)> fileChanged);
|
2016-03-02 07:29:19 +00:00
|
|
|
|
|
|
|
template bool ReadMLVLToBlender<PAKRouter<DNAMP2::PAKBridge>, DNAMP2::MLVL>
|
2017-12-29 08:08:12 +00:00
|
|
|
(hecl::blender::Connection& conn,
|
2016-03-02 07:29:19 +00:00
|
|
|
const DNAMP2::MLVL& mlvl,
|
2016-03-05 00:03:41 +00:00
|
|
|
const hecl::ProjectPath& outPath,
|
2016-03-02 07:29:19 +00:00
|
|
|
PAKRouter<DNAMP2::PAKBridge>& pakRouter,
|
2016-03-08 20:29:59 +00:00
|
|
|
const PAKRouter<DNAMP2::PAKBridge>::EntryType& entry,
|
2016-03-02 07:29:19 +00:00
|
|
|
bool force,
|
2016-03-05 00:03:41 +00:00
|
|
|
std::function<void(const hecl::SystemChar*)> fileChanged);
|
2016-03-02 07:29:19 +00:00
|
|
|
|
|
|
|
template bool ReadMLVLToBlender<PAKRouter<DNAMP3::PAKBridge>, DNAMP3::MLVL>
|
2017-12-29 08:08:12 +00:00
|
|
|
(hecl::blender::Connection& conn,
|
2016-03-02 07:29:19 +00:00
|
|
|
const DNAMP3::MLVL& mlvl,
|
2016-03-05 00:03:41 +00:00
|
|
|
const hecl::ProjectPath& outPath,
|
2016-03-02 07:29:19 +00:00
|
|
|
PAKRouter<DNAMP3::PAKBridge>& pakRouter,
|
2016-03-08 20:29:59 +00:00
|
|
|
const PAKRouter<DNAMP3::PAKBridge>::EntryType& entry,
|
2016-03-02 07:29:19 +00:00
|
|
|
bool force,
|
2016-03-05 00:03:41 +00:00
|
|
|
std::function<void(const hecl::SystemChar*)> fileChanged);
|
2016-03-02 07:29:19 +00:00
|
|
|
|
|
|
|
}
|