| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include "Entity.h"
- /**
- * A 3D model for an entity.
- */
- class EntityModel : public Entity{
- public:
- /**
- * Constructor. Creates an entity model.
- *
- * The models will be looked for in the resource groups FIELD_MODELS, BATTLE_MODELS or
- * WORLD_MODELS, depending on the module the {@see EntityManager} is currerntly set to.
- *
- * @param[in] name Entity name.
- * @param[in] file_name File with the model data.
- * @param[in] node Scene node to attach the model to.
- */
- EntityModel(
- const Ogre::String& name, const Ogre::String file_name,
- Ogre::SceneNode* node, const Ogre::String& resource_group = ""
- );
- virtual ~EntityModel();
- /**
- * Updates the model status.
- */
- virtual void Update();
- /**
- * Toggles the model visibility.
- *
- * @param[in] visible True to make the model visible, false to turn it
- * invisible.
- */
- virtual void SetVisible(const bool visible);
- /**
- * Checks the model visibility.
- *
- * @return True if the model is visible, false if it's invisible.
- */
- virtual bool IsVisible() const;
- virtual float GetAnimationLength(const Ogre::String& animation) const;
- virtual unsigned int GetAnimationCount() const;
- Ogre::Entity* GetModel();
- virtual void ScriptSetBlend(const int blend);
- virtual void ScriptSetAlpha(const float alpha);
- virtual void ScriptSetTexture(const char* texture);
- virtual std::tuple<float, float, float> ScriptGetBonePosition(const int bone);
- virtual bool ScriptAttachModel(
- const char* model, const int bone, const float rx, const float ry, const float rz
- );
- virtual void ReleaseResources();
- /**
- * Plays an animation of the model.
- *
- * @param[in] animation Name of the animation to play.
- * @param[in] state Initial state of the animation.
- * @param[in] play_type Play mode, for single or looped playbacks.
- * @param[in] start Start point in time of the animation, in seconds.
- * @param[in] end End point in time of the animation, in seconds.
- */
- virtual void PlayAnimation(
- const Ogre::String& animation, AnimationState state,
- AnimationPlayType play_type, const float start, const float end
- );
- /**
- * Resumes an animation.
- *
- * @param[in] animation The name of the animation to resume.
- */
- virtual void PlayAnimationContinue(const Ogre::String& animation);
- /**
- * Updates the animation.
- *
- * @param[in] delta Ellapsed time.
- */
- virtual void UpdateAnimation(const float delta);
- private:
- /**
- * Gets the material of a part of the model that only this model uses, making it from the shared
- * one the first time.
- */
- Ogre::MaterialPtr OwnMaterial(Ogre::SubEntity* sub_entity);
- /**
- * Constructor.
- */
- EntityModel();
- /**
- * The model.
- */
- Ogre::Entity* model_;
- /**
- * Model attached to a bone of the skeleton (a weapon), nullptr if there is none.
- */
- Ogre::Entity* attached_model_ = nullptr;
- /**
- * Resource group of the model, to load the attached models from.
- */
- Ogre::String resource_group_;
- /**
- * The current animation state.
- */
- Ogre::AnimationState* animation_current_;
- /**
- * Blend mode of the model, one of {@see Entity::EffectBlend}.
- */
- int blend_ = Entity::BLEND_NORMAL;
- /**
- * Materials created to give this model its own blending, so they are removed with it.
- */
- std::vector<Ogre::String> own_materials_;
- };
|