Exemple #1
0
        protected override Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
        {
            Vector3 upperBound = newBounds.max;
            Vector3 lowerBound = newBounds.min;
            // ensure radius changes uniformly
            int changedAxis = 0;

            switch (handle)
            {
            case HandleDirection.NegativeY:
            case HandleDirection.PositiveY:
                changedAxis = 1;
                break;

            case HandleDirection.NegativeZ:
            case HandleDirection.PositiveZ:
                changedAxis = 2;
                break;
            }
            float rad = 0.5f * (upperBound[changedAxis] - lowerBound[changedAxis]);

            for (int axis = 0; axis < 3; ++axis)
            {
                if (axis == changedAxis)
                {
                    continue;
                }
                lowerBound[axis] = center[axis] - rad;
                upperBound[axis] = center[axis] + rad;
            }
            return(new Bounds((upperBound + lowerBound) * 0.5f, upperBound - lowerBound));
        }
        protected void DrawHandleMidpoint(int handleControlID, Vector3 handlePosition, Quaternion handleRotation, float handleSize, EventType eventType)
        {
            // Highlight the plane we are currently interacting with.
            if (handleControlID == GUIUtility.hotControl)
            {
                HandleDirection handleDirection = HandleDirectionFromRotation(handleRotation);
                DrawHandleDirectionPlane(handleDirection, size, center);
            }

            // Draw standard PrimitiveBoundsHandle mindpoint handle.
            Handles.DotHandleCap(handleControlID, handlePosition, handleRotation, handleSize, eventType);
        }
        protected static void DrawHandleDirectionPlane(HandleDirection handleDirection, Vector3 size, Vector3 center)
        {
            // Set global Handles.color to white to avoid global state from interfering with the desired colors set at DrawSolidRectangleWithOutline().
            Color handlesColorPrevious = Handles.color;

            Handles.color = Color.white;

            Color       planeColorOutline   = ColorFromHandleDirection(handleDirection);
            const float planeColorFillAlpha = 0.25f;
            Color       planeColorFill      = planeColorOutline * planeColorFillAlpha;

            PlaneVerticesFromHandleDirection(ref s_PlaneVertices, handleDirection, size, center);
            Handles.DrawSolidRectangleWithOutline(s_PlaneVertices, planeColorFill, planeColorOutline);

            Handles.color = handlesColorPrevious;
        }
 protected override Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
 {
     // special case for Y axis because decal mesh is centered at 0, -0.5, 0
     if (handle == HandleDirection.NegativeY)
     {
         m_Translation = Vector3.zero;
         m_Scale       = newBounds.size;
     }
     else if (handle == HandleDirection.PositiveY)
     {
         m_Translation = (newBounds.center + newBounds.extents - (m_Center + 0.5f * m_Size));
         m_Scale       = (m_Size + m_Translation);
     }
     else
     {
         m_Translation = newBounds.center - m_Center;
         m_Scale       = newBounds.size;
     }
     return(newBounds);
 }
        // Could use a static readonly LUT, but this would require syncing with order with enum HandleDirection.
        protected static Color ColorFromHandleDirection(HandleDirection handleDirection)
        {
            switch (handleDirection)
            {
            case HandleDirection.PositiveX:
            case HandleDirection.NegativeX:
                return(Handles.xAxisColor);

            case HandleDirection.PositiveY:
            case HandleDirection.NegativeY:
                return(Handles.yAxisColor);

            case HandleDirection.PositiveZ:
            case HandleDirection.NegativeZ:
                return(Handles.zAxisColor);

            default:
                throw new ArgumentOutOfRangeException("handleDirection", "Must be PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, or NegativeZ");
            }
        }
