kfbxanimcurvekfcurve.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002 
00003 Copyright (C) 2010 Autodesk, Inc.
00004 All rights reserved.
00005 
00006 Use of this software is subject to the terms of the Autodesk license agreement
00007 provided at the time of installation or download, or which otherwise accompanies
00008 this software in either electronic or hard copy form.
00009 
00010 ****************************************************************************************/
00011 
00015 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H
00016 #define FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H
00017 
00018 #include <fbxfilesdk/components/kfcurve/kfcurve.h>
00019 #include <fbxfilesdk/kfbxplugins/kfbxanimcurve.h>
00020 #include <fbxfilesdk/kfbxplugins/kfbxobject.h>
00021 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00022 
00023 class KSet;
00024 
00032 class KFBX_DLL KFbxAnimCurveKFCurveKey : public KFbxAnimCurveKeyImpl
00033 {
00034 private:
00035     KFCurveKey mKey;
00036 
00037 public:
00043 
00047     static KFbxAnimCurveKeyImpl* AllocatorFct()
00048     {
00049         return FbxSdkNew<KFbxAnimCurveKFCurveKey>();
00050     }
00051 
00056     static KFbxAnimCurveKeyImpl* CopyAllocatorFct(KFbxAnimCurveKeyImpl* pImpl)
00057     {
00058         return FbxSdkNew<KFbxAnimCurveKFCurveKey>(*((KFbxAnimCurveKFCurveKey*)pImpl));
00059     }
00060 
00064     static void DeallocatorFct(KFbxAnimCurveKeyImpl* pImpl)
00065     {
00066         FbxSdkDelete<KFbxAnimCurveKFCurveKey>((KFbxAnimCurveKFCurveKey*)pImpl);
00067     }
00068 
00071     KFbxAnimCurveKFCurveKey() : KFbxAnimCurveKeyImpl()
00072     {
00073         KTime lTime = GetTime();
00074         SetTime(lTime);
00075         mKey.Set(lTime, 0.0);
00076     };
00077 
00080     virtual ~KFbxAnimCurveKFCurveKey()
00081     {
00082         // nothing specific to do!
00083     }
00084 
00088     KFbxAnimCurveKFCurveKey(KTime pTime) : KFbxAnimCurveKeyImpl()
00089     {
00090         SetTime(pTime);
00091         mKey.Set(pTime, 0.0);
00092     }
00093 
00098     KFbxAnimCurveKFCurveKey(KTime pTime, float pVal) : KFbxAnimCurveKeyImpl()
00099     {
00100         SetTime(pTime);
00101         mKey.Set(pTime, pVal);
00102 
00103     }
00104 
00108     KFbxAnimCurveKFCurveKey(KFbxAnimCurveKFCurveKey const& pFKey) : KFbxAnimCurveKeyImpl()
00109     {
00110         mKey = pFKey.mKey;
00111         SetTime(mKey.GetTime());
00112     };
00113 
00117     KFbxAnimCurveKFCurveKey(KFCurveKey const& pFKey) : KFbxAnimCurveKeyImpl()
00118     {
00119         mKey = pFKey;
00120         SetTime(mKey.GetTime());
00121     };
00122 
00127     KFbxAnimCurveKeyImpl& operator=(const KFbxAnimCurveKeyImpl& pFKey)
00128     {
00129         *this = *((KFbxAnimCurveKFCurveKey*)&pFKey);
00130         return *this;
00131     }
00132 
00137     KFbxAnimCurveKFCurveKey& operator=(const KFbxAnimCurveKFCurveKey& pFKey)
00138     {
00139         SetTime(pFKey.GetTime());
00140         mKey = pFKey.mKey;
00141         return *this;
00142     }
00143 
00146     operator KFCurveKey&()
00147     { 
00148         return mKey; 
00149     };
00150 
00154     KFCurveKey* GetKFCurveKey()
00155     {
00156         return &mKey;
00157     };
00159 
00160     /* \name Key time, values, data.
00161     */
00163 
00166     virtual KTime GetTime() const
00167     {
00168         return mKey.GetTime();
00169     };
00170 
00174     virtual void  SetTime(const KTime& pTime)
00175     {
00176         mKey.SetTime(pTime);
00177     };
00178 
00183     void Set(KTime pTime, float pValue)
00184     {
00185         mKey.Set(pTime, pValue);
00186     }
00187 
00199     void SetTCB(KTime pTime, float pValue, float pData0 = 0.0f, float pData1 = 0.0f, float pData2 = 0.0f)
00200     {
00201         mKey.SetTCB(pTime, pValue, pData0, pData1, pData2);
00202     }
00203 
00207     float GetValue() const
00208     {
00209         return mKey.GetValue();
00210     }
00211 
00215     void SetValue(float pValue)
00216     {
00217         mKey.SetValue(pValue);
00218     }
00219 
00223     KFbxAnimCurveDef::EInterpolationType GetInterpolation() const
00224     {
00225         return KFbxAnimCurveDef::EInterpolationType(mKey.GetInterpolation());
00226     }
00227 
00231     void SetInterpolation (KFbxAnimCurveDef::EInterpolationType pInterpolation)
00232     {
00233         mKey.SetInterpolation(pInterpolation);
00234     }
00235 
00242     KFbxAnimCurveDef::ETangentMode GetTangentMode(bool pIncludeOverrides = false) const
00243     {
00244         return KFbxAnimCurveDef::ETangentMode(mKey.GetTangeantMode(pIncludeOverrides));
00245     }
00246 
00251     void SetTangentMode (KFbxAnimCurveDef::ETangentMode pTangentMode)
00252     {
00253         bool lTI = (pTangentMode&KFbxAnimCurveDef::eTANGENT_GENERIC_TIME_INDEPENDENT)==KFbxAnimCurveDef::eTANGENT_GENERIC_TIME_INDEPENDENT;
00254         mKey.SetTangeantMode(pTangentMode, lTI==false);
00255     }
00256 
00260     KFbxAnimCurveDef::EWeightedMode GetTangentWeightMode() const
00261     {
00262         return KFbxAnimCurveDef::EWeightedMode(mKey.GetTangeantWeightMode());
00263     }
00264 
00270     void SetTangentWeightMode(KFbxAnimCurveDef::EWeightedMode pTangentWeightMode, KFbxAnimCurveDef::EWeightedMode pMask = KFbxAnimCurveDef::eWEIGHTED_ALL )
00271     {
00272         mKey.SetTangeantWeightMode(pTangentWeightMode, pMask);
00273     }
00274 
00275 
00279     KFbxAnimCurveDef::EVelocityMode GetTangentVelocityMode() const
00280     {
00281         return KFbxAnimCurveDef::EVelocityMode(mKey.GetTangeantVelocityMode());
00282     }
00283 
00289     void SetTangentVelocityMode(KFbxAnimCurveDef::EVelocityMode pTangentVelocityMode, KFbxAnimCurveDef::EVelocityMode pMask = KFbxAnimCurveDef::eVELOCITY_ALL )
00290     {
00291         mKey.SetTangeantVelocityMode(pTangentVelocityMode, pMask);
00292     }
00293 
00299     KFbxAnimCurveDef::EConstantMode GetConstantMode() const
00300     {
00301         return KFbxAnimCurveDef::EConstantMode(mKey.GetConstantMode());
00302     }
00303 
00308     void SetConstantMode(KFbxAnimCurveDef::EConstantMode pMode)
00309     {
00310         mKey.SetConstantMode(pMode);
00311     }
00312 
00320     float GetDataFloat(KFbxAnimCurveDef::EKFbxAnimCurveDataIndex pIndex) const
00321     {
00322         // VR: The way KFCurveKey::GetDataFloat() and GetDataDouble() are implemented are different.
00323         // GetDataDouble() works for cases USER, AUTO, BREAK, etc, which have 2 or 4 float values to store.
00324         // GetDataFloat() works for the TCB case which has 3 float values (Tension, Continuity and Bias).
00325         // It is not my purpose to modify KFCurveKey at this point, so we use GetDataDouble in general,
00326         // and GetDataFloat in the case of a TCB.
00327 
00328         if (GetTangentMode() == KFbxAnimCurveDef::eTANGENT_TCB)
00329         {
00330             return mKey.GetDataFloat(EKFCurveDataIndex(pIndex));
00331         }
00332 
00333         return (float)mKey.GetDataDouble(EKFCurveDataIndex(pIndex));
00334     }
00335 
00343     void SetDataFloat(KFbxAnimCurveDef::EKFbxAnimCurveDataIndex pIndex, float pValue)
00344     {
00345         // VR: The way KFCurveKey::SetDataFloat() and SetDataDouble() are implemented are different.
00346         // SetDataDouble() works for cases USER, AUTO, BREAK, etc, which have 2 or 4 float values to store.
00347         // SetDataFloat() works for the TCB case which has 3 float values (Tension, Continuity and Bias).
00348         // It is not my purpose to modivy KFCurveKey at this point, so we use SetDataDouble in general,
00349         // and SetDataFloat in the case of a TCB.
00350 
00351         if (GetTangentMode() == KFbxAnimCurveDef::eTANGENT_TCB)
00352         {
00353             mKey.SetDataFloat(EKFCurveDataIndex(pIndex), pValue);
00354         }
00355 
00356         mKey.SetDataDouble(EKFCurveDataIndex(pIndex), (kFCurveDouble)pValue);
00357     }
00358 
00363     void    SetTangentVisibility (KFbxAnimCurveDef::ETangentVisibility pVisibility)
00364     {
00365         mKey.SetTangeantVisibility(pVisibility);
00366     }
00367 
00372     KFbxAnimCurveDef::ETangentVisibility GetTangentVisibility () const
00373     {
00374         return KFbxAnimCurveDef::ETangentVisibility(mKey.GetTangeantVisibility());
00375     }
00376 
00382     void SetBreak(bool pVal)
00383     {
00384         mKey.SetBreak(pVal);
00385     }
00386 
00392     bool GetBreak() const
00393     {
00394         return mKey.GetBreak();
00395     }
00397 };
00398 
00399 
00406 class KFBX_DLL KFbxAnimCurveKFCurve : public KFbxAnimCurve
00407 {
00408     KFBXOBJECT_DECLARE(KFbxAnimCurveKFCurve, KFbxAnimCurve);
00409 
00410 public:
00416 
00420         void ResizeKeyBuffer(int pKeyCount);
00421 
00425         void KeyModifyBegin ();
00426         
00430         void KeyModifyEnd ();
00431 
00435         void KeyShrink();
00436 
00438         virtual void KeyClear (); 
00439        
00443         virtual int KeyGetCount () const;
00444   
00460         int KeyAdd (KTime pTime, KFbxAnimCurveKeyBase& pKey, int* pLast = NULL); 
00461 
00475         int KeyAdd (KTime pTime, int* pLast = NULL) 
00476         {   
00477             KFbxAnimCurveKFCurveKey key(pTime);
00478             return KeyAdd(pTime, key, pLast); 
00479         }
00480 
00489         bool KeySet(int pIndex,  KFbxAnimCurveKeyBase& pKey);
00490         
00495         bool KeyRemove(int pIndex);
00496 
00502         bool KeyRemove(int pStartIndex, int pEndIndex);
00503 
00519         int KeyInsert ( KTime pTime, int* pLast = NULL );
00520         
00533         double KeyFind (KTime pTime, int* pLast = NULL);
00534 
00539         bool KeyScaleValue (float pMultValue);
00540 
00545         bool KeyScaleValueAndTangent (float pMultValue);
00547 
00570         void KeySet 
00571         (
00572             int pKeyIndex,
00573             KTime pTime, 
00574             float pValue, 
00575             KFbxAnimCurveDef::EInterpolationType pInterpolation = KFbxAnimCurveDef::eINTERPOLATION_CUBIC, 
00576             KFbxAnimCurveDef::ETangentMode pTangentMode = KFbxAnimCurveDef::eTANGENT_AUTO, 
00577             float pData0 = 0.0,
00578             float pData1 = 0.0,
00579             KFbxAnimCurveDef::EWeightedMode pTangentWeightMode = KFbxAnimCurveDef::eWEIGHTED_NONE, 
00580             float pWeight0 = KFbxAnimCurveDef::sDEFAULT_WEIGHT,
00581             float pWeight1 = KFbxAnimCurveDef::sDEFAULT_WEIGHT,
00582             float pVelocity0 = KFbxAnimCurveDef::sDEFAULT_VELOCITY,
00583             float pVelocity1 = KFbxAnimCurveDef::sDEFAULT_VELOCITY
00584         );
00585 
00598         void KeySetTCB 
00599         (
00600             int pKeyIndex,
00601             KTime pTime, 
00602             float pValue, 
00603             float pData0 = 0.0f, 
00604             float pData1 = 0.0f, 
00605             float pData2 = 0.0f
00606         );
00607 
00612         KFbxAnimCurveDef::EInterpolationType KeyGetInterpolation(int pKeyIndex) const;
00613 
00618         void KeySetInterpolation(int pKeyIndex, KFbxAnimCurveDef::EInterpolationType pInterpolation);
00619 
00626         KFbxAnimCurveDef::EConstantMode KeyGetConstantMode(int pKeyIndex) const;
00627 
00635         KFbxAnimCurveDef::ETangentMode KeyGetTangentMode(int pKeyIndex, bool pIncludeOverrides = false ) const;
00636 
00642         void KeySetConstantMode(int pKeyIndex, KFbxAnimCurveDef::EConstantMode pMode);
00643 
00649         void KeySetTangentMode(int pKeyIndex, KFbxAnimCurveDef::ETangentMode pTangent);
00650 
00657         KFbxAnimCurveKey KeyGet(int pIndex) const;
00658 
00663         float KeyGetValue(int pKeyIndex) const;
00664 
00669         void KeySetValue(int pKeyIndex, float pValue);
00670 
00675         void KeyIncValue(int pKeyIndex, float pValue);
00676 
00682         void KeyMultValue(int pKeyIndex, float pValue);
00683 
00690         void KeyMultTangent(int pKeyIndex, float pValue);
00691 
00696         virtual KTime KeyGetTime(int pKeyIndex) const;
00697 
00703         virtual void KeySetTime(int pKeyIndex, KTime pTime);
00704 
00711         void KeySetBreak(int pKeyIndex, bool pVal); 
00712 
00719         bool KeyGetBreak(int pKeyIndex) const; 
00721 
00732         float KeyGetLeftDerivative(int pIndex);
00733 
00743         void KeySetLeftDerivative(int pIndex, float pValue);
00744 
00752         float KeyGetLeftAuto(int pIndex, bool pApplyOvershootProtection = false);
00753 
00760         KFCurveTangeantInfo KeyGetLeftDerivativeInfo(kFCurveIndex pIndex);
00761 
00773         void KeySetLeftDerivativeInfo(kFCurveIndex pIndex, KFCurveTangeantInfo pValue, bool pForceDerivative = false);
00774 
00781         float KeyGetRightDerivative(int pIndex);
00782 
00792         void KeySetRightDerivative(int pIndex, float pValue);
00793 
00801         float KeyGetRightAuto(int pIndex, bool pApplyOvershootProtection = false);
00802 
00809         KFCurveTangeantInfo KeyGetRightDerivativeInfo(kFCurveIndex pIndex);
00810 
00822         void KeySetRightDerivativeInfo(kFCurveIndex pIndex, KFCurveTangeantInfo pValue, bool pForceDerivative = false);
00823 
00831         bool KeyIsLeftTangentWeighted(int pIndex) const;
00832 
00840         bool KeyIsRightTangentWeighted(int pIndex) const;
00841 
00847         float KeyGetLeftTangentWeight(int pIndex) const;
00848 
00854         float KeyGetRightTangentWeight(int pIndex) const;
00855 
00867         void   KeySetLeftTangentWeight( int pIndex, float pWeight, bool pAdjustTan = false );
00868 
00880         void   KeySetRightTangentWeight( int pIndex, float pWeight, bool pAdjustTan = false  );
00881 
00887         float KeyGetLeftTangentVelocity( int pIndex) const;
00888 
00894         float KeyGetRightTangentVelocity( int pIndex) const;
00895 
00897 
00914         virtual float Evaluate (KTime pTime, int* pLast = NULL);
00915 
00925         virtual float EvaluateIndex( double pIndex);
00926         
00934         float EvaluateLeftDerivative (KTime pTime, int* pLast = NULL);
00935         
00943         float EvaluateRightDerivative (KTime pTime, int* pLast = NULL);
00945 
00955         float GetValue() const;
00956 
00964         K_DEPRECATED virtual bool GetTimeInterval(KTime& pStart, KTime& pStop);
00965 
00971         virtual bool GetTimeInterval(KTimeSpan& pTimeInterval);
00972 
00976         void SetColor(float *pColor);
00977 
00981         float* GetColor();
00982 
00986         KFCurve* GetKFCurve();
00987 
00994         void CopyFrom(KFbxAnimCurve& pSource, bool pWithKeys = true);
00996 
00997 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00998 
00999     //  WARNING!
01000     //    Anything beyond these lines may not be documented accurately and is 
01001     //     subject to change without notice.
01003     virtual int KeyAdd (KTime pTime, KFbxAnimCurveKFCurveKey& pKey, int* pLast = 0);
01004     virtual bool KeySet(int pIndex, KFbxAnimCurveKFCurveKey& pKey);
01005 
01006 protected:
01007     KFbxAnimCurveKFCurve(KFbxSdkManager& pManager, char const* pName);
01008 
01009     virtual void Construct(const KFbxAnimCurve* pFrom);
01010     virtual void Destruct(bool pRecursive, bool pDependents);
01011  
01012     friend void CollectAnimFromCurveNode(KFCurve **lSrc, KFCurveNode *fcn, unsigned int nbCrvs, KFbxAnimCurveNode *cn, KSet* pNickToAnimCurveTimeWarpsSet, KSet& pNickToKFCurveNodeWarpSet);
01013     friend void TransferTimeWarp(int lNickNumber, KFCurveNode* lTimeWarp, KSet& mNickToKFCurveNodeTimeWarpsSet, KSet& pTimeWarpSet, KFbxScene& pScene);
01014     
01015     void SetKFCurve(KFCurve *lKFCurve);
01016     KFCurve* mFCurve;
01017 
01018 public:
01019     virtual bool Store(KFbx* pFileObject);
01020             bool LegacyStore(KFbx* pFileObject); // this one can only exist in this class and should not be inherited!
01021     virtual bool Retrieve(KFbx* pFileObject);
01022  
01023 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01024 };
01025 
01026 #include <fbxfilesdk/fbxfilesdk_nsend.h>
01027 
01028 #endif // FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H