diff --git a/lib/mayaUsd/fileio/registryHelper.cpp b/lib/mayaUsd/fileio/registryHelper.cpp index 324cedd41b..e5a7a61157 100644 --- a/lib/mayaUsd/fileio/registryHelper.cpp +++ b/lib/mayaUsd/fileio/registryHelper.cpp @@ -189,10 +189,17 @@ UsdMaya_RegistryHelper::FindAndLoadMayaPlug( } else { TF_DEBUG(PXRUSDMAYA_REGISTRY).Msg( - "Found usdMaya plugin %s: %s = %s. No maya plugin.\n", + "Found %s usdMaya plugin %s: %s = %s. No maya plugin.\n", + plug->IsLoaded() ? "loaded" : "unloaded", plug->GetName().c_str(), _PluginDictScopeToDebugString(scope).c_str(), value.c_str()); + + // Make sure that the Plug plugin is loaded to ensure that the + // library is loaded in case it is a "library" type plugin with + // no accompanying Maya plugin. This is a noop if the plugin is + // already loaded. + plug->Load(); } break; } diff --git a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt index 22d0c14ed3..c564117036 100644 --- a/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt +++ b/plugin/pxr/maya/lib/usdMaya/CMakeLists.txt @@ -77,9 +77,6 @@ pxr_test_scripts( testenv/testUsdImportAsAssemblies.py testenv/testUsdImportNestedAssemblyAnimation.py testenv/testUsdTranslateTypelessDefs.py - testenv/testUsdMayaAdaptor.py - testenv/testUsdMayaAdaptorGeom.py - testenv/testUsdMayaAdaptorMetadata.py testenv/testUsdMayaBlockSceneModificationContext.py testenv/testUsdMayaDiagnosticDelegate.py testenv/testUsdMayaGetVariantSetSelections.py @@ -240,50 +237,6 @@ pxr_register_test(testUsdTranslateTypelessDefs MAYA_APP_DIR=/maya_profile ) -pxr_register_test(testUsdMayaAdaptor - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptor" - TESTENV testUsdMayaAdaptor - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - -pxr_install_test_dir( - SRC testenv/UsdMayaAdaptorGeomTest - DEST testUsdMayaAdaptorGeom -) -pxr_register_test(testUsdMayaAdaptorGeom - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorGeom" - TESTENV testUsdMayaAdaptorGeom - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - -pxr_install_test_dir( - SRC testenv/UsdMayaAdaptorMetadataTest - DEST testUsdMayaAdaptorMetadata -) -pxr_register_test(testUsdMayaAdaptorMetadata - CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} - COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaAdaptorMetadata" - TESTENV testUsdMayaAdaptorMetadata - ENV - MAYA_PLUG_IN_PATH=${TEST_INSTALL_PREFIX}/maya/plugin - MAYA_SCRIPT_PATH=${TEST_INSTALL_PREFIX}/maya/lib/usd/usdMaya/resources - MAYA_DISABLE_CIP=1 - MAYA_NO_STANDALONE_ATEXIT=1 - MAYA_APP_DIR=/maya_profile -) - pxr_register_test(testUsdMayaBlockSceneModificationContext CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE} COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaBlockSceneModificationContext" diff --git a/test/lib/usd/translators/CMakeLists.txt b/test/lib/usd/translators/CMakeLists.txt index 2f72a68078..e99ef15559 100644 --- a/test/lib/usd/translators/CMakeLists.txt +++ b/test/lib/usd/translators/CMakeLists.txt @@ -51,6 +51,10 @@ set(TEST_SCRIPT_FILES testUsdExportImportRoundtripPreviewSurface.py testUsdImportSkeleton.py testUsdImportXforms.py + testUsdMayaAdaptor.py + testUsdMayaAdaptorGeom.py + testUsdMayaAdaptorMetadata.py + testUsdMayaAdaptorUndoRedo.py ) add_custom_target(${TARGET_NAME} ALL) diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorGeomTest/UsdAttrs.usda b/test/lib/usd/translators/UsdMayaAdaptorGeomTest/UsdAttrs.usda similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorGeomTest/UsdAttrs.usda rename to test/lib/usd/translators/UsdMayaAdaptorGeomTest/UsdAttrs.usda diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorMetadataTest/UsdAttrs.usda b/test/lib/usd/translators/UsdMayaAdaptorMetadataTest/UsdAttrs.usda similarity index 100% rename from plugin/pxr/maya/lib/usdMaya/testenv/UsdMayaAdaptorMetadataTest/UsdAttrs.usda rename to test/lib/usd/translators/UsdMayaAdaptorMetadataTest/UsdAttrs.usda diff --git a/test/lib/usd/translators/fixturesUtils.py b/test/lib/usd/translators/fixturesUtils.py index 4394412eb1..61cd4ce02e 100644 --- a/test/lib/usd/translators/fixturesUtils.py +++ b/test/lib/usd/translators/fixturesUtils.py @@ -29,9 +29,11 @@ def _setUpClass(modulePathName, loadPlugin): if loadPlugin: cmds.loadPlugin('mayaUsdPlugin', quiet=True) - # Monkey patch cmds so that usdExport and usdImport becomes aliases. - cmds.usdExport = cmds.mayaUSDExport - cmds.usdImport = cmds.mayaUSDImport + # Monkey patch cmds so that usdExport and usdImport becomes aliases. We + # *only* do this if we're loading the plugin, since otherwise the + # export/import commands will not exist. + cmds.usdExport = cmds.mayaUSDExport + cmds.usdImport = cmds.mayaUSDImport realPath = os.path.realpath(modulePathName) return os.path.split(realPath) diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py b/test/lib/usd/translators/testUsdMayaAdaptor.py similarity index 85% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py rename to test/lib/usd/translators/testUsdMayaAdaptor.py index 9fee5df3aa..bafb31f227 100644 --- a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptor.py +++ b/test/lib/usd/translators/testUsdMayaAdaptor.py @@ -15,8 +15,6 @@ # limitations under the License. # -from pxr import UsdMaya - import mayaUsd.lib as mayaUsdLib from pxr import Sdf @@ -29,12 +27,17 @@ import unittest +import fixturesUtils + class testUsdMayaAdaptor(unittest.TestCase): @classmethod def setUpClass(cls): - standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') + # Note that we do *not* explicitly load any USD plugins in this test. + # We are testing that the Plug-based lookup mechanism correctly + # identifies and loads the necessary libraries when a schema adapter is + # requested. + cls.inputPath = fixturesUtils.setUpClass(__file__, loadPlugin=False) @classmethod def tearDownClass(cls): @@ -293,42 +296,6 @@ def testConcreteSchemaRegistrations(self): self.assertTrue( mayaUsdLib.Adaptor("TestParticles").GetSchema(UsdGeom.Points)) - def testUndoRedo(self): - """Tests that adaptors work with undo/redo.""" - cmds.file(new=True, force=True) - cmds.group(name="group1", empty=True) - adaptor = mayaUsdLib.Adaptor("group1") - self.assertEqual(adaptor.GetAppliedSchemas(), []) - - # Do a single operation, then undo, then redo. - adaptor.ApplySchema(UsdGeom.ModelAPI) - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - cmds.undo() - self.assertEqual(adaptor.GetAppliedSchemas(), []) - cmds.redo() - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - - # Do a compound operation, then undo, then redo. - cmds.undoInfo(openChunk=True) - adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute( - UsdGeom.Tokens.motionVelocityScale).Set(0.42) - self.assertEqual(adaptor.GetAppliedSchemas(), - ["GeomModelAPI", "MotionAPI"]) - self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) - cmds.undoInfo(closeChunk=True) - cmds.undo() - self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) - self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale)) - self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get()) - cmds.redo() - self.assertEqual(adaptor.GetAppliedSchemas(), - ["GeomModelAPI", "MotionAPI"]) - self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( - UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) - def testGetAttributeAliases(self): """Tests the GetAttributeAliases function.""" self.assertEqual( diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorGeom.py b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py similarity index 91% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorGeom.py rename to test/lib/usd/translators/testUsdMayaAdaptorGeom.py index 18bad08490..ed0f6fedc4 100644 --- a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorGeom.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorGeom.py @@ -15,12 +15,16 @@ # limitations under the License. # +from pxr import Usd +from pxr import UsdGeom + from maya import cmds from maya import standalone import os import unittest -from pxr import Usd, UsdGeom + +import fixturesUtils class testUsdMayaAdaptorGeom(unittest.TestCase): @@ -31,10 +35,10 @@ def tearDownClass(cls): @classmethod def setUpClass(cls): - standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') + cls.inputPath = fixturesUtils.setUpClass(__file__) - usdFile = os.path.abspath('UsdAttrs.usda') + usdFile = os.path.join(cls.inputPath, 'UsdMayaAdaptorGeomTest', + 'UsdAttrs.usda') cmds.usdImport(file=usdFile, shadingMode='none') def testImportImageable(self): diff --git a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorMetadata.py b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py similarity index 91% rename from plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorMetadata.py rename to test/lib/usd/translators/testUsdMayaAdaptorMetadata.py index 98955c3bcc..d317664773 100644 --- a/plugin/pxr/maya/lib/usdMaya/testenv/testUsdMayaAdaptorMetadata.py +++ b/test/lib/usd/translators/testUsdMayaAdaptorMetadata.py @@ -15,17 +15,19 @@ # limitations under the License. # +import mayaUsd.lib as mayaUsdLib + from pxr import Usd from pxr import UsdGeom -import mayaUsd.lib as mayaUsdLib - from maya import cmds from maya import standalone import os import unittest +import fixturesUtils + class testUsdMayaAdaptorMetadata(unittest.TestCase): @@ -35,8 +37,10 @@ def tearDownClass(cls): @classmethod def setUpClass(cls): - standalone.initialize('usd') - cmds.loadPlugin('pxrUsd') + cls.inputPath = fixturesUtils.setUpClass(__file__) + + cls.inputUsdFile = os.path.join(cls.inputPath, + 'UsdMayaAdaptorMetadataTest', 'UsdAttrs.usda') def testImport_HiddenInstanceableKind(self): """ @@ -44,8 +48,7 @@ def testImport_HiddenInstanceableKind(self): hidden, instanceable, and kind metadata properly. """ cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none') + cmds.usdImport(file=self.inputUsdFile, shadingMode='none') # pCube1 and pCube2 have USD_kind. self.assertEqual(cmds.getAttr('pCube1.USD_kind'), 'potato') @@ -74,8 +77,7 @@ def testImport_HiddenInstanceableKind(self): def testImport_HiddenInstanceable(self): """Tests import with only hidden, instanceable metadata and not kind.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', metadata=['hidden', 'instanceable']) # pCube1 and pCube2 have USD_kind, but that shouldn't be imported. @@ -97,8 +99,7 @@ def testImport_HiddenInstanceable(self): def testImport_TypeName(self): """Tests import with metadata=typeName manually specified.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', metadata=["typeName"]) # typeName metadata should come through. @@ -120,8 +121,7 @@ def testImport_TypeName(self): def testImport_GeomModelAPI(self): """Tests importing UsdGeomModelAPI attributes.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI']) worldProxy = mayaUsdLib.Adaptor('World') @@ -154,8 +154,7 @@ def testExport(self): the correct metadata in the output USD file. """ cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none') + cmds.usdImport(file=self.inputUsdFile, shadingMode='none') newUsdFilePath = os.path.abspath('UsdAttrsNew.usda') cmds.usdExport(file=newUsdFilePath, shadingMode='none') @@ -185,8 +184,7 @@ def testExport(self): def testExport_GeomModelAPI(self): """Tests export with the GeomModelAPI.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI']) newUsdFilePath = os.path.abspath('UsdAttrsNew_GeomModelAPI.usda') @@ -203,8 +201,7 @@ def testExport_GeomModelAPI(self): def testExport_GeomModelAPI_MotionAPI(self): """Tests export with both the GeomModelAPI and MotionAPI.""" cmds.file(new=True, force=True) - usdFile = os.path.abspath('UsdAttrs.usda') - cmds.usdImport(file=usdFile, shadingMode='none', + cmds.usdImport(file=self.inputUsdFile, shadingMode='none', apiSchema=['GeomModelAPI', 'MotionAPI']) newUsdFilePath = os.path.abspath('UsdAttrsNew_TwoAPIs.usda') diff --git a/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py b/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py new file mode 100644 index 0000000000..30aaa33d50 --- /dev/null +++ b/test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py @@ -0,0 +1,79 @@ +#!/pxrpythonsubst +# +# Copyright 2020 Pixar +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import mayaUsd.lib as mayaUsdLib + +from pxr import UsdGeom + +from maya import cmds +from maya import standalone + +import unittest + +import fixturesUtils + + +class testUsdMayaAdaptorUndoRedo(unittest.TestCase): + @classmethod + def setUpClass(cls): + # We load the plugin here to ensure that the usdUndoHelperCmd has been + # registered. See the documentation on UsdMayaAdaptor for more detail. + cls.inputPath = fixturesUtils.setUpClass(__file__, loadPlugin=True) + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def testUndoRedo(self): + """Tests that adaptors work with undo/redo.""" + cmds.file(new=True, force=True) + cmds.group(name="group1", empty=True) + adaptor = mayaUsdLib.Adaptor("group1") + self.assertEqual(adaptor.GetAppliedSchemas(), []) + + # Do a single operation, then undo, then redo. + adaptor.ApplySchema(UsdGeom.ModelAPI) + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + cmds.undo() + self.assertEqual(adaptor.GetAppliedSchemas(), []) + cmds.redo() + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + + # Do a compound operation, then undo, then redo. + cmds.undoInfo(openChunk=True) + adaptor.ApplySchema(UsdGeom.MotionAPI).CreateAttribute( + UsdGeom.Tokens.motionVelocityScale).Set(0.42) + self.assertEqual(adaptor.GetAppliedSchemas(), + ["GeomModelAPI", "MotionAPI"]) + self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) + cmds.undoInfo(closeChunk=True) + cmds.undo() + self.assertEqual(adaptor.GetAppliedSchemas(), ["GeomModelAPI"]) + self.assertFalse(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale)) + self.assertIsNone(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get()) + cmds.redo() + self.assertEqual(adaptor.GetAppliedSchemas(), + ["GeomModelAPI", "MotionAPI"]) + self.assertAlmostEqual(adaptor.GetSchema(UsdGeom.MotionAPI).GetAttribute( + UsdGeom.Tokens.motionVelocityScale).Get(), 0.42) + + +if __name__ == '__main__': + unittest.main(verbosity=2)