UsdMayaSchemaApiAdaptor creates empty attributes
- Dominant language
- Wolfram Language
- Stars
- 905
- Forks
- 223
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 17
Description
**Describe the bug**
it would be nice if the schema adaptor didn't create attributes that it didn't need to.
When adding an adaptor for MeshLightAPI for PxrMeshLight, we noticed that many attributes end up being created without values.
The schemaAdaptor->GetAttribute(attrName) ends up creating the attribute. But then if attrAdaptor.Get(&value) fails, we end up with an attribute without any value.
**Steps to reproduce**
Here's a script you can run to reproduce the issue
```
import maya.standalone
maya.standalone.initialize()
import mayaUsd.lib as mayaUsdLib
from maya import cmds
import os
cmds.loadPlugin("mayaUsdPlugin")
class _LightAPIAdaptor(mayaUsdLib.SchemaApiAdaptor):
def CanAdapt(self):
return True
def CanAdaptForExport(self, jobArgs):
return True
def GetAdaptedAttributeNames(self):
return ['inputs:intensity', 'inputs:exposure']
def GetMayaNameForUsdAttrName(self, usdName):
mayaName = usdName.split(":")[-1]
return mayaName
def _AddFloat(shape, name, val):
cmds.addAttr(shape, longName=name, attributeType='float', defaultValue=val)
def main():
# Suppose some plugin registers some apiSchemas that could apply to all
# shapes.
mayaUsdLib.SchemaApiAdaptor.Register(_LightAPIAdaptor, "shape", "LightAPI")
# create a mesh to export
cmds.file(new=True, force=True)
sphere, _ = cmds.polySphere()
sphereShape = cmds.listRelatives(sphere, shapes=True)[0]
_AddFloat(sphereShape, 'intensity', 1.0)
_AddFloat(sphereShape, 'exposure', 1.0) # note default is 0.0
outFile = os.path.abspath('./tmp.usda')
# When exporting a "mesh" (which is also a "shape"), I'd expect both schemas
# to be exported.
cmds.mayaUSDExport(file=outFile, apiSchema=["LightAPI"])
from pxr import Sdf
layer = Sdf.Layer.FindOrOpen(outFile)
assert(layer.GetAttributeAtPath('/pSphere1.inputs:exposure'))
assert(not layer.GetAttributeAtPath('/pSphere1.inputs:intensity'))
if __name__ == '__main__':
main()
```
**Expected behavior**
I'd expect the script above to run without getting the assertion error.
The resulting usd looks like
```
float inputs:exposure = 1
float inputs:intensity
```
I'd expect only inputs:exposure to be present (which is what the assert is testing).
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with UsdMayaSchemaApiAdaptor and the SchemaApiAdaptor.GetAttribute path used during mayaUSDExport, then run the provided standalone Maya reproduction script. Trace the case where attrAdaptor.Get fails and confirm that an attribute is not left behind without a value; the script's final assertions define the done condition.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100