Example #1
0
        private TerrainChunkMeshData GetInterpolatedDataLod(int lodLevel, int[] neighbors)
        {
            var lod    = Consts.LodsAmount - lodLevel - _maxDataLod;
            var amount = (HeigthData.GetLength(0) - 1) * ((int)Mathf.Pow(2, lod)) + 1;
            var matrix = Assistant.CreateVerticesMatrix(amount, Consts.UnitSize);

            for (int i = 0; i < HeigthData.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < HeigthData.GetLength(1) - 1; j++)
                {
                    var interpolatedData = GetInterpolatedData(new Int2(i + 1, j), (int)Mathf.Pow(2, lod) - 1);
                    for (int k = 0; k < interpolatedData.GetLength(0); k++)
                    {
                        for (int l = 0; l < interpolatedData.GetLength(1); l++)
                        {
                            matrix[i * (interpolatedData.GetLength(0) - 1) + k, j *(interpolatedData.GetLength(0) - 1) + l].y = interpolatedData[k, interpolatedData.GetLength(1) - 1 - l] * MaxHeight;
                        }
                    }
                }
            }
            var verts = Assistant.CheckNeighbors(matrix, lodLevel, neighbors).ToArray();
            var data  = new TerrainChunkMeshData()
            {
                Vertices  = verts,
                Colors32  = Assistant.CreateColorsFromVerticies(verts),
                Triangles = Assistant.CreateTriangles(amount),
                UVs       = Assistant.CreateUvs(amount),
                Lod       = lodLevel
            };

            PostProcessChunkMeshData(ref data);
            return(data);
        }
Example #2
0
    private MeshData GetInterpolatedDataLod(int lodLevel, bool[] neighbors)
    {
        var lod    = Consts.LodsAmount - lodLevel - _maxDataLod;
        var amount = (_heigthData.GetLength(0) - 1) * ((int)Mathf.Pow(2, lod)) + 1;

        var matrix = Assistant.CreateVerticesMatrix(amount, Consts.UnitSize);

        for (int i = 0; i < _heigthData.GetLength(0) - 1; i++)
        {
            for (int j = 0; j < _heigthData.GetLength(1) - 1; j++)
            {
                var data       = GetInterpolatedData(new Int2(i, j), (int)Mathf.Pow(2, lod) - 1);
                var lineLength = ((data.GetLength(0) - 1) * (_heigthData.GetLength(0) - 1) + 1);
                for (int k = 0; k < data.GetLength(0); k++)
                {
                    for (int l = 0; l < data.GetLength(1); l++)
                    {
                        //vertices[i * (data.GetLength(0) - 1) * lineLength + k * lineLength + j * (data.GetLength(0) - 1) + l].y = data[k, data.GetLength(1) - 1 - l] * Consts.MaxHight;
                        matrix[i * (data.GetLength(0) - 1) + k, j *(data.GetLength(0) - 1) + l].y = data[k, data.GetLength(1) - 1 - l] * Consts.MaxHight;
                    }
                }
            }
        }
        return(new MeshData()
        {
            Vertices = GetArrayFromMatrix(matrix, neighbors),
            Triangles = Assistant.CreateTriangles(amount),
            UVs = Assistant.CreateUvs(amount)
        });
    }
Example #3
0
        private Vector3[,] PickDataVertices(int step)
        {
            var size = HeigthData.GetLength(0);

            if (size % 2 == 0)
            {
                throw new ArgumentException();
            }
            var matrix = Assistant.CreateVerticesMatrix(((size - 1) / step) + 1, _сhunkSize);

            for (int x = 0; x < size; x += step)
            {
                for (int z = 0; z < size; z += step)
                {
                    matrix[x / step, z / step].y = HeigthData[x, z] * MaxHeight;
                }
            }
            return(matrix);
        }
