~ubuntu-branches/ubuntu/wily/opencollada/wily-proposed

« back to all changes in this revision

Viewing changes to dae2ma/src/DAE2MAAnimationImporter.cpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2008-2009 NetAllied Systems GmbH
 
3
 
 
4
    This file is part of DAE2MA.
 
5
 
 
6
    Licensed under the MIT Open Source License, 
 
7
    for details please see LICENSE file or the website
 
8
    http://www.opensource.org/licenses/mit-license.php
 
9
*/
 
10
 
 
11
#include "DAE2MAStableHeaders.h"
 
12
#include "DAE2MAAnimationImporter.h"
 
13
#include "DAE2MASyntax.h"
 
14
#include "DAE2MAVisualSceneImporter.h"
 
15
#include "DAE2MATransformAnimation.h"
 
16
#include "DAE2MAEffectImporter.h"
 
17
#include "DAE2MAMorphAnimation.h"
 
18
#include "DAE2MAControllerImporter.h"
 
19
 
 
20
#include "COLLADAFWFloatOrDoubleArray.h"
 
21
#include "COLLADAFWScale.h"
 
22
#include "COLLADAFWTranslate.h"
 
23
 
 
24
#include <MayaDMAnimCurveTA.h>
 
25
#include <MayaDMAnimCurveTU.h>
 
26
#include <MayaDMCommands.h>
 
27
#include <MayaDMScript.h>
 
28
 
 
29
 
 
30
namespace DAE2MA
 
31
{
 
32
 
 
33
    /** The standard name for an animation. */
 
34
    const String AnimationImporter::ANIMATION_NAME = "anim";
 
35
 
 
36
    /** The framerate of the animation. */
 
37
    const double AnimationImporter::ANIM_FRAMERATE = 24;
 
38
 
 
39
 
 
40
    //------------------------------
 
41
        AnimationImporter::AnimationImporter( DocumentImporter* documentImporter )
 
42
        : BaseImporter ( documentImporter )
 
43
        {
 
44
        }
 
45
        
 
46
    //------------------------------
 
47
        AnimationImporter::~AnimationImporter()
 
48
        {
 
49
        std::map<COLLADAFW::UniqueId, std::vector<MayaDM::AnimCurve*> >::iterator it = mMayaDMAnimationCurves.begin ();
 
50
        while ( it != mMayaDMAnimationCurves.end () )
 
51
        {
 
52
            std::vector<MayaDM::AnimCurve*> animCurves = it->second;
 
53
            for ( size_t i=0; i<animCurves.size (); ++i )
 
54
            {
 
55
                MayaDM::AnimCurve* animCurve = animCurves [i];
 
56
                delete animCurve;
 
57
            }
 
58
            animCurves.clear ();
 
59
 
 
60
            ++it;
 
61
        }
 
62
        mMayaDMAnimationCurves.clear ();
 
63
        }
 
64
 
 
65
    //------------------------------
 
66
    void AnimationImporter::importAnimation ( const COLLADAFW::Animation* animation )
 
67
    {
 
68
        // Check if the animation is already imported.
 
69
        const COLLADAFW::UniqueId& animationId = animation->getUniqueId ();
 
70
        if ( findAnimation ( animationId ) ) return;
 
71
 
 
72
        // Push the animation id in the list of imported ids.
 
73
        mAnimationIds.push_back ( animationId );
 
74
 
 
75
        // Import the animation data.
 
76
        const COLLADAFW::Animation::AnimationType& animationType = animation->getAnimationType ();
 
77
        switch ( animationType )
 
78
        {
 
79
        case COLLADAFW::Animation::ANIMATION_CURVE:
 
80
            {
 
81
                COLLADAFW::AnimationCurve* animationCurve = ( COLLADAFW::AnimationCurve* ) animation;
 
82
                importAnimationCurve ( animationCurve );
 
83
                break;
 
84
            }
 
85
        case COLLADAFW::Animation::ANIMATION_FORMULA:
 
86
            break;
 
87
        default:
 
88
            break;
 
89
        }
 
90
    }
 
91
 
 
92
    //------------------------------
 
93
    void AnimationImporter::importAnimationCurve ( COLLADAFW::AnimationCurve* animationCurve )
 
94
    {
 
95
        const COLLADAFW::PhysicalDimension& physicalDimension = animationCurve->getInPhysicalDimension ();
 
96
        if ( physicalDimension != COLLADAFW::PHYSICAL_DIMENSION_TIME )
 
97
        {
 
98
            std::cerr << "Import of other physical dimension then TIME not supported: " << physicalDimension << std::endl;
 
99
            return;
 
100
        }
 
101
 
 
102
        // Write the key time values
 
103
        const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = animationCurve->getInterpolationType ();
 
104
        switch ( interpolationType )
 
105
        {
 
106
        case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
107
            {
 
108
                TangentType tangentType = TANGENT_TYPE_FIXED;
 
109
                writeAnimationCurve ( animationCurve, tangentType );
 
110
            }
 
111
            break;
 
112
        case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
 
113
            {
 
114
                std::cerr << "Unknown animation interpolation type: INTERPOLATION_BSPLINE" << std::endl;
 
115
            }
 
116
            break;
 
117
        case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
 
118
            {
 
119
                std::cerr << "Unknown animation interpolation type: INTERPOLATION_CARDINAL" << std::endl;
 
120
            }
 
121
            break;
 
122
        case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
 
123
            {
 
124
                std::cerr << "Unknown animation interpolation type: INTERPOLATION_HERMITE" << std::endl;
 
125
            }
 
126
            break;
 
127
        case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
128
            {
 
129
                TangentType tangentType = TANGENT_TYPE_LINEAR;
 
130
                writeAnimationCurve ( animationCurve, tangentType );
 
131
            }
 
132
            break;
 
133
        case COLLADAFW::AnimationCurve::INTERPOLATION_MIXED:
 
134
            {
 
135
                writeAnimationCurveByKeys ( animationCurve );
 
136
            }
 
137
            break;
 
138
        case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
139
            {
 
140
                TangentType tangentType = TANGENT_TYPE_STEP;
 
141
                writeAnimationCurve ( animationCurve, tangentType );
 
142
            }
 
143
            break;
 
144
        case COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN:
 
145
            {
 
146
                TangentType tangentType = TANGENT_TYPE_CLAMPED;
 
147
                writeAnimationCurve ( animationCurve, tangentType );
 
148
                //std::cerr << "Unknown animation interpolation type!" << std::endl;
 
149
                break;
 
150
            }
 
151
        default:
 
152
            break;
 
153
        }
 
154
    }
 
155
 
 
156
    //------------------------------
 
157
    void AnimationImporter::writeAnimationCurve ( 
 
158
        const COLLADAFW::AnimationCurve* animationCurve, 
 
159
        const TangentType& tangentType /*= TANGENT_TYPE_DEFAULT*/ )
 
160
    {
 
161
        // The input is always the time with a stride of 2
 
162
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
163
        size_t numInputValues = inputValuesArray.getValuesCount ();
 
164
 
 
165
        // The output can have different dimensions.
 
166
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
167
        size_t outDimension = animationCurve->getOutDimension ();
 
168
        size_t numOutputValues = outputValuesArray.getValuesCount () / outDimension;
 
169
 
 
170
        const COLLADAFW::PhysicalDimensionArray& outPhysicalDimensions = animationCurve->getOutPhysicalDimensions ();
 
171
        size_t outDimension2 = outPhysicalDimensions.getCount ();
 
172
 
 
173
        if ( numInputValues != numOutputValues || outDimension != outDimension2 )
 
174
        {
 
175
            std::cerr << "Invalid animation!" << std::endl;
 
176
            return;
 
177
        }
 
178
 
 
179
        // The uniqueId of the animation.
 
180
        const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
 
181
 
 
182
        // Create a curve for every animated element.
 
183
        for ( size_t outputIndex=0; outputIndex<outDimension; ++outputIndex )
 
184
        {
 
185
            // Make the maya name unique and manage it in all necessary lists.
 
186
            String animationName = animationCurve->getName ();
 
187
            if ( animationName.empty () ) animationName = ANIMATION_NAME;
 
188
            animationName = DocumentImporter::frameworkNameToMayaName ( animationName );
 
189
            const ExtraDataCallbackHandler& callbackHandler = getDocumentImporter ()->getMayaIdCallbackHandler ();
 
190
            String originalMayaId = getOriginalMayaId ( callbackHandler, animationId, COLLADASaxFWL15::HASH_ELEMENT_ANIMATION );
 
191
            if ( !originalMayaId.empty () ) animationName = originalMayaId;
 
192
            animationName = generateUniqueDependNodeName ( animationName, true, true );
 
193
 
 
194
            // Get the maya file
 
195
            FILE* file = getDocumentImporter ()->getFile ();
 
196
 
 
197
            // Create the animation curve.
 
198
            MayaDM::AnimCurve* animCurve = 0;
 
199
 
 
200
            const COLLADAFW::PhysicalDimension& outPhysicalDimension = outPhysicalDimensions [outputIndex];
 
201
            switch ( outPhysicalDimension )
 
202
            {
 
203
            case COLLADAFW::PHYSICAL_DIMENSION_LENGTH:
 
204
                {
 
205
                    // We have to check for scale animations. They have to use an AnimCurveTU 
 
206
                    // (like dimension number) instead of an AnimCurveTL (like dimension length).
 
207
                    if ( !isScaleAnimation ( animationId ) )
 
208
                    {
 
209
                        animCurve = new MayaDM::AnimCurveTL ( file, animationName );
 
210
                        animCurve->setTangentType ( tangentType );
 
211
                        setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTL*)animCurve, outputIndex );
 
212
                    }
 
213
                    else
 
214
                    {
 
215
                        animCurve = new MayaDM::AnimCurveTU ( file, animationName );
 
216
                        animCurve->setTangentType ( tangentType );
 
217
                        setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTU*)animCurve, outputIndex );
 
218
                    }
 
219
                }
 
220
                break;
 
221
            case COLLADAFW::PHYSICAL_DIMENSION_ANGLE:
 
222
                {
 
223
                    animCurve = new MayaDM::AnimCurveTA ( file, animationName );
 
224
                    animCurve->setTangentType ( tangentType );
 
225
                    setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTA*)animCurve, outputIndex );
 
226
                }
 
227
                break;
 
228
            case COLLADAFW::PHYSICAL_DIMENSION_COLOR:
 
229
            case COLLADAFW::PHYSICAL_DIMENSION_NUMBER:
 
230
                {
 
231
                    animCurve = new MayaDM::AnimCurveTU ( file, animationName );
 
232
                    animCurve->setTangentType ( tangentType );
 
233
                    setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTU*)animCurve, outputIndex );
 
234
                }
 
235
                break;
 
236
            case COLLADAFW::PHYSICAL_DIMENSION_TIME:
 
