private void GenerateBillboardCell(BillboardCell billboardCell) { Vector3 terrainPosition = VegetationSystem.UnityTerrainData.terrainPosition; List <VegetationCell> intercectingVegetationCellList = VegetationSystem.VegetationCellQuadTree.Query(billboardCell.Rectangle); //VegetationSystem.SpawnCells(3, intercectingVegetationCellList); billboardCell.MaterialList = _vegetationItemBillboardMaterialList; billboardCell.AddVegetationCells(intercectingVegetationCellList, terrainPosition); billboardCell.GenerateBillboardMeshes(terrainPosition); }
public void SetupBillboardCells() { if (!VegetationSystem) { return; } if (VegetationSystem.UnityTerrainData == null) { return; } Random.InitState(VegetationSystem.vegetationSettings.RandomSeed); ClearBillboardCells(); BillboardCellQuadTree = new QuadTree <BillboardCell>(VegetationSystem.UnityTerrainData.GetTerrainRect(CellSize)); int cellXCount = Mathf.CeilToInt(VegetationSystem.UnityTerrainData.size.x / CellSize); int cellZCount = Mathf.CeilToInt(VegetationSystem.UnityTerrainData.size.z / CellSize); float worldSpaceMaxTreeHeight = GetWorldSpaceMaxTreeHeight(); float worldSpaceMinTreeHeight = GetWorldSpaceMinTreeHeight(); float yExtent = (worldSpaceMaxTreeHeight + worldSpaceMinTreeHeight) / 2f; for (int x = 0; x <= cellXCount - 1; x++) { for (int z = 0; z <= cellZCount - 1; z++) { BillboardCell billboardCell = new BillboardCell { CellCorner = new Vector3( VegetationSystem.UnityTerrainData.terrainPosition.x + CellSize * x, VegetationSystem.UnityTerrainData.terrainPosition.y, VegetationSystem.UnityTerrainData.terrainPosition.z + CellSize * z), CellSize = new Vector3(CellSize, yExtent * 2, CellSize), VegetationCellSize = VegetationSystem.CellSize, CurrentvegetationPackage = VegetationSystem.CurrentVegetationPackage, }; billboardCell.Init(); BillboardCellList.Add(billboardCell); BillboardCellQuadTree.Insert(billboardCell); } } }