2017-12-29 08:08:12 +00:00
|
|
|
#include "DCLN.hpp"
|
|
|
|
#include "hecl/Blender/Connection.hpp"
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace DataSpec::DNAMP1 {
|
2017-12-29 08:08:12 +00:00
|
|
|
|
|
|
|
#if DCLN_DUMP_OBB
|
2018-12-08 05:30:43 +00:00
|
|
|
void DCLN::Collision::Node::sendToBlender(hecl::blender::PyOutStream& os) const {
|
|
|
|
os.format(
|
|
|
|
"obj = bpy.data.objects.new('%s', None)\n"
|
2019-05-08 03:50:21 +00:00
|
|
|
"obj.empty_display_type = 'CUBE'\n"
|
|
|
|
"bpy.context.scene.collection.objects.link(obj)\n"
|
2018-12-08 05:30:43 +00:00
|
|
|
"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"
|
|
|
|
"obj.rotation_mode = 'QUATERNION'\n"
|
|
|
|
"obj.location = mtxd[0]\n"
|
|
|
|
"obj.rotation_quaternion = mtxd[1]\n"
|
|
|
|
"obj.scale = (%f,%f,%f)\n",
|
2019-03-08 04:16:42 +00:00
|
|
|
isLeaf ? "leaf" : "branch", xf[0].simd[0], xf[0].simd[1], xf[0].simd[2], xf[0].simd[3], xf[1].simd[0],
|
|
|
|
xf[1].simd[1], xf[1].simd[2], xf[1].simd[3], xf[2].simd[0], xf[2].simd[1], xf[2].simd[2], xf[2].simd[3],
|
|
|
|
halfExtent.simd[0], halfExtent.simd[1], halfExtent.simd[2]);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (isLeaf)
|
|
|
|
os << "obj.show_name = True\n";
|
|
|
|
if (!isLeaf) {
|
|
|
|
left->sendToBlender(os);
|
|
|
|
right->sendToBlender(os);
|
|
|
|
}
|
2017-12-29 08:08:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void DCLN::sendToBlender(hecl::blender::Connection& conn, std::string_view entryName) {
|
|
|
|
/* Open Py Stream and read sections */
|
|
|
|
hecl::blender::PyOutStream os = conn.beginPythonOut(true);
|
2021-06-07 19:29:18 +00:00
|
|
|
os.format(FMT_STRING("import bpy\n"
|
|
|
|
"import bmesh\n"
|
|
|
|
"from mathutils import Vector, Matrix\n"
|
|
|
|
"\n"
|
|
|
|
"bpy.context.scene.name = '{}'\n"
|
|
|
|
"# Clear Scene\n"
|
|
|
|
"if len(bpy.data.collections):\n"
|
|
|
|
" bpy.data.collections.remove(bpy.data.collections[0])\n"),
|
|
|
|
entryName);
|
2017-12-29 08:08:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
DeafBabe::BlenderInit(os);
|
|
|
|
atInt32 idx = 0;
|
|
|
|
for (const Collision& col : collision) {
|
|
|
|
DeafBabeSendToBlender(os, col, true, idx++);
|
2017-12-29 08:08:12 +00:00
|
|
|
#if DCLN_DUMP_OBB
|
2018-12-08 05:30:43 +00:00
|
|
|
col.root.sendToBlender(os);
|
2017-12-29 08:08:12 +00:00
|
|
|
#endif
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
os.centerView();
|
|
|
|
os.close();
|
2017-12-29 08:08:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool DCLN::Extract(const SpecBase& dataSpec, PAKEntryReadStream& rs, const hecl::ProjectPath& outPath,
|
|
|
|
PAKRouter<PAKBridge>& pakRouter, const PAK::Entry& entry, bool force, hecl::blender::Token& btok,
|
2021-06-30 18:20:45 +00:00
|
|
|
std::function<void(const char*)> fileChanged) {
|
2018-12-08 05:30:43 +00:00
|
|
|
DCLN dcln;
|
|
|
|
dcln.read(rs);
|
|
|
|
hecl::blender::Connection& conn = btok.getBlenderConnection();
|
|
|
|
if (!conn.createBlend(outPath, hecl::blender::BlendType::ColMesh))
|
|
|
|
return false;
|
2017-12-29 08:08:12 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
dcln.sendToBlender(conn, pakRouter.getBestEntryName(entry, false));
|
|
|
|
return conn.saveBlend();
|
2017-12-29 08:08:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool DCLN::Cook(const hecl::ProjectPath& outPath, const std::vector<Mesh>& meshes) {
|
|
|
|
DCLN dcln;
|
|
|
|
dcln.colCount = atUint32(meshes.size());
|
|
|
|
for (const Mesh& mesh : meshes) {
|
|
|
|
dcln.collision.emplace_back();
|
|
|
|
Collision& colOut = dcln.collision.back();
|
|
|
|
DeafBabeBuildFromBlender(colOut, mesh);
|
|
|
|
colOut.root = std::move(*OBBTreeBuilder::buildCol<Collision::Node>(mesh));
|
|
|
|
colOut.memSize = atUint32(colOut.root.getMemoryUsage());
|
|
|
|
}
|
2017-12-29 08:08:12 +00:00
|
|
|
|
2018-11-09 00:25:55 +00:00
|
|
|
#if DCLN_DUMP_OBB
|
2018-12-08 05:30:43 +00:00
|
|
|
hecl::blender::Connection& conn = hecl::blender::SharedBlenderToken.getBlenderConnection();
|
2021-06-30 18:20:45 +00:00
|
|
|
conn.createBlend(outPath.getWithExtension(".blend"), hecl::blender::BlendType::ColMesh);
|
2018-12-08 05:30:43 +00:00
|
|
|
dcln.sendToBlender(conn, "BLAH");
|
|
|
|
conn.saveBlend();
|
2018-11-09 00:25:55 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
athena::io::FileWriter w(outPath.getAbsolutePath());
|
|
|
|
dcln.write(w);
|
|
|
|
int64_t rem = w.position() % 32;
|
|
|
|
if (rem)
|
|
|
|
for (int64_t i = 0; i < 32 - rem; ++i)
|
|
|
|
w.writeUByte(0xff);
|
|
|
|
return true;
|
2017-12-29 08:08:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace DataSpec::DNAMP1
|