예제 #1
0
        protected override void Write(ContentWriter output, HeightMapInfoContent value)
        {
            output.WriteObject(value.Model);
            output.Write(value.TerrainScale);
            output.Write(value.Height.GetLength(0));
            output.Write(value.Height.GetLength(1));
            float[,] height = value.Height;
            int upperBound = height.GetUpperBound(0);
            int num        = height.GetUpperBound(1);

            for (int i = height.GetLowerBound(0); i <= upperBound; i++)
            {
                for (int j = height.GetLowerBound(1); j <= num; j++)
                {
                    float single = height[i, j];
                    output.Write(single);
                }
            }
            Vector3[,] normals = value.Normals;
            int upperBound1 = normals.GetUpperBound(0);
            int num1        = normals.GetUpperBound(1);
            int lowerBound  = normals.GetLowerBound(0);

            while (lowerBound <= upperBound1)
            {
                for (int k = normals.GetLowerBound(1); k <= num1; k++)
                {
                    Vector3 vector3 = normals[lowerBound, k];
                    output.Write(vector3);
                }
                lowerBound++;
            }
        }
예제 #2
0
    bool HasCloseNeighbor(Vector3 point, ref Vector3[,] grid, float cellSize, float minDistance)
    {
        var gridXY = GetGridXY(point, cellSize);

        for (int x = Math.Max(0, gridXY.Item1 - 2); x <= Math.Min(grid.GetUpperBound(0), gridXY.Item1 + 2); x++)
        {
            for (int y = Math.Max(0, gridXY.Item2 - 2); y <= Math.Min(grid.GetUpperBound(1), gridXY.Item2 + 2); y++)
            {
                if (Vector3.Distance(point, grid[x, y]) < minDistance)
                {
                    return(true);
                }
            }
        }
        return(false);
    }
예제 #3
0
    List <Vector3[, ]> CutVertical(Vector3[,] initalArray)
    {
        List <Vector3[, ]> itemList = new List <Vector3[, ]>();

        Vector3[,] arrayBlock = new Vector3[(initalArray.GetUpperBound(0) / 2) + 1, initalArray.GetUpperBound(1) + 1];

        for (int z = 0; z <= initalArray.GetUpperBound(1); z++)
        {
            for (int x = 0; x <= initalArray.GetUpperBound(0) / 2 - 1; x++)
            {
                // Gizmos.color = Color.green;
                // Gizmos.DrawSphere(initalArray[x, z], 0.5f);
                arrayBlock[x, z] = initalArray[x, z];
            }
        }

        itemList.Add(arrayBlock);

        Vector3[,] UpdatedInitArry = new Vector3[arrayBlock.GetUpperBound(0), arrayBlock.GetUpperBound(1) + 1];

        // print($"Updated Init array Size x:{UpdatedInitArry.GetUpperBound(0)} z: {UpdatedInitArry.GetUpperBound(1)}");

        for (int z = 0, zIndex = 0; z <= arrayBlock.GetUpperBound(1); z++, zIndex++)

        {
            for (int x = arrayBlock.GetUpperBound(0) + 1, xIndex = 0; x <= initalArray.GetUpperBound(0); x++, xIndex++)
            {
                // Gizmos.color = Color.red;
                // Gizmos.DrawSphere(initalArray[x, z], 0.5f);
                UpdatedInitArry[xIndex, zIndex] = initalArray[x, z];
            }
        }

        itemList.Add(UpdatedInitArry);


        for (int z = 0; z < arrayBlock.GetUpperBound(1) + 1; z++)
        {
            // Gizmos.color = Color.magenta;
            // Gizmos.DrawSphere(initalArray[arrayBlock.GetUpperBound(0), z], 0.5f);
            removeObject.Add(initalArray[arrayBlock.GetUpperBound(0), z]);
        }


        return(itemList);
    }
예제 #4
0
    List <Vector3[, ]> SplitDesicion(Vector3[,] sizeData)
    {
        List <Vector3[, ]> itemList = new List <Vector3[, ]>();
        int num = Random.Range(0, 2);

        switch (num)
        {
        case 0:
            if (sizeData.GetUpperBound(0) % 2 == 0)
            {
                itemList.AddRange(CutVertical(sizeData));
            }
            else if (sizeData.GetUpperBound(1) % 2 == 0)
            {
                itemList.AddRange(CutHorizontal(sizeData));
            }
            else
            {
                print("Data size is to small to partition");
            }
            break;

        case 1:
            if (sizeData.GetUpperBound(1) % 2 == 0)
            {
                itemList.AddRange(CutHorizontal(sizeData));
            }
            else if (sizeData.GetUpperBound(0) % 2 == 0)
            {
                itemList.AddRange(CutVertical(sizeData));
            }
            else
            {
                print("Data size is to small to partition");
            }
            break;
        }

        if (!itemList.Any())
        {
            print("item-list return null");
            return(null);
        }

        return(itemList);
    }
