Exemplo n.º 1
0
 protected override HalfEdgeMesh.Vertex Merge(MergeArgs args)
 {
     return(TriMeshModify.MergeEdge(args.Target, args.Pos));
 }
Exemplo n.º 2
0
        public bool RemoveVertex4(TriMesh.Vertex cur)
        {
            /*                                        cur
             *      vl     vr                       /\
             *      |\     /|                      /  \
             *      | \   / |                     /    \
             *      |  \ /  |                    /      \
             *      |  cur  |                   /        \
             *      |  / \  |                  /          \
             *      | /   \ |                lm-----sm-----rm
             *      |/face \|                / \    /\    / \
             *    left-----right            /   \  /  \  /   \
             *       \     /               /     sl____sr     \
             *        \   /               /       \    /       \
             *         \ /               /         \  /         \
             *         vm               /           \/           \
             *                        left----------mm----------right
             *
             *                               中部三角形放大图
             */

            TriMesh.HalfEdge curToLeft = null;

            //找到一个可用的面,这个面的3个邻面必须都存在
            foreach (var item in cur.HalfEdges)
            {
                if (item.Face != null && item.Face.FaceCount == 3)
                {
                    curToLeft = item;
                    break;
                }
            }
            if (curToLeft == null)
            {
                return(false);
            }

            TriMesh.Vertex left, right, vl, vr, vm,
                           lm, sm, rm, sl, sr, mm;
            TriMesh.HalfEdge leftToRight = curToLeft.Next;
            TriMesh.HalfEdge rightToCur  = leftToRight.Next;

            left  = curToLeft.ToVertex;
            right = leftToRight.ToVertex;
            vl    = curToLeft.Opposite.Next.ToVertex;
            vr    = rightToCur.Opposite.Next.ToVertex;
            vm    = leftToRight.Opposite.Next.ToVertex;

            lm = this.AddMid(left, cur);
            rm = this.AddMid(right, cur);
            mm = this.AddMid(left, right);

            sm = this.AddMid(lm, rm);
            sl = this.AddMid(lm, mm);
            sr = this.AddMid(mm, rm);

            TriMeshModify.RemoveEdge(curToLeft.Edge);
            TriMeshModify.RemoveEdge(leftToRight.Edge);
            TriMeshModify.RemoveEdge(rightToCur.Edge);

            //图1外圈三角形
            this.CreateFace(vl, left, lm);
            this.CreateFace(vl, lm, cur);
            this.CreateFace(vr, cur, rm);
            this.CreateFace(vr, rm, right);
            this.CreateFace(mm, left, vm);
            this.CreateFace(mm, vm, right);

            //图2外圈三角形
            this.CreateFace(cur, lm, sm);
            this.CreateFace(cur, sm, rm);
            this.CreateFace(lm, left, sl);
            this.CreateFace(sl, left, mm);
            this.CreateFace(rm, sr, right);
            this.CreateFace(sr, mm, right);

            //图2内圈三角形
            this.CreateFace(sm, lm, sl);
            this.CreateFace(sm, sr, rm);
            this.CreateFace(sm, sl, sr);
            this.CreateFace(sl, mm, sr);

            return(true);
        }
Exemplo n.º 3
0
        public TriMesh Cut(IEnumerable <TriMesh.Vertex> region)
        {
            Dictionary <int, TriMesh.Vertex> vMap  = new Dictionary <int, HalfEdgeMesh.Vertex>();
            Dictionary <int, bool>           fFlag = new Dictionary <int, bool>();


            TriMesh newMesh = new TriMesh();

            foreach (var v in region)
            {
                TriMesh.Vertex newV = new HalfEdgeMesh.Vertex(
                    new VertexTraits(v.Traits.Position));
                vMap[v.Index] = newV;
                newMesh.AppendToVertexList(newV);
            }

            foreach (var f in this.mesh.Faces)
            {
                bool inner = true;
                foreach (var v in f.Vertices)
                {
                    if (!vMap.ContainsKey(v.Index))
                    {
                        inner = false;
                        break;
                    }
                }
                if (inner)
                {
                    TriMesh.HalfEdge hf = f.HalfEdge;
                    newMesh.Faces.AddTriangles(
                        vMap[hf.FromVertex.Index],
                        vMap[hf.ToVertex.Index],
                        vMap[hf.Next.ToVertex.Index]);
                    fFlag[f.Index] = true;
                }
            }

            List <TriMesh.Edge> remove = new List <HalfEdgeMesh.Edge>();

            foreach (var e in this.mesh.Edges)
            {
                if (fFlag.ContainsKey(e.Face0.Index) &&
                    fFlag.ContainsKey(e.Face1.Index))
                {
                    remove.Add(e);
                }
            }
            foreach (var e in remove)
            {
                TriMeshModify.RemoveEdge(e);
            }

            foreach (var v in region)
            {
                bool inner = true;
                foreach (var round in v.Vertices)
                {
                    if (!vMap.ContainsKey(round.Index))
                    {
                        inner = false;
                    }
                }
                if (inner)
                {
                    this.mesh.RemoveVertex(v);
                }
            }

            return(newMesh);
        }