Torque3D Documentation / _generateds / guiConvexShapeEditorCtrl.h

guiConvexShapeEditorCtrl.h

Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.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 _GUICONVEXSHAPEEDITORCTRL_H_
 25#define _GUICONVEXSHAPEEDITORCTRL_H_
 26
 27#ifndef _EDITTSCTRL_H_
 28#include "gui/worldEditor/editTSCtrl.h"
 29#endif
 30#ifndef _UNDO_H_
 31#include "util/undo.h"
 32#endif
 33#ifndef _GIZMO_H_
 34#include "gui/worldEditor/gizmo.h"
 35#endif
 36#ifndef _CONVEXSHAPE_H_
 37#include "T3D/convexShape.h"
 38#endif
 39
 40class GameBase;
 41class GuiConvexEditorUndoAction;
 42class ConvexEditorTool;
 43class ConvexEditorCreateTool;
 44
 45class GuiConvexEditorCtrl : public EditTSCtrl
 46{
 47   typedef EditTSCtrl Parent;
 48
 49   friend class GuiConvexEditorUndoAction;   
 50
 51public:   
 52
 53   GuiConvexEditorCtrl();
 54   virtual ~GuiConvexEditorCtrl();
 55
 56   DECLARE_CONOBJECT( GuiConvexEditorCtrl );
 57
 58   // SimObject
 59   virtual bool onAdd();
 60   virtual void onRemove();
 61   static void initPersistFields();
 62
 63   // GuiControl
 64   virtual bool onWake();
 65   virtual void onSleep();
 66   virtual void setVisible(bool value);
 67
 68   // EditTSCtrl      
 69   bool onKeyDown( const GuiEvent &event );
 70   bool onKeyUp( const GuiEvent &event );
 71   void get3DCursor( GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event_ );
 72   void on3DMouseDown( const Gui3DMouseEvent &event );
 73   void on3DMouseUp( const Gui3DMouseEvent &event );
 74   void on3DMouseMove( const Gui3DMouseEvent &event );
 75   void on3DMouseDragged( const Gui3DMouseEvent &event );
 76   void on3DMouseEnter( const Gui3DMouseEvent &event );
 77   void on3DMouseLeave( const Gui3DMouseEvent &event );
 78   void on3DRightMouseDown( const Gui3DMouseEvent &event );
 79   void on3DRightMouseUp( const Gui3DMouseEvent &event );
 80   void renderScene(const RectI & updateRect);   
 81   void updateGizmo();
 82
 83   void updateShape( ConvexShape *shape, S32 offsetFace = -1 );
 84   static void synchClientObject( const ConvexShape *serverConvex );
 85
 86   void updateGizmoPos();
 87
 88   bool setActiveTool( ConvexEditorTool *tool );
 89
 90   void drawFacePlane( ConvexShape *shape, S32 faceId );
 91
 92   void scaleFace( ConvexShape *shape, S32 faceId, Point3F scale );
 93
 94   void translateFace( ConvexShape *shape, S32 faceId, const Point3F &displace );
 95
 96   void updateModifiedFace( ConvexShape *shape, S32 faceId );
 97
 98   bool isShapeValid( ConvexShape *shape );
 99
100   void setupShape( ConvexShape *shape );
101
102   void setPivotPos( ConvexShape *shape, S32 faceId, const Gui3DMouseEvent &event );
103
104   void cleanMatrix( MatrixF &mat );
105
106   S32 getEdgeByPoints( ConvexShape *shape, S32 faceId, S32 pId0, S32 pId1 );
107
108   bool getEdgesTouchingPoint( ConvexShape *shape, S32 faceId, S32 pId, Vector< U32> &edgeIdxList, S32 excludeEdge = -1 );
109
110   void hollowSelection();
111   void hollowShape( ConvexShape *shape, F32 thickness );   
112
113   void recenterSelection();
114   void recenterShape( ConvexShape *shape );
115   void dropSelectionAtScreenCenter();
116   void splitSelectedFace();
117
118   SceneObject* createPolyhedralObject(const char* className, SceneObject* geometryProvider);
119   ConvexShape* createConvexShapeFrom(SceneObject* polyObject);
120   Point2F getSelectedFaceUVOffset();
121   Point2F getSelectedFaceUVScale();
122   const char* getSelectedFaceMaterial();
123   bool getSelectedFaceHorzFlip();
124   bool getSelectedFaceVertFlip();
125   float getSelectedFaceZRot();
126
127   void setSelectedFaceUVOffset(Point2F offset);
128   void setSelectedFaceUVScale(Point2F offset);
129   void setSelectedFaceMaterial(const char* materialName);
130   void setSelectedFaceHorzFlip(bool flipped);
131   void setSelectedFaceVertFlip(bool flipped);
132   void setSelectedFaceZRot(float degrees);
133   void toggleGridSnapping();
134   void setGridSnapSize(float gridSize);
135
136   void updateShape();
137
138   float getGridSnapSize() { return mGridPlaneSize; }
139   /// Interface with Tools.
140   /// @{ 
141
142      MatrixF getCameraMat() const { return mLastCameraQuery.cameraMatrix; }
143
144      enum UndoType
145      {
146         ModifyShape = 0,
147         CreateShape,
148         DeleteShape,
149         HollowShape
150      };
151
152      void submitUndo( UndoType type, ConvexShape *shape );   
153      void submitUndo( UndoType type, const Vector< ConvexShape*> &shape );
154
155   /// @}
156
157   bool hasSelection() const;
158   void clearSelection();
159   void setSelection( ConvexShape *shape, S32 faceId );
160   void handleDeselect();
161   bool handleEscape();
162   bool handleDelete();   
163   bool handleTab();
164public:
165
166   StringTableEntry mMaterialName;
167protected:
168
169   void _prepRenderImage( SceneManager* sceneGraph, const SceneRenderState* sceneState );
170   void _renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *matInst );
171
172   bool _cursorCast( const Gui3DMouseEvent &event, ConvexShape **hitShape, S32 *hitFace );
173   static bool _cursorCastCallback( RayInfo* ri );
174
175protected:
176
177   bool mIsDirty;
178
179   U32 mSavedGizmoFlags;
180
181   Vector<SimObjectPtr<ConvexShape>> mSelectedBrushes;
182   struct selectedFace
183   {
184      SimObjectPtr<ConvexShape> mOwnerBrush;
185      U32 faceId;
186   };
187   Vector<selectedFace> mSelectedFaces;
188
189   struct selectedVert
190   {
191      SimObjectPtr<ConvexShape> mOwnerBrush;
192      U32 vertId;
193   };
194   Vector<selectedVert>  mSelectedVerts;
195   /// The selected ConvexShape.
196   SimObjectPtr<ConvexShape> mConvexSEL;      
197
198   /// The highlighted ConvexShape ( mouse over ).
199   SimObjectPtr<ConvexShape> mConvexHL;
200
201   S32 mFaceSEL;
202   S32 mFaceHL;
203
204   MatrixF mFaceSavedXfm;
205
206   ConvexShape::Geometry mSavedGeometry;
207   Vector< MatrixF> mSavedSurfaces;
208   Vector< MatrixF> mLastValidShape;
209
210   Point3F mSavedPivotPos;
211
212   bool mCtrlDown;
213   bool mSavedUndo;
214   bool mHasGeometry;
215   bool mDragging;
216   bool mMouseDown;
217   bool mHasCopied;
218   RayInfo mLastRayInfo;
219
220   bool mGridSnap;
221
222   Gui3DMouseEvent mMouseDownEvent;
223
224   Point3F mGizmoMatOffset;
225
226   Point3F mPivotPos;
227   bool mUsingPivot;
228   bool mSettingPivot;
229
230   UndoAction *mLastUndo;
231   UndoManager *mUndoManager;
232
233   struct ConvexShapeProxy
234   {
235      ConvexShape* shapeProxy;
236      SceneObject* targetObject;
237      String targetObjectClass;
238      bool dirty;
239   };
240
241   Vector<ConvexShapeProxy> mProxyObjects;
242
243   ConvexEditorTool *mActiveTool;
244   ConvexEditorCreateTool *mCreateTool;   
245};
246
247class GuiConvexEditorUndoAction : public UndoAction
248{
249   friend class GuiConvexEditorCtrl;
250public:
251
252   GuiConvexEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName ), mEditor(NULL), mObjId(NULL)
253   {
254   }
255
256   GuiConvexEditorCtrl *mEditor;         
257   
258   SimObjectId mObjId;
259
260   Vector< MatrixF> mSavedSurfaces;
261   MatrixF mSavedObjToWorld;
262   Point3F mSavedScale;   
263
264   virtual void undo();
265   virtual void redo() { undo(); }
266};
267
268class ConvexEditorTool
269{
270public:
271
272   enum EventResult
273   {
274      NotHandled = 0,
275      Handled = 1,
276      Done = 2,
277      Failed = 3
278   };
279
280   ConvexEditorTool( GuiConvexEditorCtrl *editor ) 
281      : mEditor( editor ), mDone( false ) {}
282   virtual ~ConvexEditorTool() {}
283
284   virtual void onActivated( ConvexEditorTool *prevTool ) {}
285   virtual void onDeactivated( ConvexEditorTool *newTool ) {}
286
287   virtual EventResult onKeyDown( const GuiEvent &event ) { return NotHandled; }
288   virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; }
289   virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; }
290   virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event ) { return NotHandled; }
291   virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event ) { return NotHandled; }
292   virtual EventResult on3DMouseEnter( const Gui3DMouseEvent &event ) { return NotHandled; }
293   virtual EventResult on3DMouseLeave( const Gui3DMouseEvent &event ) { return NotHandled; }
294   virtual EventResult on3DRightMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; }
295   virtual EventResult on3DRightMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; }
296   
297   virtual void renderScene(const RectI & updateRect) {}
298   virtual void render2D() {} 
299
300   bool isDone() { return mDone; }
301
302public:
303   GuiConvexEditorCtrl *mEditor;
304protected:
305   bool mDone;
306};
307
308class ConvexEditorCreateTool : public ConvexEditorTool
309{
310   typedef ConvexEditorTool Parent;
311public:
312   ConvexEditorCreateTool( GuiConvexEditorCtrl *editor );
313   virtual ~ConvexEditorCreateTool() {}
314
315   virtual void onActivated( ConvexEditorTool *prevTool );
316   virtual void onDeactivated( ConvexEditorTool *newTool );
317
318   virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event );
319   virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event );
320   virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event );
321   virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event );
322
323   virtual void renderScene(const RectI & updateRect);   
324
325   ConvexShape* extrudeShapeFromFace( ConvexShape *shape, S32 face );
326
327protected:
328   
329   S32 mStage;   
330   ConvexShape *mNewConvex;
331   PlaneF mCreatePlane;
332   
333   MatrixF mTransform;
334   Point3F mStart;
335   Point3F mEnd;
336   Point3F mPlaneSizes;
337};
338
339#endif // _GUICONVEXSHAPEEDITORCTRL_H_
340
341
342
343