/// <summary> /// Add a tree instance into storage - must be called after the initial load call /// </summary> /// <param name="position"></param> /// <param name="prototypeIdx"></param> public void AddTree(Vector3 position, int prototypeIdx) { if (m_terrainTreeLocations == null) { return; } m_terrainTreeLocations.Insert(position.x, position.z, prototypeIdx); }
/// <summary> /// Load the probes in from the scene /// </summary> private static void LoadProbesFromScene() { //Start time //DateTime startTime = DateTime.Now; //Destroy previous contents m_probeLocations = null; //Work out the bounds of the environment float minY = float.NaN; float minX = float.NaN; float maxX = float.NaN; float minZ = float.NaN; float maxZ = float.NaN; Terrain sampleTerrain = null; foreach (Terrain terrain in Terrain.activeTerrains) { if (float.IsNaN(minY)) { sampleTerrain = terrain; minY = terrain.transform.position.y; minX = terrain.transform.position.x; minZ = terrain.transform.position.z; maxX = minX + terrain.terrainData.size.x; maxZ = minZ + terrain.terrainData.size.z; } else { if (terrain.transform.position.x < minX) { minX = terrain.transform.position.x; } if (terrain.transform.position.z < minZ) { minZ = terrain.transform.position.z; } if ((terrain.transform.position.x + terrain.terrainData.size.x) > maxX) { maxX = terrain.transform.position.x + terrain.terrainData.size.x; } if ((terrain.transform.position.z + terrain.terrainData.size.z) > maxZ) { maxZ = terrain.transform.position.z + terrain.terrainData.size.z; } } } if (sampleTerrain != null) { Rect terrainBounds = new Rect(minX, minZ, maxX - minX, maxZ - minZ); m_probeLocations = new Quadtree <LightProbeGroup>(terrainBounds); } else { Rect bigSpace = new Rect(-10000f, -10000f, 20000f, 20000f); m_probeLocations = new Quadtree <LightProbeGroup>(bigSpace); } //Now grab all the light probes in the scene LightProbeGroup probeGroup; LightProbeGroup[] probeGroups = UnityEngine.Object.FindObjectsOfType <LightProbeGroup>(); for (int probeGroupIdx = 0; probeGroupIdx < probeGroups.Length; probeGroupIdx++) { probeGroup = probeGroups[probeGroupIdx]; for (int probePosition = 0; probePosition < probeGroup.probePositions.Length; probePosition++) { m_probeLocations.Insert(probeGroup.transform.position.x + probeGroup.probePositions[probePosition].x, probeGroup.transform.position.z + probeGroup.probePositions[probePosition].z, probeGroup); } } }
#pragma warning restore 414 /// <summary> /// Load the trees in from the terrain /// </summary> public void LoadTreesFromTerrain() { //Destroy previous contents m_terrainTrees = null; m_terrainTreeLocations = null; //Work out the bounds of the environment float minY = float.NaN; float minX = float.NaN; float maxX = float.NaN; float minZ = float.NaN; float maxZ = float.NaN; Terrain sampleTerrain = null; foreach (Terrain terrain in Terrain.activeTerrains) { if (float.IsNaN(minY)) { sampleTerrain = terrain; minY = terrain.transform.position.y; minX = terrain.transform.position.x; minZ = terrain.transform.position.z; maxX = minX + terrain.terrainData.size.x; maxZ = minZ + terrain.terrainData.size.z; } else { if (terrain.transform.position.x < minX) { minX = terrain.transform.position.x; } if (terrain.transform.position.z < minZ) { minZ = terrain.transform.position.z; } if ((terrain.transform.position.x + terrain.terrainData.size.x) > maxX) { maxX = terrain.transform.position.x + terrain.terrainData.size.x; } if ((terrain.transform.position.z + terrain.terrainData.size.z) > maxZ) { maxZ = terrain.transform.position.z + terrain.terrainData.size.z; } } } if (sampleTerrain != null) { Rect terrainBounds = new Rect(minX, minZ, maxX - minX, maxZ - minZ); m_terrainTreeLocations = new Quadtree <int>(terrainBounds, 32); m_terrainTrees = new List <TreePrototype>(sampleTerrain.terrainData.treePrototypes); foreach (Terrain terrain in Terrain.activeTerrains) { float terrainOffsetX = terrain.transform.position.x; float terrainOffsetZ = terrain.transform.position.z; float terrainWidth = terrain.terrainData.size.x; float terrainDepth = terrain.terrainData.size.z; TreeInstance[] terrainTreeInstances = terrain.terrainData.treeInstances; for (int treeIdx = 0; treeIdx < terrainTreeInstances.Length; treeIdx++) { TreeInstance treeInstance = terrainTreeInstances[treeIdx]; m_terrainTreeLocations.Insert(terrainOffsetX + (treeInstance.position.x * terrainWidth), terrainOffsetZ + (treeInstance.position.z * terrainDepth), terrainTreeInstances[treeIdx].prototypeIndex); } } } }