CFx SDK Documentation  2023 SP0
GsLightNode.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 #ifndef __OD_GS_LIGHT_NODE__
25 #define __OD_GS_LIGHT_NODE__
26 
27 #include "TD_PackPush.h"
28 
29 #include "Gs/GsEntityNode.h"
30 #include "Gi/GiLightTraitsData.h"
31 
32 #define STL_USING_MAP
33 #include "OdaSTL.h"
34 
35 // Lights are entities that have some special meaning
36 
40 {
41  OdGeMatrix3d m_model2World; // In case light isn't in model space
42  OdGiLightTraitsData* m_pLightTraits;
43  OdGsNode *m_pLightParent;
45  LightInsertPath m_lightInsertParents;
46 
47  bool m_bIsVewportDependentLight;
48  bool m_bIsViewportDependentNeedUpdate;
49  std::map< OdUInt32, OdGiLightTraitsData* > m_mapVpDepTraitsData;
50 
51 protected:
52  void update();
53 
54  void adjustViewportDependentLightTraitsData( OdGiLightTraitsVpDepData* vdData, OdGiLightTraitsData* data );
55 
56  void clearVpDepTraitsMap();
57 
58 public:
60 
62  OdGsLightNode(OdGsBaseModel* pModel, const OdGiDrawable* pUnderlyingDrawable, bool bSetGsNode = true);
63 public:
64 
65  void setModelTransform(const OdGeMatrix3d& xform) { m_model2World = xform; }
66  OdGeMatrix3d modelTransform() const { return m_model2World; }
67 
68  void setLightOwner(OdGsUpdateContext& ctx, OdGsContainerNode* pParent);
69  bool isOwnedBy(OdGsUpdateContext& ctx, OdGsContainerNode* pParent) const;
70  bool isOwnedBy(const OdGsNode *pOwner) const { return m_pLightParent == pOwner; }
71  OdGsNode *getLightOwner() const { return m_pLightParent; }
72 
74  virtual bool isLight() const;
75 
76  OdGiPointLightTraitsData* pointLightTraitsData( OdUInt32 viewportID = ULONG_MAX );
77  OdGiSpotLightTraitsData* spotLightTraitsData( OdUInt32 viewportID = ULONG_MAX );
78  OdGiDistantLightTraitsData* distantLightTraitsData( OdUInt32 viewportID = ULONG_MAX );
79  OdGiWebLightTraitsData* webLightTraitsData( OdUInt32 viewportID = ULONG_MAX );
80  OdGiLightTraitsData* lightTraitsData( OdUInt32 viewportID = ULONG_MAX );
81 
82  // OdGsNode virtual overrides
83 
84  virtual void invalidate(OdGsContainerNode* pParent, OdGsViewImpl* pView, OdUInt32 mask);
85  virtual void update(OdGsUpdateContext& ctx, OdGsContainerNode* pParent,
87 
88  virtual bool saveClientNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer) const;
89  virtual bool loadClientNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer);
90 
96 
101  static bool drawableIsLight(const OdGiDrawable *pDrawable);
102 };
103 
105 
107 {
109 }
110 
111 inline bool OdGsLightNode::isLight() const
112 {
113  return true;
114 }
115 
117 {
118  if (!m_pLightTraits || ((m_pLightTraits->type() != OdGiLightTraitsData::kPointLight) && (m_pLightTraits->type() != OdGiLightTraitsData::kWebLight)))
119  return NULL;
120  if( m_bIsVewportDependentLight )
121  {
122  std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.find( viewportID );
123  if( it != m_mapVpDepTraitsData.end() )
124  {
125  return (OdGiPointLightTraitsData*)(it->second);
126  }
127  }
128  return (OdGiPointLightTraitsData*)m_pLightTraits;
129 }
131 {
132  if (!m_pLightTraits || (m_pLightTraits->type() != OdGiLightTraitsData::kSpotLight))
133  return NULL;
134  if( m_bIsVewportDependentLight )
135  {
136  std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.find( viewportID );
137  if( it != m_mapVpDepTraitsData.end() )
138  {
139  return (OdGiSpotLightTraitsData*)(it->second);
140  }
141  }
142  return (OdGiSpotLightTraitsData*)m_pLightTraits;
143 }
145 {
146  if (!m_pLightTraits || (m_pLightTraits->type() != OdGiLightTraitsData::kDistantLight))
147  return NULL;
148  if( m_bIsVewportDependentLight )
149  {
150  std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.find( viewportID );
151  if( it != m_mapVpDepTraitsData.end() )
152  {
153  return (OdGiDistantLightTraitsData*)(it->second);
154  }
155  }
156  return (OdGiDistantLightTraitsData*)m_pLightTraits;
157 }
159 {
160  if (!m_pLightTraits || (m_pLightTraits->type() != OdGiLightTraitsData::kWebLight))
161  return NULL;
162  if( m_bIsVewportDependentLight )
163  {
164  std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.find( viewportID );
165  if( it != m_mapVpDepTraitsData.end() )
166  {
167  return (OdGiWebLightTraitsData*)(it->second);
168  }
169  }
170  return (OdGiWebLightTraitsData*)m_pLightTraits;
171 }
173 {
174  if( m_bIsVewportDependentLight )
175  {
176  std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.find( viewportID );
177  if( it != m_mapVpDepTraitsData.end() )
178  {
179  return it->second;
180  }
181  }
182  return m_pLightTraits;
183 }
184 
185 
187 {
188  if( !m_bIsVewportDependentLight ) return;
189  if( !data || !vdData ) return;
190  data->setOn( vdData->vpDepOn() );
191  data->setIntensity( data->intensity() * ( 1.0 - vdData->vpDepDimming() ) );
192 }
193 
194 inline bool OdGsLightNode::drawableIsLight(const OdGiDrawable *pDrawable)
195 {
197 }
198 
199 
201 {
202  for( std::map< OdUInt32, OdGiLightTraitsData* >::iterator it = m_mapVpDepTraitsData.begin(); it != m_mapVpDepTraitsData.end(); ++it )
203  {
205  }
206  m_mapVpDepTraitsData.clear();
207 }
208 
209 
210 #include "TD_PackPop.h"
211 
212 #endif // __OD_GS_LIGHT_NODE__
#define GS_TOOLKIT_EXPORT
Definition: GsExport.h:37
OdSmartPtr< OdGsLightNode > OdGsLightNodePtr
Definition: GsLightNode.h:104
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
static void deleteLightTraitsData(OdGiLightTraitsData *pLightTraits)
LightType type() const
static LightType drawableLightType(const OdGiDrawable *pDrawable)
virtual bool isLight() const
Definition: GsEntityNode.h:579
OdGsLightNode(OdGsBaseModel *pModel, const OdGiDrawable *pUnderlyingDrawable, bool bSetGsNode=true)
bool isOwnedBy(OdGsUpdateContext &ctx, OdGsContainerNode *pParent) const
virtual void invalidate(OdGsContainerNode *pParent, OdGsViewImpl *pView, OdUInt32 mask)
OdGeMatrix3d modelTransform() const
Definition: GsLightNode.h:66
void setLightOwner(OdGsUpdateContext &ctx, OdGsContainerNode *pParent)
void adjustViewportDependentLightTraitsData(OdGiLightTraitsVpDepData *vdData, OdGiLightTraitsData *data)
Definition: GsLightNode.h:186
OdGiLightTraitsData * lightTraitsData(OdUInt32 viewportID=ULONG_MAX)
Definition: GsLightNode.h:172
OdGiSpotLightTraitsData * spotLightTraitsData(OdUInt32 viewportID=ULONG_MAX)
Definition: GsLightNode.h:130
void setModelTransform(const OdGeMatrix3d &xform)
Definition: GsLightNode.h:65
OdGsNode * getLightOwner() const
Definition: GsLightNode.h:71
OdGiPointLightTraitsData * pointLightTraitsData(OdUInt32 viewportID=ULONG_MAX)
Definition: GsLightNode.h:116
void updateViewportDependent(OdGsViewImpl *pView)
ODRX_DECLARE_MEMBERS(OdGsLightNode)
virtual void update(OdGsUpdateContext &ctx, OdGsContainerNode *pParent, OdSiSpatialIndex *)
virtual bool saveClientNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer) const
void clearVpDepTraitsMap()
Definition: GsLightNode.h:200
OdGiDistantLightTraitsData * distantLightTraitsData(OdUInt32 viewportID=ULONG_MAX)
Definition: GsLightNode.h:144
virtual bool isLight() const
Definition: GsLightNode.h:111
static bool drawableIsLight(const OdGiDrawable *pDrawable)
Definition: GsLightNode.h:194
virtual bool loadClientNodeState(OdGsFiler *pFiler, OdGsBaseVectorizer *pVectorizer)
OdGiWebLightTraitsData * webLightTraitsData(OdUInt32 viewportID=ULONG_MAX)
Definition: GsLightNode.h:158
OdGiLightTraitsData::LightType lightType()
Definition: GsLightNode.h:106
bool isOwnedBy(const OdGsNode *pOwner) const
Definition: GsLightNode.h:70
OdGiDrawablePtr underlyingDrawable() const
Definition: GsNode.h:243
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
GLenum GLint GLuint mask
Definition: gles2_ext.h:262