Ejemplo n.º 1
0
        public static bool DrawQuadFace(ExtQuad quad, bool face, bool allowBottom, Color color, out bool hasChanged)
        {
            hasChanged = false;

            float scaleRect = quad.LocalScale.magnitude;
            float xScale    = quad.LenghtX / 2;
            float yScale    = quad.LenghtY / 2;


            Matrix4x4 scaleMatrix = Matrix4x4.TRS(quad.Position, quad.Rotation, new Vector3(xScale, 1, yScale));

            using (new Handles.DrawingScope(scaleMatrix))
            {
                Vector3 up = scaleMatrix.ExtractRotation() * Vector3.up;
                bool    isCameraViewBehindFace = Vector3.Dot(ExtSceneView.GetSceneViewCameraTransform().forward, up) > 0 && !allowBottom;

                Handles.color = (isCameraViewBehindFace) ? new Color(color.r, color.g, color.b, color.a / 2f) : color;

                float     scale = 1f;
                Vector3[] verts = new Vector3[]
                {
                    new Vector3(-scale, 0, -scale),
                    new Vector3(-scale, 0, +scale),
                    new Vector3(+scale, 0, +scale),
                    new Vector3(+scale, 0, -scale)
                };

                if (!face)
                {
                    Handles.DrawSolidRectangleWithOutline(verts, Handles.color, Color.clear);
                }

                Quaternion rotation = Quaternion.identity * Quaternion.LookRotation(Vector3.up);


                if (!Event.current.alt && Event.current.button != 2 && Handles.Button(
                        Vector3.zero,
                        Quaternion.identity * Quaternion.LookRotation(Vector3.up),
                        1,
                        1,
                        Handles.RectangleHandleCap))
                {
                    if (isCameraViewBehindFace)
                    {
                        Debug.Log("not behind face");
                        return(false);
                    }
                    Debug.Log("face pressed");
                    face       = !face;
                    hasChanged = true;
                    Use();
                }
            }
            return(face);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// draw a disc
        /// </summary>
        public static GravityOverrideDisc DrawDisc(ExtCircle circle, GravityOverrideDisc discGravity, Color color, bool allowBottom, out bool hasChanged)
        {
            hasChanged = false;
            Quaternion rotation     = ExtRotation.QuaternionFromVectorDirector(circle.Normal, Vector3.up);
            bool       topFace      = discGravity.Face;
            bool       topExtremity = discGravity.Borders;

            bool isCameraViewBehindFace = Vector3.Dot(ExtSceneView.GetSceneViewCameraTransform().forward, circle.Normal) > 0 && !allowBottom;

            Handles.color = color;
            if (!Event.current.alt && Event.current.button != 2 && Handles.Button(circle.Point,
                                                                                  rotation,
                                                                                  circle.Radius,
                                                                                  circle.Radius, Handles.CircleHandleCap))
            {
                Debug.Log("extremity pressed");
                discGravity.Borders = !discGravity.Borders;
                hasChanged          = true;
                Use();
            }

            if (!topFace)
            {
                Handles.color = (isCameraViewBehindFace) ? new Color(color.r, color.g, color.b, color.a / 2) : color;
                Handles.DrawSolidDisc(circle.Point, circle.Normal, circle.Radius / 10 * 8);
            }
            if (!topExtremity)
            {
                Handles.color = (isCameraViewBehindFace) ? new Color(color.r, color.g, color.b, color.a / 2) : color;
                ExtHandle.DrawCircleThickness(circle, 50, ExtHandle.DrawOutlineType.INSIDE);
            }
            Handles.color = Color.red;

            if (!Event.current.alt && Event.current.button != 2 && Handles.Button(circle.Point,
                                                                                  rotation,
                                                                                  circle.Radius / 10 * 7,
                                                                                  circle.Radius / 10 * 7, Handles.CircleHandleCap))
            {
                if (isCameraViewBehindFace)
                {
                    Debug.Log("not behind face");
                }
                else
                {
                    Debug.Log("Face pressed !");
                    discGravity.Face = !discGravity.Face;
                    hasChanged       = true;
                    Use();
                }
            }

            return(discGravity);
        }
Ejemplo n.º 3
0
        ///
        ///      6 ------------ 7
        ///    / |    3       / |
        ///  5 ------------ 8   |
        ///  |   |          |   |
        ///  | 5 |     6    | 2 |     ------8-----
        ///  |   |   1      |   |
        ///  |  2 ----------|-- 3
        ///  |/       4     | /     |       3      |
        ///  1 ------------ 4
        ///
        ///          6 ------6----- 5 ------2----- 8 -----10----- 7       -
        ///          |              |              |              |
        ///          |              |              |              |
        ///          5      5       1       1      3       2      11       6       |
        ///          |              |              |              |
        ///          |              |              |              |
        ///          2 ------7----- 1 ------4----- 4 ------12---- 3       -
        ///
        ///
        ///                         |       4      |
        ///
        ///
        ///                           ------9-----
        public static GravityOverrideCube DrawCube(ExtCube cube, GravityOverrideCube cubeGravity, Color color, out bool hasChanged)
        {
            hasChanged = false;
            bool changed = hasChanged;

            float sizeLine  = cube.LocalScale.magnitude / 35;
            float sizePoint = cube.LocalScale.magnitude / 30;

            Color colorQuad = new Color(color.r, color.g, color.b, color.a * 0.5f);
            Color colorLine = new Color(color.r, color.g, color.b, color.a * 0.8f);

            //we have to order the button from the point of view of the camera
            FloatRange[] facesArranged = ExtCube.GetOrdersOfFaceFromPoint(cube, ExtSceneView.GetSceneViewCameraTransform().position);
            for (int i = facesArranged.Length - 1; i >= 0; i--)
            {
                switch (facesArranged[i].Min)
                {
                case 1:
                    cubeGravity.Face1  = DrawQuadFace(new ExtQuad(cube.P1, cube.P5, cube.P8, cube.P4), cubeGravity.Face1, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line1  = DrawLineTrunk(cubeGravity.Line1, cube.P1, cube.P5, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line2  = DrawLineTrunk(cubeGravity.Line2, cube.P5, cube.P8, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line3  = DrawLineTrunk(cubeGravity.Line3, cube.P8, cube.P4, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line4  = DrawLineTrunk(cubeGravity.Line4, cube.P4, cube.P1, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point1 = DrawPoint(cubeGravity.Point1, cube.P1, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point5 = DrawPoint(cubeGravity.Point5, cube.P5, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point8 = DrawPoint(cubeGravity.Point8, cube.P8, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point4 = DrawPoint(cubeGravity.Point4, cube.P4, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;

                case 2:
                    cubeGravity.Face2  = DrawQuadFace(new ExtQuad(cube.P4, cube.P8, cube.P7, cube.P3), cubeGravity.Face2, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line3  = DrawLineTrunk(cubeGravity.Line3, cube.P4, cube.P8, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line10 = DrawLineTrunk(cubeGravity.Line10, cube.P8, cube.P7, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line11 = DrawLineTrunk(cubeGravity.Line11, cube.P7, cube.P3, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line12 = DrawLineTrunk(cubeGravity.Line12, cube.P3, cube.P4, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point4 = DrawPoint(cubeGravity.Point4, cube.P4, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point8 = DrawPoint(cubeGravity.Point8, cube.P8, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point7 = DrawPoint(cubeGravity.Point7, cube.P7, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point3 = DrawPoint(cubeGravity.Point3, cube.P3, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;

                case 3:
                    cubeGravity.Face3  = DrawQuadFace(new ExtQuad(cube.P5, cube.P6, cube.P7, cube.P8), cubeGravity.Face3, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line6  = DrawLineTrunk(cubeGravity.Line6, cube.P5, cube.P6, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line8  = DrawLineTrunk(cubeGravity.Line8, cube.P6, cube.P7, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line10 = DrawLineTrunk(cubeGravity.Line10, cube.P7, cube.P8, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line2  = DrawLineTrunk(cubeGravity.Line2, cube.P5, cube.P8, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point5 = DrawPoint(cubeGravity.Point5, cube.P5, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point6 = DrawPoint(cubeGravity.Point6, cube.P6, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point7 = DrawPoint(cubeGravity.Point7, cube.P7, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point8 = DrawPoint(cubeGravity.Point8, cube.P8, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;

                case 4:
                    cubeGravity.Face4  = DrawQuadFace(new ExtQuad(cube.P2, cube.P1, cube.P4, cube.P3), cubeGravity.Face4, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line7  = DrawLineTrunk(cubeGravity.Line7, cube.P2, cube.P1, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line4  = DrawLineTrunk(cubeGravity.Line4, cube.P1, cube.P4, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line12 = DrawLineTrunk(cubeGravity.Line12, cube.P4, cube.P3, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line9  = DrawLineTrunk(cubeGravity.Line9, cube.P2, cube.P3, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point2 = DrawPoint(cubeGravity.Point2, cube.P2, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point1 = DrawPoint(cubeGravity.Point1, cube.P1, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point4 = DrawPoint(cubeGravity.Point4, cube.P4, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point3 = DrawPoint(cubeGravity.Point3, cube.P3, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;

                case 5:
                    cubeGravity.Face5  = DrawQuadFace(new ExtQuad(cube.P2, cube.P6, cube.P5, cube.P1), cubeGravity.Face5, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line5  = DrawLineTrunk(cubeGravity.Line5, cube.P2, cube.P6, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line6  = DrawLineTrunk(cubeGravity.Line6, cube.P6, cube.P5, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line1  = DrawLineTrunk(cubeGravity.Line1, cube.P5, cube.P1, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line7  = DrawLineTrunk(cubeGravity.Line7, cube.P1, cube.P2, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point2 = DrawPoint(cubeGravity.Point2, cube.P2, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point6 = DrawPoint(cubeGravity.Point6, cube.P6, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point5 = DrawPoint(cubeGravity.Point5, cube.P5, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point1 = DrawPoint(cubeGravity.Point1, cube.P1, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;

                case 6:
                    cubeGravity.Face6  = DrawQuadFace(new ExtQuad(cube.P3, cube.P7, cube.P6, cube.P2), cubeGravity.Face6, false, colorQuad, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line11 = DrawLineTrunk(cubeGravity.Line11, cube.P3, cube.P7, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line8  = DrawLineTrunk(cubeGravity.Line8, cube.P7, cube.P6, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line5  = DrawLineTrunk(cubeGravity.Line5, cube.P6, cube.P2, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Line9  = DrawLineTrunk(cubeGravity.Line9, cube.P3, cube.P2, colorLine, sizeLine, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point3 = DrawPoint(cubeGravity.Point3, cube.P3, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point7 = DrawPoint(cubeGravity.Point7, cube.P7, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point6 = DrawPoint(cubeGravity.Point6, cube.P6, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    cubeGravity.Point2 = DrawPoint(cubeGravity.Point2, cube.P2, color, sizePoint, out changed); hasChanged = (changed) ? true : hasChanged;
                    break;
                }
            }
            return(cubeGravity);
        }