Exemple #1
0
        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);
            }
        }
Exemple #2
0
        void SetCircles(AxisInfo axisInfo, AxisVectors axisVectors)
        {
            axisVectors.Clear();

            if (type == TransformType.Rotate)
            {
                float circleLength = handleLength * GetDistanceMultiplier();
                AddCircle(target.position, axisInfo.xDirection, circleLength, axisVectors.x);
                AddCircle(target.position, axisInfo.yDirection, circleLength, axisVectors.y);
                AddCircle(target.position, axisInfo.zDirection, circleLength, axisVectors.z);
                AddCircle(target.position, (target.position - transform.position).normalized, circleLength, axisVectors.all, false);
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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 #5
0
        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 = Geometry.LinePlaneIntersect(mouseRay.origin, mouseRay.direction, target.position, (transform.position - target.position).normalized);
                if ((target.position - mousePlaneHit).sqrMagnitude <= (handleLength * GetDistanceMultiplier()).Squared())
                {
                    selectedAxis = Axis.Any;
                }
            }
        }