| 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 | #include "Components/BsCLightProbeVolume.h" |
| 4 | #include "Private/RTTI/BsCLightProbeVolumeRTTI.h" |
| 5 | #include "Scene/BsSceneManager.h" |
| 6 | |
| 7 | namespace bs |
| 8 | { |
| 9 | CLightProbeVolume::CLightProbeVolume() |
| 10 | { |
| 11 | setFlag(ComponentFlag::AlwaysRun, true); |
| 12 | setName("LightProbeVolume"); |
| 13 | } |
| 14 | |
| 15 | CLightProbeVolume::CLightProbeVolume(const HSceneObject& parent, const AABox& volume, const Vector3I& cellCount) |
| 16 | :Component(parent), mVolume(volume), mCellCount(cellCount) |
| 17 | { |
| 18 | setFlag(ComponentFlag::AlwaysRun, true); |
| 19 | setName("LightProbeVolume"); |
| 20 | } |
| 21 | |
| 22 | CLightProbeVolume::~CLightProbeVolume() |
| 23 | { |
| 24 | if(mInternal != nullptr) |
| 25 | mInternal->destroy(); |
| 26 | } |
| 27 | |
| 28 | void CLightProbeVolume::renderProbe(UINT32 handle) |
| 29 | { |
| 30 | if (mInternal != nullptr && SO()->getActive()) |
| 31 | { |
| 32 | mInternal->_updateState(*SO()); |
| 33 | mInternal->renderProbe(handle); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | void CLightProbeVolume::renderProbes() |
| 38 | { |
| 39 | if (mInternal != nullptr && SO()->getActive()) |
| 40 | { |
| 41 | mInternal->_updateState(*SO()); |
| 42 | mInternal->renderProbes(); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | Vector<LightProbeInfo> CLightProbeVolume::getProbes() const |
| 47 | { |
| 48 | if (mInternal != nullptr) |
| 49 | return mInternal->getProbes(); |
| 50 | |
| 51 | return Vector<LightProbeInfo>(); |
| 52 | } |
| 53 | |
| 54 | void CLightProbeVolume::onInitialized() |
| 55 | { |
| 56 | // If mInternal already exists this means this object was deserialized, |
| 57 | // so all we need to do is initialize it. |
| 58 | if (mInternal != nullptr) |
| 59 | mInternal->initialize(); |
| 60 | else |
| 61 | mInternal = LightProbeVolume::create(mVolume, mCellCount); |
| 62 | |
| 63 | gSceneManager()._bindActor(mInternal, sceneObject()); |
| 64 | } |
| 65 | |
| 66 | void CLightProbeVolume::onDestroyed() |
| 67 | { |
| 68 | gSceneManager()._unbindActor(mInternal); |
| 69 | } |
| 70 | |
| 71 | RTTITypeBase* CLightProbeVolume::getRTTIStatic() |
| 72 | { |
| 73 | return CLightProbeVolumeRTTI::instance(); |
| 74 | } |
| 75 | |
| 76 | RTTITypeBase* CLightProbeVolume::getRTTI() const |
| 77 | { |
| 78 | return CLightProbeVolume::getRTTIStatic(); |
| 79 | } |
| 80 | } |
| 81 |