237
                std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_TIME" << std::endl;
 
238
                return; break;
 
239
            default:
 
240
                std::cerr << "Unknown physical dimension!" << std::endl;
 
241
                return; break;
 
242
            }
 
243
 
 
244
            // Add the original id attribute.
 
245
            String colladaId = animationCurve->getOriginalId ();
 
246
            if ( !colladaId.empty () )
 
247
            {
 
248
                MayaDM::addAttr ( file, COLLADA_ID_ATTRIBUTE_NAME, ATTRIBUTE_DATA_TYPE, ATTRIBUTE_TYPE_STRING );
 
249
                MayaDM::setAttr ( file, COLLADA_ID_ATTRIBUTE_NAME, ATTRIBUTE_TYPE, ATTRIBUTE_TYPE_STRING, colladaId );
 
250
            }
 
251
//             // TODO Add the attributes for all the extra tags.
 
252
//             setExtraData ( animationCurve->getExtraDataArray () );
 
253
 
 
254
            // Push the maya animation curve element in a list.
 
255
            const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
 
256
            mMayaDMAnimationCurves [animationId].push_back ( animCurve );
 
257
 
 
258
            // True makes the in- and out-tangents move together. False makes them move separately.
 
259
            setKeyTangentLocks ( animationCurve, animCurve, false );
 
260
 
 
261
            // Set the in- and out-tangents
 
262
            if ( tangentType != TANGENT_TYPE_LINEAR && tangentType != TANGENT_TYPE_STEP )
 
263
            {
 
264
                setWeightedInTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
265
                setWeightedOutTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
266
            }
 
267
        }
 
268
    }
 
269
 
 
270
    //------------------------------
 
271
    const std::vector<MayaDM::AnimCurve*>* AnimationImporter::findMayaDMAnimCurves ( 
 
272
        const COLLADAFW::UniqueId& animationId )
 
273
    {
 
274
        const std::map<COLLADAFW::UniqueId, std::vector<MayaDM::AnimCurve*> >::iterator it = mMayaDMAnimationCurves.find ( animationId );
 
275
        if ( it != mMayaDMAnimationCurves.end () )
 
276
        {
 
277
            return &(it->second);
 
278
        }
 
279
        return 0;
 
280
    }
 
281
 
 
282
    //------------------------------
 
283
    void AnimationImporter::writeAnimationCurveByKeys (
 
284
        const COLLADAFW::AnimationCurve* animationCurve )
 
285
    {
 
286
        // The output can have different dimensions.
 
287
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
288
        size_t outDimension = animationCurve->getOutDimension ();
 
289
        size_t numOutputValues = outputValuesArray.getValuesCount () / outDimension;
 
290
 
 
291
        const COLLADAFW::PhysicalDimensionArray& outPhysicalDimensions = animationCurve->getOutPhysicalDimensions ();
 
292
        size_t outDimension2 = outPhysicalDimensions.getCount ();
 
293
 
 
294
        size_t keyCount = animationCurve->getKeyCount ();
 
295
        if ( numOutputValues != keyCount  || outDimension != outDimension2 )
 
296
        {
 
297
            std::cerr << "Animation not valid!" << std::endl;
 
298
            return;
 
299
        }
 
300
 
 
301
        // The uniqueId of the element.
 
302
        const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
 
303
 
 
304
        // Create a curve for every animated element.
 
305
        for ( size_t outputIndex=0; outputIndex<outDimension; ++outputIndex )
 
306
        {
 
307
            // Make the maya name unique and manage it in all necessary lists.
 
308
            String animationName = animationCurve->getName ();
 
309
            if ( animationName.empty () ) animationName = ANIMATION_NAME;
 
310
            animationName = DocumentImporter::frameworkNameToMayaName ( animationName );
 
311
            const ExtraDataCallbackHandler& callbackHandler = getDocumentImporter ()->getMayaIdCallbackHandler ();
 
312
            String originalMayaId = getOriginalMayaId ( callbackHandler, animationId, COLLADASaxFWL15::HASH_ELEMENT_ANIMATION );
 
313
            if ( !originalMayaId.empty () ) animationName = originalMayaId;
 
314
            animationName = generateUniqueDependNodeName ( animationName );
 
315
 
 
316
            // Create the animation curve.
 
317
            FILE* file = getDocumentImporter ()->getFile ();
 
318
 
 
319
            // Flag, if the values of the tangents should be normalized.
 
320
            bool normalizeTangents = true;
 
321
 
 
322
            // Create the animation curve.
 
323
            MayaDM::AnimCurve* animCurve = 0;
 
324
 
 
325
            const COLLADAFW::PhysicalDimension& outPhysicalDimension = outPhysicalDimensions [outputIndex];
 
326
            switch ( outPhysicalDimension )
 
327
            {
 
328
            case COLLADAFW::PHYSICAL_DIMENSION_LENGTH:
 
329
                {
 
330
                    animCurve = new MayaDM::AnimCurveTL ( file, animationName );
 
331
                    animCurve->setTangentType ( TANGENT_TYPE_FIXED );
 
332
                    setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTL*)animCurve, outputIndex );
 
333
                }
 
334
                break;
 
335
            case COLLADAFW::PHYSICAL_DIMENSION_ANGLE:
 
336
                {
 
337
                    animCurve = new MayaDM::AnimCurveTA ( file, animationName );
 
338
                    animCurve->setTangentType ( TANGENT_TYPE_FIXED );
 
339
                    setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTA*)animCurve, outputIndex );
 
340
                    normalizeTangents = false;
 
341
                }
 
342
                break;
 
343
            case COLLADAFW::PHYSICAL_DIMENSION_TIME:
 
344
                std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_TIME" << std::endl;
 
345
                return; break;
 
346
            case COLLADAFW::PHYSICAL_DIMENSION_COLOR:
 
347
                std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_COLOR" << std::endl;
 
348
                return; break;
 
349
            case COLLADAFW::PHYSICAL_DIMENSION_NUMBER:
 
350
                {
 
351
//                     animCurve = new MayaDM::AnimCurveTL ( file, animationName );
 
352
//                     animCurve->setTangentType ( TANGENT_TYPE_FIXED );
 
353
//                     setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTL*)animCurve, outputIndex );
 
354
                    std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_NUMBER" << std::endl;
 
355
                }
 
356
                return; break;
 
357
            default:
 
358
                std::cerr << "Unknown physical dimension!" << std::endl;
 
359
                return; break;
 
360
            }
 
361
 
 
362
            // Add the original id attribute.
 
363
            String colladaId = animationCurve->getOriginalId ();
 
364
            if ( !colladaId.empty () )
 
365
            {
 
366
                MayaDM::addAttr ( file, COLLADA_ID_ATTRIBUTE_NAME, ATTRIBUTE_DATA_TYPE, ATTRIBUTE_TYPE_STRING );
 
367
                MayaDM::setAttr ( file, COLLADA_ID_ATTRIBUTE_NAME, ATTRIBUTE_TYPE, ATTRIBUTE_TYPE_STRING, colladaId );
 
368
            }
 
369
//             // TODO Add the attributes for all the extra tags.
 
370
//             setExtraData ( animationCurve->getExtraDataArray () );
 
371
 
 
372
            // Push the maya animation curve element in a list.
 
373
            const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
 
374
            mMayaDMAnimationCurves [animationId].push_back ( animCurve );
 
375
 
 
376
            // Set key tangent in and out types
 
377
            setKeyTangentInTypes ( animationCurve, animCurve );
 
378
            setKeyTangentOutTypes ( animationCurve, animCurve );
 
379
 
 
380
            // True makes the in- and out-tangents move together. False makes them move separately.
 
381
            setKeyTangentLocks ( animationCurve, animCurve, false );
 
382
            
 
383
            // Set the in- and out-tangents
 
384
            setWeightedInTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
385
            setWeightedOutTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
386
        }
 
387
    }
 
388
 
 
389
    //------------------------------
 
390
    void AnimationImporter::setKeyTimeValues ( 
 
391
        const COLLADAFW::AnimationCurve* animationCurve, 
 
392
        MayaDM::AnimCurveTL* animCurveTL, 
 
393
        const size_t outputIndex )
 
394
    {
 
395
        // The input is always the time 
 
396
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
397
        size_t numInputValues = inputValuesArray.getValuesCount ();
 
398
 
 
399
        // The output can have different dimensions.
 
400
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
401
        size_t outDimension = animationCurve->getOutDimension ();
 
402
        size_t numOutputValues = outputValuesArray.getValuesCount () / outDimension;
 
403
 
 
404
        size_t keyCount = animationCurve->getKeyCount ();
 
405
        if ( numInputValues != numOutputValues || numInputValues != keyCount )
 
406
        {
 
407
            std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
 
408
            return;
 
409
        }
 
410
 
 
411
        // Start
 
412
        animCurveTL->startKeyTimeValue ( 0, keyCount-1 );
 
413
        MayaDM::AnimCurveTL::KeyTimeValue keyTimeValue;
 
414
 
 
415
        double inputValue = 0;
 
416
        double outputValue = 0;
 
417
 
 
418
        for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
 
419
        {
 
420
            inputValue = getDoubleValue ( inputValuesArray, inputIndex );
 
421
            size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
 
422
            outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
 
423
 
 
424
            // Framerate: 24 frames per second...
 
425
            keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
 
426
            keyTimeValue.keyValue = outputValue;
 
427
            animCurveTL->appendKeyTimeValue ( keyTimeValue );
 
428
 
 
429
            // Set the maya playback options (start and end time).
 
430
            mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
 
431
        }
 
432
 
 
433
        animCurveTL->endKeyTimeValue ();
 
434
    }
 
435
 
 
436
    //------------------------------
 
437
    void AnimationImporter::setKeyTimeValues ( 
 
438
        const COLLADAFW::AnimationCurve* animationCurve, 
 
439
        MayaDM::AnimCurveTU* animCurveTU, 
 
440
        const size_t outputIndex )
 
441
    {
 
442
        // The input is always the time 
 
443
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
444
        size_t numInputValues = inputValuesArray.getValuesCount ();
 
445
 
 
446
        // The output can have different dimensions.
 
447
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
448
        size_t outDimension = animationCurve->getOutDimension ();
 
449
        size_t numOutputValues = outputValuesArray.getValuesCount () / outDimension;
 
450
 
 
451
        size_t keyCount = animationCurve->getKeyCount ();
 
452
        if ( numInputValues != numOutputValues || numInputValues != keyCount )
 
453
        {
 
454
            std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
 
455
            return;
 
456
        }
 
457
 
 
458
        // Start
 
459
        animCurveTU->startKeyTimeValue ( 0, keyCount-1 );
 
460
        MayaDM::AnimCurveTU::KeyTimeValue keyTimeValue;
 
461
 
 
462
        double inputValue = 0;
 
463
        double outputValue = 0;
 
464
 
 
465
        for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
 
466
        {
 
467
            inputValue = getDoubleValue ( inputValuesArray, inputIndex );
 
468
            size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
 
469
            outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
 
470
 
 
471
            // Framerate: 24 frames per second...
 
472
            keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
 
473
            keyTimeValue.keyValue = outputValue;
 
474
            animCurveTU->appendKeyTimeValue ( keyTimeValue );
 
475
 
 
476
            // Set the maya playback options (start and end time).
 
477
            mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
 
478
        }
 
479
 
 
480
        animCurveTU->endKeyTimeValue ();
 
481
    }
 
