Random prim rotations?
9286 7 2-
- 3dspline
- Member
- 36 posts
- Joined: Nov. 2019
- Offline
I'm stumped on how to rotate these pieces randomly on their center points, pretty new to VEX.
To offset their position is very easy, I can simply do a @P.x += rand(@class);
However rotation and with a center pivot I'm not sure.
I tried to do a for each connected piece loop and put a transform node with a pivot center $CEX, $CEY, $CEZ, then a fit01(rand(@class),0,360) in to rotation fields, but it will rotate everything evenly this way so it doesn't work.
To offset their position is very easy, I can simply do a @P.x += rand(@class);
However rotation and with a center pivot I'm not sure.
I tried to do a for each connected piece loop and put a transform node with a pivot center $CEX, $CEY, $CEZ, then a fit01(rand(@class),0,360) in to rotation fields, but it will rotate everything evenly this way so it doesn't work.
-
- animatrix_
- Member
- 5041 posts
- Joined: Feb. 2012
- Offline
Hi,
Here is one way if the class attribute is a point attribute:
Or if the class attribute is a primitive attribute:
Here is one way if the class attribute is a point attribute:
vector center = getpointbbox_center ( 0, sprintf ( "@class=%s", i@class ) ); @P -= center; vector v = rand ( i@class + ch("seed") ); vector q = sample_orientation_uniform ( v ); @P = qrotate ( q, @P ); @P += center;
Or if the class attribute is a primitive attribute:
int cls = prim ( 0, "class", @primnum ); vector center = getbbox_center ( 0, sprintf ( "@class=%s", cls ) ); @P -= center; vector v = rand ( cls + ch("seed") ); vector q = sample_orientation_uniform ( v ); @P = qrotate ( q, @P ); @P += center;

Edited by animatrix_ - June 26, 2021 02:12:43
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]

-
- mestela
- Member
- 1850 posts
- Joined: May 2006
- Offline
Short answer: Use Mops: https://www.motionoperators.com/ [www.motionoperators.com]
Long answer: If you're new to Houdini, to do what you're after requires vectors, matricies, some other stuff. Definitely useful to know, and if you end up using Houdini for a while you'll hit it eventually, but can be daunting. Mops has wrapped up this complexity and hidden it behind some clean nodes, it's both a fast way to get started, and a good on-ramp to the more advanced workflows.
If you're determined to go without Mops, I'd suggest packing the geo, defining random a rotation axis per piece, a random rotation speed per piece, create a @xform matrix per piece which uses that angle/axis to create a quaternion rotation, that quaternion into a matrix, and then use a transform by attrib to do the rotation. I've attached an example, but hopefully that'll convince you to use mops.
(heh, animatrix beat me to the answer while I was typing...
)
Long answer: If you're new to Houdini, to do what you're after requires vectors, matricies, some other stuff. Definitely useful to know, and if you end up using Houdini for a while you'll hit it eventually, but can be daunting. Mops has wrapped up this complexity and hidden it behind some clean nodes, it's both a fast way to get started, and a good on-ramp to the more advanced workflows.
If you're determined to go without Mops, I'd suggest packing the geo, defining random a rotation axis per piece, a random rotation speed per piece, create a @xform matrix per piece which uses that angle/axis to create a quaternion rotation, that quaternion into a matrix, and then use a transform by attrib to do the rotation. I've attached an example, but hopefully that'll convince you to use mops.

