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-106190 - As a user, I would like see prim type icons #712

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
38 changes: 38 additions & 0 deletions lib/mayaUsd/ufe/UsdSceneItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
//
#include "UsdSceneItem.h"

#include <pxr/base/tf/type.h>
#include <pxr/usd/usd/primTypeInfo.h>
#if USD_VERSION_NUM >= 2008
#include <pxr/usd/usd/schemaRegistry.h>
#endif

MAYAUSD_NS_DEF {
namespace ufe {

Expand All @@ -39,5 +45,37 @@ std::string UsdSceneItem::nodeType() const
return fPrim.GetTypeName();
}

#if UFE_PREVIEW_VERSION_NUM >= 2020
std::vector<std::string> 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<TfType, std::vector<std::string>> ancestorTypesCache;
const auto iter = ancestorTypesCache.find(schemaType);
if (iter != ancestorTypesCache.end()) {
return iter->second;
}
Comment on lines +70 to +75
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Keep a cache (key'd by schema type) for faster lookup.


std::vector<std::string> strAncestorTypes;
std::vector<TfType> 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
3 changes: 3 additions & 0 deletions lib/mayaUsd/ufe/UsdSceneItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> ancestorNodeTypes() const override;
#endif

private:
UsdPrim fPrim;
Expand Down
1 change: 1 addition & 0 deletions test/lib/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
63 changes: 63 additions & 0 deletions test/lib/ufe/testSceneItem.py
Original file line number Diff line number Diff line change
@@ -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)