Rigging

Rigging101 » Rigging125

Unfrezing/unreseting translation values question (7 posts)

About This Topic

Tags

No tags yet.

  1. lubitel
    Member
    Posted 8 months ago
    #

    Hi

    I have a city with buildings (rectangles) placed around the scene that have their translation values zeroed out when they are where they shold be.

    I need a script that queries their relative offset from the worldOrigin and sets it as their translation value. (unreset/unfreze) So that if a cube is placed at WS [1,1,1] its translation value is [1,1,1] and not [0,0,0].

    xform shold be able to query the position and than i shold be able to setAttr if i made a loop right?

    Will some of you MEL Wizards help with this?

    heres a snapshot of the city:)

    http://www.facebook.com/photo.php?pid=3947939&l=54314cf20a&id=574437196

    cheers

  2. thnkr
    Member
    Posted 8 months ago
    #

    that's not very difficult:

    // center pivot
    xform -cp;
    // get translate from new pivot
    float $pivot[] = getAttr ".rotatePivot";
    //move to origin
    move -r (-1* $pivot[0]) (-1 * $pivot[1]) (-1 * $pivot[2]);
    // freeze transforms
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0;
    //reset transforms
    makeIdentity -apply false -t 1 -r 1 -s 1;
    //move object back to newly found pivot;
    move -r $pivot[0] $pivot[1] $pivot[2];

  3. lubitel
    Member
    Posted 8 months ago
    #

    Thank you for replying.

    I select all the objects i want to reReset pivot for and run the script...and

    for some reason i am getting error:

    // Error: float $pivot[] = getAttr ".rotatePivot"; //
    // Error: Invalid use of Maya object "getAttr". //

    I am using MAya2010 64bits....cout it be the reason?

    And if you want to have a look at the scene its here:

    http://www.opendrive.com/files/5946137_ch06F_6424/UnrealOsloDanny.ma

    Apriciate it.

  4. thnkr
    Member
    Posted 8 months ago
    #

    What I wrote works on a single object. If you want too use it on all models, put it in a for loop like this and select all models

    $sel = ls -sl;
    for ($tmp in $sel) {
    // center pivot
    xform -cp $tmp;
    // get translate from new pivot
    float $pivot[] = getAttr ($tmp + ".rotatePivot");
    //move to origin
    move -r (-1* $pivot[0]) (-1 * $pivot[1]) (-1 * $pivot[2]) $tmp ;
    // freeze transforms
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $tmp;
    //reset transforms
    makeIdentity -apply false -t 1 -r 1 -s 1 $tmp;
    //move object back to newly found pivot;
    move -r $pivot[0] $pivot[1] $pivot[2] $tmp;
    }

  5. lubitel
    Member
    Posted 8 months ago
    #

    strange, it now says:

    "$tmp" is an undeclared variable. //

    and I tried the previous script with a single object but it still gave me the same error:

    // Error: float $pivot[] = getAttr ".rotatePivot"; //
    // Error: Invalid use of Maya object "getAttr". //

  6. lubitel
    Member
    Posted 8 months ago
    #

    gotit:)

    it was the
    ls -sl

    :)

    thanx aLOT

  7. lubitel
    Member
    Posted 8 months ago
    #

    Ooooops ....It turns out that I also need to reReset the rotation values :)

    ----Help-----Thanx---

    :)

    Heres the script that worked for translation

    $sel = ls -sl;
    for ($tmp in $sel) {
    // center pivot
    xform -cp $tmp;
    // get translate from new pivot
    float $pivot[] = getAttr ($tmp + ".rotatePivot");
    //move to origin
    move -r (-1* $pivot[0]) (-1 * $pivot[1]) (-1 * $pivot[2]) $tmp ;
    // freeze transforms
    makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 $tmp;
    //reset transforms
    makeIdentity -apply false -t 1 -r 1 -s 1 $tmp;
    //move object back to newly found pivot;
    move -r $pivot[0] $pivot[1] $pivot[2] $tmp;
    }

Reply

You must log in to post.

Rigging101 » Rigging125