assimpAppNode.h 4.8 KB

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