private void DoExportGeometry()
        {
            DesData.heightmapResolution = SrcData.Geometry.HeightMapResolution + 1;
            int resolution = DesData.heightmapResolution;

            float[,] heightSample = new float[resolution, resolution];
            Vector2 uv  = Vector2.zero;
            Vector2 enc = Vector2.zero;
            float   h   = 0;

            for (int z = 0; z < resolution; ++z)
            {
                for (int x = 0; x < resolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, resolution - 1, x),
                        Mathf.InverseLerp(0, resolution - 1, z));
                    enc = (Vector4)SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    h   = GCommon.DecodeFloatRG(enc);
                    heightSample[z, x] = h;
                }
            }

            DesData.SetHeights(0, 0, heightSample);

            if (ExportTerrainSize)
            {
                DesData.size = new Vector3(SrcData.Geometry.Width, SrcData.Geometry.Height, SrcData.Geometry.Length);
            }
        }
Ejemplo n.º 2
0
        private void DoExportRaw8()
        {
            int rawResolution = SrcData.Geometry.HeightMapResolution + 1;

            byte[] data = new byte[rawResolution * rawResolution];

            Vector2 uv  = Vector2.zero;
            Color   c   = Color.white;
            Vector2 enc = Vector2.zero;
            byte    h   = 0;

            for (int z = 0; z < rawResolution; ++z)
            {
                for (int x = 0; x < rawResolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, rawResolution - 1, x),
                        1 - Mathf.InverseLerp(0, rawResolution - 1, z));
                    c = SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    enc.Set(c.r, c.g);
                    h = (byte)(GCommon.DecodeFloatRG(enc) * byte.MaxValue);
                    data[GUtilities.To1DIndex(x, z, rawResolution)] = h;
                }
            }

            GUtilities.EnsureDirectoryExists(DataDirectory);
            string fileName = string.Format("RAW8_{0}x{0}_{1}.raw", rawResolution, SrcData.Id);
            string path     = Path.Combine(DataDirectory, fileName);

            File.WriteAllBytes(path, data);
#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
Ejemplo n.º 3
0
        private void DoExportRaw16()
        {
            int rawResolution = SrcData.Geometry.HeightMapResolution + 1;

            byte[] data = new byte[rawResolution * rawResolution * sizeof(UInt16)];

            Vector2 uv         = Vector2.zero;
            Color   c          = Color.white;
            Vector2 enc        = Vector2.zero;
            UInt16  h          = 0;
            int     startIndex = 0;

            for (int z = 0; z < rawResolution; ++z)
            {
                for (int x = 0; x < rawResolution; ++x)
                {
                    uv.Set(
                        Mathf.InverseLerp(0, rawResolution - 1, x),
                        1 - Mathf.InverseLerp(0, rawResolution - 1, z));
                    c = SrcData.Geometry.HeightMap.GetPixelBilinear(uv.x, uv.y);
                    enc.Set(c.r, c.g);
                    h          = (UInt16)(GCommon.DecodeFloatRG(enc) * UInt16.MaxValue);
                    startIndex = 2 * GUtilities.To1DIndex(x, z, rawResolution);
                    Array.Copy(BitConverter.GetBytes(h), 0, data, startIndex, sizeof(UInt16));
                }
            }

            GUtilities.EnsureDirectoryExists(DataDirectory);
            string fileName = string.Format("RAW16_{0}x{0}_{1}.r16", rawResolution, SrcData.Id);
            string path     = Path.Combine(DataDirectory, fileName);

            File.WriteAllBytes(path, data);
#if UNITY_EDITOR
            AssetDatabase.Refresh();
#endif
        }
Ejemplo n.º 4
0
        private void DoExportHeightMap()
        {
            GUtilities.EnsureDirectoryExists(DataDirectory);
            Color[] colors = SrcData.Geometry.HeightMap.GetPixels();
            Vector2 enc    = Vector2.zero;
            float   h      = 0;

            for (int i = 0; i < colors.Length; ++i)
            {
                enc.Set(colors[i].r, colors[i].g);
                h         = GCommon.DecodeFloatRG(enc);
                colors[i] = new Color(h, 0, 0, 0);
            }
            Texture2D tex = new Texture2D(SrcData.Geometry.HeightMapResolution, SrcData.Geometry.HeightMapResolution, TextureFormat.RGBAFloat, false);

            tex.SetPixels(colors);
            tex.Apply();
            byte[] data = tex.EncodeToPNG();
            GUtilities.DestroyObject(tex);
            string fileName = string.Format("HeightMap_{0}x{0}_{1}.png", SrcData.Geometry.HeightMapResolution, SrcData.Id);
            string filePath = Path.Combine(DataDirectory, fileName);

            File.WriteAllBytes(filePath, data);
        }