public static Mesh GenerateConeZ_Radius(float lengthZ, float radiusStart, float radiusEnd, int numSides, int numSegments, bool cap) { Debug.Assert(lengthZ > 0f); Debug.Assert(radiusStart >= 0f); Debug.Assert(numSides >= 3); Debug.Assert(numSegments >= 0); Mesh mesh = new Mesh(); bool flag = false; flag = (!cap ? false : radiusStart > 0f); radiusStart = Mathf.Max(radiusStart, 0.001f); int num = numSides * (numSegments + 2); int num1 = num; if (flag) { num1 = num1 + numSides + 1; } Vector3[] vector3 = new Vector3[num1]; for (int i = 0; i < numSides; i++) { float single = 6.28318548f * (float)i / (float)numSides; float single1 = Mathf.Cos(single); float single2 = Mathf.Sin(single); for (int j = 0; j < numSegments + 2; j++) { float single3 = (float)j / (float)(numSegments + 1); Debug.Assert((single3 < 0f ? false : single3 <= 1f)); float single4 = Mathf.Lerp(radiusStart, radiusEnd, single3); vector3[i + j * numSides] = new Vector3(single4 * single1, single4 * single2, single3 * lengthZ); } } if (flag) { int num2 = num; vector3[num2] = Vector3.zero; num2++; for (int k = 0; k < numSides; k++) { float single5 = 6.28318548f * (float)k / (float)numSides; float single6 = Mathf.Cos(single5); float single7 = Mathf.Sin(single5); vector3[num2] = new Vector3(radiusStart * single6, radiusStart * single7, 0f); num2++; } Debug.Assert(num2 == (int)vector3.Length); } if (MeshGenerator.duplicateBackFaces) { Vector3[] vector3Array = new Vector3[(int)vector3.Length * 2]; vector3.CopyTo(vector3Array, 0); vector3.CopyTo(vector3Array, (int)vector3.Length); mesh.vertices = vector3Array; } else { mesh.vertices = vector3; } Vector2[] vector2 = new Vector2[num1]; int num3 = 0; for (int l = 0; l < num; l++) { int num4 = num3; num3 = num4 + 1; vector2[num4] = Vector2.zero; } if (flag) { for (int m = 0; m < numSides + 1; m++) { int num5 = num3; num3 = num5 + 1; vector2[num5] = new Vector2(1f, 0f); } } Debug.Assert(num3 == (int)vector2.Length); if (MeshGenerator.duplicateBackFaces) { Vector2[] vector2Array = new Vector2[(int)vector2.Length * 2]; vector2.CopyTo(vector2Array, 0); vector2.CopyTo(vector2Array, (int)vector2.Length); for (int n = 0; n < (int)vector2.Length; n++) { Vector2 vector21 = vector2Array[n + (int)vector2.Length]; vector2Array[n + (int)vector2.Length] = new Vector2(vector21.x, 1f); } mesh.uv = vector2Array; } else { mesh.uv = vector2; } int num6 = numSides * 2 * Mathf.Max(numSegments + 1, 1) * 3; if (flag) { num6 = num6 + numSides * 3; } int[] numArray = new int[num6]; int num7 = 0; for (int o = 0; o < numSides; o++) { int num8 = o + 1; if (num8 == numSides) { num8 = 0; } for (int p = 0; p < numSegments + 1; p++) { int num9 = p * numSides; int num10 = num7; num7 = num10 + 1; numArray[num10] = num9 + o; int num11 = num7; num7 = num11 + 1; numArray[num11] = num9 + num8; int num12 = num7; num7 = num12 + 1; numArray[num12] = num9 + o + numSides; int num13 = num7; num7 = num13 + 1; numArray[num13] = num9 + num8 + numSides; int num14 = num7; num7 = num14 + 1; numArray[num14] = num9 + o + numSides; int num15 = num7; num7 = num15 + 1; numArray[num15] = num9 + num8; } } if (flag) { for (int q = 0; q < numSides - 1; q++) { int num16 = num7; num7 = num16 + 1; numArray[num16] = num; int num17 = num7; num7 = num17 + 1; numArray[num17] = num + q + 2; int num18 = num7; num7 = num18 + 1; numArray[num18] = num + q + 1; } int num19 = num7; num7 = num19 + 1; numArray[num19] = num; int num20 = num7; num7 = num20 + 1; numArray[num20] = num + 1; int num21 = num7; num7 = num21 + 1; numArray[num21] = num + numSides; } Debug.Assert(num7 == (int)numArray.Length); if (MeshGenerator.duplicateBackFaces) { int[] numArray1 = new int[(int)numArray.Length * 2]; numArray.CopyTo(numArray1, 0); for (int r = 0; r < (int)numArray.Length; r += 3) { numArray1[(int)numArray.Length + r] = numArray[r] + num1; numArray1[(int)numArray.Length + r + 1] = numArray[r + 2] + num1; numArray1[(int)numArray.Length + r + 2] = numArray[r + 1] + num1; } mesh.triangles = numArray1; } else { mesh.triangles = numArray; } Bounds bound = new Bounds(new Vector3(0f, 0f, lengthZ * 0.5f), new Vector3(Mathf.Max(radiusStart, radiusEnd) * 2f, Mathf.Max(radiusStart, radiusEnd) * 2f, lengthZ)); mesh.bounds = bound; Debug.Assert(mesh.vertexCount == MeshGenerator.GetVertexCount(numSides, numSegments, flag)); Debug.Assert((int)mesh.triangles.Length == MeshGenerator.GetIndicesCount(numSides, numSegments, flag)); return(mesh); }
public static int GetSharedMeshIndicesCount() { return(MeshGenerator.GetIndicesCount(Config.Instance.sharedMeshSides, Config.Instance.sharedMeshSegments, true)); }
public static Mesh GenerateConeZ_Radius( float lengthZ, float radiusStart, float radiusEnd, int numSides, int numSegments, bool cap) { Debug.Assert((double)lengthZ > 0.0); Debug.Assert((double)radiusStart >= 0.0); Debug.Assert(numSides >= 3); Debug.Assert(numSegments >= 0); Mesh mesh = new Mesh(); bool geomCap = cap && (double)radiusStart > 0.0; radiusStart = Mathf.Max(radiusStart, 1f / 1000f); int num1 = numSides * (numSegments + 2); int length1 = num1; if (geomCap) { length1 += numSides + 1; } Vector3[] vector3Array1 = new Vector3[length1]; for (int index1 = 0; index1 < numSides; ++index1) { double num2 = 6.28318548202515 * (double)index1 / (double)numSides; float num3 = Mathf.Cos((float)num2); float num4 = Mathf.Sin((float)num2); for (int index2 = 0; index2 < numSegments + 2; ++index2) { float num5 = (float)index2 / (float)(numSegments + 1); Debug.Assert((double)num5 >= 0.0 && (double)num5 <= 1.0); float num6 = Mathf.Lerp(radiusStart, radiusEnd, num5); vector3Array1[index1 + index2 * numSides] = new Vector3(num6 * num3, num6 * num4, num5 * lengthZ); } } if (geomCap) { int index1 = num1; vector3Array1[index1] = Vector3.get_zero(); int index2 = index1 + 1; for (int index3 = 0; index3 < numSides; ++index3) { double num2 = 6.28318548202515 * (double)index3 / (double)numSides; float num3 = Mathf.Cos((float)num2); float num4 = Mathf.Sin((float)num2); vector3Array1[index2] = new Vector3(radiusStart * num3, radiusStart * num4, 0.0f); ++index2; } Debug.Assert(index2 == vector3Array1.Length); } if (!MeshGenerator.duplicateBackFaces) { mesh.set_vertices(vector3Array1); } else { Vector3[] vector3Array2 = new Vector3[vector3Array1.Length * 2]; vector3Array1.CopyTo((Array)vector3Array2, 0); vector3Array1.CopyTo((Array)vector3Array2, vector3Array1.Length); mesh.set_vertices(vector3Array2); } Vector2[] vector2Array1 = new Vector2[length1]; int num7 = 0; for (int index = 0; index < num1; ++index) { vector2Array1[num7++] = Vector2.get_zero(); } if (geomCap) { for (int index = 0; index < numSides + 1; ++index) { vector2Array1[num7++] = new Vector2(1f, 0.0f); } } Debug.Assert(num7 == vector2Array1.Length); if (!MeshGenerator.duplicateBackFaces) { mesh.set_uv(vector2Array1); } else { Vector2[] vector2Array2 = new Vector2[vector2Array1.Length * 2]; vector2Array1.CopyTo((Array)vector2Array2, 0); vector2Array1.CopyTo((Array)vector2Array2, vector2Array1.Length); for (int index = 0; index < vector2Array1.Length; ++index) { Vector2 vector2 = vector2Array2[index + vector2Array1.Length]; vector2Array2[index + vector2Array1.Length] = new Vector2((float)vector2.x, 1f); } mesh.set_uv(vector2Array2); } int length2 = numSides * 2 * Mathf.Max(numSegments + 1, 1) * 3; if (geomCap) { length2 += numSides * 3; } int[] numArray1 = new int[length2]; int num8 = 0; for (int index1 = 0; index1 < numSides; ++index1) { int num2 = index1 + 1; if (num2 == numSides) { num2 = 0; } for (int index2 = 0; index2 < numSegments + 1; ++index2) { int num3 = index2 * numSides; int[] numArray2 = numArray1; int index3 = num8; int num4 = index3 + 1; int num5 = num3 + index1; numArray2[index3] = num5; int[] numArray3 = numArray1; int index4 = num4; int num6 = index4 + 1; int num9 = num3 + num2; numArray3[index4] = num9; int[] numArray4 = numArray1; int index5 = num6; int num10 = index5 + 1; int num11 = num3 + index1 + numSides; numArray4[index5] = num11; int[] numArray5 = numArray1; int index6 = num10; int num12 = index6 + 1; int num13 = num3 + num2 + numSides; numArray5[index6] = num13; int[] numArray6 = numArray1; int index7 = num12; int num14 = index7 + 1; int num15 = num3 + index1 + numSides; numArray6[index7] = num15; int[] numArray7 = numArray1; int index8 = num14; num8 = index8 + 1; int num16 = num3 + num2; numArray7[index8] = num16; } } if (geomCap) { for (int index1 = 0; index1 < numSides - 1; ++index1) { int[] numArray2 = numArray1; int index2 = num8; int num2 = index2 + 1; int num3 = num1; numArray2[index2] = num3; int[] numArray3 = numArray1; int index3 = num2; int num4 = index3 + 1; int num5 = num1 + index1 + 2; numArray3[index3] = num5; int[] numArray4 = numArray1; int index4 = num4; num8 = index4 + 1; int num6 = num1 + index1 + 1; numArray4[index4] = num6; } int[] numArray5 = numArray1; int index5 = num8; int num9 = index5 + 1; int num10 = num1; numArray5[index5] = num10; int[] numArray6 = numArray1; int index6 = num9; int num11 = index6 + 1; int num12 = num1 + 1; numArray6[index6] = num12; int[] numArray7 = numArray1; int index7 = num11; num8 = index7 + 1; int num13 = num1 + numSides; numArray7[index7] = num13; } Debug.Assert(num8 == numArray1.Length); if (!MeshGenerator.duplicateBackFaces) { mesh.set_triangles(numArray1); } else { int[] numArray2 = new int[numArray1.Length * 2]; numArray1.CopyTo((Array)numArray2, 0); for (int index = 0; index < numArray1.Length; index += 3) { numArray2[numArray1.Length + index] = numArray1[index] + length1; numArray2[numArray1.Length + index + 1] = numArray1[index + 2] + length1; numArray2[numArray1.Length + index + 2] = numArray1[index + 1] + length1; } mesh.set_triangles(numArray2); } Bounds bounds; ((Bounds) ref bounds).\u002Ector(new Vector3(0.0f, 0.0f, lengthZ * 0.5f), new Vector3(Mathf.Max(radiusStart, radiusEnd) * 2f, Mathf.Max(radiusStart, radiusEnd) * 2f, lengthZ)); mesh.set_bounds(bounds); Debug.Assert(mesh.get_vertexCount() == MeshGenerator.GetVertexCount(numSides, numSegments, geomCap)); Debug.Assert(mesh.get_triangles().Length == MeshGenerator.GetIndicesCount(numSides, numSegments, geomCap)); return(mesh); }