コード例 #1
0
ファイル: MeshHelper.cs プロジェクト: lalanikarim/agg-sharp
        /// <summary>
        /// For every T Junction add a vertex to the mesh edge that needs one.
        /// </summary>
        /// <param name="mesh"></param>
        public static void RepairTJunctions(this Mesh mesh)
        {
            var nonManifoldEdges = mesh.GetNonManifoldEdges();

            foreach (MeshEdge edge in nonManifoldEdges)
            {
                IVertex start  = edge.VertexOnEnd[0];
                IVertex end    = edge.VertexOnEnd[1];
                Vector3 normal = (end.Position - start.Position).GetNormal();

                // Get all the vertices that lay on this edge
                foreach (var vertex in mesh.Vertices)
                {
                    // test if it falls on the edge
                    // split the edge at them
                    IVertex  createdVertex;
                    MeshEdge createdMeshEdge;
                    mesh.SplitMeshEdge(edge, out createdVertex, out createdMeshEdge);
                    createdVertex.Position = vertex.Position;
                    createdVertex.Normal   = vertex.Normal;
                    mesh.MergeVertices(vertex, createdVertex);
                }
            }

            throw new NotImplementedException();

            // and merge the mesh edges that are now manifold
            //mesh.MergeMeshEdges(CancellationToken.None);
        }