예제 #1
0
        private void RemoveFace(SkeletonFace face)
        {
            _faces.Remove(face);
            Edge liveEdge = face.liveEdge;
            Node nodeA    = liveEdge.nodeA;
            Node nodeB    = liveEdge.nodeB;

            if (_edgeDic.ContainsKey(nodeA))
            {
                _edgeDic[nodeA].Remove(face);
                if (_edgeDic[nodeA].Count == 0)
                {
                    _edgeDic.Remove(nodeA);
                }
            }
            if (_edgeDic.ContainsKey(nodeB))
            {
                _edgeDic[nodeB].Remove(face);
                if (_edgeDic[nodeB].Count == 0)
                {
                    _edgeDic.Remove(nodeB);
                }
            }

            if (_nodeDic.ContainsKey(liveEdge))
            {
                _nodeDic.Remove(liveEdge);
            }
        }
예제 #2
0
        public void EdgeComplete(Edge liveEdge)
        {
            if (!_nodeDic.ContainsKey(liveEdge))
            {
                Debug.Log("EdgeComplete error");
                return;
            }
            SkeletonFace face = _nodeDic[liveEdge];

            SkeletonTri[] tris = face.Convert();
            AddTriangles(tris);
            RemoveFace(face);
        }
예제 #3
0
        private void AddFace(Edge liveEdge, Node staticNodeA, Node staticNodeB)
        {
            OffsetShapeLog.DrawEdge(liveEdge, Color.red);
            OffsetShapeLog.DrawLabel(liveEdge.nodeA.position, "new face");
            SkeletonFace face = new SkeletonFace(liveEdge, staticNodeA, staticNodeB);

            _faces.Add(face);

            if (!_edgeDic.ContainsKey(liveEdge.nodeA))
            {
                _edgeDic.Add(liveEdge.nodeA, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeA].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeA].Add(face);
            }

            if (!_edgeDic.ContainsKey(liveEdge.nodeB))
            {
                _edgeDic.Add(liveEdge.nodeB, new List <SkeletonFace>());
                _edgeDic[liveEdge.nodeB].Add(face);
            }
            else
            {
                _edgeDic[liveEdge.nodeB].Add(face);
            }

            if (!_nodeDic.ContainsKey(liveEdge))
            {
                _nodeDic.Add(liveEdge, face);
            }
            else
            {
                _nodeDic[liveEdge] = face;
            }
        }
예제 #4
0
        public void SplitEdge(SplitEvent e)
        {
            Edge         oldLiveEdge  = e.edge;
            Vector3      splitTangent = Utils.ToV3(oldLiveEdge.direction);
            SkeletonFace oldFace      = _nodeDic[oldLiveEdge];
            Node         staticNode   = e.newStaticNode;

            Edge newLiveEdgeA = e.newLiveEdgeA;
            Edge newLiveEdgeB = e.newLiveEdgeB;

            Node oldNode      = e.node;
            Node newLiveNodeA = e.newLiveNodeA;
            Node newLiveNodeB = e.newLiveNodeB;

            //centre tri
            SkeletonTri newTriangle = new SkeletonTri(oldFace[0], oldFace[1], staticNode, splitTangent);

            AddTriangle(newTriangle);

            if (!_nodeDic.ContainsKey(e.nodeEdgeA))
            {
                return;
            }
            SkeletonFace faceA = _nodeDic[e.nodeEdgeA];

            faceA.ReplaceNode(oldNode, newLiveNodeA);
            //left tri
            SkeletonTri newTriangleA = new SkeletonTri(staticNode, faceA[0], newLiveNodeA, splitTangent);

            AddTriangle(newTriangleA);

            if (!_nodeDic.ContainsKey(e.nodeEdgeB))
            {
                return;
            }
            SkeletonFace faceB = _nodeDic[e.nodeEdgeB];

            faceB.ReplaceNode(oldNode, newLiveNodeB);
            //right tri
            SkeletonTri newTriangleB = new SkeletonTri(faceB[1], staticNode, newLiveNodeB, splitTangent);

            AddTriangle(newTriangleB);

            RemoveFace(oldFace);
            AddFace(newLiveEdgeA, oldFace[0], staticNode);
            AddFace(newLiveEdgeB, staticNode, oldFace[1]);

            int oldNodeReferenceCount = 0;

            if (_edgeDic.ContainsKey(oldNode))
            {
                oldNodeReferenceCount = _edgeDic[oldNode].Count;
            }
            for (int r = 0; r < oldNodeReferenceCount; r++)
            {
                SkeletonFace face     = _edgeDic[oldNode][r];
                Edge         liveEdge = face.liveEdge;

                if (liveEdge.Contains(newLiveNodeA))
                {
                    if (!_edgeDic.ContainsKey(newLiveNodeA))
                    {
                        _edgeDic.Add(newLiveNodeA, new List <SkeletonFace>());
                    }
                    _edgeDic[newLiveNodeA].Add(face);
                }
                if (liveEdge.Contains(newLiveNodeB))
                {
                    if (!_edgeDic.ContainsKey(newLiveNodeB))
                    {
                        _edgeDic.Add(newLiveNodeB, new List <SkeletonFace>());
                    }
                    _edgeDic[newLiveNodeB].Add(face);
                }
            }
        }
