using System.Collections.Generic; using UnityEngine; using System.IO; using System; namespace ProceduralToolkit { public partial class MeshDraft { public static MeshDraft Sphere_EX(float radius, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("Sphere.txt")) //{ var draft = new MeshDraft { name = "Sphere" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = Mathf.PI / latitudeSegments; float currentLatitude = -Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //writer.WriteLine("{0} Long = {1:f3} Lat = {2:f3} Vertex = " + point.ToString("F3"),line_no, currentLongitude, currentLatitude); draft.normals.Add(point.normalized); draft.uv.Add(new Vector2((float)i / longitudeSegments, (float)ring / latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude -= longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude += latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0,i1,i2,i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } public static MeshDraft Sphere_Location_EX(float radius, Vector3 pos, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("Sphere.txt")) //{ var draft = new MeshDraft { name = "Sphere" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = Mathf.PI / latitudeSegments; float currentLatitude = -Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point + pos); //writer.WriteLine("{0} Long = {1:f3} Lat = {2:f3} Vertex = " + point.ToString("F3"),line_no, currentLongitude, currentLatitude); draft.normals.Add(point.normalized); draft.uv.Add(new Vector2((float)i / longitudeSegments, (float)ring / latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude -= longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude += latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0,i1,i2,i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } public static MeshDraft Sphere_Argos_EX(float radius, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("CheckLongLat.txt")) //{ var draft = new MeshDraft { name = "Sphere Argos" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = Mathf.PI / latitudeSegments; //float fCheckLong; //float fCheckLat; float currentLatitude = Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //fCheckLong = Mathf.Atan2(point.x, point.z); //if(fCheckLong < 0.0f) //{ // fCheckLong = 2f * Mathf.PI + fCheckLong; //} //fCheckLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x*point.x+point.z*point.z)); //writer.WriteLine("Actual {0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, currentLongitude, currentLatitude); //writer.WriteLine("Derived{0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, fCheckLong, fCheckLat); //writer.WriteLine("------"); draft.normals.Add(point.normalized); //draft.uv.Add(new Vector2((float) i/longitudeSegments, (float) ring/latitudeSegments)); draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude += longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude -= latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0, i1, i2, i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } public static MeshDraft Lens_Argos_LLUV_ANGLE_EX(float angle, float radius, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("CheckLongLat.txt")) //{ var draft = new MeshDraft { name = "AT&T PRESENTATION LENS - ANTENNA" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = angle / latitudeSegments; //float fCheckLong; //float fCheckLat; float currentLatitude = Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //fCheckLong = Mathf.Atan2(point.x, point.z); //if(fCheckLong < 0.0f) //{ // fCheckLong = 2f * Mathf.PI + fCheckLong; //} //fCheckLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x*point.x+point.z*point.z)); //writer.WriteLine("Actual {0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, currentLongitude, currentLatitude); //writer.WriteLine("Derived{0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, fCheckLong, fCheckLat); //writer.WriteLine("------"); draft.normals.Add(-point.normalized); draft.uv.Add(new Vector2((float)i / longitudeSegments, (float)ring / latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude -= longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude += latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i2, i1 }); draft.triangles.AddRange(new[] { i1, i2, i3 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0, i1, i2, i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i2, i1 }); draft.triangles.AddRange(new[] { i2, i3, i1 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } line_no = 0; longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; latitudeSegmentAngle = angle / latitudeSegments; //float fCheckLong; //float fCheckLat; currentLatitude = Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //fCheckLong = Mathf.Atan2(point.x, point.z); //if(fCheckLong < 0.0f) //{ // fCheckLong = 2f * Mathf.PI + fCheckLong; //} //fCheckLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x*point.x+point.z*point.z)); //writer.WriteLine("Actual {0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, currentLongitude, currentLatitude); //writer.WriteLine("Derived{0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, fCheckLong, fCheckLat); //writer.WriteLine("------"); draft.normals.Add(-point.normalized); draft.uv.Add(new Vector2((float)i / longitudeSegments, (float)ring / latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude -= longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude += latitudeSegmentAngle; } line_no = 0; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i1, i3, i2 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0, i1, i2, i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } public static MeshDraft Sphere_Argos_LLUV_EX(float radius, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("CheckLongLat.txt")) //{ var draft = new MeshDraft { name = "Sphere Argos" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = Mathf.PI / latitudeSegments; //float fCheckLong; //float fCheckLat; float currentLatitude = Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //fCheckLong = Mathf.Atan2(point.x, point.z); //if(fCheckLong < 0.0f) //{ // fCheckLong = 2f * Mathf.PI + fCheckLong; //} //fCheckLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x*point.x+point.z*point.z)); //writer.WriteLine("Actual {0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, currentLongitude, currentLatitude); //writer.WriteLine("Derived{0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, fCheckLong, fCheckLat); //writer.WriteLine("------"); draft.normals.Add(-point.normalized); draft.uv.Add(new Vector2((float)i / longitudeSegments, (float)ring / latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); currentLongitude += longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude -= latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i0, i2, i1 }); draft.triangles.AddRange(new[] { i1, i2, i3 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0, i1, i2, i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i0, i1, i2 }); draft.triangles.AddRange(new[] { i2, i1, i3 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } public static MeshDraft Sphere_Argos_Horzontal_EX(float radius, int longitudeSegments, int latitudeSegments) { //using (var writer = new StreamWriter("CheckLongLat.txt")) //{ var draft = new MeshDraft { name = "Sphere Argos" }; int line_no = 0; float longitudeSegmentAngle = Mathf.PI * 2 / longitudeSegments; float latitudeSegmentAngle = Mathf.PI / latitudeSegments; //float fCheckLong; //float fCheckLat; float currentLatitude = Mathf.PI / 2; for (var ring = 0; ring <= latitudeSegments; ring++) { var currentLongitude = 0f; for (int i = 0; i < longitudeSegments; i++) { var point = PTUtils.PointOnSphere_Zmajor(radius, currentLongitude, currentLatitude); draft.vertices.Add(point); //fCheckLong = Mathf.Atan2(point.x, point.z); //if(fCheckLong < 0.0f) //{ // fCheckLong = 2f * Mathf.PI + fCheckLong; //} //fCheckLat = Mathf.Atan2(point.y, Mathf.Sqrt(point.x*point.x+point.z*point.z)); //writer.WriteLine("Actual {0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, currentLongitude, currentLatitude); //writer.WriteLine("Derived{0} Long = {1:f5} Lat = {2:f5} Vertex = " + point.ToString("F10"), line_no, fCheckLong, fCheckLat); //writer.WriteLine("------"); draft.normals.Add(-point.normalized); //draft.uv.Add(new Vector2((float) i/longitudeSegments, (float) ring/latitudeSegments)); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); //draft.uv.Add(new Vector2((float)(i % 2), (float)(ring % 2))); draft.uv.Add(new Vector2(Mathf.Sin(((i % 8) / 8f) * Mathf.PI), Mathf.Sin(((ring % 8) / 8f) * Mathf.PI))); currentLongitude += longitudeSegmentAngle; line_no++; } //writer.WriteLine("---------------------------"); currentLatitude -= latitudeSegmentAngle; } line_no = 0; int i0, i1, i2, i3; for (int ring = 0; ring < latitudeSegments; ring++) { for (int i = 0; i < longitudeSegments - 1; i++) { i0 = ring * longitudeSegments + i; i1 = (ring + 1) * longitudeSegments + i; i2 = ring * longitudeSegments + i + 1; i3 = (ring + 1) * longitudeSegments + i + 1; draft.triangles.AddRange(new[] { i1, i2, i0 }); draft.triangles.AddRange(new[] { i1, i3, i2 }); //writer.WriteLine("{6} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = {5} ", i0, i1, i2, i3, ring, i, line_no); line_no += 6; } i0 = (ring + 1) * longitudeSegments - 1; i1 = (ring + 2) * longitudeSegments - 1; i2 = ring * longitudeSegments; i3 = (ring + 1) * longitudeSegments; draft.triangles.AddRange(new[] { i1, i2, i0 }); draft.triangles.AddRange(new[] { i1, i3, i2 }); //writer.WriteLine("----------"); //writer.WriteLine("{5} (idx) {0},{1},{2},{2},{1},{3} ring = {4} i = extra ", i0, i1, i2, i3, ring, line_no); //writer.WriteLine("-----------------"); line_no += 6; } //writer.Close(); return draft; //} } } }