// Token: 0x060027D1 RID: 10193 RVA: 0x001B497C File Offset: 0x001B2B7C
        private RasterizationMesh GenerateHeightmapChunk(float[,] heights, Vector3 sampleSize, Vector3 offset, int x0, int z0, int width, int depth, int stride)
        {
            int num     = RecastMeshGatherer.CeilDivision(width, this.terrainSampleSize) + 1;
            int num2    = RecastMeshGatherer.CeilDivision(depth, this.terrainSampleSize) + 1;
            int length  = heights.GetLength(0);
            int length2 = heights.GetLength(1);
            int num3    = num * num2;

            Vector3[] array = ArrayPool <Vector3> .Claim(num3);

            for (int i = 0; i < num2; i++)
            {
                for (int j = 0; j < num; j++)
                {
                    int num4 = Math.Min(x0 + j * stride, length - 1);
                    int num5 = Math.Min(z0 + i * stride, length2 - 1);
                    array[i * num + j] = new Vector3((float)num5 * sampleSize.x, heights[num4, num5] * sampleSize.y, (float)num4 * sampleSize.z) + offset;
                }
            }
            int num6 = (num - 1) * (num2 - 1) * 2 * 3;

            int[] array2 = ArrayPool <int> .Claim(num6);

            int num7 = 0;

            for (int k = 0; k < num2 - 1; k++)
            {
                for (int l = 0; l < num - 1; l++)
                {
                    array2[num7]     = k * num + l;
                    array2[num7 + 1] = k * num + l + 1;
                    array2[num7 + 2] = (k + 1) * num + l + 1;
                    num7            += 3;
                    array2[num7]     = k * num + l;
                    array2[num7 + 1] = (k + 1) * num + l + 1;
                    array2[num7 + 2] = (k + 1) * num + l;
                    num7            += 3;
                }
            }
            RasterizationMesh rasterizationMesh = new RasterizationMesh(array, array2, default(Bounds));

            rasterizationMesh.numVertices  = num3;
            rasterizationMesh.numTriangles = num6;
            rasterizationMesh.pool         = true;
            rasterizationMesh.RecalculateBounds();
            return(rasterizationMesh);
        }
Ejemplo n.º 2
0
 public void CollectSceneMeshes(List <RasterizationMesh> meshes)
 {
     if (this.tagMask.Count > 0 || this.mask != 0)
     {
         MeshFilter[]                 meshFilters = UnityEngine.Object.FindObjectsOfType <MeshFilter>();
         List <MeshFilter>            list        = RecastMeshGatherer.FilterMeshes(meshFilters, this.tagMask, this.mask);
         Dictionary <Mesh, Vector3[]> dictionary  = new Dictionary <Mesh, Vector3[]>();
         Dictionary <Mesh, int[]>     dictionary2 = new Dictionary <Mesh, int[]>();
         bool flag = false;
         for (int i = 0; i < list.Count; i++)
         {
             MeshFilter meshFilter = list[i];
             Renderer   component  = meshFilter.GetComponent <Renderer>();
             if (component.isPartOfStaticBatch)
             {
                 flag = true;
             }
             else if (component.bounds.Intersects(this.bounds))
             {
                 Mesh sharedMesh = meshFilter.sharedMesh;
                 RasterizationMesh rasterizationMesh = new RasterizationMesh();
                 rasterizationMesh.matrix   = component.localToWorldMatrix;
                 rasterizationMesh.original = meshFilter;
                 if (dictionary.ContainsKey(sharedMesh))
                 {
                     rasterizationMesh.vertices  = dictionary[sharedMesh];
                     rasterizationMesh.triangles = dictionary2[sharedMesh];
                 }
                 else
                 {
                     rasterizationMesh.vertices  = sharedMesh.vertices;
                     rasterizationMesh.triangles = sharedMesh.triangles;
                     dictionary[sharedMesh]      = rasterizationMesh.vertices;
                     dictionary2[sharedMesh]     = rasterizationMesh.triangles;
                 }
                 rasterizationMesh.bounds = component.bounds;
                 meshes.Add(rasterizationMesh);
             }
             if (flag)
             {
                 Debug.LogWarning("Some meshes were statically batched. These meshes can not be used for navmesh calculation due to technical constraints.\nDuring runtime scripts cannot access the data of meshes which have been statically batched.\nOne way to solve this problem is to use cached startup (Save & Load tab in the inspector) to only calculate the graph when the game is not playing.");
             }
         }
     }
 }
Ejemplo n.º 3
0
        private RasterizationMesh GenerateHeightmapChunk(float[,] heights, Vector3 sampleSize, Vector3 offset, int x0, int z0, int width, int depth, int stride)
        {
            int num     = RecastMeshGatherer.CeilDivision(width, this.terrainSampleSize) + 1;
            int num2    = RecastMeshGatherer.CeilDivision(depth, this.terrainSampleSize) + 1;
            int length  = heights.GetLength(0);
            int length2 = heights.GetLength(1);

            Vector3[] array = new Vector3[num * num2];
            for (int i = 0; i < num2; i++)
            {
                for (int j = 0; j < num; j++)
                {
                    int num3 = Math.Min(x0 + j * stride, length - 1);
                    int num4 = Math.Min(z0 + i * stride, length2 - 1);
                    array[i * num + j] = new Vector3((float)num4 * sampleSize.x, heights[num3, num4] * sampleSize.y, (float)num3 * sampleSize.z) + offset;
                }
            }
            int[] array2 = new int[(num - 1) * (num2 - 1) * 2 * 3];
            int   num5   = 0;

            for (int k = 0; k < num2 - 1; k++)
            {
                for (int l = 0; l < num - 1; l++)
                {
                    array2[num5]     = k * num + l;
                    array2[num5 + 1] = k * num + l + 1;
                    array2[num5 + 2] = (k + 1) * num + l + 1;
                    num5            += 3;
                    array2[num5]     = k * num + l;
                    array2[num5 + 1] = (k + 1) * num + l + 1;
                    array2[num5 + 2] = (k + 1) * num + l;
                    num5            += 3;
                }
            }
            RasterizationMesh rasterizationMesh = new RasterizationMesh(array, array2, default(Bounds));

            rasterizationMesh.RecalculateBounds();
            return(rasterizationMesh);
        }