浏览代码

Optimized `Edge.GetFromToPoints` with caching of left and right anchor `GraphElement`'s.

It is called in every frame and calls `parent.allElements` twice to find the GraphElement for its anchors. The implementation of `allElements` is very slow right now (as is noted in `VisualContainer.cs` comments), but either way we should avoid a traversal of all `VisualElement`'s for every edge every frame.
/main
Peter Bay Bastian 8 年前
当前提交
ff7ce7e4
共有 1 个文件被更改,包括 20 次插入7 次删除
  1. 27
      MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs

27
MaterialGraphProject/Assets/NewUI/Editor/Elements/Edge.cs


DrawEdge(painter);
}
private NodeAnchorPresenter m_OutputPresenter;
private NodeAnchorPresenter m_InputPresenter;
private GraphElement m_LeftAnchor;
private GraphElement m_RightAnchor;
protected void GetFromToPoints(ref Vector2 from, ref Vector2 to)
{
var edgePresenter = GetPresenter<EdgePresenter>();

if (outputPresenter != null)
{
GraphElement leftAnchor = parent.allElements.OfType<NodeAnchor>().First(e => e.GetPresenter<NodeAnchorPresenter>() == outputPresenter);
if (leftAnchor != null)
if (outputPresenter != m_OutputPresenter)
{
m_LeftAnchor = parent.allElements.OfType<NodeAnchor>().First(e => e.GetPresenter<NodeAnchorPresenter>() == outputPresenter);
m_OutputPresenter = outputPresenter;
}
if (m_LeftAnchor != null)
from = leftAnchor.GetGlobalCenter();
from = m_LeftAnchor.GetGlobalCenter();
from = globalTransform.inverse.MultiplyPoint3x4(from);
}
}

if (inputPresenter != null)
{
GraphElement rightAnchor = parent.allElements.OfType<NodeAnchor>().First(e => e.GetPresenter<NodeAnchorPresenter>() == inputPresenter);
if (rightAnchor != null)
if (inputPresenter != m_InputPresenter)
{
m_RightAnchor = parent.allElements.OfType<NodeAnchor>().First(e => e.GetPresenter<NodeAnchorPresenter>() == inputPresenter);
m_InputPresenter = inputPresenter;
}
if (m_RightAnchor != null)
to = rightAnchor.GetGlobalCenter();
to = m_RightAnchor.GetGlobalCenter();
to = globalTransform.inverse.MultiplyPoint3x4(to);
}
}

Vector3[] points, tangents;
GetTangents(orientation, from, to, out points, out tangents);
Handles.DrawBezier(points[0], points[1], tangents[0], tangents[1], edgeColor, null, 2f);
// little widget on the middle of the edge
// I'll leave this in here for later, might come in handy, but for now it doesn't do anything
// Vector3[] allPoints = Handles.MakeBezierPoints(points[0], points[1], tangents[0], tangents[1], 20);

正在加载...
取消
保存