|
|
|||
File indexing completed on 2026-11-14 10:35:02
0001 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0002 // 0003 // This file is part of Open CASCADE Technology software library. 0004 // 0005 // This library is free software; you can redistribute it and/or modify it under 0006 // the terms of the GNU Lesser General Public License version 2.1 as published 0007 // by the Free Software Foundation, with special exception defined in the file 0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0009 // distribution for complete text of the license and disclaimer of any warranty. 0010 // 0011 // Alternatively, this file may be used under the terms of Open CASCADE 0012 // commercial license or contractual agreement. 0013 0014 #ifndef _Graphic3d_CLight_HeaderFile 0015 #define _Graphic3d_CLight_HeaderFile 0016 0017 #include <gp_Dir.hxx> 0018 #include <Graphic3d_TypeOfLightSource.hxx> 0019 #include <NCollection_Vec2.hxx> 0020 #include <Standard_TypeDef.hxx> 0021 #include <NCollection_Vec3.hxx> 0022 #include <NCollection_Vec4.hxx> 0023 #include <NCollection_Mat4.hxx> 0024 #include <NCollection_List.hxx> 0025 #include <TCollection_AsciiString.hxx> 0026 #include <Quantity_ColorRGBA.hxx> 0027 0028 //! Generic light source definition. 0029 //! This class defines arbitrary light source - see Graphic3d_TypeOfLightSource enumeration. 0030 //! Some parameters are applicable only to particular light type; 0031 //! calling methods unrelated to current type will throw an exception. 0032 class Graphic3d_CLight : public Standard_Transient 0033 { 0034 DEFINE_STANDARD_RTTIEXT(Graphic3d_CLight, Standard_Transient) 0035 public: 0036 //! Empty constructor, which should be followed by light source properties configuration. 0037 Standard_EXPORT Graphic3d_CLight(Graphic3d_TypeOfLightSource theType); 0038 0039 //! Copy parameters from another light source excluding source type. 0040 Standard_EXPORT void CopyFrom(const occ::handle<Graphic3d_CLight>& theLight); 0041 0042 //! Returns the Type of the Light, cannot be changed after object construction. 0043 Graphic3d_TypeOfLightSource Type() const { return myType; } 0044 0045 //! Returns light source name; empty string by default. 0046 const TCollection_AsciiString& Name() const { return myName; } 0047 0048 //! Sets light source name. 0049 void SetName(const TCollection_AsciiString& theName) { myName = theName; } 0050 0051 //! Returns the color of the light source; WHITE by default. 0052 const Quantity_Color& Color() const { return myColor.GetRGB(); } 0053 0054 //! Defines the color of a light source by giving the basic color. 0055 Standard_EXPORT void SetColor(const Quantity_Color& theColor); 0056 0057 //! Check that the light source is turned on; TRUE by default. 0058 //! This flag affects all occurrences of light sources, where it was registered and activated; 0059 //! so that it is possible defining an active light in View which is actually in disabled state. 0060 bool IsEnabled() const { return myIsEnabled; } 0061 0062 //! Change enabled state of the light state. 0063 //! This call does not remove or deactivate light source in Views/Viewers; 0064 //! instead it turns it OFF so that it just have no effect. 0065 Standard_EXPORT void SetEnabled(bool theIsOn); 0066 0067 //! Return TRUE if shadow casting is enabled; FALSE by default. 0068 //! Has no effect in Ray-Tracing rendering mode. 0069 bool ToCastShadows() const { return myToCastShadows; } 0070 0071 //! Enable/disable shadow casting. 0072 Standard_EXPORT void SetCastShadows(bool theToCast); 0073 0074 //! Returns true if the light is a headlight; FALSE by default. 0075 //! Headlight flag means that light position/direction are defined not in a World coordinate 0076 //! system, but relative to the camera orientation. 0077 bool IsHeadlight() const { return myIsHeadlight; } 0078 0079 //! Alias for IsHeadlight(). 0080 bool Headlight() const { return myIsHeadlight; } 0081 0082 //! Setup headlight flag. 0083 Standard_EXPORT void SetHeadlight(bool theValue); 0084 0085 //! @name positional/spot light properties 0086 public: 0087 //! Returns location of positional/spot light; (0, 0, 0) by default. 0088 const gp_Pnt& Position() const { return myPosition; } 0089 0090 //! Setup location of positional/spot light. 0091 Standard_EXPORT void SetPosition(const gp_Pnt& thePosition); 0092 0093 //! Returns location of positional/spot light. 0094 void Position(double& theX, double& theY, double& theZ) const 0095 { 0096 theX = myPosition.X(); 0097 theY = myPosition.Y(); 0098 theZ = myPosition.Z(); 0099 } 0100 0101 //! Setup location of positional/spot light. 0102 void SetPosition(double theX, double theY, double theZ) { SetPosition(gp_Pnt(theX, theY, theZ)); } 0103 0104 //! Returns constant attenuation factor of positional/spot light source; 1.0f by default. 0105 //! Distance attenuation factors of reducing positional/spot light intensity depending on the 0106 //! distance from its position: 0107 //! @code 0108 //! float anAttenuation = 1.0 / (ConstAttenuation() + LinearAttenuation() * theDistance + 0109 //! QuadraticAttenuation() * theDistance * theDistance); 0110 //! @endcode 0111 float ConstAttenuation() const { return myParams.x(); } 0112 0113 //! Returns linear attenuation factor of positional/spot light source; 0.0 by default. 0114 //! Distance attenuation factors of reducing positional/spot light intensity depending on the 0115 //! distance from its position: 0116 //! @code 0117 //! float anAttenuation = 1.0 / (ConstAttenuation() + LinearAttenuation() * theDistance + 0118 //! QuadraticAttenuation() * theDistance * theDistance); 0119 //! @endcode 0120 float LinearAttenuation() const { return myParams.y(); } 0121 0122 //! Returns the attenuation factors. 0123 void Attenuation(double& theConstAttenuation, double& theLinearAttenuation) const 0124 { 0125 theConstAttenuation = ConstAttenuation(); 0126 theLinearAttenuation = LinearAttenuation(); 0127 } 0128 0129 //! Defines the coefficients of attenuation; values should be >= 0.0 and their summ should not be 0130 //! equal to 0. 0131 Standard_EXPORT void SetAttenuation(float theConstAttenuation, float theLinearAttenuation); 0132 0133 //! @name directional/spot light additional properties 0134 public: 0135 //! Returns direction of directional/spot light. 0136 gp_Dir Direction() const { return gp_Dir(myDirection.x(), myDirection.y(), myDirection.z()); } 0137 0138 //! Sets direction of directional/spot light. 0139 Standard_EXPORT void SetDirection(const gp_Dir& theDir); 0140 0141 //! Returns the theVx, theVy, theVz direction of the light source. 0142 void Direction(double& theVx, double& theVy, double& theVz) const 0143 { 0144 theVx = myDirection.x(); 0145 theVy = myDirection.y(); 0146 theVz = myDirection.z(); 0147 } 0148 0149 //! Sets direction of directional/spot light. 0150 void SetDirection(double theVx, double theVy, double theVz) 0151 { 0152 SetDirection(gp_Dir(theVx, theVy, theVz)); 0153 } 0154 0155 //! Returns location of positional/spot/directional light, which is the same as returned by 0156 //! Position(). 0157 const gp_Pnt& DisplayPosition() const { return myPosition; } 0158 0159 //! Setup location of positional/spot/directional light, 0160 //! which is the same as SetPosition() but allows directional light source 0161 //! (technically having no position, but this point can be used for displaying light source 0162 //! presentation). 0163 Standard_EXPORT void SetDisplayPosition(const gp_Pnt& thePosition); 0164 0165 //! @name spotlight additional definition parameters 0166 public: 0167 //! Returns an angle in radians of the cone created by the spot; 30 degrees by default. 0168 float Angle() const { return myParams.z(); } 0169 0170 //! Angle in radians of the cone created by the spot, should be within range (0.0, M_PI). 0171 Standard_EXPORT void SetAngle(float theAngle); 0172 0173 //! Returns intensity distribution of the spot light, within [0.0, 1.0] range; 1.0 by default. 0174 //! This coefficient should be converted into spotlight exponent within [0.0, 128.0] range: 0175 //! @code 0176 //! float aSpotExponent = Concentration() * 128.0; 0177 //! anAttenuation *= pow (aCosA, aSpotExponent);" 0178 //! @endcode 0179 //! The concentration factor determines the dispersion of the light on the surface, the default 0180 //! value (1.0) corresponds to a minimum of dispersion. 0181 float Concentration() const { return myParams.w(); } 0182 0183 //! Defines the coefficient of concentration; value should be within range [0.0, 1.0]. 0184 Standard_EXPORT void SetConcentration(float theConcentration); 0185 0186 //! @name Ray-Tracing / Path-Tracing light properties 0187 public: 0188 //! Returns the intensity of light source; 1.0 by default. 0189 float Intensity() const { return myIntensity; } 0190 0191 //! Modifies the intensity of light source, which should be > 0.0. 0192 Standard_EXPORT void SetIntensity(float theValue); 0193 0194 //! Returns the smoothness of light source (either smoothing angle for directional light or 0195 //! smoothing radius in case of positional light); 0.0 by default. 0196 float Smoothness() const { return mySmoothness; } 0197 0198 //! Modifies the smoothing radius of positional/spot light; should be >= 0.0. 0199 Standard_EXPORT void SetSmoothRadius(float theValue); 0200 0201 //! Modifies the smoothing angle (in radians) of directional light source; should be within range 0202 //! [0.0, M_PI/2]. 0203 Standard_EXPORT void SetSmoothAngle(float theValue); 0204 0205 //! Returns TRUE if maximum distance of point light source is defined. 0206 bool HasRange() const { return myDirection.w() != 0.0f; } 0207 0208 //! Returns maximum distance on which point light source affects to objects and is considered 0209 //! during illumination calculations. 0.0 means disabling range considering at all without any 0210 //! distance limits. Has sense only for point light sources (positional and spot). 0211 float Range() const { return myDirection.w(); } 0212 0213 //! Modifies maximum distance on which point light source affects to objects and is considered 0214 //! during illumination calculations. Positional and spot lights are only point light sources. 0.0 0215 //! means disabling range considering at all without any distance limits. 0216 Standard_EXPORT void SetRange(float theValue); 0217 0218 //! @name low-level access methods 0219 public: 0220 //! @return light resource identifier string 0221 const TCollection_AsciiString& GetId() const { return myId; } 0222 0223 //! Packed light parameters. 0224 const NCollection_Vec4<float>& PackedParams() const { return myParams; } 0225 0226 //! Returns the color of the light source with dummy Alpha component, which should be ignored. 0227 const NCollection_Vec4<float>& PackedColor() const { return myColor; } 0228 0229 //! Returns direction of directional/spot light and range for positional/spot light in alpha 0230 //! channel. 0231 const NCollection_Vec4<float>& PackedDirectionRange() const { return myDirection; } 0232 0233 //! Returns direction of directional/spot light. 0234 NCollection_Vec3<float> PackedDirection() const { return myDirection.xyz(); } 0235 0236 //! @return modification counter 0237 size_t Revision() const { return myRevision; } 0238 0239 //! Dumps the content of me into the stream 0240 Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const; 0241 0242 private: 0243 //! Access positional/spot light constant attenuation coefficient from packed vector. 0244 float& changeConstAttenuation() { return myParams.x(); } 0245 0246 //! Access positional/spot light linear attenuation coefficient from packed vector. 0247 float& changeLinearAttenuation() { return myParams.y(); } 0248 0249 //! Access spotlight angle parameter from packed vector. 0250 float& changeAngle() { return myParams.z(); } 0251 0252 //! Access spotlight concentration parameter from packed vector. 0253 float& changeConcentration() { return myParams.w(); } 0254 0255 private: 0256 //! Generate unique object id. 0257 void makeId(); 0258 0259 //! Update modification counter. 0260 void updateRevisionIf(bool theIsModified) 0261 { 0262 if (theIsModified) 0263 { 0264 ++myRevision; 0265 } 0266 } 0267 0268 private: 0269 Graphic3d_CLight(const Graphic3d_CLight&) = delete; 0270 Graphic3d_CLight& operator=(const Graphic3d_CLight&) = delete; 0271 0272 protected: 0273 TCollection_AsciiString myId; //!< resource id 0274 TCollection_AsciiString myName; //!< user given name 0275 gp_Pnt myPosition; //!< light position 0276 Quantity_ColorRGBA myColor; //!< light color 0277 NCollection_Vec4<float> myDirection; //!< direction of directional/spot light 0278 NCollection_Vec4<float> myParams; //!< packed light parameters 0279 // clang-format off 0280 float mySmoothness; //!< radius for point light or cone angle for directional light 0281 // clang-format on 0282 float myIntensity; //!< intensity multiplier for light 0283 const Graphic3d_TypeOfLightSource myType; //!< Graphic3d_TypeOfLightSource enumeration 0284 size_t myRevision; //!< modification counter 0285 bool myIsHeadlight; //!< flag to mark head light 0286 bool myIsEnabled; //!< enabled state 0287 bool myToCastShadows; //!< casting shadows is requested 0288 }; 0289 0290 #endif // Graphic3d_CLight_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|