Torque3D Documentation / _generateds / terrainActions.h

terrainActions.h

Engine/source/gui/worldEditor/terrainActions.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _TERRAINACTIONS_H_
 25#define _TERRAINACTIONS_H_
 26
 27#ifndef _TERRAINEDITOR_H_
 28#include "gui/worldEditor/terrainEditor.h"
 29#endif
 30#ifndef _GUIFILTERCTRL_H_
 31#include "gui/editor/guiFilterCtrl.h"
 32#endif
 33#ifndef _UNDO_H_
 34#include "util/undo.h"
 35#endif
 36#ifndef _NOISE2D_H_
 37#include "util/noise2d.h"
 38#endif
 39
 40class TerrainAction
 41{
 42   protected:
 43      TerrainEditor *         mTerrainEditor;
 44
 45   public:
 46
 47      virtual ~TerrainAction(){};
 48      TerrainAction(TerrainEditor * editor) : mTerrainEditor(editor){}
 49
 50      virtual StringTableEntry getName() = 0;
 51
 52      enum Type {
 53         Begin = 0,
 54         Update,
 55         End,
 56         Process
 57      };
 58
 59      //
 60      virtual void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type) = 0;
 61      virtual bool useMouseBrush() { return(true); }
 62};
 63
 64//------------------------------------------------------------------------------
 65
 66class SelectAction : public TerrainAction
 67{
 68   public:
 69      SelectAction(TerrainEditor * editor) : TerrainAction(editor){};
 70      StringTableEntry getName(){return("select");}
 71
 72      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
 73};
 74
 75class DeselectAction : public TerrainAction
 76{
 77   public:
 78      DeselectAction(TerrainEditor * editor) : TerrainAction(editor){};
 79      StringTableEntry getName(){return("deselect");}
 80
 81      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
 82};
 83
 84class ClearAction : public TerrainAction
 85{
 86   public:
 87      ClearAction(TerrainEditor * editor) : TerrainAction(editor){};
 88      StringTableEntry getName(){return("clear");}
 89
 90      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type) {};
 91      bool useMouseBrush() { mTerrainEditor->getCurrentSel()->reset(); return true; }
 92};
 93
 94
 95class SoftSelectAction : public TerrainAction
 96{
 97   public:
 98      SoftSelectAction(TerrainEditor * editor) : TerrainAction(editor){};
 99      StringTableEntry getName(){return("softSelect");}
100
101      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
102
103      Filter   mFilter;
104};
105
106//------------------------------------------------------------------------------
107
108class OutlineSelectAction : public TerrainAction
109{
110   public:
111      OutlineSelectAction(TerrainEditor * editor) : TerrainAction(editor){};
112      StringTableEntry getName(){return("outlineSelect");}
113
114      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
115      bool useMouseBrush() { return(false); }
116
117   private:
118
119      Gui3DMouseEvent   mLastEvent;
120};
121
122//------------------------------------------------------------------------------
123
124class PaintMaterialAction : public TerrainAction
125{
126   public:
127      PaintMaterialAction(TerrainEditor * editor) : TerrainAction(editor){}
128      StringTableEntry getName(){return("paintMaterial");}
129
130      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
131};
132
133//------------------------------------------------------------------------------
134
135class ClearMaterialsAction : public TerrainAction
136{
137public:
138   ClearMaterialsAction(TerrainEditor * editor) : TerrainAction(editor){}
139   StringTableEntry getName(){return("clearMaterials");}
140
141   void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
142};
143
144//------------------------------------------------------------------------------
145
146class RaiseHeightAction : public TerrainAction
147{
148   public:
149      RaiseHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
150      StringTableEntry getName(){return("raiseHeight");}
151
152      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
153};
154
155//------------------------------------------------------------------------------
156
157class LowerHeightAction : public TerrainAction
158{
159   public:
160      LowerHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
161      StringTableEntry getName(){return("lowerHeight");}
162
163      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
164};
165
166//------------------------------------------------------------------------------
167
168class SetHeightAction : public TerrainAction
169{
170   public:
171      SetHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
172      StringTableEntry getName(){return("setHeight");}
173
174      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
175};
176
177//------------------------------------------------------------------------------
178
179class SetEmptyAction : public TerrainAction
180{
181   public:
182      SetEmptyAction(TerrainEditor * editor) : TerrainAction(editor){}
183      StringTableEntry getName(){return("setEmpty");}
184
185      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
186};
187
188//------------------------------------------------------------------------------
189
190class ClearEmptyAction : public TerrainAction
191{
192   public:
193      ClearEmptyAction(TerrainEditor * editor) : TerrainAction(editor){}
194      StringTableEntry getName(){return("clearEmpty");}
195
196      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
197};
198
199//------------------------------------------------------------------------------
200
201class ScaleHeightAction : public TerrainAction
202{
203   public:
204      ScaleHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
205      StringTableEntry getName(){return("scaleHeight");}
206
207      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
208};
209
210//------------------------------------------------------------------------------
211
212class BrushAdjustHeightAction : public TerrainAction
213{
214   public:
215      BrushAdjustHeightAction(TerrainEditor* editor) : TerrainAction(editor) { mPreviousZ = 0.0f; }
216      StringTableEntry getName(){return("brushAdjustHeight");}
217
218      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
219
220   private:
221      PlaneF mIntersectionPlane;
222      Point3F mTerrainUpVector;
223      F32 mPreviousZ;
224};
225
226class AdjustHeightAction : public BrushAdjustHeightAction
227{
228   public:
229      AdjustHeightAction(TerrainEditor * editor);
230      StringTableEntry getName(){return("adjustHeight");}
231
232      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
233      bool useMouseBrush() { return(false); }
234
235   private:
236      //
237      Point3F                    mHitPos;
238      Point3F                    mLastPos;
239      SimObjectPtr<GuiCursor>    mCursor;
240};
241
242//------------------------------------------------------------------------------
243
244class FlattenHeightAction : public TerrainAction
245{
246   public:
247      FlattenHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
248      StringTableEntry getName(){return("flattenHeight");}
249
250      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
251};
252
253class SmoothHeightAction : public TerrainAction
254{
255   public:
256      SmoothHeightAction(TerrainEditor * editor) : TerrainAction(editor){}
257      StringTableEntry getName(){return("smoothHeight");}
258
259      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
260};
261
262class SmoothSlopeAction : public TerrainAction  
263{  
264   public:  
265      SmoothSlopeAction(TerrainEditor * editor) : TerrainAction(editor){}  
266      StringTableEntry getName(){return("smoothSlope");}  
267  
268      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);  
269};  
270
271class PaintNoiseAction : public TerrainAction
272{
273   public:
274
275      PaintNoiseAction( TerrainEditor *editor ) 
276         :  TerrainAction( editor ),
277            mNoiseSize( 256 )
278      {
279         mNoise.setSeed( 5342219 );
280         mNoiseData.setSize( mNoiseSize * mNoiseSize );
281         mNoise.fBm( &mNoiseData, mNoiseSize, 12, 1.0f, 5.0f );
282         //Vector<F32> scratch = mNoiseData;
283         //mNoise.rigidMultiFractal( &mNoiseData, &scratch, TerrainBlock::BlockSize, 12, 1.0f, 5.0f );
284         mNoise.getMinMax( &mNoiseData, &mMinMaxNoise.x, &mMinMaxNoise.y, mNoiseSize );
285       
286         mScale = 1.5f / ( mMinMaxNoise.x - mMinMaxNoise.y);
287      }
288      
289      StringTableEntry getName() { return "paintNoise"; }
290
291      void process( Selection *sel, const Gui3DMouseEvent &event, bool selChanged, Type type );
292
293   protected:
294
295      const U32 mNoiseSize;
296
297      Noise2D mNoise;
298
299      Vector<F32> mNoiseData;
300
301      Point2F mMinMaxNoise;
302
303      F32 mScale;
304};
305
306/*
307class ThermalErosionAction : public TerrainAction
308{
309   public:
310      ThermalErosionAction(TerrainEditor * editor) 
311      : TerrainAction(editor)
312      {
313         mNoise.setSeed( 1 );//Sim::getCurrentTime() );
314         mNoiseData.setSize( TerrainBlock::BlockSize * TerrainBlock::BlockSize );
315         mTerrainHeights.setSize( TerrainBlock::BlockSize * TerrainBlock::BlockSize );
316      }
317      
318      StringTableEntry getName(){return("thermalErode");}
319
320      void process(Selection * sel, const Gui3DMouseEvent & event, bool selChanged, Type type);
321
322      Noise2D mNoise;
323      Vector<F32> mNoiseData;
324      Vector<F32> mTerrainHeights;
325};
326*/
327
328/// An undo action used to perform terrain wide smoothing.
329class TerrainSmoothAction : public UndoAction
330{
331   typedef UndoAction Parent;
332
333protected:
334
335   SimObjectId mTerrainId;
336
337   U32 mSteps;
338
339   F32 mFactor;
340
341   Vector<U16> mUnsmoothedHeights;
342
343public:
344
345   TerrainSmoothAction();
346
347   // SimObject
348   DECLARE_CONOBJECT( TerrainSmoothAction );
349   static void initPersistFields();
350
351   // UndoAction
352   virtual void undo();
353   virtual void redo();
354
355   /// Performs the initial smoothing and stores
356   /// the heighfield state for later undo.
357   void smooth( TerrainBlock *terrain, F32 factor, U32 steps );
358};
359
360
361#endif // _TERRAINACTIONS_H_
362