예제 #5
0
    List <Vector3[, ]> CutHorizontal(Vector3[,] initalArray)
    {
        List <Vector3[, ]> itemList = new List <Vector3[, ]>();

        Vector3[,] arrayBlock = new Vector3[initalArray.GetUpperBound(0) + 1, (initalArray.GetUpperBound(1) / 2) + 1];

        for (int z = 0; z <= initalArray.GetUpperBound(1) / 2 - 1; z++)
        {
            for (int x = 0; x <= initalArray.GetUpperBound(0); x++)
            {
                // Gizmos.color = Color.blue;
                // Gizmos.DrawSphere(initalArray[x, z], 0.05f);
                arrayBlock[x, z] = initalArray[x, z];
            }
        }

        itemList.Add(arrayBlock);

        Vector3[,] UpdatedInitArry = new Vector3[arrayBlock.GetUpperBound(0) + 1, arrayBlock.GetUpperBound(1) + 1];
        // print($"x: {UpdatedInitArry.GetUpperBound(0)}, z: {UpdatedInitArry.GetUpperBound(1)}");


        for (int z = arrayBlock.GetUpperBound(1) + 1, zIndex = 0; z <= initalArray.GetUpperBound(1); z++, zIndex++)

        {
            for (int x = 0, xIndex = 0; x <= arrayBlock.GetUpperBound(0); x++, xIndex++)
            {
                // Gizmos.color = Color.green;
                // Gizmos.DrawSphere(initalArray[x, z], 0.05f);
                UpdatedInitArry[xIndex, zIndex] = initalArray[x, z];
            }

            print("ran");
        }

        itemList.Add(UpdatedInitArry);
        for (int x = 0; x < arrayBlock.GetUpperBound(0) + 1; x++)
        {
            // Gizmos.color = Color.magenta;
            // Gizmos.DrawSphere(initalArray[x, arrayBlock.GetUpperBound(1)], 0.05f);
            removeObject.Add(initalArray[x, arrayBlock.GetUpperBound(1)]);
        }

        return(itemList);
    }
예제 #6
0
파일: Utils.cs 프로젝트: sk-zk/TruckLib
        public static Vector3[,] MirrorX(Vector3[,] arr)
        {
            Vector3[,] newArr = Copy2dArray(arr);

            var upperBound0     = newArr.GetUpperBound(1) + 1;
            var halfUpperBound0 = upperBound0 / 2;

            for (int y = 0; y <= newArr.GetUpperBound(0); y++)
            {
                for (int x = 0; x < halfUpperBound0; x++)
                {
                    (newArr[x, y], newArr[upperBound0 - 1 - x, y])
                        = (newArr[upperBound0 - 1 - x, y], newArr[x, y]);
                }
            }

            return(newArr);
        }
예제 #7
0
        /// <summary>
        /// Writes a 2D array of vector3 structs to the output.
        /// </summary>
        /// <param name="name">Name of the value</param>
        /// <param name="value">2D array of vector3</param>
        public void Write(string name, Vector3[,] value)
        {
            if (value == null)
            {
                _output.Write(NULL_OBJECT);
                return;
            }
            else
            {
                _output.Write(A_OK);
            }
            int row = value.GetUpperBound(0);
            int col = value.GetUpperBound(1);

            _output.Write(row);
            _output.Write(col);
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    this.Write(null, value[i, j]);
                }
            }
        }
예제 #8
0
파일: Utils.cs 프로젝트: sk-zk/TruckLib
 /// <summary>
 /// Creates a copy of a 2D array.
 /// </summary>
 /// <param name="arr">The array to copy.</param>
 /// <returns>A copy of the array.</returns>
 public static Vector3[,] Copy2dArray(Vector3[,] arr)
 {
     Vector3[,] newArr = new Vector3[arr.GetUpperBound(0) + 1, arr.GetUpperBound(1) + 1];
     Array.Copy(arr, newArr, (arr.GetUpperBound(0) + 1) * (arr.GetUpperBound(1) + 1));
     return(newArr);
 }