Esempio n. 1
0
        public static ParallelQHullData ConvextHull3D(Fix64Vec3[] verts, UInt32 count, bool simplify, Fix64 rad)
        {
            if (!initialized)
            {
                Initialize();
            }

            UInt32 outCount = 1024 * 10;

            Fix64Vec3[]     vertsOut  = new Fix64Vec3[outCount];
            ParallelEdge[]  edgesOut  = new ParallelEdge[outCount];
            ParallelFace[]  facesOut  = new ParallelFace[outCount];
            ParallelPlane[] planesOut = new ParallelPlane[outCount];

            UInt32 vertsOutCount = outCount;
            UInt32 edgesOutCount = outCount;
            UInt32 facesOutCount = outCount;

            NativeParallel3D.ConvexHull3D(verts, count, vertsOut, ref vertsOutCount, edgesOut, ref edgesOutCount, facesOut, ref facesOutCount, planesOut, simplify, rad);

            ParallelQHullData parallelQHullData = new ParallelQHullData();

            parallelQHullData.vertexCount = vertsOutCount;
            parallelQHullData.edgeCount   = edgesOutCount;
            parallelQHullData.faceCount   = facesOutCount;
            parallelQHullData.vertices    = vertsOut;
            parallelQHullData.edges       = edgesOut;
            parallelQHullData.faces       = facesOut;
            parallelQHullData.planes      = planesOut;
            return(parallelQHullData);
        }
        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;
        }