Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
SkeletalModel.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Engine - Graphics module"
3 // For conditions of distribution and use, see copyright notice in Config.hpp
4 
5 #pragma once
6 
7 #ifndef NAZARA_SKELETALMODEL_HPP
8 #define NAZARA_SKELETALMODEL_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/ResourceLoader.hpp>
12 #include <Nazara/Core/Updatable.hpp>
13 #include <Nazara/Graphics/Model.hpp>
14 #include <Nazara/Utility/Animation.hpp>
15 #include <Nazara/Utility/Skeleton.hpp>
16 
17 namespace Nz
18 {
19  struct NAZARA_GRAPHICS_API SkeletalModelParameters : ModelParameters
20  {
21  bool loadAnimation = true;
22  AnimationParams animation;
23 
24  bool IsValid() const;
25  };
26 
27  class SkeletalModel;
28 
29  using SkeletalModelLoader = ResourceLoader<SkeletalModel, SkeletalModelParameters>;
30 
31  class NAZARA_GRAPHICS_API SkeletalModel : public Model, Updatable
32  {
33  friend SkeletalModelLoader;
34 
35  public:
36  SkeletalModel();
37  SkeletalModel(const SkeletalModel& model) = default;
38  SkeletalModel(SkeletalModel&& model) = default;
39  ~SkeletalModel() = default;
40 
41  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
42  void AdvanceAnimation(float elapsedTime);
43 
44  SkeletalModel* Clone() const;
45  SkeletalModel* Create() const;
46 
47  void EnableAnimation(bool animation);
48 
49  Animation* GetAnimation() const;
50  Skeleton* GetSkeleton();
51  const Skeleton* GetSkeleton() const;
52 
53  bool HasAnimation() const;
54 
55  bool IsAnimated() const override;
56  bool IsAnimationEnabled() const;
57 
58  bool LoadFromFile(const String& filePath, const SkeletalModelParameters& params = SkeletalModelParameters());
59  bool LoadFromMemory(const void* data, std::size_t size, const SkeletalModelParameters& params = SkeletalModelParameters());
60  bool LoadFromStream(Stream& stream, const SkeletalModelParameters& params = SkeletalModelParameters());
61 
62  bool SetAnimation(Animation* animation);
63  void SetMesh(Mesh* mesh) override;
64  bool SetSequence(const String& sequenceName);
65  void SetSequence(unsigned int sequenceIndex);
66 
67  SkeletalModel& operator=(const SkeletalModel& node) = default;
68  SkeletalModel& operator=(SkeletalModel&& node) = default;
69 
70  private:
71  void MakeBoundingVolume() const override;
72  /*void Register() override;
73  void Unregister() override;*/
74  void Update() override;
75 
76  AnimationRef m_animation;
77  Skeleton m_skeleton;
78  const Sequence* m_currentSequence;
79  bool m_animationEnabled;
80  float m_interpolation;
81  unsigned int m_currentFrame;
82  unsigned int m_nextFrame;
83 
84  static SkeletalModelLoader::LoaderList s_loaders;
85  };
86 }
87 
88 #endif // NAZARA_SKELETALMODEL_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents a model.
Definition: Model.hpp:37
Graphics class that represents a model with a skeleton.
Definition: SkeletalModel.hpp:31
Core class that represents a string.
Definition: String.hpp:22
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
Core class that represents a loader of resources.
Definition: ResourceLoader.hpp:23
Core class that represents a stream.
Definition: Stream.hpp:19