private void CreateVisibleMesh(GpNavMesh gpNavMesh) { var navMeshName = "GpNavMesh"; var mesh = new Mesh { name = navMeshName, vertices = gpNavMesh.Vertices.ToVector3Array(), triangles = gpNavMesh.TriangleIndices }; var go = Instantiate(m_NavMeshPrefab); m_NavMeshGo = go.transform; go.transform.position = Vector3.zero; go.transform.localRotation = Quaternion.identity; var meshFilter = go.GetComponent <MeshFilter>(); meshFilter.mesh = mesh; }
private void OnGUI() { GUILayout.BeginArea(new Rect(10, 10, 200, 300), GUIContent.none, "box"); if (GUILayout.Button("Export to GpNavMesh")) { // Convert the scene NavMesh to a GpNavMesh m_GpNavMesh = GenerateGpNavMesh(); // Visualize the GpNavMesh as a GameObject CreateVisibleMesh(m_GpNavMesh); } if (GUILayout.Button("Show Centroids")) { // Create objects to show the center of each NavMesh triangle for (var i = 0; i < m_GpNavMesh.Triangles.Length; i++) { var centroid = m_GpNavMesh.Triangles[i].Centroid(); CreateNode($"Node:{i}", centroid.ToVector3()); } } if (GUILayout.Button("Show Directions")) { // Create objects to show the center of each NavMesh triangle var vectorField = m_GpNavMesh.GetVectorField(m_Destination.ToGpVector3()); CreateDestination(m_Destination); for (var i = 0; i < vectorField.Length; i++) { var postition = m_GpNavMesh.Triangles[i].Centroid().ToVector3(); var direction = vectorField[i].ToVector3(); var rotation = Quaternion.LookRotation(direction); CreateDirection($"Dir:{i}", postition, rotation); } } if (GUILayout.Button("Get Connected Triangles")) { var connectedTris = m_GpNavMesh.GetConnectedTriangles(); var i = 0; foreach (var connectedTri in connectedTris) { Debug.Log($"Tri{i} is connected to {connectedTri.Value.Count} other Tris."); i++; } } if (GUILayout.Button("Build Graph")) { var gpGraph = new GpGraph(m_GpNavMesh); // Create objects to show the center of each NavMesh triangle int i = 0; foreach (var node in gpGraph.Nodes) { CreateNode($"Node:{i}", node.Position.ToVector3()); i++; } VisitNode(gpGraph.Nodes[0]); } GUILayout.EndArea(); }