Example #4
0
    //private MeshData GetInterpolatedDataLod(int lodLevel, bool[] neighbors)
    //{
    //    var lod = Consts.LodsAmount - lodLevel - _maxDataLod;
    //    var amount = (_heigthData.GetLength(0) - 1) * ((int)Mathf.Pow(2, lod)) + 1;
    //    var vertices = CalculateVertices(amount);
    //    for (int i = 0; i < _heigthData.GetLength(0) - 1; i++)
    //    {
    //        for (int j = 0; j < _heigthData.GetLength(1) - 1; j++)
    //        {
    //            var data = GetInterpolatedData(new Int2(i,j), (int)Mathf.Pow(2,lod) - 1);
    //            var lineLength = ((data.GetLength(0) - 1)*(_heigthData.GetLength(0) - 1) + 1);
    //            for (int k = data.GetLength(0) - 1; k >=0 ; k--)
    //            {
    //                for (int l = data.GetLength(1) - 1; l >= 0; l--)
    //                {
    //                    vertices[i* (data.GetLength(0) - 1) * lineLength + k * lineLength + j * (data.GetLength(0) - 1) + l].y = data[k, data.GetLength(1) - 1 - l]*Consts.MaxHight;
    //                }
    //            }
    //        }
    //    }
    //    return new MeshData()
    //    {
    //        Vertices = vertices,
    //        Triangles = CalulateTriangles(amount),
    //        UVs = CalculateUvs(amount)
    //    };
    //}

    private MeshData GetDataLod(bool[] neighbors)
    {
        var amount = (_heigthData.GetLength(0));
        var matrix = Assistant.CreateVerticesMatrix(amount, Consts.UnitSize);

        for (int i = 0; i < _heigthData.GetLength(0); i++)
        {
            for (int j = 0; j < _heigthData.GetLength(1); j++)
            {
                matrix[i, j].y = _heigthData[i, j] * Consts.MaxHight;
            }
        }

        return(new MeshData()
        {
            Vertices = GetArrayFromMatrix(matrix, neighbors),
            Triangles = Assistant.CreateTriangles(amount),
            UVs = Assistant.CreateUvs(amount)
        });
    }
Example #5
0
    //private MeshData GetDataLod(int lodLevel, bool[] neighbors)
    //{
    //    var lod = Consts.LodsAmount - lodLevel;
    //    if (lod == 0) return GetSeaBottomData();
    //    if (lod > _maxDataLod - 1) lod = _maxDataLod - 1;

    //    var size = _heigthData.GetLength(0);
    //    var step = (size - 1)/(int)Mathf.Pow(2, lod);


    //    var amount = (size - 1)/step + 1;
    //    var vertices = CalculateVertices(amount);

    //    for (int x = 0; x < size; x += step)
    //    {
    //        for (int z = 0; z < size; z += step)
    //        {
    //            var height = _heigthData[x, z]*_maxHeight;

    //            //Debug.Log(x.ToString("D2") + "|" + z.ToString("D2") + "|" + step.ToString("D2") + "|" + vertices.Length.ToString("D3") + "|" + (((x / step) * ((size - 1) / step + 1)) + (z / step)).ToString("D3"));
    //            vertices[((x/step)*((size - 1)/step + 1)) + (z/step)].y = height;
    //        }
    //    }
    //    return new MeshData()
    //    {
    //        Vertices = vertices,
    //        Triangles = CalulateTriangles(amount),
    //        UVs = CalculateUvs(amount)
    //    };
    //}

    private MeshData GetDataLod(int lodLevel, bool[] neighbors)
    {
        var lod = Consts.LodsAmount - lodLevel;

        if (lod > _maxDataLod - 1)
        {
            lod = _maxDataLod - 1;
        }


        var size = _heigthData.GetLength(0);
        var step = (size - 1) / (int)Mathf.Pow(2, lod);


        var amount = (size - 1) / step + 1;

        var matrix = Assistant.CreateVerticesMatrix(amount, Consts.UnitSize);

        for (int x = 0; x < size; x += step)
        {
            for (int z = 0; z < size; z += step)
            {
                var height = _heigthData[x, z] * _maxHeight;

                //Debug.Log(x.ToString("D2") + "|" + z.ToString("D2") + "|" + step.ToString("D2") + "|" + vertices.Length.ToString("D3") + "|" + (((x / step) * ((size - 1) / step + 1)) + (z / step)).ToString("D3"));
                //vertices[((x / step) * ((size - 1) / step + 1)) + (z / step)].y = height;
                matrix[x / step, z / step].y = height;
            }
        }
        return(new MeshData()
        {
            Vertices = GetArrayFromMatrix(matrix, neighbors),
            Triangles = Assistant.CreateTriangles(amount),
            UVs = Assistant.CreateUvs(amount)
        });
    }