Ejemplo n.º 1
0
        public bool findCurve(leaf leaf, ref branch target, List <branch> listBranch, NurbsCurve curve)
        {
            var Points  = curve.Points;
            var rPoints = curve.Points.Reverse().ToList();

            foreach (var branch in listBranch)
            {
                if (branch.crv.Points[0].Location.DistanceTo(Points[0].Location) < 0.0001)
                {
                    if (branch.crv.Points[1].Location.DistanceTo(Points[1].Location) < 0.0001)
                    {
                        target = branch;
                        if (branch.branchType != branch.type.kink)
                        {
                            branch.target = leaf;
                        }
                        else
                        {
                            if (branch.left == null)
                            {
                                branch.left = leaf;
                            }
                            else
                            {
                                branch.right = leaf;
                            }
                        }
                        return(false);
                    }
                }
                else if (branch.crv.Points[0].Location.DistanceTo(rPoints[0].Location) < 0.0001)
                {
                    if (branch.crv.Points[1].Location.DistanceTo(rPoints[1].Location) < 0.0001)
                    {
                        target = branch;
                        if (branch.branchType != branch.type.kink)
                        {
                            branch.target = leaf;
                        }
                        else
                        {
                            if (branch.left == null)
                            {
                                branch.left = leaf;
                            }
                            else
                            {
                                branch.right = leaf;
                            }
                        }
                        return(true);
                    }
                }
            }
            ttt++;
            AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "cannot find:" + ttt.ToString());
            listError.Add(curve);
            return(false);
        }
Ejemplo n.º 2
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            leaf l = getLeaf(e.Node.Text);

            hexBox1.Select(l.offset, l.size);
            toolStripStatusLabel1.Text = string.Format("Offset: 0x{0:X}    Size: 0x{1:X}",
                                                       l.offset, l.size);
        }
Ejemplo n.º 3
0
        void createNurbsElements(leaf leaf)
        {
            double[] uKnot;
            double[] vKnot;

            int N     = leaf.nU * leaf.nV;
            int uDim  = leaf.srf.OrderU;
            int vDim  = leaf.srf.OrderV;
            int uDdim = leaf.srf.OrderU - 1;
            int vDdim = leaf.srf.OrderV - 1;


            uKnot = new double[leaf.nU - uDdim + 1 + uDdim * 2];
            vKnot = new double[leaf.nV - vDdim + 1 + vDdim * 2];
            for (int i = 0; i < uDdim; i++)
            {
                uKnot[i] = 0;
            }
            for (int i = 0; i < vDdim; i++)
            {
                vKnot[i] = 0;
            }
            for (int i = 0; i < leaf.nU - uDdim + 1; i++)
            {
                uKnot[i + uDdim] = i;
            }
            for (int i = 0; i < leaf.nV - vDdim + 1; i++)
            {
                vKnot[i + vDdim] = i;
            }
            for (int i = 0; i < uDdim; i++)
            {
                uKnot[i + leaf.nU + 1] = leaf.nU - uDdim;
            }
            for (int i = 0; i < vDdim; i++)
            {
                vKnot[i + leaf.nV + 1] = leaf.nV - vDdim;
            }
            leaf.myMasonry = new Minilla3D.Objects.masonry();
            for (int j = 1; j < leaf.nV - vDdim + 1; j++)
            {
                for (int i = 1; i < leaf.nU - uDdim + 1; i++)
                {
                    int[] index = new int[uDim * vDim];
                    for (int k = 0; k < vDim; k++)
                    {
                        for (int l = 0; l < uDim; l++)
                        {
                            index[k * uDim + l] = (j - 1 + k) * leaf.nU + i - 1 + l;
                        }
                    }
                    leaf.myMasonry.elemList.Add(new Minilla3D.Elements.nurbsElement(uDim, vDim, index, i, j, uKnot, vKnot));
                }
            }
        }
