Пример #1
0
        //Algoritmo de refinamiento Se va ejecutando sobre la marcha, buscando angulos demasiado poco pronunciados y refinándolos o puntos demasiado juntos y eliminando puntos para evitar nudos
        void Refine(BranchContainer branch)
        {
            if (branch.branchPoints.Count > 3)
            {
                if (Vector3.Distance(branch.branchPoints [branch.branchPoints.Count - 2].point, branch.branchPoints [branch.branchPoints.Count - 3].point) < infoPool.ivyParameters.stepSize * 0.7f ||
                    Vector3.Distance(branch.branchPoints [branch.branchPoints.Count - 2].point, branch.branchPoints [branch.branchPoints.Count - 1].point) < infoPool.ivyParameters.stepSize * 0.7f)
                {
                    branch.RemoveBranchPoint(branch.branchPoints.Count - 2);

                    //branch.grabVectors.RemoveAt (branch.branchPoints.Count - 2);
                }

                if (Vector3.Angle(branch.branchPoints [branch.branchPoints.Count - 1].point - branch.branchPoints [branch.branchPoints.Count - 2].point, branch.branchPoints [branch.branchPoints.Count - 2].point - branch.branchPoints [branch.branchPoints.Count - 3].point) > 25f)
                {
                    Vector3 last    = branch.branchPoints [branch.branchPoints.Count - 1].point - branch.branchPoints [branch.branchPoints.Count - 2].point;
                    Vector3 preLast = branch.branchPoints [branch.branchPoints.Count - 3].point - branch.branchPoints [branch.branchPoints.Count - 2].point;

                    //BranchPoint branchPoint01 = branch.branchPoints[branch.branchPoints.Count - 2];
                    branch.InsertBranchPoint(branch.branchPoints[branch.branchPoints.Count - 2].point + preLast / 2f,
                                             branch.branchPoints[branch.branchPoints.Count - 2].grabVector,
                                             branch.branchPoints.Count - 2);

                    //branch.grabVectors.Insert(branch.grabVectors.Count - 2, ,branch.grabVectors[branch.grabVectors.Count-2]);

                    branch.InsertBranchPoint(branch.branchPoints[branch.branchPoints.Count - 2].point + last / 2f,
                                             branch.branchPoints[branch.branchPoints.Count - 2].grabVector,
                                             branch.branchPoints.Count - 1);

                    //branch.grabVectors.Insert(branch.grabVectors.Count - 1, branch.grabVectors[branch.grabVectors.Count-2]);


                    branch.RemoveBranchPoint(branch.branchPoints.Count - 3);
                    //branch.grabVectors.RemoveAt (branch.branchPoints.Count - 3);
                }
            }
        }
 public void Optimize()
 {
     for (int b = 0; b < infoPool.ivyContainer.branches.Count; b++)
     {
         BranchContainer branch = infoPool.ivyContainer.branches[b];
         for (int p = 1; p < branch.branchPoints.Count - 1; p++)
         {
             Vector3 segment1 = branch.branchPoints[p].point - branch.branchPoints[p - 1].point;
             Vector3 segment2 = branch.branchPoints[p + 1].point - branch.branchPoints[p].point;
             if (Vector3.Angle(segment1, segment2) < infoPool.ivyParameters.optAngleBias)
             {
                 SaveIvy();
                 branch.RemoveBranchPoint(p);
                 RefreshMesh();
             }
         }
     }
 }