Пример #1
0
    void OutputData()
    {
        int nodeNumber = nodes.Count;

        thisKnot.ClearAll();
        for (int n = 0; n < nodeNumber; n++)
        {
            DNode nn = nodes[n];
            if (n % 5 == 0)
            {                                                                                             // ジョイント
                Node nd = thisKnot.AddNode(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n
                Bead bd = thisKnot.AddBead(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n
                if (nn.ou)
                {
                    nd.Theta = Mathf.Atan2(nodes[n + 1].y - nodes[n].y, nodes[n + 1].x - nodes[n].x);
                }
                else
                {
                    nd.Theta = Mathf.Atan2(nodes[n + 2].y - nodes[n].y, nodes[n + 1].x - nodes[n].x);
                }
                nd.R[0]      = nd.R[1] = nd.R[2] = nd.R[3] = 0.1f;
                nd.ID        = n;
                nd.Joint     = true;
                nd.MidJoint  = false;
                bd.NumOfNbhd = 4;            //あとで設定
                bd.N1        = bd.N2 = null; //あとで設定
                bd.U1        = bd.U2 = null; //あとで設定
                bd.ID        = n;
                bd.Joint     = true;
                bd.MidJoint  = false;
                nd.ThisBead  = bd;
            }
            else
            {                                                                                             //非ジョイント
                Bead bd = thisKnot.AddBead(new Vector3((nn.x - 400f) * 0.01f, (nn.y - 400f) * 0.01f), n); // ID = n
                bd.NumOfNbhd = 2;                                                                         //あとで設定
                bd.N1        = bd.N2 = null;                                                              //あとで設定
                bd.U1        = bd.U2 = null;                                                              //あとで設定
                bd.ID        = n;
                bd.Joint     = false;
                bd.MidJoint  = false;
            }
        }
        int BeadLastID = thisKnot.GetMaxIDOfBead();
        // edges
        int A = -1, AR = -1, B = -1, BR = -1;

        for (int e = 0; e < edges.Count; e++)
        {
            DEdge ee = edges[e];
            if (ee.visible)
            {
                A = AR = B = BR = -1;
                if (ee.s % 5 != 0 && ee.t % 5 != 0)
                {
                    for (int es = 0; es < edges.Count; es++)
                    {
                        DEdge ees = edges[es];
                        // ee.sからたどれるジョイントを見つける
                        if (ees.visible && ees.s % 5 == 0 && ees.t == ee.s)
                        {
                            int   s0          = ees.s;
                            float aX          = nodes[s0 + 2].x - nodes[s0 + 1].x;
                            float aY          = nodes[s0 + 2].y - nodes[s0 + 1].y;
                            float bX          = nodes[s0 + 4].x - nodes[s0 + 1].x;
                            float bY          = nodes[s0 + 4].y - nodes[s0 + 1].y;
                            float orientation = aX * bY - aY * bX;
                            int   t           = ees.t - ees.s;
                            if (orientation > 0)
                            {
                                if (nodes[ees.s].ou)
                                {
                                    t = (t + 7) % 4;
                                }
                                else
                                {
                                    t = (t + 6) % 4;
                                }
                            }
                            else
                            {
                                if (nodes[ees.s].ou)
                                {
                                    t = (5 - t) % 4;
                                }
                                else
                                {
                                    t = (6 - t) % 4;
                                }
                            }
                            A  = ees.s;// ee.sからたどれるジョイント
                            AR = t;
                        }
                        // ee.tからたどれるジョイント
                        if (ees.visible && ees.s % 5 == 0 && ees.t == ee.t)
                        {
                            int   s0          = ees.s;
                            float aX          = nodes[s0 + 2].x - nodes[s0 + 1].x;
                            float aY          = nodes[s0 + 2].y - nodes[s0 + 1].y;
                            float bX          = nodes[s0 + 4].x - nodes[s0 + 1].x;
                            float bY          = nodes[s0 + 4].y - nodes[s0 + 1].y;
                            float orientation = aX * bY - aY * bX;
                            int   t           = ees.t - ees.s;
                            if (orientation > 0)
                            {
                                if (nodes[ees.s].ou)
                                {
                                    t = (t + 7) % 4;
                                }
                                else
                                {
                                    t = (t + 6) % 4;
                                }
                            }
                            else
                            {
                                if (nodes[ees.s].ou)
                                {
                                    t = (5 - t) % 4;
                                }
                                else
                                {
                                    t = (6 - t) % 4;
                                }
                            }
                            B  = ees.s;// ee.tからたどれるジョイント
                            BR = t;
                        }
                    }                                                  ////
                    Edge ed       = thisKnot.AddEdge(A, B, AR, BR, e); // iD = e (連番に限らない。)
                    Bead bdJointA = thisKnot.GetBeadByID(A);
                    Bead bdAR     = thisKnot.GetBeadByID(ee.s);
                    Bead bdBR     = thisKnot.GetBeadByID(ee.t);
                    Bead bdJointB = thisKnot.GetBeadByID(B);
                    if (bdJointA == null || bdAR == null || bdBR == null || bdJointB == null)
                    {
                        continue;
                    }
                    bdJointA.SetNU12(AR, bdAR);
                    bdAR.N1 = bdJointA;
                    bdAR.N2 = bdBR;
                    bdBR.N1 = bdJointB;
                    bdBR.N2 = bdAR;
                    bdJointB.SetNU12(BR, bdBR);
                }
            }
        }
        thisKnot.GetAllThings();

        thisKnot.Modify();
        // NodeEdgeからBeadsを整える
        thisKnot.UpdateBeads();
        //グラフの形を整える。現状ではR[]を整えるだけ。
        thisKnot.Modify();
        Display.SetDrawKnotMode();// drawモードの変更
    }