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-104213 - add a new USD stage to an empty scene #478

Merged
merged 3 commits into from
May 12, 2020

Conversation

seando-adsk
Copy link
Collaborator

MAYA-104213 - As a user, I'd like to add a new USD stage to an empty scene

  • New USD notice type for stage invalidate. Send this notice when certain attributes (like filepath) are changed. From the StagesSubject receiver of this notice we also send the new Ufe::ObjectInvalidate() notification.
  • When proxy shape compute is called if no filepath was attached, we create an in memory stage.
  • Added dirty state to UsdStageMap. When dirty it will rebuild when a new request for stage info is made.
  • Cleanup: renamed "UsdMayaProxyStageSetNotice" -> "MayaUsdProxyStageSetNotice".
  • Added new menu item "Stage with New Layer".

…scene

* New USD notice type for stage invalidate. Send this notice
  when certain attributes (like filepath) are changed.
  From the StagesSubject receiver of this notice we also send
  the new Ufe::ObjectInvalidate() notification.
* When proxy shape compute is called if no filepath was
  attached, we create an in memory stage.
* Added dirty state to UsdStageMap. When dirty it will
  rebuild when a new request for stage info is made.
* Cleanup: renamed "UsdMayaProxyStageSetNotice" ->
  "MayaUsdProxyStageSetNotice".
* Added new menu item "Stage with New Layer".
@@ -27,11 +27,11 @@ PXR_NAMESPACE_OPEN_SCOPE
class MayaUsdProxyShapeBase;

/// Notice sent when the ProxyShape loads a new stage
class UsdMayaProxyStageSetNotice : public TfNotice
class MayaUsdProxyStageBaseNotice : public TfNotice
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Renamed this one "UsdMaya" -> "MayaUsd" and made it a base notice class. Below created this existing one (deriving from this base) and new one for stage invalidate.

else if (!usdStage) {
// Create a new stage in memory with an anonymous root layer.
UsdStageCacheContext ctx(UsdMayaStageCache::Get());
usdStage = UsdStage::CreateInMemory("", loadSet);
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 empty string is for the identifier, which is used when naming the root layer. Here we just want it named as the default "anon", rather than "tmp.usda"

@@ -797,6 +802,7 @@ MayaUsdProxyShapeBase::setDependentsDirty(const MPlug& plug, MPlugArray& plugArr
plug == loadPayloadsAttr ||
plug == inStageDataAttr) {
_IncreaseUsdStageVersion();
MayaUsdProxyStageInvalidateNotice(*this).Send();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Send the new stage invalidate notice whenever one of the plugs that affects outStageDataAttr changes.

Comment on lines -174 to -179
StagesSubject::Ptr me(this);
for (auto stage : ProxyShapeHandler::getAllStages())
{
fStageListeners[stage] = TfNotice::Register(
me, &StagesSubject::stageChanged, stage);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We should not get the stages here as that will pull, but the new stage may not be ready yet.

Comment on lines -187 to -195
g_StageMap.clear();
auto proxyShapeNames = ProxyShapeHandler::getAllNames();
for (const auto& psn : proxyShapeNames)
{
MDagPath dag = nameToDagPath(psn);
Ufe::Path ufePath = dagPathToUfe(dag);
auto stage = ProxyShapeHandler::dagPathToStage(psn);
g_StageMap.addItem(ufePath, stage);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All this code was moved into the stage map. We just set it dirty now. It will be rebuilt when queried.

Comment on lines +286 to +290
#if UFE_PREVIEW_VERSION_NUM >= 2014
Ufe::SceneItem::Ptr sceneItem = Ufe::Hierarchy::createItem(notice.GetProxyShape().ufePath());
auto notification = Ufe::SubtreeInvalidate(sceneItem);
Ufe::Scene::notifySubtreeInvalidate(notification);
#endif
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Send a new UFE subtree invalidate notice when the stage is invalidated. Clients like the Outliner can use this to re-build.

Comment on lines +96 to +98
UsdStageWeakPtr UsdStageMap::stage(const Ufe::Path& path)
{
rebuildIfDirty();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the query methods on the stage map, will now rebuild first if the map is flagged as dirty.

Comment on lines +134 to +141
auto proxyShapeNames = ProxyShapeHandler::getAllNames();
for (const auto& psn : proxyShapeNames)
{
MDagPath dag = nameToDagPath(psn);
Ufe::Path ufePath = dagPathToUfe(dag);
auto stage = ProxyShapeHandler::dagPathToStage(psn);
addItem(ufePath, stage);
}
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 code was moved from the StagesSubject.

@@ -103,6 +112,7 @@ global proc mayaUsdMenu_createMenuCallback() {
-label "Universal Scene Description (USD)"
-annotation "Create a USD stage"
-version $mayaVersion`;
menuItem -runTimeCommand mayaUsdCreateStageWithNewLayer;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New menu item to create a new empty USD stage.

# Simply create a proxy shape. Since it does not have a USD file associated
# (in the .filePath attribute), the proxy shape base will create an empty
# stage in memory. This will create the session and root layer as well.
shapeNode = cmds.createNode('mayaUsdProxyShape', name='stageShape')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because of the changes in the proxyshapebase (to create stage in memory when no file attr) we simply need to create a proxy shape node here. That will create the stage, which will create the root layer and session layer.

@seando-adsk
Copy link
Collaborator Author

@pilarmolinalopez Would you be available to review these changes?

@kxl-adsk kxl-adsk added proxy Related to base proxy shape workflows Related to in-context workflows labels May 4, 2020
Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@pilarmolinalopez pilarmolinalopez left a comment

Choose a reason for hiding this comment

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

Looks good to me!

Copy link

@kxl-adsk kxl-adsk left a comment

Choose a reason for hiding this comment

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

The following tests FAILED:
12 - testObject3d (Failed)
15 - testTransform3dTranslate (Failed)
99 - TestPxrUsdTranslators (Failed)

…scene

* Fix broken unitttests:
    12 - testObject3d (Failed)
    15 - testTransform3dTranslate (Failed)
    99 - TestPxrUsdTranslators (Failed)
@seando-adsk
Copy link
Collaborator Author

@kxl-adsk I fixed the three failing tests with c5bc21d.

@kxl-adsk kxl-adsk requested a review from robthebloke May 6, 2020 20:29
@@ -398,6 +398,18 @@ MStatus ProxyShape::setDependentsDirty(const MPlug& plugBeingDirtied, MPlugArray
{
MHWRender::MRenderer::setGeometryDrawDirty(thisMObject(), true);
}

if (plugBeingDirtied == outStageData() ||
Copy link

Choose a reason for hiding this comment

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

ProxyShapeBase is a base class...shouldn't we just forward it to the base class instead of making a copy?

@kxl-adsk kxl-adsk merged commit 2fbabab into dev May 12, 2020
@kxl-adsk kxl-adsk deleted the donnels/MAYA-104213/add_new_usd_stage_to_empty_scene branch May 12, 2020 14:20
ppt-adsk pushed a commit that referenced this pull request Sep 27, 2023
Changes:
1.fix light transform and material binding issues due to usd 23.08
2.make mayaHydraSceneIndex derive from HdRetainedScneIndex in usd 23.08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proxy Related to base proxy shape workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants