| 1 | /**************************************************************************************** |
| 2 | |
| 3 | Copyright (C) 2015 Autodesk, Inc. |
| 4 | All rights reserved. |
| 5 | |
| 6 | Use of this software is subject to the terms of the Autodesk license agreement |
| 7 | provided at the time of installation or download, or which otherwise accompanies |
| 8 | this software in either electronic or hard copy form. |
| 9 | |
| 10 | ****************************************************************************************/ |
| 11 | |
| 12 | //! \file fbxanimevalstate.h |
| 13 | #ifndef _FBXSDK_SCENE_ANIMATION_EVALUATION_STATE_H_ |
| 14 | #define _FBXSDK_SCENE_ANIMATION_EVALUATION_STATE_H_ |
| 15 | |
| 16 | #include <fbxsdk/fbxsdk_def.h> |
| 17 | |
| 18 | #include <fbxsdk/core/base/fbxtime.h> |
| 19 | #include <fbxsdk/core/fbxpropertydef.h> |
| 20 | #include <fbxsdk/scene/geometry/fbxnode.h> |
| 21 | |
| 22 | #include <fbxsdk/fbxsdk_nsbegin.h> |
| 23 | |
| 24 | class FbxTransform; |
| 25 | class FbxNodeEvalState; |
| 26 | class FbxPropertyEvalState; |
| 27 | |
| 28 | typedef FbxMap<FbxNode*, FbxNodeEvalState*> FbxNodeEvalStateMap; |
| 29 | typedef FbxMap<FbxProperty, FbxPropertyEvalState*> FbxPropertyEvalStateMap; |
| 30 | typedef FbxMap<FbxAnimLayer*, FbxAnimCurveNode*> FbxAnimLayerCurveNodeMap; |
| 31 | typedef FbxMap<FbxProperty, FbxAnimLayerCurveNodeMap*> FbxPropertyCurveNodeMap; |
| 32 | |
| 33 | /** This class hold results from animation evaluations. To clear an evaluation state for re-use, it is possible to invalidate |
| 34 | * or to reset it. For the same scene with the same objects, invalidating an evaluation state is the quickest way to clear |
| 35 | * an evaluation state object for re-use because it only zeroes all the entries. A reset will delete all the entries. |
| 36 | * Unless the scene changes, for performance purposes it is recommended to invalidate evaluation states instead of resetting them. |
| 37 | * |
| 38 | * \internal |
| 39 | * \see FbxAnimEvaluator |
| 40 | */ |
| 41 | class FBXSDK_DLL FbxAnimEvalState |
| 42 | { |
| 43 | public: |
| 44 | /** Get the time associated with this evaluation state. |
| 45 | * \return The time associated with this evaluation state. */ |
| 46 | FbxTime GetTime() const; |
| 47 | |
| 48 | /** Reset an evaluation state by deleting the cache it contains. This will remove all entries in the cache. */ |
| 49 | void Reset(); |
| 50 | |
| 51 | /** Start a new evaluation state frame by zeroing the cache it contains, and changing its associated time. All |
| 52 | * node and property entries will remain in the list, but their evaluation state will not be up-to-date. |
| 53 | * \param pTime The time at which the evaluation state should be set after the invalidation. */ |
| 54 | void Begin(const FbxTime& pTime); |
| 55 | |
| 56 | /** Invalidate a node evaluation state to force update on next evaluation. |
| 57 | * \param pNode The node that needs to be updated on next evaluation. */ |
| 58 | void Flush(FbxNode* pNode); |
| 59 | |
| 60 | /** Invalidate a property evaluation state to force update on next evaluation. |
| 61 | * \param pProperty The property that needs to be updated on next evaluation. */ |
| 62 | void Flush(FbxProperty& pProperty); |
| 63 | |
| 64 | /** Get node transform evaluation result from the evaluation state. |
| 65 | * \param pNode The node for which the value was stored. |
| 66 | * \return The global or local matrix transform for the specified node. */ |
| 67 | FbxNodeEvalState* GetNodeEvalState(FbxNode* pNode); |
| 68 | |
| 69 | /** Get a property evaluation result from the evaluation state. |
| 70 | * \param pProperty The property for which the value was stored. |
| 71 | * \return The result value that was stored. */ |
| 72 | FbxPropertyEvalState* GetPropertyEvalState(FbxProperty& pProperty); |
| 73 | |
| 74 | /** Get a property curve node from the evaluation state for quick access. |
| 75 | * \param pProperty The property to search for its animation curve node. |
| 76 | * \param pAnimLayer The animation layer on which the animation curve node must be searched. |
| 77 | * \remark This function uses a map to store animation curve node search results. If animation curve nodes are replaced, the evaluation state must be reset. */ |
| 78 | FbxAnimCurveNode* GetPropertyCurveNode(FbxProperty& pProperty, FbxAnimLayer* pAnimLayer); |
| 79 | |
| 80 | /***************************************************************************************************************************** |
| 81 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
| 82 | *****************************************************************************************************************************/ |
| 83 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 84 | FbxAnimEvalState(); |
| 85 | virtual ~FbxAnimEvalState(); |
| 86 | |
| 87 | private: |
| 88 | FbxTime mTime; |
| 89 | FbxNodeEvalStateMap mNodeMap; |
| 90 | FbxPropertyEvalStateMap mPropertyMap; |
| 91 | FbxPropertyCurveNodeMap mPropertyCurveNodeMap; |
| 92 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
| 93 | }; |
| 94 | |
| 95 | //! This class serves as the base class for an evaluation state element. |
| 96 | class FBXSDK_DLL FbxEvalState |
| 97 | { |
| 98 | public: |
| 99 | FbxEvalState() : mUpToDate(false){} |
| 100 | bool mUpToDate; //!< If \c true, the evaluation state element is up-to-date for the current evaluation time. |
| 101 | }; |
| 102 | |
| 103 | //! This class hold results for node evaluation. |
| 104 | class FBXSDK_DLL FbxNodeEvalState : public FbxEvalState |
| 105 | { |
| 106 | public: |
| 107 | FbxNodeEvalState(FbxNode* pNode); |
| 108 | |
| 109 | FbxVector4 mLT; //!< Used to hold result value of LclTranslation property from node evaluation. |
| 110 | FbxVector4 mLR; //!< Used to hold result value of LclRotation property from node evaluation. |
| 111 | FbxVector4 mLS; //!< Used to hold result value of LclScaling property from node evaluation. |
| 112 | FbxAMatrix mLX; //!< Used to hold result local transform matrix from node evaluation. Pivots, offsets, pre/post rotation and all other transforms are taken into consideration. |
| 113 | FbxAMatrix mGX; //!< Used to hold result global transform matrix from node evaluation. Pivots, offsets, pre/post rotation and all other transforms are taken into consideration. |
| 114 | |
| 115 | /** mTransform is used to hold the corresponding FbxTransform of the node. |
| 116 | * This FbxTransform takes all transform-related info, including pivots, offsets, pre/post rotation, rotation order, limits, etc. |
| 117 | * The evaluation is actually done through the utility functions of FbxTransform. */ |
| 118 | FbxTransform* mTransform; |
| 119 | }; |
| 120 | |
| 121 | //! This class hold results for property evaluation. |
| 122 | class FBXSDK_DLL FbxPropertyEvalState : public FbxEvalState |
| 123 | { |
| 124 | public: |
| 125 | FbxPropertyEvalState(FbxProperty& pProperty); |
| 126 | virtual ~FbxPropertyEvalState(); |
| 127 | |
| 128 | template <class T> inline T Get() const { T lValue; mValue->Get(&lValue, FbxTypeOf(lValue)); return lValue; } |
| 129 | template <class T> inline bool Set(const T& pValue){ return mValue->Set(&pValue, FbxTypeOf(pValue)); } |
| 130 | |
| 131 | FbxPropertyValue* mValue; |
| 132 | }; |
| 133 | |
| 134 | #include <fbxsdk/fbxsdk_nsend.h> |
| 135 | |
| 136 | #endif /* _FBXSDK_SCENE_ANIMATION_EVALUATION_STATE_H_ */ |
| 137 | |