PDA

View Full Version : utilizing the xform command to get rid of constraint popping. need help


Geuse
03-11-2008, 03:56 AM
I'm trying to figure out a way to maintain an object in space no matter it's constraints. As you know using constraints on an object causes the object that is constrained to pop between their objects local space when switching. So I'm trying to figure out a way to maintain the objects position in space no matter what it is constrained to.
I start off by creating a locator and move it to the position of an object that is frozen inside a group. This can be done using the -rp command instead of -translation so you'll get the rotate pivot information you need. So far so good. Now I got the position it should be at after the constraint switches.
Next I switch the constraint so the object pops which means it moves away from the locator. So all I need to do now is to move the hand ctrl to the locator. No biggie, but this is were I'm stuck!

How do you do this? and is it possible utilizing this idea?
I was thinking of writing a script to do this as soon as I press a button to switch the constraints.


I've tried John Doublesteins dynamic parent script and it worked great at first, but I've encountered some errors so I mailed him and hopefully I'll come to understand how to fix it. But in the meantime it struck me that maybe I could do this myself so that's when I came up with this idea. I'm really not a scripter but I do want to learn.


So pretty please with some sugar on the top, clean the fu....I mean...please help :)
Would really appreciate it!

Geuse
03-11-2008, 06:08 AM
actually I got it to work. I had to create a second locator of course.
We'll see if I can make a script out of it.

Geuse
03-11-2008, 10:41 AM
Ah yes! it's working!
But sadly it will only work for this exact setup and names which I have.
Will have to learn indepth mel to create a useful script out of it so it can be applied to any naming convention. Furthermore, I'm well aware I might be using far to much code than necessary to make this happen, but as stated, I'm not a scripter =/
But if anyone would like to have a look at it, here it is.

As follows is the switch(no-pop) constraint code from torso to hip.

And the other way around it's exactly the same but in opposite order so I don't care 'bout posting that.

select -r L_upper_arm_ik_ctrl ;
duplicate -rr; parent -w L_upper_arm_ik_ctrl1;

CreateLocator;
rename "locator_1";


$torso_parent_grp_pos = `xform -query -ws -rp L_upper_arm_ik_ctrl_grp`;
xform -ws -translation $torso_parent_grp_pos[0] $torso_parent_grp_pos[1] $torso_parent_grp_pos[2] locator_1;

select -r locator_1 ;
select -add L_upper_arm_ik_ctrl_grp ;
parent;

FreezeTransformations;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;




$L_upper_wrist_pos = `xform -query -ws -translation L_upper_arm_ik_ctrl`;
xform -ws -translation $L_upper_wrist_pos[0] $L_upper_wrist_pos[1] $L_upper_wrist_pos[2] locator_1;

parent -w locator_1;


select -r L_upper_arm_ik_ctrl_grp_parentConstraint1 ;


setAttr "L_upper_arm_ik_ctrl_grp_parentConstraint1.spine_offset_ctrlW0" 0;

setAttr "L_upper_arm_ik_ctrl_grp_parentConstraint1.hips_ctrlW1" 1;



CreateLocator;
rename "locator_2";


$hips_parent_grp_pos = `xform -query -ws -rp L_upper_arm_ik_ctrl_grp`;
xform -ws -translation $hips_parent_grp_pos[0] $hips_parent_grp_pos[1] $hips_parent_grp_pos[2] locator_2;

select -r locator_2 ;
select -add L_upper_arm_ik_ctrl_grp ;
parent;

FreezeTransformations;
makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;

parent -w locator_2;


select -r locator_2 locator_1;
SnapPointToPoint;

$locator_2_pos =`xform -q -ws -translation locator_2`;
xform -ws -translation $locator_2_pos[0] $locator_2_pos[1] $locator_2_pos[2] L_upper_arm_ik_ctrl;


select -r L_upper_arm_ik_ctrl1 ;
select -add L_upper_arm_ik_ctrl ;
orientConstraint -offset 0 0 0 -weight 1;


select -r L_upper_arm_ik_ctrl_orientConstraint1;
doDelete;


