示例#1
0
        private MyNavigationTriangle GetClosestNavigationTriangle(ref Vector3 point, ref float closestDistanceSq)
        {
            MyNavigationTriangle triangle = null;
            Vector3I             vectori  = Vector3I.Round((point + (this.m_voxelMap.PositionComp.GetPosition() - this.m_voxelMap.PositionLeftBottomCorner)) / this.m_cellSize);

            for (int i = 0; i < 8; i++)
            {
                Vector3I position = (Vector3I)(vectori + m_cornerOffsets[i]);
                if (this.m_processedCells.Contains(position))
                {
                    ulong          packedCellCoord = new MyCellCoord(0, position).PackId64();
                    MyIntervalList list            = this.m_higherLevelHelper.TryGetTriangleList(packedCellCoord);
                    if (list != null)
                    {
                        MyIntervalList.Enumerator enumerator = list.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            int current = enumerator.Current;
                            MyNavigationTriangle triangle2 = base.GetTriangle(current);
                            float num4 = Vector3.DistanceSquared(triangle2.Center, point);
                            if (num4 < closestDistanceSq)
                            {
                                closestDistanceSq = num4;
                                triangle          = triangle2;
                            }
                        }
                    }
                }
            }
            return(triangle);
        }
        public MyIntervalList TryGetTriangleList(ulong packedCellCoord)
        {
            MyIntervalList retval = null;

            m_triangleLists.TryGetValue(packedCellCoord, out retval);
            return(retval);
        }
示例#3
0
        public MyIntervalList TryGetTriangleList(ulong packedCellCoord)
        {
            MyIntervalList list = null;

            this.m_triangleLists.TryGetValue(packedCellCoord, out list);
            return(list);
        }
示例#4
0
        public void AddComponentTriangle(MyNavigationTriangle triangle, Vector3 center)
        {
            MyIntervalList list = this.m_components[this.m_componentNum];

            list.Add(triangle.Index);
            float num2 = 1f / ((float)list.Count);

            this.m_lastCellComponentCenters[this.m_componentNum] = (center * num2) + (this.m_lastCellComponentCenters[this.m_componentNum] * (1f - num2));
        }
示例#5
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 void AddComponentTriangle(MyNavigationTriangle triangle, Vector3 center)
        {
            Debug.Assert(m_componentOpen, "Adding a triangle to a component in TriangleComponentMapping, when no component is open!");

            int triIndex = triangle.Index;

            MyIntervalList triList = m_components[m_componentNum];

            triList.Add(triIndex);

            float t = 1.0f / triList.Count;

            m_lastCellComponentCenters[m_componentNum] = center * t + m_lastCellComponentCenters[m_componentNum] * (1.0f - t);
        }
        private MyNavigationTriangle GetClosestNavigationTriangle(ref Vector3 point, ref float closestDistanceSq)
        {
            // TODO: When point is completely away (according to BB), return null

            MyNavigationTriangle closestTriangle = null;

            // Convert from world matrix local coords to LeftBottomCorner-based coords
            Vector3 lbcPoint = point + (m_voxelMap.PositionComp.GetPosition() - m_voxelMap.PositionLeftBottomCorner);

            Vector3I closestCellCorner = Vector3I.Round(lbcPoint / m_cellSize);

            for (int i = 0; i < 8; ++i)
            {
                Vector3I cell = closestCellCorner + m_cornerOffsets[i];
                if (!m_processedCells.Contains(cell))
                {
                    continue;
                }

                MyCellCoord    coord       = new MyCellCoord(NAVMESH_LOD, cell);
                ulong          packedCoord = coord.PackId64();
                MyIntervalList triList     = m_higherLevelHelper.TryGetTriangleList(packedCoord);
                if (triList == null)
                {
                    continue;
                }

                foreach (var triIndex in triList)
                {
                    MyNavigationTriangle tri = GetTriangle(triIndex);

                    // TODO: Use triangle centers so far
                    float distSq = Vector3.DistanceSquared(tri.Center, point);
                    if (distSq < closestDistanceSq)
                    {
                        closestDistanceSq = distSq;
                        closestTriangle   = tri;
                    }
                }
            }

            return(closestTriangle);
        }
        private bool RemoveCell(Vector3I cell)
        {
            if (!MyFakes.REMOVE_VOXEL_NAVMESH_CELLS)
            {
                return(true);
            }

            Debug.Assert(m_processedCells.Contains(cell), "Removing a non-existent cell from the navmesh!");
            if (!m_processedCells.Contains(cell))
            {
                return(false);
            }

            MyTrace.Send(TraceWindow.Ai, "Removing cell " + cell);

            ProfilerShort.Begin("Removing navmesh links");
            MyVoxelPathfinding.CellId cellId = new MyVoxelPathfinding.CellId()
            {
                VoxelMap = m_voxelMap, Pos = cell
            };
            m_navmeshCoordinator.RemoveVoxelNavmeshLinks(cellId);
            ProfilerShort.End();

            ProfilerShort.Begin("Removing triangles");
            MyCellCoord    coord        = new MyCellCoord(NAVMESH_LOD, cell);
            ulong          packedCoord  = coord.PackId64();
            MyIntervalList triangleList = m_higherLevelHelper.TryGetTriangleList(packedCoord);

            if (triangleList != null)
            {
                foreach (var triangleIndex in triangleList)
                {
                    RemoveTerrainTriangle(GetTriangle(triangleIndex));
                }
                m_higherLevelHelper.ClearCachedCell(packedCoord);
            }
            ProfilerShort.End();

            Debug.Assert(m_processedCells.Contains(ref cell));
            m_processedCells.Remove(ref cell);

            return(triangleList != null);
        }
示例#9
0
        private bool RemoveCell(Vector3I cell)
        {
            if (!MyFakes.REMOVE_VOXEL_NAVMESH_CELLS)
            {
                return(true);
            }
            if (!this.m_processedCells.Contains(cell))
            {
                return(false);
            }
            if (MyFakes.LOG_NAVMESH_GENERATION)
            {
                MyCestmirPathfindingShorts.Pathfinding.VoxelPathfinding.DebugLog.LogCellRemoval(this, cell);
            }
            MyVoxelPathfinding.CellId cellId = new MyVoxelPathfinding.CellId {
                VoxelMap = this.m_voxelMap,
                Pos      = cell
            };
            this.m_navmeshCoordinator.RemoveVoxelNavmeshLinks(cellId);
            ulong          packedCellCoord = new MyCellCoord(0, cell).PackId64();
            MyIntervalList list            = this.m_higherLevelHelper.TryGetTriangleList(packedCellCoord);

            if (list != null)
            {
                MyIntervalList.Enumerator enumerator = list.GetEnumerator();
                while (true)
                {
                    if (!enumerator.MoveNext())
                    {
                        this.m_higherLevelHelper.ClearCachedCell(packedCellCoord);
                        break;
                    }
                    int current = enumerator.Current;
                    this.RemoveTerrainTriangle(base.GetTriangle(current));
                }
            }
            this.m_processedCells.Remove(ref cell);
            return(list != null);
        }