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