public static (float, float, float, float) SnapBounds(Extents1D currentExtents, float snappingStep)
        {
            if (!Snapping.BoundsSnappingActive)
            {
                return(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
            }

            // Snap current extents against the grid (we're in grid space, so simple snap)
            var snappedExtents = currentExtents;

            snappedExtents.min = SnappingUtility.SnapValue(snappedExtents.min, snappingStep);
            snappedExtents.max = SnappingUtility.SnapValue(snappedExtents.max, snappingStep);

            // Determine the offset relative to the current extents
            var snappedExtentsOffset  = currentExtents - snappedExtents;
            var quantized_min_extents = SnappingUtility.Quantize(snappedExtentsOffset.min);
            var quantized_max_extents = SnappingUtility.Quantize(snappedExtentsOffset.max);
            var abs_min_extents       = Mathf.Abs(quantized_min_extents);
            var abs_max_extents       = Mathf.Abs(quantized_max_extents);

            // Use the smallest distance as the best snap distance
            if (abs_min_extents < abs_max_extents)
            {
                return(abs_min_extents, snappedExtentsOffset.min, quantized_min_extents, quantized_max_extents);
            }
            else
            {
                return(abs_max_extents, snappedExtentsOffset.max, quantized_min_extents, quantized_max_extents);
            }
        }
Beispiel #2
0
        public                           Extents1D this[int index]
        {
            get
            {
                switch (index)
                {
                case 0: return(x);

                case 1: return(y);

                case 2: return(z);

                default: throw new ArgumentException("index must be 0,1 or 2");
                }
            }
            set
            {
                switch (index)
                {
                case 0: x = value; return;

                case 1: y = value; return;

                case 2: z = value; return;

                default: throw new ArgumentException("index must be 0,1 or 2");
                }
            }
        }
Beispiel #3
0
        public static float SnapDistanceExtents1D(Extents1D currentExtents, float snapping, float origin = 0.0f)
        {
            var snapMin  = SnapPoint1D(currentExtents.min, snapping, origin);
            var snapMax  = SnapPoint1D(currentExtents.max, snapping, origin);
            var deltaMin = snapMin - currentExtents.min;
            var deltaMax = snapMax - currentExtents.max;

            return((Mathf.Abs(deltaMin) < Mathf.Abs(deltaMax)) ? deltaMin : deltaMax);
        }
Beispiel #4
0
        public Vector3 SnapExtents1D(Extents1D currentExtents, Vector3 currentPosition, Vector3 slideOrigin, Vector3 slideDirection, float snappingStep, out SnapResult1D snapResult)
        {
            snapResult = SnapResult1D.None;

            var offsetPos      = currentPosition - slideOrigin;
            var offsetDistance = SnappingUtility.WorldPointToDistance(offsetPos, slideDirection);
            var currDistance   = offsetDistance - this.startOffset;
            var movedExtents   = currentExtents + offsetDistance;

            var snappedExtents = movedExtents;

            snappedExtents.min = SnappingUtility.SnapValue(movedExtents.min, snappingStep);
            snappedExtents.max = SnappingUtility.SnapValue(movedExtents.max, snappingStep);

            var snappedExtentsOffset = snappedExtents - movedExtents;
            var snappedPivot         = SnappingUtility.SnapValue(currDistance, snappingStep) - currDistance;

            if (!Snapping.BoundsSnappingActive && !Snapping.PivotSnappingActive)
            {
                return(currentPosition);
            }
            var abs_pivot             = Snapping.PivotSnappingActive  ? SnappingUtility.Quantize(Mathf.Abs(snappedPivot)) : float.PositiveInfinity;
            var abs_min_extents       = Snapping.BoundsSnappingActive ? SnappingUtility.Quantize(Mathf.Abs(snappedExtentsOffset.min)) : float.PositiveInfinity;
            var abs_max_extents       = Snapping.BoundsSnappingActive ? SnappingUtility.Quantize(Mathf.Abs(snappedExtentsOffset.max)) : float.PositiveInfinity;
            var snappedOffsetDistance = (abs_pivot < abs_min_extents && abs_pivot < abs_max_extents) ? snappedPivot : ((abs_min_extents < abs_max_extents) ? snappedExtentsOffset.min : snappedExtentsOffset.max);

            if (abs_min_extents <= abs_max_extents && abs_min_extents <= abs_pivot)
            {
                snapResult |= SnapResult1D.Min;
            }
            if (abs_max_extents <= abs_min_extents && abs_max_extents <= abs_pivot)
            {
                snapResult |= SnapResult1D.Max;
            }
            if (abs_pivot <= abs_min_extents && abs_pivot <= abs_max_extents)
            {
                snapResult |= SnapResult1D.Pivot;
            }

            min = slideOrigin + SnappingUtility.DistanceToWorldPoint(snappedExtents.min, slideDirection);
            max = slideOrigin + SnappingUtility.DistanceToWorldPoint(snappedExtents.max, slideDirection);

            var newOffset = offsetDistance + snappedOffsetDistance;

            if (Mathf.Abs(snappedOffsetDistance) > Mathf.Abs(offsetDistance))
            {
                newOffset = 0;
            }

            var snappedDistance = SnappingUtility.DistanceToWorldPoint(newOffset, slideDirection);
            var snappedPosition = (snappedDistance + slideOrigin);

            return(snappedPosition);
        }
Beispiel #5
0
 public void CalculateExtents(Matrix4x4 matrix, Vector3[] points)
 {
     this.slideExtents = GetExtentsOfPointArray(matrix, points, this.slideOrigin, this.slideDirection);
 }
Beispiel #6
0
 public static Extents1D SnapExtentsRay(Extents1D currentExtents, float snapping, Vector3 direction, Vector3 origin)
 {
     return(currentExtents + SnapDistanceExtentsRay(currentExtents, snapping, direction, origin));
 }
Beispiel #7
0
        public static float SnapDistanceExtentsRay(Extents1D currentExtents, float snapping, Vector3 direction, Vector3 origin)
        {
            var deltaOrigin = WorldPointToDistance(origin, direction);

            return(SnapDistanceExtents1D(currentExtents, snapping, deltaOrigin));
        }
Beispiel #8
0
 public static Extents1D SnapExtents1D(Extents1D currentExtents, float snapping, float origin = 0.0f)
 {
     return(currentExtents + SnapDistanceExtents1D(currentExtents, snapping, origin));
 }