BVB Source Codes

CRYENGINE Show CharacterInstance.h Source code

Return Download CRYENGINE: download CharacterInstance.h Source code - Download CRYENGINE Source code - Type:.h
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #pragma once
  4.  
  5. #include <CryAnimation/ICryAnimation.h>
  6. #include "AttachmentManager.h"
  7. #include "Model.h"
  8. #include "SkeletonEffectManager.h"
  9. #include "SkeletonAnim.h"
  10. #include "SkeletonPose.h"
  11.  
  12. struct AnimData;
  13. class CCamera;
  14. class CFacialInstance;
  15. class CModelMesh;
  16. class CSkeletonAnim;
  17. class CSkeletonPose;
  18. class CryCharManager;
  19. struct CryParticleSpawnInfo;
  20. namespace CharacterInstanceProcessing {
  21. struct SStartAnimationProcessing;
  22. }
  23.  
  24. extern f32 g_YLine;
  25.  
  26. class CRY_ALIGN(128) CCharInstance final : public ICharacterInstance
  27. {
  28. public:
  29.         friend CharacterInstanceProcessing::SStartAnimationProcessing;
  30.  
  31.         ~CCharInstance();
  32.  
  33.         CCharInstance(const string &strFileName, CDefaultSkeleton * pDefaultSkeleton);
  34.  
  35.         //////////////////////////////////////////////////////////
  36.         // ICharacterInstance implementation
  37.         //////////////////////////////////////////////////////////
  38.         virtual int AddRef() override;
  39.         virtual int Release() override;
  40.         virtual int GetRefCount() const override;
  41.         virtual ISkeletonAnim*            GetISkeletonAnim() override                 { return &m_SkeletonAnim; }
  42.         virtual const ISkeletonAnim*      GetISkeletonAnim() const override           { return &m_SkeletonAnim; }
  43.         virtual ISkeletonPose*            GetISkeletonPose() override                 { return &m_SkeletonPose; }
  44.         virtual const ISkeletonPose*      GetISkeletonPose() const override           { return &m_SkeletonPose; }
  45.         virtual IAttachmentManager*       GetIAttachmentManager() override            { return &m_AttachmentManager; }
  46.         virtual const IAttachmentManager* GetIAttachmentManager() const override      { return &m_AttachmentManager; }
  47.         virtual IDefaultSkeleton&       GetIDefaultSkeleton() override              { return *m_pDefaultSkeleton; }
  48.         virtual const IDefaultSkeleton& GetIDefaultSkeleton() const override        { return *m_pDefaultSkeleton; }
  49.         virtual IAnimationSet*          GetIAnimationSet() override                 { return m_pDefaultSkeleton->GetIAnimationSet(); }
  50.         virtual const IAnimationSet*    GetIAnimationSet() const override           { return m_pDefaultSkeleton->GetIAnimationSet(); }
  51.         virtual const char*             GetModelAnimEventDatabase() const override  { return m_pDefaultSkeleton->GetModelAnimEventDatabaseCStr(); }
  52.         virtual void                    EnableStartAnimation(bool bEnable) override { m_bEnableStartAnimation = bEnable; }
  53.         virtual void StartAnimationProcessing(const SAnimationProcessParams &params) override;
  54.         virtual AABB                    GetAABB() const override                    { return m_SkeletonPose.GetAABB(); }
  55.         virtual float GetExtent(EGeomForm eForm) override;
  56.         virtual void GetRandomPos(PosNorm & ran, CRndGen & seed, EGeomForm eForm) const override;
  57.         virtual CLodValue ComputeLod(int wantedLod, const SRenderingPassInfo &passInfo) override;
  58.         virtual void Render(const SRendParams &rParams, const QuatTS &Offset, const SRenderingPassInfo &passInfo) override;
  59.         virtual void                   SetFlags(int nFlags) override                        { m_rpFlags = nFlags; }
  60.         virtual int                    GetFlags() const override                            { return m_rpFlags; }
  61.         virtual int                    GetObjectType() const override                       { return m_pDefaultSkeleton->m_ObjectType; }
  62.         virtual const char*            GetFilePath() const override                         { return m_strFilePath.c_str(); }
  63.         virtual SMeshLodInfo           ComputeGeometricMean() const override;
  64.         virtual bool                   HasVertexAnimation() const override                  { return m_bHasVertexAnimation; }
  65.         virtual IMaterial*             GetMaterial() const override                         { return GetIMaterial(); }
  66.         virtual IMaterial*             GetIMaterial() const override                        { return m_pInstanceMaterial ? m_pInstanceMaterial.get() : m_pDefaultSkeleton->GetIMaterial(); }
  67.         virtual void                   SetIMaterial_Instance(IMaterial* pMaterial) override { m_pInstanceMaterial = pMaterial; }
  68.         virtual IMaterial*             GetIMaterial_Instance() const override               { return m_pInstanceMaterial; }
  69.         virtual IRenderMesh*           GetRenderMesh() const override                       { return m_pDefaultSkeleton ? m_pDefaultSkeleton->GetIRenderMesh() : nullptr; }
  70.         virtual phys_geometry*         GetPhysGeom(int nType) const override;
  71.         virtual IPhysicalEntity*       GetPhysEntity() const override;
  72.         virtual IFacialInstance*       GetFacialInstance() override;
  73.         virtual const IFacialInstance* GetFacialInstance() const override;
  74.         virtual void EnableFacialAnimation(bool bEnable) override;
  75.         virtual void EnableProceduralFacialAnimation(bool bEnable) override;
  76.         virtual void   SetPlaybackScale(f32 speed) override { m_fPlaybackScale = max(0.0f, speed); }
  77.         virtual f32    GetPlaybackScale() const override    { return m_fPlaybackScale; }
  78.         virtual uint32 IsCharacterVisible() const override  { return m_SkeletonPose.m_bInstanceVisible; };
  79.         virtual void SpawnSkeletonEffect(const char* effectName, const char* boneName, const Vec3 &offset, const Vec3 &dir, const QuatTS &entityLoc) override;
  80.         virtual void KillAllSkeletonEffects() override;
  81.         virtual void  SetViewdir(const Vec3& rViewdir) override                                     { m_Viewdir = rViewdir; }
  82.         virtual float GetUniformScale() const override                                              { return m_location.s; }
  83.         virtual void CopyPoseFrom(const ICharacterInstance &instance) override;
  84.         virtual void  FinishAnimationComputations() override                                        { m_SkeletonAnim.FinishAnimationComputations(); }
  85.         virtual void  SetAttachmentLocation_DEPRECATED(const QuatTS& newCharacterLocation) override { m_location = newCharacterLocation; } // TODO: Resolve this issue (has been described as "This is a hack to keep entity attachments in sync.").
  86.         virtual void OnDetach() override;
  87.         virtual void  HideMaster(uint32 h) override                                                 { m_bHideMaster = (h > 0); };
  88.         virtual void GetMemoryUsage(ICrySizer * pSizer) const override;
  89.         virtual void Serialize(TSerialize ser) override;
  90. #ifdef EDITOR_PCDEBUGCODE
  91.         virtual uint32 GetResetMode() const override        { return m_ResetMode; }
  92.         virtual void   SetResetMode(uint32 rm) override     { m_ResetMode = rm > 0; }
  93.         virtual f32    GetAverageFrameTime() const override { return g_AverageFrameTime; }
  94.         virtual void   SetCharEditMode(uint32 m) override   { m_CharEditMode = m; }
  95.         virtual uint32 GetCharEditMode() const override     { return m_CharEditMode; }
  96.         virtual void DrawWireframeStatic(const Matrix34 &m34, int nLOD, uint32 color) override;
  97.         virtual void ReloadCHRPARAMS() override;
  98. #endif
  99.         //////////////////////////////////////////////////////////
  100.  
  101.         CharacterInstanceProcessing::SContext* GetProcessingContext();
  102.         void                                   ClearProcessingContext() { m_processingContext = -1; };
  103.  
  104.         void WaitForSkinningJob() const;
  105.  
  106.         void RuntimeInit(CDefaultSkeleton * pExtDefaultSkeleton);
  107.  
  108.         SSkinningData* GetSkinningData();
  109.  
  110.         void           SetFilePath(const string& filePath) { m_strFilePath = filePath; }
  111.  
  112.         void           SetHasVertexAnimation(bool state)   { m_bHasVertexAnimation = state; }
  113.  
  114.         void SkinningTransformationsComputation(SSkinningData * pSkinningData, CDefaultSkeleton * pDefaultSkeleton, int nRenderLod, const Skeleton::CPoseData * pPoseData, f32 * pSkinningTransformationsMovement);
  115.  
  116.         void  SetWasVisible(bool wasVisible) { m_bWasVisible = wasVisible; }
  117.  
  118.         bool  GetWasVisible() const          { return m_bWasVisible; };
  119.  
  120.         int32 GetAnimationLOD() const        { return m_nAnimationLOD; }
  121.  
  122.         bool  FacialAnimationEnabled() const { return m_bFacialAnimationEnabled; }
  123.  
  124.         void SkeletonPostProcess();
  125.  
  126.         void UpdatePhysicsCGA(Skeleton::CPoseData & poseData, f32 fScale, const QuatTS &rAnimLocationNext);
  127.  
  128.         void ApplyJointVelocitiesToPhysics(IPhysicalEntity * pent, const Quat& qrot = Quat(IDENTITY), const Vec3& velHost = Vec3(ZERO));
  129.  
  130.         size_t SizeOfCharInstance() const;
  131.  
  132.         void RenderCGA(const struct SRendParams& rParams, const Matrix34 &RotTransMatrix34, const SRenderingPassInfo &passInfo);
  133.  
  134.         void RenderCHR(const struct SRendParams& rParams, const Matrix34 &RotTransMatrix34, const SRenderingPassInfo &passInfo);
  135.  
  136.         bool MotionBlurMotionCheck(uint64 nObjFlags) const;
  137.  
  138.         uint32 GetSkinningTransformationCount() const { return m_skinningTransformationsCount; }
  139.  
  140.         void BeginSkinningTransformationsComputation(SSkinningData * pSkinningData);
  141.  
  142.         void PerFrameUpdate();
  143.  
  144. private:
  145.         // Functions that are called from Character Instance Processing
  146.         void SetupThroughParent(const CCharInstance * pParent);
  147.         void SetupThroughParams(const SAnimationProcessParams * pParams);
  148.  
  149.         CCharInstance(const CCharInstance &) /*= delete*/;
  150.         void operator=(const CCharInstance&) /*= delete*/;
  151.  
  152. public:
  153.  
  154.         CAttachmentManager m_AttachmentManager;
  155.  
  156.         CSkeletonEffectManager m_skeletonEffectManager;
  157.  
  158.         CSkeletonAnim m_SkeletonAnim;
  159.  
  160.         CSkeletonPose m_SkeletonPose;
  161.  
  162.         QuatTS m_location;
  163.         Vec3 m_Viewdir;
  164.  
  165.         string m_strFilePath;
  166.  
  167.         struct
  168.         {
  169.                 SSkinningData* pSkinningData;
  170.                 int            nFrameID;
  171.         } arrSkinningRendererData[3];                                                      // Triple buffered for motion blur. (These resources are owned by the renderer)
  172.  
  173.         _smart_ptr<CDefaultSkeleton> m_pDefaultSkeleton;
  174.  
  175.         _smart_ptr<CFacialInstance> m_pFacialInstance;
  176.  
  177.         uint32 m_CharEditMode;
  178.  
  179.         uint32 m_rpFlags;
  180.  
  181.         uint32 m_LastUpdateFrameID_Pre;
  182.         uint32 m_LastUpdateFrameID_Post;
  183.  
  184.         float m_fPostProcessZoomAdjustedDistanceFromCamera;
  185.  
  186.         f32 m_fDeltaTime;
  187.         f32 m_fOriginalDeltaTime;
  188.  
  189.         // This is the scale factor that affects the animation speed of the character.
  190.         // All the animations are played with the constant real-time speed multiplied by this factor.
  191.         // So, 0 means still animations (stuck at some frame), 1 - normal, 2 - twice as fast, 0.5 - twice slower than normal.
  192.         f32 m_fPlaybackScale;
  193.  
  194.         bool m_bEnableStartAnimation;
  195.  
  196. private:
  197.  
  198.         _smart_ptr<IMaterial> m_pInstanceMaterial;
  199.  
  200.         CGeomExtents m_Extents;
  201.  
  202.         int m_nRefCounter;
  203.  
  204.         uint32 m_LastRenderedFrameID;     // Can be accessed from main thread only!
  205.  
  206.         int32 m_nAnimationLOD;
  207.  
  208.         uint32 m_ResetMode;
  209.  
  210.         uint32 m_skinningTransformationsCount;
  211.  
  212.         f32 m_skinningTransformationsMovement;
  213.  
  214.         bool m_bHasVertexAnimation;
  215.  
  216.         bool m_bWasVisible;
  217.  
  218.         bool m_bPlayedPhysAnim;
  219.  
  220.         bool m_bHideMaster;
  221.  
  222.         bool m_bFacialAnimationEnabled;
  223.  
  224.         int m_processingContext;
  225.  
  226. };
  227.  
  228. inline int CCharInstance::AddRef()
  229. {
  230.         return ++m_nRefCounter;
  231. }
  232.  
  233. inline int CCharInstance::GetRefCount() const
  234. {
  235.         return m_nRefCounter;
  236. }
  237.  
  238. inline int CCharInstance::Release()
  239. {
  240.         if (--m_nRefCounter == 0)
  241.         {
  242.                 m_AttachmentManager.RemoveAllAttachments();
  243.                 delete this;
  244.                 return 0;
  245.         }
  246.         else if (m_nRefCounter < 0)
  247.         {
  248.                 // Should never happens, someone tries to release CharacterInstance pointer twice.
  249.                 assert(0 && "CSkelInstance::Release");
  250.                 CryFatalError("CSkelInstance::Release");
  251.         }
  252.         return m_nRefCounter;
  253. }
  254.  
  255. inline void CCharInstance::SpawnSkeletonEffect(const char* effectName, const char* boneName, const Vec3& offset, const Vec3& dir, const QuatTS& entityLoc)
  256. {
  257.         m_skeletonEffectManager.SpawnEffect(this, effectName, boneName, offset, dir, entityLoc);
  258. }
  259.  
  260. inline void CCharInstance::KillAllSkeletonEffects()
  261. {
  262.         m_skeletonEffectManager.KillAllEffects();
  263. }
  264.  
downloadCharacterInstance.h Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top