예제 #5
0
        public void CollapseEdge(Edge liveEdge, Node newLiveNode, Node newStaticNode)
        {
            Edge edgeA = null, edgeB = null;

            if (!_edgeDic.ContainsKey(newLiveNode))
            {
                _edgeDic.Add(newLiveNode, new List <SkeletonFace>());
            }
            foreach (SkeletonFace face in _faces)
            {
                Edge liveFaceEdge = face.liveEdge;

                if (liveEdge == liveFaceEdge)
                {
                    continue;
                }

                if (liveFaceEdge.Contains(liveEdge.nodeA))
                {
                    edgeA = liveFaceEdge;
                    _edgeDic[newLiveNode].Add(face);
                }
                if (liveFaceEdge.Contains(liveEdge.nodeB))
                {
                    edgeB = liveFaceEdge;
                    _edgeDic[newLiveNode].Add(face);
                }
            }

            if (edgeA != null)
            {
                SkeletonFace faceA = _nodeDic[edgeA];
                Node         n0    = faceA[0];
                Node         n1    = faceA[1];
                Node         n2    = newStaticNode;
                if (n0 != n2 && n1 != n2)
                {
                    SkeletonTri newtriangle = new SkeletonTri(n0, n1, n2, faceA.tangent);
                    AddTriangle(newtriangle);//remove static triangle from face - add to triangle stack
                    faceA.ReplaceNode(faceA[1], newStaticNode);
                    faceA.ReplaceNode(faceA[3], newLiveNode);
                }
            }
            if (edgeB != null)
            {
                SkeletonFace faceB = _nodeDic[edgeB];
                Node         n0    = faceB[0];
                Node         n1    = faceB[1];
                Node         n2    = newStaticNode;
                if (n0 != n2 && n1 != n2)
                {
                    SkeletonTri newtriangle = new SkeletonTri(n0, n1, n2, faceB.tangent);
                    AddTriangle(newtriangle);
                    faceB.ReplaceNode(faceB[0], newStaticNode);
                    faceB.ReplaceNode(faceB[2], newLiveNode);
                }
            }

            if (_nodeDic.ContainsKey(liveEdge))
            {
                SkeletonFace liveFace = _nodeDic[liveEdge];
                Node         lfn0     = liveFace[0];
                Node         lfn1     = liveFace[1];
                Node         lfn2     = newStaticNode;
                if (lfn0 != lfn2 && lfn1 != lfn2)
                {
                    SkeletonTri newFaceTriangle = new SkeletonTri(lfn0, lfn1, lfn2, liveFace.tangent);
                    AddTriangle(newFaceTriangle);
                }
                _nodeDic.Remove(liveEdge);
                RemoveFace(liveFace);
            }
        }