### TestVHACD Command-Line Example Source: https://github.com/kmammou/v-hacd/blob/master/README.md Example of using the TestVHACD command-line tool with specific tuning parameters for accurate results. This may take a significant amount of time to run. ```bash TestVHACD beshon.obj -e 0.01 -d 15 -r 10000000 -r 128 ``` -------------------------------- ### Install V-HACD on Linux Source: https://github.com/kmammou/v-hacd/blob/master/README.md Instructions for building V-HACD on Linux using CMake. Ensure you are in the 'app' directory before running the commands. ```bash cd app cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build ``` -------------------------------- ### Create Asynchronous V-HACD Instance Source: https://context7.com/kmammou/v-hacd/llms.txt Use `CreateVHACD_ASYNC` to get a non-blocking V-HACD instance. Poll `IsReady()` for completion or implement `IUserCallback::NotifyVHACDComplete()` for notifications. This example demonstrates setting up callbacks and logging for the asynchronous computation. ```cpp #define ENABLE_VHACD_IMPLEMENTATION 1 #include "VHACD.h" #include #include #include // Optional progress + completion callback class MyCallback : public VHACD::IVHACD::IUserCallback { public: void Update(const double overallProgress, const double stageProgress, const char* const stage, const char* operation) override { printf("[%%.0f%%] %%s – %%s (stage %%.0f%%)\n", overallProgress, stage, operation, stageProgress); } // Called from the worker thread when decomposition finishes void NotifyVHACDComplete() override { printf("V-HACD complete!\n"); } }; // Optional logger class MyLogger : public VHACD::IVHACD::IUserLogger { public: void Log(const char* const msg) override { printf("LOG: %%s\n", msg); } }; int main() { float points[] = { /* ... */ }; uint32_t tris[] = { /* ... */ }; uint32_t nPts = /* ... */, nTris = /* ... */; MyCallback cb; MyLogger lg; VHACD::IVHACD* vhacd = VHACD::CreateVHACD_ASYNC(); VHACD::IVHACD::Parameters params; params.m_callback = &cb; params.m_logger = ≶ params.m_maxConvexHulls = 32; params.m_asyncACD = true; // use internal thread pool vhacd->Compute(points, nPts, tris, nTris, params); // Poll until ready (IsReady() also dispatches queued log/progress messages) while (!vhacd->IsReady()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } uint32_t n = vhacd->GetNConvexHulls(); for (uint32_t i = 0; i < n; ++i) { VHACD::IVHACD::ConvexHull ch; vhacd->GetConvexHull(i, ch); // use ch.m_points and ch.m_triangles … } vhacd->Release(); return 0; } ``` -------------------------------- ### Basic V-HACD command-line usage Source: https://context7.com/kmammou/v-hacd/llms.txt Decompose an OBJ file into a specified number of convex hulls using the command-line tool. This is a basic example demonstrating the core functionality. ```bash # Basic usage – decompose bunny.obj into at most 32 hulls ./build/TestVHACD meshes/bunny.obj -h 32 ``` -------------------------------- ### V-HACD command-line usage for high-quality settings Source: https://context7.com/kmammou/v-hacd/llms.txt Apply high-quality decomposition settings for machined parts with sharp angles. This example uses flags to control error threshold, voxel resolution, maximum hulls, and recursion depth. ```bash # High-quality settings for machined parts with sharp angles ./build/TestVHACD meshes/hornbug.obj \ -e 0.01 \ # error threshold 1% -r 10000000 \ # 10 million voxels -h 128 \ # up to 128 hulls -d 15 # recursion depth 15 (64-bit required) ``` -------------------------------- ### IUserCallback Source: https://context7.com/kmammou/v-hacd/llms.txt Interface for receiving progress notifications during the convex decomposition. Implement this interface and provide a pointer via `Parameters::m_callback` to get updates on the decomposition stages and completion. ```APIDOC ## `IUserCallback` — Progress notifications Implement this interface and pass a pointer via `Parameters::m_callback` to receive per-stage progress updates and, in async mode, a completion notification. ```cpp class MyProgress : public VHACD::IVHACD::IUserCallback { public: // Called periodically; in async mode comes from the worker thread. void Update(const double overallProgress, // 0–100 const double stageProgress, // 0–100 within current stage const char* const stage, // e.g. "VOXELIZING_INPUT_MESH" const char* operation) override // sub-operation description { // Simple progress bar int bar = int(overallProgress / 5); printf("\r[%-20.*s] %.0f%% %-30s", bar, "####################", overallProgress, stage); fflush(stdout); } // Async only – called from the worker thread when finished void NotifyVHACDComplete() override { printf("\nDecomposition finished!\n"); m_done = true; } bool m_done{ false }; }; // Usage MyProgress progress; VHACD::IVHACD::Parameters p; p.m_callback = &progress; ``` ``` -------------------------------- ### Run Convex Decomposition with Compute() Source: https://context7.com/kmammou/v-hacd/llms.txt The `Compute` method runs the convex decomposition. It accepts vertex and triangle data, along with parameters for controlling the decomposition process. Use the float or double overload based on your data precision. The return value indicates if the decomposition was started (async) or completed (sync). ```cpp // --- float overload --- bool Compute(const float* const points, const uint32_t countPoints, const uint32_t* const triangles, const uint32_t countTriangles, const Parameters& params); // --- double overload --- bool Compute(const double* const points, const uint32_t countPoints, const uint32_t* const triangles, const uint32_t countTriangles, const Parameters& params); ``` ```cpp // Example — double-precision bunny mesh #include std::vector pts; // filled from your mesh loader std::vector idx; // triangle indices VHACD::IVHACD::Parameters p; p.m_maxConvexHulls = 16; p.m_resolution = 400000; // default p.m_minimumVolumePercentErrorAllowed = 2.0; // 2 % tolerance p.m_maxRecursionDepth = 10; // default p.m_shrinkWrap = true; // fit hull to surface p.m_fillMode = VHACD::FillMode::FLOOD_FILL; // default, works for closed meshes // p.m_fillMode = VHACD::FillMode::RAYCAST_FILL; // use for meshes with holes // p.m_fillMode = VHACD::FillMode::SURFACE_ONLY; // hollow / skin-only VHACD::IVHACD* vhacd = VHACD::CreateVHACD(); bool ok = vhacd->Compute(pts.data(), uint32_t(pts.size() / 3), idx.data(), uint32_t(idx.size() / 3), p); // ok == true → decomposition complete, results available ``` -------------------------------- ### IVHACD::Compute() Source: https://context7.com/kmammou/v-hacd/llms.txt Runs the convex decomposition using either float or double precision. It accepts interleaved vertex arrays and a triangle index array. The method returns true if the decomposition was started successfully (for async) or completed successfully (for sync). ```APIDOC ## `IVHACD::Compute()` — Run the convex decomposition (float or double overload) Accepts flat interleaved vertex arrays (`X,Y,Z,X,Y,Z,...`) in either `float` or `double` precision together with a flat triangle index array. Returns `true` when decomposition was started successfully (for async) or completed successfully (for sync). ```cpp // --- float overload --- bool Compute(const float* const points, const uint32_t countPoints, const uint32_t* const triangles, const uint32_t countTriangles, const Parameters& params); // --- double overload --- bool Compute(const double* const points, const uint32_t countPoints, const uint32_t* const triangles, const uint32_t countTriangles, const Parameters& params); // Example — double-precision bunny mesh #include std::vector pts; // filled from your mesh loader std::vector idx; // triangle indices VHACD::IVHACD::Parameters p; p.m_maxConvexHulls = 16; p.m_resolution = 400000; // default p.m_minimumVolumePercentErrorAllowed = 2.0; // 2 % tolerance p.m_maxRecursionDepth = 10; // default p.m_shrinkWrap = true; // fit hull to surface p.m_fillMode = VHACD::FillMode::FLOOD_FILL; // default, works for closed meshes // p.m_fillMode = VHACD::FillMode::RAYCAST_FILL; // use for meshes with holes // p.m_fillMode = VHACD::FillMode::SURFACE_ONLY; // hollow / skin-only VHACD::IVHACD* vhacd = VHACD::CreateVHACD(); bool ok = vhacd->Compute(pts.data(), uint32_t(pts.size() / 3), idx.data(), uint32_t(idx.size() / 3), p); // ok == true → decomposition complete, results available ``` ``` -------------------------------- ### Create and Use V-HACD Instance Source: https://context7.com/kmammou/v-hacd/llms.txt Demonstrates creating a synchronous V-HACD instance, setting decomposition parameters, computing convex hulls from mesh data, and retrieving hull information. Ensure ENABLE_VHACD_IMPLEMENTATION is defined in one .cpp file before including VHACD.h. Call Release() when done. ```cpp #define ENABLE_VHACD_IMPLEMENTATION 1 #include "VHACD.h" int main() { // --- mesh data (flat arrays: X0,Y0,Z0, X1,Y1,Z1, ...) float points[] = { -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, -1, // bottom face -1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1 // top face }; uint32_t triangles[] = { 0,1,2, 0,2,3, // bottom 4,6,5, 4,7,6, // top 0,4,1, 1,4,5, // front 2,6,3, 3,6,7, // back 0,3,4, 3,7,4, // left 1,5,2, 2,5,6 // right }; const uint32_t nPoints = 8; const uint32_t nTriangles = 12; VHACD::IVHACD* vhacd = VHACD::CreateVHACD(); VHACD::IVHACD::Parameters params; params.m_maxConvexHulls = 8; // at most 8 output hulls params.m_resolution = 100000; // voxel resolution params.m_minimumVolumePercentErrorAllowed = 1.0; // stop if error < 1% bool ok = vhacd->Compute(points, nPoints, triangles, nTriangles, params); if (!ok) { vhacd->Release(); return 1; } uint32_t hullCount = vhacd->GetNConvexHulls(); printf("Produced %u convex hulls\n", hullCount); // e.g. "Produced 1 convex hulls" for (uint32_t i = 0; i < hullCount; ++i) { VHACD::IVHACD::ConvexHull ch; vhacd->GetConvexHull(i, ch); printf(" Hull %u: %zu vertices, %zu triangles, volume=%f\n", i, ch.m_points.size(), ch.m_triangles.size(), ch.m_volume); // ch.m_points : std::vector (double x,y,z) // ch.m_triangles: std::vector (uint32 i0,i1,i2) // ch.m_center : centroid VHACD::Vect3 // ch.mBmin/mBmax: AABB corners } vhacd->Clean(); // free internal buffers vhacd->Release(); // delete the instance return 0; } ``` -------------------------------- ### Build V-HACD command-line tool (Linux) Source: https://context7.com/kmammou/v-hacd/llms.txt Compile the standalone command-line application from the `app/` directory. This tool can process Wavefront OBJ input and export to OBJ, STL, or USD formats. ```bash # Build (Linux) cd app cmake -S . -B build -DCMAKE_BUILD_TYPE=Release cmake --build build ``` -------------------------------- ### Configure VHACD Parameters Source: https://context7.com/kmammou/v-hacd/llms.txt Set decomposition parameters for v-hacd. Adjust quality, output, and experimental settings as needed. Ensure callbacks are correctly assigned if used. ```cpp VHACD::IVHACD::Parameters params; // --- quality / count --- params.m_maxConvexHulls = 64; // upper bound on output hulls (default 64) params.m_resolution = 400000;// voxel grid size (default 400 000) params.m_minimumVolumePercentErrorAllowed = 1.0; // stop splitting if hull error < 1% (default) params.m_maxRecursionDepth = 10; // binary-tree depth (default 10, max practical ~15) params.m_minEdgeLength = 2; // min voxel edge before stopping recursion // --- output quality --- params.m_maxNumVerticesPerCH = 64; // max vertices per output convex hull (default 64) params.m_shrinkWrap = true;// project hull vertices onto source mesh (default true) // --- experimental --- params.m_findBestPlane = false; // scan for highest-concavity split (slower, default false) // --- execution --- params.m_asyncACD = true; // use internal thread pool (default true) // --- callbacks (all optional) --- params.m_callback = &myCallback; // IVHACD::IUserCallback* params.m_logger = &myLogger; // IVHACD::IUserLogger* params.m_taskRunner = &myTaskRunner; // IVHACD::IUserTaskRunner* (custom threads) ``` -------------------------------- ### Add Executable Target Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Defines the main executable target 'TestVHACD' and lists its source files. Ensure all listed source files exist. ```cmake add_executable(TestVHACD TestVHACD.cpp FloatMath.cpp InParser.cpp wavefront.cpp SaveUSDA.cpp) ``` -------------------------------- ### CreateVHACD_ASYNC() Source: https://context7.com/kmammou/v-hacd/llms.txt Creates an asynchronous V-HACD instance that returns a non-blocking IVHACD pointer. The Compute() method returns immediately, and users can poll IsReady() for completion or implement IUserCallback::NotifyVHACDComplete() for notifications. ```APIDOC ## `CreateVHACD_ASYNC()` — Create an asynchronous V-HACD instance Returns a non-blocking `IVHACD*`. `Compute()` returns immediately; use `IsReady()` to poll for completion or implement `IUserCallback::NotifyVHACDComplete()` to receive a thread-safe notification. ```cpp #define ENABLE_VHACD_IMPLEMENTATION 1 #include "VHACD.h" #include #include #include // Optional progress + completion callback class MyCallback : public VHACD::IVHACD::IUserCallback { public: void Update(const double overallProgress, const double stageProgress, const char* const stage, const char* operation) override { printf("[%%.0f%%] %%s – %%s (stage %%.0f%%)\n", overallProgress, stage, operation, stageProgress); } // Called from the worker thread when decomposition finishes void NotifyVHACDComplete() override { printf("V-HACD complete!\n"); } }; // Optional logger class MyLogger : public VHACD::IVHACD::IUserLogger { public: void Log(const char* const msg) override { printf("LOG: %%s\n", msg); } }; int main() { float points[] = { /* ... */ }; uint32_t tris[] = { /* ... */ }; uint32_t nPts = /* ... */, nTris = /* ... */; MyCallback cb; MyLogger lg; VHACD::IVHACD* vhacd = VHACD::CreateVHACD_ASYNC(); VHACD::IVHACD::Parameters params; params.m_callback = &cb; params.m_logger = ≶ params.m_maxConvexHulls = 32; params.m_asyncACD = true; // use internal thread pool vhacd->Compute(points, nPts, tris, nTris, params); // Poll until ready (IsReady() also dispatches queued log/progress messages) while (!vhacd->IsReady()) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); } uint32_t n = vhacd->GetNConvexHulls(); for (uint32_t i = 0; i < n; ++i) { VHACD::IVHACD::ConvexHull ch; vhacd->GetConvexHull(i, ch); // use ch.m_points and ch.m_triangles … } vhacd->Release(); return 0; } ``` ``` -------------------------------- ### Set Include Directories Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Adds a public include directory for the 'TestVHACD' target. This makes the '../include' directory available for header files. ```cmake target_include_directories(TestVHACD PUBLIC "../include") ``` -------------------------------- ### Include V-HACD Implementation Header Source: https://github.com/kmammou/v-hacd/blob/master/README.md To use V-HACD, define ENABLE_VHACD_IMPLEMENTATION before including VHACD.h in one CPP file. This is the sole method of integration as there are no separate libraries or CPP files. ```c++ #define ENABLE_VHACD_IMPLEMENTATION 1 #include "VHACD.h" ``` -------------------------------- ### Implement User Callback for Progress Source: https://context7.com/kmammou/v-hacd/llms.txt Implement the IUserCallback interface to receive progress notifications during decomposition. Use Update for periodic status and NotifyVHACDComplete for async completion. ```cpp class MyProgress : public VHACD::IVHACD::IUserCallback { public: // Called periodically; in async mode comes from the worker thread. void Update(const double overallProgress, // 0–100 const double stageProgress, // 0–100 within current stage const char* const stage, // e.g. "VOXELIZING_INPUT_MESH" const char* operation) override // sub-operation description { // Simple progress bar int bar = int(overallProgress / 5); printf("\r[%-20.*s] %.0f%% %-30s", bar, "####################", overallProgress, stage); fflush(stdout); } // Async only – called from the worker thread when finished void NotifyVHACDComplete() override { printf("\nDecomposition finished!\n"); m_done = true; } bool m_done{ false }; }; // Usage MyProgress progress; VHACD::IVHACD::Parameters p; p.m_callback = &progress; ``` -------------------------------- ### Set C++ Standard Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Configures the C++ standard to C++11 and enforces its usage. C++ extensions are disabled. ```cmake set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) ``` -------------------------------- ### CreateVHACD() Source: https://context7.com/kmammou/v-hacd/llms.txt Creates a synchronous V-HACD instance that performs decomposition on the calling thread. The instance should be released using `Release()` when no longer needed. ```APIDOC ## CreateVHACD() ### Description Creates a synchronous V-HACD instance that runs the decomposition on the calling thread. Call `Release()` when done to free the instance. ### Method `VHACD::CreateVHACD()` ### Parameters None ### Request Example ```cpp #define ENABLE_VHACD_IMPLEMENTATION 1 #include "VHACD.h" // ... mesh data setup ... VHACD::IVHACD* vhacd = VHACD::CreateVHACD(); // ... compute and process hulls ... vhacd->Release(); // Release the instance when done ``` ### Response Returns a blocking `IVHACD*` instance. ### Success Response (200) `VHACD::IVHACD*` - A pointer to the V-HACD interface. ### Response Example (See Request Example for usage) ``` -------------------------------- ### IVHACD::Parameters Source: https://context7.com/kmammou/v-hacd/llms.txt Configuration options for tuning the convex decomposition process. These parameters control aspects like the maximum number of convex hulls, resolution, minimum volume error, recursion depth, and output quality. ```APIDOC ## IVHACD::Parameters — Tuning the decomposition All members have sensible defaults; only override what you need. ```cpp VHACD::IVHACD::Parameters params; // --- quality / count --- params.m_maxConvexHulls = 64; // upper bound on output hulls (default 64) params.m_resolution = 400000; // voxel grid size (default 400 000) params.m_minimumVolumePercentErrorAllowed = 1.0; // stop splitting if hull error < 1% (default) params.m_maxRecursionDepth = 10; // binary-tree depth (default 10, max practical ~15) params.m_minEdgeLength = 2; // min voxel edge before stopping recursion // --- output quality --- params.m_maxNumVerticesPerCH = 64; // max vertices per output convex hull (default 64) params.m_shrinkWrap = true; // project hull vertices onto source mesh (default true) // --- experimental --- params.m_findBestPlane = false; // scan for highest-concavity split (slower, default false) // --- execution --- params.m_asyncACD = true; // use internal thread pool (default true) // --- callbacks (all optional) --- params.m_callback = &myCallback; // IVHACD::IUserCallback* params.m_logger = &myLogger; // IVHACD::IUserLogger* params.m_taskRunner = &myTaskRunner; // IVHACD::IUserTaskRunner* (custom threads) ``` ``` -------------------------------- ### Project Definition Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Defines the project name, version, and supported languages. This is essential for CMake to identify and manage the project. ```cmake project(TestVHACD VERSION 1.23.0 LANGUAGES C CXX) ``` -------------------------------- ### V-HACD command-line tool flags Source: https://context7.com/kmammou/v-hacd/llms.txt Reference for available flags in the V-HACD command-line tool. These flags control various aspects of the convex decomposition process, including hull count, resolution, error tolerance, and output format. ```bash # Available flags: # -h max convex hulls (default 64) # -r voxel resolution (default 400000) # -e min volume percent error (default 1.0) # -d max recursion depth (default 10) # -v max vertices per hull (default 64) # -s t/f shrink-wrap hull vertices (default true) # -p t/f find best split plane (default false, experimental) # -f flood|raycast|surface fill mode (default flood) # -o obj|stl|usda export format ``` -------------------------------- ### Implement IUserLogger for custom logging Source: https://context7.com/kmammou/v-hacd/llms.txt Override the IUserLogger interface to redirect V-HACD's diagnostic messages to a custom output, such as stderr. This is useful for debugging and monitoring the decomposition process. ```cpp class MyLogger : public VHACD::IVHACD::IUserLogger { public: void Log(const char* const msg) override { fprintf(stderr, "[V-HACD] %s\n", msg); // Example messages: // "[V-HACD] Skipped 3 degenerate triangles" // "[V-HACD] Convex Decomposition took 0.42310 seconds" } }; VHACD::IVHACD::Parameters p; p.m_logger = new MyLogger(); ``` -------------------------------- ### Implement IUserTaskRunner for custom threading Source: https://context7.com/kmammou/v-hacd/llms.txt Replace the default threading backend with a custom implementation by overriding the IUserTaskRunner interface. This allows integration with engine-specific thread pools, such as UE5's task graph. ```cpp class EngineTaskRunner : public VHACD::IVHACD::IUserTaskRunner { public: // Launch func() in a background thread; return an opaque handle void* StartTask(std::function func) override { auto* t = new std::thread(std::move(func)); return static_cast(t); } // Block until the task with handle 'Task' is complete void JoinTask(void* Task) override { auto* t = static_cast(Task); t->join(); delete t; } }; EngineTaskRunner runner; VHACD::IVHACD::Parameters p; p.m_taskRunner = &runner; ``` -------------------------------- ### Release() Source: https://context7.com/kmammou/v-hacd/llms.txt Releases the V-HACD instance, freeing all associated memory. This is the final step after using the V-HACD object. ```APIDOC ## Release() ### Description Releases the V-HACD instance, freeing all associated memory. This is the final step after using the V-HACD object. ### Method `void Release()` ### Parameters None ### Request Example ```cpp vhacd->Release(); ``` ### Response None ### Success Response (200) None ``` -------------------------------- ### Clean() Source: https://context7.com/kmammou/v-hacd/llms.txt Frees internal buffers and resources used by the V-HACD instance. ```APIDOC ## Clean() ### Description Frees internal buffers and resources used by the V-HACD instance. This should be called before `Release()` if the instance was used for computation. ### Method `void Clean()` ### Parameters None ### Request Example ```cpp vhacd->Clean(); ``` ### Response None ### Success Response (200) None ``` -------------------------------- ### Link Libraries Conditionally Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Links the 'pthread' library to the 'TestVHACD' target on non-Windows systems. This is necessary for threading support on platforms like Linux. ```cmake if (WIN32) else (WIN32) target_link_libraries(TestVHACD pthread) endif (WIN32) ``` -------------------------------- ### Configure FillMode for voxel interior classification Source: https://context7.com/kmammou/v-hacd/llms.txt Select how the interior of a voxelized mesh is determined before decomposition. Choose between FLOOD_FILL (fast, for watertight meshes), RAYCAST_FILL (robust, for meshes with holes), and SURFACE_ONLY (for hollow meshes). ```cpp // FLOOD_FILL (default) — fast BFS from the exterior; fails on non-watertight meshes params.m_fillMode = VHACD::FillMode::FLOOD_FILL; // RAYCAST_FILL — cast 6 rays per voxel; robust for meshes with holes params.m_fillMode = VHACD::FillMode::RAYCAST_FILL; // SURFACE_ONLY — treat the mesh as hollow; only surface voxels are considered params.m_fillMode = VHACD::FillMode::SURFACE_ONLY; // Practical guidance: // • Simple watertight mesh → FLOOD_FILL (fastest) // • CAD part / mesh with small holes → RAYCAST_FILL // • Shell / fabric simulation → SURFACE_ONLY ``` -------------------------------- ### Set Minimum CMake Version Source: https://github.com/kmammou/v-hacd/blob/master/app/CMakeLists.txt Specifies the minimum version of CMake required for this project. Ensure your CMake version meets this requirement. ```cmake cmake_minimum_required(VERSION 3.10) ``` -------------------------------- ### Compute() Source: https://context7.com/kmammou/v-hacd/llms.txt Computes the convex decomposition of the input mesh using the specified parameters. This is a blocking operation. ```APIDOC ## Compute() ### Description Computes the convex decomposition of the input mesh using the specified parameters. This is a blocking operation. ### Method `bool Compute(const float* const points, const uint32_t numPoints, const uint32_t* const triangles, const uint32_t numTriangles, const Parameters& params)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **points** (const float* const) - Required - Flat array of vertex coordinates (X0, Y0, Z0, X1, Y1, Z1, ...). - **numPoints** (uint32_t) - Required - The total number of vertices. - **triangles** (const uint32_t* const) - Required - Flat array of triangle indices (I0, I1, I2, I0, I1, I2, ...). - **numTriangles** (uint32_t) - Required - The total number of triangles. - **params** (const Parameters&) - Required - A struct containing decomposition parameters like `m_maxConvexHulls`, `m_resolution`, etc. ### Request Example ```cpp VHACD::IVHACD::Parameters params; params.m_maxConvexHulls = 8; params.m_resolution = 100000; bool ok = vhacd->Compute(points, nPoints, triangles, nTriangles, params); ``` ### Response Returns `true` if the computation was successful, `false` otherwise. ### Success Response (200) `bool` - `true` on success, `false` on failure. ### Response Example ``` true ``` ``` -------------------------------- ### GetNConvexHulls() Source: https://context7.com/kmammou/v-hacd/llms.txt Retrieves the number of convex hulls generated by the decomposition process. ```APIDOC ## GetNConvexHulls() ### Description Retrieves the number of convex hulls generated by the decomposition process. ### Method `uint32_t GetNConvexHulls() const` ### Parameters None ### Request Example ```cpp uint32_t hullCount = vhacd->GetNConvexHulls(); printf("Produced %u convex hulls\n", hullCount); ``` ### Response Returns the count of generated convex hulls. ### Success Response (200) `uint32_t` - The number of convex hulls. ### Response Example ``` 1 ``` ``` -------------------------------- ### GetConvexHull() Source: https://context7.com/kmammou/v-hacd/llms.txt Retrieves the details of a specific convex hull by its index. ```APIDOC ## GetConvexHull() ### Description Retrieves the details of a specific convex hull by its index. ### Method `void GetConvexHull(const uint32_t index, IVHACD::ConvexHull& convexHull) const` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **index** (uint32_t) - Required - The index of the convex hull to retrieve. - **convexHull** (IVHACD::ConvexHull&) - Required - An output struct to populate with the convex hull data. ### Request Example ```cpp VHACD::IVHACD::ConvexHull ch; vhacd->GetConvexHull(i, ch); ``` ### Response Populates the provided `convexHull` struct with data for the specified hull. ### Success Response (200) `IVHACD::ConvexHull` - A struct containing hull details: - **m_points**: `std::vector` (double x,y,z) - **m_triangles**: `std::vector` (uint32 i0,i1,i2) - **m_center**: `VHACD::Vect3` (centroid) - **m_Bmin/m_Bmax**: AABB corners ### Response Example ``` { "m_points": [ {"x": 0.0, "y": 0.0, "z": 0.0}, // ... other vertices ], "m_triangles": [ {"i0": 0, "i1": 1, "i2": 2}, // ... other triangles ], "m_center": {"x": 0.0, "y": 0.0, "z": 0.0}, "m_Bmin": {"x": -1.0, "y": -1.0, "z": -1.0}, "m_Bmax": {"x": 1.0, "y": 1.0, "z": 1.0} } ``` ``` -------------------------------- ### Find Nearest Convex Hull Source: https://context7.com/kmammou/v-hacd/llms.txt Locate the index and distance of the convex hull nearest to a given world-space position. Useful for mapping mesh vertices to physics materials. ```cpp double pos[3] = { 0.5, 1.2, -0.3 }; double distanceToHull; uint32_t hullIndex = vhacd->findNearestConvexHull(pos, distanceToHull); printf("Position (%.2f, %.2f, %.2f) is closest to hull %u (dist=%.4f)\n", pos[0], pos[1], pos[2], hullIndex, distanceToHull); // Expected output: "Position (0.50, 1.20, -0.30) is closest to hull 2 (dist=0.0312)" ``` -------------------------------- ### IVHACD::GetConvexHull() / GetNConvexHulls() Source: https://context7.com/kmammou/v-hacd/llms.txt Retrieve the computed convex hulls after the decomposition process. `GetNConvexHulls()` returns the total count, and `GetConvexHull(index, out_hull)` retrieves the details of a specific hull, including vertices, triangles, volume, centroid, and bounding box. ```APIDOC ## `IVHACD::GetConvexHull()` / `GetNConvexHulls()` — Retrieve results Iterate over all output hulls after `Compute()` returns (sync) or after `IsReady()` is `true` (async). ```cpp uint32_t n = vhacd->GetNConvexHulls(); for (uint32_t i = 0; i < n; ++i) { VHACD::IVHACD::ConvexHull ch; if (!vhacd->GetConvexHull(i, ch)) continue; // index out of range // Vertex buffer (double precision) for (const VHACD::Vertex& v : ch.m_points) printf(" v %f %f %f\n", v.mX, v.mY, v.mZ); // Index buffer for (const VHACD::Triangle& t : ch.m_triangles) printf(" f %u %u %u\n", t.mI0, t.mI1, t.mI2); printf(" volume = %f\n", ch.m_volume); printf(" centroid = (%f, %f, %f)\n", ch.m_center.GetX(), ch.m_center.GetY(), ch.m_center.GetZ()); printf(" AABB min = (%f, %f, %f)\n", ch.mBmin.GetX(), ch.mBmin.GetY(), ch.mBmin.GetZ()); printf(" AABB max = (%f, %f, %f)\n", ch.mBmax.GetX(), ch.mBmax.GetY(), ch.mBmax.GetZ()); } ``` ``` -------------------------------- ### Updated IUserCallback Update Function Signature Source: https://github.com/kmammou/v-hacd/blob/master/README.md The Update function signature in IUserCallback has been slightly modified. Ensure your implementation matches the new signature for progress reporting during V-HACD operations. ```c++ virtual void Update(const double overallProgress, const double stageProgress, const char* const stage,const char *operation) final ``` -------------------------------- ### Retrieve Convex Hulls Source: https://context7.com/kmammou/v-hacd/llms.txt Iterate through computed convex hulls to access their vertices, triangles, volume, centroid, and AABB. Handles potential index out-of-range errors. ```cpp uint32_t n = vhacd->GetNConvexHulls(); for (uint32_t i = 0; i < n; ++i) { VHACD::IVHACD::ConvexHull ch; if (!vhacd->GetConvexHull(i, ch)) continue; // index out of range // Vertex buffer (double precision) for (const VHACD::Vertex& v : ch.m_points) printf(" v %f %f %f\n", v.mX, v.mY, v.mZ); // Index buffer for (const VHACD::Triangle& t : ch.m_triangles) printf(" f %u %u %u\n", t.mI0, t.mI1, t.mI2); printf(" volume = %f\n", ch.m_volume); printf(" centroid = (%f, %f, %f)", ch.m_center.GetX(), ch.m_center.GetY(), ch.m_center.GetZ()); printf(" AABB min = (%f, %f, %f)", ch.mBmin.GetX(), ch.mBmin.GetY(), ch.mBmin.GetZ()); printf(" AABB max = (%f, %f, %f)", ch.mBmax.GetX(), ch.mBmax.GetY(), ch.mBmax.GetZ()); } ``` -------------------------------- ### IVHACD::findNearestConvexHull() Source: https://context7.com/kmammou/v-hacd/llms.txt Efficiently find the index of the convex hull closest to a given world-space position. This is useful for tasks like assigning physics materials to mesh vertices based on their proximity to specific hulls. ```APIDOC ## `IVHACD::findNearestConvexHull()` — Spatial hull lookup Given a world-space position, returns the index of the output hull closest to that position and the distance to it. Useful for mapping source mesh vertices to their most-likely hull for physics material assignment. ```cpp double pos[3] = { 0.5, 1.2, -0.3 }; double distanceToHull; uint32_t hullIndex = vhacd->findNearestConvexHull(pos, distanceToHull); printf("Position (%.2f, %.2f, %.2f) is closest to hull %u (dist=%.4f)\n", pos[0], pos[1], pos[2], hullIndex, distanceToHull); // Expected output: "Position (0.50, 1.20, -0.30) is closest to hull 2 (dist=0.0312)" ``` ``` -------------------------------- ### Cancel Decomposition Source: https://context7.com/kmammou/v-hacd/llms.txt Interrupt an ongoing v-hacd decomposition safely from any thread. The async worker thread exits cleanly, and the sync variant aborts on the next check. ```cpp // Example: cancel via key press while async decomposition runs VHACD::IVHACD* vhacd = VHACD::CreateVHACD_ASYNC(); vhacd->Compute(/* ... */); // in another thread / event loop: if (userPressedEscape) { vhacd->Cancel(); // signal cancellation while (!vhacd->IsReady()) // wait for worker to finish std::this_thread::yield(); printf("Canceled. No results available.\n"); } vhacd->Release(); ``` -------------------------------- ### IVHACD::Cancel() Source: https://context7.com/kmammou/v-hacd/llms.txt Interrupt an in-progress convex decomposition. This method is safe to call from any thread and ensures a clean exit for asynchronous operations or an abort for synchronous ones. ```APIDOC ## `IVHACD::Cancel()` — Interrupt an in-progress decomposition Safe to call from any thread. For the async variant the background thread will exit cleanly; for the sync variant it will abort on the next internal check. ```cpp // Example: cancel via key press while async decomposition runs VHACD::IVHACD* vhacd = VHACD::CreateVHACD_ASYNC(); vhacd->Compute(/* ... */); // in another thread / event loop: if (userPressedEscape) { vhacd->Cancel(); // signal cancellation while (!vhacd->IsReady()) // wait for worker to finish std::this_thread::yield(); printf("Canceled. No results available.\n"); } vhacd->Release(); ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.