public static void ShowTilePolyDetails(DbgRenderMesh renderMesh, Detour.dtNavMesh navMesh, int tileId) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; if (navMesh == null) { renderMesh.Rebuild(); return; } Detour.dtMeshTile tile = navMesh.getTile(tileId); if (tile == null) { Debug.LogError("RcdtcsUnityUtils.ShowTilePolyDetails : Tile " + tileId + " does not exist."); return; } int detailMeshCount = tile.detailMeshes.Length; for (int i = 0; i < detailMeshCount; ++i) { Detour.dtPolyDetail pd = tile.detailMeshes[i]; Detour.dtPoly poly = tile.polys[i]; Color col = Color.green; //new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); for (int j = 0; j < pd.triCount; ++j) { int tStart = (int)(pd.triBase + j) * 4; int[] vStarts = new int[3]; float[][] vSrc = new float[3][]; for (int k = 0; k < 3; ++k) { byte tk = tile.detailTris[tStart + k]; byte vCount = poly.vertCount; if (tk < vCount) { vStarts[k] = poly.verts[tk] * 3; vSrc[k] = tile.verts; } else { vStarts[k] = (int)(pd.vertBase + (tk - vCount)) * 3; vSrc[k] = tile.detailVerts; } } Vector3 a = new Vector3(vSrc[0][vStarts[0] + 0], vSrc[0][vStarts[0] + 1], vSrc[0][vStarts[0] + 2]); Vector3 b = new Vector3(vSrc[1][vStarts[1] + 0], vSrc[1][vStarts[1] + 1], vSrc[1][vStarts[1] + 2]); Vector3 c = new Vector3(vSrc[2][vStarts[2] + 0], vSrc[2][vStarts[2] + 1], vSrc[2][vStarts[2] + 2]); col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle(a, b, c, col)); } } renderMesh.Rebuild(); }
public void DebugViewUpdate() { if (m_CurrentDebugView != m_DebugView) { m_CurrentDebugView = m_DebugView; m_DbgRenderMesh.Clear(); switch (m_CurrentDebugView) { case DebugView.PolyMesh: RcdtcsUnityUtils.ShowRecastNavmesh(m_DbgRenderMesh, m_System.m_pmesh, m_System.m_cfg); break; case DebugView.NavMesh: RcdtcsUnityUtils.ShowTilePolyDetails(m_DbgRenderMesh, m_System.m_navMesh, 0); break; case DebugView.DetailMesh: RcdtcsUnityUtils.ShowRecastDetailMesh(m_DbgRenderMesh, m_System.m_dmesh); break; case DebugView.None: m_DbgRenderMesh.Rebuild(); break; case DebugView.ContourSet: RcdtcsUnityUtils.ShowContours(m_DbgRenderMesh, m_System.m_cset); break; case DebugView.RawContourSet: RcdtcsUnityUtils.ShowRawContours(m_DbgRenderMesh, m_System.m_cset); break; } } }
private void RecomputePath() { if (m_EndPos != Vector3.zero && m_StartPos != Vector3.zero) { m_DbgPathRenderer.Clear(); m_ComputedPathType = m_PathType; if (m_PathType == PathType.Smooth) { m_SmoothPath = RcdtcsUnityUtils.ComputeSmoothPath(m_System.m_navQuery, m_StartPos, m_EndPos); m_DbgPathRenderer.AddPath(m_SmoothPath.m_smoothPath, m_SmoothPath.m_nsmoothPath, 1.25f, Color.black, Color.white); } else if (m_PathType == PathType.Straight) { m_StraightPath = RcdtcsUnityUtils.ComputeStraightPath(m_System.m_navQuery, m_StartPos, m_EndPos); m_DbgPathRenderer.AddPath(m_StraightPath.m_straightPath, m_StraightPath.m_straightPathCount, 1.25f, Color.black, Color.white); } m_DbgPathRenderer.Rebuild(); } }
public void ShowRecastNavmesh(DbgRenderMesh renderMesh) { renderMesh.Clear(); int vbsize = RecastMove.get_vb_size(); vbsize = RecastMove.get_tri_vert_count() * 3; float[] vb = new float[vbsize]; //RecastMove.get_vb(vb); RecastMove.get_tri_vert_pos(vb); Dbgrendermesh.Clear(); for (int i = 0; i < vbsize;) { Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); Vector3 b = new Vector3(vb[i + 3], vb[i + 4], vb[i + 5]); Vector3 c = new Vector3(vb[i + 6], vb[i + 7], vb[i + 8]); Dbgrendermesh.AddTriangle(new DbgRenderTriangle(a, b, c, _vcolor)); i += 9; } renderMesh.Rebuild(); renderMesh.ComputeBounds(); _Bounds = new Bounds(renderMesh.m_BBCenter, renderMesh.m_Max - renderMesh.m_Min); int obsize = RecastMove.get_ob_count() * 3; float[] op = new float[obsize]; RecastMove.get_ob_info(op); for (int i = 0; i != obsize;) { if (first) { break; } first = true; Vector3 pos = new Vector3(op[i++], op[i++], op[i++]); // radius 1.0f, height 2.0f GameObject tempQie = AssetDatabase.LoadAssetAtPath("Assets/Models/obstacle_perfab/CubeOBBOX.prefab", typeof(GameObject)) as GameObject; GameObject tempQie2 = (GameObject)GameObject.Instantiate(tempQie); tempQie2.transform.position = pos; } }
public void ShowRecastNavmesh(DbgRenderMesh renderMesh) { renderMesh.Clear(); int vbsize = RecastMove.get_vb_size(); float[] vb = new float[vbsize]; RecastMove.get_vb(vb); Dbgrendermesh.Clear(); for (int i = 0; i < vbsize;) { Vector3 a = new Vector3(vb[i], vb[i + 1], vb[i + 2]); Vector3 b = new Vector3(vb[i + 3], vb[i + 4], vb[i + 5]); Vector3 c = new Vector3(vb[i + 6], vb[i + 7], vb[i + 8]); Dbgrendermesh.AddTriangle(new DbgRenderTriangle(a, b, c, _vcolor)); i += 9; } renderMesh.Rebuild(); }
public static void ShowRecastNavmesh(DbgRenderMesh renderMesh, PolyMeshAsset.PolyMeshData pmesh, Pathfinding.Config config) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; int npolys = pmesh.npolys; int nvp = pmesh.nvp; int[] tri = new int[3]; Vector3[] verts = new Vector3[3]; for (int i = 0; i < npolys; ++i) { int pIndex = i * nvp * 2; Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); for (int j = 2; j < nvp; ++j) { if (pmesh.polys[pIndex + j] == RC_MESH_NULL_IDX) { break; } tri[0] = pmesh.polys[pIndex]; tri[1] = pmesh.polys[pIndex + j - 1]; tri[2] = pmesh.polys[pIndex + j]; for (int k = 0; k < 3; ++k) { int vIndex = tri[k] * 3; verts[k].x = config.bmin[0] + pmesh.verts[vIndex + 0] * pmesh.cs; verts[k].y = config.bmin[1] + (pmesh.verts[vIndex + 1] + 1) * pmesh.ch + 0.1f; verts[k].z = config.bmin[2] + pmesh.verts[vIndex + 2] * pmesh.cs; } col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle(verts[0], verts[1], verts[2], col)); } } renderMesh.Rebuild(); }
public void LoadMap(string path) { m_ret = RecastHelper.load_map_bin(path); if (!m_ret) { Debug.LogWarning("load map bin failed"); return; } CreateDbgRenderMesh(); ///1 tri => 3 verts, 1 verts = 1 pos(vec3) => 3 float int vertCount = RecastHelper.get_mesh_vert_count(); float[] vertPos = new float[vertCount * 3]; RecastHelper.get_mesh_vert_pos(vertPos); Color col = new Color(); for (int i = 0; i < vertCount * 3; i += 9) { Vector3 a = new Vector3(vertPos[i + 0], vertPos[i + 1], vertPos[i + 2]); Vector3 b = new Vector3(vertPos[i + 3], vertPos[i + 4], vertPos[i + 5]); Vector3 c = new Vector3(vertPos[i + 6], vertPos[i + 7], vertPos[i + 8]); m_dbgRenderMesh.AddTriangle(new DbgRenderTriangle(a, b, c, col)); Vector3 triCenter = (a + b + c) / 3; float[] pos = new float[3]; pos[0] = triCenter.x; pos[1] = triCenter.y; pos[2] = triCenter.z; if (RecastHelper.is_valid_pos(pos)) { bornList.Add(triCenter); } } m_dbgRenderMesh.Rebuild(); BuildPathMap(); }
public static void ShowRecastDetailMesh(DbgRenderMesh renderMesh, PolyMeshAsset.PolyMeshDetailData dmesh) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; int nmeshes = dmesh.nmeshes; for (int i = 0; i < nmeshes; ++i) { Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); uint bverts = dmesh.meshes[i * 4]; uint btris = dmesh.meshes[i * 4 + 2]; uint ntris = dmesh.meshes[i * 4 + 3];; uint trisStart = btris * 4; for (uint j = 0; j < ntris; ++j) { Vector3[] verts = new Vector3[3]; for (int k = 0; k < 3; ++k) { int vertStart = (int)(bverts + dmesh.tris[trisStart + j * 4 + k]) * 3; verts[k].x = dmesh.verts[vertStart + 0]; verts[k].y = dmesh.verts[vertStart + 1]; verts[k].z = dmesh.verts[vertStart + 2]; } col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle( verts[0] , verts[1] , verts[2] , col)); } } renderMesh.Rebuild(); }
public static void ShowRecastNavmesh(DbgRenderMesh renderMesh, PolyMeshAsset.PolyMeshData pmesh, Pathfinding.Config config) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; int npolys = pmesh.npolys; int nvp = pmesh.nvp; int[] tri = new int[3]; Vector3[] verts = new Vector3[3]; for (int i = 0; i < npolys; ++i) { int pIndex = i * nvp * 2; Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); for (int j = 2; j < nvp; ++j) { if (pmesh.polys[pIndex + j] == RC_MESH_NULL_IDX) break; tri[0] = pmesh.polys[pIndex]; tri[1] = pmesh.polys[pIndex + j - 1]; tri[2] = pmesh.polys[pIndex + j]; for (int k = 0; k < 3; ++k) { int vIndex = tri[k] * 3; verts[k].x = config.bmin[0] + pmesh.verts[vIndex + 0] * pmesh.cs; verts[k].y = config.bmin[1] + (pmesh.verts[vIndex + 1] + 1) * pmesh.ch + 0.1f; verts[k].z = config.bmin[2] + pmesh.verts[vIndex + 2] * pmesh.cs; } col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle(verts[0], verts[1], verts[2], col)); } } renderMesh.Rebuild(); }
public static void ShowContours(DbgRenderMesh renderMesh, Recast.rcContourSet cset) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; float[] orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; for (int i = 0; i < cset.nconts; ++i) { Recast.rcContour c = cset.conts[i]; if (c.nverts == 0) continue; Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); Color bcol = VaryColor(col); for (int j = 0, k = c.nverts - 1; j < c.nverts; k = j++) { int vaStart = k * 4; int vbStart = j * 4; Color segCol = ((c.verts[vaStart + 3] & Recast.RC_AREA_BORDER) != 0) ? bcol : col; Vector3 start = new Vector3(orig[0] + c.verts[vaStart + 0] * cs, orig[1] + (c.verts[vaStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.verts[vaStart + 2] * cs); Vector3 end = new Vector3(orig[0] + c.verts[vbStart + 0] * cs, orig[1] + (c.verts[vbStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.verts[vbStart + 2] * cs); renderMesh.AddVerticalQuad(start, end, 0.5f, segCol); } } /* dd->begin(DU_DRAW_POINTS, 3.0f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); for (int j = 0; j < c.nverts; ++j) { const int* v = &c.verts[j*4]; float off = 0; unsigned int colv = color; if (v[3] & RC_BORDER_VERTEX) { colv = duRGBA(255,255,255,a); off = ch*2; } float fx = orig[0] + v[0]*cs; float fy = orig[1] + (v[1]+1+(i&1))*ch + off; float fz = orig[2] + v[2]*cs; fx,fy,fz, colv); } } */ renderMesh.Rebuild(); }
public void OnEnable() { _recastConfig = GameObject.FindObjectOfType <RecastConfig>(); _tileCache = new TileCache(navmeshData, _recastConfig); IntPtr h = createCrowd(MaxAgents, AgentMaxRadius, _tileCache.NavMeshHandle.Handle); _crowd = new HandleRef(this, h); ushort k = 0; var filters = _recastConfig.Filters.ToList(); filters.Reverse(); foreach (var filter in filters) { ushort include = 0; ushort exclude = 0; foreach (var incl in filter.Include) { include |= _recastConfig.Areas[incl.Name]; } foreach (var excl in filter.Exclude) { exclude |= _recastConfig.Areas[excl.Name]; } setFilter(_crowd.Handle, k, include, exclude); ++k; } randomSample = new float[3]; positions = new float[MaxAgents * 3]; velocities = new float[MaxAgents * 3]; targetStates = new byte[MaxAgents]; states = new byte[MaxAgents]; partial = new bool[MaxAgents]; Instance = this; if (RenderInGame) { mesh.Clear(); switch (Mode) { case RenderMode.POLYS: Assert.IsTrue(polymesh != null); RecastDebug.ShowRecastNavmesh(mesh, polymesh.PolyMesh, polymesh.config); break; case RenderMode.DETAIL_POLYS: Assert.IsTrue(polymesh != null); RecastDebug.ShowRecastDetailMesh(mesh, polymesh.PolyDetailMesh); break; case RenderMode.TILE_POLYS: for (int i = 0; i < navmeshData.header.numTiles; ++i) { RecastDebug.ShowTilePolyDetails(mesh, _tileCache.NavMeshHandle.Handle, i); } break; } //RecastDebug.RenderObstacles(_tileCache.TileCacheHandle.Handle); mesh.CreateGameObjects("RecastRenderer", material); mesh.Rebuild(); } }
public static void ShowTilePolyDetails(DbgRenderMesh renderMesh, IntPtr navMesh, int tileId) { UnityEngine.Random.seed = c_RandomSeed; if (navMesh == null) { renderMesh.Rebuild(); return; } IntPtr tilePtr = Pathfinding.Detour.getTile(navMesh, tileId); Pathfinding.MeshTile tile = (Pathfinding.MeshTile)Marshal.PtrToStructure(tilePtr, typeof(Pathfinding.MeshTile)); if (tile.header.ToInt32() == 0) { return; } Pathfinding.MeshHeader header = (Pathfinding.MeshHeader)Marshal.PtrToStructure(tile.header, typeof(Pathfinding.MeshHeader)); byte[] detailTris = new byte[header.detailTriCount * 4]; Marshal.Copy(tile.detailTris, detailTris, 0, header.detailTriCount * 4); float[] verts = new float[header.vertCount * 3]; Marshal.Copy(tile.verts, verts, 0, header.vertCount * 3); float[] detailVerts = new float[header.detailVertCount * 3]; Marshal.Copy(tile.detailVerts, detailVerts, 0, header.detailVertCount * 3); int polyDetailSize = Marshal.SizeOf(typeof(Pathfinding.PolyDetail)); int polySize = Marshal.SizeOf(typeof(Pathfinding.Poly)); int detailMeshCount = header.detailMeshCount; for (int i = 0; i < detailMeshCount; ++i) { Pathfinding.PolyDetail pd = (Pathfinding.PolyDetail)Marshal.PtrToStructure(new IntPtr(tile.detailMeshes.ToInt64() + (polyDetailSize * i)), typeof(Pathfinding.PolyDetail)); Pathfinding.Poly poly = (Pathfinding.Poly)Marshal.PtrToStructure(new IntPtr(tile.polys.ToInt64() + (polySize * i)), typeof(Pathfinding.Poly)); Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); for (int j = 0; j < pd.triCount; ++j) { int tStart = (int)(pd.triBase + j) * 4; int[] vStarts = new int[3]; float[][] vSrc = new float[3][]; for (int k = 0; k < 3; ++k) { byte tk = detailTris[tStart + k]; byte vCount = poly.vertCount; if (tk < vCount) { vStarts[k] = poly.verts[tk] * 3; vSrc[k] = verts; } else { vStarts[k] = (int)(pd.vertBase + (tk - vCount)) * 3; vSrc[k] = detailVerts; } } Vector3 a = new Vector3(vSrc[0][vStarts[0] + 0], vSrc[0][vStarts[0] + 1], vSrc[0][vStarts[0] + 2]); Vector3 b = new Vector3(vSrc[1][vStarts[1] + 0], vSrc[1][vStarts[1] + 1], vSrc[1][vStarts[1] + 2]); Vector3 c = new Vector3(vSrc[2][vStarts[2] + 0], vSrc[2][vStarts[2] + 1], vSrc[2][vStarts[2] + 2]); col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle(a, b, c, col)); } } renderMesh.Rebuild(); }
public static void ShowContours(DbgRenderMesh renderMesh, Recast.rcContourSet cset) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; float[] orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; for (int i = 0; i < cset.nconts; ++i) { Recast.rcContour c = cset.conts[i]; if (c.nverts == 0) { continue; } Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); Color bcol = VaryColor(col); for (int j = 0, k = c.nverts - 1; j < c.nverts; k = j++) { int vaStart = k * 4; int vbStart = j * 4; Color segCol = ((c.verts[vaStart + 3] & Recast.RC_AREA_BORDER) != 0) ? bcol : col; Vector3 start = new Vector3(orig[0] + c.verts[vaStart + 0] * cs, orig[1] + (c.verts[vaStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.verts[vaStart + 2] * cs); Vector3 end = new Vector3(orig[0] + c.verts[vbStart + 0] * cs, orig[1] + (c.verts[vbStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.verts[vbStart + 2] * cs); renderMesh.AddVerticalQuad(start, end, 0.5f, segCol); } } /* * dd->begin(DU_DRAW_POINTS, 3.0f); * * for (int i = 0; i < cset.nconts; ++i) * { * const rcContour& c = cset.conts[i]; * unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); * for (int j = 0; j < c.nverts; ++j) * { * const int* v = &c.verts[j*4]; * float off = 0; * unsigned int colv = color; * if (v[3] & RC_BORDER_VERTEX) * { * colv = duRGBA(255,255,255,a); * off = ch*2; * } * * float fx = orig[0] + v[0]*cs; * float fy = orig[1] + (v[1]+1+(i&1))*ch + off; * float fz = orig[2] + v[2]*cs; * fx,fy,fz, colv); * } * } */ renderMesh.Rebuild(); }
public static void ShowRawContours(DbgRenderMesh renderMesh, Recast.rcContourSet cset) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; float[] orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; for (int i = 0; i < cset.nconts; ++i) { Recast.rcContour c = cset.conts[i]; if (c.nrverts == 0) { continue; } Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); int triStartIndex = renderMesh.GetTriangleCount(); Vector3 start = new Vector3(orig[0] + c.rverts[0] * cs, orig[1] + (c.rverts[1] + 1 + (i & 1)) * ch, orig[2] + c.rverts[2] * cs); Vector3 a = Vector3.zero; Vector3 b = start; for (int j = 1; j < c.nrverts; ++j) { a = b; int vStart = j * 4; b = new Vector3(orig[0] + c.rverts[vStart + 0] * cs, orig[1] + (c.rverts[vStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.rverts[vStart + 2] * cs); if (j > 0) { renderMesh.AddVerticalQuad(a, b, 0.5f, col); } } // Loop last segment. renderMesh.AddVerticalQuad(b, start, 0.5f, col); int triEndIndex = renderMesh.GetTriangleCount(); Vector3 labelPos = renderMesh.GetBoundingBoxTop(triStartIndex, triEndIndex); renderMesh.AddLabel(labelPos, "contour " + i + "\nReg: " + c.reg + "\nnrverts:" + c.nrverts + "\nnverts:" + c.nverts); } /* * dd->end(); * * dd->begin(DU_DRAW_POINTS, 2.0f); * * for (int i = 0; i < cset.nconts; ++i) * { * const rcContour& c = cset.conts[i]; * unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); * * for (int j = 0; j < c.nrverts; ++j) * { * const int* v = &c.rverts[j*4]; * float off = 0; * unsigned int colv = color; * if (v[3] & RC_BORDER_VERTEX) * { * colv = duRGBA(255,255,255,a); * off = ch*2; * } * * float fx = orig[0] + v[0]*cs; * float fy = orig[1] + (v[1]+1+(i&1))*ch + off; * float fz = orig[2] + v[2]*cs; * fx,fy,fz, colv); * } * } * dd->end(); */ renderMesh.Rebuild(); }
public static void ShowRecastDetailMesh(DbgRenderMesh renderMesh, PolyMeshAsset.PolyMeshDetailData dmesh) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; int nmeshes = dmesh.nmeshes; for (int i = 0; i < nmeshes; ++i) { Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); uint bverts = dmesh.meshes[i * 4]; uint btris = dmesh.meshes[i * 4 + 2]; uint ntris = dmesh.meshes[i * 4 + 3]; ; uint trisStart = btris * 4; for (uint j = 0; j < ntris; ++j) { Vector3[] verts = new Vector3[3]; for (int k = 0; k < 3; ++k) { int vertStart = (int)(bverts + dmesh.tris[trisStart + j * 4 + k]) * 3; verts[k].x = dmesh.verts[vertStart + 0]; verts[k].y = dmesh.verts[vertStart + 1]; verts[k].z = dmesh.verts[vertStart + 2]; } col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle( verts[0] , verts[1] , verts[2] , col)); } } renderMesh.Rebuild(); }
public static void ShowTilePolyDetails(DbgRenderMesh renderMesh, IntPtr navMesh, int tileId) { UnityEngine.Random.seed = c_RandomSeed; if (navMesh == null) { renderMesh.Rebuild(); return; } IntPtr tilePtr = Pathfinding.Detour.getTile(navMesh, tileId); Pathfinding.MeshTile tile = (Pathfinding.MeshTile)Marshal.PtrToStructure(tilePtr, typeof(Pathfinding.MeshTile)); if (tile.header.ToInt32() == 0) { return; } Pathfinding.MeshHeader header = (Pathfinding.MeshHeader)Marshal.PtrToStructure(tile.header, typeof(Pathfinding.MeshHeader)); byte[] detailTris = new byte[header.detailTriCount * 4]; Marshal.Copy(tile.detailTris, detailTris, 0, header.detailTriCount * 4); float[] verts = new float[header.vertCount * 3]; Marshal.Copy(tile.verts, verts, 0, header.vertCount * 3); float[] detailVerts = new float[header.detailVertCount * 3]; Marshal.Copy(tile.detailVerts, detailVerts, 0, header.detailVertCount * 3); int polyDetailSize = Marshal.SizeOf(typeof(Pathfinding.PolyDetail)); int polySize = Marshal.SizeOf(typeof(Pathfinding.Poly)); int detailMeshCount = header.detailMeshCount; for (int i = 0; i < detailMeshCount; ++i) { Pathfinding.PolyDetail pd = (Pathfinding.PolyDetail)Marshal.PtrToStructure(new IntPtr(tile.detailMeshes.ToInt64() + (polyDetailSize * i)), typeof(Pathfinding.PolyDetail)); Pathfinding.Poly poly = (Pathfinding.Poly)Marshal.PtrToStructure(new IntPtr(tile.polys.ToInt64() + (polySize * i)), typeof(Pathfinding.Poly)); Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); for (int j = 0; j < pd.triCount; ++j) { int tStart = (int)(pd.triBase + j) * 4; int[] vStarts = new int[3]; float[][] vSrc = new float[3][]; for (int k = 0; k < 3; ++k) { byte tk = detailTris[tStart + k]; byte vCount = poly.vertCount; if (tk < vCount) { vStarts[k] = poly.verts[tk] * 3; vSrc[k] = verts; } else { vStarts[k] = (int)(pd.vertBase + (tk - vCount)) * 3; vSrc[k] = detailVerts; } } Vector3 a = new Vector3(vSrc[0][vStarts[0] + 0], vSrc[0][vStarts[0] + 1], vSrc[0][vStarts[0] + 2]); Vector3 b = new Vector3(vSrc[1][vStarts[1] + 0], vSrc[1][vStarts[1] + 1], vSrc[1][vStarts[1] + 2]); Vector3 c = new Vector3(vSrc[2][vStarts[2] + 0], vSrc[2][vStarts[2] + 1], vSrc[2][vStarts[2] + 2]); col = VaryColor(col); renderMesh.AddTriangle(new DbgRenderTriangle(a, b, c, col)); } } renderMesh.Rebuild(); }
public static void ShowRawContours(DbgRenderMesh renderMesh, Recast.rcContourSet cset) { renderMesh.Clear(); UnityEngine.Random.seed = c_RandomSeed; float[] orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; for (int i = 0; i < cset.nconts; ++i) { Recast.rcContour c = cset.conts[i]; if (c.nrverts == 0) { continue; } Color col = new Color(UnityEngine.Random.value, UnityEngine.Random.value, UnityEngine.Random.value); int triStartIndex = renderMesh.GetTriangleCount(); Vector3 start = new Vector3(orig[0] + c.rverts[0] * cs, orig[1] + (c.rverts[1] + 1 + (i & 1)) * ch, orig[2] + c.rverts[2] * cs); Vector3 a = Vector3.zero; Vector3 b = start; for (int j = 1; j < c.nrverts; ++j) { a = b; int vStart = j * 4; b = new Vector3(orig[0] + c.rverts[vStart + 0] * cs, orig[1] + (c.rverts[vStart + 1] + 1 + (i & 1)) * ch, orig[2] + c.rverts[vStart + 2] * cs); if (j > 0) { renderMesh.AddVerticalQuad(a, b, 0.5f, col); } } // Loop last segment. renderMesh.AddVerticalQuad(b, start, 0.5f, col); int triEndIndex = renderMesh.GetTriangleCount(); Vector3 labelPos = renderMesh.GetBoundingBoxTop(triStartIndex, triEndIndex); renderMesh.AddLabel(labelPos, "contour " + i + "\nReg: " + c.reg + "\nnrverts:" + c.nrverts + "\nnverts:" + c.nverts); } /* dd->end(); dd->begin(DU_DRAW_POINTS, 2.0f); for (int i = 0; i < cset.nconts; ++i) { const rcContour& c = cset.conts[i]; unsigned int color = duDarkenCol(duIntToCol(c.reg, a)); for (int j = 0; j < c.nrverts; ++j) { const int* v = &c.rverts[j*4]; float off = 0; unsigned int colv = color; if (v[3] & RC_BORDER_VERTEX) { colv = duRGBA(255,255,255,a); off = ch*2; } float fx = orig[0] + v[0]*cs; float fy = orig[1] + (v[1]+1+(i&1))*ch + off; float fz = orig[2] + v[2]*cs; fx,fy,fz, colv); } } dd->end(); */ renderMesh.Rebuild(); }