public MyGridNavigationMesh(MyCubeGrid grid, MyNavmeshCoordinator coordinator, int triPrealloc = 32, Func <long> timestampFunction = null)
            : base(coordinator != null ? coordinator.Links : null, triPrealloc, timestampFunction)
        {
            m_connectionHelper      = new Dictionary <EdgeIndex, int>();
            m_smallTriangleRegistry = new Dictionary <Vector3I, List <int> >();
            m_cubeSet = new MyVector3ISet();

            m_coordinator = coordinator;

            m_static = false;
            if (grid != null)
            {
                m_higherLevel       = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
                m_higherLevelHelper = new MyGridHighLevelHelper(this, m_smallTriangleRegistry, new Vector3I(8, 8, 8));

                m_grid               = grid;
                grid.OnBlockAdded   += grid_OnBlockAdded;
                grid.OnBlockRemoved += grid_OnBlockRemoved;

                float   divisor = 1.0f / grid.CubeBlocks.Count;
                Vector3 center  = Vector3.Zero;

                foreach (var block in grid.CubeBlocks)
                {
                    OnBlockAddedInternal(block);
                    center += block.Position * grid.GridSize * divisor;
                }
            }
        }
Esempio n. 2
0
 public void MakeStatic()
 {
     if (!this.m_static)
     {
         this.m_static           = true;
         this.m_connectionHelper = null;
         this.m_cubeSet          = null;
     }
 }
        public void MakeStatic()
        {
            if (m_static == true)
            {
                return;
            }

            m_static           = true;
            m_connectionHelper = null;
            m_cubeSet          = null;
        }
Esempio n. 4
0
 public MyGridHighLevelHelper(MyGridNavigationMesh mesh, Dictionary <Vector3I, List <int> > triangleRegistry, Vector3I cellSize)
 {
     this.m_mesh                   = mesh;
     this.m_cellSize               = cellSize;
     this.m_packedCoord            = 0UL;
     this.m_currentCellConnections = new List <List <int> >();
     this.m_changedCells           = new MyVector3ISet();
     this.m_changedCubes           = new MyVector3ISet();
     this.m_triangleRegistry       = triangleRegistry;
     this.m_components             = new MyNavmeshComponents();
 }
        public MyGridHighLevelHelper(MyGridNavigationMesh mesh, Dictionary<Vector3I, List<int>> triangleRegistry, Vector3I cellSize)
        {
            m_mesh = mesh;
            m_cellSize = cellSize;
            m_packedCoord = 0;
            m_currentCellConnections = new List<List<int>>();

            m_changedCells = new MyVector3ISet();
            m_changedCubes = new MyVector3ISet();

            m_triangleRegistry = triangleRegistry;
            m_components = new MyNavmeshComponents();
        }
Esempio n. 6
0
 public MyVoxelHighLevelHelper(MyVoxelNavigationMesh mesh)
 {
     this.m_mesh                   = mesh;
     this.m_triangleList           = new MyIntervalList();
     this.m_triangleLists          = new Dictionary <ulong, MyIntervalList>();
     this.m_exploredCells          = new MyVector3ISet();
     this.m_navmeshComponents      = new MyNavmeshComponents();
     this.m_currentCellConnections = new List <List <ConnectionInfo> >();
     for (int i = 0; i < 8; i++)
     {
         this.m_currentCellConnections.Add(new List <ConnectionInfo>());
     }
 }
        public MyVoxelHighLevelHelper(MyVoxelNavigationMesh mesh)
        {
            m_mesh = mesh;
            m_triangleList = new MyIntervalList();

            m_triangleLists = new Dictionary<ulong, MyIntervalList>();
            m_exploredCells = new MyVector3ISet();
            m_navmeshComponents = new MyNavmeshComponents();

            m_currentCellConnections = new List<List<ConnectionInfo>>();
            for (int i = 0; i < 8; ++i)
            {
                m_currentCellConnections.Add(new List<ConnectionInfo>());
            }
        }
        public MyVoxelNavigationMesh(MyVoxelMap voxelMap, MyNavmeshCoordinator coordinator, Func <long> timestampFunction)
            : base(coordinator.Links, 16, timestampFunction)
        {
            m_voxelMap = voxelMap;
            m_cellSize = m_voxelMap.SizeInMetres / m_voxelMap.Storage.Geometry.CellsCount * (1 << NAVMESH_LOD);

            m_processedCells    = new MyVector3ISet();
            m_markedForAddition = new MyVector3ISet();
            m_toAdd             = new MyBinaryStructHeap <float, Vector3I>(128);

            m_connectionHelper   = new MyVoxelConnectionHelper();
            m_navmeshCoordinator = coordinator;
            m_higherLevel        = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
            m_higherLevelHelper  = new MyVoxelHighLevelHelper(this);

            m_debugCellEdges = new Dictionary <ulong, List <DebugDrawEdge> >();

            voxelMap.Storage.RangeChanged += OnStorageChanged;
        }
