Team Fortress 2 Source Code as on 22/4/2020
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.

401 lines
14 KiB

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