123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #ifndef _GUICONVEXSHAPEEDITORCTRL_H_
- #define _GUICONVEXSHAPEEDITORCTRL_H_
- #ifndef _EDITTSCTRL_H_
- #include "gui/worldEditor/editTSCtrl.h"
- #endif
- #ifndef _UNDO_H_
- #include "util/undo.h"
- #endif
- #ifndef _GIZMO_H_
- #include "gui/worldEditor/gizmo.h"
- #endif
- #ifndef _CONVEXSHAPE_H_
- #include "T3D/convexShape.h"
- #endif
- class GameBase;
- class GuiConvexEditorUndoAction;
- class ConvexEditorTool;
- class ConvexEditorCreateTool;
- class GuiConvexEditorCtrl : public EditTSCtrl
- {
- typedef EditTSCtrl Parent;
- friend class GuiConvexEditorUndoAction;
- public:
- GuiConvexEditorCtrl();
- virtual ~GuiConvexEditorCtrl();
- DECLARE_CONOBJECT( GuiConvexEditorCtrl );
- // SimObject
- virtual bool onAdd();
- virtual void onRemove();
- static void initPersistFields();
- // GuiControl
- virtual bool onWake();
- virtual void onSleep();
- virtual void setVisible(bool value);
- // EditTSCtrl
- bool onKeyDown( const GuiEvent &event );
- bool onKeyUp( const GuiEvent &event );
- void get3DCursor( GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event_ );
- void on3DMouseDown( const Gui3DMouseEvent &event );
- void on3DMouseUp( const Gui3DMouseEvent &event );
- void on3DMouseMove( const Gui3DMouseEvent &event );
- void on3DMouseDragged( const Gui3DMouseEvent &event );
- void on3DMouseEnter( const Gui3DMouseEvent &event );
- void on3DMouseLeave( const Gui3DMouseEvent &event );
- void on3DRightMouseDown( const Gui3DMouseEvent &event );
- void on3DRightMouseUp( const Gui3DMouseEvent &event );
- void renderScene(const RectI & updateRect);
- void updateGizmo();
- void updateShape( ConvexShape *shape, S32 offsetFace = -1 );
- static void synchClientObject( const ConvexShape *serverConvex );
- void updateGizmoPos();
- bool setActiveTool( ConvexEditorTool *tool );
- void drawFacePlane( ConvexShape *shape, S32 faceId );
- void scaleFace( ConvexShape *shape, S32 faceId, Point3F scale );
- void translateFace( ConvexShape *shape, S32 faceId, const Point3F &displace );
- void updateModifiedFace( ConvexShape *shape, S32 faceId );
- bool isShapeValid( ConvexShape *shape );
- void setupShape( ConvexShape *shape );
- void setPivotPos( ConvexShape *shape, S32 faceId, const Gui3DMouseEvent &event );
- void cleanMatrix( MatrixF &mat );
- S32 getEdgeByPoints( ConvexShape *shape, S32 faceId, S32 pId0, S32 pId1 );
- bool getEdgesTouchingPoint( ConvexShape *shape, S32 faceId, S32 pId, Vector< U32 > &edgeIdxList, S32 excludeEdge = -1 );
- void hollowSelection();
- void hollowShape( ConvexShape *shape, F32 thickness );
- void recenterSelection();
- void recenterShape( ConvexShape *shape );
- void dropSelectionAtScreenCenter();
- void splitSelectedFace();
- SceneObject* createPolyhedralObject(const char* className, SceneObject* geometryProvider);
- ConvexShape* createConvexShapeFrom(SceneObject* polyObject);
- Point2F getSelectedFaceUVOffset();
- Point2F getSelectedFaceUVScale();
- const char* getSelectedFaceMaterial();
- bool getSelectedFaceHorzFlip();
- bool getSelectedFaceVertFlip();
- float getSelectedFaceZRot();
- void setSelectedFaceUVOffset(Point2F offset);
- void setSelectedFaceUVScale(Point2F offset);
- void setSelectedFaceMaterial(const char* materialName);
- void setSelectedFaceHorzFlip(bool flipped);
- void setSelectedFaceVertFlip(bool flipped);
- void setSelectedFaceZRot(float degrees);
- void toggleGridSnapping();
- void setGridSnapSize(float gridSize);
- void updateShape();
- float getGridSnapSize() { return mGridPlaneSize; }
- /// Interface with Tools.
- /// @{
- MatrixF getCameraMat() const { return mLastCameraQuery.cameraMatrix; }
- enum UndoType
- {
- ModifyShape = 0,
- CreateShape,
- DeleteShape,
- HollowShape
- };
- void submitUndo( UndoType type, ConvexShape *shape );
- void submitUndo( UndoType type, const Vector< ConvexShape* > &shape );
- /// @}
- bool hasSelection() const;
- void clearSelection();
- void setSelection( ConvexShape *shape, S32 faceId );
- void handleDeselect();
- bool handleEscape();
- bool handleDelete();
- bool handleTab();
- public:
- StringTableEntry mMaterialName;
- protected:
- void _prepRenderImage( SceneManager* sceneGraph, const SceneRenderState* sceneState );
- void _renderObject( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *matInst );
- bool _cursorCast( const Gui3DMouseEvent &event, ConvexShape **hitShape, S32 *hitFace );
- static bool _cursorCastCallback( RayInfo* ri );
- protected:
- bool mIsDirty;
- U32 mSavedGizmoFlags;
- Vector<SimObjectPtr<ConvexShape>> mSelectedBrushes;
- struct selectedFace
- {
- SimObjectPtr<ConvexShape> mOwnerBrush;
- U32 faceId;
- };
- Vector<selectedFace> mSelectedFaces;
- struct selectedVert
- {
- SimObjectPtr<ConvexShape> mOwnerBrush;
- U32 vertId;
- };
- Vector<selectedVert> mSelectedVerts;
- /// The selected ConvexShape.
- SimObjectPtr<ConvexShape> mConvexSEL;
- /// The highlighted ConvexShape ( mouse over ).
- SimObjectPtr<ConvexShape> mConvexHL;
- S32 mFaceSEL;
- S32 mFaceHL;
- MatrixF mFaceSavedXfm;
- ConvexShape::Geometry mSavedGeometry;
- Vector< MatrixF > mSavedSurfaces;
- Vector< MatrixF > mLastValidShape;
- Point3F mSavedPivotPos;
- bool mCtrlDown;
- bool mSavedUndo;
- bool mHasGeometry;
- bool mDragging;
- bool mMouseDown;
- bool mHasCopied;
- RayInfo mLastRayInfo;
- bool mGridSnap;
- Gui3DMouseEvent mMouseDownEvent;
- Point3F mGizmoMatOffset;
- Point3F mPivotPos;
- bool mUsingPivot;
- bool mSettingPivot;
- UndoAction *mLastUndo;
- UndoManager *mUndoManager;
- struct ConvexShapeProxy
- {
- ConvexShape* shapeProxy;
- SceneObject* targetObject;
- String targetObjectClass;
- bool dirty;
- };
- Vector<ConvexShapeProxy> mProxyObjects;
- ConvexEditorTool *mActiveTool;
- ConvexEditorCreateTool *mCreateTool;
- };
- class GuiConvexEditorUndoAction : public UndoAction
- {
- friend class GuiConvexEditorCtrl;
- public:
- GuiConvexEditorUndoAction( const UTF8* actionName ) : UndoAction( actionName ), mEditor(NULL), mObjId(0)
- {
- }
- GuiConvexEditorCtrl *mEditor;
-
- SimObjectId mObjId;
- Vector< MatrixF > mSavedSurfaces;
- MatrixF mSavedObjToWorld;
- Point3F mSavedScale;
- virtual void undo();
- virtual void redo() { undo(); }
- };
- class ConvexEditorTool
- {
- public:
- enum EventResult
- {
- NotHandled = 0,
- Handled = 1,
- Done = 2,
- Failed = 3
- };
- ConvexEditorTool( GuiConvexEditorCtrl *editor )
- : mEditor( editor ), mDone( false ) {}
- virtual ~ConvexEditorTool() {}
- virtual void onActivated( ConvexEditorTool *prevTool ) {}
- virtual void onDeactivated( ConvexEditorTool *newTool ) {}
- virtual EventResult onKeyDown( const GuiEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseEnter( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DMouseLeave( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DRightMouseDown( const Gui3DMouseEvent &event ) { return NotHandled; }
- virtual EventResult on3DRightMouseUp( const Gui3DMouseEvent &event ) { return NotHandled; }
-
- virtual void renderScene(const RectI & updateRect) {}
- virtual void render2D() {}
- bool isDone() { return mDone; }
- public:
- GuiConvexEditorCtrl *mEditor;
- protected:
- bool mDone;
- };
- class ConvexEditorCreateTool : public ConvexEditorTool
- {
- typedef ConvexEditorTool Parent;
- public:
- ConvexEditorCreateTool( GuiConvexEditorCtrl *editor );
- virtual ~ConvexEditorCreateTool() {}
- virtual void onActivated( ConvexEditorTool *prevTool );
- virtual void onDeactivated( ConvexEditorTool *newTool );
- virtual EventResult on3DMouseDown( const Gui3DMouseEvent &event );
- virtual EventResult on3DMouseUp( const Gui3DMouseEvent &event );
- virtual EventResult on3DMouseMove( const Gui3DMouseEvent &event );
- virtual EventResult on3DMouseDragged( const Gui3DMouseEvent &event );
- virtual void renderScene(const RectI & updateRect);
- ConvexShape* extrudeShapeFromFace( ConvexShape *shape, S32 face );
- protected:
-
- S32 mStage;
- ConvexShape *mNewConvex;
- PlaneF mCreatePlane;
-
- MatrixF mTransform;
- Point3F mStart;
- Point3F mEnd;
- Point3F mPlaneSizes;
- };
- #endif // _GUICONVEXSHAPEEDITORCTRL_H_
|