# Sorting/unitizying multiple surfaces direction UVS

Hello
I was wondering if there is any script or plugin that can sort/align UV direction of multiple surfaces just like Flip surface or flip curve.

ps. I already know about lunch box and pufferfish but both of them only make change on 1 surface.
Thanks,
A

With a c# script you can achieve whatever you want (like always)

Import a surface object (change its â€śType hintâ€ť with right click), and you can flip it by flipping both domains like this:

private void RunScript(Surface x, ref object A)
{
x.Reverse(0, true); //To flip U
x.Reverse(1, true); //To flip V
x.SetDomain(0, new Interval(0, 1)); //To reparametrize U
x.SetDomain(1, new Interval(0, 1)); //To reparametrize V
A = x;
}

You can evaluate a surface in a specific point, extract U or V vector and calculate the angle with a guide vector, and decide if to flip or not U or Vâ€¦
Do you have some geometries to work on? Some cases?

thanks for the respond, however I am not familiar with coding, is it possible you can make it gh-user component
and I can give it a test ?

"As for the geometries, imagine you have 50 panel with different UV direction, but you want to sort/align them in such a way that when you select the U isocruve they are all in 1 direction. "

Thanks,
A

sortUV.gh (14.5 KB)

Try this c# script (Iâ€™ve added comments inside, maybe youâ€™ll understand/learn something â€¦ itâ€™s useful)
This script do:

• evaluate the surface at center (like reparametrized at 0.5,0.5) and extract U and V vectors
• test which of the 2 vectors is more suitable to be aligned with World X vector; if V then it swap UV
• invert U domain if not aligned with X
• invert V domain if not aligned with Y

I wasnâ€™t able to keep original domain span, to work you need to reparametrize the output surfaceâ€¦

5 Likes

Awesome thanks

ps. I already know about lunch box and pufferfish but both of them only make change on 1 surface.

They make changes to as many surfaces that are input, what you were looking for was a guide (like @maje90 used the world plane). Iâ€™ll add a guide surface input when I get around to it, nice idea.

2 Likes

Hello,

the problem with aligning is that you usually you donâ€™t want it aligned by a plane but rather about inside and outside, where ideally u and v direction matches up for each surface patch. This is much tougher to implement, but nothing impossible, since many cad software can do.
Just as a side note here, I once made a uv component but I did not modify the domain, because under the hood its not about changing the domain, but instead transposing or reversing the controlpoint matrix. If you check controlpoints, you see that they changed after changing the domain and reparameterising. The problem with reversing the domain is that you need to make it negative. What Riccardo did, he reparamised after doing this, however there are situations where a reparametrisation is not wanted. So the most direct way, might just recreating the surface but feeding in cps,weights,knots in different order.

2 Likes

Nice ideaâ€¦ seems logic!
Sad there isnâ€™t a direct command to just reverse the points (or it is?), and we have to make it â€śmanuallyâ€ťâ€¦

well, I donâ€™t have access to this code right know, but I remember its about retrieving the cps from an existing surface with a nested loop in the right way. For each flipping direction you just loop upwards or downwards or you loop through u first or for v first. Then you recreate a new NurbsSurface from scratch. if you flip u with v you also need to feed in the uKnots as vKnots and vice versa. Iâ€™m not sure if you need to pass the degree, since the knotvector usually hints the degree. But in case you need to, just pass that as well.
Its a bit more code but nothing huge. Just donâ€™t forget to pass in weights as well in case you are dealing with rational surfaces.

hello,

Thanks for the script. I did a test, it works well with surfaces in xy planes only, Please see the image below, for clarification of the issue.

Ok, it obviously canâ€™t work with that kind of surfacesâ€¦ the script must be updated to use a generic plane instead of always worldXY. A different plane for each surface.
That plane could be found by putting a cylinder inside your structure as a reference/guide surfaceâ€¦

even with a generic plane it will fail in this case. You will need some sort of recursive approach to determine the orientation based on the neighbour. One major problem in this forum is, that user constantly underestimating the effort to code reliable and especially universal solutions. The most simple solution would be building these surfaces in a way, that they having the right uv from beginning on.

2 Likes

You are right.
But it could be that the surfaces are imported from another softwareâ€¦ I donâ€™t know.

Still, updating the script is almost effortless, feeding the proper plane (with surf closest point and evaluating surface) is a 2 min solutionâ€¦ if the problem grows, weâ€™ll seeâ€¦

sortUV_V2.gh (16.4 KB)

UVN Unification for surface models is an important topic. Some CAD programs already provide good solutions, but they are not perfect.
By the way I think you can always join to a Brep. Then the internal faces are oriented.
However if you want do this with single surfaces the problem quickly gets complicated.
Iâ€™m just tired writing little script, and in the end they complaining that its not working right. Thatâ€™s why Iâ€™m not doing this anymore. These 2 min quickly get 30 mins, and in the end the problem still isnâ€™t solved. You can also flip them manually within 5 mins.

1 Like

Yes, i understand what you are sayingâ€¦
I just built up a tool to flip U/V â€¦ as there is no direct gh component to do that.
If you can provide a rough, simple, surface (or polysurface) with correct UV directions, that resemble the original structure, you can sort/flip a large amount of surfaces easily.
With a shape like in Arianâ€™s picture, Iâ€™d think of a cylinder.

2 Likes

yes donâ€™t worry thatâ€™s a good idea.

Best,
A

Surafce_UVS Sort_Sample 02.3dm (1.5 MB)
Surafce_UVS Sort_Sample 04.3dm (2.8 MB)

Your surfaces are almost all already ok, with a â€ścontinueâ€ť UV orientation.
The only problem are the triangular surfaces, whose canâ€™t be â€śfixedâ€ť with a script, you need to redraw them.
sortUV_V2_sample02.gh (69.7 KB)
sortUV_V2_sample04.gh (25.0 KB)

1 Like

A while back I was working on this problem a bit, then I put it away. I think the cylinder idea is a good one, so this is an example that creates a bounding cylinder on vertical surfaces. It does join all connected surfaces. Joining surfaces into breps does unify the normal direction of each surface, however, it does not unify the UV direction. The UVâ€™s can still be miss-matched, which can be frustrating. This should work for the pictured example.

So, this isnâ€™t a totally universal application. Another way that this could be dealt with is separating each surface by its direction to an input vector, and then a plane could be provided for each direction (perhaps with a bounding box).

UnifyUV.gh (47.5 KB)

3 Likes

Wouldnâ€™t simply adding two boolean inputs â€śuâ€ť and â€śvâ€ť to the â€śFlipâ€ť component solve all our torments ?

1 Like