Ejemplo n.º 4
0
    public bool attacked = false;               // Checks if attacked

    void Update()
    {
        // If the wheat was attacked, it will be destroyed and spwn 3 leaves
        if (attacked == true)
        {
            GameObject leef1 = (GameObject)Instantiate(leaff, new Vector3(transform.position.x + 0.0f, transform.position.y + 0.5f, transform.position.z), transform.rotation);
            GameObject leef2 = (GameObject)Instantiate(leaff, new Vector3(transform.position.x + 0.5f, transform.position.y - 0.5f, transform.position.z), transform.rotation);
            GameObject leef3 = (GameObject)Instantiate(leaff, new Vector3(transform.position.x - 0.5f, transform.position.y - 0.5f, transform.position.z), transform.rotation);

            //leaff.gameObject.GetComponent<leaf>.cango = true;

            leaf leff1 = leef1.GetComponent <leaf>();
            leaf leff2 = leef2.GetComponent <leaf>();
            leaf leff3 = leef3.GetComponent <leaf>();
            leff1.cango        = true;
            leff2.cango        = true;
            leff3.cango        = true;
            leff2.makeplatform = true;
            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 5
0
        protected override void SolveInstance(Grasshopper.Kernel.IGH_DataAccess DA)
        {
            init();
            _listSrf = new List <Surface>();
            _listCrv = new List <Curve>();
            listPnt  = new List <Point3d>();
            List <string> crvTypes   = new List <string>();
            List <string> pntHeights = new List <string>();

            if (!DA.GetDataList(0, _listSrf))
            {
                return;
            }
            if (!DA.GetDataList(1, _listCrv))
            {
                return;
            }
            if (!DA.GetDataList(2, crvTypes))
            {
                return;
            }
            if (!DA.GetDataList(3, listPnt))
            {
                listPnt.Clear();
            }
            if (!DA.GetData(4, ref globalC))
            {
                return;
            }

            if (_listCrv.Count != crvTypes.Count)
            {
                AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "need types for curves"); return;
            }

            listSlice  = new Dictionary <string, slice>();
            listSlice2 = new Dictionary <string, slice2>();
            listLeaf   = new List <leaf>();
            listBranch = new List <branch>();
            listNode   = new List <node>();
            myControlBox.clearSliders();

            for (int i = 0; i < _listCrv.Count; i++)
            {
                var branch = new branch();
                branch.crv     = _listCrv[i] as NurbsCurve;
                branch.N       = branch.crv.Points.Count;
                branch.dom     = branch.crv.Domain;
                branch.Dim     = branch.crv.Order;
                branch.dDim    = branch.crv.Order - 1;
                branch.nElem   = branch.N - branch.dDim;
                branch.scaleT  = (branch.dom.T1 - branch.dom.T0) / branch.nElem;
                branch.originT = branch.dom.T0;
                if (crvTypes[i].StartsWith("reinforce"))
                {
                    branch.branchType = branch.type.reinforce;
                    var key = crvTypes[i].Replace("reinforce", "");
                    branch.sliceKey = key;
                    try{
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e) {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("kink"))
                {
                    branch.branchType = branch.type.kink;
                    var    key = crvTypes[i].Replace("kink", "");
                    double lb  = 0.0d;
                    double _lb;
                    bool   res = double.TryParse(key, out _lb);
                    if (res)
                    {
                        lb = _lb;
                    }
                    else
                    {
                        lb = 0.0d;
                    }
                    branch.lb = lb;
                    //int NN;
                    //res = int.TryParse(key, out NN);
                    //if (res) { if (NN == 123) { branch.obj = true; } }
                }
                else if (crvTypes[i].StartsWith("open"))
                {
                    branch.branchType = branch.type.open;
                    var key = crvTypes[i].Replace("open", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice[key]         = new slice();
                        branch.slice           = listSlice[key];
                        branch.slice.sliceType = slice.type.fr;
                        branch.slice.lB.Add(branch);
                    }
                }
                else if (crvTypes[i].StartsWith("fix"))
                {
                    branch.branchType = branch.type.fix;
                    var key = crvTypes[i].Replace("fix", "");
                    branch.sliceKey = key;
                    try
                    {
                        branch.slice2 = listSlice2[key];
                    }
                    catch (KeyNotFoundException e)
                    {
                        listSlice2[key] = new slice2();
                        branch.slice2   = listSlice2[key];

                        var slider = myControlBox.addSliderVert(0, 1, 200, 100);
                        slider.Converter = (val) =>
                        {
                            double height = val / 10d - 10d;
                            branch.slice2.height = height;
                            this.ExpirePreview(true);
                            return(height);
                        };
                    }
                }
                else
                {
                    AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "type should be either of reinforce, kink, fix, or open");
                }
                listBranch.Add(branch);
            }

            // Connect nodes
            foreach (var node in listNode)
            {
                node.N = 0;
                node.share.Clear();
                node.number.Clear();
            }
            foreach (var branch in listBranch)
            {
                var  P    = branch.crv.Points[0].Location;
                bool flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(P))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(0);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(0);
                    newNode.x = P.X;
                    newNode.y = P.Y;
                    newNode.z = P.Z;
                }
                var Q = branch.crv.Points[branch.N - 1].Location;
                flag = false;
                foreach (var node in listNode)
                {
                    if (node.compare(Q))
                    {
                        flag = true;
                        node.N++;
                        node.share.Add(branch);
                        node.number.Add(branch.N - 1);
                        break;
                    }
                }
                if (!flag)
                {
                    var newNode = new node();
                    listNode.Add(newNode);
                    newNode.N++;
                    newNode.share.Add(branch);
                    newNode.number.Add(branch.N - 1);
                    newNode.x = Q.X;
                    newNode.y = Q.Y;
                    newNode.z = Q.Z;
                }
            }
            for (int i = 0; i < _listSrf.Count; i++)
            {
                var srf  = _listSrf[i];
                var leaf = new leaf();
                listLeaf.Add(leaf);
                leaf.srf     = srf as NurbsSurface;
                leaf.nU      = leaf.srf.Points.CountU;
                leaf.nV      = leaf.srf.Points.CountV;
                leaf.domU    = leaf.srf.Domain(0);
                leaf.domV    = leaf.srf.Domain(1);
                leaf.uDim    = leaf.srf.OrderU;
                leaf.vDim    = leaf.srf.OrderV;
                leaf.uDdim   = leaf.srf.OrderU - 1;
                leaf.vDdim   = leaf.srf.OrderV - 1;
                leaf.nUelem  = leaf.nU - leaf.uDdim;
                leaf.nVelem  = leaf.nV - leaf.vDdim;
                leaf.scaleU  = (leaf.domU.T1 - leaf.domU.T0) / leaf.nUelem;
                leaf.scaleV  = (leaf.domV.T1 - leaf.domV.T0) / leaf.nVelem;
                leaf.originU = leaf.domU.T0;
                leaf.originV = leaf.domV.T0;
                var domainU = leaf.srf.Domain(0);
                var domainV = leaf.srf.Domain(1);
                //Find corresponding curve
                //(0,0)->(1,0)
                var curve = leaf.srf.IsoCurve(0, domainV.T0) as NurbsCurve;
                leaf.flip[0] = findCurve(leaf, ref leaf.branch[0], listBranch, curve);//bottom
                //(1,0)->(1,1)
                curve        = leaf.srf.IsoCurve(1, domainU.T1) as NurbsCurve;
                leaf.flip[1] = findCurve(leaf, ref leaf.branch[1], listBranch, curve);//right
                //(1,1)->(0,1)
                curve        = leaf.srf.IsoCurve(0, domainV.T1) as NurbsCurve;
                leaf.flip[2] = findCurve(leaf, ref leaf.branch[2], listBranch, curve);//top
                //(0,1)->(0,0)
                curve        = leaf.srf.IsoCurve(1, domainU.T0) as NurbsCurve;
                leaf.flip[3] = findCurve(leaf, ref leaf.branch[3], listBranch, curve);//left
            }
            //multiqudric surface
            var A = new Rhino.Geometry.Matrix(listPnt.Count, listPnt.Count);
            var z = new Rhino.Geometry.Matrix(listPnt.Count, 1);

            for (int i = 0; i < listPnt.Count; i++)
            {
                for (int j = 0; j < listPnt.Count; j++)
                {
                    var pi = listPnt[i];
                    var pj = listPnt[j];
                    A[i, j] = quadFunc(pi.X, pj.X, pi.Y, pj.Y);
                    z[i, 0] = pi.Z;
                }
            }
            A.Invert(0.0);  //this parameter should be 0.0
            var c = A * z;

            globalCoeff = new double[listPnt.Count];
            for (int i = 0; i < listPnt.Count; i++)
            {
                globalCoeff[i] = c[i, 0];
            }
            targetSrf  = new List <Point3d>();
            globalFunc = (xi, yi) => {
                double Z = 0;
                for (int j = 0; j < listPnt.Count; j++)
                {
                    Z = Z + globalCoeff[j] * quadFunc(xi, listPnt[j].X, yi, listPnt[j].Y);
                }
                return(Z);
            };
            foreach (var leaf in listLeaf)
            {
                var domU = leaf.domU;
                var domV = leaf.domV;
                for (double i = 0; i <= 1.0; i += 0.05)
                {
                    for (double j = 0; j < 1.0; j += 0.05)
                    {
                        double u = domU[0] + i * (domU[1] - domU[0]);
                        double v = domV[0] + j * (domV[1] - domV[0]);
                        Rhino.Geometry.Point3d    P;
                        Rhino.Geometry.Vector3d[] V;
                        leaf.srf.Evaluate(u, v, 0, out P, out V);
                        var newP = new Rhino.Geometry.Point3d(P.X, P.Y, globalFunc(P.X, P.Y));
                        targetSrf.Add(newP);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void tieBranch2(branch branch, leaf leaf)
        {
            int T0 = 0, T1 = 0;

            for (int s = 0; s < 4; s++)
            {
                if (s == 0)
                {
                    T0 = 0; T1 = (leaf.nUelem * leaf.NN) - 1;
                }
                if (s == 1)
                {
                    T0 = (leaf.nUelem * leaf.NN); T1 = (leaf.nUelem + leaf.nVelem) * leaf.NN - 1;
                }
                if (s == 2)
                {
                    T0 = (leaf.nUelem + leaf.nVelem) * leaf.NN; T1 = (leaf.nUelem * 2 + leaf.nVelem) * leaf.NN - 1;
                }
                if (s == 3)
                {
                    T0 = (leaf.nUelem * 2 + leaf.nVelem) * leaf.NN; T1 = (leaf.nUelem * 2 + leaf.nVelem * 2) * leaf.NN - 1;
                }
                if (leaf.branch[s] == branch)//s=0:bottom, s=1:right, s=2:top, s=3:left
                {
                    int N = 0;
                    if (s == 0 || s == 2)
                    {
                        N = leaf.nU;
                    }
                    else
                    {
                        N = leaf.nV;
                    }
                    if (N == branch.N)
                    {
                        for (int i = 0; i < branch.nElem * branch.NN; i++)
                        {
                            if (leaf.flip[s])
                            {
                                if (branch.left == leaf)
                                {
                                    branch.tuples[i].left = leaf.edgeTuples[T1 - i];
                                }
                                if (branch.right == leaf)
                                {
                                    branch.tuples[i].right = leaf.edgeTuples[T1 - i];
                                }
                                if (branch.target == leaf)
                                {
                                    branch.tuples[i].target = leaf.edgeTuples[T1 - i];
                                }
                            }
                            else
                            {
                                if (branch.left == leaf)
                                {
                                    branch.tuples[i].left = leaf.edgeTuples[T0 + i];
                                }
                                if (branch.right == leaf)
                                {
                                    branch.tuples[i].right = leaf.edgeTuples[T0 + i];
                                }
                                if (branch.target == leaf)
                                {
                                    branch.tuples[i].target = leaf.edgeTuples[T0 + i];
                                }
                            }
                        }
                    }
                    else
                    {
                        AddRuntimeMessage(Grasshopper.Kernel.GH_RuntimeMessageLevel.Error, "cannot tie");
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void buildTree()
        {
            fillTree();
            TreeNode treeroot = new TreeNode();

            List <TreeNode> temp  = new List <TreeNode>();
            STATES          state = STATES.NONE;
            int             i     = 0;

            for (i = 0; i < list.Count; i++)
            {
                leaf l = list[i];
                if (l.isRoot)
                {
                    state    = STATES.ROOT;
                    treeroot = new TreeNode(l.name);
                }
                else if (l.hasChildren)
                {
                    state = STATES.PARENT;
                    temp.Add(new TreeNode(l.name));
                    continue;
                }
                else if (l.lastChild)
                {
                    STATES tempstate = state;
                    state = STATES.LAST_CHILD;
                    if (temp.Count > 0)
                    {
                        temp[temp.Count - 1].Nodes.Add(l.name);
                        if (getLeaf(l.fatherName).fatherName == "Key Vault" || l.fatherName == "Key Vault")
                        {
                            treeroot.Nodes.Add(temp[temp.Count - 1]);
                        }
                        else
                        {
                            temp[temp.Count - 2].Nodes.Add(temp[temp.Count - 1]);
                        }
                        temp.RemoveAt(temp.Count - 1);
                    }
                    if (temp.Count > 0)
                    {
                        state = tempstate;
                    }
                    else
                    {
                        state = STATES.LEAF;
                    }
                    continue;
                }

                if (state != STATES.PARENT)
                {
                    treeroot.Nodes.Add(l.name);
                }
                if (state == STATES.PARENT)
                {
                    temp[temp.Count - 1].Nodes.Add(l.name);
                }
            }
            treeroot.Nodes.Add(list[i - 1].name);
            this.treeView1.Nodes.AddRange(new TreeNode[] { treeroot });
            //treeView1.ExpandAll();
        }