#include #include "CMDL.hpp" #include "DNAMP1.hpp" #include "CMDLMaterials.hpp" namespace Retro { namespace DNAMP1 { bool CMDL::ReadToBlender(HECL::BlenderConnection& conn, Athena::io::IStreamReader& reader, PAKRouter& pakRouter) { return true; reader.setEndian(Athena::BigEndian); CMDL::Header head; head.read(reader); if (head.magic != 0xDEADBABE) { Log.report(LogVisor::Error, "invalid CMDL magic"); return false; } if (head.version != 2) { Log.report(LogVisor::Error, "invalid CMDL version for MP1"); return false; } /* Open Py Stream */ HECL::BlenderConnection::PyOutStream os = conn.beginPythonOut(); os << "import bmesh\n" "import bpy\n" "bm = bmesh.new()\n"; MaterialSet::RegisterMaterialProps(os); for (size_t s=0 ; s vertPos; std::unique_ptr vertNorm; typedef atInt16 ShortVec3[3]; std::unique_ptr vertNormShort; std::unique_ptr vertUVs; typedef atInt16 ShortVec2[2]; std::unique_ptr vertUVsShort; */ std::vector> matUVCounts; matUVCounts.reserve(head.matSetCount); bool visitedDLOffsets = false; if (s < head.matSetCount) { MaterialSet matSet; matSet.read(reader); /* Texmaps */ os << "texmap_list = []\n"; for (const UniqueID32& tex : matSet.head.textureIDs) { os.format("if '%s' in bpy.data.textures:\n" " image = bpy.data.images['%s']\n" " texture = bpy.data.textures[image.name]\n" "else:\n" " image_path = os.path.relpath('../../%s/textures/%s.png')\n" " print(os.getcwd()+image_path)\n" " image = bpy.data.images.load('//' + image_path)\n" " image.name = '%s'\n" " texture = bpy.data.textures.new(image.name, 'IMAGE')\n" " texture.image = image\n" "texmap_list.append(texture)\n" "\n"); } matUVCounts.emplace_back(); std::vector& uvCounts = matUVCounts.back(); uvCounts.reserve(matSet.head.materialCount); unsigned m=0; for (const MaterialSet::Material& mat : matSet.materials) { uvCounts.emplace_back(); unsigned& uvCount = uvCounts.back(); MaterialSet::ConstructMaterial(os, mat, s, m++, uvCount); } } else { switch (s-head.matSetCount) { case 0: { /* Positions */ size_t vertCount = head.secSizes[s] / 12; //vertPos.reset(new atVec3f[vertCount]); for (size_t i=0 ; i