EntityModel.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "Entity.h"
  17. /**
  18. * A 3D model for an entity.
  19. */
  20. class EntityModel : public Entity{
  21. public:
  22. /**
  23. * Constructor. Creates an entity model.
  24. *
  25. * The models will be looked for in the resource groups FIELD_MODELS, BATTLE_MODELS or
  26. * WORLD_MODELS, depending on the module the {@see EntityManager} is currerntly set to.
  27. *
  28. * @param[in] name Entity name.
  29. * @param[in] file_name File with the model data.
  30. * @param[in] node Scene node to attach the model to.
  31. */
  32. EntityModel(
  33. const Ogre::String& name, const Ogre::String file_name,
  34. Ogre::SceneNode* node, const Ogre::String& resource_group = ""
  35. );
  36. virtual ~EntityModel();
  37. /**
  38. * Updates the model status.
  39. */
  40. virtual void Update();
  41. /**
  42. * Toggles the model visibility.
  43. *
  44. * @param[in] visible True to make the model visible, false to turn it
  45. * invisible.
  46. */
  47. virtual void SetVisible(const bool visible);
  48. /**
  49. * Checks the model visibility.
  50. *
  51. * @return True if the model is visible, false if it's invisible.
  52. */
  53. virtual bool IsVisible() const;
  54. virtual float GetAnimationLength(const Ogre::String& animation) const;
  55. virtual unsigned int GetAnimationCount() const;
  56. Ogre::Entity* GetModel();
  57. virtual void ScriptSetBlend(const int blend);
  58. virtual void ScriptSetAlpha(const float alpha);
  59. virtual void ScriptSetTexture(const char* texture);
  60. virtual std::tuple<float, float, float> ScriptGetBonePosition(const int bone);
  61. virtual bool ScriptAttachModel(
  62. const char* model, const int bone, const float rx, const float ry, const float rz
  63. );
  64. virtual void ReleaseResources();
  65. /**
  66. * Plays an animation of the model.
  67. *
  68. * @param[in] animation Name of the animation to play.
  69. * @param[in] state Initial state of the animation.
  70. * @param[in] play_type Play mode, for single or looped playbacks.
  71. * @param[in] start Start point in time of the animation, in seconds.
  72. * @param[in] end End point in time of the animation, in seconds.
  73. */
  74. virtual void PlayAnimation(
  75. const Ogre::String& animation, AnimationState state,
  76. AnimationPlayType play_type, const float start, const float end
  77. );
  78. /**
  79. * Resumes an animation.
  80. *
  81. * @param[in] animation The name of the animation to resume.
  82. */
  83. virtual void PlayAnimationContinue(const Ogre::String& animation);
  84. /**
  85. * Updates the animation.
  86. *
  87. * @param[in] delta Ellapsed time.
  88. */
  89. virtual void UpdateAnimation(const float delta);
  90. private:
  91. /**
  92. * Gets the material of a part of the model that only this model uses, making it from the shared
  93. * one the first time.
  94. */
  95. Ogre::MaterialPtr OwnMaterial(Ogre::SubEntity* sub_entity);
  96. /**
  97. * Constructor.
  98. */
  99. EntityModel();
  100. /**
  101. * The model.
  102. */
  103. Ogre::Entity* model_;
  104. /**
  105. * Model attached to a bone of the skeleton (a weapon), nullptr if there is none.
  106. */
  107. Ogre::Entity* attached_model_ = nullptr;
  108. /**
  109. * Resource group of the model, to load the attached models from.
  110. */
  111. Ogre::String resource_group_;
  112. /**
  113. * The current animation state.
  114. */
  115. Ogre::AnimationState* animation_current_;
  116. /**
  117. * Blend mode of the model, one of {@see Entity::EffectBlend}.
  118. */
  119. int blend_ = Entity::BLEND_NORMAL;
  120. /**
  121. * Materials created to give this model its own blending, so they are removed with it.
  122. */
  123. std::vector<Ogre::String> own_materials_;
  124. };