482
 
 
483
    //------------------------------
 
484
    void AnimationImporter::setKeyTimeValues ( 
 
485
        const COLLADAFW::AnimationCurve* animationCurve, 
 
486
        MayaDM::AnimCurveTA* animCurveTA, 
 
487
        const size_t outputIndex )
 
488
    {
 
489
        // The input is always the time 
 
490
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
491
        size_t numInputValues = inputValuesArray.getValuesCount ();
 
492
 
 
493
        // The output can have different dimensions.
 
494
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
495
        size_t outDimension = animationCurve->getOutDimension ();
 
496
        size_t numOutputValues = outputValuesArray.getValuesCount () / outDimension;
 
497
 
 
498
        size_t keyCount = animationCurve->getKeyCount ();
 
499
        if ( numInputValues != numOutputValues || numInputValues != keyCount )
 
500
        {
 
501
            std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
 
502
            return;
 
503
        }
 
504
 
 
505
        // Start
 
506
        animCurveTA->startKeyTimeValue ( 0, keyCount-1 );
 
507
        MayaDM::AnimCurveTA::KeyTimeValue keyTimeValue;
 
508
 
 
509
        double inputValue = 0;
 
510
        double outputValue = 0;
 
511
 
 
512
        for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
 
513
        {
 
514
            inputValue = getDoubleValue ( inputValuesArray, inputIndex );
 
515
            size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
 
516
            outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
 
517
 
 
518
            // Framerate: 24 frames per second...
 
519
            keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
 
520
            keyTimeValue.keyValue = outputValue;
 
521
            animCurveTA->appendKeyTimeValue ( keyTimeValue );
 
522
 
 
523
            // Set the maya playback options (start and end time).
 
524
            mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
 
525
        }
 
526
 
 
527
        animCurveTA->endKeyTimeValue ();
 
528
    }
 
529
 
 
530
    //------------------------------
 
531
    void AnimationImporter::setWeightedInTangents ( 
 
532
        const COLLADAFW::AnimationCurve* animationCurve, 
 
533
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
534
        const size_t outputIndex, 
 
535
        MayaDM::AnimCurve* animCurve )
 
536
    {
 
537
        setWeightedInTangentXValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
538
        setWeightedInTangentYValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
539
    }
 
540
 
 
541
    //------------------------------
 
542
    void AnimationImporter::setWeightedInTangentXValues ( 
 
543
        const COLLADAFW::AnimationCurve* animationCurve, 
 
544
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
545
        const size_t outputIndex, 
 
546
        MayaDM::AnimCurve* animCurve )
 
547
    {
 
548
        // Check the interpolation type
 
549
        bool mixedInterpolation = false;
 
550
        COLLADAFW::AnimationCurve::InterpolationType interpolationType = animationCurve->getInterpolationType ();
 
551
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR ) return;
 
552
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_MIXED ) mixedInterpolation = true;
 
553
 
 
554
        // The time input and the output.
 
555
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
556
 
 
557
        // The in-tangent positions
 
558
        const size_t keyCount = animationCurve->getKeyCount ();
 
559
        const COLLADAFW::FloatOrDoubleArray& inTangentValuesArray = animationCurve->getInTangentValues ();
 
560
        size_t numTangentValues = inTangentValuesArray.getValuesCount ();
 
561
        if ( numTangentValues == 0 ) return;
 
562
 
 
563
        const size_t outDimension = animationCurve->getOutDimension ();
 
564
 
 
565
        // Write the in-tangent x values.
 
566
        animCurve->startKeyTanInX ( 0, keyCount-1 );
 
567
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
568
        {
 
569
            if ( mixedInterpolation )
 
570
                interpolationType = animationCurve->getInterpolationTypes () [keyPosition];
 
571
 
 
572
            switch ( interpolationType )
 
573
            {
 
574
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
575
                {
 
576
                    double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
577
                    size_t indexX = keyPosition*(outDimension*2) + (outputIndex*2);
 
578
                    double inTangentValueX = getDoubleValue ( inTangentValuesArray, indexX );
 
579
                    double resultX = 3 * ( inputValue - inTangentValueX );
 
580
                    animCurve->appendKeyTanInX ( resultX );
 
581
                }
 
582
                break;
 
583
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
584
                {
 
585
                    double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
586
                    double lastInputValue = 0;
 
587
                    if ( keyPosition > 0 )
 
588
                        lastInputValue = getDoubleValue ( inputValuesArray, keyPosition-1 );
 
589
                    double resultX = inputValue - lastInputValue;
 
590
                    animCurve->appendKeyTanInX ( resultX );
 
591
                }
 
592
                break;
 
593
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
594
                {
 
595
                    animCurve->appendKeyTanInX ( 0 );
 
596
                }
 
597
                break;
 
598
            default:
 
599
                {
 
600
                    std::cerr << "Interpolation type not supported!" << std::endl;
 
601
                    animCurve->appendKeyTanInX ( 0 );
 
602
                }
 
603
                break;
 
604
            }
 
605
        }
 
606
        animCurve->endKeyTanInX ();
 
607
    }
 
608
 
 
609
    //------------------------------
 
610
    void AnimationImporter::setWeightedInTangentYValues ( 
 
611
        const COLLADAFW::AnimationCurve* animationCurve, 
 
612
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
613
        const size_t outputIndex, 
 
614
        MayaDM::AnimCurve* animCurve )
 
615
    {
 
616
        // Check the interpolation type
 
617
        bool mixedInterpolation = false;
 
618
        COLLADAFW::AnimationCurve::InterpolationType interpolationType = animationCurve->getInterpolationType ();
 
619
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR ) return;
 
620
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_MIXED ) mixedInterpolation = true;
 
621
 
 
622
        // The time input values and the output values.
 
623
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
624
 
 
625
        // The in-tangent positions
 
626
        const size_t keyCount = animationCurve->getKeyCount ();
 
627
        const COLLADAFW::FloatOrDoubleArray& inTangentValuesArray = animationCurve->getInTangentValues ();
 
628
        size_t numTangentValues = inTangentValuesArray.getValuesCount ();
 
629
        if ( numTangentValues == 0 ) return;
 
630
 
 
631
        const size_t outDimension = animationCurve->getOutDimension ();
 
632
 
 
633
        // Write the in-tangent y values
 
634
        animCurve->startKeyTanInY ( 0, keyCount-1 );
 
635
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
636
        {
 
637
            if ( mixedInterpolation )
 
638
                interpolationType = animationCurve->getInterpolationTypes () [keyPosition];
 
639
 
 
640
            switch ( interpolationType )
 
641
            {
 
642
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
643
                {
 
644
                    size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
645
                    double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
646
                    size_t indexY = keyPosition*(outDimension*2) + (outputIndex*2) + 1;
 
647
                    double inTangentValueY = getDoubleValue ( inTangentValuesArray, indexY );
 
648
                    double resultY = 3 * ( outputValue - inTangentValueY );
 
649
                    if ( outPhysicalDimension == COLLADAFW::PHYSICAL_DIMENSION_ANGLE )
 
650
                        resultY = COLLADABU::Math::Utils::degToRad ( resultY );
 
651
                    animCurve->appendKeyTanInY ( resultY );
 
652
                }
 
653
                break;
 
654
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
655
                {
 
656
                    size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
657
                    double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
658
                    double lastOutputValue = 0;
 
659
                    if ( keyPosition > 0 )
 
660
                        lastOutputValue = getDoubleValue ( outputValuesArray, keyPosition-1 );
 
661
                    double resultY = outputValue - lastOutputValue;
 
662
                    if ( outPhysicalDimension == COLLADAFW::PHYSICAL_DIMENSION_ANGLE )
 
663
                        resultY = COLLADABU::Math::Utils::degToRad ( resultY );
 
664
                    animCurve->appendKeyTanInX ( resultY );
 
665
                }
 
666
                break;
 
667
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
668
                {
 
669
                    animCurve->appendKeyTanInX ( 0 );
 
670
                }
 
671
                break;
 
672
            default:
 
673
                {
 
674
                    std::cerr << "Interpolation type not supported!" << std::endl;
 
675
                    animCurve->appendKeyTanInX ( 0 );
 
676
                }
 
677
                break;
 
678
            }
 
679
        }
 
680
        animCurve->endKeyTanInY ();
 
681
    }
 
682
 
 
683
    //------------------------------
 
684
    void AnimationImporter::setWeightedOutTangents ( 
 
685
        const COLLADAFW::AnimationCurve* animationCurve, 
 
686
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
687
        const size_t outputIndex, 
 
688
        MayaDM::AnimCurve* animCurve )
 
689
    {
 
690
        setWeightedOutTangentXValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
691
        setWeightedOutTangentYValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
 
692
    }
 
693
 
 
694
    //------------------------------
 
695
    void AnimationImporter::setWeightedOutTangentXValues ( 
 
696
        const COLLADAFW::AnimationCurve* animationCurve, 
 
697
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
698
        const size_t outputIndex, 
 
699
        MayaDM::AnimCurve* animCurve )
 
700
    {
 
701
        // The time input values and the output values.
 
702
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
703
 
 
704
        // The out-tangent positions
 
705
        const size_t keyCount = animationCurve->getKeyCount ();
 
706
        const COLLADAFW::FloatOrDoubleArray& outTangentValuesArray = animationCurve->getOutTangentValues ();
 
707
        size_t numTangentValues = outTangentValuesArray.getValuesCount ();
 
708
        if ( numTangentValues == 0 ) return;
 
709
 
 
710
        // Check the interpolation type
 
711
        bool mixedInterpolation = false;
 
712
        COLLADAFW::AnimationCurve::InterpolationType interpolationType = animationCurve->getInterpolationType ();
 
713
        const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypeArray = animationCurve->getInterpolationTypes ();
 
714
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR ) return;
 
715
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_MIXED ) mixedInterpolation = true;
 
716
 
 
717
        const size_t outDimension = animationCurve->getOutDimension ();
 
718
 
 
719
        // Write the in-tangent x values.
 
720
        animCurve->startKeyTanOutX ( 0, keyCount-1 );
 
