Exemplo n.º 1
0
        // This sorts the vertices of a face clockwise from a given "baseline" vertex.
        private Vertex[] SortBoundaryVertices(Face face, Vertex baseline)
        {
            var center = CenterOfFace(face);

            // So we sort the vertices clockwise from 12 o'clock (global north)...
            var clockwiseFromBaseline   = new CompareVectorsClockwise(center, new Vector3(0, 0, 1));
            var clockwiseSortedVertices = face.Vertices.OrderBy(vertex => vertex.Position, clockwiseFromBaseline).ToList();

            // ...and then cycle the elements of the array so that the first vertex in the array is the baseline.
            var indexOfBaseline = clockwiseSortedVertices.IndexOf(baseline);
            var sortedVertices  = new Vertex[clockwiseSortedVertices.Count];

            for (int i = 0; i < sortedVertices.Length; i++)
            {
                sortedVertices[i] = clockwiseSortedVertices[MathMod(indexOfBaseline + i, clockwiseSortedVertices.Count)];
            }

            return(sortedVertices);
        }
        private Dictionary <Face, Vertex> CreateGeodesicVertices(List <Face> icosahedralFaces)
        {
            var geodesicVertices = new Dictionary <Face, Vertex>();

            foreach (var face in icosahedralFaces)
            {
                var centerOfFace = FoamUtils.Center(face);

                var corners           = face.Vertices.Select(vertex => vertex.Position).ToList();
                var clockwiseComparer = new CompareVectorsClockwise(centerOfFace, corners.First());
                var orderedCorners    = corners.OrderBy(corner => corner, clockwiseComparer).ToList();

                var edgeA        = orderedCorners[1].normalized - orderedCorners[0].normalized;
                var edgeB        = orderedCorners[2].normalized - orderedCorners[0].normalized;
                var voronoiPoint = Vector3.Cross(edgeA, edgeB).normalized;

                var geodesicVertex = new Vertex {
                    Position = voronoiPoint
                };
                geodesicVertices.Add(face, geodesicVertex);
            }

            return(geodesicVertices);
        }