There was a following problem in Maya: to separate a mesh and to preserve the skin for export to fbx. Polygon separate operation conflicts with fbx export. On other side if we clear the history of the operation, the skin will be lost.

I wrote a little helper script to split the model into separate parts (Separate operation), and then to reassign skin cluster for each part and to copy the skin data from the original model.

MEL Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
proc string[] getShapes( string $xform )
{
string $shapes[];

$shapes[0] = $xform;

if ( "transform" == `nodeType $xform` )
// If given node is not a transform, assume it is a shape
// and pass it through
{
$shapes = `listRelatives -fullPath -shapes $xform`;
}

return $shapes;
}

global proc string WC_listSkinCluster(string $object)
{
if (!`objExists $object`) error "Object provided as argument dosen't exist - WC_listSkinCluster.mel";

string $objHist[] = `listHistory -pdo 1 $object`;
string $skinClusters[] = `ls -type "skinCluster" $objHist`;
if (`size $skinClusters` > 0)
return $skinClusters[0];
else
return 0;
}

proc copySkinData( string $src, string $dst )
{
string $srcSkin = WC_listSkinCluster($src);
string $dstSkin = WC_listSkinCluster($dst);

if ($srcSkin != 0 && $dstSkin != 0) {
copySkinWeights -ss $srcSkin -ds $dstSkin -noMirror -surfaceAssociation closestPoint -influenceAssociation oneToOne;
}
}

string $sel[];
$sel = `ls -sl`;
if (size($sel) > 0) {
//-- get list of skin joints
string $jointsList[] = `skinCluster -q -inf $sel[0]`;

//-- dublicate and separate mesh
string $newMesh[] = `duplicate -rr`;
string $shapes[] = getShapes($newMesh[0]);
if (size($shapes) > 0) {
string $sepMeshes[] = `polySeparate -ch 0 $shapes[0]`;
select -clear;
select -add $sepMeshes;
DeleteHistory;

//-- let's bind skin cluster for each mesh
select -clear;
select -add $jointsList;
select -add $sepMeshes;

newSkinCluster "-toSelectedBones -bindMethod 1 -normalizeWeights 1 -mi 4 -omi true -dr 4 -rui true,multipleBindPose,1";

//-- for each separated piece of mesh -> copy skin data from the original mesh
for ($mesh in $sepMeshes)
{

copySkinData( $sel[0], $mesh );
}
}
}
separate mesh with preserving skin cluster
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *