FilterLowHeightSpans() public method

public FilterLowHeightSpans ( uint voxelWalkableHeight, float cs, float ch, Vector3 min ) : void
voxelWalkableHeight uint
cs float
ch float
min UnityEngine.Vector3
return void
示例#1
0
 protected void BuildTileMesh(Voxelize vox, int x, int z)
 {
     float num = (float)this.tileSizeX * this.cellSize;
     float num2 = (float)this.tileSizeZ * this.cellSize;
     int num3 = Mathf.CeilToInt(this.characterRadius / this.cellSize);
     Vector3 min = this.forcedBounds.min;
     Vector3 max = this.forcedBounds.max;
     Bounds forcedBounds = default(Bounds);
     forcedBounds.SetMinMax(new Vector3((float)x * num, 0f, (float)z * num2) + min, new Vector3((float)(x + 1) * num + min.x, max.y, (float)(z + 1) * num2 + min.z));
     vox.borderSize = num3 + 3;
     forcedBounds.Expand(new Vector3((float)vox.borderSize, 0f, (float)vox.borderSize) * this.cellSize * 2f);
     vox.forcedBounds = forcedBounds;
     vox.width = this.tileSizeX + vox.borderSize * 2;
     vox.depth = this.tileSizeZ + vox.borderSize * 2;
     if (!this.useTiles && this.relevantGraphSurfaceMode == RecastGraph.RelevantGraphSurfaceMode.OnlyForCompletelyInsideTile)
     {
         vox.relevantGraphSurfaceMode = RecastGraph.RelevantGraphSurfaceMode.RequireForAll;
     }
     else
     {
         vox.relevantGraphSurfaceMode = this.relevantGraphSurfaceMode;
     }
     vox.minRegionSize = Mathf.RoundToInt(this.minRegionSize / (this.cellSize * this.cellSize));
     vox.Init();
     vox.CollectMeshes();
     vox.VoxelizeInput();
     vox.FilterLedges(vox.voxelWalkableHeight, vox.voxelWalkableClimb, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
     vox.FilterLowHeightSpans(vox.voxelWalkableHeight, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
     vox.BuildCompactField();
     vox.BuildVoxelConnections();
     vox.ErodeWalkableArea(num3);
     vox.BuildDistanceField();
     vox.BuildRegions();
     VoxelContourSet cset = new VoxelContourSet();
     vox.BuildContours(this.contourMaxError, 1, cset, 1);
     VoxelMesh mesh;
     vox.BuildPolyMesh(cset, 3, out mesh);
     for (int i = 0; i < mesh.verts.Length; i++)
     {
         mesh.verts[i] = mesh.verts[i] * 1000 * vox.cellScale + (Int3)vox.voxelOffset;
     }
     RecastGraph.NavmeshTile navmeshTile = this.CreateTile(vox, mesh, x, z);
     this.tiles[navmeshTile.x + navmeshTile.z * this.tileXCount] = navmeshTile;
 }
示例#2
0
		protected void BuildTileMesh (Voxelize vox, int x, int z) {
			
			AstarProfiler.StartProfile ("Build Tile");
			
			AstarProfiler.StartProfile ("Init");
			
			//World size of tile
			float tcsx = tileSizeX*cellSize;
			float tcsz = tileSizeZ*cellSize;
			
			int voxelCharacterRadius = Mathf.CeilToInt (characterRadius/cellSize);			
			
			Vector3 forcedBoundsMin = forcedBounds.min;
			Vector3 forcedBoundsMax = forcedBounds.max;
			
			Bounds bounds = new Bounds ();
			bounds.SetMinMax(new Vector3 (x*tcsx, 0, z*tcsz) + forcedBoundsMin,
						new Vector3 ((x+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (z+1)*tcsz + forcedBoundsMin.z)
				);
			vox.borderSize = voxelCharacterRadius + 3;
			
			//Expand borderSize voxels on each side
			bounds.Expand (new Vector3 (vox.borderSize,0,vox.borderSize)*cellSize*2);
			
			vox.forcedBounds = bounds;
			vox.width = tileSizeX + vox.borderSize*2;
			vox.depth = tileSizeZ + vox.borderSize*2;
			
			if (!useTiles && relevantGraphSurfaceMode == RelevantGraphSurfaceMode.OnlyForCompletelyInsideTile) {
				// This best reflects what the user would actually want
				vox.relevantGraphSurfaceMode = RelevantGraphSurfaceMode.RequireForAll;
			} else {
				vox.relevantGraphSurfaceMode = relevantGraphSurfaceMode;
			}
			
			vox.minRegionSize = Mathf.RoundToInt(minRegionSize / (cellSize*cellSize));
			
 #if ASTARDEBUG
			Debug.Log ("Building Tile " + x+","+z);
			Console.WriteLine ("Recast Graph -- Voxelizing");
#endif
			AstarProfiler.EndProfile ("Init");
			
			
			//Init voxelizer
			vox.Init ();
			
			vox.CollectMeshes ();
			
			vox.VoxelizeInput ();
			
			AstarProfiler.StartProfile ("Filter Ledges");
			
			if (importMode) {
				if (System.IO.File.Exists(Application.dataPath+"/tile."+x+"."+z)) {
					System.IO.FileStream fs = System.IO.File.OpenRead (Application.dataPath+"/tile."+x+"."+z);
					byte[] bytes = new byte[fs.Length];
					fs.Read (bytes,0,(int)fs.Length);
					VoxelArea tmpVox = new VoxelArea(vox.width,vox.depth);
					Pathfinding.Voxels.VoxelSerializeUtility.DeserializeVoxelAreaData (bytes,tmpVox);
					Pathfinding.Voxels.VoxelSerializeUtility.MergeVoxelAreaData(tmpVox,vox.voxelArea,vox.voxelWalkableClimb);
				}
			}
			if (exportMode) {
				System.IO.FileStream fs = System.IO.File.Create(Application.dataPath+"/tile."+x+"."+z);
				byte[] bytes = Pathfinding.Voxels.VoxelSerializeUtility.SerializeVoxelAreaData(vox.voxelArea);
				fs.Write(bytes,0,bytes.Length);
				fs.Close();
			}
			
			vox.FilterLedges (vox.voxelWalkableHeight, vox.voxelWalkableClimb, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
			
			AstarProfiler.EndProfile ("Filter Ledges");
			
			AstarProfiler.StartProfile ("Filter Low Height Spans");
			vox.FilterLowHeightSpans (vox.voxelWalkableHeight, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
			AstarProfiler.EndProfile ("Filter Low Height Spans");
			
			vox.BuildCompactField ();
			
			vox.BuildVoxelConnections ();
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Eroding");
#endif
			
			vox.ErodeWalkableArea (voxelCharacterRadius);
					
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Building Distance Field");
#endif
			
			vox.BuildDistanceField ();

#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Building Regions");
#endif
			
			vox.BuildRegions ();
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Building Contours");
#endif
			
			VoxelContourSet cset = new VoxelContourSet ();
			
			vox.BuildContours (contourMaxError,1,cset,Voxelize.RC_CONTOUR_TESS_WALL_EDGES);
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Building Poly Mesh");
#endif
			
			VoxelMesh mesh;
			
			vox.BuildPolyMesh (cset,3,out mesh);
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Building Nodes");
#endif
			
			//Vector3[] vertices = new Vector3[mesh.verts.Length];
			
			AstarProfiler.StartProfile ("Build Nodes");
			
			//matrix = Matrix4x4.TRS (vox.voxelOffset,Quaternion.identity,Int3.Precision*vox.cellScale);
			
			//Position the vertices correctly in the world
			for (int i=0;i<mesh.verts.Length;i++) {
				//Note the multiplication is Scalar multiplication of vectors
				mesh.verts[i] = ((mesh.verts[i]*Int3.Precision) * vox.cellScale) + (Int3)vox.voxelOffset;
				
				//Debug.DrawRay (matrix.MultiplyPoint3x4(vertices[i]),Vector3.up,Color.red);
			}
			
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Generating Nodes");
#endif
			
			//NavMeshGraph.GenerateNodes (this,vertices,mesh.tris, out _vectorVertices, out _vertices);
			
			/*NavmeshTile prevTile = tiles[x + z*tileXCount];
			if (prevTile != null) {
				for (int i=0;i<prevTile.nodes.Length;i++) {
					prevTile.nodes[i].v0 = -1;
					prevTile.nodes[i].v1 = -1;
					prevTile.nodes[i].v2 = -1;
				}
			}*/
			
			NavmeshTile tile = CreateTile (vox, mesh, x,z);
			tiles[tile.x + tile.z*tileXCount] = tile;
			
			AstarProfiler.EndProfile ("Build Nodes");
			
#if ASTARDEBUG
			Console.WriteLine ("Recast Graph -- Done");
#endif
			
			AstarProfiler.EndProfile ("Build Tile");
		}
示例#3
0
		protected void BuildTileMesh (Voxelize vox, int x, int z) {
			AstarProfiler.StartProfile("Build Tile");

			AstarProfiler.StartProfile("Init");

			//World size of tile
			float tcsx = tileSizeX*cellSize;
			float tcsz = tileSizeZ*cellSize;

			int voxelCharacterRadius = Mathf.CeilToInt(characterRadius/cellSize);

			Vector3 forcedBoundsMin = forcedBounds.min;
			Vector3 forcedBoundsMax = forcedBounds.max;

			var bounds = new Bounds();
			bounds.SetMinMax(new Vector3(x*tcsx, 0, z*tcsz) + forcedBoundsMin,
				new Vector3((x+1)*tcsx + forcedBoundsMin.x, forcedBoundsMax.y, (z+1)*tcsz + forcedBoundsMin.z)
				);
			vox.borderSize = voxelCharacterRadius + 3;

			//Expand borderSize voxels on each side
			bounds.Expand(new Vector3(vox.borderSize, 0, vox.borderSize)*cellSize*2);

			vox.forcedBounds = bounds;
			vox.width = tileSizeX + vox.borderSize*2;
			vox.depth = tileSizeZ + vox.borderSize*2;

			if (!useTiles && relevantGraphSurfaceMode == RelevantGraphSurfaceMode.OnlyForCompletelyInsideTile) {
				// This best reflects what the user would actually want
				vox.relevantGraphSurfaceMode = RelevantGraphSurfaceMode.RequireForAll;
			} else {
				vox.relevantGraphSurfaceMode = relevantGraphSurfaceMode;
			}

			vox.minRegionSize = Mathf.RoundToInt(minRegionSize / (cellSize*cellSize));

 #if ASTARDEBUG
			Debug.Log("Building Tile " + x+","+z);
			System.Console.WriteLine("Recast Graph -- Voxelizing");
#endif
			AstarProfiler.EndProfile("Init");


			//Init voxelizer
			vox.Init();

			vox.CollectMeshes();

			vox.VoxelizeInput();

			AstarProfiler.StartProfile("Filter Ledges");


			vox.FilterLedges(vox.voxelWalkableHeight, vox.voxelWalkableClimb, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);

			AstarProfiler.EndProfile("Filter Ledges");

			AstarProfiler.StartProfile("Filter Low Height Spans");
			vox.FilterLowHeightSpans(vox.voxelWalkableHeight, vox.cellSize, vox.cellHeight, vox.forcedBounds.min);
			AstarProfiler.EndProfile("Filter Low Height Spans");

			vox.BuildCompactField();

			vox.BuildVoxelConnections();

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Eroding");
#endif

			vox.ErodeWalkableArea(voxelCharacterRadius);

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Building Distance Field");
#endif

			vox.BuildDistanceField();

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Building Regions");
#endif

			vox.BuildRegions();

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Building Contours");
#endif

			var cset = new VoxelContourSet();

			vox.BuildContours(contourMaxError, 1, cset, Voxelize.RC_CONTOUR_TESS_WALL_EDGES);

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Building Poly Mesh");
#endif

			VoxelMesh mesh;

			vox.BuildPolyMesh(cset, 3, out mesh);

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Building Nodes");
#endif

			//Vector3[] vertices = new Vector3[mesh.verts.Length];

			AstarProfiler.StartProfile("Build Nodes");

			// Debug code
			//matrix = Matrix4x4.TRS (vox.voxelOffset,Quaternion.identity,Int3.Precision*vox.cellScale);

			//Position the vertices correctly in the world
			for (int i = 0; i < mesh.verts.Length; i++) {
				//Note the multiplication is Scalar multiplication of vectors
				mesh.verts[i] = ((mesh.verts[i]*Int3.Precision) * vox.cellScale) + (Int3)vox.voxelOffset;

				// Debug code
				//Debug.DrawRay (matrix.MultiplyPoint3x4(vertices[i]),Vector3.up,Color.red);
			}


#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Generating Nodes");
#endif

			NavmeshTile tile = CreateTile(vox, mesh, x, z);
			tiles[tile.x + tile.z*tileXCount] = tile;

			AstarProfiler.EndProfile("Build Nodes");

#if ASTARDEBUG
			System.Console.WriteLine("Recast Graph -- Done");
#endif

			AstarProfiler.EndProfile("Build Tile");
		}