colladaAppNode.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 _COLLADA_APPNODE_H_
  23. #define _COLLADA_APPNODE_H_
  24. #ifndef _TDICTIONARY_H_
  25. #include "core/util/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. class ColladaAppNode : public AppNode
  34. {
  35. typedef AppNode Parent;
  36. friend class ColladaAppMesh;
  37. MatrixF getTransform(F32 time);
  38. void buildMeshList();
  39. void buildChildList();
  40. protected:
  41. const domNode* p_domNode; ///< Pointer to the node in the Collada DOM
  42. ColladaAppNode* appParent; ///< Parent node in Collada-space
  43. ColladaExtension_node* nodeExt; ///< node extension
  44. Vector<AnimatedFloatList> nodeTransforms; ///< Ordered vector of node transform elements (scale, translate etc)
  45. bool invertMeshes; ///< True if this node's coordinate space is inverted (left handed)
  46. Map<StringTableEntry, F32> mProps; ///< Hash of float properties (converted to int or bool as needed)
  47. F32 lastTransformTime; ///< Time of the last transform lookup (getTransform)
  48. MatrixF lastTransform; ///< Last transform lookup (getTransform)
  49. bool defaultTransformValid; ///< Flag indicating whether the defaultNodeTransform is valid
  50. MatrixF defaultNodeTransform; ///< Transform at DefaultTime
  51. public:
  52. ColladaAppNode(const domNode* node, ColladaAppNode* parent = 0);
  53. virtual ~ColladaAppNode()
  54. {
  55. delete nodeExt;
  56. mProps.clear();
  57. }
  58. const domNode* getDomNode() const { return p_domNode; }
  59. //-----------------------------------------------------------------------
  60. const char *getName() { return mName; }
  61. const char *getParentName() { return mParentName; }
  62. bool isEqual(AppNode* node)
  63. {
  64. const ColladaAppNode* appNode = dynamic_cast<const ColladaAppNode*>(node);
  65. return (appNode && (appNode->p_domNode == p_domNode));
  66. }
  67. // Property look-ups: only float properties are stored, the rest are
  68. // converted from floats as needed
  69. bool getFloat(const char* propName, F32& defaultVal)
  70. {
  71. Map<StringTableEntry,F32>::Iterator itr = mProps.find(propName);
  72. if (itr != mProps.end())
  73. defaultVal = itr->value;
  74. return false;
  75. }
  76. bool getInt(const char* propName, S32& defaultVal)
  77. {
  78. F32 value = defaultVal;
  79. bool ret = getFloat(propName, value);
  80. defaultVal = (S32)value;
  81. return ret;
  82. }
  83. bool getBool(const char* propName, bool& defaultVal)
  84. {
  85. F32 value = defaultVal;
  86. bool ret = getFloat(propName, value);
  87. defaultVal = (value != 0);
  88. return ret;
  89. }
  90. MatrixF getNodeTransform(F32 time);
  91. bool animatesTransform(const AppSequence* appSeq);
  92. bool isParentRoot() { return (appParent == NULL); }
  93. };
  94. #endif // _COLLADA_APPNODE_H_