예제 #1
0
        private void DelaunayRefinement(Int3[] verts, int[] tris, ref int tCount, bool delaunay, bool colinear)
        {
            if (tCount % 3 != 0)
            {
                throw new ArgumentException("Triangle array length must be a multiple of 3");
            }
            Dictionary <Int2, int> dictionary = this.cached_Int2_int_dict;

            dictionary.Clear();
            for (int i = 0; i < tCount; i += 3)
            {
                if (!VectorMath.IsClockwiseXZ(verts[tris[i]], verts[tris[i + 1]], verts[tris[i + 2]]))
                {
                    int num = tris[i];
                    tris[i]     = tris[i + 2];
                    tris[i + 2] = num;
                }
                dictionary[new Int2(tris[i], tris[i + 1])]     = i + 2;
                dictionary[new Int2(tris[i + 1], tris[i + 2])] = i;
                dictionary[new Int2(tris[i + 2], tris[i])]     = i + 1;
            }
            for (int j = 0; j < tCount; j += 3)
            {
                for (int k = 0; k < 3; k++)
                {
                    int num2;
                    if (dictionary.TryGetValue(new Int2(tris[j + (k + 1) % 3], tris[j + k % 3]), out num2))
                    {
                        Int3 @int = verts[tris[j + (k + 2) % 3]];
                        Int3 int2 = verts[tris[j + (k + 1) % 3]];
                        Int3 int3 = verts[tris[j + (k + 3) % 3]];
                        Int3 int4 = verts[tris[num2]];
                        @int.y = 0;
                        int2.y = 0;
                        int3.y = 0;
                        int4.y = 0;
                        bool flag = false;
                        if (!VectorMath.RightOrColinearXZ(@int, int3, int4) || VectorMath.RightXZ(@int, int2, int4))
                        {
                            if (!colinear)
                            {
                                goto IL_409;
                            }
                            flag = true;
                        }
                        if (colinear && VectorMath.SqrDistancePointSegmentApproximate(@int, int4, int2) < 9f && !dictionary.ContainsKey(new Int2(tris[j + (k + 2) % 3], tris[j + (k + 1) % 3])) && !dictionary.ContainsKey(new Int2(tris[j + (k + 1) % 3], tris[num2])))
                        {
                            tCount -= 3;
                            int num3 = num2 / 3 * 3;
                            tris[j + (k + 1) % 3] = tris[num2];
                            if (num3 != tCount)
                            {
                                tris[num3]     = tris[tCount];
                                tris[num3 + 1] = tris[tCount + 1];
                                tris[num3 + 2] = tris[tCount + 2];
                                dictionary[new Int2(tris[num3], tris[num3 + 1])]     = num3 + 2;
                                dictionary[new Int2(tris[num3 + 1], tris[num3 + 2])] = num3;
                                dictionary[new Int2(tris[num3 + 2], tris[num3])]     = num3 + 1;
                                tris[tCount]     = 0;
                                tris[tCount + 1] = 0;
                                tris[tCount + 2] = 0;
                            }
                            else
                            {
                                tCount += 3;
                            }
                            dictionary[new Int2(tris[j], tris[j + 1])]     = j + 2;
                            dictionary[new Int2(tris[j + 1], tris[j + 2])] = j;
                            dictionary[new Int2(tris[j + 2], tris[j])]     = j + 1;
                        }
                        else if (delaunay && !flag)
                        {
                            float num4 = Int3.Angle(int2 - @int, int3 - @int);
                            float num5 = Int3.Angle(int2 - int4, int3 - int4);
                            if (num5 > 6.28318548f - 2f * num4)
                            {
                                tris[j + (k + 1) % 3] = tris[num2];
                                int num6 = num2 / 3 * 3;
                                int num7 = num2 - num6;
                                tris[num6 + (num7 - 1 + 3) % 3]                      = tris[j + (k + 2) % 3];
                                dictionary[new Int2(tris[j], tris[j + 1])]           = j + 2;
                                dictionary[new Int2(tris[j + 1], tris[j + 2])]       = j;
                                dictionary[new Int2(tris[j + 2], tris[j])]           = j + 1;
                                dictionary[new Int2(tris[num6], tris[num6 + 1])]     = num6 + 2;
                                dictionary[new Int2(tris[num6 + 1], tris[num6 + 2])] = num6;
                                dictionary[new Int2(tris[num6 + 2], tris[num6])]     = num6 + 1;
                            }
                        }
                    }
                    IL_409 :;
                }
            }
        }
