diff --git a/doc/codingGuidelines.md b/doc/codingGuidelines.md index 31be1832d5..15f9069531 100644 --- a/doc/codingGuidelines.md +++ b/doc/codingGuidelines.md @@ -284,7 +284,7 @@ For source files (.cpp) with an associated header file (.h) that resides in the All included public header files from outside and inside the project should be `#include`’d using angle brackets. For example: ```cpp #include -#include +#include ``` Private project’s header files should be `#include`'d using double quotes, and a relative path. Private headers may live in the same directory or sub-directories, but they should never be included using "._" or ".._" as part of a relative path. For example: diff --git a/doc/mayaHydraDetails.md b/doc/mayaHydraDetails.md index 8f73017379..9c81ae6e27 100644 --- a/doc/mayaHydraDetails.md +++ b/doc/mayaHydraDetails.md @@ -91,7 +91,7 @@ classDiagram -_renderIndex: HdRenderIndex* -_fvpSelectionTracker: Fvp::SelectionTrackerSharedPtr -_selectionSceneIndex: Fvp::SelectionSceneIndexRefPtr - -_mayaHydraSceneProducer: std::unique_ptr + -_mayaHydraSceneIndex: std::unique_ptr +Render(const MHWRender::MDrawContext& drawContext, const MHWRender::MDataServerOperation::MViewportScene& scene) } ``` @@ -129,8 +129,8 @@ stateDiagram state InitHydraResources() { [*] --> HydraResources - HydraResources --> MayaHydraSceneProducer() : RenderDelegate/RenderIndex - MayaHydraSceneProducer() --> Populate() : Creates MayaHydra specific Scene Indices internally + HydraResources --> MayaHydraSceneIndex() : RenderDelegate/RenderIndex + MayaHydraSceneIndex() --> Populate() : Creates MayaHydra specific Scene Indices internally Populate() --> MayaHydraAdapter : Loop over Maya native nodes MayaHydraAdapter --> SceneIndexRegistration : Flow Viewport API (WIP) to inject various Scene Indices including USD data and SelectionHighlighting SceneIndexRegistration --> [*] diff --git a/lib/mayaHydra/hydraExtensions/CMakeLists.txt b/lib/mayaHydra/hydraExtensions/CMakeLists.txt index 16f2978922..cef6759426 100644 --- a/lib/mayaHydra/hydraExtensions/CMakeLists.txt +++ b/lib/mayaHydra/hydraExtensions/CMakeLists.txt @@ -13,7 +13,6 @@ target_sources(${TARGET_NAME} mayaUtils.cpp mhBuildInfo.cpp mixedUtils.cpp - mayaHydraSceneProducer.cpp ) set(HEADERS @@ -25,7 +24,6 @@ set(HEADERS mayaHydraLibInterfaceImp.h mayaUtils.h mixedUtils.h - mayaHydraSceneProducer.h ) # ----------------------------------------------------------------------------- diff --git a/lib/mayaHydra/hydraExtensions/adapters/adapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/adapter.cpp index 989544ceb4..9f23c64176 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/adapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/adapter.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include @@ -36,7 +36,7 @@ void _preRemoval(MObject& node, void* clientData) auto* adapter = reinterpret_cast(clientData); TF_DEBUG(MAYAHYDRALIB_ADAPTER_CALLBACKS) .Msg("Pre-removal callback triggered for prim (%s)\n", adapter->GetID().GetText()); - adapter->GetSceneProducer()->RemoveAdapter(adapter->GetID()); + adapter->GetMayaHydraSceneIndex()->RemoveAdapter(adapter->GetID()); } void _nameChanged(MObject& node, const MString& str, void* clientData) @@ -47,7 +47,7 @@ void _nameChanged(MObject& node, const MString& str, void* clientData) TF_DEBUG(MAYAHYDRALIB_ADAPTER_CALLBACKS) .Msg("Name-changed callback triggered for prim (%s)\n", adapter->GetID().GetText()); adapter->RemoveCallbacks(); - adapter->GetSceneProducer()->RecreateAdapterOnIdle(adapter->GetID(), adapter->GetNode()); + adapter->GetMayaHydraSceneIndex()->RecreateAdapterOnIdle(adapter->GetID(), adapter->GetNode()); } } // namespace @@ -57,9 +57,9 @@ void _nameChanged(MObject& node, const MString& str, void* clientData) MayaHydraAdapter::MayaHydraAdapter( const MObject& node, const SdfPath& id, - MayaHydraSceneProducer* producer) + MayaHydraSceneIndex* mayaHydraSceneIndex) : _id(id) - , _sceneProducer(producer) + , _mayaHydraSceneIndex(mayaHydraSceneIndex) , _node(node) { } diff --git a/lib/mayaHydra/hydraExtensions/adapters/adapter.h b/lib/mayaHydra/hydraExtensions/adapters/adapter.h index 76f1fa0d2b..e59dd17e7a 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/adapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/adapter.h @@ -44,7 +44,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraAdapter is the base class for all adapters. An adapter is used to translate from @@ -55,12 +55,12 @@ class MayaHydraAdapter { public: MAYAHYDRALIB_API - MayaHydraAdapter(const MObject& node, const SdfPath& id, MayaHydraSceneProducer* producer); + MayaHydraAdapter(const MObject& node, const SdfPath& id, MayaHydraSceneIndex* mayaHydraSceneIndex); MAYAHYDRALIB_API virtual ~MayaHydraAdapter(); - const SdfPath& GetID() const { return _id; } - MayaHydraSceneProducer* GetSceneProducer() const { return _sceneProducer; } + const SdfPath& GetID() const { return _id; } + MayaHydraSceneIndex* GetMayaHydraSceneIndex() const { return _mayaHydraSceneIndex; } MAYAHYDRALIB_API void AddCallback(MCallbackId callbackId); MAYAHYDRALIB_API @@ -109,7 +109,7 @@ class MayaHydraAdapter protected: SdfPath _id; std::vector _callbacks; - MayaHydraSceneProducer* _sceneProducer; + MayaHydraSceneIndex* _mayaHydraSceneIndex; MObject _node; bool _isPopulated = false; diff --git a/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h b/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h index c6672b301b..be802f46d3 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h +++ b/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h @@ -44,7 +44,7 @@ class MayaHydraAdapterRegistry : public TfSingleton public: using ShapeAdapterCreator - = std::function; + = std::function; MAYAHYDRALIB_API static void RegisterShapeAdapter(const TfToken& type, ShapeAdapterCreator creator); @@ -52,7 +52,7 @@ class MayaHydraAdapterRegistry : public TfSingleton static ShapeAdapterCreator GetShapeAdapterCreator(const MDagPath& dag); using LightAdapterCreator - = std::function; + = std::function; MAYAHYDRALIB_API static void RegisterLightAdapter(const TfToken& type, LightAdapterCreator creator); @@ -63,7 +63,7 @@ class MayaHydraAdapterRegistry : public TfSingleton static LightAdapterCreator GetLightAdapterCreator(const MObject& dag); using MaterialAdapterCreator = std::function< - MayaHydraMaterialAdapterPtr(const SdfPath&, MayaHydraSceneProducer*, const MObject&)>; + MayaHydraMaterialAdapterPtr(const SdfPath&, MayaHydraSceneIndex*, const MObject&)>; MAYAHYDRALIB_API static void RegisterMaterialAdapter(const TfToken& type, MaterialAdapterCreator creator); @@ -71,7 +71,7 @@ class MayaHydraAdapterRegistry : public TfSingleton static MaterialAdapterCreator GetMaterialAdapterCreator(const MObject& node); using CameraAdapterCreator - = std::function; + = std::function; MAYAHYDRALIB_API static void RegisterCameraAdapter(const TfToken& type, CameraAdapterCreator creator); diff --git a/lib/mayaHydra/hydraExtensions/adapters/aiSkydomeLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/aiSkydomeLightAdapter.cpp index 2cc3c5f0a7..0f94c8257a 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/aiSkydomeLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/aiSkydomeLightAdapter.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraAiSkyDomeLightAdapter is used to handle the translation from an Arnold skydome @@ -59,8 +59,8 @@ class MayaHydraAiSkyDomeLightAdapter : public MayaHydraLightAdapter bool _colorIsConnected = false; public: - MayaHydraAiSkyDomeLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraLightAdapter(producer, dag) + MayaHydraAiSkyDomeLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraLightAdapter(mayaHydraSceneIndex, dag) { //Init static variables if needed if (! _pTextureManager){ @@ -185,7 +185,7 @@ class MayaHydraAiSkyDomeLightAdapter : public MayaHydraLightAdapter if (!_colorIsConnected){ if (!_dummyTextureFullPathFilename.empty()){ // Update Hydra texture resource everytime Domelight color is tweaked. - auto resourceReg = GetSceneProducer()->GetRenderIndex().GetResourceRegistry(); + auto resourceReg = GetMayaHydraSceneIndex()->GetRenderIndex().GetResourceRegistry(); if (TF_VERIFY(resourceReg, "Unable to update AikSkyDomelights constant color")) resourceReg->ReloadResource(TfToken("texture"), _dummyTextureFullPathFilename); // SdfAssetPath requires both "path" and "resolvedPath" @@ -240,8 +240,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, domeLight) { MayaHydraAdapterRegistry::RegisterLightAdapter( TfToken("aiSkyDomeLight"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraLightAdapterPtr { - return MayaHydraLightAdapterPtr(new MayaHydraAiSkyDomeLightAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraLightAdapterPtr { + return MayaHydraLightAdapterPtr(new MayaHydraAiSkyDomeLightAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/areaLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/areaLightAdapter.cpp index 69e4539611..afad125897 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/areaLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/areaLightAdapter.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include @@ -31,8 +31,8 @@ PXR_NAMESPACE_OPEN_SCOPE class MayaHydraAreaLightAdapter : public MayaHydraLightAdapter { public: - MayaHydraAreaLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraLightAdapter(producer, dag) + MayaHydraAreaLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraLightAdapter(mayaHydraSceneIndex, dag) { } @@ -40,7 +40,7 @@ class MayaHydraAreaLightAdapter : public MayaHydraLightAdapter const TfToken& LightType() const override { - if (GetSceneProducer()->IsHdSt()) { + if (GetMayaHydraSceneIndex()->IsHdSt()) { return HdPrimTypeTokens->simpleLight; } else { return HdPrimTypeTokens->rectLight; @@ -73,8 +73,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, pointLight) { MayaHydraAdapterRegistry::RegisterLightAdapter( TfToken("areaLight"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraLightAdapterPtr { - return MayaHydraLightAdapterPtr(new MayaHydraAreaLightAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraLightAdapterPtr { + return MayaHydraLightAdapterPtr(new MayaHydraAreaLightAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.cpp index b8c568f9fb..51dd20f749 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -40,16 +40,16 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, camera) { MayaHydraAdapterRegistry::RegisterCameraAdapter( HdPrimTypeTokens->camera, - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraCameraAdapterPtr { - return MayaHydraCameraAdapterPtr(new MayaHydraCameraAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraCameraAdapterPtr { + return MayaHydraCameraAdapterPtr(new MayaHydraCameraAdapter(mayaHydraSceneIndex, dag)); }); } } // namespace // MayaHydraCameraAdapter is used to handle the translation from a Maya camera to hydra. -MayaHydraCameraAdapter::MayaHydraCameraAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraShapeAdapter(producer->GetPrimPath(dag, true), producer, dag) +MayaHydraCameraAdapter::MayaHydraCameraAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraShapeAdapter(mayaHydraSceneIndex->GetPrimPath(dag, true), mayaHydraSceneIndex, dag) { } @@ -59,7 +59,7 @@ TfToken MayaHydraCameraAdapter::CameraType() { return HdPrimTypeTokens->camera; bool MayaHydraCameraAdapter::IsSupported() const { - return GetSceneProducer()->GetRenderIndex().IsSprimTypeSupported(CameraType()); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsSprimTypeSupported(CameraType()); } void MayaHydraCameraAdapter::Populate() @@ -67,7 +67,7 @@ void MayaHydraCameraAdapter::Populate() if (_isPopulated) { return; } - GetSceneProducer()->InsertSprim(this, CameraType(), GetID(), HdCamera::AllDirty); + GetMayaHydraSceneIndex()->InsertPrim(this, CameraType(), GetID()); _isPopulated = true; } @@ -75,7 +75,7 @@ void MayaHydraCameraAdapter::MarkDirty(HdDirtyBits dirtyBits) { if (_isPopulated && dirtyBits != 0) { dirtyBits = dirtyBits & HdCamera::AllDirty; - GetSceneProducer()->MarkSprimDirty(GetID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkSprimDirty(GetID(), dirtyBits); } } @@ -120,7 +120,7 @@ void MayaHydraCameraAdapter::RemovePrim() if (!_isPopulated) { return; } - GetSceneProducer()->RemoveSprim(CameraType(), GetID()); + GetMayaHydraSceneIndex()->RemovePrim(GetID()); _isPopulated = false; } @@ -195,20 +195,20 @@ VtValue MayaHydraCameraAdapter::GetCameraParamValue(const TfToken& paramName) if (paramName == HdCameraTokens->shutterOpen) { // No motion samples, instantaneous shutter - if (!GetSceneProducer()->GetParams().motionSamplesEnabled()) + if (!GetMayaHydraSceneIndex()->GetParams().motionSamplesEnabled()) return VtValue(double(0)); - return VtValue(double(GetSceneProducer()->GetCurrentTimeSamplingInterval().GetMin())); + return VtValue(double(GetMayaHydraSceneIndex()->GetCurrentTimeSamplingInterval().GetMin())); } if (paramName == HdCameraTokens->shutterClose) { // No motion samples, instantaneous shutter - if (!GetSceneProducer()->GetParams().motionSamplesEnabled()) + if (!GetMayaHydraSceneIndex()->GetParams().motionSamplesEnabled()) return VtValue(double(0)); const auto shutterAngle = camera.shutterAngle(&status); if (hadError(status)) return {}; auto constexpr maxRadians = M_PI * 2.0; auto shutterClose = std::min(std::max(0.0, shutterAngle), maxRadians) / maxRadians; - auto interval = GetSceneProducer()->GetCurrentTimeSamplingInterval(); + auto interval = GetMayaHydraSceneIndex()->GetCurrentTimeSamplingInterval(); return VtValue(double(interval.GetMin() + interval.GetSize() * shutterClose)); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.h index 575c972732..b646f8bca9 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/cameraAdapter.h @@ -23,7 +23,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraCameraAdapter is used to handle the translation from a Maya camera to hydra. @@ -32,7 +32,7 @@ class MayaHydraCameraAdapter : public MayaHydraShapeAdapter { public: MAYAHYDRALIB_API - MayaHydraCameraAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag); + MayaHydraCameraAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag); MAYAHYDRALIB_API virtual ~MayaHydraCameraAdapter(); diff --git a/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.cpp index 8d411ee758..e0d5880983 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include @@ -109,7 +109,7 @@ void _HierarchyChanged(MDagPath& child, MDagPath& parent, void* clientData) parent.partialPathName().asChar()); adapter->RemoveCallbacks(); adapter->RemovePrim(); - adapter->GetSceneProducer()->RecreateAdapterOnIdle(adapter->GetID(), adapter->GetNode()); + adapter->GetMayaHydraSceneIndex()->RecreateAdapterOnIdle(adapter->GetID(), adapter->GetNode()); } void _InstancerNodeDirty(MObject& node, MPlug& plug, void* clientData) @@ -135,9 +135,9 @@ const auto _instancePrimvarDescriptors = HdPrimvarDescriptorVector { // MayaHydraDagAdapter is the adapter base class for any dag object. MayaHydraDagAdapter::MayaHydraDagAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dagPath) - : MayaHydraAdapter(dagPath.node(), id, producer) + : MayaHydraAdapter(dagPath.node(), id, mayaHydraSceneIndex) , _dagPath(dagPath) { // We shouldn't call virtual functions in constructors. @@ -168,7 +168,7 @@ GfMatrix4d MayaHydraDagAdapter::GetTransform() size_t MayaHydraDagAdapter::SampleTransform(size_t maxSampleCount, float* times, GfMatrix4d* samples) { - return GetSceneProducer()->SampleValues(maxSampleCount, times, samples, [&]() -> GfMatrix4d { + return GetMayaHydraSceneIndex()->SampleValues(maxSampleCount, times, samples, [&]() -> GfMatrix4d { return GetGfMatrixFromMaya(_dagPath.inclusiveMatrix()); }); } @@ -210,9 +210,9 @@ void MayaHydraDagAdapter::CreateCallbacks() void MayaHydraDagAdapter::MarkDirty(HdDirtyBits dirtyBits) { if (dirtyBits != 0) { - GetSceneProducer()->MarkRprimDirty(GetID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkRprimDirty(GetID(), dirtyBits); if (IsInstanced()) { - GetSceneProducer()->MarkInstancerDirty(GetInstancerID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkInstancerDirty(GetInstancerID(), dirtyBits); } if (dirtyBits & HdChangeTracker::DirtyVisibility) { _visibilityDirty = true; @@ -225,9 +225,9 @@ void MayaHydraDagAdapter::RemovePrim() if (!_isPopulated) { return; } - GetSceneProducer()->RemoveRprim(GetID()); + GetMayaHydraSceneIndex()->RemovePrim(GetID()); if (_isInstanced) { - GetSceneProducer()->GetRenderIndex().RemoveInstancer(GetID().AppendProperty(_tokens->instancer)); + GetMayaHydraSceneIndex()->GetRenderIndex().RemoveInstancer(GetID().AppendProperty(_tokens->instancer)); } _isPopulated = false; } diff --git a/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.h index eb72c953bb..c381dbac71 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/dagAdapter.h @@ -39,7 +39,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraDagAdapter is the adapter base class for any dag object. @@ -48,7 +48,7 @@ class MayaHydraDagAdapter : public MayaHydraAdapter { protected: MAYAHYDRALIB_API - MayaHydraDagAdapter(const SdfPath& id, MayaHydraSceneProducer* producer, const MDagPath& dagPath); + MayaHydraDagAdapter(const SdfPath& id, MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dagPath); public: MAYAHYDRALIB_API diff --git a/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp index 57e2f5404c..6108d34467 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/directionalLightAdapter.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -38,14 +38,14 @@ PXR_NAMESPACE_OPEN_SCOPE class MayaHydraDirectionalLightAdapter : public MayaHydraLightAdapter { public: - MayaHydraDirectionalLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraLightAdapter(producer, dag) + MayaHydraDirectionalLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraLightAdapter(mayaHydraSceneIndex, dag) { } const TfToken& LightType() const override { - if (GetSceneProducer()->IsHdSt()) { + if (GetMayaHydraSceneIndex()->IsHdSt()) { return HdPrimTypeTokens->simpleLight; } else { return HdPrimTypeTokens->distantLight; @@ -116,8 +116,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, pointLight) { MayaHydraAdapterRegistry::RegisterLightAdapter( TfToken("directionalLight"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraLightAdapterPtr { - return MayaHydraLightAdapterPtr(new MayaHydraDirectionalLightAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraLightAdapterPtr { + return MayaHydraLightAdapterPtr(new MayaHydraDirectionalLightAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp index d2f1878be8..390dbc5443 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -95,8 +95,8 @@ const MString defaultLightSet("defaultLightSet"); // MayaHydraLightAdapter is the base class for any light adapter used to handle the translation from // a light to hydra. -MayaHydraLightAdapter::MayaHydraLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraDagAdapter(producer->GetPrimPath(dag, true), producer, dag) +MayaHydraLightAdapter::MayaHydraLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraDagAdapter(mayaHydraSceneIndex->GetPrimPath(dag, true), mayaHydraSceneIndex, dag) { // This should be avoided, not a good idea to call virtual functions // directly or indirectly in a constructor. @@ -110,7 +110,7 @@ MayaHydraLightAdapter::~MayaHydraLightAdapter() bool MayaHydraLightAdapter::IsSupported() const { - return GetSceneProducer()->GetRenderIndex().IsSprimTypeSupported(LightType()); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsSprimTypeSupported(LightType()); } void MayaHydraLightAdapter::Populate() @@ -119,7 +119,7 @@ void MayaHydraLightAdapter::Populate() return; } if (IsVisible() && _isLightingOn) { - GetSceneProducer()->InsertSprim(this, LightType(), GetID(), HdLight::AllDirty); + GetMayaHydraSceneIndex()->InsertPrim(this, LightType(), GetID()); _isPopulated = true; } } @@ -127,7 +127,7 @@ void MayaHydraLightAdapter::Populate() void MayaHydraLightAdapter::MarkDirty(HdDirtyBits dirtyBits) { if (_isPopulated && dirtyBits != 0) { - GetSceneProducer()->MarkSprimDirty(GetID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkSprimDirty(GetID(), dirtyBits); } } @@ -136,7 +136,7 @@ void MayaHydraLightAdapter::RemovePrim() if (!_isPopulated) { return; } - GetSceneProducer()->RemoveSprim(LightType(), GetID()); + GetMayaHydraSceneIndex()->RemovePrim(GetID()); _isPopulated = false; } @@ -198,8 +198,8 @@ VtValue MayaHydraLightAdapter::Get(const TfToken& key) return VtValue(MayaHydraDagAdapter::GetTransform()); } else if (key == HdLightTokens->shadowCollection) { // Exclude prims that should not be lighted by only - // taking the primitives whose root path is GetSceneProducer()->GetLightedPrimsRootPath() - const SdfPath lightedPrimsRootPath = GetSceneProducer()->GetLightedPrimsRootPath(); + // taking the primitives whose root path is GetMayaHydraSceneIndex()->GetLightedPrimsRootPath() + const SdfPath lightedPrimsRootPath = GetMayaHydraSceneIndex()->GetLightedPrimsRootPath(); HdRprimCollection coll( HdTokens->geometry, HdReprSelector(HdReprTokens->refined), @@ -302,9 +302,9 @@ void MayaHydraLightAdapter::_CalculateShadowParams(MFnLight& light, HdxShadowPar params.enabled = true; params.resolution = dmapResolutionPlug.isNull() - ? GetSceneProducer()->GetParams().maximumShadowMapResolution + ? GetMayaHydraSceneIndex()->GetParams().maximumShadowMapResolution : std::min( - GetSceneProducer()->GetParams().maximumShadowMapResolution, dmapResolutionPlug.asInt()); + GetMayaHydraSceneIndex()->GetParams().maximumShadowMapResolution, dmapResolutionPlug.asInt()); params.shadowMatrix = std::make_shared(GetTransform() * _shadowProjectionMatrix); diff --git a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.h index 8c570f640b..a54cd54fa4 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/lightAdapter.h @@ -29,7 +29,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraLightAdapter is the base class for any light adapter used to handle the @@ -44,7 +44,7 @@ class MayaHydraLightAdapter : public MayaHydraDagAdapter } MAYAHYDRALIB_API - MayaHydraLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag); + MayaHydraLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag); MAYAHYDRALIB_API virtual ~MayaHydraLightAdapter(); MAYAHYDRALIB_API diff --git a/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.cpp index 1b8ed545ad..b69c5b829b 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -67,15 +67,15 @@ const TfTokenVector _stSamplerCoords = { TfToken("st") }; MayaHydraMaterialAdapter::MayaHydraMaterialAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MObject& node) - : MayaHydraAdapter(node, id, producer) + : MayaHydraAdapter(node, id, mayaHydraSceneIndex) { } bool MayaHydraMaterialAdapter::IsSupported() const { - return GetSceneProducer()->GetRenderIndex().IsSprimTypeSupported(HdPrimTypeTokens->material); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsSprimTypeSupported(HdPrimTypeTokens->material); } bool MayaHydraMaterialAdapter::HasType(const TfToken& typeId) const @@ -85,7 +85,7 @@ bool MayaHydraMaterialAdapter::HasType(const TfToken& typeId) const void MayaHydraMaterialAdapter::MarkDirty(HdDirtyBits dirtyBits) { - GetSceneProducer()->MarkSprimDirty(GetID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkSprimDirty(GetID(), dirtyBits); } void MayaHydraMaterialAdapter::RemovePrim() @@ -93,7 +93,7 @@ void MayaHydraMaterialAdapter::RemovePrim() if (!_isPopulated) { return; } - GetSceneProducer()->RemoveSprim(HdPrimTypeTokens->material, GetID()); + GetMayaHydraSceneIndex()->RemovePrim(GetID()); _isPopulated = false; } @@ -104,7 +104,7 @@ void MayaHydraMaterialAdapter::Populate() if (_isPopulated) { return; } - GetSceneProducer()->InsertSprim(this, HdPrimTypeTokens->material, GetID(), HdMaterial::AllDirty); + GetMayaHydraSceneIndex()->InsertPrim(this, HdPrimTypeTokens->material, GetID()); _isPopulated = true; } @@ -149,9 +149,9 @@ class MayaHydraShadingEngineAdapter : public MayaHydraMaterialAdapter MayaHydraShadingEngineAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MObject& obj) - : MayaHydraMaterialAdapter(id, producer, obj) + : MayaHydraMaterialAdapter(id, mayaHydraSceneIndex, obj) , _surfaceShaderCallback(0) { _CacheNodeAndTypes(); @@ -199,8 +199,8 @@ class MayaHydraShadingEngineAdapter : public MayaHydraMaterialAdapter { auto* adapter = reinterpret_cast(clientData); adapter->MarkDirty(HdMaterial::AllDirty); - if (adapter->GetSceneProducer()->IsHdSt()) { - adapter->GetSceneProducer()->MaterialTagChanged(adapter->GetID()); + if (adapter->GetMayaHydraSceneIndex()->IsHdSt()) { + adapter->GetMayaHydraSceneIndex()->MaterialTagChanged(adapter->GetID()); } } @@ -390,10 +390,10 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, shadingEngine) MayaHydraAdapterRegistry::RegisterMaterialAdapter( TfToken("shadingEngine"), [](const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MObject& obj) -> MayaHydraMaterialAdapterPtr { return MayaHydraMaterialAdapterPtr( - new MayaHydraShadingEngineAdapter(id, producer, obj)); + new MayaHydraShadingEngineAdapter(id, mayaHydraSceneIndex, obj)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.h index 19e9062f7f..07f27a374f 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/materialAdapter.h @@ -22,7 +22,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraMaterialAdapter is used to handle the translation from a Maya material to hydra. @@ -35,7 +35,7 @@ class MayaHydraMaterialAdapter : public MayaHydraAdapter MAYAHYDRALIB_API MayaHydraMaterialAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MObject& node); MAYAHYDRALIB_API virtual ~MayaHydraMaterialAdapter() = default; diff --git a/lib/mayaHydra/hydraExtensions/adapters/meshAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/meshAdapter.cpp index a873b21be2..f378533db1 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/meshAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/meshAdapter.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include @@ -79,8 +79,8 @@ const std::pair _dirtyBits[] { class MayaHydraMeshAdapter : public MayaHydraShapeAdapter { public: - MayaHydraMeshAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraShapeAdapter(producer->GetPrimPath(dag, false), producer, dag) + MayaHydraMeshAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraShapeAdapter(mayaHydraSceneIndex->GetPrimPath(dag, false), mayaHydraSceneIndex, dag) { } @@ -91,7 +91,7 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter if (_isPopulated) { return; } - GetSceneProducer()->InsertRprim(this, HdPrimTypeTokens->mesh, GetID(), GetInstancerID()); + GetMayaHydraSceneIndex()->InsertPrim(this, HdPrimTypeTokens->mesh, GetID()); _isPopulated = true; } @@ -150,7 +150,7 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter bool IsSupported() const override { - return GetSceneProducer()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->mesh); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->mesh); } VtValue GetUVs() @@ -220,7 +220,7 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter if (ARCH_UNLIKELY(!status)) { return 0; } - return GetSceneProducer()->SampleValues( + return GetMayaHydraSceneIndex()->SampleValues( maxSampleCount, times, samples, [&]() -> VtValue { return GetPoints(mesh); }); } else if (key == MayaHydraAdapterTokens->st) { times[0] = 0.0f; @@ -247,7 +247,7 @@ class MayaHydraMeshAdapter : public MayaHydraShapeAdapter } return HdMeshTopology( - (GetSceneProducer()->GetParams().displaySmoothMeshes || GetDisplayStyle().refineLevel > 0) + (GetMayaHydraSceneIndex()->GetParams().displaySmoothMeshes || GetDisplayStyle().refineLevel > 0) ? PxOsdOpenSubdivTokens->catmullClark : PxOsdOpenSubdivTokens->none, @@ -463,8 +463,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, mesh) { MayaHydraAdapterRegistry::RegisterShapeAdapter( TfToken("mesh"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraShapeAdapterPtr { - return MayaHydraShapeAdapterPtr(new MayaHydraMeshAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraShapeAdapterPtr { + return MayaHydraShapeAdapterPtr(new MayaHydraMeshAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/nurbsCurveAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/nurbsCurveAdapter.cpp index a852d6ed8b..417d3fe515 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/nurbsCurveAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/nurbsCurveAdapter.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -59,8 +59,8 @@ const std::array, 4> _dirtyBits { { class MayaHydraNurbsCurveAdapter : public MayaHydraShapeAdapter { public: - MayaHydraNurbsCurveAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraShapeAdapter(producer->GetPrimPath(dag, false), producer, dag) + MayaHydraNurbsCurveAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraShapeAdapter(mayaHydraSceneIndex->GetPrimPath(dag, false), mayaHydraSceneIndex, dag) { } @@ -68,10 +68,10 @@ class MayaHydraNurbsCurveAdapter : public MayaHydraShapeAdapter bool IsSupported() const override { - return GetSceneProducer()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->basisCurves); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->basisCurves); } - void Populate() override { GetSceneProducer()->InsertRprim(this, HdPrimTypeTokens->basisCurves, GetID()); } + void Populate() override { GetMayaHydraSceneIndex()->InsertPrim(this, HdPrimTypeTokens->basisCurves, GetID()); } void CreateCallbacks() override { @@ -241,8 +241,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, mesh) { MayaHydraAdapterRegistry::RegisterShapeAdapter( TfToken("nurbsCurve"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraShapeAdapterPtr { - return MayaHydraShapeAdapterPtr(new MayaHydraNurbsCurveAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraShapeAdapterPtr { + return MayaHydraShapeAdapterPtr(new MayaHydraNurbsCurveAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/pointLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/pointLightAdapter.cpp index 00644bc636..453942f8a2 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/pointLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/pointLightAdapter.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include @@ -36,14 +36,14 @@ PXR_NAMESPACE_OPEN_SCOPE class MayaHydraPointLightAdapter : public MayaHydraLightAdapter { public: - MayaHydraPointLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraLightAdapter(producer, dag) + MayaHydraPointLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraLightAdapter(mayaHydraSceneIndex, dag) { } const TfToken& LightType() const override { - if (GetSceneProducer()->IsHdSt()) { + if (GetMayaHydraSceneIndex()->IsHdSt()) { return HdPrimTypeTokens->simpleLight; } else { return HdPrimTypeTokens->sphereLight; @@ -79,8 +79,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, pointLight) { MayaHydraAdapterRegistry::RegisterLightAdapter( TfToken("pointLight"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraLightAdapterPtr { - return MayaHydraLightAdapterPtr(new MayaHydraPointLightAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraLightAdapterPtr { + return MayaHydraLightAdapterPtr(new MayaHydraPointLightAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp index 4241bdf286..18a59a9bba 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -61,9 +61,9 @@ MayaHydraRenderItemAdapter::MayaHydraRenderItemAdapter( const MDagPath& dagPath, const SdfPath& slowId, int fastId, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MRenderItem& ri) - : MayaHydraAdapter(MObject(), slowId, producer) + : MayaHydraAdapter(MObject(), slowId, mayaHydraSceneIndex) , _dagPath(dagPath) , _primitive(ri.primitive()) , _name(ri.name()) @@ -81,7 +81,7 @@ void MayaHydraRenderItemAdapter::UpdateTransform(const MRenderItem& ri) MMatrix matrix; if (ri.getMatrix(matrix) == MStatus::kSuccess) { _transform[0] = GetGfMatrixFromMaya(matrix); - if (GetSceneProducer()->GetParams().motionSamplesEnabled()) { + if (GetMayaHydraSceneIndex()->GetParams().motionSamplesEnabled()) { MDGContextGuard guard(MAnimControl::currentTime() + 1.0); _transform[1] = GetGfMatrixFromMaya(matrix); } else { @@ -94,12 +94,12 @@ bool MayaHydraRenderItemAdapter::IsSupported() const { switch (_primitive) { case MHWRender::MGeometry::Primitive::kTriangles: - return GetSceneProducer()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->mesh); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->mesh); case MHWRender::MGeometry::Primitive::kLines: case MHWRender::MGeometry::Primitive::kLineStrip: - return GetSceneProducer()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->basisCurves); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->basisCurves); case MHWRender::MGeometry::Primitive::kPoints: - return GetSceneProducer()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->points); + return GetMayaHydraSceneIndex()->GetRenderIndex().IsRprimTypeSupported(HdPrimTypeTokens->points); default: return false; } } @@ -108,14 +108,14 @@ void MayaHydraRenderItemAdapter::_InsertRprim(MayaHydraAdapter* adapter) { switch (GetPrimitive()) { case MHWRender::MGeometry::Primitive::kTriangles: - GetSceneProducer()->InsertRprim(adapter, HdPrimTypeTokens->mesh, GetID(), {}); + GetMayaHydraSceneIndex()->InsertPrim(adapter, HdPrimTypeTokens->mesh, GetID()); break; case MHWRender::MGeometry::Primitive::kLines: case MHWRender::MGeometry::Primitive::kLineStrip: - GetSceneProducer()->InsertRprim(adapter, HdPrimTypeTokens->basisCurves, GetID(), {}); + GetMayaHydraSceneIndex()->InsertPrim(adapter, HdPrimTypeTokens->basisCurves, GetID()); break; case MHWRender::MGeometry::Primitive::kPoints: - GetSceneProducer()->InsertRprim(adapter, HdPrimTypeTokens->points, GetID(), {}); + GetMayaHydraSceneIndex()->InsertPrim(adapter, HdPrimTypeTokens->points, GetID()); break; default: assert(false); // unexpected/unsupported primitive type @@ -123,7 +123,7 @@ void MayaHydraRenderItemAdapter::_InsertRprim(MayaHydraAdapter* adapter) } } -void MayaHydraRenderItemAdapter::_RemoveRprim() { GetSceneProducer()->RemoveRprim(GetID());} +void MayaHydraRenderItemAdapter::_RemoveRprim() { GetMayaHydraSceneIndex()->RemovePrim(GetID());} // We receive in that function the changes made in the Maya viewport between the last frame rendered // and the current frame @@ -310,7 +310,7 @@ void MayaHydraRenderItemAdapter::UpdateFromDelta(const UpdateFromDeltaData& data switch (GetPrimitive()) { case MGeometry::Primitive::kTriangles: _topology.reset(new HdMeshTopology( - (GetSceneProducer()->GetParams().displaySmoothMeshes + (GetMayaHydraSceneIndex()->GetParams().displaySmoothMeshes || GetDisplayStyle().refineLevel > 0) ? PxOsdOpenSubdivTokens->catmullClark : PxOsdOpenSubdivTokens->none, @@ -377,7 +377,7 @@ VtValue MayaHydraRenderItemAdapter::Get(const TfToken& key) void MayaHydraRenderItemAdapter::MarkDirty(HdDirtyBits dirtyBits) { if (dirtyBits != 0) { - GetSceneProducer()->MarkRprimDirty(GetID(), dirtyBits); + GetMayaHydraSceneIndex()->MarkRprimDirty(GetID(), dirtyBits); } } @@ -431,8 +431,8 @@ bool MayaHydraRenderItemAdapter::GetVisible() if (_isHideOnPlayback) { // MAYA-127216: Remove dependency on parent class MayaHydraAdapter. This will let us use // MayaHydraSceneDelegate directly - auto sceneProducer = static_cast(GetSceneProducer()); - return !sceneProducer->GetPlaybackRunning(); + auto mayaHydraSceneIndex = static_cast(GetMayaHydraSceneIndex()); + return !mayaHydraSceneIndex->GetPlaybackRunning(); } return _visible; diff --git a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h index bbec8f1969..2878a0d894 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.h @@ -37,7 +37,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; namespace { std::string kRenderItemTypeName = "renderItem"; @@ -61,7 +61,7 @@ class MayaHydraRenderItemAdapter : public MayaHydraAdapter const MDagPath& dagPath, const SdfPath& slowId, int fastId, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MRenderItem& ri); MAYAHYDRALIB_API diff --git a/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.cpp index 90c09fa0f8..2d7263e7fd 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.cpp @@ -37,9 +37,9 @@ TF_REGISTRY_FUNCTION(TfType) */ MayaHydraShapeAdapter::MayaHydraShapeAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dagPath) - : MayaHydraDagAdapter(id, producer, dagPath) + : MayaHydraDagAdapter(id, mayaHydraSceneIndex, dagPath) { _CalculateExtent(); } diff --git a/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.h b/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.h index 8494c8f02c..ada0d72742 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/shapeAdapter.h @@ -22,7 +22,7 @@ PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraSceneProducer; +class MayaHydraSceneIndex; /** * \brief MayaHydraShapeAdapter is an adapter to translate from Maya shapes to hydra @@ -35,7 +35,7 @@ class MayaHydraShapeAdapter : public MayaHydraDagAdapter MAYAHYDRALIB_API MayaHydraShapeAdapter( const SdfPath& id, - MayaHydraSceneProducer* producer, + MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dagPath); public: diff --git a/lib/mayaHydra/hydraExtensions/adapters/spotLightAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/spotLightAdapter.cpp index 92f8b73bf4..e1b7f1e70b 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/spotLightAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/spotLightAdapter.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include @@ -70,14 +70,14 @@ float GetSpotFalloff(MFnSpotLight& mayaLight) { return static_cast(mayaLi class MayaHydraSpotLightAdapter : public MayaHydraLightAdapter { public: - MayaHydraSpotLightAdapter(MayaHydraSceneProducer* producer, const MDagPath& dag) - : MayaHydraLightAdapter(producer, dag) + MayaHydraSpotLightAdapter(MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) + : MayaHydraLightAdapter(mayaHydraSceneIndex, dag) { } const TfToken& LightType() const override { - if (GetSceneProducer()->IsHdSt()) { + if (GetMayaHydraSceneIndex()->IsHdSt()) { return HdPrimTypeTokens->simpleLight; } else { return HdPrimTypeTokens->sphereLight; @@ -159,8 +159,8 @@ TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraAdapterRegistry, pointLight) { MayaHydraAdapterRegistry::RegisterLightAdapter( TfToken("spotLight"), - [](MayaHydraSceneProducer* producer, const MDagPath& dag) -> MayaHydraLightAdapterPtr { - return MayaHydraLightAdapterPtr(new MayaHydraSpotLightAdapter(producer, dag)); + [](MayaHydraSceneIndex* mayaHydraSceneIndex, const MDagPath& dag) -> MayaHydraLightAdapterPtr { + return MayaHydraLightAdapterPtr(new MayaHydraSpotLightAdapter(mayaHydraSceneIndex, dag)); }); } diff --git a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp deleted file mode 100644 index 3204cf303a..0000000000 --- a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp +++ /dev/null @@ -1,216 +0,0 @@ -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -// 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 "mayaHydraSceneProducer.h" - -#include -#include - -#include -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -MayaHydraSceneProducer::MayaHydraSceneProducer( - const std::shared_ptr& renderIndexProxy, - const SdfPath& id, - MayaHydraInitData& initData, - bool lightEnabled -) : _renderIndexProxy(renderIndexProxy) -{ - initData.name = TfToken("MayaHydraSceneIndex"); - initData.delegateID = id.AppendChild( - TfToken(TfStringPrintf("_Index_MayaHydraSceneIndex_%p", this))); - initData.producer = this; - _sceneIndex = MayaHydraSceneIndex::New(initData, lightEnabled); - TF_VERIFY(_sceneIndex, "Maya Hydra scene index not found, check mayaHydra plugin installation."); -} - -MayaHydraSceneProducer::~MayaHydraSceneProducer() -{ - _renderIndexProxy->RemoveSceneIndex(_sceneIndex); - _sceneIndex->RemoveCallbacksAndDeleteAdapters();//This should be called before calling _sceneIndex.Reset(); which will call the destructor if the ref count reaches 0 - _sceneIndex.Reset(); -} - -#ifdef CODE_COVERAGE_WORKAROUND -void MayaHydraSceneProducer::Cleanup() -{ - _sceneIndex->RemoveCallbacksAndDeleteAdapters(); -} -#endif - -void MayaHydraSceneProducer::HandleCompleteViewportScene(const MDataServerOperation::MViewportScene& scene, MFrameContext::DisplayStyle ds) -{ - return _sceneIndex->HandleCompleteViewportScene(scene, ds); -} - -void MayaHydraSceneProducer::Populate() -{ - _sceneIndex->Populate(); - //Add the scene index as an input scene index of the merging scene index - _renderIndexProxy->InsertSceneIndex(_sceneIndex, SdfPath::AbsoluteRootPath()); -} - -SdfPath MayaHydraSceneProducer::SetCameraViewport(const MDagPath& camPath, const GfVec4d& viewport) -{ - return _sceneIndex->SetCameraViewport(camPath, viewport); -} - -void MayaHydraSceneProducer::SetLightsEnabled(const bool enabled) -{ - return _sceneIndex->SetLightsEnabled(enabled); -} - -void MayaHydraSceneProducer::SetDefaultLightEnabled(const bool enabled) -{ - _sceneIndex->SetDefaultLightEnabled(enabled); -} - - -void MayaHydraSceneProducer::SetDefaultLight(const GlfSimpleLight& light) -{ - _sceneIndex->SetDefaultLight(light); -} - -const MayaHydraParams& MayaHydraSceneProducer::GetParams() const -{ - return _sceneIndex->GetParams(); -} - -void MayaHydraSceneProducer::SetParams(const MayaHydraParams& params) -{ - return _sceneIndex->SetParams(params); -} - -bool MayaHydraSceneProducer::AddPickHitToSelectionList( - const HdxPickHit& hit, - const MHWRender::MSelectionInfo& selectInfo, - MSelectionList& selectionList, - MPointArray& worldSpaceHitPts) -{ - return _sceneIndex->AddPickHitToSelectionList( - hit, - selectInfo, - selectionList, - worldSpaceHitPts); -} - -HdRenderIndex& MayaHydraSceneProducer::GetRenderIndex() -{ - return _sceneIndex->GetRenderIndex(); -} - -bool MayaHydraSceneProducer::IsHdSt() const -{ - return _sceneIndex->IsHdSt(); -} - -bool MayaHydraSceneProducer::GetPlaybackRunning() const -{ - return false; -} - -SdfPath MayaHydraSceneProducer::GetPrimPath(const MDagPath& dg, bool isSprim) -{ - return _sceneIndex->GetPrimPath(dg, isSprim); -} - -void MayaHydraSceneProducer::InsertRprim( - MayaHydraAdapter* adapter, - const TfToken& typeId, - const SdfPath& id, - const SdfPath& instancerId) -{ - return _sceneIndex->InsertPrim(adapter, typeId, id); -} - -void MayaHydraSceneProducer::RemoveRprim(const SdfPath& id) -{ - _sceneIndex->RemovePrim(id); -} - -void MayaHydraSceneProducer::MarkRprimDirty(const SdfPath& id, HdDirtyBits dirtyBits) -{ - _sceneIndex->MarkRprimDirty(id, dirtyBits); -} - -void MayaHydraSceneProducer::MarkInstancerDirty(const SdfPath& id, HdDirtyBits dirtyBits) -{ - _sceneIndex->MarkInstancerDirty(id, dirtyBits); -} - -void MayaHydraSceneProducer::InsertSprim( - MayaHydraAdapter* adapter, - const TfToken& typeId, - const SdfPath& id, - HdDirtyBits initialBits) -{ - _sceneIndex->InsertPrim(adapter, typeId, id); -} - -void MayaHydraSceneProducer::RemoveSprim(const TfToken& typeId, const SdfPath& id) -{ - _sceneIndex->RemovePrim(id); -} - -void MayaHydraSceneProducer::MarkSprimDirty(const SdfPath& id, HdDirtyBits dirtyBits) -{ - _sceneIndex->MarkSprimDirty(id, dirtyBits); -} - -SdfPath MayaHydraSceneProducer::GetDelegateID(TfToken name) const -{ - return _sceneIndex->GetDelegateID(name); -} - -void MayaHydraSceneProducer::PreFrame(const MHWRender::MDrawContext& drawContext) -{ - _sceneIndex->PreFrame(drawContext); -} - -void MayaHydraSceneProducer::PostFrame() -{ - _sceneIndex->PostFrame(); -} - -void MayaHydraSceneProducer::RemoveAdapter(const SdfPath& id) -{ - return _sceneIndex->RemoveAdapter(id); -} - -void MayaHydraSceneProducer::RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj) -{ - return _sceneIndex->RecreateAdapterOnIdle(id, obj); -} - -SdfPath MayaHydraSceneProducer::GetLightedPrimsRootPath() const -{ - return _sceneIndex->GetLightedPrimsRootPath(); -} - -void MayaHydraSceneProducer::MaterialTagChanged(const SdfPath& id) -{ - _sceneIndex->MaterialTagChanged(id); -} - -GfInterval MayaHydraSceneProducer::GetCurrentTimeSamplingInterval() const -{ - return _sceneIndex->GetCurrentTimeSamplingInterval(); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h deleted file mode 100644 index 092082c86c..0000000000 --- a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h +++ /dev/null @@ -1,197 +0,0 @@ -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -// 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. -// - -#ifndef MAYAHYDRASCENEPRODUCER_H -#define MAYAHYDRASCENEPRODUCER_H - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace FVP_NS_DEF { -class RenderIndexProxy; -} - -PXR_NAMESPACE_OPEN_SCOPE -class MayaHydraAdapter; - -/** - * \brief MayaHydraSceneProducer is used to produce the hydra scene from Maya native scene. - */ -class MAYAHYDRALIB_API MayaHydraSceneProducer -{ -public: - MayaHydraSceneProducer( - const std::shared_ptr& renderIndexProxy, - const SdfPath& id, - MayaHydraInitData& initData, - bool lightEnabled); - ~MayaHydraSceneProducer(); - - // Propogate scene changes from Maya to Hydra - void HandleCompleteViewportScene(const MDataServerOperation::MViewportScene& scene, MFrameContext::DisplayStyle ds); - - // Populate primitives from Maya - void Populate(); - - // Add hydra pick points and items to Maya's selection list - bool AddPickHitToSelectionList( - const HdxPickHit& hit, - const MHWRender::MSelectionInfo& selectInfo, - MSelectionList& selectionList, - MPointArray& worldSpaceHitPts); - - // Insert a Rprim to hydra scene - void InsertRprim( - MayaHydraAdapter* adapter, - const TfToken& typeId, - const SdfPath& id, - const SdfPath& instancerId = {}); - - // Remove a Rprim from hydra scene - void RemoveRprim(const SdfPath& id); - - // Mark a Rprim in hydra scene as dirty - void MarkRprimDirty(const SdfPath& id, HdDirtyBits dirtyBits); - - void MarkInstancerDirty(const SdfPath& id, HdDirtyBits dirtyBits); - - // Insert a Sprim to hydra scene - void InsertSprim( - MayaHydraAdapter* adapter, - const TfToken& typeId, - const SdfPath& id, - HdDirtyBits initialBits); - - // Remove a Sprim from hydra scene - void RemoveSprim(const TfToken& typeId, const SdfPath& id); - - // Mark a Sprim in hydra scene as dirty - void MarkSprimDirty(const SdfPath& id, HdDirtyBits dirtyBits); - - // Operation that's performed on rendering a frame - void PreFrame(const MHWRender::MDrawContext& drawContext); - void PostFrame(); - - const MayaHydraParams& GetParams() const; - void SetParams(const MayaHydraParams& params); - - // Adapter operations - void RemoveAdapter(const SdfPath& id); - void RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj); - - // Update viewport info to camera - SdfPath SetCameraViewport(const MDagPath& camPath, const GfVec4d& viewport); - - // Enable or disable lighting - void SetLightsEnabled(const bool enabled); - void SetDefaultLightEnabled(const bool enabled); - void SetDefaultLight(const GlfSimpleLight& light); - - bool IsHdSt() const; - - bool GetPlaybackRunning() const; - - SdfPath GetPrimPath(const MDagPath& dg, bool isSprim); - - HdRenderIndex& GetRenderIndex(); - std::shared_ptr GetRenderIndexProxy(){ return _renderIndexProxy;} - - SdfPath GetLightedPrimsRootPath() const; - - GfInterval GetCurrentTimeSamplingInterval() const; - - // Return the id of underlying delegate by name (MayaHydraSceneIndex or MayaHydraSceneDelegate) - SdfPath GetDelegateID(TfToken name) const; - - MayaHydraSceneIndexRefPtr GetSceneIndex() const { return _sceneIndex; } - - void MaterialTagChanged(const SdfPath& id); - - // Common function to return templated sample types - template - size_t SampleValues(size_t maxSampleCount, float* times, T* samples, Getter getValue) - { - if (ARCH_UNLIKELY(maxSampleCount == 0)) { - return 0; - } - // Fast path 1 sample at current-frame - if (maxSampleCount == 1 - || (!GetParams().motionSamplesEnabled() && GetParams().motionSampleStart == 0)) { - times[0] = 0.0f; - samples[0] = getValue(); - return 1; - } - - const GfInterval shutter = GetCurrentTimeSamplingInterval(); - // Shutter for [-1, 1] (size 2) should have a step of 2 for 2 samples, and 1 for 3 samples - // For sample size of 1 tStep is unused and we match USD and to provide t=shutterOpen - // sample. - const double tStep = maxSampleCount > 1 ? (shutter.GetSize() / (maxSampleCount - 1)) : 0; - const MTime mayaTime = MAnimControl::currentTime(); - size_t nSamples = 0; - double relTime = shutter.GetMin(); - - for (size_t i = 0; i < maxSampleCount; ++i) { - T sample; - { - MDGContextGuard guard(mayaTime + relTime); - sample = getValue(); - } - // We compare the sample to the previous in order to reduce sample count on output. - // Goal is to reduce the amount of samples/keyframes the Hydra delegate has to absorb. - if (!nSamples || sample != samples[nSamples - 1]) { - samples[nSamples] = std::move(sample); - times[nSamples] = relTime; - ++nSamples; - } - relTime += tStep; - } - return nSamples; - } - -#ifdef CODE_COVERAGE_WORKAROUND - void Cleanup(); -#endif - -private: - - // SceneIndex - MayaHydraSceneIndexRefPtr _sceneIndex; - const std::shared_ptr _renderIndexProxy; -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRASCENEPRODUCER_H diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp index 823ecef43e..4cf8789f16 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include @@ -375,8 +374,8 @@ SdfPath MayaHydraSceneIndex::_mayaDefaultLightPath; // Common to all scene index MayaHydraSceneIndex::MayaHydraSceneIndex( MayaHydraInitData& initData, bool lightEnabled) - : _ID(initData.delegateID) - , _producer(initData.producer) + : _ID(initData.delegateID.AppendChild( + TfToken(TfStringPrintf("_Index_MayaHydraSceneIndex_%p", this)))) , _renderIndex(initData.renderIndex) , _isHdSt(initData.isHdSt) , _rprimPath(initData.delegateID.AppendPath(SdfPath(std::string("rprims")))) @@ -476,7 +475,7 @@ void MayaHydraSceneIndex::HandleCompleteViewportScene(const MDataServerOperation } // MAYA-128021: We do not currently support maya instances. MDagPath dagPath(ri.sourceDagPath()); - ria = std::make_shared(dagPath, slowId, fastId, _producer, ri); + ria = std::make_shared(dagPath, slowId, fastId, this, ri); //Update the render item adapter if this render item is an aiSkydomeLight shape ria->SetIsRenderITemAnaiSkydomeLightTriangleShape(isRenderItem_aiSkyDomeLightTriangleShape(ri)); @@ -903,6 +902,11 @@ void MayaHydraSceneIndex::PreFrame(const MHWRender::MDrawContext& context) _lightAdapters); } +bool MayaHydraSceneIndex::GetPlaybackRunning() const +{ + return _isPlaybackRunning; +} + void MayaHydraSceneIndex::PostFrame() { } @@ -1287,7 +1291,7 @@ void MayaHydraSceneIndex::RecreateAdapter(const SdfPath& id, const MObject& obj) template AdapterPtr MayaHydraSceneIndex::_CreateAdapter( const MDagPath& dag, - const std::function& adapterCreator, + const std::function& adapterCreator, Map& adapterMap, bool isSprim) { @@ -1308,7 +1312,7 @@ AdapterPtr MayaHydraSceneIndex::_CreateAdapter( if (TfMapLookupPtr(adapterMap, id) != nullptr) { return {}; } - auto adapter = adapterCreator(GetProducer(), dag); + auto adapter = adapterCreator(this, dag); if (adapter == nullptr || !adapter->IsSupported()) { return {}; } @@ -1447,7 +1451,7 @@ bool MayaHydraSceneIndex::_CreateMaterial(const SdfPath& id, const MObject& obj) if (materialCreator == nullptr) { return false; } - auto materialAdapter = materialCreator(id, GetProducer(), obj); + auto materialAdapter = materialCreator(id, this, obj); if (materialAdapter == nullptr || !materialAdapter->IsSupported()) { return false; } @@ -1511,12 +1515,4 @@ VtValue MayaHydraSceneIndex::GetShadingStyle(SdfPath const& id) return VtValue(); } -const std::shared_ptr MayaHydraSceneIndex::GetRenderIndexProxy() -{ - if (! _producer){ - TF_CODING_ERROR("The MayaHydraSceneProducer pointer should not be a nullptr !"); - } - return _producer->GetRenderIndexProxy(); -} - PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h index f6b1a2dee7..558ba22adc 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h @@ -65,8 +65,7 @@ struct MayaHydraInitData HdRendererPlugin* rendererPluginIn, HdxTaskController* taskControllerIn, const SdfPath& delegateIDIn, - bool isHdStIn, - MayaHydraSceneProducer* producerIn = nullptr) + bool isHdStIn) : name(nameIn) , engine(engineIn) , renderIndex(renderIndexIn) @@ -74,7 +73,6 @@ struct MayaHydraInitData , taskController(taskControllerIn) , delegateID(delegateIDIn) , isHdSt(isHdStIn) - , producer(producerIn) { } @@ -85,7 +83,6 @@ struct MayaHydraInitData HdxTaskController* taskController; SdfPath delegateID; bool isHdSt; - MayaHydraSceneProducer* producer; }; class MayaHydraSceneIndex; @@ -200,11 +197,51 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public bool IsHdSt() const { return _isHdSt; } - MayaHydraSceneProducer* GetProducer() { return _producer; }; - - const std::shared_ptr GetRenderIndexProxy(); + bool GetPlaybackRunning() const; SdfPath SceneIndexPath(const Ufe::Path& appPath) const override; + + // Common function to return templated sample types + template + size_t SampleValues(size_t maxSampleCount, float* times, T* samples, Getter getValue) + { + if (ARCH_UNLIKELY(maxSampleCount == 0)) { + return 0; + } + // Fast path 1 sample at current-frame + if (maxSampleCount == 1 + || (!GetParams().motionSamplesEnabled() && GetParams().motionSampleStart == 0)) { + times[0] = 0.0f; + samples[0] = getValue(); + return 1; + } + + const GfInterval shutter = GetCurrentTimeSamplingInterval(); + // Shutter for [-1, 1] (size 2) should have a step of 2 for 2 samples, and 1 for 3 samples + // For sample size of 1 tStep is unused and we match USD and to provide t=shutterOpen + // sample. + const double tStep = maxSampleCount > 1 ? (shutter.GetSize() / (maxSampleCount - 1)) : 0; + const MTime mayaTime = MAnimControl::currentTime(); + size_t nSamples = 0; + double relTime = shutter.GetMin(); + + for (size_t i = 0; i < maxSampleCount; ++i) { + T sample; + { + MDGContextGuard guard(mayaTime + relTime); + sample = getValue(); + } + // We compare the sample to the previous in order to reduce sample count on output. + // Goal is to reduce the amount of samples/keyframes the Hydra delegate has to absorb. + if (!nSamples || sample != samples[nSamples - 1]) { + samples[nSamples] = std::move(sample); + times[nSamples] = relTime; + ++nSamples; + } + relTime += tStep; + } + return nSamples; + } private: MayaHydraSceneIndex( @@ -214,9 +251,9 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public template AdapterPtr _CreateAdapter( const MDagPath& dag, - const std::function& adapterCreator, + const std::function& adapterCreator, Map& adapterMap, - bool isSprim = false); + bool isSprim = false); MayaHydraLightAdapterPtr CreateLightAdapter(const MDagPath& dagPath); MayaHydraCameraAdapterPtr CreateCameraAdapter(const MDagPath& dagPath); MayaHydraShapeAdapterPtr CreateShapeAdapter(const MDagPath& dagPath); @@ -254,8 +291,6 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public SdfPath _ID; MayaHydraParams _params; - // Weak refs - MayaHydraSceneProducer* _producer = nullptr; HdRenderIndex* _renderIndex = nullptr; // Adapters @@ -271,7 +306,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public std::vector _addedNodes; using LightAdapterCreator - = std::function; + = std::function; std::vector> _lightsToAdd; std::vector _materialTagsChanged; diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index 2712d821f5..fa2467b62a 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -27,6 +27,7 @@ #include "renderOverrideUtils.h" #include "tokens.h" +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include @@ -386,8 +388,8 @@ SdfPath MtohRenderOverride::RendererSceneDelegateId(TfToken rendererName, TfToke return SdfPath(); } - if (instance->_mayaHydraSceneProducer) { - return instance->_mayaHydraSceneProducer->GetDelegateID(sceneDelegateName); + if (instance->_mayaHydraSceneIndex) { + return instance->_mayaHydraSceneIndex->GetDelegateID(sceneDelegateName); } return SdfPath(); } @@ -527,8 +529,8 @@ MStatus MtohRenderOverride::Render( replaceSelectionTask(&tasks); if (scene.changed()) { - if (_mayaHydraSceneProducer) { - _mayaHydraSceneProducer->HandleCompleteViewportScene( + if (_mayaHydraSceneIndex) { + _mayaHydraSceneIndex->HandleCompleteViewportScene( scene, static_cast(drawContext.getDisplayStyle())); } } @@ -591,11 +593,11 @@ MStatus MtohRenderOverride::Render( MayaHydraParams delegateParams = _globals.delegateParams; delegateParams.displaySmoothMeshes = !(displayStyle & MHWRender::MFrameContext::kFlatShaded); - if (_mayaHydraSceneProducer) { - _mayaHydraSceneProducer->SetDefaultLightEnabled(_hasDefaultLighting); - _mayaHydraSceneProducer->SetDefaultLight(_defaultLight); - _mayaHydraSceneProducer->SetParams(delegateParams); - _mayaHydraSceneProducer->PreFrame(drawContext); + if (_mayaHydraSceneIndex) { + _mayaHydraSceneIndex->SetDefaultLightEnabled(_hasDefaultLighting); + _mayaHydraSceneIndex->SetDefaultLight(_defaultLight); + _mayaHydraSceneIndex->SetParams(delegateParams); + _mayaHydraSceneIndex->PreFrame(drawContext); } HdxRenderTaskParams params; @@ -654,10 +656,10 @@ MStatus MtohRenderOverride::Render( Ufe::Path ufeCameraPath = Ufe::PathString::path(ufeCameraPathString.asChar()); bool isMayaCamera = ufeCameraPath.runTimeId() == UfeExtensions::getMayaRunTimeId(); if (isMayaCamera) { - if (_mayaHydraSceneProducer) { - params.camera = _mayaHydraSceneProducer->SetCameraViewport(camPath, _viewport); + if (_mayaHydraSceneIndex) { + params.camera = _mayaHydraSceneIndex->SetCameraViewport(camPath, _viewport); if (vpDirty) - _mayaHydraSceneProducer->MarkSprimDirty(params.camera, HdCamera::DirtyParams); + _mayaHydraSceneIndex->MarkSprimDirty(params.camera, HdCamera::DirtyParams); } } } else { @@ -715,8 +717,8 @@ MStatus MtohRenderOverride::Render( } else { renderFrame(true); } - if (_mayaHydraSceneProducer) { - _mayaHydraSceneProducer->PostFrame(); + if (_mayaHydraSceneIndex) { + _mayaHydraSceneIndex->PostFrame(); } return MStatus::kSuccess; @@ -745,6 +747,13 @@ void MtohRenderOverride::_SetRenderPurposeTags(const MayaHydraParams& delegatePa _taskController->SetRenderTags(mhRenderTags); } +void MtohRenderOverride::_ClearMayaHydraSceneIndex() +{ + _renderIndexProxy->RemoveSceneIndex(_mayaHydraSceneIndex); + _mayaHydraSceneIndex->RemoveCallbacksAndDeleteAdapters(); //This should be called before calling _sceneIndex.Reset(); which will call the destructor if the ref count reaches 0 + _mayaHydraSceneIndex.Reset(); +} + void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& drawContext) { TF_DEBUG(MAYAHYDRALIB_RENDEROVERRIDE_RESOURCES) @@ -780,12 +789,12 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw } MayaHydraInitData mhInitData( - TfToken(), + TfToken("MayaHydraSceneIndex"), _engine, _renderIndex, _rendererPlugin, _taskController, - SdfPath(), + SdfPath("/MayaHydraViewportRenderer"), _isUsingHdSt ); @@ -798,12 +807,15 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw _renderIndexProxy = std::make_shared(_renderIndex); - _mayaHydraSceneProducer.reset(new MayaHydraSceneProducer(_renderIndexProxy, _ID, mhInitData, !_hasDefaultLighting)); - + _mayaHydraSceneIndex = MayaHydraSceneIndex::New(mhInitData, !_hasDefaultLighting); + TF_VERIFY(_mayaHydraSceneIndex, "Maya Hydra scene index not found, check mayaHydra plugin installation."); + VtValue fvpSelectionTrackerValue(_fvpSelectionTracker); _engine.SetTaskContextData(FvpTokens->fvpSelectionState, fvpSelectionTrackerValue); - _mayaHydraSceneProducer->Populate(); + _mayaHydraSceneIndex->Populate(); + //Add the scene index as an input scene index of the merging scene index + _renderIndexProxy->InsertSceneIndex(_mayaHydraSceneIndex, SdfPath::AbsoluteRootPath()); _CreateSceneIndicesChainAfterMergingSceneIndex(); @@ -850,14 +862,15 @@ void MtohRenderOverride::ClearHydraResources(bool fullReset) _sceneIndexRegistry.reset(); } -#ifdef CODE_COVERAGE_WORKAROUND - // Leak the Maya scene index, as its base class HdRetainedSceneIndex - // destructor crashes under Windows clang code coverage build. - _mayaHydraSceneProducer->Cleanup(); - _mayaHydraSceneProducer.release(); -#else - _mayaHydraSceneProducer.reset(); -#endif + #ifdef CODE_COVERAGE_WORKAROUND + // Leak the Maya scene index, as its base class HdRetainedSceneIndex + // destructor crashes under Windows clang code coverage build. + _mayaHydraSceneIndex->RemoveCallbacksAndDeleteAdapters(); + _mayaHydraSceneIndex.release(); + #else + _ClearMayaHydraSceneIndex(); + #endif + _selectionSceneIndex.Reset(); _selection.reset(); @@ -1109,12 +1122,12 @@ void MtohRenderOverride::_PopulateSelectionList( if (hits.empty()) return; - if (_mayaHydraSceneProducer) { + if (_mayaHydraSceneIndex) { MStatus status; if (auto ufeSel = Ufe::NamedSelection::get(kNamedSelection)) { for (const HdxPickHit& hit : hits) { - if (_mayaHydraSceneProducer->AddPickHitToSelectionList( + if (_mayaHydraSceneIndex->AddPickHitToSelectionList( hit, selectInfo, selectionList, worldSpaceHitPts)) { continue; } diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.h b/lib/mayaHydra/mayaPlugin/renderOverride.h index 18da6ee150..ca60dc518e 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.h +++ b/lib/mayaHydra/mayaPlugin/renderOverride.h @@ -34,8 +34,9 @@ #include "pluginUtils.h" #include -#include #include +#include + #include #include @@ -144,7 +145,8 @@ class MtohRenderOverride : public MHWRender::MRenderOverride void _InitHydraResources(const MHWRender::MDrawContext& drawContext); void _RemovePanel(MString panelName); void _DetectMayaDefaultLighting(const MHWRender::MDrawContext& drawContext); - HdRenderDelegate* _GetRenderDelegate(); + HdRenderDelegate* _GetRenderDelegate(); + void _ClearMayaHydraSceneIndex(); void _SetRenderPurposeTags(const MayaHydraParams& delegateParams); void _CreateSceneIndicesChainAfterMergingSceneIndex(); @@ -185,7 +187,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride // Callbacks static void _ClearHydraCallback(void* data); static void _TimerCallback(float, float, void* data); - static void _PlayblastingChanged(bool state, void*); + static void _PlayblastingChanged(bool state, void*); static void _PanelDeletedCallback(const MString& panelName, void* data); static void _RendererChangedCallback( const MString& panelName, @@ -243,7 +245,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride GlfSimpleLight _defaultLight; - std::unique_ptr _mayaHydraSceneProducer; + MayaHydraSceneIndexRefPtr _mayaHydraSceneIndex; /** This class creates the scene index data factories and set them up into the flow viewport library to be able to create DCC * specific scene index data classes without knowing their content in Flow viewport.