assimpAppNode.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Point3F interpolateVectorKey(const aiVectorKey* keys, U32 numKeys, F32 frameTime);
  44. QuatF interpolateQuaternionKey(const aiQuatKey* keys, U32 numKeys, F32 frameTime);
  45. void buildMeshList() override {};
  46. void buildChildList() override {};
  47. protected:
  48. const aiScene* mScene;
  49. const aiNode* mNode; ///< Pointer to the assimp scene node
  50. AssimpAppNode* appParent; ///< Parent node
  51. MatrixF mNodeTransform; ///< Scene node transform converted to TorqueSpace (filled for ALL nodes)
  52. bool mInvertMeshes; ///< True if this node's coordinate space is inverted (left handed)
  53. F32 mLastTransformTime; ///< Time of the last transform lookup (getTransform)
  54. MatrixF mLastTransform; ///< Last transform lookup (getTransform) (Only Non-Dummy Nodes)
  55. bool mDefaultTransformValid; ///< Flag indicating whether the defaultNodeTransform is valid
  56. MatrixF mDefaultNodeTransform; ///< Transform at DefaultTime (Only Non-Dummy Nodes)
  57. public:
  58. AssimpAppNode(const aiScene* scene, const aiNode* node, AssimpAppNode* parentNode = nullptr);
  59. virtual ~AssimpAppNode()
  60. {
  61. //
  62. }
  63. static aiAnimation* sActiveSequence;
  64. static F32 sTimeMultiplier;
  65. //-----------------------------------------------------------------------
  66. const char *getName() override { return mName; }
  67. const char *getParentName() override { return mParentName; }
  68. bool isEqual(AppNode* node) override
  69. {
  70. const AssimpAppNode* appNode = dynamic_cast<const AssimpAppNode*>(node);
  71. return (appNode && (appNode->mNode == mNode));
  72. }
  73. // Property look-ups: only float properties are stored, the rest are
  74. // converted from floats as needed
  75. bool getFloat(const char* propName, F32& defaultVal) override
  76. {
  77. //Map<StringTableEntry,F32>::Iterator itr = mProps.find(propName);
  78. //if (itr != mProps.end())
  79. // defaultVal = itr->value;
  80. return false;
  81. }
  82. bool getInt(const char* propName, S32& defaultVal) override
  83. {
  84. F32 value = defaultVal;
  85. bool ret = getFloat(propName, value);
  86. defaultVal = (S32)value;
  87. return ret;
  88. }
  89. bool getBool(const char* propName, bool& defaultVal) override
  90. {
  91. F32 value = defaultVal;
  92. bool ret = getFloat(propName, value);
  93. defaultVal = (value != 0);
  94. return ret;
  95. }
  96. MatrixF getNodeTransform(F32 time) override;
  97. bool animatesTransform(const AppSequence* appSeq) override;
  98. bool isParentRoot() override { return (appParent == NULL); }
  99. static void assimpToTorqueMat(const aiMatrix4x4& inAssimpMat, MatrixF& outMat);
  100. static void convertMat(MatrixF& outMat);
  101. static aiNode* findChildNodeByName(const char* nodeName, aiNode* rootNode);
  102. void AssimpAppNode::addChild(AssimpAppNode* child);
  103. void AssimpAppNode::addMesh(AssimpAppMesh* child);
  104. };
  105. #endif // _ASSIMP_APPNODE_H_