main.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include <irrlicht.h>
  2. #include <iostream>
  3. using namespace irr;
  4. using namespace core;
  5. using namespace scene;
  6. using namespace video;
  7. using namespace io;
  8. using namespace gui;
  9. #ifdef _MSC_VER
  10. #pragma comment(lib, "Irrlicht.lib")
  11. #endif
  12. void usage(const char* name)
  13. {
  14. std::cerr << "Usage: " << name << " [options] <srcFile> <destFile>" << std::endl;
  15. std::cerr << " where options are" << std::endl;
  16. std::cerr << " --createTangents: convert to tangents mesh is possible." << std::endl;
  17. std::cerr << " --format=[irrmesh|collada|stl|obj|ply]: Choose target format" << std::endl;
  18. }
  19. int main(int argc, char* argv[])
  20. {
  21. if ((argc < 3) ||
  22. ((argc==3) && (argv[1][0]=='-')))
  23. {
  24. usage(argv[0]);
  25. return 1;
  26. }
  27. IrrlichtDevice *device = createDevice( video::EDT_NULL,
  28. dimension2d<u32>(800, 600), 32, false, false, false, 0);
  29. device->setWindowCaption(L"Mesh Converter");
  30. scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH;
  31. u32 i=1;
  32. bool createTangents=false;
  33. while (argv[i][0]=='-')
  34. {
  35. core::stringc format = argv[i];
  36. if (format.size() > 3)
  37. {
  38. if (format.equalsn("--format=",9))
  39. {
  40. format = format.subString(9,format.size());
  41. if (format=="collada")
  42. type = EMWT_COLLADA;
  43. else if (format=="stl")
  44. type = EMWT_STL;
  45. else if (format=="obj")
  46. type = EMWT_OBJ;
  47. else if (format=="ply")
  48. type = EMWT_PLY;
  49. else
  50. type = EMWT_IRR_MESH;
  51. }
  52. else
  53. if (format =="--createTangents")
  54. createTangents=true;
  55. }
  56. else
  57. if (format=="--")
  58. {
  59. ++i;
  60. break;
  61. }
  62. ++i;
  63. }
  64. const s32 srcmesh = i;
  65. const s32 destmesh = i+1;
  66. --argc;
  67. if ((argc<srcmesh) || (argc<destmesh))
  68. {
  69. std::cerr << "Not enough files given." << std::endl;
  70. usage(argv[0]);
  71. return 1;
  72. }
  73. createTangents = createTangents && (type==EMWT_IRR_MESH);
  74. std::cout << "Converting " << argv[srcmesh] << " to " << argv[destmesh] << std::endl;
  75. IMesh* mesh = device->getSceneManager()->getMesh(argv[srcmesh])->getMesh(0);
  76. if (!mesh)
  77. {
  78. std::cerr << "Could not load " << argv[srcmesh] << std::endl;
  79. return 1;
  80. }
  81. if (createTangents)
  82. {
  83. IMesh* tmp = device->getSceneManager()->getMeshManipulator()->createMeshWithTangents(mesh);
  84. mesh->drop();
  85. mesh=tmp;
  86. }
  87. IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type);
  88. IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]);
  89. mw->writeMesh(file, mesh);
  90. file->drop();
  91. mw->drop();
  92. device->drop();
  93. return 0;
  94. }