Jump to content
Marcola

Copy geos on grid with random position and rotation

Recommended Posts

Hello masters,

I think i have a fairly easy question. I'm trying to copy 5 different geos (cube blocks) on mesh grid points in a way that the 5 geos occupy all the points randomly and also the Y rotation for each block is different in increment of 45 degrees angle from each other.

I've been trying to lay a mesh grid, use sort, group expression and group combine to select random points and so far the block positioning work. However, i'd like to add more randomness as some of the cubes are positioned aside each other due to the sort node. Also, i'm not finding a solution to rotate the blocks in Y randomly in 45 degrees increments.

Does anyone know how to do that? I attached the file that i've worked on.

(i didn't attached the objs i've been using but consider them like a piramid, cone, torus or any other platonic.

Any help is appreciated.

Tiles_OdForce.hiplc

Share this post


Link to post
Share on other sites

The "modern" way of Houdini is to try avoid using copy stamping as much as you can though. You can instead also put everything in the new forloop and loop 8 times with transform sop, once with every 45deg rotation.
reference in the vid below.

An even more performant method, and arguably easier, is to pre-supply the rotations into your points on the right side of the copy input.

you could do this with something like the following attribute wrangle script:

v@up = {0, 1, 0}; // up vector in positive Y axis
v@N = {0, 0, 1}; // N vector in positive Z axis

matrix rotationMatrix = ident() // create a matrix with no initial rotation;
int rotationSegment = rint(rand(@ptnum) * 8); //creates a random number from 0 to 8
float angleInRads = radians(45.0 * rotationSegment); //multiply the angle by 45 and convert to radians (angle/180 * $PI)
rotate(rotationMatrix, angleInRads, {0, 1, 0}); //rotates the matrix, by the angle, around the vertical axis

v@N = v@N * rotationMatrix; //rotates the N around the Up vector in a random amount of steps of 45 degrees

 

 

Edited by acey195
  • Like 1

Share this post


Link to post
Share on other sites

Hey acey195,

Thank you so much for the info. Researching the web, I've noticed that a lot of people are mentioning the aversion to the "copy stamp" node and instead showing preference for the "for each" and "for loop" nodes. When using the "copy stamp" node, i noticed that if i'm working on a point grid instead of a mesh grid, the transformation doesn't quite work as expected but as soon as i convert it to mesh, it works. Not as i expected though.

Your point about rotating the points before copying the geos is exactly what i tried to do but rotating points using the standard grid in points mode and using the "copy stamp" has been a bit challenging.

I'll definitely check the video that you sent and also your code. It looks really simple and it might perform way better than using the nodes. Appreciate your help.

Best.

 

Share this post


Link to post
Share on other sites

hey acey195,

Your snippet worked perfectly! It is somewhat faster than the node compilation and it is really nice to have the explanation embedded on it. I understood most of it but if you don't mind, i have a few questions about your code and would like to get some info about it.

For instance, this code line: 

v@N = {0, 0, 1};

I understand the v@up in Y as i want the rotation to happen in Y but how come a positive normal vector in Z if the modification is a rotation on the Y axis?

And then this code line:

v@N = v@N * rotationMatrix;

This is multiplying the positive normal vector in Z with and empty matrix (indent()). Could you please explain this line?

Once again, thank you for the help! Much appreciated.

Share this post


Link to post
Share on other sites
On 9/15/2017 at 11:23 PM, Marcola said:

hey acey195,

Your snippet worked perfectly! It is somewhat faster than the node compilation and it is really nice to have the explanation embedded on it. I understood most of it but if you don't mind, i have a few questions about your code and would like to get some info about it.

For instance, this code line: 

v@N = {0, 0, 1};

I understand the v@up in Y as i want the rotation to happen in Y but how come a positive normal vector in Z if the modification is a rotation on the Y axis?

And then this code line:

v@N = v@N * rotationMatrix;

This is multiplying the positive normal vector in Z with and empty matrix (indent()). Could you please explain this line?

Once again, thank you for the help! Much appreciated.

Glad it worked!

Basically to get a proper copy rotation in Houdini you need either 2 vectors ("N"(aim) & "up"(up/roll)) or 1 quaternion ("orient"(aim+up/roll))
Since quaternions are more difficult to keep track of, I usually prefer the 2 vector approach.

v@N = {0, 0, 1};

The N has to be initialized first, and since Houdini uses Z forward as the default forward axis, that is the one to use here ( {0, 0, 1} )

On this line: 

rotate(rotationMatrix, angleInRads, {0, 1, 0}); //rotates the matrix, by the angle, around the vertical axis

or if you have a custom up vector:

rotate(rotationMatrix, angleInRads, v@up); //rotates the matrix, by the angle, around the up axis

the matrix is converted from an identity (basically 0 rotation matrix) to the matrix that will rotate the vector in the way that you want.
so it is not an identity matrix anymore at this point.

v@N = v@N * rotationMatrix; // or v@N *= rotationMatrix;

will apply the matrix to the initialized front vector, since in the rotate function we rotated around the up axis, the rotation will be in the XZ plane.

 

  • Like 1

Share this post


Link to post
Share on other sites

Fantastic! It completely makes sense now, i didn't know about the need for the "aim" vector in case one wants to copy rotate properly. That is why the doubt with v@N... It is definitely easier to handle the equation with 2 vectors than with quaternion. 

Thanks very much for the explanation, acey195! Really clever solution for something that has been talked about in the forums for quite a while.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×