Esempio n. 9
0
 public MyVoxelNavigationMesh(MyVoxelBase voxelMap, MyNavmeshCoordinator coordinator, Func <long> timestampFunction) : base(coordinator.Links, 0x10, timestampFunction)
 {
     this.LimitAddingWeight         = GetWeight(25f);
     this.m_voxelMap                = voxelMap;
     m_staticVoxelMap               = this.m_voxelMap;
     this.m_processedCells          = new MyVector3ISet();
     this.m_cellsOnWayCoords        = new HashSet <ulong>();
     this.m_cellsOnWay              = new List <Vector3I>();
     this.m_primitivesOnPath        = new List <MyHighLevelPrimitive>(0x80);
     this.m_toAdd                   = new MyBinaryHeap <float, CellToAddHeapItem>(0x80);
     this.m_heapItemList            = new List <CellToAddHeapItem>();
     this.m_markedForAddition       = new MyVector3ISet();
     this.m_cellsToChange           = new LinkedList <Vector3I>();
     this.m_cellsToChangeSet        = new MyVector3ISet();
     this.m_connectionHelper        = new MyVoxelConnectionHelper();
     this.m_navmeshCoordinator      = coordinator;
     this.m_higherLevel             = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
     this.m_higherLevelHelper       = new MyVoxelHighLevelHelper(this);
     this.m_debugCellEdges          = new Dictionary <ulong, List <DebugDrawEdge> >();
     voxelMap.Storage.RangeChanged += new Action <Vector3I, Vector3I, MyStorageDataTypeFlags>(this.OnStorageChanged);
     this.m_maxCellCoord            = ((Vector3I)(this.m_voxelMap.Size / 8)) - Vector3I.One;
 }
Esempio n. 10
0
 public MyGridNavigationMesh(MyCubeGrid grid, MyNavmeshCoordinator coordinator, int triPrealloc = 0x20, Func <long> timestampFunction = null) : this(coordinator?.Links, triPrealloc, timestampFunction)
 {
     this.m_connectionHelper      = new Dictionary <EdgeIndex, int>();
     this.m_smallTriangleRegistry = new Dictionary <Vector3I, List <int> >();
     this.m_cubeSet     = new MyVector3ISet();
     this.m_coordinator = coordinator;
     this.m_static      = false;
     if (grid != null)
     {
         this.m_higherLevel       = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
         this.m_higherLevelHelper = new MyGridHighLevelHelper(this, this.m_smallTriangleRegistry, new Vector3I(8, 8, 8));
         this.m_grid          = grid;
         grid.OnBlockAdded   += new Action <MySlimBlock>(this.grid_OnBlockAdded);
         grid.OnBlockRemoved += new Action <MySlimBlock>(this.grid_OnBlockRemoved);
         float   num  = 1f / ((float)grid.CubeBlocks.Count);
         Vector3 zero = Vector3.Zero;
         foreach (MySlimBlock block in grid.CubeBlocks)
         {
             this.OnBlockAddedInternal(block);
             zero += (block.Position * grid.GridSize) * num;
         }
     }
 }
        public MyVoxelNavigationMesh(MyVoxelBase voxelMap, MyNavmeshCoordinator coordinator, Func<long> timestampFunction)
            : base(coordinator.Links, 16, timestampFunction)
        {
            m_voxelMap = voxelMap;
            m_cellSize = m_voxelMap.SizeInMetres / m_voxelMap.Storage.Geometry.CellsCount * (1 << NAVMESH_LOD);

            m_processedCells = new MyVector3ISet();
            m_markedForAddition = new MyVector3ISet();
            m_toAdd = new MyBinaryStructHeap<float, Vector3I>(128);

            m_connectionHelper = new MyVoxelConnectionHelper();
            m_navmeshCoordinator = coordinator;
            m_higherLevel = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
            m_higherLevelHelper = new MyVoxelHighLevelHelper(this);

            m_debugCellEdges = new Dictionary<ulong, List<DebugDrawEdge>>();

            voxelMap.Storage.RangeChanged += OnStorageChanged;
        }
        public void RemoveTooFarCells(List <Vector3D> importantPositions, float maxDistance, MyVector3ISet processedCells)
        {
            // remove too far high level info (if it isn't in processed cells)
            m_removedHLpackedCoord.Clear();
            foreach (var cell in m_exploredCells)
            {
                Vector3D worldCellCenterPos;
                Vector3I cellPos = cell;
                MyVoxelCoordSystems.GeometryCellCenterCoordToWorldPos(m_mesh.VoxelMapReferencePosition, ref cellPos, out worldCellCenterPos);

                // finding of distance from the nearest important object
                float dist = float.PositiveInfinity;
                foreach (Vector3D vec in importantPositions)
                {
                    float d = Vector3.RectangularDistance(vec, worldCellCenterPos);
                    if (d < dist)
                    {
                        dist = d;
                    }
                }

                if (dist > maxDistance && !processedCells.Contains(cellPos))
                {
                    MyCellCoord coord = new MyCellCoord(MyVoxelNavigationMesh.NAVMESH_LOD, cellPos);
                    m_removedHLpackedCoord.Add(coord.PackId64());
                }
            }
            foreach (ulong coord in m_removedHLpackedCoord)
            {
                TryClearCell(coord);
            }
        }
