コード例 #1
0
    /// <summary>
    /// ドウカー表示を出力する
    /// </summary>
    public void DowkerNotation()
    {
        thisKnot.GetAllThings();
        thisKnot.MakeOrientation();
        int NodeID, NodeRID, StartNodeID, StartNodeRID;
        int JointCount = 0;

        for (int i = 0; i < thisKnot.AllNodes.Length; i++)
        {
            if (thisKnot.AllNodes[i].Joint)
            {
                JointCount++;
            }
        }
        if (JointCount > 0)
        {
            Edge ed = thisKnot.AllEdges[0];//とりあえず0番から始める
            if (ed == null)
            {
                return;
            }
            StartNodeID  = ed.ANodeID;
            StartNodeRID = ed.ANodeRID;
            NodeID       = ed.BNodeID;
            NodeRID      = ed.BNodeRID;
            int[]  DowkerSet   = new int[JointCount * 2];
            bool[] WhetherOver = new bool[JointCount * 2];
            int    repeatCount = 0;
            Node   nd          = thisKnot.GetNodeByID(NodeID);
            if (nd == null)
            {
                return;
            }
            if (nd.Joint)
            {
                DowkerSet[repeatCount]   = NodeID;
                WhetherOver[repeatCount] = (NodeRID == 0 || NodeRID == 2);
                repeatCount++;
            }
            switch (NodeRID)
            {
            case 0: NodeRID = 2; break;

            case 1: NodeRID = 3; break;

            case 2: NodeRID = 0; break;

            case 3: NodeRID = 1; break;
            }

            //Debug.Log(NodeID + "," + NodeRID + "->");
            for (int repeat = 0; repeat < thisKnot.AllEdges.Length; repeat++)
            {
                bool OK = false;
                for (int e = 0; e < thisKnot.AllEdges.Length; e++)
                {
                    ed = thisKnot.AllEdges[e];
                    //Debug.Log("   "+ed.ANodeID + "," + ed.ANodeRID+"||"+ ed.BNodeID + "," + ed.BNodeRID);
                    if (ed.ANodeID == NodeID && ed.ANodeRID == NodeRID)
                    {
                        NodeID  = ed.BNodeID;
                        NodeRID = ed.BNodeRID;
                        Debug.Log(ed.ANodeID + "," + ed.ANodeRID + ":" + ed.BNodeID + "," + ed.BNodeRID);
                        nd = thisKnot.GetNodeByID(NodeID);
                        if (nd == null)
                        {
                            return;
                        }
                        OK = true;
                        if (nd.Joint)
                        {
                            Debug.Log(NodeID + "," + repeatCount);
                            DowkerSet[repeatCount]   = NodeID;
                            WhetherOver[repeatCount] = (NodeRID == 0 || NodeRID == 2);
                            repeatCount++;
                        }
                        switch (NodeRID)
                        {
                        case 0: NodeRID = 2; break;

                        case 1: NodeRID = 3; break;

                        case 2: NodeRID = 0; break;

                        case 3: NodeRID = 1; break;
                        }
                        break;
                    }
                }
                if (NodeID == StartNodeID && NodeRID == StartNodeRID)
                {
                    break;
                }
                if (!OK)
                {
                    return;
                }
            }
            if (repeatCount != JointCount * 2)
            {
                Debug.Log("This is not a knot but a link.");
                return;
            }
            string ret = "";
            for (int i = 0; i < JointCount; i++)
            {
                for (int j = 0; j < JointCount; j++)
                {
                    if (DowkerSet[2 * i] == DowkerSet[2 * j + 1] && WhetherOver[2 * i] != WhetherOver[2 * j + 1])
                    {
                        if (WhetherOver[2 * j + 1])
                        {
                            ret += ((-2 * j - 2) + " ");
                        }
                        else
                        {
                            ret += ((2 * j + 2) + " ");
                        }
                    }
                }
            }
            Debug.Log(ret);
        }
    }
