Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
14 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef TOOLDISPLACE_H
  8. #define TOOLDISPLACE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. //=============================================================================
  13. #include "ToolInterface.h"
  14. #include "MapDisp.h"
  15. #include "DispMapImageFilter.h"
  16. #include "MapFace.h"
  17. #include "DispPaint.h"
  18. class CMapView3D;
  19. //=============================================================================
  20. #define DISPTOOL_NONE 0
  21. #define DISPTOOL_SELECT 1
  22. #define DISPTOOL_PAINT 2
  23. #define DISPTOOL_SELECT_DISP_FACE 3
  24. #define DISPTOOL_TAG_WALKABLE 4
  25. #define DISPTOOL_TAG_BUILDABLE 5
  26. #define DISPTOOL_PAINT_SCULPT 6
  27. #define DISPPAINT_EFFECT_RAISELOWER 0
  28. #define DISPPAINT_EFFECT_RAISETO 1
  29. #define DISPPAINT_EFFECT_SMOOTH 2
  30. #define DISPPAINT_EFFECT_MODULATE 3
  31. #define DISPPAINT_AXIS_X 0
  32. #define DISPPAINT_AXIS_Y 1
  33. #define DISPPAINT_AXIS_Z 2
  34. #define DISPPAINT_AXIS_SUBDIV 3
  35. #define DISPPAINT_AXIS_FACE 4
  36. #define DISPPAINT_BRUSHTYPE_SOFT 0
  37. #define DISPPAINT_BRUSHTYPE_HARD 1
  38. class CSculptTool;
  39. //=============================================================================
  40. //
  41. // Displacement Tool Class
  42. //
  43. class CToolDisplace : public CBaseTool
  44. {
  45. public:
  46. //=========================================================================
  47. //
  48. // Constructor/Deconstructor
  49. //
  50. CToolDisplace();
  51. ~CToolDisplace();
  52. //=========================================================================
  53. //
  54. // CBaseTool implementation.
  55. //
  56. virtual void OnActivate();
  57. virtual void OnDeactivate();
  58. virtual ToolID_t GetToolID(void) { return TOOL_FACEEDIT_DISP; }
  59. virtual bool OnLMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  60. virtual bool OnLMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  61. virtual bool OnRMouseUp3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  62. virtual bool OnRMouseDown3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  63. virtual bool OnMouseMove3D( CMapView3D *pView, UINT nFlags, const Vector2D &vPoint );
  64. virtual void RenderTool3D( CRender3D *pRender );
  65. //=========================================================================
  66. //
  67. // Attribute Functions
  68. //
  69. inline void SetTool( unsigned int uiTool );
  70. inline unsigned int GetTool( void );
  71. inline void SetEffect( unsigned int uiEffect );
  72. inline unsigned int GetEffect( void );
  73. inline void SetBrushType( unsigned int uiBrushType ) { m_uiBrushType = uiBrushType; }
  74. inline unsigned int GetBrushType( void ) { return m_uiBrushType; }
  75. inline void SetChannel( int iType, float flValue );
  76. inline void GetChannel( int iType, float &flValue );
  77. inline void SetPaintAxis( int iType, Vector const &vecAxis );
  78. inline void GetPaintAxis( int &iType, Vector &vecAxis );
  79. inline CDispMapImageFilterManager *GetFilterRaiseLowerMgr( void );
  80. inline CDispMapImageFilterManager *GetFilterRaiseToMgr( void );
  81. inline CDispMapImageFilterManager *GetFilterSmoothMgr( void );
  82. inline void SetSculptPainter( CSculptTool *Painter ) { m_SculptTool = Painter; }
  83. inline CSculptTool *GetSculptPainter( void ) { return m_SculptTool; }
  84. int GetSelectedDisps( void );
  85. // flags
  86. inline bool GetAutoSew( void );
  87. inline void ToggleAutoSew( void );
  88. inline bool IsNudging( void );
  89. inline void SetSelectMask( bool bSelect );
  90. inline void ToggleSelectMask( void );
  91. inline bool HasSelectMask( void );
  92. inline void SetGridMask( bool bGrid );
  93. inline void ToggleGridMask( void );
  94. inline bool HasGridMask( void );
  95. //=========================================================================
  96. //
  97. // Spatial Painting
  98. //
  99. inline void ToggleSpatialPainting( void );
  100. inline bool IsSpatialPainting( void );
  101. inline void SetSpatialRadius( float flRadius );
  102. inline float GetSpatialRadius( void );
  103. protected:
  104. void ApplyPaintTool( UINT nFlags, const Vector2D &vPoint, CMapDisp *pDisp );
  105. void ApplySpatialPaintTool( UINT nFlags,const Vector2D &vPoint, CMapDisp *pDisp );
  106. void ApplySculptSpatialPaintTool( CMapView3D *pView, UINT nFlags,const Vector2D &vPoint );
  107. void LiftFaceNormal( CMapView3D *pView, const Vector2D &vPoint );
  108. void ResizeSpatialRadius_Activate( CMapView3D *pView );
  109. void ResizeSpatialRadius_Do( void );
  110. void ResizeSpatialRadius_Deactivate( void );
  111. void Nudge_Activate( CMapView3D *pView, EditDispHandle_t dispHandle );
  112. void Nudge_Deactivate( void );
  113. void Nudge_Do( void );
  114. void HandleSelection( CMapView3D *pView, const Vector2D &vPoint );
  115. EditDispHandle_t GetHitPos( CMapView3D *pView, const Vector2D &vPoint );
  116. inline CMapDisp *GetEditDisp( void );
  117. void HandleTagging( CMapView3D *pView, const Vector2D &vPoint );
  118. void HandleTaggingReset( CMapView3D *pView, const Vector2D &vPoint );
  119. private:
  120. void AddFiltersToManagers( void );
  121. bool LoadFilters( const char *filename );
  122. static ChunkFileResult_t LoadFiltersCallback( CChunkFile *pFile, CToolDisplace *pDisplaceTool );
  123. EditDispHandle_t CollideWithSelectedDisps( const Vector &rayStart, const Vector &rayEnd );
  124. bool RayAABBTest( CMapDisp *pDisp, const Vector &rayStart, const Vector &rayEnd );
  125. void BuildParallelepiped( const Vector &boxMin, const Vector &boxMax, PLANE planes[6] );
  126. bool RayPlaneTest( PLANE *pPlane, const Vector& rayStart, const Vector& rayEnd /*, float *fraction*/ );
  127. float DistFromPointToRay( const Vector& rayStart, const Vector& rayEnd, const Vector& point );
  128. inline void UpdateMapViews( CMapView3D *pView );
  129. inline void CalcViewCenter( CMapView3D *pView );
  130. void RenderPaintSphere( CRender3D *pRender );
  131. void RenderHitBox( CRender3D *pRender );
  132. protected:
  133. unsigned int m_uiTool; // active displacement tool
  134. unsigned int m_uiEffect; // active displacement effect
  135. unsigned int m_uiBrushType; // active brush type (soft, hard edged)
  136. CDispMapImageFilterManager m_FilterLoaderMgr; // load all the filters into this manager initially
  137. CDispMapImageFilterManager m_FilterRaiseLowerMgr; // filter manager for raise/lower filters
  138. CDispMapImageFilterManager m_FilterRaiseToMgr; // filter manager for raise to filters
  139. CDispMapImageFilterManager m_FilterSmoothMgr; // filter manager for smoothing filters
  140. int m_iPaintChannel; // the paint channel - distance, alpha, etc...
  141. float m_flPaintValueGeo; // the paint value - scalar distance
  142. float m_flPaintValueData; // the paint value - scalar alpha, etc...
  143. int m_iPaintAxis; // the paint axis type xyz-axis, subdiv normal, face normal
  144. Vector m_vecPaintAxis; // the paint axis vector (for subdiv and face normal)
  145. bool m_bAutoSew; // is the auto-sew functionality enabled
  146. bool m_bSpatial; // painting spatially - set spatial default
  147. float m_flSpatialRadius; // spatial painting radius
  148. bool m_bSpatialRadius; // adjust the spatial radius
  149. bool m_bSelectMaskTool; // show the "red" selection state (true/false)
  150. bool m_bGridMaskTool; // show the displacement overlay (true/false)
  151. bool m_bNudge; // special painting style
  152. bool m_bNudgeInit;
  153. EditDispHandle_t m_EditDispHandle; // displacement currently being nudged or painted on
  154. CPoint m_viewCenter; // center point of the given view
  155. Vector2D m_MousePoint;
  156. bool m_bLMBDown; // left mouse button state
  157. bool m_bRMBDown; // right mouse button state
  158. CDispPaintMgr m_DispPaintMgr; // displacement painting manager
  159. CSculptTool *m_SculptTool;
  160. };
  161. //-----------------------------------------------------------------------------
  162. //-----------------------------------------------------------------------------
  163. inline void CToolDisplace::SetTool( unsigned int uiTool )
  164. {
  165. m_uiTool = uiTool;
  166. }
  167. //-----------------------------------------------------------------------------
  168. //-----------------------------------------------------------------------------
  169. inline unsigned int CToolDisplace::GetTool( void )
  170. {
  171. return m_uiTool;
  172. }
  173. //-----------------------------------------------------------------------------
  174. //-----------------------------------------------------------------------------
  175. inline void CToolDisplace::SetEffect( unsigned int uiEffect )
  176. {
  177. m_uiEffect = uiEffect;
  178. }
  179. //-----------------------------------------------------------------------------
  180. //-----------------------------------------------------------------------------
  181. inline unsigned int CToolDisplace::GetEffect( void )
  182. {
  183. return m_uiEffect;
  184. }
  185. //-----------------------------------------------------------------------------
  186. //-----------------------------------------------------------------------------
  187. inline void CToolDisplace::SetChannel( int iType, float flValue )
  188. {
  189. m_iPaintChannel = iType;
  190. if ( iType == DISPPAINT_CHANNEL_POSITION )
  191. {
  192. m_flPaintValueGeo = flValue;
  193. }
  194. else if ( iType == DISPPAINT_CHANNEL_ALPHA )
  195. {
  196. m_flPaintValueData = flValue;
  197. }
  198. }
  199. //-----------------------------------------------------------------------------
  200. //-----------------------------------------------------------------------------
  201. inline void CToolDisplace::GetChannel( int iType, float &flValue )
  202. {
  203. if ( iType == DISPPAINT_CHANNEL_POSITION )
  204. {
  205. flValue = m_flPaintValueGeo;
  206. }
  207. else if ( iType == DISPPAINT_CHANNEL_ALPHA )
  208. {
  209. flValue = m_flPaintValueData;
  210. }
  211. }
  212. //-----------------------------------------------------------------------------
  213. //-----------------------------------------------------------------------------
  214. inline void CToolDisplace::SetPaintAxis( int iType, Vector const &vecAxis )
  215. {
  216. m_iPaintAxis = iType;
  217. m_vecPaintAxis = vecAxis;
  218. }
  219. //-----------------------------------------------------------------------------
  220. //-----------------------------------------------------------------------------
  221. inline void CToolDisplace::GetPaintAxis( int &iType, Vector &vecAxis )
  222. {
  223. iType = m_iPaintAxis;
  224. vecAxis = m_vecPaintAxis;
  225. }
  226. //-----------------------------------------------------------------------------
  227. //-----------------------------------------------------------------------------
  228. inline CDispMapImageFilterManager *CToolDisplace::GetFilterRaiseLowerMgr( void )
  229. {
  230. return &m_FilterRaiseLowerMgr;
  231. }
  232. //-----------------------------------------------------------------------------
  233. //-----------------------------------------------------------------------------
  234. inline CDispMapImageFilterManager *CToolDisplace::GetFilterRaiseToMgr( void )
  235. {
  236. return &m_FilterRaiseToMgr;
  237. }
  238. //-----------------------------------------------------------------------------
  239. //-----------------------------------------------------------------------------
  240. inline CDispMapImageFilterManager *CToolDisplace::GetFilterSmoothMgr( void )
  241. {
  242. return &m_FilterSmoothMgr;
  243. }
  244. //-----------------------------------------------------------------------------
  245. //-----------------------------------------------------------------------------
  246. inline bool CToolDisplace::GetAutoSew( void )
  247. {
  248. return m_bAutoSew;
  249. }
  250. //-----------------------------------------------------------------------------
  251. //-----------------------------------------------------------------------------
  252. inline void CToolDisplace::ToggleAutoSew( void )
  253. {
  254. m_bAutoSew = !m_bAutoSew;
  255. }
  256. //-----------------------------------------------------------------------------
  257. //-----------------------------------------------------------------------------
  258. inline bool CToolDisplace::IsNudging( void )
  259. {
  260. return m_bNudge;
  261. }
  262. //-----------------------------------------------------------------------------
  263. //-----------------------------------------------------------------------------
  264. inline void CToolDisplace::SetSelectMask( bool bSelect )
  265. {
  266. m_bSelectMaskTool = bSelect;
  267. CMapDisp::SetSelectMask( m_bSelectMaskTool );
  268. }
  269. //-----------------------------------------------------------------------------
  270. //-----------------------------------------------------------------------------
  271. inline void CToolDisplace::ToggleSelectMask( void )
  272. {
  273. m_bSelectMaskTool = !m_bSelectMaskTool;
  274. CMapDisp::SetSelectMask( m_bSelectMaskTool );
  275. }
  276. //-----------------------------------------------------------------------------
  277. //-----------------------------------------------------------------------------
  278. inline bool CToolDisplace::HasSelectMask( void )
  279. {
  280. return m_bSelectMaskTool;
  281. }
  282. //-----------------------------------------------------------------------------
  283. //-----------------------------------------------------------------------------
  284. inline void CToolDisplace::SetGridMask( bool bGrid )
  285. {
  286. m_bGridMaskTool = bGrid;
  287. CMapDisp::SetGridMask( m_bGridMaskTool );
  288. }
  289. //-----------------------------------------------------------------------------
  290. //-----------------------------------------------------------------------------
  291. inline void CToolDisplace::ToggleGridMask( void )
  292. {
  293. m_bGridMaskTool = !m_bGridMaskTool;
  294. CMapDisp::SetGridMask( m_bGridMaskTool );
  295. }
  296. //-----------------------------------------------------------------------------
  297. //-----------------------------------------------------------------------------
  298. inline bool CToolDisplace::HasGridMask( void )
  299. {
  300. return m_bGridMaskTool;
  301. }
  302. //-----------------------------------------------------------------------------
  303. // Purpose: Returns the displacement that we are working on, based on the last
  304. // button down event that we received..
  305. //-----------------------------------------------------------------------------
  306. inline CMapDisp *CToolDisplace::GetEditDisp( void )
  307. {
  308. // sanity check
  309. if ( m_EditDispHandle == EDITDISPHANDLE_INVALID )
  310. return NULL;
  311. return EditDispMgr()->GetDisp( m_EditDispHandle );
  312. }
  313. inline void CToolDisplace::ToggleSpatialPainting( void ) { m_bSpatial = !m_bSpatial; }
  314. inline bool CToolDisplace::IsSpatialPainting( void ) { return m_bSpatial; }
  315. inline void CToolDisplace::SetSpatialRadius( float flRadius ) { m_flSpatialRadius = flRadius; }
  316. inline float CToolDisplace::GetSpatialRadius( void ) { return m_flSpatialRadius; }
  317. #endif // TOOLDISPLACE_H