Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Model.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_MODEL_HPP
8 #define NAZARA_MODEL_HPP
9 
10 #include <Nazara/Prerequesites.hpp>
11 #include <Nazara/Core/Resource.hpp>
12 #include <Nazara/Core/ResourceLoader.hpp>
13 #include <Nazara/Core/ResourceParameters.hpp>
14 #include <Nazara/Graphics/InstancedRenderable.hpp>
15 #include <Nazara/Graphics/Material.hpp>
16 #include <Nazara/Utility/Mesh.hpp>
17 
18 namespace Nz
19 {
20  struct NAZARA_GRAPHICS_API ModelParameters : ResourceParameters
21  {
22  ModelParameters();
23 
24  bool loadMaterials = true;
25  MaterialParams material;
26  MeshParams mesh;
27 
28  bool IsValid() const;
29  };
30 
31  class Model;
32 
33  using ModelConstRef = ObjectRef<const Model>;
34  using ModelLoader = ResourceLoader<Model, ModelParameters>;
35  using ModelRef = ObjectRef<Model>;
36 
37  class NAZARA_GRAPHICS_API Model : public InstancedRenderable, public Resource
38  {
39  friend ModelLoader;
40 
41  public:
42  inline Model();
43  Model(const Model& model) = default;
44  Model(Model&& model) = default;
45  virtual ~Model();
46 
47  void AddToRenderQueue(AbstractRenderQueue* renderQueue, const InstanceData& instanceData) const override;
48  inline void AddToRenderQueue(AbstractRenderQueue* renderQueue, const Matrix4f& transformMatrix, unsigned int renderOrder = 0);
49 
51  const MaterialRef& GetMaterial(const String& subMeshName) const;
52  const MaterialRef& GetMaterial(std::size_t skinIndex, const String& subMeshName) const;
53  Mesh* GetMesh() const;
54 
55  virtual bool IsAnimated() const;
56 
57  bool LoadFromFile(const String& filePath, const ModelParameters& params = ModelParameters());
58  bool LoadFromMemory(const void* data, std::size_t size, const ModelParameters& params = ModelParameters());
59  bool LoadFromStream(Stream& stream, const ModelParameters& params = ModelParameters());
60 
62  bool SetMaterial(const String& subMeshName, MaterialRef material);
63  bool SetMaterial(std::size_t skinIndex, const String& subMeshName, MaterialRef material);
64 
65  virtual void SetMesh(Mesh* mesh);
66 
67  Model& operator=(const Model& node) = default;
68  Model& operator=(Model&& node) = default;
69 
70  template<typename... Args> static ModelRef New(Args&&... args);
71 
72  protected:
73  void MakeBoundingVolume() const override;
74 
75  MeshRef m_mesh;
76 
77  static ModelLoader::LoaderList s_loaders;
78  };
79 }
80 
81 #include <Nazara/Graphics/Model.inl>
82 
83 #endif // NAZARA_MODEL_HPP
TODO: Inherit SoundEmitter from Node.
Definition: Algorithm.hpp:12
Graphics class that represents a model.
Definition: Model.hpp:37
Core class that represents a string.
Definition: String.hpp:22
Graphics class that represents the rendering queue for our scene.
Definition: AbstractRenderQueue.hpp:26
const MaterialRef & GetMaterial(std::size_t matIndex=0) const
Gets one of the material used by the object.
Definition: InstancedRenderable.inl:54
void SetMaterial(std::size_t matIndex, MaterialRef material)
Changes the material used at the specified index by another one.
Definition: InstancedRenderable.inl:216
Graphics class that represents an instancer renderable.
Definition: InstancedRenderable.hpp:30
Core class that represents a loader of resources.
Definition: ResourceLoader.hpp:23
Core class that represents a resource.
Definition: Resource.hpp:15
Core class that represents a stream.
Definition: Stream.hpp:19