Compare commits
5 Commits
e1243e6186
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e81c2baef | |||
| cec90b4113 | |||
| ab1026ece5 | |||
| bc6b95441e | |||
| d95a6b5817 |
7
LICENSE.md.meta
Normal file
7
LICENSE.md.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1cd39da8a5283a746bbb0c7f6eb50757
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
Runtime/MeshSafe.cs
Normal file
19
Runtime/MeshSafe.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.VHACD
|
||||
{
|
||||
public struct MeshSafe
|
||||
{
|
||||
public Vector3[] Vertices;
|
||||
public int[] Triangles;
|
||||
|
||||
public Mesh ToMesh()
|
||||
{
|
||||
return new Mesh
|
||||
{
|
||||
vertices = Vertices,
|
||||
triangles = Triangles
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Runtime/MeshSafe.cs.meta
Normal file
2
Runtime/MeshSafe.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 182d52cf7acb8c2409432384bf11f643
|
||||
22
Runtime/Shazbot.VHACD.asmdef
Normal file
22
Runtime/Shazbot.VHACD.asmdef
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "Shazbot.VHACD",
|
||||
"rootNamespace": "Unity.VHACD",
|
||||
"references": [
|
||||
"GUID:80ed647da8ce73c45b66c239eba0365a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "ru.shazbot.utils",
|
||||
"expression": "",
|
||||
"define": "UTILS"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
120
Runtime/VHACD.cs
120
Runtime/VHACD.cs
@@ -1,11 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MeshProcess
|
||||
namespace Unity.VHACD
|
||||
{
|
||||
#if UTILS
|
||||
[Utils.HideScriptField]
|
||||
#endif
|
||||
public class VHACD : MonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
@@ -28,61 +30,53 @@ namespace MeshProcess
|
||||
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
|
||||
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)]
|
||||
[Tooltip("Maximum concavity")] [Range(0, 1)]
|
||||
public double m_concavity;
|
||||
|
||||
[Tooltip("controls the bias toward clipping along symmetry planes")]
|
||||
[Range(0, 1)]
|
||||
[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)]
|
||||
[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)]
|
||||
[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)]
|
||||
[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)]
|
||||
[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)]
|
||||
[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")]
|
||||
[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)]
|
||||
[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)]
|
||||
[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_convexhullApproximation;
|
||||
|
||||
[Range(0, 1)]
|
||||
public uint m_oclAcceleration;
|
||||
[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")]
|
||||
[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;
|
||||
};
|
||||
|
||||
@@ -96,9 +90,11 @@ namespace MeshProcess
|
||||
public fixed double m_center[3];
|
||||
};
|
||||
|
||||
[DllImport("libvhacd")] static extern unsafe void* CreateVHACD();
|
||||
[DllImport("libvhacd")]
|
||||
static extern unsafe void* CreateVHACD();
|
||||
|
||||
[DllImport("libvhacd")] static extern unsafe void DestroyVHACD(void* pVHACD);
|
||||
[DllImport("libvhacd")]
|
||||
static extern unsafe void DestroyVHACD(void* pVHACD);
|
||||
|
||||
[DllImport("libvhacd")]
|
||||
static extern unsafe bool ComputeFloat(
|
||||
@@ -118,7 +114,8 @@ namespace MeshProcess
|
||||
uint countTriangles,
|
||||
Parameters* parameters);
|
||||
|
||||
[DllImport("libvhacd")] static extern unsafe uint GetNConvexHulls(void* pVHACD);
|
||||
[DllImport("libvhacd")]
|
||||
static extern unsafe uint GetNConvexHulls(void* pVHACD);
|
||||
|
||||
[DllImport("libvhacd")]
|
||||
static extern unsafe void GetConvexHull(
|
||||
@@ -128,15 +125,18 @@ namespace MeshProcess
|
||||
|
||||
public Parameters m_parameters;
|
||||
|
||||
public VHACD() { m_parameters.Init(); }
|
||||
public VHACD()
|
||||
{
|
||||
m_parameters.Init();
|
||||
}
|
||||
|
||||
[ContextMenu("Generate Convex Meshes")]
|
||||
public unsafe List<Mesh> GenerateConvexMeshes(Mesh mesh = null)
|
||||
{
|
||||
if (mesh == null)
|
||||
{
|
||||
mesh = GetComponent<MeshFilter>().sharedMesh;
|
||||
}
|
||||
|
||||
var vhacd = CreateVHACD();
|
||||
var parameters = m_parameters;
|
||||
|
||||
@@ -186,7 +186,61 @@ namespace MeshProcess
|
||||
|
||||
convexMesh.Add(hullMesh);
|
||||
}
|
||||
|
||||
return convexMesh;
|
||||
}
|
||||
|
||||
public unsafe List<MeshSafe> GenerateConvexMeshes(Vector3[] verts, int[] tris)
|
||||
{
|
||||
var vhacd = CreateVHACD();
|
||||
var parameters = m_parameters;
|
||||
|
||||
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<MeshSafe> convexMesh = new List<MeshSafe>((int)numHulls);
|
||||
foreach (var index in Enumerable.Range(0, (int)numHulls))
|
||||
{
|
||||
ConvexHull hull;
|
||||
GetConvexHull(vhacd, (uint)index, &hull);
|
||||
|
||||
var hullMesh = new MeshSafe();
|
||||
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.Vertices = hullVerts;
|
||||
|
||||
var indices = new int[hull.m_nTriangles * 3];
|
||||
Marshal.Copy((System.IntPtr)hull.m_triangles, indices, 0, indices.Length);
|
||||
hullMesh.Triangles = indices;
|
||||
|
||||
|
||||
convexMesh.Add(hullMesh);
|
||||
}
|
||||
|
||||
return convexMesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"name": "vhacd",
|
||||
"rootNamespace": "VHACD",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
19
package.json
19
package.json
@@ -1,9 +1,18 @@
|
||||
{
|
||||
"name": "com.unity.robotics.vhacd",
|
||||
"version": "0.0.1-preview",
|
||||
"name": "ru.shazbot.vhacd",
|
||||
"version": "1.0.2",
|
||||
"displayName": "VHACD",
|
||||
"description": "",
|
||||
"description": "Based on https://github.com/Unity-Technologies/VHACD",
|
||||
"licensesUrl": "https://git.well-placed.de/InnoLab/VHACD/src/LICENSE.md",
|
||||
"unity": "2020.3",
|
||||
"unityRelease": "19f1",
|
||||
"_fingerprint": "d52fd80370d9257cb417999c6f5eab56604b3da9"
|
||||
}
|
||||
"keywords": [
|
||||
"vhacd"
|
||||
],
|
||||
"author": {
|
||||
"name": "Alexander Filippov",
|
||||
"email": "alexander@shazbot.ru",
|
||||
"url": "https://shazbot.ru/"
|
||||
},
|
||||
"dependencies": { }
|
||||
}
|
||||
Reference in New Issue
Block a user