guiShapeEdPreview.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _GUISHAPEEDPREVIEW_H_
  23. #define _GUISHAPEEDPREVIEW_H_
  24. #include "gui/worldEditor/editTSCtrl.h"
  25. #include "ts/tsShapeInstance.h"
  26. class LightInfo;
  27. class GuiShapeEdPreview : public EditTSCtrl
  28. {
  29. struct Thread
  30. {
  31. TSThread* key; //!< TSThread key
  32. String seqName; //!< Name of the sequence for this thread
  33. S32 direction; //!< Playback direction: -1 (reverse), 0 (paused), 1 (forward)
  34. bool pingpong; //!< Pingpong flag (auto-reverse direction at start/end)
  35. Thread()
  36. {
  37. init();
  38. }
  39. void init()
  40. {
  41. key = NULL;
  42. direction = 1.0f;
  43. pingpong = false;
  44. }
  45. };
  46. struct MountedShape
  47. {
  48. enum eMountType
  49. {
  50. Object, //!< Mount origin of shape to target node
  51. Image, //!< Mount 'mountPoint' or origin of shape to target node
  52. Wheel, //!< Mount origin of shape to target node, ignore target node rotation
  53. };
  54. TSShapeInstance* mShape; //!< The mounted shape instance
  55. S32 mNode; //!< Index of the node this shape is mounted to
  56. MatrixF mTransform; //!< Mount offset transform
  57. eMountType mType; //!< Type of mount
  58. Thread mThread; //!< Animation thread for the mounted shape
  59. MountedShape() : mShape(0), mNode(-1), mTransform(true), mType(Object) { }
  60. ~MountedShape() { delete mShape; }
  61. };
  62. protected:
  63. typedef EditTSCtrl Parent;
  64. // View and node selection
  65. bool mUsingAxisGizmo;
  66. bool mEditingSun; //!< True if editing the sun direction, false otherwise
  67. S32 mGizmoDragID; //!< Used to track transform changes within a single gizmo drag action
  68. S32 mSelectedNode; //!< Index of the selected node
  69. S32 mHoverNode; //!< Index of the node the mouse is over
  70. Vector<Point3F> mProjectedNodes; //!< Projected screen positions of the model nodes
  71. S32 mSelectedObject; //!< Name of the selected object
  72. S32 mSelectedObjDetail; //!< Detail mesh index of the selected object
  73. // Camera
  74. EulerF mCameraRot;
  75. bool mRenderCameraAxes;
  76. Point3F mOrbitPos;
  77. F32 mOrbitDist;
  78. F32 mMoveSpeed;
  79. F32 mZoomSpeed;
  80. // Current Detail
  81. bool mFixedDetail; //!< If false, the detail level will be determined based on camera distance
  82. S32 mCurrentDL; //!< Current detail level
  83. S32 mDetailSize; //!< Size of current detail level
  84. S32 mDetailPolys; //!< Number of polys (triangles) in current detail level
  85. F32 mPixelSize; //!< Current pixel size
  86. S32 mNumMaterials; //!< Number of materials in the current detail level
  87. S32 mNumDrawCalls; //!< Number of draw calls in the current detail level
  88. S32 mNumBones; //!< Number of bones in the current detail level (skins only)
  89. S32 mNumWeights; //!< Number of vertex weights in the current detail level (skins only)
  90. S32 mColMeshes; //!< Number of collision meshes
  91. S32 mColPolys; //!< Number of collision polygons (all meshes)
  92. // Rendering
  93. Point2I mGridDimension; //!< Dimension of grid in perspective view (eg. 30x30)
  94. bool mRenderGhost;
  95. bool mRenderNodes;
  96. bool mRenderBounds;
  97. bool mRenderObjBox;
  98. bool mRenderColMeshes;
  99. bool mRenderMounts;
  100. TSShapeInstance* mModel;
  101. LightInfo* mFakeSun;
  102. EulerF mSunRot;
  103. ColorI mSunDiffuseColor;
  104. ColorI mSunAmbientColor;
  105. // Animation and playback control
  106. Vector<Thread> mThreads;
  107. F32 mTimeScale;
  108. S32 mActiveThread;
  109. S32 mLastRenderTime;
  110. // Mounted objects
  111. Vector<MountedShape*> mMounts;
  112. static bool setFieldCurrentDL( void *object, const char *index, const char *data );
  113. static bool setFieldSunDiffuse( void *object, const char *index, const char *data );
  114. static bool setFieldSunAmbient( void *object, const char *index, const char *data );
  115. static bool setFieldSunAngleX( void *object, const char *index, const char *data );
  116. static bool setFieldSunAngleZ( void *object, const char *index, const char *data );
  117. static bool setFieldThreadPos( void *object, const char *index, const char *data );
  118. static bool setFieldThreadIn( void *object, const char *index, const char *data );
  119. static bool setFieldThreadOut( void *object, const char *index, const char *data );
  120. static bool setFieldThreadDir( void *object, const char *index, const char *data );
  121. static bool setFieldThreadPingPong( void *object, const char *index, const char *data );
  122. static const char *getFieldThreadPos( void *object, const char *data );
  123. static const char *getFieldThreadIn( void *object, const char *data );
  124. static const char *getFieldThreadOut( void *object, const char *data );
  125. static const char *getFieldThreadDir( void *object, const char *data );
  126. static const char *getFieldThreadPingPong( void *object, const char *data );
  127. // Generic mouse event handlers
  128. void handleMouseDown(const GuiEvent& event, GizmoMode mode);
  129. void handleMouseUp(const GuiEvent& event, GizmoMode mode);
  130. void handleMouseMove(const GuiEvent& event, GizmoMode mode);
  131. void handleMouseDragged(const GuiEvent& event, GizmoMode mode);
  132. // Node picking
  133. S32 collideNode(const Gui3DMouseEvent& event) const;
  134. void updateProjectedNodePoints();
  135. void updateSun();
  136. void updateDetailLevel(const SceneRenderState* state);
  137. void updateThreads(F32 delta);
  138. // Rendering
  139. void renderGrid();
  140. void renderNodes() const;
  141. void renderNodeAxes(S32 index, const ColorF& nodeColor) const;
  142. void renderNodeName(S32 index, const ColorF& textColor) const;
  143. void renderSunDirection() const;
  144. void renderCollisionMeshes() const;
  145. public:
  146. bool onWake();
  147. void setDisplayType(S32 type);
  148. /// @name Mouse event handlers
  149. ///@{
  150. void onMouseDown(const GuiEvent& event) { handleMouseDown(event, NoneMode); }
  151. void onMouseUp(const GuiEvent& event) { handleMouseUp(event, NoneMode); }
  152. void onMouseMove(const GuiEvent& event) { handleMouseMove(event, NoneMode); }
  153. void onMouseDragged(const GuiEvent& event) { handleMouseDragged(event, NoneMode); }
  154. void onMiddleMouseDown(const GuiEvent& event) { handleMouseDown(event, MoveMode); }
  155. void onMiddleMouseUp(const GuiEvent& event) { handleMouseUp(event, MoveMode); }
  156. void onMiddleMouseDragged(const GuiEvent& event) { handleMouseDragged(event, MoveMode); }
  157. void onRightMouseDown(const GuiEvent& event) { handleMouseDown(event, RotateMode); }
  158. void onRightMouseUp(const GuiEvent& event) { handleMouseUp(event, RotateMode); }
  159. void onRightMouseDragged(const GuiEvent& event) { handleMouseDragged(event, RotateMode); }
  160. void on3DMouseWheelUp(const Gui3DMouseEvent& event);
  161. void on3DMouseWheelDown(const Gui3DMouseEvent& event);
  162. ///@}
  163. // Setters/Getters
  164. TSShapeInstance* getModel() { return mModel; }
  165. void setCurrentDetail(S32 dl);
  166. bool setObjectModel(const char * modelName);
  167. /// @name Threads
  168. ///@{
  169. void addThread();
  170. void removeThread(S32 slot);
  171. S32 getThreadCount() const { return mThreads.size(); }
  172. void setTimeScale(F32 scale);
  173. void setActiveThreadSequence(const char* seqName, F32 duration, F32 pos, bool play);
  174. void setThreadSequence(Thread& thread, TSShapeInstance* shape, const char * seqName, F32 duration=0.0f, F32 pos=0.0f, bool play=false);
  175. const char* getThreadSequence() const;
  176. void refreshThreadSequences();
  177. DECLARE_CALLBACK( void, onThreadPosChanged, ( F32 pos, bool inTransition ) );
  178. ///@}
  179. /// @name Mounting
  180. ///@{
  181. bool mountShape(const char* modelName, const char* nodeName, const char* mountType, S32 slot=-1);
  182. void setMountNode(S32 mountSlot, const char* nodeName);
  183. const char* getMountThreadSequence(S32 mountSlot) const;
  184. void setMountThreadSequence(S32 mountSlot, const char* seqName);
  185. F32 getMountThreadPos(S32 mountSlot) const;
  186. void setMountThreadPos(S32 mountSlot, F32 pos);
  187. F32 getMountThreadDir(S32 mountSlot) const;
  188. void setMountThreadDir(S32 mountSlot, F32 dir);
  189. void unmountShape(S32 mountSlot);
  190. void unmountAll();
  191. ///@}
  192. void refreshShape();
  193. void updateNodeTransforms();
  194. void get3DCursor(GuiCursor *& cursor, bool& visible, const Gui3DMouseEvent& event_);
  195. void fitToShape();
  196. void setOrbitPos( const Point3F& pos );
  197. void exportToCollada( const String& path );
  198. /// @name Rendering
  199. ///@{
  200. bool getCameraTransform(MatrixF* cameraMatrix);
  201. void computeSceneBounds(Box3F& bounds);
  202. bool getMeshHidden(const char* name) const;
  203. void setMeshHidden(const char* name, bool hidden);
  204. void setAllMeshesHidden(bool hidden);
  205. void renderWorld(const RectI& updateRect);
  206. void renderGui(Point2I offset, const RectI& updateRect);
  207. ///@}
  208. DECLARE_CONOBJECT(GuiShapeEdPreview);
  209. DECLARE_CATEGORY( "Gui Editor" );
  210. static void initPersistFields();
  211. GuiShapeEdPreview();
  212. ~GuiShapeEdPreview();
  213. };
  214. #endif