コード例 #1
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
        public void Clear()
        {
            //if (_isCleared)
            //{
            //	return;
            //}
            _cloneVerts.Clear();
            _crossVerts.Clear();
            _cloneEdges.Clear();
            _mesh          = null;
            _nSelectedVert = 0;
            _nTotalVert    = 0;
            _nTotalEdge    = 0;
            _offset        = 0.0f;
            _isAddOnRuler  = false;
            _isMirrorX     = true;
            _mirrorPos     = 0.0f;
            _srcEdges.Clear();
            _srcVerts.Clear();
            _vert2Verts.Clear();

            _vert2Clone.Clear();
            _clone2Vert.Clear();
            CloneVertex.ClearIndex();

            //_isCleared = true;
        }
コード例 #2
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
 public void RemoveLinkedCloneVert(CloneVertex cloneVert)
 {
     if (_linkedCloneVerts.Contains(cloneVert))
     {
         _linkedCloneVerts.Remove(cloneVert);
     }
 }
コード例 #3
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
            public static CloneVertex MakeMirrorPoint(apVertex srcVert, Vector2 pos, int compare)
            {
                CloneVertex newCVert = new CloneVertex();

                newCVert._srcVert         = srcVert;
                newCVert._pos             = pos;
                newCVert._compareToMirror = compare;
                return(newCVert);
            }
コード例 #4
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
            public static CloneVertex MakeCrossPoint(Vector2 pos, apMeshEdge splitEdge)
            {
                CloneVertex newCVert = new CloneVertex();

                newCVert._pos             = pos;
                newCVert._isCrossOnAxis   = true;
                newCVert._srcSplitEdge    = splitEdge;
                newCVert._compareToMirror = 0;
                return(newCVert);
            }
コード例 #5
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
            public static CloneVertex MakePointOnAxis(apVertex srcVert)
            {
                CloneVertex newCVert = new CloneVertex();

                newCVert._srcVert         = srcVert;
                newCVert._pos             = srcVert._pos;
                newCVert._isOnAxis        = true;
                newCVert._compareToMirror = 0;
                return(newCVert);
            }
