Skip to content

Commit

Permalink
EMSUSD-215 support custom display name for USD attributes
Browse files Browse the repository at this point in the history
Add support to modify the names of USD attributes to nicer names for UI display
purpose. We already had an algorithm to automatically make the names prettier,
this adds support for user-defined attribute names.

The user-defined attribute names are defined in a JSON file named
"attribute_mappings.json". There are two such files in two locations:
- one in the `lib` folder under the installation folder of the plugin.
- one in the `prefs` folder of the user Maya folder.

Each such file contains a section for prefixes to be removed and a section to
map attribute names to nicer names. Note that the mappings are applied after
the prefixes are removed. The format of these JSON files is shown in the
following example:

      {
          "version": 1.0,
          "removed_prefixes": [ "abc", "def" ],
          "attribute_mappings": {
              "example-attribute-name": "example-display-name",
              "foo": "bar",
          },
      }

The built-in attribute mappings do the following:
- Remove the "xformOp:" prefix.
- Map "xfor
- Map "xformOpOrder" to "Transform Order".

Modify the USD attribute-related classes:
- Add a displayName funtion to the UsdAttrbute class.
- Add a displayName funtion to the UsdAttributeHolder class.
- Add a displayName funtion to the UsdShaderAttributeHolder class.

Add support for display name in the Attribute Editor template:
- Refactor custom-control for various types into their own files.
- Add a AttributeCustomControl base class to handle display names.
- Make the default control creation use the display names.

Add new support functions:
- Add new JSON helper function to convert floating-point values.
- Add the getMayaPrefDir function to get the preference folder.
- Add the joinPaths function to join together multiple file paths.
- Add loadAttributeNameMappings function to load the user-defined attribute name mapping from the JSON file.
- Add getAttributeDisplayName function to convert an attribute name into its display name.
- Use the plugin location to derive the built-in file location.

Added a simple unit test.
  • Loading branch information
pierrebai-adsk committed Nov 29, 2023
1 parent 0db534b commit c512522
Show file tree
Hide file tree
Showing 27 changed files with 823 additions and 359 deletions.
13 changes: 12 additions & 1 deletion lib/mayaUsd/resources/ae/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ install(FILES __init__.py DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/ufe_ae/
set(MAYAUSD_AE_TEMPLATES usdschemabase)

foreach(_SUBDIR ${MAYAUSD_AE_TEMPLATES})
install(FILES ${_SUBDIR}/__init__.py ${_SUBDIR}/custom_image_control.py ${_SUBDIR}/custom_enum_control.py ${_SUBDIR}/ae_template.py
install(FILES
${_SUBDIR}/__init__.py
${_SUBDIR}/ae_template.py
${_SUBDIR}/ae_auto_template.py
${_SUBDIR}/array_custom_control.py
${_SUBDIR}/attribute_custom_control.py
${_SUBDIR}/connections_custom_control.py
${_SUBDIR}/enum_custom_control.py
${_SUBDIR}/image_custom_control.py
${_SUBDIR}/metadata_custom_control.py
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/ufe_ae/usd/nodes/${_SUBDIR}
)
endforeach()

install(FILES __init__.py DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/python/${PROJECT_NAME})

install(FILES "attribute_mappings.json" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
7 changes: 7 additions & 0 deletions lib/mayaUsd/resources/ae/attribute_mappings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": 1.0,
"removed_prefixes": [ "xformOp:" ],
"attribute_mappings": {
"xformOpOrder": "Transform Order"
}
}
2 changes: 1 addition & 1 deletion lib/mayaUsd/resources/ae/usdschemabase/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .ae_template import AETemplate
from .custom_enum_control import customEnumControlCreator
import ufe
if hasattr(ufe.Attributes, "getEnums"):
from .enum_custom_control import customEnumControlCreator
AETemplate.prependControlCreator(customEnumControlCreator)
30 changes: 30 additions & 0 deletions lib/mayaUsd/resources/ae/usdschemabase/ae_auto_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2023 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.
#

import maya.cmds as cmds

class AEUITemplate:
'''
Helper class to push/pop the Attribute Editor Template. This makes
sure that controls are aligned properly.
'''

def __enter__(self):
cmds.setUITemplate('attributeEditorTemplate', pst=True)
return self

def __exit__(self, mytype, value, tb):
cmds.setUITemplate(ppt=True)

Loading

0 comments on commit c512522

Please sign in to comment.