BVB Source Codes

CRYENGINE Show MannequinObject.cpp Source code

Return Download CRYENGINE: download MannequinObject.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. #include "StdAfx.h"
  4. #include "MannequinObject.h"
  5.  
  6. #include <CrySerialization/Decorators/Resources.h>
  7.  
  8. #include "IAnimatedCharacter.h"
  9. #include "GameObjects/GameObject.h"
  10.  
  11. CRYREGISTER_CLASS(CMannequinObject);
  12.  
  13. CMannequinObject::CProperties::CProperties(CMannequinObject& owner)
  14.         : modelFilePath()
  15.         , actionControllerFilePath()
  16.         , animationDatabaseFilePath()
  17.         , ownerBackReference(owner)
  18. {
  19. }
  20.  
  21. const char* CMannequinObject::CProperties::GetLabel() const
  22. {
  23.         return "Mannequin";
  24. }
  25.  
  26. void CMannequinObject::CProperties::SerializeProperties(Serialization::IArchive& archive)
  27. {
  28.         archive(Serialization::ModelFilename(modelFilePath), "model", "Model");
  29.         archive(Serialization::GeneralFilename(actionControllerFilePath), "actionController", "Action Controller");
  30.         archive(Serialization::GeneralFilename(animationDatabaseFilePath), "animationDatabase", "Animation Database (3P)");
  31.  
  32.         if (archive.isInput())
  33.         {
  34.                 ownerBackReference.Reset();
  35.         }
  36. }
  37.  
  38. CMannequinObject::CMannequinObject()
  39.         : m_properties(*this)
  40.         , m_pAnimatedCharacter(nullptr)
  41. {
  42. }
  43.  
  44. void CMannequinObject::Initialize()
  45. {
  46.         const auto pGameObject = gEnv->pGameFramework->GetIGameObjectSystem()->CreateGameObjectForEntity(GetEntity()->GetId());
  47.         assert(pGameObject);
  48.  
  49.         pGameObject->EnablePrePhysicsUpdate(ePPU_Always);
  50.         pGameObject->EnablePhysicsEvent(true, eEPE_OnPostStepImmediate);
  51. }
  52.  
  53. void CMannequinObject::OnShutDown()
  54. {
  55.         if (m_pAnimatedCharacter)
  56.         {
  57.                 IGameObject* pGameObject = GetEntity()->GetComponent<CGameObject>();
  58.                 assert(pGameObject);
  59.                 assert(pGameObject == gEnv->pGameFramework->GetGameObject(GetEntity()->GetId()));
  60.  
  61.                 pGameObject->ReleaseExtension("AnimatedCharacter");
  62.         }
  63. }
  64.  
  65. void CMannequinObject::ProcessEvent(SEntityEvent& event)
  66. {
  67.         switch (event.event)
  68.         {
  69.         case ENTITY_EVENT_START_LEVEL:
  70.         case ENTITY_EVENT_RESET:
  71.         case ENTITY_EVENT_EDITOR_PROPERTY_CHANGED:
  72.         case ENTITY_EVENT_XFORM_FINISHED_EDITOR:
  73.                 Reset();
  74.                 break;
  75.         default:
  76.                 break;
  77.         }
  78. }
  79.  
  80. uint64 CMannequinObject::GetEventMask() const
  81. {
  82.         return BIT64(ENTITY_EVENT_START_LEVEL)
  83.                | BIT64(ENTITY_EVENT_EDITOR_PROPERTY_CHANGED)
  84.                | BIT64(ENTITY_EVENT_RESET)
  85.                | BIT64(ENTITY_EVENT_XFORM_FINISHED_EDITOR);
  86. }
  87.  
  88. IEntityPropertyGroup* CMannequinObject::GetPropertyGroup()
  89. {
  90.         return &m_properties;
  91. }
  92.  
  93. void CMannequinObject::GetMemoryUsage(ICrySizer* s) const
  94. {
  95.         s->Add(*this);
  96. }
  97.  
  98. void CMannequinObject::Reset()
  99. {
  100.         IEntity& entity = *GetEntity();
  101.  
  102.         const auto pGameObject = gEnv->pGameFramework->GetIGameObjectSystem()->CreateGameObjectForEntity(entity.GetId());
  103.         assert(pGameObject);
  104.  
  105.         if (!m_pAnimatedCharacter)
  106.         {
  107.                 m_pAnimatedCharacter = static_cast<IAnimatedCharacter*>(pGameObject->AcquireExtension("AnimatedCharacter"));
  108.                 assert(m_pAnimatedCharacter);
  109.         }
  110.  
  111.         m_pAnimatedCharacter->ResetState();
  112.         m_pAnimatedCharacter->Init(pGameObject);
  113.         m_pAnimatedCharacter->SetMovementControlMethods(eMCM_Animation, eMCM_Animation);
  114.         if (IActionController* pActionController = m_pAnimatedCharacter->GetActionController())
  115.         {
  116.                 pActionController->GetContext().state.Clear();
  117.         }
  118.  
  119.         if (!m_properties.modelFilePath.empty())
  120.         {
  121.                 entity.LoadCharacter(0, m_properties.modelFilePath.c_str());
  122.         }
  123.  
  124.         {
  125.                 SEntityPhysicalizeParams physicsParams;
  126.                 physicsParams.type = PE_LIVING;
  127.                 physicsParams.nSlot = 0;
  128.                 physicsParams.mass = 80.0f;
  129.                 physicsParams.nFlagsOR = pef_monitor_poststep;
  130.  
  131.                 pe_player_dynamics playerDyn;
  132.                 playerDyn.gravity = Vec3(0, 0, 9.81f);
  133.                 playerDyn.kAirControl = 0.9f;
  134.                 playerDyn.mass = 80;
  135.                 playerDyn.minSlideAngle = 45;
  136.                 playerDyn.maxClimbAngle = 50;
  137.                 playerDyn.minFallAngle = 50;
  138.                 playerDyn.maxVelGround = 16;
  139.                 physicsParams.pPlayerDynamics = &playerDyn;
  140.  
  141.                 pe_player_dimensions playerDim;
  142.                 playerDim.heightCollider = 1.0f;
  143.                 playerDim.sizeCollider = Vec3(0.4f, 0.4f, 0.1f);
  144.                 playerDim.heightPivot = 0.0f;
  145.                 playerDim.maxUnproj = 0.0f;
  146.                 playerDim.bUseCapsule = true;
  147.                 physicsParams.pPlayerDimensions = &playerDim;
  148.  
  149.                 entity.Physicalize(physicsParams);
  150.         }
  151.  
  152.         m_pAnimatedCharacter->ResetInertiaCache();
  153. }
  154.  
downloadMannequinObject.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