From 4a70868fddff0446040e3cf584cdb0351b613852 Mon Sep 17 00:00:00 2001 From: Pierre Baillargeon Date: Tue, 10 Dec 2024 08:58:54 -0500 Subject: [PATCH] EMSUSD-1919 expose export job args to Python Some export job arguments were not exposed to Python code. We now expose them and verify that they are accessible in a unit test. --- lib/mayaUsd/python/wrapPrimWriter.cpp | 16 ++++ test/lib/mayaUsd/fileio/testPrimWriter.py | 104 ++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/lib/mayaUsd/python/wrapPrimWriter.cpp b/lib/mayaUsd/python/wrapPrimWriter.cpp index 625933cea1..2e1572a0d1 100644 --- a/lib/mayaUsd/python/wrapPrimWriter.cpp +++ b/lib/mayaUsd/python/wrapPrimWriter.cpp @@ -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; @@ -552,6 +558,7 @@ void wrapJobExportArgs() make_getter( &UsdMayaJobExportArgs::exportRelativeTextures, return_value_policy())) + .def_readonly("legacyMaterialScope", &UsdMayaJobExportArgs::legacyMaterialScope) .add_property( "referenceObjectMode", make_getter( @@ -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())) .def_readonly("upAxis", &UsdMayaJobExportArgs::upAxis) .def_readonly("unit", &UsdMayaJobExportArgs::unit) .add_property( @@ -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())) @@ -629,6 +641,7 @@ void wrapJobExportArgs() .add_property( "rootKind", make_getter(&UsdMayaJobExportArgs::rootKind, return_value_policy())) + .def_readonly("disableModelKindProcessor", &UsdMayaJobExportArgs::disableModelKindProcessor) .add_property( "rootMapFunction", make_getter( @@ -647,6 +660,9 @@ void wrapJobExportArgs() make_getter( &UsdMayaJobExportArgs::usdModelRootOverridePath, return_value_policy())) + .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) diff --git a/test/lib/mayaUsd/fileio/testPrimWriter.py b/test/lib/mayaUsd/fileio/testPrimWriter.py index 53c3d30a3f..89fabbc09c 100644 --- a/test/lib/mayaUsd/fileio/testPrimWriter.py +++ b/test/lib/mayaUsd/fileio/testPrimWriter.py @@ -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(): @@ -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): @@ -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") @@ -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)