示例#1
0
        void optimize_mesh(DMesh3 mesh)
        {
            Reducer         reducer     = new Reducer(mesh);
            MeshConstraints constraints = new MeshConstraints();

            MeshConstraintUtil.FixAllBoundaryEdges(constraints, mesh);
            reducer.SetExternalConstraints(constraints);
            reducer.ReduceToTriangleCount(1);

            Vector3d a, b, c, d;

            a = b = c = d = Vector3d.Zero;

            bool done = false;

            while (!done)
            {
                done = true;

                for (int eid = 0; eid < mesh.MaxEdgeID; ++eid)
                {
                    if (mesh.IsEdge(eid) == false)
                    {
                        continue;
                    }

                    Index4i evt = mesh.GetEdge(eid);
                    if (evt.d == DMesh3.InvalidID)
                    {
                        continue;
                    }
                    a = mesh.GetVertex(evt.a); b = mesh.GetVertex(evt.b);
                    Index2i ov = mesh.GetEdgeOpposingV(eid);
                    c = mesh.GetVertex(ov.a); d = mesh.GetVertex(ov.b);

                    if (c.DistanceSquared(d) > a.DistanceSquared(b))
                    {
                        continue;
                    }
                    if (MeshUtil.CheckIfEdgeFlipCreatesFlip(mesh, eid))
                    {
                        continue;
                    }

                    DMesh3.EdgeFlipInfo flipInfo;
                    if (mesh.FlipEdge(eid, out flipInfo) == MeshResult.Ok)
                    {
                        done = false;
                    }
                }
            }
        }