Fillwave  10.0.0
Model.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/flf/models/base/Programmable.h>
25 #include <flw/flf/models/Mesh.h>
26 
27 #include <flw/flf/loaders/modelloader/ModelLoaderTraits.h>
28 #include <flw/flf/loaders/ProgramLoader.h>
29 
30 #include <flw/cmn/pointers/PointerProtected.h>
31 
32 
33 namespace flw {
34 class Engine;
35 namespace flf {
36 class TimedBoneUpdateCallback;
37 
42 class Model : public Programmable {
43 public:
44  Model(Engine* engine,
45  flc::Program* program,
46  const flf::Shape<flc::VertexBasic>& shape,
47  flc::Texture2D* diffuseMap,
48  flc::Texture2D* normalMap = nullptr,
49  flc::Texture2D* specularMap = nullptr,
50  const Material &material = Material());
51 
52  Model(Engine *engine, flc::Program* program, const std::string& shapePath);
53 
54  Model(Engine *engine,
55  flc::Program* program,
56  const std::string& shapePath,
57  const std::string& diffuseMapPath,
58  const std::string& normalMapPath = "",
59  const std::string& specularMapPath = "");
60 
61  Model(Engine *engine,
62  flc::Program* program,
63  const std::string& shapePath,
64  flc::Texture2D* diffuseMap,
65  flc::Texture2D* normalMap = nullptr,
66  flc::Texture2D* specularMap = nullptr,
67  const Material &material = Material());
68 
69  ~Model() override;
70 
71  Model &operator=(Model &&) = default;
72 
73  Model(Model &&obj) = default;
74 
75  void reloadModel(const std::string& shapePath);
76 
77  void reloadModel(
78  const std::string& path
79  , flc::Texture2D* diff
80  , flc::Texture2D* norm
81  , flc::Texture2D* specular
82  , const Material& material = Material());
83 
84  void drawFR(ICamera &camera) override;
85 
86  void drawPBRP(ICamera &camera) override;
87 
88  void drawDR(ICamera &camera) override;
89 
90  /* Animation */
91  void performAnimation(GLfloat timeElapsed_us);
92 
93  void setActiveAnimation(GLint animationID);
94 
95  pn<Mesh> getMesh(size_t id);
96 
97  /* IRenderable */
98  void updateRenderer(flc::IRenderer &renderer) override;
99 
100  void log() const override;
101 
102  protected:
103  Engine* mEngine;
104  ProgramLoader mProgramLoader;
105  pu<ModelLoader::Animator> mAnimator;
106 
107  LightSystem& mLights;
108  flc::Program* mProgramShadow;
109  flc::Program* mProgramShadowColor;
110  GLint mUniformLocationCacheBones;
111  GLint mUniformLocationCacheBonesShadow;
112  GLint mUniformLocationCacheBonesShadowColor;
113  vecHeap<Mesh*> mMeshes;
114 
115  private:
116  /* Init */
117  void initUniformsCache();
118  void initShadowing();
119 
120  /* Animation */
121  void initAnimations(const ModelLoader::SceneType& scene);
122  void evaluateAnimations();
123  bool isAnimated() const override;
124 
125  void unloadNodes();
126 
127  void loadNodes(const ModelLoader::NodeType* node, const ModelLoader::SceneType& scene, Entity* entity);
128 
129  void loadNodes(
130  const ModelLoader::NodeType* node
131  , const ModelLoader::SceneType& scene
132  , Entity* entity
133  , flc::Texture2D* diffuse
134  , flc::Texture2D* normal
135  , flc::Texture2D* specular
136  , const Material &material = Material());
137 
138  pu<Mesh> loadMesh(
139  const ModelLoader::ShapeType* shape
140  , const Material& material
141  , flc::Texture2D* diffuse
142  , flc::Texture2D* normal
143  , flc::Texture2D* specular
144  , Engine *engine);
145 };
146 
147 } /* flf */
148 } /* flw */
Definition: Aliases.h:30
Per mesh material info.
Definition: Material.h:32
Base for all renderers.
Definition: IRenderer.h:42
Single GLSL 2D Texture object.
Definition: Texture2D.h:36
Loads programs.
Definition: ProgramLoader.h:37
Fillwave engine core.
Definition: Engine.h:85
Base for all Scene nodes.
Definition: Entity.h:48
Light system knows about all light related stuff.
Definition: LightSystem.h:40
Single GLSL program object.
Definition: Program.h:37
Drawable Mesh set.
Definition: Model.h:42
Stores camera view parameters.
Definition: ICamera.h:32
Entity for which is it possible to add/remove Effect objects.
Definition: Programmable.h:34