Пример #1
0
        // Token: 0x060042FC RID: 17148 RVA: 0x0015AB44 File Offset: 0x00158F44
        private static int GetVertCount(GeoSpherePrimitive.BaseType type, int subdivision, bool sharedVertices)
        {
            int triCount = GeoSpherePrimitive.GetTriCount(type, subdivision);

            if (sharedVertices)
            {
                return(triCount);
            }
            return(triCount * 3);
        }
Пример #2
0
        // Token: 0x060042FA RID: 17146 RVA: 0x0015A5D0 File Offset: 0x001589D0
        private static void InitBasePrimitive(float radius, GeoSpherePrimitive.BaseType baseType, Vector3[] vertices, Vector2[] uvs, int[] triangles)
        {
            switch (baseType)
            {
            case GeoSpherePrimitive.BaseType.Tetrahedron:
            {
                float num  = 1f / Mathf.Sqrt(2f);
                float num2 = 1f / Mathf.Sqrt(1.5f);
                float num3 = 0.67f * radius / num2;
                num = 0.67f * radius * num / num2;
                GeoSpherePrimitive.SetVertices(vertices, new Vector3[]
                    {
                        new Vector3(num3, 0f, -num),
                        new Vector3(-num3, 0f, -num),
                        new Vector3(0f, num3, num),
                        new Vector3(0f, -num3, num)
                    });
                GeoSpherePrimitive.SetTriangles(triangles, new int[]
                    {
                        0,
                        1,
                        2,
                        1,
                        3,
                        2,
                        0,
                        2,
                        3,
                        0,
                        3,
                        1
                    });
                break;
            }

            case GeoSpherePrimitive.BaseType.Octahedron:
                GeoSpherePrimitive.SetVertices(vertices, new Vector3[]
                {
                    new Vector3(0f, -radius, 0f),
                    new Vector3(-radius, 0f, 0f),
                    new Vector3(0f, 0f, -radius),
                    new Vector3(radius, 0f, 0f),
                    new Vector3(0f, 0f, radius),
                    new Vector3(0f, radius, 0f)
                });
                GeoSpherePrimitive.SetTriangles(triangles, new int[]
                {
                    0,
                    1,
                    2,
                    0,
                    2,
                    3,
                    0,
                    3,
                    4,
                    0,
                    4,
                    1,
                    5,
                    2,
                    1,
                    5,
                    3,
                    2,
                    5,
                    4,
                    3,
                    5,
                    1,
                    4
                });
                break;

            case GeoSpherePrimitive.BaseType.Icosahedron:
            {
                float num4 = 1f;
                float num5 = (1f + Mathf.Sqrt(5f)) / 2f;
                float num6 = radius / Mathf.Sqrt(num4 * num4 + num5 * num5);
                num4 *= num6;
                num5 *= num6;
                GeoSpherePrimitive.SetVertices(vertices, new Vector3[]
                    {
                        new Vector3(-num4, num5, 0f),
                        new Vector3(num4, num5, 0f),
                        new Vector3(-num4, -num5, 0f),
                        new Vector3(num4, -num5, 0f),
                        new Vector3(0f, -num4, num5),
                        new Vector3(0f, num4, num5),
                        new Vector3(0f, -num4, -num5),
                        new Vector3(0f, num4, -num5),
                        new Vector3(num5, 0f, -num4),
                        new Vector3(num5, 0f, num4),
                        new Vector3(-num5, 0f, -num4),
                        new Vector3(-num5, 0f, num4)
                    });
                GeoSpherePrimitive.SetTriangles(triangles, new int[]
                    {
                        0,
                        11,
                        5,
                        0,
                        5,
                        1,
                        0,
                        1,
                        7,
                        0,
                        7,
                        10,
                        0,
                        10,
                        11,
                        1,
                        5,
                        9,
                        5,
                        11,
                        4,
                        11,
                        10,
                        2,
                        10,
                        7,
                        6,
                        7,
                        1,
                        8,
                        3,
                        9,
                        4,
                        3,
                        4,
                        2,
                        3,
                        2,
                        6,
                        3,
                        6,
                        8,
                        3,
                        8,
                        9,
                        4,
                        9,
                        5,
                        2,
                        4,
                        11,
                        6,
                        2,
                        10,
                        8,
                        6,
                        7,
                        9,
                        8,
                        1
                    });
                break;
            }

            case GeoSpherePrimitive.BaseType.Icositetrahedron:
            {
                float num7 = radius / Mathf.Sqrt(3f);
                GeoSpherePrimitive.SetVertices(vertices, new Vector3[]
                    {
                        new Vector3(0f, radius, 0f),
                        new Vector3(0f, -radius, 0f),
                        new Vector3(radius, 0f, 0f),
                        new Vector3(-radius, 0f, 0f),
                        new Vector3(0f, 0f, radius),
                        new Vector3(0f, 0f, -radius),
                        new Vector3(-num7, num7, num7),
                        new Vector3(-num7, num7, -num7),
                        new Vector3(num7, num7, -num7),
                        new Vector3(num7, num7, num7),
                        new Vector3(-num7, -num7, num7),
                        new Vector3(-num7, -num7, -num7),
                        new Vector3(num7, -num7, -num7),
                        new Vector3(num7, -num7, num7)
                    });
                GeoSpherePrimitive.SetTriangles(triangles, new int[]
                    {
                        0,
                        7,
                        6,
                        0,
                        8,
                        7,
                        0,
                        9,
                        8,
                        0,
                        6,
                        9,
                        1,
                        10,
                        11,
                        1,
                        11,
                        12,
                        1,
                        12,
                        13,
                        1,
                        13,
                        10,
                        2,
                        8,
                        9,
                        2,
                        9,
                        13,
                        2,
                        13,
                        12,
                        2,
                        12,
                        8,
                        3,
                        6,
                        7,
                        3,
                        7,
                        11,
                        3,
                        11,
                        10,
                        3,
                        10,
                        6,
                        4,
                        9,
                        6,
                        4,
                        13,
                        9,
                        4,
                        10,
                        13,
                        4,
                        6,
                        10,
                        5,
                        7,
                        8,
                        5,
                        8,
                        12,
                        5,
                        12,
                        11,
                        5,
                        11,
                        7
                    });
                break;
            }
            }
        }
