Пример #1
0
        public void StartStretchMode()
        {
            var stretchnodename = curEditNode.name;

            Debug.Log("StartStrechMode selname:" + stretchnodename);
            grc.uniqueNodePrefix = uniqueNodePrefix;
            grc.uniqueLinkPrefix = uniqueLinkPrefix;

            if (grc.IsNodeName(stretchnodename))
            {
                var node = grc.GetNode(stretchnodename);
                if (nodeMoveMode == nodeMoveModeE.move)
                {
                    // turn purple and start stretching
                    this.nodeMoveMode = nodeMoveModeE.stretch;
                    originalpos       = node.pt;
                    lm.SetNodeColorOverride(node.name, "purple", node.go);
                }
                else
                {
                    // now stop stretching
                    //var npt = grc.finishStretchMovement(selname, originalpos,linkUseType, editNodeRegion.regid);
                    var nodename = LcNode.NormName(stretchnodename);
                    var lnode    = grc.GetNode(nodename);
                    var closeest = grc.FindClosestNodeToNodeGo(lnode);
                    if (Vector3.Distance(closeest.go.transform.position, lnode.go.transform.position) > 0.2f)
                    {
                        // move the node because there is nothing close (20 cm)
                        var newname = grc.genuniquenodename();
                        var newnode = grc.GetNewNode(newname, lnode.go.transform.position, lnode.usetype);
                        newnode.regid = editNodeRegion.regid;
                        lnode.pt      = originalpos;
                        lnode.go.transform.position = originalpos;
                        var lnk = grc.AddLink("", lnode, newnode, linkUseType);
                        lnk.regid = editNodeRegion.regid;
                        SetCurrentEditNode(newnode.name);
                    }
                    else
                    {
                        // here we just link to the closest node ... this may not always be the right thing to do
                        var newlinkname = grc.genuniquelinkname();
                        var lnk         = grc.AddLink(newlinkname, lnode, closeest, linkUseType);
                        lnk.regid = editNodeRegion.regid;
                    }
                    lm.RemoveNodeColorOverride(node.name);
                    nodeMoveMode = nodeMoveModeE.move;
                    //sm.RequestHighObjRefresh(selname,"SetStretchMode");
                }
            }
            else
            {
                Debug.Log("Not a node name:" + stretchnodename);
            }
        }
Пример #2
0
        public void CreateSpherePoints(int nlng = 10, int nlat = 10, float rad = 5.0f, float heit = 0)
        {
            grc.gm.initmods();
            grc.gm.mod_name_pfx = getmodelprefix("sph-", forcecount: true);
            var optar = new LcNode[nlng, nlat];

            for (int i = 0; i < nlat; i++)
            {
                float alat = Mathf.PI * (90 - (i * 180f / (nlat - 1))) / 180;
                float y    = rad * Mathf.Sin(alat) + heit;
                float crad = rad * Mathf.Cos(alat);
                for (int j = 0; j < nlng; j++)
                {
                    float  alng  = Mathf.PI * (j * 360f / nlng) / 180;
                    float  z     = crad * Mathf.Sin(alng);
                    float  x     = crad * Mathf.Cos(alng);
                    var    pt    = new Vector3(x, y, z);
                    var    pname = "pt." + i.ToString() + "." + j.ToString();
                    LcNode npt   = grc.AddNode(pname, pt);
                    optar[i, j] = npt;
                }
            }
            for (int i = 0; i < nlat; i++)
            {
                for (int j = 0; j < nlng; j++)
                {
                    var jto   = (j + 1) % nlng;
                    var lname = "lk.h." + i + "." + j;
                    grc.AddLink(lname, optar[i, j], optar[i, jto]);
                    if (i > 0)
                    {
                        var lname1 = "lk.v." + i + "." + j;
                        grc.AddLink(lname1, optar[i - 1, j], optar[i, j]);
                    }
                }
            }
        }