private void RemoveDuplicateModels(QuadTreeNode node) { var GameObjectsToDestroy = new List <GameObject>(); var AncestorNodes = DataByNode.Keys.ToList(); AncestorNodes.RemoveAll(n => DataByNode[n].Features.Count == 0); AncestorNodes.RemoveAll(n => n.Depth >= node.Depth); AncestorNodes = GetNodesWithOverlappingBounds(node, AncestorNodes); foreach (var AncestorNode in AncestorNodes) { foreach (var featurePosition in DataByNode[node].PositionByFeature) { var GameObjects = DataByNode[AncestorNode].GameObjects; foreach (GameObject go in GameObjects) { if (featurePosition.Value.x == go.transform.position.x && featurePosition.Value.z == go.transform.position.z) { var model = go.GetComponent <Model>(); DataByNode[AncestorNode].Features.Add(model.Feature); UnityEngine.Object.Destroy(model); GameObjectsToDestroy.Add(go); } } } for (int i = 0, c = GameObjectsToDestroy.Count; i < c; ++i) { DataByNode[AncestorNode].GameObjects.Remove(GameObjectsToDestroy[i]); //DataByNode[AncestorNode].LoadingGameObjects.Remove(GameObjectsToDestroy[i]); LoadingGameObjects.Remove(GameObjectsToDestroy[i]); UnityEngine.Object.Destroy(GameObjectsToDestroy[i]); } GameObjectsToDestroy.Clear(); } }
private void ApplyElevation(QuadTreeNode tile) { var data = DataByTile[tile]; TileMatrix tileMatrix = ElevationTileMatrixSet[tile.Depth]; long zoomLevel = tile.Depth; long matrixRow = (long)Mathf.Floor((float)(tile.GeographicBounds.MinimumCoordinates.Latitude - Elevation.MinY) / tileMatrix.TilesHigh); long matrixColumn = (long)Mathf.Floor((float)(tile.GeographicBounds.MinimumCoordinates.Longitude - Elevation.MinX) / tileMatrix.TilesWide); var elevation = Elevation.Tile(zoomLevel, matrixRow, matrixColumn); //File.WriteAllBytes("D:/elevtest.dat", elevation.Bytes); int meshDimension = (int)tileMatrix.TileWidth; var array = TiffToFloatArray(elevation.Bytes, meshDimension); int vertexIndex = 0; for (int row = 0; row < meshDimension; ++row) { for (int column = 0; column < meshDimension; ++column, ++vertexIndex) { data.vertices[vertexIndex].y = array[vertexIndex]; } } }
//////////////////////////////////////////////////////////////////////////////// public void QuadTreeDataLoad(QuadTreeNode node) // QuadTreeDelegate { var token = node.TaskLoadToken.Token; Task t = Task.Run(() => { TaskLoad(node); }, token); }
//////////////////////////////////////////////////////////////////////////////// public void QuadTreeDataUpdate(QuadTreeNode node) // QuadTreeDelegate { #if UNITY_EDITOR if (node.IsActive) { var sw = node.GeographicBounds.MinimumCoordinates; var ne = node.GeographicBounds.MaximumCoordinates; var se = new GeographicCoordinates(sw.Latitude, ne.Longitude); var nw = new GeographicCoordinates(ne.Latitude, sw.Longitude); var swc = sw.TransformedWith(Database.Projection); var sec = se.TransformedWith(Database.Projection); var nwc = nw.TransformedWith(Database.Projection); var nec = ne.TransformedWith(Database.Projection); var elev = 100.0f; var swv = new Vector3((float)swc.X, elev, (float)swc.Y); var sev = new Vector3((float)sec.X, elev, (float)sec.Y); var nwv = new Vector3((float)nwc.X, elev, (float)nwc.Y); var nev = new Vector3((float)nec.X, elev, (float)nec.Y); Debug.DrawLine(swv, sev); Debug.DrawLine(swv, nwv); Debug.DrawLine(nwv, nev); Debug.DrawLine(sev, nev); } #endif if (!node.IsActive) { return; } if (!node.IsLoaded) { return; } if (Database.SystemMemoryLimitExceeded) { return; } //if (HasLoadedDecendents(node)) // return; var maxdist = Database.LODSwitchByObject[this].MaxDistance * Database.Projection.Scale; GSFeatureDataNode featureData = null; if (!DataByNode.TryGetValue(node, out featureData)) { return; } for (int i = 0; i < 1; ++i) { if (featureData.Features.Count < 1) { return; } if (Time.frameCount % 10 != 0) { var tempList = new List <GameObject>(); foreach (var go in featureData.LoadingGameObjects) { if (!go.GetComponent <Model>().Loaded) { tempList.Add(go); } } featureData.LoadingGameObjects = tempList; } if (featureData.LoadingGameObjects.Count > 4) { return; } int index = featureData.Features.Count - 1; var feature = featureData.Features[index]; var dist2 = (featureData.PositionByFeature[feature] - featureData.CameraPosition).sqrMagnitude; if (dist2 > maxdist * maxdist) { return; } lock (featureData.Features) { featureData.Features.RemoveAt(index); } try { var modelGameObject = GenerateModel(node, feature); if (modelGameObject != null) { featureData.GameObjects.Add(modelGameObject); featureData.LoadingGameObjects.Add(modelGameObject); } } catch (Exception e) { Debug.LogException(e); } } }
public void QuadTreeDataUnload(QuadTreeNode tile) // QuadTreeDelegate { // TODO //tile.gameObject.GetComponent<MeshFilter>().mesh = null; }
public void QuadTreeDataLoad(QuadTreeNode tile) // QuadTreeDelegate { Task.Run(() => TaskLoad(tile)); }
public void QuadTreeDataUpdate(QuadTreeNode tile) // QuadTreeDelegate { // TODO: any update operations (regardless of state) }
private void GenerateMesh(QuadTreeNode tile) { var data = DataByTile[tile]; TileMatrix tileMatrix = ElevationTileMatrixSet[tile.Depth]; int MeshDimension = (int)tileMatrix.TileWidth; CartesianBounds cartesianBounds = tile.GeographicBounds.TransformedWith(Projection); double spacingX = (cartesianBounds.MaximumCoordinates.X - cartesianBounds.MinimumCoordinates.X) / tileMatrix.TileWidth; double spacingY = (cartesianBounds.MaximumCoordinates.Y - cartesianBounds.MinimumCoordinates.Y) / tileMatrix.TileHeight; double originX = cartesianBounds.MinimumCoordinates.X; double originY = cartesianBounds.MinimumCoordinates.Y; // vertices { data.vertices = new Vector3[MeshDimension * MeshDimension]; int vertexIndex = 0; for (int row = 0; row < MeshDimension; ++row) { for (int column = 0; column < MeshDimension; ++column, ++vertexIndex) { data.vertices[vertexIndex] = new Vector3((float)(originX + (column * spacingX)), 0.0f, (float)(originY + (row * spacingY))); } } } // triangles { data.triangles = new int[(MeshDimension - 1) * (MeshDimension - 1) * 6]; int triangleIndex = 0; for (int row = 0; row < (MeshDimension - 1); ++row) { for (int column = 0; column < (MeshDimension - 1); ++column, triangleIndex += 6) { int vertexIndex = (row * MeshDimension) + column; int lowerLeftIndex = vertexIndex; int lowerRightIndex = lowerLeftIndex + 1; int upperLeftIndex = lowerLeftIndex + MeshDimension; int upperRightIndex = upperLeftIndex + 1; data.triangles[triangleIndex + 0] = lowerLeftIndex; data.triangles[triangleIndex + 1] = upperLeftIndex; data.triangles[triangleIndex + 2] = upperRightIndex; data.triangles[triangleIndex + 3] = lowerLeftIndex; data.triangles[triangleIndex + 4] = upperRightIndex; data.triangles[triangleIndex + 5] = lowerRightIndex; } } } // uvs { data.uv = new Vector2[data.vertices.Length]; int vertexIndex = 0; for (int row = 0; row < MeshDimension; ++row) { for (int column = 0; column < MeshDimension; ++column, ++vertexIndex) { data.uv[vertexIndex] = new Vector2((float)column / (MeshDimension - 1), (float)row / (MeshDimension - 1)); } } } }