Пример #3
0
        // Token: 0x060042F8 RID: 17144 RVA: 0x0015A1FC File Offset: 0x001585FC
        public static float GenerateGeometry(Mesh mesh, float radius, int subdivision, GeoSpherePrimitive.BaseType baseType, NormalsType normalsType, PivotPosition pivotPosition)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            radius      = Mathf.Clamp(radius, 0f, 100f);
            subdivision = Mathf.Clamp(subdivision, 0, 6);
            mesh.Clear();
            bool sharedVertices = normalsType == NormalsType.Vertex;
            int  i        = GeoSpherePrimitive.GetVertCount(baseType, subdivision, sharedVertices);
            int  triCount = GeoSpherePrimitive.GetTriCount(baseType, subdivision);

            while (i > 60000)
            {
                subdivision--;
                i        = GeoSpherePrimitive.GetVertCount(baseType, subdivision, sharedVertices);
                triCount = GeoSpherePrimitive.GetTriCount(baseType, subdivision);
            }
            Vector3 zero = Vector3.zero;

            if (pivotPosition != PivotPosition.Botttom)
            {
                if (pivotPosition == PivotPosition.Top)
                {
                    zero = new Vector3(0f, -radius, 0f);
                }
            }
            else
            {
                zero = new Vector3(0f, radius, 0f);
            }
            int[]     array   = new int[triCount * 3];
            int[]     array2  = new int[triCount * 3];
            Vector3[] array3  = new Vector3[i];
            Vector2[] array4  = new Vector2[i];
            Vector3[] normals = null;
            GeoSpherePrimitive.InitBasePrimitive(radius, baseType, array3, array4, array);
            Dictionary <int, int> indexLookup = new Dictionary <int, int>();
            int vertCount = GeoSpherePrimitive.GetVertCount(baseType, 0, sharedVertices);

            for (int j = 0; j < subdivision; j++)
            {
                int num  = 0;
                int num2 = GeoSpherePrimitive.GetTriCount(baseType, j) * 3;
                for (int k = 0; k < num2; k += 3)
                {
                    int num3 = array[k];
                    int num4 = array[k + 1];
                    int num5 = array[k + 2];
                    int num6 = GeoSpherePrimitive.AddMidPoint(array3, radius, vertCount++, num3, num4, indexLookup);
                    int num7 = GeoSpherePrimitive.AddMidPoint(array3, radius, vertCount++, num4, num5, indexLookup);
                    int num8 = GeoSpherePrimitive.AddMidPoint(array3, radius, vertCount++, num5, num3, indexLookup);
                    array2[num]      = num3;
                    array2[num + 1]  = num6;
                    array2[num + 2]  = num8;
                    array2[num + 3]  = num4;
                    array2[num + 4]  = num7;
                    array2[num + 5]  = num6;
                    array2[num + 6]  = num5;
                    array2[num + 7]  = num8;
                    array2[num + 8]  = num7;
                    array2[num + 9]  = num6;
                    array2[num + 10] = num7;
                    array2[num + 11] = num8;
                    num += 12;
                }
                int[] array5 = array2;
                array2 = array;
                array  = array5;
            }
            if (normalsType == NormalsType.Face)
            {
                MeshUtils.DuplicateSharedVertices(ref array3, ref array4, array, -1);
            }
            for (int l = 0; l < i; l++)
            {
                array4[l] = GeoSpherePrimitive.GetSphericalUV(ref array3[l]);
            }
            List <Vector3> list  = new List <Vector3>(array3);
            List <Vector2> list2 = new List <Vector2>(array4);
            List <int>     list3 = new List <int>(array);

            GeoSpherePrimitive.CorrectSeam(list, list2, list3);
            GeoSpherePrimitive.CorrectPoles(list, list2, ref list3, radius);
            array3 = list.ToArray();
            array  = list3.ToArray();
            if (normalsType == NormalsType.Vertex)
            {
                GeoSpherePrimitive.CalculateNormals(array3, out normals);
            }
            else
            {
                MeshUtils.ComputeVertexNormals(array3, array, out normals);
            }
            GeoSpherePrimitive.CorrectPivot(list, pivotPosition, ref zero);
            if (list.Count > 60000)
            {
                UnityEngine.Debug.LogError("Too much vertices!");
                return(0f);
            }
            mesh.vertices  = list.ToArray();
            mesh.uv        = list2.ToArray();
            mesh.triangles = list3.ToArray();
            mesh.normals   = normals;
            mesh.RecalculateBounds();
            MeshUtils.CalculateTangents(mesh);
            stopwatch.Stop();
            return((float)stopwatch.ElapsedMilliseconds);
        }