Pioneer
ModelViewer.h
Go to the documentation of this file.
1 // Copyright © 2008-2022 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 showGeomBBox;
117  bool showShields;
118  bool showGrid;
119  bool showLandingPad;
120  bool showUI;
121  bool wireframe;
122  bool mouselookEnabled;
123  float gridInterval;
124  uint32_t lightPreset;
125  bool orthoView;
126  bool metricsWindow;
127 
128  Options();
129  };
130 
131 private:
132  Input::Manager *m_input;
133  PiGui::Instance *m_pigui;
134 
135  struct Inputs : Input::InputFrame {
136  using InputFrame::InputFrame;
137 
138  Axis *moveForward;
139  Axis *moveLeft;
140  Axis *moveUp;
141  Axis *zoomAxis;
142 
143  Axis *rotateViewLeft;
144  Axis *rotateViewUp;
145 
146  Action *viewTop;
147  Action *viewLeft;
148  Action *viewFront;
149  } m_bindings;
150 
151  vector2f m_windowSize;
152  vector2f m_logWindowSize;
153  vector2f m_animWindowSize;
154  std::vector<std::string> m_log;
155  bool m_resetLogScroll = false;
156 
157  vector3f m_linearThrust = {};
158  vector3f m_angularThrust = {};
159 
160  // Model pattern colors
161  std::vector<Color> m_colors;
162 
163  std::vector<std::string> m_fileNames;
164  std::string m_modelName;
165  std::string m_requestedModelName;
166 
167  std::unique_ptr<SceneGraph::Model> m_model;
168  bool m_modelIsShip = false;
169 
170  SceneGraph::MatrixTransform *m_selectedTag = nullptr;
171 
172  std::vector<SceneGraph::Animation *> m_animations;
173  SceneGraph::Animation *m_currentAnimation = nullptr;
174 
175  bool m_modelSupportsPatterns = false;
176  std::vector<std::string> m_patterns;
177  uint32_t m_currentPattern = 0;
178 
179  bool m_modelSupportsDecals = false;
180  std::vector<std::string> m_decals;
181  uint32_t m_currentDecal = 0;
182 
183  bool m_modelHasShields = false;
184  std::unique_ptr<Shields> m_shields;
185  std::unique_ptr<NavLights> m_navLights;
186  std::unique_ptr<SceneGraph::Model> m_gunModel;
187  std::unique_ptr<SceneGraph::Model> m_scaleModel;
188 
189  bool m_screenshotQueued;
190  bool m_shieldIsHit;
191  float m_shieldHitPan;
192  Graphics::Renderer *m_renderer;
193  Graphics::Texture *m_decalTexture;
194  matrix4x4f m_modelViewMat;
195  vector3f m_viewPos;
196  matrix3x3f m_viewRot;
197  float m_rotX, m_rotY, m_zoom;
198  float m_baseDistance;
199  Random m_rng;
200 
201  Options m_options;
202  float m_landingMinOffset;
203 
204  std::unique_ptr<Graphics::Material> m_bgMaterial;
205  std::unique_ptr<Graphics::Material> m_gridMaterial;
206  std::unique_ptr<Graphics::MeshObject> m_bgMesh;
207 
208  sigc::signal<void> onModelChanged;
209 
210  Graphics::Drawables::Lines m_gridLines;
211 };
212 
213 #endif
Definition: Application.h:20
Definition: Drawables.h:80
Definition: Renderer.h:44
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:124
void PreUpdate() override
Definition: ModelViewer.cpp:139
void PostUpdate() override
Definition: ModelViewer.cpp:145
void Startup() override
Definition: ModelViewer.cpp:86
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:294
void SetModel(const std::string &modelName)
Definition: ModelViewer.cpp:773
void HandleInput()
Definition: ModelViewer.cpp:608
void SetupAxes()
Definition: ModelViewer.cpp:558
CameraPreset
Definition: ModelViewer.h:48
void End() override
Definition: ModelViewer.cpp:196
void Start() override
Definition: ModelViewer.cpp:190
bool SetRandomColor()
Definition: ModelViewer.cpp:240
void Update(float deltaTime) override
Definition: ModelViewer.cpp:460
ModelViewer(ModelViewerApp *app, LuaManager *l)
Definition: ModelViewer.cpp:151
void ResetCamera()
Definition: ModelViewer.cpp:719
Definition: PiGui.h:86
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