Exemple #1
0
        public static Vertex[] Create(int smoothLevel = 0)
        {
            IReadOnlyList <Triangle> triangles = Icosahedron.CreateTriangles();

            for (var i = 0; i < smoothLevel; ++i)
            {
                var smoothedTriangles = new List <Triangle>(triangles.Count * 4);
                foreach (var tri in triangles)
                {
                    var a = Vector3.Normalize(GeometryHelper.GetEdgeMiddle(tri.A, tri.B));
                    var b = Vector3.Normalize(GeometryHelper.GetEdgeMiddle(tri.B, tri.C));
                    var c = Vector3.Normalize(GeometryHelper.GetEdgeMiddle(tri.C, tri.A));

                    smoothedTriangles.Add(new Triangle(tri.A, a, c));
                    smoothedTriangles.Add(new Triangle(tri.B, b, a));
                    smoothedTriangles.Add(new Triangle(tri.C, c, b));
                    smoothedTriangles.Add(new Triangle(a, b, c));
                }

                triangles = smoothedTriangles;
            }

            var mesh = triangles.ToMesh();

            GeometryHelper.UVMap(mesh, UVMapping);
            return(mesh);
        }
Exemple #2
0
        private static Vector3 GetNewPosition(IReadOnlyList <Triangle> allFaces, Vector3 vertex)
        {
            var faces = GetFacesForPoint(allFaces, vertex);
            var edges = GetEdgesForPoint(allFaces, vertex);

            if (faces.Count == edges.Count)
            {
                return(Barycentre(vertex, faces.Count,
                                  GeometryHelper.Average(faces.Select(f => f.Center)),
                                  GeometryHelper.Average(edges.Select(p => GeometryHelper.GetEdgeMiddle(vertex, p)))));
            }
            else
            {
                var avgMidEdges = GeometryHelper.Average(edges.Where(p => GetFacesForEdge(allFaces, vertex, p).Count == 1).Select(p => GeometryHelper.GetEdgeMiddle(vertex, p)));
                return((vertex + avgMidEdges) / 2f);
            }
        }