+ Add query unset face ids (colorSet)

This commit is contained in:
indigo 2023-09-24 21:17:35 +08:00
parent 394da05c5f
commit 6399e88618
3 changed files with 104 additions and 21 deletions

View File

@ -37,16 +37,22 @@ if not defined VisualStudioVersion (
set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio !compiler_ver!\VC\vcvarsall.bat" x86_amd64 set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio !compiler_ver!\VC\vcvarsall.bat" x86_amd64
) )
if %maya_ver% GEQ 2020 ( if %maya_ver% EQU 2020 (
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" ( if exist "%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" (
set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64 set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio 2017\WDExpress\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
set compiler_ver=15.0 set compiler_ver=15.0
) )
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" ( if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" (
set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat"
set compiler_ver=15.0
)
)
if %maya_ver% GEQ 2022 (
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" (
set compiler_bat="%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
set compiler_ver=16.0
) )
) )
set VisualStudioVersion=!compiler_ver! set VisualStudioVersion=!compiler_ver!
if not exist !compiler_bat! ( if not exist !compiler_bat! (
@ -66,6 +72,7 @@ IF %VisualStudioVersion% == 11.0 set vc_config=Visual Studio 11 2012 Win64
IF %VisualStudioVersion% == 12.0 set vc_config=Visual Studio 12 2013 Win64 IF %VisualStudioVersion% == 12.0 set vc_config=Visual Studio 12 2013 Win64
IF %VisualStudioVersion% == 14.0 set vc_config=Visual Studio 14 2015 Win64 IF %VisualStudioVersion% == 14.0 set vc_config=Visual Studio 14 2015 Win64
IF %VisualStudioVersion% == 15.0 set vc_config=Visual Studio 15 2017 Win64 IF %VisualStudioVersion% == 15.0 set vc_config=Visual Studio 15 2017 Win64
IF %VisualStudioVersion% == 16.0 set vc_config=Visual Studio 16 2019
set install_dir=%current%\install set install_dir=%current%\install

View File

@ -41,6 +41,7 @@ MSyntax MeshInfoCmd::newSyntex()
syntax.addFlag(kVtxHashFlag, kVtxHashFlagLong, MSyntax::kNoArg); syntax.addFlag(kVtxHashFlag, kVtxHashFlagLong, MSyntax::kNoArg);
syntax.addFlag(kUvHashFlag, kUvHashFlagLong, MSyntax::kNoArg); syntax.addFlag(kUvHashFlag, kUvHashFlagLong, MSyntax::kNoArg);
syntax.addFlag(kPtHashFlag, kPtHashFlagLong, MSyntax::kNoArg); syntax.addFlag(kPtHashFlag, kPtHashFlagLong, MSyntax::kNoArg);
syntax.addFlag(kUnsetFlag, kUnsetFlagLong, MSyntax::kNoArg);
syntax.addFlag(kExtendToShapeFlag, kExtendToShapeFlagLong, MSyntax::kNoArg); syntax.addFlag(kExtendToShapeFlag, kExtendToShapeFlagLong, MSyntax::kNoArg);
syntax.addFlag(kNoIntermediaFlag, kNoIntermediaFlagLong, MSyntax::kNoArg); syntax.addFlag(kNoIntermediaFlag, kNoIntermediaFlagLong, MSyntax::kNoArg);
syntax.addFlag(kFileFlag, kFileFlagLong, MSyntax::kString); syntax.addFlag(kFileFlag, kFileFlagLong, MSyntax::kString);
@ -106,6 +107,46 @@ MString MeshInfoCmd::getPtHash(MFnMesh & fnMesh)
MString pt_hash = getHash(ptArray); MString pt_hash = getHash(ptArray);
return pt_hash; return pt_hash;
} }
MIntArray MeshInfoCmd::getUnsetIds(MFnMesh& fnMesh)
{
MStatus status;
MStringArray familyNames;
std::vector<int> UnsetIds;
status = fnMesh.getColorSetFamilyNames(familyNames);
if (!familyNames.length())
{
return MIntArray();
}
MIntArray vtxCounts, vtxList;
fnMesh.getVertices(vtxCounts, vtxList);
for (unsigned int i = 0; i < familyNames.length(); i++)
{
MColorArray colors;
fnMesh.getFaceVertexColors(colors, &familyNames[i]);
if (!colors.length())
continue;
for (unsigned int fid=0; fid < fnMesh.numPolygons(); fid++)
{
int vtx_count = vtxCounts[fid];
for (int vid = 0; vid < vtx_count; vid++)
{
int fv_index;
fnMesh.getFaceVertexColorIndex(fid, vid, fv_index, &familyNames[i]);
if (colors[fv_index].r < 0 && colors[fv_index].g < 0 && colors[fv_index].b < 0 && colors[fv_index].a < 0)
{
if (std::find(UnsetIds.begin(), UnsetIds.end(), fid) == UnsetIds.end())
{
UnsetIds.push_back(fid);
}
}
}
}
}
MIntArray result(&UnsetIds[0], UnsetIds.size());
return result;
}
MStatus MeshInfoCmd::extendToShape(MSelectionList & list) MStatus MeshInfoCmd::extendToShape(MSelectionList & list)
{ {
@ -129,7 +170,6 @@ MStatus MeshInfoCmd::extendToShape(MSelectionList & list)
itDag.reset(node); itDag.reset(node);
while (!itDag.isDone()) while (!itDag.isDone())
{ {
MObject currentItem = itDag.currentItem(); MObject currentItem = itDag.currentItem();
if (currentItem.hasFn(MFn::kMesh)) { if (currentItem.hasFn(MFn::kMesh)) {
MDagPath dagPath; MDagPath dagPath;
@ -167,6 +207,7 @@ MStatus MeshInfoCmd::doIt(const MArgList & args)
bool vtxHashGen = argData.isFlagSet(kVtxHashFlag); bool vtxHashGen = argData.isFlagSet(kVtxHashFlag);
bool uvHashGen = argData.isFlagSet(kUvHashFlag); bool uvHashGen = argData.isFlagSet(kUvHashFlag);
bool ptHashGen = argData.isFlagSet(kPtHashFlag); bool ptHashGen = argData.isFlagSet(kPtHashFlag);
bool unsetIdGen = argData.isFlagSet(kUnsetFlag);
bool ets = argData.isFlagSet(kExtendToShapeFlag); bool ets = argData.isFlagSet(kExtendToShapeFlag);
bool noIntermdia = argData.isFlagSet(kNoIntermediaFlag); bool noIntermdia = argData.isFlagSet(kNoIntermediaFlag);
bool fileGen = argData.isFlagSet(kFileFlag); bool fileGen = argData.isFlagSet(kFileFlag);
@ -190,6 +231,19 @@ MStatus MeshInfoCmd::doIt(const MArgList & args)
MDagPath meshPath; MDagPath meshPath;
list.getDagPath(0, meshPath); list.getDagPath(0, meshPath);
MFnMesh fnMesh(meshPath); MFnMesh fnMesh(meshPath);
if (unsetIdGen) {
setResult(getUnsetIds(fnMesh));
return MS::kSuccess;
}
else {
int argCount = int(vtxHashGen) + int(uvHashGen) + int(ptHashGen);
if (argCount > 1)
{
MGlobal::displayError("Could not mix multiple hash arguments in query mode");
return MS::kInvalidParameter;
}
if (vtxHashGen) { if (vtxHashGen) {
setResult(getVtxHash(fnMesh)); setResult(getVtxHash(fnMesh));
return MS::kSuccess; return MS::kSuccess;
@ -203,6 +257,9 @@ MStatus MeshInfoCmd::doIt(const MArgList & args)
return MS::kSuccess; return MS::kSuccess;
} }
} }
MGlobal::displayError("Empty query arguments in query mode");
return MS::kInvalidParameter;
}
if (ets) { if (ets) {
extendToShape(list); extendToShape(list);
@ -210,7 +267,23 @@ MStatus MeshInfoCmd::doIt(const MArgList & args)
unsigned nObj = list.length(); unsigned nObj = list.length();
std::vector<std::string> header = { "name", "vertices_hash", "uv_hash", "point_hash", "num_vertices", "num_polygons" }; std::vector<std::string> header = { "name" };
//{"vertices_hash", "uv_hash", "point_hash", "num_vertices", "num_polygons"}
if (vtxHashGen)
header.push_back("vertices_hash");
if (uvHashGen)
header.push_back("uv_hash");
if (ptHashGen)
header.push_back("point_hash");
if (unsetIdGen)
header.push_back("unset_ids");
header.push_back("num_vertices");
header.push_back("num_polygons");
auto meshInfo = json::array(); auto meshInfo = json::array();
meshInfo.push_back(header); meshInfo.push_back(header);
@ -235,27 +308,26 @@ MStatus MeshInfoCmd::doIt(const MArgList & args)
} }
MString vtxHash, uvHash, ptHash; MString vtxHash, uvHash, ptHash;
std::vector<std::string> hashData = { fnMesh.name().asChar() };
if (vtxHashGen || fileGen) { if (vtxHashGen || fileGen) {
vtxHash = getVtxHash(fnMesh); vtxHash = getVtxHash(fnMesh);
hashData.push_back(vtxHash.asChar());
} }
if (uvHashGen || fileGen) { if (uvHashGen || fileGen) {
uvHash = getUvHash(fnMesh); uvHash = getUvHash(fnMesh);
hashData.push_back(uvHash.asChar());
} }
if (ptHashGen || fileGen) { if (ptHashGen || fileGen) {
ptHash = getPtHash(fnMesh); ptHash = getPtHash(fnMesh);
hashData.push_back(ptHash.asChar());
} }
if (fileGen) if (fileGen)
{ {
std::vector<std::string> hashData = { hashData.push_back(std::to_string(fnMesh.numVertices()));
fnMesh.name().asChar(), hashData.push_back(std::to_string(fnMesh.numPolygons()));
vtxHash.asChar(), uvHash.asChar(), ptHash.asChar(),
std::to_string(fnMesh.numVertices()),
std::to_string(fnMesh.numPolygons())
};
meshInfo.push_back(hashData); meshInfo.push_back(hashData);
} }
} }

View File

@ -1,6 +1,7 @@
#include <maya/MPxCommand.h> #include <maya/MPxCommand.h>
#include <maya/MSyntax.h> #include <maya/MSyntax.h>
#include <maya/MArgList.h> #include <maya/MArgList.h>
#include <maya/MIntArray.h>
#define kCommandName "meshInfo" #define kCommandName "meshInfo"
@ -10,6 +11,8 @@
#define kUvHashFlagLong "-uvHash" #define kUvHashFlagLong "-uvHash"
#define kPtHashFlag "-pth" #define kPtHashFlag "-pth"
#define kPtHashFlagLong "-ptHash" #define kPtHashFlagLong "-ptHash"
#define kUnsetFlag "-ust"
#define kUnsetFlagLong "-unset"
#define kExtendToShapeFlag "-ets" #define kExtendToShapeFlag "-ets"
#define kExtendToShapeFlagLong "-extendToShape" #define kExtendToShapeFlagLong "-extendToShape"
#define kNoIntermediaFlag "-ni" #define kNoIntermediaFlag "-ni"
@ -33,5 +36,6 @@ public:
MString getVtxHash(MFnMesh& fnMesh); MString getVtxHash(MFnMesh& fnMesh);
MString getUvHash(MFnMesh& fnMesh); MString getUvHash(MFnMesh& fnMesh);
MString getPtHash(MFnMesh& fnMesh); MString getPtHash(MFnMesh& fnMesh);
MIntArray getUnsetIds(MFnMesh& fnMesh);
MStatus extendToShape(MSelectionList &list); MStatus extendToShape(MSelectionList &list);
}; };