# Home    # nevrax.com   
Nevrax
Nevrax.org
#News
#Mailing-list
#Documentation
#CVS
#Bugs
#License
Docs
 
Documentation  
Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Search  

skeleton_model.h

Go to the documentation of this file.
00001 
00007 /* Copyright, 2001 Nevrax Ltd.
00008  *
00009  * This file is part of NEVRAX NEL.
00010  * NEVRAX NEL is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2, or (at your option)
00013  * any later version.
00014 
00015  * NEVRAX NEL is distributed in the hope that it will be useful, but
00016  * WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00018  * General Public License for more details.
00019 
00020  * You should have received a copy of the GNU General Public License
00021  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00023  * MA 02111-1307, USA.
00024  */
00025 
00026 #ifndef NL_SKELETON_MODEL_H
00027 #define NL_SKELETON_MODEL_H
00028 
00029 #include "nel/misc/types_nl.h"
00030 #include "nel/misc/object_vector.h"
00031 #include "3d/transform_shape.h"
00032 #include "3d/bone.h"
00033 #include "3d/mrm_level_detail.h"
00034 #include "3d/lod_character_instance.h"
00035 
00036 namespace NLMISC
00037 {
00038         class   CAABBox;
00039 }
00040 
00041 namespace NL3D
00042 {
00043 
00044 class CSkeletonShape;
00045 class CTransformClipObs;
00046 class CLodCharacterManager;
00047 
00048 
00049 // ***************************************************************************
00050 // ClassIds.
00051 const NLMISC::CClassId          SkeletonModelId=NLMISC::CClassId(0x7d4703b4, 0x43ad6ab1);
00052 
00053 
00054 // ***************************************************************************
00064 class CSkeletonModel : public CTransformShape
00065 {
00066 public:
00068         static  void    registerBasic();
00069 
00070 public:
00071 
00075         std::vector<CBone>                      Bones;
00076 
00077 public:
00079         // @{
00080         enum    TAnimValues
00081         {
00082                 OwnerBit= CTransformShape::AnimValueLast, 
00083 
00084                 AnimValueLast,
00085         };
00086 
00087         // Register bones into chanMixer.
00088         virtual void    registerToChannelMixer(CChannelMixer *chanMixer, const std::string &prefix);
00089         // @}
00090 
00091 
00093         // @{
00102         bool            bindSkin(CTransform *mi);
00109         void            stickObject(CTransform *mi, uint boneId);
00110 
00115         void            stickObjectEx(CTransform *mi, uint boneId, bool forceCLod);
00116 
00121         void            detachSkeletonSon(CTransform *mi);
00122 
00128         void            dirtSkinRenderLists() {_SkinToRenderDirty= true;}
00129         // @}
00130 
00131 
00133         // @{
00134 
00135         typedef enum {UsageNormal, UsageForced, UsageCLodForced} TBoneUsageType;
00136 
00141         void            incBoneUsage(uint i, TBoneUsageType boneUsageType);
00143         void            decBoneUsage(uint i, TBoneUsageType boneUsageType);
00144 
00148         void            flagBoneAndParents(uint32 boneId, std::vector<bool>     &boneUsage) const;
00149 
00150         // @}
00151 
00152 
00154         // @{
00156         sint32          getBoneIdByName(const std::string &name) const;
00157 
00159         bool            isBoneComputed(uint boneId) const;
00160 
00162         uint            getNumBoneComputed() const {return _BoneToCompute.size();}
00163 
00167         void            setInterpolationDistance(float dist);
00168 
00170         float           getInterpolationDistance() const;
00171 
00175         const NLMISC::CMatrix   &getActiveBoneSkinMatrix(uint boneId) const;
00176 
00177 
00182         void            computeAllBones(const CMatrix &modelWorldMatrix);
00183 
00190         bool            computeRenderedBBox(NLMISC::CAABBox &bbox);
00191 
00199         bool            computeCurrentBBox(NLMISC::CAABBox &bbox, bool forceCompute = false);
00200 
00201         // @}
00202 
00203 
00205         // @{
00206 
00208         void                    setLodCharacterShape(sint shapeId);
00210         sint                    getLodCharacterShape() const {return _CLodInstance.ShapeId;}
00211 
00213         void                    setLodCharacterAnimId(uint animId);
00214         uint                    getLodCharacterAnimId() const {return _CLodInstance.AnimId;}
00215         void                    setLodCharacterAnimTime(TGlobalAnimationTime time);
00216         TGlobalAnimationTime    getLodCharacterAnimTime() const {return _CLodInstance.AnimTime;}
00217 
00219         void                    setLodCharacterWrapMode(bool wrapMode);
00220         bool                    getLodCharacterWrapMode() const {return _CLodInstance.WrapMode;}
00221 
00222 
00226         bool                    isDisplayedAsLodCharacter() const {return _DisplayedAsLodCharacter;}
00227 
00231         void                    setLodCharacterDistance(float dist);
00232 
00234         float                   getLodCharacterDistance() const {return _LodCharacterDistance;}
00235 
00241         float                   computeDisplayLodCharacterPriority() const;
00242 
00245         void                    setDisplayLodCharacterFlag(bool displayCLod);
00246 
00249         void                    dirtLodVertexColor() {_CLodVertexColorDirty= true;}
00250 
00256         void                    computeLodTexture();
00257 
00258         // @}
00259 
00261         // @{
00262 
00264         virtual float   getNumTriangles (float distance);
00265 
00274         void                    changeMRMDistanceSetup(float distanceFinest, float distanceMiddle, float distanceCoarsest);
00275 
00277         void                    resetDefaultMRMDistanceSetup();
00278 
00279         // @}
00280 
00281 // ***********************
00282 protected:
00284         CSkeletonModel();
00286         virtual ~CSkeletonModel();
00287 
00289         virtual void    initModel();
00290 
00291 
00292 private:
00293         static IModel   *creator() {return new CSkeletonModel;}
00294         friend  class CSkeletonShape;
00295         friend  class CSkeletonModelAnimDetailObs;
00296         friend  class CSkeletonModelRenderObs;
00297         friend  class CTransformClipObs;
00298 
00299 
00300 public:
00302         bool    isClipVisible() const
00303         {
00304                 return _ClipObs->Visible;
00305         }
00306 
00307         // update if needed the renderList
00308         void                                            updateSkinRenderLists();
00309 
00310 private:
00311 
00312         // The iterator of the skeleton inserted in the scene
00313         std::list<CSkeletonModel*>::iterator    _ItSkeletonInScene;
00314 
00316         typedef std::set<CTransform*>           TTransformSet;
00317         typedef TTransformSet::iterator         ItTransformSet;
00319         TTransformSet                           _Skins;
00321         TTransformSet                           _StickedObjects;
00322 
00323         // see dirtSkinRenderLists
00324         bool                                            _SkinToRenderDirty;
00325         // see _LevelDetail
00326         bool                                            _DefaultMRMSetup;
00327         // Raw lists of Skins. Both for transparent and opaque pass
00328         typedef NLMISC::CObjectVector<CTransform*, false>       TTransformArray;
00329         TTransformArray                         _OpaqueSkins;
00330         TTransformArray                         _TransparentSkins;
00331         // Skins which need to be animated (very rare)
00332         TTransformArray                         _AnimDetailSkins;
00333 
00334         // The level detail used to drive MRM skins
00335         CMRMLevelDetail                         _LevelDetail;
00336         // build a bug-free level detail
00337         void                                            buildDefaultLevelDetail();
00338 
00340         // @{
00341 
00342         struct CBoneUsage
00343         {
00345                 uint8                   Usage;
00347                 uint8                   ForcedUsage;
00352                 uint8                   CLodForcedUsage;
00356                 uint8                   MustCompute;
00358                 uint                    ValidBoneSkinMatrix;
00359         };
00360 
00361         // A bone to compute information
00362         struct CBoneCompute
00363         {
00364                 // The bone
00365                 CBone                   *Bone;
00366                 // Father of the bone. May be NULL
00367                 CBone                   *Father;
00368                 // true if must interpolate this bone with next lod
00369                 bool                    MustInterpolate;
00370         };
00371 
00373         std::vector<CBoneUsage>         _BoneUsage;
00375         std::vector<CBoneCompute>       _BoneToCompute;
00377         bool                                            _BoneToComputeDirty;
00379         uint                                            _CurLod;
00381         float                                           _CurLodInterp;
00383         float                                           _LodInterpMultiplier;
00384 
00385 
00387         void            initBoneUsages();
00388 
00390         void            incForcedBoneUsageAndParents(uint i, bool forceCLod);
00392         void            decForcedBoneUsageAndParents(uint i, bool forceCLod);
00393 
00395         void            updateBoneToCompute();
00396 
00397         // @}
00398 
00399 
00401         // @{
00402 
00403         // return the contribution of lights (for Character Lod render).
00404         const CLightContribution        &getSkeletonLightContribution() {return _LightContribution;}
00405 
00409         bool                                    _DisplayedAsLodCharacter;
00410 
00412         float                                   _LodCharacterDistance;
00413         float                                   _OOLodCharacterDistance;
00414 
00416         CLodCharacterInstance   _CLodInstance;
00417 
00421         bool                                    _CLodVertexColorDirty;
00422 
00424         void                            computeCLodVertexColors(CLodCharacterManager *mngr);
00425 
00426         // @}
00427 
00428 
00429         // The traversal of the Scene which owns this Skeleton.
00430         CHrcTrav                *HrcTrav;
00431         CClipTrav               *ClipTrav;
00432 };
00433 
00434 
00435 // ***************************************************************************
00446 class   CSkeletonModelAnimDetailObs : public CTransformAnimDetailObs
00447 {
00448 public:
00449 
00454         virtual void    traverse(IObs *caller);
00455 
00456 
00457 public:
00458         static IObs     *creator() {return new CSkeletonModelAnimDetailObs;}
00459 };
00460 
00461 
00462 // ***************************************************************************
00472 class   CSkeletonModelRenderObs : public CTransformShapeRenderObs
00473 {
00474 public:
00475  
00479         virtual void    traverse(IObs *caller);
00480 
00485         void                    renderCLod();
00486 
00492         void                    renderSkins();
00493 
00496         void                    renderSkinList(NLMISC::CObjectVector<CTransform*, false>        &skinList, float alphaMRM);
00497 
00498 public:
00499         static IObs     *creator() {return new CSkeletonModelRenderObs;}
00500 };
00501 
00502 
00503 } // NL3D
00504 
00505 
00506 #endif // NL_SKELETON_MODEL_H
00507 
00508 /* End of skeleton_model.h */