예제 #1
0
        private void OnRepaint(SceneView sceneView, Event e)
        {
            OnRepaintGUI(sceneView, e);

            if (activePolygon != null && activePolygon.Vertices.Length >= 3)
            {
                Camera sceneViewCamera = sceneView.camera;

                SabreCSGResources.GetVertexMaterial().SetPass(0);
                GL.PushMatrix();
                GL.LoadPixelMatrix();

                GL.Begin(GL.QUADS);

                GL.Color(Color.white);

                Vector3 target = sceneViewCamera.WorldToScreenPoint(mouseHoverPoint);

                if (target.z > 0)
                {
                    // Make it pixel perfect
                    target = MathHelper.RoundVector3(target);
                    SabreGraphics.DrawBillboardQuad(target, 8, 8);
                }

                GL.End();
                GL.PopMatrix();

                Handles.DrawWireArc(mouseHoverPoint, activePolygon.Plane.normal, activePolygon.GetTangent(), 360f, brushRadius);
            }
        }
예제 #2
0
        void DrawVertices(SceneView sceneView, Event e)
        {
            Camera sceneViewCamera = sceneView.camera;

            SabreGraphics.GetVertexMaterial().SetPass(0);
            GL.PushMatrix();
            GL.LoadPixelMatrix();

            GL.Begin(GL.QUADS);

            // Draw each handle, colouring it if it's selected
            foreach (PrimitiveBrush brush in targetBrushes)
            {
                Polygon[] polygons = brush.GetPolygons();

                Vector3 target;

                for (int i = 0; i < polygons.Length; i++)
                {
                    for (int j = 0; j < polygons[i].Vertices.Length; j++)
                    {
                        Vertex vertex = polygons[i].Vertices[j];

                        if (selectedVertices.ContainsKey(vertex))
                        {
                            GL.Color(new Color32(0, 255, 128, 255));
                        }
                        else
                        {
                            GL.Color(Color.white);
                        }

                        target = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(vertex.Position));
                        if (target.z > 0)
                        {
                            // Make it pixel perfect
                            target = MathHelper.RoundVector3(target);
                            SabreGraphics.DrawBillboardQuad(target, 8, 8);
                        }
                    }
                }
            }

            GL.End();

            // Draw lines for selected edges
            SabreGraphics.GetSelectedBrushMaterial().SetPass(0);

            GL.Begin(GL.LINES);
            GL.Color(Color.green);

            for (int edgeIndex = 0; edgeIndex < selectedEdges.Count; edgeIndex++)
            {
                Edge edge = selectedEdges[edgeIndex];

                if (selectedVertices.ContainsKey(edge.Vertex1))
                {
                    Brush brush = selectedVertices[edge.Vertex1];

                    Vector3 target1 = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(edge.Vertex1.Position));
                    Vector3 target2 = sceneViewCamera.WorldToScreenPoint(brush.transform.TransformPoint(edge.Vertex2.Position));

                    if (target1.z > 0 && target2.z > 0)
                    {
                        SabreGraphics.DrawScreenLine(target1, target2);
                    }
                }
            }

            GL.End();

            GL.PopMatrix();
        }
