public void UpdateVoxelNavmeshCellHighLevelLinks(MyVoxelPathfinding.CellId cellId)
        {
            // Make sure links are where they should be
            List <MyNavigationPrimitive> linkedTriangles = null;

            if (m_voxelLinkDictionary.TryGetValue(cellId, out linkedTriangles))
            {
                MyNavigationPrimitive hlPrimitive1 = null;
                MyNavigationPrimitive hlPrimitive2 = null;

                foreach (var primitive in linkedTriangles)
                {
                    hlPrimitive1 = primitive.GetHighLevelPrimitive();

                    List <MyNavigationPrimitive> otherLinkedPrimitives = null;
                    otherLinkedPrimitives = m_links.GetLinks(primitive);
                    if (otherLinkedPrimitives != null)
                    {
                        foreach (var otherPrimitive in otherLinkedPrimitives)
                        {
                            hlPrimitive2 = otherPrimitive.GetHighLevelPrimitive();
                            m_highLevelLinks.AddLink(hlPrimitive1, hlPrimitive2, onlyIfNotPresent: true);
                        }
                    }
                }
            }

            // CH: TODO: Make sure that links are not where they should not be
        }
        // This is an old version of the function
        public void TryAddVoxelNavmeshLinks(MyNavigationTriangle addedPrimitive, MyVoxelPathfinding.CellId cellId, List <MyGridPathfinding.CubeId> linkCandidates)
        {
            ProfilerShort.Begin("TryAddVoxelNavmeshLinks");

            m_tmpNavTris.Clear();
            foreach (var candidate in linkCandidates)
            {
                // First, find closest navigation triangle from the given candidate cube
                ProfilerShort.Begin("Find closest grid nav tri");
                m_gridPathfinding.GetCubeTriangles(candidate, m_tmpNavTris);

                double closestDistSq = double.MaxValue;
                MyNavigationTriangle closestGridTri = null;

                foreach (var tri in m_tmpNavTris)
                {
                    Vector3D posDiff = addedPrimitive.WorldPosition - tri.WorldPosition;
                    if (MyPerGameSettings.NavmeshPresumesDownwardGravity)
                    {
                        if (Math.Abs(posDiff.Y) < 0.3)
                        {
                            if (posDiff.LengthSquared() < closestDistSq)
                            {
                                closestDistSq  = posDiff.LengthSquared();
                                closestGridTri = tri;
                            }
                        }
                    }
                }
                ProfilerShort.End();

                if (closestGridTri != null)
                {
                    bool createLink    = true;
                    var  existingLinks = m_links.GetLinks(closestGridTri);
                    List <MyNavigationPrimitive> existingCellLinks = null;
                    m_voxelLinkDictionary.TryGetValue(cellId, out existingCellLinks);

                    if (existingLinks != null)
                    {
                        m_tmpNavPrims.Clear();
                        CollectClosePrimitives(addedPrimitive, m_tmpNavPrims, 2);
                        for (int i = 0; i < m_tmpNavPrims.Count; ++i)
                        {
                            if (existingLinks.Contains(m_tmpNavPrims[i]) && existingCellLinks != null && existingCellLinks.Contains(m_tmpNavPrims[i]))
                            {
                                double existingDistSq = (m_tmpNavPrims[i].WorldPosition - closestGridTri.WorldPosition).LengthSquared();
                                if (existingDistSq < closestDistSq)
                                {
                                    createLink = false;
                                    break;
                                }
                                else
                                {
                                    m_links.RemoveLink(closestGridTri, m_tmpNavPrims[i]);
                                    if (m_links.GetLinkCount(m_tmpNavPrims[i]) == 0)
                                    {
                                        RemoveVoxelLinkFromDictionary(cellId, m_tmpNavPrims[i]);
                                    }
                                    DecreaseGridLinkCounter(candidate);
                                    continue;
                                }
                            }
                        }
                        m_tmpNavPrims.Clear();
                    }

                    if (createLink)
                    {
                        m_links.AddLink(addedPrimitive, closestGridTri);
                        SaveVoxelLinkToDictionary(cellId, addedPrimitive);
                        IncreaseGridLinkCounter(candidate);
                    }
                }

                m_tmpNavTris.Clear();
            }

            ProfilerShort.End();
        }