Exemple #6
0
        protected override Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
        {
            int changedAxis = k_DirectionX;

            switch (handle)
            {
            case HandleDirection.NegativeY:
            case HandleDirection.PositiveY:
                changedAxis = k_DirectionY;
                break;

            case HandleDirection.NegativeZ:
            case HandleDirection.PositiveZ:
                changedAxis = k_DirectionZ;
                break;
            }

            Vector3 upperBound = newBounds.max;
            Vector3 lowerBound = newBounds.min;

            // ensure height cannot be made less than diameter
            if (changedAxis == m_HeightAxis)
            {
                int radiusAxis;
                GetRadiusAxis(out radiusAxis);
                float diameter  = upperBound[radiusAxis] - lowerBound[radiusAxis];
                float newHeight = upperBound[m_HeightAxis] - lowerBound[m_HeightAxis];
                if (newHeight < diameter)
                {
                    if (handle == HandleDirection.PositiveX || handle == HandleDirection.PositiveY || handle == HandleDirection.PositiveZ)
                    {
                        upperBound[m_HeightAxis] = lowerBound[m_HeightAxis] + diameter;
                    }
                    else
                    {
                        lowerBound[m_HeightAxis] = upperBound[m_HeightAxis] - diameter;
                    }
                }
            }
            // ensure radius changes uniformly and enlarges the height if necessary
            else
            {
                // try to return height to its value at the time handle was clicked
                upperBound[m_HeightAxis] = boundsOnClick.center[m_HeightAxis] + 0.5f * boundsOnClick.size[m_HeightAxis];
                lowerBound[m_HeightAxis] = boundsOnClick.center[m_HeightAxis] - 0.5f * boundsOnClick.size[m_HeightAxis];

                float rad = 0.5f * (upperBound[changedAxis] - lowerBound[changedAxis]);
                float halfCurrentHeight = 0.5f * (upperBound[m_HeightAxis] - lowerBound[m_HeightAxis]);
                for (int axis = 0; axis < 3; ++axis)
                {
                    if (axis == changedAxis)
                    {
                        continue;
                    }
                    float amt = axis == m_HeightAxis?Mathf.Max(halfCurrentHeight, rad) : rad;

                    lowerBound[axis] = center[axis] - amt;
                    upperBound[axis] = center[axis] + amt;
                }
            }
            return(new Bounds((upperBound + lowerBound) * 0.5f, upperBound - lowerBound));
        }
Exemple #7
0
 protected virtual Bounds OnHandleChanged(HandleDirection handle, Bounds boundsOnClick, Bounds newBounds)
 {
     return(newBounds);
 }
        protected static void PlaneVerticesFromHandleDirection(ref Vector3[] outVertices, HandleDirection handleDirection, Vector3 boundsSize, Vector3 boundsCenter)
        {
            Vector3 boundsMin = boundsSize * -0.5f + boundsCenter;
            Vector3 boundsMax = boundsSize * 0.5f + boundsCenter;

            switch (handleDirection)
            {
            case HandleDirection.PositiveX:
                outVertices[0] = new Vector3(boundsMax.x, boundsMin.y, boundsMin.z);
                outVertices[1] = new Vector3(boundsMax.x, boundsMax.y, boundsMin.z);
                outVertices[2] = new Vector3(boundsMax.x, boundsMax.y, boundsMax.z);
                outVertices[3] = new Vector3(boundsMax.x, boundsMin.y, boundsMax.z);
                break;

            case HandleDirection.NegativeX:
                outVertices[0] = new Vector3(boundsMin.x, boundsMin.y, boundsMin.z);
                outVertices[1] = new Vector3(boundsMin.x, boundsMax.y, boundsMin.z);
                outVertices[2] = new Vector3(boundsMin.x, boundsMax.y, boundsMax.z);
                outVertices[3] = new Vector3(boundsMin.x, boundsMin.y, boundsMax.z);
                break;

            case HandleDirection.PositiveY:
                outVertices[0] = new Vector3(boundsMin.x, boundsMax.y, boundsMin.z);
                outVertices[1] = new Vector3(boundsMax.x, boundsMax.y, boundsMin.z);
                outVertices[2] = new Vector3(boundsMax.x, boundsMax.y, boundsMax.z);
                outVertices[3] = new Vector3(boundsMin.x, boundsMax.y, boundsMax.z);
                break;

            case HandleDirection.NegativeY:
                outVertices[0] = new Vector3(boundsMin.x, boundsMin.y, boundsMin.z);
                outVertices[1] = new Vector3(boundsMax.x, boundsMin.y, boundsMin.z);
                outVertices[2] = new Vector3(boundsMax.x, boundsMin.y, boundsMax.z);
                outVertices[3] = new Vector3(boundsMin.x, boundsMin.y, boundsMax.z);
                break;

            case HandleDirection.PositiveZ:
                outVertices[0] = new Vector3(boundsMin.x, boundsMin.y, boundsMax.z);
                outVertices[1] = new Vector3(boundsMax.x, boundsMin.y, boundsMax.z);
                outVertices[2] = new Vector3(boundsMax.x, boundsMax.y, boundsMax.z);
                outVertices[3] = new Vector3(boundsMin.x, boundsMax.y, boundsMax.z);
                break;

            case HandleDirection.NegativeZ:
                outVertices[0] = new Vector3(boundsMin.x, boundsMin.y, boundsMin.z);
                outVertices[1] = new Vector3(boundsMax.x, boundsMin.y, boundsMin.z);
                outVertices[2] = new Vector3(boundsMax.x, boundsMax.y, boundsMin.z);
                outVertices[3] = new Vector3(boundsMin.x, boundsMax.y, boundsMin.z);
                break;

            default:
                throw new ArgumentOutOfRangeException("handleDirection", "Must be PositiveX, NegativeX, PositiveY, NegativeY, PositiveZ, or NegativeZ");
            }
        }