public async Task <ConvexDecomposition> ComputeAsync(double[] vertices, uint[] triangles, ConvexDecompositionOptions options, CancellationToken cancellationToken = default) => await ComputeAsync(new ArraySegment <double>(vertices), new ArraySegment <uint>(triangles), options, cancellationToken);
public async Task <ConvexDecomposition> ComputeAsync(ArraySegment <double> vertices, ArraySegment <uint> triangles, ConvexDecompositionOptions options, CancellationToken cancellationToken = default) { ThrowIfDisposed(); // Convert decomposition options to unmanaged representation var parameters = ComputeParameters.FromDecompositionOptions(options); // A proper API for OpenCL support isn't exposed yet, // so to be safe it's forced off for now. parameters.m_oclAcceleration = 0u; VHACD_GetUserPointers(handle, out parameters.m_callback, out parameters.m_logger ); // The async Compute() method always returns true, // so we don't need to bother checking its result. VHACD_Compute(handle, in vertices.Array[vertices.Offset], (uint)vertices.Count / 3, in triangles.Array[triangles.Offset], (uint)triangles.Count / 3, in parameters ); // If the token is cancelled, we need to notify the library using (cancellationToken.Register(() => VHACD_Cancel(handle))) { // Unfortunately, the V-HACD API lacks proper completion events, // so we need to resort to a busy-loop, checking the IsReady value. while (!VHACD_IsReady(handle)) { ThrowIfDisposed(); cancellationToken.ThrowIfCancellationRequested(); await Task.Yield(); } } return(new ConvexDecomposition( convexHulls: AllocateConvexHulls(), centerOfMass: ComputeCenterOfMass() )); }
ConvexDecompositionOptions(ConvexDecompositionOptions source) => this = source;