void Start() { int n = 0; if (materials == null || materials.Length == 0) { materials = new Material[1]; // make a blank one } // let's make a very low poly one GameObject go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZMINUS, 10); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.left * 1.4f; SpinMeY.Attach(go); n++; // and now one that looks good go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZPLUS, 32); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.right * 1.4f; SpinMeY.Attach(go); n++; // and finally a SUPER-fine one, coincidentally also double-sided go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZMINUS, 1024, true); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.up * 1.4f; SpinMeY.Attach(go); n++; // a flat one, double-sided go = MakeUVCircle.Create(Vector3.one, AxisDirection.YPLUS, 32, true); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.down * 1.0f; SpinMeZ.Attach(go); n++; // an inverted one high where we can see it go = MakeUVCircle.Create(Vector3.one, AxisDirection.YMINUS, 32); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.up * 4.0f; SpinMeY.Attach(go); n++; // a nice simple five-pointed star go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZMINUS, 10, CyclicRadiusModifiers: new float[] { 1.0f, 0.5f }); go.GetComponent <MeshRenderer>().material = materials[n % materials.Length]; go.transform.position = Vector3.left * 3.4f + Vector3.up * 1.6f; n++; }
void Start() { int n = 0; if (materials == null || materials.Length == 0) { materials = new Material[1]; // make a blank one } // let's make a very low poly one GameObject go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZMINUS, 10); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.left * 1.4f; go.AddComponent <SpinMeY> (); n++; // and now one that looks good go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZPLUS, 32); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.right * 1.4f; go.AddComponent <SpinMeY> (); n++; // and finally a SUPER-fine one, coincidentally also double-sided go = MakeUVCircle.Create(Vector3.one, AxisDirection.ZMINUS, 1024, true); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.up * 1.4f; go.AddComponent <SpinMeY> ().RateOfSpin *= 0.3f; n++; // a flat one, double-sided go = MakeUVCircle.Create(Vector3.one, AxisDirection.YPLUS, 32, true); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.down * 1.0f; go.AddComponent <SpinMeZ> (); n++; // an inverted one high where we can see it go = MakeUVCircle.Create(Vector3.one, AxisDirection.YMINUS, 32); go.GetComponent <MeshRenderer> ().material = materials [n % materials.Length]; go.transform.position = Vector3.up * 4.0f; go.AddComponent <SpinMeY> (); n++; }
// top is y position and x,z radius // bottom is y position and x,z radius // sectors are how many longitudinal dividers (full equatorial) going around // bands are how many vertical bands / dividers (base to top) public static GameObject Create(Vector3 top, Vector3 bottom, int sectors, int bands, bool capTop = true, bool capBottom = true) { if (bands < 2) { bands = 2; } GameObject go = new GameObject("MakeUVCone.Create();"); MeshFilter mf = go.AddComponent <MeshFilter> (); Mesh mesh = new Mesh(); List <Vector3> verts = new List <Vector3> (); List <int> tris = new List <int> (); List <Vector2> uvs = new List <Vector2> (); for (int i = 0; i <= sectors; i++) { float longitude = (Mathf.PI * 2 * i) / sectors; for (int j = 0; j < bands; j++) { int n = verts.Count; float fraction = (float)j / (bands - 1); Vector3 radius = Vector3.Lerp(bottom, top, fraction); Vector3 conicalPoint = new Vector3( Mathf.Cos(longitude) * radius.x, Mathf.Lerp(bottom.y, top.y, fraction), Mathf.Sin(longitude) * radius.z); verts.Add(conicalPoint); Vector2 uvPoint = new Vector2((float)i / sectors, (float)j / (bands - 1)); uvs.Add(uvPoint); if (i > 0 && j > 0) { tris.Add(n); tris.Add(n - (bands + 1)); tris.Add(n - bands); tris.Add(n); tris.Add(n - 1); tris.Add(n - (bands + 1)); } } } mesh.vertices = verts.ToArray(); mesh.triangles = tris.ToArray(); mesh.uv = uvs.ToArray(); mesh.RecalculateBounds(); mesh.RecalculateNormals(); mf.mesh = mesh; go.AddComponent <MeshRenderer> (); // for now top and bottom caps are provided on separate GameObjects if (capTop) { var cap = MakeUVCircle.Create(top, AxisDirection.YPLUS, sectors); cap.transform.SetParent(go.transform); cap.transform.localPosition = Vector3.up * top.y; } if (capBottom) { var cap = MakeUVCircle.Create(bottom, AxisDirection.YMINUS, sectors); cap.transform.SetParent(go.transform); cap.transform.localPosition = Vector3.up * bottom.y; } return(go); }