Skip to content

Commit

Permalink
Merge pull request #1699 from Autodesk/boudrey/MAYA-113469/register
Browse files Browse the repository at this point in the history
Boudrey/maya 113469/register
  • Loading branch information
Krystian Ligenza committed Sep 16, 2021
2 parents 1ce152e + 4b06569 commit 0c906e8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
21 changes: 19 additions & 2 deletions lib/mayaUsd/python/wrapAdaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <mayaUsd/fileio/registryHelper.h>
#include <mayaUsd/fileio/utils/adaptor.h>
#include <mayaUsd/utils/undoHelperCommand.h>
#include <mayaUsd/utils/util.h>
Expand Down Expand Up @@ -173,6 +174,20 @@ static std::string _AttributeAdaptor__repr__(const UsdMayaAdaptor::AttributeAdap
}
}

static void RegisterTypedSchemaConversion(const std::string& nodeTypeName, const TfType& usdType)
{
UsdMaya_RegistryHelper::g_pythonRegistry = true;
UsdMayaAdaptor::RegisterTypedSchemaConversion(nodeTypeName, usdType);
UsdMaya_RegistryHelper::g_pythonRegistry = false;
}

static void RegisterAttributeAlias(const TfToken& attributeName, const std::string& alias)
{
UsdMaya_RegistryHelper::g_pythonRegistry = true;
UsdMayaAdaptor::RegisterAttributeAlias(attributeName, alias);
UsdMaya_RegistryHelper::g_pythonRegistry = false;
}

void wrapAdaptor()
{
typedef UsdMayaAdaptor This;
Expand Down Expand Up @@ -216,10 +231,12 @@ void wrapAdaptor()
&This::GetRegisteredTypedSchemas,
return_value_policy<TfPySequenceToList>())
.staticmethod("GetRegisteredTypedSchemas")
.def("RegisterAttributeAlias", &This::RegisterAttributeAlias)
.def("RegisterAttributeAlias", &::RegisterAttributeAlias)
.staticmethod("RegisterAttributeAlias")
.def("GetAttributeAliases", &This::GetAttributeAliases)
.staticmethod("GetAttributeAliases");
.staticmethod("GetAttributeAliases")
.def("RegisterTypedSchemaConversion", &::RegisterTypedSchemaConversion)
.staticmethod("RegisterTypedSchemaConversion");

class_<This::SchemaAdaptor>("SchemaAdaptor")
.def(!self)
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/python/wrapOpenMaya.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2016 Pixar
// Copyright 2021 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
5 changes: 0 additions & 5 deletions test/lib/mayaUsd/fileio/testShaderWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ def PostExport(self):
print("shaderWriterTest.PostExport called")
return False

class shaderReaderTest(mayaUsdLib.ShaderReader):
def HasPostReadSubtree(self):
print("shaderReaderTest.HasPostReadSubtree called")
return False

class testShaderWriter(unittest.TestCase):
@classmethod
def setUpClass(cls):
Expand Down
12 changes: 12 additions & 0 deletions test/lib/usd/translators/testUsdMayaAdaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,17 @@ def testGetAttributeAliases(self):
mayaUsdLib.Adaptor.GetAttributeAliases("subdivisionScheme"),
["USD_ATTR_subdivisionScheme", "USD_subdivisionScheme"])

def testAdaptorRegistration(self):
"""Tests Registration Python functions."""
mayaUsdLib.Adaptor.RegisterTypedSchemaConversion("polySphere", UsdGeom.Sphere)
mayaUsdLib.Adaptor.RegisterAttributeAlias(UsdGeom.Tokens.faceVaryingLinearInterpolation,"USD_RegTest")
cmds.file(new=True, force=True)
cmds.createNode("polySphere", name="TestSphere")
self.assertTrue(
mayaUsdLib.Adaptor("TestSphere").GetSchema(UsdGeom.Sphere))
self.assertEqual(
mayaUsdLib.Adaptor.GetAttributeAliases("faceVaryingLinearInterpolation"),
["USD_ATTR_faceVaryingLinearInterpolation", "USD_RegTest", "USD_faceVaryingLinearInterpolation"])

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 0c906e8

Please sign in to comment.