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-107276 - As a user, on the stage AE template I'd like to use Pri… #1189

Merged
merged 10 commits into from
Mar 12, 2021
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
2 changes: 0 additions & 2 deletions lib/mayaUsd/nodes/proxyShapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ MStatus MayaUsdProxyShapeBase::initialize()
retValue = attributeAffects(filePathAttr, outStageCacheIdAttr);
CHECK_MSTATUS_AND_RETURN_IT(retValue);

retValue = attributeAffects(primPathAttr, inStageDataCachedAttr);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the dependency in subclass ProxyShape.
Having this dependency in proxyShapeBase cause issue when using a primPath with a stage that is created in memory.
When computing the inStageDataCachedAttr, when the stage is create in memory, a new stage is created and everything is lost.

Choose a reason for hiding this comment

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

It's worth mentioning why this dependency doesn't belong to the base class - when computing inStageDataCachedAttr, there is nothing that reads primPathAttr unless we are calling into computeSessionLayer implementation of pxr proxy shape - https://github.com/Autodesk/maya-usd/blob/dev/plugin/pxr/maya/lib/usdMaya/proxyShape.cpp#L189

There is still the unwanted effect of clearing the stage on a change to the prim path with pxr proxy shape, but assembly workflows were not working with in-memory stages.

CHECK_MSTATUS_AND_RETURN_IT(retValue);
retValue = attributeAffects(primPathAttr, outStageDataAttr);
CHECK_MSTATUS_AND_RETURN_IT(retValue);
retValue = attributeAffects(primPathAttr, outStageCacheIdAttr);
Expand Down
16 changes: 16 additions & 0 deletions lib/mayaUsd/render/pxrUsdMayaGL/usdProxyShapeAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,26 @@ bool PxrMayaHdUsdProxyShapeAdapter::_Sync(
_renderTags.push_back(HdRenderTagTokens->guide);
}

// Update the root transform used to render by the delagate.
// USD considers that the root prim transform is always the Identity matrix so that means
// the root transform define the root prim transform. When the real stage root is used to
// render this is not a issue because the root transform will be the maya transform.
// The problem is when using a primPath as the root prim, we are losing
// the prim path world transform. So we need to set the root transform as the world
// transform of the prim used for rendering.
MStatus status;
const MMatrix transform = GetDagPath().inclusiveMatrix(&status);
if (status == MS::kSuccess) {
_rootXform = GfMatrix4d(transform.matrix);

if (usdProxyShape->usdPrim().GetPath() != SdfPath::AbsoluteRootPath()) {
const UsdTimeCode timeCode = usdProxyShape->getTime();
UsdGeomXformCache xformCache(timeCode);
GfMatrix4d primTransform
= xformCache.GetLocalToWorldTransform(usdProxyShape->usdPrim());
_rootXform = primTransform * _rootXform;
}

_delegate->SetRootTransform(_rootXform);
}

Expand Down
23 changes: 19 additions & 4 deletions lib/mayaUsd/render/vp2RenderDelegate/proxyRenderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,7 @@ bool ProxyRenderDelegate::_Populate()
}
}
_proxyShapeData->ExcludePrimsUpdated();

_sceneDelegate->Populate(_proxyShapeData->UsdStage()->GetPseudoRoot(), excludePrimPaths);
_sceneDelegate->Populate(_proxyShapeData->ProxyShape()->usdPrim(), excludePrimPaths);
_isPopulated = true;
}

Expand All @@ -604,8 +603,24 @@ void ProxyRenderDelegate::_UpdateSceneDelegate()
_sceneDelegate->SetTime(timeCode);
}

const MMatrix inclusiveMatrix = _proxyShapeData->ProxyDagPath().inclusiveMatrix();
const GfMatrix4d transform(inclusiveMatrix.matrix);
// Update the root transform used to render by the delagate.
// USD considers that the root prim transform is always the Identity matrix so that means
// the root transform define the root prim transform. When the real stage root is used to
// render this is not a issue because the root transform will be the maya transform.
// The problem is when using a primPath as the root prim, we are losing
// the prim path world transform. So we need to set the root transform as the world
// transform of the prim used for rendering.
const MMatrix inclusiveMatrix = _proxyShapeData->ProxyDagPath().inclusiveMatrix();
GfMatrix4d transform(inclusiveMatrix.matrix);

if (_proxyShapeData->ProxyShape()->usdPrim().GetPath() != SdfPath::AbsoluteRootPath()) {
const UsdTimeCode timeCode = _proxyShapeData->ProxyShape()->getTime();
UsdGeomXformCache xformCache(timeCode);
GfMatrix4d m
= xformCache.GetLocalToWorldTransform(_proxyShapeData->ProxyShape()->usdPrim());
transform = m * transform;
}

