guiConvexShapeEditorCtrl.h
Engine/source/gui/worldEditor/guiConvexShapeEditorCtrl.h
Classes:
class
class
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 /// Interface with Tools. 119 /// @{ 120 121 MatrixF getCameraMat() const { return mLastCameraQuery.cameraMatrix; } 122 123 enum UndoType 124 { 125 ModifyShape = 0, 126 CreateShape, 127 DeleteShape, 128 HollowShape 129 }; 130 131 void submitUndo( UndoType type, ConvexShape *shape ); 132 void submitUndo( UndoType type, const Vector< ConvexShape*> &shape ); 133 134 /// @} 135 136 bool hasSelection() const; 137 void clearSelection(); 138 void setSelection( ConvexShape *shape, S32 faceId ); 139 void handleDeselect(); 140 bool handleEscape(); 141 bool handleDelete(); 142 bool handleTab(); 143public: 144 145 StringTableEntry mMaterialName; 146protected: 147 148 void _prepRenderImage( SceneManager* sceneGraph, const SceneRenderState* sceneState ); 149 void _renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *matInst ); 150 151 bool _cursorCast( const Gui3DMouseEvent &event, ConvexShape **hitShape, S32 *hitFace ); 152 static bool _cursorCastCallback( RayInfo* ri ); 153 154protected: 155 156 bool mIsDirty; 157 158 U32 mSavedGizmoFlags; 159 160 /// The selected ConvexShape. 161 SimObjectPtr<ConvexShape> mConvexSEL; 162 163 /// The highlighted ConvexShape ( mouse over ). 164 SimObjectPtr<ConvexShape> mConvexHL; 165 166 S32 mFaceSEL; 167 S32 mFaceHL; 168 169 MatrixF mFaceSavedXfm; 170 171 ConvexShape::Geometry mSavedGeometry; 172 Vector< MatrixF> mSavedSurfaces; 173 Vector< MatrixF> mLastValidShape; 174 175 Point3F mSavedPivotPos; 176 177 bool mCtrlDown; 178 bool mSavedUndo; 179 bool mHasGeometry; 180 bool mDragging; 181 bool mMouseDown; 182 bool mHasCopied; 183 RayInfo mLastRayInfo; 184 185 Gui3DMouseEvent mMouseDownEvent; 186 187 Point3F mGizmoMatOffset; 188 189 Point3F mPivotPos; 190 bool mUsingPivot; 191 bool mSettingPivot; 192 193 UndoAction *mLastUndo; 194 UndoManager *mUndoManager; 195 196 ConvexEditorTool *mActiveTool; 197 ConvexEditorCreateTool *mCreateTool; 198}; 199 200class GuiConvexEditorUndoAction : public UndoAction 201{ 202 friend class GuiConvexEditorCtrl; 203public: 204 205 GuiConvexEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName ) 206 { 207 } 208 209 GuiConvexEditorCtrl *mEditor; 210 211 SimObjectId mObjId; 212 213 Vector< MatrixF> mSavedSurfaces; 214 MatrixF mSavedObjToWorld; 215 Point3F mSavedScale; 216 217 virtual void undo(); 218 virtual void redo() { undo(); } 219}; 220 221class ConvexEditorTool 222{ 223public: 224 225 enum EventResult 226 { 227 NotHandled = 0, 228 Handled = 1, 229 Done = 2, 230 Failed = 3 231 }; 232 233 ConvexEditorTool( GuiConvexEditorCtrl *editor ) 234 : mEditor( editor ), mDone( false ) {} 235 virtual ~ConvexEditorTool() {} 236 237 virtual void onActivated( ConvexEditorTool *prevTool ) {} 238 virtual void onDeactivated( ConvexEditorTool *newTool ) {} 239 240 virtual EventResult onKeyDown( const GuiEvent &event ) { return NotHandled; } 241 virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; } 242 virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; } 243 virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event ) { return NotHandled; } 244 virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event ) { return NotHandled; } 245 virtual EventResult on3DMouseEnter( const Gui3DMouseEvent &event ) { return NotHandled; } 246 virtual EventResult on3DMouseLeave( const Gui3DMouseEvent &event ) { return NotHandled; } 247 virtual EventResult on3DRightMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; } 248 virtual EventResult on3DRightMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; } 249 250 virtual void renderScene(const RectI & updateRect) {} 251 virtual void render2D() {} 252 253 bool isDone() { return mDone; } 254 255public: 256 GuiConvexEditorCtrl *mEditor; 257protected: 258 bool mDone; 259}; 260 261class ConvexEditorCreateTool : public ConvexEditorTool 262{ 263 typedef ConvexEditorTool Parent; 264public: 265 ConvexEditorCreateTool( GuiConvexEditorCtrl *editor ); 266 virtual ~ConvexEditorCreateTool() {} 267 268 virtual void onActivated( ConvexEditorTool *prevTool ); 269 virtual void onDeactivated( ConvexEditorTool *newTool ); 270 271 virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event ); 272 virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event ); 273 virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event ); 274 virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event ); 275 276 virtual void renderScene(const RectI & updateRect); 277 278 ConvexShape* extrudeShapeFromFace( ConvexShape *shape, S32 face ); 279 280protected: 281 282 S32 mStage; 283 ConvexShape *mNewConvex; 284 PlaneF mCreatePlane; 285 286 MatrixF mTransform; 287 Point3F mStart; 288 Point3F mEnd; 289 Point3F mPlaneSizes; 290}; 291 292#endif // _GUICONVEXSHAPEEDITORCTRL_H_ 293 294 295 296
