2
Copyright (c) 2008-2009 NetAllied Systems GmbH
4
This file is part of COLLADASaxFrameworkLoader.
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 "COLLADASaxFWLStableHeaders.h"
12
#include "COLLADASaxFWLLibraryAnimationsLoader.h"
13
#include "COLLADASaxFWLSidAddress.h"
14
#include "COLLADASaxFWLSidTreeNode.h"
15
#include "COLLADASaxFWLInterpolationTypeSource.h"
16
#include "COLLADASaxFWLLoader.h"
18
#include "COLLADAFWValidate.h"
19
#include "COLLADAFWAnimationCurve.h"
20
#include "COLLADAFWAnimationList.h"
21
#include "COLLADAFWIWriter.h"
22
#include "COLLADAFWTypes.h"
25
namespace COLLADASaxFWL
28
enum SamplerInputSemantics
33
SEMANTIC_INTERPOLATION,
38
const String INTERPOLATIONTYPE_LINEAR("LINEAR");
39
const String INTERPOLATIONTYPE_BEZIER("BEZIER");
40
const String INTERPOLATIONTYPE_CARDINAL("CARDINAL");
41
const String INTERPOLATIONTYPE_HERMITE("HERMITE");
42
const String INTERPOLATIONTYPE_BSPLINE("BSPLINE");
43
const String INTERPOLATIONTYPE_STEP("STEP");
44
const String INTERPOLATIONTYPE_MIXED("MIXED");
47
//------------------------------
48
bool operator==( const ParserString& parserString, const String& stlSring )
50
if ( parserString.length != stlSring.length() )
54
const char* str = stlSring.c_str();
55
while ( (pos < parserString.length) )
57
if ( parserString.str[pos] != str[pos] )
64
struct AccessorAnimationClassPair
66
AccessorAnimationClassPair( const SourceBase::AccessorParameter* _parameters,
67
size_t _parameterCount,
68
COLLADAFW::AnimationList::AnimationClass _animationClass)
69
: parameters(_parameters)
70
, parameterCount(_parameterCount/sizeof(SourceBase::AccessorParameter))
71
, animationClass(_animationClass)
73
const SourceBase::AccessorParameter* parameters;
74
size_t parameterCount;
75
COLLADAFW::AnimationList::AnimationClass animationClass;
78
struct AccessorDimensionsPair
80
AccessorDimensionsPair( const SourceBase::AccessorParameter& _parameter,
81
COLLADAFW::PhysicalDimension _physicalDimension,
83
: parameter(_parameter)
84
, physicalDimension(_physicalDimension)
85
, dimension(_dimension)
87
const SourceBase::AccessorParameter& parameter;
88
COLLADAFW::PhysicalDimension physicalDimension;
92
SourceBase::AccessorParameter parameterTime = {"TIME", "float"};
93
SourceBase::AccessorParameter parameterFloat = {"", "float"};
94
SourceBase::AccessorParameter parameterX = {"X", "float"};
95
SourceBase::AccessorParameter parameterY = {"Y", "float"};
96
SourceBase::AccessorParameter parameterZ = {"Z", "float"};
97
SourceBase::AccessorParameter parameterR = {"R", "float"};
98
SourceBase::AccessorParameter parameterG = {"G", "float"};
99
SourceBase::AccessorParameter parameterB = {"B", "float"};
100
SourceBase::AccessorParameter parameterA = {"A", "float"};
101
SourceBase::AccessorParameter parameterAngle = {"ANGLE", "float"};
102
SourceBase::AccessorParameter parameterTransform = {"TRANSFORM", "float4x4"};
104
SourceBase::AccessorParameter accessorTime[] = {parameterTime};
105
SourceBase::AccessorParameter accessorFloat[] = {parameterFloat};
106
SourceBase::AccessorParameter accessorX[] = {parameterX};
107
SourceBase::AccessorParameter accessorY[] = {parameterY};
108
SourceBase::AccessorParameter accessorZ[] = {parameterZ};
109
SourceBase::AccessorParameter accessorR[] = {parameterR};
110
SourceBase::AccessorParameter accessorG[] = {parameterG};
111
SourceBase::AccessorParameter accessorB[] = {parameterB};
112
SourceBase::AccessorParameter accessorA[] = {parameterA};
113
SourceBase::AccessorParameter accessorAngle[] = {parameterAngle};
114
SourceBase::AccessorParameter accessorTransform[] = {parameterTransform};
116
SourceBase::AccessorParameter accessorXYZ[] = {parameterX, parameterY, parameterZ};
117
SourceBase::AccessorParameter accessorRGB[] = {parameterR, parameterG, parameterB};
118
SourceBase::AccessorParameter accessorRGBA[] = {parameterR, parameterG, parameterB, parameterA};
119
SourceBase::AccessorParameter accessorAxisAngle[] = {parameterX, parameterY, parameterZ, parameterAngle};
121
AccessorAnimationClassPair animationClassMap[] =
123
AccessorAnimationClassPair( accessorTime, sizeof(accessorTime), COLLADAFW::AnimationList::TIME)
124
, AccessorAnimationClassPair( accessorFloat, sizeof(accessorFloat), COLLADAFW::AnimationList::FLOAT)
125
, AccessorAnimationClassPair( accessorX, sizeof(accessorX), COLLADAFW::AnimationList::POSITION_X)
126
, AccessorAnimationClassPair( accessorY, sizeof(accessorY), COLLADAFW::AnimationList::POSITION_Y)
127
, AccessorAnimationClassPair( accessorZ, sizeof(accessorZ), COLLADAFW::AnimationList::POSITION_Z)
128
, AccessorAnimationClassPair( accessorR, sizeof(accessorR), COLLADAFW::AnimationList::COLOR_R)
129
, AccessorAnimationClassPair( accessorG, sizeof(accessorG), COLLADAFW::AnimationList::COLOR_G)
130
, AccessorAnimationClassPair( accessorB, sizeof(accessorB), COLLADAFW::AnimationList::COLOR_B)
131
, AccessorAnimationClassPair( accessorA, sizeof(accessorA), COLLADAFW::AnimationList::COLOR_A)
132
, AccessorAnimationClassPair( accessorAngle, sizeof(accessorAngle), COLLADAFW::AnimationList::ANGLE)
133
, AccessorAnimationClassPair( accessorXYZ, sizeof(accessorXYZ), COLLADAFW::AnimationList::POSITION_XYZ)
134
, AccessorAnimationClassPair( accessorRGB, sizeof(accessorRGB), COLLADAFW::AnimationList::COLOR_RGB)
135
, AccessorAnimationClassPair( accessorRGBA, sizeof(accessorRGBA), COLLADAFW::AnimationList::COLOR_RGBA)
136
, AccessorAnimationClassPair( accessorAxisAngle, sizeof(accessorAxisAngle), COLLADAFW::AnimationList::AXISANGLE)
137
, AccessorAnimationClassPair( accessorTransform, sizeof(accessorTransform), COLLADAFW::AnimationList::MATRIX4X4)
141
AccessorDimensionsPair animationDimensionMap[] =
143
AccessorDimensionsPair( parameterFloat, PHYSICAL_DIMENSION_UNKNOWN, 1)
144
, AccessorDimensionsPair( parameterX, PHYSICAL_DIMENSION_LENGTH, 1)
145
, AccessorDimensionsPair( parameterY, PHYSICAL_DIMENSION_LENGTH, 1)
146
, AccessorDimensionsPair( parameterZ, PHYSICAL_DIMENSION_LENGTH, 1)
147
, AccessorDimensionsPair( parameterAngle, PHYSICAL_DIMENSION_ANGLE, 1)
148
, AccessorDimensionsPair( parameterTransform, PHYSICAL_DIMENSION_TRANSFORMATIONMATRIX4X4, 16)
153
/** Determines the animation class from the accessor.*/
154
//------------------------------
155
COLLADAFW::AnimationList::AnimationClass determineAnimationClass( const SourceBase::Accessor& accessor )
157
static const size_t mapSize = sizeof(animationClassMap)/sizeof(AccessorAnimationClassPair);
158
for ( size_t i = 0; i < mapSize; ++i)
160
const AccessorAnimationClassPair& animationClassPair = animationClassMap[i];
162
if ( accessor.size() != animationClassPair.parameterCount )
164
// two accessor must have equal number of parameters to be equal
169
for ( size_t j = 0; j < animationClassPair.parameterCount; ++j)
171
const SourceBase::AccessorParameter& parameter = animationClassPair.parameters[j];
172
const SourceBase::AccessorParameter& accessorParameter = accessor[j];
173
if ( parameter != accessorParameter )
182
// if we reach this point, the parameters in accessor are equal to those in animationClassPair
183
return animationClassPair.animationClass;
187
return COLLADAFW::AnimationList::UNKNOWN_CLASS;
191
/** Determines the physical dimension and the dimension of @a parameter.
192
@param parameters the accessor parameter to determine the dimensions from
193
@param physicalDimension Will be set to the physical dimension
194
@param dimension Will be set to the dimension of the parameter, e.g. 1 for float, 16 for float4x4
195
@return True if parameter was found, false otherwise.*/
196
//------------------------------
197
bool determineParameterDimensions( const SourceBase::AccessorParameter& parameter,
198
COLLADAFW::PhysicalDimension& physicalDimension,
201
static const size_t mapSize = sizeof(animationDimensionMap)/sizeof(AccessorDimensionsPair);
202
for ( size_t i = 0; i < mapSize; ++i)
204
const AccessorDimensionsPair& animationDimensionPair = animationDimensionMap[i];
206
if ( parameter == animationDimensionPair.parameter )
208
physicalDimension = animationDimensionPair.physicalDimension;
209
dimension = animationDimensionPair.dimension;
218
//------------------------------
219
COLLADAFW::AnimationCurve::InterpolationType LibraryAnimationsLoader::getInterpolationTypeByString( const ParserString& string )
221
if ( string == INTERPOLATIONTYPE_LINEAR )
223
return COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR;
225
else if ( string == INTERPOLATIONTYPE_BEZIER )
227
return COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER;
229
else if ( string == INTERPOLATIONTYPE_CARDINAL )
231
return COLLADAFW::AnimationCurve::INTERPOLATION_CARDINAL;
233
else if ( string == INTERPOLATIONTYPE_HERMITE )
235
return COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE;
237
else if ( string == INTERPOLATIONTYPE_BSPLINE )
239
return COLLADAFW::AnimationCurve::INTERPOLATION_BSPLINE;
241
else if ( string == INTERPOLATIONTYPE_STEP )
243
return COLLADAFW::AnimationCurve::INTERPOLATION_STEP;
245
else if ( string == INTERPOLATIONTYPE_MIXED )
247
return COLLADAFW::AnimationCurve::INTERPOLATION_MIXED;
250
return COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN;
253
//------------------------------
254
SamplerInputSemantics getSemanticBySemanticStr( const char * semanticStr)
256
if ( strcmp(semanticStr, "INPUT" ) == 0 )
258
return SEMANTIC_INPUT;
260
else if ( strcmp(semanticStr, "OUTPUT" ) == 0 )
262
return SEMANTIC_OUTPUT;
264
else if ( strcmp(semanticStr, "INTERPOLATION" ) == 0 )
266
return SEMANTIC_INTERPOLATION;
268
else if ( strcmp(semanticStr, "IN_TANGENT" ) == 0 )
270
return SEMANTIC_IN_TANGENT;
272
else if ( strcmp(semanticStr, "OUT_TANGENT" ) == 0 )
274
return SEMANTIC_OUT_TANGENT;
276
return SEMANTIC_UNKNOWN;
279
//------------------------------
280
LibraryAnimationsLoader::LibraryAnimationsLoader( IFilePartLoader* callingFilePartLoader )
281
: SourceArrayLoader(callingFilePartLoader)
282
, mCurrentAnimationCurve(0)
283
, mCurrentlyParsingInterpolationArray(false)
284
, mCurrentAnimationInfo( 0 )
285
, mCurrentAnimationCurveRequiresTangents(true)
286
, mVerboseValidate(true)
290
//------------------------------
291
LibraryAnimationsLoader::~LibraryAnimationsLoader()
295
//------------------------------
296
const COLLADAFW::UniqueId& LibraryAnimationsLoader::getUniqueId ()
298
if ( mCurrentAnimationCurve )
299
return mCurrentAnimationCurve->getUniqueId ();
301
// TODO One curve for every sampler in an collada animation. Returns always an invalid id!
302
return COLLADAFW::UniqueId::INVALID;
305
//------------------------------
306
AnimationInfo* LibraryAnimationsLoader::getAnimationInfoBySamplerId( const String& samplerId )
308
StringAnimationInfoMap::iterator it = mSamplerIdAnimationInfoMap.find( samplerId );
309
if ( it == mSamplerIdAnimationInfoMap.end() )
315
return &(it->second);
319
//------------------------------
320
bool LibraryAnimationsLoader::end__library_animations()
327
//------------------------------
328
bool LibraryAnimationsLoader::begin__source( const source__AttributeData& attributes )
330
return beginSource(attributes);
333
//------------------------------
334
bool LibraryAnimationsLoader::end__source( )
339
//------------------------------
340
bool LibraryAnimationsLoader::begin__animation( const animation__AttributeData& attributeData )
342
if ( attributeData.name )
343
mName = (const char*)attributeData.name;
344
else if ( attributeData.id)
345
mName = (const char*)attributeData.id;
347
if ( attributeData.id )
348
mOriginalId = (const char*)attributeData.id;
350
//FR: we create an id, so that clients can figure out - for an incoming animation - which animation it originally belongs to.
351
//Thus, it can be able to respect the same layout of animation than the input COLLADA file.
352
std::ostringstream o;
353
o << "animation_" << this->mProcessedCount++;
354
mOriginalId = o.str();
360
//------------------------------
361
bool LibraryAnimationsLoader::end__animation()
363
mOriginalId = COLLADABU::Utils::EMPTY_STRING;
368
//------------------------------
369
bool LibraryAnimationsLoader::begin__sampler( const sampler__AttributeData& attributeData )
371
mCurrentAnimationCurve = FW_NEW COLLADAFW::AnimationCurve(createUniqueIdFromId(attributeData.id, COLLADAFW::Animation::ID()));
373
mCurrentAnimationCurve->setName ( mName );
374
mCurrentAnimationCurve->setOriginalId ( mOriginalId );
376
if ( attributeData.id && *attributeData.id )
378
AnimationInfo animationInfo;
379
animationInfo.uniqueId = mCurrentAnimationCurve->getUniqueId();
380
animationInfo.animationClass = COLLADAFW::AnimationList::UNKNOWN_CLASS;
381
mCurrentAnimationInfo = &(mSamplerIdAnimationInfoMap.insert(std::make_pair(attributeData.id, animationInfo)).first->second);
386
//------------------------------
387
bool LibraryAnimationsLoader::end__sampler()
390
if ( !mCurrentAnimationCurveRequiresTangents )
392
mCurrentAnimationCurve->getInTangentValues().clear();
393
mCurrentAnimationCurve->getOutTangentValues().clear();
395
if ( (getObjectFlags() & Loader::ANIMATION_FLAG) != 0 )
397
//assume linear interpolation if no interpolation is set
398
if ( mCurrentAnimationCurve->getInterpolationType() == COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN )
400
mCurrentAnimationCurve->setInterpolationType(COLLADAFW::AnimationCurve::INTERPOLATION_LINEAR );
403
if ( COLLADAFW::validate( mCurrentAnimationCurve, mVerboseValidate ) == 0)
405
success = writer()->writeAnimation(mCurrentAnimationCurve);
406
FW_DELETE mCurrentAnimationCurve;
410
handleFWLError ( SaxFWLError::ERROR_DATA_NOT_VALID, "Animation curve \"" + mCurrentAnimationCurve->getName () + "\" not valid!" );
413
mCurrentAnimationCurve = 0;
414
mCurrentAnimationInfo = 0;
415
mCurrentAnimationCurveRequiresTangents = true;
419
//------------------------------
420
bool LibraryAnimationsLoader::begin__channel( const channel__AttributeData& attributeData )
422
String samplerId = getIdFromURIFragmentType(attributeData.source);
424
AnimationInfo* animationInfo = getAnimationInfoBySamplerId( samplerId );
426
if ( !animationInfo )
429
SidAddress sidAddress( String(attributeData.target) );
431
const SidTreeNode* sidTreeNode = resolveSid( sidAddress );
435
if ( sidTreeNode->getTargetType() == SidTreeNode::TARGETTYPE_ANIMATABLE )
437
COLLADAFW::Animatable* animatable = sidTreeNode->getAnimatableTarget();
438
COLLADAFW::UniqueId animationListUniqueId = animatable->getAnimationList();
439
if ( !animationListUniqueId.isValid() )
441
animationListUniqueId = getUniqueId( COLLADAFW::AnimationList::ID() );
442
animatable->setAnimationList( animationListUniqueId );
444
COLLADAFW::AnimationList*& animationList = getAnimationListByUniqueId(animationListUniqueId);
446
if ( !animationList )
448
animationList = new COLLADAFW::AnimationList( animationListUniqueId.getObjectId() );
451
// TODO handle this for arrays
452
COLLADAFW::AnimationList::AnimationBinding animationBinding;
453
animationBinding.animation = animationInfo->uniqueId;
454
animationBinding.animationClass = animationInfo->animationClass;
455
if ( animationBinding.animationClass == COLLADAFW::AnimationList::MATRIX4X4_ELEMENT )
457
animationBinding.firstIndex = sidAddress.getFirstIndex();
458
animationBinding.secondIndex = sidAddress.getSecondIndex();
462
animationBinding.firstIndex = 0;
463
animationBinding.secondIndex = 0;
465
animationList->getAnimationBindings().append( animationBinding );
471
// the references element has not been parsed. Store the connection. Will be processed by FileLoader
472
// at the end of the collada file.
473
addToAnimationSidAddressBindings( *animationInfo, sidAddress );
479
//------------------------------
480
bool LibraryAnimationsLoader::end__channel()
486
//------------------------------
487
bool LibraryAnimationsLoader::begin__input____InputLocal( const input____InputLocal__AttributeData& attributeData )
489
// we ignore inputs that don't have semantics or source
490
if ( !attributeData.semantic || !attributeData.source )
495
SamplerInputSemantics semantic = getSemanticBySemanticStr( attributeData.semantic );
496
if ( semantic == SEMANTIC_UNKNOWN )
501
String sourceId = getIdFromURIFragmentType(attributeData.source);
502
const SourceBase* sourceBase = getSourceById ( sourceId );
503
// TODO handle case where source could not be found
506
SourceBase::DataType sourceDataType = sourceBase->getDataType();
513
if ( sourceDataType != SourceBase::DATA_TYPE_REAL )
515
// The source array has wrong type. Only reals are allowed for semantic INPUT
519
COLLADAFW::AnimationList::AnimationClass animationClass = determineAnimationClass( sourceBase->getAccessor() );
521
if ( animationClass == COLLADAFW::AnimationList::TIME )
523
mCurrentAnimationCurve->setInPhysicalDimension( COLLADAFW::PHYSICAL_DIMENSION_TIME );
527
mCurrentAnimationCurve->setInPhysicalDimension( COLLADAFW::PHYSICAL_DIMENSION_UNKNOWN );
530
setRealValues( mCurrentAnimationCurve->getInputValues(), (const RealSource*)sourceBase);
533
case SEMANTIC_OUTPUT:
535
if ( sourceDataType != SourceBase::DATA_TYPE_REAL )
537
// The source array has wrong type. Only reals are allowed for semantic OUTPUT
541
COLLADABU_ASSERT( mCurrentAnimationInfo );
542
COLLADAFW::PhysicalDimensionArray& physicalDimensions = mCurrentAnimationCurve->getOutPhysicalDimensions();
544
if ( mCurrentAnimationInfo )
546
COLLADAFW::AnimationList::AnimationClass animationClass = determineAnimationClass( sourceBase->getAccessor() );
547
mCurrentAnimationInfo->animationClass = animationClass;
549
switch ( animationClass )
551
case COLLADAFW::AnimationList::POSITION_X:
552
case COLLADAFW::AnimationList::POSITION_Y:
553
case COLLADAFW::AnimationList::POSITION_Z:
554
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
556
case COLLADAFW::AnimationList::POSITION_XYZ:
557
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
558
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
559
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
561
case COLLADAFW::AnimationList::ANGLE:
562
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_ANGLE);
564
case COLLADAFW::AnimationList::AXISANGLE:
565
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
566
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
567
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
568
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_ANGLE);
570
case COLLADAFW::AnimationList::MATRIX4X4:
571
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
572
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
573
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
574
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
575
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
576
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
577
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
578
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
579
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
580
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
581
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
582
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_LENGTH);
583
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
584
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
585
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
586
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
588
case COLLADAFW::AnimationList::COLOR_R:
589
case COLLADAFW::AnimationList::COLOR_G:
590
case COLLADAFW::AnimationList::COLOR_B:
591
case COLLADAFW::AnimationList::COLOR_A:
592
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
594
case COLLADAFW::AnimationList::COLOR_RGB:
595
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
596
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
597
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
599
case COLLADAFW::AnimationList::COLOR_RGBA:
600
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
601
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
602
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
603
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_COLOR);
605
case COLLADAFW::AnimationList::FLOAT:
606
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_NUMBER);
608
case COLLADAFW::AnimationList::ARRAY_ELEMENT_1D:
609
case COLLADAFW::AnimationList::ARRAY_ELEMENT_2D:
610
//https://github.com/KhronosGroup/OpenCOLLADA/issues/245
611
//FR: is this an issue to have nothing processed here, or is it processed somewhere else ?
613
case COLLADAFW::AnimationList::UNKNOWN_CLASS:
614
case COLLADAFW::AnimationList::TIME:
619
const RealSource* realSource = (const RealSource*)sourceBase;
620
setRealValues( mCurrentAnimationCurve->getOutputValues(), realSource);
622
size_t stride = (size_t)realSource->getStride();
623
size_t physicalDimensionsCount = physicalDimensions.getCount();
624
// if stride is larger that physicalDimensionsCount, we need to append dimensions to physicalDimensions
625
for ( size_t i = physicalDimensionsCount; i < stride; ++i)
627
physicalDimensions.append(COLLADAFW::PHYSICAL_DIMENSION_UNKNOWN);
629
mCurrentAnimationCurve->setOutDimension(stride);
632
case SEMANTIC_OUT_TANGENT:
634
if ( sourceDataType != SourceBase::DATA_TYPE_REAL )
636
// The source array has wrong type. Only reals are allowed for semantic OUTPUT
640
if ( !mCurrentAnimationCurveRequiresTangents )
642
// This animation does not require tangents
645
setRealValues( mCurrentAnimationCurve->getOutTangentValues(), (const RealSource*)sourceBase);
648
case SEMANTIC_IN_TANGENT:
650
if ( sourceDataType != SourceBase::DATA_TYPE_REAL )
652
// The source array has wrong type. Only reals are allowed for semantic OUTPUT
655
if ( !mCurrentAnimationCurveRequiresTangents )
657
// This animation does not require tangents
660
setRealValues( mCurrentAnimationCurve->getInTangentValues(), (const RealSource*)sourceBase);
663
case SEMANTIC_INTERPOLATION:
665
if ( sourceDataType != SourceBase::DATA_TYPE_INTERPOLATIONTYPE )
667
// The source array has wrong type. Only reals are allowed for semantic INTERPOLATION
671
COLLADAFW::AnimationCurve::InterpolationType currentAnimationCurveInterpolationType = mCurrentAnimationCurve->getInterpolationType();
673
if ( currentAnimationCurveInterpolationType != COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN )
675
// There already must have been an input with semantic INTERPOLATION. We ignore all following.
679
const InterpolationTypeSource* interpolationTypeSource = (const InterpolationTypeSource*)sourceBase;
680
COLLADAFW::AnimationCurve::InterpolationType interpolationType = interpolationTypeSource->getInterpolationType();
681
mCurrentAnimationCurveRequiresTangents = interpolationTypeSource->getRequiresTangents();
683
mCurrentAnimationCurve->setInterpolationType(interpolationType);
685
if ( interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_MIXED )
687
COLLADAFW::AnimationCurve::InterpolationTypeArray& interpolationTypes = mCurrentAnimationCurve->getInterpolationTypes();
688
interpolationTypes.appendValues(interpolationTypeSource->getArrayElement().getValues());
699
//------------------------------
700
bool LibraryAnimationsLoader::begin__Name_array( const Name_array__AttributeData& attributeData )
702
return beginArray<InterpolationTypeSource>( attributeData.count, attributeData.id ) != 0;
706
//------------------------------
707
bool LibraryAnimationsLoader::end__Name_array()
712
//------------------------------
713
bool LibraryAnimationsLoader::data__Name_array( const ParserString* data, size_t length )
715
InterpolationTypeSource* interpolationTypeSource = (InterpolationTypeSource*)mCurrentSoure;
716
for ( size_t i = 0; i < length; ++i)
718
const ParserString& interpolationTypeString = data[i];
719
COLLADAFW::AnimationCurve::InterpolationType interpolationType = getInterpolationTypeByString( interpolationTypeString );
720
COLLADAFW::AnimationCurve::InterpolationTypeArray& array = interpolationTypeSource->getArrayElement().getValues();
721
array.append( interpolationType );
723
COLLADAFW::AnimationCurve::InterpolationType interpolationTypeSourceInterpolationType = interpolationTypeSource->getInterpolationType();
724
if ( (interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_BEZIER) ||
725
(interpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_HERMITE) )
727
interpolationTypeSource->setRequiresTangents( true );
729
if ( interpolationTypeSourceInterpolationType == COLLADAFW::AnimationCurve::INTERPOLATION_UNKNOWN )
731
interpolationTypeSource->setInterpolationType( interpolationType );
733
else if ( interpolationTypeSourceInterpolationType != interpolationType )
735
interpolationTypeSource->setInterpolationType( COLLADAFW::AnimationCurve::INTERPOLATION_MIXED);
741
} // namespace COLLADASaxFWL