2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of DAE2MA.
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
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"
20
#include "COLLADAFWFloatOrDoubleArray.h"
21
#include "COLLADAFWScale.h"
22
#include "COLLADAFWTranslate.h"
24
#include <MayaDMAnimCurveTA.h>
25
#include <MayaDMAnimCurveTU.h>
26
#include <MayaDMCommands.h>
27
#include <MayaDMScript.h>
33
/** The standard name for an animation. */
34
const String AnimationImporter::ANIMATION_NAME = "anim";
36
/** The framerate of the animation. */
37
const double AnimationImporter::ANIM_FRAMERATE = 24;
40
//------------------------------
41
AnimationImporter::AnimationImporter( DocumentImporter* documentImporter )
42
: BaseImporter ( documentImporter )
46
//------------------------------
47
AnimationImporter::~AnimationImporter()
49
std::map<COLLADAFW::UniqueId, std::vector<MayaDM::AnimCurve*> >::iterator it = mMayaDMAnimationCurves.begin ();
50
while ( it != mMayaDMAnimationCurves.end () )
52
std::vector<MayaDM::AnimCurve*> animCurves = it->second;
53
for ( size_t i=0; i<animCurves.size (); ++i )
55
MayaDM::AnimCurve* animCurve = animCurves [i];
62
mMayaDMAnimationCurves.clear ();
65
//------------------------------
66
void AnimationImporter::importAnimation ( const COLLADAFW::Animation* animation )
68
// Check if the animation is already imported.
69
const COLLADAFW::UniqueId& animationId = animation->getUniqueId ();
70
if ( findAnimation ( animationId ) ) return;
72
// Push the animation id in the list of imported ids.
73
mAnimationIds.push_back ( animationId );
75
// Import the animation data.
76
const COLLADAFW::Animation::AnimationType& animationType = animation->getAnimationType ();
77
switch ( animationType )
79
case COLLADAFW::Animation::ANIMATION_CURVE:
81
COLLADAFW::AnimationCurve* animationCurve = ( COLLADAFW::AnimationCurve* ) animation;
82
importAnimationCurve ( animationCurve );
85
case COLLADAFW::Animation::ANIMATION_FORMULA:
92
//------------------------------
93
void AnimationImporter::importAnimationCurve ( COLLADAFW::AnimationCurve* animationCurve )
95
const COLLADAFW::PhysicalDimension& physicalDimension = animationCurve->getInPhysicalDimension ();
96
if ( physicalDimension != COLLADAFW::PHYSICAL_DIMENSION_TIME )
98
std::cerr << "Import of other physical dimension then TIME not supported: " << physicalDimension << std::endl;
102
// Write the key time values
103
const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = animationCurve->getInterpolationType ();
104
switch ( interpolationType )
106
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
108
TangentType tangentType = TANGENT_TYPE_FIXED;
109
writeAnimationCurve ( animationCurve, tangentType );
112
case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
114
std::cerr << "Unknown animation interpolation type: INTERPOLATION_BSPLINE" << std::endl;
117
case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
119
std::cerr << "Unknown animation interpolation type: INTERPOLATION_CARDINAL" << std::endl;
122
case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
124
std::cerr << "Unknown animation interpolation type: INTERPOLATION_HERMITE" << std::endl;
127
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
129
TangentType tangentType = TANGENT_TYPE_LINEAR;
130
writeAnimationCurve ( animationCurve, tangentType );
133
case COLLADAFW::AnimationCurve::INTERPOLATION_MIXED:
135
writeAnimationCurveByKeys ( animationCurve );
138
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
140
TangentType tangentType = TANGENT_TYPE_STEP;
141
writeAnimationCurve ( animationCurve, tangentType );
144
case COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN:
146
TangentType tangentType = TANGENT_TYPE_CLAMPED;
147
writeAnimationCurve ( animationCurve, tangentType );
148
//std::cerr << "Unknown animation interpolation type!" << std::endl;
156
//------------------------------
157
void AnimationImporter::writeAnimationCurve (
158
const COLLADAFW::AnimationCurve* animationCurve,
159
const TangentType& tangentType /*= TANGENT_TYPE_DEFAULT*/ )
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 ();
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;
170
const COLLADAFW::PhysicalDimensionArray& outPhysicalDimensions = animationCurve->getOutPhysicalDimensions ();
171
size_t outDimension2 = outPhysicalDimensions.getCount ();
173
if ( numInputValues != numOutputValues || outDimension != outDimension2 )
175
std::cerr << "Invalid animation!" << std::endl;
179
// The uniqueId of the animation.
180
const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
182
// Create a curve for every animated element.
183
for ( size_t outputIndex=0; outputIndex<outDimension; ++outputIndex )
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 );
195
FILE* file = getDocumentImporter ()->getFile ();
197
// Create the animation curve.
198
MayaDM::AnimCurve* animCurve = 0;
200
const COLLADAFW::PhysicalDimension& outPhysicalDimension = outPhysicalDimensions [outputIndex];
201
switch ( outPhysicalDimension )
203
case COLLADAFW::PHYSICAL_DIMENSION_LENGTH:
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 ) )
209
animCurve = new MayaDM::AnimCurveTL ( file, animationName );
210
animCurve->setTangentType ( tangentType );
211
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTL*)animCurve, outputIndex );
215
animCurve = new MayaDM::AnimCurveTU ( file, animationName );
216
animCurve->setTangentType ( tangentType );
217
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTU*)animCurve, outputIndex );
221
case COLLADAFW::PHYSICAL_DIMENSION_ANGLE:
223
animCurve = new MayaDM::AnimCurveTA ( file, animationName );
224
animCurve->setTangentType ( tangentType );
225
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTA*)animCurve, outputIndex );
228
case COLLADAFW::PHYSICAL_DIMENSION_COLOR:
229
case COLLADAFW::PHYSICAL_DIMENSION_NUMBER:
231
animCurve = new MayaDM::AnimCurveTU ( file, animationName );
232
animCurve->setTangentType ( tangentType );
233
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTU*)animCurve, outputIndex );
236
case COLLADAFW::PHYSICAL_DIMENSION_TIME:
237
std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_TIME" << std::endl;
240
std::cerr << "Unknown physical dimension!" << std::endl;
244
// Add the original id attribute.
245
String colladaId = animationCurve->getOriginalId ();
246
if ( !colladaId.empty () )
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 );
251
// // TODO Add the attributes for all the extra tags.
252
// setExtraData ( animationCurve->getExtraDataArray () );
254
// Push the maya animation curve element in a list.
255
const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
256
mMayaDMAnimationCurves [animationId].push_back ( animCurve );
258
// True makes the in- and out-tangents move together. False makes them move separately.
259
setKeyTangentLocks ( animationCurve, animCurve, false );
261
// Set the in- and out-tangents
262
if ( tangentType != TANGENT_TYPE_LINEAR && tangentType != TANGENT_TYPE_STEP )
264
setWeightedInTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
265
setWeightedOutTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
270
//------------------------------
271
const std::vector<MayaDM::AnimCurve*>* AnimationImporter::findMayaDMAnimCurves (
272
const COLLADAFW::UniqueId& animationId )
274
const std::map<COLLADAFW::UniqueId, std::vector<MayaDM::AnimCurve*> >::iterator it = mMayaDMAnimationCurves.find ( animationId );
275
if ( it != mMayaDMAnimationCurves.end () )
277
return &(it->second);
282
//------------------------------
283
void AnimationImporter::writeAnimationCurveByKeys (
284
const COLLADAFW::AnimationCurve* animationCurve )
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;
291
const COLLADAFW::PhysicalDimensionArray& outPhysicalDimensions = animationCurve->getOutPhysicalDimensions ();
292
size_t outDimension2 = outPhysicalDimensions.getCount ();
294
size_t keyCount = animationCurve->getKeyCount ();
295
if ( numOutputValues != keyCount || outDimension != outDimension2 )
297
std::cerr << "Animation not valid!" << std::endl;
301
// The uniqueId of the element.
302
const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
304
// Create a curve for every animated element.
305
for ( size_t outputIndex=0; outputIndex<outDimension; ++outputIndex )
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 );
316
// Create the animation curve.
317
FILE* file = getDocumentImporter ()->getFile ();
319
// Flag, if the values of the tangents should be normalized.
320
bool normalizeTangents = true;
322
// Create the animation curve.
323
MayaDM::AnimCurve* animCurve = 0;
325
const COLLADAFW::PhysicalDimension& outPhysicalDimension = outPhysicalDimensions [outputIndex];
326
switch ( outPhysicalDimension )
328
case COLLADAFW::PHYSICAL_DIMENSION_LENGTH:
330
animCurve = new MayaDM::AnimCurveTL ( file, animationName );
331
animCurve->setTangentType ( TANGENT_TYPE_FIXED );
332
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTL*)animCurve, outputIndex );
335
case COLLADAFW::PHYSICAL_DIMENSION_ANGLE:
337
animCurve = new MayaDM::AnimCurveTA ( file, animationName );
338
animCurve->setTangentType ( TANGENT_TYPE_FIXED );
339
setKeyTimeValues ( animationCurve, (MayaDM::AnimCurveTA*)animCurve, outputIndex );
340
normalizeTangents = false;
343
case COLLADAFW::PHYSICAL_DIMENSION_TIME:
344
std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_TIME" << std::endl;
346
case COLLADAFW::PHYSICAL_DIMENSION_COLOR:
347
std::cerr << "Physical dimension not supported: PHYSICAL_DIMENSION_COLOR" << std::endl;
349
case COLLADAFW::PHYSICAL_DIMENSION_NUMBER:
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;
358
std::cerr << "Unknown physical dimension!" << std::endl;
362
// Add the original id attribute.
363
String colladaId = animationCurve->getOriginalId ();
364
if ( !colladaId.empty () )
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 );
369
// // TODO Add the attributes for all the extra tags.
370
// setExtraData ( animationCurve->getExtraDataArray () );
372
// Push the maya animation curve element in a list.
373
const COLLADAFW::UniqueId& animationId = animationCurve->getUniqueId ();
374
mMayaDMAnimationCurves [animationId].push_back ( animCurve );
376
// Set key tangent in and out types
377
setKeyTangentInTypes ( animationCurve, animCurve );
378
setKeyTangentOutTypes ( animationCurve, animCurve );
380
// True makes the in- and out-tangents move together. False makes them move separately.
381
setKeyTangentLocks ( animationCurve, animCurve, false );
383
// Set the in- and out-tangents
384
setWeightedInTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
385
setWeightedOutTangents ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
389
//------------------------------
390
void AnimationImporter::setKeyTimeValues (
391
const COLLADAFW::AnimationCurve* animationCurve,
392
MayaDM::AnimCurveTL* animCurveTL,
393
const size_t outputIndex )
395
// The input is always the time
396
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
397
size_t numInputValues = inputValuesArray.getValuesCount ();
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;
404
size_t keyCount = animationCurve->getKeyCount ();
405
if ( numInputValues != numOutputValues || numInputValues != keyCount )
407
std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
412
animCurveTL->startKeyTimeValue ( 0, keyCount-1 );
413
MayaDM::AnimCurveTL::KeyTimeValue keyTimeValue;
415
double inputValue = 0;
416
double outputValue = 0;
418
for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
420
inputValue = getDoubleValue ( inputValuesArray, inputIndex );
421
size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
422
outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
424
// Framerate: 24 frames per second...
425
keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
426
keyTimeValue.keyValue = outputValue;
427
animCurveTL->appendKeyTimeValue ( keyTimeValue );
429
// Set the maya playback options (start and end time).
430
mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
433
animCurveTL->endKeyTimeValue ();
436
//------------------------------
437
void AnimationImporter::setKeyTimeValues (
438
const COLLADAFW::AnimationCurve* animationCurve,
439
MayaDM::AnimCurveTU* animCurveTU,
440
const size_t outputIndex )
442
// The input is always the time
443
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
444
size_t numInputValues = inputValuesArray.getValuesCount ();
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;
451
size_t keyCount = animationCurve->getKeyCount ();
452
if ( numInputValues != numOutputValues || numInputValues != keyCount )
454
std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
459
animCurveTU->startKeyTimeValue ( 0, keyCount-1 );
460
MayaDM::AnimCurveTU::KeyTimeValue keyTimeValue;
462
double inputValue = 0;
463
double outputValue = 0;
465
for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
467
inputValue = getDoubleValue ( inputValuesArray, inputIndex );
468
size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
469
outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
471
// Framerate: 24 frames per second...
472
keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
473
keyTimeValue.keyValue = outputValue;
474
animCurveTU->appendKeyTimeValue ( keyTimeValue );
476
// Set the maya playback options (start and end time).
477
mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
480
animCurveTU->endKeyTimeValue ();
483
//------------------------------
484
void AnimationImporter::setKeyTimeValues (
485
const COLLADAFW::AnimationCurve* animationCurve,
486
MayaDM::AnimCurveTA* animCurveTA,
487
const size_t outputIndex )
489
// The input is always the time
490
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
491
size_t numInputValues = inputValuesArray.getValuesCount ();
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;
498
size_t keyCount = animationCurve->getKeyCount ();
499
if ( numInputValues != numOutputValues || numInputValues != keyCount )
501
std::cerr << "AnimationImporter::setKeyTimeValues(): Invalid animation!" << std::endl;
506
animCurveTA->startKeyTimeValue ( 0, keyCount-1 );
507
MayaDM::AnimCurveTA::KeyTimeValue keyTimeValue;
509
double inputValue = 0;
510
double outputValue = 0;
512
for ( size_t inputIndex=0; inputIndex<keyCount; ++inputIndex )
514
inputValue = getDoubleValue ( inputValuesArray, inputIndex );
515
size_t currentOutputIndex = inputIndex*outDimension + outputIndex;
516
outputValue = getDoubleValue ( outputValuesArray, currentOutputIndex );
518
// Framerate: 24 frames per second...
519
keyTimeValue.keyTime = inputValue * ANIM_FRAMERATE;
520
keyTimeValue.keyValue = outputValue;
521
animCurveTA->appendKeyTimeValue ( keyTimeValue );
523
// Set the maya playback options (start and end time).
524
mPlaybackOptions.setTimeValue ( inputValue * ANIM_FRAMERATE );
527
animCurveTA->endKeyTimeValue ();
530
//------------------------------
531
void AnimationImporter::setWeightedInTangents (
532
const COLLADAFW::AnimationCurve* animationCurve,
533
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
534
const size_t outputIndex,
535
MayaDM::AnimCurve* animCurve )
537
setWeightedInTangentXValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
538
setWeightedInTangentYValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
541
//------------------------------
542
void AnimationImporter::setWeightedInTangentXValues (
543
const COLLADAFW::AnimationCurve* animationCurve,
544
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
545
const size_t outputIndex,
546
MayaDM::AnimCurve* animCurve )
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;
554
// The time input and the output.
555
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
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;
563
const size_t outDimension = animationCurve->getOutDimension ();
565
// Write the in-tangent x values.
566
animCurve->startKeyTanInX ( 0, keyCount-1 );
567
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
569
if ( mixedInterpolation )
570
interpolationType = animationCurve->getInterpolationTypes () [keyPosition];
572
switch ( interpolationType )
574
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
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 );
583
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
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 );
593
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
595
animCurve->appendKeyTanInX ( 0 );
600
std::cerr << "Interpolation type not supported!" << std::endl;
601
animCurve->appendKeyTanInX ( 0 );
606
animCurve->endKeyTanInX ();
609
//------------------------------
610
void AnimationImporter::setWeightedInTangentYValues (
611
const COLLADAFW::AnimationCurve* animationCurve,
612
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
613
const size_t outputIndex,
614
MayaDM::AnimCurve* animCurve )
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;
622
// The time input values and the output values.
623
const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
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;
631
const size_t outDimension = animationCurve->getOutDimension ();
633
// Write the in-tangent y values
634
animCurve->startKeyTanInY ( 0, keyCount-1 );
635
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
637
if ( mixedInterpolation )
638
interpolationType = animationCurve->getInterpolationTypes () [keyPosition];
640
switch ( interpolationType )
642
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
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 );
654
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
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 );
667
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
669
animCurve->appendKeyTanInX ( 0 );
674
std::cerr << "Interpolation type not supported!" << std::endl;
675
animCurve->appendKeyTanInX ( 0 );
680
animCurve->endKeyTanInY ();
683
//------------------------------
684
void AnimationImporter::setWeightedOutTangents (
685
const COLLADAFW::AnimationCurve* animationCurve,
686
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
687
const size_t outputIndex,
688
MayaDM::AnimCurve* animCurve )
690
setWeightedOutTangentXValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
691
setWeightedOutTangentYValues ( animationCurve, outPhysicalDimension, outputIndex, animCurve );
694
//------------------------------
695
void AnimationImporter::setWeightedOutTangentXValues (
696
const COLLADAFW::AnimationCurve* animationCurve,
697
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
698
const size_t outputIndex,
699
MayaDM::AnimCurve* animCurve )
701
// The time input values and the output values.
702
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
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;
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;
717
const size_t outDimension = animationCurve->getOutDimension ();
719
// Write the in-tangent x values.
720
animCurve->startKeyTanOutX ( 0, keyCount-1 );
721
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
723
if ( mixedInterpolation )
724
interpolationType = interpolationTypeArray [keyPosition];
726
switch ( interpolationType )
728
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
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 );
737
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
739
double inputValue = getDoubleValue ( inputValuesArray, keyPosition );
740
double nextInputValue = 0;
741
if ( keyPosition < keyCount-1 )
743
nextInputValue = getDoubleValue ( inputValuesArray, keyPosition+1 );
744
double resultX = nextInputValue - inputValue;
745
animCurve->appendKeyTanInX ( resultX );
747
else animCurve->appendKeyTanInX ( 1 );
750
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
752
animCurve->appendKeyTanInX ( 0 );
757
std::cerr << "Interpolation type not supported!" << std::endl;
758
animCurve->appendKeyTanInX ( 0 );
763
animCurve->endKeyTanOutX ();
766
//------------------------------
767
void AnimationImporter::setWeightedOutTangentYValues (
768
const COLLADAFW::AnimationCurve* animationCurve,
769
const COLLADAFW::PhysicalDimension& outPhysicalDimension,
770
const size_t outputIndex,
771
MayaDM::AnimCurve* animCurve )
773
// The time input values and the output values.
774
const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
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;
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;
789
const size_t outDimension = animationCurve->getOutDimension ();
791
// Write the in-tangent y values
792
animCurve->startKeyTanOutY ( 0, keyCount-1 );
793
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
795
if ( mixedInterpolation )
796
interpolationType = interpolationTypeArray [keyPosition];
798
switch ( interpolationType )
800
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
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 );
812
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
814
size_t outputValueIndex = keyPosition*outDimension + outputIndex;
815
double outputValue = getDoubleValue ( outputValuesArray, outputValueIndex );
816
double nextOutputValue = 0;
817
if ( keyPosition < keyCount-1 )
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 );
825
else animCurve->appendKeyTanInX ( 0 );
828
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
830
animCurve->appendKeyTanInX ( 0 );
835
std::cerr << "Interpolation type not supported!" << std::endl;
836
animCurve->appendKeyTanInX ( 0 );
841
animCurve->endKeyTanOutY ();
844
//------------------------------
845
void AnimationImporter::setNonWeightedInTangents (
846
const COLLADAFW::AnimationCurve* animationCurve,
847
MayaDM::AnimCurve* animCurve,
848
const size_t outputIndex,
849
const bool normalize /*= true*/ )
851
// The input is always the time
852
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
855
const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
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;
863
const size_t outDimension = animationCurve->getOutDimension ();
865
// Write the in-tangent x values.
866
animCurve->startKeyTanInX ( 0, keyCount-1 );
867
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
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;
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 )
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;
890
else normedDeltaX = deltaX;
893
// Set the normed x delta value.
894
animCurve->appendKeyTanInX ( normedDeltaX );
896
animCurve->endKeyTanInX ();
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 )
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 )
911
// Set the key tangent in y value.
913
if ( deltaY > 0 ) normedDeltaY = 1;
915
else normedDeltaY = deltaY;
917
// Set the normed y delta value.
918
animCurve->appendKeyTanInY ( normedDeltaY );
920
animCurve->endKeyTanInY ();
923
//------------------------------
924
void AnimationImporter::setNonWeightedOutTangents (
925
const COLLADAFW::AnimationCurve* animationCurve,
926
MayaDM::AnimCurve* animCurve,
927
const size_t outputIndex,
928
const bool normalize /*= true*/ )
930
// The input is always the time
931
const COLLADAFW::FloatOrDoubleArray& inputValuesArray = animationCurve->getInputValues ();
934
const COLLADAFW::FloatOrDoubleArray& outputValuesArray = animationCurve->getOutputValues ();
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;
942
const size_t outDimension = animationCurve->getOutDimension ();
944
// Write the in-tangent x values.
945
animCurve->startKeyTanOutX ( 0, keyCount-1 );
946
for ( size_t keyPosition=0; keyPosition<keyCount; ++keyPosition )
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;
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 )
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;
969
else normedDeltaX = deltaX * -1;
972
// Set the key tangent in x value.
973
animCurve->appendKeyTanOutX ( normedDeltaX );
975
animCurve->endKeyTanOutX ();
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 )
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 )
990
// Set the key tangent out y value.
992
if ( deltaY > 0 ) normedDeltaY = -1;
994
else normedDeltaY = deltaY;
996
// Set the key tangent in y value.
997
animCurve->appendKeyTanOutY ( normedDeltaY );
999
animCurve->endKeyTanOutY ();
1002
//------------------------------
1003
void AnimationImporter::setKeyTangentInTypes (
1004
const COLLADAFW::AnimationCurve* animationCurve,
1005
MayaDM::AnimCurve* animCurve )
1007
TangentType keyTangentInType;
1009
// The interpolation types
1010
const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypes = animationCurve->getInterpolationTypes ();
1011
size_t numInterpolationTypes = interpolationTypes.getCount ();
1013
size_t keyCount = animationCurve->getKeyCount ();
1014
if ( numInterpolationTypes != keyCount )
1016
std::cerr << "AnimationImporter::setKeyTangentInType(): Invalid animation!" << std::endl;
1020
animCurve->startKeyTanInType ( 0, keyCount-1 );
1021
for ( size_t i=0; i<keyCount; ++i )
1023
const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = interpolationTypes [i];
1024
switch ( interpolationType )
1026
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
1027
keyTangentInType = TANGENT_TYPE_FIXED;
1029
case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
1030
keyTangentInType = TANGENT_TYPE_FIXED;
1032
case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
1033
keyTangentInType = TANGENT_TYPE_FIXED;
1035
case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
1036
keyTangentInType = TANGENT_TYPE_FIXED;
1038
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
1039
keyTangentInType = TANGENT_TYPE_LINEAR;
1041
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
1042
keyTangentInType = TANGENT_TYPE_STEP;
1045
std::cerr << "Unknown interpolation type in mixed interpolations!" << std::endl;
1046
keyTangentInType = TANGENT_TYPE_DEFAULT;
1048
animCurve->appendKeyTanInType ( keyTangentInType );
1050
animCurve->endKeyTanInType ();
1053
//------------------------------
1054
void AnimationImporter::setKeyTangentOutTypes (
1055
const COLLADAFW::AnimationCurve* animationCurve,
1056
MayaDM::AnimCurve* animCurve )
1058
TangentType keyTangentOutType;
1060
// The interpolation types
1061
const COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypes = animationCurve->getInterpolationTypes ();
1062
size_t numInterpolationTypes = interpolationTypes.getCount ();
1064
size_t keyCount = animationCurve->getKeyCount ();
1065
if ( numInterpolationTypes != keyCount )
1067
std::cerr << "AnimationImporter::setKeyTangentOutType(): Invalid animation!" << std::endl;
1071
animCurve->startKeyTanOutType ( 0, keyCount-1 );
1072
for ( size_t i=0; i<keyCount; ++i )
1074
const COLLADAFW::AnimationCurve::InterpolationType& interpolationType = interpolationTypes [i];
1075
switch ( interpolationType )
1077
case COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER:
1078
keyTangentOutType = TANGENT_TYPE_FIXED;
1080
case COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE:
1081
keyTangentOutType = TANGENT_TYPE_FIXED;
1083
case COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL:
1084
keyTangentOutType = TANGENT_TYPE_FIXED;
1086
case COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE:
1087
keyTangentOutType = TANGENT_TYPE_FIXED;
1089
case COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR:
1090
keyTangentOutType = TANGENT_TYPE_LINEAR;
1092
case COLLADAFW::AnimationCurve::INTERPOLATION_STEP:
1093
keyTangentOutType = TANGENT_TYPE_STEP;
1096
std::cerr << "Unknown interpolation type in mixed interpolations!" << std::endl;
1097
keyTangentOutType = TANGENT_TYPE_DEFAULT;
1099
animCurve->appendKeyTanOutType ( keyTangentOutType );
1101
animCurve->endKeyTanOutType ();
1104
//------------------------------
1105
void AnimationImporter::setKeyTangentLocks (
1106
const COLLADAFW::AnimationCurve* animationCurve,
1107
MayaDM::AnimCurve* animCurve,
1108
const bool keyTanLocked )
1110
if ( !keyTanLocked )
1112
size_t keyCount = animationCurve->getKeyCount ();
1113
animCurve->startKeyTanLocked ( 0, keyCount-1 );
1114
for ( size_t i=0; i<keyCount; ++i )
1116
animCurve->appendKeyTanLocked ( keyTanLocked );
1118
animCurve->endKeyTanLocked ();
1122
//------------------------------
1123
void AnimationImporter::importPlaybackOptions ()
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".
1129
// Get the maya file.
1130
FILE* file = getDocumentImporter ()->getFile ();
1132
// createNode script -n "sceneConfigurationScriptNode";
1133
// setAttr ".b" -type "string" "playbackOptions -min 1 -max 50 -ast 1 -aet 50 ";
1135
if ( mPlaybackOptions.getMaxEndTime () > 0 )
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 ();
1143
scriptNode.setBefore ( scriptValue.str () );
1144
scriptNode.setScriptType ( 2 );
1148
//------------------------------
1149
const bool AnimationImporter::findAnimation ( const COLLADAFW::UniqueId& animationId )
1151
UniqueIdVec::const_iterator it = mAnimationIds.begin ();
1152
while ( it != mAnimationIds.end () )
1154
const COLLADAFW::UniqueId& uniqueId = *it;
1155
if ( uniqueId == animationId ) return true;
1162
//------------------------------
1163
const bool AnimationImporter::findAnimationList ( const COLLADAFW::UniqueId& animationListId )
1165
UniqueIdVec::const_iterator it = mAnimationListIds.begin ();
1166
while ( it != mAnimationListIds.end () )
1168
const COLLADAFW::UniqueId& uniqueId = *it;
1169
if ( uniqueId == animationListId ) return true;
1176
//------------------------------
1177
void AnimationImporter::detectScaleAnimations ( const COLLADAFW::AnimationList* animationList )
1179
// Get the id of the current animation list.
1180
const COLLADAFW::UniqueId& animationListId = animationList->getUniqueId ();
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;
1187
const COLLADAFW::Transformation* transformation = transformAnimation->getTransformation ();
1188
COLLADAFW::Transformation::TransformationType transformType = transformation->getTransformationType ();
1190
// Check if it is a scale animation.
1191
switch ( transformType )
1193
case COLLADAFW::Transformation::SCALE:
1195
// Get the animation bindings.
1196
const COLLADAFW::AnimationList::AnimationBindings& animationBindings = animationList->getAnimationBindings ();
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 )
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;
1206
// Store the scale animation id in a list.
1207
mScaleAnimations.push_back ( animationId );
1216
//------------------------------
1217
const bool AnimationImporter::isScaleAnimation ( const COLLADAFW::UniqueId& animationId )
1219
UniqueIdVec::const_iterator it = mScaleAnimations.begin ();
1220
while ( it != mScaleAnimations.end () )
1222
if ( animationId == *it ) return true;
1228
//------------------------------
1229
void AnimationImporter::writeConnections ( const COLLADAFW::AnimationList* animationList )
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 );
1236
// Get the animation bindings.
1237
const COLLADAFW::AnimationList::AnimationBindings& animationBindings = animationList->getAnimationBindings ();
1239
// Write the transformation animation connections.
1240
connectTransforms ( animationListId, animationBindings );
1242
// Write the effect animation connections.
1243
connectEffects ( animationListId, animationBindings );
1245
// Write the morph controller source connections.
1246
connectMorphControllers ( animationListId, animationBindings );
1249
//------------------------------
1250
void AnimationImporter::connectEffects (
1251
const COLLADAFW::UniqueId& animationListId,
1252
const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
1254
// Get the maya file.
1255
FILE* file = getDocumentImporter ()->getFile ();
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;
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 )
1267
for ( size_t effectIndex=0; effectIndex<mayaEffectList->size (); ++effectIndex )
1269
const MayaDM::Lambert* lambertNode = (*mayaEffectList) [effectIndex];
1271
// Get the animated value type
1272
const EffectAnimation::AnimatedValueType& animatedValueType = effectAnimation->getAnimatedValueType ();
1273
switch ( animatedValueType )
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:
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 )
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;
1293
// Connect all animation curves of the current animation.
1294
size_t animationCurveCount = animationCurves->size ();
1295
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1297
const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
1298
MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
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 )
1305
case COLLADAFW::AnimationList::COLOR_R:
1306
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
1308
case COLLADAFW::AnimationList::COLOR_G:
1309
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
1311
case COLLADAFW::AnimationList::COLOR_B:
1312
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
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 () );
1318
case COLLADAFW::AnimationList::COLOR_RGB:
1319
if ( animationCurveCount == 1 )
1321
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColor () );
1325
switch ( curveIndex )
1328
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
1331
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
1334
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
1337
std::cerr << "Too much animation curves for animation class \"COLOR_RGB\"!" << std::endl;
1341
case COLLADAFW::AnimationList::COLOR_RGBA:
1342
if ( animationCurveCount == 1 )
1344
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColor () );
1348
switch ( curveIndex )
1351
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorR () );
1354
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorG () );
1357
connectAttr ( file, animCurveTL->getOutput (),lambertNode->getColorB () );
1360
std::cerr << "Can't connect the animation of alpha values!" << std::endl;
1363
std::cerr << "Too much animation curves for animation class \"COLOR_RGBA\"!" << std::endl;
1368
std::cerr << "Animation class for effect type \"COLOR_OR_TEXTURE_STANDARD_COLOR\" not implemented!" << std::endl;
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:
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 )
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;
1390
// Connect all animation curves of the current animation.
1391
size_t animationCurveCount = animationCurves->size ();
1392
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1394
const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
1395
MayaDM::AnimCurveTL* animCurveTU = (MayaDM::AnimCurveTL*) animCurve;
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 )
1402
case COLLADAFW::AnimationList::FLOAT:
1403
switch ( animatedValueType )
1405
case EffectAnimation::FLOAT_OR_PARAM_COSINE_POWER:
1406
connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Phong*)lambertNode)->getCosinePower () );
1408
case EffectAnimation::FLOAT_OR_PARAM_ECCENTRICITY:
1409
connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Blinn*)lambertNode)->getEccentricity () );
1411
case EffectAnimation::FLOAT_OR_PARAM_REFLECTIVITY:
1412
connectAttr ( file, animCurveTU->getOutput (),((MayaDM::Reflect*)lambertNode)->getReflectivity () );
1414
case EffectAnimation::FLOAT_OR_PARAM_REFRACTIVE_INDEX:
1415
connectAttr ( file, animCurveTU->getOutput (),lambertNode->getRefractiveIndex () );
1418
std::cerr << "Animation class for effect type \"FLOAT\" not implemented!" << std::endl;
1423
std::cerr << "Animation class for effect type \"FLOAT_OR_PARAM_...\" not implemented!" << std::endl;
1431
std::cerr << "Animation on effect not supported!" << std::endl;
1438
//------------------------------
1439
void AnimationImporter::connectMorphControllers (
1440
const COLLADAFW::UniqueId& animationListId,
1441
const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
1443
// Get the maya file.
1444
FILE* file = getDocumentImporter ()->getFile ();
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;
1451
// connectAttr "animCurveTU1.output" "geom_QuadPatch01_morph1.weight[0]";
1452
MayaDM::BlendShape blendShapeTarget = morphAnimation->getBlendShapeTarget ();
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 )
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;
1464
// Get the array binding.
1465
size_t firstIndex = animationBinding.firstIndex;
1467
// Connect all animation curves of the current animation.
1468
size_t animationCurveCount = animationCurves->size ();
1469
if ( animationCurveCount > 1 )
1471
std::cerr << "Multiple curves on morph animation not implemented!" << std::endl;
1474
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1476
const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
1477
MayaDM::AnimCurveTA* animCurveTA = (MayaDM::AnimCurveTA*) animCurve;
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 )
1484
case COLLADAFW::AnimationList::ARRAY_ELEMENT_1D:
1486
connectAttr ( file, animCurveTA->getOutput (), blendShapeTarget.getWeight ( firstIndex ) );
1491
std::cerr << "Animation class for morph controller animation not implemented!" << std::endl;
1499
//------------------------------
1500
void AnimationImporter::connectTransforms (
1501
const COLLADAFW::UniqueId& animationListId,
1502
const COLLADAFW::AnimationList::AnimationBindings& animationBindings )
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;
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 ();
1515
const COLLADAFW::Transformation* transformation = transformAnimation->getTransformation ();
1516
COLLADAFW::Transformation::TransformationType transformType = transformation->getTransformationType ();
1518
// Set the transformation information in depend of the transform type.
1519
switch ( transformType )
1521
case COLLADAFW::Transformation::ROTATE:
1522
writeRotateConnections ( transformation, transformPhase, isJointTransform, animationBindings, transform );
1524
case COLLADAFW::Transformation::SCALE:
1525
writeScaleConnections ( transformation, animationBindings, transform );
1527
case COLLADAFW::Transformation::SKEW:
1528
std::cerr << "Import of animated skew not implemented!" << std::endl;
1529
// writeSkewConnections ( transformation, animationList, transform );
1531
case COLLADAFW::Transformation::TRANSLATE:
1532
writeTranslateConnections ( transformation, animationBindings, transform );
1535
std::cerr << "Animation on transformation not supported!" << std::endl;
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 )
1548
// Get the maya file.
1549
FILE* file = getDocumentImporter ()->getFile ();
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 ();
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 )
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;
1567
size_t firstIndex = animationBinding.firstIndex;
1569
// Connect all animation curves of the current animation.
1570
size_t animationCurveCount = animationCurves->size ();
1571
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1573
const MayaDM::AnimCurve* animCurve = (*animationCurves) [curveIndex];
1574
MayaDM::AnimCurveTA* animCurveTA = (MayaDM::AnimCurveTA*) animCurve;
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 )
1581
case COLLADAFW::AnimationList::ANGLE:
1583
switch ( transformPhase )
1585
case MayaTransform::PHASE_JOINT_ORIENT1:
1586
case MayaTransform::PHASE_JOINT_ORIENT2:
1587
case MayaTransform::PHASE_JOINT_ORIENT3:
1589
if ( !isJointTransform )
1591
std::cerr << " Can't connect rotate animation, about the transform is not a joint node!" << std::endl;
1594
if ( COLLADABU::Math::Vector3::UNIT_X == axis )
1596
connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientX () );
1598
else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
1600
connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientY () );
1602
else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
1604
connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrientZ () );
1608
case MayaTransform::PHASE_ROTATE1:
1609
case MayaTransform::PHASE_ROTATE2:
1610
case MayaTransform::PHASE_ROTATE3:
1612
if ( COLLADABU::Math::Vector3::UNIT_X == axis )
1614
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateX () );
1616
else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
1618
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateY () );
1620
else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
1622
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateZ () );
1626
case MayaTransform::PHASE_ROTATE_ORIENT1:
1627
case MayaTransform::PHASE_ROTATE_ORIENT2:
1628
case MayaTransform::PHASE_ROTATE_ORIENT3:
1630
if ( COLLADABU::Math::Vector3::UNIT_X == axis )
1632
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisX () );
1634
else if ( COLLADABU::Math::Vector3::UNIT_Y == axis )
1636
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisY () );
1638
else if ( COLLADABU::Math::Vector3::UNIT_Z == axis )
1640
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxisZ () );
1647
case COLLADAFW::AnimationList::AXISANGLE:
1649
switch ( transformPhase )
1651
case MayaTransform::PHASE_JOINT_ORIENT1:
1652
case MayaTransform::PHASE_JOINT_ORIENT2:
1653
case MayaTransform::PHASE_JOINT_ORIENT3:
1655
if ( !isJointTransform )
1657
std::cerr << " Can't connect rotate animation, about the transform is not a joint node!" << std::endl;
1660
connectAttr ( file, animCurveTA->getOutput (), ((MayaDM::Joint*)transform)->getJointOrient () );
1663
case MayaTransform::PHASE_ROTATE1:
1664
case MayaTransform::PHASE_ROTATE2:
1665
case MayaTransform::PHASE_ROTATE3:
1667
connectAttr ( file, animCurveTA->getOutput (), transform->getRotate () );
1670
case MayaTransform::PHASE_ROTATE_ORIENT1:
1671
case MayaTransform::PHASE_ROTATE_ORIENT2:
1672
case MayaTransform::PHASE_ROTATE_ORIENT3:
1674
connectAttr ( file, animCurveTA->getOutput (), transform->getRotateAxis () );
1682
std::cerr << "Animation class for transformation type \"ROTATE\" not implemented!" << std::endl;
1690
//------------------------------
1691
void AnimationImporter::writeScaleConnections (
1692
const COLLADAFW::Transformation* transformation,
1693
const COLLADAFW::AnimationList::AnimationBindings& animationBindings,
1694
const MayaDM::Transform* transform )
1697
COLLADAFW::Scale* scale = ( COLLADAFW::Scale* )transformation;
1699
// Get the maya file.
1700
FILE* file = getDocumentImporter ()->getFile ();
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 )
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;
1712
// Connect all animation curves of the current animation.
1713
size_t animationCurveCount = animCurves->size ();
1714
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1716
const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
1717
MayaDM::AnimCurveTL* animCurveTU = (MayaDM::AnimCurveTL*) animCurve;
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 )
1724
case COLLADAFW::AnimationList::POSITION_X:
1725
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleX() );
1727
case COLLADAFW::AnimationList::POSITION_Y:
1728
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleY() );
1730
case COLLADAFW::AnimationList::POSITION_Z:
1731
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleZ() );
1733
case COLLADAFW::AnimationList::POSITION_XYZ:
1734
if ( animationCurveCount == 1 )
1736
connectAttr ( file, animCurveTU->getOutput (), transform->getScale() );
1740
switch ( curveIndex )
1743
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleX() );
1746
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleY() );
1749
connectAttr ( file, animCurveTU->getOutput (), transform->getScaleZ() );
1752
std::cerr << "Too much animation curves for animation class \"POSITION_XYZ\" in transformation type \"SCALE\"!" << std::endl;
1758
std::cerr << "Animation class for transformation type \"SCALE\" not implemented!" << std::endl;
1765
//------------------------------
1766
void AnimationImporter::writeSkewConnections (
1767
const COLLADAFW::Transformation* transformation,
1768
const COLLADAFW::AnimationList::AnimationBindings& animationBindings,
1769
const MayaDM::Transform* transform )
1772
COLLADAFW::Skew* skew = ( COLLADAFW::Skew* )transformation;
1774
float s = tanf ( COLLADABU::Math::Utils::degToRadF ( skew->getAngle () ) );
1776
const COLLADABU::Math::Vector3& rotateAxis = skew->getRotateAxis();
1777
const COLLADABU::Math::Vector3& translateAxis = skew->getTranslateAxis();
1780
// skewValuesToMayaMatrix ( skew, matrix );
1781
// MTransformationMatrix tm ( matrix );
1784
// tm.getShear ( shear, MSpace::kTransform );
1786
// Get the maya file.
1787
FILE* file = getDocumentImporter ()->getFile ();
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 )
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;
1799
// Connect all animation curves of the current animation.
1800
size_t animationCurveCount = animCurves->size ();
1801
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1803
const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
1804
MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
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 )
1812
// case COLLADAFW::AnimationList::POSITION_X:
1813
// connectAttr ( file, animationCurve->getOutput (), transform->getShearX() );
1815
// case COLLADAFW::AnimationList::POSITION_Y:
1816
// connectAttr ( file, animationCurve->getOutput (), transform->getShearY() );
1818
// case COLLADAFW::AnimationList::POSITION_Z:
1819
// connectAttr ( file, animationCurve->getOutput (), transform->getShearZ() );
1821
case COLLADAFW::AnimationList::POSITION_XYZ:
1822
connectAttr ( file, animCurveTL->getOutput (), transform->getShear() );
1825
std::cerr << "Animation class for transformation type \"SHEAR\" not implemented!" << std::endl;
1832
//------------------------------
1833
void AnimationImporter::writeTranslateConnections (
1834
const COLLADAFW::Transformation* transformation,
1835
const COLLADAFW::AnimationList::AnimationBindings& animationBindings,
1836
const MayaDM::Transform* transform )
1838
COLLADAFW::Translate* translate = ( COLLADAFW::Translate* )transformation;
1839
COLLADABU::Math::Vector3 translation = translate->getTranslation ();
1841
// Get the maya file.
1842
FILE* file = getDocumentImporter ()->getFile ();
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 )
1848
const COLLADAFW::AnimationList::AnimationBinding& animationBinding = animationBindings [i];
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;
1855
// Connect all animation curves of the current animation.
1856
size_t animationCurveCount = animCurves->size ();
1857
for ( size_t curveIndex=0; curveIndex<animationCurveCount; ++curveIndex )
1859
const MayaDM::AnimCurve* animCurve = (*animCurves) [curveIndex];
1860
MayaDM::AnimCurveTL* animCurveTL = (MayaDM::AnimCurveTL*) animCurve;
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 )
1867
case COLLADAFW::AnimationList::POSITION_X:
1868
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateX () );
1870
case COLLADAFW::AnimationList::POSITION_Y:
1871
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateY () );
1873
case COLLADAFW::AnimationList::POSITION_Z:
1874
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateZ () );
1876
case COLLADAFW::AnimationList::POSITION_XYZ:
1878
if ( animationCurveCount == 1 )
1880
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslate () );
1884
switch ( curveIndex )
1887
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateX () );
1890
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateY () );
1893
connectAttr ( file, animCurveTL->getOutput (), transform->getTranslateZ () );
1896
std::cerr << "Too much animation curves for animation class \"POSITION_XYZ\" in transformation type \"TRANSLATE\"!" << std::endl;
1902
std::cerr << "Animation class for transformation type \"TRANSLATE\" not implemented!" << std::endl;
1909
} // namespace DAE2MA