public void Build() { Name = "Cone " + TotalObjects.ToString(); Element = new GameObject(PublicName); Element.transform.position = StartPoint; Element.AddComponent <MeshRenderer>(); mf = new MeshFilter(); mf = Element.AddComponent <MeshFilter>(); mesh = new Mesh(); mf.sharedMesh = mesh; MeshCollider MC = Element.AddComponent <MeshCollider>(); #region blablabla //verticies List <Vector3> verticiesList = new List <Vector3> { }; List <Vector3> verticiesList2 = new List <Vector3> { }; float x; // = radius.Value * Mathf.Sin((2 * Mathf.PI * (points - 1) / points)) / 2f; float z; //= radius.Value * Mathf.Cos((2 * Mathf.PI * (points - 1) / points)) / 2f; verticiesList.Add(new Vector3(0f, height.Value, 0f)); verticiesList2.Add(verticiesList[0]); for (int i = 0; i < points; i++) { x = radius.Value * Mathf.Sin((2 * Mathf.PI * i) / points); z = radius.Value * Mathf.Cos((2 * Mathf.PI * i) / points); verticiesList2.Add(new Vector3(x, 0f, z)); } if (points > 3) { List <Vector3> MainVectors = new List <Vector3> { }; //Liczydło int Abacus = points / 3; for (int i = 1; i < Abacus * 3; i += Abacus) { MainVectors.Add(verticiesList2[i]); } for (int i = 0; i < 3; i++) { ix += MainVectors[i].x; iz += MainVectors[i].z; } C_x = ix / 3; C_z = iz / 3; verticiesList.Add(new Vector3(C_x, 0f, C_z)); } for (int i = 0; i < points; i++) { x = radius.Value * Mathf.Sin((2 * Mathf.PI * i) / points); z = radius.Value * Mathf.Cos((2 * Mathf.PI * i) / points); verticiesList.Add(new Vector3(x, 0f, z)); } Vector3[] verticies = verticiesList.ToArray(); /* * //Vertices// * Vector3[] vertices = new Vector3[] * { * * * };*/ //triangles List <int> trianglesList = new List <int> { }; for (int i = 1; i <= points; i++) { if (points == 3) { if (i < points - 1) { trianglesList.Add(0); trianglesList.Add(i + 1); trianglesList.Add(i + 2); } else { trianglesList.Add(0); trianglesList.Add(points); trianglesList.Add(points - i); } } else { if (i < points) { trianglesList.Add(0); trianglesList.Add(i + 1); trianglesList.Add(i + 2); } else { trianglesList.Add(0); trianglesList.Add(points + 1); trianglesList.Add(2); } } } if (points == 3) { for (int i = points; i >= 2; i--) { trianglesList.Add(i); } } else { for (int i = points + 1; i >= 2; i--) { if (i > 2) { trianglesList.Add(i); trianglesList.Add(i - 1); trianglesList.Add(1); } else { trianglesList.Add(i); trianglesList.Add(points + 1); trianglesList.Add(1); } } } int[] triangles = trianglesList.ToArray(); //normals /*List<Vector3> normalsList = new List<Vector3> { }; * for (int i = 0; i < verticies.Length; i++) * { * normalsList.Add(-Vector3.forward); * } * Vector3[] normals = normalsList.ToArray();*/ //UVs// Vector2[] uvs = new Vector2[verticies.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(verticies[i].x, verticies[i].z); } mesh.Clear(); mesh.vertices = verticies; mesh.uv = uvs; //mesh.normals = normals; mesh.triangles = triangles; MC.sharedMesh = Mesh.Instantiate(mesh); Existed += 1; Element.AddInformation(PublicName, Name, type); #endregion }
// Use this for initialization public void Build() { Name = "Duplex Trapeze " + TotalObjects.ToString(); RightDownFront = new Vector3(BottomRadius.Length.Right, 0f, 0f); RightUpFront = new Vector3(TopRadius.Length.Right * upperWidth, Height.Value, 0f); RightDownBack = new Vector3(BottomRadius.Length.Right, 0f, BottomRadius.Height.Value); RightUpBack = new Vector3(TopRadius.Length.Right * upperWidth, Height.Value, TopRadius.Height.Value); LeftDownFront = new Vector3(-BottomRadius.Length.Left, 0f, 0f); LeftUpFront = new Vector3(-TopRadius.Length.Left * upperWidth, Height.Value, 0f); LeftDownBack = new Vector3(-BottomRadius.Length.Left, 0f, BottomRadius.Height.Value); LeftUpBack = new Vector3(-TopRadius.Length.Left * upperWidth, Height.Value, TopRadius.Height.Value); /* * RightMiddleFront = new Vector3(BottomRadius.Length.Right / 2f, 0f, 0f); * LeftMiddleFront = new Vector3(-BottomRadius.Length.Left / 2f, 0f, 0f); * * RightMiddleBack = new Vector3(BottomRadius.Length.Right / 2f, 0f, BottomRadius.Height.Value); * LeftMiddleBack = new Vector3(-BottomRadius.Length.Left / 2f, 0f, BottomRadius.Height.Value); */ UpperCenter = new Vector3(TopRadius.Length.Value / 2f, Height.Value, TopRadius.Height.Value / 2f); BottomCenter = new Vector3(BottomRadius.Length.Value / 2f, 0f, BottomRadius.Height.Value / 2f); LeftCenter = new Vector3(-BottomRadius.Length.Right / 2f, Height.Value / 2f, BottomRadius.Height.Value / 2f); RightCenter = new Vector3(BottomRadius.Length.Right / 2f, Height.Value / 2f, BottomRadius.Height.Value / 2f); Element = new GameObject(PublicName); Element.transform.position = StartPoint; Element.AddComponent <MeshRenderer>(); mf = new MeshFilter(); mf = Element.AddComponent <MeshFilter>(); mesh = new Mesh(); mf.sharedMesh = mesh; MeshCollider MC = Element.AddComponent <MeshCollider>(); #region blablabla //Vertices// Vector3[] vertices = new Vector3[] { // RightMiddleFront, // RightMiddleBack, RightDownFront, RightDownBack, RightUpFront, RightUpBack, LeftUpFront, LeftUpBack, LeftDownFront, LeftDownBack, // LeftMiddleFront, // LeftMiddleBack }; //Triangles// 3 points, clockwise determines which side is visible List <int> triangles = new List <int>(); for (int a = 0; a < 5; a += 2) { if (a < 10) { triangles.Add(a + 2); triangles.Add(a + 1); triangles.Add(a); triangles.Add(a + 3); triangles.Add(a + 1); triangles.Add(a + 2); } } triangles.Add(7); triangles.Add(6); triangles.Add(0); triangles.Add(1); triangles.Add(7); triangles.Add(0); triangles.Add(4); triangles.Add(2); triangles.Add(0); triangles.Add(6); triangles.Add(4); triangles.Add(0); triangles.Add(1); triangles.Add(3); triangles.Add(5); triangles.Add(1); triangles.Add(5); triangles.Add(7); //UVs// Vector2[] uvs = new Vector2[vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(vertices[i].x, vertices[i].z); } mesh.Clear(); mesh.vertices = vertices; mesh.uv = uvs; mesh.triangles = triangles.ToArray(); MC.sharedMesh = Mesh.Instantiate(mesh); Existed += 1; Element.AddInformation(PublicName, Name, type); #endregion }