Jump to content

Copy to points - help randomly rotate donut sprinkles


Recommended Posts

Hi!

Usual disclaimer - I'm fairly new to Houdini (though, I know enough to have built this delicious looking donut) and I've searched previous posts and the internet for answers. ;)

I know this question has been asked 100 times, but I haven't yet found an answer compatible with my brain. 

I just want to randomly rotate the sprinkles and keep them (mostly) flat against the surface of the icing.

I know they are aligned to N of the face that the copy sop used to place them. Can I simply randomize their rotation based on that? (I don't know what's creating their individual rotations at the moment, as they are generally facing the same way, but not exactly. That could be helpful to know.)

Thanks!

image.thumb.png.0a731baafdd94f0d7fcc72a3eb68c766.png

Link to comment
Share on other sites

Thanks for the reply!

I actually read your blog post this morning. It helped me understand some things. I need to read it again.

I have to admit I'm not that enthusiastic that the easiest solution is to install external tools through git. lol

I'll check it out though, thanks for the tip.

There must be a VOPpy solution?

I can't think of why sidefx doesn't have this "rotate/orient copies" function built into the copy node? 

 

 

 

Link to comment
Share on other sites

2 hours ago, evilRainbow said:

Thanks for the reply!

I actually read your blog post this morning. It helped me understand some things. I need to read it again.

I have to admit I'm not that enthusiastic that the easiest solution is to install external tools through git. lol

I'll check it out though, thanks for the tip.

There must be a VOPpy solution?

I can't think of why sidefx doesn't have this "rotate/orient copies" function built into the copy node? 

 

 

 

Well, the function is *sort of* built into the Copy SOP via template point attributes... you just have to know how to do the math / VEX to rotate your up vector around the normal axis in order to get the randomized rotation around the normal. That's why I wrote MOPs... it's annoying to do that kind of thing manually every time.

The VOP solution is more or less the same as the VEX solution, since VEX and VOPs are interchangeable. I'm attaching a file here where I define the "rot" attribute as a random axis/angle rotation around N.

Edit: updated file to bind to rot instead of orient

random_rot_around_axis_toadstorm.hiplc

Edited by toadstorm
Link to comment
Share on other sites

1 hour ago, toadstorm said:

Well, the function is *sort of* built into the Copy SOP via template point attributes... you just have to know how to do the math / VEX to rotate your up vector around the normal axis in order to get the randomized rotation around the normal. That's why I wrote MOPs... it's annoying to do that kind of thing manually every time.

The VOP solution is more or less the same as the VEX solution, since VEX and VOPs are interchangeable. I'm attaching a file here where I define the "rot" attribute as a random axis/angle rotation around N.

Edit: updated file to bind to rot instead of orient

random_rot_around_axis_toadstorm.hiplc

This is so cool. Thank you. I get it way better now.

The quaternion vop operator makes it pretty simple.

I have an additional question. So I turned your sprinkle into a little gnomon thing to see how the sprinkles were lying on the surface (the green tube is your original sprinkle). Some of the sprinkles are going to have different shapes and need to be rotated randomly on the Y (green) axis too. How could that be implemented?  (I haven't had a chance to look at Konstantin Magnus's solution yet) 

Thanks again.

image.thumb.png.6e7a647b8c0200dac76bcb2cab8027c4.png

 

 

Link to comment
Share on other sites

On 10/27/2019 at 3:23 PM, toadstorm said:

Well, the function is *sort of* built into the Copy SOP via template point attributes... you just have to know how to do the math / VEX to rotate your up vector around the normal axis in order to get the randomized rotation around the normal. That's why I wrote MOPs... it's annoying to do that kind of thing manually every time.

The VOP solution is more or less the same as the VEX solution, since VEX and VOPs are interchangeable. I'm attaching a file here where I define the "rot" attribute as a random axis/angle rotation around N.

Edit: updated file to bind to rot instead of orient

random_rot_around_axis_toadstorm.hiplc

Thanks so much for posting this file, I was studying it as well and was curious about the fit, you remapped it to -1,1 and you are getting the full 360 range, I get why remapping it from 0 to 2*pi gives the full range but how does -1,1 in the fit give the same result? Thank You!

Link to comment
Share on other sites

@evilRainbow Hey sorry I didn't reply sooner. I'm posting an updated file that goes into a little bit more depth as to how orientations are computed by the Copy SOP, and then how to modify those rotations one axis at a time, all using quaternions.

Basically the Copy SOP is going to try to do whatever it can to figure out how to orient your copies if you don't provide enough information in the form of template point attributes. An orientation requires a minimum of two vectors: the third can be automatically calculated by finding the cross product of the other two. Once you have three vectors, you have a 3x3 transform matrix, and so you know which way each axis (X,Y,Z) should be facing.

If all you do is provide N, which is typically the case when you're just starting with any old geometry, Houdini is going to guess at an "up" axis by figuring out the matrix that would rotate world N (the +Z axis) to the current surface normal, and then multiply that same matrix by world up (the +Y axis). This "guess" in VEX is the dihedral() function. Then it will cross N and up to find the implicit third axis, and that's your final orientation. I'm doing that manually inside the VOP network "determine_initial_orient" here, converting it to a quaternion, and then binding the result to "orient". Quaternions and 3x3 matrices are interchangeable when you're just talking about orientations (matrices can also describe scale and shear but we won't get into that here).

Next, the extra rotations... a quaternion can be described as an axis to rotate around and a number of radians to rotate around that axis. In the second VOP "twisting_manual", first we decompose the orient attribute back into N and up vectors by multiplying +Z and +Y by the orient quaternion... this effectively recreates the original orientation we did in the previous VOP, but now it's relative to a specific axis. Now we can just create a new quaternion out of that axis, and any angle we like; this will create a "twist" around whatever axis.

Finally, all these new twists are combined by multiplying the quaternions together, and then multiplying the combined rotations by the original orient quaternion. You can try dragging the "twist" parameters around on that second VOPnet to see the sprinkles twisting around. You could easily modify this VOP to generate random values for the "angle" of both axes rather than using a parameter.

Sorry this is so wordy but quaternions and orientation in general is a pretty complicated thing and I still only really understand half of it. There's more notes inside the HIP file... it's probably easier to just look for yourself and play with the settings.

 

manual_rot_around_axis_toadstorm.hiplc

  • Like 2
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...