Пример #1
0
        private void TaskLoad(QuadTreeNode node)
        {
            try
            {
                var featureData = new GSFeatureDataNode();
                DataByNode[node]     = featureData;
                featureData.Features = ReadFeatures(node);

                foreach (var feature in featureData.Features)
                {
                    var     geographicCoordinates = new GeographicCoordinates(feature.Geometry.Centroid.Y, feature.Geometry.Centroid.X);
                    var     cartesianCoordinates  = geographicCoordinates.TransformedWith(Database.Projection);
                    float   elev     = Database.TerrainElevationAtLocation(geographicCoordinates);
                    Vector3 position = new Vector3((float)cartesianCoordinates.X, elev, (float)cartesianCoordinates.Y);
                    featureData.PositionByFeature[feature] = position;
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            node.IsLoaded  = true;
            node.IsLoading = false;
        }
Пример #2
0
        ////////////////////////////////////////////////////////////////////////////////

        public void QuadTreeDataUnload(QuadTreeNode node)       // QuadTreeDelegate
        {
            GSFeatureDataNode featureData = null;

            if (!DataByNode.TryGetValue(node, out featureData))
            {
                return;
            }
            foreach (var gameObj in featureData.GameObjects)
            {
                GameObject.Destroy(gameObj);
            }
            lock (featureData.Features)
            {
                featureData.Features.Clear();
            }
            featureData.CDBTileByFeature.Clear();
            featureData.GameObjects.Clear();
        }
Пример #3
0
        ////////////////////////////////////////////////////////////////////////////////

        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);
                }
            }
        }