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  bool metricsWindow;
126 
127  Options();
128  };
129 
130 private:
131  Input::Manager *m_input;
132  PiGui::Instance *m_pigui;
133 
134  struct Inputs : Input::InputFrame {
135  using InputFrame::InputFrame;
136 
137  Axis *moveForward;
138  Axis *moveLeft;
139  Axis *moveUp;
140  Axis *zoomAxis;
141 
142  Axis *rotateViewLeft;
143  Axis *rotateViewUp;
144 
145  Action *viewTop;
146  Action *viewLeft;
147  Action *viewFront;
148  } m_bindings;
149 
150  vector2f m_windowSize;
151  vector2f m_logWindowSize;
152  vector2f m_animWindowSize;
153  std::vector<std::string> m_log;
154  bool m_resetLogScroll = false;
155 
156  vector3f m_linearThrust = {};
157  vector3f m_angularThrust = {};
158 
159  // Model pattern colors
160  std::vector<Color> m_colors;
161 
162  std::vector<std::string> m_fileNames;
163  std::string m_modelName;
164  std::string m_requestedModelName;
165 
166  std::unique_ptr<SceneGraph::Model> m_model;
167  bool m_modelIsShip = false;
168 
169  SceneGraph::MatrixTransform *m_selectedTag = nullptr;
170 
171  std::vector<SceneGraph::Animation *> m_animations;
172  SceneGraph::Animation *m_currentAnimation = nullptr;
173 
174  bool m_modelSupportsPatterns = false;
175  std::vector<std::string> m_patterns;
176  uint32_t m_currentPattern = 0;
177 
178  bool m_modelSupportsDecals = false;
179  std::vector<std::string> m_decals;
180  uint32_t m_currentDecal = 0;
181 
182  bool m_modelHasShields = false;
183  std::unique_ptr<Shields> m_shields;
184  std::unique_ptr<NavLights> m_navLights;
185  std::unique_ptr<SceneGraph::Model> m_gunModel;
186  std::unique_ptr<SceneGraph::Model> m_scaleModel;
187 
188  bool m_screenshotQueued;
189  bool m_shieldIsHit;
190  float m_shieldHitPan;
191  Graphics::Renderer *m_renderer;
192  Graphics::Texture *m_decalTexture;
193  matrix4x4f m_modelViewMat;
194  vector3f m_viewPos;
195  matrix3x3f m_viewRot;
196  float m_rotX, m_rotY, m_zoom;
197  float m_baseDistance;
198  Random m_rng;
199 
200  Options m_options;
201  float m_landingMinOffset;
202 
203  Graphics::RenderState *m_bgState;
205 
206  sigc::signal<void> onModelChanged;
207 
208  Graphics::Drawables::Lines m_gridLines;
209 };
210 
211 #endif
Definition: Application.h:15
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:120
void PreUpdate() override
Definition: ModelViewer.cpp:133
void PostUpdate() override
Definition: ModelViewer.cpp:139
void Startup() override
Definition: ModelViewer.cpp:82
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:284
void SetModel(const std::string &modelName)
Definition: ModelViewer.cpp:770
void HandleInput()
Definition: ModelViewer.cpp:606
void SetupAxes()
Definition: ModelViewer.cpp:556
CameraPreset
Definition: ModelViewer.h:48
void End() override
Definition: ModelViewer.cpp:184
void Start() override
Definition: ModelViewer.cpp:178
bool SetRandomColor()
Definition: ModelViewer.cpp:230
void Update(float deltaTime) override
Definition: ModelViewer.cpp:457
ModelViewer(ModelViewerApp *app, LuaManager *l)
Definition: ModelViewer.cpp:145
void ResetCamera()
Definition: ModelViewer.cpp:716
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