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[]);
            }
        }
        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[]);
            }
        }
Example #3
0
        public override IEnumerable <Progress> ScanInternal()
        {
            this.transform  = this.CalculateTransform();
            this.tileZCount = (this.tileXCount = 1);
            this.tiles      = new NavmeshTile[this.tileZCount * this.tileXCount];
            TriangleMeshNode.SetNavmeshHolder(AstarPath.active.data.GetGraphIndex(this), this);
            if (this.sourceMesh == null)
            {
                base.FillWithEmptyTiles();
                yield break;
            }
            yield return(new Progress(0f, "Transforming Vertices"));

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

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

            for (int i = 0; i < vertices.Length; i++)
            {
                intVertices.Add((Int3)matrix4x.MultiplyPoint3x4(vertices[i]));
            }
            yield return(new Progress(0.1f, "Compressing Vertices"));

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

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

            base.ReplaceTile(0, 0, compressedVertices, compressedTriangles);
            if (this.OnRecalculatedTiles != null)
            {
                this.OnRecalculatedTiles(this.tiles.Clone() as NavmeshTile[]);
            }
            yield break;
            yield break;
        }