Exemplo n.º 1
0
    private void ClickAtLine(Vector3 midPoint)
    {
        //Get two faces' indices of the selected line.
        List <int> faceIndices = meshGenerator.GetFaceIndicesOfLine(midPoint);

        int indexA = faceIndices[0];
        int indexB = faceIndices[1];

        //Delete the lines in the two faces. Then check if one of these faces has only one line left, if so, it needs to unfold.
        unfoldA   = DeleteAndCheckLinesInFace(indexA, midPoint);
        unfoldB   = DeleteAndCheckLinesInFace(indexB, midPoint);
        unfolding = unfoldA || unfoldB;
        Debug.Log(unfolding);

        PreviousUnfoldingA.Add(unfoldA);
        PreviousUnfoldingB.Add(unfoldB);

        if (unfoldA)
        {
            Vector3 rmStartingPoint = meshGenerator.model.faces[indexA].lineStartingPoint[0];
            Vector3 rmEndingPoint   = meshGenerator.model.faces[indexA].lineEndingPoint[0];
            Vector3 rmMidPoint      = meshGenerator.model.faces[indexA].linesMidpoints[0];

            DeleteLastLine(rmStartingPoint, rmEndingPoint);
            meshGenerator.AddDashedLineIndex(indexA);

            if (GameObject.FindGameObjectWithTag("Line") == null)
            {
                WaitingLinesStartingPoint.Clear();
                WaitingLinesEndingPoint.Clear();
                return;
            }

            int     TargetIndexofA   = meshGenerator.GetTheOtherFaceIndex(rmMidPoint, indexA);
            Vector3 currentNormalofA = meshGenerator.GetNormalofFace(indexA);
            Vector3 TargetNormalofA  = meshGenerator.GetNormalofFace(TargetIndexofA);

            int NumOfConnectedFaces = meshGenerator.model.faces[indexA].ConnectedFaces.ToArray().Length;
            for (int i = -1; i < NumOfConnectedFaces; i++)
            {
                int currentIndex;
                if (i == -1)
                {
                    currentIndex = indexA;
                    meshGenerator.model.faces[TargetIndexofA].Neighbors.Add(currentIndex);
                    meshGenerator.model.faces[currentIndex].Neighbors.Add(TargetIndexofA);
                }
                else
                {
                    currentIndex = meshGenerator.model.faces[indexA].ConnectedFaces[i];
                }

                meshGenerator.model.faces[TargetIndexofA].ConnectedFaces.Add(currentIndex);
            }


            PreviousStartingNormalA.Add(currentNormalofA);
            StartUnfolding(indexA, currentNormalofA, TargetNormalofA, rmStartingPoint, rmEndingPoint);
        }
        if (unfoldB)
        {
            Vector3 rmStartingPoint = meshGenerator.model.faces[indexB].lineStartingPoint[0];
            Vector3 rmEndingPoint   = meshGenerator.model.faces[indexB].lineEndingPoint[0];
            Vector3 rmMidPoint      = meshGenerator.model.faces[indexB].linesMidpoints[0];

            DeleteLastLine(rmStartingPoint, rmEndingPoint);
            meshGenerator.AddDashedLineIndex(indexB);

            if (GameObject.FindGameObjectWithTag("Line") == null)
            {
                WaitingLinesStartingPoint.Clear();
                WaitingLinesEndingPoint.Clear();
                return;
            }

            int     TargetIndexofB   = meshGenerator.GetTheOtherFaceIndex(rmMidPoint, indexB);
            Vector3 currentNormalofB = meshGenerator.GetNormalofFace(indexB);
            Vector3 TargetNormalofB  = meshGenerator.GetNormalofFace(TargetIndexofB);

            int NumOfConnectedFaces = meshGenerator.model.faces[indexB].ConnectedFaces.ToArray().Length;
            for (int i = -1; i < NumOfConnectedFaces; i++)
            {
                int currentIndex;
                if (i == -1)
                {
                    currentIndex = indexB;
                    meshGenerator.model.faces[TargetIndexofB].Neighbors.Add(currentIndex);
                    meshGenerator.model.faces[currentIndex].Neighbors.Add(TargetIndexofB);
                }
                else
                {
                    currentIndex = meshGenerator.model.faces[indexB].ConnectedFaces[i];
                }

                meshGenerator.model.faces[TargetIndexofB].ConnectedFaces.Add(currentIndex);
            }

            PreviousStartingNormalB.Add(currentNormalofB);
            StartUnfolding(indexB, currentNormalofB, TargetNormalofB, rmStartingPoint, rmEndingPoint);
        }
    }