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

Use new HdSceneIndex APIs. #3275

Closed
wants to merge 3 commits into from
Closed
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
40 changes: 33 additions & 7 deletions lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,26 @@

#include <usdUfe/ufe/Utils.h>

#include <pxr/imaging/hd/retainedDataSource.h>

#if USD_IMAGING_API_VERSION >= 20
#include <pxr/usdImaging/usdImaging/sceneIndices.h>
#else
#include <pxr/imaging/hd/flatteningSceneIndex.h>
#if defined(HD_API_VERSION) && HD_API_VERSION >= 51
#include <pxr/imaging/hd/materialBindingsSchema.h>
#else
#include <pxr/imaging/hd/materialBindingSchema.h>
#endif
#include <pxr/imaging/hd/purposeSchema.h>
#include <pxr/imaging/hd/retainedDataSource.h>
#include <pxr/imaging/hd/sceneIndexPlugin.h>
#include <pxr/imaging/hd/sceneIndexPluginRegistry.h>
#include <pxr/usd/usd/primFlags.h>
#include <pxr/usdImaging/usdImaging/delegate.h>
#if PXR_VERSION >= 2302
#include <pxr/usdImaging/usdImaging/drawModeSceneIndex.h> //For USD 2302 and later
#include <pxr/usdImaging/usdImaging/modelSchema.h> //For USD 2302 and later
#include <pxr/usdImaging/usdImaging/niPrototypePropagatingSceneIndex.h>
#include <pxr/usdImaging/usdImaging/piPrototypePropagatingSceneIndex.h>
#else
Expand All @@ -45,6 +52,7 @@
#if defined(HD_API_VERSION) && HD_API_VERSION >= 54
#include <pxr/imaging/hd/flattenedMaterialBindingsDataSourceProvider.h>
#endif
#endif

#include <maya/MObject.h>
#include <maya/MObjectHandle.h>
Expand Down Expand Up @@ -121,10 +129,19 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn

