public bool DragUpdated(Transform transformInInspector, Rect selectionRect)
        {
            try
            {
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                hoverBrushSurface = null;
                hoverParent       = (transformInInspector == null) ? null : transformInInspector.parent;
                hoverSiblingIndex = (transformInInspector == null) ? int.MaxValue : transformInInspector.transform.GetSiblingIndex();

                float middle = (selectionRect.yMax + selectionRect.yMin) * 0.5f;
                if (Event.current.mousePosition.y > middle)
                {
                    hoverSiblingIndex++;
                }

                hoverRotation = MathConstants.identityQuaternion;
                hoverPosition = MathConstants.zeroVector3;
                haveNoParent  = true;
                return(true);
            }
            finally
            {
                if (!UpdateLoop.IsActive())
                {
                    UpdateLoop.ResetUpdateRoutine();
                }
            }
        }
        public void Reset()
        {
            CleanUp();
            hoverBrushSurface = null;
            dragGameObjects   = null;

            hoverPosition     = MathConstants.zeroVector3;
            hoverRotation     = MathConstants.identityQuaternion;
            hoverParent       = null;
            hoverSiblingIndex = int.MaxValue;
        }
Пример #3
0
        public override bool DragUpdated()
        {
            //Debug.Log("DragUpdated");
            //InternalCSGModelManager.skipRefresh = true;
            try
            {
                DisableVisualObjects();
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                var intersection = SceneQueryUtility.FindMeshIntersection(Event.current.mousePosition);
                var normal       = intersection.plane.normal;

                hoverPosition     = intersection.worldIntersection;
                hoverParent       = SelectionUtility.FindParentToAssignTo(intersection);
                hoverBrushSurface = intersection.brush != null ? new SelectedBrushSurface(intersection.brush, intersection.surfaceIndex) : null;
                hoverRotation     = SelectionUtility.FindDragOrientation(normal, sourceSurfaceAlignment, destinationSurfaceAlignment);
                haveNoParent      = (hoverParent == null);
                hoverSiblingIndex = int.MaxValue;

                RealtimeCSG.Grid.SetForcedGrid(intersection.plane);

                var toggleSnapping = (Event.current.modifiers & EventModifiers.Control) == EventModifiers.Control;
                var doSnapping     = RealtimeCSG.CSGSettings.SnapToGrid ^ toggleSnapping;
                if (doSnapping)
                {
                    var localPoints = new Vector3[8];
                    var localPlane  = intersection.plane;
                    for (var i = 0; i < localPoints.Length; i++)
                    {
                        localPoints[i] = GeometryUtility.ProjectPointOnPlane(localPlane, (hoverRotation * projectedBounds[i]) + hoverPosition);
                    }

                    hoverPosition += RealtimeCSG.Grid.SnapDeltaToGrid(MathConstants.zeroVector3, localPoints);
                }
                hoverPosition = GeometryUtility.ProjectPointOnPlane(intersection.plane, hoverPosition) + (normal * 0.01f);

                EnableVisualObjects();
                return(true);
            }
            finally
            {
                if (!SceneViewEventHandler.IsActive())
                {
                    SceneViewEventHandler.ResetUpdateRoutine();
                }
            }
        }
        public bool DragUpdated(SceneView sceneView)
        {
            try
            {
                DisableVisualObjects();
                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                var camera       = sceneView.camera;
                var intersection = SceneQueryUtility.FindMeshIntersection(camera, Event.current.mousePosition);
                var normal       = intersection.worldPlane.normal;

                hoverPosition     = intersection.worldIntersection;
                hoverParent       = SelectionUtility.FindParentToAssignTo(intersection);
                hoverBrushSurface = intersection.brush != null ? new SelectedBrushSurface(intersection.brush, intersection.surfaceIndex, intersection.worldPlane) : null;
                hoverRotation     = SelectionUtility.FindDragOrientation(sceneView, normal, sourceSurfaceAlignment, destinationSurfaceAlignment);
                haveNoParent      = (hoverParent == null);
                hoverSiblingIndex = int.MaxValue;

                RealtimeCSG.CSGGrid.SetForcedGrid(camera, intersection.worldPlane);

                // Since we're snapping points to grid and do not have a relative distance, relative snapping makes no sense
                var doGridSnapping = RealtimeCSG.CSGSettings.ActiveSnappingMode != SnapMode.None;
                if (doGridSnapping)
                {
                    var localPoints = new Vector3[8];
                    var localPlane  = intersection.worldPlane;
                    for (var i = 0; i < localPoints.Length; i++)
                    {
                        localPoints[i] = GeometryUtility.ProjectPointOnPlane(localPlane, (hoverRotation * projectedBounds[i]) + hoverPosition);
                    }

                    hoverPosition += RealtimeCSG.CSGGrid.SnapDeltaToGrid(camera, MathConstants.zeroVector3, localPoints);
                }
                hoverPosition = GeometryUtility.ProjectPointOnPlane(intersection.worldPlane, hoverPosition);                  // + (normal * 0.01f);

                EnableVisualObjects();
                return(true);
            }
            finally
            {
                if (!UpdateLoop.IsActive())
                {
                    UpdateLoop.ResetUpdateRoutine();
                }
            }
        }
        public SelectedBrushSurface[] HoverOnBrush(CSGBrush[] hoverBrushes, int surfaceIndex)
        {
            hoverOnSelectedSurfaces = false;
            if (hoverBrushes == null ||
                hoverBrushes.Length == 0 ||
                hoverBrushes[0] == null)
            {
                return(null);
            }

            var activetool = EditModeManager.ActiveTool as EditModeSurface;

            if (activetool != null)
            {
                var selectedBrushSurfaces = activetool.GetSelectedSurfaces();
                for (int i = 0; i < selectedBrushSurfaces.Length; i++)
                {
                    if (selectedBrushSurfaces[i].surfaceIndex == surfaceIndex &&
                        ArrayUtility.Contains(hoverBrushes, selectedBrushSurfaces[i].brush))
                    {
                        if (i != 0 && selectedBrushSurfaces.Length > 1)
                        {
                            var temp = selectedBrushSurfaces[0];
                            selectedBrushSurfaces[0] = selectedBrushSurfaces[i];
                            selectedBrushSurfaces[i] = temp;
                        }
                        hoverOnSelectedSurfaces = true;
                        return(selectedBrushSurfaces);
                    }
                }
            }

            var surfaces = new SelectedBrushSurface[hoverBrushes.Length];

            for (int i = 0; i < hoverBrushes.Length; i++)
            {
                surfaces[i] = new SelectedBrushSurface(hoverBrushes[i], surfaceIndex);
            }
            return(surfaces);
        }