From 4cdb93f9806a1c59f2ebed8f20fb58a89221607b Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 12 Aug 2016 09:42:18 -1000 Subject: [PATCH] MREA cooker fixes --- DataSpec/DNACommon/CMDL.cpp | 37 ++++++++++++++++++++++++++++++++++++- DataSpec/DNACommon/MAPA.cpp | 5 +++++ DataSpec/DNAMP1/MREA.cpp | 2 +- Editor/ViewManager.cpp | 4 ++++ Editor/main.cpp | 2 +- hecl | 2 +- 6 files changed, 48 insertions(+), 4 deletions(-) diff --git a/DataSpec/DNACommon/CMDL.cpp b/DataSpec/DNACommon/CMDL.cpp index 6a93bfc1e..77a5f7a54 100644 --- a/DataSpec/DNACommon/CMDL.cpp +++ b/DataSpec/DNACommon/CMDL.cpp @@ -1656,7 +1656,30 @@ bool WriteHMDLMREASecs(std::vector>& secsOut, const hecl::P const std::vector& meshes, zeus::CAABox& fullAABB, std::vector& meshAABBs) { /* Build material set */ + std::vector surfToGlobalMats; { + struct MaterialPool + { + std::vector materials; + size_t addMaterial(const Mesh::Material& mat) + { + size_t ret = 0; + for (const Mesh::Material* testMat : materials) + { + if (mat == *testMat) + return ret; + ++ret; + } + materials.push_back(&mat); + return ret; + } + } matPool; + + size_t surfCount = 0; + for (const Mesh& mesh : meshes) + surfCount += mesh.surfaces.size(); + surfToGlobalMats.reserve(surfCount); + MaterialSet matSet; hecl::Frontend::Frontend FE; size_t endOff = 0; @@ -1665,8 +1688,16 @@ bool WriteHMDLMREASecs(std::vector>& secsOut, const hecl::P { if (mesh.materialSets.size()) { + std::vector meshToGlobalMats; + meshToGlobalMats.reserve(mesh.materialSets[0].size()); + for (const Mesh::Material& mat : mesh.materialSets[0]) { + size_t idx = matPool.addMaterial(mat); + meshToGlobalMats.push_back(idx); + if (idx < matPool.materials.size() - 1) + continue; + for (const hecl::ProjectPath& path : mat.texs) { bool found = false; @@ -1687,6 +1718,9 @@ bool WriteHMDLMREASecs(std::vector>& secsOut, const hecl::P endOff = matSet.materials.back().binarySize(endOff); matSet.head.addMaterialEndOff(endOff); } + + for (const Mesh::Surface& surf : mesh.surfaces) + surfToGlobalMats.push_back(meshToGlobalMats[surf.materialIdx]); } } for (const hecl::ProjectPath& path : texPaths) @@ -1698,6 +1732,7 @@ bool WriteHMDLMREASecs(std::vector>& secsOut, const hecl::P } /* Iterate meshes */ + auto matIt = surfToGlobalMats.cbegin(); for (const Mesh& mesh : meshes) { zeus::CTransform meshXf(mesh.sceneXf.val); @@ -1769,7 +1804,7 @@ bool WriteHMDLMREASecs(std::vector>& secsOut, const hecl::P SurfaceHeader header; header.centroid = meshXf * zeus::CVector3f(osurf.centroid); - header.matIdx = osurf.materialIdx; + header.matIdx = *matIt++; header.reflectionNormal = (meshXf.basis * zeus::CVector3f(osurf.reflectionNormal)).normalized(); header.idxStart = surf.m_start; header.idxCount = surf.m_count; diff --git a/DataSpec/DNACommon/MAPA.cpp b/DataSpec/DNACommon/MAPA.cpp index 472b53854..5a7c4241f 100644 --- a/DataSpec/DNACommon/MAPA.cpp +++ b/DataSpec/DNACommon/MAPA.cpp @@ -114,6 +114,11 @@ bool ReadMAPAToBlender(hecl::BlenderConnection& conn, "bpy.types.Object.retro_mappable_unk = bpy.props.IntProperty(name='Retro: MAPA object unk')\n" "bpy.types.Object.retro_mappable_sclyid = bpy.props.StringProperty(name='Retro: MAPA object SCLY ID')\n" "\n" + "for ar in bpy.context.screen.areas:\n" + " for sp in ar.spaces:\n" + " if sp.type == 'VIEW_3D':\n" + " sp.viewport_shade = 'SOLID'\n" + "\n" "# Clear Scene\n" "for ob in bpy.data.objects:\n" " if ob.type != 'CAMERA':\n" diff --git a/DataSpec/DNAMP1/MREA.cpp b/DataSpec/DNAMP1/MREA.cpp index 5ee62e30a..6a320d389 100644 --- a/DataSpec/DNAMP1/MREA.cpp +++ b/DataSpec/DNAMP1/MREA.cpp @@ -344,7 +344,7 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath, FILE* yamlFile = hecl::Fopen(layer.getAbsolutePath().c_str(), _S("r")); if (!yamlFile) continue; - if (!BigYAML::ValidateFromYAMLFile(yamlFile)) + if (!BigYAML::ValidateFromYAMLFile(yamlFile)) { fclose(yamlFile); continue; diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index 76de16e27..446a63fb8 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -27,6 +27,10 @@ URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter) void ViewManager::BuildTestPART(urde::IObjectStore& objStore) { + SObjectTag areaTag = m_projManager.resourceFactoryMP1().ProjectResourceFactoryBase::TagFromPath( + _S("MP1/Metroid1/!1IntroLevel1027/01 Air Lock/!area.blend")); + auto areaData = m_projManager.resourceFactoryMP1().LoadResourceSync(areaTag); + //m_modelTest = objStore.GetObj("gun_cmdl"); m_modelTest = objStore.GetObj("MP1/Shared/CMDL_B2B41738.blend"); //m_modelTest = objStore.GetObj("CMDL_GameCube"); diff --git a/Editor/main.cpp b/Editor/main.cpp index e536a4f34..85a1b32d8 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -60,7 +60,7 @@ struct Application : boo::IApplicationCallback void initialize(boo::IApplication* /*app*/) { zeus::detectCPU(); - //hecl::VerbosityLevel = 1; + hecl::VerbosityLevel = 1; const zeus::CPUInfo& cpuInf = zeus::cpuFeatures(); Log.report(logvisor::Info, "CPU Name: %s", cpuInf.cpuBrand); diff --git a/hecl b/hecl index 700b166ef..52b3ba658 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit 700b166efaf9d548f1fc9e92f65894a398efee42 +Subproject commit 52b3ba6582d7b5e19be8ad01eb47c95c3c8e9039