Ejemplo n.º 1
0
    public void Action_Triangulate()
    {
        float[] p = new float[points.Count * 2];
        for (int i = 0; i < points.Count; i++)
        {
            p[i * 2]     = points[i].transform.position.x;
            p[i * 2 + 1] = points[i].transform.position.z;
        }

        SaveTestInputInFile(p);

        IntPtr raw_points = Marshal.AllocHGlobal(sizeof(float) * p.Length);

        Marshal.Copy(p, 0, raw_points, p.Length);

        IntPtr return_size = Marshal.AllocHGlobal(sizeof(int));
        IntPtr result      = triangulate(raw_points, p.Length / 2, return_size);

        Marshal.FreeHGlobal(raw_points);

        if (result != IntPtr.Zero)
        {
            int result_size = Marshal.ReadInt32(return_size);

            float[] final_result = new float[result_size];
            Marshal.Copy(result, final_result, 0, result_size);

            Debug.Log("Triangulate - Points : " + result_size / 2 + " - Triangle : " + result_size / 6);

            for (int i = 0; i < result_size; i += 6)
            {
                Debug.Log("Triangle " + i / 6 + " : " + final_result[i] + "," + final_result[i + 1] + " - " + final_result[i + 2] + "," + final_result[i + 3] + " - " + final_result[i + 4] + "," + final_result[i + 5]);
            }

            meshCreate.Create2D(final_result);

            Marshal.FreeHGlobal(return_size);
            Marshal.FreeHGlobal(result);
        }
        else
        {
            Debug.LogWarning("3 points are required for performing triangulation.");
        }
    }