// Use this for initialization void Start() { unityPath = new NavMeshPath(); MeshFilter meshFilter = this.gameObject.AddComponent <MeshFilter>(); NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation(); debugNavMeshVertices.AddRange(triangulatedNavMesh.vertices); debugNavMeshIndices.AddRange(triangulatedNavMesh.indices); //weld vertices for (int i = 0; i < triangulatedNavMesh.indices.Length; i += 3) { for (int j = 0; j < 3; j++) { int vertexIndex = triangulatedNavMesh.indices[i + j]; Vector3 v = triangulatedNavMesh.vertices[vertexIndex]; int index = FindIndex(v); if (index == -1) { vertices.Add(v); index = vertices.Count - 1; } triangles.Add(index); } } this.ExportNavMesh(); TNavMesh.Init("G:/navmesh.txt"); }
// Use this for initialization void Awake() { navMeshAgent = GetComponent <NavMeshAgent>(); if (startObject != null) { startPosition = startObject.transform.position; startRotation = startObject.transform.rotation; } if (ghostCageObject != null) { ghostCagePosition = ghostCageObject.transform.position; } isActive = false; isScared = false; isEaten = false; MeshFilter meshFilter = GetComponent <MeshFilter>(); if (meshFilter != null) { defaultMesh = meshFilter.mesh; } objectRenderer = GetComponent <Renderer>(); navMeshTriangulation = NavMesh.CalculateTriangulation(); navMeshVertices = navMeshTriangulation.vertices; waitToChoosePoint = new WaitForSeconds(choosePointIntervalWhenScared); waitToBlinkWhenEnergizedNearEnd = new WaitForSeconds(blinkIntervalWhenEnergizedNearEnd); currentMaterialIndex = 0; }
void ExportNavMesh(out string error) { var tgn = NavMesh.CalculateTriangulation(); if (tgn.areas.Length == 0) { error = "No navmesh was found."; lastStatus = null; return; } // We only use the first settings var settings = NavMesh.GetSettingsByID(0); var path = EditorUtility.SaveFilePanel("Save NavMesh as Obj", "", "navmesh" + ".obj", "obj"); if (string.IsNullOrEmpty(path)) { error = null; return; } MeshToObjFile(tgn, settings, path); var builder = new StringBuilder(); builder.AppendFormat("last export: {0} \n", System.DateTime.Now); builder.AppendFormat("areas count: {0} \n", tgn.areas.Length); builder.AppendFormat("indices count: {0} \n", tgn.indices.Length); builder.AppendFormat("vertices count: {0} \n", tgn.vertices.Length); builder.AppendFormat("path: {0} \n", tgn.areas.Length); lastStatus = builder.ToString(); error = null; }
Vector3 GetRandomLocation() { NavMeshTriangulation navMeshData = NavMesh.CalculateTriangulation(); int maxIndices = navMeshData.indices.Length - 3; // Pick the first indice of a random triangle in the nav mesh int firstVertexSelected = Random.Range(0, maxIndices); int secondVertexSelected = Random.Range(0, maxIndices); //Spawn on Verticies Vector3 point = navMeshData.vertices[navMeshData.indices[firstVertexSelected]]; Vector3 firstVertexPosition = navMeshData.vertices[navMeshData.indices[firstVertexSelected]]; Vector3 secondVertexPosition = navMeshData.vertices[navMeshData.indices[secondVertexSelected]]; //Eliminate points that share a similar X or Z position to stop spawining in square grid line formations if ((int)firstVertexPosition.x == (int)secondVertexPosition.x || (int)firstVertexPosition.z == (int)secondVertexPosition.z ) { point = GetRandomLocation(); //Re-Roll a position - I'm not happy with this recursion it could be better } else { // Select a random point on it point = Vector3.Lerp( firstVertexPosition, secondVertexPosition, //[t + 1]], Random.Range(0.05f, 0.95f) // Not using Random.value as clumps form around Verticies ); } //Vector3.Lerp(point, navMeshData.vertices[navMeshData.indices[t + 2]], Random.value); //Made Obsolete return(point); }
public override void OnInspectorGUI() { GUIStyle bold_wrap = EditorStyles.boldLabel; bold_wrap.wordWrap = true; GUILayout.Label("Navmesh Preprocessor for HTC Vive Locomotion", bold_wrap); GUILayout.Label("Adrian Biagioli 2016", EditorStyles.miniLabel); GUILayout.Label("Before Using", bold_wrap); GUIStyle wrap = EditorStyles.label; wrap.wordWrap = true; GUILayout.Label( "Change your navmesh settings (Window > Navigation) to where you want the player to be able to navigate and bake the navmesh. " + "Then click \"Update Navmesh Data\" below. You may change the navigation settings back and rebake after you have updated.\n\nRecommended Settings:\n" + "Agent Radius: 0.25\nAgent Height: 2\nMax Slope: 0\nStep Height: 0\nDrop Height: 0\nJump Distance: 0\n", wrap); ViveNavMesh mesh = (ViveNavMesh)target; if (GUILayout.Button("Update Navmesh Data")) { mesh.SelectableMesh = ConvertNavmeshToMesh(NavMesh.CalculateTriangulation(), 0); mesh.SelectableMeshBorder = FindBorderEdges(mesh.SelectableMesh); } EditorGUILayout.LabelField("Render Settings", EditorStyles.boldLabel); mesh.GroundMaterial = (Material)EditorGUILayout.ObjectField("Ground Material", mesh.GroundMaterial, typeof(Material), false); mesh.GroundAlpha = EditorGUILayout.Slider("Ground Alpha", mesh.GroundAlpha, 0, 1); }
/* * 床面推定が完了した時に呼ばれるメソッド。推定された床面は3Dオブジェクト(SurfacePlane)として取得できる(ここでは、SurfacePlaneとして取得しなくても良いため、GameObjectとして検索している)。 * タグ"Plane"がついたSurfacePlaneが推定された床面であるが、それに対しNavMeshSourceTagという要素を付加することで後にNavMeshによる歩行可能エリアの計算がその面に対して可能になる。 */ private void SurfaceMeshesToPlanes_MakePlanesComplete(object source, System.EventArgs args) { RemoveSurfaceVertices.Instance.RemoveSurfaceVerticesWithinBounds(SurfaceMeshesToPlanes.Instance.ActivePlanes); //SpatialMappingManager.Instance.DrawVisualMeshes = false; SpatialMappingManager.Instance.StartObserver(); var planes = GameObject.FindGameObjectsWithTag("Plane"); if (planes.Length != 0) { foreach (GameObject item in planes) { item.gameObject.AddComponent <NavMeshSourceTag> (); } makedPlane = true; //NavMeshの三角形集合取得 NavMeshTriangulation triangles = NavMesh.CalculateTriangulation(); Vector3[] v = triangles.vertices; for (int i = 0; i < v.Length; i++) { mkRoute.huNav.log.writeMessage_area("area" + areaNum + "," + v[i].x + "," + v[i].z); } areaNum++; } else { makedPlane = false; } }
//测试用 void ExportNavMeshTest() { NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation(); Mesh mesh = new Mesh(); mesh.name = "_NavMesh"; mesh.vertices = triangulatedNavMesh.vertices; mesh.triangles = triangulatedNavMesh.indices; GameObject test = new GameObject("TestMesh"); MeshFilter mf = test.AddComponent <MeshFilter>(); test.AddComponent <MeshRenderer>(); mf.mesh = mesh; for (int i = 0; i < mesh.vertices.Length; ++i) { GameObject sp = GameObject.CreatePrimitive(PrimitiveType.Sphere); sp.transform.position = test.transform.TransformPoint(mesh.vertices[i]); sp.transform.parent = test.transform; } }
public Vector3 GetRandomPointOnNavMesh() { Vector3 randomPoint; do { NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); int randomIndex = Random.Range(0, navMeshTriangulation.indices.Length - 3); randomPoint = Vector3.Lerp(navMeshTriangulation.vertices[navMeshTriangulation.indices[randomIndex]], navMeshTriangulation.vertices[navMeshTriangulation.indices[randomIndex + 1]], Random.value); Vector3.Lerp(randomPoint, navMeshTriangulation.vertices[navMeshTriangulation.indices[randomIndex + 2]], Random.value); } while (randomPoint.y > 1); /* Use this to debug the destination point with a cube * GameObject primitive = GameObject.CreatePrimitive(PrimitiveType.Cube); * * primitive.GetComponent<Renderer>().material.color = Color.red; * * if (primitive != null) * primitive.transform.position = randomPoint; */ return(randomPoint); }
// Update is called once per frame void Update() { // made it to destination if (Vector3.Distance(transform.position, navMeshAgent.destination) < 1f) { NavMeshTriangulation data = NavMesh.CalculateTriangulation(); Vector3 vertex = data.vertices[Random.Range(0, data.vertices.Length)]; navMeshAgent.destination = vertex; } // collision with player foreach (PlayerController p in players) { if (Vector3.Distance(transform.position, p.transform.position) <= range) { colorCaster.playerTag = p.PlayerTag; // Change Material if (colorMaterials[(int)p.PlayerTag]) { GetComponentInChildren <Renderer>().material = colorMaterials[(int)p.PlayerTag]; } } } }
static void OnGizmo(Transform tf, GizmoType gt) { // rebuild if necessary if (!gizmesh || needsRebuild) { if (!NavMeshBuilder.isRunning) { RebuildGizmesh(NavMesh.CalculateTriangulation()); } } // draw if not empty if (gizmesh.vertices.Length > 0) { Gizmos.color = Color.cyan; if (showNavMesh == 1) { Gizmos.DrawWireMesh(gizmesh); } else if (showNavMesh == 2) { Gizmos.DrawMesh(gizmesh); Gizmos.DrawWireMesh(gizmesh); } } }
public const int MAX_WALL = 7; //can change this to create a geant map // Start is called before the first frame update void Start() { float begin = Time.realtimeSinceStartup; this.seed = Mathf.FloorToInt(Random.value * int.MaxValue); Random.InitState(seed); MapGeneration(); surface.BuildNavMesh(); surface.AddData(); //Add the surface to the singleton Nav Mesh NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); DebugDisplayTriangle(navMeshTriangulation); MapGraph mapGraph = GenerateGraph(navMeshTriangulation); mapGraph.DeugDrawGrahp(); Debug.Log("Generation took " + (Time.realtimeSinceStartup - begin) + " seconds"); GenerateLights(mapGraph); TemporaryPlayerGeneration(mapGraph); surface.RemoveData(); //Remove the surface to the singleton NavMesh surface_enemy.BuildNavMesh(); GenerateEnemies(5, mapGraph); gameObject.BroadcastMessage("StartTheGame"); }
void ShowNavMesh() { triangles = NavMesh.CalculateTriangulation(); mesh = new Mesh(); vertices = triangles.vertices; indices = triangles.indices;; mesh.vertices = vertices; mesh.triangles = indices; indicesCount = indices.Length; if (meshShowObj) { Mesh mesh2 = meshShowObj.GetComponent <MeshFilter>().mesh; mesh2.Clear(); mesh2.vertices = vertices; mesh2.triangles = indices; //mesh.Optimize(); mesh2.RecalculateNormals(); //if (meshShowObj.GetComponent<MeshCollider>() == null) //{ // meshShowObj.AddComponent<MeshCollider>(); //} //Collider collider = meshShowObj.GetComponent<Collider>(); //var p=collider.ClosestPoint(targetPos); //NavMeshHelper.CreatePoint(p, "MeshCollider", 0.5f, Color.yellow); } //ShowVertices(); ShowNavMeshPoints(); }
private void drawNavMesh() { NavMeshTriangulation nt = NavMesh.CalculateTriangulation(); m.vertices = nt.vertices; m.triangles = nt.indices; }
void GenerateLinks(NavLinkGenerator gen) { var tri = NavMesh.CalculateTriangulation(); var edge_list = CreateEdges(tri); foreach (var edge in edge_list) { edge.ComputeDerivedData(); } if (edge_list.Count() == 0) { return; } RemoveLinks(); m_CreatedLinks.Clear(); var parent = NavEdUtil.GetNamedRoot(k_LinkRootName); foreach (var edge in edge_list) { var mid = edge.GetMidpoint(); var fwd = edge.m_Normal; var link = CreateNavLink(parent, gen, edge, mid, fwd); if (link != null) { m_CreatedLinks.Add(link); } } }
//导出NavMesh的数据 void ExportNavMesh() { NavMeshTriangulation triangulatedNavMesh = NavMesh.CalculateTriangulation(); Mesh mesh = new Mesh(); mesh.name = "_NavMesh"; mesh.vertices = triangulatedNavMesh.vertices; mesh.triangles = triangulatedNavMesh.indices; string baseName = "navmesh_" + SceneManager.GetActiveScene().name; string fileName = Application.dataPath + "/navmesh/" + baseName + ".obj"; string txtName = Application.dataPath + "/navmesh/" + baseName + ".txt"; NavMeshToMeshObj(mesh, fileName); NavMeshToBinaryFile(mesh, txtName); AssetDatabase.Refresh(); /* * string assetName = fileName.Replace(Application.dataPath, "Assets"); * GameObject navMesh = Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>(assetName)); * navMesh.name = baseName; * MeshObjToBinaryFile(navMesh); */ Debug.Log("导出完成:" + baseName); AssetDatabase.Refresh(); }
public void Awake() { instance = this; NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); navMesh = new Mesh(); navMesh.vertices = navMeshTriangulation.vertices; navMesh.triangles = navMeshTriangulation.indices; int num = navMeshTriangulation.indices.Length / 3; navWeights = new float[num]; float num2 = 0f; for (int i = 0; i < num; i++) { Vector3 a = navMesh.vertices[navMesh.triangles[i * 3]]; Vector3 vector = navMesh.vertices[navMesh.triangles[i * 3 + 1]]; Vector3 b = navMesh.vertices[navMesh.triangles[i * 3 + 2]]; float magnitude = (a - vector).magnitude; float magnitude2 = (a - b).magnitude; float magnitude3 = (vector - b).magnitude; float num3 = (magnitude + magnitude2 + magnitude3) * 0.5f; float num4 = Mathf.Sqrt(num3 * (num3 - magnitude) * (num3 - magnitude2) * (num3 - magnitude3)); navWeights[i] = num4; num2 += num4; } for (int i = 0; i < num; i++) { navWeights[i] /= num2; } }
private Vector3 GetRandomGameBoardLocation() { NavMeshTriangulation navMeshData = NavMesh.CalculateTriangulation(); int maxIndices = navMeshData.indices.Length - 3; // pick the first indice of a random triangle in the nav mesh int firstVertexSelected = Random.Range(0, maxIndices); int secondVertexSelected = Random.Range(0, maxIndices); // spawn on verticies Vector3 point = navMeshData.vertices[navMeshData.indices[firstVertexSelected]]; Vector3 firstVertexPosition = navMeshData.vertices[navMeshData.indices[firstVertexSelected]]; Vector3 secondVertexPosition = navMeshData.vertices[navMeshData.indices[secondVertexSelected]]; // eliminate points that share a similar X or Z position to stop spawining in square grid line formations if ((int)firstVertexPosition.x == (int)secondVertexPosition.x || (int)firstVertexPosition.z == (int)secondVertexPosition.z) { point = GetRandomGameBoardLocation(); // re-roll a position - I'm not happy with this recursion it could be better } else { // select a random point on it point = Vector3.Lerp(firstVertexPosition, secondVertexPosition, UnityEngine.Random.Range(0.05f, 0.95f)); } return(point); }
static void Export() { Debug.Log("NavmMesh Export Start"); NavMeshTriangulation navMeshTriangulation = NavMesh.CalculateTriangulation(); //文件路径 路径文件夹不存在会报错 string path = Application.dataPath + "/Scripts/Obj/" + SceneManager.GetActiveScene().name + ".obj"; //新建文件 StreamWriter streamWriter = new StreamWriter(path); //顶点 for (int i = 0; i < navMeshTriangulation.vertices.Length; i++) { streamWriter.WriteLine("v " + navMeshTriangulation.vertices[i].x + " " + navMeshTriangulation.vertices[i].y + " " + navMeshTriangulation.vertices[i].z); } streamWriter.WriteLine("g pPlane1"); //索引 for (int i = 0; i < navMeshTriangulation.indices.Length; i++) { streamWriter.WriteLine("f " + (navMeshTriangulation.indices[i] + 1) + " " + (navMeshTriangulation.indices[i + 1] + 1) + " " + (navMeshTriangulation.indices[i + 2] + 1)); i = i + 3; } streamWriter.Flush(); streamWriter.Close(); AssetDatabase.Refresh(); Debug.Log("NavMesh Export Success"); }
public NavMeshInfo() { var triangles = NavMesh.CalculateTriangulation(); vertices = triangles.vertices; //顶点 indicesCount = vertices.Length; var indices = triangles.indices; //索引 if (indices.Length % 3 != 0) { Debug.LogError("顶点数量不对 不是3的倍数 :" + indices.Length); } else { for (int i = 0; i < indices.Length; i += 3) { var i1 = indices[i]; var i2 = indices[i + 1]; var i3 = indices[i + 2]; var p1 = vertices[i1]; var p2 = vertices[i2]; var p3 = vertices[i3]; segments.Add(new Segment3(p1, p2)); segments.Add(new Segment3(p2, p3)); segments.Add(new Segment3(p3, p1)); planes.Add(new Plane3(p1, p2, p3)); triangle3s.Add(new Triangle3(p1, p2, p3)); } } }
// Use this for initialization void Start() { UnityEngine.Random.InitState(0); verticalOffsetFinal = Vector3.up * VerticalOffset; CellList = new SortedCellList(); VoronoiNeighborLines = new List <LineRenderer>(); /// Cycling through all child objects, finding OffMeshLinks /// Hope is to connect our Cells together via the OffMeshLinks //foreach (Transform child in transform) //{ // OffMeshLink offMeshLink = child.GetComponent<OffMeshLink>(); // if (offMeshLink && offMeshLink.enabled) // { // NavMesh.areas // offMeshLink.area // } //} // Get all NavMesh information NavMeshTriangulation tris = NavMesh.CalculateTriangulation(); // Spawn vertex prefabs at the vertices of the NavMesh foreach (Vector3 vert in tris.vertices) { Instantiate(NavMeshVertPrefab, vert + verticalOffsetFinal, transform.rotation); } // Using the indicies of the NavMesh, create Triangles and call PoissonDiscDistribution with it to create // Voronoi regions for (int index = 0; index < tris.indices.Length; index += 3) { Triangle tri = new Triangle( tris.vertices[tris.indices[index + 0]], tris.vertices[tris.indices[index + 1]], tris.vertices[tris.indices[index + 2]], PoissonDotPrefab, LinePrefab, LineWidth ); NavMeshTris.Add(tri); PoissonDiscDistribution(tri, PoissonTolerance); } for (int i = 0; i < CellList.GetCount(); ++i) { GetNeighbors(CellList.GetCell(i)); } CellList.RaiseCells(verticalOffsetFinal); CellList.AssignIndices(); CellList.FindWallInfluence(GameObject.FindGameObjectsWithTag("Wall")); CellList.FindVisibilityInfluence(NavMeshTris); InfluenceMapModeText.GetComponent <ModeUI>().ModeChange(Mode); if (Mode == InfluenceMode.OpennessClosestWall) { CellList.ApplyWallInfluences(); } else if (Mode == InfluenceMode.VisibleToSpot) { CellList.ApplyVisibilityInfluences(); } }
// Update 1 time per second (only for debug, costs a lot of resources) // UNCOMMENT TO TEST STUFF //void Update() //{ // int dixiemes = Mathf.RoundToInt(Time.time * 10) % 10; // if (dixiemes == 0 && m_goBake) // { // m_goBake = false; // Debug.Log("BAKE"); // BakeNavMeshSurface(); // } // else if (dixiemes == 5 && !m_goBake) m_goBake = true; //} /// <summary> /// Function called by the "Calculer le passage" button /// </summary> public void BakeNavMeshSurface() { //desactivate all opening for calculBaking GameObject[] wallOpening = GameObject.FindGameObjectsWithTag("WallOpening"); foreach (GameObject item in wallOpening) { item.SetActive(false); } //Bake GetComponent <MeshFilter>().mesh = null; m_surface.BuildNavMesh(); var triangles = NavMesh.CalculateTriangulation(); var mesh = new Mesh(); mesh.vertices = triangles.vertices; mesh.triangles = triangles.indices; GetComponent <MeshFilter>().mesh = mesh; //Reactivate for visual all opening foreach (GameObject item in wallOpening) { item.SetActive(true); } }
public void ScanFromUnity() { Profiler.BeginSample("Scan"); var recast = GetFirstActiveRecastGraph(); // multi recast graph not supported if (recast == null) { Debug.LogError("Recast graph not found."); return; } var surface = GetNavMeshSurface(); if (surface == null) { Debug.LogError("NavMesh Surface invalid."); return; } if (!ConfigNavMeshSurface(recast, ref surface)) { Debug.LogError("Agent setting not found."); return; } surface.RemoveData(); surface.BuildNavMesh(); var unityNavMesh = NavMesh.CalculateTriangulation(); SerializeUnityNavMesh(unityNavMesh, ref recast); surface.RemoveData(); Profiler.EndSample(); }
public static Vector3 GetRandomLocation() { while (true) { NavMeshTriangulation navMeshData = NavMesh.CalculateTriangulation(); int maxIndices = navMeshData.indices.Length - 3; int firstVertexSelected = Random.Range(0, maxIndices); int secondVertexSelected = Random.Range(0, maxIndices); Vector3 point; Vector3 firstVertexPosition = navMeshData.vertices[navMeshData.indices[firstVertexSelected]]; Vector3 secondVertexPosition = navMeshData.vertices[navMeshData.indices[secondVertexSelected]]; if ((int)firstVertexPosition.x == (int)secondVertexPosition.x || (int)firstVertexPosition.z == (int)secondVertexPosition.z) { continue; } point = Vector3.Lerp(firstVertexPosition, secondVertexPosition, Random.Range(0.0f, 1f)); if (NavMesh.SamplePosition(point, out var hit, 2.0f, NavMesh.AllAreas)) { return(hit.position); } } }
static void Export() { Debug.Log("ExportNavMesh"); NavMeshTriangulation tmpNavMeshTriangulation = NavMesh.CalculateTriangulation(); //新建文件 string tmpPath = Application.dataPath + "/" + SceneManager.GetActiveScene().name + ".obj"; StreamWriter tmpStreamWriter = new StreamWriter(tmpPath); //顶点 for (int i = 0; i < tmpNavMeshTriangulation.vertices.Length; i++) { tmpStreamWriter.WriteLine("v " + tmpNavMeshTriangulation.vertices[i].x + " " + tmpNavMeshTriangulation.vertices[i].y + " " + tmpNavMeshTriangulation.vertices[i].z); } tmpStreamWriter.WriteLine("g pPlane1"); //索引 for (int i = 0; i < tmpNavMeshTriangulation.indices.Length;) { tmpStreamWriter.WriteLine("f " + (tmpNavMeshTriangulation.indices[i] + 1) + " " + (tmpNavMeshTriangulation.indices[i + 1] + 1) + " " + (tmpNavMeshTriangulation.indices[i + 2] + 1)); i = i + 3; } tmpStreamWriter.Flush(); tmpStreamWriter.Close(); Debug.Log("ExportNavMesh Success"); }
static void OnGizmo(Transform tf, GizmoType gt) { // only show navmesh while the window is visible // Gizmos.Draw is slow, so only do it when the user really needs it. // otherwise bigger games would be slow all the time. if (!visible) { return; } // rebuild if necessary if (!gizmesh || needsRebuild) { if (!UnityEditor.AI.NavMeshBuilder.isRunning) { RebuildGizmesh(NavMesh.CalculateTriangulation()); } } // draw if not empty if (gizmesh.vertices.Length > 0) { Gizmos.color = Color.cyan; if (drawMode == 0) { Gizmos.DrawWireMesh(gizmesh); } else if (drawMode == 1) { Gizmos.DrawMesh(gizmesh); Gizmos.DrawWireMesh(gizmesh); } } }
public void UpdateNavMesh() { ViveNavMesh mesh = (ViveNavMesh)target; Undo.RecordObject(mesh, "Update Navmesh Data"); NavMeshTriangulation tri = NavMesh.CalculateTriangulation(); Vector3[] verts = tri.vertices; int[] tris = tri.indices; int[] areas = tri.areas; int vert_size = verts.Length; int tri_size = tris.Length; RemoveMeshDuplicates(verts, tris, out vert_size, 0.01f); DewarpMesh(verts, mesh.DewarpingMethod, mesh.SampleRadius); CullNavmeshTriangulation(verts, tris, areas, p_area.intValue, mesh.IgnoreSlopedSurfaces, ref vert_size, ref tri_size); Mesh m = ConvertNavmeshToMesh(verts, tris, vert_size, tri_size); // Can't use SerializedProperties here because BorderPointSet doesn't derive from UnityEngine.Object mesh.SelectableMeshBorder = FindBorderEdges(m); serializedObject.Update(); p_mesh.objectReferenceValue = m; serializedObject.ApplyModifiedPropertiesWithoutUndo(); mesh.SelectableMesh = mesh.SelectableMesh; // Make sure that setter is called }
private void startbuildingMode() { buildingMode = true; rotationbar.SetActive(true); clickDetector.clearPopUps(); GameObject.Find("Terrain").GetComponent <Scene_Controller>().buildButton.SetActive(true); print("reset override cost"); overrideCost = null; NavMeshTriangulation triangulation = NavMesh.CalculateTriangulation(); GameObject meshBuilder = GameObject.Find("NavController"); meshBuilder.GetComponent <MeshRenderer>().enabled = true; //meshBuilder.AddComponent<MeshFilter>(); //meshBuilder.AddComponent<MeshRenderer>(); Mesh mesh = meshBuilder.GetComponent <MeshFilter>().mesh; mesh.Clear(); mesh.vertices = triangulation.vertices; mesh.triangles = triangulation.indices; Vector2[] uvs = new Vector2[triangulation.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(triangulation.vertices[i].x, triangulation.vertices[i].z); } mesh.uv = uvs; meshBuilder.GetComponent <MeshRenderer>().enabled = true; meshBuilder.GetComponent <MeshCollider>().sharedMesh = mesh; Time.timeScale = 0.1f; }
void Start() { m_Sound = GetComponent <Sound>(); NavMesh.AddNavMeshData(m_NavMeshData); NavMesh.CalculateTriangulation(); for (int i = 0; i < transform.childCount; ++i) { if (transform.GetChild(i).name.Contains("FreeCamRig")) { m_CameraRig = transform.GetChild(i).gameObject; break; } } m_EventList = new Dictionary <string, MethodInfo>(); foreach (string e in m_Events) { string eventName = e.Split(' ')[0]; string phaseName = e.Split(' ')[1]; m_EventList.Add(phaseName, this[eventName]); } LoadPhasesData(); NextPhase(); }
static int CalculateTriangulation(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 0); NavMeshTriangulation o = NavMesh.CalculateTriangulation(); LuaScriptMgr.PushValue(L, o); return(1); }
public static ref NativeArray <Edge> GetNativeEdges() { if (!_outsideEdgesNative.IsCreated) { CalculateEdges(NavMesh.CalculateTriangulation()); } return(ref _outsideEdgesNative); }