Skip to content

Commit

Permalink
Merge pull request #4041 from Autodesk/bailp/EMSUSD-1919/expose-expor…
Browse files Browse the repository at this point in the history
…t-args-to-python

EMSUSD-1919 expose export job args to Python
  • Loading branch information
seando-adsk authored Dec 12, 2024
2 parents c25a8fe + 4a70868 commit 2eb4a2a
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/mayaUsd/python/wrapPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ PXR_BOOST_PYTHON_NAMESPACE::object get_allChaserArgs(UsdMayaJobExportArgs& self)
return PXR_BOOST_PYTHON_NAMESPACE::object(allChaserArgs);
}

bool get_ExportCameras(UsdMayaJobExportArgs& self) { return self.isExportingCameras(); }

bool get_ExportMeshes(UsdMayaJobExportArgs& self) { return self.isExportingMeshes(); }

bool get_ExportLights(UsdMayaJobExportArgs& self) { return self.isExportingLights(); }

PXR_BOOST_PYTHON_NAMESPACE::object get_remapUVSetsTo(UsdMayaJobExportArgs& self)
{
PXR_BOOST_PYTHON_NAMESPACE::dict uvSetRemaps;
Expand Down Expand Up @@ -552,6 +558,7 @@ void wrapJobExportArgs()
make_getter(
&UsdMayaJobExportArgs::exportRelativeTextures,
return_value_policy<return_by_value>()))
.def_readonly("legacyMaterialScope", &UsdMayaJobExportArgs::legacyMaterialScope)
.add_property(
"referenceObjectMode",
make_getter(
Expand All @@ -568,6 +575,10 @@ void wrapJobExportArgs()
.def_readonly("file", &UsdMayaJobExportArgs::file)
.def_readonly("rootPrim", &UsdMayaJobExportArgs::rootPrim)
.def_readonly("rootPrimType", &UsdMayaJobExportArgs::rootPrimType)
.add_property(
"exportRoots",
make_getter(
&UsdMayaJobExportArgs::exportRoots, return_value_policy<TfPySequenceToSet>()))
.def_readonly("upAxis", &UsdMayaJobExportArgs::upAxis)
.def_readonly("unit", &UsdMayaJobExportArgs::unit)
.add_property(
Expand Down Expand Up @@ -604,6 +615,7 @@ void wrapJobExportArgs()
.def_readonly("normalizeNurbs", &UsdMayaJobExportArgs::normalizeNurbs)
.def_readonly("preserveUVSetNames", &UsdMayaJobExportArgs::preserveUVSetNames)
.def_readonly("writeDefaults", &UsdMayaJobExportArgs::writeDefaults)
.def_readonly("metersPerUnit", &UsdMayaJobExportArgs::metersPerUnit)
.add_property(
"parentScope",
make_getter(&UsdMayaJobExportArgs::parentScope, return_value_policy<return_by_value>()))
Expand All @@ -629,6 +641,7 @@ void wrapJobExportArgs()
.add_property(
"rootKind",
make_getter(&UsdMayaJobExportArgs::rootKind, return_value_policy<return_by_value>()))
.def_readonly("disableModelKindProcessor", &UsdMayaJobExportArgs::disableModelKindProcessor)
.add_property(
"rootMapFunction",
make_getter(
Expand All @@ -647,6 +660,9 @@ void wrapJobExportArgs()
make_getter(
&UsdMayaJobExportArgs::usdModelRootOverridePath,
return_value_policy<return_by_value>()))
.add_property("exportMeshes", ::get_ExportMeshes)
.add_property("exportCameras", ::get_ExportCameras)
.add_property("exportLights", ::get_ExportLights)
.def_readonly("verbose", &UsdMayaJobExportArgs::verbose)
.def("GetResolvedFileName", &UsdMayaJobExportArgs::GetResolvedFileName)
.def("GetDefaultMaterialsScopeName", &UsdMayaJobExportArgs::GetDefaultMaterialsScopeName)
Expand Down
104 changes: 104 additions & 0 deletions test/lib/mayaUsd/fileio/testPrimWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,105 @@
import unittest


def getJobArgsProperties():
return [
"allChaserArgs",
"allMaterialConversions",
"chaserNames",
"compatibility",
"convertMaterialsTo",
"remapUVSetsTo",
"defaultMeshScheme",
"defaultUSDFormat",
"defaultPrim",
"eulerFilter",
"excludeInvisible",
"exportBlendShapes",
"exportCollectionBasedBindings",
"exportColorSets",
"exportMaterials",
"exportAssignedMaterials",
"exportComponentTags",
"exportStagesAsRefs",
"exportDefaultCameras",
"exportDisplayColor",
"exportDistanceUnit",
"exportInstances",
"exportMaterialCollections",
"exportMeshUVs",
"exportNurbsExplicitUV",
"exportRelativeTextures",
"legacyMaterialScope",
"referenceObjectMode",
"exportRefsAsInstanceable",
"exportSelected",
"exportSkels",
"exportSkin",
"exportVisibility",
"file",
"rootPrim",
"rootPrimType",
"exportRoots",
"upAxis",
"unit",
"filteredTypeIds",
"geomSidedness",
"ignoreWarnings",
"includeEmptyTransforms",
"isDuplicating",
"includeAPINames",
"jobContextNames",
"materialCollectionsPath",
"materialsScopeName",
"melPerFrameCallback",
"melPostCallback",
"mergeTransformAndShape",
"normalizeNurbs",
"preserveUVSetNames",
"writeDefaults",
"metersPerUnit",
"parentScope",
"rootPrim",
"rootPrimType",
"upAxis",
"unit",
"pythonPerFrameCallback",
"pythonPostCallback",
"renderLayerMode",
"rootKind",
"disableModelKindProcessor",
"rootMapFunction",
"shadingMode",
"staticSingleSample",
"stripNamespaces",
"worldspace",
"timeSamples",
"usdModelRootOverridePath",
"exportMeshes",
"exportCameras",
"exportLights",
"verbose",
]

def copyJobArgs(jobArgs):
args = {}
for name in getJobArgsProperties():
args[name] = getattr(jobArgs, name)

args["resolvedFileName"] = jobArgs.GetResolvedFileName()
args["defaultMaterialsScopeName"] = jobArgs.GetDefaultMaterialsScopeName()

return args


class primWriterTest(mayaUsdLib.PrimWriter):
InitCalled = False
WriteCalled = False
PostExportCalled = False
CanExportCalled = False

JobArgs = {}

def __init__(self, *args, **kwargs):
super(primWriterTest, self).__init__(*args, **kwargs)
if not self.GetDagPath().isValid():
Expand All @@ -53,6 +146,7 @@ def __init__(self, *args, **kwargs):
@classmethod
def CanExport(cls, exportArgs, exportObj=None):
primWriterTest.CanExportCalled = True
primWriterTest.JobArgs = copyJobArgs(exportArgs)
return mayaUsdLib.PrimWriter.ContextSupport.Supported

def Write(self, usdTime):
Expand Down Expand Up @@ -83,6 +177,12 @@ def tearDownClass(cls):
def setUp(self):
cmds.file(new=True, force=True)

def _verifyJobArgs(self, args):
for name in getJobArgsProperties():
self.assertIn(name, args)
self.assertIn('resolvedFileName', args)
self.assertIn('defaultMaterialsScopeName', args)

def testSimplePrimWriter(self):
mayaUsdLib.PrimWriter.Register(primWriterTest, "mesh")

Expand All @@ -98,5 +198,9 @@ def testSimplePrimWriter(self):
self.assertTrue(primWriterTest.WriteCalled)
self.assertTrue(primWriterTest.PostExportCalled)

# Verify the job args had all expected properties.
self._verifyJobArgs(primWriterTest.JobArgs)


if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 2eb4a2a

Please sign in to comment.