Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Maya MEL script that breaks up a mesh based on materials. Created by Andrew Coggeshall at Basenji Games.
// Poly Separate
// Copyright (C) 2012 Basenji Games
// Licensed under the MIT license
string $selection[] = `ls -sl`;
sepMat($selection[0]);
global proc sepMat(string $object){
string $shadingGroups[] = getSGsFromShape($object);
string $ParentName = ($object + "_lightMap_Group");
group -empty -n $ParentName;
for ($i = 0; $i < size($shadingGroups) ; $i = $i + 1)
{
string $theMaterial[] = `listConnections -d off -s on $shadingGroups[$i]`;
string $clone = ($object + "_" + $theMaterial[0]);
duplicate -n $clone $object;
parent $clone $ParentName;
string $material[] = `listConnections -d off -s on $shadingGroups[$i]`;
select $clone; ConvertSelectionToFaces;
string $tempset = `sets`;
string $tempgrps[] = `listConnections -type shadingEngine $material[0]`;
select `sets -int $tempset $tempgrps[0]`;
InvertSelection;
delete;
}
delete $object;
}
proc string[] getSGsFromShape( string $shape )
{
string $myShapeNode[] = `listRelatives -children -shapes $shape`;
string $shadingEngines[];
if ( `objExists $shape` )
{
string $dest[] = `listConnections -destination true -source false
-plugs false -type "shadingEngine" $myShapeNode[0]`;
if ( size( $dest ) )
{
string $select[] = `ls -sl`;
select -r -ne $dest;
$shadingEngines = `ls -sl`;
select -r $select;
}
}
return $shadingEngines;
}
@viliusddd

This comment has been minimized.

Copy link

@viliusddd viliusddd commented Jul 21, 2017

amazing!

@Dariusz1989

This comment has been minimized.

Copy link

@Dariusz1989 Dariusz1989 commented Mar 3, 2021

Epic, can we get python version? :- D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment