ff7DataInstaller.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. }
  51. else if (file == "field\\flevel.lgp")
  52. {
  53. auto fullPath = inputDir + file;
  54. mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
  55. ConvertFields(fullPath, outputDir);
  56. }
  57. }
  58. }
  59. // TOOD: Share with pc model exporter
  60. static void exportMesh(std::string outdir, const Ogre::MeshPtr &mesh)
  61. {
  62. Ogre::MeshSerializer mesh_ser;
  63. mesh_ser.exportMesh(mesh.getPointer(), outdir + mesh->getName());
  64. Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
  65. Ogre::SkeletonSerializer sk_ser;
  66. sk_ser.exportSkeleton(skeleton.getPointer(), outdir + skeleton->getName());
  67. Ogre::Mesh::SubMeshIterator it(mesh->getSubMeshIterator());
  68. Ogre::MaterialSerializer mat_ser;
  69. size_t i(0);
  70. while (it.hasMoreElements())
  71. {
  72. Ogre::SubMesh *sub_mesh(it.getNext());
  73. Ogre::MaterialPtr mat(Ogre::MaterialManager::getSingleton().getByName(sub_mesh->getMaterialName()));
  74. if (!mat.isNull())
  75. {
  76. mat_ser.queueForExport(mat);
  77. }
  78. ++i;
  79. }
  80. QGears::String base_name;
  81. QGears::StringUtil::splitFull(mesh->getName(), base_name);
  82. mat_ser.exportQueued(outdir + base_name + QGears::EXT_MATERIAL);
  83. }
  84. void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDir)
  85. {
  86. Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVII", "*.hrc");
  87. for (auto& resourceName : *resources)
  88. {
  89. if (QGears::StringUtil::endsWith(resourceName, ".hrc"))
  90. {
  91. //try
  92. {
  93. Ogre::ResourcePtr hrc = QGears::HRCFileManager::getSingleton().load(resourceName, "FFVII");
  94. Ogre::String baseName;
  95. QGears::StringUtil::splitBase(resourceName, baseName);
  96. auto meshName = QGears::FF7::NameLookup::model(baseName) + ".mesh";
  97. Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(meshName, "FFVII"));
  98. Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
  99. exportMesh(outDir, mesh);
  100. }
  101. // catch (const Ogre::Exception& ex)
  102. {
  103. // std::cout << "ERROR converting: " << resourceName << " Exception: " << ex.what() << std::endl;
  104. }
  105. }
  106. }
  107. /*
  108. TODO:
  109. To figure out what .a files relate to which .hrc files, we need to enumerate every field
  110. and check its model loader data. These are always Idle, Walk, Run and then field specific
  111. ordering.
  112. Model loader is section 3 of the field file.
  113. */
  114. }
  115. void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
  116. {
  117. }