protected override void Generate()
        {
            int hVertCount = _sides + 1;
            int vVertCount = _heightSegments + 1;

            float startAngle = GetStartAngle();
            float angleStep  = _angleSweep / _sides;

            float startHeight = GetStartY();
            float heightStep  = _height / _heightSegments;

            Vector3[] verts       = new Vector3[hVertCount * vVertCount];
            Vector2[] uvs         = new Vector2[hVertCount * vVertCount];
            int       vertexIndex = 0;

            for (int x = 0; x < hVertCount; x++)
            {
                float   angle      = angleStep * x + startAngle;
                Vector3 baseVertex = _radius * new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle));

                for (int y = 0; y < vVertCount; y++)
                {
                    Vector3 vertex = baseVertex + new Vector3(0, startHeight - heightStep * y, 0);
                    verts[vertexIndex] = vertex;
                    uvs[vertexIndex]   = MeshGenerationUtils.GenerateUVCoord(x, y, hVertCount, vVertCount, -Vector2.one, Vector2.one);
                    vertexIndex++;
                }
            }

            _progress = 1f;

            // Only one LOD is generated.
            _meshData = new MeshData[] {
                new MeshData()
                {
                    Vertices  = verts,
                    TexCoords = uvs,
                    Triangles = MeshGenerationUtils.GenerateTrianglesTransposed(hVertCount, vVertCount)
                }
            };
        }
예제 #2
0
        private Mesh GenerateMesh()
        {
            Vector3[] verts = new Vector3[] {
                new Vector3(0, 0),
                new Vector3(0, 1),
                new Vector3(1, 0),
                new Vector3(1, 1)
            };

            Vector2[] uvs = new Vector2[] {
                new Vector3(0, 0),
                new Vector3(0, 1),
                new Vector3(1, 0),
                new Vector3(1, 1)
            };

            int[] tris = MeshGenerationUtils.GenerateTrianglesTransposed(2, 2);

            return(new Mesh {
                vertices = verts,
                uv = uvs,
                triangles = tris
            });
        }