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/BsCReflectionProbe.h"
4#include "Private/RTTI/BsCReflectionProbeRTTI.h"
5#include "Scene/BsSceneManager.h"
6
7namespace bs
8{
9 CReflectionProbe::CReflectionProbe()
10 {
11 setFlag(ComponentFlag::AlwaysRun, true);
12 setName("ReflectionProbe");
13 }
14
15 CReflectionProbe::CReflectionProbe(const HSceneObject& parent)
16 : Component(parent)
17 {
18 setFlag(ComponentFlag::AlwaysRun, true);
19 setName("ReflectionProbe");
20 }
21
22 CReflectionProbe::~CReflectionProbe()
23 {
24 mInternal->destroy();
25 }
26
27 Sphere CReflectionProbe::getBounds() const
28 {
29 mInternal->_updateState(*SO());
30
31 return mInternal->getBounds();
32 }
33
34 void CReflectionProbe::onInitialized()
35 {
36 // If mInternal already exists this means this object was deserialized,
37 // so all we need to do is initialize it.
38 if (mInternal != nullptr)
39 mInternal->initialize();
40 else
41 mInternal = ReflectionProbe::createBox(Vector3::ONE);
42
43 gSceneManager()._bindActor(mInternal, sceneObject());
44
45 // If filtered texture doesn't exist, ensure it is generated
46 SPtr<Texture> filteredTexture = mInternal->getFilteredTexture();
47 if(filteredTexture == nullptr)
48 {
49 if (mInternal->getCustomTexture())
50 mInternal->filter();
51 else
52 mInternal->capture();
53 }
54 }
55
56 void CReflectionProbe::onDestroyed()
57 {
58 gSceneManager()._unbindActor(mInternal);
59 }
60
61 RTTITypeBase* CReflectionProbe::getRTTIStatic()
62 {
63 return CReflectionProbeRTTI::instance();
64 }
65
66 RTTITypeBase* CReflectionProbe::getRTTI() const
67 {
68 return CReflectionProbe::getRTTIStatic();
69 }
70}
71