コード例 #1
0
ファイル: RTIvyGrowth.cs プロジェクト: AndreasGoettig/cmn6302
        //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) < ivyParameters.stepSize * 0.7f ||
         *                 Vector3.Distance(branch.branchPoints[branch.branchPoints.Count - 2].point, branch.branchPoints[branch.branchPoints.Count - 1].point) < 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);
         *
         *              }
         *      }
         * } */

        private RTBranchPoint GetNextFreeBranchPoint()
        {
            RTBranchPoint res = branchPointsPool[branchPointPoolIndex];

            branchPointPoolIndex++;

            if (branchPointPoolIndex >= branchPointsPool.Length)
            {
                System.Array.Resize(ref branchPointsPool, branchPointsPool.Length * 2);

                for (int i = branchPointPoolIndex; i < branchPointsPool.Length; i++)
                {
                    RTBranchPoint branchPoint = new RTBranchPoint();
                    branchPoint.PreInit(ivyParameters);
                    branchPointsPool[i] = branchPoint;
                }
            }

            return(res);
        }
コード例 #2
0
ファイル: RTIvyGrowth.cs プロジェクト: AndreasGoettig/cmn6302
        public void Init(RTIvyContainer ivyContainer, IvyParameters ivyParameters,
                         GameObject ivyGO, RTMeshData[] leavesMeshesByChosenLeaf,
                         int numPoints, int numLeaves, int maxNumVerticesPerLeaf)
        {
            this.rtIvyContainer           = ivyContainer;
            this.ivyParameters            = ivyParameters;
            this.ivyGO                    = ivyGO;
            this.leavesMeshesByChosenLeaf = leavesMeshesByChosenLeaf;
            this.numPoints                = numPoints;
            this.numLeaves                = numLeaves;
            this.maxNumVerticesPerLeaf    = maxNumVerticesPerLeaf;

            this.branchPointsPool     = new RTBranchPoint[numPoints];
            this.branchPointPoolIndex = 0;

            for (int i = 0; i < numPoints; i++)
            {
                RTBranchPoint branchPoint = new RTBranchPoint();
                branchPoint.PreInit(ivyParameters);
                branchPointsPool[i] = branchPoint;
            }

            this.leavesPool      = new RTLeafPoint[numLeaves];
            this.leavesPoolIndex = 0;
            for (int i = 0; i < numLeaves; i++)
            {
                RTLeafPoint leafPoint = new RTLeafPoint();
                leafPoint.PreInit(maxNumVerticesPerLeaf);
                leavesPool[i] = leafPoint;
            }

            this.branchesPool = new RTBranchContainer[ivyParameters.maxBranchs];
            for (int i = 0; i < ivyParameters.maxBranchs; i++)
            {
                this.branchesPool[i] = new RTBranchContainer(numPoints, numLeaves);
            }


            Random.InitState(System.Environment.TickCount);


            RTBranchContainer firstBranch = GetNextBranchContainer();



            ivyContainer.AddBranch(firstBranch);



            RTBranchPoint nextRTBranchPoint = GetNextFreeBranchPoint();

            nextRTBranchPoint.SetValues(ivyGO.transform.position, -ivyGO.transform.up, false, 0);
            firstBranch.AddBranchPoint(nextRTBranchPoint, ivyParameters.stepSize);

            CalculateVerticesLastPoint(firstBranch);
            //Vector3 axis = GetLoopAxis(nextRTBranchPoint, firstBranch, rtIvyContainer, ivyGO);
            //Vector3 firstVector = GetFirstVector(nextRTBranchPoint, firstBranch, rtIvyContainer, ivyParameters, axis);
            //nextRTBranchPoint.CalculateCenterLoop(ivyGO);
            //nextRTBranchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO, firstVector, axis);



            ivyContainer.branches[0].growDirection = Quaternion.AngleAxis(Random.value * 360f, ivyGO.transform.up) *
                                                     ivyGO.transform.forward;

            ivyContainer.firstVertexVector           = ivyContainer.branches[0].growDirection;
            ivyContainer.branches[0].randomizeHeight = Random.Range(4f, 8f);
            CalculateNewHeight(ivyContainer.branches[0]);
            ivyContainer.branches[0].branchSense = ChooseBranchSense();
            randomstate = Random.state;
        }
コード例 #3
0
        public RTBranchContainer(BranchContainer branchContainer, IvyParameters ivyParameters, RTIvyContainer rtIvyContainer,
                                 GameObject ivyGO, RTMeshData[] leavesMeshesByChosenLeaf)
        {
            this.totalLength             = branchContainer.totalLenght;
            this.growDirection           = branchContainer.growDirection;
            this.randomizeHeight         = branchContainer.randomizeHeight;
            this.heightVar               = branchContainer.heightVar;
            this.newHeight               = branchContainer.newHeight;
            this.heightParameter         = branchContainer.heightParameter;
            this.deltaHeight             = branchContainer.deltaHeight;
            this.currentHeight           = branchContainer.currentHeight;
            this.branchSense             = branchContainer.branchSense;
            this.falling                 = branchContainer.falling;
            this.rotationOnFallIteration = branchContainer.rotationOnFallIteration;
            this.branchNumber            = branchContainer.branchNumber;



            this.branchPoints = new List <RTBranchPoint>(branchContainer.branchPoints.Count);
            for (int i = 0; i < branchContainer.branchPoints.Count; i++)
            {
                RTBranchPoint rtBranchPoint = new RTBranchPoint(branchContainer.branchPoints[i], this);

                rtBranchPoint.CalculateCenterLoop(ivyGO);
                rtBranchPoint.PreInit(ivyParameters);
                rtBranchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO);

                this.branchPoints.Add(rtBranchPoint);
            }


            branchContainer.PrepareRTLeavesDict();


            if (ivyParameters.generateLeaves)
            {
                this.leavesOrderedByInitSegment = new RTLeafPoint[branchPoints.Count][];
                for (int i = 0; i < branchPoints.Count; i++)
                {
                    List <LeafPoint> leavesToBake = branchContainer.dictRTLeavesByInitSegment[i];
                    int numLeaves = 0;
                    if (leavesToBake != null)
                    {
                        numLeaves = leavesToBake.Count;
                    }


                    this.leavesOrderedByInitSegment[i] = new RTLeafPoint[numLeaves];


                    for (int j = 0; j < numLeaves; j++)
                    {
                        RTLeafPoint rtLeafPoint  = new RTLeafPoint(leavesToBake[j], ivyParameters);
                        RTMeshData  leafMeshData = leavesMeshesByChosenLeaf[rtLeafPoint.chosenLeave];

                        rtLeafPoint.CreateVertices(ivyParameters, leafMeshData, ivyGO);
                        this.leavesOrderedByInitSegment[i][j] = rtLeafPoint;
                    }
                }
            }
        }