kfbxanimcurvekfcurve.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H
00005 #define FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2009 - 2010 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 
00042 #include <fbxfilesdk/components/kfcurve/kfcurve.h>
00043 #include <fbxfilesdk/kfbxplugins/kfbxanimcurve.h>
00044 #include <fbxfilesdk/kfbxplugins/kfbxobject.h>
00045 
00046 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00047 
00048 static void CollectAnimFromCurveNode(KFCurve **lSrc, KFCurveNode *fcn, unsigned int nbCrvs, KFbxAnimCurveNode *cn);
00049 
00057 class KFBX_DLL KFbxAnimCurveKFCurveKey : public KFbxAnimCurveKeyImpl
00058 {
00059 private:
00060     KFCurveKey mKey;
00061 
00062 public:
00063     static KFbxAnimCurveKeyImpl* AllocatorFct()
00064     {
00065         return FbxSdkNew<KFbxAnimCurveKFCurveKey>();
00066     }
00067 
00068     static KFbxAnimCurveKeyImpl* CopyAllocatorFct(KFbxAnimCurveKeyImpl* pImpl)
00069     {
00070         return FbxSdkNew<KFbxAnimCurveKFCurveKey>(*((KFbxAnimCurveKFCurveKey*)pImpl));
00071     }
00072 
00073     static void DeallocatorFct(KFbxAnimCurveKeyImpl* pImpl)
00074     {
00075         FbxSdkDelete<KFbxAnimCurveKFCurveKey>((KFbxAnimCurveKFCurveKey*)pImpl);
00076     }
00077 
00080     KFbxAnimCurveKFCurveKey() : KFbxAnimCurveKeyImpl()
00081     {
00082         KTime lTime = GetTime();
00083         SetTime(lTime);
00084         mKey.Set(lTime, 0.0);
00085     };
00086 
00089     virtual ~KFbxAnimCurveKFCurveKey()
00090     {
00091         // nothing specific to do!
00092     }
00093 
00094     KFbxAnimCurveKFCurveKey(KTime pTime) : KFbxAnimCurveKeyImpl()
00095     {
00096         SetTime(pTime);
00097         mKey.Set(pTime, 0.0);
00098     }
00099 
00100     KFbxAnimCurveKFCurveKey(KTime pTime, float pVal) : KFbxAnimCurveKeyImpl()
00101     {
00102         SetTime(pTime);
00103         mKey.Set(pTime, pVal);
00104 
00105     }
00106 
00110     KFbxAnimCurveKFCurveKey(KFbxAnimCurveKFCurveKey const& pFKey) : KFbxAnimCurveKeyImpl()
00111     {
00112         mKey = pFKey.mKey;
00113         SetTime(mKey.GetTime());
00114     };
00115 
00119     KFbxAnimCurveKFCurveKey(KFCurveKey const& pFKey) : KFbxAnimCurveKeyImpl()
00120     {
00121         mKey = pFKey;
00122         SetTime(mKey.GetTime());
00123     };
00124 
00127     KFbxAnimCurveKeyImpl& operator=(const KFbxAnimCurveKeyImpl& pFKey)
00128     {
00129         *this = *((KFbxAnimCurveKFCurveKey*)&pFKey);
00130         return *this;
00131     }
00132 
00135     KFbxAnimCurveKFCurveKey& operator=(const KFbxAnimCurveKFCurveKey& pFKey)
00136     {
00137         SetTime(pFKey.GetTime());
00138         mKey = pFKey.mKey;
00139         return *this;
00140     }
00141 
00144     operator KFCurveKey&()
00145     { 
00146         return mKey; 
00147     };
00148 
00152     KFCurveKey* GetKFCurveKey()
00153     {
00154         return &mKey;
00155     };
00156 
00160     virtual KTime GetTime() const
00161     {
00162         return mKey.GetTime();
00163     };
00164 
00168     virtual void  SetTime(const KTime& pTime)
00169     {
00170         mKey.SetTime(pTime);
00171     };
00172 
00177     void Set(KTime pTime, float pValue)
00178     {
00179         mKey.Set(pTime, pValue);
00180     }
00181 
00189     void SetTCB(KTime pTime, float pValue, float pData0 = 0.0f, float pData1 = 0.0f, float pData2 = 0.0f)
00190     {
00191         mKey.SetTCB(pTime, pValue, pData0, pData1, pData2);
00192     }
00193 
00197     float GetValue() const
00198     {
00199         return mKey.GetValue();
00200     }
00201 
00205     void SetValue(float pValue)
00206     {
00207         mKey.SetValue(pValue);
00208     }
00209 
00213     KFbxAnimCurveDef::EInterpolationType GetInterpolation() const
00214     {
00215         return KFbxAnimCurveDef::EInterpolationType(mKey.GetInterpolation());
00216     }
00217 
00221     void SetInterpolation (KFbxAnimCurveDef::EInterpolationType pInterpolation)
00222     {
00223         mKey.SetInterpolation(pInterpolation);
00224     }
00225 
00229     KFbxAnimCurveDef::ETangentMode GetTangentMode(bool pIncludeOverrides = false) const
00230     {
00231         return KFbxAnimCurveDef::ETangentMode(mKey.GetTangeantMode(pIncludeOverrides));
00232     }
00233 
00237     void SetTangentMode (KFbxAnimCurveDef::ETangentMode pTangentMode)
00238     {
00239         bool lTI = (pTangentMode&KFbxAnimCurveDef::eTANGENT_GENERIC_TIME_INDEPENDENT)==KFbxAnimCurveDef::eTANGENT_GENERIC_TIME_INDEPENDENT;
00240         mKey.SetTangeantMode(pTangentMode, lTI==false);
00241     }
00242 
00250     KFbxAnimCurveDef::EWeightedMode GetTangentWeightMode() const
00251     {
00252         return KFbxAnimCurveDef::EWeightedMode(mKey.GetTangeantWeightMode());
00253     }
00254 
00267     void SetTangentWeightMode(KFbxAnimCurveDef::EWeightedMode pTangentWeightMode, KFbxAnimCurveDef::EWeightedMode pMask = KFbxAnimCurveDef::eWEIGHTED_ALL )
00268     {
00269         mKey.SetTangeantWeightMode(pTangentWeightMode, pMask);
00270     }
00271 
00272 
00280     KFbxAnimCurveDef::EVelocityMode GetTangentVelocityMode() const
00281     {
00282         return KFbxAnimCurveDef::EVelocityMode(mKey.GetTangeantVelocityMode());
00283     }
00284 
00297     void SetTangentVelocityMode(KFbxAnimCurveDef::EVelocityMode pTangentVelocityMode, KFbxAnimCurveDef::EVelocityMode pMask = KFbxAnimCurveDef::eVELOCITY_ALL )
00298     {
00299         mKey.SetTangeantVelocityMode(pTangentVelocityMode, pMask);
00300     }
00301 
00309     KFbxAnimCurveDef::EConstantMode GetConstantMode() const
00310     {
00311         return KFbxAnimCurveDef::EConstantMode(mKey.GetConstantMode());
00312     }
00313 
00317     void SetConstantMode(KFbxAnimCurveDef::EConstantMode pMode)
00318     {
00319         mKey.SetConstantMode(pMode);
00320     }
00321 
00326     float GetDataFloat(KFbxAnimCurveDef::EKFbxAnimCurveDataIndex pIndex) const
00327     {
00328         // VR: The way KFCurveKey::GetDataFloat() and GetDataDouble() are implemented are different.
00329         // GetDataDouble() works for cases USER, AUTO, BREAK, etc, which have 2 or 4 float values to store.
00330         // GetDataFloat() works for the TCB case which has 3 float values (Tension, Continuity and Bias).
00331         // It is not my purpose to modivy KFCurveKey at this point, so we use GetDataDouble in general,
00332         // and GetDataFloat in the case of a TCB.
00333 
00334         if (GetTangentMode() == KFbxAnimCurveDef::eTANGENT_TCB)
00335         {
00336             return mKey.GetDataFloat(EKFCurveDataIndex(pIndex));
00337         }
00338 
00339         return (float)mKey.GetDataDouble(EKFCurveDataIndex(pIndex));
00340     }
00341 
00346     void SetDataFloat(KFbxAnimCurveDef::EKFbxAnimCurveDataIndex pIndex, float pValue)
00347     {
00348         // VR: The way KFCurveKey::SetDataFloat() and SetDataDouble() are implemented are different.
00349         // SetDataDouble() works for cases USER, AUTO, BREAK, etc, which have 2 or 4 float values to store.
00350         // SetDataFloat() works for the TCB case which has 3 float values (Tension, Continuity and Bias).
00351         // It is not my purpose to modivy KFCurveKey at this point, so we use SetDataDouble in general,
00352         // and SetDataFloat in the case of a TCB.
00353 
00354         if (GetTangentMode() == KFbxAnimCurveDef::eTANGENT_TCB)
00355         {
00356             mKey.SetDataFloat(EKFCurveDataIndex(pIndex), pValue);
00357         }
00358 
00359         mKey.SetDataDouble(EKFCurveDataIndex(pIndex), (kFCurveDouble)pValue);
00360     }
00361 
00369     void    SetTangentVisibility (KFbxAnimCurveDef::ETangentVisibility pVisibility)
00370     {
00371         mKey.SetTangeantVisibility(pVisibility);
00372     }
00373 
00381     KFbxAnimCurveDef::ETangentVisibility GetTangentVisibility () const
00382     {
00383         return KFbxAnimCurveDef::ETangentVisibility(mKey.GetTangeantVisibility());
00384     }
00385 
00390     void SetBreak(bool pVal)
00391     {
00392         mKey.SetBreak(pVal);
00393     }
00394 
00398     bool GetBreak() const
00399     {
00400         return mKey.GetBreak();
00401     }
00402 };
00403 
00404 
00412 class KFBX_DLL KFbxAnimCurveKFCurve : public KFbxAnimCurve
00413 {
00414     KFBXOBJECT_DECLARE(KFbxAnimCurveKFCurve, KFbxAnimCurve);
00415 
00416 public:
00417 
00422     float GetValue() const;
00423 
00432         void ResizeKeyBuffer(int pKeyCount);
00433 
00438         void KeyModifyBegin ();
00439         
00444         void KeyModifyEnd ();
00445 
00447         void KeyShrink();
00448 
00450         virtual void KeyClear (); 
00451        
00455         virtual int KeyGetCount () const;
00456   
00474         int KeyAdd (KTime pTime, KFbxAnimCurveKeyBase& pKey, int* pLast = NULL); 
00481         int KeyAdd (KTime pTime, int* pLast = NULL) 
00482         {   
00483             KFbxAnimCurveKFCurveKey key(pTime);
00484             return KeyAdd(pTime, key, pLast); 
00485         }
00486 
00495         bool KeySet(int pIndex,  KFbxAnimCurveKeyBase& pKey);
00496         
00501         bool KeyRemove(int pIndex);
00502 
00519         int KeyInsert ( KTime pTime, int* pLast = NULL );
00520         
00531         double KeyFind (KTime pTime, int* pLast = NULL);
00532 
00537         bool KeyScaleValue (float pMultValue);
00538 
00543         bool KeyScaleValueAndTangent (float pMultValue);
00545 
00566         void KeySet 
00567         (
00568             int pKeyIndex,
00569             KTime pTime, 
00570             float pValue, 
00571             KFbxAnimCurveDef::EInterpolationType pInterpolation = KFbxAnimCurveDef::eINTERPOLATION_CUBIC, 
00572             KFbxAnimCurveDef::ETangentMode pTangentMode = KFbxAnimCurveDef::eTANGENT_AUTO, 
00573             float pData0 = 0.0,
00574             float pData1 = 0.0,
00575             KFbxAnimCurveDef::EWeightedMode pTangentWeightMode = KFbxAnimCurveDef::eWEIGHTED_NONE, 
00576             float pWeight0 = KFbxAnimCurveDef::kDEFAULT_WEIGHT,
00577             float pWeight1 = KFbxAnimCurveDef::kDEFAULT_WEIGHT,
00578             float pVelocity0 = KFbxAnimCurveDef::kDEFAULT_VELOCITY,
00579             float pVelocity1 = KFbxAnimCurveDef::kDEFAULT_VELOCITY
00580         );
00581 
00590         void KeySetTCB 
00591         (
00592             int pKeyIndex,
00593             KTime pTime, 
00594             float pValue, 
00595             float pData0 = 0.0f, 
00596             float pData1 = 0.0f, 
00597             float pData2 = 0.0f
00598         );
00599 
00604         KFbxAnimCurveDef::EInterpolationType KeyGetInterpolation(int pKeyIndex) const;
00605 
00610         void KeySetInterpolation(int pKeyIndex, KFbxAnimCurveDef::EInterpolationType pInterpolation);
00611 
00618         KFbxAnimCurveDef::EConstantMode KeyGetConstantMode(int pKeyIndex) const;
00619 
00627         KFbxAnimCurveDef::ETangentMode KeyGetTangentMode(int pKeyIndex, bool pIncludeOverrides = false ) const;
00628 
00634         void KeySetConstantMode(int pKeyIndex, KFbxAnimCurveDef::EConstantMode pMode);
00635 
00641         void KeySetTangentMode(int pKeyIndex, KFbxAnimCurveDef::ETangentMode pTangent);
00642 
00648         KFbxAnimCurveKey KeyGet(int pIndex) const;
00649 
00654         float KeyGetValue(int pKeyIndex) const;
00655 
00660         void KeySetValue(int pKeyIndex, float pValue);
00661 
00666         void KeyIncValue(int pKeyIndex, float pValue);
00667 
00672         void KeyMultValue(int pKeyIndex, float pValue);
00673 
00680         void KeyMultTangent(int pKeyIndex, float pValue);
00681 
00686         virtual KTime KeyGetTime(int pKeyIndex) const;
00687 
00692         virtual void KeySetTime(int pKeyIndex, KTime pTime);
00693 
00699         void KeySetBreak(int pKeyIndex, bool pVal); 
00700 
00705         bool KeyGetBreak(int pKeyIndex) const; 
00707 
00718         float KeyGetLeftDerivative(int pIndex);
00719 
00727         void KeySetLeftDerivative(int pIndex, float pValue);
00728 
00736         float KeyGetLeftAuto(int pIndex, bool pApplyOvershootProtection = false);
00737 
00744         KFCurveTangeantInfo KeyGetLeftDerivativeInfo(kFCurveIndex pIndex);
00745 
00756         void KeySetLeftDerivativeInfo(kFCurveIndex pIndex, KFCurveTangeantInfo pValue, bool pForceDerivative = false);
00757 
00764         float KeyGetRightDerivative(int pIndex);
00765 
00773         void KeySetRightDerivative(int pIndex, float pValue);
00774 
00782         float KeyGetRightAuto(int pIndex, bool pApplyOvershootProtection = false);
00783 
00790         KFCurveTangeantInfo KeyGetRightDerivativeInfo(kFCurveIndex pIndex);
00791 
00802         void KeySetRightDerivativeInfo(kFCurveIndex pIndex, KFCurveTangeantInfo pValue, bool pForceDerivative = false);
00803 
00810         bool KeyIsLeftTangentWeighted(int pIndex) const;
00811 
00818         bool KeyIsRightTangentWeighted(int pIndex) const;
00819 
00825         float KeyGetLeftTangentWeight(int pIndex) const;
00826 
00832         float KeyGetRightTangentWeight(int pIndex) const;
00833 
00843         void   KeySetLeftTangentWeight( int pIndex, float pWeight, bool pAdjustTan = false );
00844 
00854         void   KeySetRightTangentWeight( int pIndex, float pWeight, bool pAdjustTan = false  );
00855 
00861         float KeyGetLeftTangentVelocity( int pIndex) const;
00862 
00868         float KeyGetRightTangentVelocity( int pIndex) const;
00869 
00871 
00887           virtual float Evaluate (KTime pTime, int* pLast = NULL);
00888 
00897         virtual float EvaluateIndex( double pIndex);
00898         
00907           float EvaluateLeftDerivative (KTime pTime, int* pLast = NULL);
00908         
00917           float EvaluateRightDerivative (KTime pTime, int* pLast = NULL);
00919 
00931         virtual bool GetTimeInterval(KTime& pStart, KTime& pStop);
00932 
00936         void SetColor(float *pColor);
00937 
00941         float* GetColor();
00942 
00946         KFCurve* GetKFCurve();
00947 
00954         void CopyFrom(KFbxAnimCurve& pSource, bool pWithKeys = true);
00956 
00957 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00959     //  WARNING!
00960     //    Anything beyond these lines may not be documented accurately and is 
00961     //     subject to change without notice.
00963     virtual int KeyAdd (KTime pTime, KFbxAnimCurveKFCurveKey& pKey, int* pLast = 0);
00964     virtual bool KeySet(int pIndex, KFbxAnimCurveKFCurveKey& pKey);
00965 
00966 protected:
00967     KFbxAnimCurveKFCurve(KFbxSdkManager& pManager, char const* pName);
00968 
00969     virtual void Construct(const KFbxAnimCurve* pFrom);
00970     virtual void Destruct(bool pRecursive, bool pDependents);
00971  
00972     friend void CollectAnimFromCurveNode(KFCurve **lSrc, KFCurveNode *fcn, unsigned int nbCrvs, KFbxAnimCurveNode *cn);
00973     void SetKFCurve(KFCurve *lKFCurve);
00974     KFCurve* mFCurve;
00975 
00976 public:
00977     virtual bool Store(KFbx* pFileObject);
00978     virtual bool Retrieve(KFbx* pFileObject);
00979 
00980 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00981 };
00982 
00983 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00984 
00985 #endif // FBXFILESDK_KFBXPLUGINS_KFBXANIMCURVEKFCURVE_H