/// <summary>
        /// Gets the grid square preview color based on which LOD
        /// level it falls within.
        /// </summary>
        /// <returns></returns>
        private Color GetLodPreviewColor(GridPosition position)
        {
            if (Generator == null || Generator.Lod == null)
            {
                return(Color.white);
            }

            Vector3 worldXYZ = Generator.TrackedObject == null ? Vector3.zero : Generator.TrackedObject.transform.position;

            LodData lod = Generator.Lod;

            LodData.Lod lvlType = lod.GetLevelForPosition(position, worldXYZ);

            return(lvlType.PreviewColor);
        }
예제 #2
0
        /// <summary>
        /// Creates a heightmap of resolution <see cref="HeightmapResolution"/> asynchronously.
        /// If a <see cref="Heightmap"/> of the same resolution or higher has already been
        /// created, this method does nothing.
        /// A heightmap is 2D array of floats that represents the Y values (or heights)
        /// of to-be created vertices in 3D space.
        /// </summary>
        /// <param name="remapMin">Optionally linear transform the heightmap from [min, max] to [0, 1]</param>
        /// <param name="remapMax">Optionally linear transform the heightmap from [min, max] to [0, 1]</param>
        /// <param name="onComplete">Called when the heightmap has been created</param>
        public void CalculateHeightmapAsync(float remapMin = 0f, float remapMax = 1f, Action onComplete = null)
        {
            _lastGeneratedLodLevel = _tile.GetLodLevel();
            Lod = _lastGeneratedLodLevel;
            bool shouldProfile = TerraConfig.Instance.EditorState.ShowDebugMessages;

            Stopwatch wsw = null;

            if (shouldProfile)
            {
                wsw = new Stopwatch();
                wsw.Start();
            }
            TerraConfig.Instance.Worker.Enqueue(() => {
                Stopwatch sw = null;
                if (shouldProfile)
                {
                    sw = new Stopwatch();
                    Profiler.BeginThreadProfiling("Heightmap Workers", "Tile " + _tile.GridPosition);
                    sw.Start();
                }
                CalculateHeightmap(null, remapMin, remapMax);

                if (shouldProfile)
                {
                    sw.Stop();
                    TerraConfig.Log("Tile " + _tile.GridPosition + " heightmap time: " + sw.ElapsedMilliseconds);
                    Profiler.EndThreadProfiling();
                }
            }, () => {
                if (shouldProfile)
                {
                    wsw.Stop();
                    MTDispatch.Instance().Enqueue(() => { TerraConfig.Log("CalculateHM worker time elapsed " + wsw.ElapsedMilliseconds); onComplete(); });
                }
            });
        }
예제 #3
0
 /// <summary>
 /// Constructs a new TileMesh instance
 /// </summary>
 /// <param name="tile">Tile to attach mesh to</param>
 /// <param name="lod">LOD level to reference when creating heightmap and Terrain</param>
 public TileMesh(Tile tile, LodData.Lod lod)
 {
     _tile = tile;
     Lod   = lod;
 }