TDME2  1.9.200
TerrainEditorTabController.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <memory>
5 #include <string>
6 #include <unordered_map>
7 #include <vector>
8 
9 #include <tdme/tdme.h>
11 #include <tdme/engine/Transform.h>
24 #include <tdme/utilities/Terrain.h>
25 
26 #include <ext/tinyxml/tinyxml.h>
27 
28 using std::array;
29 using std::string;
30 using std::unordered_map;
31 using std::unique_ptr;
32 using std::vector;
33 
53 
57 
58 /**
59  * Terrain editor tab controller
60  * @author Andreas Drewke
61  */
63  : public TabController
64 {
65 
66 private:
67  unique_ptr<BasePropertiesSubController> basePropertiesSubController;
68  TerrainEditorTabView* view { nullptr };
69  GUIScreenNode* screenNode { nullptr };
70  PopUps* popUps { nullptr };
71 
72  vector<unordered_map<int, vector<Transform>>> newFoliageMaps;
73  unordered_set<int> recreateFoliagePartitions;
74 
76  float currentTerrainBrushHeight { 0.0f };
77  float currentTerrainBrushScale { 1.0f };
82  Terrain::BrushOperation currentTerrainBrushOperation { Terrain::BRUSHOPERATION_NONE };
83  Terrain::BrushOperation currentFoliageBrushOperation { Terrain::BRUSHOPERATION_NONE };
84 
85  Terrain::FoliageBrush foliageBrush = {
86  .brushTexture = nullptr,
87  .brushScale = 1.0f,
88  .brushDensity = 1.0f
89  };
90  vector<Terrain::FoliageBrushPrototype> foliageBrushPrototypes;
91 
92  array<string, 2> textureBrushApplyNodes = {
93  "terrainbrush_size",
94  "terrainbrush_strength"
95  };
96 
97  array<string, 2> foliageBrushApplyNodes = {
98  "foliagebrush_size",
99  "foliagebrush_density"
100  };
101 
102  array<string, 16> foliageBrushPrototypeApplyNodes = {
103  "foliagebrush_prototype_object_count",
104  "foliagebrush_prototype_normalalign",
105  "foliagebrush_prototype_rotationrange_x_min",
106  "foliagebrush_prototype_rotationrange_x_max",
107  "foliagebrush_prototype_rotationrange_y_min",
108  "foliagebrush_prototype_rotationrange_y_max",
109  "foliagebrush_prototype_rotationrange_z_min",
110  "foliagebrush_prototype_rotationrange_z_max",
111  "foliagebrush_prototype_scalerange_min",
112  "foliagebrush_prototype_scalerange_max",
113  "foliagebrush_prototype_scalerange_max",
114  "foliagebrush_prototype_heightrange_max",
115  "foliagebrush_prototype_heightrange_min",
116  "foliagebrush_prototype_heightrange_max",
117  "foliagebrush_prototype_sloperange_max",
118  "foliagebrush_prototype_sloperange_max"
119  };
120 
121 public:
122  // forbid class copy
124 
125  /**
126  * Public constructor
127  * @param view view
128  */
130 
131  /**
132  * Destructor
133  */
134  virtual ~TerrainEditorTabController();
135 
136  /**
137  * Get view
138  * @return view
139  */
141  return view;
142  }
143 
144  // overridden method
145  inline GUIScreenNode* getScreenNode() override {
146  return screenNode;
147  }
148 
149  /**
150  * @return current terrain brush operation
151  */
152  inline Terrain::BrushOperation getTerrainBrushOperation() {
154  }
155 
156  /**
157  * @return current foliage brush operation
158  */
159  inline Terrain::BrushOperation getFoliageBrushOperation() {
161  }
162 
163  // overridden methods
164  void initialize(GUIScreenNode* screenNode) override;
165  void dispose() override;
166  void onChange(GUIElementNode* node) override;
167  void onAction(GUIActionListenerType type, GUIElementNode* node) override;
168  void onFocus(GUIElementNode* node) override;
169  void onUnfocus(GUIElementNode* node) override;
170  void onContextMenuRequest(GUIElementNode* node, int mouseX, int mouseY) override;
171  void onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) override;
172  void onTooltipCloseRequest() override;
173  void onCommand(TabControllerCommand command) override;
174  void onDrop(const string& payload, int mouseX, int mouseY) override;
175 
176  /**
177  * Set outliner content
178  */
179  void setOutlinerContent();
180 
181  /**
182  * Set outliner add drop down content
183  */
185 
186  /**
187  * On create terrain
188  */
189  void onCreateTerrain();
190 
191  /**
192  * Set brush scale
193  * @param scale scale
194  */
195  void setBrushScale(float scale);
196 
197  /**
198  * Set brush density/strength
199  * @param densityStrength density/strength
200  */
201  void setBrushDensityStrength(float densityStrength);
202 
203  /**
204  * Set terrain details
205  */
206  void setTerrainDetails();
207 
208  /**
209  * Set terrain brush details
210  */
211  void setTerrainBrushDetails();
212 
213  /**
214  * Update terrain brush details
215  */
217 
218  /**
219  * Apply terrain brush details
220  */
222 
223  /**
224  * Set foliage brush details
225  */
226  void setFoliageBrushDetails();
227 
228  /**
229  * Update foliage brush details
230  */
232 
233  /**
234  * Apply foliage brush details
235  */
237 
238  /**
239  * Set foliage brush details
240  */
242 
243  /**
244  * Apply foliage brush prototype details
245  */
247 
248  /**
249  * Check if outliner selection is foliage brush prototype
250  * @param outlinerNode outliner node
251  * @param foliageBrushIdx foliage brush index
252  * @param foliageBrushPrototypeIdx foliage brush prototype index
253  */
254  bool checkOutlinerFoliageBrushPrototype(const string& outlinerNode, int& foliageBrushIdx, int& foliageBrushPrototypeIdx);
255 
256  /**
257  * Update details
258  * @param outlinerNode outliner node
259  */
260  void updateDetails(const string& outlinerNode);
261 
262  /**
263  * Initialize terrain
264  */
265  void initializeTerrain();
266 
267  /**
268  * Apply current brush to terrain at given brush center position
269  * @param terrainBoundingBox terrain bounding box
270  * @param terrainModels terrain models
271  * @param brushCenterPosition brush center position
272  * @param deltaTime delta time between last frame and this frame
273  */
274  void applyTerrainBrush(BoundingBox& terrainBoundingBox, vector<Model*>& terrainModels, const Vector3& brushCenterPosition, int64_t deltaTime);
275 
276  /**
277  * Determine current brush flatten height
278  * @param terrainBoundingBox terrain bounding box
279  * @param terrainModels terrain models
280  * @param brushCenterPosition brush center position
281  * @return success
282  */
283  bool determineCurrentBrushHeight(BoundingBox& terrainBoundingBox, vector<Model*> terrainModels, const Vector3& brushCenterPosition);
284 
285  /**
286  * Determine ramp height
287  * @param terrainBoundingBox terrain bounding box
288  * @param terrainModels terrain models
289  * @param position position
290  * @param height height
291  * @return success
292  */
293  bool determineRampHeight(BoundingBox& terrainBoundingBox, vector<Model*> terrainModels, const Vector3& position, float& height);
294 
295  /**
296  * Unset current brush flatten height
297  */
299 
300  /**
301  * Apply current brush to terrain at given brush center position
302  * @param terrainBoundingBox terrain bounding box
303  * @param terrainModels terrain models
304  * @param position position
305  * @param rotation rotation
306  * @param scale scale
307  * @param minHeight min height
308  * @param maxHeigth max heigth
309  */
310  void applyRampTerrainBrush(BoundingBox& terrainBoundingBox, vector<Model*>& terrainModels, const Vector3& position, float rotation, const Vector2& scale, float minHeight, float maxHeight);
311 
312  /**
313  * Create water using a auto fill like algorithm
314  * @param terrainBoundingBox terrain bounding box
315  * @param brushCenterPosition brush center position
316  * @param waterModels water models
317  * @param waterReflectionEnvironmentMappingPosition water reflection environment mapping position
318  */
319  void createWater(BoundingBox& terrainBoundingBox, const Vector3& brushCenterPosition, vector<Model*>& waterModels, Vector3& waterReflectionEnvironmentMappingPosition);
320 
321  /**
322  * Delete water models
323  * @param waterPositionMapIdx water position map index
324  */
325  void deleteWater(int waterPositionMapIdx);
326 
327  /**
328  * Set foliage brush
329  */
330  void setFoliageBrush();
331 
332  /**
333  * Update foliage brush
334  * @param foliageBrush foliage brush
335  * @param foliageBrushPrototypes foliage brush prototypes
336  */
337  void updateFoliageBrush();
338 
339  /**
340  * Apply current brush to foliage at given brush center position
341  * @param terrainBoundingBox terrain bounding box
342  * @param brushCenterPosition brush center position
343  * @param deltaTime delta time between last frame and this frame
344  */
345  void applyFoliageBrush(BoundingBox& terrainBoundingBox, const Vector3& brushCenterPosition, int64_t deltaTime);
346 
347  /**
348  * @return UI terrain brush operation
349  */
350  Terrain::BrushOperation getUITerrainBrushOperation();
351 
352  /**
353  * @return UI water operation
354  */
355  Terrain::BrushOperation getUIWaterOperation();
356 
357  /**
358  * @return UI foliage brush operation
359  */
360  Terrain::BrushOperation getUIFoliageBrushOperation();
361 
362  /**
363  * Update info text line
364  * @param text text
365  */
366  void updateInfoText(const MutableString& text);
367 
368  /**
369  * Show the information pop up / modal
370  * @param caption caption
371  * @param message message
372  */
373  void showInfoPopUp(const string& caption, const string& message);
374 
375  /**
376  * Set terrain brush texture
377  * @param fileName file name
378  */
379  void setTerrainBrushTexture(const string& fileName);
380 
381  /**
382  * Set foliage brush texture
383  * @param fileName file name
384  */
385  void setFoliageBrushTexture(const string& fileName);
386 
387  /**
388  * Set foliage brush prototype
389  * @param fileName file name
390  */
391  void setFoliageBrushPrototype(const string& fileName);
392 };
Texture entity.
Definition: Texture.h:24
Transform which contain scale, rotations and translation.
Definition: Transform.h:29
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Definition: BoundingBox.h:26
GUI node base class.
Definition: GUINode.h:64
GUI parent node base class thats supporting child nodes.
Definition: GUIParentNode.h:42
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Pop ups controller accessor class.
Definition: PopUps.h:29
void onContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY) override
On context menu request.
void onDrop(const string &payload, int mouseX, int mouseY) override
On drop.
void updateInfoText(const MutableString &text)
Update info text line.
void applyFoliageBrushPrototypeDetails()
Apply foliage brush prototype details.
void applyTerrainBrush(BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, const Vector3 &brushCenterPosition, int64_t deltaTime)
Apply current brush to terrain at given brush center position.
void setTerrainBrushTexture(const string &fileName)
Set terrain brush texture.
bool determineCurrentBrushHeight(BoundingBox &terrainBoundingBox, vector< Model * > terrainModels, const Vector3 &brushCenterPosition)
Determine current brush flatten height.
vector< unordered_map< int, vector< Transform > > > newFoliageMaps
void onCommand(TabControllerCommand command) override
On command.
void setBrushDensityStrength(float densityStrength)
Set brush density/strength.
bool determineRampHeight(BoundingBox &terrainBoundingBox, vector< Model * > terrainModels, const Vector3 &position, float &height)
Determine ramp height.
bool checkOutlinerFoliageBrushPrototype(const string &outlinerNode, int &foliageBrushIdx, int &foliageBrushPrototypeIdx)
Check if outliner selection is foliage brush prototype.
void setFoliageBrushTexture(const string &fileName)
Set foliage brush texture.
void applyRampTerrainBrush(BoundingBox &terrainBoundingBox, vector< Model * > &terrainModels, const Vector3 &position, float rotation, const Vector2 &scale, float minHeight, float maxHeight)
Apply current brush to terrain at given brush center position.
void showInfoPopUp(const string &caption, const string &message)
Show the information pop up / modal.
void setFoliageBrushPrototype(const string &fileName)
Set foliage brush prototype.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
TerrainEditorTabController(TerrainEditorTabView *view)
Public constructor.
void createWater(BoundingBox &terrainBoundingBox, const Vector3 &brushCenterPosition, vector< Model * > &waterModels, Vector3 &waterReflectionEnvironmentMappingPosition)
Create water using a auto fill like algorithm.
void applyFoliageBrush(BoundingBox &terrainBoundingBox, const Vector3 &brushCenterPosition, int64_t deltaTime)
Apply current brush to foliage at given brush center position.
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
Mutable utf8 aware string class.
Definition: MutableString.h:23
Terrain utility.
Definition: Terrain.h:33
An attribute is a name-value pair.
Definition: tinyxml.h:734
Always the top level node.
Definition: tinyxml.h:1317
The element is a container class.
Definition: tinyxml.h:886
GUI action listener interface.
GUI change listener interface.
GUI focus listener interface.
Tab controller, which connects UI with logic.
Definition: TabController.h:34
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6