Exemplo n.º 1
0
        //static readonly Color emptyColor = new Color(0, 0, 0, 0);

        public static void DrawSelectedBrush(Int32 brushID, Shape shape, Vector3 translation, Color wireframeColor, int texGenID, bool selectAllSurfaces, float thickness = -1)
        {
            if (selectAllSurfaces)
            {
                Color selectedOuterColor         = wireframeColor;
                Color selectedInnerColor         = wireframeColor;
                Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
                Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

                selectedOuterOccludedColor.a *= 0.5f;
                selectedInnerOccludedColor.a *= 0.5f;

                CSGRenderer.DrawOutlines(brushID, translation, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
            }
            else
            {
                Color unselectedOuterColor         = wireframeColor * unselected_factor;
                Color unselectedInnerColor         = wireframeColor * (unselected_factor * inner_factor);
                Color selectedOuterColor           = wireframeColor;
                Color selectedInnerColor           = wireframeColor * inner_factor;
                Color unselectedOuterOccludedColor = unselectedOuterColor * occluded_factor;
                Color unselectedInnerOccludedColor = unselectedInnerColor * occluded_factor;
//				Color selectedOuterOccludedColor	= selectedOuterColor * occluded_factor;
//				Color selectedInnerOccludedColor	= selectedInnerColor * occluded_factor;

                unselectedOuterOccludedColor.a *= 0.5f;
                unselectedInnerOccludedColor.a *= 0.5f;

                if (texGenID >= 0 && texGenID < shape.TexGens.Length)
                {
                    CSGRenderer.DrawTexGenOutlines(brushID, shape, translation, texGenID, selectedOuterColor, selectedInnerColor);
                }
                CSGRenderer.DrawOutlines(brushID, translation, unselectedOuterColor, unselectedOuterOccludedColor, unselectedInnerColor, unselectedInnerOccludedColor, thickness);
            }
        }
Exemplo n.º 2
0
        public override void OnPaint()
        {
            RealtimeCSG.Grid.RenderGrid();
            if (hoverBrushSurface == null)
            {
                return;
            }

            var brush       = hoverBrushSurface.brush;
            var brush_cache = InternalCSGModelManager.GetBrushCache(brush);

            if (brush_cache == null ||
                brush_cache.childData == null ||
                brush_cache.childData.ModelTransform == null)
            {
                return;
            }

            var highlight_surface = hoverBrushSurface.surfaceIndex;
            var highlight_texGen  = brush.Shape.Surfaces[highlight_surface].TexGenIndex;
            var model_translation = brush_cache.childData.Model.transform.position;
            var brush_translation = brush_cache.compareTransformation.modelLocalPosition + model_translation;

            CSGRenderer.DrawSelectedBrush(brush.brushID, brush.Shape,
                                          brush_translation, ColorSettings.WireframeOutline,
                                          highlight_texGen,
                                          false, ToolConstants.oldLineScale);
        }
Exemplo n.º 3
0
        protected void PaintSnapVisualisation()
        {
            if (visualSnappedEdges != null)
            {
                PaintUtility.DrawLines(visualSnappedEdges.ToArray(), ToolConstants.oldThickLineScale, ColorSettings.SnappedEdges);
            }

            var _origMatrix = Handles.matrix;

            Handles.matrix = MathConstants.identityMatrix;
            if (visualSnappedGrid != null)
            {
                PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges);
            }

            if (visualSnappedBrush != null)
            {
                var brush_cache = InternalCSGModelManager.GetBrushCache(visualSnappedBrush);
                if (brush_cache != null &&
                    brush_cache.compareTransformation != null &&
                    brush_cache.childData != null &&
                    brush_cache.childData.ModelTransform != null &&
                    brush_cache.childData.ModelTransform)
                {
                    var color             = ColorSettings.HoverOutlines;
                    var brush_translation = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position;
                    CSGRenderer.DrawOutlines(visualSnappedBrush.brushID, brush_translation,
                                             color, color, color, color, ToolConstants.oldThickLineScale);
                }
            }
            Handles.matrix = _origMatrix;
        }
Exemplo n.º 4
0
        /*
         * public static void DrawSelectedBrush(GeometryWireframe outline, Matrix4x4 transformation, Color wireframeColor, float thickness = -1)
         * {
         *      Color selectedOuterColor		 = wireframeColor;
         *      Color selectedInnerColor		 = wireframeColor * inner_factor;
         *      Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
         *      Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;
         *
         *      selectedOuterOccludedColor.a *= 0.5f;
         *      selectedInnerOccludedColor.a *= 0.5f;
         *
         *      CSGRenderer.DrawOutlines(outline, transformation, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
         * }*/

        //static readonly Color emptyColor = new Color(0, 0, 0, 0);

        public static void DrawSelectedBrush(Int32 brushNodeID, Shape shape, Matrix4x4 transformation, Color wireframeColor, int surfaceIndex, bool selectAllSurfaces, float thickness = -1)
        {
            if (selectAllSurfaces)
            {
                Color selectedOuterColor         = wireframeColor;
                Color selectedInnerColor         = wireframeColor;
                Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
                Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

                selectedOuterOccludedColor.a *= 0.5f;
                selectedInnerOccludedColor.a *= 0.5f;

                CSGRenderer.DrawOutlines(brushNodeID, transformation, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
            }
            else
            {
                Color unselectedOuterColor         = wireframeColor * unselected_factor;
                Color unselectedInnerColor         = wireframeColor * (unselected_factor * inner_factor);
                Color selectedOuterColor           = wireframeColor;
                Color selectedInnerColor           = wireframeColor * inner_factor;
                Color unselectedOuterOccludedColor = unselectedOuterColor * occluded_factor;
                Color unselectedInnerOccludedColor = unselectedInnerColor * occluded_factor;
//				Color selectedOuterOccludedColor	= selectedOuterColor * occluded_factor;
//				Color selectedInnerOccludedColor	= selectedInnerColor * occluded_factor;

                unselectedOuterOccludedColor.a *= 0.5f;
                unselectedInnerOccludedColor.a *= 0.5f;

                if (surfaceIndex >= 0 && surfaceIndex < shape.Surfaces.Length)
                {
                    CSGRenderer.DrawSurfaceOutlines(brushNodeID, shape, transformation, surfaceIndex, selectedOuterColor, selectedInnerColor);
                }
                CSGRenderer.DrawOutlines(brushNodeID, transformation, unselectedOuterColor, unselectedOuterOccludedColor, unselectedInnerColor, unselectedInnerOccludedColor, thickness);
            }
        }
Exemplo n.º 5
0
        protected void PaintSnapVisualisation()
        {
            if (visualSnappedEdges != null)
            {
                PaintUtility.DrawLines(visualSnappedEdges.ToArray(), GUIConstants.oldThickLineScale, ColorSettings.SnappedEdges);
            }

            var _origMatrix = Handles.matrix;

            Handles.matrix = MathConstants.identityMatrix;
            if (visualSnappedGrid != null)
            {
                PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges);
            }

            if (visualSnappedBrush != null)
            {
                if (visualSnappedBrush.compareTransformation != null &&
                    visualSnappedBrush.ChildData != null &&
                    visualSnappedBrush.ChildData.ModelTransform)
                {
                    var color = ColorSettings.HoverOutlines;
                    var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
                    CSGRenderer.DrawOutlines(visualSnappedBrush.brushNodeID, brush_transformation,
                                             color, color, color, color, GUIConstants.oldThickLineScale);
                }
            }
            Handles.matrix = _origMatrix;
        }
