Пример #1
0
 public NavTile(Vector2i location, int layer, NavPolyIdManager manager, NavPolyId baseRef)
 {
     this.Location  = location;
     this.Layer     = layer;
     this.idManager = manager;
     this.baseRef   = baseRef;
 }
Пример #2
0
        public string ToString(NavPolyIdManager manager)
        {
            int polyIndex, tileIndex, salt;

            manager.Decode(ref this, out polyIndex, out tileIndex, out salt);

            return("{ Poly: " + polyIndex + ", Tile: " + tileIndex + ", Salt: " + salt + "}");
        }
Пример #3
0
        private NavTile DeserializeMeshTile(JToken token, NavPolyIdManager manager, out NavPolyId refId)
        {
            refId = token["polyId"].ToObject<NavPolyId>(serializer);
            Vector2i location = token["location"].ToObject<Vector2i>(serializer);
            int layer = token["layer"].ToObject<int>(serializer);
            NavTile result = new NavTile(location, layer, manager, refId);

            result.Salt = token["salt"].ToObject<int>(serializer);
            result.Bounds = token["bounds"].ToObject<BBox3>(serializer);
            result.Polys = token["polys"].ToObject<NavPoly[]>(serializer);
            result.PolyCount = result.Polys.Length;
            result.Verts = token["verts"].ToObject<Vector3[]>(serializer);
            result.DetailMeshes = token["detailMeshes"].ToObject<PolyMeshDetail.MeshData[]>(serializer);
            result.DetailVerts = token["detailVerts"].ToObject<Vector3[]>(serializer);
            result.DetailTris = token["detailTris"].ToObject<PolyMeshDetail.TriangleData[]>(serializer);
            result.OffMeshConnections = token["offMeshConnections"].ToObject<OffMeshConnection[]>(serializer);
            result.OffMeshConnectionCount = result.OffMeshConnections.Length;
            result.BvNodeCount = token["bvNodeCount"].ToObject<int>(serializer);
            result.BvQuantFactor = token["bvQuantFactor"].ToObject<float>(serializer);
            result.WalkableClimb = token["walkableClimb"].ToObject<float>(serializer);

            var treeObject = (JObject) token["bvTree"];
            var nodes = treeObject.GetValue("nodes").ToObject<BVTree.Node[]>();

            result.BVTree = new BVTree(nodes);

            return result;
        }
Пример #4
0
 public NavTile(int x, int y, int layer, NavPolyIdManager manager, NavPolyId baseRef)
     : this(new Vector2i(x, y), layer, manager, baseRef)
 {
 }
Пример #5
0
        public TiledNavMesh(Vector3 origin, float tileWidth, float tileHeight, int maxTiles, int maxPolys)
        {
            this.origin = origin;
            this.tileWidth = tileWidth;
            this.tileHeight = tileHeight;
            this.maxTiles = maxTiles;
            this.maxPolys = maxPolys;

            //init tiles
            tileSet = new Dictionary<Vector2i, List<NavTile>>();
            tileRefs = new Dictionary<NavTile, NavPolyId>();
            tileList = new List<NavTile>();

            //init ID generator values
            int tileBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxTiles));
            int polyBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxPolys));

            //only allow 31 salt bits, since salt mask is calculated using 32-bit int and it will overflow
            int saltBits = Math.Min(31, 32 - tileBits - polyBits);

            //TODO handle this in a sane way/do we need this?
            if (saltBits < 10)
                return;

            idManager = new NavPolyIdManager(polyBits, tileBits, saltBits);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TiledNavMesh"/> class.
        /// </summary>
        /// <param name="data">The Navigation Mesh data</param>
        public TiledNavMesh(NavMeshBuilder data)
        {
            this.origin = data.Header.Bounds.Min;
            this.tileWidth = data.Header.Bounds.Max.X - data.Header.Bounds.Min.X;
            this.tileHeight = data.Header.Bounds.Max.Z - data.Header.Bounds.Min.Z;
            this.maxTiles = 1;
            this.maxPolys = data.Header.PolyCount;

            //init tiles
            tileSet = new Dictionary<Vector2i, List<NavTile>>();
            tileRefs = new Dictionary<NavTile, NavPolyId>();
            tileList = new List<NavTile>();

            //init ID generator values
            int tileBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxTiles));
            int polyBits = MathHelper.Log2(MathHelper.NextPowerOfTwo(maxPolys));

            //only allow 31 salt bits, since salt mask is calculated using 32-bit int and it will overflow
            int saltBits = Math.Min(31, 32 - tileBits - polyBits);

            //TODO handle this in a sane way/do we need this?
            if (saltBits < 10)
                return;

            idManager = new NavPolyIdManager(polyBits, tileBits, saltBits);

            AddTile(data);
        }