Advertisement
Guest User

Untitled

a guest
Apr 12th, 2023
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. // Poly Separate
  2. // Copyright (C) 2012 Basenji Games
  3. // Licensed under the MIT license
  4.  
  5. proc string[] getSGsFromShape( string $shape )
  6. {
  7. if ( ! `objExists $shape` )
  8. error ($shape + " does not exist.");
  9.  
  10. string $shape_children[] = `listRelatives -f -children -shapes $shape`;
  11. string $dest[] = `listConnections -destination true -source false -plugs false -type "shadingEngine" $shape_children[0]`;
  12. if(!size( $dest ))
  13. error($shape + " has no shaders.");
  14.  
  15. string $curr_selection[] = `ls -sl -l`;
  16. select -r -ne $dest;
  17. string $shadingEngines[] = `ls -sl`;
  18. select -r $curr_selection;
  19.  
  20. return $shadingEngines;
  21. }
  22.  
  23.  
  24. proc sepMat(string $object)
  25. {
  26. string $temp[];
  27.  
  28. string $shadingGroups[] = getSGsFromShape($object);
  29. print("$shadingGroups:\n"); print($shadingGroups); print("\n");
  30.  
  31. string $ParentName = `group -empty -n ($object + "_split_per_shader")`;
  32.  
  33. for ($i = 0; $i < size($shadingGroups) ; $i++) {
  34. string $shader = $shadingGroups[$i];
  35.  
  36. // make a copy of mesh and rename with shader suffix
  37. $temp = `listConnections -d off -s on $shader`;
  38. $temp = `duplicate -n ($object + "_" + $shader) $object`;
  39. $temp = `parent $temp[0] $ParentName`;
  40. string $clone = $temp[0];
  41.  
  42. // delete all faces which have assigned shader other than $shader
  43. select $clone;
  44. ConvertSelectionToFaces;
  45. string $tempset = `sets`;
  46. $temp = `listConnections -d off -s on $shadingGroups[$i]`;
  47. string $tempgrps[] = `listConnections -type shadingEngine $temp[0]`;
  48. select `sets -int $tempset $tempgrps[0]`;
  49. InvertSelection;
  50. delete;
  51.  
  52. select -ne $tempset;
  53. delete;
  54. }
  55. }
  56.  
  57. global proc splitMeshByShaders()
  58. {
  59. string $selection[] = `ls -sl -l`;
  60. for($o in $selection)
  61. sepMat($o);
  62. }
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement