ff7DataInstaller.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "ff7DataInstaller.h"
  2. #include <boost/filesystem.hpp>
  3. #include <boost/program_options.hpp>
  4. #include <OgreConfigFile.h>
  5. #include <OgreArchiveManager.h>
  6. #include <OgreMeshSerializer.h>
  7. #include <OgreSkeletonSerializer.h>
  8. #include <OgreMeshManager.h>
  9. #include <OgreRenderWindow.h>
  10. #include <OgreHardwarePixelBuffer.h>
  11. #include "QGearsGameState.h"
  12. #include "data/QGearsAFileManager.h"
  13. #include "data/QGearsBackgroundFileManager.h"
  14. #include "data/QGearsCameraMatrixFileManager.h"
  15. #include "data/QGearsHRCFileManager.h"
  16. #include "data/QGearsLZSFLevelFileManager.h"
  17. #include "data/QGearsPaletteFileManager.h"
  18. #include "data/QGearsPFileManager.h"
  19. #include "data/QGearsRSDFileManager.h"
  20. #include "data/QGearsTexCodec.h"
  21. #include "map/QGearsBackground2DFileManager.h"
  22. #include "map/QGearsWalkmeshFileManager.h"
  23. #include "data/FF7ModelListFileManager.h"
  24. #include "data/QGearsLGPArchiveFactory.h"
  25. #include "common/QGearsStringUtil.h"
  26. #include "common/FF7NameLookup.h"
  27. #include "data/QGearsTexCodec.h"
  28. FF7DataInstaller::FF7DataInstaller()
  29. #ifdef _DEBUG
  30. : mApp("plugins_d.cfg", "resources_d.cfg", "install_d.log")
  31. #else
  32. : mApp("plugins.cfg", "resources.cfg", "install.log")
  33. #endif
  34. {
  35. mApp.initOgre(true);
  36. }
  37. FF7DataInstaller::~FF7DataInstaller()
  38. {
  39. }
  40. void FF7DataInstaller::Convert(std::string inputDir, std::string outputDir, const std::vector<std::string>& files)
  41. {
  42. for (const auto& file : files)
  43. {
  44. // TODO: Comparison will be incorrect on some platforms
  45. if (file == "field\\char.lgp")
  46. {
  47. auto fullPath = inputDir + file;
  48. mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
  49. ConvertFieldModels(fullPath, outputDir);
  50. mApp.getRoot()->removeResourceLocation(fullPath, "FFVII");
  51. }
  52. else if (file == "field\\flevel.lgp")
  53. {
  54. auto fullPath = inputDir + file;
  55. mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
  56. ConvertFields(fullPath, outputDir);
  57. mApp.getRoot()->removeResourceLocation(fullPath, "FFVII");
  58. }
  59. }
  60. }
  61. // TOOD: Share with pc model exporter
  62. static void exportMesh(std::string outdir, const Ogre::MeshPtr &mesh)
  63. {
  64. Ogre::MeshSerializer mesh_ser;
  65. mesh_ser.exportMesh(mesh.getPointer(), outdir + mesh->getName());
  66. Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
  67. Ogre::SkeletonSerializer sk_ser;
  68. sk_ser.exportSkeleton(skeleton.getPointer(), outdir + skeleton->getName());
  69. Ogre::Mesh::SubMeshIterator it(mesh->getSubMeshIterator());
  70. Ogre::MaterialSerializer mat_ser;
  71. size_t i(0);
  72. while (it.hasMoreElements())
  73. {
  74. Ogre::SubMesh *sub_mesh(it.getNext());
  75. Ogre::MaterialPtr mat(Ogre::MaterialManager::getSingleton().getByName(sub_mesh->getMaterialName()));
  76. if (!mat.isNull())
  77. {
  78. mat_ser.queueForExport(mat);
  79. }
  80. ++i;
  81. }
  82. QGears::String base_name;
  83. QGears::StringUtil::splitFull(mesh->getName(), base_name);
  84. mat_ser.exportQueued(outdir + base_name + QGears::EXT_MATERIAL);
  85. }
  86. void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDir)
  87. {
  88. Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVII", "*.hrc");
  89. for (auto& resourceName : *resources)
  90. {
  91. if (QGears::StringUtil::endsWith(resourceName, ".hrc"))
  92. {
  93. //try
  94. {
  95. Ogre::ResourcePtr hrc = QGears::HRCFileManager::getSingleton().load(resourceName, "FFVII");
  96. Ogre::String baseName;
  97. QGears::StringUtil::splitBase(resourceName, baseName);
  98. auto meshName = QGears::FF7::NameLookup::model(baseName) + ".mesh";
  99. Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(meshName, "FFVII"));
  100. Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
  101. exportMesh(outDir, mesh);
  102. }
  103. // catch (const Ogre::Exception& ex)
  104. {
  105. // std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
  106. }
  107. }
  108. }
  109. /*
  110. TODO:
  111. To figure out what .a files relate to which .hrc files, we need to enumerate every field
  112. and check its model loader data. These are always Idle, Walk, Run and then field specific
  113. ordering.
  114. Model loader is section 3 of the field file.
  115. */
  116. }
  117. void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
  118. {
  119. // Everything in here is a field
  120. Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVII", "*.hrc");
  121. for (auto& resourceName : *resources)
  122. {
  123. }
  124. }