예제 #3
0
        private static void OnRepaint(SceneView sceneView)
        {
            float distanceScaler = 1f;

#if UNITY_5_4_OR_NEWER
            distanceScaler = EditorGUIUtility.pixelsPerPoint;
#endif
            // Distance in points from the radial center to the center of each option circle
            float distance = 100 * distanceScaler;

            // Number of sectors (or slices) the circle is cut into
            int angleCount = messages.Length;
            // Radians angle that each sector takes up
            float angleDelta = (Mathf.PI * 2f) / (float)angleCount;

            // Radial center position
            Vector2 centerPosition = new Vector2(Screen.width / 2, Screen.height / 2);

            // Sector being highlighted
            int highlightIndex = GetIndex(centerPosition);

            GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel);
            labelStyle.alignment = TextAnchor.MiddleCenter;

            // Draw normal circles
            SabreCSGResources.GetCircleMaterial().SetPass(0);

            GL.PushMatrix();
            GL.LoadPixelMatrix();

            GL.Begin(GL.QUADS);

            for (int i = 0; i < angleCount; i++)
            {
                float angle = i * angleDelta;
                Color color = colors[i];

                // Highlighted circle should be a bit more opaque
                if (i == highlightIndex)
                {
                    color.a = 0.75f;
                }
                else
                {
                    color.a = 0.5f;
                }
                GL.Color(color);

                Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                SabreGraphics.DrawBillboardQuad(position, 64, 64);
            }

            // Draw white dots from the center towards the highlighted circle
            if (highlightIndex != -1)
            {
                float angle = highlightIndex * angleDelta;

                GL.Color(Color.white);

                Vector3 position = centerPosition;
                SabreGraphics.DrawBillboardQuad(position, 8, 8);

                position = centerPosition + 20 * distanceScaler * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                SabreGraphics.DrawBillboardQuad(position, 16, 16);

                position = centerPosition + 50 * distanceScaler * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                SabreGraphics.DrawBillboardQuad(position, 32, 32);
            }
            else
            {
                // No highlighted option, just draw a white dot at the center
                GL.Color(Color.white);

                Vector3 position = centerPosition;
                SabreGraphics.DrawBillboardQuad(position, 16, 16);
            }

            GL.End();
            GL.PopMatrix();

            // Draw a white circle around the edge of the higlighted circle
            if (highlightIndex != -1)
            {
                SabreCSGResources.GetCircleOutlineMaterial().SetPass(0);

                GL.PushMatrix();
                GL.LoadPixelMatrix();

                GL.Begin(GL.QUADS);

                float angle = highlightIndex * angleDelta;

                GL.Color(Color.white);

                Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));
                SabreGraphics.DrawBillboardQuad(position, 64, 64);

                GL.End();
                GL.PopMatrix();
            }

            // Draw the text

            Vector3 screenOffset = new Vector3(0, 5, 0);

            for (int i = 0; i < angleCount; i++)
            {
                string message = messages[i];
                // The Iso/Persp toggle should show the appropriate text based on active scene view
                if (message == "Iso" && sceneView.orthographic)
                {
                    message = "Persp";
                }

                // Make the font size bigger for a highlighted option
                if (i == highlightIndex)
                {
                    labelStyle.fontSize = 14;
                }
                else
                {
                    labelStyle.fontSize = 12;
                }

                float angle = i * angleDelta;

                Vector3 position = centerPosition + distance * new Vector2(Mathf.Sin(angle), Mathf.Cos(angle));

                // Offset the position slightly so that it better aligns with the drawn circle
                position += screenOffset * distanceScaler;

                // Need to manually offset the text to be center aligned for some reason
                Vector2 size = labelStyle.CalcSize(new GUIContent(message));
                position += new Vector3(-size.x * distanceScaler / 4f, 0, 0);

                // Calculate the world position of the screen point just in front of the camera
                Ray     ray   = sceneView.camera.ScreenPointToRay(position);
                Vector3 world = ray.origin + ray.direction * 0.01f;

                // Draw using a world space Handle label
                Handles.Label(world, message, labelStyle);
            }
        }
예제 #4
0
        void OnRepaint(SceneView sceneView, Event e)
        {
            if (primaryTargetBrush != null)
            {
                // Use a helper method to draw a visualisation of the clipping plane
                float largestExtent = GetBounds().GetLargestExtent();
                float planeSize     = largestExtent * 4f;
//				clipPlane.
                SabreGraphics.DrawPlane(displayPlane, planePosition, new Color(0f, 1f, 0f, .3f), new Color(1f, 0f, 0f, .3f), planeSize);

                // Selected brush green outline
                SabreGraphics.GetSelectedBrushMaterial().SetPass(0);

                // Draw black lines where the clip plane intersects the brushes
                if (!sceneView.camera.orthographic || EditorHelper.GetSceneViewCamera(sceneView) == EditorHelper.SceneViewCamera.Other)
                {
                    GL.Begin(GL.LINES);
                    GL.Color(Color.black);

                    foreach (PrimitiveBrush brush in targetBrushes)
                    {
                        Polygon[] polygons = brush.GenerateTransformedPolygons();
                        foreach (Polygon polygon in polygons)
                        {
                            Vector3 position1;
                            Vector3 position2;
                            if (Polygon.PlanePolygonIntersection(polygon, out position1, out position2, displayPlane))
                            {
                                GL.Vertex(position1);
                                GL.Vertex(position2);
                            }
                        }
                    }

                    GL.End();
                }

                if (displayPoint)
                {
                    Camera sceneViewCamera = sceneView.camera;

                    SabreGraphics.GetVertexMaterial().SetPass(0);
                    GL.PushMatrix();
                    GL.LoadPixelMatrix();

                    GL.Begin(GL.QUADS);


                    // Draw points in reverse order because we want the precedence to be Red, Green, Blue

                    GL.Color(Color.blue);

                    Vector3 target = sceneViewCamera.WorldToScreenPoint(points[2]);

                    if (target.z > 0)
                    {
                        // Make it pixel perfect
                        target = MathHelper.RoundVector3(target);
                        SabreGraphics.DrawBillboardQuad(target, 8, 8);
                    }

                    GL.Color(Color.green);

                    target = sceneViewCamera.WorldToScreenPoint(points[1]);

                    if (target.z > 0)
                    {
                        // Make it pixel perfect
                        target = MathHelper.RoundVector3(target);
                        SabreGraphics.DrawBillboardQuad(target, 8, 8);
                    }

                    GL.Color(Color.red);

                    target = sceneViewCamera.WorldToScreenPoint(points[0]);

                    if (target.z > 0)
                    {
                        // Make it pixel perfect
                        target = MathHelper.RoundVector3(target);
                        SabreGraphics.DrawBillboardQuad(target, 8, 8);
                    }

                    GL.End();
                    GL.PopMatrix();
                }
            }

            // Draw UI specific to this editor
//			GUI.backgroundColor = Color.red;
            Rect     rectangle = new Rect(0, 50, 210, 130);
            GUIStyle toolbar   = new GUIStyle(EditorStyles.toolbar);

            toolbar.normal.background = SabreGraphics.ClearTexture;
            toolbar.fixedHeight       = rectangle.height;
            GUILayout.Window(140006, rectangle, OnToolbarGUI, "", toolbar);
        }
