void SetHandlePlanes()
        {
            handlePlanes.Clear();

            if (TranslatingTypeContains(TransformType.Move))
            {
                Vector3 pivotToCamera = myCamera.transform.position - pivotPoint;
                float   cameraXSign   = Mathf.Sign(Vector3.Dot(axisInfo.xDirection, pivotToCamera));
                float   cameraYSign   = Mathf.Sign(Vector3.Dot(axisInfo.yDirection, pivotToCamera));
                float   cameraZSign   = Mathf.Sign(Vector3.Dot(axisInfo.zDirection, pivotToCamera));

                float planeSize = this.planeSize;
                if (transformType == TransformType.All)
                {
                    planeSize *= allMoveHandleLengthMultiplier;
                }
                planeSize *= GetDistanceMultiplier();

                Vector3 xDirection = (axisInfo.xDirection * planeSize) * cameraXSign;
                Vector3 yDirection = (axisInfo.yDirection * planeSize) * cameraYSign;
                Vector3 zDirection = (axisInfo.zDirection * planeSize) * cameraZSign;

                Vector3 xPlaneCenter = pivotPoint + (yDirection + zDirection);
                Vector3 yPlaneCenter = pivotPoint + (xDirection + zDirection);
                Vector3 zPlaneCenter = pivotPoint + (xDirection + yDirection);

                AddQuad(xPlaneCenter, axisInfo.yDirection, axisInfo.zDirection, planeSize, handlePlanes.x);
                AddQuad(yPlaneCenter, axisInfo.xDirection, axisInfo.zDirection, planeSize, handlePlanes.y);
                AddQuad(zPlaneCenter, axisInfo.xDirection, axisInfo.yDirection, planeSize, handlePlanes.z);
            }
        }
        void SetHandleLines()
        {
            handleLines.Clear();

            if (TranslatingTypeContains(TransformType.Move) || TranslatingTypeContains(TransformType.Scale))
            {
                float lineWidth = handleWidth * GetDistanceMultiplier();

                float xLineLength = 0;
                float yLineLength = 0;
                float zLineLength = 0;
                if (TranslatingTypeContains(TransformType.Move))
                {
                    xLineLength = yLineLength = zLineLength = GetHandleLength(TransformType.Move);
                }
                else if (TranslatingTypeContains(TransformType.Scale))
                {
                    xLineLength = GetHandleLength(TransformType.Scale, Axis.X);
                    yLineLength = GetHandleLength(TransformType.Scale, Axis.Y);
                    zLineLength = GetHandleLength(TransformType.Scale, Axis.Z);
                }

                AddQuads(pivotPoint, axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, xLineLength, lineWidth, handleLines.x);
                AddQuads(pivotPoint, axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, yLineLength, lineWidth, handleLines.y);
                AddQuads(pivotPoint, axisInfo.zDirection, axisInfo.xDirection, axisInfo.yDirection, zLineLength, lineWidth, handleLines.z);
            }
        }
        void SetHandleTriangles()
        {
            handleTriangles.Clear();

            if (type == TransformType.Move)
            {
                float triangleLength = triangleSize * GetDistanceMultiplier();
                AddTriangles(axisInfo.xAxisEnd, axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, triangleLength, handleTriangles.x);
                AddTriangles(axisInfo.yAxisEnd, axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, triangleLength, handleTriangles.y);
                AddTriangles(axisInfo.zAxisEnd, axisInfo.zDirection, axisInfo.yDirection, axisInfo.xDirection, triangleLength, handleTriangles.z);
            }
        }
        void SetHandleTriangles()
        {
            handleTriangles.Clear();

            if (TranslatingTypeContains(TransformType.Move))
            {
                float triangleLength = triangleSize * GetDistanceMultiplier();
                AddTriangles(axisInfo.GetXAxisEnd(GetHandleLength(TransformType.Move)), axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, triangleLength, handleTriangles.x);
                AddTriangles(axisInfo.GetYAxisEnd(GetHandleLength(TransformType.Move)), axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, triangleLength, handleTriangles.y);
                AddTriangles(axisInfo.GetZAxisEnd(GetHandleLength(TransformType.Move)), axisInfo.zDirection, axisInfo.yDirection, axisInfo.xDirection, triangleLength, handleTriangles.z);
            }
        }
        void SetHandleSquares()
        {
            handleSquares.Clear();

            if (type == TransformType.Scale)
            {
                float boxSize = this.boxSize * GetDistanceMultiplier();
                AddSquares(axisInfo.xAxisEnd, axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxSize, handleSquares.x);
                AddSquares(axisInfo.yAxisEnd, axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, boxSize, handleSquares.y);
                AddSquares(axisInfo.zAxisEnd, axisInfo.zDirection, axisInfo.xDirection, axisInfo.yDirection, boxSize, handleSquares.z);
                AddSquares(pivotPoint - (axisInfo.xDirection * (boxSize * .5f)), axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxSize, handleSquares.all);
            }
        }
        void SetCircles(AxisInfo axisInfo, AxisVectors axisVectors)
        {
            axisVectors.Clear();

            if (type == TransformType.Rotate)
            {
                float circleLength = handleLength * GetDistanceMultiplier();
                AddCircle(pivotPoint, axisInfo.xDirection, circleLength, axisVectors.x);
                AddCircle(pivotPoint, axisInfo.yDirection, circleLength, axisVectors.y);
                AddCircle(pivotPoint, axisInfo.zDirection, circleLength, axisVectors.z);
                AddCircle(pivotPoint, (pivotPoint - transform.position).normalized, circleLength, axisVectors.all, false);
            }
        }
        void SetCircles(AxisInfo axisInfo, AxisVectors axisVectors)
        {
            axisVectors.Clear();

            if (TranslatingTypeContains(TransformType.Rotate))
            {
                float circleLength = GetHandleLength(TransformType.Rotate);
                AddCircle(pivotPoint, axisInfo.xDirection, circleLength, axisVectors.x);
                AddCircle(pivotPoint, axisInfo.yDirection, circleLength, axisVectors.y);
                AddCircle(pivotPoint, axisInfo.zDirection, circleLength, axisVectors.z);
                AddCircle(pivotPoint, (pivotPoint - transform.position).normalized, circleLength, axisVectors.all, false);
            }
        }
        void SetHandleSquares()
        {
            handleSquares.Clear();

            if (TranslatingTypeContains(TransformType.Scale))
            {
                float boxSize = this.boxSize * GetDistanceMultiplier();
                AddSquares(axisInfo.GetXAxisEnd(GetHandleLength(TransformType.Scale, Axis.X)), axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxSize, handleSquares.x);
                AddSquares(axisInfo.GetYAxisEnd(GetHandleLength(TransformType.Scale, Axis.Y)), axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, boxSize, handleSquares.y);
                AddSquares(axisInfo.GetZAxisEnd(GetHandleLength(TransformType.Scale, Axis.Z)), axisInfo.zDirection, axisInfo.xDirection, axisInfo.yDirection, boxSize, handleSquares.z);
                AddSquares(pivotPoint - (axisInfo.xDirection * (boxSize * .5f)), axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxSize, handleSquares.all);
            }
        }
        void SetHandleSquares()
        {
            handleSquares.Clear();

            if (type == TransformType.Scale)
            {
                float boxLength = boxSize * GetDistanceMultiplier();
                AddSquares(axisInfo.xAxisEnd, axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxLength, handleSquares.x);
                AddSquares(axisInfo.yAxisEnd, axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, boxLength, handleSquares.y);
                AddSquares(axisInfo.zAxisEnd, axisInfo.zDirection, axisInfo.xDirection, axisInfo.yDirection, boxLength, handleSquares.z);
                AddSquares(target.position - (axisInfo.xDirection * boxLength), axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, boxLength, handleSquares.all);
            }
        }
        void SetHandleLines()
        {
            handleLines.Clear();

            if (type == TransformType.Move || type == TransformType.Scale)
            {
                handleLines.x.Add(target.position);
                handleLines.x.Add(axisInfo.xAxisEnd);
                handleLines.y.Add(target.position);
                handleLines.y.Add(axisInfo.yAxisEnd);
                handleLines.z.Add(target.position);
                handleLines.z.Add(axisInfo.zAxisEnd);
            }
        }