constexpr double tolerance = 1e-9;
if (!GfIsClose(transform, _sceneDelegate->GetRootTransform(), tolerance)) {
MProfilingScope subProfilingScope(
Expand Down
3 changes: 1 addition & 2 deletions plugin/adsk/scripts/AEmayaUsdProxyShapeBaseTemplate.mel
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ global proc AEmayaUsdProxyShapeBaseTemplate( string $nodeName )
editorTemplate -suppress "outStageCacheId";

// MAYA-109438 - temp suppress these non-functional attributes.
editorTemplate -suppress "primPath";
editorTemplate -suppress "loadPayloads";

editorTemplate -beginLayout `getMayaUsdString("kLabelStage")` -collapse 0;
Expand All @@ -108,7 +107,7 @@ global proc AEmayaUsdProxyShapeBaseTemplate( string $nodeName )
"drawGuidePurpose"
"drawProxyPurpose"
"drawRenderPurpose";
//editorTemplate -addControl "primPath";
editorTemplate -addControl "primPath";
editorTemplate -ann `getMayaUsdString("kExcludePrimPathsAnn")`
-addControl "excludePrimPaths";
editorTemplate -endLayout;
Expand Down
4 changes: 2 additions & 2 deletions plugin/adsk/scripts/mayaUSDRegisterStrings.mel
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ global proc mayaUSDRegisterStrings() {
register("kPurposeOption2", "Proxy");
register("kPurposeOption3", "Render");
register("kPrimPath", "Prim Path:");
register("kPrimPathAnn", "Loads the specified prim path. If a matching prim path is not found, all prims in the file are loaded.");
register("kPrimPathSbm", "Loads the specified prim path");
register("kPrimPathAnn", "Specify the path of a prim to display it alone in the viewport. If a prim path is not specified or a matching prim path is not found, all prims in the stage are displayed.");
register("kPrimPathSbm", "Specify the path of a prim to display it alone in the viewport.");
register("kRootLayer", "Root Layer");
register("kRootLayerAnn", "Identifies the root layer of a stage. If a file path is shown in this field, the root layer is a file on disk. If a layerName is shown in this field, the root layer is an anonymous layer.");
register("kSaveAndClose", "Save and Close");
Expand Down
2 changes: 1 addition & 1 deletion plugin/pxr/maya/lib/usdMaya/proxyShape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ MStatus UsdMayaProxyShape::initialize()
//
retValue = attributeAffects(variantKeyAttr, inStageDataCachedAttr);
retValue = attributeAffects(variantKeyAttr, outStageDataAttr);

retValue = attributeAffects(primPathAttr, inStageDataCachedAttr);
return retValue;
}

Expand Down
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/vp2RenderDelegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ if (CMAKE_UFE_V2_FEATURES_AVAILABLE AND PXR_VERSION GREATER_EQUAL 2008)
list(APPEND TEST_SCRIPT_FILES
testVP2RenderDelegatePointInstanceSelection.py
testVP2RenderDelegatePointInstancesPickMode.py
testVP2RenderDelegatePrimPath.py
)
endif()

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env mayapy
#
# 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.
# 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 fixturesUtils
import imageUtils
import mayaUtils
import usdUtils

from mayaUsd import lib as mayaUsdLib
from mayaUsd import ufe as mayaUsdUfe

from maya import cmds

import ufe

import os


class testVP2RenderDelegatePrimPath(imageUtils.ImageDiffingTestCase):
"""
Tests imaging using the Viewport 2.0 render delegate when using a primPath.
"""

@classmethod
def setUpClass(cls):
# The test USD data is authored Y-up, so make sure Maya is configured
# that way too.
cmds.upAxis(axis='y')

inputPath = fixturesUtils.setUpClass(__file__, initializeStandalone=False, loadPlugin=False)
cls._baselineDir = os.path.join(inputPath,'VP2RenderDelegatePrimPathTest', 'baseline')
cls._testDir = os.path.abspath('.')

def assertSnapshotClose(self, imageName):
baselineImage = os.path.join(self._baselineDir, imageName)
snapshotImage = os.path.join(self._testDir, imageName)
imageUtils.snapshot(snapshotImage, width=960, height=540)
return self.assertImagesClose(baselineImage, snapshotImage)

@staticmethod
def _GetUfePath(name):
mayaSegment = mayaUtils.createUfePathSegment('|stage1|stageShape1')
usdSegmentString = mayaUsdUfe.usdPathToUfePathSegment(name, -1)
usdSegment = usdUtils.createUfePathSegment(usdSegmentString)
ufePath = ufe.Path([mayaSegment, usdSegment])
return ufePath

@staticmethod
def _GetSceneItem(name):
ufePath = testVP2RenderDelegatePrimPath._GetUfePath(name)
ufeItem = ufe.Hierarchy.createItem(ufePath)
return ufeItem

def testPrimPath(self):

def testSinglePrim(primPath, imageName):
cmds.setAttr( 'stageShape1.primPath', primPath, type="string")
self.assertSnapshotClose('%s.png' % imageName)

globalSelection = ufe.GlobalSelection.get()
sceneItem = testVP2RenderDelegatePrimPath._GetSceneItem(primPath)
globalSelection.append(sceneItem)

cmds.move(-5,0,0, relative=True)
self.assertSnapshotClose('%s_moved.png' % imageName)

mayaUtils.openPrimPathScene()

globalSelection = ufe.GlobalSelection.get()
globalSelection.clear()
self.assertSnapshotClose('initial.png')

testSinglePrim("/Cube1", "Cube1")
testSinglePrim("/Cube1/Cube2", "Cube2")
testSinglePrim("/Cube1/Cube2/Cube3", "Cube3")

cmds.setAttr( 'stageShape1.primPath', "", type="string")
self.assertSnapshotClose('final.png')

# Test with a invalid prime path
# Nothing should change in the viewport
cmds.setAttr( 'stageShape1.primPath', "/invalidPrim", type="string")
self.assertSnapshotClose('final.png')


if __name__ == '__main__':
fixturesUtils.runTests(globals())
Loading