Skip to content

Commit

Permalink
Merge pull request #475 from elrond79/pr/filterTypes
Browse files Browse the repository at this point in the history
[usdMaya] add filterTypes option to avoid exporting certain node types

(Internal change: 1867883)
  • Loading branch information
pixar-oss committed Jun 25, 2018
2 parents 2b66a46 + 53c9dc8 commit 2a0c51f
Show file tree
Hide file tree
Showing 9 changed files with 587 additions and 0 deletions.
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) {
TF_WARN("Given excluded node type '%s' does not exist; ignoring",
typeName.asChar());
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) {
TF_WARN("Error querying derived types for '%s': %s",
typeName.asChar(), status.errorString().asChar());
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

0 comments on commit 2a0c51f

Please sign in to comment.