scene_group.h
Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_SCENE_GROUP_H
00025 #define NL_SCENE_GROUP_H
00026
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/vector.h"
00029 #include "nel/misc/quat.h"
00030 #include "nel/misc/smart_ptr.h"
00031 #include "nel/3d/portal.h"
00032 #include "nel/3d/cluster.h"
00033 #include "nel/3d/transform.h"
00034 #include "nel/3d/point_light_named.h"
00035 #include "nel/3d/point_light_named_array.h"
00036 #include "nel/3d/ig_surface_light.h"
00037 #include "nel/3d/clip_trav.h"
00038
00039 #include <vector>
00040
00041 namespace NLMISC
00042 {
00043 class CRGBA;
00044 class IStream;
00045 struct EStream;
00046 class CMatrix;
00047 }
00048
00049 namespace NL3D {
00050
00051 class CScene;
00052 class CTransformShape;
00053 class IDriver;
00054 class ITransformName;
00055 struct IAddRemoveInstance;
00056 struct IIGAddBegin;
00057
00070 class CInstanceGroup : public NLMISC::CRefCount
00071 {
00072
00073
00074
00075
00076
00077 public:
00078
00080 enum {NumStaticLightPerInstance= 2};
00081 enum TState { StateNotAdded = 0, StateAdding, StateAdded, StateError };
00082
00083 public:
00084
00089
00090 class CInstance
00091 {
00092 public:
00094 std::string Name;
00095
00097 sint32 nParent;
00098
00100 std::vector<uint32> Clusters;
00101
00103 NLMISC::CQuat Rot;
00104 NLMISC::CVector Pos;
00105 NLMISC::CVector Scale;
00106
00107
00108 std::string InstanceName;
00109
00111 bool DontAddToScene;
00112
00114 bool Visible;
00115
00117
00118 bool DontCastShadow;
00119
00120 bool AvoidStaticLightPreCompute;
00121
00122 bool StaticLightEnabled;
00123 uint8 SunContribution;
00124
00125 uint8 Light[NumStaticLightPerInstance];
00129 uint8 LocalAmbientId;
00135 bool DontCastShadowForInterior;
00139 bool DontCastShadowForExterior;
00140
00141
00143 CInstance ();
00144
00146 void serial (NLMISC::IStream& f);
00147 };
00148
00150 typedef std::vector<CInstance> TInstanceArray;
00151
00153
00155 uint getNumInstance () const;
00156
00158 const std::string& getShapeName (uint instanceNb) const;
00159
00161 const std::string& getInstanceName (uint instanceNb) const;
00162
00164 const NLMISC::CVector& getInstancePos (uint instanceNb) const;
00165
00167 const NLMISC::CQuat& getInstanceRot (uint instanceNb) const;
00168
00169
00170 const NLMISC::CVector& getInstanceScale (uint instanceNb) const;
00171
00172
00173 void getInstanceMatrix(uint instanceNb, NLMISC::CMatrix &dest) const;
00174
00175
00176 sint32 getInstanceParent (uint instanceNb) const;
00177
00178
00179 const CInstance &getInstance(uint instanceNb) const;
00180
00181
00182 CInstance &getInstance(uint instanceNb);
00183
00184
00185 const NLMISC::CVector &getGlobalPos() const { return _GlobalPos; }
00186
00190 CTransformShape *getTransformShape(uint instanceNb) const;
00191
00196 CInstanceGroup();
00197 ~CInstanceGroup();
00198
00202 void build (const CVector &vGlobalPos, const TInstanceArray& array,
00203 const std::vector<CCluster>& Clusters,
00204 const std::vector<CPortal>& Portals);
00205
00210 void build (const CVector &vGlobalPos, const TInstanceArray& array,
00211 const std::vector<CCluster>& Clusters,
00212 const std::vector<CPortal>& Portals,
00213 const std::vector<CPointLightNamed> &pointLightList,
00214 const CIGSurfaceLight::TRetrieverGridMap *retrieverGridMap= NULL,
00215 float igSurfaceLightCellSize= 0);
00216
00219 void retrieve (CVector &vGlobalPos, TInstanceArray& array,
00220 std::vector<CCluster>& Clusters,
00221 std::vector<CPortal>& Portals,
00222 std::vector<CPointLightNamed> &pointLightList) const;
00223
00225 void serial (NLMISC::IStream& f);
00226
00228 void createRoot (CScene& scene);
00229
00231 void setTransformNameCallback (ITransformName *pTN);
00232
00234 void setAddRemoveInstanceCallback(IAddRemoveInstance *callback);
00235
00237 void setIGAddBeginCallback(IIGAddBegin *callback);
00238
00239
00240
00249 bool addToScene (CScene& scene, IDriver *driver=NULL, uint selectedTexture=0);
00250 bool addToSceneAsync (CScene& scene, IDriver *driver=NULL, uint selectedTexture=0);
00251 void stopAddToSceneAsync ();
00252 TState getAddToSceneState ();
00253
00257 void getShapeName (uint instanceIndex, std::string &shapeName) const;
00258
00260 void setUserInterface(class UInstanceGroup *uig) {_UserIg= uig;}
00261 class UInstanceGroup *getUserInterface() const {return _UserIg;}
00262
00266 void displayDebugClusters(IDriver *drv, class CTextContext *txtCtx);
00267
00268 private:
00269 bool addToSceneWhenAllShapesLoaded (CScene& scene, IDriver *driver, uint selectedTexture);
00270
00271 public:
00273 bool removeFromScene (CScene& scene);
00274
00275
00280
00281 void getLights (std::set<std::string> &LightNames);
00282
00283
00284
00289
00290 void getBlendShapes (std::set<std::string> &BlendShapeNames);
00291
00293 void setBlendShapeFactor (const std::string &BlendShapeName, float rFactor);
00294
00295
00300
00301 void addCluster (CCluster *pCluster);
00302
00304 void setClusterSystemForInstances (CInstanceGroup *pIG);
00305
00307 void getDynamicPortals (std::vector<std::string> &names);
00308
00310 void setDynamicPortal (std::string& name, bool opened);
00311
00313 bool getDynamicPortal (std::string& name);
00314
00315
00320
00321 void linkRoot (CScene &scene, CTransform *father);
00322
00324 void setPos (const CVector &pos);
00325
00327 void setRotQuat (const CQuat &quat);
00328
00330 CVector getPos ();
00331
00333 CQuat getRotQuat ();
00334
00336 void freezeHRC();
00337
00339 void unfreezeHRC();
00340
00341
00342 public:
00343
00345
00346
00348 const std::vector<CPointLightNamed> &getPointLightList() const {return _PointLightArray.getPointLights();}
00349
00351 uint getNumPointLights() const { return _PointLightArray.getPointLights().size(); }
00352
00354 CPointLightNamed &getPointLightNamed(uint index)
00355 {
00356 return _PointLightArray.getPointLights()[index];
00357 }
00358
00360 void setPointLightFactor(const CScene &scene);
00361
00363 bool getStaticLightSetup(NLMISC::CRGBA sunAmbient, uint retrieverIdentifier, sint surfaceId, const CVector &localPos,
00364 std::vector<CPointLightInfluence> &pointLightList, uint8 &sunContribution, NLMISC::CRGBA &localAmbient)
00365 {
00366 return _IGSurfaceLight.getStaticLightSetup(sunAmbient, retrieverIdentifier, surfaceId, localPos,
00367 pointLightList, sunContribution, localAmbient);
00368 }
00369
00371 const CIGSurfaceLight &getIGSurfaceLight() const {return _IGSurfaceLight;}
00372
00374 void enableRealTimeSunContribution(bool enable);
00375 bool getRealTimeSunContribution() const {return _RealTimeSunContribution;}
00376
00377
00378
00379
00382 bool linkToParent (CInstanceGroup*pFather);
00383
00386 CInstanceGroup *getParentClusterSystem() const {return _ParentClusterSystem;}
00387
00388 public:
00389
00390 TInstanceArray _InstancesInfos;
00391 std::vector<CTransformShape*> _Instances;
00392
00393 std::vector<CPortal> _Portals;
00394 std::vector<CCluster> _ClusterInfos;
00395 std::vector<CCluster*> _ClusterInstances;
00396
00397 CTransform *_Root;
00398
00399 CClipTrav *_ClipTrav;
00400
00401 CInstanceGroup *_ClusterSystemForInstances;
00402
00403 CInstanceGroup *_ParentClusterSystem;
00404
00405 NLMISC::CVector _GlobalPos;
00406
00407
00408 private:
00410
00411
00413 bool _RealTimeSunContribution;
00414
00416 CPointLightNamedArray _PointLightArray;
00417
00419 void buildPointLightList(const std::vector<CPointLightNamed> &pointLightList,
00420 std::vector<uint> &plRemap);
00421
00423 CIGSurfaceLight _IGSurfaceLight;
00424
00425
00426
00428
00429 bool _AddToSceneSignal;
00430 TState _AddToSceneState;
00431 CScene *_AddToSceneTempScene;
00432 IDriver *_AddToSceneTempDriver;
00433 uint _AddToSceneTempSelectTexture;
00434
00435
00436 ITransformName *_TransformName;
00437 IAddRemoveInstance *_AddRemoveInstance;
00438 IIGAddBegin *_IGAddBeginCallback;
00439
00440
00441 UInstanceGroup *_UserIg;
00442 };
00443
00444
00445 }
00446
00447
00448 #endif // NL_SCENE_GROUP_H
00449
00450