Exemplo n.º 6
0
        private void PaintSelectedBrushes()
        {
            if (lastLineMeshGeneration != InternalCSGModelManager.MeshGeneration)
            {
                lastLineMeshGeneration = InternalCSGModelManager.MeshGeneration;

                var brushTransformation = new Matrix4x4[brushes.Length];
                var brushNodeIDs        = new Int32[brushes.Length];
                for (int i = brushes.Length - 1; i >= 0; i--)
                {
                    var brush = brushes[i];
                    if (brush.brushNodeID == CSGNode.InvalidNodeID ||   // could be a prefab
                        brush.compareTransformation == null ||
                        brush.ChildData == null ||
                        brush.ChildData.ModelTransform == null ||
                        !brush.ChildData.ModelTransform)
                    {
                        ArrayUtility.RemoveAt(ref brushTransformation, i);
                        ArrayUtility.RemoveAt(ref brushNodeIDs, i);
                        continue;
                    }
                    brushTransformation[i] = brush.compareTransformation.localToWorldMatrix;
                    brushNodeIDs[i]        = brush.brushNodeID;
                }
                CSGRenderer.DrawSelectedBrushes(zTestLineMeshManager, noZTestLineMeshManager, brushNodeIDs, brushTransformation,
                                                ColorSettings.SelectedOutlines, GUIConstants.lineScale);
            }

            MaterialUtility.LineAlphaMultiplier     = 1.0f;
            MaterialUtility.LineDashMultiplier      = 2.0f;
            MaterialUtility.LineThicknessMultiplier = 2.0f;
            noZTestLineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
            MaterialUtility.LineThicknessMultiplier = 1.0f;
            zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);
        }
Exemplo n.º 7
0
        public void OnPaint(SceneView sceneView)
        {
            RealtimeCSG.CSGGrid.RenderGrid(sceneView);

            if (hoverBrushSurface == null)
            {
                return;
            }

            var brush = hoverBrushSurface.brush;

            if (brush.ChildData == null ||
                !brush.ChildData.ModelTransform)
            {
                return;
            }

            var highlight_surface    = hoverBrushSurface.surfaceIndex;
            var brush_transformation = brush.compareTransformation.localToWorldMatrix;

            CSGRenderer.DrawSelectedBrush(brush.brushNodeID, brush.Shape,
                                          brush_transformation, ColorSettings.WireframeOutline,
                                          highlight_surface,
                                          false, GUIConstants.oldLineScale);
        }
Exemplo n.º 8
0
        public void OnPaint()
        {
            if (!hoverOnSelectedSurfaces)
            {
                var activetool = EditModeManager.ActiveTool as EditModeSurface;
                if (activetool != null)
                {
                    var selectedBrushSurfaces = activetool.GetSelectedSurfaces();
                    for (int i = 0; i < selectedBrushSurfaces.Length; i++)
                    {
                        var brush       = selectedBrushSurfaces[i].brush;
                        var brush_cache = InternalCSGModelManager.GetBrushCache(brush);
                        if (brush_cache == null)
                        {
                            return;
                        }

                        var highlight_surface = selectedBrushSurfaces[i].surfaceIndex;
                        var highlight_texGen  = brush.Shape.Surfaces[highlight_surface].TexGenIndex;
                        var brush_translation = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position;

                        CSGRenderer.DrawTexGenOutlines(brush.brushID, brush.Shape,
                                                       brush_translation, highlight_texGen,
                                                       ColorSettings.SurfaceInnerStateColor[2],
                                                       ColorSettings.SurfaceOuterStateColor[2],
                                                       //ColorSettings.SurfaceTriangleStateColor[2],
                                                       ToolConstants.oldThinLineScale);
                    }
                }
            }

            if (hoverBrushSurfaces != null)
            {
                for (int i = 0; i < hoverBrushSurfaces.Length; i++)
                {
                    var brush       = hoverBrushSurfaces[i].brush;
                    var brush_cache = InternalCSGModelManager.GetBrushCache(brush);
                    if (brush_cache == null)
                    {
                        return;
                    }

                    var brush_translation = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position;

                    var highlight_surface = hoverBrushSurfaces[i].surfaceIndex;
                    if (highlight_surface == -1 || selectAllSurfaces)
                    {
                        CSGRenderer.DrawSelectedBrush(brush.brushID, brush.Shape, brush_translation, ColorSettings.WireframeOutline, 0, selectAllSurfaces, ToolConstants.oldLineScale);
                    }
                    else
                    {
                        var highlight_texGen = brush.Shape.Surfaces[highlight_surface].TexGenIndex;
                        CSGRenderer.DrawSelectedBrush(brush.brushID, brush.Shape, brush_translation, ColorSettings.WireframeOutline, highlight_texGen, selectAllSurfaces, ToolConstants.oldLineScale);
                    }
                }
            }
        }
