Exemple #1
0
        internal void SetHeightData(byte[] data, float heightMultiplier = 1f, bool useRelative = false)
        {
            // HACK: compute height values for terrain. We could probably do this without a texture2d.
            if (_heightTexture == null)
            {
                _heightTexture = new Texture2D(0, 0);
            }

            _heightTexture.LoadImage(data);
            byte[] rgbData = _heightTexture.GetRawTextureData();

            // Get rid of this temporary texture. We don't need to bloat memory.
            _heightTexture.LoadImage(null);

            if (_heightData == null)
            {
                _heightData = new float[256 * 256];
            }

            var relativeScale = useRelative ? _relativeScale : 1f;

            for (int xx = 0; xx < 256; ++xx)
            {
                for (int yy = 0; yy < 256; ++yy)
                {
                    float r = rgbData[(xx * 256 + yy) * 4 + 1];
                    float g = rgbData[(xx * 256 + yy) * 4 + 2];
                    float b = rgbData[(xx * 256 + yy) * 4 + 3];
                    _heightData[xx * 256 + yy] = relativeScale * heightMultiplier * Conversions.GetAbsoluteHeightFromColor(r, g, b);
                }
            }

            HeightDataState = TilePropertyState.Loaded;
            OnHeightDataChanged(this);
        }
Exemple #2
0
        internal void Recycle()
        {
            // TODO: to hide potential visual artifacts, use placeholder mesh / texture?

            gameObject.SetActive(false);

            // Reset internal state.
            RasterDataState = TilePropertyState.None;
            HeightDataState = TilePropertyState.None;
            VectorDataState = TilePropertyState.None;

            OnHeightDataChanged = delegate { };
            OnRasterDataChanged = delegate { };
            OnVectorDataChanged = delegate { };

            Cancel();
            _tiles.Clear();

            // HACK: this is for vector layer features and such.
            // It's slow and wasteful, but a better solution will be difficult.
            var childCount = transform.childCount;

            if (childCount > 0)
            {
                for (int i = 0; i < childCount; i++)
                {
                    Destroy(transform.GetChild(i).gameObject);
                }
            }
        }
Exemple #3
0
        internal void Recycle()
        {
            if (_loadingTexture)
            {
                MeshRenderer.material.mainTexture = _loadingTexture;
            }

            gameObject.SetActive(false);

            // Reset internal state.
            RasterDataState = TilePropertyState.None;
            HeightDataState = TilePropertyState.None;
            VectorDataState = TilePropertyState.None;

            OnHeightDataChanged = delegate { };
            OnRasterDataChanged = delegate { };
            OnVectorDataChanged = delegate { };

            Cancel();
            _tiles.Clear();

            // HACK: this is for vector layer features and such.
            // It's slow and wasteful, but a better solution will be difficult.
            var childCount = transform.childCount;

            if (childCount > 0)
            {
                for (int i = 0; i < childCount; i++)
                {
                    Destroy(transform.GetChild(i).gameObject);
                }
            }
        }
Exemple #4
0
        public void SetRasterData(byte[] data, bool useMipMap, bool useCompression)
        {
            // Don't leak the texture, just reuse it.
            if (_rasterData == null)
            {
                _rasterData          = new Texture2D(0, 0, TextureFormat.RGB24, useMipMap);
                _rasterData.wrapMode = TextureWrapMode.Clamp;
            }

            _rasterData.LoadImage(data);
            if (useCompression)
            {
                // High quality = true seems to decrease image quality?
                _rasterData.Compress(false);
            }

            MeshRenderer.material.mainTexture = _rasterData;
            RasterDataState = TilePropertyState.Loaded;
            OnRasterDataChanged(this);
        }
Exemple #5
0
        internal void Recycle()
        {
            if (_loadingTexture && MeshRenderer != null)
            {
                MeshRenderer.material.mainTexture = _loadingTexture;
            }

            gameObject.SetActive(false);

            // Reset internal state.
            RasterDataState = TilePropertyState.None;
            HeightDataState = TilePropertyState.None;
            VectorDataState = TilePropertyState.None;

            OnHeightDataChanged = delegate { };
            OnRasterDataChanged = delegate { };
            OnVectorDataChanged = delegate { };

            Cancel();
            _tiles.Clear();
        }
Exemple #6
0
        internal void Recycle()
        {
            if (_loadingTexture && MeshRenderer != null && MeshRenderer.sharedMaterial != null)
            {
                MeshRenderer.sharedMaterial.SetTexture("_BaseMap", _loadingTexture);
            }

            gameObject.SetActive(false);
            IsRecycled = true;

            // Reset internal state.
            RasterDataState = TilePropertyState.Unregistered;
            HeightDataState = TilePropertyState.Unregistered;
            VectorDataState = TilePropertyState.Unregistered;
            TileState       = TilePropertyState.Unregistered;

            OnHeightDataChanged = delegate { };
            OnRasterDataChanged = delegate { };
            OnVectorDataChanged = delegate { };

            Cancel();
            _tiles.Clear();
        }