Exemplo n.º 1
0
        void OnHierarchyWindowChanged()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            SceneDragToolManager.UpdateDragAndDrop();
            InternalCSGModelManager.UpdateHierarchy();
        }
Exemplo n.º 2
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.º 3
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.º 4
0
        internal static void OnScene(SceneView sceneView)
        {
            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                return;
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }
            UpdateLoop.UpdateOnSceneChange();

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                ColorSettings.isInitialized = false;
            }
            else
            if (!ColorSettings.isInitialized)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    ColorSettings.Update();
                }
            }

            if (!UpdateLoop.IsActive())
            {
                UpdateLoop.ResetUpdateRoutine();
            }

            if (Event.current.type == EventType.MouseDown ||
                Event.current.type == EventType.MouseDrag)
            {
                mousePressed = true;
            }
            else if (Event.current.type == EventType.MouseUp ||
                     Event.current.type == EventType.MouseMove)
            {
                mousePressed = false;
            }

            SceneDragToolManager.OnHandleDragAndDrop(sceneView);
            RectangleSelectionManager.Update(sceneView);
            EditModeManager.InitSceneGUI(sceneView);

            if (Event.current.type == EventType.Repaint)
            {
                MeshInstanceManager.RenderHelperSurfaces(sceneView);
            }

            if (Event.current.type == EventType.Repaint)
            {
                SceneToolRenderer.OnPaint(sceneView);
            }
            else
            //if (fallbackGUI)
            {
                SceneViewBottomBarGUI.ShowGUI(sceneView);
                SceneViewInfoGUI.DrawInfoGUI(sceneView);
            }

            EditModeManager.OnSceneGUI(sceneView);

            //if (fallbackGUI)
            {
                TooltipUtility.InitToolTip(sceneView);
                if (Event.current.type == EventType.Repaint)
                {
                    SceneViewBottomBarGUI.ShowGUI(sceneView);
                    SceneViewInfoGUI.DrawInfoGUI(sceneView);
                }
                if (!mousePressed)
                {
                    Handles.BeginGUI();
                    TooltipUtility.DrawToolTip(getLastRect: false);
                    Handles.EndGUI();
                }
            }

            if (Event.current.type == EventType.Layout)
            {
                var currentFocusControl = CSGHandles.FocusControl;
                if (prevFocusControl != currentFocusControl)
                {
                    prevFocusControl = currentFocusControl;
                    HandleUtility.Repaint();
                }
            }
        }
Exemplo n.º 5
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.º 6
0
        internal static void OnHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            var o = EditorUtility.InstanceIDToObject(instanceID) as GameObject;

            if (selectionRect.Contains(Event.current.mousePosition))
            {
                Transform t = (o == null) ? null : o.transform;
                SceneDragToolManager.OnHandleDragAndDrop(inSceneView: false, transformInInspector: t, selectionRect: selectionRect);
            }

            if (o == null)
            {
                return;
            }

            CSG_GUIStyleUtility.InitStyles();

            var node = o.GetComponent <CSGNode>();

            if (node == null ||
                !node.enabled || (node.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) != 0)
            {
                return;
            }

            CSGOperationType operationType = CSGOperationType.Additive;

            var brush = node as CSGBrush;

            if (brush != null)
            {
                operationType = brush.OperationType;
                var skin = CSG_GUIStyleUtility.Skin;
                GUI.Label(selectionRect, skin.hierarchyOperations[(int)operationType], CSG_GUIStyleUtility.rightAlignedLabel);
                return;
            }
            var operation = node as CSGOperation;

            if (operation != null)
            {
                var skin = CSG_GUIStyleUtility.Skin;
                if (!operation.PassThrough)
                {
                    operationType = operation.OperationType;
                    var operationTypeIndex = (int)operationType;
                    if (operationTypeIndex >= 0 && operationTypeIndex < skin.hierarchyOperations.Length)
                    {
                        GUI.Label(selectionRect, skin.hierarchyOperations[operationTypeIndex], CSG_GUIStyleUtility.rightAlignedLabel);
                    }
                }
                else
                {
                    GUI.Label(selectionRect, skin.hierarchyPassThrough, CSG_GUIStyleUtility.rightAlignedLabel);
                }
                return;
            }
        }