auto proxyShape = dynamic_cast<MayaUsdProxyShapeBase*>(dependNodeFn.userNode());
if (TF_VERIFY(proxyShape, "Error getting MayaUsdProxyShapeBase")) {
#if USD_IMAGING_API_VERSION >= 20
UsdImagingCreateSceneIndicesInfo createInfo;

UsdImagingSceneIndices sceneIndices = UsdImagingCreateSceneIndices(createInfo);

return MayaUsd::MayaUsdProxyShapeSceneIndex::New(
proxyShape, sceneIndices.finalSceneIndex, sceneIndices.stageSceneIndex);
#else

// We already have PXR_VERSION >= 2211
#if PXR_VERSION < 2302 // So for 2211
auto usdImagingStageSceneIndex = UsdImagingStageSceneIndex::New();
HdSceneIndexBaseRefPtr _sceneIndex = UsdImagingGLDrawModeSceneIndex::New(
HdSceneIndexBaseRefPtr sceneIndex = UsdImagingGLDrawModeSceneIndex::New(
HdFlatteningSceneIndex::New(
HdInstancedBySceneIndex::New(usdImagingStageSceneIndex)),
/* inputArgs = */ nullptr);
Expand Down Expand Up @@ -153,21 +170,30 @@ HdSceneIndexBaseRefPtr MayaUsdProxyShapeMayaNodeSceneIndexPlugin::_AppendSceneIn
// Flatten transforms, visibility, purpose, model, and material
// bindings over hierarchies.
// Do it the same way as USDView does with a SceneIndices chain
HdSceneIndexBaseRefPtr _sceneIndex
HdSceneIndexBaseRefPtr sceneIndex
= UsdImagingPiPrototypePropagatingSceneIndex::New(usdImagingStageSceneIndex);
_sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(_sceneIndex);
#if PXR_VERSION < 2311
Copy link
Collaborator

Choose a reason for hiding this comment

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

@seando-adsk : there is a missing case here which is for usd 23.08, it should contain :

            //#For USD 23.08 and later, HD_API_VERSION=54 in USD 23.08
            static const bool _displayUnloadedPrimsWithBounds = true;

            HdContainerDataSourceHandle const stageInputArgs =
            HdRetainedContainerDataSource::New(
                UsdImagingStageSceneIndexTokens->includeUnloadedPrims,
                HdRetainedTypedSampledDataSource<bool>::New(
                    _displayUnloadedPrimsWithBounds));

            // Create the scene index graph.
            _sceneIndex = _stageSceneIndex =
                UsdImagingStageSceneIndex::New(stageInputArgs);

            static HdContainerDataSourceHandle const materialPruningInputArgs =
                HdRetainedContainerDataSource::New(
                    HdsiPrimTypePruningSceneIndexTokens->primTypes,
                    HdRetainedTypedSampledDataSource<TfTokenVector>::New(
                        { HdPrimTypeTokens->material }),
                    HdsiPrimTypePruningSceneIndexTokens->bindingToken,
                    HdRetainedTypedSampledDataSource<TfToken>::New(
                        HdMaterialBindingsSchema::GetSchemaToken()));

            // Prune scene materials prior to flattening inherited
            // materials bindings and resolving material bindings
            _sceneIndex = _materialPruningSceneIndex =
                HdsiPrimTypePruningSceneIndex::New(
                    _sceneIndex, materialPruningInputArgs);

            static HdContainerDataSourceHandle const lightPruningInputArgs =
                HdRetainedContainerDataSource::New(
                    HdsiPrimTypePruningSceneIndexTokens->primTypes,
                    HdRetainedTypedSampledDataSource<TfTokenVector>::New(
                        HdLightPrimTypeTokens()),
                    HdsiPrimTypePruningSceneIndexTokens->doNotPruneNonPrimPaths,
                    HdRetainedTypedSampledDataSource<bool>::New(
                        false));

            _sceneIndex = _lightPruningSceneIndex =
                HdsiPrimTypePruningSceneIndex::New(
                    _sceneIndex, lightPruningInputArgs);

            // Use extentsHint for default_/geometry purpose
            HdContainerDataSourceHandle const extentInputArgs =
                HdRetainedContainerDataSource::New(
                    UsdGeomTokens->purpose,
                    HdRetainedTypedSampledDataSource<TfToken>::New(
                        UsdGeomTokens->default_));

            _sceneIndex =
                UsdImagingExtentResolvingSceneIndex::New(
                    _sceneIndex, extentInputArgs);

            if (_displayUnloadedPrimsWithBounds) {
                _sceneIndex =
                    UsdImagingUnloadedDrawModeSceneIndex::New(_sceneIndex);
            }

            _sceneIndex = _rootOverridesSceneIndex =
                UsdImagingRootOverridesSceneIndex::New(_sceneIndex);

            _sceneIndex =
                UsdImagingPiPrototypePropagatingSceneIndex::New(_sceneIndex);
        
            _sceneIndex =
                UsdImagingNiPrototypePropagatingSceneIndex::New(_sceneIndex);

            _sceneIndex = _selectionSceneIndex =
                UsdImagingSelectionSceneIndex::New(_sceneIndex);

            _sceneIndex =
                UsdImagingRenderSettingsFlatteningSceneIndex::New(_sceneIndex);

            _sceneIndex =
                HdFlatteningSceneIndex::New(
                    _sceneIndex, UsdImagingFlattenedDataSourceProviders());

            _sceneIndex =
                UsdImagingDrawModeSceneIndex::New(_sceneIndex,
                                                  /* inputArgs = */ nullptr);

            _sceneIndex = _displayStyleSceneIndex =
                HdsiLegacyDisplayStyleOverrideSceneIndex::New(_sceneIndex);

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dj-mcg can you have a look at the code review comment here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@dj-mcg Dan would you mind if we pushed the change to the missing 23.08 case to this PR? We are using 23.08 internally and need this fix for MayaHydra.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, so sorry to have dropped the ball on this, I was OOO and am just catching up on things.

No problem checking this in, thanks for taking care of this case!

sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(sceneIndex);
#else
sceneIndex = UsdImagingNiPrototypePropagatingSceneIndex::New(
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I am correct, this block will never be called as line 137 we already returned from the function for USD 23.11+.

sceneIndex,
{ HdMaterialBindingsSchema::GetSchemaToken(),
HdPurposeSchema::GetSchemaToken(),
UsdImagingModelSchema::GetSchemaToken() },
{});
#endif

// The native prototype propagating scene index does a lot of
// the flattening before inserting copies of the the prototypes
// into the scene index. However, the resolved material for a prim
// coming from a USD prototype can depend on the prim ancestors of
// a corresponding instance. So we need to do one final resolve here.
_sceneIndex = HdFlatteningSceneIndex::New(_sceneIndex, flatteningInputArgs);
_sceneIndex = UsdImagingDrawModeSceneIndex::New(_sceneIndex, /* inputArgs = */ nullptr);
sceneIndex = HdFlatteningSceneIndex::New(sceneIndex, flatteningInputArgs);
sceneIndex = UsdImagingDrawModeSceneIndex::New(sceneIndex, /* inputArgs = */ nullptr);
#endif

return MayaUsd::MayaUsdProxyShapeSceneIndex::New(
proxyShape, _sceneIndex, usdImagingStageSceneIndex);
proxyShape, sceneIndex, usdImagingStageSceneIndex);
#endif
}
}

Expand Down