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…

8 Likes

Awesome thanks :slight_smile:

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.

3 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…
Can you upload those geometries?

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.

3 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)

1 Like

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 :slight_smile: that’s a good idea.

Sure, please find attached.

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)

2 Likes

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)

4 Likes

Wouldn’t simply adding two boolean inputs “u” and “v” to the “Flip” component solve all our torments ?

2 Likes