Ejemplo n.º 1
0
        public override void Update(VrUpdateArgs args)
        {
            var session = args.Session;

            DeleteBrushTempGfx();

            var input = session.SemanticInput();

            if (_trackedBrushInstruction != null)
            {
                if (input.IsSelectPressed)
                {
                    // Drag brush
                    var relatedMI = FindRelatedMoveInstruction(_trackedBrushInstruction);
                    if (relatedMI != null)
                    {
                        Matrix4 wobjMat = relatedMI.GetWorkObject().ObjectFrame.GlobalMatrix;
                        Vector3 point   = wobjMat.InverseRigid().MultiplyPoint(session.RightController.PointerTransform.Translation);
                        var     pos     = PathEditingHelper.GetBrushEventPosition(_trackedBrushInstruction);
                        string  val     = ((int)(point[(int)pos.Item1 - 1] * 1000)).ToString();
                        if (val != pos.Item2.Value)
                        {
                            WithUndoAppend("VR Move SetBrush", () => { pos.Item2.Value = val; });
                        }
                        _brushSelector.Caption = _trackedBrushInstruction.DisplayName;
                    }
                    return;
                }
            }

            var hitObj = GetHitObject(session.RightController.PointerTransform.Translation);

            var trackedMoveInstruction = hitObj?.Item1 as RsMoveInstruction;

            if (trackedMoveInstruction != null)
            {
                //:TODO: Supported for PaintC??
                if (trackedMoveInstruction.Name != "PaintL" && trackedMoveInstruction.Name != "PaintC" ||
                    trackedMoveInstruction.GetToTarget() == null)
                {
                    trackedMoveInstruction = null;
                }
            }

            var trackedBrushInstr = hitObj?.Item1 as RsActionInstruction;

            if (trackedBrushInstr != null && !string.Equals(trackedBrushInstr.Name, "SetBrush", StringComparison.OrdinalIgnoreCase))
            {
                trackedBrushInstr = null;
            }

            if (trackedMoveInstruction != _trackedMoveInstruction)
            {
                _trackedMoveInstruction = trackedMoveInstruction;
                if (_brushSelector == null)
                {
                    _brushSelector = new VrScrollSelector(session.RightController, "", _brushValues, _lastBrushNum);
                }
                _brushSelector.Caption = (_trackedMoveInstruction != null) ? "Add SetBrush" : "Brush Number";
            }

            else if (trackedBrushInstr != _trackedBrushInstruction || _brushSelector == null)
            {
                if (_brushSelector != null)
                {
                    _brushSelector.Dispose();
                }

                _trackedBrushInstruction = trackedBrushInstr;
                if (_trackedBrushInstruction != null)
                {
                    var numarg = _trackedBrushInstruction.InstructionArguments["BrushNumber"];
                    _brushSelector = new VrScrollSelector(session.RightController, _trackedBrushInstruction.DisplayName, _brushValues, numarg.Value);
                }
                else
                {
                    _brushSelector = new VrScrollSelector(session.RightController, (_trackedMoveInstruction != null) ? "Add SetBrush" : "Brush Number", _brushValues, _lastBrushNum);
                }
            }

            if (_trackedBrushInstruction != null && input.DeleteClick)
            {
                var path = (RsPathProcedure)_trackedBrushInstruction.Parent;
                WithUndo("VR Delete SetBrush", () => { path.Instructions.Remove(_trackedBrushInstruction); });
                _trackedBrushInstruction = null;
                return;
            }

            bool brushNumUpdated = _brushSelector.Update();

            if (brushNumUpdated)
            {
                _lastBrushNum = _brushSelector.SelectedValue;
            }

            if (_trackedMoveInstruction != null && _trackedBrushInstruction == null)
            {
                Matrix4 wobjMat = _trackedMoveInstruction.GetWorkObject().ObjectFrame.GlobalMatrix;

                CreateBrushPlanePreview(hitObj.Item2, wobjMat);

                if (input.SelectClick)
                {
                    Vector3 point = wobjMat.InverseRigid().MultiplyPoint(hitObj.Item2);
                    var     axis  = ComputeBrushAxis();
                    int     val   = (int)(point[(int)axis - 1] * 1000);
                    WithUndo("VR Create SetBrush", () =>
                    {
                        PathEditingHelper.CreateSetBrush(
                            _trackedMoveInstruction,
                            axis,
                            val,
                            _brushSelector.SelectedValue);
                    }
                             );
                    DeleteBrushTempGfx();
                }
            }
            else if (_trackedBrushInstruction != null && brushNumUpdated)
            {
                var numarg = _trackedBrushInstruction.InstructionArguments["BrushNumber"];
                WithUndo("VR Edit SetBrush", () => { numarg.Value = _brushSelector.SelectedValue; });
                _brushSelector.Caption = _trackedBrushInstruction.DisplayName;
            }
        }