Exemplo n.º 9
0
        internal static void OnPaint(SceneView sceneView)
        {
            SceneDragToolManager.OnPaint();

            if (sceneView == null ||
                Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (RealtimeCSG.CSGSettings.GridVisible)
            {
                RealtimeCSG.CSGGrid.RenderGrid();
            }

            if (RealtimeCSG.CSGSettings.IsWireframeShown(sceneView))
            {
                if (forceOutlineUpdate || meshGeneration != InternalCSGModelManager.MeshGeneration)
                {
                    forceOutlineUpdate = false;
                    meshGeneration     = InternalCSGModelManager.MeshGeneration;
                    lineMeshManager.Begin();
                    for (int i = 0; i < InternalCSGModelManager.Brushes.Length; i++)
                    {
                        var brush = InternalCSGModelManager.Brushes[i];
                        if (!brush)
                        {
                            continue;
                        }

                        var brush_cache = InternalCSGModelManager.GetBrushCache(brush);
                        if (brush_cache == null)
                        {
                            continue;
                        }

                        if (!brush.outlineColor.HasValue)
                        {
                            brush.outlineColor = ColorSettings.GetBrushOutlineColor(brush);
                        }

                        var brush_translation = brush_cache.compareTransformation.modelLocalPosition +
                                                brush_cache.childData.ModelTransform.position;
                        CSGRenderer.DrawSimpleOutlines(lineMeshManager, brush.brushID, brush_translation, brush.outlineColor.Value);
                    }
                    lineMeshManager.End();
                }

                MaterialUtility.LineDashMultiplier      = 1.0f;
                MaterialUtility.LineThicknessMultiplier = 1.0f;
                MaterialUtility.LineAlphaMultiplier     = 1.0f;
                lineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
            }
        }
Exemplo n.º 10
0
        public static void DrawSelectedBrushes(LineMeshManager zTestLineMeshManager, LineMeshManager noZTestLineMeshManager, GeometryWireframe[] wireframes, Matrix4x4[] transformations, Color wireframeColor, float thickness = -1)
        {
            Color selectedOuterColor         = wireframeColor;                             //selectedOuterColor.a         = 1.0f;
            Color selectedInnerColor         = selectedOuterColor * inner_factor;
            Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
            Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

            //selectedOuterOccludedColor.a *= 0.5f;
            //selectedInnerOccludedColor.a *= 0.5f;

            CSGRenderer.DrawOutlines(zTestLineMeshManager, noZTestLineMeshManager, wireframes, transformations, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
        }
Exemplo n.º 11
0
        public static void DrawSelectedBrush(Int32 brushNodeID, Matrix4x4 transformation, Color wireframeColor, float thickness = -1)
        {
            Color selectedOuterColor         = wireframeColor;                             //selectedOuterColor.a         = 1.0f;
            Color selectedInnerColor         = selectedOuterColor * inner_factor;
            Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
            Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

            selectedOuterOccludedColor.a *= 0.5f;
            selectedInnerOccludedColor.a *= 0.5f;

            CSGRenderer.DrawOutlines(brushNodeID, transformation, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
        }
Exemplo n.º 12
0
        public static void DrawSelectedBrush(GeometryWireframe outline, Vector3 translation, Color wireframeColor, float thickness = -1)
        {
            Color selectedOuterColor         = wireframeColor;
            Color selectedInnerColor         = wireframeColor * inner_factor;
            Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
            Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

            selectedOuterOccludedColor.a *= 0.5f;
            selectedInnerOccludedColor.a *= 0.5f;

            CSGRenderer.DrawOutlines(outline, translation, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
        }
Exemplo n.º 13
0
        internal static void OnPaint(SceneView sceneView)
        {
            if (!sceneView)
            {
                return;
            }

            var camera = sceneView.camera;

            SceneDragToolManager.OnPaint(camera);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (RealtimeCSG.CSGSettings.GridVisible)
            {
                RealtimeCSG.CSGGrid.RenderGrid(camera);
            }

            if (RealtimeCSG.CSGSettings.IsWireframeShown(sceneView))
            {
                if (forceOutlineUpdate || meshGeneration != InternalCSGModelManager.MeshGeneration)
                {
                    forceOutlineUpdate = false;
                    meshGeneration     = InternalCSGModelManager.MeshGeneration;
                    lineMeshManager.Begin();
                    for (int i = 0; i < InternalCSGModelManager.Brushes.Count; i++)
                    {
                        var brush = InternalCSGModelManager.Brushes[i];
                        if (!brush)
                        {
                            continue;
                        }

                        if (!brush.outlineColor.HasValue)
                        {
                            brush.outlineColor = ColorSettings.GetBrushOutlineColor(brush);
                        }

                        var brush_transformation = brush.compareTransformation.localToWorldMatrix;
                        CSGRenderer.DrawSimpleOutlines(lineMeshManager, brush.brushNodeID, brush_transformation, brush.outlineColor.Value);
                    }
                    lineMeshManager.End();
                }

                MaterialUtility.LineDashMultiplier      = 1.0f;
                MaterialUtility.LineThicknessMultiplier = 1.0f;
                MaterialUtility.LineAlphaMultiplier     = 1.0f;
                lineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
            }
        }
Exemplo n.º 14
0
        public static void DrawSelectedBrushes(LineMeshManager zTestLineMeshManager, LineMeshManager noZTestLineMeshManager, Int32[] brushIDs, Vector3[] translations, Color wireframeColor, float thickness = -1)
        {
            Color selectedOuterColor         = wireframeColor;                             //selectedOuterColor.a         = 1.0f;
            Color selectedInnerColor         = selectedOuterColor * inner_factor;
            Color selectedOuterOccludedColor = selectedOuterColor * occluded_factor;
            Color selectedInnerOccludedColor = selectedInnerColor * occluded_factor;

            selectedOuterOccludedColor.a *= 0.5f;
            selectedInnerOccludedColor.a *= 0.5f;

            var wireframes = BrushOutlineManager.GetBrushOutlines(brushIDs);

            CSGRenderer.DrawOutlines(zTestLineMeshManager, noZTestLineMeshManager, wireframes, translations, selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor, thickness);
        }
Exemplo n.º 15
0
        public void OnPaint(SceneView sceneView)
        {
            if (hoverOverObject != null)
            {
                return;
            }

            if (!hoverOnSelectedSurfaces)
            {
                var activetool = EditModeManager.ActiveTool as EditModeSurface;
                if (activetool != null)
                {
                    var selectedBrushSurfaces = activetool.GetSelectedSurfaces();
                    for (int i = 0; i < selectedBrushSurfaces.Length; i++)
                    {
                        var brush = selectedBrushSurfaces[i].brush;

                        var highlight_surface    = selectedBrushSurfaces[i].surfaceIndex;
                        var brush_transformation = brush.compareTransformation.localToWorldMatrix;

                        CSGRenderer.DrawSurfaceOutlines(brush.brushNodeID, brush.Shape,
                                                        brush_transformation, highlight_surface,
                                                        ColorSettings.SurfaceInnerStateColor[2],
                                                        ColorSettings.SurfaceOuterStateColor[2],
                                                        GUIConstants.oldThinLineScale);
                    }
                }
            }

            if (hoverBrushSurfaces != null)
            {
                for (int i = 0; i < hoverBrushSurfaces.Length; i++)
                {
                    var brush = hoverBrushSurfaces[i].brush;

                    var brush_transformation = brush.compareTransformation.localToWorldMatrix;

                    var highlight_surface = hoverBrushSurfaces[i].surfaceIndex;
                    if (highlight_surface == -1 || selectAllSurfaces)
                    {
                        CSGRenderer.DrawSelectedBrush(brush.brushNodeID, brush.Shape, brush_transformation, ColorSettings.WireframeOutline, 0, selectAllSurfaces, GUIConstants.oldLineScale);
                    }
                    else
                    {
                        CSGRenderer.DrawSelectedBrush(brush.brushNodeID, brush.Shape, brush_transformation, ColorSettings.WireframeOutline, highlight_surface, selectAllSurfaces, GUIConstants.oldLineScale);
                    }
                }
            }
        }
Exemplo n.º 16
0
        public static void DrawDeselectedTexGenOutline(Int32 brushID, Shape shape, Vector3 translation, Color wireframeColor, int texGenID)
        {
//			Color unselectedOuterColor			= wireframeColor * unselected_factor;
//			Color unselectedInnerColor			= wireframeColor * (unselected_factor * inner_factor);
            Color selectedOuterColor = wireframeColor;
            Color selectedInnerColor = wireframeColor * inner_factor;

//			Color unselectedOuterOccludedColor	= unselectedOuterColor * occluded_factor;
//			Color unselectedInnerOccludedColor	= unselectedInnerColor * occluded_factor;
//			Color selectedOuterOccludedColor	= selectedOuterColor * occluded_factor;
//			Color selectedInnerOccludedColor	= selectedInnerColor * occluded_factor;

            if (texGenID >= 0 && texGenID < shape.TexGens.Length)
            {
                CSGRenderer.DrawTexGenOutlines(brushID, shape, translation, texGenID, selectedOuterColor, selectedInnerColor);                //, emptyColor);
                //selectedOuterColor, selectedOuterOccludedColor, selectedInnerColor, selectedInnerOccludedColor);
            }
        }
Exemplo n.º 17
0
        public void HandleEvents(SceneView sceneView, Rect sceneRect)
        {
            if (CurrentGenerator == null)
            {
                return;
            }

            CurrentGenerator.HandleEvents(sceneView, sceneRect);
            switch (Event.current.type)
            {
            case EventType.ValidateCommand:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (Keys.HandleSceneValidate(EditModeManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.KeyDown:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (Keys.HandleSceneKeyDown(EditModeManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.KeyUp:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Additive);     Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Subtractive);  Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Intersecting); Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    CurrentGenerator.PerformDeselectAll(); Event.current.Use(); break;
                }
                if (Keys.HandleSceneKeyUp(EditModeManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.Repaint:
            {
                if (lastLineMeshGeneration != InternalCSGModelManager.MeshGeneration)
                {
                    lastLineMeshGeneration = InternalCSGModelManager.MeshGeneration;

                    var brushTransformation = new Matrix4x4[brushes.Length];
                    var brushNodeIDs        = new Int32[brushes.Length];
                    for (int i = brushes.Length - 1; i >= 0; i--)
                    {
                        var brush = brushes[i];
                        if (brush.brushNodeID == CSGNode.InvalidNodeID ||                                       // could be a prefab
                            brush.compareTransformation == null ||
                            brush.ChildData == null ||
                            brush.ChildData.ModelTransform == null ||
                            !brush.ChildData.ModelTransform)
                        {
                            ArrayUtility.RemoveAt(ref brushTransformation, i);
                            ArrayUtility.RemoveAt(ref brushNodeIDs, i);
                            continue;
                        }
                        brushTransformation[i] = brush.compareTransformation.localToWorldMatrix;
                        brushNodeIDs[i]        = brush.brushNodeID;
                    }
                    CSGRenderer.DrawSelectedBrushes(zTestLineMeshManager, noZTestLineMeshManager, brushNodeIDs, brushTransformation,
                                                    ColorSettings.SelectedOutlines, GUIConstants.lineScale);
                }

                MaterialUtility.LineAlphaMultiplier     = 1.0f;
                MaterialUtility.LineDashMultiplier      = 2.0f;
                MaterialUtility.LineThicknessMultiplier = 2.0f;
                noZTestLineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
                MaterialUtility.LineThicknessMultiplier = 1.0f;
                zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);

                break;
            }
            }
        }
Exemplo n.º 18
0
        public static void OnSceneGUI(SceneView sceneView)
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            CameraUtility.InitDistanceChecks(sceneView);
            SelectionUtility.HandleEvents();
            InitTools();

            HandleBuilderEvents();
            {
                UpdateTool();

                if (instance.activeTool != null)
                {
                    if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
                    {
                        // handle the tool
                        var sceneSize = sceneView.position.size;
                        var sceneRect = new Rect(0, 0, sceneSize.x, sceneSize.y - ((CSG_GUIStyleUtility.BottomToolBarHeight + 4) + 17));

                        instance.activeTool.HandleEvents(sceneRect);
                    }
                    else
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            var brushes         = instance.filteredSelection.BrushTargets;
                            var wireframes      = new List <GeometryWireframe>(brushes.Length);
                            var transformations = new List <Matrix4x4>(brushes.Length);
                            for (int i = 0; i < brushes.Length; i++)
                            {
                                var brush = brushes[i];
                                if (!brush)
                                {
                                    continue;
                                }

                                if (brush.ChildData == null ||
                                    !brush.ChildData.Model)
                                {
                                    continue;
                                }

                                var brushTransformation = brush.compareTransformation.localToWorldMatrix;

                                wireframes.Add(BrushOutlineManager.GetBrushOutline(brushes[i].brushNodeID));
                                transformations.Add(brushTransformation);
                            }
                            if (wireframes.Count > 0)
                            {
                                CSGRenderer.DrawSelectedBrushes(instance.zTestLineMeshManager, instance.noZTestLineMeshManager,
                                                                wireframes.ToArray(), transformations.ToArray(),
                                                                ColorSettings.SelectedOutlines, GUIConstants.thickLineScale);
                            }
                            MaterialUtility.LineDashMultiplier      = 1.0f;
                            MaterialUtility.LineThicknessMultiplier = 1.0f;
                            MaterialUtility.LineAlphaMultiplier     = 1.0f;
                            instance.zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);
                            instance.zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);
                        }
                    }
                }
            }

            int sceneWindowId   = GUIUtility.GetControlID(SceneWindowHash, FocusType.Passive);
            var sceneWindowType = Event.current.GetTypeForControl(sceneWindowId);

            if (sceneWindowType == EventType.Repaint)
            {
                if (currentEditorWindows.Count > 0)
                {
                    for (int i = 0; i < currentEditorWindows.Count; i++)
                    {
                        currentEditorWindows[i].Repaint();
                    }
                    return;
                }
            }

            if (sceneWindowType == EventType.MouseMove)
            {
                SceneDragToolManager.IsDraggingObjectInScene = false;
            }

            if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                if (sceneView && sceneWindowType != EventType.Used && !SceneDragToolManager.IsDraggingObjectInScene)
                {
                    if (currentEditorWindows.Count == 0)
                    {
                        try
                        {
                            Handles.BeginGUI();
                            Rect windowRect = new Rect(Vector2.zero, sceneView.position.size);
                            EditModeSelectionGUI.HandleWindowGUI(windowRect);
                        }
                        finally
                        {
                            Handles.EndGUI();
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        internal static void OnPaint(SceneView sceneView)
        {
            if (!sceneView)
            {
                return;
            }

            SceneDragToolManager.OnPaint(sceneView);

            if (Event.current.type != EventType.Repaint)
            {
                return;
            }

            if (RealtimeCSG.CSGSettings.GridVisible)
            {
                sceneView.showGrid = false;
                RealtimeCSG.CSGGrid.RenderGrid(sceneView);
            }

            if (RealtimeCSG.CSGSettings.IsWireframeShown(sceneView))
            {
                if (forceOutlineUpdate || meshGeneration != InternalCSGModelManager.MeshGeneration)
                {
                    forceOutlineUpdate = false;
                    meshGeneration     = InternalCSGModelManager.MeshGeneration;
                    lineMeshManager.Begin();
                    for (int i = 0; i < InternalCSGModelManager.Brushes.Count; i++)
                    {
                        var brush = InternalCSGModelManager.Brushes[i];

                        if (!brush)
                        {
                            continue;
                        }

                        //if (!brush.outlineColor.HasValue)
                        //                  {
                        //	//brush.outlineColor = ColorSettings.GetBrushOutlineColor(brush);
                        //	brush.outlineColor = ColorSettings.SimpleOutlineColor;
                        //}

                        var color      = Color.white;
                        var comparison = brush.OperationType;
                        var op         = brush.GetComponentInParent <CSGOperation>();
                        if (op)
                        {
                            comparison = op.OperationType;
                        }
                        switch (comparison)
                        {
                        case Foundation.CSGOperationType.Additive:
                            color = ColorSettings.SimpleOutlineAdditiveColor;
                            break;

                        case Foundation.CSGOperationType.Subtractive:
                            color = ColorSettings.SimpleOutlineSubtractiveColor;
                            break;

                        case Foundation.CSGOperationType.Intersecting:
                            color = ColorSettings.SimpleOutlineIntersectingColor;
                            break;
                        }

                        var brushTransformation = brush.compareTransformation.localToWorldMatrix;
                        CSGRenderer.DrawSimpleOutlines(lineMeshManager, brush.brushNodeID, brushTransformation, color);
                        CSGRenderer.DrawPolygonCenters(lineMeshManager, brush);
                    }
                    lineMeshManager.End();
                }

                MaterialUtility.LineDashMultiplier      = 1.0f;
                MaterialUtility.LineThicknessMultiplier = 1.0f;
                MaterialUtility.LineAlphaMultiplier     = 1.0f;
                lineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
            }
        }
Exemplo n.º 20
0
        public void HandleEvents(Rect sceneRect)
        {
            if (CurrentGenerator == null)
            {
                return;
            }

            CurrentGenerator.HandleEvents(sceneRect);
            switch (Event.current.type)
            {
            case EventType.ValidateCommand:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (Keys.HandleSceneValidate(CSGBrushEditorManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.KeyDown:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    Event.current.Use(); break;
                }
                if (Keys.HandleSceneKeyDown(CSGBrushEditorManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.KeyUp:
            {
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedAdditiveKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Additive);     Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedSubtractiveKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Subtractive);  Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.MakeSelectedIntersectingKey.IsKeyPressed())
                {
                    SetOperationType(CSGOperationType.Intersecting); Event.current.Use(); break;
                }
                if (!EditorGUIUtility.editingTextField && Keys.CancelActionKey.IsKeyPressed())
                {
                    CurrentGenerator.PerformDeselectAll(); Event.current.Use(); break;
                }
                if (Keys.HandleSceneKeyUp(CSGBrushEditorManager.CurrentTool, false))
                {
                    Event.current.Use(); HandleUtility.Repaint(); break;
                }
                break;
            }

            case EventType.Repaint:
            {
                if (lastLineMeshGeneration != InternalCSGModelManager.MeshGeneration)
                {
                    lastLineMeshGeneration = InternalCSGModelManager.MeshGeneration;

                    var brush_translations = new Vector3[brushes.Length];
                    var brush_ids          = new Int32[brushes.Length];
                    for (int i = brushes.Length - 1; i >= 0; i--)
                    {
                        var brush       = brushes[i];
                        var brush_cache = InternalCSGModelManager.GetBrushCache(brush);
                        if (brush.brushID == -1 ||                                      // could be a prefab
                            brush_cache == null ||
                            brush_cache.compareTransformation == null ||
                            brush_cache.childData == null ||
                            brush_cache.childData.ModelTransform == null ||
                            !brush_cache.childData.ModelTransform)
                        {
                            ArrayUtility.RemoveAt(ref brush_translations, i);
                            ArrayUtility.RemoveAt(ref brush_ids, i);
                            continue;
                        }
                        brush_translations[i] = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position;
                        brush_ids[i]          = brush.brushID;
                    }
                    CSGRenderer.DrawSelectedBrushes(zTestLineMeshManager, noZTestLineMeshManager, brush_ids, brush_translations,
                                                    ColorSettings.SelectedOutlines, ToolConstants.lineScale);
                }

                MaterialUtility.LineDashMultiplier      = 2.0f;
                MaterialUtility.LineThicknessMultiplier = 2.0f;
                noZTestLineMeshManager.Render(MaterialUtility.NoZTestGenericLine);
                MaterialUtility.LineThicknessMultiplier = 1.0f;
                zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);

                break;
            }
            }
        }
Exemplo n.º 21
0
		protected override void HandleEditShapeEvents(SceneView sceneView, Rect sceneRect)
		{
            var camera = sceneView.camera;

			if (settings.vertices.Length < 2)
			{
				if (editMode == EditMode.ExtrudeShape ||
					editMode == EditMode.EditShape)
					editMode = EditMode.CreatePlane;
			}

			if (!SceneDragToolManager.IsDraggingObjectInScene &&
				Event.current.type == EventType.Repaint)
			{			
				if (visualSnappedEdges != null)
					PaintUtility.DrawLines(visualSnappedEdges.ToArray(), GUIConstants.oldThickLineScale, ColorSettings.SnappedEdges);
				
				if (visualSnappedGrid != null)
				{
					var _origMatrix = Handles.matrix;
					Handles.matrix = MathConstants.identityMatrix;
					PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges);
					Handles.matrix = _origMatrix;
				}
					
				if (visualSnappedBrush != null)
				{
					if (visualSnappedBrush.compareTransformation != null &&
						visualSnappedBrush.ChildData != null &&
						visualSnappedBrush.ChildData.ModelTransform)
					{
						var brush_transformation = visualSnappedBrush.compareTransformation.localToWorldMatrix;
						CSGRenderer.DrawOutlines(visualSnappedBrush.brushNodeID, brush_transformation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines);
					}						
				}

				var origMatrix = Handles.matrix;
				Handles.matrix = MathConstants.identityMatrix;
				PaintBounds(camera);
				Handles.matrix = origMatrix;
			}
			
			HandleHeightHandles(sceneView, sceneRect, false);

			for (int i = 0; i < settings.vertices.Length; i++)
			{
				var id = settings.vertexIDs[i];
				var point_type = Event.current.GetTypeForControl(id);
				switch (point_type)
				{
					case EventType.Repaint:
					{
						if (SceneDragToolManager.IsDraggingObjectInScene)
							break;

						bool isSelected = id == GUIUtility.keyboardControl;
						var temp		= Handles.color;
						var origMatrix	= Handles.matrix;
					
						Handles.matrix = MathConstants.identityMatrix;
						var rotation = camera.transform.rotation;


						if (isSelected)
						{
							Handles.color = ColorSettings.PointInnerStateColor[3];
						} else
						if (HandleUtility.nearestControl == id)
						{
							Handles.color = ColorSettings.PointInnerStateColor[1];
						} else						
						{
							Handles.color = ColorSettings.PointInnerStateColor[0];
						}

						float handleSize = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
						float scaledHandleSize = handleSize * GUIConstants.handleScale;
						PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize);
						
						Handles.matrix = origMatrix;
						Handles.color = temp;
						break;
					}

					case EventType.Layout:
					{
						if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan))
							break;

						var origMatrix = Handles.matrix;
						Handles.matrix = MathConstants.identityMatrix;
						float handleSize = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
						float scaledHandleSize = handleSize * GUIConstants.handleScale;
						HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(settings.vertices[i], scaledHandleSize));
						Handles.matrix = origMatrix;						
					
						break;
					}

					case EventType.ValidateCommand:
					case EventType.KeyDown:
					{
						if (GUIUtility.hotControl == id)
						{
							if (Keys.CancelActionKey.IsKeyPressed())
							{
								Event.current.Use(); 
								break;
							}
						}
						break;
					}
					case EventType.KeyUp:
					{
						if (GUIUtility.hotControl == id)
						{
							if (Keys.CancelActionKey.IsKeyPressed())
                            {
                                GUIUtility.hotControl = 0;
								GUIUtility.keyboardControl = 0;
								EditorGUIUtility.editingTextField = false;
								Event.current.Use(); 
								break;
							}
						}
						break;
					}

					case EventType.MouseDown:
					{
						if (!sceneRect.Contains(Event.current.mousePosition))
							break;
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id && Event.current.button == 0)
						{
                            GUIUtility.hotControl = id;
							GUIUtility.keyboardControl = id;
							EditorGUIUtility.editingTextField = false; 
							EditorGUIUtility.SetWantsMouseJumping(1);
							Event.current.Use(); 
							break;
						}
						break;
					}
					case EventType.MouseDrag:
					{
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (GUIUtility.hotControl == id && Event.current.button == 0)
						{
							Undo.RecordObject(this, "Modify shape");

							var mouseRay		= HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
							RealtimeCSG.CSGGrid.SetForcedGrid(camera, buildPlane);
							var alignedPlane	= new CSGPlane(RealtimeCSG.CSGGrid.CurrentWorkGridPlane.normal, settings.vertices[0]);
							var worldPosition	= buildPlane.Project(alignedPlane.RayIntersection(mouseRay));
							if (float.IsInfinity(worldPosition.x) || float.IsNaN(worldPosition.x) ||
								float.IsInfinity(worldPosition.y) || float.IsNaN(worldPosition.y) ||
								float.IsInfinity(worldPosition.z) || float.IsNaN(worldPosition.z))
								worldPosition = settings.vertices[i];

							ResetVisuals();
							if (snapFunction != null)
							{
								CSGBrush snappedOnBrush;
								worldPosition = snapFunction(camera, worldPosition, buildPlane, ref base.visualSnappedEdges, out snappedOnBrush, generatedBrushes);
							}
								
							base.visualSnappedGrid = RealtimeCSG.CSGGrid.FindAllGridEdgesThatTouchPoint(camera, worldPosition);

							settings.vertices[i] = worldPosition;
							
							CenterExtrusionPoints(buildPlane);
							UpdateBaseShape();

							if (editMode == EditMode.ExtrudeShape)
							{
								StartExtrudeMode(camera);
								UpdateBaseShape();
							}
							UpdateExtrudedShape();

							GUI.changed = true;
							Event.current.Use(); 
							break;
						}
						break;
					}
					case EventType.MouseUp:
					{
						if (GUIUtility.hotControl != id)
							break;
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (Event.current.button == 0)
                        {
							GUIUtility.hotControl = 0;
							GUIUtility.keyboardControl = 0;
							EditorGUIUtility.editingTextField = false;
							EditorGUIUtility.SetWantsMouseJumping(0);
							Event.current.Use(); 

							ResetVisuals();
							//if (Length == 0 || Width == 0)
							//{
							//	Cancel();
							//}
							break;
						}
						break;
					}
				}
				
			}
		}
