protected virtual void AddNextBranch(int branchNumber) { lastIdxActiveBranch++; RTBranchContainer newBuildingBranch = activeBuildingBranches[lastIdxActiveBranch]; RTBranchContainer bakedBranch = rtIvyContainer.GetBranchContainerByBranchNumber(branchNumber); newBuildingBranch.AddBranchPoint(bakedBranch.branchPoints[0], ivyParameters.stepSize); newBuildingBranch.AddBranchPoint(bakedBranch.branchPoints[1], ivyParameters.stepSize); newBuildingBranch.leavesOrderedByInitSegment = bakedBranch.leavesOrderedByInitSegment; rtBuildingIvyContainer.AddBranch(newBuildingBranch); activeBakedBranches.Add(bakedBranch); activeBuildingBranches.Add(newBuildingBranch); meshBuilder.activeBranches.Add(newBuildingBranch); UpdateGrowingPoints(rtBuildingIvyContainer.branches.Count - 1); RTBranchPoint lastBranchPoint = newBuildingBranch.GetLastBranchPoint(); if (lastBranchPoint.newBranch) { AddNextBranch(lastBranchPoint.newBranchNumber); } }
//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); } }
protected virtual void NextPoints(int branchIndex) { if (rtBuildingIvyContainer.branches[branchIndex].branchPoints.Count > 0) { RTBranchPoint lastBuildingBranchPoint = rtBuildingIvyContainer.branches[branchIndex].GetLastBranchPoint(); if (lastBuildingBranchPoint.index < activeBakedBranches[branchIndex].branchPoints.Count - 1) { int indexBranchPoint = lastBuildingBranchPoint.index; indexBranchPoint++; RTBranchPoint branchPoint = activeBakedBranches[branchIndex].branchPoints[indexBranchPoint]; RTBranchContainer branch = rtBuildingIvyContainer.branches[branchIndex]; branch.AddBranchPoint(branchPoint, ivyParameters.stepSize); if (branchPoint.newBranch) { RTBranchContainer candidateBranch = rtIvyContainer.GetBranchContainerByBranchNumber(branchPoint.newBranchNumber); if (candidateBranch.branchPoints.Count >= 2) { AddNextBranch(branchPoint.newBranchNumber); } } UpdateGrowingPoints(branchIndex); if (rtBuildingIvyContainer.branches[branchIndex].branchPoints.Count > backtrackingPoints) { if (!IsVertexLimitReached()) { meshBuilder.CheckCopyMesh(branchIndex, activeBakedBranches); refreshProcessedMesh = true; } else { Debug.LogWarning("Limit vertices reached! --> " + Constants.VERTEX_LIMIT_16 + " vertices", meshBuilder.ivyGO); } } } } }
//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); }
//Añadimos punto y todo lo que ello conlleva. Es ligeramente diferente a AddPoint. Está la posibilidad de spawnear una rama void AddFallingPoint(RTBranchContainer branch) { Vector3 grabVector = branch.rotationOnFallIteration * branch.GetLastBranchPoint().grabVector; RTBranchPoint branchPoint = GetNextFreeBranchPoint(); branchPoint.point = branch.branchPoints[branch.branchPoints.Count - 1].point + branch.growDirection * ivyParameters.stepSize; branchPoint.grabVector = grabVector; 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, -branch.GetLastBranchPoint().grabVector); } if (ivyParameters.generateLeaves) { AddLeave(branch); } }
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; }