syflex:A plugin for syflex in maya


#1

Many a time, the Animation is too fast cause the results of syflex can’t be great.
So I try to write this script(in MAYA4.0).
It is can slow down the speed of the Animation, and after your simulation, it’s can baked cloth in your original time segment of the Animation automatic.

Question & advice are welcom.

enjoy it!


#2

/*
||
|| Script Name: lbScaleBake ;
|| Author: libo ;
|| Usage: … ;
|| ? July, 2004
||
*/

//Time Information;
global proc lbCount()
{
int $startTime_re;
int $endTime_re;

int $startTime_an;
int $endTime_an;

int $frameSum_re;
int $frameSum_an;

float $scaleTime;

int $frameSum_re1;
int $frameSum_re2;

int $startTime_wo;
int $endTime_wo;
int $startTime_wr;
int $endTime_wr;

int $frameSum_re3;

$startTime_re = `intFieldGrp -q -value1 intFieldGrpv1`;
$endTime_re = `intFieldGrp -q -value1 intFieldGrpv2`;

$startTime_an = `intFieldGrp -q -value1 intFieldGrpv3`;
$endTime_an = $endTime_re;

$frameSum_re = $endTime_re - $startTime_re + 1;
$frameSum_an = $endTime_an - $startTime_an + 1;

$scaleTime = `floatFieldGrp -q -value1 floatFieldGrpv7`;

$frameSum_re1 = $startTime_re - $startTime_an + 1;
$frameSum_re2 = $endTime_re - $startTime_an + 1;

$startTime_wo = $startTime_an;
$endTime_wo = ($frameSum_an - 1) * $scaleTime + $startTime_wo;
$startTime_wr = ($frameSum_re1 - 1) * $scaleTime + $startTime_wo;
$endTime_wr = ($frameSum_re2 - 1) * $scaleTime + $startTime_wo;

$frameSum_re3 = $endTime_wr - $startTime_wr + 1;

/*
print("
" +
“Time Information” + "
" +
"Rendering Start Frame: " + $startTime_re + "
" +
"Rendering End Frame: " + $endTime_re + "
" +
"Animation Start Frame: " + $startTime_an + "
" +
"Animation End Frame: " + $endTime_an + "
" +
"Rendering Frames Sum: " + $frameSum_re + "
" +
"Animation Frames Sum: " + $frameSum_an + "
" +
"if " + "
" +
"Scale time by: " + $scaleTime + "
" +
"Working Start Frame: " + $startTime_wo + "
" +
"then " + "
" +
"Rendering Start Frame " + $startTime_re + " --> " + $startTime_wr + "
" +
"Rendering End Frame " + $endTime_re + " --> " + $endTime_wr + "
" +
"Working End Frame " + $endTime_an + " --> " + $endTime_wo + "
" +
"Rendering Frames Sum " + $frameSum_re + " --> " + $frameSum_re3 + "
");
*/

string $lbUpdate4 = `intFieldGrp -e -value1 $endTime_an intFieldGrpv4`;
string $lbUpdate5 = `intFieldGrp -e -value1 $frameSum_re intFieldGrpv5`;
string $lbUpdate6 = `intFieldGrp -e -value1 $frameSum_an intFieldGrpv6`;
string $lbUpdate8 = `intFieldGrp -e -value1 $startTime_wo intFieldGrpv8`;
string $lbUpdate9 = `intFieldGrp -e -value1 $endTime_wo intFieldGrpv9`;
string $lbUpdate10 = `intFieldGrp -e -value1 $startTime_wr intFieldGrpv10`;
string $lbUpdate11 = `intFieldGrp -e -value1 $endTime_wr intFieldGrpv11`;
string $lbUpdate12 = `intFieldGrp -e -value1 $frameSum_re3 intFieldGrpv12`;

}
// lbCount();

// Scale animation for cloth simulation ;
global proc lbAnScale()
{
select -hi;

string $scaleTime_an = "scaleKey" + " " + "-ts" + " " + $scaleTime + " " + "-tp" + " " + $startTime_wo ;
// Result: scaleKey -ts 4 -tp -30 //
eval($scaleTime_an);

}
// lbAnScale();

// set playback to my working range ;
global proc lbSetPlayback()
{
$startTime_wo = $startTime_an;
$endTime_wo = ($frameSum_an - 1) * $scaleTime + $startTime_wo;

string $mySetPlayback = `playbackOptions -minTime $startTime_wo -maxTime $endTime_wo`;
//eval($mySetPlayback);

}
// lbSetPlayback();

