예제 #1
0
        private static void AddSnapPlane(ProductionAxis axis, string snapPlaneKey, Bounds volumeTerminus)
        {
            var normal = new Vector3();

            normal[(int)axis] = 1;
            ModuleProduction.SnapPlanes.Add(new KeyValuePair <string, Plane>(snapPlaneKey, new Plane(normal, volumeTerminus.max[(int)axis])));
        }
예제 #2
0
        /// <summary>
        /// Select all snap planes with normal matching a given axis and with name among given selector.
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="snapPlaneSelectors"></param>
        /// <returns></returns>
        private IEnumerable <Plane> SelectSnapPlanes(ProductionAxis axis, IEnumerable <string> snapPlaneSelectors)
        {
            var snaps = snapPlaneSelectors != null
                            ? ModuleProduction.SnapPlanes.Where(planeEntry => planeEntry.Value.normal[(int)axis] > 0 &&
                                                                snapPlaneSelectors.Any(selector => selector.Equals(planeEntry.Key))).Select(kvp => kvp.Value)
                            : new Plane[0];

            return(snaps);
        }
예제 #3
0
        /// <summary>
        /// Nudge bounds to match with the closest snap plane.
        /// </summary>
        /// <param name="axis"></param>
        /// <param name="selectedSnapPlanes">
        /// All selected snap planes have normal vector with a component matching axis of magnitude 1;
        /// eg if ProductionAxis.X then all planes have normal (+/-1, 0, 0)
        /// </param>
        /// <param name="proposedBounds"></param>
        /// <returns></returns>
        private Bounds SnapBoundsToSnapPlanes(ProductionAxis axis, IEnumerable <Plane> selectedSnapPlanes, Bounds proposedBounds)
        {
            var candidates = selectedSnapPlanes
                             .OrderBy(plane => Mathf.Abs(plane.distance - proposedBounds.max[(int)axis]))
                             .ToArray();

            if (candidates.Length > 0)
            {
                if (candidates[0].distance < proposedBounds.min[(int)axis])
                {
                    var newMax = proposedBounds.max;
                    newMax[(int)axis] = candidates[0].distance;

                    var newCenter = proposedBounds.center;
                    newCenter[(int)axis] = proposedBounds.min[(int)axis] + (newMax[(int)axis] - proposedBounds.min[(int)axis]) / 2f;

                    return(new Bounds(newCenter, newMax - proposedBounds.min));
                }
            }
            return(proposedBounds);
        }
예제 #4
0
        private CubeProductionScope SelectionScaleAndShift(SelectProduction selector, Quaternion rotation, Vector3 octant, ProductionAxis axis)
        {
            var s = rotation * Bounds.size;

            s[(int)axis] = selector.IsAbsolute
                           ? selector.FaceBreadth
                           : s[(int)axis] * selector.FaceBreadth;
            // after applying the rotation, we could have rotated into a negative space. so just abs it!
            s[0] = Mathf.Abs(s[0]);
            s[1] = Mathf.Abs(s[1]);
            s[2] = Mathf.Abs(s[2]);

            var offset = (Math.Abs((rotation * Bounds.size)[(int)axis]) - s[(int)axis]) / 2f;

            var c = Bounds.center - offset * (rotation * octant);

            if (s.x < 0f || s.y < 0f || s.z < 0f)
            {
                Debug.Log("Selecting to a negative size...");
            }
            return(new CubeProductionScope(new Bounds(c, s), rotation));
        }