コード例 #6
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
        // Functions
        //-----------------------------------------------
        public void Refresh(apMesh mesh, bool isReset)
        {
            //리셋할지 말지 체크
            if (!isReset)
            {
                if (_mesh != mesh ||
                    mesh == null ||
                    _nSelectedVert != _editor.VertController.Vertices.Count ||
                    _nTotalVert != mesh._vertexData.Count ||
                    _nTotalEdge != mesh._edges.Count ||
                    !Mathf.Approximately(_offset, _editor._meshTRSOption_MirrorOffset) ||
                    _isAddOnRuler != _editor._meshTRSOption_MirrorSnapVertOnRuler
                    )
                {
                    isReset = true;
                }
                else
                {
                    if (mesh != null)
                    {
                        if (_isMirrorX != mesh._isMirrorX)
                        {
                            isReset = true;
                        }
                        else if ((mesh._isMirrorX && !Mathf.Approximately(_mirrorPos, mesh._mirrorAxis.x)) ||
                                 (!mesh._isMirrorX && !Mathf.Approximately(_mirrorPos, mesh._mirrorAxis.y)))
                        {
                            isReset = true;
                        }
                    }
                }
            }


            if (!isReset)
            {
                //리스트를 돌면서
                //SrcVert의 위치가 미러 축의 (+, -, 0) 중 어디에 들어가는지 확인하자
                //하나라도 변경된게 있다면 Reset이다.
                CloneVertex checkClone = null;
                for (int i = 0; i < _cloneVerts.Count; i++)
                {
                    checkClone = _cloneVerts[i];
                    if (checkClone._compareToMirror != GetMirrorCompare(checkClone._srcVert._pos, true))
                    {
                        //리셋을 해야할 만큼 위치가 바뀌었다.
                        //Debug.LogError("Mirror 변경됨");
                        isReset = true;
                        break;
                    }
                }
            }

            if (isReset)
            {
                Clear();

                if (mesh == null)
                {
                    return;
                }

                if (_editor.VertController.Vertices.Count == 0)
                {
                    return;
                }

                List <apVertex>   selectVerts = _editor.VertController.Vertices;
                List <apVertex>   verts       = mesh._vertexData;
                List <apMeshEdge> edges       = mesh._edges;


                _mesh          = mesh;
                _nSelectedVert = selectVerts.Count;
                _nTotalVert    = verts.Count;
                _nTotalEdge    = edges.Count;
                _offset        = _editor._meshTRSOption_MirrorOffset;
                _isAddOnRuler  = _editor._meshTRSOption_MirrorSnapVertOnRuler;
                _isMirrorX     = mesh._isMirrorX;
                _mirrorPos     = mesh._isMirrorX ? mesh._mirrorAxis.x : mesh._mirrorAxis.y;

                apMeshEdge curEdge  = null;
                apVertex   curVert1 = null;
                apVertex   curVert2 = null;
                for (int iEdge = 0; iEdge < edges.Count; iEdge++)
                {
                    curEdge  = edges[iEdge];
                    curVert1 = curEdge._vert1;
                    curVert2 = curEdge._vert2;

                    //하나라도 등록되어 있다면 "미러가 될 Edge"로 일단 등록
                    bool isVert1InList = selectVerts.Contains(curVert1);
                    bool isVert2InList = selectVerts.Contains(curVert2);

                    if (isVert1InList || isVert2InList)
                    {
                        _srcEdges.Add(curEdge);

                        if (isVert1InList)
                        {
                            if (!_srcVerts.Contains(curVert1))
                            {
                                _srcVerts.Add(curVert1);
                            }

                            if (!_vert2Verts.ContainsKey(curVert1))
                            {
                                _vert2Verts.Add(curVert1, new List <apVertex>());
                            }
                            if (!_vert2Verts[curVert1].Contains(curVert2))
                            {
                                _vert2Verts[curVert1].Add(curVert2);                                //<Vert1 -> Vert2가 이어져 있음을 등록
                            }
                        }
                        if (isVert2InList)
                        {
                            if (!_srcVerts.Contains(curVert2))
                            {
                                _srcVerts.Add(curVert2);
                            }
                            if (!_vert2Verts.ContainsKey(curVert2))
                            {
                                _vert2Verts.Add(curVert2, new List <apVertex>());
                            }
                            if (!_vert2Verts[curVert2].Contains(curVert1))
                            {
                                _vert2Verts[curVert2].Add(curVert1);                                //<Vert2 -> Vert1가 이어져 있음을 등록
                            }
                        }

                        //Edge중에서 축에 Cross되는 경우
                        if (IsCrossAxis(curEdge._vert1._pos, curEdge._vert2._pos))
                        {
                            Vector2 crossPos = GetCrossPos(curEdge._vert1._pos, curEdge._vert2._pos);
                            _crossVerts.Add(CloneVertex.MakeCrossPoint(crossPos, curEdge)
                                            .AddLinkedSrcVert(curEdge._vert1)
                                            .AddLinkedSrcVert(curEdge._vert2));
                        }
                    }
                }

                //등록된 Vertex 리스트를 바탕으로 Clone을 만들자
                //- 옵션에 따라 바뀐다.
                //- 일단 Clone간의 연결은 생략하고, Vert -> Clone만 만들자
                //- 위치 보정이 중요
                //- Cross가 되는 Clone은 여기서 만들지 않는다.
                apVertex        srcVert     = null;
                List <apVertex> linkedVerts = null;
                apVertex        linkedVert  = null;

                for (int iVert = 0; iVert < _srcVerts.Count; iVert++)
                {
                    srcVert = _srcVerts[iVert];
                    CloneVertex newCVert = null;
                    if (IsOnAxis(srcVert._pos))
                    {
                        //Axis 위에 있다면..
                        newCVert = CloneVertex.MakePointOnAxis(srcVert);
                    }
                    else
                    {
                        //그렇지 않다면
                        Vector2 mirrorPos = GetMirrorPos(srcVert._pos);
                        newCVert = CloneVertex.MakeMirrorPoint(srcVert, mirrorPos, GetMirrorCompare(srcVert._pos, false));
                    }

                    //이어진 Vertex 들을 입력하자
                    linkedVerts = _vert2Verts[srcVert];
                    for (int iLink = 0; iLink < linkedVerts.Count; iLink++)
                    {
                        linkedVert = linkedVerts[iLink];
                        newCVert.AddLinkedSrcVert(linkedVert);
                    }
                    _cloneVerts.Add(newCVert);
                    _clone2Vert.Add(newCVert, srcVert);
                    _vert2Clone.Add(srcVert, newCVert);
                }

                //CloneVert간에 연결을 하자
                CloneVertex cloneVert       = null;
                CloneVertex linkedCloneVert = null;
                for (int iClone = 0; iClone < _cloneVerts.Count; iClone++)
                {
                    cloneVert = _cloneVerts[iClone];
                    for (int iLinkedSrc = 0; iLinkedSrc < cloneVert._linkedSrcVerts.Count; iLinkedSrc++)
                    {
                        srcVert = cloneVert._linkedSrcVerts[iLinkedSrc];
                        if (_vert2Clone.ContainsKey(srcVert))
                        {
                            linkedCloneVert = _vert2Clone[srcVert];
                            cloneVert.AddLinkedCloneVert(linkedCloneVert);
                        }
                    }
                }

                //CrossVert를 이용해서 연결 관계를 바꾸자
                CloneVertex crossVert        = null;
                CloneVertex linkedCloneVert1 = null;
                CloneVertex linkedCloneVert2 = null;
                for (int iCross = 0; iCross < _crossVerts.Count; iCross++)
                {
                    crossVert = _crossVerts[iCross];
                    curVert1  = crossVert._srcSplitEdge._vert1;
                    curVert2  = crossVert._srcSplitEdge._vert2;

                    linkedCloneVert1 = null;
                    linkedCloneVert2 = null;
                    if (_vert2Clone.ContainsKey(curVert1))
                    {
                        linkedCloneVert1 = _vert2Clone[curVert1];
                        crossVert.AddLinkedCloneVert(linkedCloneVert1);
                    }
                    if (_vert2Clone.ContainsKey(curVert2))
                    {
                        linkedCloneVert2 = _vert2Clone[curVert2];
                        crossVert.AddLinkedCloneVert(linkedCloneVert2);
                    }

                    if (linkedCloneVert1 != null)
                    {
                        linkedCloneVert1.AddLinkedCloneVert(crossVert);
                        //만약 반대쪽이 연결된 상태라면 연결을 끊는다.
                        if (linkedCloneVert2 != null)
                        {
                            linkedCloneVert1.RemoveLinkedCloneVert(linkedCloneVert2);
                        }
                    }

                    if (linkedCloneVert2 != null)
                    {
                        linkedCloneVert2.AddLinkedCloneVert(crossVert);
                        //만약 반대쪽이 연결된 상태라면 연결을 끊는다.
                        if (linkedCloneVert1 != null)
                        {
                            linkedCloneVert2.RemoveLinkedCloneVert(linkedCloneVert1);
                        }
                    }
                }

                //CloneEdge를 완성한다. >> _cloneEdges
                //빠른 중복
                CloneVertex cloneVert1 = null;
                CloneVertex cloneVert2 = null;
                Dictionary <CloneVertex, List <CloneVertex> > edgedVertPairs = new Dictionary <CloneVertex, List <CloneVertex> >();
                for (int iClone = 0; iClone < _cloneVerts.Count; iClone++)
                {
                    cloneVert = _cloneVerts[iClone];
                    for (int iLinkClone = 0; iLinkClone < cloneVert._linkedCloneVerts.Count; iLinkClone++)
                    {
                        linkedCloneVert = cloneVert._linkedCloneVerts[iLinkClone];
                        if (cloneVert._index < linkedCloneVert._index)
                        {
                            cloneVert1 = cloneVert;
                            cloneVert2 = linkedCloneVert;
                        }
                        else
                        {
                            cloneVert1 = linkedCloneVert;
                            cloneVert2 = cloneVert;
                        }

                        bool isExisted = false;
                        if (edgedVertPairs.ContainsKey(cloneVert1))
                        {
                            if (edgedVertPairs[cloneVert1].Contains(cloneVert2))
                            {
                                isExisted = true;
                            }
                            else
                            {
                                edgedVertPairs[cloneVert1].Add(cloneVert2);
                            }
                        }
                        else
                        {
                            edgedVertPairs.Add(cloneVert1, new List <CloneVertex>());
                            edgedVertPairs[cloneVert1].Add(cloneVert2);
                        }
                        if (!isExisted)
                        {
                            _cloneEdges.Add(new CloneEdge(cloneVert1, cloneVert2));
                        }
                    }
                }
            }
            else
            {
                //위치만 갱신하자
                CloneVertex curCloneVert = null;
                for (int iClone = 0; iClone < _cloneVerts.Count; iClone++)
                {
                    curCloneVert = _cloneVerts[iClone];
                    if (!curCloneVert._isOnAxis)
                    {
                        curCloneVert._pos = GetMirrorPos(curCloneVert._srcVert._pos);
                    }
                    else
                    {
                        curCloneVert._pos = curCloneVert._srcVert._pos;
                    }
                }

                for (int iClone = 0; iClone < _crossVerts.Count; iClone++)
                {
                    curCloneVert = _crossVerts[iClone];
                    if (curCloneVert._linkedSrcVerts.Count < 2)
                    {
                        continue;
                    }

                    Vector2 crossPos = GetCrossPos(curCloneVert._linkedSrcVerts[0]._pos,
                                                   curCloneVert._linkedSrcVerts[1]._pos);
                    curCloneVert._pos = crossPos;
                }
            }
        }
コード例 #7
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
 public bool IsSame(CloneVertex vert1, CloneVertex vert2)
 {
     return((_cloneVert1 == vert1 && _cloneVert2 == vert2) ||
            (_cloneVert1 == vert2 && _cloneVert2 == vert1));
 }
コード例 #8
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
 public CloneEdge(CloneVertex vert1, CloneVertex vert2)
 {
     _cloneVert1 = vert1;
     _cloneVert2 = vert2;
 }
コード例 #9
0
ファイル: apMirrorVertexSet.cs プロジェクト: kirsi0/Sheepy
 public CloneVertex AddLinkedCloneVert(CloneVertex cloneVert)
 {
     _linkedCloneVerts.Add(cloneVert);
     return(this);
 }