Autodesk / maya-usd

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

Allow to suppress exporting default materials #3113

Open BeardedPlatypus opened 1 year ago

BeardedPlatypus commented 1 year ago

I hope this Feature Request is not something that is already possible, but I couldn't find a way in the documentation to do this.

Is your feature request related to a problem? Please describe.

If my understanding is correct, Maya requires every mesh to have a material, and by default the initialShadingGroup is assigned. When exporting with Maya-USD with materials, when a mesh a with a default material is exported, this default material is written to the USD file.

For certain scenes, we have utilize meshes for different purposes, some meshes might have actual (non-default) materials assigned that we want to export, but also have meshes that should not have materials associated with them (e.g. related to collision detection). Currently, I could not find a way to suppress writing such default materials to these meshes.

Describe the solution you'd like

I would like to have a flag, e.g. -exportDefaultMaterials that defaults to true, that allows us to disable writing the initialShadingGroup to USD files.

Or alternatively, more fine-grained control which materials are exported than just export all materials, or export no materials.

Describe alternatives you've considered

Currently, we work around this by using an export filter, and explicitly removing the default material from any mesh that has it assigned. This works, however it seems cumbersome to do this, and feels like something that should be supported in Maya-USD rather than being a post-process step.

It might be possible to do this with a custom shader writer, however I have not yet explored this possibility. If this would be recommended approach, I would love to know that.

womanyoyoyo-adsk commented 1 year ago

Hi @BeardedPlatypus ,

In the UI you are able to export without a material by unchecking all the Materials listed, like this:

image (19)

We do have a flag to export without materials. It is-shadingMode and it takes a string. Set the string to none. You can find this flag and all our export commands here: https://github.com/Autodesk/maya-usd/blob/dev/lib/mayaUsd/commands/Readme.md#mayausdexportcommand

Hopefully this is what you're looking for! Natalia

BeardedPlatypus commented 1 year ago

Hi @womanyoyoyo-adsk , thank you for your answer! Apologies for the late response. Unfortunately I don't think it is what I am looking, I am looking explicitly to suppress the export of default materials. I do want to export materials explicitly authored by artists.

I created the following scene which hopefully illustrates what I'm trying to achieve (I am very much just a developer not a Maya expert, so not sure if I did everything correctly).

The file should contain the maya scene and the corresponding usda export.

The scene has two objects:

image

In this case, the SimpleCube has an authored material and SimpleCube_Collision has a default material.

When I export these I get the following material scope export in my usd file:

    def Scope "mtl"
    {
        def Material "initialShadingGroup"
        {
        }

        def Material "SimpleCube_SG"
        {
            token outputs:surface.connect = </SimpleCube_Entity/mtl/SimpleCube_SG/SimpleCube_Material.outputs:surface>

            def Shader "SimpleCube_Material"
            {
                uniform token info:id = "UsdPreviewSurface"
                color3f inputs:diffuseColor = (0.8, 0.296, 0)
                normal3f inputs:normal = (1, 1, 1)
                float inputs:roughness = 1
                int inputs:useSpecularWorkflow = 1
                token outputs:displacement
                token outputs:surface
            }
        }
    }

Which are linked by the SimpleCube_Collision and SimpleCube respectively:

       def Mesh "SimpleCube" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        ...
        rel material:binding = </SimpleCube_Entity/mtl/SimpleCube_SG>
        ...
   }
   def Mesh "SimpleCube_Collision" (
        prepend apiSchemas = ["MaterialBindingAPI"]
    )
    {
        ...
        rel material:binding = </SimpleCube_Entity/mtl/initialShadingGroup>
        ...
    }

In this case, I do want to export the SimpleCube_SG as this is explicitly authored by me, but I do not want to export the initialShadingGroup material associated with SimpleCube_Collision as this was not authored by me at all.

If I follow your suggestion, if I understand it correctly I either will export both materials or neither. I hope this explains my issue a bit better.

I can still use my export chaser to deactivate the material and remove the binding, but it seems like something that should be configurable in Maya-USD itself.

womanyoyoyo-adsk commented 1 year ago

Thanks @BeardedPlatypus for explaining and providing the example. Yes, you are right - currently we only have the ability to export both materials or neither. Let me bring this back to my team and discuss.

maya-usd-git-sync[bot] commented 10 months ago

Issue synced internally to EMSUSD-783