// BlendShape;
global proc lbBlendShape()
{
// get the name of selected object ;
string $customSelect[] = ls -sl;
// print $customSelect[0] ;

int $i;
int $newNameNum = $startTime_re - 1 ; // 42;
string $newNamestr = $newNameNum ;
int $currentTimeNum = $startTime_wr - 4 ; // 258;
string $temp[] = {};

for ($i = 0; $i < $frameSum_re; $i++)
{
    // print($i +"

"); // 0:49/1;
$newNameNum += 1;
// print($newNameNum + "
"); // 43:92/1;
$currentTimeNum += 4;
// print($currentTimeNum + "
"); // 262:458/4;

    // copy target for blendshape ;
    currentTime $currentTimeNum ;

    // naming the copy target to ;
    string $BSName ;
    $BSName = $customSelect[0] + $currentTimeNum ;

    string $bsBase;
    $bsBase = $customSelect[0] + "Baked" ;
    // print $bsBase;
    $temp[$i] = $bsBase;
    // $temp[0];

    string $bsTarget;
    $bsTarget = $customSelect[0] + $newNameNum + "target" + "Baked" ;

    // the name of blendshape ;
    string $BS_Bake;
    $BS_Bake = "lbclothBS" ;

    // create blendshape ;
    // blendShape -name $blendShape $base;
    string $bs_c ;
    $bs_c = "blendShape" + " " + "-n" + " " + $BS_Bake + " " + $temp[0] ;

     // Add target ;
    // blendShape -edit -target $base $index $target 1.0 $blendShape;
    string $bs_a ;
    $bs_a = "blendShape" + " " + "-edit" + " " + "-target" + " " + $temp[0] + " " +
             $i + " " + $bsTarget + " " + "1.0" + " " + $BS_Bake ;

    if ($i == 0)
        {
          string $myCopy ;
          $myCopy = "duplicate" + " " + "-n" + " " + $BSName + " " + "-rr" + " " + $customSelect[0] + "

";
// print($myCopy + "
"); // duplicate -n $BSName -rr cloth;
eval($myCopy);

          rename $BSName $bsBase ;

          eval($bs_c);
        }
    else
        {
          string $myCopy ;
          $myCopy = "duplicate" + " " + "-n" + " " + $BSName + " " + "-rr" + " " + $customSelect[0] + "

";
// print($myCopy + "
"); // duplicate -n $BSName -rr cloth;
eval($myCopy);

          rename $BSName $bsTarget ;

          eval($bs_a);

          // delete the target after add blednshape ;
          delete $bsTarget;
        }
}

for ($i = ($startTime_re + 1); $i <= $endTime_re; $i++)
{
    string $BS_Bake;
    $BS_Bake = "lbclothBS" ;
    string $bsTarget;
    $bsTarget = $customSelect[0] + $i + "target" + "Baked" ;

    currentTime $i;

    // set keyframe for the blendshape ;
    string $setKey0 ;
    string $setKey1 ;
    string $setKey2 ;

    $setKey0 = ($i - 1);
    $setKey1 = $i;
    $setKey2 = ($i + 1);

    string $setKey0v = 0;
    string $setKey1v = 1;

    string $bst_setKey0 ;
    $bst_setKey0 = "setKeyframe" + " " + "-t" + " " + $setKey0 + " " + "-value" +
                        " " + $setKey0v + " " + $BS_Bake + "." + $bsTarget ;
    eval($bst_setKey0);

    string $bst_setKey1 ;
    $bst_setKey1 = "setKeyframe" + " " + "-t" + " " + $setKey1 + " " + "-value" +
                        " " + $setKey1v + " " + $BS_Bake + "." + $bsTarget ;
    eval($bst_setKey1);

    string $bst_setKey2 ;
    $bst_setKey2 = "setKeyframe" + " " + "-t" + " " + $setKey2 + " " + "-value" +
                        " " + $setKey0v + " " + $BS_Bake + "." + $bsTarget ;
    eval($bst_setKey2);
}

select -cl ;

// reName the original cloth, then hide it ;
string $newClothName = "Orginal_Cloth" + "_" + $customSelect[0] ;
rename $customSelect[0] $newClothName ;

string $hideOld ;
$hideOld = "hide" + $newClothName;
eval ($hideOld);

// set playback back to original rendering range ;
playbackOptions -minTime $startTime_re -maxTime $endTime_re;

// go back rendering start;
string $goback_start = "currentTime " + $startTime_re;
eval($goback_start);

}
// lbBlendShape();

