Skip to content

Commit

Permalink
Merge pull request #694 from mattyjams/pr/load_Plug_library_when_find…
Browse files Browse the repository at this point in the history
…ing_and_loading_in_registry

[mayaUsd] load Plug libraries when finding and loading in the registry
  • Loading branch information
Krystian Ligenza authored Aug 9, 2020
2 parents 99f14fe + ec6780a commit 8e40e77
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 113 deletions.
9 changes: 8 additions & 1 deletion lib/mayaUsd/fileio/registryHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
47 changes: 0 additions & 47 deletions plugin/pxr/maya/lib/usdMaya/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -240,50 +237,6 @@ pxr_register_test(testUsdTranslateTypelessDefs
MAYA_APP_DIR=<PXR_TEST_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=<PXR_TEST_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=<PXR_TEST_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=<PXR_TEST_DIR>/maya_profile
)

pxr_register_test(testUsdMayaBlockSceneModificationContext
CUSTOM_PYTHON ${MAYA_PY_EXECUTABLE}
COMMAND "${TEST_INSTALL_PREFIX}/tests/testUsdMayaBlockSceneModificationContext"
Expand Down
4 changes: 4 additions & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions test/lib/usd/translators/fixturesUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# limitations under the License.
#

from pxr import UsdMaya

import mayaUsd.lib as mayaUsdLib

from pxr import Sdf
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -35,17 +37,18 @@ 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):
"""
Tests that the adaptor mechanism can import
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')
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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')
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down
79 changes: 79 additions & 0 deletions test/lib/usd/translators/testUsdMayaAdaptorUndoRedo.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 8e40e77

Please sign in to comment.