Esempio n. 1
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 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 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;
                }
            }
        }