Exemplo n.º 22
0
        protected override void HandleEditShapeEvents(Rect sceneRect)
        {
            if (!SceneDragToolManager.IsDraggingObjectInScene &&
                Event.current.type == EventType.Repaint)
            {
                if (visualSnappedEdges != null)
                {
                    PaintUtility.DrawLines(visualSnappedEdges.ToArray(), ToolConstants.oldThickLineScale, ColorSettings.SnappedEdges);
                }

                if (visualSnappedGrid != null)
                {
                    var _origMatrix = Handles.matrix;
                    Handles.matrix = MathConstants.identityMatrix;
                    PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges);
                    Handles.matrix = _origMatrix;
                }

                if (visualSnappedBrush != null)
                {
                    var brush_cache = InternalCSGModelManager.GetBrushCache(visualSnappedBrush);
                    if (brush_cache != null &&
                        brush_cache.compareTransformation != null &&
                        brush_cache.childData != null &&
                        brush_cache.childData.ModelTransform != null &&
                        brush_cache.childData.ModelTransform)
                    {
                        var brush_translation = brush_cache.compareTransformation.modelLocalPosition + brush_cache.childData.ModelTransform.position;
                        CSGRenderer.DrawOutlines(visualSnappedBrush.brushID, brush_translation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines);
                    }
                }

                var origMatrix = Handles.matrix;
                Handles.matrix = MathConstants.identityMatrix;

                /*
                 * bool isValid;
                 * var realVertices		= settings.GetVertices(buildPlane, worldPosition, gridTangent, gridBinormal, out isValid);
                 * if (editMode == EditMode.EditShape)
                 *      shapeIsValid = isValid;
                 *
                 * if (realVertices.Length > 0)*/
                {
                    PaintSquare();
                    PaintRadiusMessage();
                }

                Handles.matrix = origMatrix;
            }

            HandleHeightHandles(sceneRect, false);
            for (int i = 1; i < settings.vertices.Length; i++)
            {
                var id         = settings.vertexIDs[i];
                var point_type = Event.current.GetTypeForControl(id);
                switch (point_type)
                {
                case EventType.Repaint:
                {
                    if (SceneDragToolManager.IsDraggingObjectInScene)
                    {
                        break;
                    }

                    bool isSelected = id == GUIUtility.keyboardControl;
                    var  temp       = Handles.color;
                    var  origMatrix = Handles.matrix;

                    Handles.matrix = MathConstants.identityMatrix;
                    var rotation = Camera.current.transform.rotation;


                    if (isSelected)
                    {
                        Handles.color = ColorSettings.PointInnerStateColor[3];
                    }
                    else
                    if (HandleUtility.nearestControl == id)
                    {
                        Handles.color = ColorSettings.PointInnerStateColor[1];
                    }
                    else
                    {
                        Handles.color = ColorSettings.PointInnerStateColor[0];
                    }

                    float handleSize       = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
                    float scaledHandleSize = handleSize * ToolConstants.handleScale;
                    PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize);

                    Handles.matrix = origMatrix;
                    Handles.color  = temp;
                    break;
                }

                case EventType.Layout:
                {
                    if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan))
                    {
                        break;
                    }

                    var origMatrix = Handles.matrix;
                    Handles.matrix = MathConstants.identityMatrix;
                    float handleSize       = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
                    float scaledHandleSize = handleSize * ToolConstants.handleScale;
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(settings.vertices[i], scaledHandleSize));
                    Handles.matrix = origMatrix;

                    break;
                }

                case EventType.ValidateCommand:
                case EventType.KeyDown:
                {
                    if (GUIUtility.hotControl == id)
                    {
                        if (Keys.CancelActionKey.IsKeyPressed())
                        {
                            Event.current.Use();
                            break;
                        }
                    }
                    break;
                }

                case EventType.KeyUp:
                {
                    if (GUIUtility.hotControl == id)
                    {
                        if (Keys.CancelActionKey.IsKeyPressed())
                        {
                            GUIUtility.hotControl             = 0;
                            GUIUtility.keyboardControl        = 0;
                            EditorGUIUtility.editingTextField = false;
                            Event.current.Use();
                            break;
                        }
                    }
                    break;
                }

                case EventType.MouseDown:
                {
                    if (!sceneRect.Contains(Event.current.mousePosition))
                    {
                        break;
                    }
                    if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                    {
                        break;
                    }
                    if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id && Event.current.button == 0)
                    {
                        GUIUtility.hotControl             = id;
                        GUIUtility.keyboardControl        = id;
                        EditorGUIUtility.editingTextField = false;
                        EditorGUIUtility.SetWantsMouseJumping(1);
                        Event.current.Use();
                        break;
                    }
                    break;
                }

                case EventType.MouseDrag:
                {
                    if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                    {
                        break;
                    }
                    if (GUIUtility.hotControl == id && Event.current.button == 0)
                    {
                        Undo.RecordObject(this, "Modify shape");

                        var mouseRay      = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                        var alignedPlane  = new CSGPlane(RealtimeCSG.CSGGrid.CurrentWorkGridPlane.normal, settings.vertices[0]);
                        var worldPosition = buildPlane.Project(alignedPlane.Intersection(mouseRay));
                        if (float.IsInfinity(worldPosition.x) || float.IsNaN(worldPosition.x) ||
                            float.IsInfinity(worldPosition.y) || float.IsNaN(worldPosition.y) ||
                            float.IsInfinity(worldPosition.z) || float.IsNaN(worldPosition.z))
                        {
                            worldPosition = settings.vertices[i];
                        }

                        ResetVisuals();
                        if (snapFunction != null)
                        {
                            CSGBrush snappedOnBrush;
                            worldPosition = snapFunction(worldPosition, buildPlane, ref base.visualSnappedEdges, out snappedOnBrush, generatedBrushes);
                        }

                        base.visualSnappedGrid = RealtimeCSG.CSGGrid.FindAllGridEdgesThatTouchPoint(worldPosition);

                        settings.vertices[i] = worldPosition;
                        if (editMode == EditMode.ExtrudeShape)
                        {
                            StartExtrudeMode();
                        }
                        UpdateBaseShape();
                        UpdateExtrudedShape();

                        GUI.changed = true;
                        Event.current.Use();
                        break;
                    }
                    break;
                }

                case EventType.MouseUp:
                {
                    if (GUIUtility.hotControl != id)
                    {
                        break;
                    }
                    if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
                    {
                        break;
                    }
                    if (Event.current.button == 0)
                    {
                        GUIUtility.hotControl             = 0;
                        GUIUtility.keyboardControl        = 0;
                        EditorGUIUtility.editingTextField = false;
                        EditorGUIUtility.SetWantsMouseJumping(0);
                        Event.current.Use();

                        ResetVisuals();
                        if (RadiusA == 0)
                        {
                            Cancel();
                        }
                        break;
                    }
                    break;
                }
                }
            }
        }