Exemple #11
0
        void SetNearAxis()
        {
            if (isTransforming)
            {
                return;
            }

            SetTranslatingAxis(transformType, Axis.None);

            if (mainTargetRoot == null)
            {
                return;
            }

            float distanceMultiplier             = GetDistanceMultiplier();
            float handleMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + handleWidth) * distanceMultiplier;

            if (nearAxis == Axis.None && (TransformTypeContains(TransformType.Move) || TransformTypeContains(TransformType.Scale)))
            {
                float tipMinSelectedDistanceCheck = 0;
                axisVectorsBuffer.Clear();

                if (nearAxis == Axis.None && TransformTypeContains(TransformType.Move))
                {
                    tipMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + triangleSize) * distanceMultiplier;
                    axisVectorsBuffer.Add(handleTriangles);
                    HandleNearest(TransformType.Move, axisVectorsBuffer, tipMinSelectedDistanceCheck);
                }

                if (nearAxis == Axis.None && TransformTypeContains(TransformType.Scale))
                {
                    tipMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + boxSize) * distanceMultiplier;
                    axisVectorsBuffer.Add(handleSquares);
                    HandleNearest(TransformType.Scale, axisVectorsBuffer, tipMinSelectedDistanceCheck);
                }

                if (nearAxis == Axis.None)
                {
                    //Since Move and Scale share the same handle line, we give Move the priority.
                    TransformType transType = transformType == TransformType.All ? TransformType.Move : transformType;
                    HandleNearest(transType, handleLines, handleMinSelectedDistanceCheck);
                }
            }

            if (nearAxis == Axis.None && TransformTypeContains(TransformType.Rotate))
            {
                HandleNearest(TransformType.Rotate, circlesLines, handleMinSelectedDistanceCheck);
            }
        }
        void SetCircles(AxisInfo axisInfo, AxisVectors axisVectors)
        {
            axisVectors.Clear();

            if (type == TransformType.Rotate)
            {
                float circleLength = setting.handleLength * DistanceMultiplier;
                if (setting.enableState == EnableState.Normal)
                {
                    AddCircle(target.position, axisInfo.xDirection, circleLength, axisVectors.x);
                    AddCircle(target.position, axisInfo.zDirection, circleLength, axisVectors.z);
                    AddCircle(target.position, (target.position - myCamera.transform.position).normalized, circleLength, axisVectors.all, false);
                }
                AddCircle(target.position, axisInfo.yDirection, circleLength, axisVectors.y);
            }
        }
        void SetNearAxis()
        {
            if (isTransforming)
            {
                return;
            }

            nearAxis = Axis.None;

            if (mainTargetRoot == null)
            {
                return;
            }

            float distanceMultiplier             = GetDistanceMultiplier();
            float handleMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + handleWidth) * distanceMultiplier;

            if (type == TransformType.Move || type == TransformType.Scale)
            {
                float tipMinSelectedDistanceCheck = 0;
                axisVectorsBuffer.Clear();

                if (type == TransformType.Move)
                {
                    tipMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + triangleSize) * distanceMultiplier;
                    axisVectorsBuffer.Add(handleTriangles);
                }
                else if (type == TransformType.Scale)
                {
                    tipMinSelectedDistanceCheck = (this.minSelectedDistanceCheck + boxSize) * distanceMultiplier;
                    axisVectorsBuffer.Add(handleSquares);
                }

                HandleNearest(axisVectorsBuffer, tipMinSelectedDistanceCheck);

                if (nearAxis == Axis.None)
                {
                    HandleNearest(handleLines, handleMinSelectedDistanceCheck);
                }
            }
            else if (type == TransformType.Rotate)
            {
                HandleNearest(circlesLines, handleMinSelectedDistanceCheck);
            }
        }
        void SetHandleLines()
        {
            handleLines.Clear();

            if (type == TransformType.Move || type == TransformType.Scale)
            {
                float distanceMultiplier = GetDistanceMultiplier();
                float lineWidth          = handleWidth * distanceMultiplier;
                //When scaling, the axis will have different line lengths and direction.
                float xLineLength = Vector3.Distance(pivotPoint, axisInfo.xAxisEnd) * AxisDirectionMultiplier(axisInfo.xAxisEnd - pivotPoint, axisInfo.xDirection);
                float yLineLength = Vector3.Distance(pivotPoint, axisInfo.yAxisEnd) * AxisDirectionMultiplier(axisInfo.yAxisEnd - pivotPoint, axisInfo.yDirection);
                float zLineLength = Vector3.Distance(pivotPoint, axisInfo.zAxisEnd) * AxisDirectionMultiplier(axisInfo.zAxisEnd - pivotPoint, axisInfo.zDirection);

                AddQuads(pivotPoint, axisInfo.xDirection, axisInfo.yDirection, axisInfo.zDirection, xLineLength, lineWidth, handleLines.x);
                AddQuads(pivotPoint, axisInfo.yDirection, axisInfo.xDirection, axisInfo.zDirection, yLineLength, lineWidth, handleLines.y);
                AddQuads(pivotPoint, axisInfo.zDirection, axisInfo.xDirection, axisInfo.yDirection, zLineLength, lineWidth, handleLines.z);
            }
        }
 void SetHandleSquares()
 {
     handleSquares.Clear();
 }
        void SelectAxis()
        {
            if (!Input.GetMouseButtonDown(0))
            {
                return;
            }
            selectedAxis = Axis.None;

            float xClosestDistance         = float.MaxValue;
            float yClosestDistance         = float.MaxValue;
            float zClosestDistance         = float.MaxValue;
            float allClosestDistance       = float.MaxValue;
            float minSelectedDistanceCheck = this.minSelectedDistanceCheck * GetDistanceMultiplier();

            if (type == TransformType.Move || type == TransformType.Scale)
            {
                selectedLinesBuffer.Clear();
                selectedLinesBuffer.Add(handleLines);
                if (type == TransformType.Move)
                {
                    selectedLinesBuffer.Add(handleTriangles);
                }
                else if (type == TransformType.Scale)
                {
                    selectedLinesBuffer.Add(handleSquares);
                }

                xClosestDistance   = ClosestDistanceFromMouseToLines(selectedLinesBuffer.x);
                yClosestDistance   = ClosestDistanceFromMouseToLines(selectedLinesBuffer.y);
                zClosestDistance   = ClosestDistanceFromMouseToLines(selectedLinesBuffer.z);
                allClosestDistance = ClosestDistanceFromMouseToLines(selectedLinesBuffer.all);
            }
            else if (type == TransformType.Rotate)
            {
                xClosestDistance   = ClosestDistanceFromMouseToLines(circlesLines.x);
                yClosestDistance   = ClosestDistanceFromMouseToLines(circlesLines.y);
                zClosestDistance   = ClosestDistanceFromMouseToLines(circlesLines.z);
                allClosestDistance = ClosestDistanceFromMouseToLines(circlesLines.all);
            }

            if (type == TransformType.Scale && allClosestDistance <= minSelectedDistanceCheck)
            {
                selectedAxis = Axis.Any;
            }
            else if (xClosestDistance <= minSelectedDistanceCheck && xClosestDistance <= yClosestDistance && xClosestDistance <= zClosestDistance)
            {
                selectedAxis = Axis.X;
            }
            else if (yClosestDistance <= minSelectedDistanceCheck && yClosestDistance <= xClosestDistance && yClosestDistance <= zClosestDistance)
            {
                selectedAxis = Axis.Y;
            }
            else if (zClosestDistance <= minSelectedDistanceCheck && zClosestDistance <= xClosestDistance && zClosestDistance <= yClosestDistance)
            {
                selectedAxis = Axis.Z;
            }
            else if (type == TransformType.Rotate && target != null)
            {
                Ray     mouseRay      = myCamera.ScreenPointToRay(Input.mousePosition);
                Vector3 mousePlaneHit = GeometryUtil.LinePlaneIntersect(mouseRay.origin, mouseRay.direction, target.position, (transform.position - target.position).normalized);
                if ((target.position - mousePlaneHit).sqrMagnitude <= Mathf.Pow((handleLength * GetDistanceMultiplier()), 2))
                {
                    selectedAxis = Axis.Any;
                }
            }
        }