예제 #1
0
        public List <Branch> SearchBranch(BranchSC search)
        {
            var result = new List <Branch>();

            try
            {
                var query = Context.Branch.AsQueryable();
                if (search != null)
                {
                    if (!string.IsNullOrEmpty(search.Name))
                    {
                        query = query.Where(b => b.Name != null && b.Name.Contains(search.Name));
                    }
                    if (!string.IsNullOrEmpty(search.Code))
                    {
                        query = query.Where(b => b.Code != null && b.Code == search.Code);
                    }
                    if (!string.IsNullOrEmpty(search.Email))
                    {
                        query = query.Where(b => b.Email != null && b.Email.Contains(search.Email));
                    }
                }
                result = query.ToList();
            }
            catch { }

            return(result);
        }
예제 #2
0
 private void drawBranch(BranchSC branch)
 {
     for (int i = 0; i < branch.childs.Count; i++)
     {
         Gizmos.DrawLine(branch.pos, branch.childs[i].pos);
         drawBranch(branch.childs[i]);
     }
 }
예제 #3
0
 /// <summary>
 /// Constructs a new Tree
 /// </summary>
 /// <param name="pos">The position wher the tree root is going to be placed</param>
 public TreeSC(Vector3 pos, Material mat)
 {
     tree = new GameObject("Tree");
     tree.transform.position = pos;
     root             = new BranchSC(pos, null, true, mat, ref tree, 1);
     maxGrowIteration = root.growIteration;
     growBranchList   = new List <BranchSC>();
     canGrow          = false;
 }
예제 #4
0
    /// <summary>
    /// Grow the truck of the tree until it reaches the point cloud.
    /// </summary>
    /// <param name="growDist">The distance that grows each new branch</param>
    /// <param name="attractionDist">The maximum distanche at witch a branch can be attracted</param>
    /// <param name="pointList">List of points in the point cloud</param>
    public void growTrunk(float growDist, float attractionDist, ref List <Vector3> pointList, Vector3 tropism)
    {
        float minDist = Mathf.Infinity;
        bool  found   = false;

        int timeout = 1000;

        BranchSC currentBranch = this.root;

        while (!found && timeout > 0)
        {
            // Look in the point list if there is any point that can affect
            // the trunk branches
            for (int i = 0; i < pointList.Count && !found; i++)
            {
                // For each poitn calculate the ditance to the last branch of the trunk
                float dist = Vector3.Distance(currentBranch.pos, pointList[i]);

                // Udate the grow direction of the last branch
                currentBranch.growDir += (pointList[i] - currentBranch.pos).normalized;

                if (dist < minDist)
                {
                    minDist = dist;
                    if (minDist < attractionDist)
                    {
                        found = true;
                    }
                }
            }

            if (!found)
            {
                BranchSC newBranch = currentBranch.grow(growDist, true, tropism);
                if (newBranch.growIteration > maxGrowIteration)
                {
                    maxGrowIteration = newBranch.growIteration;
                }
                currentBranch = newBranch;
                //endedBranchList.Add(growBranchList[growBranchList.Count - 1]);
                //growBranchList.RemoveAt(growBranchList.Count - 1);
                //growBranchList.Add(newBranch);
            }
            else
            {
                currentBranch.growDir = Vector3.zero;
                this.growBranchList.Add(currentBranch);
            }
            timeout--;
        }
        if (timeout <= 0)
        {
            Debug.LogError("Error generating the trunk");
        }
        this.canGrow = true;
    }
        public PartialViewResult _BranchList(BranchSC search)
        {
            BranchVM[] branches = null;
            try
            {
                branches = UnitOfWork.BranchBL.SearchBranch(search).Select(b => new BranchVM(b)).ToArray();
            }
            catch (Exception e)
            {
                branches = null;
            }

            return(PartialView(branches));
        }
