| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "BsCorePrerequisites.h" |
| 6 | #include "Renderer/BsRenderable.h" |
| 7 | #include "Math/BsBounds.h" |
| 8 | #include "Scene/BsComponent.h" |
| 9 | |
| 10 | namespace bs |
| 11 | { |
| 12 | /** @addtogroup Components-Core |
| 13 | * @{ |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * @copydoc Renderable |
| 18 | * |
| 19 | * @note Wraps a Renderable as a Component. |
| 20 | */ |
| 21 | class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering,n:Renderable) CRenderable : public Component |
| 22 | { |
| 23 | public: |
| 24 | /** @copydoc Renderable::setMesh */ |
| 25 | BS_SCRIPT_EXPORT(n:Mesh,pr:setter) |
| 26 | void setMesh(HMesh mesh); |
| 27 | |
| 28 | /** @copydoc Renderable::getMesh */ |
| 29 | BS_SCRIPT_EXPORT(n:Mesh,pr:getter) |
| 30 | HMesh getMesh() const { return mInternal->getMesh(); } |
| 31 | |
| 32 | /** @copydoc Renderable::setMaterial */ |
| 33 | BS_SCRIPT_EXPORT(n:SetMaterial) |
| 34 | void setMaterial(UINT32 idx, HMaterial material) { mInternal->setMaterial(idx, material); } |
| 35 | |
| 36 | /** @copydoc Renderable::setMaterial */ |
| 37 | BS_SCRIPT_EXPORT(n:SetMaterial) |
| 38 | void setMaterial(HMaterial material) { mInternal->setMaterial(material); } |
| 39 | |
| 40 | /** @copydoc Renderable::getMaterial */ |
| 41 | BS_SCRIPT_EXPORT(n:GetMaterial) |
| 42 | HMaterial getMaterial(UINT32 idx) const { return mInternal->getMaterial(idx); } |
| 43 | |
| 44 | /** @copydoc Renderable::setMaterials */ |
| 45 | BS_SCRIPT_EXPORT(n:Materials,pr:setter) |
| 46 | void setMaterials(const Vector<HMaterial>& materials) { mInternal->setMaterials(materials); } |
| 47 | |
| 48 | /** @copydoc Renderable::getMaterials */ |
| 49 | BS_SCRIPT_EXPORT(n:Materials,pr:getter) |
| 50 | const Vector<HMaterial>& getMaterials() { return mInternal->getMaterials(); } |
| 51 | |
| 52 | /** @copydoc Renderable::setCullDistanceFactor */ |
| 53 | BS_SCRIPT_EXPORT(n:CullDistance, pr:setter) |
| 54 | void setCullDistanceFactor(float factor) { mInternal->setCullDistanceFactor(factor); } |
| 55 | |
| 56 | /** @copydoc Renderable::getCullDistanceFactor */ |
| 57 | BS_SCRIPT_EXPORT(n:CullDistance, pr:getter) |
| 58 | float getCullDistanceFactor() const { return mInternal->getCullDistanceFactor(); } |
| 59 | |
| 60 | /** @copydoc Renderable::setLayer */ |
| 61 | BS_SCRIPT_EXPORT(n:Layers,pr:setter) |
| 62 | void setLayer(UINT64 layer) { mInternal->setLayer(layer); } |
| 63 | |
| 64 | /** @copydoc Renderable::getLayer */ |
| 65 | BS_SCRIPT_EXPORT(n:Layers,pr:getter) |
| 66 | UINT64 getLayer() const { return mInternal->getLayer(); } |
| 67 | |
| 68 | /** Gets world bounds of the mesh rendered by this object. */ |
| 69 | BS_SCRIPT_EXPORT(n:Bounds,pr:getter) |
| 70 | Bounds getBounds() const; |
| 71 | |
| 72 | /** @copydoc Component::calculateBounds */ |
| 73 | bool calculateBounds(Bounds& bounds) override; |
| 74 | |
| 75 | /** @name Internal |
| 76 | * @{ |
| 77 | */ |
| 78 | |
| 79 | /** Returns the internal renderable that is used for majority of operations by this component. */ |
| 80 | SPtr<Renderable> _getInternal() const { return mInternal; } |
| 81 | |
| 82 | /** Registers an Animation component that will be used for animating the renderable's mesh. */ |
| 83 | void _registerAnimation(const HAnimation& animation); |
| 84 | |
| 85 | /** Removes the Animation component, making the renderable rendered as a static object. */ |
| 86 | void _unregisterAnimation(); |
| 87 | |
| 88 | /** @} */ |
| 89 | |
| 90 | private: |
| 91 | mutable SPtr<Renderable> mInternal; |
| 92 | HAnimation mAnimation; |
| 93 | |
| 94 | /************************************************************************/ |
| 95 | /* COMPONENT OVERRIDES */ |
| 96 | /************************************************************************/ |
| 97 | |
| 98 | protected: |
| 99 | friend class SceneObject; |
| 100 | |
| 101 | CRenderable(const HSceneObject& parent); |
| 102 | |
| 103 | /** @copydoc Component::onInitialized */ |
| 104 | void onInitialized() override; |
| 105 | |
| 106 | /** @copydoc Component::onDestroyed */ |
| 107 | void onDestroyed() override; |
| 108 | |
| 109 | public: |
| 110 | /** @copydoc Component::update */ |
| 111 | void update() override; |
| 112 | |
| 113 | /************************************************************************/ |
| 114 | /* RTTI */ |
| 115 | /************************************************************************/ |
| 116 | public: |
| 117 | friend class CRenderableRTTI; |
| 118 | static RTTITypeBase* getRTTIStatic(); |
| 119 | RTTITypeBase* getRTTI() const override; |
| 120 | |
| 121 | protected: |
| 122 | CRenderable(); // Serialization only |
| 123 | }; |
| 124 | |
| 125 | /** @} */ |
| 126 | } |