NvConvexDecomposition.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #ifndef CONVEX_DECOMPOSITION_H
  2. #define CONVEX_DECOMPOSITION_H
  3. /*
  4. NvConvexDecomposition.h : The main interface to the convex decomposition library.
  5. */
  6. /*!
  7. **
  8. ** Copyright (c) 2009 by John W. Ratcliff mailto:[email protected]
  9. **
  10. ** Portions of this source has been released with the PhysXViewer application, as well as
  11. ** Rocket, CreateDynamics, ODF, and as a number of sample code snippets.
  12. **
  13. ** If you find this code useful or you are feeling particularily generous I would
  14. ** ask that you please go to http://www.amillionpixels.us and make a donation
  15. ** to Troy DeMolay.
  16. **
  17. ** DeMolay is a youth group for young men between the ages of 12 and 21.
  18. ** It teaches strong moral principles, as well as leadership skills and
  19. ** public speaking. The donations page uses the 'pay for pixels' paradigm
  20. ** where, in this case, a pixel is only a single penny. Donations can be
  21. ** made for as small as $4 or as high as a $100 block. Each person who donates
  22. ** will get a link to their own site as well as acknowledgement on the
  23. ** donations blog located here http://www.amillionpixels.blogspot.com/
  24. **
  25. ** If you wish to contact me you can use the following methods:
  26. **
  27. ** Skype ID: jratcliff63367
  28. ** Yahoo: jratcliff63367
  29. ** AOL: jratcliff1961
  30. ** email: [email protected]
  31. **
  32. **
  33. ** The MIT license:
  34. **
  35. ** Permission is hereby granted, free of charge, to any person obtaining a copy
  36. ** of this software and associated documentation files (the "Software"), to deal
  37. ** in the Software without restriction, including without limitation the rights
  38. ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  39. ** copies of the Software, and to permit persons to whom the Software is furnished
  40. ** to do so, subject to the following conditions:
  41. **
  42. ** The above copyright notice and this permission notice shall be included in all
  43. ** copies or substantial portions of the Software.
  44. ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  45. ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  46. ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  47. ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  48. ** WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  49. ** CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  50. */
  51. #include "NvSimpleTypes.h"
  52. namespace CONVEX_DECOMPOSITION
  53. {
  54. struct ConvexHullResult
  55. {
  56. NxU32 mVcount; // number of vertices.
  57. NxF32 *mVertices; // vertex positions.
  58. NxU32 mTcount; // number of triangles.
  59. NxU32 *mIndices; // indexed triangle list.
  60. };
  61. class iConvexDecomposition
  62. {
  63. public:
  64. virtual void reset(void) = 0; // reset the input mesh data.
  65. virtual bool addTriangle(const NxF32 *p1,const NxF32 *p2,const NxF32 *p3) = 0; // add the input mesh one triangle at a time.
  66. virtual NxU32 computeConvexDecomposition(NxF32 skinWidth=0, // Skin width on the convex hulls generated
  67. NxU32 decompositionDepth=8, // recursion depth for convex decomposition.
  68. NxU32 maxHullVertices=64, // maximum number of vertices in output convex hulls.
  69. NxF32 concavityThresholdPercent=0.1f, // The percentage of concavity allowed without causing a split to occur.
  70. NxF32 mergeThresholdPercent=30.0f, // The percentage of volume difference allowed to merge two convex hulls.
  71. NxF32 volumeSplitThresholdPercent=0.1f, // The percentage of the total volume of the object above which splits will still occur.
  72. bool useInitialIslandGeneration=true, // whether or not to perform initial island generation on the input mesh.
  73. bool useIslandGeneration=false, // Whether or not to perform island generation at each split. Currently disabled due to bug in RemoveTjunctions
  74. bool useBackgroundThread=true) = 0; // Whether or not to compute the convex decomposition in a background thread, the default is true.
  75. virtual bool isComputeComplete(void) = 0; // if building the convex hulls in a background thread, this returns true if it is complete.
  76. virtual bool cancelCompute(void) = 0; // cause background thread computation to abort early. Will return no results. Use 'isComputeComplete' to confirm the thread is done.
  77. virtual NxU32 getHullCount(void) = 0; // returns the number of convex hulls produced.
  78. virtual bool getConvexHullResult(NxU32 hullIndex,ConvexHullResult &result) = 0; // returns each convex hull result.
  79. protected:
  80. virtual ~iConvexDecomposition(void)
  81. {
  82. }
  83. };
  84. iConvexDecomposition * createConvexDecomposition(void);
  85. void releaseConvexDecomposition(iConvexDecomposition *ic);
  86. }; // end of namespace
  87. #endif