/// <summary> /// Returns the 3D point that the user most likely clicked on. /// Returns the closest intersection with a mesh, if possible. /// If useClosestMeshIfPossible is true it will otherwise returns the mesh vertex that is closest to the clicked 2D screen coordinate, if possible. /// Returns the unprojected position otherwise. /// Also returns the 2D point corresponding to the returned 3D point. /// </summary> /// <param name="position"> The point in screen coordinates to calculate the closest vertices for. </param> /// <param name="useClosestMeshIfPossible"> When true the closest vertex point to the clicked position will be used when no mesh is hit at the exact mouse cursor area.</param> public NearestPointInCamera CalculateMouseDownNearestPoint(Point position, bool useClosestMeshIfPossible) { if (mViewPort3D.FindNearest(position, out Point3D nearestPoint, out _, out _)) { return(new NearestPointInCamera(position, nearestPoint)); } if (useClosestMeshIfPossible) { ClosestVertexResult closestResult = ResultOfClosestPointHit2D(position); if (closestResult != null) { return(new NearestPointInCamera(closestResult.ClosestPointIn2D, closestResult.ClosestPoint)); } } Point3D?unprojectedPosition = mViewPort3D.UnProject(position); return(new NearestPointInCamera(position, unprojectedPosition)); }