예제 #2
0
        // Token: 0x060005E3 RID: 1507 RVA: 0x00037424 File Offset: 0x00035824
        private void DelaunayRefinement(Int3[] verts, int[] tris, ref int vCount, ref int tCount, bool delaunay, bool colinear, Int3 worldOffset)
        {
            if (tCount % 3 != 0)
            {
                throw new Exception("Triangle array length must be a multiple of 3");
            }
            Dictionary <Int2, int> dictionary = this.cached_Int2_int_dict;

            dictionary.Clear();
            for (int i = 0; i < tCount; i += 3)
            {
                if (!Polygon.IsClockwise(verts[tris[i]], verts[tris[i + 1]], verts[tris[i + 2]]))
                {
                    int num = tris[i];
                    tris[i]     = tris[i + 2];
                    tris[i + 2] = num;
                }
                dictionary[new Int2(tris[i], tris[i + 1])]     = i + 2;
                dictionary[new Int2(tris[i + 1], tris[i + 2])] = i;
                dictionary[new Int2(tris[i + 2], tris[i])]     = i + 1;
            }
            int num2 = 9;

            for (int j = 0; j < tCount; j += 3)
            {
                for (int k = 0; k < 3; k++)
                {
                    int num3;
                    if (dictionary.TryGetValue(new Int2(tris[j + (k + 1) % 3], tris[j + k % 3]), out num3))
                    {
                        Int3 @int = verts[tris[j + (k + 2) % 3]];
                        Int3 int2 = verts[tris[j + (k + 1) % 3]];
                        Int3 int3 = verts[tris[j + (k + 3) % 3]];
                        Int3 int4 = verts[tris[num3]];
                        @int.y = 0;
                        int2.y = 0;
                        int3.y = 0;
                        int4.y = 0;
                        bool flag = false;
                        if (!Polygon.Left(@int, int3, int4) || Polygon.LeftNotColinear(@int, int2, int4))
                        {
                            if (!colinear)
                            {
                                goto IL_439;
                            }
                            flag = true;
                        }
                        if (colinear && AstarMath.DistancePointSegment(@int, int4, int2) < (float)num2 && !dictionary.ContainsKey(new Int2(tris[j + (k + 2) % 3], tris[j + (k + 1) % 3])) && !dictionary.ContainsKey(new Int2(tris[j + (k + 1) % 3], tris[num3])))
                        {
                            tCount -= 3;
                            int num4 = num3 / 3 * 3;
                            tris[j + (k + 1) % 3] = tris[num3];
                            if (num4 != tCount)
                            {
                                tris[num4]     = tris[tCount];
                                tris[num4 + 1] = tris[tCount + 1];
                                tris[num4 + 2] = tris[tCount + 2];
                                dictionary[new Int2(tris[num4], tris[num4 + 1])]     = num4 + 2;
                                dictionary[new Int2(tris[num4 + 1], tris[num4 + 2])] = num4;
                                dictionary[new Int2(tris[num4 + 2], tris[num4])]     = num4 + 1;
                                tris[tCount]     = 0;
                                tris[tCount + 1] = 0;
                                tris[tCount + 2] = 0;
                            }
                            else
                            {
                                tCount += 3;
                            }
                            dictionary[new Int2(tris[j], tris[j + 1])]     = j + 2;
                            dictionary[new Int2(tris[j + 1], tris[j + 2])] = j;
                            dictionary[new Int2(tris[j + 2], tris[j])]     = j + 1;
                        }
                        else if (delaunay && !flag)
                        {
                            float num5 = Int3.Angle(int2 - @int, int3 - @int);
                            float num6 = Int3.Angle(int2 - int4, int3 - int4);
                            if (num6 > 6.28318548f - 2f * num5)
                            {
                                tris[j + (k + 1) % 3] = tris[num3];
                                int num7 = num3 / 3 * 3;
                                int num8 = num3 - num7;
                                tris[num7 + (num8 - 1 + 3) % 3]                      = tris[j + (k + 2) % 3];
                                dictionary[new Int2(tris[j], tris[j + 1])]           = j + 2;
                                dictionary[new Int2(tris[j + 1], tris[j + 2])]       = j;
                                dictionary[new Int2(tris[j + 2], tris[j])]           = j + 1;
                                dictionary[new Int2(tris[num7], tris[num7 + 1])]     = num7 + 2;
                                dictionary[new Int2(tris[num7 + 1], tris[num7 + 2])] = num7;
                                dictionary[new Int2(tris[num7 + 2], tris[num7])]     = num7 + 1;
                            }
                        }
                    }
                    IL_439 :;
                }
            }
        }