// window lbScale;
global proc lbScaleBake()
{
string $myWindowName = “lbScaleBake”;
int $developing = true ;
if( $developing && window -exists $myWindowName)
deleteUI $myWindowName ;
if( !window -exists $myWindowName)
{
if( $developing );
string $myWindow = window -title "lbScaleBake" -iconName "lbScale" -w 450 -h 250 $myWindowName;
//scrollLayout scrollLayout;
columnLayout -adjustableColumn true;
frameLayout -collapsable true -label “Time Info” -labelAlign “center”
-borderStyle “etchedIn”;
columnLayout;
intFieldGrp -numberOfFields 1 -label “Rendering Start” -value1 43 -cc “lbCount” intFieldGrpv1;
intFieldGrp -numberOfFields 1 -label “Rendering End” -value1 100 -cc “lbCount” intFieldGrpv2;
intFieldGrp -numberOfFields 1 -label “Start An” -value1 -30 -cc “lbCount” intFieldGrpv3;
intFieldGrp -numberOfFields 1 -label “End An” -value1 $endTime_an -cc “lbCount” -en 0 intFieldGrpv4;
intFieldGrp -numberOfFields 1 -label “Rendering Sum” -value1 $frameSum_re -cc “lbCount” -en 0 intFieldGrpv5;
intFieldGrp -numberOfFields 1 -label “Animation Sum” -value1 $frameSum_an -cc “lbCount” -en 0 intFieldGrpv6;
text -label " If:" -font “boldLabelFont”;
floatFieldGrp -numberOfFields 1 -label “Scale Time” -value1 0.0 -cc “lbCount” floatFieldGrpv7;
intFieldGrp -numberOfFields 1 -label “Working Start” -value1 $startTime_wo -cc “lbCount” -en 0 intFieldGrpv8;
text -label " Then:" -font “boldLabelFont”;
intFieldGrp -numberOfFields 1 -label “Working End” -value1 $endTime_wo -cc “lbCount” -en 0 intFieldGrpv9;
intFieldGrp -numberOfFields 1 -label “Rendering Start” -value1 $startTime_wr -cc “lbCount” -en 0 intFieldGrpv10;
intFieldGrp -numberOfFields 1 -label “Rendering End” -value1 $endTime_wr -cc “lbCount” -en 0 intFieldGrpv11;
intFieldGrp -numberOfFields 1 -label “Rendering Sum” -value1 $frameSum_re3 -cc “lbCount” -en 0 intFieldGrpv12;
setParent …;
setParent …;
frameLayout -label “Scale Bake” -labelAlign “top”
-borderStyle “in”;
columnLayout;
button -label “Scale Animation” -c “lbAnScale();” -w 200 -al “center”;
button -label “Set playback” -c “lbSetPlayback();” -w 200 -al “center”;
button -label “Scale BlendShape/Set Key” -c “lbBlendShape();” -w 200 -al “center”;
setParent …;
setParent …;
frameLayout -label “Note:” -labelAlign “bottom”
-borderStyle “etchedOut”;
columnLayout;
text -label " The Rendering Start Frame" -w 200 -al “center” -font “boldLabelFont”;
text -label " can’t be negative!!!" -w 200 -al “center” -font “boldLabelFont”;
setParent …;
setParent …;
}
showWindow $myWindowName ;
}
//lbScaleBake();


#3

Hi implibo,

Your script idea sounds very useful! But it doesn’t work in Maya 6.
I’m no MEL wizard, so can you make this compatible with Maya 6?
I’d be eternally grateful!

Thanks,

Mike


#4

double post


#5

Here’s a script to convert Syflex solver into local space solving.

//mel!
//usage : feed the proc a root tranform, cloth mesh, string array of colliders, and a string array of forces
//example:
//string $forces[] ={“syGravity1Trs”,“syDamp1Trs”,“syAir1Trs”,“syNail1Trs”,“syWind1Trs”};
//string $cols[] ={“pSphere1Col”};
//syflexLocalSolveConvert rootTransform syCloth1ShapeTrf $cols $forces;

global proc syflexLocalSolveConvert(string $root,string $cloth, string $cols[], string $forces[]){

  string $loc[] = `spaceLocator -n "localSolve_loc"`;
  float $r_pos[] = `xform -q -ws -t $root`;
  string $pcon[] = `pointConstraint -offset ($r_pos[0]*-1) ($r_pos[1]*-1) ($r_pos[2]*-1) -weight 1 $root $loc[0]`;

  string $multMatrix = `createNode multMatrix`;

  int $c=0;
  for($item in $cols){
      connectAttr -f ($item+".worldMatrix[0]") ($multMatrix+".matrixIn["+$c+"]");
      $c++;
      }
  connectAttr -f ($loc[0]+".inverseMatrix") ($multMatrix+".matrixIn["+$c+"]");

  for($item in $forces){
      connectAttr -f ($multMatrix+".o") ($item+".mat_trf");
      }

  parent $cloth $loc[0];

}


#6

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.