BsCRenderable.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "Renderer/BsRenderable.h"
  6. #include "Math/BsBounds.h"
  7. #include "Scene/BsComponent.h"
  8. namespace bs
  9. {
  10. /** @addtogroup Components
  11. * @{
  12. */
  13. /**
  14. * @copydoc Renderable
  15. *
  16. * Wraps a TRenderable as a Component.
  17. */
  18. class BS_CORE_EXPORT CRenderable : public Component
  19. {
  20. public:
  21. /** @copydoc Renderable::setMesh */
  22. void setMesh(HMesh mesh);
  23. /** @copydoc Renderable::setMaterial */
  24. void setMaterial(UINT32 idx, HMaterial material) { mInternal->setMaterial(idx, material); }
  25. /** @copydoc Renderable::setMaterial */
  26. void setMaterial(HMaterial material) { mInternal->setMaterial(material); }
  27. /** @copydoc Renderable::setLayer */
  28. void setLayer(UINT64 layer) { mInternal->setLayer(layer); }
  29. /** @copydoc Renderable::getLayer */
  30. UINT64 getLayer() const { return mInternal->getLayer(); }
  31. /** @copydoc Renderable::getMesh */
  32. HMesh getMesh() const { return mInternal->getMesh(); }
  33. /** @copydoc Renderable::getMaterial */
  34. HMaterial getMaterial(UINT32 idx) const { return mInternal->getMaterial(idx); }
  35. /** Gets world bounds of the mesh rendered by this object. */
  36. Bounds getBounds() const;
  37. /** @copydoc Component::calculateBounds */
  38. bool calculateBounds(Bounds& bounds) override;
  39. /** @name Internal
  40. * @{
  41. */
  42. /** Returns the internal renderable that is used for majority of operations by this component. */
  43. SPtr<Renderable> _getRenderable() const { return mInternal; }
  44. /** Registers an Animation component that will be used for animating the renderable's mesh. */
  45. void _registerAnimation(const HAnimation& animation);
  46. /** Removes the Animation component, making the renderable rendered as a static object. */
  47. void _unregisterAnimation();
  48. /** @} */
  49. private:
  50. mutable SPtr<Renderable> mInternal;
  51. HAnimation mAnimation;
  52. /************************************************************************/
  53. /* COMPONENT OVERRIDES */
  54. /************************************************************************/
  55. protected:
  56. friend class SceneObject;
  57. CRenderable(const HSceneObject& parent);
  58. /** @copydoc Component::onInitialized */
  59. void onInitialized() override;
  60. /** @copydoc Component::onDestroyed */
  61. void onDestroyed() override;
  62. public:
  63. /** @copydoc Component::update */
  64. void update() override;
  65. /************************************************************************/
  66. /* RTTI */
  67. /************************************************************************/
  68. public:
  69. friend class CRenderableRTTI;
  70. static RTTITypeBase* getRTTIStatic();
  71. RTTITypeBase* getRTTI() const override;
  72. protected:
  73. CRenderable(); // Serialization only
  74. };
  75. /** @} */
  76. }