Pioneer
ModelViewer.h
Go to the documentation of this file.
1 // Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
2 // Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3 
4 #ifndef MODELVIEWER_H
5 #define MODELVIEWER_H
6 
7 #include "Input.h"
8 #include "NavLights.h"
9 #include "Shields.h"
10 #include "core/GuiApplication.h"
11 #include "graphics/Drawables.h"
12 #include "graphics/Renderer.h"
13 #include "graphics/Texture.h"
14 #include "libs.h"
15 #include "lua/LuaManager.h"
16 #include "pigui/PiGui.h"
17 #include "scenegraph/SceneGraph.h"
18 
19 #include <memory>
20 
21 class ModelViewer;
22 
24 public:
26  GuiApplication("Model Viewer")
27  {}
28 
29  void SetInitialModel(std::string &modelName) { m_modelName = modelName; }
30  std::string &GetModelName() { return m_modelName; }
31 
32 protected:
33  void Startup() override;
34  void Shutdown() override;
35 
36  void PreUpdate() override;
37  void PostUpdate() override;
38 
39  friend class ModelViewer;
40 
41 private:
42  std::string m_modelName;
43  std::shared_ptr<ModelViewer> m_modelViewer;
44 };
45 
47 public:
48  enum class CameraPreset : uint8_t {
49  Front,
50  Back,
51  Left,
52  Right,
53  Top,
54  Bottom
55  };
56 
58 
59  void SetModel(const std::string &modelName);
60  bool SetRandomColor();
61  void ResetCamera();
62  void ChangeCameraPreset(CameraPreset preset);
63 
64 protected:
65  void Start() override;
66  void Update(float deltaTime) override;
67  void End() override;
68  void SetupAxes();
69  void HandleInput();
70 
71 private:
72  void AddLog(const std::string &line);
73 
74  void UpdateModelList();
75  void UpdateDecalList();
76  void UpdateShield();
77 
78  void UpdateCamera(float deltaTime);
79  void UpdateLights();
80 
81  void ReloadModel();
82  void SetDecals(const std::string &file);
83 
84  void OnModelChanged();
85 
86  void ToggleGuns();
87  void HitIt();
88 
89  void ToggleViewControlMode();
90  void ClearModel();
91  void CreateTestResources();
92  void DrawBackground();
93  void DrawGrid(const matrix4x4f &trans, float radius);
94  void DrawModel(const matrix4x4f &mv);
95 
96  void ResetThrusters();
97  void Screenshot();
98  void SaveModelToBinary();
99 
100  void DrawModelSelector();
101  void DrawModelOptions();
102  void DrawModelTags();
103  void DrawTagNames();
104  void DrawShipControls();
105  void DrawLog();
106  void DrawPiGui();
107 
108 private:
109  //toggleable options
110  struct Options {
111  bool attachGuns;
112  bool showTags;
113  bool showDockingLocators;
114  bool showCollMesh;
115  bool showAabb;
116  bool showShields;
117  bool showGrid;
118  bool showLandingPad;
119  bool showUI;
120  bool wireframe;
121  bool mouselookEnabled;
122  float gridInterval;
123  uint32_t lightPreset;
124  bool orthoView;
125 
126  Options();
127  };
128 
129 private:
130  Input::Manager *m_input;
131  PiGui::Instance *m_pigui;
132 
133  struct Inputs : Input::InputFrame {
134  using InputFrame::InputFrame;
135 
136  Axis *moveForward;
137  Axis *moveLeft;
138  Axis *moveUp;
139  Axis *zoomAxis;
140 
141  Axis *rotateViewLeft;
142  Axis *rotateViewUp;
143 
144  Action *viewTop;
145  Action *viewLeft;
146  Action *viewFront;
147  } m_bindings;
148 
149  vector2f m_windowSize;
150  vector2f m_logWindowSize;
151  vector2f m_animWindowSize;
152  std::vector<std::string> m_log;
153  bool m_resetLogScroll = false;
154 
155  vector3f m_linearThrust = {};
156  vector3f m_angularThrust = {};
157 
158  // Model pattern colors
159  std::vector<Color> m_colors;
160 
161  std::vector<std::string> m_fileNames;
162  std::string m_modelName;
163  std::string m_requestedModelName;
164 
165  std::unique_ptr<SceneGraph::Model> m_model;
166  bool m_modelIsShip = false;
167 
168  SceneGraph::MatrixTransform *m_selectedTag = nullptr;
169 
170  std::vector<SceneGraph::Animation *> m_animations;
171  SceneGraph::Animation *m_currentAnimation = nullptr;
172 
173  bool m_modelSupportsPatterns = false;
174  std::vector<std::string> m_patterns;
175  uint32_t m_currentPattern = 0;
176 
177  bool m_modelSupportsDecals = false;
178  std::vector<std::string> m_decals;
179  uint32_t m_currentDecal = 0;
180 
181  bool m_modelHasShields = false;
182  std::unique_ptr<Shields> m_shields;
183  std::unique_ptr<NavLights> m_navLights;
184  std::unique_ptr<SceneGraph::Model> m_gunModel;
185  std::unique_ptr<SceneGraph::Model> m_scaleModel;
186 
187  bool m_screenshotQueued;
188  bool m_shieldIsHit;
189  float m_shieldHitPan;
190  Graphics::Renderer *m_renderer;
191  Graphics::Texture *m_decalTexture;
192  matrix4x4f m_modelViewMat;
193  vector3f m_viewPos;
194  matrix3x3f m_viewRot;
195  float m_rotX, m_rotY, m_zoom;
196  float m_baseDistance;
197  Random m_rng;
198 
199  Options m_options;
200  float m_landingMinOffset;
201 
202  Graphics::RenderState *m_bgState;
204 
205  sigc::signal<void> onModelChanged;
206 
207  Graphics::Drawables::Lines m_gridLines;
208 };
209 
210 #endif
Definition: Application.h:14
Definition: Drawables.h:79
Definition: RenderState.h:25
Definition: Renderer.h:39
Definition: Texture.h:106
Definition: GuiApplication.h:18
Definition: Input.h:118
Definition: LuaManager.h:9
Definition: ModelViewer.h:23
void Shutdown() override
Definition: ModelViewer.cpp:116
void PreUpdate() override
Definition: ModelViewer.cpp:129
void PostUpdate() override
Definition: ModelViewer.cpp:135
void Startup() override
Definition: ModelViewer.cpp:81
ModelViewerApp()
Definition: ModelViewer.h:25
void SetInitialModel(std::string &modelName)
Definition: ModelViewer.h:29
std::string & GetModelName()
Definition: ModelViewer.h:30
Definition: ModelViewer.h:46
void ChangeCameraPreset(CameraPreset preset)
Definition: ModelViewer.cpp:279
void SetModel(const std::string &modelName)
Definition: ModelViewer.cpp:760
void HandleInput()
Definition: ModelViewer.cpp:600
void SetupAxes()
Definition: ModelViewer.cpp:550
CameraPreset
Definition: ModelViewer.h:48
void End() override
Definition: ModelViewer.cpp:180
void Start() override
Definition: ModelViewer.cpp:174
bool SetRandomColor()
Definition: ModelViewer.cpp:225
void Update(float deltaTime) override
Definition: ModelViewer.cpp:451
ModelViewer(ModelViewerApp *app, LuaManager *l)
Definition: ModelViewer.cpp:141
void ResetCamera()
Definition: ModelViewer.cpp:706
Definition: PiGui.h:84
Definition: Random.h:27
Definition: Animation.h:19
Definition: MatrixTransform.h:24
Definition: Input.h:45
InputBindings::Action Action
Definition: Input.h:47
InputBindings::Axis Axis
Definition: Input.h:46