00001
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef NL_TRANSFORM_H
00025 #define NL_TRANSFORM_H
00026
00027 #include "nel/3d/hrc_trav.h"
00028 #include "nel/3d/track.h"
00029 #include "nel/3d/transformable.h"
00030 #include "nel/3d/animated_value.h"
00031 #include "nel/3d/channel_mixer.h"
00032 #include "nel/misc/matrix.h"
00033 #include "nel/misc/matrix.h"
00034 #include "nel/misc/aabbox.h"
00035 #include "nel/3d/light_contribution.h"
00036 #include "nel/3d/lighting_manager.h"
00037 #include "nel/misc/class_id.h"
00038 #include "nel/3d/fast_ptr_list.h"
00039
00040
00041 namespace NLMISC
00042 {
00043 class CAABBox;
00044 };
00045
00046
00047 namespace NL3D
00048 {
00049
00050 using NLMISC::CRGBA;
00051
00052
00053 using NLMISC::CVector;
00054 using NLMISC::CPlane;
00055 using NLMISC::CMatrix;
00056 using NLMISC::CAABBox;
00057
00058
00059 class CSkeletonModel;
00060 class CInstanceGroup;
00061 class ILogicInfo;
00062 class CLoadBalancingGroup;
00063 class CSkinSpecularRdrPass;
00064 class CShadowMap;
00065 class CMaterial;
00066 class IDriver;
00067 class CInstanceUser;
00068
00069
00070
00071 const NLMISC::CClassId TransformId=NLMISC::CClassId(0x174750cb, 0xf952024);
00072
00073
00074
00097 class CTransform : public ITransformable
00098 {
00099 public:
00101 static void registerBasic();
00102
00104 CScene *getOwnerScene() const {return _OwnerScene;}
00105
00106 public:
00107
00109
00110
00118 virtual void update();
00119
00130 virtual void initModel();
00131
00133 virtual void traverseHrc();
00143 virtual void traverseClip();
00145 virtual void traverseAnimDetail();
00147 virtual void traverseLoadBalancing();
00149 virtual void traverseLight();
00151 virtual void traverseRender();
00152
00154 virtual bool clip()
00155 {
00156 return true;
00157 }
00158
00160 virtual void profileRender();
00161
00162
00163
00164
00165
00166 virtual class UTransform *buildMatchingUserInterfaceObject ();
00167
00168 public:
00169
00172 void setTransparency(bool v);
00173 void setOpacity(bool v);
00174
00175 void setBypassLODOpacityFlag(bool bypass);
00176 bool getBypassLODOpacityFlag() const{ return getStateFlag(BypassLODOpacity) != 0; }
00177
00178 uint32 isOpaque() { return getStateFlag(IsOpaque); }
00179 uint32 isTransparent() { return getStateFlag(IsTransparent); }
00180
00181
00189 void setOrderingLayer(uint layer) { _OrderingLayer = uint8(layer); }
00190
00192 uint getOrderingLayer() const { return _OrderingLayer; }
00193
00195
00196
00197
00198 void setTransparencyPriority(uint8 priority) { _TransparencyPriority = priority; }
00199 uint8 getTransparencyPriority() const { return _TransparencyPriority; }
00200
00202 void hide();
00204 void show();
00205
00206
00207
00208
00209 void setUserClipping(bool enable);
00211 bool getUserClipping() const;
00213 void heritVisibility();
00215 CHrcTrav::TVisibility getVisibility() {return Visibility;}
00217 CSkeletonModel* getSkeletonModel () const {return _FatherSkeletonModel;}
00218
00219 CSkeletonModel *getAncestorSkeletonModel() const { return _AncestorSkeletonModel; }
00220
00222
00225 void hrcLinkSon(CTransform *son);
00228 void hrcUnlink();
00229
00230 CTransform *hrcGetParent() const {return _HrcParent;}
00231
00232 uint hrcGetNumChildren() const {return _HrcSons.size();}
00233 CTransform *hrcGetChild(uint index) const;
00234
00235
00236
00238
00239
00240 void clipAddChild(CTransform *son);
00241
00242 void clipDelChild(CTransform *son);
00243
00244 void clipUnlinkFromAll();
00245
00246 uint clipGetNumParents() const {return _ClipParents.size();}
00247 CTransform *clipGetParent(uint index) const;
00248
00249 uint clipGetNumChildren() const {return _ClipSons.size();}
00250 CTransform *clipGetChild(uint index) const;
00251
00252
00253
00255
00257 virtual ITrack* getDefaultTrack (uint valueId);
00261 virtual void registerToChannelMixer(CChannelMixer *chanMixer, const std::string &prefix);
00262
00263
00268 void setChannelMixerOwnerShip(bool enable = true) { setStateFlag(IsDeleteChannelMixer, enable); }
00269 bool getChannelMixerOwnerShip() const { return getStateFlag(IsDeleteChannelMixer)!=0; }
00270
00271
00279 void freeze();
00280 void setDontUnfreezeChildren(bool val);
00281
00282
00296 void freezeHRC();
00297
00298
00301 void unfreezeHRC();
00302
00303
00306 uint32 isQuadGridClipEnabled() const {return getStateFlag(QuadGridClipEnabled);}
00307
00311 const CMatrix& getWorldMatrix() const {return _WorldMatrix;}
00312
00313
00314 void setWorldMatrix(const CMatrix &mat) { _WorldMatrix = mat;}
00315
00318 bool isHrcVisible() const
00319 {
00320 return _WorldVis;
00321 }
00322
00325 bool isClipVisible() const
00326 {
00327 return _Visible;
00328 }
00329
00330
00331
00332 void setClusterSystem (CInstanceGroup *pCS);
00333 CInstanceGroup* getClusterSystem ();
00334
00335
00337
00343 void resetLighting();
00344
00350 uint32 isLightable() const {return getStateFlag(IsFinalLightable);}
00351
00356 void setUserLightable(bool enable);
00357
00360 bool getUserLightable() const {return getStateFlag(IsUserLightable)!=0;}
00361
00366 void freezeStaticLightSetup(CPointLight *pointLight[NL3D_MAX_LIGHT_CONTRIBUTION],
00367 uint numPointLights, uint8 sunContribution, CPointLight *frozenAmbientlight);
00368
00373 void unfreezeStaticLightSetup();
00374
00378 uint32 isBigLightable() const {return getStateFlag(IsBigLightable);}
00379
00382 bool useMergedPointLight() const {return _LightContribution.UseMergedPointLight;}
00383
00386 const CLightContribution &getLightContribution() const { return _LightContribution; }
00387
00388
00394 virtual void getLightHotSpotInWorld(CVector &modelPos, float &modelRadius) const {modelPos= CVector::Null; modelRadius=0;}
00395
00396
00397
00398
00402 void setLogicInfo(ILogicInfo *logicInfo) {_LogicInfo= logicInfo;}
00403
00404
00407 virtual void getAABBox(NLMISC::CAABBox &bbox) const;
00408
00409
00411
00412
00422 void setLoadBalancingGroup(const std::string &group);
00423
00426 const std::string &getLoadBalancingGroup() const;
00427
00428
00429
00430
00432
00434 uint32 isSkeleton() const {return getStateFlag(IsSkeleton);}
00436 uint32 isSkinned() const {return getStateFlag(IsSkinned);}
00446 virtual bool getSkinBoneBBox(NLMISC::CAABBox &, uint ) {return false;}
00447
00448
00449
00451
00452
00457 void setMeanColor(CRGBA color);
00458
00460 CRGBA getMeanColor() const {return _MeanColor;}
00461
00463 uint32 isAnimDetailable() const {return getStateFlag(IsAnimDetailable);}
00465 uint32 isLoadBalancable() const {return getStateFlag(IsLoadBalancable);}
00467 uint32 isRenderable() const {return getStateFlag(IsRenderable);}
00468
00470 uint32 isMeshBaseInstance() const {return getStateFlag(IsMeshBaseInstance);}
00472 uint32 isTransformShape() const {return getStateFlag(IsTransformShape);}
00474 uint32 isCluster() const {return getStateFlag(IsCluster);}
00475
00482 bool supportFastIntersect() const {return _SupportFastIntersect;}
00489 virtual bool fastIntersect(const NLMISC::CVector &, const NLMISC::CVector &, float &, float &, bool ) {return false;}
00490
00492 void enableFastIntersectSupport(bool enable) {_SupportFastIntersect= enable;}
00493
00494
00495
00496
00504
00509 void enableCastShadowMap(bool state);
00511 bool canCastShadowMap() const {return getStateFlag(IsFinalShadowMapCaster)!=0;}
00512
00516 void enableReceiveShadowMap(bool state) {if(modelCanReceiveShadowMap()) setStateFlag(IsFinalShadowMapReceiver, state);}
00518 bool canReceiveShadowMap() const {return getStateFlag(IsFinalShadowMapReceiver)!=0;}
00519
00521 uint32 modelCanCastShadowMap() const {return getStateFlag(IsShadowMapCaster);}
00523 uint32 modelCanReceiveShadowMap() const {return getStateFlag(IsShadowMapReceiver);}
00524
00533 virtual void generateShadowMap(const CVector &) { }
00536 virtual CShadowMap *getShadowMap() {return NULL;}
00537
00540 virtual void getReceiverBBox(CAABBox &bbox);
00541
00547 virtual void receiveShadowMap(CShadowMap * , const CVector &, const CMaterial &) { }
00548
00552 virtual const CMatrix &getReceiverRenderWorldMatrix() const {return getWorldMatrix();}
00553
00555 void setGeneratingShadowMap(bool state) {if(canCastShadowMap()) setStateFlag(IsGeneratingShadowMap, state);}
00556 bool isGeneratingShadowMap() const {return getStateFlag(IsGeneratingShadowMap)!=0;}
00557
00562 virtual bool computeWorldBBoxForShadow(NLMISC::CAABBox &) {return false;}
00568 virtual void renderIntoSkeletonShadowMap(CSkeletonModel * , CMaterial &) { }
00569
00579 void setShadowMapDirectionZThreshold(float zthre);
00580 float getShadowMapDirectionZThreshold() const {return _ShadowMapDirectionZThreshold;}
00581
00587 void setShadowMapMaxDepth(float depth);
00588 float getShadowMapMaxDepth() const {return _ShadowMapMaxDepth;}
00589
00590
00591
00598 void setForceClipRoot(bool forceClipRoot);
00599 bool getForceClipRoot() const { return getStateFlag(ForceClipRoot) != 0; }
00600
00601
00602
00603 virtual bool isFlare() const { return false; }
00604
00605
00607 void setSSSWO(bool state) {setStateFlag(SSSWO, state);}
00608 bool getSSSWO() const {return getStateFlag(SSSWO)!=0;}
00609
00610
00611
00612 private:
00613 CHrcTrav::TVisibility Visibility;
00614
00615 static CTrackDefaultVector DefaultPos;
00616 static CTrackDefaultVector DefaultPivot;
00617 static CTrackDefaultVector DefaultRotEuler;
00618 static CTrackDefaultQuat DefaultRotQuat;
00619 static CTrackDefaultVector DefaultScale;
00620
00621 protected:
00626 CTransform();
00628 virtual ~CTransform();
00629
00631 virtual void unlinkFromQuadCluster() {}
00632
00634
00635
00637 virtual bool isSkinnable() const {return false;}
00642 virtual void setApplySkin(bool state);
00648 virtual const std::vector<sint32> *getSkinBoneUsage() const {return NULL;}
00654 virtual const std::vector<NLMISC::CBSphere> *getSkinBoneSphere() const {return NULL;}
00660 virtual void renderSkin(float ) { }
00661
00662
00667 virtual bool supportSkinGrouping() const {return false;}
00671 virtual sint renderSkinGroupGeom(float , uint , uint8 * ) {return 0;}
00676 virtual void renderSkinGroupPrimitives(uint , std::vector<CSkinSpecularRdrPass> &, uint ) { }
00678 virtual void renderSkinGroupSpecularRdrPass(uint ) { }
00679
00681 virtual bool supportShadowSkinGrouping() const {return false;}
00682 virtual sint renderShadowSkinGeom(uint , uint8 * ) {return 0;}
00683 virtual void renderShadowSkinPrimitives(CMaterial &, IDriver * , uint ) { }
00684
00691 virtual bool supportIntersectSkin() const {return false;}
00692 virtual bool intersectSkin(const CMatrix &, float &, float &, bool ) {return false;}
00693
00694
00695 CSkeletonModel *_FatherSkeletonModel;
00696
00697 uint _FatherBoneId;
00698
00699
00700
00702
00703
00705 CLightContribution _LightContribution;
00706
00708 uint32 isNeedUpdateLighting() const {return getStateFlag(IsNeedUpdateLighting);}
00710 uint32 isNeedUpdateFrozenStaticLightSetup() const {return getStateFlag(IsNeedUpdateFrozenStaticLightSetup);}
00711
00713 CLightingManager::CQGItLightedModel _LightedModelIt;
00714
00715
00716
00717
00720 CChannelMixer *getChannelMixer() const {return _ChannelMixer;}
00721
00722
00724
00725
00727 void setIsLightable(bool val);
00733 void setIsRenderable(bool val);
00735 void setIsBigLightable(bool val);
00737 void setIsSkeleton(bool val);
00741 void setIsForceAnimDetail(bool val);
00743 void setIsLoadbalancable(bool val);
00744
00746 void setIsMeshBaseInstance(bool val) {setStateFlag(IsMeshBaseInstance, val);}
00748 void setIsTransformShape(bool val) {setStateFlag(IsTransformShape, val);}
00750 void setIsCluster(bool val) {setStateFlag(IsCluster, val);}
00751
00753 void setIsShadowMapCaster(bool val) {setStateFlag(IsShadowMapCaster, val);}
00754 void setIsShadowMapReceiver(bool val) {setStateFlag(IsShadowMapReceiver, val);}
00755
00756
00757
00759 bool getShowWhenLODSticked() const { return _ForceCLodSticked; }
00760
00761
00762 void forceCompute();
00763
00764 private:
00765 static CTransform *creator() {return new CTransform;}
00766 friend class CSkeletonModel;
00767 friend class CScene;
00768 friend class CClipTrav;
00769 friend class CAnimDetailTrav;
00770 friend class CRenderTrav;
00771
00772
00773 CScene *_OwnerScene;
00774
00776
00777
00778 CFastPtrListNode _HrcNode;
00779 CFastPtrList<CTransform> _HrcSons;
00780 CTransform *_HrcParent;
00781 NLMISC::CRefPtr<CTransform> _HrcParentUnfreeze;
00782
00783
00784
00785
00786 struct CClipNode
00787 {
00788 CFastPtrListNode ClipNode;
00789 CTransform *Parent;
00790 };
00791 CFastPtrList<CTransform> _ClipSons;
00792 std::vector<CClipNode*> _ClipParents;
00793 bool clipHasParent(CTransform *parent);
00794 void clipDelFromParent(CTransform *parent);
00795
00796
00797
00799
00800
00801 CTransform *_PrecModelToUpdate;
00802 CTransform *_NextModelToUpdate;
00803
00804
00805 void linkToUpdateList();
00806 void unlinkFromUpdateList();
00807
00808
00809
00810
00811
00812 NLMISC::CRefPtr<CChannelMixer> _ChannelMixer;
00813
00814
00815 uint64 _LastTransformableMatrixDate;
00816
00817 NLMISC::CRefPtr<CInstanceGroup> _ClusterSystem;
00818
00819
00820 enum TFreezeHRCState { FreezeHRCStateDisabled=0, FreezeHRCStateRequest, FreezeHRCStateReady, FreezeHRCStateEnabled};
00821 TFreezeHRCState _FreezeHRCState;
00822
00823 uint8 _OrderingLayer;
00824 uint8 _TransparencyPriority;
00825
00826
00827 bool _ForceCLodSticked : 1;
00828
00830 bool _TransformDirty : 1;
00831
00832
00833 bool _SupportFastIntersect : 1;
00834
00836 ILogicInfo *_LogicInfo;
00837
00838
00840 CRGBA _MeanColor;
00841
00843 std::list<CTransform*>::iterator _ItShadowCasterInScene;
00844
00846 float _ShadowMapDirectionZThreshold;
00847 float _ShadowMapMaxDepth;
00848
00850
00851
00853 enum TState {
00854
00855 IsAnimDetailable= 0x0001,
00856 IsLoadBalancable= 0x0002,
00857 IsLightable= 0x0004,
00858 IsRenderable= 0x0008,
00859
00860 IsTransparent= 0x0010,
00861 IsOpaque= 0x0020,
00862
00863 QuadGridClipEnabled= 0x0040,
00864
00865 IsUserLightable= 0x0080,
00866 IsFinalLightable= 0x0100,
00867 IsBigLightable= 0x0200,
00868 IsNeedUpdateLighting= 0x0400,
00869 IsNeedUpdateFrozenStaticLightSetup=
00870 0x0800,
00871
00872 IsSkeleton= 0x1000,
00873 IsSkinned= 0x2000,
00874
00875 IsDeleteChannelMixer= 0x4000,
00876 IsForceAnimDetail= 0x8000,
00877 IsMeshBaseInstance= 0x10000,
00878 IsTransformShape= 0x20000,
00879 IsCluster= 0x40000,
00880 UserClipping= 0x80000,
00881
00882
00883 IsShadowMapCaster= 0x100000,
00884 IsFinalShadowMapCaster= 0x200000,
00885 IsShadowMapReceiver= 0x400000,
00886 IsFinalShadowMapReceiver= 0x800000,
00887 IsGeneratingShadowMap= 0x1000000,
00888
00889 ForceClipRoot = 0x2000000,
00890
00891
00892 ClusterSystemAuto = 0x4000000,
00893
00894 SSSWO = 0x8000000,
00895
00896 BypassLODOpacity = 0x10000000
00897
00898
00899 };
00900
00902 uint32 _StateFlags;
00903
00905 void setStateFlag(uint32 mask, bool val)
00906 {
00907
00908 _StateFlags&= ~mask;
00909
00910 _StateFlags|= ( 0- ((uint32)val) ) & mask;
00911 }
00912
00914 uint32 getStateFlag(uint32 mask) const
00915 {
00916 return _StateFlags&mask;
00917 }
00918
00919
00920
00921 protected:
00922
00926 uint32 _RenderFilterType;
00927
00928
00929 protected:
00930
00932
00933
00935 CMatrix _LocalMatrix;
00936 CHrcTrav::TVisibility _LocalVis;
00937 sint64 _LocalDate;
00939 CMatrix _WorldMatrix;
00940 sint64 _WorldDate;
00941 bool _WorldVis;
00942
00943 bool _Frozen;
00944 bool _DontUnfreezeChildren;
00945 bool _ClipLinkedInSonsOfAncestorSkeletonModelGroup;
00946
00947 CSkeletonModel *_AncestorSkeletonModel;
00948
00950 void updateWorld();
00951
00952 void updateClipTravForAncestorSkeleton();
00953
00954
00955
00956
00958
00959
00961 sint64 _ClipDate;
00962
00963 sint _IndexInVisibleList;
00965 bool _Visible;
00966
00967
00968
00970
00971
00972 uint8 _IndexLSBInRenderList;
00973
00974
00976
00977
00983 void updateWorldMatrixFromFather();
00984
00988 void traverseAnimDetailWithoutUpdateWorldMatrix();
00989
00990
00991
00993
00994
00995 CLoadBalancingGroup *_LoadBalancingGroup;
00996
00997
00999
01004 virtual void createShadowMap() {}
01006 virtual void deleteShadowMap() {}
01007
01008
01009 };
01010
01011
01012 }
01013
01014
01015 #endif // NL_TRANSFORM_H
01016
01017