Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAYA-114977 Updated documentation + unit test #2105

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
24 changes: 16 additions & 8 deletions plugin/pxr/doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
```

Expand Down
12 changes: 12 additions & 0 deletions test/lib/usd/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

30 changes: 30 additions & 0 deletions test/lib/usd/plugin/plugInfoSiteSpecificConfig.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
9 changes: 9 additions & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

90 changes: 90 additions & 0 deletions test/lib/usd/translators/testUsdImportExportSiteSpecificConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env mayapy
#
# Copyright 2021 Autodesk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should start putting 2022. :)

#
# 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)