Esempio n. 1
0
            void AddTriangle(int i, int j, int k)
            {
                TessStar si = m_Stars[i];
                TessStar sj = m_Stars[j];
                TessStar sk = m_Stars[k];

                si.points[si.pointCount++] = j;
                si.points[si.pointCount++] = k;
                sj.points[sj.pointCount++] = k;
                sj.points[sj.pointCount++] = i;
                sk.points[sk.pointCount++] = i;
                sk.points[sk.pointCount++] = j;
                m_Stars[i] = si;
                m_Stars[j] = sj;
                m_Stars[k] = sk;
            }
Esempio n. 2
0
            void Prepare(NativeArray <TessEdge> edgesIn)
            {
                m_Stars = new NativeArray <TessStar>(edgesIn.Length, Allocator.Temp);

                for (int i = 0; i < edgesIn.Length; ++i)
                {
                    TessEdge e = edgesIn[i];
                    e.a        = (edgesIn[i].a < edgesIn[i].b) ? edgesIn[i].a : edgesIn[i].b;
                    e.b        = (edgesIn[i].a > edgesIn[i].b) ? edgesIn[i].a : edgesIn[i].b;
                    edgesIn[i] = e;
                    TessStar s = m_Stars[i];
                    s.points     = new ArraySlice <int>(m_SPArray, i * m_StarCount, m_StarCount);
                    s.pointCount = 0;
                    m_Stars[i]   = s;
                }

                unsafe
                {
                    TessUtils.InsertionSort <TessEdge, TessEdgeCompare>(
                        NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(edgesIn), 0, edgesIn.Length - 1,
                        new TessEdgeCompare());
                }

                m_Edges = new NativeArray <TessEdge>(edgesIn.Length, Allocator.Temp);
                m_Edges.CopyFrom(edgesIn);

                // Fill stars.
                for (int i = 0; i < m_CellCount; ++i)
                {
                    int      a  = m_Cells[i].a;
                    int      b  = m_Cells[i].b;
                    int      c  = m_Cells[i].c;
                    TessStar sa = m_Stars[a];
                    TessStar sb = m_Stars[b];
                    TessStar sc = m_Stars[c];
                    sa.points[sa.pointCount++] = b;
                    sa.points[sa.pointCount++] = c;
                    sb.points[sb.pointCount++] = c;
                    sb.points[sb.pointCount++] = a;
                    sc.points[sc.pointCount++] = a;
                    sc.points[sc.pointCount++] = b;
                    m_Stars[a] = sa;
                    m_Stars[b] = sb;
                    m_Stars[c] = sc;
                }
            }
Esempio n. 3
0
            void RemovePair(int r, int j, int k)
            {
                TessStar         s      = m_Stars[r];
                ArraySlice <int> points = s.points;

                for (int i = 1, n = s.pointCount; i < n; i += 2)
                {
                    if (points[i - 1] == j && points[i] == k)
                    {
                        points[i - 1] = points[n - 2];
                        points[i]     = points[n - 1];
                        s.points      = points;
                        s.pointCount  = s.pointCount - 2;
                        m_Stars[r]    = s;
                        return;
                    }
                }
            }
Esempio n. 4
0
            internal void ApplyDelaunay(NativeArray <float2> points, NativeArray <TessEdge> edgesIn)
            {
                NativeArray <int> stack = new NativeArray <int>(m_NumPoints * (m_NumPoints + 1), Allocator.Temp);
                int stackCount          = 0;

                Prepare(edgesIn);
                for (int a = 0; a < m_NumPoints; ++a)
                {
                    TessStar star = m_Stars[a];
                    for (int j = 1; j < star.pointCount; j += 2)
                    {
                        int b = star.points[j];

                        if (b < a)
                        {
                            continue;
                        }

                        if (FindConstraint(a, b) >= 0)
                        {
                            continue;
                        }

                        int x = star.points[j - 1], y = -1;
                        for (int k = 1; k < star.pointCount; k += 2)
                        {
                            if (star.points[k - 1] == b)
                            {
                                y = star.points[k];
                                break;
                            }
                        }

                        if (y < 0)
                        {
                            continue;
                        }

                        if (TessUtils.IsInsideCircle(points[a], points[b], points[x], points[y]))
                        {
                            stack[stackCount++] = a;
                            stack[stackCount++] = b;
                        }
                    }
                }

                while (stackCount > 0)
                {
                    int b = stack[stackCount - 1];
                    stackCount--;
                    int a = stack[stackCount - 1];
                    stackCount--;

                    int      x = -1, y = -1;
                    TessStar star = m_Stars[a];
                    for (int i = 1; i < star.pointCount; i += 2)
                    {
                        int s = star.points[i - 1];
                        int t = star.points[i];
                        if (s == b)
                        {
                            y = t;
                        }
                        else if (t == b)
                        {
                            x = s;
                        }
                    }

                    if (x < 0 || y < 0)
                    {
                        continue;
                    }

                    if (!TessUtils.IsInsideCircle(points[a], points[b], points[x], points[y]))
                    {
                        continue;
                    }

                    EdgeFlip(a, b);

                    Flip(points, ref stack, ref stackCount, x, a, y);
                    Flip(points, ref stack, ref stackCount, a, y, x);
                    Flip(points, ref stack, ref stackCount, y, b, x);
                    Flip(points, ref stack, ref stackCount, b, x, y);
                }

                stack.Dispose();
            }