Home > 未分類 > [ MEL ] curveをくっつける

[ MEL ] curveをくっつける

  • Posted by: tai
  • 2007/10/05 18:06
  • 未分類

複数のnurbsCurveを1つのtransformにまとめるMEL書いた。
attachとかではないので注意。
rigのcontroler作るときなんかに使えるかも。


以下ソースコード↓↓↓
———————————————————————-

global proc unionMultiCurveUI()
{
  string $window = “unionMultiCurveWindow”;
  string $title = “unionMultiCurve”;

  if( `window -q -ex $window` )
    deleteUI $window;

  window -t $title -w 310 -h 100 $window;
  {
    string $tfg1, $cbg1, $s1, $b1;
    string $form = `formLayout`;
    {
      $tfg1 = `textFieldGrp -l “Name ” -cat 1 “right” 0
          -cw2 80 220 -tx “” “tfg_uni”`;
      $cbg1 = `checkBoxGrp -l “Keep Original ” -cat 1 “right” 0
          -cw2 80 40 -v1 0 “cbg_ko”`;
      $s1 = `separator -h 4`;
      $b1 = `button -l “Execute” -h 30 -c “unionMultiCurveAddapt()”`;
    }
    formLayout -e
      -attachForm $tfg1 “top” 5
      -attachForm $tfg1 “left” 5
      -attachControl $cbg1 “top” 5 $tfg1
      -attachForm $cbg1 “left” 5
      -attachControl $s1 “bottom” 5 $b1
      -attachForm $s1 “left” 5
      -attachForm $s1 “right” 5
      -attachForm $b1 “left” 5
      -attachForm $b1 “right” 5
      -attachForm $b1 “bottom” 5
      $form;
  }
  showWindow $window;

}

global proc unionMultiCurveAddapt()
{
  string $name = `textFieldGrp -q -tx “tfg_uni”`;
  if( $name == “” )
    $name = “unionCurve”;
  int $keepOriginal = `checkBoxGrp -q -v1 “cbg_ko”`;

  string $sl[] = `ls -sl -type transform`;
  
  string $union = unionMultiCurve( $name, $sl, $keepOriginal );
  if( $union != “” )
    select -r $union;
}

global proc string unionMultiCurve( string $name, string $unionTgt[], int $keepOriginal )
{

  if( $unionTgt[0] == “” )
    error “No item given.”;

  string $union = `createNode transform -n $name`;
  string $curve;
  for( $curve in $unionTgt ){
    string $shapes[], $shape;
    $shapes = `listRelatives -pa -s -type nurbsCurve $curve`;

    float $t[], $r[], $s[];
    $t = `getAttr ( $curve+”.t” )`;
    $r = `getAttr ( $curve+”.r” )`;
    $s = `getAttr ( $curve+”.s” )`;
    for( $shape in $shapes ){
      string $unionSh = `createNode nurbsCurve -n ($union+”Shape”) -p $union`;
      connectAttr -f ( $shape+”.local” ) ( $unionSh+”.create” );
      delete -ch $union;  // delete history

      // match pos
      select -r ( $unionSh+”.cv[*]” );
      scale -r $s[0] $s[1] $s[2];
      rotate -r -os $r[0] $r[1] $r[2];
      move -r $t[0] $t[1] $t[2];
      select -cl;
    }
    clear $shapes;

    if( !$keepOriginal )
      delete $curve;
  }

  return $union;

}

———————————————————————-
selectしたtransformのshapeからnurbsCurve探してひとつにする。

unionMultiCurveUI
と実行するとUIが立ち上がる。あとはわかると思われます。

ノシ

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://blog.taikomatsu.com/2007/10/05/mel-curve%e3%82%92%e3%81%8f%e3%81%a3%e3%81%a4%e3%81%91%e3%82%8b/trackback/
Listed below are links to weblogs that reference
[ MEL ] curveをくっつける from memlog

Home > 未分類 > [ MEL ] curveをくっつける

Return to page top