Exemple #1
0
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == Handle.Id || handleId == _cap3D.HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    // We need to tell the session about the data that it needs in order to do its work
                    GizmoSglAxisOffsetDrag3D.WorkData workData = new GizmoSglAxisOffsetDrag3D.WorkData();
                    workData.Axis       = Direction;                        // The offset session will offset along the slider direction
                    workData.DragOrigin = StartPosition;                    // The point on the drag plane is the slider's start point
                    workData.SnapStep   = Settings.OffsetSnapStep;          // Use the snap step stored in the slider settings
                    _offsetDrag.SetWorkData(workData);                      // Set the work data
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    // We need to tell the session about the data that it needs in order to do its work
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis             = DragRotationAxis;           // The rotation session will rotate around the drag rotation axis
                    workData.RotationPlanePos = StartPosition;              // The point on the rotation plane is the slider's start point
                    workData.SnapStep         = Settings.RotationSnapStep;  // Use the snap step stored in the slider settings
                    workData.SnapMode         = Settings.RotationSnapMode;  // Use the snap mode stored in the slider settings
                    _rotationDrag.SetWorkData(workData);                    // Set the work data

                    // Configure the rotation arc plane
                    _rotationArc.SetArcData(DragRotationAxis, StartPosition, StartPosition + Direction, GetRealLength(GetZoomFactor(Gizmo.FocusCamera)));
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    // We need to tell the session about the data that it needs in order to do its work
                    GizmoSglAxisScaleDrag3D.WorkData workData = new GizmoSglAxisScaleDrag3D.WorkData();
                    workData.Axis       = Direction;                                        // The scale session will scale along the slider direction
                    workData.DragOrigin = StartPosition;                                    // The point on the drag plane is the slider's start point
                    workData.SnapStep   = Settings.ScaleSnapStep;                           // Use the snap step stored in the slider settings
                    workData.AxisIndex  = ScaleDragAxisIndex;                               // We want the slider to store the scale ouput in the component with the specified index.
                    workData.BaseSize   = GetRealLength(GetZoomFactor(Gizmo.FocusCamera));  // The session needs to know the size of the entity which will be scaled in order to properly
                                                                                            // calculate a scale drag value. We use the real length of the slider for this.
                    _scaleDrag.SetWorkData(workData);                                       // Set the work data
                }
            }
        }
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == Handle.Id || handleId == _cap2D.HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    GizmoSglAxisOffsetDrag3D.WorkData workData = new GizmoSglAxisOffsetDrag3D.WorkData();
                    workData.Axis       = Vector2Ex.ConvertDirTo3D(StartPosition, GetRealEndPosition(), OffsetDragOrigin, Gizmo.FocusCamera).normalized;
                    workData.DragOrigin = OffsetDragOrigin;
                    workData.SnapStep   = Settings.OffsetSnapStep;
                    _offsetDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis             = Gizmo.FocusCamera.transform.forward;
                    workData.SnapMode         = Settings.RotationSnapMode;
                    workData.SnapStep         = Settings.RotationSnapStep;
                    workData.RotationPlanePos = Gizmo.FocusCamera.ScreenToWorldPoint(new Vector3(_transform.Position2D.x, _transform.Position2D.y, Gizmo.FocusCamera.nearClipPlane));

                    _rotationArc.SetArcData(StartPosition, GetRealEndPosition(), GetRealLength());
                    _rotationDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    _scaleAxis = Vector2Ex.ConvertDirTo3D(StartPosition, GetRealEndPosition(), ScaleDragOrigin, Gizmo.FocusCamera);
                    GizmoSglAxisScaleDrag3D.WorkData workData = new GizmoSglAxisScaleDrag3D.WorkData();
                    workData.Axis       = _scaleAxis.normalized;
                    workData.AxisIndex  = _scaleDragAxisIndex;
                    workData.BaseSize   = _scaleAxis.magnitude;
                    workData.DragOrigin = ScaleDragOrigin;
                    workData.SnapStep   = Settings.ScaleSnapStep;

                    _scaleDrag.SetWorkData(workData);
                }
            }
        }