721
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
722
        {
 
723
            if ( mixedInterpolation )
 
724
                interpolationType = interpolationTypeArray [keyPosition];
 
725
 
 
726
            switch ( interpolationType )
 
727
            {
 
728
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
729
                {
 
730
                    double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
731
                    size_t indexX = keyPosition*(outDimension*2) + (outputIndex*2);
 
732
                    double outTangentValueX = getDoubleValue ( outTangentValuesArray, indexX );
 
733
                    double resultX = -3 * ( inputValue - outTangentValueX );
 
734
                    animCurve->appendKeyTanOutX ( resultX );
 
735
                }
 
736
                break;
 
737
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
738
                {
 
739
                    double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
740
                    double nextInputValue = 0;
 
741
                    if ( keyPosition < keyCount-1 )
 
742
                    {
 
743
                        nextInputValue = getDoubleValue ( inputValuesArray, keyPosition+1 );
 
744
                        double resultX = nextInputValue - inputValue;
 
745
                        animCurve->appendKeyTanInX ( resultX );
 
746
                    }
 
747
                    else animCurve->appendKeyTanInX ( 1 );
 
748
                }
 
749
                break;
 
750
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
751
                {
 
752
                    animCurve->appendKeyTanInX ( 0 );
 
753
                }
 
754
                break;
 
755
            default:
 
756
                {
 
757
                    std::cerr << "Interpolation type not supported!" << std::endl;
 
758
                    animCurve->appendKeyTanInX ( 0 );
 
759
                }
 
760
                break;
 
761
            }
 
762
        }
 
763
        animCurve->endKeyTanOutX ();
 
764
    }
 
765
 
 
766
    //------------------------------
 
767
    void AnimationImporter::setWeightedOutTangentYValues ( 
 
768
        const COLLADAFW::AnimationCurve* animationCurve, 
 
769
        const COLLADAFW::PhysicalDimension& outPhysicalDimension, 
 
770
        const size_t outputIndex, 
 
771
        MayaDM::AnimCurve* animCurve )
 
772
    {
 
773
        // The time input values and the output values.
 
774
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
775
 
 
776
        // The out-tangent positions
 
777
        const size_t keyCount = animationCurve->getKeyCount ();
 
778
        const COLLADAFW::FloatOrDoubleArray& outTangentValuesArray = animationCurve->getOutTangentValues ();
 
779
        size_t numTangentValues = outTangentValuesArray.getValuesCount ();
 
780
        if ( numTangentValues == 0 ) return;
 
781
 
 
782
        // Check the interpolation type
 
783
        bool mixedInterpolation = false;
 
784
        COLLADAFW::AnimationCurve::InterpolationType interpolationType = animationCurve->getInterpolationType ();
 
785
        const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypeArray = animationCurve->getInterpolationTypes ();
 
786
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR ) return;
 
787
        if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_MIXED ) mixedInterpolation = true;
 
788
 
 
789
        const size_t outDimension = animationCurve->getOutDimension ();
 
790
 
 
791
        // Write the in-tangent y values 
 
792
        animCurve->startKeyTanOutY ( 0, keyCount-1 );
 
793
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
794
        {
 
795
            if ( mixedInterpolation )
 
796
                interpolationType = interpolationTypeArray [keyPosition];
 
797
 
 
798
            switch ( interpolationType )
 
799
            {
 
800
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
801
                {
 
802
                    size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
803
                    double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
804
                    size_t indexY = keyPosition*(outDimension*2) + (outputIndex*2) + 1;
 
805
                    double outTangentValueY = getDoubleValue ( outTangentValuesArray, indexY );
 
806
                    double resultY = -3 * ( outputValue - outTangentValueY );
 
807
                    if ( outPhysicalDimension == COLLADAFW::PHYSICAL_DIMENSION_ANGLE )
 
808
                        resultY = COLLADABU::Math::Utils::degToRad ( resultY );
 
809
                    animCurve->appendKeyTanOutY ( resultY );
 
810
                }
 
811
                break;
 
812
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
813
                {
 
814
                    size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
815
                    double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
816
                    double nextOutputValue = 0;
 
817
                    if ( keyPosition < keyCount-1 )
 
818
                    {
 
819
                        nextOutputValue = getDoubleValue ( outputValuesArray, keyPosition+1 );
 
820
                        double resultY = nextOutputValue - outputValue;
 
821
                        if ( outPhysicalDimension == COLLADAFW::PHYSICAL_DIMENSION_ANGLE )
 
822
                            resultY = COLLADABU::Math::Utils::degToRad ( resultY );
 
823
                        animCurve->appendKeyTanInX ( resultY );
 
824
                    }
 
825
                    else animCurve->appendKeyTanInX ( 0 );
 
826
                }
 
827
                break;
 
828
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
829
                {
 
830
                    animCurve->appendKeyTanInX ( 0 );
 
831
                }
 
832
                break;
 
833
            default:
 
834
                {
 
835
                    std::cerr << "Interpolation type not supported!" << std::endl;
 
836
                    animCurve->appendKeyTanInX ( 0 );
 
837
                }
 
838
                break;
 
839
            }
 
840
        }
 
841
        animCurve->endKeyTanOutY ();
 
842
    }
 
843
 
 
844
    //------------------------------
 
845
    void AnimationImporter::setNonWeightedInTangents ( 
 
846
        const COLLADAFW::AnimationCurve* animationCurve, 
 
847
        MayaDM::AnimCurve* animCurve, 
 
848
        const size_t outputIndex, 
 
849
        const bool normalize /*= true*/ )
 
850
    {
 
851
        // The input is always the time 
 
852
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
853
 
 
854
        // The output array.
 
855
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
856
 
 
857
        // The in-tangent positions
 
858
        const size_t keyCount = animationCurve->getKeyCount ();
 
859
        const COLLADAFW::FloatOrDoubleArray& inTangentValuesArray = animationCurve->getInTangentValues ();
 
860
        size_t numTangentValues = inTangentValuesArray.getValuesCount ();
 
861
        if ( numTangentValues == 0 ) return;
 
862
        
 
863
        const size_t outDimension = animationCurve->getOutDimension ();
 
864
 
 
865
        // Write the in-tangent x values.
 
866
        animCurve->startKeyTanInX ( 0, keyCount-1 );
 
867
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
868
        {
 
869
            // Get the delta x
 
870
            double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
871
            size_t indexX = keyPosition*outDimension*2 + outputIndex;
 
872
            double inTangentValueX = getDoubleValue ( inTangentValuesArray, indexX );
 
873
            double deltaX = inputValue - inTangentValueX;
 
874
            double normedDeltaX = 0;
 
875
            if ( deltaX != 0 )
 
876
            {
 
877
                // Get the delta x
 
878
                size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
879
                double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
880
                size_t indexY = keyPosition*outDimension*2 + outputIndex + 1;
 
881
                double inTangentValueY = getDoubleValue ( inTangentValuesArray, indexY );
 
882
                double deltaY = outputValue - inTangentValueY;
 
883
                if ( normalize && deltaY != 0 )
 
884
                {
 
885
                    // Norm the delta x to a delta y of 1
 
886
                    double m = deltaY / deltaX;
 
887
                    normedDeltaX = 1 / m;
 
888
                    if ( normedDeltaX < 0 ) normedDeltaX *= -1;
 
889
                }
 
890
                else normedDeltaX = deltaX;
 
891
            }
 
892
 
 
893
            // Set the normed x delta value.
 
894
            animCurve->appendKeyTanInX ( normedDeltaX );
 
895
        }
 
896
        animCurve->endKeyTanInX ();
 
897
 
 
898
        // Write the in-tangent y values (just the normed values of 1)
 
899
        animCurve->startKeyTanInY ( 0, keyCount-1 );
 
900
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
901
        {
 
902
            // Get the delta y
 
903
            size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
904
            double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
905
            size_t indexY = keyPosition*outDimension*2 + outputIndex + 1;
 
906
            double inTangentValueY = getDoubleValue ( inTangentValuesArray, indexY );
 
907
            double deltaY = outputValue - inTangentValueY;
 
908
            double normedDeltaY = 0;
 
909
            if ( normalize && deltaY != 0 )
 
910
            {
 
911
                // Set the key tangent in y value.
 
912
                normedDeltaY = -1;
 
913
                if ( deltaY > 0 ) normedDeltaY = 1;
 
914
            }
 
915
            else normedDeltaY = deltaY;
 
916
 
 
917
            // Set the normed y delta value.
 
918
            animCurve->appendKeyTanInY ( normedDeltaY );
 
919
        }
 
920
        animCurve->endKeyTanInY ();
 
921
    }
 
922
 
 
923
    //------------------------------
 
924
    void AnimationImporter::setNonWeightedOutTangents ( 
 
925
        const COLLADAFW::AnimationCurve* animationCurve, 
 
926
        MayaDM::AnimCurve* animCurve, 
 
927
        const size_t outputIndex, 
 
928
        const bool normalize /*= true*/ )
 
929
    {
 
930
        // The input is always the time 
 
931
        const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
 
932
 
 
933
        // The output array.
 
934
        const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
 
935
 
 
936
        // The out-tangent positions
 
937
        const size_t keyCount = animationCurve->getKeyCount ();
 
938
        const COLLADAFW::FloatOrDoubleArray& outTangentValuesArray = animationCurve->getOutTangentValues ();
 
939
        size_t numTangentValues = outTangentValuesArray.getValuesCount ();
 
940
        if ( numTangentValues == 0 ) return;
 
941
 
 
942
        const size_t outDimension = animationCurve->getOutDimension ();
 
943
 
 
944
        // Write the in-tangent x values.
 
945
        animCurve->startKeyTanOutX ( 0, keyCount-1 );
 
946
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
947
        {
 
948
            // Get the delta x
 
949
            double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
 
950
            size_t indexX = keyPosition*outDimension*2 + outputIndex;
 
951
            double outTangentValueX = getDoubleValue ( outTangentValuesArray, indexX );
 
952
            double deltaX = inputValue - outTangentValueX;
 
953
            double normedDeltaX = 0;
 
954
            if ( deltaX != 0 )
 
955
            {
 
956
                // Get the delta y
 
957
                size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
958
                double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
959
                size_t indexY = keyPosition*outDimension*2 + outputIndex + 1;
 
960
                double outTangentValueY = getDoubleValue ( outTangentValuesArray, indexY );
 
961
                double deltaY = outputValue - outTangentValueY;
 
962
                if ( normalize && deltaY != 0 )
 
963
                {
 
964
                    // Norm the delta x to a delta y of 1
 
965
                    double m = deltaY / deltaX;
 
966
                    normedDeltaX = 1 / m;
 
967
                    if ( normedDeltaX < 0 ) normedDeltaX *= -1;
 
968
                }
 
969
                else normedDeltaX = deltaX * -1;
 
970
            }
 
971
 
 
972
            // Set the key tangent in x value.
 
973
            animCurve->appendKeyTanOutX ( normedDeltaX );
 
974
        }
 
975
        animCurve->endKeyTanOutX ();
 
976
 
 
977
        // Write the in-tangent y values (just the normed values of 1)
 
978
        animCurve->startKeyTanOutY ( 0, keyCount-1 );
 
979
        for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
 
980
        {
 
981
            // Get the delta y
 
982
            size_t outputValueIndex = keyPosition*outDimension + outputIndex;
 
983
            double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
 
984
            size_t indexY = keyPosition*outDimension*2 + outputIndex + 1;
 
985
            double outTangentValueY = getDoubleValue ( outTangentValuesArray, indexY );
 
986
            double deltaY = outputValue - outTangentValueY;
 
987
            double normedDeltaY = 0;
 
988
            if ( normalize && deltaY != 0 )
 
989
            {
 
990
                // Set the key tangent out y value.
 
991
                normedDeltaY = 1;
 
992
                if ( deltaY > 0 ) normedDeltaY = -1;
 
993
            }
 
994
            else normedDeltaY = deltaY;
 
995
 
 
996
            // Set the key tangent in y value.
 
997
            animCurve->appendKeyTanOutY ( normedDeltaY );
 
998
        }
 
999
        animCurve->endKeyTanOutY ();
 
1000
    }
 
