Is there a faster way to paint mesh by line color?

Hi all,

I have some meshes that I need to paint according to some lines…

I worked out this way, but when the mesh is very heavy, the def takes some time…

This is basically where the bottle neck is, the whole problem arises because the Pull Point component does not output grouped items in branches according to the closest geometry to each point… so I have re project all points to all curves, and test for distance almost 0…

paint mesh by line color.gh (26.5 KB)

right-click and change to All, I think that Pull Point is missing an indexes output … This data is important.


paint mesh by line color_v2.gh (31.4 KB)

1 Like

I know you are looking for a grasshopper solution, but here is a slightly faster solution in C#

private void RunScript(List<Line> lines, Mesh mesh, List<System.Drawing.Color> colors, ref object A)
{
  mesh.VertexColors.Clear();
  foreach (Point3d vertex in mesh.Vertices)
  {
    var min = double.MaxValue;
    var closest = -1;
    for (var j = 0; j < lines.Count; j++)
    {
      var d = lines[j].DistanceTo(vertex, true);
      if (d > min) continue;
      min = d;
      closest = j;
    }
    mesh.VertexColors.Add(colors[closest]);
  }
  A = mesh;
}

PaintByLines.gh (19.5 KB)

2 Likes

Indeed, thank you Thomas! It is a nice improvement nevertheless.

Awesome! will use this as a learning example along my scripting journey. Thanks!