public void RenderOutlines()
        {
            var zTestGenericLineMaterial   = MaterialUtility.ZTestGenericLine;
            var noZTestGenericLineMaterial = MaterialUtility.NoZTestGenericLine;
            var coloredPolygonMaterial     = MaterialUtility.ColoredPolygonMaterial;

            _polygonManager.Render(coloredPolygonMaterial);

            MaterialUtility.LineAlphaMultiplier     = 0.75f;
            MaterialUtility.LineDashMultiplier      = 4.0f;
            MaterialUtility.LineThicknessMultiplier = ToolConstants.thickLineScale * 2.0f;
            _outlinesManager.Render(noZTestGenericLineMaterial);

            MaterialUtility.LineDashMultiplier      = 0.0f;
            MaterialUtility.LineThicknessMultiplier = ToolConstants.thickLineScale * 2.0f;
            _outlinesManager.Render(zTestGenericLineMaterial);


            MaterialUtility.LineDashMultiplier      = 4.0f;
            MaterialUtility.LineThicknessMultiplier = ToolConstants.thickLineScale;
            _edgeColorsManager.Render(noZTestGenericLineMaterial);

            MaterialUtility.LineDashMultiplier      = 0.0f;
            MaterialUtility.LineThicknessMultiplier = ToolConstants.thickLineScale;
            _edgeColorsManager.Render(zTestGenericLineMaterial);

            MaterialUtility.LineAlphaMultiplier = 1.0f;
        }
Example #2
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);
        }
Example #3
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);
            }
        }
Example #4
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);
            }
        }
        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;
            }
            }
        }
Example #6
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);
            }
        }
Example #7
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;
            }
            }
        }