示例#1
0
        private void GenDrawMesh()
        {
            drawMeshs.Clear();
            var tile = tiledNavMesh.GetTileAt(0, 0, 0);

            if (null != tile)
            {
                for (int i = 0; i < tile.Polys.Length; i++)
                {
                    Mesh mesh = new Mesh();
                    {
                        List <UnityEngine.Vector3> vertices = new List <UnityEngine.Vector3>();
                        List <int> triangles = new List <int>();
                        for (int j = 0; j < settings.VertsPerPoly; ++j)
                        {
                            int vertIndex = tile.Polys[i].Verts[j];
                            if (0 == vertIndex)
                            {
                                break;
                            }
                            vertices.Add(ConvertVector3(tile.Verts[vertIndex]));
                        }
                        if (vertices.Count < 3)
                        {
                            continue;
                        }
                        mesh.vertices = vertices.ToArray();

                        int idx_1 = 1;
                        int idx_2 = 2;
                        while (idx_2 < mesh.vertices.Length)
                        {
                            triangles.Add(0);
                            triangles.Add(idx_1);
                            triangles.Add(idx_2);
                            ++idx_1;
                            ++idx_2;
                        }
                        mesh.triangles = triangles.ToArray();
                        Gizmos.color   = Color.green;
                        mesh.RecalculateNormals();
                        mesh.RecalculateBounds();
                    }
                    drawMeshs.Add(mesh);
                }
            }
        }
示例#2
0
		//void DebugRenderTileGrid( Camera camera )
		//{
		//   //make a tile grid
		//   {
		//      if( tileGridMeshVertices == null )
		//         CreateTileGridMesh( out tileGridMeshVertices, out tileGridMeshIndices, false );

		//      camera.DebugGeometry.Color = new ColorValue( 0f, 1f, 0f, .3f );
		//      camera.DebugGeometry.AddVertexIndexBuffer( tileGridMeshVertices, tileGridMeshIndices,
		//         Mat4.Identity, true, false );
		//   }

		//   //make a cell grid
		//   {
		//      if( cellGridMeshVertices == null )
		//         CreateTileGridMesh( out cellGridMeshVertices, out cellGridMeshIndices, true );

		//      camera.DebugGeometry.Color = new ColorValue( 1f, 0f, 0f, .3f );
		//      camera.DebugGeometry.AddVertexIndexBuffer( cellGridMeshVertices, cellGridMeshIndices,
		//         Mat4.Identity, true, false );
		//   }

		//   //add the bounds
		//   {
		//      camera.DebugGeometry.Color = new ColorValue( 0f, 1f, 1f, .6f );
		//      camera.DebugGeometry.AddBounds( new Bounds( boundsMin, boundsMax ) );
		//   }
		//}

		//void CreateTileGridMesh( out Vec3[] vertices, out int[] indices, bool cellSplit )
		//{
		//   int size;
		//   if( cellSplit )
		//      size = 128;
		//   else
		//      size = 64;

		//   vertices = new Vec3[ ( size + 1 ) * ( size + 1 ) ];
		//   {
		//      int vertexPosition = 0;
		//      for( int y = 0; y < size + 1; y++ )
		//      {
		//         for( int x = 0; x < size + 1; x++ )
		//         {
		//            xx;
		//            if( cellSplit )
		//            {
		//               vertices[ vertexPosition ] = new Vec3(
		//                  boundsMin.X + x * tileSize * cellSize,
		//                  boundsMax.Y - y * tileSize * cellSize,
		//                  boundsMin.Z + gridHeight * ( boundsMax.Z - boundsMin.Z ) );
		//            }
		//            else
		//            {
		//               vertices[ vertexPosition ] = new Vec3(
		//                  boundsMin.X + x * tileSize,
		//                  boundsMax.Y - y * tileSize,
		//                  boundsMin.Z + gridHeight * ( boundsMax.Z - boundsMin.Z ) );
		//            }
		//            vertexPosition++;
		//         }
		//      }
		//   }

		//   indices = new int[ size * size * 6 ];
		//   {
		//      int indexPosition = 0;
		//      for( int y = 0; y < size; y++ )
		//      {
		//         for( int x = 0; x < size; x++ )
		//         {
		//            indices[ indexPosition + 0 ] = ( size + 1 ) * y + x;
		//            indices[ indexPosition + 1 ] = ( size + 1 ) * y + x + 1;
		//            indices[ indexPosition + 2 ] = ( size + 1 ) * ( y + 1 ) + x + 1;
		//            indices[ indexPosition + 3 ] = ( size + 1 ) * ( y + 1 ) + x + 1;
		//            indices[ indexPosition + 4 ] = ( size + 1 ) * ( y + 1 ) + x;
		//            indices[ indexPosition + 5 ] = ( size + 1 ) * y + x;
		//            indexPosition += 6;
		//         }
		//      }
		//   }
		//}

		void GetDebugNavigationMeshGeometry( out Vector3F[] vertices )
		{
			//WaitForExecutionAllQueuedOperations();

			//lock( nativeLock )
			//{

			//!!!!one tile
			var tile = tiledNavMesh.GetTileAt( 0, 0, 0 );

			int capacity = 0;
			for( int nPoly = 0; nPoly < tile.PolyCount; nPoly++ )
			{
				var poly = tile.Polys[ nPoly ];
				if( poly.Area.IsWalkable )
				{
					for( int n = 2; n < poly.VertCount; n++ )
						capacity += 3;
				}
			}

			var result = new List<Vector3F>( capacity );

			for( int nPoly = 0; nPoly < tile.PolyCount; nPoly++ )
			{
				var poly = tile.Polys[ nPoly ];
				if( poly.Area.IsWalkable )
				{
					for( int n = 2; n < poly.VertCount; n++ )
					{
						int index0 = poly.Verts[ 0 ];
						int index1 = poly.Verts[ n - 1 ];
						int index2 = poly.Verts[ n ];

						result.Add( ToEngine( tile.Verts[ index0 ] ) );
						result.Add( ToEngine( tile.Verts[ index1 ] ) );
						result.Add( ToEngine( tile.Verts[ index2 ] ) );
					}
				}
			}

			vertices = result.ToArray();
		}