source: OGRE/trunk/ogrenew/Tools/MayaExport/src/paramlist.cpp @ 692

Revision 692, 10.0 KB checked in by mattausch, 18 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1
2#include "paramlist.h"
3#include <maya/MGlobal.h>
4
5/***** Class ParamList *****/
6// method to parse arguments from command line
7namespace OgreMayaExporter
8{
9        void ParamList::parseArgs(const MArgList &args)
10        {
11                MStatus stat;
12                // Parse arguments from command line
13                for (unsigned int i = 0; i < args.length(); i++ )
14                {
15                        if ((MString("-all") == args.asString(i,&stat)) && (MS::kSuccess == stat))
16                                exportAll = true;
17                        else if ((MString("-world") == args.asString(i,&stat)) && (MS::kSuccess == stat))
18                                exportWorldCoords = true;
19                        else if ((MString("-mesh") == args.asString(i,&stat)) && (MS::kSuccess == stat))
20                        {
21                                exportMesh = true;
22                                meshFilename = args.asString(++i,&stat);
23                        }
24                        else if ((MString("-mat") == args.asString(i,&stat)) && (MS::kSuccess == stat))
25                        {
26                                exportMaterial = true;
27                                materialFilename = args.asString(++i,&stat);
28                        }
29                        else if ((MString("-matPrefix") == args.asString(i,&stat)) && (MS::kSuccess == stat))
30                        {
31                                matPrefix = args.asString(++i,&stat);
32                        }
33                        else if ((MString("-copyTex") == args.asString(i,&stat)) && (MS::kSuccess == stat))
34                        {
35                                copyTextures = true;
36                                texOutputDir = args.asString(++i,&stat);
37                        }
38                        else if ((MString("-lightOff") == args.asString(i,&stat)) && (MS::kSuccess == stat))
39                        {
40                                lightingOff = true;
41                        }
42                        else if ((MString("-skel") == args.asString(i,&stat)) && (MS::kSuccess == stat))
43                        {
44                                exportSkeleton = true;
45                                skeletonFilename = args.asString(++i,&stat);
46                        }
47                        else if ((MString("-anims") == args.asString(i,&stat)) && (MS::kSuccess == stat))
48                        {
49                                exportAnims = true;
50                        }
51                        else if ((MString("-animCur") == args.asString(i,&stat)) && (MS::kSuccess == stat))
52                        {
53                                exportAnimCurves = true;
54                                animFilename = args.asString(++i,&stat);
55                        }
56                        else if ((MString("-cam") == args.asString(i,&stat)) && (MS::kSuccess == stat))
57                        {
58                                exportCameras = true;
59                                camerasFilename = args.asString(++i,&stat);
60                        }
61                        else if ((MString("-v") == args.asString(i,&stat)) && (MS::kSuccess == stat))
62                        {
63                                exportVBA = true;
64                        }
65                        else if ((MString("-n") == args.asString(i,&stat)) && (MS::kSuccess == stat))
66                        {
67                                exportVertNorm = true;
68                        }
69                        else if ((MString("-c") == args.asString(i,&stat)) && (MS::kSuccess == stat))
70                        {
71                                exportVertCol = true;
72                        }
73                        else if ((MString("-cw") == args.asString(i,&stat)) && (MS::kSuccess == stat))
74                        {
75                                exportVertCol = true;
76                                exportVertColWhite = true;
77                        }
78                        else if ((MString("-t") == args.asString(i,&stat)) && (MS::kSuccess == stat))
79                        {
80                                exportTexCoord = true;
81                        }
82                        else if ((MString("-camAnim") == args.asString(i,&stat)) && (MS::kSuccess == stat))
83                        {
84                                exportCamerasAnim = true;
85                        }
86                        else if ((MString("-meshbin") == args.asString(i,&stat)) && (MS::kSuccess == stat))
87                        {
88                                exportMeshBin = true;
89                        }
90                        else if ((MString("-skelbin") == args.asString(i,&stat)) && (MS::kSuccess == stat))
91                        {
92                                exportSkelBin = true;
93                        }
94                        else if ((MString("-particles") == args.asString(i,&stat)) && (MS::kSuccess == stat))
95                        {
96                                exportParticles = true;
97                                particlesFilename = args.asString(++i,&stat);
98                        }
99                        else if ((MString("-shared") == args.asString(i,&stat)) && (MS::kSuccess == stat))
100                        {
101                                useSharedGeom = true;
102                        }
103                        else if ((MString("-np") == args.asString(i,&stat)) && (MS::kSuccess == stat))
104                        {
105                                MString npType = args.asString(i,&stat);
106                                if (npType == "curFrame")
107                                        neutralPoseType = NPT_CURFRAME;
108                                else if (npType == "bindPose")
109                                        neutralPoseType = NPT_BINDPOSE;
110                                else if (npType == "frame")
111                                {
112                                        neutralPoseType = NPT_FRAME;
113                                        neutralPoseFrame = args.asInt(++i,&stat);
114                                }
115                        }
116                        else if ((MString("-clip") == args.asString(i,&stat)) && (MS::kSuccess == stat))
117                        {
118                                //get clip name
119                                MString clipName = args.asString(++i,&stat);
120                                //get clip range
121                                MString clipRangeType = args.asString(++i,&stat);
122                                double startTime, stopTime;
123                                if (clipRangeType == "startEnd")
124                                {
125                                        startTime = args.asDouble(++i,&stat);
126                                        stopTime = args.asDouble(++i,&stat);
127                                        MString rangeUnits = args.asString(++i,&stat);
128                                        if (rangeUnits == "frames")
129                                        {
130                                                //range specified in frames => convert to seconds
131                                                MTime t1(startTime, MTime::uiUnit());
132                                                MTime t2(stopTime, MTime::uiUnit());
133                                                startTime = t1.as(MTime::kSeconds);
134                                                stopTime = t2.as(MTime::kSeconds);
135                                        }
136                                }
137                                else
138                                {
139                                        //range specified by time slider
140                                        MTime t1 = MAnimControl::minTime();
141                                        MTime t2 = MAnimControl::maxTime();
142                                        startTime = t1.as(MTime::kSeconds);
143                                        stopTime = t2.as(MTime::kSeconds);
144                                }
145                                // get sample rate
146                                double rate;
147                                MString sampleRateType = args.asString(++i,&stat);
148                                if (sampleRateType == "sampleByFrames")
149                                {
150                                        // rate specified in frames
151                                        int intRate = args.asInt(++i,&stat);
152                                        MTime t = MTime(intRate, MTime::uiUnit());
153                                        rate = t.as(MTime::kSeconds);
154                                }
155                                else
156                                {
157                                        // rate specified in seconds
158                                        rate = args.asDouble(++i,&stat);
159                                }
160                                //add clip info
161                                clipInfo clip;
162                                clip.name = clipName;
163                                clip.start = startTime;
164                                clip.stop = stopTime;
165                                clip.rate = rate;
166                                clipList.push_back(clip);
167                                std::cout << "clip " << clipName.asChar() << "\n";
168                                std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
169                                std::cout << "rate: " << rate << "\n";
170                                std::cout << "-----------------\n";
171                        }
172                }
173        /*      // Read options from exporter window
174                // Gather clips data
175                // Read info about the clips we have to transform
176                int numClips,exportClip,rangeType,rateType,rangeUnits;
177                double startTime,stopTime,rate;
178                MString clipName;
179                //read number of clips
180                MGlobal::executeCommand("eval \"$numClips+=0\"",numClips,false);
181                //read clips data
182                for (int i=1; i<=numClips; i++)
183                {
184                        MString command = "checkBox -q -v ExportClip";
185                        command += i;
186                        MGlobal::executeCommand(command,exportClip,false);
187                        if (exportClip)
188                        {
189                                //get clip name
190                                command = "textField -q -tx ClipName";
191                                command += i;
192                                MGlobal::executeCommand(command,clipName,false);
193                                //get clip range
194                                command = "radioButtonGrp -q -sl ClipRangeRadio";
195                                command += i;
196                                MGlobal::executeCommand(command,rangeType,false);
197                                if (rangeType == 1)
198                                {       //range specified from user
199                                        command = "floatField -q -v ClipRangeStart";
200                                        command += i;
201                                        MGlobal::executeCommand(command,startTime,false);
202                                        command = "floatField -q -v ClipRangeEnd";
203                                        command += i;
204                                        MGlobal::executeCommand(command,stopTime,false);
205                                        //get range units
206                                        command = "radioButtonGrp -q -sl ClipRangeUnits";
207                                        command += i;
208                                        MGlobal::executeCommand(command,rangeUnits,false);
209                                        if (rangeUnits == 1)
210                                        {       //range specified in frames => convert to seconds
211                                                MTime t1(startTime, MTime::uiUnit());
212                                                MTime t2(stopTime, MTime::uiUnit());
213                                                startTime = t1.as(MTime::kSeconds);
214                                                stopTime = t2.as(MTime::kSeconds);
215                                        }
216                                }
217                                else
218                                {       //range specified by time slider
219                                        MTime t1 = MAnimControl::minTime();
220                                        MTime t2 = MAnimControl::maxTime();
221                                        startTime = t1.as(MTime::kSeconds);
222                                        stopTime = t2.as(MTime::kSeconds);
223                                }
224                                //get sample rate
225                                command = "radioButtonGrp -q -sl ClipRateType";
226                                command += i;
227                                MGlobal::executeCommand(command,rateType,false);
228                                MTime t;
229                                switch (rateType)
230                                {
231                                case 1: //rate specified in frames
232                                        command = "intField -q -v ClipRateFrames";
233                                        command += i;
234                                        MGlobal::executeCommand(command,rate,false);
235                                        t = MTime(rate, MTime::uiUnit());
236                                        rate = t.as(MTime::kSeconds);
237                                        break;
238                                case 2: //rate specified in seconds
239                                        command = "floatField -q -v ClipRateSeconds";
240                                        command += i;
241                                        MGlobal::executeCommand(command,rate,false);
242                                        break;
243                                default://rate not specified, get from time slider
244                                        rate = -1;
245                                        break;
246                                }
247                                //add clip info
248                                clipInfo clip;
249                                clip.name = clipName;
250                                clip.start = startTime;
251                                clip.stop = stopTime;
252                                clip.rate = rate;
253                                clipList.push_back(clip);
254                                std::cout << "clip " << clipName.asChar() << "\n";
255                                std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
256                                std::cout << "rate: " << rate << "\n";
257                                std::cout << "-----------------\n";
258                        }
259                }*/
260        }
261
262
263        // method to open output files for writing
264        MStatus ParamList::openFiles()
265        {
266                MString msg;
267                if (exportMesh)
268                {
269                        outMesh.open(meshFilename.asChar());
270                        if (!outMesh)
271                        {
272                                std::cout << "Error opening file: " << meshFilename.asChar() << "\n";
273                                return MS::kFailure;
274                        }
275                }
276                if (exportMaterial)
277                {
278                        outMaterial.open(materialFilename.asChar());
279                        if (!outMaterial)
280                        {
281                                std::cout << "Error opening file: " << materialFilename.asChar() << "\n";
282                                return MS::kFailure;
283                        }
284                }
285                if (exportSkeleton)
286                {
287                        outSkeleton.open(skeletonFilename.asChar());
288                        if (!outSkeleton)
289                        {
290                                std::cout << "Error opening file: " << skeletonFilename.asChar() << "\n";
291                                return MS::kFailure;
292                        }
293                }
294                if (exportAnimCurves)
295                {
296                        outAnim.open(animFilename.asChar());
297                        if (!outAnim)
298                        {
299                                std::cout << "Error opening file: " << animFilename.asChar() << "\n";
300                                return MS::kFailure;
301                        }
302                }
303                if (exportCameras)
304                {
305                        outCameras.open(camerasFilename.asChar());
306                        if (!outCameras)
307                        {
308                                std::cout << "Error opening file: " << camerasFilename.asChar() << "\n";
309                                return MS::kFailure;
310                        }
311                }
312                if (exportParticles)
313                {
314                        outParticles.open(particlesFilename.asChar());
315                        if (!outParticles)
316                        {
317                                std::cout << "Error opening file: " << particlesFilename.asChar() << "\n";
318                                return MS::kFailure;
319                        }
320                }
321                return MS::kSuccess;
322        }
323
324        // method to close open output files
325        MStatus ParamList::closeFiles()
326        {
327                if (exportMesh)
328                        outMesh.close();
329               
330                if (exportMaterial)
331                        outMaterial.close();
332       
333                if (exportSkeleton)
334                        outSkeleton.close();
335               
336                if (exportAnimCurves)
337                        outAnim.close();
338                       
339                if (exportCameras)
340                        outCameras.close();
341               
342                return MS::kSuccess;
343        }
344
345}       //end namespace
Note: See TracBrowser for help on using the repository browser.