Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tools/MayaExport/src/paramlist.cpp @ 10

Last change on this file since 10 was 6, checked in by anonymous, 17 years ago

=…

File size: 13.9 KB
Line 
1////////////////////////////////////////////////////////////////////////////////
2// paramlist.cpp
3// Author     : Francesco Giordana
4// Start Date : January 13, 2005
5// Copyright  : (C) 2006 by Francesco Giordana
6// Email      : fra.giordana@tiscali.it
7////////////////////////////////////////////////////////////////////////////////
8
9/*********************************************************************************
10*                                                                                *
11*   This program is free software; you can redistribute it and/or modify         *
12*   it under the terms of the GNU Lesser General Public License as published by  *
13*   the Free Software Foundation; either version 2 of the License, or            *
14*   (at your option) any later version.                                          *
15*                                                                                *
16**********************************************************************************/
17
18#include "paramlist.h"
19#include <maya/MGlobal.h>
20
21/***** Class ParamList *****/
22// method to parse arguments from command line
23namespace OgreMayaExporter
24{
25        void ParamList::parseArgs(const MArgList &args)
26        {
27                MStatus stat;
28                // Parse arguments from command line
29                for (unsigned int i = 0; i < args.length(); i++ )
30                {
31                        if ((MString("-all") == args.asString(i,&stat)) && (MS::kSuccess == stat))
32                                exportAll = true;
33                        else if ((MString("-world") == args.asString(i,&stat)) && (MS::kSuccess == stat))
34                                exportWorldCoords = true;
35                        else if ((MString("-lu") == args.asString(i,&stat)) && (MS::kSuccess == stat))
36                        {
37                                MString lengthUnit = args.asString(++i,&stat);
38                                if (MString("pref") == lengthUnit)
39                                {
40                                        MGlobal::executeCommand("currentUnit -q -l",lengthUnit,false);
41                                }
42                                if (MString("mm") == lengthUnit)
43                                        lum = CM2MM;
44                                else if (MString("cm") == lengthUnit)
45                                        lum = CM2CM;
46                                else if (MString("m") == lengthUnit)
47                                        lum = CM2M;
48                                else if (MString("in") == lengthUnit)
49                                        lum = CM2IN;
50                                else if (MString("ft") == lengthUnit)
51                                        lum = CM2FT;
52                                else if (MString("yd") == lengthUnit)
53                                        lum = CM2YD;
54                        }
55                        else if ((MString("-scale") == args.asString(i,&stat)) && (MS::kSuccess == stat))
56                        {
57                                float s = args.asDouble(++i,&stat);
58                                lum *= s;
59                        }
60                        else if ((MString("-mesh") == args.asString(i,&stat)) && (MS::kSuccess == stat))
61                        {
62                                exportMesh = true;
63                                meshFilename = args.asString(++i,&stat);
64                        }
65                        else if ((MString("-mat") == args.asString(i,&stat)) && (MS::kSuccess == stat))
66                        {
67                                exportMaterial = true;
68                                materialFilename = args.asString(++i,&stat);
69                        }
70                        else if ((MString("-matPrefix") == args.asString(i,&stat)) && (MS::kSuccess == stat))
71                        {
72                                matPrefix = args.asString(++i,&stat);
73                        }
74                        else if ((MString("-copyTex") == args.asString(i,&stat)) && (MS::kSuccess == stat))
75                        {
76                                copyTextures = true;
77                                texOutputDir = args.asString(++i,&stat);
78                        }
79                        else if ((MString("-lightOff") == args.asString(i,&stat)) && (MS::kSuccess == stat))
80                        {
81                                lightingOff = true;
82                        }
83                        else if ((MString("-skel") == args.asString(i,&stat)) && (MS::kSuccess == stat))
84                        {
85                                exportSkeleton = true;
86                                skeletonFilename = args.asString(++i,&stat);
87                        }
88                        else if ((MString("-skeletonAnims") == args.asString(i,&stat)) && (MS::kSuccess == stat))
89                        {
90                                exportSkelAnims = true;
91                        }
92                        else if ((MString("-vertexAnims") == args.asString(i,&stat)) && (MS::kSuccess == stat))
93                        {
94                                exportVertAnims = true;
95                        }
96                        else if ((MString("-blendShapes") == args.asString(i,&stat)) && (MS::kSuccess == stat))
97                        {
98                                exportBlendShapes = true;
99                        }
100                        else if ((MString("-BSAnims") == args.asString(i,&stat)) && (MS::kSuccess == stat))
101                        {
102                                exportBSAnims = true;
103                        }
104                        else if ((MString("-skelBB") == args.asString(i,&stat)) && (MS::kSuccess == stat))
105                        {
106                                skelBB = true;
107                        }
108                        else if ((MString("-bsBB") == args.asString(i,&stat)) && (MS::kSuccess == stat))
109                        {
110                                bsBB = true;
111                        }
112                        else if ((MString("-vertBB") == args.asString(i,&stat)) && (MS::kSuccess == stat))
113                        {
114                                vertBB = true;
115                        }
116                        else if ((MString("-animCur") == args.asString(i,&stat)) && (MS::kSuccess == stat))
117                        {
118                                exportAnimCurves = true;
119                                animFilename = args.asString(++i,&stat);
120                        }
121                        else if ((MString("-cam") == args.asString(i,&stat)) && (MS::kSuccess == stat))
122                        {
123                                exportCameras = true;
124                                camerasFilename = args.asString(++i,&stat);
125                        }
126                        else if ((MString("-v") == args.asString(i,&stat)) && (MS::kSuccess == stat))
127                        {
128                                exportVBA = true;
129                        }
130                        else if ((MString("-n") == args.asString(i,&stat)) && (MS::kSuccess == stat))
131                        {
132                                exportVertNorm = true;
133                        }
134                        else if ((MString("-c") == args.asString(i,&stat)) && (MS::kSuccess == stat))
135                        {
136                                exportVertCol = true;
137                        }
138                        else if ((MString("-t") == args.asString(i,&stat)) && (MS::kSuccess == stat))
139                        {
140                                exportTexCoord = true;
141                        }
142                        else if ((MString("-edges") == args.asString(i,&stat)) && (MS::kSuccess == stat))
143                        {
144                                buildEdges = true;
145                        }
146                        else if ((MString("-tangents") == args.asString(i,&stat)) && (MS::kSuccess == stat))
147                        {
148                                buildTangents = true;
149                                MString tanSem = args.asString(++i,&stat);
150                                if (tanSem == "TECOORD")
151                                        tangentSemantic = TS_TEXCOORD;
152                                else if (tanSem == "TANGENT")
153                                        tangentSemantic = TS_TANGENT;
154                        }
155                        else if ((MString("-camAnim") == args.asString(i,&stat)) && (MS::kSuccess == stat))
156                        {
157                                exportCamerasAnim = true;
158                        }
159                        else if ((MString("-particles") == args.asString(i,&stat)) && (MS::kSuccess == stat))
160                        {
161                                exportParticles = true;
162                                particlesFilename = args.asString(++i,&stat);
163                        }
164                        else if ((MString("-shared") == args.asString(i,&stat)) && (MS::kSuccess == stat))
165                        {
166                                useSharedGeom = true;
167                        }
168                        else if ((MString("-np") == args.asString(i,&stat)) && (MS::kSuccess == stat))
169                        {
170                                MString npType = args.asString(++i,&stat);
171                                if (npType == "curFrame")
172                                        neutralPoseType = NPT_CURFRAME;
173                                else if (npType == "bindPose")
174                                        neutralPoseType = NPT_BINDPOSE;
175                        }
176                        else if ((MString("-skeletonClip") == args.asString(i,&stat)) && (MS::kSuccess == stat))
177                        {
178                                //get clip name
179                                MString clipName = args.asString(++i,&stat);
180                                //check if name is unique, otherwise skip the clip
181                                int k;
182                                bool uniqueName = true;
183                                for (k=0; k<skelClipList.size() && uniqueName; k++)
184                                {
185                                        if (clipName == skelClipList[k].name)
186                                                uniqueName = false;
187                                }
188                                //if the name is uniue, load the clip info
189                                if (uniqueName)
190                                {
191                                        //get clip range
192                                        MString clipRangeType = args.asString(++i,&stat);
193                                        float startTime, stopTime;
194                                        if (clipRangeType == "startEnd")
195                                        {
196                                                startTime = args.asDouble(++i,&stat);
197                                                stopTime = args.asDouble(++i,&stat);
198                                                MString rangeUnits = args.asString(++i,&stat);
199                                                if (rangeUnits == "frames")
200                                                {
201                                                        //range specified in frames => convert to seconds
202                                                        MTime t1(startTime, MTime::uiUnit());
203                                                        MTime t2(stopTime, MTime::uiUnit());
204                                                        startTime = t1.as(MTime::kSeconds);
205                                                        stopTime = t2.as(MTime::kSeconds);
206                                                }
207                                        }
208                                        else
209                                        {
210                                                //range specified by time slider
211                                                MTime t1 = MAnimControl::minTime();
212                                                MTime t2 = MAnimControl::maxTime();
213                                                startTime = t1.as(MTime::kSeconds);
214                                                stopTime = t2.as(MTime::kSeconds);
215                                        }
216                                        // get sample rate
217                                        float rate;
218                                        MString sampleRateType = args.asString(++i,&stat);
219                                        if (sampleRateType == "sampleByFrames")
220                                        {
221                                                // rate specified in frames
222                                                int intRate = args.asInt(++i,&stat);
223                                                MTime t = MTime(intRate, MTime::uiUnit());
224                                                rate = t.as(MTime::kSeconds);
225                                        }
226                                        else
227                                        {
228                                                // rate specified in seconds
229                                                rate = args.asDouble(++i,&stat);
230                                        }
231                                        //add clip info
232                                        clipInfo clip;
233                                        clip.name = clipName;
234                                        clip.start = startTime;
235                                        clip.stop = stopTime;
236                                        clip.rate = rate;
237                                        skelClipList.push_back(clip);
238                                        std::cout << "skeleton clip " << clipName.asChar() << "\n";
239                                        std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
240                                        std::cout << "rate: " << rate << "\n";
241                                        std::cout << "-----------------\n";
242                                        std::cout.flush();
243                                }
244                                //warn of duplicate clip name
245                                else
246                                {
247                                        std::cout << "Warning! A skeleton clip with name \"" << clipName.asChar() << "\" already exists\n";
248                                        std::cout.flush();
249                                }
250                        }
251                        else if ((MString("-BSClip") == args.asString(i,&stat)) && (MS::kSuccess == stat))
252                        {
253                                //get clip name
254                                MString clipName = args.asString(++i,&stat);
255                                //check if name is unique, otherwise skip the clip
256                                int k;
257                                bool uniqueName = true;
258                                for (k=0; k<BSClipList.size() && uniqueName; k++)
259                                {
260                                        if (clipName == BSClipList[k].name)
261                                                uniqueName = false;
262                                }
263                                //if the name is uniue, load the clip info
264                                if (uniqueName)
265                                {
266                                        //get clip range
267                                        MString clipRangeType = args.asString(++i,&stat);
268                                        float startTime, stopTime;
269                                        if (clipRangeType == "startEnd")
270                                        {
271                                                startTime = args.asDouble(++i,&stat);
272                                                stopTime = args.asDouble(++i,&stat);
273                                                MString rangeUnits = args.asString(++i,&stat);
274                                                if (rangeUnits == "frames")
275                                                {
276                                                        //range specified in frames => convert to seconds
277                                                        MTime t1(startTime, MTime::uiUnit());
278                                                        MTime t2(stopTime, MTime::uiUnit());
279                                                        startTime = t1.as(MTime::kSeconds);
280                                                        stopTime = t2.as(MTime::kSeconds);
281                                                }
282                                        }
283                                        else
284                                        {
285                                                //range specified by time slider
286                                                MTime t1 = MAnimControl::minTime();
287                                                MTime t2 = MAnimControl::maxTime();
288                                                startTime = t1.as(MTime::kSeconds);
289                                                stopTime = t2.as(MTime::kSeconds);
290                                        }
291                                        // get sample rate
292                                        float rate;
293                                        MString sampleRateType = args.asString(++i,&stat);
294                                        if (sampleRateType == "sampleByFrames")
295                                        {
296                                                // rate specified in frames
297                                                int intRate = args.asInt(++i,&stat);
298                                                MTime t = MTime(intRate, MTime::uiUnit());
299                                                rate = t.as(MTime::kSeconds);
300                                        }
301                                        else
302                                        {
303                                                // rate specified in seconds
304                                                rate = args.asDouble(++i,&stat);
305                                        }
306                                        //add clip info
307                                        clipInfo clip;
308                                        clip.name = clipName;
309                                        clip.start = startTime;
310                                        clip.stop = stopTime;
311                                        clip.rate = rate;
312                                        BSClipList.push_back(clip);
313                                        std::cout << "blend shape clip " << clipName.asChar() << "\n";
314                                        std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
315                                        std::cout << "rate: " << rate << "\n";
316                                        std::cout << "-----------------\n";
317                                        std::cout.flush();
318                                }
319                                //warn of duplicate clip name
320                                else
321                                {
322                                        std::cout << "Warning! A blend shape clip with name \"" << clipName.asChar() << "\" already exists\n";
323                                        std::cout.flush();
324                                }
325                        }
326                        else if ((MString("-vertexClip") == args.asString(i,&stat)) && (MS::kSuccess == stat))
327                        {
328                                //get clip name
329                                MString clipName = args.asString(++i,&stat);
330                                //check if name is unique, otherwise skip the clip
331                                int k;
332                                bool uniqueName = true;
333                                for (k=0; k<vertClipList.size() && uniqueName; k++)
334                                {
335                                        if (clipName == vertClipList[k].name)
336                                                uniqueName = false;
337                                }
338                                //if the name is uniue, load the clip info
339                                if (uniqueName)
340                                {
341                                //get clip range
342                                        MString clipRangeType = args.asString(++i,&stat);
343                                        float startTime, stopTime;
344                                        if (clipRangeType == "startEnd")
345                                        {
346                                                startTime = args.asDouble(++i,&stat);
347                                                stopTime = args.asDouble(++i,&stat);
348                                                MString rangeUnits = args.asString(++i,&stat);
349                                                if (rangeUnits == "frames")
350                                                {
351                                                        //range specified in frames => convert to seconds
352                                                        MTime t1(startTime, MTime::uiUnit());
353                                                        MTime t2(stopTime, MTime::uiUnit());
354                                                        startTime = t1.as(MTime::kSeconds);
355                                                        stopTime = t2.as(MTime::kSeconds);
356                                                }
357                                        }
358                                        else
359                                        {
360                                                //range specified by time slider
361                                                MTime t1 = MAnimControl::minTime();
362                                                MTime t2 = MAnimControl::maxTime();
363                                                startTime = t1.as(MTime::kSeconds);
364                                                stopTime = t2.as(MTime::kSeconds);
365                                        }
366                                        // get sample rate
367                                        float rate;
368                                        MString sampleRateType = args.asString(++i,&stat);
369                                        if (sampleRateType == "sampleByFrames")
370                                        {
371                                                // rate specified in frames
372                                                int intRate = args.asInt(++i,&stat);
373                                                MTime t = MTime(intRate, MTime::uiUnit());
374                                                rate = t.as(MTime::kSeconds);
375                                        }
376                                        else
377                                        {
378                                                // rate specified in seconds
379                                                rate = args.asDouble(++i,&stat);
380                                        }
381                                        //add clip info
382                                        clipInfo clip;
383                                        clip.name = clipName;
384                                        clip.start = startTime;
385                                        clip.stop = stopTime;
386                                        clip.rate = rate;
387                                        vertClipList.push_back(clip);
388                                        std::cout << "vertex clip " << clipName.asChar() << "\n";
389                                        std::cout << "start: " << startTime << ", stop: " << stopTime << "\n";
390                                        std::cout << "rate: " << rate << "\n";
391                                        std::cout << "-----------------\n";
392                                        std::cout.flush();
393                                }
394                                //warn of duplicate clip name
395                                else
396                                {
397                                        std::cout << "Warning! A vertex animation clip with name \"" << clipName.asChar() << "\" already exists\n";
398                                        std::cout.flush();
399                                }
400                        }
401                }
402        }
403
404
405        // method to open output files for writing
406        MStatus ParamList::openFiles()
407        {
408                MString msg;
409                if (exportMaterial)
410                {
411                        outMaterial.open(materialFilename.asChar());
412                        if (!outMaterial)
413                        {
414                                std::cout << "Error opening file: " << materialFilename.asChar() << "\n";
415                                return MS::kFailure;
416                        }
417                }
418                if (exportAnimCurves)
419                {
420                        outAnim.open(animFilename.asChar());
421                        if (!outAnim)
422                        {
423                                std::cout << "Error opening file: " << animFilename.asChar() << "\n";
424                                return MS::kFailure;
425                        }
426                }
427                if (exportCameras)
428                {
429                        outCameras.open(camerasFilename.asChar());
430                        if (!outCameras)
431                        {
432                                std::cout << "Error opening file: " << camerasFilename.asChar() << "\n";
433                                return MS::kFailure;
434                        }
435                }
436                if (exportParticles)
437                {
438                        outParticles.open(particlesFilename.asChar());
439                        if (!outParticles)
440                        {
441                                std::cout << "Error opening file: " << particlesFilename.asChar() << "\n";
442                                return MS::kFailure;
443                        }
444                }
445                return MS::kSuccess;
446        }
447
448        // method to close open output files
449        MStatus ParamList::closeFiles()
450        {
451                if (exportMaterial)
452                        outMaterial.close();
453       
454                if (exportAnimCurves)
455                        outAnim.close();
456                       
457                if (exportCameras)
458                        outCameras.close();
459               
460                return MS::kSuccess;
461        }
462
463}       //end namespace
Note: See TracBrowser for help on using the repository browser.