1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 | /*
|
---|
6 | Based on the FS Import classes:
|
---|
7 | Copyright (C) 2005-2006 Feeling Software Inc
|
---|
8 | Copyright (C) 2005-2006 Autodesk Media Entertainment
|
---|
9 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | @file FCDLight.h
|
---|
14 | This file contains the FCDLight class.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef _FCD_LIGHT_H_
|
---|
18 | #define _FCD_LIGHT_H_
|
---|
19 |
|
---|
20 | #include "FCDocument/FCDTargetedEntity.h"
|
---|
21 | #include "FUtils/FUDaeEnum.h"
|
---|
22 |
|
---|
23 | class FCDocument;
|
---|
24 | class FCDSceneNode;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | A COLLADA light.
|
---|
28 | Based on the FCDTargetedEntity class to supported aimed lights.
|
---|
29 | COLLADA defines four types of native lights: point, spot, ambient and directional.
|
---|
30 | These four types are fully handled by this class: make sure to check the type flag
|
---|
31 | as well as which information to expect for each light type.
|
---|
32 |
|
---|
33 | A COLLADA ambient light has a global color, which should be added to
|
---|
34 | all other lighting on all geometry.
|
---|
35 |
|
---|
36 | A COLLADA directional light has a global color, which should be multiplied
|
---|
37 | to the cosine of the angle between the normal vector of a triangle
|
---|
38 | and the direction of the light. Note that the direction will be calculated
|
---|
39 | from the transforms, for each instance, and is not provided by this class.
|
---|
40 |
|
---|
41 | A COLLADA point light has a color which attenuates as the distance increases
|
---|
42 | between the light position and the vertex being shaded. Note that the position
|
---|
43 | will be calculated from the transforms, for each instance,
|
---|
44 | and is not provided by this class.
|
---|
45 |
|
---|
46 | A COLLADA spot light is a point light which lights only the objects that
|
---|
47 | appear within a specific angle, with respect to the direction of the light.
|
---|
48 | Note that the position and the direction will be calculated from the
|
---|
49 | transforms, for each instance, and is not provided by this class.
|
---|
50 |
|
---|
51 | @ingroup FCDocument
|
---|
52 | */
|
---|
53 | class FCOLLADA_EXPORT FCDLight : public FCDTargetedEntity
|
---|
54 | {
|
---|
55 | public:
|
---|
56 | /** The types of lights supported by this class. */
|
---|
57 | enum LightType
|
---|
58 | {
|
---|
59 | POINT, /**< A point light. This is the default type. */
|
---|
60 | SPOT, /**< A spot light. */
|
---|
61 | AMBIENT, /**< An ambient light. */
|
---|
62 | DIRECTIONAL /**< A directional light. */
|
---|
63 | };
|
---|
64 |
|
---|
65 | private:
|
---|
66 | DeclareObjectType;
|
---|
67 |
|
---|
68 | // Common Light parameters
|
---|
69 | FMVector3 color;
|
---|
70 | float intensity; // Max and Maya
|
---|
71 | LightType lightType;
|
---|
72 |
|
---|
73 | // Point and spot light parameters
|
---|
74 | float constantAttenuationFactor;
|
---|
75 | float linearAttenuationFactor;
|
---|
76 | float quadracticAttenuationFactor;
|
---|
77 |
|
---|
78 | // Spot-specific light parameters
|
---|
79 | float fallOffExponent;
|
---|
80 | float fallOffAngle;
|
---|
81 | float outerAngle; // Max-specific
|
---|
82 | float penumbraAngle; // Maya-specifc: these last two are are related as 'penumbra = outerAngle - fallOffAngle'.
|
---|
83 | float aspectRatio; // Max-specific, for rectangle lights
|
---|
84 | float dropoff; // Maya-specific
|
---|
85 |
|
---|
86 | // Directional light parameters
|
---|
87 | // Overshoot is a Max-specific flag that sets a directional light to cover everything,
|
---|
88 | // rather than to be restricted to a cylinder defined by the fallOffAngle/outerAngle.
|
---|
89 | bool overshoots; // Max-specific
|
---|
90 |
|
---|
91 | public:
|
---|
92 | /** Constructor: do not use directly. Create new lights using the FCDLibrary::AddEntity function.
|
---|
93 | @param document The COLLADA document that contains this light entity. */
|
---|
94 | FCDLight(FCDocument* document);
|
---|
95 |
|
---|
96 | /** Destructor: do not release directly. Release lights using the FCDLibrary::ReleaseEntity function.
|
---|
97 | All lights are also released with the document that they belong to. */
|
---|
98 | virtual ~FCDLight();
|
---|
99 |
|
---|
100 | /** Retrieves the entity type for this class. This function is part of the FCDEntity interface.
|
---|
101 | @return The entity type: LIGHT. */
|
---|
102 | virtual Type GetType() const { return LIGHT; }
|
---|
103 |
|
---|
104 | /** Retrieves the base color for the light. To calculate the light color,
|
---|
105 | multiply the base color with the intensity.
|
---|
106 | @return The base color for the light. */
|
---|
107 | FMVector3& GetColor() { return color; }
|
---|
108 | const FMVector3& GetColor() const { return color; } /**< See above. */
|
---|
109 |
|
---|
110 | /** Sets the base color for the light. To calculate the light color,
|
---|
111 | multiply the base color with the intensity.
|
---|
112 | @param col The base color for the light. */
|
---|
113 | void SetColor(const FMVector3& col) { color = col; }
|
---|
114 |
|
---|
115 | /** Retrieves the intensity of the light. To calculate the light color,
|
---|
116 | multiply the base color with the intensity.
|
---|
117 | @return The intensity of the light. */
|
---|
118 | float& GetIntensity() { return intensity; }
|
---|
119 | const float& GetIntensity() const { return intensity; } /**< See above. */
|
---|
120 |
|
---|
121 | /** Sets the intensity of the light. To calculate the light color,
|
---|
122 | multiply the base color with the intensity.
|
---|
123 | @param _intensity The intensity of the light. */
|
---|
124 | void SetIntensity(float _intensity) { intensity = _intensity; }
|
---|
125 |
|
---|
126 | /** Retrieves the type of the light.
|
---|
127 | Make sure to check the type of light before using the values, as some values
|
---|
128 | may not make sense with some types of light.
|
---|
129 | @return The light type. */
|
---|
130 | LightType GetLightType() const { return lightType; }
|
---|
131 |
|
---|
132 | /** Sets the type of the light. The default type of a new light is POINT.
|
---|
133 | @param type The light type. */
|
---|
134 | void SetLightType(LightType type) { lightType = type; }
|
---|
135 |
|
---|
136 | /** Retrieves the constant attenuation factor for the light.
|
---|
137 | This value is valid only for point and spot lights.
|
---|
138 | @return The constant attenuation factor. */
|
---|
139 | float& GetConstantAttenuationFactor() { return constantAttenuationFactor; }
|
---|
140 | const float& GetConstantAttenuationFactor() const { return constantAttenuationFactor; } /**< See above. */
|
---|
141 |
|
---|
142 | /** Sets the constant attenuation factor for the light.
|
---|
143 | This value is valid only for point and spot lights.
|
---|
144 | @param factor The constant attenuation factor. */
|
---|
145 | void SetConstantAttenuationFactor(float factor) { constantAttenuationFactor = factor; }
|
---|
146 |
|
---|
147 | /** Retrieves the linear attenuation factor for the light.
|
---|
148 | This value is valid only for point and spot lights.
|
---|
149 | @return The linear attenuation factor. */
|
---|
150 | float& GetLinearAttenuationFactor() { return linearAttenuationFactor; }
|
---|
151 | const float& GetLinearAttenuationFactor() const { return linearAttenuationFactor; } /**< See above. */
|
---|
152 |
|
---|
153 | /** Sets the linear attenuation factor for the light.
|
---|
154 | This value is valid only for point and spot lights.
|
---|
155 | @param factor The linear attenuation factor. */
|
---|
156 | void SetLinearAttenuationFactor(float factor) { linearAttenuationFactor = factor; }
|
---|
157 |
|
---|
158 | /** Retrieves the quadratic attenuation factor for the light.
|
---|
159 | This value is valid only for point and spot lights.
|
---|
160 | @return The quadratic attenuation factor. */
|
---|
161 | float& GetQuadraticAttenuationFactor() { return quadracticAttenuationFactor; }
|
---|
162 | const float& GetQuadraticAttenuationFactor() const { return quadracticAttenuationFactor; } /**< See above. */
|
---|
163 |
|
---|
164 | /** Sets the quadratic attenuation factor for the light.
|
---|
165 | This value is valid only for point and spot lights.
|
---|
166 | @param factor The quadratic attenuation factor. */
|
---|
167 | void SetQuadraticAttenuationFactor(float factor) { quadracticAttenuationFactor = factor; }
|
---|
168 |
|
---|
169 | /** Retrieves the fall-off exponent for the light.
|
---|
170 | This value is valid only for spot lights. It determines
|
---|
171 | how fast the lighting turns off, with respect to
|
---|
172 | angles greater than the fall-off angle. This results in a smooth
|
---|
173 | lighting at the spot light's edges.
|
---|
174 |
|
---|
175 | IMPORTANT NOTE: Neither ColladaMaya or ColladaMax use this value
|
---|
176 | as neither Maya or 3dsMax use this technique for soft lighting.
|
---|
177 |
|
---|
178 | @return The spot light fall-off exponent. */
|
---|
179 | float& GetFallOffExponent() { return fallOffExponent; }
|
---|
180 | const float& GetFallOffExponent() const { return fallOffExponent; } /**< See above. */
|
---|
181 |
|
---|
182 | /** Sets the fall-off exponent for the light.
|
---|
183 | @see GetFallOffExponent
|
---|
184 | @param exponent The spot light fall-off exponent. */
|
---|
185 | void SetFallOffExponent(float exponent) { fallOffExponent = exponent; }
|
---|
186 |
|
---|
187 | /** Retrieves the fall-off angle for the light.
|
---|
188 | This value is valid only for spot lights. It defines
|
---|
189 | the cone of the spot light.
|
---|
190 | @return The spot light fall-off angle. */
|
---|
191 | float& GetFallOffAngle() { return fallOffAngle; }
|
---|
192 | const float& GetFallOffAngle() const { return fallOffAngle; } /**< See above. */
|
---|
193 |
|
---|
194 | /** Sets the fall-off angle for the light.
|
---|
195 | @see GetFallOffAngle
|
---|
196 | @param angle The spot light fall-off angle. */
|
---|
197 | void SetFallOffAngle(float angle) { fallOffAngle = angle; }
|
---|
198 |
|
---|
199 | /** Retrieves the outer angle for the light.
|
---|
200 | This value is valid only for spot lights. This value is only used
|
---|
201 | by documents exported by ColladaMax. This value should always be
|
---|
202 | greater than the fall-off angle. It represents the angle at which
|
---|
203 | the lighting is black. All lighting between the fall-off angle and
|
---|
204 | the outer angle is a linear interpolation between the light color
|
---|
205 | and black.
|
---|
206 | @return The spot light outer angle. */
|
---|
207 | float& GetOuterAngle() { return outerAngle; }
|
---|
208 | const float& GetOuterAngle() const { return outerAngle; } /**< See above. */
|
---|
209 |
|
---|
210 | /** Sets the outer angle for the light.
|
---|
211 | @see GetOuterAngle
|
---|
212 | @param angle The spot light outer angle. */
|
---|
213 | void SetOuterAngle(float angle) { outerAngle = angle; }
|
---|
214 |
|
---|
215 | /** Retrieves the penumbra angle for the light.
|
---|
216 | This value is valid only for spot lights. The value is only used
|
---|
217 | by documents exported by ColladaMaya. This value is relative to
|
---|
218 | the fall-off angle and may be negative. If this value is positive,
|
---|
219 | it determines the outer angle, as described above. If this value
|
---|
220 | is negative, the fall-off angle is used as the outer angle and the
|
---|
221 | fall-off angle + the penumbra angle is used as the full-lighting
|
---|
222 | angle.
|
---|
223 | @see GetOuterAngle
|
---|
224 | @return The spot light penumbra angle. */
|
---|
225 | float& GetPenumbraAngle() { return penumbraAngle; }
|
---|
226 | const float& GetPenumbraAngle() const { return penumbraAngle; } /**< See above. */
|
---|
227 |
|
---|
228 | /** Sets the penumbra angle for the light.
|
---|
229 | @see GetPenumbraAngle
|
---|
230 | @param angle The spot light penumbra angle. */
|
---|
231 | void SetPenumbraAngle(float angle) { penumbraAngle = angle; }
|
---|
232 |
|
---|
233 | /** Retrieves the aspect ratio for the light.
|
---|
234 | This value is only used by documents exported by ColladaMax.
|
---|
235 | This value is valid only for spot lights and directional lights
|
---|
236 | which project a rectangle (for pyramidal projection). It represents the ratio
|
---|
237 | of the projection's height to the projection's width and defines
|
---|
238 | the projection's rectangle. For pyramidal projections, the fall-off and outer angles
|
---|
239 | represent the width of the projection.
|
---|
240 | Note that there is no way to know if the projection is conic or pyramidal.
|
---|
241 | @return The aspect ratio of the light pyramidal projection. */
|
---|
242 | float& GetAspectRatio() { return aspectRatio; }
|
---|
243 | const float& GetAspectRatio() const { return aspectRatio; } /**< See above. */
|
---|
244 |
|
---|
245 | /** Sets the aspect ratio for the light.
|
---|
246 | @see GetAspectRatio
|
---|
247 | @param ratio The aspect ratio of the light pyramidal projection. */
|
---|
248 | void SetAspectRatio(float ratio) { aspectRatio = ratio; }
|
---|
249 |
|
---|
250 | /** Retrieves the drop-off for the light.
|
---|
251 | This value is only used by documents exported by ColladaMaya.
|
---|
252 | @return The drop-off for the light. */
|
---|
253 | float& GetDropoff() { return dropoff; }
|
---|
254 | const float& GetDropoff() const { return dropoff; } /**< See above. */
|
---|
255 |
|
---|
256 | /** Sets the drop-off for the light.
|
---|
257 | This value is only used by documents exported by ColladaMaya.
|
---|
258 | @param factor The drop-off for the light. */
|
---|
259 | void SetDropoff(float factor) { dropoff = factor; }
|
---|
260 |
|
---|
261 | /** Retrieves whether the directional light overshoots.
|
---|
262 | This value is only used by documents exported by ColladaMax.
|
---|
263 | This value is valid only for directional lights. This flag
|
---|
264 | represents whether the directional light has a global projection,
|
---|
265 | as defined in COLLADA, or a cylinder/prism projection.
|
---|
266 | Note that there is no way to know if the projection is conic or pyramidal.
|
---|
267 | @return Whether the directional light overshoots. */
|
---|
268 | bool DoesOvershoot() const { return overshoots; }
|
---|
269 |
|
---|
270 | /** Sets whether the directional light overshoots.
|
---|
271 | @see DoesOvershoot
|
---|
272 | @param _overshoots The overshoot flag for the directional light. */
|
---|
273 | void SetOvershoot(bool _overshoots) { overshoots = _overshoots; }
|
---|
274 |
|
---|
275 | /** [INTERNAL] Reads in the \<light\> element from a given COLLADA XML tree node.
|
---|
276 | @param lightNode A COLLADA XML tree node.
|
---|
277 | @return The status of the import. If the status is not successful,
|
---|
278 | it may be dangerous to extract information from the light.*/
|
---|
279 | FUStatus LoadFromXML(xmlNode* lightNode);
|
---|
280 |
|
---|
281 | /** [INTERNAL] Writes out the \<light\> element to the given COLLADA XML tree node.
|
---|
282 | @param parentNode The COLLADA XML parent node in which to insert the geometry information.
|
---|
283 | @return The created XML tree node. */
|
---|
284 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
285 | };
|
---|
286 |
|
---|
287 | #endif // _FCD_LIGHT_H_
|
---|
288 |
|
---|