ff7DataInstaller.cpp 3.9 KB

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