diff --git a/tools/MeshConverter/main.cpp b/tools/MeshConverter/main.cpp index 4ce81e7d..107cc8ef 100644 --- a/tools/MeshConverter/main.cpp +++ b/tools/MeshConverter/main.cpp @@ -13,12 +13,20 @@ using namespace gui; #pragma comment(lib, "Irrlicht.lib") #endif +void usage(const char* name) +{ + std::cerr << "Usage: " << name << " [options] " << std::endl; + std::cerr << " where options are" << std::endl; + std::cerr << " --createTangents: convert to tangents mesh is possible." << std::endl; + std::cerr << " --format=[irrmesh|collada|stl|obj]: Choose target format" << std::endl; +} + int main(int argc, char* argv[]) { if ((argc < 3) || ((argc==3) && (argv[1][0]=='-'))) { - std::cout << "Usage: " << argv[0] << " [--format=irrmesh|collada|stl] " << std::endl; + usage(argv[0]); return 1; } @@ -27,38 +35,68 @@ int main(int argc, char* argv[]) device->setWindowCaption(L"Image Converter"); - IVideoDriver* driver = device->getVideoDriver(); - scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH; - u32 srcmesh = 1; - u32 destmesh = 2; - if (argv[1][0]=='-') + u32 i=1; + bool createTangents=false; + while (argv[i][0]=='-') { - core::stringc format = argv[1]; - if ((format.size() > 3) && format.equalsn("--format=",9)) + core::stringc format = argv[i]; + if (format.size() > 3) { - ++srcmesh; - ++destmesh; - format = format.subString(9,format.size()); - if (format=="collada") - type = EMWT_COLLADA; + if (format.equalsn("--format=",9)) + { + format = format.subString(9,format.size()); + if (format=="collada") + type = EMWT_COLLADA; + else if (format=="stl") + type = EMWT_STL; + else if (format=="obj") + type = EMWT_OBJ; + else + type = EMWT_IRR_MESH; + } else - if (format=="stl") - type = EMWT_STL; - else - type = EMWT_IRR_MESH; + if (format =="--createTangents") + createTangents=true; } + else + if (format=="--") + { + ++i; + break; + } + ++i; } + + const s32 srcmesh = i; + const s32 destmesh = i+1; + + --argc; + if ((argcgetSceneManager()->getMesh(argv[srcmesh]); + IMesh* mesh = device->getSceneManager()->getMesh(argv[srcmesh])->getMesh(0); if (!mesh) { std::cerr << "Could not load " << argv[srcmesh] << std::endl; return 1; } + if (createTangents) + { + IMesh* tmp = device->getSceneManager()->getMeshManipulator()->createMeshWithTangents(mesh); + mesh->drop(); + mesh=tmp; + } IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type); IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]); - mw->writeMesh(file, mesh->getMesh(0)); + mw->writeMesh(file, mesh); + mesh->drop(); file->drop(); mw->drop();