summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Graphs/Navmesh/TileMesh.cs
blob: e5a772a346c7ca455da78ff5ddedfda3ecb12ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Pathfinding.Util;

namespace Pathfinding.Graphs.Navmesh {
	/// <summary>
	/// A tile in a navmesh graph.
	///
	/// This is an intermediate representation used when building the navmesh, and also in some cases for serializing the navmesh to a portable format.
	///
	/// See: <see cref="NavmeshTile"/> for the representation used for pathfinding.
	/// </summary>
	public struct TileMesh {
		public int[] triangles;
		public Int3[] verticesInTileSpace;
		/// <summary>One tag per triangle</summary>
		public uint[] tags;

		/// <summary>Unsafe version of <see cref="TileMesh"/></summary>
		public struct TileMeshUnsafe {
			/// <summary>Three indices per triangle, of type int</summary>
			public Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer triangles;
			/// <summary>One vertex per triangle, of type Int3</summary>
			public Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer verticesInTileSpace;
			/// <summary>One tag per triangle, of type uint</summary>
			public Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer tags;

			public void Dispose () {
				triangles.Dispose();
				verticesInTileSpace.Dispose();
				tags.Dispose();
			}

			public TileMesh ToManaged () {
				return new TileMesh {
						   triangles = Memory.UnsafeAppendBufferToArray<int>(triangles),
						   verticesInTileSpace = Memory.UnsafeAppendBufferToArray<Int3>(verticesInTileSpace),
						   tags = Memory.UnsafeAppendBufferToArray<uint>(tags),
				};
			}
		}
	}
}