예제 #1
0
        /** Creates a mesh of the surfaces of the navmesh for use in OnDrawGizmos in the editor */
        public static void CreateNavmeshSurfaceVisualization(this NavmeshBase navmeshBase, NavmeshTile tile, GraphGizmoHelper helper)
        {
            // Vertex array might be a bit larger than necessary, but that's ok
            var vertices = PF.ArrayPool <Vector3> .Claim(tile.nodes.Length *3);

            var colors = PF.ArrayPool <Color> .Claim(tile.nodes.Length *3);

            for (int j = 0; j < tile.nodes.Length; j++)
            {
                var  node = tile.nodes[j];
                Int3 v0, v1, v2;
                node.GetVertices(out v0, out v1, out v2);
                vertices[j * 3 + 0] = (Vector3)v0;
                vertices[j * 3 + 1] = (Vector3)v1;
                vertices[j * 3 + 2] = (Vector3)v2;

                var color = helper.NodeColor(node);
                colors[j * 3 + 0] = colors[j * 3 + 1] = colors[j * 3 + 2] = color;
            }

            if (navmeshBase.showMeshSurface)
            {
                helper.DrawTriangles(vertices, colors, tile.nodes.Length);
            }
            if (navmeshBase.showMeshOutline)
            {
                helper.DrawWireTriangles(vertices, colors, tile.nodes.Length);
            }

            // Return lists to the pool
            PF.ArrayPool <Vector3> .Release(ref vertices);

            PF.ArrayPool <Color> .Release(ref colors);
        }
예제 #2
0
        /** Creates an outline of the navmesh for use in OnDrawGizmos in the editor */
        public static void CreateNavmeshOutlineVisualization(NavmeshTile tile, GraphGizmoHelper helper)
        {
            var sharedEdges = new bool[3];

            for (int j = 0; j < tile.nodes.Length; j++)
            {
                sharedEdges[0] = sharedEdges[1] = sharedEdges[2] = false;

                var node = tile.nodes[j];
                for (int c = 0; c < node.connections.Length; c++)
                {
                    var other = node.connections[c].node as TriangleMeshNode;

                    // Loop through neighbours to figure out which edges are shared
                    if (other != null && other.GraphIndex == node.GraphIndex)
                    {
                        for (int v = 0; v < 3; v++)
                        {
                            for (int v2 = 0; v2 < 3; v2++)
                            {
                                if (node.GetVertexIndex(v) == other.GetVertexIndex((v2 + 1) % 3) && node.GetVertexIndex((v + 1) % 3) == other.GetVertexIndex(v2))
                                {
                                    // Found a shared edge with the other node
                                    sharedEdges[v] = true;
                                    v = 3;
                                    break;
                                }
                            }
                        }
                    }
                }

                var color = helper.NodeColor(node);
                for (int v = 0; v < 3; v++)
                {
                    if (!sharedEdges[v])
                    {
                        helper.builder.DrawLine((Vector3)node.GetVertex(v), (Vector3)node.GetVertex((v + 1) % 3), color);
                    }
                }
            }
        }