maya-usd
maya-usd copied to clipboard
Schema API Adaptors registered on "mesh" will override ones on "shape"
Describe the bug Registering an API adaptor for "mesh" will cause all the ones registered for "shape" to fall off. We encountered this when trying to use the schema API Adaptors in order to register a MeshLightAPI adaptor for "mesh". This caused the testSchemaApiAdaptor to fail because the test registers adaptors on "shape".
Steps to reproduce Here's a standalone script you can run to reproduce the issue
import maya.standalone
maya.standalone.initialize()
import mayaUsd.lib as mayaUsdLib
from maya import cmds
cmds.loadPlugin("mayaUsdPlugin")
class _A(mayaUsdLib.SchemaApiAdaptor):
def CanAdaptForExport(self, jobArgs):
print("_A")
return False
def GetAdaptedAttributeNames(self):
return []
def GetMayaNameForUsdAttrName(self, usdName):
return usdName
class _B(mayaUsdLib.SchemaApiAdaptor):
def CanAdaptForExport(self, jobArgs):
print("_B")
return False
def GetAdaptedAttributeNames(self):
return []
def GetMayaNameForUsdAttrName(self, usdName):
return usdName
def main():
# Suppose some plugin registers some apiSchemas that could apply to all
# shapes.
mayaUsdLib.SchemaApiAdaptor.Register(_A, "shape", "ShapingAPI")
# Now, suppose we have an API schema that only applies to meshes.
mayaUsdLib.SchemaApiAdaptor.Register(_B, "mesh", "ShadowAPI")
# create a mesh to export
cmds.file(new=True, force=True)
cmds.polySphere()
# When exporting a "mesh" (which is also a "shape"), I'd expect both schemas
# to be exported.
cmds.mayaUSDExport(file="tmp.usda", apiSchema=["ShapingAPI", "ShadowAPI"])
if __name__ == '__main__':
main()
Additional context I believe this code that finds the adaptors should actually be walking up the type hierarchy: https://github.com/Autodesk/maya-usd/blob/dev/lib/mayaUsd/fileio/schemaApiAdaptorRegistry.cpp#L106