Exemplo n.º 7
0
        internal static void OnScene(SceneView sceneView)
        {
            if (Event.current.type == EventType.MouseMove)
            {
                sceneView.Repaint();
            }

            sceneView.cameraSettings.dynamicClip         = false;
            sceneView.cameraSettings.easingEnabled       = false;
            sceneView.cameraSettings.accelerationEnabled = false;

            //if (sceneView.orthographic)
            //{
            //    sceneView.camera.nearClipPlane = 1;
            //    sceneView.camera.farClipPlane = 1001f;

            //    var camPos = sceneView.pivot;
            //    var camForward = sceneView.camera.transform.forward;
            //    for (int i = 0; i < 3; i++)
            //    {
            //        if (!FastApproximately(camForward[i], 0, .01f))
            //        {
            //            camPos[i] = 1000;
            //        }
            //    }
            //    sceneView.pivot = camPos;
            //}

            if (sceneView.orthographic)
            {
                if (Event.current.type == EventType.KeyDown &&
                    Event.current.keyCode == KeyCode.F)
                {
                    Event.current.Use();
                    sceneView.pivot = Vector3.zero;
                    if (TryGetSelectionBounds(out Bounds bounds))
                    {
                        var sz = bounds.extents.magnitude;
                        sz = Mathf.Clamp(sz, 0.05f, 500);
                        sceneView.pivot = bounds.center;
                        sceneView.size  = sz;
                    }
                }

                if (sceneView.size > 500)
                {
                    sceneView.size = 500;
                }

                if (sceneView.size < .05f)
                {
                    sceneView.size = .05f;
                }
            }

            CSGSettings.RegisterSceneView(sceneView);

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG ||
                EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            UpdateLoop.UpdateOnSceneChange();

            if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG)
            {
                ColorSettings.isInitialized = false;
            }
            else if (!ColorSettings.isInitialized)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    ColorSettings.Update();
                }
            }

            if (!UpdateLoop.IsActive())
            {
                UpdateLoop.ResetUpdateRoutine();
            }

            if (Event.current.type == EventType.MouseDown ||
                Event.current.type == EventType.MouseDrag)
            {
                mousePressed = true;
            }
            else if (Event.current.type == EventType.MouseUp ||
                     Event.current.type == EventType.MouseMove)
            {
                mousePressed = false;
            }

            SceneDragToolManager.OnHandleDragAndDrop(sceneView);
            RectangleSelectionManager.Update(sceneView);
            EditModeManager.InitSceneGUI(sceneView);

            if (Event.current.type == EventType.Repaint)
            {
                MeshInstanceManager.UpdateHelperSurfaces();
                SceneToolRenderer.OnPaint(sceneView);
            }
            else
            {
                SceneViewBottomBarGUI.ShowGUI(sceneView);
                SceneViewInfoGUI.DrawInfoGUI(sceneView);
            }

            //if(EditorWindow.mouseOverWindow == sceneView)
            {
                EditModeManager.OnSceneGUI(sceneView);

                TooltipUtility.InitToolTip(sceneView);

                if (!mousePressed)
                {
                    Handles.BeginGUI();
                    TooltipUtility.DrawToolTip(getLastRect: false);
                    Handles.EndGUI();
                }

                if (Event.current.type == EventType.Layout)
                {
                    var currentFocusControl = CSGHandles.FocusControl;
                    if (prevFocusControl != currentFocusControl)
                    {
                        prevFocusControl = currentFocusControl;
                        HandleUtility.Repaint();
                    }
                }
            }
        }