Exemplo n.º 23
0
		protected override void HandleEditShapeEvents(SceneView sceneView, Rect sceneRect)
		{
            var camera = sceneView.camera;
            if (!SceneDragToolManager.IsDraggingObjectInScene &&
				Event.current.type == EventType.Repaint)
			{			
				if (visualSnappedEdges != null)
					PaintUtility.DrawLines(visualSnappedEdges.ToArray(), GUIConstants.oldThickLineScale, ColorSettings.SnappedEdges);
				
				if (visualSnappedGrid != null)
				{
					var _origMatrix = Handles.matrix;
					Handles.matrix = MathConstants.identityMatrix;
					PaintUtility.DrawDottedLines(visualSnappedGrid.ToArray(), ColorSettings.SnappedEdges);
					Handles.matrix = _origMatrix;
				}
					
				if (visualSnappedBrush != null)
				{
					if (visualSnappedBrush.compareTransformation != null &&
						visualSnappedBrush.ChildData != null &&
						visualSnappedBrush.ChildData.ModelTransform)
					{
						var brush_transformation	= visualSnappedBrush.compareTransformation.localToWorldMatrix;
						CSGRenderer.DrawOutlines(visualSnappedBrush.brushNodeID, brush_transformation, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines, ColorSettings.SelectedOutlines);
					}						
				}
				
				var origMatrix	= Handles.matrix;
				Handles.matrix = MathConstants.identityMatrix;

				bool isValid;
				var realVertices		= settings.GetVertices(buildPlane, worldPosition, gridTangent, gridBinormal, out isValid);
				if (editMode == EditMode.EditShape)
					shapeIsValid = isValid;

				var wireframeColor		= ColorSettings.WireframeOutline;
				//var topWireframeColor	= ColorSettings.BoundsEdgeHover;

				if (!shapeIsValid || !isValid)
					wireframeColor = Color.red;

				if (realVertices.Length > 0)
				{
					if (realVertices.Length >= 3)
					{
						var color = ColorSettings.ShapeDrawingFill;
						PaintUtility.DrawPolygon(MathConstants.identityMatrix, realVertices, color);
					}

					for (int i = 1; i < realVertices.Length; i++)
					{
						PaintUtility.DrawLine(realVertices[i - 1], realVertices[i], GUIConstants.oldLineScale, wireframeColor);
						PaintUtility.DrawDottedLine(realVertices[i - 1], realVertices[i], wireframeColor, 4.0f);
					}

					PaintUtility.DrawLine(realVertices[realVertices.Length - 1], realVertices[0], GUIConstants.oldLineScale, wireframeColor);
					PaintUtility.DrawDottedLine(realVertices[realVertices.Length - 1], realVertices[0], wireframeColor, 4.0f);
					/*
					if (editMode == EditMode.ExtrudeShape)
					{
						var delta = (base.extrusionPoints[1].Vertex - base.extrusionPoints[0].Vertex);
						for (int i = 1; i < realVertices.Length; i++)
						{
							PaintUtility.DrawLine(realVertices[i - 1] + delta, realVertices[i] + delta, GUIConstants.oldLineScale, topWireframeColor);
							PaintUtility.DrawDottedLine(realVertices[i - 1] + delta, realVertices[i] + delta, topWireframeColor, 4.0f);
						}

						for (int i = 0; i < realVertices.Length; i++)
						{
							PaintUtility.DrawLine(realVertices[i] + delta, realVertices[i], GUIConstants.oldLineScale, wireframeColor);
							PaintUtility.DrawDottedLine(realVertices[i] + delta, realVertices[i], wireframeColor, 4.0f);
						}

						PaintUtility.DrawLine(realVertices[realVertices.Length - 1] + delta, realVertices[0] + delta, GUIConstants.oldLineScale, topWireframeColor);
						PaintUtility.DrawDottedLine(realVertices[realVertices.Length - 1] + delta, realVertices[0] + delta, topWireframeColor, 4.0f);
					}
					*/
					PaintSquare(camera);
					PaintRadiusMessage(camera);
				}
				
				Handles.matrix = origMatrix;
			}
			
			var shapeType = Event.current.GetTypeForControl(shapeId);
			HandleKeyboard(shapeType);

			for (int i = 1; i < settings.vertices.Length; i++)
			{
				var id = settings.vertexIDs[i];
				var point_type = Event.current.GetTypeForControl(id);
				switch (point_type)
				{
					case EventType.Repaint:
					{
						if (SceneDragToolManager.IsDraggingObjectInScene)
							break;

						bool isSelected = id == GUIUtility.keyboardControl;
						var temp		= Handles.color;
						var origMatrix	= Handles.matrix;
					
						Handles.matrix = MathConstants.identityMatrix;
						var rotation = camera.transform.rotation;


						if (isSelected)
						{
							Handles.color = ColorSettings.PointInnerStateColor[3];
						} else
						if (HandleUtility.nearestControl == id)
						{
							Handles.color = ColorSettings.PointInnerStateColor[1];
						} else						
						{
							Handles.color = ColorSettings.PointInnerStateColor[0];
						}

						float handleSize = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
						float scaledHandleSize = handleSize * GUIConstants.handleScale;
						PaintUtility.SquareDotCap(id, settings.vertices[i], rotation, scaledHandleSize);
						
						Handles.matrix = origMatrix;
						Handles.color = temp;
						break;
					}

					case EventType.Layout:
					{
						if ((Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan))
							break;

						var origMatrix = Handles.matrix;
						Handles.matrix = MathConstants.identityMatrix;
						float handleSize = CSG_HandleUtility.GetHandleSize(settings.vertices[i]);
						float scaledHandleSize = handleSize * GUIConstants.handleScale;
						HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(settings.vertices[i], scaledHandleSize));
						Handles.matrix = origMatrix;						
					
						break;
					}

					case EventType.ValidateCommand:
					case EventType.KeyDown:
					{
						if (GUIUtility.hotControl == id)
						{
							if (Keys.CancelActionKey.IsKeyPressed())
							{
								Event.current.Use(); 
								break;
							}
						}
						break;
					}
					case EventType.KeyUp:
					{
						if (GUIUtility.hotControl == id)
						{
							if (Keys.CancelActionKey.IsKeyPressed())
                            {
                                GUIUtility.hotControl = 0;
								GUIUtility.keyboardControl = 0;
								EditorGUIUtility.editingTextField = false;
								Event.current.Use(); 
								break;
							}
						}
						break;
					}

					case EventType.MouseDown:
					{
						if (!sceneRect.Contains(Event.current.mousePosition))
							break;
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (GUIUtility.hotControl == 0 && HandleUtility.nearestControl == id && Event.current.button == 0)
						{
                            GUIUtility.hotControl = id;
							GUIUtility.keyboardControl = id;
							EditorGUIUtility.editingTextField = false; 
							EditorGUIUtility.SetWantsMouseJumping(1);
							Event.current.Use(); 
							break;
						}
						break;
					}
					case EventType.MouseDrag:
					{
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (GUIUtility.hotControl == id && Event.current.button == 0)
						{
							Undo.RecordObject(this, "Modify shape");

							var mouseRay		= HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
							var alignedPlane	= new CSGPlane(RealtimeCSG.CSGGrid.CurrentWorkGridPlane.normal, settings.vertices[0]);
							var worldPosition	= buildPlane.Project(alignedPlane.RayIntersection(mouseRay));
							if (float.IsInfinity(worldPosition.x) || float.IsNaN(worldPosition.x) ||
								float.IsInfinity(worldPosition.y) || float.IsNaN(worldPosition.y) ||
								float.IsInfinity(worldPosition.z) || float.IsNaN(worldPosition.z))
								worldPosition = settings.vertices[i];

							ResetVisuals();
							if (snapFunction != null)
							{
								CSGBrush snappedOnBrush;
								worldPosition = snapFunction(camera, worldPosition, buildPlane, ref base.visualSnappedEdges, out snappedOnBrush, generatedBrushes, ignoreAllBrushes: true);
							}
								
							base.visualSnappedGrid = RealtimeCSG.CSGGrid.FindAllGridEdgesThatTouchPoint(camera, worldPosition);

                            settings.vertices[i] = worldPosition;

							UpdateBaseShape(true);

							GUI.changed = true;
							Event.current.Use(); 
							break;
						}
						break;
					}
					case EventType.MouseUp:
					{
						if (GUIUtility.hotControl != id)
							break;
						if (Tools.viewTool != ViewTool.None && Tools.viewTool != ViewTool.Pan)
							break;
						if (Event.current.button == 0)
                        {
							GUIUtility.hotControl = 0;
							GUIUtility.keyboardControl = 0;
							EditorGUIUtility.editingTextField = false;
							EditorGUIUtility.SetWantsMouseJumping(0);
							Event.current.Use(); 

							ResetVisuals();
							if (SphereRadius == 0)
							{
								Cancel();
							}
							break;
						}
						break;
					}
				}
				
			}
		}
        //void OnSceneGUI() <- paints -everything- again for every selected brush
        public static void OnSceneGUI(SceneView sceneView)
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }


            /*
             * int prevHotControl		= GUIUtility.hotControl;
             * int prevKeyboardControl = GUIUtility.keyboardControl;
             *
             * // make it impossible for the tool to click in the bottom bar area
             * int bottomBarId	 = GUIUtility.GetControlID (BottomBarInputHash, FocusType.Passive);
             * bool forceRevert = false;
             * //if (GUIUtility.hotControl == 0)
             * {
             *      var bottomBarRect = sceneView.position;
             *      var min = bottomBarRect.min;
             *      var max = bottomBarRect.max;
             *
             *      min.y = max.y - (GUIStyleUtility.BottomToolBarHeight + 18);
             *
             *      bottomBarRect.min = min;
             *      bottomBarRect.max = max;
             *
             *      if (bottomBarRect.Contains(Event.current.mousePosition))
             *      {
             *              GUIUtility.hotControl	   = bottomBarId;
             *              GUIUtility.keyboardControl = bottomBarId;
             *              forceRevert = true;
             *      }
             * }
             */
            SelectionUtility.HandleEvents();
            InitTools();

            HandleBuilderEvents();
            //HandleYMode();
            {
                UpdateTool();

                if (instance.activeTool != null)
                {
                    if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
                    {
                        // handle the tool
                        var sceneSize = sceneView.position.size;
                        var sceneRect = new Rect(0, 0, sceneSize.x, sceneSize.y - ((GUIStyleUtility.BottomToolBarHeight + 4) + 17));
                        //var originalEventType = Event.current.type;
                        //if (originalEventType == EventType.MouseMove ||
                        //	originalEventType == EventType.MouseUp)
                        //	holdingDownMouse = false;

                        //var mousePos = Event.current.mousePosition;
                        //if (originalEventType == EventType.Layout ||
                        //	originalEventType == EventType.Repaint ||
                        //	sceneRect.Contains(mousePos) ||
                        //	holdingDownMouse)
                        instance.activeTool.HandleEvents(sceneRect);

                        //if (originalEventType == EventType.MouseDown ||
                        //	originalEventType == EventType.MouseDrag)
                        //	holdingDownMouse = true;
                    }
                    else
                    {
                        if (Event.current.type == EventType.Repaint)
                        {
                            var brushes      = instance.filteredSelection.BrushTargets;
                            var wireframes   = new List <GeometryWireframe>(brushes.Length);
                            var translations = new List <Vector3>(brushes.Length);
                            for (int i = 0; i < brushes.Length; i++)
                            {
                                var brush = brushes[i];
                                if (!brush)
                                {
                                    continue;
                                }

                                var brushCache = InternalCSGModelManager.GetBrushCache(brush);
                                if (brushCache == null ||
                                    brushCache.childData == null ||
                                    !brushCache.childData.Model)
                                {
                                    continue;
                                }

                                var brushTranslation = brushCache.compareTransformation.modelLocalPosition + brushCache.childData.ModelTransform.position;

                                wireframes.Add(BrushOutlineManager.GetBrushOutline(brushes[i].brushID));
                                translations.Add(brushTranslation);
                            }
                            if (wireframes.Count > 0)
                            {
                                CSGRenderer.DrawSelectedBrushes(instance.zTestLineMeshManager, instance.noZTestLineMeshManager,
                                                                wireframes.ToArray(), translations.ToArray(),
                                                                ColorSettings.SelectedOutlines, ToolConstants.thickLineScale);
                            }
                            MaterialUtility.LineDashMultiplier      = 1.0f;
                            MaterialUtility.LineThicknessMultiplier = 1.0f;
                            MaterialUtility.LineAlphaMultiplier     = 1.0f;
                            instance.zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);
                            instance.zTestLineMeshManager.Render(MaterialUtility.ZTestGenericLine);
                        }
                    }
                }
            }

            /*
             * // reset the control so the bottom bar can take over
             * if (forceRevert)
             * {
             *      GUIUtility.hotControl		= prevHotControl;
             *      GUIUtility.keyboardControl	= prevKeyboardControl;
             * }
             */

            int sceneWindowId   = GUIUtility.GetControlID(SceneWindowHash, FocusType.Passive);
            var sceneWindowType = Event.current.GetTypeForControl(sceneWindowId);

            if (sceneWindowType == EventType.Repaint)
            {
                if (currentEditorWindows.Count > 0)
                {
                    for (int i = 0; i < currentEditorWindows.Count; i++)
                    {
                        currentEditorWindows[i].Repaint();
                    }
                    return;
                }
            }

            if (sceneWindowType == EventType.MouseMove)
            {
                SceneTools.IsDraggingObjectInScene = false;
            }

            if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                if (sceneView != null && sceneWindowType != EventType.Used && !SceneTools.IsDraggingObjectInScene)
                {
                    if (currentEditorWindows.Count == 0)
                    {
                        try
                        {
                            Handles.BeginGUI();
                            Rect windowRect = new Rect(Vector2.zero, sceneView.position.size);
                            CSGBrushEditorGUI.HandleWindowGUI(windowRect);
                        }
                        finally
                        {
                            Handles.EndGUI();
                        }
                    }
                }
            }
        }