1001
 
 
1002
    //------------------------------
 
1003
    void AnimationImporter::setKeyTangentInTypes ( 
 
1004
        const COLLADAFW::AnimationCurve* animationCurve, 
 
1005
        MayaDM::AnimCurve* animCurve )
 
1006
    {
 
1007
        TangentType keyTangentInType;
 
1008
 
 
1009
        // The interpolation types
 
1010
        const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypes = animationCurve->getInterpolationTypes ();
 
1011
        size_t numInterpolationTypes = interpolationTypes.getCount ();
 
1012
 
 
1013
        size_t keyCount = animationCurve->getKeyCount ();
 
1014
        if ( numInterpolationTypes != keyCount )
 
1015
        {
 
1016
            std::cerr << "AnimationImporter::setKeyTangentInType(): Invalid animation!" << std::endl;
 
1017
            return;
 
1018
        }
 
1019
 
 
1020
        animCurve->startKeyTanInType ( 0, keyCount-1 );
 
1021
        for ( size_t i=0; i<keyCount; ++i )
 
1022
        {
 
1023
            const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = interpolationTypes [i];
 
1024
            switch ( interpolationType )
 
1025
            {
 
1026
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
1027
                keyTangentInType = TANGENT_TYPE_FIXED;
 
1028
                break;
 
1029
            case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
 
1030
                keyTangentInType = TANGENT_TYPE_FIXED;
 
1031
                break;
 
1032
            case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
 
1033
                keyTangentInType = TANGENT_TYPE_FIXED;
 
1034
                break;
 
1035
            case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
 
1036
                keyTangentInType = TANGENT_TYPE_FIXED;
 
1037
                break;
 
1038
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
1039
                keyTangentInType = TANGENT_TYPE_LINEAR;
 
1040
                break;
 
1041
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
1042
                keyTangentInType = TANGENT_TYPE_STEP;
 
1043
                break;
 
1044
            default:
 
1045
                std::cerr << "Unknown interpolation type in mixed interpolations!" << std::endl;
 
1046
                keyTangentInType = TANGENT_TYPE_DEFAULT;
 
1047
            }
 
1048
            animCurve->appendKeyTanInType ( keyTangentInType );
 
1049
        }
 
1050
        animCurve->endKeyTanInType ();
 
1051
    }
 
1052
 
 
1053
    //------------------------------
 
1054
    void AnimationImporter::setKeyTangentOutTypes ( 
 
1055
        const COLLADAFW::AnimationCurve* animationCurve, 
 
1056
        MayaDM::AnimCurve* animCurve )
 
1057
    {
 
1058
        TangentType keyTangentOutType;
 
1059
 
 
1060
        // The interpolation types
 
1061
        const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypes = animationCurve->getInterpolationTypes ();
 
1062
        size_t numInterpolationTypes = interpolationTypes.getCount ();
 
1063
 
 
1064
        size_t keyCount = animationCurve->getKeyCount ();
 
1065
        if ( numInterpolationTypes != keyCount )
 
1066
        {
 
1067
            std::cerr << "AnimationImporter::setKeyTangentOutType(): Invalid animation!" << std::endl;
 
1068
            return;
 
1069
        }
 
1070
 
 
1071
        animCurve->startKeyTanOutType ( 0, keyCount-1 );
 
1072
        for ( size_t i=0; i<keyCount; ++i )
 
1073
        {
 
1074
            const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = interpolationTypes [i];
 
1075
            switch ( interpolationType )
 
1076
            {
 
1077
            case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
 
1078
                keyTangentOutType = TANGENT_TYPE_FIXED;
 
1079
                break;
 
1080
            case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
 
1081
                keyTangentOutType = TANGENT_TYPE_FIXED;
 
1082
                break;
 
1083
            case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
 
1084
                keyTangentOutType = TANGENT_TYPE_FIXED;
 
1085
                break;
 
1086
            case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
 
1087
                keyTangentOutType = TANGENT_TYPE_FIXED;
 
1088
                break;
 
1089
            case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
 
1090
                keyTangentOutType = TANGENT_TYPE_LINEAR;
 
1091
                break;
 
1092
            case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
 
1093
                keyTangentOutType = TANGENT_TYPE_STEP;
 
1094
                break;
 
1095
            default:
 
1096
                std::cerr << "Unknown interpolation type in mixed interpolations!" << std::endl;
 
1097
                keyTangentOutType = TANGENT_TYPE_DEFAULT;
 
1098
            }
 
1099
            animCurve->appendKeyTanOutType ( keyTangentOutType );
 
1100
        }
 
1101
        animCurve->endKeyTanOutType ();
 
1102
    }
 
1103
 
 
1104
    //------------------------------
 
1105
    void AnimationImporter::setKeyTangentLocks ( 
 
1106
        const COLLADAFW::AnimationCurve* animationCurve, 
 
1107
        MayaDM::AnimCurve* animCurve,
 
1108
        const bool keyTanLocked )
 
1109
    {
 
1110
        if ( !keyTanLocked )
 
1111
        {
 
1112
            size_t keyCount = animationCurve->getKeyCount ();
 
1113
            animCurve->startKeyTanLocked ( 0, keyCount-1 );
 
1114
            for ( size_t i=0; i<keyCount; ++i )
 
1115
            {
 
1116
                animCurve->appendKeyTanLocked ( keyTanLocked );
 
1117
            }
 
1118
            animCurve->endKeyTanLocked ();
 
1119
        }
 
1120
    }
 
1121
 
 
1122
    //------------------------------
 
1123
    void AnimationImporter::importPlaybackOptions ()
 
1124
    {
 
1125
        // Get the minimum and the maximum time values of the animations to get the start 
 
1126
        // time and the end time of the animation. This times we have to set as the 
 
1127
        // "playbackOptions" in the "sceneConfigurationScriptNode".
 
1128
 
 
1129
        // Get the maya file.
 
1130
        FILE* file = getDocumentImporter ()->getFile ();
 
1131
 
 
1132
        // createNode script -n "sceneConfigurationScriptNode";
 
1133
        // setAttr ".b" -type "string" "playbackOptions -min 1 -max 50 -ast 1 -aet 50 ";
 
1134
        // setAttr ".st" 6;
 
1135
        if ( mPlaybackOptions.getMaxEndTime () > 0 )
 
1136
        {
 
1137
            MayaDM::Script scriptNode ( file, SCRIPT_NODE_SCENE_CONFIG );
 
1138
            std::ostringstream scriptValue;
 
1139
            scriptValue << "playbackOptions -min " << mPlaybackOptions.getMinStartTime () 
 
1140
                << " -max " << mPlaybackOptions.getMaxEndTime () << " -ast " 
 
1141
                << mPlaybackOptions.getMinStartTime () << " -aet " << mPlaybackOptions.getMaxEndTime ();
 
1142
 
 
1143
            scriptNode.setBefore ( scriptValue.str () );
 
1144
            scriptNode.setScriptType ( 2 );
 
1145
        }
 
1146
    }
 
1147
 
 
1148
    //------------------------------
 
1149
    const bool AnimationImporter::findAnimation ( const COLLADAFW::UniqueId& animationId )
 
1150
    {
 
1151
        UniqueIdVec::const_iterator it = mAnimationIds.begin ();
 
1152
        while ( it != mAnimationIds.end () )
 
1153
        {
 
1154
            const COLLADAFW::UniqueId& uniqueId = *it;
 
1155
            if ( uniqueId == animationId ) return true;
 
1156
 
 
1157
            ++it;
 
1158
        }
 
1159
        return false;
 
1160
    }
 
1161
 
 
1162
    //------------------------------
 
1163
    const bool AnimationImporter::findAnimationList ( const COLLADAFW::UniqueId& animationListId )
 
1164
    {
 
1165
        UniqueIdVec::const_iterator it = mAnimationListIds.begin ();
 
1166
        while ( it != mAnimationListIds.end () )
 
1167
        {
 
1168
            const COLLADAFW::UniqueId& uniqueId = *it;
 
1169
            if ( uniqueId == animationListId ) return true;
 
1170
 
 
1171
            ++it;
 
1172
        }
 
1173
        return false;
 
1174
    }
 
1175
 
 
1176
    //------------------------------
 
1177
    void AnimationImporter::detectScaleAnimations ( const COLLADAFW::AnimationList* animationList )
 
1178
    {
 
1179
        // Get the id of the current animation list.
 
1180
        const COLLADAFW::UniqueId& animationListId = animationList->getUniqueId ();
 
1181
 
 
1182
        // Get the node, which use this animation list.
 
1183
        VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter ();
 
1184
        const TransformAnimation* transformAnimation = visualSceneImporter->findTransformAnimation ( animationListId );
 
1185
        if ( !transformAnimation ) return;
 
1186
 
 
1187
        const COLLADAFW::Transformation* transformation = transformAnimation->getTransformation ();
 
1188
        COLLADAFW::Transformation::TransformationType transformType = transformation->getTransformationType ();
 
1189
 
 
1190
        // Check if it is a scale animation.
 
1191
        switch ( transformType )
 
1192
        {
 
1193
        case COLLADAFW::Transformation::SCALE:
 
1194
            {
 
1195
                // Get the animation bindings.
 
1196
                const COLLADAFW::AnimationList::AnimationBindings& animationBindings = animationList->getAnimationBindings ();
 
1197
 
 
1198
                // Get the animation curves of the current animated element.
 
1199
                size_t numAnimationBindings = animationBindings.getCount ();
 
1200
                for ( size_t i=0; i<numAnimationBindings; ++i )
 
1201
                {
 
1202
                    // Get the animation curve element of the current animation id.
 
1203
                    const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1204
                    const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1205
 
 
1206
                    // Store the scale animation id in a list.
 
1207
                    mScaleAnimations.push_back ( animationId );
 
1208
                }
 
1209
            }
 
1210
            break;
 
1211
        default:
 
1212
            break;
 
1213
        }
 
1214
    }
 
