예제 #1
0
        public static IEnumerable <Edge> IterateEdges(Vert vert, Direction direction)
        {
            Edge first = vert.Edge;

            if (first == null)
            {
                yield break;
            }
            Edge iterator = first;

            switch (direction)
            {
            case Direction.FORWARD:
                do
                {
                    yield return(iterator);
                } while ((iterator = iterator.NextEdge(vert)) != first && iterator != null);

                break;

            case Direction.BACKWARD:
                do
                {
                    yield return(iterator);
                } while ((iterator = iterator.PrevEdge(vert)) != first && iterator != null);

                break;
            }
        }
예제 #2
0
 public Loop(Edge e, Vert v, Face f)
 {
     Edge = e;
     Vert = v;
     Face = f;
     AttachRadialLoopEdge(e);
 }
예제 #3
0
 public Edge(Vert v1, Vert v2)
 {
     V1 = v1;
     V2 = v2;
     AttachToDiskEdge(v1);
     AttachToDiskEdge(v2);
 }
예제 #4
0
        protected void EdgeSwapVert(Vert dest, Vert src)
        {
            if (Loop != null)
            {
                Loop iter, first;
                iter = first = Loop;
                do
                {
                    if (iter.Vert == src)
                    {
                        iter.Vert = dest;
                    }
                    else if (iter.RadialNext.Vert == src)
                    {
                        iter.RadialNext.Vert = dest;
                    }
                    else
                    {
                        if (iter.RadialPrev.Vert != src)
                        {
                            Debug.Log("Previous vert is equal to src");
                        }
                    }
                } while ((iter = iter.RadialNext) != first);
            }

            swapVert(dest, src);
        }
예제 #5
0
        private TKEdgeDisk GetDiskLinkFromVert(Vert vert)
        {
            if (vert == V2)
            {
                return(DiskV2Link);
            }

            return(DiskV1Link);
        }
예제 #6
0
        public Edge CreateEdge(Vert v1, Vert v2, bool allowDouble)
        {
            Edge e;

            if (!allowDouble && (e = Edge.EdgeExists(v1, v2)) != null)
            {
                return(e);
            }

            e = new Edge(v1, v2);
            Edges.Add(e);
            return(e);
        }
예제 #7
0
        public Face findFace(Vert[] verts)
        {
            foreach (var ed in Vert.IterateEdges(verts[0], Direction.FORWARD))
            {
                if (ed.Loop != null)
                {
                    foreach (var loopRadial in Loop.IterateRadialLoops(ed.Loop, Direction.FORWARD))
                    {
                        int i_walk = 2;
                        if (loopRadial.Next.Vert == verts[1] && loopRadial.Face.TotVerts == verts.Length)
                        {
                            var loopIter = Loop.IterateLoop(loopRadial.Next.Next, Direction.FORWARD);
                            foreach (var l in loopIter)
                            {
                                if (l.Vert != verts[i_walk])
                                {
                                    break;
                                }
                                i_walk++;
                            }
                        }
                        else if (loopRadial.Prev.Vert == verts[1])
                        {
                            var loopIter = Loop.IterateLoop(loopRadial.Next.Next, Direction.BACKWARD);
                            foreach (var l in loopIter)
                            {
                                if (l.Vert != verts[i_walk])
                                {
                                    break;
                                }

                                i_walk++;
                            }
                        }

                        if (i_walk == verts.Length)
                        {
                            return(loopRadial.Face);
                        }
                    }
                }
            }

            return(null);
        }
예제 #8
0
        public static Edge FindEdge(Vert v1, Vert v2)
        {
            Edge first, iter;

            if (v1.Edge != null)
            {
                first = iter = v1.Edge;
                do
                {
                    if (iter.IsVertInEdge(v1, v2))
                    {
                        return(iter);
                    }
                } while ((iter = iter.NextEdge(v1)) != first);
            }

            return(null);
        }
