void BuildConvexData()
        {
            //stan hull
            Vector3[] vIn1 = new Vector3[vertsCount];
            for (int i = 0; i < vertsCount; i++)
            {
                vIn1[i] = verts[i];
            }

            ParallelQHullData2 qhullData2 = Parallel3D.ConvextHull3D2(vIn1, (UInt32)vertsCount, (int)_limit);

            convexData2 = qhullData2;

            ParallelIntTriangle[] t = new ParallelIntTriangle[convexData2.triCount];
            Array.Copy(convexData2.tris, 0, t, 0, convexData2.triCount);
            convexData2.tris = t;

            //new convex hull
            Fix64Vec3[] vIn = new Fix64Vec3[_limit];
            for (int i = 0; i < _limit; i++)
            {
                vIn[i] = (Fix64Vec3)convexData2.vertices[i];
            }

            float rad = angle * Mathf.Deg2Rad;

            ParallelQHullData qhullData = Parallel3D.ConvextHull3D(vIn, (UInt32)_limit, _simplified, (Fix64)rad);

            convexData = qhullData;

            Fix64Vec3[] v = new Fix64Vec3[convexData.vertexCount];
            Array.Copy(convexData.vertices, 0, v, 0, convexData.vertexCount);
            convexData.vertices = v;

            string output = "";

            output += $"b3Vec3 verts[{convexData.vertexCount}] = {{}};\n";
            //Debug.Log($"b3Vec3 verts[{convexData.vertexCount}] = {{}};");
            for (int i = 0; i < convexData.vertexCount; i++)
            {
                Vector3 vec3 = (Vector3)convexData.vertices[i];
                output += $"b3Vec3({vec3.x}, {vec3.y}, {vec3.z}),\n";
                //Debug.Log($"verts[{i}] = b3Vec3({vec3.x}, {vec3.y}, {vec3.z});");
            }
            //Debug.Log(output);

            ParallelEdge[] e = new ParallelEdge[convexData.edgeCount];
            Array.Copy(convexData.edges, 0, e, 0, convexData.edgeCount);
            convexData.edges = e;

            ParallelFace[] f = new ParallelFace[convexData.faceCount];
            Array.Copy(convexData.faces, 0, f, 0, convexData.faceCount);
            convexData.faces = f;

            ParallelPlane[] p = new ParallelPlane[convexData.faceCount];
            Array.Copy(convexData.planes, 0, p, 0, convexData.faceCount);
            convexData.planes = p;

            return;
        }
        void DrawStanHull()
        {
            for (int i = 0; i < convexData2.triCount; i++)
            {
                ParallelIntTriangle t  = convexData2.tris[i];
                Vector3             v1 = convexData2.vertices[t.v1];
                Vector3             v2 = convexData2.vertices[t.v2];
                Vector3             v3 = convexData2.vertices[t.v3];

                Gizmos.DrawLine(transform.TransformPoint(v1.x, v1.y, v1.z), transform.TransformPoint(v2.x, v2.y, v2.z));
                Gizmos.DrawLine(transform.TransformPoint(v1.x, v1.y, v1.z), transform.TransformPoint(v3.x, v3.y, v3.z));
                Gizmos.DrawLine(transform.TransformPoint(v3.x, v3.y, v3.z), transform.TransformPoint(v2.x, v2.y, v2.z));
            }
        }
Example #3
0
        public static ParallelQHullData2 ConvextHull3D2(Vector3[] verts, UInt32 count, int limit)
        {
            if (!initialized)
            {
                Initialize();
            }

            UInt32 outCount = 1024;

            ParallelIntTriangle[] trisOut = new ParallelIntTriangle[outCount];

            Vector3[] vertsOut = new Vector3[count];

            UInt32 trisOutCount = outCount;

            NativeParallel3D.ConvexHull3D2(verts, count, trisOut, ref trisOutCount, vertsOut, limit);

            ParallelQHullData2 parallelQHullData = new ParallelQHullData2();

            parallelQHullData.triCount = trisOutCount;
            parallelQHullData.tris     = trisOut;
            parallelQHullData.vertices = vertsOut;
            return(parallelQHullData);
        }