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

Disable edit as Maya for materials. #2631

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions lib/usd/translators/plugInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"PrimUpdater": {
"providesTranslator": [
"UsdShadeMaterial",
"MayaUsd_SchemasALMayaReference",
"MayaUsd_SchemasMayaReference"
]
Expand Down
8 changes: 8 additions & 0 deletions lib/usd/translators/shading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ if (MAYA_APP_VERSION VERSION_GREATER_EQUAL 2020)
)
endif()

# Edit as Maya requires UFE path mapping.
if(CMAKE_UFE_V3_FEATURES_AVAILABLE)
target_sources(${TARGET_NAME}
PRIVATE
materialUpdater.cpp
)
endif()

# These import/export classes will work with older versions of Maya and USD if
# you plan to render in usdView or other MaterialX-aware renderers. However,
# getting these materials to appear in the Maya viewport when creating a USD
Expand Down
46 changes: 46 additions & 0 deletions lib/usd/translators/shading/materialUpdater.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright 2022 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.
//
#include "materialUpdater.h"

#include "shadingTokens.h"

#include <mayaUsd/fileio/primUpdaterRegistry.h>

#include <pxr/pxr.h>
#include <pxr/usd/usdShade/material.h>

#include <basePxrUsdPreviewSurface/usdPreviewSurface.h>

PXR_NAMESPACE_OPEN_SCOPE

PXRUSDMAYA_REGISTER_UPDATER(
UsdShadeMaterial,
usdPreviewSurface,
MaterialUpdater,
UsdMayaPrimUpdater::Supports::Invalid);

MaterialUpdater::MaterialUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path)
: UsdMayaPrimUpdater(context, depNodeFn, path)
{
}

/* virtual */
bool MaterialUpdater::canEditAsMaya() const { return false; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the single important line of this pull request: disabling edit as Maya for materials, as per design's request. Perhaps we will find a workflow that will allow this in the future, but for now edit as Maya on a material does nothing and produces a warning.


PXR_NAMESPACE_CLOSE_SCOPE
39 changes: 39 additions & 0 deletions lib/usd/translators/shading/materialUpdater.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2022 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.
//
#pragma once

#include <mayaUsd/fileio/primUpdater.h>

PXR_NAMESPACE_OPEN_SCOPE

class MaterialUpdater : public UsdMayaPrimUpdater
{
public:
MAYAUSD_CORE_PUBLIC
MaterialUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path);

/// As of 16-Sep-2022, prims of type Material cannot be pulled by
/// themselves, so this method returns false. Materials can only be edited
/// as Maya when associated with pulled Dag nodes. This may change in
/// future versions of maya-usd.
MAYAUSD_CORE_PUBLIC
bool canEditAsMaya() const override;
};

PXR_NAMESPACE_CLOSE_SCOPE
18 changes: 9 additions & 9 deletions test/lib/mayaUsd/fileio/testEditAsMaya.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import fixturesUtils

from usdUtils import createSimpleXformScene
from ufeUtils import ufeFeatureSetVersion

from maya import OpenMaya as OM
from maya import OpenMayaAnim as OMA
Expand Down Expand Up @@ -65,7 +64,6 @@ def tearDownClass(cls):
def setUp(self):
cmds.file(new=True, force=True)

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The CMakeLists.txt file explicitly adds this test file only for UFE v3, so further checking in the test is redundant.

def testCannotEditAsMayaAnAncestor(self):
'''Test that trying to edit an ancestor is not allowed.'''

Expand All @@ -82,7 +80,6 @@ def testCannotEditAsMayaAnAncestor(self):
self.assertFalse(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(aUsdUfePathStr))
self.assertFalse(mayaUsd.lib.PrimUpdaterManager.editAsMaya(aUsdUfePathStr))

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testEditAsMayaPreserveTimeline(self):
'''Test that edit does not change the timeline start and end.'''

Expand Down Expand Up @@ -114,7 +111,6 @@ def verifyTimeline():

verifyTimeline()

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testTransformEditAsMaya(self):
'''Edit a USD transform as a Maya object.'''

Expand Down Expand Up @@ -164,7 +160,6 @@ def testTransformEditAsMaya(self):

assertVectorAlmostEqual(self, mayaValues, usdValues)

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testEditAsMayaUndoRedo(self):
'''Edit a USD transform as a Maya object and apply undo and redo.'''

Expand Down Expand Up @@ -286,7 +281,6 @@ def testEditAsMayaUIInfo(self):
self.assertEqual('', icon.baseIcon)
self.assertEqual(ufe.UIInfoHandler.Disabled, icon.mode)

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testIllegalEditAsMaya(self):
'''Trying to edit as Maya on object that doesn't support it.'''

Expand All @@ -296,6 +290,8 @@ def testIllegalEditAsMaya(self):
stage = mayaUsd.lib.GetPrim(proxyShapePathStr).GetStage()
blendShape = stage.DefinePrim('/BlendShape1', 'BlendShape')
scope = stage.DefinePrim('/Scope1', 'Scope')
scope = stage.DefinePrim('/Mesh1', 'Mesh')
scope = stage.DefinePrim('/Material1', 'Material')

blendShapePathStr = proxyShapePathStr + ',/BlendShape1'
scopePathStr = proxyShapePathStr + ',/Scope1'
Expand All @@ -312,8 +308,14 @@ def testIllegalEditAsMaya(self):
# with mayaUsd.lib.OpUndoItemList():
# self.assertFalse(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(scopePathStr))
# self.assertFalse(mayaUsd.lib.PrimUpdaterManager.editAsMaya(scopePathStr))

# Mesh can be edited as Maya.
self.assertTrue(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(proxyShapePathStr + ',/Mesh1'))

# Material cannot be edited as Maya: it explicitly disables this
# capability.
self.assertFalse(mayaUsd.lib.PrimUpdaterManager.canEditAsMaya(proxyShapePathStr + ',/Material1'))

@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testSessionLayer(self):
'''Verify that the edit gets on the sessionLayer instead of the editTarget layer.'''

Expand Down Expand Up @@ -345,8 +347,6 @@ def testSessionLayer(self):

self.assertEqual(prim.GetCustomDataByKey(kPullPrimMetadataKey), None)


@unittest.skipUnless(ufeFeatureSetVersion() >= 3, 'Test only available in UFE v3 or greater.')
def testTargetLayer(self):
'''Verify that the target layer is not moved after Edit As Maya.'''

Expand Down