worldEditor.h

Engine/source/gui/worldEditor/worldEditor.h

More...

Classes:

Public Typedefs

WorldEditorAlignmentType 
WorldEditorDropType 

Detailed Description

Public Typedefs

typedef WorldEditor::AlignmentType WorldEditorAlignmentType 
typedef WorldEditor::DropType WorldEditorDropType 

Public Functions

DefineEnumType(WorldEditorAlignmentType )

DefineEnumType(WorldEditorDropType )

  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 _WORLDEDITOR_H_
 25#define _WORLDEDITOR_H_
 26
 27#ifndef _EDITTSCTRL_H_
 28#include "gui/worldEditor/editTSCtrl.h"
 29#endif
 30
 31#ifndef _CONSOLETYPES_H_
 32#include "console/consoleTypes.h"
 33#endif
 34
 35#ifndef _GFXTEXTUREHANDLE_H_
 36#include "gfx/gfxTextureHandle.h"
 37#endif
 38
 39#ifndef _TSIGNAL_H_
 40#include "core/util/tSignal.h"
 41#endif
 42
 43#ifndef _CONSOLE_SIMOBJECTMEMENTO_H_
 44#include "console/simObjectMemento.h"
 45#endif
 46
 47#ifndef _UNDO_H_
 48#include "util/undo.h"
 49#endif
 50
 51#ifndef _SIMPATH_H_
 52#include "scene/simPath.h"
 53#endif
 54
 55#ifndef _DYNAMIC_CONSOLETYPES_H_
 56#include "console/dynamicTypes.h"
 57#endif
 58
 59
 60class SceneObject;
 61class WorldEditorSelection;
 62class EditorTool;
 63
 64///
 65class WorldEditor : public EditTSCtrl
 66{
 67      typedef EditTSCtrl Parent;
 68
 69   public:
 70
 71      typedef WorldEditorSelection Selection;
 72
 73      struct Triangle
 74      {
 75         Point3F p0;
 76         Point3F p1;
 77         Point3F p2;
 78      };
 79
 80      void ignoreObjClass(U32 argc, ConsoleValueRef* argv);
 81      void clearIgnoreList();
 82
 83      static bool setObjectsUseBoxCenter( void *object, const char *index, const char *data ) { static_cast<WorldEditor*>(object)->setObjectsUseBoxCenter( dAtob( data ) ); return false; };
 84      void setObjectsUseBoxCenter(bool state);
 85      bool getObjectsUseBoxCenter() { return mObjectsUseBoxCenter; }
 86
 87      void clearSelection();
 88      void selectObject(SimObject *obj);
 89      void selectObject(const char* obj);
 90      void unselectObject(SimObject *obj);      
 91      void unselectObject(const char* obj);
 92      
 93      S32 getSelectionSize();
 94      S32 getSelectObject(S32 index);  
 95      const Point3F& getSelectionCentroid();
 96      const Box3F& getSelectionBounds();
 97      Point3F getSelectionExtent();
 98      F32 getSelectionRadius();
 99      
100      void dropCurrentSelection( bool skipUndo );
101      void copyCurrentSelection();  
102      void cutCurrentSelection();   
103      bool canPasteSelection();
104
105      bool alignByBounds(S32 boundsAxis);
106      bool alignByAxis(S32 axis);
107
108      void transformSelection(bool position, Point3F& p, bool relativePos, bool rotate, EulerF& r, bool relativeRot, bool rotLocal, S32 scaleType, Point3F& s, bool sRelative, bool sLocal);
109
110      void resetSelectedRotation();
111      void resetSelectedScale();
112
113      void addUndoState();
114      void redirectConsole(S32 objID);
115
116      void colladaExportSelection( const String &path );
117
118      void makeSelectionPrefab( const char *filename, bool dontReplaceOriginals = false);
119      void explodeSelectedPrefab();
120
121      bool makeSelectionAMesh(const char *filename);
122
123      //
124      static SceneObject* getClientObj(SceneObject *);
125      static void markAsSelected( SimObject* object, bool state );
126      static void setClientObjInfo(SceneObject *, const MatrixF &, const VectorF &);
127      static void updateClientTransforms(Selection* );
128
129   protected:
130
131      class WorldEditorUndoAction : public UndoAction
132      {
133      public:
134
135         WorldEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName )
136         {
137            mWorldEditor = NULL;
138         }
139
140         WorldEditor *mWorldEditor;
141
142         struct Entry
143         {
144            MatrixF     mMatrix;
145            VectorF     mScale;
146
147            // validation
148            U32         mObjId;
149            U32         mObjNumber;
150         };
151
152         Vector<Entry>  mEntries;
153
154         virtual void undo();
155         virtual void redo() { undo(); }
156      };
157
158      void submitUndo( Selection* sel, const UTF8* label="World Editor Action" );
159
160   public:
161
162      /// The objects currently in the copy buffer.
163      Vector<SimObjectMemento> mCopyBuffer;
164
165      bool cutSelection(Selection* sel);
166      bool copySelection(Selection*  sel);
167      bool pasteSelection(bool dropSel=true);
168      void dropSelection(Selection*  sel);
169      void dropBelowSelection(Selection*  sel, const Point3F & centroid, bool useBottomBounds = false);
170      void dropAtGizmo(Selection*  sel, const Point3F & gizmoPos);
171
172      void terrainSnapSelection(Selection* sel, U8 modifier, Point3F gizmoPos, bool forceStick=false);
173      void softSnapSelection(Selection* sel, U8 modifier, Point3F gizmoPos);
174      
175      Selection* getActiveSelectionSet() const;
176      void makeActiveSelectionSet( Selection* sel );
177
178      void hideObject(SceneObject* obj, bool hide);
179
180      // work off of mSelected
181      void hideSelection(bool hide);
182      void lockSelection(bool lock);
183
184   public:
185      bool objClassIgnored(const SimObject * obj);
186      void renderObjectBox(SceneObject * obj, const ColorI & col);
187      
188   private:
189      SceneObject * getControlObject();
190      bool collide(const Gui3DMouseEvent & event, SceneObject **hitObj );
191
192      // gfx methods
193      //void renderObjectBox(SceneObject * obj, const ColorI & col);
194      void renderObjectFace(SceneObject * obj, const VectorF & normal, const ColorI & col);
195      void renderSelectionWorldBox(Selection*  sel);
196
197      void renderPlane(const Point3F & origin);
198      void renderMousePopupInfo();
199      void renderScreenObj( SceneObject * obj, const Point3F& sPos, const Point3F& wPos );
200
201      void renderPaths(SimObject *obj);
202      void renderSplinePath(SimPath::Path *path);
203
204      // axis gizmo
205      bool        mUsingAxisGizmo;
206
207      GFXStateBlockRef mRenderSelectionBoxSB;
208      GFXStateBlockRef mRenderObjectBoxSB;
209      GFXStateBlockRef mRenderObjectFaceSB;
210      GFXStateBlockRef mSplineSB;
211
212      //
213      bool                       mIsDirty;
214
215      //
216      bool                       mMouseDown;
217      SimObjectPtr< Selection>  mSelected;
218
219      SimObjectPtr< Selection>  mDragSelected;
220      bool                       mDragSelect;
221      RectI                      mDragRect;
222      Point2I                    mDragStart;
223
224      // modes for when dragging a selection
225      enum {
226         Move = 0,
227         Rotate,
228         Scale
229      };
230
231      //
232      //U32                        mCurrentMode;
233      //U32                        mDefaultMode;
234
235      S32                        mRedirectID;
236
237      /// @name Object Icons
238      /// @{
239
240      struct IconObject
241      {         
242         SceneObject *object;
243         F32 dist;         
244         RectI rect;
245         U32 alpha;
246      };
247      
248      Vector< IconObject> mIcons;
249      
250      /// If true, icons fade out with distance to mouse cursor.
251      bool mFadeIcons;
252      
253      /// Distance at which to start fading out icons.
254      F32 mFadeIconsDist;
255      
256      /// @}
257
258      SimObjectPtr<SceneObject>  mHitObject;
259      SimObjectPtr<SceneObject>  mPossibleHitObject;
260      bool                       mMouseDragged;
261      Gui3DMouseEvent            mLastMouseEvent;
262      Gui3DMouseEvent            mLastMouseDownEvent;
263
264      //
265      class ClassInfo
266      {
267         public:
268            ~ClassInfo();
269
270            struct Entry
271            {
272               StringTableEntry  mName;
273               bool              mIgnoreCollision;
274               GFXTexHandle      mDefaultHandle;
275               GFXTexHandle      mSelectHandle;
276               GFXTexHandle      mLockedHandle;
277            };
278
279            Vector<Entry*>       mEntries;
280      };
281
282
283      ClassInfo            mClassInfo;
284      ClassInfo::Entry     mDefaultClassEntry;
285
286      ClassInfo::Entry * getClassEntry(StringTableEntry name);
287      ClassInfo::Entry * getClassEntry(const SimObject * obj);
288      bool addClassEntry(ClassInfo::Entry * entry);
289
290
291      EditorTool* mActiveEditorTool;
292
293   // persist field data
294   public:
295
296      enum DropType
297      {
298         DropAtOrigin = 0,
299         DropAtCamera,
300         DropAtCameraWithRot,
301         DropBelowCamera,
302         DropAtScreenCenter,
303         DropAtCentroid,
304         DropToTerrain,
305         DropBelowSelection,
306         DropAtGizmo
307      };
308
309      // Snapping alignment mode
310      enum AlignmentType
311      {
312         AlignNone = 0,
313         AlignPosX,
314         AlignPosY,
315         AlignPosZ,
316         AlignNegX,
317         AlignNegY,
318         AlignNegZ
319      };
320
321      /// A large hard coded distance used to test 
322      /// object and icon selection.
323      static F32 smProjectDistance;
324
325      S32               mDropType;
326      bool              mBoundingBoxCollision;
327      bool              mObjectMeshCollision;
328      bool              mRenderPopupBackground;
329      ColorI            mPopupBackgroundColor;
330      ColorI            mPopupTextColor;
331      StringTableEntry  mSelectHandle;
332      StringTableEntry  mDefaultHandle;
333      StringTableEntry  mLockedHandle;
334      ColorI            mObjectTextColor;
335      bool              mObjectsUseBoxCenter;
336      ColorI            mObjSelectColor;
337      ColorI            mObjMultiSelectColor;
338      ColorI            mObjMouseOverSelectColor;
339      ColorI            mObjMouseOverColor;
340      bool              mShowMousePopupInfo;
341      ColorI            mDragRectColor;
342      bool              mRenderObjText;
343      bool              mRenderObjHandle;
344      StringTableEntry  mObjTextFormat;
345      ColorI            mFaceSelectColor;
346      bool              mRenderSelectionBox;
347      ColorI            mSelectionBoxColor;
348      bool              mSelectionLocked;
349      bool              mPerformedDragCopy;
350      bool              mDragGridSnapToggle;       ///< Grid snap setting temporarily toggled during drag.
351      bool              mToggleIgnoreList;
352      bool              mNoMouseDrag;
353      bool              mDropAtBounds;
354      F32               mDropBelowCameraOffset;
355      F32               mDropAtScreenCenterScalar;
356      F32               mDropAtScreenCenterMax;
357
358      bool              mGridSnap;
359      bool              mUseGroupCenter;
360      bool              mStickToGround;
361      bool              mStuckToGround;            ///< Selection is stuck to the ground
362      AlignmentType     mTerrainSnapAlignment;     ///< How does the stickied object align to the terrain
363      bool              mTerrainSnapOffsetZ;       ///< Allows the use of an offset to avoid z-fighting with flat objects on a flat terrain.
364      F32               mOffsetZValue;             ///< Value of the Z offset (note: this shouldnt be changed once set)
365
366      bool              mSoftSnap;                 ///< Allow soft snapping all of the time
367      bool              mSoftSnapActivated;        ///< Soft snap has been activated by the user and allowed by the current rules
368      bool              mSoftSnapIsStuck;          ///< Are we snapping?
369      AlignmentType     mSoftSnapAlignment;        ///< How does the snapped object align to the snapped surface
370      bool              mSoftSnapRender;           ///< Render the soft snapping bounds
371      bool              mSoftSnapRenderTriangle;   ///< Render the soft snapped triangle
372      Triangle          mSoftSnapTriangle;         ///< The triangle we are snapping to
373      bool              mSoftSnapSizeByBounds;     ///< Use the selection bounds for the size
374      F32               mSoftSnapSize;             ///< If not the selection bounds, use this size
375      Box3F             mSoftSnapBounds;           ///< The actual bounds used for the soft snap
376      Box3F             mSoftSnapPreBounds;        ///< The bounds prior to any soft snapping (used when rendering the snap bounds)
377      F32               mSoftSnapBackfaceTolerance;   ///< Fraction of mSoftSnapSize for backface polys to have an influence
378
379      bool              mSoftSnapDebugRender;      ///< Activates debug rendering
380      Point3F           mSoftSnapDebugPoint;       ///< The point we're attempting to snap to
381      Triangle          mSoftSnapDebugSnapTri;     ///< The triangle we are snapping to
382      Vector<Triangle>  mSoftSnapDebugTriangles;   ///< The triangles that are considered for snapping
383      
384   protected:
385
386      S32 mCurrentCursor;
387      void setCursor(U32 cursor);
388      void get3DCursor(GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event);
389
390   public:
391
392      WorldEditor();
393      ~WorldEditor();
394
395      void setDirty() { mIsDirty = true; }
396
397      // SimObject
398      virtual bool onAdd();
399      virtual void onEditorEnable();
400
401      // EditTSCtrl
402      void on3DMouseMove(const Gui3DMouseEvent & event);
403      void on3DMouseDown(const Gui3DMouseEvent & event);
404      void on3DMouseUp(const Gui3DMouseEvent & event);
405      void on3DMouseDragged(const Gui3DMouseEvent & event);
406      void on3DMouseEnter(const Gui3DMouseEvent & event);
407      void on3DMouseLeave(const Gui3DMouseEvent & event);
408      void on3DRightMouseDown(const Gui3DMouseEvent & event);
409      void on3DRightMouseUp(const Gui3DMouseEvent & event);
410
411      void updateGuiInfo();
412
413      //
414      void renderScene(const RectI & updateRect);
415
416      static void initPersistFields();
417
418      DECLARE_CONOBJECT(WorldEditor);
419
420     static Signal<void(WorldEditor*)> smRenderSceneSignal;
421
422      void setEditorTool(EditorTool*);
423      EditorTool* getActiveEditorTool() { return mActiveEditorTool; }
424};
425
426typedef WorldEditor::DropType WorldEditorDropType;
427typedef WorldEditor::AlignmentType WorldEditorAlignmentType;
428
429DefineEnumType( WorldEditorDropType );
430DefineEnumType( WorldEditorAlignmentType );
431
432#endif // _WORLDEDITOR_H_
433
434