1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADAMax. 5 6 Portions of the code are: 7 Copyright (c) 2005-2007 Feeling Software Inc. 8 Copyright (c) 2005-2007 Sony Computer Entertainment America 9 10 Based on the 3dsMax COLLADASW Tools: 11 Copyright (c) 2005-2006 Autodesk Media Entertainment 12 13 Licensed under the MIT Open Source License, 14 for details please see LICENSE file or the website 15 http://www.opensource.org/licenses/mit-license.php 16 */ 17 18 19 #ifndef __COLLADAMAX_ANIMATIONEXPORTER_H__ 20 #define __COLLADAMAX_ANIMATIONEXPORTER_H__ 21 22 #include "COLLADAMaxPrerequisites.h" 23 24 #include "COLLADASWStreamWriter.h" 25 #include "COLLADASWLibraryAnimations.h" 26 27 #include "COLLADAMaxDocumentExporter.h" 28 #include "COLLADAMaxConversionFunctor.h" 29 30 #include "COLLADAMaxAnimationClipExporter.h" 31 32 class Control; 33 34 namespace COLLADAMax 35 { 36 37 38 39 /** A class that holds all information needed to export an animation.*/ 40 41 class Animation 42 { 43 44 public: 45 /** Types of animation*/ 46 enum Type 47 { 48 FLOAT, //!< Animated float 49 FLOAT3, //!< Animated float3 50 FLOAT4, //!< Animated float4 51 FLOAT4x4, //!< Animated float4x4 52 53 POSITION_X, //!< Animated x translation 54 POSITION_Y, //!< Animated y translation 55 POSITION_Z, //!< Animated z translation 56 57 ROTATION_X, //!< Animated x rotation 58 ROTATION_Y, //!< Animated y rotation 59 ROTATION_Z, //!< Animated z rotation 60 61 SCALE_ROT_AXIS, //!< The pivot rotation for scale/skew 62 SCALE_ROT_AXIS_R, //!< The reverse pivot rotation for scale/skew 63 64 // Collapsed types 65 SCALE = FLOAT3, //!< Animated scale in three dimensions 66 TRANSLATION = FLOAT3 //!< Animated translation in three dimensions 67 }; 68 69 enum InputTypeFlags 70 { 71 NONE = 0x0000, 72 INPUT = 0x0001, 73 OUTPUT = 0x0002, 74 IN_TANGENT = 0x0004, 75 OUT_TANGENT = 0x0008, 76 INTERPOLATION = 0x0010 77 }; 78 79 /** Function pointer for conversion functions, to convert doubles.*/ 80 // typedef float ( *ConversionFunction ) ( const float & ); 81 82 83 84 private: 85 /** The max controller.*/ 86 Control * mController; 87 88 /** The max node, used for sampled transformations (matrices).*/ 89 INode * mINode; 90 91 /** The id of the element to animate.*/ 92 String mId; 93 94 /** The sid of the element to animate.*/ 95 String mSid; 96 97 /** A pointer to an array of parameters to animate.*/ 98 const String * mParameters; 99 100 /** Matrix index of the the value to animate. If it is set, the parameters in @a mParameters are ignored.*/ 101 int mMatrixIndex; 102 103 /** Type of animation.*/ 104 int mType; 105 106 /** Flags that indicates which inputs need to be exported in the sampler*/ 107 int mInputTypeFlags; 108 109 /** Pointer to conversion function, to convert all animated values.*/ 110 ConversionFunctor* mConversionFunctor; 111 112 public: 113 114 /** 115 @param controller the controller used for the animation 116 @param id The id of the element to animate 117 @param sid The sid of the element to animate 118 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 119 exists until the animation has been exported. 120 @param type Type of animation 121 @param conversionFunctor Pointer to conversion function, to convert all animated values*/ 122 Animation ( Control * controller, const String & id, const String & sid, const String * parameter, int type, ConversionFunctor* conversionFunctor = 0 ); 123 124 /** 125 @param controller the controller used for the animation 126 @param id The id of the element to animate 127 @param sid The sid of the element to animate 128 @param matrixIndex Matrix index of the array to animate 129 @param type Type of animation 130 @param conversionFunctor Pointer to conversion function, to convert all animated values*/ 131 Animation ( Control * controller, const String & id, const String & sid, int matrixIndex, int type, ConversionFunctor* conversionFunctor = 0 ); 132 133 134 /**Use this constructor to creat an animation for sampled transformation matrices of a max node 135 @param nIode the max node which transformation should be animated (sampled) 136 @param id The id of the element to animate 137 @param sid The sid of the element to animate 138 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 139 exists until the animation has been exported. 140 @param type Type of animation 141 @param conversionFunctor Pointer to conversion function, to convert all animated values*/ 142 Animation ( INode * iNode, const String & id, const String & sid, const String * parameter, int type, ConversionFunctor* conversionFunctor = 0 ); 143 144 145 /** Destructor*/ 146 virtual ~Animation(); 147 148 /** Returns the controller.*/ getController()149 Control * getController() const 150 { 151 return mController; 152 } 153 154 /** Returns the max node.*/ getNode()155 INode * getNode() const 156 { 157 return mINode; 158 } 159 160 /** Returns the id of the element to animate.*/ getId()161 const String & getId() const 162 { 163 return mId; 164 } 165 166 /** Returns the sid of the element to animate.*/ getSid()167 const String & getSid() const 168 { 169 return mSid; 170 } 171 172 /** Returns the pointer to an array of parameters to animate.*/ getParameter()173 const String * getParameter() const 174 { 175 return mParameters; 176 } 177 178 /** Returns the matrix index to animate ore -1 if no matrix is animted.*/ getMatrixIndex()179 int getMatrixIndex() const 180 { 181 return mMatrixIndex; 182 } 183 184 185 186 /** Returns the type of the animation.*/ getType()187 int getType() const 188 { 189 return mType; 190 } 191 192 /** Returns the pointer to conversion function, to convert all animated values.*/ getConversionFunctor()193 const ConversionFunctor* const & getConversionFunctor() const 194 { 195 return mConversionFunctor; 196 } 197 198 /** Returns the dimension of the animation, i.e. how many values are animated. */ 199 int getDimension() const; 200 201 /** Sets the input type flags @a newFlags. Previously set flags remain set.*/ setInputTypeFlags(int newFlags)202 void setInputTypeFlags(int newFlags) { mInputTypeFlags |= newFlags; } 203 204 /** Returns true if the input type flag @a flag is set, false otherwise*/ inputFlagSet(InputTypeFlags flag)205 bool inputFlagSet(InputTypeFlags flag)const { return (mInputTypeFlags & flag) == flag; } 206 207 /** Returns true if at least one input type flag is set.*/ hasAnyInputFlagsSet()208 bool hasAnyInputFlagsSet()const { return mInputTypeFlags != NONE; } 209 210 Animation(const Animation& other); 211 const Animation& operator=(const Animation& other); 212 213 }; 214 215 216 /** Class to exports all animations of a max document.*/ 217 218 class AnimationExporter : public COLLADASW::LibraryAnimations 219 { 220 221 private: 222 /** List of animations*/ 223 typedef std::vector<Animation> AnimationList; 224 225 typedef std::map<String, AnimationList> AnimationMap; 226 227 /** Function pointer to a function that fills the float buffer @a keyValues with the @a keyIndex'th output value 228 of @a animation. */ 229 typedef void ( AnimationExporter::*OutputValueFunctionPtr ) ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 230 231 /** Function pointer to a function that fills the float buffer @a keyValues with the @a keyIndex'th output value 232 of @a animation. */ 233 typedef void ( AnimationExporter::*TangentValueFunctionPtr ) ( float * tangentValuesX, float * tangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 234 235 /** Function pointer to a function that returns the interpolation type as a string of @a i'th 236 key of @a keyInterface. */ 237 typedef const String & ( *InterpolationTypeFunctionPtr ) ( IKeyControl * keyInterface, int i ); 238 239 /** List of floats used to temporarily store key values.*/ 240 typedef std::vector<float> KeyValueList; 241 242 private: 243 /** Value used for inlength if none is specified.*/ 244 static const float DEFAULT_INLENGHT; 245 246 /** Value used for outlength if none is specified.*/ 247 static const float DEFAULT_OUTLENGHT; 248 249 /** Value used for inlength for animated floats if none is specified.*/ 250 static const float DEFAULT_INLENGHT_FLOAT; 251 252 /** Value used for outlength for animated floats if none is specified.*/ 253 static const float DEFAULT_OUTLENGHT_FLOAT; 254 255 /** Value used for inlength for animated points if none is specified.*/ 256 static float DEFAULT_INLENGHT_POINTX_FLOAT_ARRAY[4]; 257 258 /** Value used for outlength for animated points if none is specified.*/ 259 static float DEFAULT_OUTLENGHT_POINTX_FLOAT_ARRAY[4]; 260 261 /** The documentexporter this exporter belongs to.*/ 262 DocumentExporter * mDocumentExporter; 263 264 /** List of all animations to export*/ 265 AnimationList mAnimationList; 266 267 AnimationMap mAnimationMap; 268 269 AnimationClipExporter mClipExporter; 270 271 /** Factor to multiply the key time with to get the real time.*/ 272 static const float mTimeFactor; 273 274 /** List of floats used to temporarily store key values that need to be calculated and are not stored 275 directly in the max api.*/ 276 KeyValueList mKeyValueList; 277 278 /** Stores the euler angles of the last rotation key, if a rotation that requires patching of the euler 279 angles is being exported*/ 280 float mPreviousEulerAngles[3]; 281 282 public: 283 /** Constructor 284 @param streamWriter The stream the animation should be written to 285 @param documentExporter The documentexporter this exporter belongs to 286 */ 287 AnimationExporter ( COLLADASW::StreamWriter * streamWriter, DocumentExporter * documentExporter ); 288 289 /** Destructor*/ ~AnimationExporter()290 ~AnimationExporter() 291 {} 292 293 294 /** Start export of all the animations.*/ 295 void doExport(); 296 297 /** Add @a animation to the list of animations that should be exported.*/ addAnimation(const Animation & animation)298 void addAnimation ( const Animation & animation ) 299 { 300 mAnimationList.push_back ( animation ); 301 } 302 addNamedAnimation(const Animation & animation,const String & name)303 void addNamedAnimation(const Animation& animation, const String& name) { 304 AnimationList& list = mAnimationMap[name]; 305 list.push_back(animation); 306 } 307 308 309 /** Adds an animation that animates a float. 310 @param controller The controller that contains the animation. 311 @param id The id of the element to animate. 312 @param sid The sid of the element to animate. 313 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 314 exists until the animation has been exported. 315 @param conversionFunctor Conversion functor used to convert the output values 316 @return Returns true if the float is animated, false otherwise. 317 */ 318 bool addAnimatedFloat ( Control * controller, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0); 319 320 321 /** Adds an animation that animates a float. 322 @param controller The controller that contains the animation. 323 @param id The id of the element to animate. 324 @param sid The sid of the element to animate. 325 @param matrixIndex Matrix index of the array to animate 326 @param conversionFunctor Conversion functor used to convert the output values 327 @return Returns true if the float is animated, false otherwise. 328 */ 329 bool addAnimatedFloat ( Control * controller, const String & id, const String & sid, int matrixIndex, bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0); 330 331 332 /** Adds an animation that animates a Point3. 333 @param controller The controller that contains the animation 334 @param id The id of the element to animate 335 @param sid The sid of the element to animate 336 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 337 exists until the animation has been exported. 338 @return Returns true if the Point3 is animated, false otherwise. 339 */ 340 bool addAnimatedPoint3(Control * controller, const String& layerName, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0); 341 342 343 /** Adds an animation that animates a Point4, i.e. a parameter that has 4 values, e.g. color 344 @param controller The controller that contains the animation 345 @param id The id of the element to animate 346 @param sid The sid of the element to animate 347 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 348 exists until the animation has been exported. 349 @return Returns true if the Point3 is animated, false otherwise. 350 */ 351 bool addAnimatedPoint4(Control * controller, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0); 352 353 354 /** Adds an animation that animates an angle. 355 @param controller The controller that contains the animation 356 @param id The id of the element to animate 357 @param sid The sid of the element to animate 358 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 359 exists until the animation has been exported. 360 @param animatedAngle The type of the angle that should be animated 361 @param forceFullCheck If true, a full check will be performed f the animations is not constant. 362 @return Returns true if the angle is animated, false otherwise. 363 */ 364 bool addAnimatedAngle ( Control * controller, const String& layerName, const String & id, const String & sid, const String parameters[], int animatedAngle, bool forceFullCheck = true ); 365 366 367 /** Adds an animation that animates an axis angle rotation 368 @param controller The controller that contains the animation 369 @param id The id of the element to animate 370 @param sid The sid of the element to animate 371 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 372 exists until the animation has been exported. 373 @param type The type of the animation 374 @param forceFullCheck If true, a full check will be performed f the animations is not constant. 375 @return Returns true if the Point3 is animated, false otherwise. 376 */ 377 bool addAnimatedAxisAngle(Control * controller, const String & id, const String & sid, const String parameters[], int type, bool forceFullCheck = true); 378 379 bool addAnimatedFloat4x4 ( INode * node, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true ); 380 381 382 /** Adds an animation that animates a Point3. 383 @param controller The controller that contains the animation 384 @param id The id of the element to animate 385 @param sid The sid of the element to animate 386 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 387 exists until the animation has been exported. 388 */ 389 bool addAnimation4 ( Control * controller, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true ); 390 391 /** Adds an animation that animates a parameter within a IParamBlock. 392 @param parameterBlock The IParamBlock that contains the parameter 393 @param parameterId The id of the parameter in the IParamBlock 394 @param id The id of the element to animate 395 @param sid The sid of the element to animate 396 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 397 exists until the animation has been exported. 398 @param conversionFunctor Conversion Functor used to convert the animated values 399 @param forceFullCheck Specifies, if a full check should be performed. 400 @return Returns true, if the controller is animated, false if not. 401 */ 402 bool addAnimatedParameter(IParamBlock * parameterBlock, int parameterId, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0 ); 403 404 /** Adds an animation that animates a parameter within a IParamBlock2. 405 @param parameterBlock2 The IParamBlock2 that contains the parameter 406 @param parameterId The id of the parameter in the IParamBlock2 407 @param id The id of the element to animate 408 @param sid The sid of the element to animate 409 @param parameter A pointer to an array of parameters to animate. The programmer must ensure, that this array 410 exists until the animation has been exported. 411 @param conversionFunctor Conversion Functor used to convert the animated values 412 @param forceFullCheck Specifies, if a full check should be performed. 413 @return Returns true, if the controller is animated, false if not. 414 */ 415 bool addAnimatedParameter(IParamBlock2 * parameterBlock, int parameterId, const String & id, const String & sid, const String parameters[], bool forceFullCheck = true, ConversionFunctor* conversionFunctor = 0 ); 416 417 418 /** Returns true, if the controller is animated an should be exported. 419 This method does not perform a full check, i.e. it only checks if the controller says it is animated, but does 420 not check, if the key values are constant. Use isAnimated(const Animation& animation, bool forceFullCheck) to 421 perform a full check. 422 @param control The controller that should be checked. 423 @return Returns true, if the controller is animated, false if not. 424 */ 425 static bool isAnimated ( Control * controller ); 426 427 /** Returns true, if the controller is animated an should be exported. 428 If @a forceFullCheck is true, this method perform a full check, i.e. it checks if the key values are 429 not constant. This method might be time consuming for laregh animations that are constsnt. If @a forceFullCheck 430 id false, this method behaves exacly as isAnimated ( Control * controller ). 431 @param control The controller that should be checked. 432 @param forceFullCheck Specifies, if a full check should be performed. 433 @return Returns true, if the controller is animated, false if not. 434 */ 435 bool isAnimated ( const Animation& animation, bool forceFullCheck = false ); 436 437 /** Returns true, if the parameter of @a paramBlock with index @a parameterId is animated an should be exported.*/ 438 static bool isAnimated ( IParamBlock * paramBlock, int parameterId ); 439 440 /** Returns true, if the parameter of @a paramBlock with index @a parameterId is animated an should be exported.*/ 441 static bool isAnimated ( IParamBlock2 * paramBlock, int parameterId ); 442 443 /** Generates an id from all the strings contained in @a animation.*/ 444 static String getBaseId ( const Animation & animation ); 445 446 /** Generates the correct target string for use in the @a \<channel\> element.*/ 447 static String getTarget ( const Animation & animation ); 448 449 /** Checks, if the transformations of node @a iNode must be sampled, i.e. it has no stnadart controller*/ 450 static bool forceSampleMatrices(INode* iNode); 451 452 453 454 455 private: 456 /** Disable copy constructor.*/ 457 AnimationExporter ( const AnimationExporter & animationExporter ); 458 459 /** Disable assignment operator.*/ 460 AnimationExporter & operator= ( const AnimationExporter & animationExporter ); 461 462 463 /** Get the time of the key prior to key number @a i of @a controller.*/ 464 TimeValue getPreviousTime ( const int & i, Control * controller ) const; 465 466 /** Get the time of the key next to key number @a i of @a controller.*/ 467 TimeValue getNextTime ( const int & i, const int & keyCount, Control * controller ) const; 468 469 470 /** Function searches @a controller and all subanims for presence of a Constraint. 471 This is bit of a cheap fix, a slightly better option may be to include 472 parent offset calculation in rotation/position sampling (like Matrix sampling). 473 */ 474 static bool findConstraint(Animatable* controller); 475 476 /** Checks if an animation is really animated, by comparing the key values with the first key value. 477 @param animation The animation that should be checked. 478 @return Returns true, if animated, false if not.*/ 479 bool checkIfIsAnimated ( const Animation& animation ); 480 481 /** Checks if an animation is really animated, by comparing the key values with the first key value. 482 @param animation The animation being exported. 483 @param keyInterface The key control interface used to retrieve the key values. 484 @param outputValueFunction Function pointer to a function used to retrieve the output values. 485 @return Returns true, if animated, false if not.*/ 486 bool checkIfIsAnimated ( const Animation & animation, IKeyControl* keyInterface, OutputValueFunctionPtr outputValueFunction ); 487 488 /** Checks if a sampled float value animation is really animated, by comparing the key values with the first key value. 489 @param animation The animation to export. 490 @param keyInterface The key control interface used to retrieve the key values. 491 @param startTime The time the animation should start. 492 @param endTime The time the animation should end. 493 @param ticksPerFrame The ticks per frame used by the animation 494 @return Returns true, if animated, false if not. 495 */ 496 bool checkIfSampledFloatIsAnimated ( const Animation & animation, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 497 498 /** Checks if a sampled Point3 animation is really animated, by comparing the key values with the first key value. 499 @param animation The animation to export. 500 @param keyInterface The key control interface used to retrieve the key values. 501 @param startTime The time the animation should start. 502 @param endTime The time the animation should end. 503 @param ticksPerFrame The ticks per frame used by the animation 504 @return Returns true, if animated, false if not. 505 */ 506 bool checkIfSampledPoint3IsAnimated ( const Animation & animation, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 507 508 /** Checks if a sampled rotation animation is really animated, by comparing the key values with the first key value. 509 @param animation The animation to export. 510 @param keyInterface The key control interface used to retrieve the key values. 511 @param startTime The time the animation should start. 512 @param endTime The time the animation should end. 513 @param ticksPerFrame The ticks per frame used by the animation 514 @return Returns true, if animated, false if not. 515 */ 516 bool checkIfSampledRotationIsAnimated ( const Animation & animation, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 517 518 /** Checks if a sampled transformation animation is really animated, by comparing the key values with the first key value. 519 @param animation The animation to export. 520 @param keyInterface The key control interface used to retrieve the key values. 521 @param startTime The time the animation should start. 522 @param endTime The time the animation should end. 523 @param ticksPerFrame The ticks per frame used by the animation 524 @return Returns true, if animated, false if not. 525 */ 526 bool checkIfSampledTransformationIsAnimated( const Animation & animation, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 527 528 /** Exports all the source elements for @a animation.*/ 529 void exportSources ( Animation & animation ); 530 531 /** Exports the input source element. 532 @param baseId The base id of the animation 533 @param controller The controller being exported 534 @param keyInterface The IKeyControl interface*/ 535 536 template <class KeyClassName> 537 void exportInputSource ( const String & baseId, Control * controller, IKeyControl* keyInterface ); 538 539 540 /** Exports the output source element. 541 @param animation The animation being exported 542 @param baseId The base id of the animation 543 @param keyInterface The IKeyControl interface 544 @param outputValueFunction Function pointer to a function used to retrieve the output values*/ 545 void exportOutputSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, OutputValueFunctionPtr outputValueFunction ); 546 547 /** Retrieves the @a keyIndex'th value of type float from @a keyInterface of @a animation and stores it 548 in the float buffer @a keyValues.*/ 549 template <class KeyType> 550 void getFloatValue ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 551 552 /** Retrieves the @a keyIndex'th position value of a position animation that animates one value 553 from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. The buffer 554 @a keyValues must have at least length 1.*/ 555 template<class KeyType> 556 void getPointXSingleValue ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 557 558 /** Retrieves the three @a keyIndex'th position values of a position animation that animates all 559 three values from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. 560 The buffer @a keyValues must have at least length 3.*/ 561 template<int dimension, class KeyType> 562 void getPointXValue ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 563 564 /** Retrieves the @a keyIndex'th rotation value of a rotation animation that animates one value 565 from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. The buffer 566 @a keyValues must have at least length 1.*/ 567 template<class KeyType> 568 void getRotationSingleValue ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 569 570 /** Retrieves the three @a keyIndex'th rotation values of a rotation animation that animates all 571 three values from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. 572 The buffer @a keyValues must have at least length 3.*/ 573 template<class KeyType> 574 void getRotationValue ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 575 576 577 /** Retrieves the @a keyIndex'th rotation value of a rotation Bezier animation that animates one value 578 from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. The buffer 579 @a keyValues must have at least length 1. The value of the key is stored in @a mKeyValueList, for further 580 use by the tangent functions.*/ 581 void getRotationSingleValuePatchEuler ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 582 583 /** Retrieves the three @a keyIndex'th rotation values of a rotation Bezier animation that animates one value 584 from @a keyInterface of @a animation and stores it in the float buffer @a keyValues. The buffer 585 @a keyValues must have at least length 3. The value of the keys is stored in @a mKeyValueList, for further 586 use by the tangent functions.*/ 587 void getRotationValuePatchEuler ( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 588 589 590 591 template<class KeyType, bool reversed> 592 void getScaleRotationAxisValue( float * keyValues, IKeyControl * keyInterface, const int & keyIndex, const Animation & animation ); 593 594 595 /** Exports a tangent source element. It can be used for both in and out tangents. 596 @param sourceIdSuffix The id suffix that should be used for the source element 597 @param animation The animation being exported 598 @param baseId The base id of the animation 599 @param keyInterface The IKeyControl interface 600 @param tangentValueFunction Function pointer to a function used to retrieve the tangent values*/ 601 void exportTangentSource ( const String & sourceIdSuffix, const Animation & animation, const String & baseId, IKeyControl* keyInterface, TangentValueFunctionPtr tangentValueFunction ); 602 603 604 /** Exports the in tangent source element. 605 @param animation The animation being exported 606 @param baseId The base id of the animation 607 @param keyInterface The IKeyControl interface 608 @param tangentValueFunction Function pointer to a function used to retrieve the in tangent values*/ 609 void exportInTangentSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TangentValueFunctionPtr tangentValueFunction ); 610 611 /** Retrieves an in tangent value pair of an animated float value. 612 @param keyValuesX float array to store the x value 613 @param keyValuesY float array to store the y value 614 @param keyInterface The IKeyControl interface 615 @param keyIndex The index of the key 616 @param keyCount The number of keys in the animation 617 @param animation The animation to export*/ 618 void getFloatInTangentValue ( float * keyValuesX, float * keyValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 619 620 621 622 /** Retrieves the @a keyIndex'th position in tangent value pair of a position animation that animates one value 623 from @a keyInterface of @a animation and stores them in the float buffers @a inTangentValuesX and @a inTangentValuesY. 624 The buffers @a keyValues must have at least length 1. 625 @param inTangentValuesX float array to store the x values 626 @param inTangentValuesY float array to store the y values 627 @param keyInterface The IKeyControl interface 628 @param keyIndex The index of the key 629 @param keyCount The number of keys in the animation 630 @param animation The animation to export 631 */ 632 template <class KeyType> 633 void getPointXSingleInTangentValue ( float * inTangentValuesX, float * inTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 634 635 636 /** Retrieves three in tangent values of an animated position or Point3. 637 @param inTangentValuesX float array to store the x values 638 @param inTangentValuesY float array to store the y values 639 @param keyInterface The IKeyControl interface 640 @param keyIndex The index of the key 641 @param keyCount The number of keys in the animation 642 @param animation The animation to export*/ 643 template <int dimension, class KeyType> 644 void getPointXInTangentValue ( float * inTangentValuesX, float * inTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 645 646 647 /** Retrieves an in tangent value pair of an Bezier animated rotation. It uses @a mKeyValueList to retrieve the 648 values of the key. It therefore requires, that @a mKeyValueList has been filled in advance. 649 @param inTangentValuesX float array to store the x values 650 @param inTangentValuesY float array to store the y values 651 @param keyInterface The IKeyControl interface 652 @param keyIndex The index of the key 653 @param keyCount The number of keys in the animation 654 @param animation The animation to export*/ 655 void getRotationSingleInTangentPatchEuler ( float * inTangentValuesX, float * inTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 656 657 658 /** Retrieves three in tangent value pairs of an Bezier animated rotation. It uses @a mKeyValueList to retrieve the 659 values of the key. It therefore requires, that @a mKeyValueList has been filled in advance. 660 @param inTangentValuesX float array to store the x values 661 @param inTangentValuesY float array to store the y values 662 @param keyInterface The IKeyControl interface 663 @param keyIndex The index of the key 664 @param keyCount The number of keys in the animation 665 @param animation The animation to export*/ 666 void getRotationInTangentPatchEuler ( float * inTangentValuesX, float * inTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 667 668 669 /** Exports the out tangent source element. 670 @param animation The animation being exported 671 @param baseId The base id of the animation 672 @param keyInterface The IKeyControl interface 673 @param tangentValueFunction Function pointer to a function used to retrieve the out tangent values*/ 674 void exportOutTangentSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TangentValueFunctionPtr tangentValueFunction ); 675 676 677 /** Retrieves an out tangent value pair of an animated float value. 678 @param outTangentValuesX float array to store the x value 679 @param outTangentValuesY float array to store the y value 680 @param keyInterface The IKeyControl interface 681 @param keyIndex The index of the key 682 @param keyCount The number of keys in the animation 683 @param animation The animation to export*/ 684 void getFloatOutTangentValue ( float * outTangentValuesX, float * outTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 685 686 687 /** Retrieves the @a keyIndex'th position out tangent value pair of a position animation that animates one value 688 from @a keyInterface of @a animation and stores them in the float buffers @a inTangentValuesX and @a inTangentValuesY. 689 The buffers @a keyValues must have at least length 1. 690 @param inTangentValuesX float array to store the x values 691 @param inTangentValuesY float array to store the y values 692 @param keyInterface The IKeyControl interface 693 @param keyIndex The index of the key 694 @param keyCount The number of keys in the animation 695 @param animation The animation to export 696 */ 697 template <class KeyType> 698 void getPointXSingleOutTangentValue ( float * outTangentValuesX, float * outTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 699 700 701 /** Retrieves three out tangent value pair of an animated position or Point3. 702 The buffers @a outTangentValuesX and @a outTangentValuesY must have at least length 3. 703 @param inTangentValuesX float array to store the x values 704 @param inTangentValuesY float array to store the y values 705 @param keyInterface The IKeyControl interface 706 @param keyIndex The index of the key 707 @param keyCount The number of keys in the animation 708 @param animation The animation to export*/ 709 template <int dimension, class KeyType> 710 void getPointXOutTangentValue ( float * outTangentValuesX, float * outTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 711 712 713 /** Retrieves an in tangent value pair of an Bezier animated rotation. It uses @a mKeyValueList to retrieve the 714 values of the key. It therefore requires, that @a mKeyValueList has been filled in advance. 715 @param inTangentValuesX float array to store the x values 716 @param inTangentValuesY float array to store the y values 717 @param keyInterface The IKeyControl interface 718 @param keyIndex The index of the key 719 @param keyCount The number of keys in the animation 720 @param animation The animation to export*/ 721 void getRotationSingleOutTangentPatchEuler ( float * outTangentValuesX, float * outTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 722 723 724 /** Retrieves three in tangent value pairs of an Bezier animated rotation. It uses @a mKeyValueList to retrieve the 725 values of the key. It therefore requires, that @a mKeyValueList has been filled in advance. 726 @param inTangentValuesX float array to store the x values 727 @param inTangentValuesY float array to store the y values 728 @param keyInterface The IKeyControl interface 729 @param keyIndex The index of the key 730 @param keyCount The number of keys in the animation 731 @param animation The animation to export*/ 732 void getRotationOutTangentPatchEuler ( float * outTangentValuesX, float * outTangentValuesY, IKeyControl * keyInterface, const int & keyIndex, const int & keyCount, const Animation & animation ); 733 734 /** Determines the out interpolation type depending on @a flags*/ 735 static InterpolationType getInterpolationOutType ( const DWORD & flags ); 736 737 /** Determines the in interpolation type depending on @a flags*/ 738 static InterpolationType getInterpolationInType ( const DWORD & flags ); 739 740 /** Exports the interpolation source. 741 @param baseId The base id of the animation 742 @param keyInterface The IKeyControl interface 743 @param interpolationTypeFunction Function pointer to a function used to retrieve the interpolation type 744 @param keyCount The number of keys in the animation 745 */ 746 void exportInterpolationSource ( const String & baseId, IKeyControl * keyInterface, InterpolationTypeFunctionPtr interpolationTypeFunction, int keyCount ); 747 748 /** Exports the input values (time values) of a sampled animation. 749 @param baseId The base id of the animation 750 @param startTime The time the animation should start. 751 @param endTime The time the animation should end. 752 @param ticksPerFrame The ticks per frame used by the animation 753 */ 754 void exportSamplingInputSource ( const String & baseId, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 755 756 /** Exports the output values of a sampled float value animation. 757 @param animation The animation to export. 758 @param baseId The base id of the animation. 759 @param startTime The time the animation should start. 760 @param endTime The time the animation should end. 761 @param ticksPerFrame The ticks per frame used by the animation 762 */ 763 void exportSamplingFloatOutputSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 764 765 /** Exports the output values of a sampled Point3 animation. 766 @param animation The animation to export. 767 @param baseId The base id of the animation. 768 @param startTime The time the animation should start. 769 @param endTime The time the animation should end. 770 @param ticksPerFrame The ticks per frame used by the animation 771 */ 772 void exportSamplingPoint3OutputSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 773 774 /** Exports the output values of a sampled rotation animation. 775 @param animation The animation to export. 776 @param baseId The base id of the animation. 777 @param startTime The time the animation should start. 778 @param endTime The time the animation should end. 779 @param ticksPerFrame The ticks per frame used by the animation 780 */ 781 void exportSamplingRotationOutputSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 782 783 /** Exports the output values of a sampled transformation animation. 784 @param animation The animation to export. 785 @param baseId The base id of the animation. 786 @param startTime The time the animation should start. 787 @param endTime The time the animation should end. 788 @param ticksPerFrame The ticks per frame used by the animation 789 */ 790 void exportSamplingTransformationOutputSource ( const Animation & animation, const String & baseId, IKeyControl* keyInterface, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 791 792 /** Exports the interpolation type of a sampled animation. 793 @param baseId The base id of the animation. 794 @param startTime The time the animation should start. 795 @param endTime The time the animation should end. 796 @param ticksPerFrame The ticks per frame used by the animation 797 */ 798 void exportSamplingInterpolationSource ( const String & baseId, TimeValue startTime, TimeValue endTime, int ticksPerFrame ); 799 800 /** Returns @a interpolationTypeName for all values of @a keyInterface and keyIndex.*/ 801 template <const String & interpolationTypeName> 802 static const String & getUniformInterpolation ( IKeyControl * keyInterface, int keyIndex ); 803 804 /** Returns the type of the interpolation. 805 @param keyInterface The IKeyControl interface 806 @param keyIndex The number of the key*/ 807 template <class KeyType> 808 static const String & getBezierInterpolation ( IKeyControl * keyInterface, int keyIndex ); 809 810 /** Exports the sampler element.*/ 811 void exportSampler ( const Animation & animation ); 812 813 /** Exports the channel element.*/ 814 void exportChannel ( const Animation & animation ); 815 816 817 /** Approaches the angle @a val to angle @a pval, by adding or subtracting multiples of 2*PI 818 to minimize the absolute value of the distance between them.*/ 819 void angleApproach(float pval, float& val); 820 821 /** Find the Euler angel representation that is equivalent to the three Euler angles in @a val with 822 the smallest distance to @a pval.*/ 823 void patchEuler(float* pval, float* val); 824 825 826 }; 827 } 828 829 #endif //__COLLADAMAX_ANIMATIONEXPORTER_H__ 830 831 832 833 834