Example #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);
        }
Example #2
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);
        }