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/BsLight.h"
7#include "Scene/BsComponent.h"
8
9namespace bs
10{
11 /** @addtogroup Components-Core
12 * @{
13 */
14
15 /**
16 * @copydoc Light
17 *
18 * @note Wraps Light as a Component.
19 */
20 class BS_CORE_EXPORT BS_SCRIPT_EXPORT(m:Rendering,n:Light) CLight : public Component
21 {
22 public:
23 CLight(const HSceneObject& parent, LightType type = LightType::Radial, Color color = Color::White,
24 float intensity = 100.0f, float range = 1.0f, bool castsShadows = false, Degree spotAngle = Degree(45),
25 Degree spotFalloffAngle = Degree(40));
26
27 virtual ~CLight();
28
29 /** @copydoc Light::setType */
30 BS_SCRIPT_EXPORT(n:Type,pr:setter)
31 void setType(LightType type) { mInternal->setType(type); }
32
33 /** @copydoc Light::getType */
34 BS_SCRIPT_EXPORT(n:Type,pr:getter)
35 LightType getType() const { return mInternal->getType(); }
36
37 /** @copydoc Light::setColor */
38 BS_SCRIPT_EXPORT(n:Color,pr:setter)
39 void setColor(const Color& color) { mInternal->setColor(color); }
40
41 /** @copydoc Light::getColor */
42 BS_SCRIPT_EXPORT(n:Color,pr:getter)
43 Color getColor() const { return mInternal->getColor(); }
44
45 /** @copydoc Light::setIntensity */
46 BS_SCRIPT_EXPORT(n:Intensity,pr:setter)
47 void setIntensity(float intensity) { mInternal->setIntensity(intensity); }
48
49 /** @copydoc Light::getIntensity */
50 BS_SCRIPT_EXPORT(n:Intensity,pr:getter)
51 float getIntensity() const { return mInternal->getIntensity(); }
52
53 /** @copydoc Light::setUseAutoAttenuation */
54 BS_SCRIPT_EXPORT(n:UseAutoAttenuation,pr:setter)
55 void setUseAutoAttenuation(bool enabled) { mInternal->setUseAutoAttenuation(enabled); }
56
57 /** @copydoc Light::getUseAutoAttenuation */
58 BS_SCRIPT_EXPORT(n:UseAutoAttenuation,pr:getter)
59 bool getUseAutoAttenuation() const { return mInternal->getUseAutoAttenuation(); }
60
61 /** @copydoc Light::setAttenuationRadius */
62 BS_SCRIPT_EXPORT(n:AttenuationRadius,pr:setter)
63 void setAttenuationRadius(float radius) { mInternal->setAttenuationRadius(radius); }
64
65 /** @copydoc Light::getAttenuationRadius */
66 BS_SCRIPT_EXPORT(n:AttenuationRadius,pr:getter)
67 float getAttenuationRadius() const { return mInternal->getAttenuationRadius(); }
68
69 /** @copydoc Light::setSourceRadius */
70 BS_SCRIPT_EXPORT(n:SourceRadius,pr:setter)
71 void setSourceRadius(float radius) { mInternal->setSourceRadius(radius); }
72
73 /** @copydoc Light::getSourceRadius */
74 BS_SCRIPT_EXPORT(n:SourceRadius,pr:getter)
75 float getSourceRadius() const { return mInternal->getSourceRadius(); }
76
77 /** @copydoc Light::setSpotAngle */
78 BS_SCRIPT_EXPORT(n:SpotAngle,pr:setter,range:[1,180],slider)
79 void setSpotAngle(const Degree& spotAngle) { mInternal->setSpotAngle(spotAngle); }
80
81 /** @copydoc Light::getSpotAngle */
82 BS_SCRIPT_EXPORT(n:SpotAngle,pr:getter)
83 Degree getSpotAngle() const { return mInternal->getSpotAngle(); }
84
85 /** @copydoc Light::setSpotFalloffAngle */
86 BS_SCRIPT_EXPORT(n:SpotAngleFalloff,pr:setter,range:[1,180],slider)
87 void setSpotFalloffAngle(const Degree& spotAngle) { mInternal->setSpotFalloffAngle(spotAngle); }
88
89 /** @copydoc Light::getSpotFalloffAngle */
90 BS_SCRIPT_EXPORT(n:SpotAngleFalloff,pr:getter)
91 Degree getSpotFalloffAngle() const { return mInternal->getSpotFalloffAngle(); }
92
93 /** @copydoc Light::setCastsShadow */
94 BS_SCRIPT_EXPORT(n:CastsShadow,pr:setter)
95 void setCastsShadow(bool castsShadow) { mInternal->setCastsShadow(castsShadow); }
96
97 /** @copydoc Light::getCastsShadow */
98 BS_SCRIPT_EXPORT(n:CastsShadow,pr:getter)
99 bool getCastsShadow() const { return mInternal->getCastsShadow(); }
100
101 /** @copydoc Light::setShadowBias */
102 BS_SCRIPT_EXPORT(n:ShadowBias,pr:setter,range:[-1,1],slider)
103 void setShadowBias(float bias) { mInternal->setShadowBias(bias); }
104
105 /** @copydoc Light::setShadowBias() */
106 BS_SCRIPT_EXPORT(n:ShadowBias,pr:getter)
107 float getShadowBias() const { return mInternal->getShadowBias(); }
108
109 /** @copydoc Light::getBounds */
110 BS_SCRIPT_EXPORT(n:Bounds,pr:getter)
111 Sphere getBounds() const;
112
113 /** @name Internal
114 * @{
115 */
116
117 /** Returns the light that this component wraps. */
118 SPtr<Light> _getLight() const { return mInternal; }
119
120 /** @} */
121
122 protected:
123 mutable SPtr<Light> mInternal;
124
125 // Only valid during construction
126 LightType mType = LightType::Radial;
127 Color mColor = Color::White;
128 float mIntensity = 100.0f;
129 float mRange = 1.0f;
130 bool mCastsShadows = false;
131 Degree mSpotAngle = Degree(45);
132 Degree mSpotFalloffAngle = Degree(40);
133
134 /************************************************************************/
135 /* COMPONENT OVERRIDES */
136 /************************************************************************/
137 protected:
138 friend class SceneObject;
139
140 /** @copydoc Component::onInitialized */
141 void onInitialized() override;
142
143 /** @copydoc Component::onDestroyed */
144 void onDestroyed() override;
145
146 /** @copydoc Component::update */
147 void update() override { }
148
149 /************************************************************************/
150 /* RTTI */
151 /************************************************************************/
152 public:
153 friend class CLightRTTI;
154 static RTTITypeBase* getRTTIStatic();
155 RTTITypeBase* getRTTI() const override;
156
157 protected:
158 CLight(); // Serialization only
159 };
160
161 /** @} */
162}