diff --git a/lib/mayaUsd/commands/Readme.md b/lib/mayaUsd/commands/Readme.md index 632f7db756..735a4ec651 100644 --- a/lib/mayaUsd/commands/Readme.md +++ b/lib/mayaUsd/commands/Readme.md @@ -404,22 +404,30 @@ wanted the default flags mentioned above: ```javascript { - "UsdMaya": { - "mayaUSDExport": { - "exportMaterialCollections": true, - "chaser": "alembic", - "chaserArgs": [ - ["alembic", "primvarprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"], - ["alembic", "attrprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"] - ] + "Plugins": [ + { + "Info": { + "UsdMaya": { + "UsdExport": { + "exportMaterialCollections": true, + "chaser": ["alembic"], + "chaserArgs": [ + ["alembic", "primvarprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"], + ["alembic", "attrprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"] + ] + } } + }, + "Name": "MySiteSpecificConfigPlugin", + "Type": "resource" } + ] } ``` This also works for the `MayaUSDImportCommand` base command, for example in the `mayaUSDImport` command and the "File > Import" menu item; use -the `mayaUSDImport` key in the `plugInfo.json` file to configure your +the `UsdImport` key in the `plugInfo.json` file to configure your site-specific defaults. diff --git a/plugin/pxr/doc/README.md b/plugin/pxr/doc/README.md index 116b916883..d395798c89 100644 --- a/plugin/pxr/doc/README.md +++ b/plugin/pxr/doc/README.md @@ -344,16 +344,24 @@ For example, your `plugInfo.json` would contain these keys if you wanted the def ```javascript { - "UsdMaya": { - "UsdExport": { - "exportMaterialCollections": true, - "chaser": "alembic", - "chaserArgs": [ - ["alembic", "primvarprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"], - ["alembic", "attrprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"] - ] + "Plugins": [ + { + "Info": { + "UsdMaya": { + "UsdExport": { + "exportMaterialCollections": true, + "chaser": ["alembic"], + "chaserArgs": [ + ["alembic", "primvarprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"], + ["alembic", "attrprefix", "ABC_,ABC2_=customPrefix_,ABC3_=,ABC4_=customNamespace:"] + ] + } } + }, + "Name": "MySiteSpecificConfigPlugin", + "Type": "resource" } + ] } ``` diff --git a/test/lib/usd/plugin/CMakeLists.txt b/test/lib/usd/plugin/CMakeLists.txt index 657025f984..afa34c29fd 100644 --- a/test/lib/usd/plugin/CMakeLists.txt +++ b/test/lib/usd/plugin/CMakeLists.txt @@ -270,3 +270,15 @@ endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/nullApiExporter_plugInfo.json" "${CMAKE_CURRENT_BINARY_DIR}/nullApiExporter/plugInfo.json" ) + +# ----------------------------------------------------------------------------- +# Site-specific configuration tests: +# ----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- +# Plug-in files +# ----------------------------------------------------------------------------- +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/plugInfoSiteSpecificConfig.json" + "${CMAKE_CURRENT_BINARY_DIR}/SiteSpecificConfig/plugInfo.json" +) + diff --git a/test/lib/usd/plugin/plugInfoSiteSpecificConfig.json b/test/lib/usd/plugin/plugInfoSiteSpecificConfig.json new file mode 100644 index 0000000000..5b8091c0ea --- /dev/null +++ b/test/lib/usd/plugin/plugInfoSiteSpecificConfig.json @@ -0,0 +1,30 @@ +{ + "Plugins": [ + { + "Info": { + "UsdMaya": { + "UsdExport": { + "exportDisplayColor": true, + "exportSkin": "auto", + "chaser": ["TestExportChaserFromSiteSpecific"], + "chaserArgs": [ + ["TestExportChaserFromSiteSpecific", "frob", "ishness"], + ["TestExportChaserFromSiteSpecific", "baz", "illion"] + ] + }, + "UsdImport": { + "useAsAnimationCache": true, + "preferredMaterial": "phong", + "chaser": ["TestImportChaserFromSiteSpecific"], + "chaserArgs": [ + ["TestImportChaserFromSiteSpecific", "frob", "ishness"], + ["TestImportChaserFromSiteSpecific", "baz", "illion"] + ] + } + } + }, + "Name": "SiteSpecificConfigPlugin", + "Type": "resource" + } + ] +} diff --git a/test/lib/usd/translators/CMakeLists.txt b/test/lib/usd/translators/CMakeLists.txt index 159b475bd2..631fb5777b 100644 --- a/test/lib/usd/translators/CMakeLists.txt +++ b/test/lib/usd/translators/CMakeLists.txt @@ -259,3 +259,12 @@ if (PXR_VERSION VERSION_GREATER 2105) ) set_property(TEST testUsdExportSchemaApi APPEND PROPERTY LABELS translators) endif() + +mayaUsd_add_test(testUsdImportExportSiteSpecificConfig + PYTHON_MODULE testUsdImportExportSiteSpecificConfig + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ENV + "${PXR_OVERRIDE_PLUGINPATH_NAME}=${CMAKE_CURRENT_BINARY_DIR}/../plugin/SiteSpecificConfig" +) +set_property(TEST testUsdImportExportSiteSpecificConfig APPEND PROPERTY LABELS translators) + diff --git a/test/lib/usd/translators/testUsdImportExportSiteSpecificConfig.py b/test/lib/usd/translators/testUsdImportExportSiteSpecificConfig.py new file mode 100644 index 0000000000..1bcb3a6b08 --- /dev/null +++ b/test/lib/usd/translators/testUsdImportExportSiteSpecificConfig.py @@ -0,0 +1,90 @@ +#!/usr/bin/env mayapy +# +# Copyright 2022 Autodesk +# +# 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. +# + +# Sample translated from C++ from +# test/lib/usd/plugin/infoImportChaser.cpp and +# test/lib/usd/translators/testUsdImportChaser.py + +import mayaUsd.lib as mayaUsdLib + +from pxr import UsdGeom +from pxr import Usd + +from maya import cmds +import maya.api.OpenMaya as OpenMaya +from maya import standalone + +import fixturesUtils, os + +import unittest + +class TestExportChaser(mayaUsdLib.ExportChaser): + CalledAsExpected = False + def __init__(self, factoryContext, *args, **kwargs): + super(TestExportChaser, self).__init__(factoryContext, *args, **kwargs) + TestExportChaser.CalledAsExpected = factoryContext.GetJobArgs().exportDisplayColor + if "auto" != factoryContext.GetJobArgs().exportSkin: + TestExportChaser.CalledAsExpected = False + if "TestExportChaserFromSiteSpecific" not in factoryContext.GetJobArgs().chaserNames: + TestExportChaser.CalledAsExpected = False + if "TestExportChaserFromSiteSpecific" not in factoryContext.GetJobArgs().allChaserArgs or\ + "frob" not in factoryContext.GetJobArgs().allChaserArgs["TestExportChaserFromSiteSpecific"]: + TestExportChaser.CalledAsExpected = False + +class TestImportChaser(mayaUsdLib.ImportChaser): + CalledAsExpected = False + def __init__(self, factoryContext, *args, **kwargs): + super(TestImportChaser, self).__init__(factoryContext, *args, **kwargs) + TestImportChaser.CalledAsExpected = factoryContext.GetJobArgs().useAsAnimationCache + if "phong" != factoryContext.GetJobArgs().preferredMaterial: + TestImportChaser.CalledAsExpected = False + if "TestImportChaserFromSiteSpecific" not in factoryContext.GetJobArgs().chaserNames: + TestImportChaser.CalledAsExpected = False + if "TestImportChaserFromSiteSpecific" not in factoryContext.GetJobArgs().allChaserArgs or\ + "frob" not in factoryContext.GetJobArgs().allChaserArgs["TestImportChaserFromSiteSpecific"]: + TestImportChaser.CalledAsExpected = False + + +class testSiteSpecificConfig(unittest.TestCase): + @classmethod + def setUpClass(cls): + fixturesUtils.setUpClass(__file__) + cls.temp_dir = os.path.abspath('.') + + @classmethod + def tearDownClass(cls): + standalone.uninitialize() + + def testChasers(self): + mayaUsdLib.ImportChaser.Register(TestImportChaser, "TestImportChaserFromSiteSpecific") + mayaUsdLib.ExportChaser.Register(TestExportChaser, "TestExportChaserFromSiteSpecific") + + cmds.polyCube() + + # Export scene, which should use site-specific settings and trigger the chaser: + usd_file_path = os.path.join(self.temp_dir, "SiteSpecificFile.usda") + cmds.mayaUSDExport(file=usd_file_path) + + # Import scene, which should use site-specific settings and trigger the chaser: + cmds.mayaUSDImport(file=usd_file_path) + + self.assertTrue(TestExportChaser.CalledAsExpected) + self.assertTrue(TestImportChaser.CalledAsExpected) + + +if __name__ == '__main__': + unittest.main(verbosity=2)