Пример #1
0
        public IcosphereBuilder(IcosphereBuilder source)
        {
            _vertices.AddRange(source._vertices);

            var midPoints = new MidpointTable(_vertices);

            foreach (var t in source._triangles)
            {
                var m1 = midPoints.GetMidpoint(t.i1, t.i2);
                var m2 = midPoints.GetMidpoint(t.i2, t.i3);
                var m3 = midPoints.GetMidpoint(t.i3, t.i1);

                _triangles.Add((t.i1, m1, m3));
                _triangles.Add((m1, t.i2, m2));
                _triangles.Add((m3, m2, t.i3));
                _triangles.Add((m1, m2, m3));
            }
        }
Пример #2
0
        public void Generate(Mesh mesh)
        {
            var builder = new IcosphereBuilder();

            for (var i = 1; i < Subdivision; i++)
            {
                builder = new IcosphereBuilder(builder);
            }

            var vtx = builder.Vertices.Select(v => (Vector3)(v * Radius));
            var nrm = builder.Vertices.Select(v => (Vector3)v);
            var idx = builder.Indices;

            if (builder.VertexCount > 65535)
            {
                mesh.indexFormat = IndexFormat.UInt32;
            }
            mesh.SetVertices(vtx.ToList());
            mesh.SetNormals(nrm.ToList());
            mesh.SetIndices(idx.ToList(), MeshTopology.Triangles, 0);
        }