//////////////////////////////////////////////////// #region Visual /// <summary> /// Creates a visual which renders the edge. /// </summary> /// <remarks> /// Creates a VisualGroup which contains the actual edge rendering visual and /// the visuals which represent the arrows. /// </remarks> /// <param name="context">The render context.</param> /// <param name="edge">The edge to render.</param> /// <returns>A visual which renders the edge.</returns> protected override VisualGroup CreateVisual(IRenderContext context, IEdge edge) { var color = GetColor(context, edge); var group = new VisualGroup(); // Create the path to be drawn GeneralPath gp = GetPath(edge); var edgeVisual = new EdgeVisual(); edgeVisual.Update(gp, PathThickness, color); group.Add(edgeVisual); // add arrow visuals to the group AddArrows(context, group, edge, gp, Arrows, Arrows); return(group); }
/// <summary> /// Creates a visual which renders the edge. /// </summary> /// <remarks> /// Creates a VisualGroup which contains the actual edge rendering visual and /// the visuals which represent the arrows. /// </remarks> /// <param name="context">The render context.</param> /// <param name="edge">The edge to render.</param> /// <returns>A visual which renders the edge.</returns> protected override VisualGroup CreateVisual(IRenderContext context, IEdge edge) { var color = GetColor(context, edge); var group = new VisualGroup(); //////////////// New in this sample //////////////// // the cached path is updated with bridges (if there are any) GeneralPath gp = CreatePathWithBridges(GetPath(edge), context); //////////////////////////////////////////////////// var edgeVisual = new EdgeVisual(); edgeVisual.Update(gp, PathThickness, color); group.Add(edgeVisual); // add arrow visuals to the group AddArrows(context, group, edge, gp, Arrows, Arrows); return(group); }
protected override VisualGroup CreateVisual(IRenderContext context, IEdge edge) { bool selected = false; // Check if edge is selected var graphControl = context.CanvasControl as GraphControl; if (graphControl != null) { selected = graphControl.Selection.SelectedEdges.IsSelected(edge); } // Get default color from MySimpleNodeStyle Color color = MySimpleNodeStyle.Color; // Check if the ownernode has stored a color in it's tag INode owner = edge.SourcePort.Owner as INode; if (!selected && owner != null) { if (owner.Tag is Color) { color = (Color)owner.Tag; } } else if (selected) { // if edge is selected, draw with different color color = Color.DarkGoldenrod; } var group = new VisualGroup(); // Create the path to be drawn GeneralPath gp = GetPath(edge); var edgeVisual = new EdgeVisual(); edgeVisual.Update(gp, PathThickness, color); group.Add(edgeVisual); AddArrows(context, group, edge, gp, Arrows, Arrows); return(group); }
public override void OnSceneViewGUI(SceneView sceneView) { if (EdgeVisual.Visible && EdgeVisual.MouseOver) { return; } // 1. Find target game object. if (m_collectedData == null) { if (GetChild <SelectGameObjectTool>() == null) { SelectGameObjectTool selectGameObjectTool = new SelectGameObjectTool(); selectGameObjectTool.OnSelect = go => { m_collectedData = new CollectedData() { Target = go }; }; AddChild(selectGameObjectTool); } } // 2. Select edge on target game object. else if (!m_collectedData.SelectedEdge.Valid) { Raycast.Hit hit = Raycast.Test(m_collectedData.Target, HandleUtility.GUIPointToWorldRay(Event.current.mousePosition)); if (hit.ClosestEdge.Valid) { m_collectedData.CurrentEdge = hit.ClosestEdge; } } // 3. Find point on edge - hold ctrl for "no-snap" mode. else if (!m_collectedData.PointOnEdgeGiven) { Vector3 pointOnEdge = FindClosestPointOnEdge(m_collectedData.SelectedEdge.Edge); if (Event.current.control) { m_collectedData.PointOnEdge = pointOnEdge; } else { float snapValue = 0.5f * HandleUtility.GetHandleSize(pointOnEdge); float closestDistance = float.PositiveInfinity; Vector3 closestPoint = pointOnEdge; Vector3[] predefinedPoints = FindPredefinedEdgePoints(m_collectedData.SelectedEdge.Edge).ToArray(); // Given set of predefined points along the edge, finds the // closest to the mouse ray (i.e., the actual point on the edge). foreach (var point in predefinedPoints) { float distanceToPoint = Vector3.Distance(pointOnEdge, point); if (distanceToPoint < snapValue && distanceToPoint < closestDistance) { closestPoint = point; closestDistance = distanceToPoint; } } m_collectedData.PointOnEdge = closestPoint; } } // 4. Find direction. else if (!m_collectedData.DirectionGiven) { if (GetChild <DirectionTool>() == null) { DirectionTool directionTool = new DirectionTool(m_collectedData.PointOnEdge, m_collectedData.SelectedEdge.Edge.Direction, m_collectedData.SelectedEdge.Edge.Normal); directionTool.OnSelect += (position, rotation) => { m_collectedData.DirectionRotation = rotation; m_collectedData.DirectionGiven = true; }; AddChild(directionTool); } } // 5. Done, fire callback with result and remove us. else { MeshUtils.Edge orgEdge = m_collectedData.SelectedEdge.Edge; Result resultingData = new Result() { Target = m_collectedData.Target, Edge = new MeshUtils.Edge(m_collectedData.PointOnEdge + 0.5f * orgEdge.Length * (m_collectedData.DirectionRotation * Vector3.back), m_collectedData.PointOnEdge + 0.5f * orgEdge.Length * (m_collectedData.DirectionRotation * Vector3.forward), m_collectedData.DirectionRotation * Vector3.up, MeshUtils.Edge.EdgeType.Triangle), Position = m_collectedData.PointOnEdge, Rotation = m_collectedData.DirectionRotation }; OnEdgeFound(resultingData); PerformRemoveFromParent(); return; } EdgeVisual.Visible = m_collectedData != null && m_collectedData.CurrentEdge.Valid; if (EdgeVisual.Visible) { const float edgeRadius = 0.035f; const float defaultAlpha = 0.25f; const float mouseOverAlpha = 0.65f; EdgeVisual.SetTransform(m_collectedData.CurrentEdge.Edge.Start, m_collectedData.CurrentEdge.Edge.End, edgeRadius); if (m_collectedData.CurrentEdge.Edge.Type == MeshUtils.Edge.EdgeType.Triangle) { EdgeVisual.Color = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, defaultAlpha); EdgeVisual.MouseOverColor = new Color(Color.yellow.r, Color.yellow.g, Color.yellow.b, mouseOverAlpha); } else if (m_collectedData.CurrentEdge.Edge.Type == MeshUtils.Edge.EdgeType.Principal) { EdgeVisual.Color = new Color(Color.red.r, Color.red.g, Color.red.b, defaultAlpha); EdgeVisual.MouseOverColor = new Color(Color.red.r, Color.red.g, Color.red.b, mouseOverAlpha); } } NodeVisual.Visible = EdgeVisual.Visible && m_collectedData.SelectedEdge.Valid; if (NodeVisual.Visible) { const float nodeRadius = 0.040f; NodeVisual.SetTransform(m_collectedData.PointOnEdge, Quaternion.identity, nodeRadius); // The user doesn't have to hit the node sphere. if (Manager.HijackLeftMouseClick()) { OnPointClick(null, NodeVisual); } } }