예제 #6
0
 private void drawLeaves(BranchSC branch)
 {
     if (branch.hasLeaf)
     {
         Gizmos.color = Color.green;
         Gizmos.DrawSphere(branch.pos, 2.0f);
     }
     else
     {
         for (int i = 0; i < branch.childs.Count; i++)
         {
             drawLeaves(branch.childs[i]);
         }
     }
 }
예제 #7
0
 public BranchSC(Vector3 pos, BranchSC parent, bool isTrunk, Material mat, ref GameObject tree, int growIteration, float initialRad = 0.01f)
 {
     this.pos           = pos;
     this.tree          = tree;
     this.parent        = parent;
     this.growIteration = growIteration;
     childs             = new List <BranchSC>();
     rad      = initialRad;
     growDir  = new Vector3(0.0f, 0.0f, 0.0f);
     hasLeaf  = false;
     meshList = new List <BranchMesh>();
     go       = new GameObject("Branch");
     go.transform.position = pos;
     go.transform.parent   = tree.transform;
     branchMaterial        = mat;
     leaves        = new List <GameObject>();
     leavesTimeOut = new List <float>();
 }
예제 #8
0
    /*private void generateMesh(BranchSC branch)
     * {
     *  branch.sortSons();
     *
     *  for(int i = 0; i < branch.childs.Count; i++) {
     *      GameObject newBranch = new GameObject("Branch");
     *      newBranch.AddComponent<MeshRenderer>();
     *      newBranch.AddComponent<MeshFilter>();
     *      if (branch.childs[i].mesh != null)
     *      {
     *          branch.mesh.recalculateMesh(branch.rad, branch.childs[i].rad);
     *          newBranch.GetComponent<MeshFilter>().mesh = branch.mesh.mesh;
     *      }
     *      newBranch.GetComponent<MeshRenderer>().material = treeMat;
     *      newBranch.transform.parent = transform;
     *      generateMesh(branch.childs[i]);
     *  }
     * }*/

    private void generateMesh(BranchSC branch)
    {
        if (branch.meshList != null)
        {
            for (int i = 0; i < branch.meshList.Count; i++)
            {
                GameObject newBranch = new GameObject("Branch");
                newBranch.AddComponent <MeshRenderer>();
                newBranch.AddComponent <MeshFilter>();
                branch.meshList[i].recalculateMesh(branch.rad, branch.childs[i].rad);
                newBranch.GetComponent <MeshFilter>().mesh       = branch.meshList[i].mesh;
                newBranch.GetComponent <MeshRenderer>().material = treeMat;
                newBranch.transform.parent = transform;
            }

            for (int i = 0; i < branch.childs.Count; i++)
            {
                generateMesh(branch.childs[i]);
            }
        }
    }
