Jump to content
Max_Steven

Procedurally Set Pivot for object

Recommended Posts

Hello,

For now I have learned to centerize the pivot but I just wonder is there any way to procedurally position the pivot?

Like in this scene I want to setup the pivot properly at the begining of each leaf

Thank you for your time.

 

 

Pivot_Position_Ask.hip

%pn-29-03-21-152824-087.png

Share this post


Link to post
Share on other sites

Hey,
I had a look at your hipfile and while I did not get it 100% procedural I did get fairly close. However, from looking at your hipfile it looks as though you are making one single leaf and then copying it out, then after the copy, you want to change the pivot, is this correct?

If so, I'd recommend going for the easier approach of setting the pivot on the leaf model before you copy it out. That way you only need to set the pivot once and it is probably also happening at world 0 so it is way easier to deal with, not having to take into account tons of small offsets or rotations that come from the instancing.

I've added my hipfile below that try to solve the pivot after copying but it's not perfect, especially because I am using bounding box expressions which does not seem to like packed geometry very well so you either get an inaccurate pivot from working with the packed geo or get an accurate pivot but have to unpack the geo.

Hope either the hip or my alternative suggestion above can be of help!

Pivot_Position_Ask_mnb.hiplc

Share this post


Link to post
Share on other sites
1 hour ago, underscoreus said:

Hey,
I had a look at your hipfile and while I did not get it 100% procedural I did get fairly close. However, from looking at your hipfile it looks as though you are making one single leaf and then copying it out, then after the copy, you want to change the pivot, is this correct?

If so, I'd recommend going for the easier approach of setting the pivot on the leaf model before you copy it out. That way you only need to set the pivot once and it is probably also happening at world 0 so it is way easier to deal with, not having to take into account tons of small offsets or rotations that come from the instancing.

I've added my hipfile below that try to solve the pivot after copying but it's not perfect, especially because I am using bounding box expressions which does not seem to like packed geometry very well so you either get an inaccurate pivot from working with the packed geo or get an accurate pivot but have to unpack the geo.

Hope either the hip or my alternative suggestion above can be of help!

Pivot_Position_Ask_mnb.hiplc

Thank you for replying me.

Yeah you are absolutely right. I did a copy to point operation and actually  I already set the pivot clean before doing copy to point step.

It's just I dont know how to make it keep the pivot at where it should be. 

When I isolate single of them to rotate, the pivot is world origin. 

Pivot_Position_Ask2.hiplc

Share this post


Link to post
Share on other sites

@Max_Steven Hmm, ok. Maybe a better question would be what are you trying to do with the transform? Most transforms you'd want to apply to the leaf, like translation, rotation and scaling can just be applied to the points themself and then it will be carried on to the leaves.

For translation simply move the points by whatever means you'd like, maybe adding a noise to their current position etc.

For rotation, there are a few ways. If you just want the leaf to rotate between two set orientations simply use the lerp function inside a normalize function to transition between the two like this:

v@N = normalize(lerp(vectora, vectorb, amount));

If you want a more "propper" way with more control and the ability to rotate stuff further then something like this would be more appropriate. It's a bit more complicated but essentially it takes two vector attributes, one vector to rotate and one vector to rotate around. You can think of it like the vector to rotate around being a big flag pole and the vector to rotate being like if someone tied a rope to the flag pole and ran around the flag pole. (That might be a very horrible analogy, sorry). Usually I end up setting "N" as the vector to rotate around and "up" as the vector to rotate, though if you change them around you can see that kind of result you get.

matrix m = ident();

vector rot_axis = point(0, chs('Rotation_Axis'), @ptnum);
vector vector_to_rotate = point(0, chs('Vector_to_Rotate'), @ptnum);

float rndm = rand(@ptnum, chf('Seed'));
float deg = chf('Degrees');

deg = fit01(rndm, (deg * -1), deg);

rotate(m, radians(deg), rot_axis);

vector_to_rotate *= m;

setpointattrib(0, chs('Vector_to_Rotate'), @ptnum, vector_to_rotate, "set");

This code has some built-in functionality that would make each leaf have an individual random rotation offset. I mostly use it to just randomize the orientation of static objects, so here is the same code but without the randomness if that is more interesting:

matrix m = ident();

vector rot_axis = point(0, chs('Rotation_Axis'), @ptnum);
vector vector_to_rotate = point(0, chs('Vector_to_Rotate'), @ptnum);

float deg = chf('Degrees');

rotate(m, radians(deg), rot_axis);

vector_to_rotate *= m;

setpointattrib(0, chs('Vector_to_Rotate'), @ptnum, vector_to_rotate, "set");


And finally for scale just assign a pscale attribute to the point, this will act as a uniform multiplier to the objects scale. If you'd like to scale it non-uniformly, ie stretching it, assign a vector attribute called scale to your points.

Share this post


Link to post
Share on other sites

Oh, sorry for not explain clearly my purpose.

I created a l-system and get the point to scatter the leaf.

I used random scale in L-system  to it more organic but it start intersecting.

So at first my purpose is fixing some intersect leaves by manually rotate it.

In Maya normally I can snap pivot to fix it easily, but in Houdini I just can't snap the pivot so I thought maybe there is a way to fix the pivot position procedurally.

And thank you so much for your code. It amazing and beyond my imagination :)  

Actually, I tried to add some wind to the leaf by adding to a divided box and point deform it, but it's not how the leaf rotates with noise.

Now with your help I can see somehow it's possible.

Thank you again for sharing those codes and light my day :D

 

 

  • Thanks 1

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

×