// ReSharper restore InconsistentNaming public Mesh() { var v = _vHead = new MeshUtils.Vertex(); var f = _fHead = new MeshUtils.Face(); var pair = MeshUtils.EdgePair.Create(); var e = _eHead = pair._e; var eSym = _eHeadSym = pair._eSym; v._next = v._prev = v; v._anEdge = null; f._next = f._prev = f; f._anEdge = null; f._trail = null; f._marked = false; f._inside = false; e._next = e; e._Sym = eSym; e._Onext = null; e._Lnext = null; e._Org = null; e._Lface = null; e._winding = 0; e._activeRegion = null; eSym._next = eSym; eSym._Sym = e; eSym._Onext = null; eSym._Lnext = null; eSym._Org = null; eSym._Lface = null; eSym._winding = 0; eSym._activeRegion = null; }
public static void AddWinding(MeshUtils.Edge eDst, MeshUtils.Edge eSrc) { eDst._winding += eSrc._winding; eDst._Sym._winding += eSrc._Sym._winding; }
public static bool EdgeGoesRight(MeshUtils.Edge e) { return(VertLeq(e._Org, e._Dst)); }
public static bool EdgeGoesLeft(MeshUtils.Edge e) { return(VertLeq(e._Dst, e._Org)); }
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); } } }