ModelNode.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #ifndef ANKI_SCENE_MODEL_NODE_H
  6. #define ANKI_SCENE_MODEL_NODE_H
  7. #include "anki/scene/SceneNode.h"
  8. #include "anki/scene/RenderComponent.h"
  9. #include "anki/scene/MoveComponent.h"
  10. #include "anki/scene/SpatialComponent.h"
  11. #include "anki/resource/Resource.h"
  12. #include "anki/resource/Model.h"
  13. #include "anki/collision/Obb.h"
  14. namespace anki {
  15. // Forward
  16. class ObbSpatialComponent;
  17. class BodyComponent;
  18. class PhysicsBody;
  19. /// @addtogroup scene
  20. /// @{
  21. /// A fragment of the ModelNode
  22. class ModelPatchNode: public SceneNode
  23. {
  24. friend class ModelNode;
  25. friend class ModelPatchRenderComponent;
  26. public:
  27. ModelPatchNode(SceneGraph* scene);
  28. ~ModelPatchNode();
  29. ANKI_USE_RESULT Error create(
  30. const CString& name, const ModelPatchBase* modelPatch);
  31. private:
  32. Obb m_obb; ///< In world space
  33. const ModelPatchBase* m_modelPatch; ///< The resource
  34. SceneDArray<ObbSpatialComponent*> m_spatials;
  35. ANKI_USE_RESULT Error updateInstanceSpatials(
  36. const MoveComponent* instanceMoves[],
  37. U32 instanceMovesCount);
  38. ANKI_USE_RESULT Error buildRendering(RenderingBuildData& data);
  39. void getRenderWorldTransform(U index, Transform& trf);
  40. };
  41. /// The model scene node
  42. class ModelNode: public SceneNode
  43. {
  44. friend class ModelPatchNode;
  45. friend class ModelMoveFeedbackComponent;
  46. public:
  47. ModelNode(SceneGraph* scene);
  48. ~ModelNode();
  49. ANKI_USE_RESULT Error create(
  50. const CString& name, const CString& modelFname);
  51. const Model& getModel() const
  52. {
  53. return *m_model;
  54. }
  55. /// Override SceneNode::frameUpdate
  56. ANKI_USE_RESULT Error frameUpdate(F32, F32) override;
  57. private:
  58. ModelResourcePointer m_model; ///< The resource
  59. SceneDArray<ModelPatchNode*> m_modelPatches;
  60. SceneDArray<Transform> m_transforms; ///< Cache the transforms of instances
  61. Timestamp m_transformsTimestamp;
  62. PhysicsBody* m_body = nullptr;
  63. BodyComponent* m_bodyComp = nullptr;
  64. void onMoveComponentUpdate(MoveComponent& move);
  65. };
  66. /// @}
  67. } // end namespace anki
  68. #endif