From 01f5b513d4901590718bf5601d6f5cf4e9418dfa Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 20 Jan 2016 23:56:22 -0800 Subject: [PATCH] Preliminary FRME blender export --- DataSpec/DNAMP1/FRME.cpp | 78 ++++++++++++++++++++++++++++++++++++++++ DataSpec/DNAMP1/FRME.hpp | 7 +--- 2 files changed, 79 insertions(+), 6 deletions(-) diff --git a/DataSpec/DNAMP1/FRME.cpp b/DataSpec/DNAMP1/FRME.cpp index cb7cbb1ac..edad4135c 100644 --- a/DataSpec/DNAMP1/FRME.cpp +++ b/DataSpec/DNAMP1/FRME.cpp @@ -262,5 +262,83 @@ size_t FRME::Widget::TXPNInfo::binarySize(size_t __isz) const return __isz + (version == 1 ? 78 : 66); } +bool FRME::Extract(const SpecBase &dataSpec, PAKEntryReadStream &rs, const HECL::ProjectPath &outPath, PAKRouter &pakRouter, const PAK::Entry &entry, bool force, std::function fileChanged) +{ + FRME frme; + frme.read(rs); + + HECL::BlenderConnection& conn = HECL::BlenderConnection::SharedConnection(); + + if (!force && outPath.getPathType() == HECL::ProjectPath::Type::File) + return true; + + if (!conn.createBlend(outPath, HECL::BlenderConnection::BlendType::Frame)) + return false; + + HECL::BlenderConnection::PyOutStream os = conn.beginPythonOut(true); + + os << "import bpy, math\n" + "from mathutils import Matrix, Quaternion\n" + "bpy.types.Object.retro_widget_type = bpy.props.StringProperty(name='Retro: FRME Widget Type')\n" + "bpy.types.Object.retro_widget_parent = bpy.props.StringProperty(name='Retro: FRME Widget Parent', description='Refers to internal frame widgets')\n" + "# Clear Scene\n" + "for ob in bpy.data.objects:\n" + " bpy.context.scene.objects.unlink(ob)\n" + " bpy.data.objects.remove(ob)\n"; + + os.format("bpy.context.scene.name = 'FRME_%s'\n", + entry.id.toString().c_str()); + + for (const FRME::Widget& w : frme.widgets) + { + os << "binding = None\n" + "angle = Quaternion((0.0, 0.0, 0.0), 0)\n"; + if (w.type == SBIG('CAMR')) + { + using CAMRInfo = FRME::Widget::CAMRInfo; + os.format("cam = bpy.data.cameras.new(name='%s')\n" + "binding = cam\n", w.header.name.c_str()); + CAMRInfo* info = dynamic_cast(w.widgetInfo.get()); + if (info) + { + if (info->projectionType == CAMRInfo::ProjectionType::Orthographic) + os << "cam.type = 'ORTHO'\n"; + else if (info->projectionType == CAMRInfo::ProjectionType::Perspective) + os << "cam.type = 'PERSP'\n"; + } + os << "angle = Quaternion((1.0, 0.0, 0.0), math.radians(90.0))\n"; + } + else if (w.type == SBIG('LITE')) + os.format("lite = bpy.data.lamps.new(name='%s', type='POINT')\n" + "binding = lite\n", + w.header.name.c_str()); + + + os.format("obj = bpy.data.objects.new(name='%s', object_data=binding)\n" + "obj.retro_widget_type = '%s'\n" + "parentName = '%s'\n" + "if parentName not in bpy.data.objects:\n" + " obj.retro_widget_parent = parentName\n" + "else:\n" + " obj.parent = bpy.data.objects[parentName]\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" + "obj.rotation_mode = 'QUATERNION'\n" + "obj.location = mtxd[0]\n" + "obj.rotation_quaternion = mtxd[1] * angle\n" + "obj.scale = mtxd[2]\n", + w.header.name.c_str(), w.type.toString().c_str(), w.header.parent.c_str(), + w.basis[0].vec[0], w.basis[0].vec[1], w.basis[0].vec[2],w.origin.vec[0], + w.basis[1].vec[0], w.basis[1].vec[1], w.basis[1].vec[2],w.origin.vec[1], + w.basis[2].vec[0], w.basis[2].vec[1], w.basis[2].vec[2],w.origin.vec[2]); + os << "bpy.context.scene.objects.link(obj)\n"; + } + + os.centerView(); + os.close(); + conn.saveBlend(); + return true; +} + } } diff --git a/DataSpec/DNAMP1/FRME.hpp b/DataSpec/DNAMP1/FRME.hpp index 5c93b8ba4..d07c4b492 100644 --- a/DataSpec/DNAMP1/FRME.hpp +++ b/DataSpec/DNAMP1/FRME.hpp @@ -215,12 +215,7 @@ struct FRME : BigDNA PAKRouter& pakRouter, const PAK::Entry& entry, bool force, - std::function fileChanged) - { - FRME frme; - frme.read(rs); - return true; - } + std::function fileChanged); }; }