-
Notifications
You must be signed in to change notification settings - Fork 202
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
EMSUSD-549 Fixes unneeded nodes getting exported on materials #3366
Conversation
@@ -180,7 +185,7 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter | |||
rootPlugCopy, | |||
MFn::kInvalid, | |||
MItDependencyGraph::Direction::kUpstream, | |||
MItDependencyGraph::Traversal::kDepthFirst, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand in which way switching to kBreadthFirst helps here and what it solves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a suggestion by @JGamache-autodesk to improve traversing for complex networks with cascading connections. Without this the example materials in question still work. What fixes the issue is Line 263
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets have this scenario:
When traversing depth first the connections will be returned in this order:
file1.outColor -> standardSurface2.base_color <== Exports file1
file3.outColor -> file1.colorGain <== Exports file3
file3.outColor -> file2.colorGain <== Incorrect since file2 is not yet exported
Traversing breadth first will produce this order:
file1.outColor -> standardSurface2.base_color <== Exports file1
file2.outColor -> standardSurface2.specular_color <== Exports file2
file3.outColor -> file1.colorGain <== Exports file3
file3.outColor -> file2.colorGain <== Correct now since we have already exported file2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind, we should not make a move file3.outColor -> file2.colorGain because this traverses the graph in the opposite direction. Since file2 is connected to standardSurface2, it will be processed in its turn. So, preventing the backward move in the graph will solve the actual bug whether we use kDepthFirst or kBreadthFirst.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the order of the connections returned by a breadth first MItDependencyGraph:
As you can see we end up traversing "file3.outColor -> file2.colorGain" at step 5. Since we already processed "file2.outColor -> standardSurface.pecularColor" at step 2 then we are OK.
Still in full agreement that browsing all the destinations of a source port is bad. I think removing that part would indeed work perfectly fine since the traversal will eventually hit all connections.
@@ -255,7 +260,7 @@ class UseRegistryShadingModeExporter : public UsdMayaShadingModeExporter | |||
} | |||
|
|||
auto dstShaderInfo = _GetExportedShaderForNode( | |||
dstPlug.node(), materialExportPath, context, shaderWriterMap); | |||
dstPlug.node(), materialExportPath, context, shaderWriterMap, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, the problem here is that we take destination plugs that we shouldn't. And it seems to me that it is at line 231 (if (!iterPlug.destinations(dstPlugs, &status) || status != MS::kSuccess) {) that we do that. So maybe the good solution would be to remove this code from there.
It looks like this code there makes us move in the opposite direction, which I think is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would be a more correct fix. We need to process only the connections returned by MItDependencyGraph and should not be looking for the full list of destination plugs. I lacked time to implement this complete solution and resorted to the quickest fix that produced correct results. If you have time to rewrite the function then it would improve the codebase.
Make sure to add unit test for both the issue in EMSUSD-549 and the other one I put in a comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vlasovi @JGamache-autodesk Thanks for the feedback. I'll update the code and will add test cases to cover the above more scenarios.
I should mention even though this correctly exports as USD surface preview, it still doesn't have the support needed to make the ColorGain link survive. For this reason, the imported usd still does not fully reflect the exported ones.
Furthermore, if we switch to MaterialX when exporting, the original issue of EMSUSD-549 doesn't occur at all and the graph is exported and imported and the user's graph is preserved.
For that reason, the tests to compare export and import will automatically fail if added and we would have to skip that for the time being until we add support for fanned out nodes in USD Surface Preview scenarios, if at all possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a better solution to make sure we don't include unneeded destination plugs. Please see my comment in the code.
@vlasovi @JGamache-autodesk Removing the change at Line231 results in a correct export but causes multiple current tests to fail:
May I suggest that we check the changes in this PR in for the time being to unblock the crashing issue, and have another ticket made for a refactor of the algorithm that involves writing more tests as well as refactor the above tests. |
The proposed fix with kBreadthFirst traversal may not fix all such crashes depending on the shader graph layout, so I would still like to see another approach implemented. I don't expect the alternative approach to require changes to the existing autotests. The failures that you see must be due to a bug. |
That code is currently the best that can be done using MItDependencyGraph because it iterates on output plugs instead of connections. |
I agree. Traversing the plugs is the right way to go here. I don't think we should rewrite anything. We just need to filter out unnecessary connections, which should be a minor adjustment here. |
That filter would be skip any destination node not found in |
The filter with 'createIfMissing' flag would rely on the order of graph traversal and may fail even with kBreadthFirst traversal, depending on the graph layout. The final filter should be similar to your one but without this issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Nice work, @AramAzhari-adsk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1- Can you try using a UsdMayaUtil::MObjectHandleUnorderedSet instead of a MObjectArray? The performance will be way better!
2- Can you add unit tests for the two cases discussed where a file is connected multiple times?
I made a separate ticket (EMSUSD-692) to address the improvement as well as the unit cases multiple times. |
When exporting prims to USD that have Lambert materials , some extra nodes were being exported that would later cause a crash due to the mismatch between input nodes and uv sets. This fixes the issue by changing to depth first when traversing the node graph and only exporting nodes that are supposed to be part of the graph.