Autodesk / maya-usd

A common USD (Universal Scene Description) plugin for Autodesk Maya
761 stars 202 forks source link

[usdExport] "exportDisplayColor" results in black for materials with textures #1705

Open nxkb opened 3 years ago

nxkb commented 3 years ago

Describe the bug When exporting display colors for a shape with an assigned material that is using a texture (file node), the result is black rather than the default color of the file node.

Basically the export code in /lib/mayaUsd/utils/util.cpp::_getMayaShadersColor() will ask the color attribute for its color, but if it's connected it will just return black. I propose that it would be more reasonable to lookup the default color of that file node so that artists would have some way to set a color (say "light brown" for a "sand" texture).

Steps to reproduce Steps to reproduce the behavior:

  1. Create a cube and assign a new lambert material
  2. Connect a file node to the 'color' attribute and set file node default color to (1.0, 0.0, 0.0)
  3. select your cube and Export Selected to test.usd
  4. Witness /root/pCube1.displayColor == (0.0, 0.0, 0.0) in usdview.

Expected behavior pCube1.displayColor == (1.0, 0.0, 0.0)

Impact Since this is case, artists have no way to set the displayColor AND a preview shader texture (or just keep the maya shader they need for other workflows). They have to disconnect the texture, set the color, export, and then reconnect their texture to get the right behavior. We currently have a warning in place to notify artists, but it would be nice to be able to grab the more appropriate color and leave everything connected.

Workaround Assign a new (lambert) material with the default color in "color" OR disconnect the texture, set the color, export, and then reconnect the texture.

Specs:

Additional context Basically add the bold to the lookup for displayColor. shape --> material --> surfaceShader.color --> file1.defaultColor

I'd like to at least start the conversation to see if this approach is agreeable to others. We don't quite rely on displayColor enough yet to jump on solving this, but I'd be happy to circle back when I have time and try to solve it if no one's done it yet.

BigRoy commented 2 years ago

For anyone looking into implementing this. The export display color flags ends up using this UsdMayaUtil::GetLinearShaderColor logic to retrieve the display colors for a mesh in the meshWriter.cpp.

Thus it seems mostly related to re-implementing this logic that actually retrieves the Shader's color if a file node is connected to the input.

As such you'll likely need to only implement changes in the util.cpp file to make this work.