Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[usdMaya] add filterTypes option to avoid exporting certain node types #475

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions third_party/maya/lib/usdMaya/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ pxr_test_scripts(
testenv/testUsdExportCamera.py
testenv/testUsdExportColorSets.py
testenv/testUsdExportDisplayColor.py
testenv/testUsdExportFilterTypes.py
testenv/testUsdExportFrameOffset.py
testenv/testUsdExportInstances.py
testenv/testUsdExportLocator.py
Expand Down Expand Up @@ -305,6 +306,21 @@ pxr_register_test(testUsdExportDisplayColor
MAYA_APP_DIR=<PXR_TEST_DIR>/maya_profile
)

pxr_install_test_dir(
SRC testenv/UsdExportFilterTypesTest
DEST testUsdExportFilterTypes
)
pxr_register_test(testUsdExportFilterTypes
CUSTOM_PYTHON "${MAYA_BASE_DIR}/bin/mayapy"
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testUsdExportFilterTypes"
TESTENV testUsdExportFilterTypes
ENV
MAYA_PLUG_IN_PATH=${CMAKE_INSTALL_PREFIX}/third_party/maya/plugin
MAYA_SCRIPT_PATH=${CMAKE_INSTALL_PREFIX}/third_party/maya/share/usd/plugins/usdMaya/resources
MAYA_DISABLE_CIP=1
MAYA_APP_DIR=<PXR_TEST_DIR>/maya_profile
)

pxr_install_test_dir(
SRC testenv/UsdExportFrameOffsetTest
DEST testUsdExportFrameOffset
Expand Down
43 changes: 43 additions & 0 deletions third_party/maya/lib/usdMaya/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#include "pxr/usd/usdGeom/tokens.h"

#include <maya/MDagPath.h>
#include <maya/MGlobal.h>
#include <maya/MNodeClass.h>
#include <maya/MTypeId.h>

#include <ostream>
#include <string>
Expand Down Expand Up @@ -347,6 +350,10 @@ operator <<(std::ostream& out, const PxrUsdMayaJobExportArgs& exportArgs)
for (const MDagPath& dagPath : exportArgs.dagPaths) {
out << " " << dagPath.fullPathName().asChar() << std::endl;
}
out << "_filteredTypeIds (" << exportArgs.GetFilteredTypeIds().size() << ")" << std::endl;
for (unsigned int id : exportArgs.GetFilteredTypeIds()) {
out << " " << id << ": " << MNodeClass(MTypeId(id)).className() << std::endl;
}

out << "chaserNames (" << exportArgs.chaserNames.size() << ")" << std::endl;
for (const std::string& chaserName : exportArgs.chaserNames) {
Expand Down Expand Up @@ -436,6 +443,42 @@ const VtDictionary& PxrUsdMayaJobExportArgs::GetDefaultDictionary()
return d;
}

void PxrUsdMayaJobExportArgs::AddFilteredTypeName(const MString& typeName)
{
MNodeClass cls(typeName);
unsigned int id = cls.typeId().id();
if (id == 0) {
MGlobal::displayWarning(MString("Given excluded node type '") + typeName
+ "' does not exist; ignoring");
return;
}
_filteredTypeIds.insert(id);
// We also insert all inherited types - only way to query this is through mel,
// which is slower, but this should be ok, as these queries are only done
// "up front" when the export starts, not per-node
MString queryCommand("nodeType -isTypeName -derived ");
queryCommand += typeName;
MStringArray inheritedTypes;
MStatus status = MGlobal::executeCommand(queryCommand, inheritedTypes, false, false);
if (!status) {
MGlobal::displayWarning(MString("Error querying derived types for '") + typeName
+ "': " + status.errorString());
return;
}

for (unsigned int i=0; i < inheritedTypes.length(); ++i) {
if (inheritedTypes[i].length() == 0) continue;
id = MNodeClass(inheritedTypes[i]).typeId().id();
if (id == 0) {
// Unfortunately, the returned list will often include weird garbage, like
// "THconstraint" for "constraint", which cannot be converted to a MNodeClass,
// so just ignore these...
continue;
}
_filteredTypeIds.insert(id);
}
}

PxrUsdMayaJobImportArgs::PxrUsdMayaJobImportArgs(
const VtDictionary& userArgs,
const bool importWithProxyShapes,
Expand Down
24 changes: 24 additions & 0 deletions third_party/maya/lib/usdMaya/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@
#include "pxr/base/tf/token.h"
#include "pxr/usd/sdf/path.h"

#include <maya/MString.h>

#include <map>
#include <ostream>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -174,12 +177,33 @@ struct PxrUsdMayaJobExportArgs
PXRUSDMAYA_API
static const VtDictionary& GetDefaultDictionary();

/// Adds type name to filter out during export. This will also add all
/// inherited types (so if you exclude "constraint", it will also exclude
/// "parentConstraint")
PXRUSDMAYA_API
void AddFilteredTypeName(const MString& typeName);

const std::set<unsigned int>& GetFilteredTypeIds() const {
return _filteredTypeIds;
}

void ClearFilteredTypeIds() {
_filteredTypeIds.clear();
}

private:
PXRUSDMAYA_API
PxrUsdMayaJobExportArgs(
const VtDictionary& userArgs,
const PxrUsdMayaUtil::ShapeSet& dagPaths,
const GfInterval& timeInterval);

// Maya type ids to avoid exporting; these are
// EXACT types, though the only exposed way to modify this,
// AddFilteredTypeName, will also add all inherited types
// (so if you exclude "constraint", it will also exclude
// "parentConstraint")
std::set<unsigned int> _filteredTypeIds;
};

PXRUSDMAYA_API
Expand Down
Loading