splitUVFtyAction.cpp
#include "splitUVFty.h"
#include <maya/MGlobal.h>
#include <maya/MIOStream.h>
#include <maya/MFnMesh.h>
#include <maya/MFnSingleIndexedComponent.h>
#include <maya/MItMeshPolygon.h>
MStatus splitUVFty::doIt()
{
MStatus status = MS::kSuccess;
MString selUVSet;
MIntArray selUVFaceIdMap;
MIntArray selUVFaceOffsetMap;
MIntArray selUVLocalVertIdMap;
MFnMesh meshFn( fMesh );
meshFn.getCurrentUVSetName( selUVSet );
int i;
int j;
int offset = 0;
int selUVsCount = fSelUVs.length();
MItMeshPolygon polyIter( fMesh );
for( i = 0; i < selUVsCount; i++ )
{
selUVFaceOffsetMap.append(offset);
for( polyIter.reset(); !polyIter.isDone(); polyIter.next() )
{
if( polyIter.hasUVs() )
{
int polyVertCount = polyIter.polygonVertexCount();
for( j = 0; j < polyVertCount; j++ )
{
int UVIndex = 0;
polyIter.getUVIndex(j, UVIndex);
if( UVIndex == fSelUVs[i] )
{
selUVFaceIdMap.append( polyIter.index() );
selUVLocalVertIdMap.append(j);
offset++;
break;
}
}
}
}
}
selUVFaceOffsetMap.append(offset);
int currentUVCount = meshFn.numUVs( selUVSet );
for( i = 0; i < selUVsCount; i++ )
{
offset = selUVFaceOffsetMap[i];
float u;
float v;
int uvId = fSelUVs[i];
meshFn.getUV( uvId, u, v, &selUVSet );
int faceCount = selUVFaceOffsetMap[i + 1] - selUVFaceOffsetMap[i];
for( j = 0; j < faceCount - 1; j++ )
{
meshFn.setUV( currentUVCount, u, v, &selUVSet );
int localVertId = selUVLocalVertIdMap[offset];
int faceId = selUVFaceIdMap[offset];
meshFn.assignUV( faceId, localVertId, currentUVCount, &selUVSet );
currentUVCount++;
offset++;
}
}
return status;
}