コード例 #2
0
    public void AdjustLineRenderer()
    {
        LineRenderer LR = gameObject.GetComponent <LineRenderer>();
        //Debug.Log("AdjustLineRenderer()");
        Node ANode = ParentKnot.GetNodeByID(ANodeID);
        Node BNode = ParentKnot.GetNodeByID(BNodeID);

        if (ANode == null || BNode == null)
        {
            Debug.LogError("Edge ID " + ID + "(" + ANodeID + "," + ANodeRID + ")(" + BNodeID + "," + BNodeRID + ") has error in NodeID");
            ParentKnot.UnderError = true;
            return;
        }
        if (!ANode.Active || !BNode.Active)
        {
            Debug.LogError("Edge ID " + ID + "(" + ANodeID + "," + ANodeRID + ")(" + BNodeID + "," + BNodeRID + ") has error in Node activity");
            ParentKnot.UnderError = true;
            return;
        }
        Bead ABead = ANode.ThisBead;
        //Bead BBead = BNode.ThisBead;
        List <Vector3> Positions = new List <Vector3>();

        if (ANodeRID == 0 || ANodeRID == 2)
        {
            Positions.Add(ABead.Position * ParentKnot.GlobalRate);
        }
        Bead Prev = ABead;
        Bead Now  = ABead.GetNU12(ANodeRID);

        if (Now == null)
        {
            LR.positionCount = 0;// 失敗
            Debug.LogError("Edge ID " + ID + "(" + ANodeID + "," + ANodeRID + ")(" + BNodeID + "," + BNodeRID + ") has error beads sequence");
            Debug.Log("ABead ID = " + ABead.ID + ", ANodeRID = " + ANodeRID + ":ABead.N1 = " + ABead.N1 + ":ABead.N2 = " + ABead.N2 + ":ABead.U1 = " + ABead.U1 + ":ABead.U2 = " + ABead.U2);
            ParentKnot.UnderError = true;
            return;
        }
        Bead Next;
        int  MaxRepeat = ParentKnot.AllBeads.Length;

        //以降は基本的にN1,N2しか見ない。
        for (int repeat = 0; repeat < MaxRepeat; repeat++)
        {
            if (Now == null)
            {
                Debug.LogError("Edge ID " + ID + "(" + ANodeID + "," + ANodeRID + ")(" + BNodeID + "," + BNodeRID + ") error in AdjustLineRenderer() : prev = " + Prev.ID + ":repeat = " + repeat);
                ParentKnot.UnderError = true;
                return;
            }
            if (Now.N1 == null)
            {
                Debug.LogError("Edge ID " + ID + "(" + ANodeID + "," + ANodeRID + ")(" + BNodeID + "," + BNodeRID + ") error in AdjustLineRenderer() : Now.ID =" + Now.ID);
                ParentKnot.UnderError = true;
                break;
            }
            if (Now.N1 == Prev || Now.N1.ID == Prev.ID)//IDベースですすめる。
            {
                Next = Now.N2;
            }
            else if (Now.N2 == Prev || Now.N2.ID == Prev.ID)
            {
                Next = Now.N1;
            }
            else
            {
                Debug.LogError("error in AdjustLineRenderer() : " + repeat + " " + Now.N1.ID + " " + Now.N2.ID);
                ParentKnot.UnderError = true;
                break;
            }
            Positions.Add(Now.Position * ParentKnot.GlobalRate);
            Prev = Now;
            Now  = Next;
            if (Now.Joint || Now.MidJoint)
            {
                if (BNodeRID == 0 || BNodeRID == 2)
                {
                    Positions.Add(Now.Position * ParentKnot.GlobalRate);
                }
                break;
            }
        }
        // LineRendererにデータを流し込む。
        LR.positionCount = Positions.Count;
        for (int count = 0; count < Positions.Count; count++)
        {
            LR.SetPosition(count, Positions[count]);
        }
    }