コード例 #1
0
        public static MeshEdge FindMeshEdge(Vector3 direction, Bounds tileBounds, Mesh mesh)
        {
            var vertices = GetBoundryVertices(direction, tileBounds, mesh);

            vertices = RemoveDubles(vertices);

            MeshEdge edge = FindEdge(vertices, direction);

            return(edge);
        }
コード例 #2
0
        private static MeshEdge FindEdge(List <Vertex> vertices, Vector3 direction)
        {
            var edgeVertices = new List <Vector3>();
            var edges        = new List <int>();

            for (int i = 0; i < vertices.Count; i++)
            {
                for (int j = i + 1; j < vertices.Count; j++)
                {
                    HashSet <int> common = new HashSet <int>(vertices[i].triangles);
                    common.IntersectWith(vertices[j].triangles);
                    if (common.Count == 1)
                    {
                        Vector3 v1 = vertices[i].position;
                        Vector3 v2 = vertices[j].position;

                        if (edgeVertices.Contains(v1) == false)
                        {
                            edgeVertices.Add(v1);
                        }
                        if (edgeVertices.Contains(v2) == false)
                        {
                            edgeVertices.Add(v2);
                        }

                        int indexV1 = edgeVertices.IndexOf(v1);
                        int indexV2 = edgeVertices.IndexOf(v2);

                        edges.Add(indexV1);
                        edges.Add(indexV2);
                    }
                }
            }

            var meshEdge = new MeshEdge(edgeVertices.ToArray(), edges.ToArray(), direction);

            return(meshEdge);
        }