public static ControllerMode Get(Controller controller) { ControllerMode cm = controller.GetAdditionalData(ref controller_mode); cm.controller = controller; return(cm); }
private void Ht_onTriggerDown(Controller controller) { var cm = ControllerMode.Get(controller); if (cm.current_sel != null) { Selection sel = cm.current_sel; cm.Leave(); cm.StartAction(this, sel); } }
private Menu.Item ModeChoice(string text, EMode mode) { if (ControllerMode.CurrentMode() == mode) { text = "✔ " + text; } return(new Menu.Item { text = text, onClick = () => ControllerMode.ChangeMode(mode), }); }
private void Ht_onMoveOver(Controller controller) { ControllerMode.Get(controller).UpdatePointer(this); Selection sel = Selection.FindClosest(world.InverseTransformPoint(controller.position), model); var cm = ControllerMode.Get(controller); if (sel == null ? cm.current_sel == null : sel.SameSelection(cm.current_sel)) { return; } cm.Leave(); if (sel != null) { sel = sel.Clone(); cm.current_sel = sel; sel.Enter(this, Selection.SELECTION_COLOR); sel.Follow(this); } }
public override void Drag() { Vector3 pos = render.world.InverseTransformPoint(ctrl.position); EdgeSelection closest_edge; var subspace = SnapPosition(pos, out closest_edge); var ptsubspace = new PointedSubspace(subspace, origin); Vector3 otherpos = render.world.InverseTransformPoint(other_ctrl.position); Selection othersel = Selection.FindClosest(otherpos, render.model, color_in_face: true); Vector3? dummyedge_from = null; string other_ctrl_hint = null; if (othersel != null) { AddSelection(othersel, GUIDE_COLOR); if (!othersel.ContainsVertex(vertex)) { PointedSubspace otherptsubspace = othersel.GetPointedSubspace(); if (othersel is VertexSelection) { Vertex v = ((VertexSelection)othersel).vertex; var foot = v.position; otherptsubspace = new PointedSubspace(subspace.NormalSubspace(), foot); if (closest_edge != null && closest_edge.ContainsVertex(v)) { float distance = Vector3.Distance(v.position, pos); int cm_distance = Mathf.RoundToInt(distance * 100 / 5) * 5; other_ctrl_hint = "clamped at " + cm_distance + " cm"; var point0 = v.position + cm_distance * 0.01f * (origin - v.position).normalized; ptsubspace = new PointedSubspace(new Subspace0(), point0); otherptsubspace = PointedSubspace.Void(); } else if (subspace is Subspace0) { float distance = Vector3.Distance(v.position, origin); int mm_distance = Mathf.RoundToInt(distance * 1000); other_ctrl_hint = (mm_distance / 10.0).ToString() + " cm"; } } else if (othersel is EdgeSelection) { Vertex v1, v2; ((EdgeSelection)othersel).GetVertices(out v1, out v2); Vector3 foot1 = v1.position; Vector3 foot2 = v2.position; Subspace orthogonal_plane = new Subspace2(foot2 - foot1); var ptsub1 = new PointedSubspace(orthogonal_plane, foot1); var ptsub2 = new PointedSubspace(orthogonal_plane, foot2); var dist0 = otherptsubspace.Distance(pos); var dist1 = ptsub1.Distance(pos); var dist2 = ptsub2.Distance(pos); if (dist1 <= dist0 && dist1 <= dist2) { otherptsubspace = ptsub1; othersel = new VertexSelection { vertex = v1 }; } else if (dist2 <= dist0 && dist2 <= dist1) { otherptsubspace = ptsub2; othersel = new VertexSelection { vertex = v2 }; } } if (otherptsubspace.Distance(pos) < Selection.DISTANCE_VERTEX_MIN) { ptsubspace = ptsubspace.IntersectedWith(otherptsubspace); dummyedge_from = othersel.Center(); } } } pos = ptsubspace.Snap(pos); vertex.position = pos; foreach (var face_rend in face_rends) { face_rend.ComputeMesh(); } if (dummyedge_from.HasValue) { AddSelection(EdgeSelection.DummyEdgeSelection(dummyedge_from.Value, pos), GUIDE_COLOR); } AddSelection(new VertexSelection { vertex = vertex }, subspace is Subspace0 ? Darker(COLOR) : COLOR); SelectionFinished(); if (other_ctrl.CurrentHoverTracker() == null) { ControllerMode.Get(other_ctrl).UpdatePointer(render, EMode.Guide); other_ctrl.SetControllerHints(trigger: other_ctrl_hint); } }
private void Ht_onTriggerUp(Controller controller) { var cm = ControllerMode.Get(controller); cm.StopAction(); }
private void Ht_onTriggerDrag(Controller controller) { var cm = ControllerMode.Get(controller); cm.DragAction(); }
private void Ht_onLeave(Controller controller) { var cm = ControllerMode.Get(controller); cm.Leave(); }