1 | /*
|
---|
2 | ============================================================================
|
---|
3 | This source file is part of the Ogre-Maya Tools.
|
---|
4 | Distributed as part of Ogre (Object-oriented Graphics Rendering Engine).
|
---|
5 | Copyright (C) 2003 Fifty1 Software Inc., Bytelords
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or
|
---|
8 | modify it under the terms of the GNU General Public License
|
---|
9 | as published by the Free Software Foundation; either version 2
|
---|
10 | of the License, or (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
20 | or go to http://www.gnu.org/licenses/gpl.txt
|
---|
21 | ============================================================================
|
---|
22 | */
|
---|
23 | #include "OgreMayaOptions.h"
|
---|
24 |
|
---|
25 | #include "OgreMayaScene.h"
|
---|
26 | #include "OgreMayaMesh.h"
|
---|
27 | #include "OgreMayaSkeleton.h"
|
---|
28 | #include "OgreMayaMaterial.h"
|
---|
29 |
|
---|
30 | #include <maya/MDagPath.h>
|
---|
31 | #include <maya/MGlobal.h>
|
---|
32 | #include <maya/MPlug.h>
|
---|
33 | #include <maya/MFnSet.h>
|
---|
34 | #include <maya/MItDependencyGraph.h>
|
---|
35 | #include <maya/MItDag.h>
|
---|
36 |
|
---|
37 | #include <iostream>
|
---|
38 |
|
---|
39 | void showHelp();
|
---|
40 |
|
---|
41 | using namespace OgreMaya;
|
---|
42 | using namespace std;
|
---|
43 |
|
---|
44 | // ------------------------------------------------------------
|
---|
45 |
|
---|
46 | class CommandLineParser {
|
---|
47 | public:
|
---|
48 | CommandLineParser() {
|
---|
49 | argv = 0;
|
---|
50 | argc = 0;
|
---|
51 | currentArg = 0;
|
---|
52 |
|
---|
53 |
|
---|
54 | // init parameter map (for command line args)
|
---|
55 | builderMap["-in" ] = &CommandLineParser::parseIn;
|
---|
56 | builderMap["-mesh" ] = &CommandLineParser::parseMeshOut;
|
---|
57 | builderMap["-vba" ] = &CommandLineParser::parseVBA;
|
---|
58 | builderMap["-skel" ] = &CommandLineParser::parseSkelOut;
|
---|
59 | builderMap["-mat" ] = &CommandLineParser::parseMatOut;
|
---|
60 | builderMap["-mprefix"] = &CommandLineParser::parseMatPrefix;
|
---|
61 | builderMap["-anim" ] = &CommandLineParser::parseAnimation;
|
---|
62 | builderMap["-n" ] = &CommandLineParser::parseN;
|
---|
63 | builderMap["-c" ] = &CommandLineParser::parseC;
|
---|
64 | builderMap["-t" ] = &CommandLineParser::parseT;
|
---|
65 | builderMap["-v" ] = &CommandLineParser::parseV;
|
---|
66 | }
|
---|
67 |
|
---|
68 | void parse(int argc, char** argv) {
|
---|
69 | this->argv = argv;
|
---|
70 | this->argc = argc;
|
---|
71 | for(currentArg=1; currentArg<argc; currentArg++) {
|
---|
72 | string arg = argv[currentArg];
|
---|
73 | void (CommandLineParser::*p)(void) = builderMap[arg];
|
---|
74 |
|
---|
75 | if(p) {
|
---|
76 | (this->*p)();
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | bool isNextTokenOption() {
|
---|
82 | bool res = false;
|
---|
83 | if(currentArg+1 < argc) {
|
---|
84 | res = argv[currentArg+1][0] == '-';
|
---|
85 | }
|
---|
86 |
|
---|
87 | return res;
|
---|
88 | }
|
---|
89 |
|
---|
90 | void parseIn() {
|
---|
91 | if(++currentArg < argc) {
|
---|
92 | OPTIONS.inFile = argv[currentArg];
|
---|
93 | int i = OPTIONS.inFile.find_first_of('.');
|
---|
94 |
|
---|
95 | if(i>=0) {
|
---|
96 | OPTIONS.outMeshFile = OPTIONS.inFile.substr(0, i) + ".mesh.xml";
|
---|
97 | OPTIONS.outSkelFile = OPTIONS.inFile.substr(0, i) + ".skeleton.xml";
|
---|
98 | OPTIONS.outMatFile = OPTIONS.inFile.substr(0, i) + ".material";
|
---|
99 | }
|
---|
100 | else {
|
---|
101 | OPTIONS.outMeshFile = OPTIONS.inFile + ".mesh.xml";
|
---|
102 | OPTIONS.outSkelFile = OPTIONS.inFile + ".skeleton.xml";
|
---|
103 | OPTIONS.outMatFile = OPTIONS.inFile + ".material";
|
---|
104 | }
|
---|
105 |
|
---|
106 | OPTIONS.valid = true;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | void parseMeshOut() {
|
---|
111 | OPTIONS.exportMesh = true;
|
---|
112 | if(!isNextTokenOption() && currentArg+1<argc) {
|
---|
113 | OPTIONS.outMeshFile = argv[currentArg+1];
|
---|
114 | currentArg++;
|
---|
115 | }
|
---|
116 | }
|
---|
117 |
|
---|
118 | void parseSkelOut() {
|
---|
119 | OPTIONS.exportSkeleton = true;
|
---|
120 | if(!isNextTokenOption() && currentArg+1<argc) {
|
---|
121 | OPTIONS.outSkelFile = argv[currentArg+1];
|
---|
122 | currentArg++;
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | void parseMatOut() {
|
---|
127 | OPTIONS.exportMaterial = true;
|
---|
128 | if(!isNextTokenOption() && currentArg+1<argc) {
|
---|
129 | OPTIONS.outMatFile = argv[currentArg+1];
|
---|
130 | currentArg++;
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | void parseMatPrefix() {
|
---|
135 | if(++currentArg < argc) {
|
---|
136 | OPTIONS.matPrefix = argv[currentArg];
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | void parseAnimation() {
|
---|
141 | if(currentArg+4 < argc) {
|
---|
142 | string name = argv[currentArg+1];
|
---|
143 | int from = atoi(argv[currentArg+2]);
|
---|
144 | int to = atoi(argv[currentArg+3]);
|
---|
145 | int step = atoi(argv[currentArg+4]);
|
---|
146 |
|
---|
147 | OPTIONS.animations[name].from = from;
|
---|
148 | OPTIONS.animations[name].to = to;
|
---|
149 | OPTIONS.animations[name].step = step;
|
---|
150 |
|
---|
151 | currentArg += 5;
|
---|
152 | }
|
---|
153 | }
|
---|
154 |
|
---|
155 | void parseVBA() {
|
---|
156 | OPTIONS.exportVBA = true;
|
---|
157 | }
|
---|
158 |
|
---|
159 | void parseN() {
|
---|
160 | OPTIONS.exportNormals = true;
|
---|
161 | }
|
---|
162 |
|
---|
163 | void parseC() {
|
---|
164 | OPTIONS.exportColours = true;
|
---|
165 | }
|
---|
166 |
|
---|
167 | void parseT() {
|
---|
168 | OPTIONS.exportUVs = true;
|
---|
169 | }
|
---|
170 |
|
---|
171 | void parseV() {
|
---|
172 | OPTIONS.verboseMode = true;
|
---|
173 | }
|
---|
174 |
|
---|
175 | private:
|
---|
176 | typedef map<string, void (CommandLineParser::*)(void)> BuilderMap;
|
---|
177 |
|
---|
178 | char** argv;
|
---|
179 | int argc;
|
---|
180 | int currentArg;
|
---|
181 |
|
---|
182 | BuilderMap builderMap;
|
---|
183 | };
|
---|
184 |
|
---|
185 | // ------------------------------------------------------------
|
---|
186 |
|
---|
187 | int main(int argc, char *argv[]) {
|
---|
188 |
|
---|
189 | // ===== Parse command line options
|
---|
190 | CommandLineParser argParser;
|
---|
191 | argParser.parse(argc, argv);
|
---|
192 |
|
---|
193 | if(!OPTIONS.valid) {
|
---|
194 | showHelp();
|
---|
195 | return -1;
|
---|
196 | }
|
---|
197 |
|
---|
198 | OPTIONS.debugOutput();
|
---|
199 |
|
---|
200 | {
|
---|
201 | SceneMgr sceneMgr;
|
---|
202 | MeshGenerator meshGen;
|
---|
203 | SkeletonGenerator skelGen;
|
---|
204 | MatGenerator matGen;
|
---|
205 |
|
---|
206 | bool bStatus;
|
---|
207 |
|
---|
208 | // ===== Initialize Maya and load scene
|
---|
209 | bStatus = sceneMgr.load();
|
---|
210 | if (!bStatus) {
|
---|
211 | cout << "\tFAILED\n";
|
---|
212 | return -2;
|
---|
213 | }
|
---|
214 |
|
---|
215 |
|
---|
216 | if(OPTIONS.verboseMode) {
|
---|
217 | // ===== Iterate over mesh components of DAG
|
---|
218 | cout << "\n=== DAG Nodes ==============================\n";
|
---|
219 | MItDag dagIter( MItDag::kBreadthFirst, MFn::kInvalid, 0 );
|
---|
220 | for ( ; !dagIter.isDone(); dagIter.next()) {
|
---|
221 | MDagPath dagPath;
|
---|
222 | dagIter.getPath( dagPath );
|
---|
223 |
|
---|
224 | cout << "Node: "
|
---|
225 | << dagPath.fullPathName().asChar()
|
---|
226 | << "\n";
|
---|
227 | }
|
---|
228 | cout << "============================================\n";
|
---|
229 | }
|
---|
230 |
|
---|
231 |
|
---|
232 |
|
---|
233 | // ===== Export
|
---|
234 | // --- Skeleton
|
---|
235 | if (OPTIONS.exportSkeleton) {
|
---|
236 | bStatus = skelGen.exportAll();
|
---|
237 | if (!bStatus) {
|
---|
238 | cout << "\tFAILED\n";
|
---|
239 | return -3;
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 |
|
---|
244 | // --- Mesh
|
---|
245 | if (OPTIONS.exportMesh) {
|
---|
246 | bStatus = meshGen.exportAll();
|
---|
247 | if (!bStatus) {
|
---|
248 | cout << "\tFAILED\n";
|
---|
249 | return -4;
|
---|
250 | }
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | // --- Material
|
---|
255 |
|
---|
256 | if(OPTIONS.exportMaterial) {
|
---|
257 | bStatus = matGen.exportAll();
|
---|
258 | if (!bStatus) {
|
---|
259 | cout << "\tFAILED\n";
|
---|
260 | return -5;
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | }
|
---|
265 |
|
---|
266 |
|
---|
267 | return 1;
|
---|
268 | }
|
---|
269 |
|
---|
270 | // ------------------------------------------------------------
|
---|
271 |
|
---|
272 | void showHelp() {
|
---|
273 | cout << "Version : "<<__DATE__<<" "<<__TIME__<<"\n";
|
---|
274 | cout << "Maya API: "<<MAYA_API_VERSION<<"\n\n";
|
---|
275 | cout << "Usage: maya2ogre -in FILE [-mesh [FILE]] [-vba] [-skel [FILE]]\n";
|
---|
276 | cout << " [-anim NAME START END STEP]\n";
|
---|
277 | cout << " [-mat [FILE]] [-mprefix PREFIX]\n";
|
---|
278 | cout << " [-n] [-c] [-t] [-v]\n\n";
|
---|
279 | cout << " -in FILE input mb File\n";
|
---|
280 | cout << " -mesh FILE export mesh (FILE is optional)\n";
|
---|
281 | cout << " -vba export vertex bone assignments\n";
|
---|
282 | cout << " -skel FILE export skeleton (FILE is optional)\n";
|
---|
283 | cout << " -anim NAME export Animation beginning at START and ending\n";
|
---|
284 | cout << " START at END with fixed STEP\n";
|
---|
285 | cout << " END\n";
|
---|
286 | cout << " STEP\n";
|
---|
287 | cout << " -mat FILE export material (FILE is optional)\n";
|
---|
288 | cout << " -mprefix PREFIX material prefix\n";
|
---|
289 | cout << " -n export normals\n";
|
---|
290 | cout << " -c export diffuse colours\n";
|
---|
291 | cout << " -t export texture coords\n";
|
---|
292 | cout << " -v more output\n\n";
|
---|
293 | cout << "Examples:\n";
|
---|
294 | cout << " maya2ogre -in foo.mb -mesh -skel -mat\n";
|
---|
295 | cout << " => exports skeleton, mesh and material using default file names,\n";
|
---|
296 | cout << " in this case foo.mesh.xml, foo.skeleton.xml and foo.material\n\n";
|
---|
297 | cout << " maya2ogre -in foo.mb -mesh custom_name.mesh.xml -skel custom_name.skel.xml\n";
|
---|
298 | cout << " => exports skeleton and mesh using user defined file names\n\n";
|
---|
299 | cout << " maya2ogre -in foo.mb -skel -anim Walk 1 30 2 -anim Die 50 60 2\n";
|
---|
300 | cout << " => exports skeleton with animation tracks Walk and Die\n";
|
---|
301 | } |
---|