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

EMSUSD-549 Fixes unneeded nodes getting exported on materials #3366

Merged
Merged
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
43 changes: 42 additions & 1 deletion lib/mayaUsd/fileio/shading/shadingModeUseRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,35 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter
// parameter, so we have to make a copy of rootPlug here.
MPlug rootPlugCopy(rootPlug);

MStatus status;
MStatus status;

// This is to perform an initial traversal to find the used nodes
// connected to the material to avoid generating unnecessary plugs.
MItDependencyGraph iterDepGraphNodeLevel(
rootPlugCopy,
MFn::kInvalid,
MItDependencyGraph::Direction::kUpstream,
MItDependencyGraph::Traversal::kDepthFirst,
MItDependencyGraph::Level::kNodeLevel,
&status);
if (status != MS::kSuccess) {
return UsdShadeShader();
}

MObjectArray allowedNodes;
for (; !iterDepGraphNodeLevel.isDone(); iterDepGraphNodeLevel.next()) {
MObject currentNode = iterDepGraphNodeLevel.currentItem(&status);
if (status != MS::kSuccess) {
continue;
}
const MFnDependencyNode currentDepNode(currentNode, &status);
if (status != MS::kSuccess) {
continue;
}

allowedNodes.append(currentNode);
}

MItDependencyGraph iterDepGraph(
rootPlugCopy,
MFn::kInvalid,
Expand Down Expand Up @@ -254,6 +282,19 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter
continue;
}

bool allowedNode = false;
for (unsigned int j = 0; j < allowedNodes.length(); ++j) {
if (dstPlug.node() == allowedNodes[j]) {
allowedNode = true;
break;
}
}
// Only generate shader writers if the plug belongs to an allowed node
// that is needed.
if (!allowedNode) {
continue;
}

auto dstShaderInfo = _GetExportedShaderForNode(
dstPlug.node(), materialExportPath, context, shaderWriterMap);
if (!dstShaderInfo) {
Expand Down