1215
 
 
1216
    //------------------------------
 
1217
    const bool AnimationImporter::isScaleAnimation ( const COLLADAFW::UniqueId& animationId )
 
1218
    {
 
1219
        UniqueIdVec::const_iterator it = mScaleAnimations.begin ();
 
1220
        while ( it != mScaleAnimations.end () )
 
1221
        {
 
1222
            if ( animationId == *it ) return true;
 
1223
            ++it;
 
1224
        }
 
1225
        return false;
 
1226
    }
 
1227
 
 
1228
    //------------------------------
 
1229
    void AnimationImporter::writeConnections ( const COLLADAFW::AnimationList* animationList )
 
1230
    {
 
1231
        // Get the id of the current animation list.
 
1232
        const COLLADAFW::UniqueId& animationListId = animationList->getUniqueId ();
 
1233
        if ( findAnimationList ( animationListId ) ) return;
 
1234
        mAnimationListIds.push_back ( animationListId );
 
1235
 
 
1236
        // Get the animation bindings.
 
1237
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings = animationList->getAnimationBindings ();
 
1238
 
 
1239
        // Write the transformation animation connections.
 
1240
        connectTransforms ( animationListId, animationBindings );
 
1241
 
 
1242
        // Write the effect animation connections.
 
1243
        connectEffects ( animationListId, animationBindings );
 
1244
 
 
1245
        // Write the morph controller source connections.
 
1246
        connectMorphControllers ( animationListId, animationBindings );
 
1247
    }
 
1248
 
 
1249
    //------------------------------
 
1250
    void AnimationImporter::connectEffects ( 
 
1251
        const COLLADAFW::UniqueId& animationListId, 
 
1252
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
 
1253
    {
 
1254
        // Get the maya file.
 
1255
        FILE* file = getDocumentImporter ()->getFile ();
 
1256
 
 
1257
        // Get the node, which use this animation list.
 
1258
        EffectImporter* effectImporter = getDocumentImporter ()->getEffectImporter ();
 
1259
        const EffectAnimation* effectAnimation = effectImporter->findEffectAnimation ( animationListId );
 
1260
        if ( !effectAnimation ) return;
 
1261
 
 
1262
        // Get the maya node object for the id.
 
1263
        const COLLADAFW::UniqueId& effectId = effectAnimation->getAnimationSourceId ();
 
1264
        const MayaEffectList* mayaEffectList = effectImporter->findMayaEffects ( effectId );
 
1265
        if ( mayaEffectList != 0 )
 
1266
        {
 
1267
            for ( size_t effectIndex=0; effectIndex<mayaEffectList->size (); ++effectIndex )
 
1268
            {
 
1269
                const MayaDM::Lambert* lambertNode = (*mayaEffectList) [effectIndex];
 
1270
 
 
1271
                // Get the animated value type
 
1272
                const EffectAnimation::AnimatedValueType& animatedValueType = effectAnimation->getAnimatedValueType ();
 
1273
                switch ( animatedValueType )
 
1274
                {
 
1275
                case EffectAnimation::COLOR_OR_TEXTURE_AMBIENT:
 
1276
                case EffectAnimation::COLOR_OR_TEXTURE_DIFFUSE:
 
1277
                case EffectAnimation::COLOR_OR_TEXTURE_TRANSPARENCY:
 
1278
                case EffectAnimation::COLOR_OR_TEXTURE_EMISSION:
 
1279
                case EffectAnimation::COLOR_OR_TEXTURE_REFLECTED:
 
1280
                case EffectAnimation::COLOR_OR_TEXTURE_SPECULAR:
 
1281
                case EffectAnimation::COLOR_OR_TEXTURE_STANDARD:
 
1282
                    {
 
1283
                        // Get the animation curves of the current animated element.
 
1284
                        size_t numAnimationBindings = animationBindings.getCount ();
 
1285
                        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1286
                        {
 
1287
                            // Get the animation curve element of the current animation id.
 
1288
                            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1289
                            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1290
                            const std::vector<MayaDM::AnimCurve*>* animationCurves = findMayaDMAnimCurves ( animationId );
 
1291
                            if ( animationCurves == 0 ) continue;
 
1292
 
 
1293
                            // Connect all animation curves of the current animation.
 
1294
                            size_t animationCurveCount = animationCurves->size ();
 
1295
                            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1296
                            {
 
1297
                                const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
 
1298
                                MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
 
1299
 
 
1300
                                // Connect the animation curve and the current transform node.
 
1301
                                // connectAttr "lambert2_colorB.o" "lambert2.cb";
 
1302
                                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1303
                                switch ( animationClass )
 
1304
                                {
 
1305
                                case COLLADAFW::AnimationList::COLOR_R:
 
1306
                                    connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
 
1307
                                    break;
 
1308
                                case COLLADAFW::AnimationList::COLOR_G:
 
1309
                                    connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
 
1310
                                    break;
 
1311
                                case COLLADAFW::AnimationList::COLOR_B:
 
1312
                                    connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
 
1313
                                    break;
 
1314
                                case COLLADAFW::AnimationList::COLOR_A:
 
1315
                                    std::cerr << "Animation of for animation class \"COLOR_A\" not implemented!" << std::endl;
 
1316
                                    //connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorA () );
 
1317
                                    break;
 
1318
                                case COLLADAFW::AnimationList::COLOR_RGB:
 
1319
                                    if ( animationCurveCount == 1 )
 
1320
                                    {
 
1321
                                        connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColor () );
 
1322
                                    }
 
1323
                                    else
 
1324
                                    {
 
1325
                                        switch ( curveIndex )
 
1326
                                        {
 
1327
                                        case 0:
 
1328
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
 
1329
                                            break;
 
1330
                                        case 1:
 
1331
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
 
1332
                                            break;
 
1333
                                        case 2:
 
1334
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
 
1335
                                            break;
 
1336
                                        default:
 
1337
                                            std::cerr << "Too much animation curves for animation class \"COLOR_RGB\"!" << std::endl;
 
1338
                                        }
 
1339
                                    }
 
1340
                                    break;
 
1341
                                case COLLADAFW::AnimationList::COLOR_RGBA:
 
1342
                                    if ( animationCurveCount == 1 )
 
1343
                                    {
 
1344
                                        connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColor () );
 
1345
                                    }
 
1346
                                    else
 
1347
                                    {
 
1348
                                        switch ( curveIndex )
 
1349
                                        {
 
1350
                                        case 0:
 
1351
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
 
1352
                                            break;
 
1353
                                        case 1:
 
1354
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
 
1355
                                            break;
 
1356
                                        case 2:
 
1357
                                            connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
 
1358
                                            break;
 
1359
                                        case 3:
 
1360
                                            std::cerr << "Can't connect the animation of alpha values!" << std::endl;
 
1361
                                            break;
 
1362
                                        default:
 
1363
                                            std::cerr << "Too much animation curves for animation class \"COLOR_RGBA\"!" << std::endl;
 
1364
                                        }
 
1365
                                    }
 
1366
                                    break;
 
1367
                                default:
 
1368
                                    std::cerr << "Animation class for effect type \"COLOR_OR_TEXTURE_STANDARD_COLOR\" not implemented!" << std::endl;
 
1369
                                    break;
 
1370
                                }
 
1371
                            }
 
1372
                        }
 
1373
                    }
 
1374
                    break;
 
1375
                case EffectAnimation::FLOAT_OR_PARAM_COSINE_POWER:
 
1376
                case EffectAnimation::FLOAT_OR_PARAM_ECCENTRICITY:
 
1377
                case EffectAnimation::FLOAT_OR_PARAM_REFLECTIVITY:
 
1378
                case EffectAnimation::FLOAT_OR_PARAM_REFRACTIVE_INDEX:
 
1379
                    {
 
1380
                        // Get the animation curves of the current animated element.
 
1381
                        size_t numAnimationBindings = animationBindings.getCount ();
 
1382
                        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1383
                        {
 
1384
                            // Get the animation curve element of the current animation id.
 
1385
                            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1386
                            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1387
                            const std::vector<MayaDM::AnimCurve*>* animationCurves = findMayaDMAnimCurves ( animationId );
 
1388
                            if ( animationCurves == 0 ) continue;
 
1389
 
 
1390
                            // Connect all animation curves of the current animation.
 
1391
                            size_t animationCurveCount = animationCurves->size ();
 
1392
                            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1393
                            {
 
1394
                                const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
 
1395
                                MayaDM::AnimCurveTL* animCurveTU = (MayaDM::AnimCurveTL*) animCurve;
 
1396
 
 
1397
                                // Connect the animation curve and the current transform node.
 
1398
                                // connectAttr "lambert2_colorB.o" "lambert2.cb";
 
1399
                                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1400
                                switch ( animationClass )
 
1401
                                {
 
1402
                                case COLLADAFW::AnimationList::FLOAT:
 
1403
                                    switch ( animatedValueType )
 
1404
                                    {
 
1405
                                    case EffectAnimation::FLOAT_OR_PARAM_COSINE_POWER:
 
1406
                                        connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Phong*)lambertNode)->getCosinePower () );
 
1407
                                        break;
 
1408
                                    case EffectAnimation::FLOAT_OR_PARAM_ECCENTRICITY:
 
1409
                                        connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Blinn*)lambertNode)->getEccentricity () );
 
1410
                                        break;
 
1411
                                    case EffectAnimation::FLOAT_OR_PARAM_REFLECTIVITY:
 
1412
                                        connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Reflect*)lambertNode)->getReflectivity () );
 
1413
                                        break;
 
1414
                                    case EffectAnimation::FLOAT_OR_PARAM_REFRACTIVE_INDEX:
 
1415
                                        connectAttr ( file, animCurveTU->getOutput (),lambertNode->getRefractiveIndex () );
 
1416
                                        break;
 
1417
                                    default:
 
1418
                                        std::cerr << "Animation class for effect type \"FLOAT\" not implemented!" << std::endl;
 
1419
                                        break;
 
1420
                                    }
 
1421
                                    break;
 
1422
                                default:
 
1423
                                    std::cerr << "Animation class for effect type \"FLOAT_OR_PARAM_...\" not implemented!" << std::endl;
 
1424
                                    break;
 
1425
                                }
 
1426
                            }
 
1427
                        }
 
1428
                    }
 
1429
                    break;
 
1430
                default:
 
1431
                    std::cerr << "Animation on effect not supported!" << std::endl;
 
1432
                    break;
 
1433
                }
 
