vhacd.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #define HL_NAME(n) heaps_##n
  2. #define ENABLE_VHACD_IMPLEMENTATION 1
  3. #include <VHACD.h>
  4. #include <hl.h>
  5. typedef struct {
  6. VHACD::IVHACD* pInstance;
  7. std::vector<VHACD::IVHACD::ConvexHull> convexHulls;
  8. } vhacd;
  9. struct convex_hull {
  10. vbyte* points;
  11. vbyte* triangles;
  12. int pointCount;
  13. int triangleCount;
  14. double volume;
  15. double centerX;
  16. double centerY;
  17. double centerZ;
  18. int meshId;
  19. double boundsMinX;
  20. double boundsMinY;
  21. double boundsMinZ;
  22. double boundsMaxX;
  23. double boundsMaxY;
  24. double boundsMaxZ;
  25. };
  26. HL_PRIM vhacd* HL_NAME(create_vhacd)() {
  27. return new vhacd{ VHACD::CreateVHACD() };
  28. }
  29. HL_PRIM bool HL_NAME(vhacd_compute)(vhacd* pVhacd, float* pPoints, uint32_t countPoints, uint32_t* pTriangles, uint32_t countTriangle, VHACD::IVHACD::Parameters* pParameters) {
  30. return pVhacd->pInstance->Compute(pPoints, countPoints, pTriangles, countTriangle, *pParameters);
  31. }
  32. HL_PRIM int HL_NAME(vhacd_get_n_convex_hulls)(vhacd* pVhacd) {
  33. return pVhacd->pInstance->GetNConvexHulls();
  34. }
  35. HL_PRIM bool HL_NAME(vhacd_get_convex_hull)(vhacd* pVhacd, int index, convex_hull* pConvexHull) {
  36. pVhacd->convexHulls.emplace_back();
  37. VHACD::IVHACD::ConvexHull& convexHull = pVhacd->convexHulls.back();
  38. if (!pVhacd->pInstance->GetConvexHull(index, convexHull))
  39. return false;
  40. pConvexHull->points = (vbyte*)convexHull.m_points.data();
  41. pConvexHull->pointCount = (int)convexHull.m_points.size();
  42. pConvexHull->triangles = (vbyte*)convexHull.m_triangles.data();
  43. pConvexHull->triangleCount = (int)convexHull.m_triangles.size();
  44. pConvexHull->volume = convexHull.m_volume;
  45. pConvexHull->centerX = convexHull.m_center[0];
  46. pConvexHull->centerY = convexHull.m_center[1];
  47. pConvexHull->centerZ = convexHull.m_center[2];
  48. pConvexHull->meshId = convexHull.m_meshId;
  49. pConvexHull->boundsMinX = convexHull.mBmin[0];
  50. pConvexHull->boundsMinY = convexHull.mBmin[1];
  51. pConvexHull->boundsMinZ = convexHull.mBmin[2];
  52. pConvexHull->boundsMaxX = convexHull.mBmax[0];
  53. pConvexHull->boundsMaxY = convexHull.mBmax[1];
  54. pConvexHull->boundsMaxZ = convexHull.mBmax[2];
  55. return true;
  56. }
  57. HL_PRIM void HL_NAME(vhacd_clean)(vhacd* pVhacd) {
  58. pVhacd->pInstance->Clean();
  59. }
  60. HL_PRIM void HL_NAME(vhacd_release)(vhacd* pVhacd) {
  61. pVhacd->pInstance->Release();
  62. delete pVhacd;
  63. }
  64. #define _VHACD _ABSTRACT(vhacd)
  65. DEFINE_PRIM(_VHACD, create_vhacd, _NO_ARG);
  66. DEFINE_PRIM(_BOOL, vhacd_compute, _VHACD _BYTES _I32 _BYTES _I32 _STRUCT);
  67. DEFINE_PRIM(_I32, vhacd_get_n_convex_hulls, _VHACD);
  68. DEFINE_PRIM(_BOOL, vhacd_get_convex_hull, _VHACD _I32 _STRUCT);
  69. DEFINE_PRIM(_VOID, vhacd_clean, _VHACD);
  70. DEFINE_PRIM(_VOID, vhacd_release, _VHACD);