From e1243e618644e4760f6dae9286b8878982407767 Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Sun, 8 Dec 2024 06:09:05 +0100 Subject: [PATCH] Add package content. --- Runtime.meta | 8 ++ Runtime/LICENSE.MD | 29 +++++ Runtime/LICENSE.MD.meta | 7 ++ Runtime/VHACD.cs | 192 +++++++++++++++++++++++++++++++++ Runtime/VHACD.cs.meta | 11 ++ Runtime/liblibvhacd.dylib | 3 + Runtime/liblibvhacd.dylib.meta | 32 ++++++ Runtime/liblibvhacd.so | 3 + Runtime/liblibvhacd.so.meta | 80 ++++++++++++++ Runtime/libvhacd.dll | 3 + Runtime/libvhacd.dll.meta | 75 +++++++++++++ Runtime/vhacd.asmdef | 15 +++ Runtime/vhacd.asmdef.meta | 7 ++ package.json | 9 ++ package.json.meta | 7 ++ 15 files changed, 481 insertions(+) create mode 100644 Runtime.meta create mode 100644 Runtime/LICENSE.MD create mode 100644 Runtime/LICENSE.MD.meta create mode 100644 Runtime/VHACD.cs create mode 100644 Runtime/VHACD.cs.meta create mode 100644 Runtime/liblibvhacd.dylib create mode 100644 Runtime/liblibvhacd.dylib.meta create mode 100644 Runtime/liblibvhacd.so create mode 100644 Runtime/liblibvhacd.so.meta create mode 100644 Runtime/libvhacd.dll create mode 100644 Runtime/libvhacd.dll.meta create mode 100644 Runtime/vhacd.asmdef create mode 100644 Runtime/vhacd.asmdef.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..2079e8d --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 926c2a7dc7f1546b9926e929b2feb39c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/LICENSE.MD b/Runtime/LICENSE.MD new file mode 100644 index 0000000..6706bf7 --- /dev/null +++ b/Runtime/LICENSE.MD @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2011, Khaled Mamou (kmamou at gmail dot com) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/Runtime/LICENSE.MD.meta b/Runtime/LICENSE.MD.meta new file mode 100644 index 0000000..124aca1 --- /dev/null +++ b/Runtime/LICENSE.MD.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 7251e877ef5d543d2b72461f9b0019e3 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/VHACD.cs b/Runtime/VHACD.cs new file mode 100644 index 0000000..8f06f79 --- /dev/null +++ b/Runtime/VHACD.cs @@ -0,0 +1,192 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using UnityEngine; + +namespace MeshProcess +{ + public class VHACD : MonoBehaviour + { + [System.Serializable] + public unsafe struct Parameters + { + public void Init() + { + m_resolution = 100000; + m_concavity = 0.001; + m_planeDownsampling = 4; + m_convexhullDownsampling = 4; + m_alpha = 0.05; + m_beta = 0.05; + m_pca = 0; + m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based + m_maxNumVerticesPerCH = 64; + m_minVolumePerCH = 0.0001; + m_callback = null; + m_logger = null; + m_convexhullApproximation = 1; + m_oclAcceleration = 0; + m_maxConvexHulls = 1024; + m_projectHullVertices = true; // This will project the output convex hull vertices onto the original source mesh to increase the floating point accuracy of the results + } + + [Tooltip("maximum concavity")] + [Range(0, 1)] + public double m_concavity; + + [Tooltip("controls the bias toward clipping along symmetry planes")] + [Range(0, 1)] + public double m_alpha; + + [Tooltip("controls the bias toward clipping along revolution axes")] + [Range(0, 1)] + public double m_beta; + + [Tooltip("controls the adaptive sampling of the generated convex-hulls")] + [Range(0, 0.01f)] + public double m_minVolumePerCH; + + public void* m_callback; + public void* m_logger; + + [Tooltip("maximum number of voxels generated during the voxelization stage")] + [Range(10000, 64000000)] + public uint m_resolution; + + [Tooltip("controls the maximum number of triangles per convex-hull")] + [Range(4, 1024)] + public uint m_maxNumVerticesPerCH; + + [Tooltip("controls the granularity of the search for the \"best\" clipping plane")] + [Range(1, 16)] + public uint m_planeDownsampling; + + [Tooltip("controls the precision of the convex-hull generation process during the clipping plane selection stage")] + [Range(1, 16)] + public uint m_convexhullDownsampling; + + [Tooltip("enable/disable normalizing the mesh before applying the convex decomposition")] + [Range(0, 1)] + public uint m_pca; + + [Tooltip("0: voxel-based (recommended), 1: tetrahedron-based")] + [Range(0, 1)] + public uint m_mode; + + [Range(0, 1)] + public uint m_convexhullApproximation; + + [Range(0, 1)] + public uint m_oclAcceleration; + + public uint m_maxConvexHulls; + + [Tooltip("This will project the output convex hull vertices onto the original source mesh to increase the floating point accuracy of the results")] + public bool m_projectHullVertices; + }; + + unsafe struct ConvexHull + { + public double* m_points; + public uint* m_triangles; + public uint m_nPoints; + public uint m_nTriangles; + public double m_volume; + public fixed double m_center[3]; + }; + + [DllImport("libvhacd")] static extern unsafe void* CreateVHACD(); + + [DllImport("libvhacd")] static extern unsafe void DestroyVHACD(void* pVHACD); + + [DllImport("libvhacd")] + static extern unsafe bool ComputeFloat( + void* pVHACD, + float* points, + uint countPoints, + uint* triangles, + uint countTriangles, + Parameters* parameters); + + [DllImport("libvhacd")] + static extern unsafe bool ComputeDouble( + void* pVHACD, + double* points, + uint countPoints, + uint* triangles, + uint countTriangles, + Parameters* parameters); + + [DllImport("libvhacd")] static extern unsafe uint GetNConvexHulls(void* pVHACD); + + [DllImport("libvhacd")] + static extern unsafe void GetConvexHull( + void* pVHACD, + uint index, + ConvexHull* ch); + + public Parameters m_parameters; + + public VHACD() { m_parameters.Init(); } + + [ContextMenu("Generate Convex Meshes")] + public unsafe List GenerateConvexMeshes(Mesh mesh = null) + { + if (mesh == null) + { + mesh = GetComponent().sharedMesh; + } + var vhacd = CreateVHACD(); + var parameters = m_parameters; + + var verts = mesh.vertices; + var tris = mesh.triangles; + fixed (Vector3* pVerts = verts) + fixed (int* pTris = tris) + { + ComputeFloat( + vhacd, + (float*)pVerts, (uint)verts.Length, + (uint*)pTris, (uint)tris.Length / 3, + ¶meters); + } + + var numHulls = GetNConvexHulls(vhacd); + List convexMesh = new List((int)numHulls); + foreach (var index in Enumerable.Range(0, (int)numHulls)) + { + ConvexHull hull; + GetConvexHull(vhacd, (uint)index, &hull); + + var hullMesh = new Mesh(); + var hullVerts = new Vector3[hull.m_nPoints]; + fixed (Vector3* pHullVerts = hullVerts) + { + var pComponents = hull.m_points; + var pVerts = pHullVerts; + + for (var pointCount = hull.m_nPoints; pointCount != 0; --pointCount) + { + pVerts->x = (float)pComponents[0]; + pVerts->y = (float)pComponents[1]; + pVerts->z = (float)pComponents[2]; + + pVerts += 1; + pComponents += 3; + } + } + + hullMesh.SetVertices(hullVerts); + + var indices = new int[hull.m_nTriangles * 3]; + Marshal.Copy((System.IntPtr)hull.m_triangles, indices, 0, indices.Length); + hullMesh.SetTriangles(indices, 0); + + + convexMesh.Add(hullMesh); + } + return convexMesh; + } + } +} diff --git a/Runtime/VHACD.cs.meta b/Runtime/VHACD.cs.meta new file mode 100644 index 0000000..47245fe --- /dev/null +++ b/Runtime/VHACD.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 845ffa358c43240dda6ed5379b4f0c8e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/liblibvhacd.dylib b/Runtime/liblibvhacd.dylib new file mode 100644 index 0000000..2253a08 --- /dev/null +++ b/Runtime/liblibvhacd.dylib @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:37cae6e4039b5936801dc49e46a85850ddd31fbddf3f21c800049f9c9d12d104 +size 738128 diff --git a/Runtime/liblibvhacd.dylib.meta b/Runtime/liblibvhacd.dylib.meta new file mode 100644 index 0000000..ca00aea --- /dev/null +++ b/Runtime/liblibvhacd.dylib.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 94c2c889690e246e8af1941d40e09b36 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/liblibvhacd.so b/Runtime/liblibvhacd.so new file mode 100644 index 0000000..93c6ca6 --- /dev/null +++ b/Runtime/liblibvhacd.so @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:225f563973dedb094b8979fa5447bdb235d3b54c6259378859f175df194c9265 +size 804792 diff --git a/Runtime/liblibvhacd.so.meta b/Runtime/liblibvhacd.so.meta new file mode 100644 index 0000000..dddcc2b --- /dev/null +++ b/Runtime/liblibvhacd.so.meta @@ -0,0 +1,80 @@ +fileFormatVersion: 2 +guid: 47c08989d7bad470487e2f72442e442f +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 1 + Exclude WindowsStoreApps: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Linux + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + WebGL: WebGL + second: + enabled: 0 + settings: {} + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: X86 + DontProcess: true + PlaceholderPath: + SDK: AnySDK + ScriptingBackend: AnyScriptingBackend + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/libvhacd.dll b/Runtime/libvhacd.dll new file mode 100644 index 0000000..166f80c --- /dev/null +++ b/Runtime/libvhacd.dll @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:751d8a352855b48f7cd215be14631fe01173fc968b188ba24b128c9b8a0f0db6 +size 442880 diff --git a/Runtime/libvhacd.dll.meta b/Runtime/libvhacd.dll.meta new file mode 100644 index 0000000..272fa6b --- /dev/null +++ b/Runtime/libvhacd.dll.meta @@ -0,0 +1,75 @@ +fileFormatVersion: 2 +guid: 4d1723769ada3482b80ae4dd6837ab53 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + : Any + second: + enabled: 0 + settings: + Exclude Editor: 0 + Exclude Linux64: 0 + Exclude OSXUniversal: 0 + Exclude WebGL: 1 + Exclude Win: 1 + Exclude Win64: 0 + Exclude WindowsStoreApps: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Windows + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: X86 + DontProcess: false + PlaceholderPath: + SDK: AnySDK + ScriptingBackend: AnyScriptingBackend + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/vhacd.asmdef b/Runtime/vhacd.asmdef new file mode 100644 index 0000000..89cacbd --- /dev/null +++ b/Runtime/vhacd.asmdef @@ -0,0 +1,15 @@ +{ + "name": "vhacd", + "rootNamespace": "VHACD", + "references": [], + "includePlatforms": [ + ], + "excludePlatforms": [], + "allowUnsafeCode": true, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/vhacd.asmdef.meta b/Runtime/vhacd.asmdef.meta new file mode 100644 index 0000000..75ee8a9 --- /dev/null +++ b/Runtime/vhacd.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: b0dc65aa46d174cbab72d2bfef413320 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..718e1a0 --- /dev/null +++ b/package.json @@ -0,0 +1,9 @@ +{ + "name": "com.unity.robotics.vhacd", + "version": "0.0.1-preview", + "displayName": "VHACD", + "description": "", + "unity": "2020.3", + "unityRelease": "19f1", + "_fingerprint": "d52fd80370d9257cb417999c6f5eab56604b3da9" +} diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..2b975c2 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: bece70ee13b874e1b9d0a20a25213f62 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: