llconvexdecomposition.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /**
  2. * @file LLConvexDecomposition.cpp
  3. * @brief LLConvexDecomposition interface definition
  4. *
  5. * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2011, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_CONVEX_DECOMPOSITION
  27. #define LL_CONVEX_DECOMPOSITION
  28. typedef int bool32;
  29. #if defined(_WIN32) || defined(_WIN64)
  30. #define LLCD_CALL __cdecl
  31. #else
  32. #define LLCD_CALL
  33. #endif
  34. struct LLCDParam
  35. {
  36. enum LLCDParamType
  37. {
  38. LLCD_INVALID = 0,
  39. LLCD_INTEGER,
  40. LLCD_FLOAT,
  41. LLCD_BOOLEAN,
  42. LLCD_ENUM
  43. };
  44. struct LLCDEnumItem
  45. {
  46. const char* mName;
  47. int mValue;
  48. };
  49. union LLCDValue
  50. {
  51. float mFloat;
  52. int mIntOrEnumValue;
  53. bool32 mBool;
  54. };
  55. union LLCDParamDetails
  56. {
  57. struct {
  58. LLCDValue mLow;
  59. LLCDValue mHigh;
  60. LLCDValue mDelta;
  61. } mRange;
  62. struct {
  63. int mNumEnums;
  64. LLCDEnumItem* mEnumsArray;
  65. } mEnumValues;
  66. };
  67. const char* mName;
  68. const char* mDescription;
  69. LLCDParamType mType;
  70. LLCDParamDetails mDetails;
  71. LLCDValue mDefault;
  72. int mStage;
  73. // WARNING: Only the LLConvexDecomposition implementation
  74. // should change this value
  75. int mReserved;
  76. };
  77. struct LLCDStageData
  78. {
  79. const char* mName;
  80. const char* mDescription;
  81. bool32 mSupportsCallback;
  82. };
  83. struct LLCDMeshData
  84. {
  85. enum IndexType
  86. {
  87. INT_16,
  88. INT_32
  89. };
  90. const float* mVertexBase;
  91. int mVertexStrideBytes;
  92. int mNumVertices;
  93. const void* mIndexBase;
  94. IndexType mIndexType;
  95. int mIndexStrideBytes;
  96. int mNumTriangles;
  97. };
  98. struct LLCDHull
  99. {
  100. const float* mVertexBase;
  101. int mVertexStrideBytes;
  102. int mNumVertices;
  103. };
  104. enum LLCDResult
  105. {
  106. LLCD_OK = 0,
  107. LLCD_UNKOWN_ERROR,
  108. LLCD_NULL_PTR,
  109. LLCD_INVALID_STAGE,
  110. LLCD_UNKNOWN_PARAM,
  111. LLCD_BAD_VALUE,
  112. LLCD_REQUEST_OUT_OF_RANGE,
  113. LLCD_INVALID_MESH_DATA,
  114. LLCD_INVALID_HULL_DATA,
  115. LLCD_STAGE_NOT_READY,
  116. LLCD_INVALID_THREAD,
  117. LLCD_NOT_IMPLEMENTED
  118. };
  119. // This callback will receive a string describing the current subtask being performed
  120. // as well as a pair of numbers indicating progress. (The values should not be interpreted
  121. // as a completion percentage as 'current' may be greater than 'final'.)
  122. // If the callback returns zero, the decomposition will be terminated
  123. typedef int (LLCD_CALL *llcdCallbackFunc)(const char* description, int current, int final);
  124. class LLConvexDecomposition
  125. {
  126. public:
  127. // Obtain a pointer to the actual implementation
  128. static LLConvexDecomposition* getInstance();
  129. static LLCDResult initSystem();
  130. static LLCDResult initThread();
  131. static LLCDResult quitThread();
  132. static LLCDResult quitSystem();
  133. // Generate a decomposition object handle
  134. virtual void genDecomposition(int& decomp) = 0;
  135. // Delete decomposition object handle
  136. virtual void deleteDecomposition(int decomp) = 0;
  137. // Bind given decomposition handle
  138. // Commands operate on currently bound decomposition
  139. virtual void bindDecomposition(int decomp) = 0;
  140. // Sets *paramsOut to the address of the LLCDParam array and returns
  141. // the number of parameters
  142. virtual int getParameters(const LLCDParam** paramsOut) = 0;
  143. // Sets *stagesOut to the address of the LLCDStageData array and returns
  144. // the number of stages
  145. virtual int getStages(const LLCDStageData** stagesOut) = 0;
  146. // Set a parameter by name. Pass enum values as integers.
  147. virtual LLCDResult setParam(const char* name, float val) = 0;
  148. virtual LLCDResult setParam(const char* name, int val) = 0;
  149. virtual LLCDResult setParam(const char* name, bool val) = 0;
  150. // Set incoming mesh data. Data is copied to local buffers and will
  151. // persist until the next setMeshData call
  152. virtual LLCDResult setMeshData( const LLCDMeshData* data, bool vertex_based ) = 0;
  153. // Register a callback to be called periodically during the specified stage
  154. // See the typedef above for more information
  155. virtual LLCDResult registerCallback( int stage, llcdCallbackFunc callback ) = 0;
  156. // Execute the specified decomposition stage
  157. virtual LLCDResult executeStage(int stage) = 0;
  158. virtual LLCDResult buildSingleHull() = 0 ;
  159. // Gets the number of hulls generated by the specified decompositions stage
  160. virtual int getNumHullsFromStage(int stage) = 0;
  161. // Populates hullOut to reference the internal copy of the requested hull
  162. // The data will persist only until the next executeStage call for that stage.
  163. virtual LLCDResult getHullFromStage( int stage, int hull, LLCDHull* hullOut ) = 0;
  164. virtual LLCDResult getSingleHull( LLCDHull* hullOut ) = 0 ;
  165. // TODO: Implement lock of some kind to disallow this call if data not yet ready
  166. // Populates the meshDataOut to reference the utility's copy of the mesh geometry
  167. // for the hull and stage specified.
  168. // You must copy this data if you want to continue using it after the next executeStage
  169. // call
  170. virtual LLCDResult getMeshFromStage( int stage, int hull, LLCDMeshData* meshDataOut) = 0;
  171. // Creates a mesh from hullIn and temporarily stores it internally in the utility.
  172. // The mesh data persists only until the next call to getMeshFromHull
  173. virtual LLCDResult getMeshFromHull( LLCDHull* hullIn, LLCDMeshData* meshOut ) = 0;
  174. // Takes meshIn, generates a single convex hull from it, converts that to a mesh
  175. // stored internally, and populates meshOut to reference the internally stored data.
  176. // The data is persistent only until the next call to generateSingleHullMeshFromMesh
  177. virtual LLCDResult generateSingleHullMeshFromMesh( LLCDMeshData* meshIn, LLCDMeshData* meshOut) = 0;
  178. //
  179. /// Debug
  180. virtual void loadMeshData(const char* fileIn, LLCDMeshData** meshDataOut) = 0;
  181. private:
  182. static bool s_isInitialized;
  183. };
  184. // Pull in our trace interface
  185. #include "ndConvexDecomposition.h"
  186. #endif //LL_CONVEX_DECOMPOSITION