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