예제 #9
0
        protected bool SwapDiskVert(Vert dest, Vert src)
        {
            if (V1 == src)
            {
                V1 = dest;
                DiskV1Link.Next = DiskV1Link.Prev = null;
                return(true);
            }

            if (V2 == src)
            {
                V2 = dest;
                DiskV2Link.Next = DiskV2Link.Prev = null;
                return(true);
            }

            return(false);
        }
예제 #10
0
        public Meshy(Mesh mesh)
        {
            Vert[] tkVertex = new Vert[mesh.vertices.Length];
            for (var i = 0; i < mesh.vertices.Length; i++)
            {
                tkVertex[i] = new Vert
                {
                    pos = new Vector3(mesh.vertices[i].x, mesh.vertices[i].y, mesh.vertices[i].z)
                };
            }

            for (int i = 0; i < mesh.triangles.Length - 3; i++)
            {
                int tr1 = mesh.triangles[i];
                int tr2 = mesh.triangles[i + 1];
                int tr3 = mesh.triangles[i + 2];
            }
        }
예제 #11
0
        public static Edge EdgeExists(Vert v1, Vert v2)
        {
            Edge e_a, e_b;

            if ((e_a = v1.Edge) != null && (e_b = v2.Edge) != null)
            {
                Edge e_a_iter = e_a, e_b_iter = e_b;
                do
                {
                    if (e_a_iter.IsVertInEdge(v2))
                    {
                        return(e_a_iter);
                    }

                    if (e_b_iter.IsVertInEdge(v1))
                    {
                        return(e_b_iter);
                    }
                } while ((e_a_iter = e_a_iter.NextEdge(v1)) != e_a && (e_b_iter = e_b_iter.NextEdge(v2)) != e_b);
            }

            return(null);
        }
예제 #12
0
        public void AttachToDiskEdge(Vert v)
        {
            if (v.Edge == null)
            {
                TKEdgeDisk dl1 = GetDiskLinkFromVert(v);
                v.Edge   = this;
                dl1.Next = dl1.Prev = this;
            }
            else
            {
                TKEdgeDisk dl1 = GetDiskLinkFromVert(v);
                TKEdgeDisk dl2 = v.Edge.GetDiskLinkFromVert(v);
                TKEdgeDisk dl3 = dl2.Prev?.GetDiskLinkFromVert(v);

                dl1.Next = v.Edge;
                dl1.Prev = dl2.Prev;

                dl2.Prev = this;
                if (dl3 != null)
                {
                    dl3.Next = this;
                }
            }
        }
예제 #13
0
        public void DetachDiskEdge(Vert v)
        {
            TKEdgeDisk dl1, dl2;

            dl1 = GetDiskLinkFromVert(v);
            if (dl1.Prev != null)
            {
                dl2      = dl1.Prev.GetDiskLinkFromVert(v);
                dl2.Next = dl1.Next;
            }

            if (dl1.Next != null)
            {
                dl2      = dl1.Next.GetDiskLinkFromVert(v);
                dl2.Prev = dl1.Prev;
            }

            if (v.Edge == this)
            {
                v.Edge = (this != dl1.Next) ? dl1.Next : null;
            }

            dl1.Next = dl1.Prev = null;
        }
예제 #14
0
 public bool IsVertInEdge(Vert v1, Vert v2)
 {
     return((V1 == v1 && V2 == v2) ||
            (V1 == v2 && V2 == v1));
 }
예제 #15
0
 public bool IsVertInEdge(Vert v1)
 {
     return(V1 == v1 || V2 == v1);
 }
예제 #16
0
 public Loop(Edge e, Vert v)
 {
     Edge = e;
     Vert = v;
     AttachRadialLoopEdge(e);
 }
예제 #17
0
 public Edge PrevEdge(Vert v)
 {
     return(GetDiskLinkFromVert(v).Next);
 }
예제 #18
0
 protected void swapVert(Vert dest, Vert src)
 {
     DetachDiskEdge(src);
     SwapDiskVert(dest, src);
     AttachToDiskEdge(dest);
 }