ModelNode.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef ANKI_SCENE_MODEL_NODE_H
  2. #define ANKI_SCENE_MODEL_NODE_H
  3. #include "anki/scene/SceneNode.h"
  4. #include "anki/scene/Renderable.h"
  5. #include "anki/scene/Movable.h"
  6. #include "anki/scene/Spatial.h"
  7. #include "anki/resource/Resource.h"
  8. #include "anki/resource/Model.h"
  9. #include "anki/collision/Obb.h"
  10. namespace anki {
  11. /// @addtogroup Scene
  12. /// @{
  13. /// A model instance
  14. class ModelPatchNodeInstance: public SceneNode, public Movable, public Spatial
  15. {
  16. friend class ModelPatchNode;
  17. friend class ModelNode;
  18. public:
  19. ModelPatchNodeInstance(
  20. const char* name, SceneGraph* scene, SceneNode* parent, // Scene
  21. U32 movableFlags, // Movable
  22. const ModelPatchBase* modelPatchResource); // Self
  23. /// @name Movable virtuals
  24. /// @{
  25. /// Overrides Movable::moveUpdate(). This does:
  26. /// - Update the collision shape
  27. /// - If it's the last instance update the parent's CS.
  28. void movableUpdate();
  29. /// @}
  30. private:
  31. Obb obb; ///< In world space
  32. const ModelPatchBase* modelPatch; ///< Keep the resource for tha OBB
  33. };
  34. /// A fragment of the ModelNode
  35. class ModelPatchNode: public SceneNode, public Movable, public Renderable,
  36. public Spatial
  37. {
  38. friend class ModelPatchNodeInstance;
  39. friend class ModelNode;
  40. public:
  41. /// @name Constructors/Destructor
  42. /// @{
  43. ModelPatchNode(
  44. const char* name, SceneGraph* scene, SceneNode* parent, // Scene
  45. U32 movableFlags, // Movable
  46. const ModelPatchBase* modelPatch, U instances); // Self
  47. ~ModelPatchNode();
  48. /// @}
  49. /// @name Movable virtuals
  50. /// @{
  51. /// Overrides Movable::moveUpdate(). This does:
  52. /// - Update the collision shape
  53. void movableUpdate();
  54. /// @}
  55. /// @name Renderable virtuals
  56. /// @{
  57. /// Implements Renderable::getModelPatchBase
  58. const ModelPatchBase& getRenderableModelPatchBase()
  59. {
  60. return *modelPatch;
  61. }
  62. /// Implements Renderable::getMaterial
  63. const Material& getRenderableMaterial()
  64. {
  65. return modelPatch->getMaterial();
  66. }
  67. /// Overrides Renderable::getRenderableWorldTransforms
  68. const Transform* getRenderableWorldTransforms();
  69. /// Overrides Renderable::getRenderableInstancesCount
  70. U32 getRenderableInstancesCount()
  71. {
  72. // return this and the instances
  73. return (transforms.size() > 0) ? transforms.size() : 1;
  74. }
  75. /// @}
  76. private:
  77. Obb obb; ///< In world space.
  78. const ModelPatchBase* modelPatch; ///< The resource
  79. SceneVector<ModelPatchNodeInstance*> instances;
  80. SceneVector<Transform> transforms;
  81. /// This is called by the last of the instances on it's movableUpdate()
  82. void updateSpatialCs();
  83. };
  84. /// The model scene node
  85. class ModelNode: public SceneNode, public Movable
  86. {
  87. public:
  88. typedef SceneVector<ModelPatchNode*> ModelPatchNodes;
  89. /// @name Constructors/Destructor
  90. /// @{
  91. ModelNode(
  92. const char* name, SceneGraph* scene, SceneNode* node, // SceneNode
  93. U32 movableFlags, // Movable
  94. const char* modelFname, U instances = 1); // Self
  95. virtual ~ModelNode();
  96. /// @}
  97. /// @name Accessors
  98. /// @{
  99. const Model& getModel() const
  100. {
  101. return *model;
  102. }
  103. /// @}
  104. /// @name Movable virtuals
  105. /// @{
  106. /// Overrides Movable::moveUpdate(). This does:
  107. /// - Update collision shape
  108. void movableUpdate()
  109. {
  110. Movable::movableUpdate();
  111. }
  112. /// @}
  113. /// Set the local transform of one instance
  114. void setInstanceLocalTransform(U instanceIndex, const Transform& trf);
  115. private:
  116. ModelResourcePointer model; ///< The resource
  117. ModelPatchNodes patches;
  118. };
  119. /// @}
  120. } // end namespace anki
  121. #endif