I want to automate rough placement of Lights probe above the Navmesh generated by Unity. Is there anyway I can access proper mesh data of a scene Navmesh?
Knowing that Unity uses Recast to generate the navmesh convex polygons, I was looking for the raw mesh data that recast also output. Having these triangles that cover the dynamic areas of the scene would make a great way to roughly place lights probe. I'm working (not actively) on a recast implementation (see below). So for now, I do have all the data I need to place my lights probe.
There is no method exposing the navmesh nodes and that is understandable since the nodes contain information that user should not have access to..You can use a Reflector decompiler to check you UnityEngine.dll and UnityEditor.dll
anyone else approaching this would likely want to keep in mind that Aron Granbergs A* path finding in its $100 Pro license utilizes the opensource Recast navmesh generation technology as well, with support for multiple meshes instead of just one as in Unitys case.
Since this has been revived, there is an undocumented accessor (the name escapes me) for grabbing the Mesh of the navigation mesh at editor time. Note that it is editor-time *only* though.
i want it too.. i beg you, please post it or send to vladcaflava@gmail.com im frustated as i can't access the navmesh points, because i want to give score for each point which unity automatically bake thanks
This thread wins the prize for: - unity sucking at finishing jobs ie navmesh - users sucking by almost being helpful but not quite Get a grip guys.
Hi AngryAnt, May i ask you to do an effort and try to remember that class name? Since you work on Unity it may be easy to ask someone (And to be honest your post is not that much of help ...hehehe) Currently i'm stuck with the navigation and obstacle implementation in unity 4, because, well, basically is not very good (sorry to be this honest, but take it as a constructive feedback). If we can have access to the navmesh data, the we can try to create our own local avoidance system, or use one available in c#, so please please, give us some info All the best.
You can access the navMesh data. I've made a simple script that creates a renderable mesh off it (just like the one you see in the navMesh baking editor). It's not a documented feature though Code (csharp): import UnityEngine class NavMeshVis (MonoBehaviour): [SerializeField] meshFilter as MeshFilter def Start (): verts as (Vector3) ids as (int) NavMesh.Triangulate(verts, ids) mesh = Mesh() mesh.vertices = verts mesh.triangles = ids meshFilter.mesh = mesh
I wrote a script that adds a menu option to export the current scene's NavMesh to an .obj file. Unity 4.6. Code (csharp): using System.IO; using System.Text; using UnityEditor; using UnityEngine; // Obj exporter component based on: http://wiki.unity3d.com/index.php?title=ObjExporter public class ExportNavMeshToObj : MonoBehaviour { [MenuItem("Custom/Export NavMesh to mesh")] static void Export() { NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation(); Mesh mesh = new Mesh(); mesh.name = "ExportedNavMesh"; mesh.vertices = triangulatedNavMesh.vertices; mesh.triangles = triangulatedNavMesh.indices; string filename = Application.dataPath +"/" + Path.GetFileNameWithoutExtension(EditorApplication.currentScene) + " Exported NavMesh.obj"; MeshToFile(mesh, filename); print("NavMesh exported as '" + filename + "'"); AssetDatabase.Refresh(); } static string MeshToString(Mesh mesh) { StringBuilder sb = new StringBuilder(); sb.Append("g ").Append(mesh.name).Append("\n"); foreach (Vector3 v in mesh.vertices) { sb.Append(string.Format("v {0} {1} {2}\n",v.x,v.y,v.z)); } sb.Append("\n"); foreach (Vector3 v in mesh.normals) { sb.Append(string.Format("vn {0} {1} {2}\n",v.x,v.y,v.z)); } sb.Append("\n"); foreach (Vector3 v in mesh.uv) { sb.Append(string.Format("vt {0} {1}\n",v.x,v.y)); } for (int material = 0; material < mesh.subMeshCount; material++) { sb.Append("\n"); //sb.Append("usemtl ").Append(mats[material].name).Append("\n"); //sb.Append("usemap ").Append(mats[material].name).Append("\n"); int[] triangles = mesh.GetTriangles(material); for (int i=0;i<triangles.Length;i+=3) { sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", triangles[i]+1, triangles[i+1]+1, triangles[i+2]+1)); } } return sb.ToString(); } static void MeshToFile(Mesh mesh, string filename) { using (StreamWriter sw = new StreamWriter(filename)) { sw.Write(MeshToString(mesh)); } } }
A little of necroposting, but thx for this precious snipper Useful to set the environnement where the player can teleport in VR !
A little necroposting, but HOLY! I finally Found how Mind Over Mushroom got the nave mesh data. Now how do I malform a circle from it?
Hello guys i use navSurface for the runtime baking Is there a way to load this file to navmeshsurface at the runtime instead of re-baking?