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.

67 lines
1.9 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ==========//
  2. //
  3. // Purpose: Mesh simplification entry points for meshutils
  4. //
  5. //=============================================================================//
  6. #ifndef SIMPLIFY_H
  7. #define SIMPLIFY_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlvector.h"
  12. #include "mathlib/vector.h"
  13. #include "mathlib/quadric.h"
  14. #include "meshutils/mesh.h"
  15. // parameters for simplification
  16. struct mesh_simplifyparams_t
  17. {
  18. inline void Defaults()
  19. {
  20. m_flMaxError = 0;
  21. m_nMaxTriangleCount = INT_MAX;
  22. m_nMaxVertexCount = INT_MAX;
  23. m_flOpenEdgePenalty = 2.0f;
  24. m_flIntegrationPenalty = 1.0f;
  25. }
  26. inline void SimplifyToVertexCount( int nMaxVertices )
  27. {
  28. Defaults();
  29. m_nMaxVertexCount = nMaxVertices;
  30. }
  31. inline void SimplifyToTriangleCount( int nMaxTriangles )
  32. {
  33. Defaults();
  34. m_nMaxTriangleCount = nMaxTriangles;
  35. }
  36. inline void SimplifyToMaxError( float flMaxError )
  37. {
  38. Defaults();
  39. m_flMaxError = flMaxError;
  40. }
  41. // NOTE: All of these are active. The helpers above use only one limit but you can set
  42. // multiple limits and simplification will stop when the first limit is reached (e.g. either max error or max vertex count)
  43. float m_flMaxError; // Simplify any edge with less than this much error (units are squared distance)
  44. float m_flOpenEdgePenalty; // scale of error on open edges
  45. float m_flIntegrationPenalty; // scale error each time edges are collapsed and their error functions are summed
  46. int m_nMaxVertexCount; // don't allow more than this many vertices in the output model
  47. int m_nMaxTriangleCount; // don't allow more than this many triangles in the output model
  48. };
  49. struct mesh_simplifyweights_t
  50. {
  51. inline void Defaults()
  52. {
  53. m_pVertexWeights = NULL;
  54. m_nVertexCount = 0;
  55. }
  56. float *m_pVertexWeights;
  57. int m_nVertexCount;
  58. };
  59. void SimplifyMesh( CMesh &meshOut, const CMesh &input, const mesh_simplifyparams_t &params, const mesh_simplifyweights_t *pWeights = NULL );
  60. #endif // SIMPLIFY_H