예제 #1
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();
        }
예제 #2
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);
        }