private static void AddGizmo(string name, IGizmo gizmo, Color color, bool clearOthers = false) { if (color.r == 0 && color.g == 0 && color.b == 0 && color.a == 0) { color = Color.white; } gizmo.Color = color; if (allGizmos.TryGetValue(name, out GizmoGroup group)) { if (clearOthers) { group.gizmos.Clear(); } group.gizmos.Add(gizmo); allGizmos[name] = group; } else { group = new GizmoGroup(); group.gizmos.Add(gizmo); allGizmos.Add(name, group); } }
/// <summary> /// Implements the MouseDown event handler for the manipulator /// </summary> /// <param name="sender"></param> /// <param name="mouseButtonEventArgs"></param> protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs) { UpdatePosition(); GizmoInAction = null; //Reset Drag. var gizmos = GetGizmos(false); if (!Active || !IsEnabled() || null == gizmos || !gizmos.Any()) { return; } var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs); if (ray == null) { return; } foreach (var item in gizmos) { object hitObject; if (item.HitTest(ray.GetOriginPoint(), ray.GetDirectionVector(), out hitObject)) { GizmoInAction = item; var nodes = OnGizmoClick(item, hitObject); if (null != nodes && nodes.Any()) { WorkspaceModel.RecordModelsForModification(nodes); } newPosition = GizmoInAction.Origin; return; } } }
/// <summary> /// Callback method when gizmo is moved by user action. /// </summary> /// <param name="gizmoInAction">Gizmo that moved.</param> /// <param name="offset">Offset by which the gizmo has moved.</param> protected override void OnGizmoMoved(IGizmo gizmoInAction, Vector offset) { var offsetPos = origin.Add(offset); origin.Dispose(); origin = offsetPos; }
private void GizmoHandler_SelectionGizmoRemoved(IGizmo gizmo, GizmoHandler.ViewportLayer layer) { HelixViewport3D viewport = GetViewport(layer); viewport.Children.Remove(gizmo.Visual); visibleGizmos.Remove(gizmo); }
private void GizmoHandler_SelectionGizmosChanged(IGizmo gizmo, GizmoHandler.ViewportLayer layer) { HelixViewport3D viewport = GetViewport(layer); if (!viewport.Children.Contains(gizmo.Visual) && IsHighlightedViewport) { viewport.Children.Add(gizmo.Visual); } if (!visibleGizmos.Contains(gizmo)) { visibleGizmos.Add(gizmo); } }
protected override IEnumerable <NodeModel> OnGizmoClick(IGizmo gizmoInAction, object hitObject) { var axis = hitObject as Vector; if (null == axis) { return(null); } if (null == inputNode) { inputNode = CreateAndConnectInputNode(0, 1); } return(new[] { inputNode }); }
protected override void OnGizmoMoved(IGizmo gizmoInAction, Vector offset) { double param; using (var offsetPosition = pointOnCurve.Add(offset)) { using (var closestPosition = curve.ClosestPointTo(offsetPosition)) { param = curve.ParameterAtPoint(closestPosition); } } param = Math.Round(param, ROUND_UP_PARAM); tangent = curve.TangentAtParameter(param); pointOnCurve = curve.PointAtParameter(param); }
/// <summary> /// Called when Gizmo is clicked. Creates new input nodes if the /// specific input is selected for manipulation by the Gizmo. /// </summary> /// <param name="gizmoInAction">Gizmo that is clicked</param> /// <param name="hitObject">The axis or plane of the gizmo hit</param> protected override IEnumerable <NodeModel> OnGizmoClick(IGizmo gizmoInAction, object hitObject) { //If an axis is hit, only one node will be updated. var axis1 = hitObject as Vector; Vector axis2 = null; if (axis1 == null) { //Hit object is a plane, two axes will be updated simultaneously. var plane = hitObject as Plane; if (plane != null) { axis1 = plane.XAxis; axis2 = plane.YAxis; } } var nodes = new Dictionary <int, NodeModel>(2); //placeholder for new nodes. foreach (var item in indexedAxisNodePairs) { var v = item.Value.Item1; var node = item.Value.Item2; if (v.Equals(axis1) || v.Equals(axis2)) { if (node == null) { node = CreateAndConnectInputNode(0, item.Key); } nodes.Add(item.Key, node); } } // Update the axisNodePairs with affected nodes. foreach (var n in nodes) { var axisIndex = n.Key; var axisNodePair = indexedAxisNodePairs[axisIndex]; var axisVector = axisNodePair.Item1; var upstreamNode = n.Value; indexedAxisNodePairs[axisIndex] = Tuple.Create(axisVector, upstreamNode); } return(nodes.Values); }
protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset) { var newPosition = pointOnCurve.Add(offset); newPosition = curve.ClosestPointTo(newPosition); var param = curve.ParameterAtPoint(newPosition); param = Math.Round(param, 3); newPosition = curve.PointAtParameter(param); if (inputNode != null) { dynamic uinode = inputNode; uinode.Value = param; } return(newPosition); }
/// <summary> /// Callback method when gizmo is moved by user action. /// </summary> /// <param name="gizmo">Gizmo that moved.</param> /// <param name="offset">Offset by which the gizmo has moved.</param> /// <returns>New expected position of the Gizmo</returns> protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset) { expectedPosition = origin.Add(offset); foreach (var item in indexedAxisNodePairs) { // When more than one input is connected to the same slider, this // method will decompose the axis corresponding to each input. var v = GetFirstAxisComponent(item.Value.Item1); var amount = Math.Round(offset.Dot(v), 3); if (Math.Abs(amount) > 0.001) { ModifyInputNode(item.Value.Item2, amount); } } return(expectedPosition); }
/// <summary> /// Callback method when gizmo is moved by user action. /// </summary> /// <param name="gizmoInAction">Gizmo that moved.</param> /// <param name="offset">Offset by which the gizmo has moved.</param> protected override void OnGizmoMoved(IGizmo gizmoInAction, Vector offset) { var offsetPos = origin.Add(offset); origin.Dispose(); origin = offsetPos; foreach (var item in indexedAxisNodePairs) { // When more than one input is connected to the same slider, this // method will decompose the axis corresponding to each input. using (var v = GetFirstAxisComponent(item.Value.Item1)) { var amount = offset.Dot(v); if (Math.Abs(amount) > 0.001) { ModifyInputNode(item.Value.Item2, amount); } } } }
protected override Point OnGizmoMoved(IGizmo gizmoInAction, Vector offset) { double param; using (var offsetPosition = pointOnCurve.Add(offset)) { using (var closestPosition = curve.ClosestPointTo(offsetPosition)) { param = curve.ParameterAtPoint(closestPosition); } } param = Math.Round(param, 3); var newPosition = curve.PointAtParameter(param); if (inputNode != null) { dynamic uinode = inputNode; uinode.Value = param; } return(newPosition); }
/// <summary> /// This method is called when mouse is moved, to check if the /// Gizmo in action can be moved successfully. If it returns true /// then this manipulator will compute the movement and call /// OnGizmoMoved. /// </summary> /// <param name="gizmo">Gizmo in action.</param> /// <returns>True if Gizmo is ready to move.</returns> protected virtual bool CanMoveGizmo(IGizmo gizmo) { //Wait until node has been evaluated and has got new origin //as expected position. return(gizmo != null && newPosition.DistanceTo(gizmo.Origin) < 0.01); }
protected override IEnumerable<NodeModel> OnGizmoClick(IGizmo gizmoInAction, object hitObject) { var axis = hitObject as Vector; if (null == axis) return null; if(null == inputNode) { inputNode = CreateAndConnectInputNode(0, 1); } return new[] { inputNode }; }
/// <summary> /// Callback method when gizmo is moved by user action. /// </summary> /// <param name="gizmo">Gizmo that moved.</param> /// <param name="offset">Offset by which the gizmo has moved.</param> /// <returns>New expected position of the Gizmo</returns> protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset) { expectedPosition = origin.Add(offset); foreach (var item in indexedAxisNodePairs) { // When more than one input is connected to the same slider, this // method will decompose the axis corresponding to each input. var v = GetFirstAxisComponent(item.Value.Item1); var amount = Math.Round(offset.Dot(v), 3); if (Math.Abs(amount) > 0.001) ModifyInputNode(item.Value.Item2, amount); } return expectedPosition; }
/// <summary> /// This method is called when the Gizmo in action is moved during mouse /// move event. Derived class can use this notification to update the /// input nodes. /// </summary> /// <param name="gizmo">The Gizmo in action.</param> /// <param name="offset">Offset amount by which Gizmo has moved.</param> /// <returns>New expected position of the Gizmo</returns> protected abstract Point OnGizmoMoved(IGizmo gizmo, Vector offset);
protected override bool CanMoveGizmo(IGizmo gizmo) { return(base.CanMoveGizmo(gizmo)); }
/// <summary> /// Called when Gizmo is clicked. Creates new input nodes if the /// specific input is selected for manipulation by the Gizmo. /// </summary> /// <param name="gizmo">Gizmo that is clicked</param> /// <param name="hitObject">The axis or plane of the gizmo hit</param> protected override IEnumerable<NodeModel> OnGizmoClick(IGizmo gizmo, object hitObject) { //If an axis is hit, only one node will be updated. var axis1 = hitObject as Vector; Vector axis2 = null; if(axis1 == null) { //Hit object is a plane, two axes will be updated simultaneously. var plane = hitObject as Plane; if(plane != null) { axis1 = plane.XAxis; axis2 = plane.YAxis; } } int count = indexedAxisNodePairs.Count; var nodes = new Dictionary<int, NodeModel>(2); //placeholder for new nodes. foreach (var item in indexedAxisNodePairs) { var v = item.Value.Item1; var node = item.Value.Item2; if (v.Equals(axis1) || v.Equals(axis2)) { if (node == null) { node = CreateAndConnectInputNode(0, item.Key); } nodes.Add(item.Key, node); } } //Update the axisNodePairs with affected nodes. foreach (var n in nodes) { var axisIndex = n.Key; var axisNodePair = indexedAxisNodePairs[axisIndex]; var axisVector = axisNodePair.Item1; var upstreamNode = n.Value; indexedAxisNodePairs[axisIndex] = Tuple.Create(axisVector, upstreamNode); } return nodes.Values; }
/// <summary> /// This method is called when a gizmo provided by derived class is hit. /// Derived class can create or update the input nodes. /// </summary> /// <param name="gizmo">The Gizmo that's hit.</param> /// <param name="hitObject">The object of Gizmo that's hit.</param> /// <returns>List of updated nodes</returns> protected abstract IEnumerable<NodeModel> OnGizmoClick(IGizmo gizmo, object hitObject);
public FooD(IGizmo gizmo) { Trace.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0} #{1} {2}", this.GetType().Name, this.GetHashCode(), ".ctor, got gizmo #" + gizmo.GetHashCode())); this.Gizmo = gizmo; }
/// <summary> /// Implements the MouseUp event handler for the manipulator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void MouseUp(object sender, MouseButtonEventArgs e) { GizmoInAction = null; //Delete all transient axis line geometry BackgroundPreviewViewModel.DeleteGeometryForIdentifier(RenderDescriptions.AxisLine); }
/// <summary> /// Implements the MouseDown event handler for the manipulator /// </summary> /// <param name="sender"></param> /// <param name="mouseButtonEventArgs"></param> protected virtual void MouseDown(object sender, MouseButtonEventArgs mouseButtonEventArgs) { UpdatePosition(); GizmoInAction = null; //Reset Drag. var gizmos = GetGizmos(false); if (!Active || null == gizmos || !gizmos.Any()) return; var ray = BackgroundPreviewViewModel.GetClickRay(mouseButtonEventArgs); if (ray == null) return; object hitObject; foreach (var item in gizmos) { if (item.HitTest(ray.GetOriginPoint(), ray.GetDirectionVector(), out hitObject)) { GizmoInAction = item; var nodes = OnGizmoClick(item, hitObject); if(null != nodes && nodes.Any()) { WorkspaceModel.RecordModelsForModification(nodes); } newPosition = GizmoInAction.Origin; return; } } }
/// <summary> /// This method is called when a gizmo provided by derived class is hit. /// Derived class can create or update the input nodes. /// </summary> /// <param name="gizmoInAction">The Gizmo that's hit.</param> /// <param name="hitObject">The object of Gizmo that's hit.</param> /// <returns>List of updated nodes</returns> protected abstract IEnumerable <NodeModel> OnGizmoClick(IGizmo gizmoInAction, object hitObject);
internal void RemoveGizmo(IGizmo gizmo) { _gizmos.Remove(gizmo); }
internal void AddGizmo(IGizmo gizmo) { _gizmos.Add(gizmo); }
protected override Point OnGizmoMoved(IGizmo gizmo, Vector offset) { var newPosition = pointOnCurve.Add(offset); newPosition = curve.ClosestPointTo(newPosition); var param = curve.ParameterAtPoint(newPosition); param = Math.Round(param, 3); newPosition = curve.PointAtParameter(param); if (inputNode != null) { dynamic uinode = inputNode; uinode.Value = param; } return newPosition; }
/// <summary> /// This method is called when mouse is moved, to check if the /// Gizmo in action can be moved successfully. If it returns true /// then this manipulator will compute the movement and call /// OnGizmoMoved. /// </summary> /// <param name="gizmo">Gizmo in action.</param> /// <returns>True if Gizmo is ready to move.</returns> protected virtual bool CanMoveGizmo(IGizmo gizmo) { //Wait until node has been evaluated and has got new origin //as expected position. return gizmo != null && newPosition.DistanceTo(gizmo.Origin) < 0.01; }
protected override void OnGizmoMoved(IGizmo gizmoInAction, Vector offset) { double param; using (var offsetPosition = pointOnCurve.Add(offset)) { using (var closestPosition = curve.ClosestPointTo(offsetPosition)) { param = curve.ParameterAtPoint(closestPosition); } } param = Math.Round(param, 3); tangent = curve.TangentAtParameter(param); pointOnCurve = curve.PointAtParameter(param); if (inputNode != null) { dynamic uinode = inputNode; uinode.Value = param; } }
public GizmoHandle(Point2D pos, IGizmo parentGizmo) { DesiredMouseCursor = Cursors.Default; Pos = pos; ParentGizmo = parentGizmo; }
/// <summary> /// This method is called when the Gizmo in action is moved during mouse /// move event. Derived class must use this notification to update the /// input nodes AND update the manipulator Origin based on the mouse move. /// </summary> /// <param name="gizmoInAction">The Gizmo in action.</param> /// <param name="offset">Offset amount by which Gizmo has moved.</param> protected abstract void OnGizmoMoved(IGizmo gizmoInAction, Vector offset);
protected override bool CanMoveGizmo(IGizmo gizmo) { return base.CanMoveGizmo(gizmo); }