Flowing colour gradient along mesh

Hi everyone, hope you are all safe and well.

I have been trying to colour a mesh along its length with a gradient and have had some success. I found this helpful forum entry which gave me the following result:

Screenshot 2020-04-15 at 18.41.59

My .gh sketch is:

Screenshot 2020-04-15 at 18.42.44

However, problems arise when the pipe intersects with itself. Here, the mesh vertices, which are being tested to find at which point on the path they are closest to, are being placed on the path at the wrong point. This means when it comes to assigning a colour, the colour is wrong:

Screenshot 2020-04-15 at 18.42.04

Is there another way to order the vertices? Could the mesh normals be used to ensure the vertices get matched with the correct point on the path?

Any suggestions will be gratefully received, I’m totally stuck! :persevere:

Here are the files incase anyone wants to play with them:
20200415_Colour Flow.gh (10.0 KB) 20200415_Colour Flow.3dm (8.9 MB)

After some persevering I have come up with a solution/work around. I thought it would be useful to post it here in case someone encounters the same problem later on.

I noticed that once the variable pipe brep becomes a mesh the order of things is somewhat lost. As such I decided to split the brep into pieces along the length of the path curve. This way I could then turn those pieces into meshes and colour these meshes with a gradient. As long as there are enough pieces the colours blend nicely and you don’t read the separate pieces.

The grasshopper sketch:

The result:

You’ll notice that the colours don’t mix up where the variable pipe intersects with itself :sunglasses:

Here is the grasshopper and rhino file in case anyone wants to investigate further:
20200421_Colouring path variable pipe.gh (17.3 KB)
Colouring Path of variable pipe.3dm (9.6 MB)

If anyone does have any other ideas I’d be super interested to hear them.