PDA

View Full Version : Pivot auto snapping: how to automate ?


KamiNoNamida
05-12-2006, 12:13 AM
Hi all, being working on a charachter setup, i've recently tried to get a controller pivot automatically snapped to a joint. I've tried it many, many ways (less or more conventionnal ones) but there always was some 'cycle problems' or relative coordinates soucy... anyway, in spite of my quite poor knowledge in mel scripting, i took that option as the only one left, since it seemed to be the only way of getting the absolute coordinates of the joint (didn't find any satisfying attribute to this purpose).
Therefore i ended up with this:

global proc float[] AutoPivot()
{
float $absolutePos[2];
$absolutePos = `joint -q -p -a "my_joint"`;
Controller.PivotAutoSnapX = $absolutePos[0];
Controller.PivotAutoSnapY = $absolutePos[1];
Controller.PivotAutoSnapZ = $absolutePos[2];
}

Where PivotAutoSnap are attributes i've created and connected to the rotatePivot attribute of the controller (putting the xyz coords directly into the rotatPivot does not work, I don't know why).
It works better than anything i've tried so far, except for this: it does not "auto-update". Then, after i rotate my controller, i have go to another frame so the pivot snaps.

That's the thing that bothers me and I can't fix it. I thought it would be permanently efficient, since I put it in the expression editor (I remembered some expressions work this way, i.e. volumic scale), but it doesn't.

Could anyone help me out on this, please ? I'm freaking out :banghead:

Thanks :)

NolanSW
05-12-2006, 12:38 AM
If you're simply trying to have a control snaped to a joint then follow these simple steps:

1. Create your control curve
2. Group it to itself.
3. Select the joint and then the group
4. Type

delete `pointConstraint`;
delete `orientConstraint`;


That will align and snap the control to the joint with maintaining zeroed out channels to the control.

5. If the curve is not in the orientation you want then select the CV's and type :rotate 0 0 90 (Whatever axis you want it to turn).

There are scripts out there that have this fuction you want. I've got a script on my site for doing this if you need it (controlMaker).

Hope that helps :)
-Sean

KamiNoNamida
05-12-2006, 01:39 AM
Well, thanks for your answer :)
In fact, i've just tried your tip very quickly, so i'm not sure if I did it correctly (may be some connections screwing things up) but it didn't work as i expected: it absolutely ruined my skeleton upside down lol

The thing is I did not explain something that might have its importance here, that is, my controller is a spine controller and I wish to get its pivot on the spine joint under it, so that it rotates around the joint, but without beeing situated around it, but above (to put it simple, there's an offset between them).

Also, i didn't know of this "delete constraint" stuff, could you explain to me what it does ? (since there are no parent/children relationship between them, nor any constraint relating one to another).

I'll get a deeper look at it tomorrow and tell you wether that's ok or not (read "if I'm too tired to do things right, right now"). Then if you could quickly have an eye on the topic tomorrow evening that would be great ;)


Thanks a lot again for your help :bounce:

edit: i had an eye on your site too, seems to have interresting stuff out there ! I tried to watch the demo of your script, but i have missing codecs so didn't work, i'll test it tomorrow then.

NolanSW
05-12-2006, 05:10 PM
Sorry, I forgot I took the link out for the codec. It's a techsmith codec. Just do a search for that and it will work. The quicktime vids you need quicktime 7 to view.


The delete `pointConstraint` is odd to people who are new to mel. Basically it's an order of operations command. The constraint is happening on what is selected. So if you selected two objects, the second selection will be point constraint to the first. Then the "delete" will delete the constraint. So think of it as a temporary constraint.

There is another way to do this operation as well where you parent the controls group to the joint without preserving position and then unparenting it. This snaps it as well.

As far as the pivot. You can use 2 groups above the controller curve. The top group will be snapped to the joint below the joint. The next group will then be snapped to the joint you want to snap to.

There is a video demo of script here:
http://highend3d.com/maya/downloads/mel_scripts/character/3877.html

To query pivots on a transform, the best command will be `xform -query -worldSpace -rotatePivot joint1`;

StephG
05-15-2006, 12:58 AM
Have you tried something like?:


vector $pos = `xform -q -ws -sp joint2`;
xform -ws -rp ($pos.x)($pos.y)($pos.z) nurbsSphere1;


or


float $pos[] = `xform -q -ws -sp joint2`;
xform -ws -rp $pos[0] $pos[1] $pos[2] nurbsSphere1;


If you want to automate it, you need to use a scriptJob or integrate it into a control interface or something.

CGTalk Moderation
05-15-2006, 12:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.