Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Poly Separate
- // Copyright (C) 2012 Basenji Games
- // Licensed under the MIT license
- proc string[] getSGsFromShape( string $shape )
- {
- if ( ! `objExists $shape` )
- error ($shape + " does not exist.");
- string $shape_children[] = `listRelatives -f -children -shapes $shape`;
- string $dest[] = `listConnections -destination true -source false -plugs false -type "shadingEngine" $shape_children[0]`;
- if(!size( $dest ))
- error($shape + " has no shaders.");
- string $curr_selection[] = `ls -sl -l`;
- select -r -ne $dest;
- string $shadingEngines[] = `ls -sl`;
- select -r $curr_selection;
- return $shadingEngines;
- }
- proc sepMat(string $object)
- {
- string $temp[];
- string $shadingGroups[] = getSGsFromShape($object);
- print("$shadingGroups:\n"); print($shadingGroups); print("\n");
- string $ParentName = `group -empty -n ($object + "_split_per_shader")`;
- for ($i = 0; $i < size($shadingGroups) ; $i++) {
- string $shader = $shadingGroups[$i];
- // make a copy of mesh and rename with shader suffix
- $temp = `listConnections -d off -s on $shader`;
- $temp = `duplicate -n ($object + "_" + $shader) $object`;
- $temp = `parent $temp[0] $ParentName`;
- string $clone = $temp[0];
- // delete all faces which have assigned shader other than $shader
- select $clone;
- ConvertSelectionToFaces;
- string $tempset = `sets`;
- $temp = `listConnections -d off -s on $shadingGroups[$i]`;
- string $tempgrps[] = `listConnections -type shadingEngine $temp[0]`;
- select `sets -int $tempset $tempgrps[0]`;
- InvertSelection;
- delete;
- select -ne $tempset;
- delete;
- }
- }
- global proc splitMeshByShaders()
- {
- string $selection[] = `ls -sl -l`;
- for($o in $selection)
- sepMat($o);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement