#include "flipUVCmd.h"
#include <maya/MIOStream.h>
#include <maya/MSyntax.h>
#include <maya/MArgDatabase.h>
#include <maya/MIntArray.h>
#include <maya/MFloatArray.h>
#include <maya/MFnMesh.h>
static const char * horizFlag = "-h";
static const char * horizFlagLong = "-horizontal";
static const char * globalFlag = "-fg";
static const char * globalFlagLong = "-flipGlobal";
static const char * extendFlag = "-es";
static const char * extendFlagLong = "-extendToShell";
const char * flipUVCmd::cmdName = "flipUV";
flipUVCmd::flipUVCmd() :
horizontal(false),
extendToShell(false),
flipGlobal(false)
{}
flipUVCmd::~flipUVCmd() {}
void *flipUVCmd::creator() { return new flipUVCmd; }
{
return syntax;
}
{
}
}
}
return MS::kSuccess;
}
{
unsigned int i;
status = mesh.getUVs(uArray, vArray);
unsigned int nbUvShells = 1;
if ((!flipGlobal) || extendToShell)
{
status = mesh.getUvShellsIds(uvShellIds, nbUvShells);
}
if (extendToShell)
{
bool *selected = new bool[nbUvShells];
for (i = 0 ; i<nbUvShells ; i++)
selected[i] = false;
for (i = 0 ; i<uvList.
length() ; i++)
{
int indx = uvList[i];
selected[uvShellIds[indx]] = true;
}
unsigned int numUvs = mesh.numUVs();
unsigned int numSelUvs = 0;
for (i = 0 ; i<numUvs ; i++)
{
if (selected[uvShellIds[i]])
uvList[numSelUvs++] = i;
}
delete [] selected;
}
if (flipGlobal) nbUvShells = 1;
float *minMax = new float[nbUvShells*4];
for (i = 0 ; i<nbUvShells ; i++)
{
minMax[4*i+0] = 1e30F;
minMax[4*i+1] = 1e30F;
minMax[4*i+2] = -1e30F;
minMax[4*i+3] = -1e30F;
}
for (i = 0 ; i<uvList.
length() ; i++)
{
int indx = uvList[i];
int shellId = 0;
if (!flipGlobal) shellId = uvShellIds[indx];
if (uArray[indx] < minMax[4*shellId+0])
minMax[4*shellId+0] = uArray[indx];
if (vArray[indx] < minMax[4*shellId+1])
minMax[4*shellId+1] = vArray[indx];
if (uArray[indx] > minMax[4*shellId+2])
minMax[4*shellId+2] = uArray[indx];
if (vArray[indx] > minMax[4*shellId+3])
minMax[4*shellId+3] = vArray[indx];
}
for (i = 0 ; i<uvList.
length() ; i++)
{
int shellId = 0;
int indx = uvList[i];
if (!flipGlobal) shellId = uvShellIds[indx];
if (horizontal)
{
uPos[i] = minMax[4*shellId+0] + minMax[4*shellId+2] -
uArray[indx];
vPos[i] = vArray[indx];
}
else
{
uPos[i] = uArray[indx];
vPos[i] = minMax[4*shellId+1] + minMax[4*shellId+3] -
vArray[indx];
}
}
delete [] minMax;
return MS::kSuccess;
}