1434
            }
 
1435
        }
 
1436
    }
 
1437
 
 
1438
    //------------------------------
 
1439
    void AnimationImporter::connectMorphControllers ( 
 
1440
        const COLLADAFW::UniqueId& animationListId, 
 
1441
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
 
1442
    {
 
1443
        // Get the maya file.
 
1444
        FILE* file = getDocumentImporter ()->getFile ();
 
1445
 
 
1446
        // Get the node, which use this animation list.
 
1447
        ControllerImporter* controllerImporter = getDocumentImporter ()->getControllerImporter ();
 
1448
        const MorphAnimation* morphAnimation = controllerImporter->findMorphAnimation ( animationListId );
 
1449
        if ( !morphAnimation ) return;
 
1450
 
 
1451
        // connectAttr "animCurveTU1.output" "geom_QuadPatch01_morph1.weight[0]";
 
1452
        MayaDM::BlendShape blendShapeTarget = morphAnimation->getBlendShapeTarget ();
 
1453
 
 
1454
        // Get the animation curves of the current animated element.
 
1455
        size_t numAnimationBindings = animationBindings.getCount ();
 
1456
        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1457
        {
 
1458
            // Get the animation curve element of the current animation id.
 
1459
            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1460
            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1461
            const std::vector<MayaDM::AnimCurve*>* animationCurves = findMayaDMAnimCurves ( animationId );
 
1462
            if ( animationCurves == 0 ) continue;
 
1463
 
 
1464
            // Get the array binding.
 
1465
            size_t firstIndex = animationBinding.firstIndex;
 
1466
 
 
1467
            // Connect all animation curves of the current animation.
 
1468
            size_t animationCurveCount = animationCurves->size ();
 
1469
            if ( animationCurveCount > 1 )
 
1470
            {
 
1471
                std::cerr << "Multiple curves on morph animation not implemented!" << std::endl;
 
1472
                return;
 
1473
            }
 
1474
            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1475
            {
 
1476
                const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
 
1477
                MayaDM::AnimCurveTA* animCurveTA = (MayaDM::AnimCurveTA*) animCurve;
 
1478
 
 
1479
                // Connect the animation curve and the current transform node.
 
1480
                // connectAttr "pCube1_translateX.output" "pCube1.translateX";
 
1481
                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1482
                switch ( animationClass )
 
1483
                {
 
1484
                case COLLADAFW::AnimationList::ARRAY_ELEMENT_1D:
 
1485
                    {
 
1486
                        connectAttr ( file, animCurveTA->getOutput (), blendShapeTarget.getWeight ( firstIndex ) );
 
1487
                    }
 
1488
                    break;
 
1489
                default:
 
1490
                    {
 
1491
                        std::cerr << "Animation class for morph controller animation not implemented!" << std::endl;
 
1492
                        break;
 
1493
                    }
 
1494
                }
 
1495
            }
 
1496
        }
 
1497
    }
 
1498
 
 
1499
    //------------------------------
 
1500
    void AnimationImporter::connectTransforms ( 
 
1501
        const COLLADAFW::UniqueId& animationListId, 
 
1502
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
 
1503
    {
 
1504
        // Get the node, which use this animation list.
 
1505
        VisualSceneImporter* visualSceneImporter = getDocumentImporter ()->getVisualSceneImporter ();
 
1506
        const TransformAnimation* transformAnimation = visualSceneImporter->findTransformAnimation ( animationListId );
 
1507
        if ( !transformAnimation ) return;
 
1508
 
 
1509
        // Get the maya node object for the id.
 
1510
        const COLLADAFW::UniqueId& transformNodeId = transformAnimation->getAnimationSourceId ();
 
1511
        const MayaDM::Transform* transform = visualSceneImporter->findMayaDMTransform ( transformNodeId );
 
1512
        const MayaTransform::TransformPhase& transformPhase = transformAnimation->getTransformPhase ();
 
1513
        const bool isJointTransform = transformAnimation->getIsJointTransform ();
 
1514
 
 
1515
        const COLLADAFW::Transformation* transformation = transformAnimation->getTransformation ();
 
1516
        COLLADAFW::Transformation::TransformationType transformType = transformation->getTransformationType ();
 
1517
 
 
1518
        // Set the transformation information in depend of the transform type.
 
1519
        switch ( transformType )
 
1520
        {
 
1521
        case COLLADAFW::Transformation::ROTATE:
 
1522
            writeRotateConnections ( transformation, transformPhase, isJointTransform, animationBindings, transform );
 
1523
            break;
 
1524
        case COLLADAFW::Transformation::SCALE:
 
1525
            writeScaleConnections ( transformation, animationBindings, transform );
 
1526
            break;
 
1527
        case COLLADAFW::Transformation::SKEW:
 
1528
            std::cerr << "Import of animated skew not implemented!" << std::endl;
 
1529
//            writeSkewConnections ( transformation, animationList, transform );
 
1530
            break;
 
1531
        case COLLADAFW::Transformation::TRANSLATE:
 
1532
            writeTranslateConnections ( transformation, animationBindings, transform );
 
1533
            break;
 
1534
        default:
 
1535
            std::cerr << "Animation on transformation not supported!" << std::endl;
 
1536
            break;
 
1537
        }
 
1538
    }
 
1539
 
 
1540
    //------------------------------
 
1541
    void AnimationImporter::writeRotateConnections ( 
 
1542
        const COLLADAFW::Transformation* transformation, 
 
1543
        const MayaTransform::TransformPhase& transformPhase, 
 
1544
        const bool isJointTransform,
 
1545
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings, 
 
1546
        const MayaDM::Transform* transform )
 
1547
    {
 
1548
        // Get the maya file.
 
1549
        FILE* file = getDocumentImporter ()->getFile ();
 
1550
 
 
1551
        // Write the current rotation in a quaternion and 
 
1552
        // multiplicate with the existing rotation.
 
1553
        COLLADAFW::Rotate* rotation = ( COLLADAFW::Rotate* )transformation;
 
1554
        COLLADABU::Math::Vector3& axis = rotation->getRotationAxis ();
 
1555
 
 
1556
        // Get the animation curves of the current animated element.
 
1557
        size_t numAnimationBindings = animationBindings.getCount ();
 
1558
        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1559
        {
 
1560
            // Get the animation curve element of the current animation id.
 
1561
            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1562
            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1563
            const std::vector<MayaDM::AnimCurve*>* animationCurves = findMayaDMAnimCurves ( animationId );
 
1564
            if ( animationCurves == 0 ) continue;
 
1565
 
 
1566
            // TODO
 
1567
            size_t firstIndex = animationBinding.firstIndex;
 
1568
 
 
1569
            // Connect all animation curves of the current animation.
 
1570
            size_t animationCurveCount = animationCurves->size ();
 
1571
            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1572
            {
 
1573
                const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
 
1574
                MayaDM::AnimCurveTA* animCurveTA = (MayaDM::AnimCurveTA*) animCurve;
 
1575
 
 
1576
                // Connect the animation curve and the current transform node.
 
1577
                // connectAttr "pCube1_translateX.output" "pCube1.translateX";
 
1578
                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1579
                switch ( animationClass )
 
1580
                {
 
1581
                case COLLADAFW::AnimationList::ANGLE:
 
1582
                    {
 
1583
                        switch ( transformPhase )
 
1584
                        {
 
1585
                        case MayaTransform::PHASE_JOINT_ORIENT1:
 
1586
                        case MayaTransform::PHASE_JOINT_ORIENT2:
 
1587
                        case MayaTransform::PHASE_JOINT_ORIENT3:
 
1588
                            {
 
1589
                                if ( !isJointTransform )
 
1590
                                {
 
1591
                                    std::cerr << " Can't connect rotate animation, about the transform is not a joint node!" << std::endl;
 
1592
                                    return;
 
1593
                                }
 
1594
                                if ( COLLADABU::Math::Vector3::UNIT_X == axis )
 
1595
                                { 
 
1596
                                    connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientX () ); 
 
1597
                                }
 
1598
                                else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
 
1599
                                {
 
1600
                                    connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientY () );
 
1601
                                }
 
1602
                                else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
 
1603
                                {
 
1604
                                    connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientZ () );
 
1605
                                }
 
1606
                            }
 
1607
                            break;
 
1608
                        case MayaTransform::PHASE_ROTATE1:
 
1609
                        case MayaTransform::PHASE_ROTATE2:
 
1610
                        case MayaTransform::PHASE_ROTATE3:
 
1611
                            {
 
1612
                                if ( COLLADABU::Math::Vector3::UNIT_X == axis )
 
1613
                                {
 
1614
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateX () );
 
1615
                                }
 
1616
                                else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
 
1617
                                {
 
1618
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateY () );
 
1619
                                }
 
1620
                                else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
 
1621
                                {
 
1622
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateZ () );
 
1623
                                }
 
1624
                            }
 
1625
                            break;
 
1626
                        case MayaTransform::PHASE_ROTATE_ORIENT1:
 
1627
                        case MayaTransform::PHASE_ROTATE_ORIENT2:
 
1628
                        case MayaTransform::PHASE_ROTATE_ORIENT3:
 
1629
                            {
 
1630
                                if ( COLLADABU::Math::Vector3::UNIT_X == axis )
 
1631
                                {
 
1632
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisX () );
 
1633
                                }
 
1634
                                else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
 
1635
                                {
 
1636
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisY () );
 
1637
                                }
 
1638
                                else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
 
1639
                                {
 
1640
                                    connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisZ () );
 
1641
                                }
 
1642
                            }
 
1643
                            break;
 
1644
                        }
 
1645
                    }
 
1646
                    break;
 
1647
                case COLLADAFW::AnimationList::AXISANGLE:
 
1648
                    {
 
1649
                        switch ( transformPhase )
 
1650
                        {
 
1651
                        case MayaTransform::PHASE_JOINT_ORIENT1:
 
1652
                        case MayaTransform::PHASE_JOINT_ORIENT2:
 
1653
                        case MayaTransform::PHASE_JOINT_ORIENT3:
 
1654
                            {
 
1655
                                if ( !isJointTransform )
 
1656
                                {
 
1657
                                    std::cerr << " Can't connect rotate animation, about the transform is not a joint node!" << std::endl;
 
1658
                                    return;
 
1659
                                }
 
1660
                                connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrient () );
 
1661
                            }
 
1662
                            break;
 
1663
                        case MayaTransform::PHASE_ROTATE1:
 
1664
                        case MayaTransform::PHASE_ROTATE2:
 
1665
                        case MayaTransform::PHASE_ROTATE3:
 
1666
                            {
 
1667
                                connectAttr ( file, animCurveTA->getOutput (), transform->getRotate () );
 
1668
                            }
 
1669
                            break;
 
1670
                        case MayaTransform::PHASE_ROTATE_ORIENT1:
 
1671
                        case MayaTransform::PHASE_ROTATE_ORIENT2:
 
1672
                        case MayaTransform::PHASE_ROTATE_ORIENT3:
 
1673
                            {
 
1674
                                connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxis () );
 
1675
                            }
 