(heh, animatrix beat me to the answer while I was typing...

Edited by mestela - June 26, 2021 02:10:44
-
- 3dspline
- Member
- 36 posts
- Joined: Nov. 2019
- Offline
Thank you Animatrix, that works wonderfully!! at least the points one,
I don't need the prim one to work but not sure why the prim one isn't working if I switch the class to prim and the attribute wrangle to prim as well... maybe I'm using that one wrong?
I'll keep playing with the code to understand it better! there's a few things in there I never used before.
Mestela, I have heard about mops but forgot about it! thank you, just never remember the extent of what they have in there, that should for sure be next on my list to learn!.
I don't need the prim one to work but not sure why the prim one isn't working if I switch the class to prim and the attribute wrangle to prim as well... maybe I'm using that one wrong?
I'll keep playing with the code to understand it better! there's a few things in there I never used before.
Mestela, I have heard about mops but forgot about it! thank you, just never remember the extent of what they have in there, that should for sure be next on my list to learn!.
-
- animatrix_
- Member
- 5041 posts
- Joined: Feb. 2012
- Offline
3dspline
Thank you Animatrix, that works wonderfully!! at least the points one,
I don't need the prim one to work but not sure why the prim one isn't working if I switch the class to prim and the attribute wrangle to prim as well... maybe I'm using that one wrong?
I'll keep playing with the code to understand it better! there's a few things in there I never used before.
Mestela, I have heard about mops but forgot about it! thank you, just never remember the extent of what they have in there, that should for sure be next on my list to learn!.
Oh yes don't change the attribute wrangle to primitives. It should still be a point wrangle basically

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com] https://lnk.bio/animatrix [lnk.bio]

-
- 3dspline
- Member
- 36 posts
- Joined: Nov. 2019
- Offline
Ahhh silly me! yes that works!
Wonderful tool and can just divide by a ch value to control how much. Edit: oh wait, divide by a value doesn't work, seems to just rotate in one direction if I do that, I should understand the code first before I mess with it
. I solved the problem with a VOP position blend between the two to control the amount, not sure if that's the best way but it works
Structures, tiles, stonework, glasswork, everything built has those slight rotations that breaks the reflections and make it look more realistic that way, I'll be using this quite a bit!
Used to do this manually in 3dsmax days, what a pain it was to do revisions on that collapsed mess.
edit2: another problem I found is that the scale changes depending on rotation, the more it rotates the larger the size becomes, for me its not a problem since I'm just using this for slight rotations.
Wonderful tool and can just divide by a ch value to control how much. Edit: oh wait, divide by a value doesn't work, seems to just rotate in one direction if I do that, I should understand the code first before I mess with it

Structures, tiles, stonework, glasswork, everything built has those slight rotations that breaks the reflections and make it look more realistic that way, I'll be using this quite a bit!
Used to do this manually in 3dsmax days, what a pain it was to do revisions on that collapsed mess.
edit2: another problem I found is that the scale changes depending on rotation, the more it rotates the larger the size becomes, for me its not a problem since I'm just using this for slight rotations.
Edited by 3dspline - June 26, 2021 15:21:05
-
- eikonoklastes
- Member
- 446 posts
- Joined: April 2018
- Online
3dsplineYou're on the right track, you just need to use the iteration attribute to vary the rotation per piece.
I'm stumped on how to rotate these pieces randomly on their center points, pretty new to VEX.
To offset their position is very easy, I can simply do a @P.x += rand(@class);
However rotation and with a center pivot I'm not sure.
I tried to do a for each connected piece loop and put a transform node with a pivot center $CEX, $CEY, $CEZ, then a fit01(rand(@class),0,360) in to rotation fields, but it will rotate everything evenly this way so it doesn't work.

-
- toadstorm
- Member
- 402 posts
- Joined: April 2017
- Offline
If you're curious about the MOPs approach, here's a file to look at. The math is essentially the same as what animatrix and mestela mentioned, but it's wrapped up for you. The "Explode" operation turns each primitive face into a packed fragment, which is a type of packed primitive that's helpful if your underlying primitives aren't exact copies of each other. Then the "Randomize" operation creates a rotation matrix and multiplies it against the packed transform intrinsic for each fragment.
I've embedded the HDA definitions, but if those don't work, the latest release is here: https://github.com/toadstorm/MOPS/releases/tag/v1.4.4e [github.com]
I've embedded the HDA definitions, but if those don't work, the latest release is here: https://github.com/toadstorm/MOPS/releases/tag/v1.4.4e [github.com]
MOPs (Motion Operators for Houdini): http://www.motionoperators.com [www.motionoperators.com]
-
- Quick Links