#include "cleanPerFaceAssignmentCmd.h"
#include <maya/MGlobal.h>
#include <maya/MDagPath.h>
#include <maya/MPlug.h>
#include <maya/MObjectArray.h>
#include <maya/MIntArray.h>
#include <maya/MStringArray.h>
#include <maya/MSelectionList.h>
#include <maya/MItSelectionList.h>
#include <maya/MFnDependencyNode.h>
#include <maya/MFnMesh.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MFnSet.h>
#ifdef MAYA_PRINT_DEBUG_INFO
#include <maya/MIOStream.h>
#endif
{
#ifdef MAYA_PRINT_DEBUG_INFO
for (
unsigned int i = 0; i < sets.
length() ; i++ ){
cout << "-------------->" << endl;
cout << setFn.
name() << endl;
cout <<
"FaceCount:" << faceIt.
count() << endl;
cout << faceIt.
index() <<
" ";
}
cout << endl;
cout << "<--------------" << endl;
}
#endif //MAYA_PRINT_DEBUG_INFO
sameConnectionFlag.
clear();
for (
unsigned int i = 0; i < sets.
length() ; i++ ){
sameConnectionFlag.
append( -1 );
bool optimizeList = true;
if (optimizeList)
{
int lastIndices[2] = { -1, -1 };
int currentIndex = -1;
bool haveAFace = false;
{
if (lastIndices[0] == -1)
{
lastIndices[0] = tempFaceIt.
index();
lastIndices[1] = tempFaceIt.
index();
}
else
{
currentIndex = tempFaceIt.
index();
if (currentIndex > lastIndices[1] + 1)
{
aMemberFaceName += (pathName + ".f[" + lastIndices[0] + ":" + lastIndices[1] + "] ");
lastIndices[0] = currentIndex;
lastIndices[1] = currentIndex;
}
else
lastIndices[1] = currentIndex;
}
haveAFace = true;
}
if (haveAFace)
{
aMemberFaceName += (pathName + ".f[" + lastIndices[0] + ":" + lastIndices[1] + "] ");
}
}
else
{
for ( ;!tempFaceIt.
isDone() ; tempFaceIt.
next() ){
}
}
memberFaceNames.
append( aMemberFaceName );
}
for (
unsigned int i = 0; i < sets.
length() ; i++ ){
if ( sameConnectionFlag[i] == -1 ){
for (
unsigned int j = 0; j < sets.
length() ; j++ ){
if ( i != j && sameConnectionFlag[j] == -1 ) {
if ( setFn.
name() == tempSetFn.
name() ){
sameConnectionFlag[j] = i;
sameSGFaceCount[i] += sameSGFaceCount[j];
sameSGFaceCount[j] = 0;
memberFaceNames[i] += memberFaceNames[j];
memberFaceNames[j] = "";
}
}
}
sameConnectionFlag[i] = i;
}
}
unsigned int tail = 0;
while( tail < sameConnectionFlag.
length() ){
if ( sameSGFaceCount[tail] == 0 ){
memberFaceNames.
remove( tail );
sameConnectionFlag.
remove( tail );
sameSGFaceCount.
remove( tail );
} else {
tail++;
}
}
for (
unsigned int i = 0; i < sameSGFaceCount.
length() ; i++ ){
}
bool needToSort = true;
while ( needToSort ){
unsigned int sortCount = 0;
if ( sameSGFaceCount.
length() > 1 ){
for(
unsigned int i = 0; i < ( sameSGFaceCount.
length() -1 ) ; i++ ){
if ( sameSGFaceCount[sortMapper[i]] < sameSGFaceCount[sortMapper[i+1]] ){
int tmp = sortMapper[i];
sortMapper[i] = sortMapper[i+1];
sortMapper[i+1] = tmp;
sortCount++;
} else {
}
}
}else {
break;
}
if ( sortCount > 0 ){
needToSort = true;
} else {
needToSort = false;
}
}
for (
unsigned int i = 0; i < sortMapper.
length(); i++ ){
sortedSGNames.
append( SGNames[sortMapper[i]] );
sortedSGFaceCount.
append( sameSGFaceCount[sortMapper[i]] );
sortedMemberFaceNames.
append( memberFaceNames[sortMapper[i]]);
}
#ifdef MAYA_PRINT_DEBUG_INFO
for (
unsigned int i = 0; i < sortedSGFaceCount.
length() ; i++ ){
cout << sortedSGNames[i] << " " << sortedSGFaceCount[i] << endl;
cout << sortedMemberFaceNames[i] << endl;
}
for (
unsigned int i = 0; i < sortMapper.
length() ; i++ ){
cout << i << " -- " << sortMapper[i] << endl;
}
#endif //MAYA_PRINT_DEBUG_INFO
bool executeImmediate = true;
for (
unsigned int i = 0; i < sortedSGFaceCount.
length() ; i++ ){
if ( i == 0 ){
} else {
resultString = ("select -r " + sortedMemberFaceNames[i] + ";");
}
if (executeImmediate )
if (executeImmediate)
{
resultString = ("sets -e -forceElement " + sortedSGNames[i] + ";");
}
else
resultString += ("sets -e -forceElement " + sortedSGNames[i] + ";");
if (!executeImmediate)
appendToResult( resultString );
}
}
}
return stat;
}
void* cleanPerFaceAssignment::creator()
{
return new cleanPerFaceAssignment();
}
cleanPerFaceAssignment::cleanPerFaceAssignment()
{}
cleanPerFaceAssignment::~cleanPerFaceAssignment()
{
}