assimpAppNode.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _ASSIMP_APPNODE_H_
  23. #define _ASSIMP_APPNODE_H_
  24. #ifndef _TDICTIONARY_H_
  25. #include "core/tDictionary.h"
  26. #endif
  27. #ifndef _APPNODE_H_
  28. #include "ts/loader/appNode.h"
  29. #endif
  30. #ifndef _COLLADA_EXTENSIONS_H_
  31. #include "ts/collada/colladaExtensions.h"
  32. #endif
  33. #ifndef AI_TYPES_H_INC
  34. #include <assimp/types.h>
  35. #endif
  36. #include <assimp/scene.h>
  37. class AssimpAppNode : public AppNode
  38. {
  39. typedef AppNode Parent;
  40. friend class AssimpAppMesh;
  41. MatrixF getTransform(F32 time);
  42. void getAnimatedTransform(MatrixF& mat, F32 t, aiAnimation* animSeq);
  43. void buildMeshList();
  44. void buildChildList();
  45. protected:
  46. const struct aiScene* mScene;
  47. const struct aiNode* mNode; ///< Pointer to the assimp scene node
  48. AssimpAppNode* appParent; ///< Parent node
  49. MatrixF mNodeTransform; ///< Scene node transform converted to TorqueSpace (filled for ALL nodes)
  50. bool mInvertMeshes; ///< True if this node's coordinate space is inverted (left handed)
  51. F32 mLastTransformTime; ///< Time of the last transform lookup (getTransform)
  52. MatrixF mLastTransform; ///< Last transform lookup (getTransform) (Only Non-Dummy Nodes)
  53. bool mDefaultTransformValid; ///< Flag indicating whether the defaultNodeTransform is valid
  54. MatrixF mDefaultNodeTransform; ///< Transform at DefaultTime (Only Non-Dummy Nodes)
  55. public:
  56. AssimpAppNode(const struct aiScene* scene, const struct aiNode* node, AssimpAppNode* parent = 0);
  57. virtual ~AssimpAppNode()
  58. {
  59. //
  60. }
  61. static aiAnimation* sActiveSequence;
  62. static F32 sTimeMultiplier;
  63. //-----------------------------------------------------------------------
  64. const char *getName() { return mName; }
  65. const char *getParentName() { return mParentName; }
  66. bool isEqual(AppNode* node)
  67. {
  68. const AssimpAppNode* appNode = dynamic_cast<const AssimpAppNode*>(node);
  69. return (appNode && (appNode->mNode == mNode));
  70. }
  71. // Property look-ups: only float properties are stored, the rest are
  72. // converted from floats as needed
  73. bool getFloat(const char* propName, F32& defaultVal)
  74. {
  75. //Map<StringTableEntry,F32>::Iterator itr = mProps.find(propName);
  76. //if (itr != mProps.end())
  77. // defaultVal = itr->value;
  78. return false;
  79. }
  80. bool getInt(const char* propName, S32& defaultVal)
  81. {
  82. F32 value = defaultVal;
  83. bool ret = getFloat(propName, value);
  84. defaultVal = (S32)value;
  85. return ret;
  86. }
  87. bool getBool(const char* propName, bool& defaultVal)
  88. {
  89. F32 value = defaultVal;
  90. bool ret = getFloat(propName, value);
  91. defaultVal = (value != 0);
  92. return ret;
  93. }
  94. MatrixF getNodeTransform(F32 time);
  95. bool animatesTransform(const AppSequence* appSeq);
  96. bool isParentRoot() { return (appParent == NULL); }
  97. static void assimpToTorqueMat(const aiMatrix4x4& inAssimpMat, MatrixF& outMat);
  98. static void convertMat(MatrixF& outMat);
  99. static aiNode* findChildNodeByName(const char* nodeName, aiNode* rootNode);
  100. };
  101. #endif // _ASSIMP_APPNODE_H_