TDME2  1.9.200
SceneEditorTabView.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <unordered_map>
6 #include <unordered_set>
7 #include <vector>
8 
9 #include <tdme/tdme.h>
10 #include <tdme/engine/fwd-tdme.h>
24 
25 using std::string;
26 using std::unique_ptr;
27 using std::unordered_map;
28 using std::unordered_set;
29 using std::vector;
30 
48 
49 /**
50  * Scene editor tab view
51  * @author Andreas Drewke
52  */
54 {
55 private:
56  /**
57  * Entity color
58  */
59  struct EntityColor {
60  float colorMulR;
61  float colorMulG;
62  float colorMulB;
63  float colorAddR;
64  float colorAddG;
65  float colorAddB;
66 
67  /**
68  * Public constructor
69  */
70  inline EntityColor() {
71  this->colorMulR = 1.0f;
72  this->colorMulG = 1.0f;
73  this->colorMulB = 1.0f;
74  this->colorAddR = 0.0f;
75  this->colorAddG = 0.0f;
76  this->colorAddB = 0.0f;
77  }
78 
79  /**
80  * Public constructor
81  * @param sceneEditorView scene editor view
82  * @param colorMulR colorMulR
83  * @param colorMulG colorMulG
84  * @param colorMulB colorMulB
85  * @param colorAddR colorAddR
86  * @param colorAddG colorAddG
87  * @param colorAddB colorAddB
88  */
89  inline EntityColor(float colorMulR, float colorMulG, float colorMulB, float colorAddR, float colorAddG, float colorAddB) {
90  this->colorMulR = colorMulR;
91  this->colorMulG = colorMulG;
92  this->colorMulB = colorMulB;
93  this->colorAddR = colorAddR;
94  this->colorAddG = colorAddG;
95  this->colorAddB = colorAddB;
96  }
97  };
98 
99  static constexpr int MOUSE_DOWN_LAST_POSITION_NONE { -1 };
100 
101  unique_ptr<Engine> engine;
102  unique_ptr<CameraInputHandler> cameraInputHandler;
103  EditorView* editorView { nullptr };
104  string tabId;
105  PopUps* popUps { nullptr };
106  unique_ptr<SceneEditorTabController> sceneEditorTabController;
108  unique_ptr<Scene> scene;
109 
110  STATIC_DLL_IMPEXT static vector<string> ENTITYCOLOR_NAMES;
111  unordered_map<string, EntityColor> entityColors;
112 
114  bool keyShift;
115  bool keyEscape;
116 
118 
126 
127  bool pasteMode;
129 
131  vector<string> selectedEntityIds;
132  unordered_set<string> selectedEntityIdsById;
133  vector<SceneEntity*> copiedEntities;
134  unique_ptr<EntityPickingFilter> entityPickingFilterNoGrid;
135  unique_ptr<EntityPickingFilter> entityPickingFilterPlacing;
136  bool needsGizmoUpdate { false };
137 
141 
142  float snappingX;
143  float snappingZ;
145 
147  float gridY;
148  unique_ptr<Model> gridModel;
149 
150  unique_ptr<ApplicationClient> applicationClient;
151 
152 public:
153  // forbid class copy
155 
156  /**
157  * Public constructor
158  * @param editorView editor view
159  * @param tabId tab id
160  * @param scene scene
161  */
163 
164  /**
165  * Destructor
166  */
167  virtual ~SceneEditorTabView();
168 
169  /**
170  * @return editor view
171  */
173  return editorView;
174  }
175 
176  /**
177  * @return pop up views
178  */
179  inline PopUps* getPopUps() {
180  return popUps;
181  }
182 
183  /**
184  * @return scene
185  */
186  inline Scene* getScene() {
187  return scene.get();
188  }
189 
190  // overridden methods
191  void handleInputEvents() override;
192  void display() override;
193  inline const string& getTabId() override {
194  return tabId;
195  }
196  void initialize() override;
197  void dispose() override;
198  void activate() override;
199  void deactivate() override;
200  Engine* getEngine() override;
201  inline TabController* getTabController() override {
202  return sceneEditorTabController.get();
203  }
204  void reloadOutliner() override;
205  void onCameraTranslation() override;
206  void onCameraRotation() override;
207  void onCameraScale() override;
208  inline bool hasFixedSize() override{ return false; };
209  void updateRendering() override;
210 
211  /**
212  * Apply sky shader parameters
213  */
215 
216  /**
217  * Apply post processing shader parameters
218  */
220 
221  /**
222  * Clear scene
223  */
224  void clearScene();
225 
226  /**
227  * Reload scene
228  */
229  void reloadScene();
230 
231  /**
232  * Reload outliner
233  * @param outlinerNode selected outliner node
234  */
235  void reloadOutliner(const string& outlinerNode);
236 
237  /**
238  * Update lights
239  */
240  void updateLights();
241 
242  /**
243  * Select entity
244  * @param object object
245  */
246  void selectEntityInternal(Entity* object);
247 
248  /**
249  * Unselect entity
250  * @param object object
251  */
252  void unselectEntityInternal(Entity* object);
253 
254  /**
255  * Reset scale to scene editor object scale
256  * @param object object
257  */
258  void resetEntity(Entity* object);
259 
260  /**
261  * Select entities
262  * @param entityIds entity ids
263  */
264  void selectEntities(const vector<string>& entityIds);
265 
266  /**
267  * Unselect entities
268  */
269  void unselectEntities();
270 
271  /**
272  * Copy current selected entities
273  */
274  void copyEntities();
275 
276  /**
277  * Initialize place entity mode
278  * @param prototype prototype
279  */
280  void setPlaceEntityMode(Prototype* prototype);
281 
282  /**
283  * Finish place entity mode
284  * @param cancelled cancelled place entity mode?
285  */
286  void unsetPlaceEntityMode(bool cancelled);
287 
288  /**
289  * Places selected entity on selected object
290  */
291  void placeEntity();
292 
293  /**
294  * Place entity
295  * @param prototype prototype
296  * @param mouseX mouse X
297  * @param mouseY mouse Y
298  */
299  bool placeEntity(Prototype* prototype, int mouseX, int mouseY);
300 
301  /**
302  * Removes selected entities
303  */
304  void removeEntities();
305 
306  /**
307  * Set paste mode
308  */
309  void setPasteMode();
310 
311  /**
312  * cancel paste
313  */
314  void unsetPasteMode();
315 
316  /**
317  * Paste entities
318  * @param displayOnly display only
319  */
320  void pasteEntities(bool displayOnly);
321 
322  /**
323  * Compute multiple selection pivot
324  */
326 
327  /**
328  * Get selected reflection environment mapping id
329  */
331 
332  /**
333  * Center entities
334  */
335  void centerEntities();
336 
337  /**
338  * Select same entities
339  */
340  void selectSameEntities();
341 
342  /**
343  * Open prototype
344  */
345  void openPrototype();
346 
347  /**
348  * Update gizmo
349  */
350  void updateGizmo();
351 
352  /**
353  * Apply base information
354  * @param name name
355  * @param description description
356  * @return success
357  */
358  bool applyBase(const string& name, const string& description);
359 
360  /**
361  * Apply translation
362  * @param translation translation
363  */
364  void applyTranslation(const Vector3& translation);
365 
366  /**
367  * Apply rotation
368  * @param rotation rotation
369  */
370  void applyRotation(const Vector3& rotation);
371 
372  /**
373  * Apply scale
374  * @param rotation rotation
375  */
376  void applyScale(const Vector3& scale);
377 
378  /**
379  * Apply reflection environment mapping id
380  * @param environmentMappingId environment mapping id
381  */
382  void applyReflectionEnvironmentMappingId(const string& reflectionEnvironmentMappingId);
383 
384  /**
385  * Update grid
386  */
387  void updateGrid();
388 
389  /**
390  * Remove grid
391  */
392  void removeGrid();
393 
394  /**
395  * @return grid enabled
396  */
397  bool isGridEnabled();
398 
399  /**
400  * @param gridEnabled grid enabled
401  */
402  void setGridEnabled(bool gridEnabled);
403 
404  /**
405  * @return grid y
406  */
407  float getGridY();
408 
409  /**
410  * Set grid y position
411  * @param gridY grid y
412  */
413  void setGridY(float gridY);
414 
415  /**
416  * Get snapping
417  * @param snappingEnabled snapping enabled
418  * @param snappingX snapping along X axis
419  * @param snappingZ snapping along Z axis
420  */
421  void getSnapping(bool& snappingEnabled, float& snappingX, float& snappingZ);
422 
423  /**
424  * Set snapping
425  * @param snappingEnabled snapping enabled
426  * @param snappingX snapping along X axis
427  * @param snappingZ snapping along Z axis
428  */
429  void setSnapping(bool snappingEnabled, float snappingX, float snappingZ);
430 
431  /**
432  * Add prototype to scene
433  * @param prototype prototype
434  */
435  void addPrototype(Prototype* prototype);
436 
437  /**
438  * Create engine entity
439  * @param prototype prototype
440  * @param id id
441  * @param transform transform
442  * @param instances instances which applies only for skinned objects
443  * @return entity
444  */
445  static Entity* createEntity(Prototype* prototype, const string& id, const Transform& transform, int instances = 1);
446 
447  /**
448  * Create engine entity
449  * @param sceneEntity scene object
450  * @param translation translation
451  * @param instances instances which applies only for skinned objects
452  * @return entity
453  */
454  static Entity* createEntity(SceneEntity* sceneEntity, const Vector3& translation = Vector3(0.0f, 0.0f, 0.0f), int instances = 1);
455 
456  /**
457  * Run scene
458  */
459  void runScene();
460 
461  /**
462  * Stop scene
463  */
464  void stopScene();
465 
466  /**
467  * Stop/Shutdown scene, to be used when closing tab
468  */
469  void shutdownScene();
470 
471 };
Engine main class.
Definition: Engine.h:131
Engine entity.
Definition: Entity.h:30
Frame buffer class.
Definition: FrameBuffer.h:22
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Representation of a 3D model.
Definition: Model.h:35
Prototype definition.
Definition: Prototype.h:55
Scene entity definition.
Definition: SceneEntity.h:23
Scene definition.
Definition: Scene.h:50
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Gizmo tool for views.
Definition: Gizmo.h:31
Pop ups controller accessor class.
Definition: PopUps.h:29
void applyTranslation(const Vector3 &translation)
Apply translation.
void unselectEntityInternal(Entity *object)
Unselect entity.
SceneEditorTabView(EditorView *editorView, const string &tabId, Scene *scene)
Public constructor.
void pasteEntities(bool displayOnly)
Paste entities.
void placeEntity()
Places selected entity on selected object.
bool hasFixedSize() override
If this viewport framebuffer has a fixed size.
void onCameraRotation() override
On rotation event to be overloaded.
const Vector3 computeMultipleSelectionPivot()
Compute multiple selection pivot.
unordered_map< string, EntityColor > entityColors
unique_ptr< EntityPickingFilter > entityPickingFilterNoGrid
bool applyBase(const string &name, const string &description)
Apply base information.
void setSnapping(bool snappingEnabled, float snappingX, float snappingZ)
Set snapping.
const string getSelectedReflectionEnvironmentMappingId()
Get selected reflection environment mapping id.
void resetEntity(Entity *object)
Reset scale to scene editor object scale.
void handleInputEvents() override
Handle input events that have not yet been processed.
void setGridY(float gridY)
Set grid y position.
void onCameraTranslation() override
On translation event to be overloaded.
static STATIC_DLL_IMPEXT vector< string > ENTITYCOLOR_NAMES
void selectEntities(const vector< string > &entityIds)
Select entities.
void getSnapping(bool &snappingEnabled, float &snappingX, float &snappingZ)
Get snapping.
void unsetPlaceEntityMode(bool cancelled)
Finish place entity mode.
unique_ptr< CameraInputHandler > cameraInputHandler
void shutdownScene()
Stop/Shutdown scene, to be used when closing tab.
void applyPostProcessingShaderParameters()
Apply post processing shader parameters.
void applyScale(const Vector3 &scale)
Apply scale.
void setPlaceEntityMode(Prototype *prototype)
Initialize place entity mode.
static Entity * createEntity(Prototype *prototype, const string &id, const Transform &transform, int instances=1)
Create engine entity.
void copyEntities()
Copy current selected entities.
void applySkyShaderParameters()
Apply sky shader parameters.
void addPrototype(Prototype *prototype)
Add prototype to scene.
void applyReflectionEnvironmentMappingId(const string &reflectionEnvironmentMappingId)
Apply reflection environment mapping id.
void selectEntityInternal(Entity *object)
Select entity.
unique_ptr< EntityPickingFilter > entityPickingFilterPlacing
unique_ptr< SceneEditorTabController > sceneEditorTabController
void onCameraScale() override
On scale event to be overloaded.
void applyRotation(const Vector3 &rotation)
Apply rotation.
Tab controller, which connects UI with logic.
Definition: TabController.h:34
EntityColor(float colorMulR, float colorMulG, float colorMulB, float colorAddR, float colorAddG, float colorAddB)
Public constructor.
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6