public static Vector3 SnapPointToGrid(Vector3 point, CSGPlane plane, ref List <Vector3> snappingEdges, out CSGBrush snappedOnBrush, CSGBrush[] ignoreBrushes, bool ignoreAllBrushes = false) { snappedOnBrush = null; var toggleSnapping = SelectionUtility.IsSnappingToggled; var doSnapping = RealtimeCSG.CSGSettings.SnapToGrid ^ toggleSnapping; var snappedPoint = point; if (doSnapping) { snappedPoint = snappedPoint + RealtimeCSG.Grid.ForceSnapDeltaToGrid(MathConstants.zeroVector3, snappedPoint); snappedPoint = RealtimeCSG.Grid.PointFromGridSpace(RealtimeCSG.Grid.CubeProject(RealtimeCSG.Grid.PlaneToGridSpace(plane), RealtimeCSG.Grid.PointToGridSpace(snappedPoint))); // snap twice to get rid of some tiny movements caused by the projection in depth snappedPoint = snappedPoint + RealtimeCSG.Grid.ForceSnapDeltaToGrid(MathConstants.zeroVector3, snappedPoint); snappedPoint = RealtimeCSG.Grid.PointFromGridSpace(RealtimeCSG.Grid.CubeProject(RealtimeCSG.Grid.PlaneToGridSpace(plane), RealtimeCSG.Grid.PointToGridSpace(snappedPoint))); } else { snappedPoint = GeometryUtility.ProjectPointOnPlane(plane, snappedPoint); } //GeometryUtility.ProjectPointOnPlane(plane, snappedPoint); if (doSnapping && !ignoreAllBrushes) { return(GridUtility.SnapToWorld(plane, point, snappedPoint, ref snappingEdges, out snappedOnBrush, ignoreBrushes)); } return(snappedPoint); }
public static Vector3 SnapPointToGrid(Vector3 point, CSGPlane plane, ref List <Vector3> snappingEdges, out CSGBrush snappedOnBrush, CSGBrush[] ignoreBrushes, bool ignoreAllBrushes = false) { snappedOnBrush = null; // Note: relative snapping wouldn't make sense here since it's a single point that's being snapped and there is no relative movement var activeSnappingMode = RealtimeCSG.CSGSettings.ActiveSnappingMode; var snappedPoint = point; switch (activeSnappingMode) { case SnapMode.RelativeSnapping: // TODO: fixme case SnapMode.GridSnapping: { snappedPoint = snappedPoint + RealtimeCSG.CSGGrid.ForceSnapDeltaToGrid(MathConstants.zeroVector3, snappedPoint); snappedPoint = RealtimeCSG.CSGGrid.PointFromGridSpace(RealtimeCSG.CSGGrid.CubeProject(RealtimeCSG.CSGGrid.PlaneToGridSpace(plane), RealtimeCSG.CSGGrid.PointToGridSpace(snappedPoint))); // snap twice to get rid of some tiny movements caused by the projection in depth snappedPoint = snappedPoint + RealtimeCSG.CSGGrid.ForceSnapDeltaToGrid(MathConstants.zeroVector3, snappedPoint); snappedPoint = RealtimeCSG.CSGGrid.PointFromGridSpace(RealtimeCSG.CSGGrid.CubeProject(RealtimeCSG.CSGGrid.PlaneToGridSpace(plane), RealtimeCSG.CSGGrid.PointToGridSpace(snappedPoint))); if (!ignoreAllBrushes) { return(GridUtility.SnapToWorld(plane, point, snappedPoint, ref snappingEdges, out snappedOnBrush, ignoreBrushes)); } return(snappedPoint); } default: case SnapMode.None: { snappedPoint = GeometryUtility.ProjectPointOnPlane(plane, snappedPoint); return(snappedPoint); } } }