public AddTreeInstance ( |
||
instance | ||
return | void |
public static void PlaceTrees(Terrain terrain, float xBase, float yBase) { if (terrain.terrainData.treePrototypes.Length == 0) { return; } TreePainter.selectedTree = Mathf.Min(TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData) - 1, TreePainter.selectedTree); if (!TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, TreePainter.selectedTree)) { return; } int num = 0; TreeInstance instance = default(TreeInstance); instance.position = new Vector3(xBase, 0f, yBase); instance.color = TreePainter.GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = TreePainter.selectedTree; instance.heightScale = TreePainter.GetTreeHeight(); instance.widthScale = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale); instance.rotation = TreePainter.GetTreeRotation(); bool flag = Event.current.type == EventType.MouseDrag || TreePainter.brushSize > 1f; if (!flag || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, TreePainter.spacing)) { terrain.AddTreeInstance(instance); num++; } Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, TreePainter.selectedTree); prototypeExtent.y = 0f; float num2 = TreePainter.brushSize / (prototypeExtent.magnitude * TreePainter.spacing * 0.5f); int num3 = (int)(num2 * num2 * 0.5f); num3 = Mathf.Clamp(num3, 0, 100); int num4 = 1; while (num4 < num3 && num < num3) { Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle; insideUnitCircle.x *= TreePainter.brushSize / terrain.terrainData.size.x; insideUnitCircle.y *= TreePainter.brushSize / terrain.terrainData.size.z; Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y); if (position.x >= 0f && position.x <= 1f && position.z >= 0f && position.z <= 1f && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, TreePainter.selectedTree, TreePainter.spacing * 0.5f)) { instance = default(TreeInstance); instance.position = position; instance.color = TreePainter.GetTreeColor(); instance.lightmapColor = Color.white; instance.prototypeIndex = TreePainter.selectedTree; instance.heightScale = TreePainter.GetTreeHeight(); instance.widthScale = ((!TreePainter.lockWidthToHeight) ? TreePainter.GetTreeWidth() : instance.heightScale); instance.rotation = TreePainter.GetTreeRotation(); terrain.AddTreeInstance(instance); num++; } num4++; } }
public static void PlaceTrees(Terrain terrain, float xBase, float yBase) { int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData); if (TreePainter.selectedTree == -1 || TreePainter.selectedTree >= prototypeCount || !TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, TreePainter.selectedTree)) return; int num1 = 0; TreeInstance instance = new TreeInstance(); instance.position = new Vector3(xBase, 0.0f, yBase); instance.color = (Color32) TreePainter.GetTreeColor(); instance.lightmapColor = (Color32) Color.white; instance.prototypeIndex = TreePainter.selectedTree; instance.heightScale = TreePainter.GetTreeHeight(); instance.widthScale = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : instance.heightScale; instance.rotation = TreePainter.GetTreeRotation(); if (Event.current.type != EventType.MouseDrag && (double) TreePainter.brushSize <= 1.0 || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, TreePainter.spacing)) { terrain.AddTreeInstance(instance); ++num1; } Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, TreePainter.selectedTree); prototypeExtent.y = 0.0f; float num2 = TreePainter.brushSize / (float) ((double) prototypeExtent.magnitude * (double) TreePainter.spacing * 0.5); int num3 = Mathf.Clamp((int) ((double) num2 * (double) num2 * 0.5), 0, 100); for (int index = 1; index < num3 && num1 < num3; ++index) { Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle; insideUnitCircle.x *= TreePainter.brushSize / terrain.terrainData.size.x; insideUnitCircle.y *= TreePainter.brushSize / terrain.terrainData.size.z; Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0.0f, yBase + insideUnitCircle.y); if ((double) position.x >= 0.0 && (double) position.x <= 1.0 && ((double) position.z >= 0.0 && (double) position.z <= 1.0) && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, TreePainter.selectedTree, TreePainter.spacing * 0.5f)) { instance = new TreeInstance(); instance.position = position; instance.color = (Color32) TreePainter.GetTreeColor(); instance.lightmapColor = (Color32) Color.white; instance.prototypeIndex = TreePainter.selectedTree; instance.heightScale = TreePainter.GetTreeHeight(); instance.widthScale = !TreePainter.lockWidthToHeight ? TreePainter.GetTreeWidth() : instance.heightScale; instance.rotation = TreePainter.GetTreeRotation(); terrain.AddTreeInstance(instance); ++num1; } } }
void FillTreeInstances(Terrain terrain, int tileX, int tileZ) { Random.seed = 0; for(int x = 0; x < m_terrainSize; x += m_treeSpacing) { for (int z = 0; z < m_terrainSize; z += m_treeSpacing) { float unit = 1.0f / (m_terrainSize - 1); float offsetX = Random.value * unit * m_treeSpacing; float offsetZ = Random.value * unit * m_treeSpacing; float normX = x * unit + offsetX; float normZ = z * unit + offsetZ; // Get the steepness value at the normalized coordinate. float angle = terrain.terrainData.GetSteepness(normX, normZ); // Steepness is given as an angle, 0..90 degrees. Divide // by 90 to get an alpha blending value in the range 0..1. float frac = angle / 90.0f; if(frac < 0.5f) //make sure tree are not on steep slopes { float worldPosX = x+tileX*(m_terrainSize-1); float worldPosZ = z+tileZ*(m_terrainSize-1); float noise = m_treeNoise.FractalNoise2D(worldPosX, worldPosZ, 3, m_treeFrq, 1.0f); float ht = terrain.terrainData.GetInterpolatedHeight(normX, normZ); if(noise > 0.0f && ht < m_terrainHeight*0.4f) { TreeInstance temp = new TreeInstance(); temp.position = new Vector3(normX,ht,normZ); temp.prototypeIndex = Random.Range(0, 3); temp.widthScale = 1; temp.heightScale = 1; temp.color = Color.white; temp.lightmapColor = Color.white; terrain.AddTreeInstance(temp); } } } } terrain.treeDistance = m_treeDistance; terrain.treeBillboardDistance = m_treeBillboardDistance; terrain.treeCrossFadeLength = m_treeCrossFadeLength; terrain.treeMaximumFullLODCount = m_treeMaximumFullLODCount; }
void SetTerrainTrees(Terrain terrain) { terrain.terrainData.treeInstances = new TreeInstance[0]; for (int x = 0; x < resolution; x++) { for (int y = 0; y < resolution; y+=20) { float height = terrain.terrainData.GetHeight(x, y); float steepness = terrain.terrainData.GetSteepness((float)x / (float)resolution, (float)(y) / (float)resolution); if (Random.value > (0.3f + (steepness / 30)) && height >= waterThreshold - 10) { TreeInstance instance = new TreeInstance(); instance.prototypeIndex = 0; instance.position = new Vector3((float)x / (float)resolution, 0, (float)(y + Random.Range(0,10)) / (float)resolution); instance.widthScale = 1.0f; instance.heightScale = 1.0f; instance.color = Color.white; instance.rotation = 0.0f; terrain.AddTreeInstance(instance); x += 20; } } } }
void TreeGenerator(Terrain terrain, int tileX, int tileZ) { Random.seed = 0; for (int x = 0; x < TamañoDelTerreno; x += EspaciadoMinimo) { for (int z = 0; z < TamañoDelTerreno; z += EspaciadoMinimo) { float unit = 1.0f / (TamañoDelTerreno - 1); float offsetX = Random.value * unit * EspaciadoMinimo; float offsetZ = Random.value * unit * EspaciadoMinimo; float normX = x * unit + offsetX; float normZ = z * unit + offsetZ; float inclinacion = terrain.terrainData.GetSteepness(normX, normZ); float angulo = inclinacion / 90.0f; if (angulo < 0.5f)//Que no estén a más de 50º { float PosX = x + tileX * (TamañoDelTerreno - 1); float PosZ = z + tileZ * (TamañoDelTerreno - 1); float ruido = ruidoarbol.FractalNoise2D(PosX, PosZ, 3, RuidoDeArboles, 1.0f); float altura = terrain.terrainData.GetInterpolatedHeight(normX, normZ); if (ruido > 0.0f && altura < AlturaMaxima * AlturaDeArboles) { TreeInstance arbolitos = new TreeInstance(); arbolitos.position = new Vector3(normX, altura, normZ); arbolitos.prototypeIndex = Random.Range(0, 3); arbolitos.widthScale = 1; arbolitos.heightScale = 1; arbolitos.color = Color.white; arbolitos.lightmapColor = Color.white; terrain.AddTreeInstance(arbolitos); } } } } terrain.treeDistance = dist_arboles; terrain.treeBillboardDistance = dist_bill_arboles; terrain.treeCrossFadeLength = trans_arboles; terrain.treeMaximumFullLODCount = max_arboles; }
void FillTreeInstancesBiomes(Terrain terrain){ Random.seed = 0; for(int x = 0; x < m_terrainSize; x ++) { for (int z = 0; z < m_terrainSize; z ++) { float ratio = (float)(m_heightMapSize-1)/m_terrainSize; Center.BiomeTypes biome = getCenter[(int)(x*ratio),(int)(z*ratio)].biome; //int space=0; int tree = 10; if ((int)biome == 4) {tree = 0;} if ((int)biome ==9) {tree = 1;} if ((int)biome == 10) { tree = 2;} if ((int)biome == 11 ){ tree =3; } if( (int) biome==13) { tree =4; } float unit = 1.0f / (m_terrainSize - 1); //float offsetX = Random.value * unit * m_treeSpacing; //float offsetZ = Random.value * unit * m_treeSpacing; float normX = x * unit;// + offsetX; float normZ = z * unit;// + offsetZ; // Get the steepness value at the normalized coordinate. float angle = terrain.terrainData.GetSteepness(normX, normZ); // Steepness is given as an angle, 0..90 degrees. Divide // by 90 to get an alpha blending value in the range 0..1. float frac = angle / 90.0f; float height = htmap[z*m_heightMapSize/m_terrainSize,x*m_heightMapSize/m_terrainSize]; float fracHeight = (height-heightMinimum)/(heightMaximum-heightMinimum); if (tree<10) { if(frac < 0.5f && fracHeight> waterLimit+0.005f && Random.Range(0,m_treeSpacing[tree]) == 0) //make sure tree are not on steep slopes & in the sea { float worldPosX = x+(m_terrainSize-1); float worldPosZ = z+(m_terrainSize-1); float noise = m_treeNoise.FractalNoise2D(worldPosX, worldPosZ, 3, m_treeFrq, 1.0f); float ht = terrain.terrainData.GetInterpolatedHeight(normX, normZ); if( noise > 0 && ht < m_terrainHeight*0.4f ) { RaycastHit hit; Physics.Raycast(new Vector3(normX * m_terrainSize, 10000.0f, normZ*m_terrainSize), -Vector3.up, out hit); if ( ! hit.transform.gameObject.CompareTag("ground")){ //Debug.Log("yeeeey"); //Debug.Log(hit.transform.gameObject.name); continue; } TreeInstance temp = new TreeInstance(); temp.position = new Vector3(normX,ht,normZ); temp.prototypeIndex = tree; temp.widthScale = 1; temp.heightScale = 1; temp.color = Color.white; temp.lightmapColor = Color.white; // if (tree==0) // Debug.DrawLine(new Vector3(x,0f,z), new Vector3(x,100f,z),Color.red,2600f); terrain.AddTreeInstance(temp); } } } } } terrain.treeBillboardDistance = m_treeBillboardDistance; terrain.treeCrossFadeLength = m_treeCrossFadeLength; terrain.treeMaximumFullLODCount = m_treeMaximumFullLODCount; }
public static void PlaceTrees(Terrain terrain, float xBase, float yBase) { int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData); if (((selectedTree != -1) && (selectedTree < prototypeCount)) && TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, selectedTree)) { TreeInstance instance; int num2 = 0; instance = new TreeInstance { position = new Vector3(xBase, 0f, yBase), color = GetTreeColor(), lightmapColor = Color.white, prototypeIndex = selectedTree, heightScale = GetTreeHeight(), widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale, rotation = GetTreeRotation() }; if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing)) { terrain.AddTreeInstance(instance); num2++; } Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, selectedTree); prototypeExtent.y = 0f; float num3 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f); int num4 = (int) ((num3 * num3) * 0.5f); num4 = Mathf.Clamp(num4, 0, 100); for (int i = 1; (i < num4) && (num2 < num4); i++) { Vector2 insideUnitCircle = UnityEngine.Random.insideUnitCircle; insideUnitCircle.x *= brushSize / terrain.terrainData.size.x; insideUnitCircle.y *= brushSize / terrain.terrainData.size.z; Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y); if ((((position.x >= 0f) && (position.x <= 1f)) && ((position.z >= 0f) && (position.z <= 1f))) && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, selectedTree, spacing * 0.5f)) { instance = new TreeInstance { position = position, color = GetTreeColor(), lightmapColor = Color.white, prototypeIndex = selectedTree, heightScale = GetTreeHeight(), widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale, rotation = GetTreeRotation() }; terrain.AddTreeInstance(instance); num2++; } } } }