Exemple #1
0
        void GenerateVertices()
        {
            var             meshDimension   = MeshDimension;
            CartesianBounds cartesianBounds = GeographicBounds.TransformedWith(Database.Projection);
            double          spacingX        = (cartesianBounds.MaximumCoordinates.X - cartesianBounds.MinimumCoordinates.X) / RasterDimension;
            double          spacingY        = (cartesianBounds.MaximumCoordinates.Y - cartesianBounds.MinimumCoordinates.Y) / RasterDimension;
            double          originX         = cartesianBounds.MinimumCoordinates.X;
            double          originY         = cartesianBounds.MinimumCoordinates.Y;

            vertices = new Vector3[meshDimension * meshDimension];
            int vertexIndex = 0;

            for (int row = 0; row < meshDimension; ++row)
            {
                for (int column = 0; column < meshDimension; ++column, ++vertexIndex)
                {
                    ref Vector3 vertex = ref vertices[vertexIndex];
                    vertex.x = (float)(originX + (column * spacingX));
                    vertex.y = 0f;
                    vertex.z = (float)(originY + (row * spacingY));
                }
            }
Exemple #2
0
        void UpdateDistance()
        {
            bool hasGrandchildren = CheckForGrandchildren();

            if (hasGrandchildren)
            {
                return;
            }

            var   cartesianBounds = GeographicBounds.TransformedWith(Database.Projection);
            float min_x           = (float)cartesianBounds.MinimumCoordinates.X;
            float max_x           = (float)cartesianBounds.MaximumCoordinates.X;
            float min_z           = (float)cartesianBounds.MinimumCoordinates.Y;
            float max_z           = (float)cartesianBounds.MaximumCoordinates.Y;
            float cam_x           = Database.lastCameraPosition.x;
            float cam_z           = Database.lastCameraPosition.z;
            float post_x          = Math.Max(Math.Min(cam_x, max_x), min_x);
            float post_z          = Math.Max(Math.Min(cam_z, max_z), min_z);
            float spacing_x       = (max_x - min_x) / MeshDimension;
            float spacing_z       = (max_z - min_z) / MeshDimension;
            int   post_col        = (int)Math.Floor((post_x - min_x) / spacing_x);
            int   post_row        = (int)Math.Floor((post_z - min_z) / spacing_z);

            post_col = Math.Min(post_col, MeshDimension - 1);
            post_row = Math.Min(post_row, MeshDimension - 1);
            int post_index = (post_row * MeshDimension) + post_col;

            cameraDistance = Vector3.Distance(Database.lastCameraPosition, vertices[post_index]);
            cameraDistance = Math.Min(cameraDistance, Vector3.Distance(Database.lastCameraPosition, vertices[0]));
            cameraDistance = Math.Min(cameraDistance, Vector3.Distance(Database.lastCameraPosition, vertices[MeshDimension - 1]));
            cameraDistance = Math.Min(cameraDistance, Vector3.Distance(Database.lastCameraPosition, vertices[vertices.Length - MeshDimension]));
            cameraDistance = Math.Min(cameraDistance, Vector3.Distance(Database.lastCameraPosition, vertices[vertices.Length - 1]));

            /*
             * try
             * {
             *  cameraDistance = Database.DistanceForBounds(GeographicBounds);
             * }
             * catch (Exception e)
             * {
             *  Debug.LogException(e);
             * }
             */

            var lodSwitch           = Database.LODSwitchByObject[Database];
            var divideDistance      = lodSwitch.EntryDistanceForLOD(CDBTile.LOD - Database.PerformanceOffsetLOD);
            var consolidateDistance = lodSwitch.ExitDistanceForLOD(CDBTile.LOD - Database.PerformanceOffsetLOD);

            if (children.Count > 0)
            {
                if (!hasGrandchildren)
                {
                    if (cameraDistance > consolidateDistance)
                    {
                        Consolidate();
                    }
                }
            }
            else
            {
                bool divide = true;
                if (!meshRenderer.enabled)
                {
                    divide = false;
                }
                if (cameraDistance > divideDistance)
                {
                    divide = false;
                }
                if (Database.SystemMemoryLimitExceeded)
                {
                    divide = false;
                }
                if (!HasImagery)
                {
                    divide = false;
                }
                if (!HasElevation)
                {
                    divide = false;
                }
                if (ParentImagery)
                {
                    divide = false;
                }
                if (divide)
                {
                    Divide();
                }
            }
        }