worldEditor.h
Engine/source/gui/worldEditor/worldEditor.h
Classes:
class
Public Typedefs
WorldEditorAlignmentType
WorldEditorDropType
Public Functions
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; 62 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 ); 119 void explodeSelectedPrefab(); 120 121 void 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 } 138 139 WorldEditor *mWorldEditor; 140 141 struct Entry 142 { 143 MatrixF mMatrix; 144 VectorF mScale; 145 146 // validation 147 U32 mObjId; 148 U32 mObjNumber; 149 }; 150 151 Vector<Entry> mEntries; 152 153 virtual void undo(); 154 virtual void redo() { undo(); } 155 }; 156 157 void submitUndo( Selection* sel, const UTF8* label="World Editor Action" ); 158 159 public: 160 161 /// The objects currently in the copy buffer. 162 Vector<SimObjectMemento> mCopyBuffer; 163 164 bool cutSelection(Selection* sel); 165 bool copySelection(Selection* sel); 166 bool pasteSelection(bool dropSel=true); 167 void dropSelection(Selection* sel); 168 void dropBelowSelection(Selection* sel, const Point3F & centroid, bool useBottomBounds=false); 169 170 void terrainSnapSelection(Selection* sel, U8 modifier, Point3F gizmoPos, bool forceStick=false); 171 void softSnapSelection(Selection* sel, U8 modifier, Point3F gizmoPos); 172 173 Selection* getActiveSelectionSet() const; 174 void makeActiveSelectionSet( Selection* sel ); 175 176 void hideObject(SceneObject* obj, bool hide); 177 178 // work off of mSelected 179 void hideSelection(bool hide); 180 void lockSelection(bool lock); 181 182 public: 183 bool objClassIgnored(const SimObject * obj); 184 void renderObjectBox(SceneObject * obj, const ColorI & col); 185 186 private: 187 SceneObject * getControlObject(); 188 bool collide(const Gui3DMouseEvent & event, SceneObject **hitObj ); 189 190 // gfx methods 191 //void renderObjectBox(SceneObject * obj, const ColorI & col); 192 void renderObjectFace(SceneObject * obj, const VectorF & normal, const ColorI & col); 193 void renderSelectionWorldBox(Selection* sel); 194 195 void renderPlane(const Point3F & origin); 196 void renderMousePopupInfo(); 197 void renderScreenObj( SceneObject * obj, const Point3F& sPos, const Point3F& wPos ); 198 199 void renderPaths(SimObject *obj); 200 void renderSplinePath(SimPath::Path *path); 201 202 // axis gizmo 203 bool mUsingAxisGizmo; 204 205 GFXStateBlockRef mRenderSelectionBoxSB; 206 GFXStateBlockRef mRenderObjectBoxSB; 207 GFXStateBlockRef mRenderObjectFaceSB; 208 GFXStateBlockRef mSplineSB; 209 210 // 211 bool mIsDirty; 212 213 // 214 bool mMouseDown; 215 SimObjectPtr< Selection> mSelected; 216 217 SimObjectPtr< Selection> mDragSelected; 218 bool mDragSelect; 219 RectI mDragRect; 220 Point2I mDragStart; 221 222 // modes for when dragging a selection 223 enum { 224 Move = 0, 225 Rotate, 226 Scale 227 }; 228 229 // 230 //U32 mCurrentMode; 231 //U32 mDefaultMode; 232 233 S32 mRedirectID; 234 235 /// @name Object Icons 236 /// @{ 237 238 struct IconObject 239 { 240 SceneObject *object; 241 F32 dist; 242 RectI rect; 243 U32 alpha; 244 }; 245 246 Vector< IconObject> mIcons; 247 248 /// If true, icons fade out with distance to mouse cursor. 249 bool mFadeIcons; 250 251 /// Distance at which to start fading out icons. 252 F32 mFadeIconsDist; 253 254 /// @} 255 256 SimObjectPtr<SceneObject> mHitObject; 257 SimObjectPtr<SceneObject> mPossibleHitObject; 258 bool mMouseDragged; 259 Gui3DMouseEvent mLastMouseEvent; 260 Gui3DMouseEvent mLastMouseDownEvent; 261 262 // 263 class ClassInfo 264 { 265 public: 266 ~ClassInfo(); 267 268 struct Entry 269 { 270 StringTableEntry mName; 271 bool mIgnoreCollision; 272 GFXTexHandle mDefaultHandle; 273 GFXTexHandle mSelectHandle; 274 GFXTexHandle mLockedHandle; 275 }; 276 277 Vector<Entry*> mEntries; 278 }; 279 280 281 ClassInfo mClassInfo; 282 ClassInfo::Entry mDefaultClassEntry; 283 284 ClassInfo::Entry * getClassEntry(StringTableEntry name); 285 ClassInfo::Entry * getClassEntry(const SimObject * obj); 286 bool addClassEntry(ClassInfo::Entry * entry); 287 288 // persist field data 289 public: 290 291 enum DropType 292 { 293 DropAtOrigin = 0, 294 DropAtCamera, 295 DropAtCameraWithRot, 296 DropBelowCamera, 297 DropAtScreenCenter, 298 DropAtCentroid, 299 DropToTerrain, 300 DropBelowSelection 301 }; 302 303 // Snapping alignment mode 304 enum AlignmentType 305 { 306 AlignNone = 0, 307 AlignPosX, 308 AlignPosY, 309 AlignPosZ, 310 AlignNegX, 311 AlignNegY, 312 AlignNegZ 313 }; 314 315 /// A large hard coded distance used to test 316 /// object and icon selection. 317 static F32 smProjectDistance; 318 319 S32 mDropType; 320 bool mBoundingBoxCollision; 321 bool mObjectMeshCollision; 322 bool mRenderPopupBackground; 323 ColorI mPopupBackgroundColor; 324 ColorI mPopupTextColor; 325 StringTableEntry mSelectHandle; 326 StringTableEntry mDefaultHandle; 327 StringTableEntry mLockedHandle; 328 ColorI mObjectTextColor; 329 bool mObjectsUseBoxCenter; 330 ColorI mObjSelectColor; 331 ColorI mObjMultiSelectColor; 332 ColorI mObjMouseOverSelectColor; 333 ColorI mObjMouseOverColor; 334 bool mShowMousePopupInfo; 335 ColorI mDragRectColor; 336 bool mRenderObjText; 337 bool mRenderObjHandle; 338 StringTableEntry mObjTextFormat; 339 ColorI mFaceSelectColor; 340 bool mRenderSelectionBox; 341 ColorI mSelectionBoxColor; 342 bool mSelectionLocked; 343 bool mPerformedDragCopy; 344 bool mDragGridSnapToggle; ///< Grid snap setting temporarily toggled during drag. 345 bool mToggleIgnoreList; 346 bool mNoMouseDrag; 347 bool mDropAtBounds; 348 F32 mDropBelowCameraOffset; 349 F32 mDropAtScreenCenterScalar; 350 F32 mDropAtScreenCenterMax; 351 352 bool mGridSnap; 353 bool mStickToGround; 354 bool mStuckToGround; ///< Selection is stuck to the ground 355 AlignmentType mTerrainSnapAlignment; ///< How does the stickied object align to the terrain 356 357 bool mSoftSnap; ///< Allow soft snapping all of the time 358 bool mSoftSnapActivated; ///< Soft snap has been activated by the user and allowed by the current rules 359 bool mSoftSnapIsStuck; ///< Are we snapping? 360 AlignmentType mSoftSnapAlignment; ///< How does the snapped object align to the snapped surface 361 bool mSoftSnapRender; ///< Render the soft snapping bounds 362 bool mSoftSnapRenderTriangle; ///< Render the soft snapped triangle 363 Triangle mSoftSnapTriangle; ///< The triangle we are snapping to 364 bool mSoftSnapSizeByBounds; ///< Use the selection bounds for the size 365 F32 mSoftSnapSize; ///< If not the selection bounds, use this size 366 Box3F mSoftSnapBounds; ///< The actual bounds used for the soft snap 367 Box3F mSoftSnapPreBounds; ///< The bounds prior to any soft snapping (used when rendering the snap bounds) 368 F32 mSoftSnapBackfaceTolerance; ///< Fraction of mSoftSnapSize for backface polys to have an influence 369 370 bool mSoftSnapDebugRender; ///< Activates debug rendering 371 Point3F mSoftSnapDebugPoint; ///< The point we're attempting to snap to 372 Triangle mSoftSnapDebugSnapTri; ///< The triangle we are snapping to 373 Vector<Triangle> mSoftSnapDebugTriangles; ///< The triangles that are considered for snapping 374 375 protected: 376 377 S32 mCurrentCursor; 378 void setCursor(U32 cursor); 379 void get3DCursor(GuiCursor *&cursor, bool &visible, const Gui3DMouseEvent &event); 380 381 public: 382 383 WorldEditor(); 384 ~WorldEditor(); 385 386 void setDirty() { mIsDirty = true; } 387 388 // SimObject 389 virtual bool onAdd(); 390 virtual void onEditorEnable(); 391 392 // EditTSCtrl 393 void on3DMouseMove(const Gui3DMouseEvent & event); 394 void on3DMouseDown(const Gui3DMouseEvent & event); 395 void on3DMouseUp(const Gui3DMouseEvent & event); 396 void on3DMouseDragged(const Gui3DMouseEvent & event); 397 void on3DMouseEnter(const Gui3DMouseEvent & event); 398 void on3DMouseLeave(const Gui3DMouseEvent & event); 399 void on3DRightMouseDown(const Gui3DMouseEvent & event); 400 void on3DRightMouseUp(const Gui3DMouseEvent & event); 401 402 void updateGuiInfo(); 403 404 // 405 void renderScene(const RectI & updateRect); 406 407 static void initPersistFields(); 408 409 DECLARE_CONOBJECT(WorldEditor); 410 411 static Signal<void(WorldEditor*)> smRenderSceneSignal; 412}; 413 414typedef WorldEditor::DropType WorldEditorDropType; 415typedef WorldEditor::AlignmentType WorldEditorAlignmentType; 416 417DefineEnumType( WorldEditorDropType ); 418DefineEnumType( WorldEditorAlignmentType ); 419 420#endif // _WORLDEDITOR_H_ 421 422
