Commit d53f71bd authored by hybrid's avatar hybrid

MeshConverter: Added better format support and added tangent calculation.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1543 dfc29bdd-3216-0410-991c-e03cc46cb475
parent a55e2d6b
...@@ -13,12 +13,20 @@ using namespace gui; ...@@ -13,12 +13,20 @@ using namespace gui;
#pragma comment(lib, "Irrlicht.lib") #pragma comment(lib, "Irrlicht.lib")
#endif #endif
void usage(const char* name)
{
std::cerr << "Usage: " << name << " [options] <srcFile> <destFile>" << 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[]) int main(int argc, char* argv[])
{ {
if ((argc < 3) || if ((argc < 3) ||
((argc==3) && (argv[1][0]=='-'))) ((argc==3) && (argv[1][0]=='-')))
{ {
std::cout << "Usage: " << argv[0] << " [--format=irrmesh|collada|stl] <srcFile> <destFile>" << std::endl; usage(argv[0]);
return 1; return 1;
} }
...@@ -27,38 +35,68 @@ int main(int argc, char* argv[]) ...@@ -27,38 +35,68 @@ int main(int argc, char* argv[])
device->setWindowCaption(L"Image Converter"); device->setWindowCaption(L"Image Converter");
IVideoDriver* driver = device->getVideoDriver();
scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH; scene::EMESH_WRITER_TYPE type = EMWT_IRR_MESH;
u32 srcmesh = 1; u32 i=1;
u32 destmesh = 2; bool createTangents=false;
if (argv[1][0]=='-') while (argv[i][0]=='-')
{ {
core::stringc format = argv[1]; core::stringc format = argv[i];
if ((format.size() > 3) && format.equalsn("--format=",9)) if (format.size() > 3)
{ {
++srcmesh; if (format.equalsn("--format=",9))
++destmesh; {
format = format.subString(9,format.size()); format = format.subString(9,format.size());
if (format=="collada") if (format=="collada")
type = EMWT_COLLADA; type = EMWT_COLLADA;
else if (format=="stl")
type = EMWT_STL;
else if (format=="obj")
type = EMWT_OBJ;
else
type = EMWT_IRR_MESH;
}
else else
if (format=="stl") if (format =="--createTangents")
type = EMWT_STL; createTangents=true;
else }
type = EMWT_IRR_MESH; else
if (format=="--")
{
++i;
break;
} }
++i;
} }
const s32 srcmesh = i;
const s32 destmesh = i+1;
--argc;
if ((argc<srcmesh) || (argc<destmesh))
{
std::cerr << "Not enough files given." << std::endl;
usage(argv[0]);
return 1;
}
createTangents = createTangents && (type==EMWT_IRR_MESH);
std::cout << "Converting " << argv[srcmesh] << " to " << argv[destmesh] << std::endl; std::cout << "Converting " << argv[srcmesh] << " to " << argv[destmesh] << std::endl;
IAnimatedMesh* mesh = device->getSceneManager()->getMesh(argv[srcmesh]); IMesh* mesh = device->getSceneManager()->getMesh(argv[srcmesh])->getMesh(0);
if (!mesh) if (!mesh)
{ {
std::cerr << "Could not load " << argv[srcmesh] << std::endl; std::cerr << "Could not load " << argv[srcmesh] << std::endl;
return 1; return 1;
} }
if (createTangents)
{
IMesh* tmp = device->getSceneManager()->getMeshManipulator()->createMeshWithTangents(mesh);
mesh->drop();
mesh=tmp;
}
IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type); IMeshWriter* mw = device->getSceneManager()->createMeshWriter(type);
IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]); IWriteFile* file = device->getFileSystem()->createAndWriteFile(argv[destmesh]);
mw->writeMesh(file, mesh->getMesh(0)); mw->writeMesh(file, mesh);
mesh->drop();
file->drop(); file->drop();
mw->drop(); mw->drop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment