BVB Source Codes

CRYENGINE Show LipSync_FacialInstance.cpp Source code

Return Download CRYENGINE: download LipSync_FacialInstance.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. // -------------------------------------------------------------------------
  4. //  File name:   LipSync_FacialInstance.cpp
  5. //  Version:     v1.00
  6. //  Created:     2014-08-29 by Christian Werle.
  7. //  Description: Automatic start of facial animation when a sound is being played back.
  8. //               Legacy version that uses CryAnimation's FacialInstance.
  9. // -------------------------------------------------------------------------
  10. //  History:
  11. //
  12. ////////////////////////////////////////////////////////////////////////////
  13. #include "StdAfx.h"
  14. #include "LipSync_FacialInstance.h"
  15.  
  16. //=============================================================================
  17. //
  18. // CLipSyncProvider_FacialInstance
  19. //
  20. //=============================================================================
  21.  
  22. CLipSyncProvider_FacialInstance::CLipSyncProvider_FacialInstance(EntityId entityId)
  23.         : m_entityId(entityId)
  24. {
  25. }
  26.  
  27. void CLipSyncProvider_FacialInstance::RequestLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  28. {
  29.         // actually facial sequence is triggered in OnSoundEvent SOUND_EVENT_ON_PLAYBACK_STARTED of the CSoundProxy
  30.         // when playback is started, it will start facial sequence as well
  31. }
  32.  
  33. void CLipSyncProvider_FacialInstance::StartLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  34. {
  35.         if (lipSyncMethod != eLSM_None)
  36.         {
  37.                 LipSyncWithSound(audioTriggerId);
  38.         }
  39. }
  40.  
  41. void CLipSyncProvider_FacialInstance::PauseLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  42. {
  43.         if (lipSyncMethod != eLSM_None)
  44.         {
  45.                 LipSyncWithSound(audioTriggerId, true);
  46.         }
  47. }
  48.  
  49. void CLipSyncProvider_FacialInstance::UnpauseLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  50. {
  51.         if (lipSyncMethod != eLSM_None)
  52.         {
  53.                 LipSyncWithSound(audioTriggerId);
  54.         }
  55. }
  56.  
  57. void CLipSyncProvider_FacialInstance::StopLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  58. {
  59.         if (lipSyncMethod != eLSM_None)
  60.         {
  61.                 LipSyncWithSound(audioTriggerId, true);
  62.         }
  63. }
  64.  
  65. void CLipSyncProvider_FacialInstance::UpdateLipSync(IEntityAudioComponent* pProxy, const AudioControlId audioTriggerId, const ELipSyncMethod lipSyncMethod)
  66. {
  67. }
  68.  
  69. void CLipSyncProvider_FacialInstance::FullSerialize(TSerialize ser)
  70. {
  71.         ser.BeginGroup("LipSyncProvider_FacialInstance");
  72.         ser.EndGroup();
  73. }
  74.  
  75. void CLipSyncProvider_FacialInstance::LipSyncWithSound(const AudioControlId audioTriggerId, bool bStop /*= false*/)
  76. {
  77.         if (IEntity* pEntity = gEnv->pEntitySystem->GetEntity(m_entityId))
  78.         {
  79.                 if (ICharacterInstance* pChar = pEntity->GetCharacter(0))
  80.                 {
  81.                         if (IFacialInstance* pFacial = pChar->GetFacialInstance())
  82.                         {
  83.                                 pFacial->LipSyncWithSound(audioTriggerId, bStop);
  84.                         }
  85.                 }
  86.         }
  87. }
  88.  
  89. //=============================================================================
  90. //
  91. // CLipSync_FacialInstance
  92. //
  93. //=============================================================================
  94.  
  95. void CLipSync_FacialInstance::InjectLipSyncProvider()
  96. {
  97.         IEntity* pEntity = GetEntity();
  98.         IEntityAudioComponent* pSoundProxy = pEntity->GetOrCreateComponent<IEntityAudioComponent>();
  99.         CRY_ASSERT(pSoundProxy);
  100.         m_pLipSyncProvider.reset(new CLipSyncProvider_FacialInstance(pEntity->GetId()));
  101.         REINST(add SetLipSyncProvider to interface)
  102.         //pSoundProxy->SetLipSyncProvider(m_pLipSyncProvider);
  103. }
  104.  
  105. void CLipSync_FacialInstance::GetMemoryUsage(ICrySizer* pSizer) const
  106. {
  107.         pSizer->Add(*this);
  108.         if (m_pLipSyncProvider)
  109.         {
  110.                 pSizer->Add(*m_pLipSyncProvider);
  111.         }
  112. }
  113.  
  114. bool CLipSync_FacialInstance::Init(IGameObject* pGameObject)
  115. {
  116.         SetGameObject(pGameObject);
  117.         return true;
  118. }
  119.  
  120. void CLipSync_FacialInstance::PostInit(IGameObject* pGameObject)
  121. {
  122.         InjectLipSyncProvider();
  123. }
  124.  
  125. void CLipSync_FacialInstance::InitClient(int channelId)
  126. {
  127. }
  128.  
  129. void CLipSync_FacialInstance::PostInitClient(int channelId)
  130. {
  131. }
  132.  
  133. bool CLipSync_FacialInstance::ReloadExtension(IGameObject* pGameObject, const SEntitySpawnParams& params)
  134. {
  135.         ResetGameObject();
  136.         return true;
  137. }
  138.  
  139. void CLipSync_FacialInstance::PostReloadExtension(IGameObject* pGameObject, const SEntitySpawnParams& params)
  140. {
  141.         InjectLipSyncProvider();
  142. }
  143.  
  144. void CLipSync_FacialInstance::FullSerialize(TSerialize ser)
  145. {
  146.         ser.BeginGroup("LipSync_FacialInstance");
  147.  
  148.         bool bLipSyncProviderIsInjected = (m_pLipSyncProvider != NULL);
  149.         ser.Value("bLipSyncProviderIsInjected", bLipSyncProviderIsInjected);
  150.         if (bLipSyncProviderIsInjected && !m_pLipSyncProvider)
  151.         {
  152.                 CRY_ASSERT(ser.IsReading());
  153.                 InjectLipSyncProvider();
  154.         }
  155.         if (m_pLipSyncProvider)
  156.         {
  157.                 m_pLipSyncProvider->FullSerialize(ser);
  158.         }
  159.  
  160.         ser.EndGroup();
  161. }
  162.  
  163. bool CLipSync_FacialInstance::NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int pflags)
  164. {
  165.         return true;
  166. }
  167.  
  168. void CLipSync_FacialInstance::PostSerialize()
  169. {
  170. }
  171.  
  172. void CLipSync_FacialInstance::SerializeSpawnInfo(TSerialize ser)
  173. {
  174. }
  175.  
  176. ISerializableInfoPtr CLipSync_FacialInstance::GetSpawnInfo()
  177. {
  178.         return NULL;
  179. }
  180.  
  181. void CLipSync_FacialInstance::Update(SEntityUpdateContext& ctx, int updateSlot)
  182. {
  183. }
  184.  
  185. void CLipSync_FacialInstance::HandleEvent(const SGameObjectEvent& event)
  186. {
  187. }
  188.  
  189. void CLipSync_FacialInstance::ProcessEvent(SEntityEvent& event)
  190. {
  191. }
  192.  
  193. uint64 CLipSync_FacialInstance::GetEventMask() const
  194. {
  195.         return 0;
  196. }
  197.  
  198. void CLipSync_FacialInstance::SetChannelId(uint16 id)
  199. {
  200. }
  201.  
  202. void CLipSync_FacialInstance::SetAuthority(bool auth)
  203. {
  204. }
  205.  
  206. void CLipSync_FacialInstance::PostUpdate(float frameTime)
  207. {
  208. }
  209.  
  210. void CLipSync_FacialInstance::PostRemoteSpawn()
  211. {
  212. }
  213.  
  214. void CLipSync_FacialInstance::OnShutDown()
  215. {
  216.         IEntity* pEntity = GetEntity();
  217.         if (IEntityAudioComponent* pSoundProxy = pEntity->GetComponent<IEntityAudioComponent>())
  218.         {
  219.                 REINST(add SetLipSyncProvider to interface)
  220.                         //pSoundProxy->SetLipSyncProvider(ILipSyncProviderPtr());
  221.         }
  222. }
  223.  
downloadLipSync_FacialInstance.cpp 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