예제 #9
0
    /// <summary>
    /// Grows all the branches in the growBranchLIst in the direction defined by the
    /// points in the point cloud. If a branch can't grow anymore it is removed from
    /// the growBranchList.
    /// If no branch grows in the iteration, canGrow is set to false
    /// </summary>
    /// <param name="growDist">The distance that grows each new branch</param>
    /// <param name="attractionDist">The maximum distanche at witch a branch can be attracted</param>
    /// <param name="removeDist">The maximum distance </param>
    /// <param name="pointList">List of points in the point cloud</param>
    public void growTreeIteration(float growDist, float attractionDist, float removeDist, ref List <Vector3> pointList, Vector3 tropism)
    {
        if (this.canGrow)
        {
            // Calculate the grow direction of all the branches with the points in
            // the point cloud
            foreach (Vector3 point in pointList)
            {
                float minDist      = Mathf.Infinity;
                int   minDistIndex = -1;
                for (int i = 0; i < this.growBranchList.Count; i++)
                {
                    float dist = Vector3.Distance(point, this.growBranchList[i].pos);
                    if (dist < minDist)
                    {
                        minDist      = dist;
                        minDistIndex = i;
                    }
                }
                if (minDist <= attractionDist && minDistIndex >= 0)
                {
                    this.growBranchList[minDistIndex].growDir += (point - this.growBranchList[minDistIndex].pos).normalized;
                }
            }

            // Try to add a new branch to all the branches in the growBranchList
            bool addedNewBranch = false;
            int  branchNum      = this.growBranchList.Count;
            for (int i = 0; i < branchNum; i++)
            {
                BranchSC newBranch = this.growBranchList[i].grow(growDist, false, tropism);
                if (newBranch == null)
                {
                    growBranchList.RemoveAt(i);
                    i--;
                    branchNum--;
                }
                else
                {
                    growBranchList.Add(newBranch);
                    if (newBranch.growIteration > maxGrowIteration)
                    {
                        maxGrowIteration = newBranch.growIteration;
                    }
                    addedNewBranch = true;
                }
            }
            // If no branch has grown, set canGrow to false
            if (!addedNewBranch)
            {
                canGrow = false;
            }

            // remove all the points that are in removeDistance range from any of the branches
            for (int i = 0; i < pointList.Count; i++)
            {
                bool rm = false;
                for (int j = 0; j < growBranchList.Count && !rm; j++)
                {
                    if (Vector3.Distance(pointList[i], growBranchList[j].pos) <= removeDist)
                    {
                        pointList.RemoveAt(i);
                        rm = true;
                        i--;
                    }
                }
            }

            // Recalcualte the radious of all the branches in the tree
            root.calculateRad(maxGrowIteration);
        }
    }
예제 #10
0
    public BranchSC grow(float growDist, bool growTrunk, Vector3 tropism)
    {
        if (/*this.growDir.magnitude > 0.1*/ true)
        {
            Vector3 newPos = this.pos + (this.growDir.normalized + tropism).normalized * growDist;
            foreach (BranchSC child in this.childs)
            {
                if (Vector3.Distance(child.pos, newPos) <= 0.05)
                {
                    this.growDir = new Vector3(0.0f, 0.0f, 0.0f);
                    return(null);
                }
            }

            if (parent != null)
            {
                if (Vector3.Distance(parent.pos, newPos) <= 0.05)
                {
                    this.growDir = new Vector3(0.0f, 0.0f, 0.0f);
                    return(null);
                }
            }

            BranchSC newBranch = new BranchSC(newPos, this, growTrunk, branchMaterial, ref tree, growIteration + 1);
            this.growDir = new Vector3(0.0f, 0.0f, 0.0f);
            this.childs.Add(newBranch);

            BranchMesh newMesh;
            if (this.parent != null)
            {
                newMesh = new BranchMesh(this.pos,
                                         this.pos - this.parent.pos,
                                         newBranch.pos - this.pos,
                                         this.rad,
                                         newBranch.rad);
            }
            else
            {
                newMesh = new BranchMesh(this.pos,
                                         this.pos - tree.transform.position,
                                         newBranch.pos - this.pos,
                                         this.rad,
                                         newBranch.rad);
            }

            GameObject newBranchObject = new GameObject("BranchChild");
            newBranchObject.AddComponent <MeshRenderer>();
            newBranchObject.AddComponent <MeshFilter>();
            newBranchObject.AddComponent <MeshCollider>();
            newBranchObject.GetComponent <MeshFilter>().mesh         = newMesh.mesh;
            newBranchObject.GetComponent <MeshRenderer>().material   = branchMaterial;
            newBranchObject.GetComponent <MeshCollider>().sharedMesh = newMesh.mesh;
            newBranchObject.transform.parent = go.transform;
            meshList.Add(newMesh);

            return(newBranch);
        }
        else
        {
            this.growDir = new Vector3(0.0f, 0.0f, 0.0f);
            return(null);
        }
    }
예제 #11
0
 static int sortByRad(BranchSC b1, BranchSC b2)
 {
     return(-b1.rad.CompareTo(b2.rad));
 }