select -r locator_1 locator_2 L_upper_arm_ik_ctrl1;
doDelete;

strarup
03-11-2008, 11:30 AM
Hi,

hmm... you could make it more generic if you select the objects needed for the script and then... use the selection list... to work with in your script... :)

otherwise you could make it work togeter with e.g. a textfile where you store the names of the controls for each char... in that way you only need one script... and then the textfile works as a kind of "database"...

I don't know was procedure you prefer... or you in the idea of you script had thought about the user to select the objects/controls... or you just want the user to click a button and wamm bamm boogiie man the thingie is done... :)

hope it helps a bit...

kind regards

Strarup

Geuse
03-11-2008, 11:54 AM
Thanks dude!
Yeah exactly. I want to be able to push a button in my character GUI and the script fires off all at once. Also added some keyframe commands to my script so it get's keyed before and after the switch. What would be preferrable. To jump back one frame with the switch or jump forward one frame?
also if it's not to much to ask for, how do you use the command "currentTime" to set a keyframe on the frame before or after. "currentTime + 1"?

Having problem with the GUI too. here's the link if you don't mind =)
http://forums.cgsociety.org/showthread.php?f=88&t=604862

strarup
03-11-2008, 12:10 PM
Hi Geuse,

will take a look at it later... at a pc and place without maya at the moment... :)

to use currentTime make a float thingie e.g. like this...
float $daCurrentTime = `currentTime -q`;

so the frame before would be ($daCurrentTime-1) and the one after... ($daCurrentTime-1)

can't remember the setKeyframe command at the moment...

kind regards

Strarup

Geuse
03-11-2008, 01:28 PM
Thank you so much!
Yes, no I'm trying to manage myself, but I can't seem to sort it out.

int $time = `currentTime -q`;

setKeyframe -time ($time-1 ) spine_offset_ctrl.r;

I think this looks correct, but it isn't =/

strarup
03-11-2008, 10:58 PM
oki doki... :)


your code is ok for the setKeyframe as far I can see..
my guess is that the r = rotate... which consist of the 3 rotations

I have tried 2 different versions and both worked...



proc setDaKeyBeforeCurrentFrame(string $daObj, string $daAttr)

{

int $daTime = `currentTime -q`;

setKeyframe -time ($daTime-1) ($daObj+"."+$daAttr);

}

setDaKeyBeforeCurrentFrame("spine_offset_ctrl","r");



and one dividing up into 3 attributes...


proc setDaKeyBeforeCurrentFrameArr(string $daObj, string[] $daAttr)
{
int $daTime = `currentTime -q`;
for($i=0; $i<size($daAttr;$i++)
{
setKeyframe -time ($daTime-1) ($daObj+"."+$daAttr[$i]);
}
}
setDaKeyBeforeCurrentFrame("spine_offset_ctrl", {"rx", "ry", "rz"});

e.g. make a string array with rotate and translate attributes...

string $daRotAttr[] = {"rx","ry","rz"};
string $daTraAttr[] = {"tx","ty","tz"};

and then calling the function using this command e.g. for the rotation attributes...

setDaKeyBeforeCurrentFrame("spine_offset_ctrl", $daRotAttr);


so why you can't get it to work I'm not sure...

kind regards

Strarup

Edit: just looked at your post again... I think it's because you don't have the -->"<--
arround your object and attribute... should be

setKeyframe -time ($time-1 ) "spine_offset_ctrl.r";

Geuse
03-12-2008, 03:05 AM
I can't thank you enough, you are too kind!

Will try this. I will however wait with the more advanced way of writing this as you've described 'til I get more comfortable with mel and maybe create a real script out of it that'll work by loading the different target and constrained object in a gui.

Once again, thank you!!

strarup
03-12-2008, 04:14 PM
hehe... you're welcome... just glad I could help with a bit... :)

might in the near future make some melscript tutorials... and also some mel tips&tricks...
e.g. maybe that can help a bit aswell... ;)

kind regards

Strarup

CGTalk Moderation
03-12-2008, 04:14 PM
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.