예제 #5
0
        private void OnRepaint(SceneView sceneView, Event e)
        {
            Camera sceneViewCamera = sceneView.camera;

            //			if(hoverPoint.HasValue)
            {
                // Draw the active polygon
                if (activePolygon != null)
                {
                    SabreCSGResources.GetSelectedBrushMaterial().SetPass(0);

                    SabreGraphics.DrawPolygons(new Color(1, 1, 0, 0.15f), new Color(1, 1, 0, 0.5f), activePolygon);
                }

                SabreCSGResources.GetVertexMaterial().SetPass(0);
                GL.PushMatrix();
                GL.LoadPixelMatrix();

                GL.Begin(GL.QUADS);

                if (activePolygon != null)
                {
                    GL.Color(Color.yellow);// new Color(0.75f,0.75f,0.75f,1));
                }
                else
                {
                    GL.Color(Color.white);
                }

                Vector3 target = sceneViewCamera.WorldToScreenPoint(hoverPoint);

                if (target.z > 0)
                {
                    // Make it pixel perfect
                    target = MathHelper.RoundVector3(target);
                    SabreGraphics.DrawBillboardQuad(target, 8, 8);
                }

                for (int i = 0; i < hitPoints.Count; i++)
                {
                    target = sceneViewCamera.WorldToScreenPoint(hitPoints[i]);
                    GL.Color(Color.blue);
                    if (target.z > 0)
                    {
                        // Make it pixel perfect
                        target = MathHelper.RoundVector3(target);
                        SabreGraphics.DrawBillboardQuad(target, 8, 8);
                    }
                }

                GL.End();
                GL.PopMatrix();
            }

            if (drawMode == DrawMode.RectangleBase || drawMode == DrawMode.PolygonBase)
            {
                List <Vector3> pointsToDraw = new List <Vector3>();
                if (drawMode == DrawMode.RectangleBase)
                {
                    pointsToDraw.AddRange(GetRectanglePoints());
                }
                else
                {
                    pointsToDraw.AddRange(hitPoints);
                    pointsToDraw.Insert(pointsToDraw.Count, hoverPoint);
                }

                SabreCSGResources.GetSelectedBrushMaterial().SetPass(0);

                //				GL.Begin(GL);
                //				GL.Color(new Color32(0, 181, 255, 100));
                //
                //				// Draw each point
                //				for (int i = 0; i < pointsToDraw.Count; i++)
                //				{
                //					GL.Vertex(pointsToDraw[i]);
                //				}
                //
                //				GL.End();

                // Marquee border
                GL.Begin(GL.LINES);

                if (csgMode == CSGMode.Add)
                {
                    GL.Color(Color.blue);
                }
                else if (csgMode == CSGMode.Subtract)
                {
                    GL.Color(Color.yellow);
                }

                // Draw lines between all the points
                for (int i = 0; i < pointsToDraw.Count; i++)
                {
                    // In polygon mode, if it's bigger than a line, draw the last edge in grey
                    if (i == pointsToDraw.Count - 1 &&
                        drawMode == DrawMode.PolygonBase &&
                        pointsToDraw.Count > 2 &&
                        !selectingHeight)
                    {
                        GL.Color(Color.grey);
                    }
                    // Draw a line from one point to the next
                    GL.Vertex(pointsToDraw[i]);
                    GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count]);
                }

                if (selectingHeight)
                {
                    Vector3 offset = GetActivePlane().normal *prismHeight;

                    for (int i = 0; i < pointsToDraw.Count; i++)
                    {
                        // Draw a line from one point to the next
                        GL.Vertex(pointsToDraw[i]);
                        GL.Vertex(pointsToDraw[i] + offset);
                    }

                    GL.Color(Color.grey);
                    // Draw grid lines along the prism to indicate size
                    for (int heightLine = 1; heightLine < Mathf.Abs(prismHeight); heightLine++)
                    {
                        for (int i = 0; i < pointsToDraw.Count; i++)
                        {
                            Vector3 gridOffset = GetActivePlane().normal *heightLine *Mathf.Sign(prismHeight);
                            // Draw a line from one point to the next
                            GL.Vertex(pointsToDraw[i] + gridOffset);
                            GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count] + gridOffset);
                        }
                    }

                    GL.Color(Color.green);
                    for (int i = 0; i < pointsToDraw.Count; i++)
                    {
                        // Draw a line from one point to the next
                        GL.Vertex(pointsToDraw[i] + offset);
                        GL.Vertex(pointsToDraw[(i + 1) % pointsToDraw.Count] + offset);
                    }
                }

                GL.End();
            }

            //			Rect rectangle = new Rect(0, 50, 210, 130);
            //			GUIStyle toolbar = new GUIStyle(EditorStyles.toolbar);
            //			toolbar.normal.background = SabreCSGResources.ClearTexture;
            //			toolbar.fixedHeight = rectangle.height;
            //			GUILayout.Window(140010, rectangle, OnToolbarGUI, "",toolbar);
        }