1 /* 2 Copyright (c) 2008-2009 NetAllied Systems GmbH 3 4 This file is part of COLLADAMaya. 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 Copyright (c) 2004-2005 Alias Systems Corp. 10 11 Licensed under the MIT Open Source License, 12 for details please see LICENSE file or the website 13 http://www.opensource.org/licenses/mit-license.php 14 */ 15 16 #ifndef __COLLADA_MAYA_ANIMATION_HELPER_H__ 17 #define __COLLADA_MAYA_ANIMATION_HELPER_H__ 18 19 #include "COLLADAMayaAnimationCurves.h" 20 #include "COLLADAMayaAnimationSampleCache.h" 21 22 #include "COLLADASWLibraryAnimations.h" 23 24 #include <maya/MFnAnimCurve.h> 25 #include <maya/MTime.h> 26 #include <maya/MDGContext.h> 27 28 namespace COLLADAMaya 29 { 30 31 #undef GetCurrentTime 32 33 class AnimationSampleCache; 34 35 36 /** The default tolerance for double-sized floating-point comparison functions. */ 37 #define DBL_TOLERANCE 0.0001 38 /** The default tolerance for single-sized floating-point comparison functions. */ 39 #define FLT_TOLERANCE 0.0001f 40 41 42 /** Contains the infinity types and their conversion functions. */ 43 44 namespace InfinityType 45 { 46 /** An infinity type. 47 They determine what happens when evaluating an animation curve outside of its bounds. */ 48 enum Infinity 49 { 50 CONSTANT = 0, /**< Uses the output value of the closest animation key. This is the default infinity type. */ 51 LINEAR, /**< Takes the distance between the closest animation key input value and the evaluation time. 52 Multiplies this distance against the instant slope at the closest animation key and offsets the 53 result with the closest animation key output value. */ 54 CYCLE, /**< Iteratively removes or adds the animation curve time length to the evaluation time until it is 55 within the animation curve time interval and evaluates it. */ 56 CYCLE_RELATIVE, /**< Iteratively removes or adds the animation curve time length to the evaluation time until it is 57 within the animation curve time interval and evaluates it. Adds to the evaluation output the 58 number of iteration done multiplied by the difference between the animation curve 59 start and end key outputs. */ 60 OSCILLATE, /**< Iteratively removes or adds the animation curve time length to the evaluation time until it is 61 within the animation curve time interval. If the number of iterations done is even, evaluate the 62 new evaluation time, otherwise evaluate (animation curve time length - evaluation time). */ 63 64 UNKNOWN, /**< An unknown infinity type. */ 65 DEFAULT = CONSTANT 66 }; 67 }; 68 69 70 // ------------------------------------------------------- 71 /** 72 * todo Doku 73 */ 74 75 class AnimationHelper 76 { 77 78 public: 79 static std::vector<float> mSamplingTimes; 80 81 public: 82 // Returns whether the plug has any sort of animation, keyed or expression-wise. 83 static AnimationResult isAnimated ( AnimationSampleCache* cache, const MObject& node, const String& attribute ); 84 static AnimationResult isAnimated ( AnimationSampleCache* cache, const MPlug& plug ); 85 static MObject getAnimatingNode ( const MPlug& plug ); 86 87 // Sample animated data 88 static bool isPhysicsAnimation ( const MObject& o ); 89 static void checkForSampling ( AnimationSampleCache* cache, SampleType sampleType, const MPlug& plug ); 90 static bool setSamplingFunction ( const MFloatArray& function ); 91 static void generateSamplingFunction(); 92 93 static bool sampleAnimatedPlug ( AnimationSampleCache* cache, const MPlug& plug, AnimationCurve* curve, ConversionFunctor* converter ); 94 static bool sampleAnimatedTransform ( AnimationSampleCache* cache, const MPlug& plug, AnimationCurveList& curves ); 95 96 // Since Maya 5.0 doesn't support MAnimControl::animation[Start/End]Time(), wrap it with the MEL command 97 static MTime animationStartTime(); 98 static MTime animationEndTime(); 99 static void setAnimationStartTime ( float time ); 100 static void setAnimationEndTime ( float time ); 101 static void getCurrentTime ( MTime& time ); 102 static void setCurrentTime ( const MTime& time ); 103 104 // Handle animation targetting 105 static MPlug getTargetedPlug ( MPlug parentPlug, int index ); 106 107 // Interpolation Type Handling 108 static COLLADASW::LibraryAnimations::InterpolationType toInterpolation ( MFnAnimCurve::TangentType outType ); 109 static MFnAnimCurve::TangentType toTangentType ( COLLADASW::LibraryAnimations::InterpolationType type ); 110 111 static const String mayaInfinityTypeToString ( MFnAnimCurve::InfinityType type ); 112 113 private: 114 115 /** Don't create an object of this class. */ AnimationHelper()116 AnimationHelper() {}; 117 118 }; 119 } 120 121 #endif // __COLLADA_MAYA_ANIMATION_HELPER_H__ 122