void HandleBeginDrag(VrEventArgs args) { _frameGfx.Visible = false; var hitInstruction = args.HitResult as HitResult <RsMoveInstruction>; var hitSegment = args.HitResult as HitResult <PathSegment>; if (hitInstruction != null) { _dragOffset = args.Frame.InverseRigid() * hitInstruction.HitObject.GetToTarget().Transform.GlobalMatrix; WithUndo("VR Drag", () => PathEditingHelper.MoveInstructionToFrame(hitInstruction.HitObject, args.Frame * _dragOffset)); _newHighlightTarget = hitInstruction?.HitObject?.GetToTarget(); } else if (hitSegment != null) { WithUndo("VR Drag", () => _newInstruction = PathEditingHelper.InsertMoveInstruction(hitSegment.HitObject, args.Frame)); } else if (args.HitResult != null) { throw new InvalidOperationException("unrecognized HitResult"); } else { WithUndo("VR Create Instruction", () => _newInstruction = PathEditingHelper.CreateNewInstructionInActivePath(args.Frame)); _dragOffset = Matrix4.Identity; args.CreatedObject = () => new HitResult <RsMoveInstruction>(_newInstruction, 0, args.Frame.Translation); } }
public override void Activate(VrSession session) { PathEditingHelper.EnsurePath(); //:TODO: Update if active tool changes CreateToolGraphics(); }
void HandleAlternateClick(VrEventArgs args) { var hitInstruction = args.HitResult as HitResult <RsMoveInstruction>; if (hitInstruction != null) { WithUndo("VR Delete", () => PathEditingHelper.DeleteInstruction(hitInstruction.HitObject)); } }
public override void Activate(VrSession session) { base.Activate(session); PathEditingHelper.EnsurePath(); _controller = session.RightController; AddGfx(); //Click += HandleClick; AlternateClick += HandleAlternateClick; DeltaDrag += HandleDeltaDrag; BeginDrag += HandleBeginDrag; EndDrag += HandleDeltaDrag; HoverObject += HandleHover; }
void HandleDeltaDrag(VrEventArgs args) { //_frameGfx.Visible = false; var hitInstruction = args.HitResult as HitResult <RsMoveInstruction>; var hitSegment = args.HitResult as HitResult <PathSegment>; if (hitInstruction != null) { WithUndoAppend("VR Drag", () => PathEditingHelper.MoveInstructionToFrame(hitInstruction.HitObject, args.Frame * _dragOffset)); _newHighlightTarget = hitInstruction?.HitObject?.GetToTarget(); _forceUpdateLine = true; } else if (hitSegment != null) { WithUndoAppend("VR Drag", () => PathEditingHelper.MoveInstructionToFrame(_newInstruction, args.Frame)); } else if (args.HitResult != null) { throw new InvalidOperationException("unrecognized HitResult"); } }
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; } }
void CreateMoveInstruction(Matrix4 tf, string name) { var moveInstr = PathEditingHelper.CreateNewInstructionInActivePath(tf); }