Rival Consoles Posted September 12, 2017 Share Posted September 12, 2017 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 Quote Link to comment Share on other sites More sharing options...
LaidlawFX Posted September 13, 2017 Share Posted September 13, 2017 This is called copy stamping, or instancing, in Houdini. Look for those terms and you'll find lots of help on it. Here are the help docs on it. http://www.sidefx.com/docs/houdini/copy/_index Quote Link to comment Share on other sites More sharing options...
woodenduck Posted September 13, 2017 Share Posted September 13, 2017 45 * @ptnum Quote Link to comment Share on other sites More sharing options...
acey195 Posted September 13, 2017 Share Posted September 13, 2017 (edited) 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 September 13, 2017 by acey195 1 Quote Link to comment Share on other sites More sharing options...
Rival Consoles Posted September 13, 2017 Author Share Posted September 13, 2017 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. Quote Link to comment Share on other sites More sharing options...
Rival Consoles Posted September 15, 2017 Author Share Posted September 15, 2017 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. Quote Link to comment Share on other sites More sharing options...
acey195 Posted September 18, 2017 Share Posted September 18, 2017 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. 1 Quote Link to comment Share on other sites More sharing options...
Rival Consoles Posted September 18, 2017 Author Share Posted September 18, 2017 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.