1 /* 2 Copyright (C) 2005-2007 Feeling Software Inc. 3 Portions of the code are: 4 Copyright (C) 2005-2007 Sony Computer Entertainment America 5 6 MIT License: http://www.opensource.org/licenses/mit-license.php 7 */ 8 /* 9 Based on the FS Import classes: 10 Copyright (C) 2005-2006 Feeling Software Inc 11 Copyright (C) 2005-2006 Autodesk Media Entertainment 12 MIT License: http://www.opensource.org/licenses/mit-license.php 13 */ 14 15 /** 16 @file FCDLight.h 17 This file contains the FCDLight class. 18 */ 19 20 #ifndef _FCD_LIGHT_H_ 21 #define _FCD_LIGHT_H_ 22 23 #ifndef _FCD_TARGETED_ENTITY_H_ 24 #include "FCDocument/FCDTargetedEntity.h" 25 #endif // _FCD_TARGETED_ENTITY_H_ 26 #ifndef _FCD_PARAMETER_ANIMATABLE_H_ 27 #include "FCDocument/FCDParameterAnimatable.h" 28 #endif // _FCD_PARAMETER_ANIMATABLE_H_ 29 30 class FCDocument; 31 class FCDSceneNode; 32 class FCDAnimated; 33 34 /** 35 A COLLADA light. 36 Based on the FCDTargetedEntity class to supported aimed lights. 37 COLLADA defines four types of native lights: point, spot, ambient and directional. 38 These four types are fully handled by this class: make sure to check the type flag 39 as well as which information to expect for each light type. 40 41 A COLLADA ambient light has a global color, which should be added to 42 all other lighting on all geometry. 43 44 A COLLADA directional light has a global color, which should be multiplied 45 to the cosine of the angle between the normal vector of a triangle 46 and the direction of the light. Note that the direction will be calculated 47 from the transforms, for each instance, and is not provided by this class. 48 49 A COLLADA point light has a color which attenuates as the distance increases 50 between the light position and the vertex being shaded. Note that the position 51 will be calculated from the transforms, for each instance, 52 and is not provided by this class. 53 54 A COLLADA spot light is a point light which lights only the objects that 55 appear within a specific angle, with respect to the direction of the light. 56 Note that the position and the direction will be calculated from the 57 transforms, for each instance, and is not provided by this class. 58 59 @ingroup FCDocument 60 */ 61 class FCOLLADA_EXPORT FCDLight : public FCDTargetedEntity 62 { 63 public: 64 /** The types of lights supported by this class. */ 65 enum LightType 66 { 67 POINT, /**< A point light. This is the default type. */ 68 SPOT, /**< A spot light. */ 69 AMBIENT, /**< An ambient light. */ 70 DIRECTIONAL /**< A directional light. */ 71 }; 72 73 private: 74 DeclareObjectType(FCDTargetedEntity); 75 76 // Common Light parameters 77 DeclareParameterAnimatable(FMVector3, FUParameterQualifiers::COLOR, color, FC("Color")); 78 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, intensity, FC("Intensity")); // Non-standard COLLADA 79 DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, lightType, FC("Light Type")); // LightType 80 81 // Point and spot light parameters 82 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, constantAttenuationFactor, FC("Constant Attenuation Factor")); 83 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, linearAttenuationFactor, FC("Linear Attenuation Factor")); 84 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, quadracticAttenuationFactor, FC("Quadratic Attenuation Factor")); 85 86 // Spot-specific light parameters 87 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffExponent, FC("Fall-off Exponent")); // Likely to be deprecated in future versions. 88 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, fallOffAngle, FC("Inner Cone Angle")); 89 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, outerAngle, FC("Outer Cone Angle")); // Non-standard COLLADA 90 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, penumbraAngle, FC("Penumbra Angle")); // *** DEPRECATED *** Replaced with the inner/outer angle. 91 DeclareParameterAnimatable(float, FUParameterQualifiers::SIMPLE, dropoff, FC("Drop-off")); 92 93 public: 94 /** Constructor: do not use directly. Create new lights using the FCDLibrary::AddEntity function. 95 @param document The COLLADA document that contains this light entity. */ 96 FCDLight(FCDocument* document); 97 98 /** Destructor. */ 99 virtual ~FCDLight(); 100 101 /** Retrieves the entity type for this class. This function is part of the FCDEntity interface. 102 @return The entity type: LIGHT. */ GetType()103 virtual Type GetType() const { return LIGHT; } 104 105 /** Checks if the light uses a DCC specific representation 106 Currently always returns false. 107 @deprecated Instead use: GetExtra()->GetDefaultType()->GetTechniques() 108 @return The DCC flag. */ GetExtra()109 DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMaxExtras() const { return false; } GetExtra()110 DEPRECATED(3.05A, GetExtra()->GetDefaultType()->GetTechniques()) virtual bool HasMayaExtras() const { return false; } /**< See above. */ 111 112 /** [INTERNAL] Set DCC specific flags. 113 @deprecated Internal method, should never have been used. 114 @param value The new flag. 115 */ SetHasMaxExtras(bool UNUSED (value))116 DEPRECATED(3.05A, nothing) void SetHasMaxExtras(bool UNUSED(value)) { } SetHasMayaExtras(bool UNUSED (value))117 DEPRECATED(3.05A, nothing) void SetHasMayaExtras(bool UNUSED(value)) { } 118 119 /** Retrieves the base color for the light. To calculate the light color, 120 multiply the base color with the intensity. 121 @return The base color for the light. */ GetColor()122 FCDParameterAnimatableColor3& GetColor() { return color; } GetColor()123 const FCDParameterAnimatableColor3& GetColor() const { return color; } /**< See above. */ 124 125 /** Sets the base color for the light. To calculate the light color, 126 multiply the base color with the intensity. 127 @param col The base color for the light. */ SetColor(const FMVector3 & col)128 void SetColor(const FMVector3& col) { color = col; SetDirtyFlag(); } 129 130 /** Sets the base color for the light. To calculate the light color, 131 multiply the base color with the intensity. 132 @param r The red component for the light color. 133 @param g The green component for the light color. 134 @param b The blue component for the light color. */ SetColor(float r,float g,float b)135 void SetColor(float r, float g, float b) { color = FMVector3(r, g, b); SetDirtyFlag(); } 136 137 /** Retrieves the intensity of the light. To calculate the light color, 138 multiply the base color with the intensity. 139 @return The intensity of the light. */ GetIntensity()140 FCDParameterAnimatableFloat& GetIntensity() { return intensity; } GetIntensity()141 const FCDParameterAnimatableFloat& GetIntensity() const { return intensity; } /**< See above. */ 142 143 /** Sets the intensity of the light. To calculate the light color, 144 multiply the base color with the intensity. 145 @param _intensity The intensity of the light. */ SetIntensity(float _intensity)146 void SetIntensity(float _intensity) { intensity = _intensity; SetDirtyFlag(); } 147 148 /** Retrieves the type of the light. 149 Make sure to check the type of light before using the values, as some values 150 may not make sense with some types of light. 151 @return The light type. */ GetLightType()152 LightType GetLightType() const { return (LightType) *lightType; } 153 154 /** Sets the type of the light. The default type of a new light is POINT. 155 @param type The light type. */ SetLightType(LightType type)156 void SetLightType(LightType type) { lightType = type; SetDirtyFlag(); } 157 158 /** Retrieves the constant attenuation factor for the light. 159 This value is valid only for point and spot lights. 160 @return The constant attenuation factor. */ GetConstantAttenuationFactor()161 FCDParameterAnimatableFloat& GetConstantAttenuationFactor() { return constantAttenuationFactor; } GetConstantAttenuationFactor()162 const FCDParameterAnimatableFloat& GetConstantAttenuationFactor() const { return constantAttenuationFactor; } /**< See above. */ 163 164 /** Sets the constant attenuation factor for the light. 165 This value is valid only for point and spot lights. 166 @param factor The constant attenuation factor. */ SetConstantAttenuationFactor(float factor)167 void SetConstantAttenuationFactor(float factor) { constantAttenuationFactor = factor; SetDirtyFlag(); } 168 169 /** Retrieves the linear attenuation factor for the light. 170 This value is valid only for point and spot lights. 171 @return The linear attenuation factor. */ GetLinearAttenuationFactor()172 FCDParameterAnimatableFloat& GetLinearAttenuationFactor() { return linearAttenuationFactor; } GetLinearAttenuationFactor()173 const FCDParameterAnimatableFloat& GetLinearAttenuationFactor() const { return linearAttenuationFactor; } /**< See above. */ 174 175 /** Sets the linear attenuation factor for the light. 176 This value is valid only for point and spot lights. 177 @param factor The linear attenuation factor. */ SetLinearAttenuationFactor(float factor)178 void SetLinearAttenuationFactor(float factor) { linearAttenuationFactor = factor; SetDirtyFlag(); } 179 180 /** Retrieves the quadratic attenuation factor for the light. 181 This value is valid only for point and spot lights. 182 @return The quadratic attenuation factor. */ GetQuadraticAttenuationFactor()183 FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() { return quadracticAttenuationFactor; } GetQuadraticAttenuationFactor()184 const FCDParameterAnimatableFloat& GetQuadraticAttenuationFactor() const { return quadracticAttenuationFactor; } /**< See above. */ 185 186 /** Sets the quadratic attenuation factor for the light. 187 This value is valid only for point and spot lights. 188 @param factor The quadratic attenuation factor. */ SetQuadraticAttenuationFactor(float factor)189 void SetQuadraticAttenuationFactor(float factor) { quadracticAttenuationFactor = factor; SetDirtyFlag(); } 190 191 /** Retrieves the fall-off exponent for the light. 192 This value is valid only for spot lights. It determines 193 how fast the lighting turns off, with respect to 194 angles greater than the fall-off angle. This results in a smooth 195 lighting at the spot light's edges. 196 197 IMPORTANT NOTE: Neither ColladaMaya or ColladaMax use this value 198 as neither Maya or 3dsMax use this technique for soft lighting. 199 200 @return The spot light fall-off exponent. */ GetFallOffExponent()201 FCDParameterAnimatableFloat& GetFallOffExponent() { return fallOffExponent; } GetFallOffExponent()202 const FCDParameterAnimatableFloat& GetFallOffExponent() const { return fallOffExponent; } /**< See above. */ 203 204 /** Sets the fall-off exponent for the light. 205 @see GetFallOffExponent 206 @param exponent The spot light fall-off exponent. */ SetFallOffExponent(float exponent)207 void SetFallOffExponent(float exponent) { fallOffExponent = exponent; SetDirtyFlag(); } 208 209 /** Retrieves the fall-off angle for the light. 210 This value is valid only for spot lights. It defines 211 the cone of the spot light. 212 @return The spot light fall-off angle. */ GetFallOffAngle()213 FCDParameterAnimatableFloat& GetFallOffAngle() { return fallOffAngle; } GetFallOffAngle()214 const FCDParameterAnimatableFloat& GetFallOffAngle() const { return fallOffAngle; } /**< See above. */ 215 216 /** Sets the fall-off angle for the light. 217 @see GetFallOffAngle 218 @param angle The spot light fall-off angle. */ SetFallOffAngle(float angle)219 void SetFallOffAngle(float angle) { fallOffAngle = angle; SetDirtyFlag(); } 220 221 /** Retrieves the outer angle for the light. 222 This value is valid only for spot lights. This value is used 223 by documents exported by ColladaMax and ColladaMaya. This value should always be 224 greater than the fall-off angle. It represents the angle at which 225 the lighting is black. All lighting between the fall-off angle and 226 the outer angle is a linear interpolation between the light color 227 and black. 228 @return The spot light outer angle. */ GetOuterAngle()229 FCDParameterAnimatableFloat& GetOuterAngle() { return outerAngle; } GetOuterAngle()230 const FCDParameterAnimatableFloat& GetOuterAngle() const { return outerAngle; } /**< See above. */ 231 232 /** Sets the outer angle for the light. 233 @see GetOuterAngle 234 @param angle The spot light outer angle. */ SetOuterAngle(float angle)235 void SetOuterAngle(float angle) { outerAngle = angle; SetDirtyFlag(); } 236 237 /** Retrieves the penumbra angle for the light. 238 This value is valid only for spot lights. The value is only used 239 by documents exported by ColladaMaya. This value is relative to 240 the fall-off angle and may be negative. If this value is positive, 241 it determines the outer angle, as described above. If this value 242 is negative, the fall-off angle is used as the outer angle and the 243 fall-off angle + the penumbra angle is used as the full-lighting 244 angle. 245 This now actually does nothing but gets the value assigned in SetPenumbraAngle 246 @deprecated Instead use: GetOuterAngle and GetFallOffAngle 247 @see GetOuterAngle 248 @return The spot light penumbra angle. */ GetPenumbraAngle()249 DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) float& GetPenumbraAngle() { return penumbraAngle; } GetPenumbraAngle()250 DEPRECATED(3.05A, GetOuterAngle and GetFallOffAngle) const float& GetPenumbraAngle() const { return penumbraAngle; } /**< See above. */ 251 252 /** Sets the penumbra angle for the light. 253 This now actually doesn't nothing except sets a variable that you can read back with GetPenumbraAngle. 254 @deprecated Instead use: SetOuterAngle and SetFallOffAngle, or FCDLightTools::LoadPenumbra 255 @see GetPenumbraAngle 256 @param angle The spot light penumbra angle. */ SetPenumbraAngle(float angle)257 DEPRECATED(3.05A, SetOuterAngle and SetFallOffAngle) void SetPenumbraAngle(float angle) { penumbraAngle = angle; } 258 259 /** Retrieves the drop-off for the light. 260 It defines the rate at which a spot light gets dimmer from the center 261 of the beam to outside angles. 262 @return The drop-off for the light. */ GetDropoff()263 FCDParameterAnimatableFloat& GetDropoff() { return dropoff; } GetDropoff()264 const FCDParameterAnimatableFloat& GetDropoff() const { return dropoff; } /**< See above. */ 265 266 /** Sets the drop-off for the light. 267 @param factor The drop-off for the light. */ SetDropoff(float factor)268 void SetDropoff(float factor) { dropoff = factor; SetDirtyFlag(); } 269 }; 270 271 #endif // _FCD_LIGHT_H_ 272 273