protected override IEnumerable <Progress> ScanInternal()
        {
            cachedSourceMeshBoundsMin = sourceMesh != null ? sourceMesh.bounds.min : Vector3.zero;
            transform  = CalculateTransform();
            tileZCount = tileXCount = 1;
            tiles      = new NavmeshTile[tileZCount * tileXCount];
            TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this);

            if (sourceMesh == null)
            {
                FillWithEmptyTiles();
                yield break;
            }

            yield return(new Progress(0.0f, "Transforming Vertices"));

            forcedBoundsSize = sourceMesh.bounds.size * scale;
            Vector3[] vectorVertices = sourceMesh.vertices;
            var       intVertices    = ListPool <Int3> .Claim(vectorVertices.Length);

            var matrix = Matrix4x4.TRS(-sourceMesh.bounds.min * scale, Quaternion.identity, Vector3.one * scale);

            // Convert the vertices to integer coordinates and also position them in graph space
            // so that the minimum of the bounding box of the mesh is at the origin
            // (the vertices will later be transformed to world space)
            for (int i = 0; i < vectorVertices.Length; i++)
            {
                intVertices.Add((Int3)matrix.MultiplyPoint3x4(vectorVertices[i]));
            }

            yield return(new Progress(0.1f, "Compressing Vertices"));

            // Remove duplicate vertices
            Int3[] compressedVertices  = null;
            int[]  compressedTriangles = null;
            Polygon.CompressMesh(intVertices, new List <int>(sourceMesh.triangles), out compressedVertices,
                                 out compressedTriangles);
            ListPool <Int3> .Release(ref intVertices);

            yield return(new Progress(0.2f, "Building Nodes"));

            ReplaceTile(0, 0, compressedVertices, compressedTriangles);

            // Signal that tiles have been recalculated to the navmesh cutting system.
            navmeshUpdateData.OnRecalculatedTiles(tiles);
            if (OnRecalculatedTiles != null)
            {
                OnRecalculatedTiles(tiles.Clone() as NavmeshTile[]);
            }
        }
Exemplo n.º 2
0
        public override IEnumerable <Progress> ScanInternal()
        {
            transform  = CalculateTransform();
            tileZCount = tileXCount = 1;
            tiles      = new NavmeshTile[tileZCount * tileXCount];
            TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this);

            if (sourceMesh == null)
            {
                FillWithEmptyTiles();
                yield break;
            }

            yield return(new Progress(0.0f, "Transforming Vertices"));

            forcedBoundsSize = sourceMesh.bounds.size * scale;
            Vector3[] vectorVertices = sourceMesh.vertices;
            var       intVertices    = ListPool <Int3> .Claim(vectorVertices.Length);

            var matrix = Matrix4x4.TRS(-sourceMesh.bounds.min * scale, Quaternion.identity, Vector3.one * scale);

            // Convert the vertices to integer coordinates and also position them in graph space
            // so that the minimum of the bounding box of the mesh is at the origin
            // (the vertices will later be transformed to world space)
            for (int i = 0; i < vectorVertices.Length; i++)
            {
                intVertices.Add((Int3)matrix.MultiplyPoint3x4(vectorVertices[i]));
            }

            yield return(new Progress(0.1f, "Compressing Vertices"));

            // Remove duplicate vertices
            Int3[] compressedVertices  = null;
            int[]  compressedTriangles = null;
            Polygon.CompressMesh(intVertices, new List <int>(sourceMesh.triangles), out compressedVertices, out compressedTriangles);
            ListPool <Int3> .Release(intVertices);

            yield return(new Progress(0.2f, "Building Nodes"));

            ReplaceTile(0, 0, compressedVertices, compressedTriangles);

            // This may be used by the TileHandlerHelper script to update the tiles
            // while taking NavmeshCuts into account after the graph has been completely recalculated.
            if (OnRecalculatedTiles != null)
            {
                OnRecalculatedTiles(tiles.Clone() as NavmeshTile[]);
            }
        }