//Añadimos punto y todo lo que ello conlleva. Está la posibilidad de spawnear una rama public void AddPoint(RTBranchContainer branch, Vector3 point, Vector3 normal) { branch.totalLength += ivyParameters.stepSize; RTBranchPoint branchPoint = GetNextFreeBranchPoint(); branchPoint.SetValues(point + normal * branch.currentHeight, -normal); branch.AddBranchPoint(branchPoint, ivyParameters.stepSize); CalculateVerticesLastPoint(branch); //Vector3 axis = GetLoopAxis(branchPoint, branch, rtIvyContainer, ivyGO); //Vector3 firstVector = GetFirstVector(branchPoint, branch, rtIvyContainer, ivyParameters, axis); //branchPoint.CalculateCenterLoop(ivyGO); //branchPoint.CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO, firstVector, axis); /*if(branch.branchPoints.Count >= 1) * { * branch.branchPoints[branch.branchPoints.Count - 2].CalculateVerticesLoop(ivyParameters, rtIvyContainer, ivyGO); * }*/ if (Random.value < ivyParameters.branchProvability && rtIvyContainer.branches.Count < ivyParameters.maxBranchs) { AddBranch(branch, branch.GetLastBranchPoint(), branch.branchPoints[branch.branchPoints.Count - 1].point, normal); } if (ivyParameters.generateLeaves) { AddLeave(branch); } }
//Todo lo necesario para añadir una rama public void AddBranch(RTBranchContainer branch, RTBranchPoint originBranchPoint, Vector3 point, Vector3 normal) { RTBranchContainer newBranchContainer = GetNextBranchContainer(); RTBranchPoint nextPoint = GetNextFreeBranchPoint(); nextPoint.SetValues(point, -normal); newBranchContainer.AddBranchPoint(nextPoint, ivyParameters.stepSize); newBranchContainer.growDirection = Vector3.Normalize(Vector3.ProjectOnPlane(branch.growDirection, normal)); newBranchContainer.randomizeHeight = Random.Range(4f, 8f); newBranchContainer.currentHeight = branch.currentHeight; newBranchContainer.heightParameter = branch.heightParameter; newBranchContainer.branchSense = ChooseBranchSense(); rtIvyContainer.AddBranch(newBranchContainer); originBranchPoint.InitBranchInThisPoint(newBranchContainer.branchNumber); }
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; }