From 41551e39f680dabdd3800742b343e6a4779b7a32 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Thu, 13 Aug 2020 16:24:03 -0400 Subject: [PATCH 1/3] MAYA-106190 - As a user, I would like see prim type icons * Implement new ancestorNodeTypes() method on Ufe::SceneItem. --- lib/mayaUsd/ufe/UsdSceneItem.cpp | 38 ++++++++++++++++++++++++++++++++ lib/mayaUsd/ufe/UsdSceneItem.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/lib/mayaUsd/ufe/UsdSceneItem.cpp b/lib/mayaUsd/ufe/UsdSceneItem.cpp index 2d50c39896..4c9e65cb9a 100644 --- a/lib/mayaUsd/ufe/UsdSceneItem.cpp +++ b/lib/mayaUsd/ufe/UsdSceneItem.cpp @@ -15,6 +15,12 @@ // #include "UsdSceneItem.h" +#include +#include +#if USD_VERSION_NUM >= 2008 +#include +#endif + MAYAUSD_NS_DEF { namespace ufe { @@ -39,5 +45,37 @@ std::string UsdSceneItem::nodeType() const return fPrim.GetTypeName(); } +#if UFE_PREVIEW_VERSION_NUM >= 2020 +std::vector UsdSceneItem::ancestorNodeTypes() const +{ + const UsdPrimTypeInfo& typeInfo = fPrim.GetPrimTypeInfo(); + const TfType& schemaType = typeInfo.GetSchemaType(); + + // According to the USD docs GetAllAncestorTypes() is expensive, so we keep a cache. + static std::map> ancestorTypesCache; + const auto iter = ancestorTypesCache.find(schemaType); + if (iter != ancestorTypesCache.end()) { + return iter->second; + } + + std::vector strAncestorTypes; + std::vector tfAncestorTypes; + schemaType.GetAllAncestorTypes(&tfAncestorTypes); + for (const TfType& ty : tfAncestorTypes) + { +#if USD_VERSION_NUM >= 2008 + // If there is a concrete schema type name, we'll return that since it is what + // is used/shown in the UI (ex: 'Xform' vs 'UsdGeomXform'). + auto concreteType = UsdSchemaRegistry::GetConcreteSchemaTypeName(ty); + strAncestorTypes.emplace_back(!concreteType.IsEmpty() ? concreteType : ty.GetTypeName()); +#else + strAncestorTypes.emplace_back(ty.GetTypeName()); +#endif + } + ancestorTypesCache[schemaType] = strAncestorTypes; + return strAncestorTypes; +} +#endif + } // namespace ufe } // namespace MayaUsd diff --git a/lib/mayaUsd/ufe/UsdSceneItem.h b/lib/mayaUsd/ufe/UsdSceneItem.h index 0e6fc5044c..727dedd15b 100644 --- a/lib/mayaUsd/ufe/UsdSceneItem.h +++ b/lib/mayaUsd/ufe/UsdSceneItem.h @@ -48,6 +48,9 @@ class MAYAUSD_CORE_PUBLIC UsdSceneItem : public Ufe::SceneItem // Ufe::SceneItem overrides std::string nodeType() const override; +#if UFE_PREVIEW_VERSION_NUM >= 2020 + std::vector ancestorNodeTypes() const override; +#endif private: UsdPrim fPrim; From 698c546b83921f94be593792bd36789142f57731 Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Thu, 13 Aug 2020 17:15:23 -0400 Subject: [PATCH 2/3] MAYA-106190 - As a user, I would like see prim type icons * Adding test for UsdSceneItem. --- test/lib/ufe/CMakeLists.txt | 1 + test/lib/ufe/testSceneItem.py | 63 +++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 test/lib/ufe/testSceneItem.py diff --git a/test/lib/ufe/CMakeLists.txt b/test/lib/ufe/CMakeLists.txt index dabe2aa3a5..5b66c1ba78 100644 --- a/test/lib/ufe/CMakeLists.txt +++ b/test/lib/ufe/CMakeLists.txt @@ -28,6 +28,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE) testParentCmd.py testRotateCmd.py testScaleCmd.py + testSceneItem.py testTransform3dTranslate.py ) if(UFE_PREVIEW_VERSION_NUM GREATER_EQUAL 2009) diff --git a/test/lib/ufe/testSceneItem.py b/test/lib/ufe/testSceneItem.py new file mode 100644 index 0000000000..d434936199 --- /dev/null +++ b/test/lib/ufe/testSceneItem.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python + +# +# Copyright 2020 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 + +from ufeTestUtils import usdUtils, mayaUtils +import ufe + +import unittest +import os + +class SceneItemTestCase(unittest.TestCase): + '''Verify the SceneItem UFE interface. + ''' + + pluginsLoaded = False + + @classmethod + def setUpClass(cls): + if not cls.pluginsLoaded: + cls.pluginsLoaded = mayaUtils.isMayaUsdPluginLoaded() + + def setUp(self): + ''' Called initially to set up the maya test environment ''' + self.assertTrue(self.pluginsLoaded) + + # Open top_layer.ma scene in test-samples + mayaUtils.openTopLayerScene() + + @unittest.skipIf(os.getenv('UFE_PREVIEW_VERSION_NUM', '0000') < '2020', 'testNodeTypes only available in UFE preview version 0.2.20 and greater') + def testNodeTypes(self): + '''Engine method to run scene item test.''' + + # Get a UFE scene item for one of the balls in the scene. + ball35Path = ufe.Path([ + mayaUtils.createUfePathSegment("|world|transform1|proxyShape1"), + usdUtils.createUfePathSegment("/Room_set/Props/Ball_35")]) + ball35Item = ufe.Hierarchy.createItem(ball35Path) + + # Ball35 is an Xform. + ball35NodeType = ball35Item.nodeType() + self.assertEqual(ball35NodeType, "Xform") + + # This node type should be the first item on the ancestor node type list + # and it should have other items. + ball35AncestorNodeTypes = ball35Item.ancestorNodeTypes() + self.assertEqual(ball35NodeType, ball35AncestorNodeTypes[0]) + self.assertTrue(len(ball35AncestorNodeTypes) > 1) From ad17063186fb9459ce5efb378c8805f75c61e9db Mon Sep 17 00:00:00 2001 From: Sean Donnelly <23455376+seando-adsk@users.noreply.github.com> Date: Wed, 19 Aug 2020 15:46:52 -0400 Subject: [PATCH 3/3] MAYA-106190 - As a user, I would like see prim type icons * Rework to support previous versions (down to 19.11) of USD. --- lib/mayaUsd/ufe/UsdSceneItem.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/mayaUsd/ufe/UsdSceneItem.cpp b/lib/mayaUsd/ufe/UsdSceneItem.cpp index 4c9e65cb9a..221aaf59de 100644 --- a/lib/mayaUsd/ufe/UsdSceneItem.cpp +++ b/lib/mayaUsd/ufe/UsdSceneItem.cpp @@ -16,7 +16,11 @@ #include "UsdSceneItem.h" #include +#if USD_VERSION_NUM < 2005 +#include +#else #include +#endif #if USD_VERSION_NUM >= 2008 #include #endif @@ -48,8 +52,20 @@ std::string UsdSceneItem::nodeType() const #if UFE_PREVIEW_VERSION_NUM >= 2020 std::vector UsdSceneItem::ancestorNodeTypes() const { - const UsdPrimTypeInfo& typeInfo = fPrim.GetPrimTypeInfo(); - const TfType& schemaType = typeInfo.GetSchemaType(); + std::vector strAncestorTypes; + +#if USD_VERSION_NUM < 2005 + static const TfType schemaBaseType = TfType::Find(); + const TfType schemaType = schemaBaseType.FindDerivedByName(fPrim.GetTypeName().GetString()); +#else + // Get the actual schema type from the prim definition. + const TfType& schemaType = fPrim.GetPrimTypeInfo().GetSchemaType(); +#endif + if (!schemaType) { + TF_CODING_ERROR("Could not find prim type '%s' for prim %s", + fPrim.GetTypeName().GetText(), UsdDescribe(fPrim).c_str()); + return strAncestorTypes; + } // According to the USD docs GetAllAncestorTypes() is expensive, so we keep a cache. static std::map> ancestorTypesCache; @@ -58,7 +74,6 @@ std::vector UsdSceneItem::ancestorNodeTypes() const return iter->second; } - std::vector strAncestorTypes; std::vector tfAncestorTypes; schemaType.GetAllAncestorTypes(&tfAncestorTypes); for (const TfType& ty : tfAncestorTypes)