1676
                            break;
 
1677
                        }
 
1678
                    }
 
1679
                    break;
 
1680
                default:
 
1681
                    {
 
1682
                        std::cerr << "Animation class for transformation type \"ROTATE\" not implemented!" << std::endl;
 
1683
                        break;
 
1684
                    }
 
1685
                }
 
1686
            }
 
1687
        }
 
1688
    }
 
1689
 
 
1690
    //------------------------------
 
1691
    void AnimationImporter::writeScaleConnections ( 
 
1692
        const COLLADAFW::Transformation* transformation, 
 
1693
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings, 
 
1694
        const MayaDM::Transform* transform )
 
1695
    {
 
1696
        // Get the scale.
 
1697
        COLLADAFW::Scale* scale = ( COLLADAFW::Scale* )transformation;
 
1698
 
 
1699
        // Get the maya file.
 
1700
        FILE* file = getDocumentImporter ()->getFile ();
 
1701
 
 
1702
        // Get the animation curves of the current animated element.
 
1703
        size_t numAnimationBindings = animationBindings.getCount ();
 
1704
        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1705
        {
 
1706
            // Get the animation curve element of the current animation id.
 
1707
            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1708
            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1709
            const std::vector<MayaDM::AnimCurve*>* animCurves = findMayaDMAnimCurves ( animationId );
 
1710
            if ( animCurves == 0 ) continue;
 
1711
 
 
1712
            // Connect all animation curves of the current animation.
 
1713
            size_t animationCurveCount = animCurves->size ();
 
1714
            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1715
            {
 
1716
                const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
 
1717
                MayaDM::AnimCurveTL* animCurveTU = (MayaDM::AnimCurveTL*) animCurve;
 
1718
 
 
1719
                // Connect the animation curve and the current transform node.
 
1720
                // connectAttr "pCube1_translateX.output" "pCube1.translateX";
 
1721
                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1722
                switch ( animationClass )
 
1723
                {
 
1724
                case COLLADAFW::AnimationList::POSITION_X:
 
1725
                    connectAttr ( file, animCurveTU->getOutput (), transform->getScaleX() );
 
1726
                    break;
 
1727
                case COLLADAFW::AnimationList::POSITION_Y:
 
1728
                    connectAttr ( file, animCurveTU->getOutput (), transform->getScaleY() );
 
1729
                    break;
 
1730
                case COLLADAFW::AnimationList::POSITION_Z:
 
1731
                    connectAttr ( file, animCurveTU->getOutput (), transform->getScaleZ() );
 
1732
                    break;
 
1733
                case COLLADAFW::AnimationList::POSITION_XYZ:
 
1734
                    if ( animationCurveCount == 1 )
 
1735
                    {
 
1736
                        connectAttr ( file, animCurveTU->getOutput (), transform->getScale() );
 
1737
                    }
 
1738
                    else
 
1739
                    {
 
1740
                        switch ( curveIndex )
 
1741
                        {
 
1742
                        case 0:
 
1743
                            connectAttr ( file, animCurveTU->getOutput (), transform->getScaleX() );
 
1744
                            break;
 
1745
                        case 1:
 
1746
                            connectAttr ( file, animCurveTU->getOutput (), transform->getScaleY() );
 
1747
                            break;
 
1748
                        case 2:
 
1749
                            connectAttr ( file, animCurveTU->getOutput (), transform->getScaleZ() );
 
1750
                            break;
 
1751
                        default:
 
1752
                            std::cerr << "Too much animation curves for animation class \"POSITION_XYZ\" in transformation type \"SCALE\"!" << std::endl;
 
1753
                            break;
 
1754
                        }
 
1755
                    }
 
1756
                    break;
 
1757
                default:
 
1758
                    std::cerr << "Animation class for transformation type \"SCALE\" not implemented!" << std::endl;
 
1759
                    break;
 
1760
                }
 
1761
            }
 
1762
        }
 
1763
    }
 
1764
 
 
1765
    //------------------------------
 
1766
    void AnimationImporter::writeSkewConnections ( 
 
1767
        const COLLADAFW::Transformation* transformation, 
 
1768
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings, 
 
1769
        const MayaDM::Transform* transform )
 
1770
    {
 
1771
        // Get the skew.
 
1772
        COLLADAFW::Skew* skew = ( COLLADAFW::Skew* )transformation;
 
1773
 
 
1774
        float s = tanf ( COLLADABU::Math::Utils::degToRadF ( skew->getAngle () ) );
 
1775
 
 
1776
        const COLLADABU::Math::Vector3& rotateAxis = skew->getRotateAxis();
 
1777
        const COLLADABU::Math::Vector3& translateAxis = skew->getTranslateAxis();
 
1778
 
 
1779
//         MMatrix matrix;
 
1780
//         skewValuesToMayaMatrix ( skew, matrix );
 
1781
//         MTransformationMatrix tm ( matrix );
 
1782
// 
 
1783
//         double shear[3];
 
1784
//         tm.getShear ( shear, MSpace::kTransform );
 
1785
 
 
1786
        // Get the maya file.
 
1787
        FILE* file = getDocumentImporter ()->getFile ();
 
1788
 
 
1789
        // Get the animation curves of the current animated element.
 
1790
        size_t numAnimationBindings = animationBindings.getCount ();
 
1791
        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1792
        {
 
1793
            // Get the animation curve element of the current animation id.
 
1794
            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1795
            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1796
            const std::vector<MayaDM::AnimCurve*>* animCurves = findMayaDMAnimCurves ( animationId );
 
1797
            if ( animCurves == 0 ) continue;
 
1798
 
 
1799
            // Connect all animation curves of the current animation.
 
1800
            size_t animationCurveCount = animCurves->size ();
 
1801
            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1802
            {
 
1803
                const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
 
1804
                MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
 
1805
 
 
1806
                // Connect the animation curve and the current transform node.
 
1807
                // connectAttr "pCube1_translateX.output" "pCube1.translateX";
 
1808
                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1809
                switch ( animationClass )
 
1810
                {
 
1811
                    //TODO
 
1812
//                 case COLLADAFW::AnimationList::POSITION_X:
 
1813
//                     connectAttr ( file, animationCurve->getOutput (), transform->getShearX() );
 
1814
//                     break;
 
1815
//                 case COLLADAFW::AnimationList::POSITION_Y:
 
1816
//                     connectAttr ( file, animationCurve->getOutput (), transform->getShearY() );
 
1817
//                     break;
 
1818
//                 case COLLADAFW::AnimationList::POSITION_Z:
 
1819
//                     connectAttr ( file, animationCurve->getOutput (), transform->getShearZ() );
 
1820
//                     break;
 
1821
                case COLLADAFW::AnimationList::POSITION_XYZ:
 
1822
                    connectAttr ( file, animCurveTL->getOutput (), transform->getShear() );
 
1823
                    break;
 
1824
                default:
 
1825
                    std::cerr << "Animation class for transformation type \"SHEAR\" not implemented!" << std::endl;
 
1826
                    break;
 
1827
                }
 
1828
            }
 
1829
        }
 
1830
    }
 
1831
 
 
1832
    //------------------------------
 
1833
    void AnimationImporter::writeTranslateConnections ( 
 
1834
        const COLLADAFW::Transformation* transformation, 
 
1835
        const COLLADAFW::AnimationList::AnimationBindings& animationBindings, 
 
1836
        const MayaDM::Transform* transform )
 
1837
    {
 
1838
        COLLADAFW::Translate* translate = ( COLLADAFW::Translate* )transformation;
 
1839
        COLLADABU::Math::Vector3 translation = translate->getTranslation ();
 
1840
 
 
1841
        // Get the maya file.
 
1842
        FILE* file = getDocumentImporter ()->getFile ();
 
1843
 
 
1844
        // Get the animation curves of the current animation list.
 
1845
        size_t numAnimationBindings = animationBindings.getCount ();
 
1846
        for ( size_t i=0; i<numAnimationBindings; ++i )
 
1847
        {
 
1848
            const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i]; 
 
1849
 
 
1850
            // Get the animation curve element of the current animation id.
 
1851
            const COLLADAFW::UniqueId& animationId = animationBinding.animation;
 
1852
            const std::vector<MayaDM::AnimCurve*>* animCurves = findMayaDMAnimCurves ( animationId );
 
1853
            if ( animCurves == 0 ) continue;
 
1854
 
 
1855
            // Connect all animation curves of the current animation.
 
1856
            size_t animationCurveCount = animCurves->size ();
 
1857
            for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
 
1858
            {
 
1859
                const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
 
1860
                MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
 
1861
 
 
1862
                // Connect the animation curve and the current transform node.
 
1863
                // connectAttr "pCube1_translateX.output" "pCube1.translateX";
 
1864
                const COLLADAFW::AnimationList::AnimationClass& animationClass = animationBinding.animationClass;
 
1865
                switch ( animationClass )
 
1866
                {
 
1867
                case COLLADAFW::AnimationList::POSITION_X:
 
1868
                    connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateX () );
 
1869
                    break;
 
1870
                case COLLADAFW::AnimationList::POSITION_Y:
 
1871
                    connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateY () );
 
1872
                    break;
 
1873
                case COLLADAFW::AnimationList::POSITION_Z:
 
1874
                    connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateZ () );
 
1875
                    break;
 
1876
                case COLLADAFW::AnimationList::POSITION_XYZ:
 
1877
                    {
 
1878
                        if ( animationCurveCount == 1 )
 
1879
                        {
 
1880
                            connectAttr ( file, animCurveTL->getOutput (), transform->getTranslate () );
 
1881
                        }
 
1882
                        else
 
1883
                        {
 
1884
                            switch ( curveIndex )
 
1885
                            {
 
1886
                            case 0:
 
1887
                                connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateX () );
 
1888
                                break;
 
1889
                            case 1:
 
1890
                                connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateY () );
 
1891
                                break;
 
1892
                            case 2:
 
1893
                                connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateZ () );
 
1894
                                break;
 
1895
                            default:
 
1896
                                std::cerr << "Too much animation curves for animation class \"POSITION_XYZ\" in transformation type \"TRANSLATE\"!" << std::endl;
 
1897
                            }
 
1898
                        }
 
1899
                    }
 
1900
                    break;
 
1901
                default:
 
1902
                    std::cerr << "Animation class for transformation type \"TRANSLATE\" not implemented!" << std::endl;
 
1903
                    break;
 
1904
                }
 
1905
            }
 
1906
        }
 
1907
    }
 
1908
 
 
1909
} // namespace DAE2MA