guiShapeEdPreview.h
Engine/source/gui/editor/guiShapeEdPreview.h
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 _GUISHAPEEDPREVIEW_H_ 25#define _GUISHAPEEDPREVIEW_H_ 26 27#include "gui/worldEditor/editTSCtrl.h" 28#include "ts/tsShapeInstance.h" 29 30class LightInfo; 31 32class GuiShapeEdPreview : public EditTSCtrl 33{ 34 struct Thread 35 { 36 TSThread* key; //!< TSThread key 37 String seqName; //!< Name of the sequence for this thread 38 S32 direction; //!< Playback direction: -1 (reverse), 0 (paused), 1 (forward) 39 bool pingpong; //!< Pingpong flag (auto-reverse direction at start/end) 40 41 Thread() 42 { 43 init(); 44 } 45 46 void init() 47 { 48 key = NULL; 49 direction = 1.0f; 50 pingpong = false; 51 } 52 }; 53 54 struct MountedShape 55 { 56 enum eMountType 57 { 58 Object, //!< Mount origin of shape to target node 59 Image, //!< Mount 'mountPoint' or origin of shape to target node 60 Wheel, //!< Mount origin of shape to target node, ignore target node rotation 61 }; 62 63 TSShapeInstance* mShape; //!< The mounted shape instance 64 S32 mNode; //!< Index of the node this shape is mounted to 65 MatrixF mTransform; //!< Mount offset transform 66 eMountType mType; //!< Type of mount 67 Thread mThread; //!< Animation thread for the mounted shape 68 69 MountedShape() : mShape(0), mNode(-1), mTransform(true), mType(Object) { } 70 ~MountedShape() { delete mShape; } 71 }; 72 73protected: 74 typedef EditTSCtrl Parent; 75 76 // View and node selection 77 bool mUsingAxisGizmo; 78 bool mEditingSun; //!< True if editing the sun direction, false otherwise 79 80 S32 mGizmoDragID; //!< Used to track transform changes within a single gizmo drag action 81 S32 mSelectedNode; //!< Index of the selected node 82 S32 mHoverNode; //!< Index of the node the mouse is over 83 Vector<Point3F> mProjectedNodes; //!< Projected screen positions of the model nodes 84 85 S32 mSelectedObject; //!< Name of the selected object 86 S32 mSelectedObjDetail; //!< Detail mesh index of the selected object 87 88 // Camera 89 EulerF mCameraRot; 90 bool mRenderCameraAxes; 91 Point3F mOrbitPos; 92 F32 mOrbitDist; 93 F32 mMoveSpeed; 94 F32 mZoomSpeed; 95 96 // Current Detail 97 bool mFixedDetail; //!< If false, the detail level will be determined based on camera distance 98 S32 mCurrentDL; //!< Current detail level 99 S32 mDetailSize; //!< Size of current detail level 100 S32 mDetailPolys; //!< Number of polys (triangles) in current detail level 101 F32 mPixelSize; //!< Current pixel size 102 S32 mNumMaterials; //!< Number of materials in the current detail level 103 S32 mNumDrawCalls; //!< Number of draw calls in the current detail level 104 S32 mNumBones; //!< Number of bones in the current detail level (skins only) 105 S32 mNumWeights; //!< Number of vertex weights in the current detail level (skins only) 106 S32 mColMeshes; //!< Number of collision meshes 107 S32 mColPolys; //!< Number of collision polygons (all meshes) 108 109 // Rendering 110 Point2I mGridDimension; //!< Dimension of grid in perspective view (eg. 30x30) 111 bool mRenderGhost; 112 bool mRenderNodes; 113 bool mRenderBounds; 114 bool mRenderObjBox; 115 bool mRenderColMeshes; 116 bool mRenderMounts; 117 TSShapeInstance* mModel; 118 119 LightInfo* mFakeSun; 120 EulerF mSunRot; 121 ColorI mSunDiffuseColor; 122 ColorI mSunAmbientColor; 123 124 // Animation and playback control 125 Vector<Thread> mThreads; 126 F32 mTimeScale; 127 S32 mActiveThread; 128 S32 mLastRenderTime; 129 130 // Mounted objects 131 Vector<MountedShape*> mMounts; 132 133 static bool setFieldCurrentDL( void *object, const char *index, const char *data ); 134 static bool setFieldSunDiffuse( void *object, const char *index, const char *data ); 135 static bool setFieldSunAmbient( void *object, const char *index, const char *data ); 136 static bool setFieldSunAngleX( void *object, const char *index, const char *data ); 137 static bool setFieldSunAngleZ( void *object, const char *index, const char *data ); 138 139 static bool setFieldThreadPos( void *object, const char *index, const char *data ); 140 static bool setFieldThreadIn( void *object, const char *index, const char *data ); 141 static bool setFieldThreadOut( void *object, const char *index, const char *data ); 142 static bool setFieldThreadDir( void *object, const char *index, const char *data ); 143 static bool setFieldThreadPingPong( void *object, const char *index, const char *data ); 144 145 static const char *getFieldThreadPos( void *object, const char *data ); 146 static const char *getFieldThreadIn( void *object, const char *data ); 147 static const char *getFieldThreadOut( void *object, const char *data ); 148 static const char *getFieldThreadDir( void *object, const char *data ); 149 static const char *getFieldThreadPingPong( void *object, const char *data ); 150 151 // Generic mouse event handlers 152 void handleMouseDown(const GuiEvent& event, GizmoMode mode); 153 void handleMouseUp(const GuiEvent& event, GizmoMode mode); 154 void handleMouseMove(const GuiEvent& event, GizmoMode mode); 155 void handleMouseDragged(const GuiEvent& event, GizmoMode mode); 156 157 // Node picking 158 S32 collideNode(const Gui3DMouseEvent& event) const; 159 void updateProjectedNodePoints(); 160 161 void updateSun(); 162 void updateDetailLevel(const SceneRenderState* state); 163 void updateThreads(F32 delta); 164 165 // Rendering 166 void renderGrid(); 167 void renderNodes() const; 168 void renderNodeAxes(S32 index, const LinearColorF& nodeColor) const; 169 void renderNodeName(S32 index, const LinearColorF& textColor) const; 170 void renderSunDirection() const; 171 void renderCollisionMeshes() const; 172 173public: 174 bool onWake(); 175 176 void setDisplayType(S32 type); 177 178 /// @name Mouse event handlers 179 ///@{ 180 void onMouseDown(const GuiEvent& event) { handleMouseDown(event, NoneMode); } 181 void onMouseUp(const GuiEvent& event) { handleMouseUp(event, NoneMode); } 182 void onMouseMove(const GuiEvent& event) { handleMouseMove(event, NoneMode); } 183 void onMouseDragged(const GuiEvent& event) { handleMouseDragged(event, NoneMode); } 184 185 void onMiddleMouseDown(const GuiEvent& event) { handleMouseDown(event, MoveMode); } 186 void onMiddleMouseUp(const GuiEvent& event) { handleMouseUp(event, MoveMode); } 187 void onMiddleMouseDragged(const GuiEvent& event) { handleMouseDragged(event, MoveMode); } 188 189 void onRightMouseDown(const GuiEvent& event) { handleMouseDown(event, RotateMode); } 190 void onRightMouseUp(const GuiEvent& event) { handleMouseUp(event, RotateMode); } 191 void onRightMouseDragged(const GuiEvent& event) { handleMouseDragged(event, RotateMode); } 192 193 void on3DMouseWheelUp(const Gui3DMouseEvent& event); 194 void on3DMouseWheelDown(const Gui3DMouseEvent& event); 195 ///@} 196 197 // Setters/Getters 198 TSShapeInstance* getModel() { return mModel; } 199 200 void setCurrentDetail(S32 dl); 201 bool setObjectModel(const char * modelName); 202 203 /// @name Threads 204 ///@{ 205 void addThread(); 206 void removeThread(S32 slot); 207 S32 getThreadCount() const { return mThreads.size(); } 208 void setTimeScale(F32 scale); 209 void setActiveThreadSequence(const char* seqName, F32 duration, F32 pos, bool play); 210 void setThreadSequence(Thread& thread, TSShapeInstance* shape, const char * seqName, F32 duration=0.0f, F32 pos=0.0f, bool play=false); 211 const char* getThreadSequence() const; 212 void refreshThreadSequences(); 213 214 DECLARE_CALLBACK( void, onThreadPosChanged, ( F32 pos, bool inTransition ) ); 215 ///@} 216 217 /// @name Mounting 218 ///@{ 219 bool mountShape(const char* modelName, const char* nodeName, const char* mountType, S32 slot=-1); 220 void setMountNode(S32 mountSlot, const char* nodeName); 221 const char* getMountThreadSequence(S32 mountSlot) const; 222 void setMountThreadSequence(S32 mountSlot, const char* seqName); 223 F32 getMountThreadPos(S32 mountSlot) const; 224 void setMountThreadPos(S32 mountSlot, F32 pos); 225 F32 getMountThreadDir(S32 mountSlot) const; 226 void setMountThreadDir(S32 mountSlot, F32 dir); 227 void unmountShape(S32 mountSlot); 228 void unmountAll(); 229 ///@} 230 231 void refreshShape(); 232 void updateNodeTransforms(); 233 234 void get3DCursor(GuiCursor *& cursor, bool& visible, const Gui3DMouseEvent& event_); 235 236 void fitToShape(); 237 void setOrbitPos( const Point3F& pos ); 238 239 void exportToCollada( const String& path ); 240 241 /// @name Rendering 242 ///@{ 243 bool getCameraTransform(MatrixF* cameraMatrix); 244 void computeSceneBounds(Box3F& bounds); 245 246 bool getMeshHidden(const char* name) const; 247 void setMeshHidden(const char* name, bool hidden); 248 void setAllMeshesHidden(bool hidden); 249 250 void renderWorld(const RectI& updateRect); 251 void renderGui(Point2I offset, const RectI& updateRect); 252 ///@} 253 254 DECLARE_CONOBJECT(GuiShapeEdPreview); 255 DECLARE_CATEGORY( "Gui Editor" ); 256 257 static void initPersistFields(); 258 259 GuiShapeEdPreview(); 260 ~GuiShapeEdPreview(); 261}; 262 263#endif 264