INSTANCES ROTATION

   1708   1   1
User Avatar
Member
14 posts
Joined: Nov. 2017
Offline
Good Morning everyone.

I have a ground with Mountain, emit scatter with a null node.
I have a instance node. basic who calls the point from the grid.
after or before my scatter inside the grid Geo i want to randomize my instances every 90 degrees, Is that possible?
i guess it is not easy as a copy node with a simple rand on the Y axis…i tried to get it with attribute wrangle but without success. I am beginner in Houdini.

Thank you.
Edited by Alex Q - May 17, 2020 23:01:49
User Avatar
Member
405 posts
Joined: April 2017
Offline
This is plenty possible, it's just a bit annoying to do. You have to generate these orientations on your template points manually.

I'm not sure what you mean exactly by “randomize every 90 degrees”, but let's say what you mean is that you want instances to be randomly oriented along any cardinal axis, positive or negative.

What you'd want to do in this case, is randomly assign your “forward” vector on the template points, N, to one of the cardinal axes. Then you'd also want to compute a matching up vector. This is a bit complicated conceptually, but what you can do is use the dihedral() function to generate a matrix that represents the difference between the “default” N (0,0,1) and your new randomized N, and then multiply the “default” up (0,1,0) by that same matrix. Then you have a v@N and a v@up attribute that the Copy to Points SOP can read.

Here's what the VEX might look like:

// initial values
vector N = {0,0,1};
vector up = {0,1,0};

// random index
int rnd = int(fit01(rand(@ptnum), 0, 5));

// define cardinal directions
vector cardinals[] = {{0,0,1}, {0,0,-1}, {0,1,0}, {0,-1,0}, {1,0,0}, {-1,0,0}};

// set N to random cardinal, then compute a suitable up vector to match
N = cardinals[rnd];

// this constructs a rotation that will "rotate" the original N to our new N.
// we can use this to figure out which way up should be pointing.
matrix3 rot = dihedral({0,0,1}, N);
// rotate up by this matrix.
up = rot * up;

// set vectors.
v@N = N;
v@up = up;

I'm attaching a file you can check out, too.

Attachments:
random_cardinals_toadstorm.hiplc (287.6 KB)

MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
  • Quick Links