Esempio n. 13
0
 public void RemoveTooFarCells(List <Vector3D> importantPositions, float maxDistance, MyVector3ISet processedCells)
 {
     m_removedHLpackedCoord.Clear();
     foreach (Vector3I vectori in this.m_exploredCells)
     {
         Vector3D vectord;
         MyVoxelCoordSystems.GeometryCellCenterCoordToWorldPos(this.m_mesh.VoxelMapReferencePosition, ref vectori, out vectord);
         float positiveInfinity = float.PositiveInfinity;
         using (List <Vector3D> .Enumerator enumerator2 = importantPositions.GetEnumerator())
         {
             while (enumerator2.MoveNext())
             {
                 float num2 = Vector3.RectangularDistance(enumerator2.Current, (Vector3)vectord);
                 if (num2 < positiveInfinity)
                 {
                     positiveInfinity = num2;
                 }
             }
         }
         if ((positiveInfinity > maxDistance) && !processedCells.Contains(vectori))
         {
             m_removedHLpackedCoord.Add(new MyCellCoord(0, vectori).PackId64());
         }
     }
     foreach (ulong num3 in m_removedHLpackedCoord)
     {
         this.TryClearCell(num3);
     }
 }
        public void RemoveTooFarCells(List<Vector3D> importantPositions, float maxDistance, MyVector3ISet processedCells)
        {
            // remove too far high level info (if it isn't in processed cells)
            m_removedHLpackedCoord.Clear();
            foreach (var cell in m_exploredCells)
            {
                Vector3D worldCellCenterPos;
                Vector3I cellPos = cell;
                MyVoxelCoordSystems.GeometryCellCenterCoordToWorldPos(m_mesh.VoxelMapReferencePosition, ref cellPos, out worldCellCenterPos);

                // finding of distance from the nearest important object
                float dist = float.PositiveInfinity;
                foreach (Vector3D vec in importantPositions)
                {
                    float d = Vector3.RectangularDistance(vec, worldCellCenterPos);
                    if (d < dist)
                        dist = d;
                }

                if (dist > maxDistance && !processedCells.Contains(cellPos))
                {
                    MyCellCoord coord = new MyCellCoord(MyVoxelNavigationMesh.NAVMESH_LOD, cellPos);
                    m_removedHLpackedCoord.Add(coord.PackId64());
                }
            }
            foreach(ulong coord in m_removedHLpackedCoord)
            {
                TryClearCell(coord);
            }
        }
        public void MakeStatic()
        {
            if (m_static == true)
            {
                return;
            }

            m_static = true;
            m_connectionHelper = null;
            m_cubeSet = null;
        }
        public MyGridNavigationMesh(MyCubeGrid grid, MyNavmeshCoordinator coordinator, int triPrealloc = 32, Func<long> timestampFunction = null)
            : base(coordinator != null ? coordinator.Links : null, triPrealloc, timestampFunction)
        {
            m_connectionHelper = new Dictionary<EdgeIndex, int>();
            m_smallTriangleRegistry = new Dictionary<Vector3I, List<int>>();
            m_cubeSet = new MyVector3ISet();

            m_coordinator = coordinator;

            m_static = false;
            if (grid != null)
            {
                m_higherLevel = new MyHighLevelGroup(this, coordinator.HighLevelLinks, timestampFunction);
                m_higherLevelHelper = new MyGridHighLevelHelper(this, m_smallTriangleRegistry, new Vector3I(8, 8, 8));

                m_grid = grid;
                grid.OnBlockAdded += grid_OnBlockAdded;
                grid.OnBlockRemoved += grid_OnBlockRemoved;

                float divisor = 1.0f / grid.CubeBlocks.Count;
                Vector3 center = Vector3.Zero;

                foreach (var block in grid.CubeBlocks)
                {
                    OnBlockAddedInternal(block);
                    center += block.Position * grid.GridSize * divisor;
                }
            }
        }