1/****************************************************************************** 2 NintendoWare for CTR Maya Plugin 3 4 File: NW4C_SetRenderPriority.mel 5 Description: set render priority 6 Date: 2010/02/12 7 8 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 9******************************************************************************/ 10 11// UpdateWindow DoSearch 12// UpdateList SortList ListButtonCB ListDropCB SetListColor 13 14/****************************************************************************** 15 variables 16******************************************************************************/ 17global int $nw4cSetRenderPriority_SortKind = 0; // 0:priority, 1:name 18global int $nw4cSetRenderPriority_SortOrder = 0; // 0:ascend, 1:descend 19global int $nw4cSetRenderPriority_KeepOrder = 0; 20 21/****************************************************************************** 22 get selected SG 23 24 return SG size 25******************************************************************************/ 26proc int GetSelectedSG(string $sgs[]) 27{ 28 $sgs = `ls -sl -typ shadingEngine`; 29 if (size($sgs) == 0) 30 { 31 // get SG from selected material 32 string $mats[] = `ls -sl -mat`; 33 for ($mat in $mats) 34 { 35 if (!`attributeQuery -n $mat -ex "oc"`) 36 { 37 continue; 38 } 39 string $connectedSgs[] = 40 `listConnections -s 0 -d 1 -type shadingEngine ($mat + ".oc")`; 41 for ($sg in $connectedSgs) 42 { 43 if ($sg != "initialParticleSE" && 44 $sg != "swatchShadingGroup") 45 { 46 $sgs[size($sgs)] = $sg; 47 } 48 } 49 } 50 } 51 return size($sgs); 52} 53 54/****************************************************************************** 55 use render priority 56******************************************************************************/ 57global proc int nw4cSetRenderPriority_Get_UseRenderPriority(string $node) 58{ 59 return (`attributeQuery -n $node -ex "nw4cUseRenderPriority"`) ? 60 `getAttr ($node + ".nw4cUseRenderPriority")` : 0; 61} 62 63global proc nw4cSetRenderPriority_Add_UseRenderPriority(string $node) 64{ 65 if (!`attributeQuery -n $node -ex "nw4cUseRenderPriority"`) 66 { 67 addAttr -ln "nw4cUseRenderPriority" -at "bool" -dv 0 -h 1 $node; 68 } 69} 70 71global proc nw4cSetRenderPriority_Set_UseRenderPriority(string $node, int $val) 72{ 73 nw4cSetRenderPriority_Add_UseRenderPriority($node); 74 setAttr ($node + ".nw4cUseRenderPriority") $val; 75} 76 77proc SetJob_UseRenderPriority(string $node) 78{ 79 if (!`attributeQuery -n $node -ex "nw4cUseRenderPriority"`) 80 { 81 return; 82 } 83 scriptJob -p nw4cSetRenderPriority_UseRenderPriority -rp -ac ($node + ".nw4cUseRenderPriority") 84 ("if (`nw4cSetRenderPriority_Get_UseRenderPriority " + $node + 85 "`) radioButtonGrp -e -sl 1 nw4cSetRenderPriority_UseRenderPriority;" + 86 "else radioButtonGrp -e -sl 1 nw4cSetRenderPriority_DontCare;" + 87 "control -e -en `nw4cSetRenderPriority_Get_UseRenderPriority " + $node + "` nw4cSetRenderPriority_RenderPriority;"); 88} 89 90global proc nw4cSetRenderPriority_UseRenderPriorityCB(string $mainNode) 91{ 92 string $sgs[]; 93 GetSelectedSG($sgs); 94 95 int $val = `radioButtonGrp -q -sl nw4cSetRenderPriority_UseRenderPriority`; 96 control -e -en $val nw4cSetRenderPriority_RenderPriority; 97 98 for ($node in $sgs) 99 { 100 nw4cSetRenderPriority_Set_UseRenderPriority($node, $val); 101 } 102 103 SetJob_UseRenderPriority($mainNode); 104} 105 106/****************************************************************************** 107 render priority 108******************************************************************************/ 109global proc int nw4cSetRenderPriority_Get_RenderPriority(string $node) 110{ 111 return (`attributeQuery -n $node -ex "nw4cRenderPriority"`) ? 112 `getAttr ($node + ".nw4cRenderPriority")` : 1; 113} 114 115global proc nw4cSetRenderPriority_Add_RenderPriority(string $node) 116{ 117 if (!`attributeQuery -n $node -ex "nw4cRenderPriority"`) 118 { 119 addAttr -ln "nw4cRenderPriority" -at "short" -min 1 -max 255 -dv 1 -h 1 $node; 120 } 121} 122 123global proc nw4cSetRenderPriority_Set_RenderPriority(string $node, int $val) 124{ 125 nw4cSetRenderPriority_Add_RenderPriority($node); 126 setAttr ($node + ".nw4cRenderPriority") $val; 127} 128 129proc SetJob_RenderPriority(string $node) 130{ 131 if (!`attributeQuery -n $node -ex "nw4cRenderPriority"`) 132 { 133 return; 134 } 135 scriptJob -p nw4cSetRenderPriority_RenderPriority -rp -ac ($node + ".nw4cRenderPriority") 136 ("intField -e -v `nw4cSetRenderPriority_Get_RenderPriority " 137 + $node + "` nw4cSetRenderPriority_RenderPriority"); 138} 139 140global proc nw4cSetRenderPriority_RenderPriorityCB(string $mainNode) 141{ 142 string $sgs[]; 143 GetSelectedSG($sgs); 144 145 int $val = `intField -q -v nw4cSetRenderPriority_RenderPriority`; 146 if ($val < 1) 147 { 148 $val = 1; 149 intField -e -v $val nw4cSetRenderPriority_RenderPriority; 150 } 151 else if ($val > 255) 152 { 153 $val = 255; 154 intField -e -v $val nw4cSetRenderPriority_RenderPriority; 155 } 156 157 for ($node in $sgs) 158 { 159 nw4cSetRenderPriority_Set_RenderPriority($node, $val); 160 } 161 162 SetJob_RenderPriority($mainNode); 163} 164 165/****************************************************************************** 166 get priority for list 167******************************************************************************/ 168proc int GetPriorityForList(string $sg) 169{ 170 int $priority = 0; 171 if (objExists($sg)) 172 { 173 if (nw4cSetRenderPriority_Get_UseRenderPriority($sg)) 174 { 175 $priority = nw4cSetRenderPriority_Get_RenderPriority($sg); 176 } 177 } 178 return $priority; 179} 180 181/****************************************************************************** 182 set priority for list 183******************************************************************************/ 184proc SetPriorityForList(string $sg, int $val) 185{ 186 if (objExists($sg)) 187 { 188 nw4cSetRenderPriority_Set_UseRenderPriority($sg, ($val != 0)); 189 if ($val != 0) 190 { 191 nw4cSetRenderPriority_Set_RenderPriority($sg, $val); 192 } 193 } 194} 195 196/****************************************************************************** 197 find list field for button 198******************************************************************************/ 199proc string FindListFieldForButton(string $childs[], string $btn) 200{ 201 string $btnS = match("[^|]+$", $btn); 202 int $sgSize = size($childs) / 2; 203 int $isg; 204 for ($isg = 0; $isg < $sgSize; ++$isg) 205 { 206 string $child = $childs[$isg]; 207 if ($child == $btn || $child == $btnS) 208 { 209 return $childs[$sgSize + $isg]; 210 } 211 } 212 return ""; 213} 214 215/****************************************************************************** 216 get SG from list label 217******************************************************************************/ 218proc string GetSGFromListLabel(string $label) 219{ 220 string $mat = match("\\(.*\\)", $label); 221 $mat = substitute("^\\( ", $mat, ""); 222 $mat = substitute(" \\)$", $mat, ""); 223 //print("[" + $mat + "] " + $label + "\n"); 224 return $mat; 225} 226 227/****************************************************************************** 228 set list color 229******************************************************************************/ 230proc SetListColor() 231{ 232 //return; 233 string $childs[] = `layout -q -ca nw4cSetRenderPriority_SGList`; 234 int $sgSize = size($childs) / 2; 235 int $isg; 236 for ($isg = 0; $isg < $sgSize; ++$isg) 237 { 238 string $btn = $childs[$isg]; 239 string $label = `button -q -l $btn`; 240 //string $sg = match("[^ ]+", $label); // sgName ( matName ) 241 string $sg = GetSGFromListLabel($label); // matName ( sgName ) 242 int $selFlag = false; 243 if (size(`ls -sl $sg`)) 244 { 245 $selFlag = true; 246 } 247 else if (objExists($sg)) 248 { 249 string $ins[] = `listConnections -s 1 -d 0 ($sg + ".ss")`; 250 if (size($ins) && size(`ls -sl $ins[0]`)) 251 { 252 string $mat = $ins[0]; 253 if (`attributeQuery -n $mat -ex "oc"`) 254 { 255 string $ots[] = `listConnections -s 0 -d 1 ($mat + ".oc")`; 256 if (size($ots) && size(`ls -sl $ots`) == 0) 257 { 258 $selFlag = true; 259 } 260 } 261 } 262 } 263 if ($selFlag) 264 { 265 button -e -bgc 0.9 0.9 0.0 $btn; 266 } 267 else 268 { 269 button -e -bgc 1 1 1 $btn; 270 } 271 control -e -en false $btn; // for update bgc 272 control -e -en true $btn; 273 } 274} 275 276/****************************************************************************** 277 list button CB 278******************************************************************************/ 279global proc nw4cSetRenderPriority_ListButtonCB(string $btn, string $sg) 280{ 281 int $mod = `getModifiers`; 282 int $shift = ($mod == 1 || $mod == 5 || $mod == 9); 283 284 //----------------------------------------------------------------------------- 285 // select SG & material & polygon 286 if (!$shift) 287 { 288 select -cl; 289 } 290 if (objExists($sg)) 291 { 292 select -add -ne $sg; // shadingEngine 293 string $ins[] = `listConnections -s 1 -d 0 ($sg + ".ss")`; 294 if (size($ins)) 295 { 296 select -add $ins[0]; // material 297 } 298 select -add $sg; // shape object & face 299 300 // frame objects 301 if (`checkBox -q -v nw4cSetRenderPriority_FrameObjects`) 302 { 303 if (size(`sets -q $sg`)) 304 { 305 fitAllPanels -selected; 306 } 307 } 308 } 309 310 //----------------------------------------------------------------------------- 311 // set list color 312 SetListColor(); 313 314 //----------------------------------------------------------------------------- 315 // set focus 316 //setFocus $btn; 317 string $childs[] = `layout -q -ca nw4cSetRenderPriority_SGList`; 318 string $field = FindListFieldForButton($childs, $btn); 319 if (size($field)) 320 { 321 setFocus $field; 322 } 323} 324 325/****************************************************************************** 326 list priority CB 327******************************************************************************/ 328global proc nw4cSetRenderPriority_ListPriorityCB(string $sg, int $val) 329{ 330 global int $nw4cSetRenderPriority_SortKind; 331 global int $nw4cSetRenderPriority_KeepOrder; 332 333 SetPriorityForList($sg, $val); 334 335 // keep priority sort order 336 if ($nw4cSetRenderPriority_SortKind == 0) 337 { 338 $nw4cSetRenderPriority_KeepOrder = 1; 339 } 340} 341 342/****************************************************************************** 343 list drag CB 344******************************************************************************/ 345global proc string[] nw4cSetRenderPriority_ListDragCB( 346 string $dragControl, int $x, int $y, int $mods) 347{ 348 string $msgs[]; 349 //trace ("drag: " + match("[^|]+$", $dragControl) + ": " + $x + ", " + $y + ": " + $mods); 350 $msgs[0] = "dummy"; // set something to enable drop CB 351 return $msgs; 352} 353 354/****************************************************************************** 355 list drop CB 356******************************************************************************/ 357global proc nw4cSetRenderPriority_ListDropCB( 358 string $dragControl, string $dropControl, string $msgs[], 359 int $x, int $y, int $type) // type is always 2 ? 360{ 361 global int $nw4cSetRenderPriority_KeepOrder; 362 363 //----------------------------------------------------------------------------- 364 // check control 365 if ($dragControl == $dropControl) 366 { 367 return; 368 } 369 //trace ("drop: " + match("[^|]+$", $dragControl) + " -> " + match("[^|]+$", $dropControl) + ": " + $x + ", " + $y + ": " + $type + ": " + size($msgs)); 370 371 //----------------------------------------------------------------------------- 372 // swap priority 373 string $name0 = `button -q -l $dragControl`; 374 string $name1 = `button -q -l $dropControl`; 375 //string $sg0 = match("[^ ]+", $name0); // sgName ( matName ) 376 //string $sg1 = match("[^ ]+", $name1); // sgName ( matName ) 377 string $sg0 = GetSGFromListLabel($name0); // matName ( sgName ) 378 string $sg1 = GetSGFromListLabel($name1); // matName ( sgName ) 379 string $pri0 = GetPriorityForList($sg0); 380 string $pri1 = GetPriorityForList($sg1); 381 SetPriorityForList($sg0, $pri1); 382 SetPriorityForList($sg1, $pri0); 383 384 //----------------------------------------------------------------------------- 385 // swap button name & command 386 button -e -l $name1 387 -c ("nw4cSetRenderPriority_ListButtonCB " + $dragControl + " " + $sg1) 388 $dragControl; 389 button -e -l $name0 390 -c ("nw4cSetRenderPriority_ListButtonCB " + $dropControl + " " + $sg0) 391 $dropControl; 392 393 //----------------------------------------------------------------------------- 394 // swap field command 395 // [notice] can't query intField changeCommand 396 string $childs[] = `layout -q -ca nw4cSetRenderPriority_SGList`; 397 string $field0 = FindListFieldForButton($childs, $dragControl); 398 string $field1 = FindListFieldForButton($childs, $dropControl); 399 //trace ("drop: " + $sg0 + " -> " + $sg1 + " (" + $field0 + " -> " + $field1 + ")"); 400 if (size($field0) && size($field1)) 401 { 402 string $parentBak = `setParent -q`; 403 setParent nw4cSetRenderPriority_SGList; 404 intField -e -cc ("nw4cSetRenderPriority_ListPriorityCB " + $sg1 + " #1") 405 $field0; 406 intField -e -cc ("nw4cSetRenderPriority_ListPriorityCB " + $sg0 + " #1") 407 $field1; 408 setParent $parentBak; 409 } 410 411 //----------------------------------------------------------------------------- 412 // keep sort order 413 $nw4cSetRenderPriority_KeepOrder = 1; 414 415 //----------------------------------------------------------------------------- 416 // set list color 417 SetListColor(); 418} 419 420/****************************************************************************** 421 sort list 422******************************************************************************/ 423proc SortList(string $sgs[], string $mats[], int $pris[]) 424{ 425 global int $nw4cSetRenderPriority_SortKind; 426 global int $nw4cSetRenderPriority_SortOrder; 427 428 int $sgSize = size($sgs); 429 for ($isg = 0; $isg < $sgSize - 1; ++$isg) 430 { 431 for ($jsg = $isg + 1; $jsg < $sgSize; ++$jsg) 432 { 433 string $sg0 = $sgs[$isg]; 434 string $mat0 = $mats[$isg]; 435 int $pri0 = $pris[$isg]; 436 string $sg1 = $sgs[$jsg]; 437 string $mat1 = $mats[$jsg]; 438 int $pri1 = $pris[$jsg]; 439 int $cond = 0; 440 if ($nw4cSetRenderPriority_SortKind == 0) // priority 441 { 442 if ($pri0 == $pri1) 443 { 444 $cond = (strcmp($mat0, $mat1) > 0); 445 } 446 else if ($nw4cSetRenderPriority_SortOrder == 0) 447 { 448 $cond = ($pri0 > $pri1); 449 } 450 else 451 { 452 $cond = ($pri0 < $pri1); 453 } 454 } 455 else // name 456 { 457 if ($nw4cSetRenderPriority_SortOrder == 0) 458 { 459 $cond = (strcmp($mat0, $mat1) > 0); 460 } 461 else 462 { 463 $cond = (strcmp($mat0, $mat1) < 0); 464 } 465 } 466 if ($cond) 467 { 468 $sgs[$isg] = $sg1; 469 $mats[$isg] = $mat1; 470 $pris[$isg] = $pri1; 471 $sgs[$jsg] = $sg0; 472 $mats[$jsg] = $mat0; 473 $pris[$jsg] = $pri0; 474 } 475 } 476 } 477} 478 479/****************************************************************************** 480 update sort icon 481******************************************************************************/ 482proc UpdateSortIcon() 483{ 484 global int $nw4cSetRenderPriority_SortKind; 485 global int $nw4cSetRenderPriority_SortOrder; 486 487 string $img = ($nw4cSetRenderPriority_SortOrder) ? 488 "arrowDown.xpm" : "arrowUp.xpm"; 489 490 iconTextStaticLabel -e -vis ($nw4cSetRenderPriority_SortKind == 1) 491 -i1 $img 492 nw4cSetRenderPriority_NameSortIcon; 493 iconTextStaticLabel -e -vis ($nw4cSetRenderPriority_SortKind == 0) 494 -i1 $img 495 nw4cSetRenderPriority_PrioritySortIcon; 496} 497 498/****************************************************************************** 499 is SG size changed 500******************************************************************************/ 501proc int IsSGSizeChanged() 502{ 503 int $sgSize = 0; 504 string $allSgs[] = `ls -typ shadingEngine`; 505 for ($sg in $allSgs) 506 { 507 if ($sg == "initialParticleSE") 508 { 509 continue; 510 } 511 string $ins[] = `listConnections -s 1 -d 0 ($sg + ".ss")`; 512 if (!size($ins)) 513 { 514 continue; 515 } 516 ++$sgSize; 517 } 518 string $childs[] = `layout -q -ca nw4cSetRenderPriority_SGList`; 519 return ((size($childs) / 2) != $sgSize); 520} 521 522/****************************************************************************** 523 update list 524******************************************************************************/ 525proc UpdateList() 526{ 527 //trace "update list"; 528 529 //----------------------------------------------------------------------------- 530 // create list 531 string $sgs[], $mats[]; 532 int $pris[]; 533 int $isg = 0; 534 string $allSgs[] = `ls -typ shadingEngine`; 535 for ($sg in $allSgs) 536 { 537 if ($sg == "initialParticleSE") 538 { 539 continue; 540 } 541 string $ins[] = `listConnections -s 1 -d 0 ($sg + ".ss")`; 542 if (!size($ins)) 543 { 544 continue; 545 } 546 string $mat = $ins[0]; 547 $sgs[$isg] = $sg; 548 $mats[$isg] = $mat; 549 $pris[$isg] = GetPriorityForList($sg); 550 ++$isg; 551 } 552 553 //----------------------------------------------------------------------------- 554 // sort list 555 UpdateSortIcon(); 556 SortList($sgs, $mats, $pris); 557 558 //----------------------------------------------------------------------------- 559 // resize UI 560 int $sgSize = size($sgs); 561 string $parentBak = `setParent -q`; 562 setParent nw4cSetRenderPriority_SGList; 563 string $childs[] = `layout -q -ca nw4cSetRenderPriority_SGList`; 564 int $rowSize = size($childs) / 2; 565 if ($rowSize != $sgSize) 566 { 567 if (size($childs)) 568 { 569 deleteUI $childs; 570 } 571 for ($isg = 0; $isg < $sgSize; ++$isg) 572 { 573 button -w 220 -h 22 -al "left" -rs 0 -bgc 1 1 1; // -rs 0 fix width 574 } 575 for ($isg = 0; $isg < $sgSize; ++$isg) 576 { 577 intField -w 66 -h 22 -min 0 -max 255; 578 } 579 $childs = `layout -q -ca nw4cSetRenderPriority_SGList`; 580 string $lastBtn; 581 for ($isg = 0; $isg < $sgSize; ++$isg) 582 { 583 string $btn = $childs[$isg]; 584 string $field = $childs[$sgSize + $isg]; 585 if ($isg == 0) 586 { 587 formLayout -e 588 -af $btn "top" 4 589 -af $btn "left" 4 590 -an $btn "bottom" 591 -ap $btn "right" 0 79 592 -af $field "top" 4 593 -ac $field "left" 4 $btn 594 -an $field "bottom" 595 -an $field "right" 596 nw4cSetRenderPriority_SGList; 597 } 598 else 599 { 600 formLayout -e 601 -ac $btn "top" 2 $lastBtn 602 -af $btn "left" 4 603 -an $btn "bottom" 604 -ap $btn "right" 0 79 605 -ac $field "top" 2 $lastBtn 606 -ac $field "left" 4 $btn 607 -an $field "bottom" 608 -an $field "right" 609 nw4cSetRenderPriority_SGList; 610 } 611 $lastBtn = $btn; 612 } 613 formLayout -e -w 299 nw4cSetRenderPriority_SGList; 614 615 // update button visibility to display button (for -rs 0) 616 for ($isg = 0; $isg < $sgSize; ++$isg) 617 { 618 string $btn = $childs[$isg]; 619 control -e -vis false $btn; 620 control -e -vis true $btn; 621 } 622 } 623 624 //----------------------------------------------------------------------------- 625 // set UI 626 $isg = 0; 627 for ($sg in $sgs) 628 { 629 //trace ("ui: " + $isg + " " + $childs[$isg] + " " + $childs[$sgSize + $isg]); 630 string $btn = $childs[$isg]; 631 button -e -l ($mats[$isg] + " ( " + $sg + " ) ") 632 -c ("nw4cSetRenderPriority_ListButtonCB " + $btn + " " + $sg) 633 -dgc ("nw4cSetRenderPriority_ListDragCB") 634 -dpc ("nw4cSetRenderPriority_ListDropCB") 635 $btn; 636 intField -e -v $pris[$isg] 637 -cc ("nw4cSetRenderPriority_ListPriorityCB " + $sg + " #1") 638 $childs[$sgSize + $isg]; 639 ++$isg; 640 } 641 setParent $parentBak; 642 SetListColor(); 643} 644 645/****************************************************************************** 646 list priority sort CB 647******************************************************************************/ 648global proc nw4cSetRenderPriority_ListPrioritySortCB() 649{ 650 global int $nw4cSetRenderPriority_SortKind; 651 global int $nw4cSetRenderPriority_SortOrder; 652 global int $nw4cSetRenderPriority_KeepOrder; 653 654 if ($nw4cSetRenderPriority_KeepOrder) 655 { 656 $nw4cSetRenderPriority_KeepOrder = 0; 657 } 658 else if ($nw4cSetRenderPriority_SortKind == 0) 659 { 660 $nw4cSetRenderPriority_SortOrder = !$nw4cSetRenderPriority_SortOrder; 661 } 662 else 663 { 664 $nw4cSetRenderPriority_SortOrder = 0; 665 } 666 $nw4cSetRenderPriority_SortKind = 0; 667 668 UpdateList(); 669} 670 671/****************************************************************************** 672 list name sort CB 673******************************************************************************/ 674global proc nw4cSetRenderPriority_ListNameSortCB() 675{ 676 global int $nw4cSetRenderPriority_SortKind; 677 global int $nw4cSetRenderPriority_SortOrder; 678 global int $nw4cSetRenderPriority_KeepOrder; 679 680 if ($nw4cSetRenderPriority_KeepOrder) 681 { 682 $nw4cSetRenderPriority_KeepOrder = 0; 683 } 684 else if ($nw4cSetRenderPriority_SortKind == 1) 685 { 686 $nw4cSetRenderPriority_SortOrder = !$nw4cSetRenderPriority_SortOrder; 687 } 688 else 689 { 690 $nw4cSetRenderPriority_SortOrder = 0; 691 } 692 $nw4cSetRenderPriority_SortKind = 1; 693 694 UpdateList(); 695} 696 697/****************************************************************************** 698 get SG name with material 699******************************************************************************/ 700proc string GetSGNameWithMat(string $sg) 701{ 702 string $name = "( " + $sg + " )"; 703 string $ins[] = `listConnections -s 1 -d 0 ($sg + ".ss")`; 704 if (size($ins)) 705 { 706 $name = $ins[0] + " " + $name; 707 } 708 return $name; 709} 710 711/****************************************************************************** 712 update window 713******************************************************************************/ 714global proc nw4cSetRenderPriority_UpdateWindow() 715{ 716 //----------------------------------------------------------------------------- 717 // get selection 718 string $sgs[]; 719 int $enableFlag = (GetSelectedSG($sgs) > 0); 720 721 //----------------------------------------------------------------------------- 722 // set node name 723 string $nodesName; 724 if ($enableFlag) 725 { 726 $nodesName = GetSGNameWithMat($sgs[0]); 727 int $nodeSize = size($sgs); 728 for ($inode = 1; $inode < $nodeSize; ++$inode) 729 { 730 if ($inode == 3) 731 { 732 $nodesName += ", ... (" + $nodeSize + ")"; 733 break; 734 } 735 $nodesName += ", " + GetSGNameWithMat($sgs[$inode]); 736 } 737 } 738 else 739 { 740 $nodesName = "(None)"; 741 } 742 text -e -l $nodesName nw4cSetRenderPriority_NodeName; 743 744 //----------------------------------------------------------------------------- 745 // set current attr & change command 746 int $useRenderPriority = 0; 747 if ($enableFlag) 748 { 749 string $node = $sgs[0]; 750 751 $useRenderPriority = 752 `nw4cSetRenderPriority_Get_UseRenderPriority $node`; 753 radioButtonGrp -e -sl (!$useRenderPriority) 754 -on1 ("nw4cSetRenderPriority_UseRenderPriorityCB " + $node) 755 nw4cSetRenderPriority_DontCare; 756 radioButtonGrp -e -sl $useRenderPriority 757 -on1 ("nw4cSetRenderPriority_UseRenderPriorityCB " + $node) 758 nw4cSetRenderPriority_UseRenderPriority; 759 760 intField -e -v `nw4cSetRenderPriority_Get_RenderPriority $node` 761 -cc ("nw4cSetRenderPriority_RenderPriorityCB " + $node) 762 nw4cSetRenderPriority_RenderPriority; 763 764 // setAttr �ȂǂŕύX���ꂽ�ꍇ�ɁA 765 // �R���g���[���̒l���X�V���邽�� 766 SetJob_UseRenderPriority($node); 767 SetJob_RenderPriority($node); 768 } 769 770 //----------------------------------------------------------------------------- 771 // set enable state 772 control -e -en $enableFlag nw4cSetRenderPriority_DontCare; 773 control -e -en $enableFlag nw4cSetRenderPriority_UseRenderPriority; 774 control -e -en ($enableFlag && $useRenderPriority) nw4cSetRenderPriority_RenderPriority; 775 control -e -en $enableFlag nw4cSetRenderPriority_Description; 776 777 //----------------------------------------------------------------------------- 778 // update list 779 if (`tabLayout -q -sti nw4cSetRenderPriority_Mode` == 2) 780 { 781 if (IsSGSizeChanged()) 782 { 783 //trace "SG size changed"; 784 UpdateList(); 785 } 786 else 787 { 788 SetListColor(); 789 } 790 } 791} 792 793/****************************************************************************** 794 search mode callback 795******************************************************************************/ 796global proc nw4cSetRenderPriority_SearchModeCB() 797{ 798 int $dontCare = 799 (`radioButtonGrp -q -sl nw4cSetRenderPriority_SearchDontCare` == 1); 800 int $useRenderPriority = 801 (`radioButtonGrp -q -sl nw4cSetRenderPriority_SearchUseRenderPriority` == 1); 802 803 control -e -en $useRenderPriority nw4cSetRenderPriority_SearchCompare; 804 control -e -en $useRenderPriority nw4cSetRenderPriority_SearchRenderPriority; 805 control -e -en ($dontCare || $useRenderPriority) nw4cSetRenderPriority_SearchBtn; 806} 807 808/****************************************************************************** 809 search value callback 810******************************************************************************/ 811global proc nw4cSetRenderPriority_SearchValueCB() 812{ 813 int $val = `intField -q -v nw4cSetRenderPriority_SearchRenderPriority`; 814 if ($val < 1) 815 { 816 intField -e -v 1 nw4cSetRenderPriority_SearchRenderPriority; 817 } 818 else if ($val > 255) 819 { 820 intField -e -v 255 nw4cSetRenderPriority_SearchRenderPriority; 821 } 822} 823 824/****************************************************************************** 825 do search 826******************************************************************************/ 827global proc nw4cSetRenderPriority_DoSearch() 828{ 829 int $searchUse = 830 (`radioButtonGrp -q -sl nw4cSetRenderPriority_SearchUseRenderPriority` == 1); 831 int $compare = `optionMenu -q -sl nw4cSetRenderPriority_SearchCompare` - 1; 832 nw4cSetRenderPriority_SearchValueCB(); // clamp value 833 int $searchVal = `intField -q -v nw4cSetRenderPriority_SearchRenderPriority`; 834 835 int $nodeCount = 0; 836 select -cl; 837 string $sgs[] = `ls -typ shadingEngine`; 838 for ($node in $sgs) 839 { 840 if ($node == "initialParticleSE" || $node == "swatchShadingGroup") 841 { 842 continue; 843 } 844 int $useRenderPriority = nw4cSetRenderPriority_Get_UseRenderPriority($node); 845 int $renderPriority = nw4cSetRenderPriority_Get_RenderPriority($node); 846 int $match = 0; 847 if (!$searchUse) 848 { 849 $match = !$useRenderPriority; 850 } 851 else 852 { 853 if (!$useRenderPriority) 854 { 855 $match = 0; 856 } 857 else if ($compare == 0) 858 { 859 $match = ($renderPriority < $searchVal); 860 } 861 else if ($compare == 1) 862 { 863 $match = ($renderPriority <= $searchVal); 864 } 865 else if ($compare == 2) 866 { 867 $match = ($renderPriority == $searchVal); 868 } 869 else if ($compare == 3) 870 { 871 $match = ($renderPriority >= $searchVal); 872 } 873 else 874 { 875 $match = ($renderPriority > $searchVal); 876 } 877 } 878 if ($match) 879 { 880 select -add -ne $node; // shadingEngine 881 string $ins[] = `listConnections -s 1 -d 0 ($node + ".ss")`; 882 if (size($ins)) 883 { 884 select -add $ins[0]; // material 885 } 886 select -add $node; // shape object & face 887 ++$nodeCount; 888 } 889 } 890 891 if ($nodeCount == 0) 892 { 893 print "Not found\n"; 894 } 895 else 896 { 897 string $msg = "Found: " + $nodeCount + " shadingEngine node"; 898 if ($nodeCount >= 2) 899 { 900 $msg += "s"; 901 } 902 print ($msg + "\n"); 903 } 904} 905 906/****************************************************************************** 907 tab change CB 908******************************************************************************/ 909global proc nw4cSetRenderPriority_TabChangeCB() 910{ 911 if (`tabLayout -q -sti nw4cSetRenderPriority_Mode` == 2) 912 { 913 UpdateList(); 914 } 915 else 916 { 917 if (`control -q -en nw4cSetRenderPriority_RenderPriority`) 918 { 919 setFocus nw4cSetRenderPriority_RenderPriority; 920 } 921 } 922} 923 924/****************************************************************************** 925 undo CB 926******************************************************************************/ 927global proc nw4cSetRenderPriority_UndoCB() 928{ 929 if (`tabLayout -q -sti nw4cSetRenderPriority_Mode` == 2) 930 { 931 UpdateList(); 932 } 933} 934 935/****************************************************************************** 936 main 937******************************************************************************/ 938global proc NW4C_SetRenderPriority() 939{ 940 global int $nw4cSetRenderPriority_SortKind; 941 global int $nw4cSetRenderPriority_SortOrder; 942 global int $nw4cSetRenderPriority_KeepOrder; 943 944 int $afterMaya2011Adjust = 0; 945 if (getApplicationVersionAsFloat() >= 2011) 946 $afterMaya2011Adjust = 1; 947 948 //----------------------------------------------------------------------------- 949 // create window 950 int $wd = 400; 951 int $ht = 380; 952 if (!`window -ex nw4cSetRenderPriority_Win`) 953 { 954 window -t "NW4C Set Render Priority" -wh $wd $ht -mxb 0 -mb 1 955 nw4cSetRenderPriority_Win; 956 menu -l "Help"; 957 menuItem -l ("Help on " + `window -q -t nw4cSetRenderPriority_Win` + "...") 958 -c "NW4C_ShowHelp \"html/NW4C_SetRenderPriority.html\" \"\""; 959 960 string $form1 = `formLayout -nd 100`; 961 962 //----------------------------------------------------------------------------- 963 // tab 964 tabLayout -imh 0 965 -cc "nw4cSetRenderPriority_TabChangeCB" // reload at change 966 nw4cSetRenderPriority_Mode; 967 968 //----------------------------------------------------------------------------- 969 // set & search 970 //----------------------------------------------------------------------------- 971 columnLayout -adj 1 -cat "both" 4 -rs 4 972 nw4cSetRenderPriority_SetLayout; 973 974 //----------------------------------------------------------------------------- 975 // node name 976 frameLayout -l "Selected Material ( Shading Group )" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; 977 columnLayout -adj 1 -cal "center" -rs 8; 978 979 text -l "" nw4cSetRenderPriority_NodeName; 980 981 setParent ..; // columnLayout 982 setParent ..; // formLayout 983 984 //----------------------------------------------------------------------------- 985 // set 986 frameLayout -l "Set" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; 987 string $form2 = `formLayout -nd 400`; 988 radioButtonGrp -l "Render Priority" -nrb 1 -cw2 110 80 989 -l1 "Don't care" 990 nw4cSetRenderPriority_DontCare; 991 992 radioButtonGrp -l "" -nrb 1 -cw2 110 18 993 -l1 "" 994 -scl nw4cSetRenderPriority_DontCare 995 nw4cSetRenderPriority_UseRenderPriority; 996 997 intField -w 50 -v 1 998 nw4cSetRenderPriority_RenderPriority; 999 1000 text -l "1 (High Priority) - 255 (Low Priority)" 1001 nw4cSetRenderPriority_Description; 1002 setParent ..; // formLayout 1003 formLayout -e 1004 -af nw4cSetRenderPriority_DontCare "top" 8 1005 -af nw4cSetRenderPriority_DontCare "left" 0 1006 -an nw4cSetRenderPriority_DontCare "bottom" 1007 -an nw4cSetRenderPriority_DontCare "right" 1008 1009 -ac nw4cSetRenderPriority_UseRenderPriority "top" 8 nw4cSetRenderPriority_DontCare 1010 -af nw4cSetRenderPriority_UseRenderPriority "left" 0 1011 -an nw4cSetRenderPriority_UseRenderPriority "bottom" 1012 -an nw4cSetRenderPriority_UseRenderPriority "right" 1013 1014 -ac nw4cSetRenderPriority_RenderPriority "top" 4 nw4cSetRenderPriority_DontCare 1015 -ac nw4cSetRenderPriority_RenderPriority "left" 0 nw4cSetRenderPriority_UseRenderPriority 1016 -an nw4cSetRenderPriority_RenderPriority "bottom" 1017 -an nw4cSetRenderPriority_RenderPriority "right" 1018 1019 -ac nw4cSetRenderPriority_Description "top" 4 nw4cSetRenderPriority_RenderPriority 1020 -ac nw4cSetRenderPriority_Description "left" 4 nw4cSetRenderPriority_UseRenderPriority 1021 -af nw4cSetRenderPriority_Description "bottom" 8 1022 -an nw4cSetRenderPriority_Description "right" 1023 $form2; 1024 setParent ..; // frameLayout 1025 1026 //----------------------------------------------------------------------------- 1027 // search 1028 frameLayout -l "Search" -cll 0 -cl 0 -bv 1 -bs "etchedIn"; 1029 columnLayout -adj 1 -cal "center" -rs 0; 1030 string $form3 = `formLayout -nd 400`; 1031 radioButtonGrp -l "" -nrb 1 -cw2 110 80 1032 -l1 "Don't care" 1033 -on1 "nw4cSetRenderPriority_SearchModeCB" 1034 nw4cSetRenderPriority_SearchDontCare; 1035 1036 radioButtonGrp -l "" -nrb 1 -cw2 110 18 1037 -l1 "" 1038 -scl nw4cSetRenderPriority_SearchDontCare 1039 -on1 "nw4cSetRenderPriority_SearchModeCB" 1040 nw4cSetRenderPriority_SearchUseRenderPriority; 1041 1042 optionMenu -w 110 1043 nw4cSetRenderPriority_SearchCompare; 1044 menuItem -l "< : ( under )"; 1045 menuItem -l "<= : ( below )"; 1046 menuItem -l "= : ( exactly )"; 1047 menuItem -l ">= : ( above )"; 1048 menuItem -l "> : ( over )"; 1049 1050 intField -w 50 -h 26 -v 1 1051 -cc "nw4cSetRenderPriority_SearchValueCB" 1052 nw4cSetRenderPriority_SearchRenderPriority; 1053 setParent ..; // formLayout 1054 formLayout -e 1055 -af nw4cSetRenderPriority_SearchDontCare "top" 8 1056 -af nw4cSetRenderPriority_SearchDontCare "left" 0 1057 -an nw4cSetRenderPriority_SearchDontCare "bottom" 1058 -an nw4cSetRenderPriority_SearchDontCare "right" 1059 1060 -ac nw4cSetRenderPriority_SearchUseRenderPriority "top" 10 nw4cSetRenderPriority_SearchDontCare 1061 -af nw4cSetRenderPriority_SearchUseRenderPriority "left" 0 1062 -an nw4cSetRenderPriority_SearchUseRenderPriority "bottom" 1063 -an nw4cSetRenderPriority_SearchUseRenderPriority "right" 1064 1065 -ac nw4cSetRenderPriority_SearchCompare "top" (4 + $afterMaya2011Adjust * 3) nw4cSetRenderPriority_SearchDontCare 1066 -ac nw4cSetRenderPriority_SearchCompare "left" 0 nw4cSetRenderPriority_SearchUseRenderPriority 1067 -an nw4cSetRenderPriority_SearchCompare "bottom" 1068 -an nw4cSetRenderPriority_SearchCompare "right" 1069 1070 -ac nw4cSetRenderPriority_SearchRenderPriority "top" 4 nw4cSetRenderPriority_SearchDontCare 1071 -ac nw4cSetRenderPriority_SearchRenderPriority "left" 4 nw4cSetRenderPriority_SearchCompare 1072 -af nw4cSetRenderPriority_SearchRenderPriority "bottom" 8 1073 -an nw4cSetRenderPriority_SearchRenderPriority "right" 1074 $form3; 1075 rowColumnLayout -nc 2 -cw 1 200 -cw 2 150; 1076 text -l ""; // dummy 1077 button -l "Search" 1078 -c "nw4cSetRenderPriority_DoSearch" 1079 nw4cSetRenderPriority_SearchBtn; 1080 setParent ..; // rowColumnLayout 1081 separator -h 8 -st "none"; 1082 1083 setParent ..; // columnLayout 1084 setParent ..; // formLayout 1085 optionMenu -e -sl 3 nw4cSetRenderPriority_SearchCompare; 1086 1087 setParent ..; // columnLayout 1088 1089 //----------------------------------------------------------------------------- 1090 // list 1091 //----------------------------------------------------------------------------- 1092 formLayout -nd 100 nw4cSetRenderPriority_ListLayout; 1093 1094 //----------------------------------------------------------------------------- 1095 string $labelRow = `rowColumnLayout -nc 4 1096 -cw 1 240 -cw 2 16 -cw 3 49 -cw 4 16 1097 -cs 1 7 -cs 3 5`; 1098 //iconTextButton -h 24 -l "Shading Group ( Material )" 1099 // -st "iconAndTextHorizontal" -i1 "arrowUp.xpm" 1100 // -c "nw4cSetRenderPriority_ListNameSortCB"; 1101 button -l "Material ( Shading Group )" -al "left" 1102 -c "nw4cSetRenderPriority_ListNameSortCB"; 1103 iconTextStaticLabel -h 24 -st "iconOnly" -i1 "arrowUp.xpm" -vis 0 1104 nw4cSetRenderPriority_NameSortIcon; 1105 button -l "Priority" -al "left" 1106 -c "nw4cSetRenderPriority_ListPrioritySortCB"; 1107 iconTextStaticLabel -h 24 -st "iconOnly" -i1 "arrowDown.xpm" -vis 0 1108 nw4cSetRenderPriority_PrioritySortIcon; 1109 setParent ..; // rowColumnLayout; 1110 1111 string $scroll = `scrollLayout -hst 0`; 1112 formLayout -nd 100 nw4cSetRenderPriority_SGList; 1113 setParent ..; // formLayout; 1114 setParent ..; // scrollLayout 1115 1116 checkBox -l "Frame Objects" -v 0 1117 nw4cSetRenderPriority_FrameObjects; 1118 1119 formLayout -e 1120 -af $labelRow "top" 4 1121 -af $labelRow "left" 4 1122 -an $labelRow "bottom" 1123 -af $labelRow "right" 4 1124 1125 -ac $scroll "top" 4 $labelRow 1126 -af $scroll "left" 4 1127 -ac $scroll "bottom" 4 nw4cSetRenderPriority_FrameObjects 1128 -af $scroll "right" 4 1129 1130 -an nw4cSetRenderPriority_FrameObjects "top" 1131 -af nw4cSetRenderPriority_FrameObjects "left" 10 1132 -af nw4cSetRenderPriority_FrameObjects "bottom" 4 1133 -af nw4cSetRenderPriority_FrameObjects "right" 4 1134 1135 nw4cSetRenderPriority_ListLayout; 1136 setParent ..; // formLayout 1137 1138 setParent ..; // tabLayout 1139 tabLayout -e -tl nw4cSetRenderPriority_SetLayout "Set and Search" 1140 nw4cSetRenderPriority_Mode; 1141 tabLayout -e -tl nw4cSetRenderPriority_ListLayout "List" 1142 nw4cSetRenderPriority_Mode; 1143 //tabLayout -e -st nw4cSetRenderPriority_ListLayout 1144 // nw4cSetRenderPriority_Mode; // select List default 1145 1146 //----------------------------------------------------------------------------- 1147 // close button 1148 string $closeCmd = "deleteUI nw4cSetRenderPriority_Win"; 1149 string $closeBtn = `button -h 26 -l "Close" -c $closeCmd`; 1150 1151 formLayout -e 1152 -af nw4cSetRenderPriority_Mode "top" 4 1153 -af nw4cSetRenderPriority_Mode "left" 4 1154 -ac nw4cSetRenderPriority_Mode "bottom" 4 $closeBtn 1155 -af nw4cSetRenderPriority_Mode "right" 4 1156 1157 -an $closeBtn "top" 1158 -af $closeBtn "left" 4 1159 -af $closeBtn "bottom" 4 1160 -af $closeBtn "right" 4 1161 $form1; 1162 setParent ..; // formLayout 1163 1164 setFocus $closeBtn; 1165 1166 //----------------------------------------------------------------------------- 1167 // set selection change job 1168 scriptJob -p nw4cSetRenderPriority_Win 1169 -e "SelectionChanged" "nw4cSetRenderPriority_UpdateWindow"; 1170 1171 //----------------------------------------------------------------------------- 1172 // set undo / redo job 1173 scriptJob -p nw4cSetRenderPriority_Win 1174 -e "Undo" "nw4cSetRenderPriority_UndoCB"; 1175 scriptJob -p nw4cSetRenderPriority_Win 1176 -e "Redo" "nw4cSetRenderPriority_UndoCB"; 1177 1178 //----------------------------------------------------------------------------- 1179 // set name change job 1180 scriptJob -p nw4cSetRenderPriority_Win 1181 -e "NameChanged" "nw4cSetRenderPriority_UndoCB"; 1182 1183 //----------------------------------------------------------------------------- 1184 // init sort state 1185 $nw4cSetRenderPriority_SortKind = 0; 1186 $nw4cSetRenderPriority_SortOrder = 0; 1187 $nw4cSetRenderPriority_KeepOrder = 0; 1188 } 1189 if (`window -q -w nw4cSetRenderPriority_Win` < $wd) 1190 { 1191 window -e -w $wd nw4cSetRenderPriority_Win; 1192 } 1193 if (`window -q -h nw4cSetRenderPriority_Win` < $ht) 1194 { 1195 window -e -h $ht nw4cSetRenderPriority_Win; 1196 } 1197 //window -e -wh $wd $ht nw4cSetRenderPriority_Win; 1198 1199 //----------------------------------------------------------------------------- 1200 // update window 1201 nw4cSetRenderPriority_UpdateWindow(); 1202 nw4cSetRenderPriority_SearchModeCB(); 1203 nw4cSetRenderPriority_TabChangeCB(); 1204 1205 //----------------------------------------------------------------------------- 1206 // show window 1207 showWindow nw4cSetRenderPriority_Win; 1208} 1209