Jump to content

Rotating uv tile


Recommended Posts

Hi David, you can do this in:

  • SOPs using primitive's node rotate and attribute copy.
  • VOPs feeding random values to UV position's rotate.
  • VEX feeding random values to the rotate function.
int seed = chi('seed');

vector pivot = primuv(0, 'uv', i@primnum, 0.5);
float amount_n = rand(i@primnum, seed);
float amount_pi = fit01(amount_n, -M_PI, M_PI);

matrix3 m = ident();
rotate(m, amount_pi, {0,0,1});

v@uv = (v@uv - pivot) * m + pivot;

 

rotate_UV_tiles.hipnc

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Or if you want overlapping UVs, using maximum space and everything in one vertex wrangle:

string grp = itoa(i@primnum);
vector bb_prim = relbbox(0, grp, v@P).xzy;
vector bb_center = bb_prim - {0.5, 0.5, 0.0};
float amount_n = rand(i@primnum);
float amount_pi = fit01(amount_n, -M_PI, M_PI);
v@uv = bb_center;

matrix m = ident();
rotate(m, amount_pi, {0,0,1});
v@uv *= m;

float diag = sqrt(0.5);
v@uv = fit(v@uv, -diag, diag, 0.0, 1.0);

Here are some screenshots showing what each paragraph is doing:

image.png.e64c568b50108b2ddbe2f3de1d9a87a4.png image.png.5c2b2e06195c5a451a41b4072d84066d.png image.png.86e5fbb40f070c1f3297e08de6c4c9ab.png

rotate_UV_tiles_overlap.hipnc

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, konstantin magnus said:

Hi Michel,

yes sure. I think we have already discussed this under the keyword "texture bombing".

Yeah I am aware of texture bombing I was hoping that someone knew a simpler way to just rotate the udims independently like Andrew does in Blender.

Thanks for the tip thou.

Link to comment
Share on other sites

I guess the continuous grouping and building of bounding boxes has killed the performance. If it's quads only, you better try something like this instead:

int vtx = vertexprimindex(0, i@vtxnum);
v@uv.x = vtx == 0 || vtx == 1;
v@uv.y = vtx == 0 || vtx == 3;
v@uv -= set(0.5, 0.5, 0.0);

float amount_n = rand(i@primnum, 123);
float amount_pi = fit01(amount_n, -M_PI, M_PI);

matrix m = ident();
rotate(m, amount_pi, {0,0,1});
v@uv *= m;

float diag = sqrt(0.5);
v@uv = fit(v@uv, -diag, diag, 0.0, 1.0);

 

Link to comment
Share on other sites

Hey Konstantin,

Your help came at the right time! I'm currently trying to achieve something very similar to David's example, but I need to restrict the rotation randomness to 90 degrees.
I am familiar with some expressions to perform rotations in set increments, but not sure how to implement them with you code. I made a couple attempts but it just completely breaks your vex.

The method that seems to work best with my setup is the 4-VEX UNIT.

Much appreciated!

 

Edited by velk
Link to comment
Share on other sites

Hi @velk,

just cut the rotation amount values in half:

float amount_n = rand(i@primnum) * 0.5;

 

Or to get exact control over maximum degrees:

float degrees = chf('max_degrees');

int vtx = vertexprimindex(0, i@vtxnum);
v@uv.x = vtx == 0 || vtx == 1;
v@uv.y = vtx == 0 || vtx == 3;
v@uv -= set(0.5, 0.5, 0.0);

float amount_n = rand(i@primnum, 123);
float amount_rad = radians(degrees) * amount_n;

matrix m = ident();
rotate(m, amount_rad, {0,0,1});
v@uv *= m;

float diag = sqrt(0.5);
v@uv = fit(v@uv, -diag, diag, 0.0, 1.0);

 

 

  • Like 1
Link to comment
Share on other sites

Thanks @konstantin magnus

It looks like this limits the maximum angle, however it also outputs any angle in-between. 
Is there a way to strictly enforce only 0, 90, 180, 270 degrees?

I tried to adjust your random function and also played with the other methods you provided earlier (primitive, vop, vex) but I can't seem to achieve what I described.

In the Vex method from your last post, I tried variations of this:
float amount_n = (floor(rand($PT)*4)*90);

In the Primitive method, I tried variations of this in the rotate Y field:
floor((rand($PT)*2-1)*(360/90))*90

Cheers

Edited by velk
Link to comment
Share on other sites

Hi @velk, does this work for you?

int inc = chi('steps');
float degrees = chf('max_degrees');

int vtx = vertexprimindex(0, i@vtxnum);
v@uv.x = vtx == 0 || vtx == 1;
v@uv.y = vtx == 0 || vtx == 3;
v@uv -= set(0.5, 0.5, 0.0);

float amount_n = rand(i@primnum, 123);
float amount_inc = floor(amount_n * inc) / float(inc);
float amount_rad = radians(degrees) * amount_inc;

matrix m = ident();
rotate(m, amount_rad, {0,0,1});
v@uv *= m;

float diag = sqrt(0.5);
v@uv = fit(v@uv, -diag, diag, 0.0, 1.0);

 

Link to comment
Share on other sites

Hey @konstantin magnus

Thanks for the fast reply!
It still rotates at random orientations. See attached. I also tried with 90 and 90, and other values to test in the Max Degrees and Steps.


Is there a way to perhaps get the code to pick between a list of values (0, 90, 180, 270) instead of random?
Not the most flexible solution, but it would get the job done for simple scenarios.
 

vex_90_degree_uv_rotate.jpg

Edited by velk
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...