From cdab016a06bdbc85aeb7c16777d6c951155a8ae8 Mon Sep 17 00:00:00 2001 From: Rakesh R Date: Tue, 12 Mar 2024 10:57:44 -0400 Subject: [PATCH] First commit for Scene delegate code removal --- doc/mayaHydraDetails.md | 3 - lib/mayaHydra/hydraExtensions/CMakeLists.txt | 2 +- .../hydraExtensions/adapters/adapter.h | 16 +- .../adapters/adapterRegistry.h | 1 - .../adapters/renderItemAdapter.cpp | 1 - .../hydraExtensions/delegates/CMakeLists.txt | 42 - .../delegates/defaultLightDelegate.cpp | 228 --- .../delegates/defaultLightDelegate.h | 74 - .../hydraExtensions/delegates/delegate.cpp | 47 - .../hydraExtensions/delegates/delegate.h | 212 --- .../hydraExtensions/delegates/delegateCtx.cpp | 248 --- .../hydraExtensions/delegates/delegateCtx.h | 110 -- .../delegates/delegateDebugCodes.cpp | 125 -- .../delegates/delegateDebugCodes.h | 58 - .../delegates/delegateRegistry.cpp | 123 -- .../delegates/delegateRegistry.h | 76 - .../delegates/sceneDelegate.cpp | 1612 ----------------- .../hydraExtensions/delegates/sceneDelegate.h | 311 ---- .../delegates/testDelegate.cpp | 64 - .../hydraExtensions/delegates/testDelegate.h | 48 - .../{delegates/params.h => mayaHydraParams.h} | 3 +- .../mayaHydraSceneProducer.cpp | 361 +--- .../hydraExtensions/mayaHydraSceneProducer.h | 19 +- lib/mayaHydra/hydraExtensions/plugInfo.json | 16 - .../mayaHydraDisplayStyleDataSource.h | 2 +- .../sceneIndex/mayaHydraSceneIndex.cpp | 4 +- .../sceneIndex/mayaHydraSceneIndex.h | 39 +- lib/mayaHydra/mayaPlugin/pluginUtils.h | 1 - lib/mayaHydra/mayaPlugin/renderGlobals.h | 2 +- lib/mayaHydra/mayaPlugin/renderOverride.cpp | 12 +- lib/mayaHydra/mayaPlugin/renderOverride.h | 3 +- lib/mayaHydra/mayaPlugin/viewCommand.cpp | 11 - .../mayaUsd/render/mayaToHydra/CMakeLists.txt | 6 - .../render/mayaToHydra/testMtohCommand.py | 5 - 34 files changed, 106 insertions(+), 3779 deletions(-) delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/CMakeLists.txt delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegate.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegate.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateCtx.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateCtx.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.h delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/testDelegate.cpp delete mode 100644 lib/mayaHydra/hydraExtensions/delegates/testDelegate.h rename lib/mayaHydra/hydraExtensions/{delegates/params.h => mayaHydraParams.h} (96%) diff --git a/doc/mayaHydraDetails.md b/doc/mayaHydraDetails.md index 55e9741fa8..8f73017379 100644 --- a/doc/mayaHydraDetails.md +++ b/doc/mayaHydraDetails.md @@ -71,9 +71,6 @@ The maya-usd plugin provides access to USD data files inside Maya by injecting t Experimentally, we have separated the two plugins so that they no longer link together. We use USD's HdSceneIndexPluginRegistry interface to query for a registered HdSceneIndex provider for a Maya node, using a naming convention based on the node type name. Our hope is that this can also be the entry point for third-party plugins to control the viewport rendering of custom node types (MPxLocatorNode or MPxSurfaceShape) purely through the Hydra API instead of through Maya's various viewport APIs. This could potentially replace the Maya APIs MPxSubsceneOverride, MPxDrawOverride, and MPxGeometryOverride. -### Scene Delegate vs Scene Index -MayaHydra's long term plan is to migrate to using Scene Index completely and remove dependency on SceneDelegates. This aligns with the Pixar's recommendation as Hydra will eventually deprecate Scene Delegate support. During this transition phase, we are supporting both Scene Delegate and Scene Indices. By default, Scene Index is used but it can be overridden to use Scene Delegate using the environment variable ```MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX``` to 0. Please note that Scene Delegate mode will not be actively supported and the Scene Index mode is the recommended one. - ### Plugin initialization, render loop and data flow through the plugin. As described in the section above, the plugin hooks into Maya Viewport through the MRenderOverride API. diff --git a/lib/mayaHydra/hydraExtensions/CMakeLists.txt b/lib/mayaHydra/hydraExtensions/CMakeLists.txt index 94f4b776a1..16f2978922 100644 --- a/lib/mayaHydra/hydraExtensions/CMakeLists.txt +++ b/lib/mayaHydra/hydraExtensions/CMakeLists.txt @@ -20,6 +20,7 @@ set(HEADERS api.h debugCodes.h hydraUtils.h + mayaHydraParams.h mayaHydraLibInterface.h mayaHydraLibInterfaceImp.h mayaUtils.h @@ -200,5 +201,4 @@ endif() # subdirectories # ----------------------------------------------------------------------------- add_subdirectory(adapters) -add_subdirectory(delegates) add_subdirectory(sceneIndex) diff --git a/lib/mayaHydra/hydraExtensions/adapters/adapter.h b/lib/mayaHydra/hydraExtensions/adapters/adapter.h index d055e74a7f..76f1fa0d2b 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/adapter.h +++ b/lib/mayaHydra/hydraExtensions/adapters/adapter.h @@ -19,12 +19,26 @@ #define MAYAHYDRALIB_ADAPTER_H #include -#include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include #include diff --git a/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h b/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h index 34fb71f29b..c6672b301b 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h +++ b/lib/mayaHydra/hydraExtensions/adapters/adapterRegistry.h @@ -21,7 +21,6 @@ #include #include #include -#include #include #include diff --git a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp index be02e06d9c..4241bdf286 100644 --- a/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp +++ b/lib/mayaHydra/hydraExtensions/adapters/renderItemAdapter.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include diff --git a/lib/mayaHydra/hydraExtensions/delegates/CMakeLists.txt b/lib/mayaHydra/hydraExtensions/delegates/CMakeLists.txt deleted file mode 100644 index b11a9fe287..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/CMakeLists.txt +++ /dev/null @@ -1,42 +0,0 @@ -# ----------------------------------------------------------------------------- -# sources -# ----------------------------------------------------------------------------- -target_sources(${TARGET_NAME} - PRIVATE - delegate.cpp - delegateCtx.cpp - delegateDebugCodes.cpp - delegateRegistry.cpp - sceneDelegate.cpp - defaultLightDelegate.cpp - testDelegate.cpp -) - -set(HEADERS - delegate.h - delegateCtx.h - delegateDebugCodes.h - delegateRegistry.h - params.h - sceneDelegate.h - defaultLightDelegate.h - testDelegate.h -) - -# ----------------------------------------------------------------------------- -# promoted headers -# ----------------------------------------------------------------------------- -mayaUsd_promoteHeaderList( - HEADERS - ${HEADERS} - BASEDIR - ${TARGET_NAME}/delegates -) - -# ----------------------------------------------------------------------------- -# install -# ----------------------------------------------------------------------------- -install(FILES ${HEADERS} - DESTINATION - ${CMAKE_INSTALL_PREFIX}/include/mayaHydraLib/delegates -) diff --git a/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.cpp b/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.cpp deleted file mode 100644 index f150605f76..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.cpp +++ /dev/null @@ -1,228 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 "defaultLightDelegate.h" - -#include - -#include -#include -#include -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -namespace { -bool AreLightsParamsWeUseDifferent(const GlfSimpleLight& light1, const GlfSimpleLight& light2) -{ - // We only update 3 parameters in the default light : position, diffuse and specular. We don't - // use the primitive's transform. - return (light1.GetPosition() != light2.GetPosition()) - || // Position (in which we actually store a direction, updated when rotating the view for - // example) - (light1.GetDiffuse() != light2.GetDiffuse()) - || (light1.GetSpecular() != light2.GetSpecular()); -} -} // namespace - -// clang-format off -TF_DEFINE_PRIVATE_TOKENS( - _tokens, - - (DefaultMayaLight) -); -// clang-format on - -// MtohDefaultLightDelegate is a separate Hydra custom scene delegate to handle the default lighting -// from Maya. We use another Hydra custom scene delegate to handle the other parts of the Maya -// scene. See sceneDelegate.h in the mayaHydraLib project. If you want to know how to add a custom -// scene index to this plug-in, then please see the registration.cpp file in the mayaHydraLib -// project. -MtohDefaultLightDelegate::MtohDefaultLightDelegate(const InitData& initData) - : HdSceneDelegate(initData.renderIndex, initData.delegateID) - , MayaHydraDelegate(initData) - , _lightPath(initData.delegateID.AppendChild(_tokens->DefaultMayaLight)) -{ -} - -MtohDefaultLightDelegate::~MtohDefaultLightDelegate() { RemovePrim(); } - -void MtohDefaultLightDelegate::Populate() -{ - if (_isPopulated) { - return; - } - if (!_isLightingOn) { - return; - } - _isSupported = IsHdSt() ? GetRenderIndex().IsSprimTypeSupported(HdPrimTypeTokens->simpleLight) - : GetRenderIndex().IsSprimTypeSupported(HdPrimTypeTokens->distantLight); - if (ARCH_UNLIKELY(!_isSupported)) { - return; - } - if (IsHdSt()) { - GetRenderIndex().InsertSprim(HdPrimTypeTokens->simpleLight, this, _lightPath); - } else { - GetRenderIndex().InsertSprim(HdPrimTypeTokens->distantLight, this, _lightPath); - } - GetRenderIndex().GetChangeTracker().SprimInserted(_lightPath, HdLight::AllDirty); - _isPopulated = true; -} - -void MtohDefaultLightDelegate::RemovePrim() -{ - if (!_isPopulated) { - return; - } - if (ARCH_UNLIKELY(!_isSupported)) { - return; - } - if (IsHdSt()) { - GetRenderIndex().RemoveSprim(HdPrimTypeTokens->simpleLight, _lightPath); - } else { - GetRenderIndex().RemoveSprim(HdPrimTypeTokens->distantLight, _lightPath); - } - _isPopulated = false; -} - -void MtohDefaultLightDelegate::SetDefaultLight(const GlfSimpleLight& light) -{ - if (!_isPopulated) { - return; - } - if (ARCH_UNLIKELY(!_isSupported)) { - return; - } - - // We only update 3 parameters in the default light : position (in which we store a direction), - // diffuse and specular - // We don't never update the transform for the default light - const bool lightsParamsWeUseAreDifferent = AreLightsParamsWeUseDifferent(_light, light); - if (lightsParamsWeUseAreDifferent) { - // Update our light - _light.SetDiffuse(light.GetDiffuse()); - _light.SetSpecular(light.GetSpecular()); - _light.SetPosition(light.GetPosition()); - GetRenderIndex().GetChangeTracker().MarkSprimDirty(_lightPath, HdLight::DirtyParams); - } -} - -GfMatrix4d MtohDefaultLightDelegate::GetTransform(const SdfPath& id) -{ - TF_UNUSED(id); - - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_TRANSFORM) - .Msg("MtohDefaultLightDelegate::GetTransform(%s)\n", id.GetText()); - - // We have to rotate the distant to match the simple light's direction - // stored in it's position. Otherwise, the matrix needs to be an identity - // matrix. - if (!IsHdSt()) { - const auto position = _light.GetPosition(); - GfTransform transform; - transform.SetRotation( - GfRotation(GfVec3d(0.0, 0.0, -1.0), GfVec3d(-position[0], -position[1], -position[2]))); - return transform.GetMatrix(); - } - return GfMatrix4d(1.0); -} - -VtValue MtohDefaultLightDelegate::Get(const SdfPath& id, const TfToken& key) -{ - TF_UNUSED(id); - - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET) - .Msg("MtohDefaultLightDelegate::Get(%s, %s)\n", id.GetText(), key.GetText()); - - if (key == HdLightTokens->params) { - return VtValue(_light); - } else if (key == HdTokens->transform) { - return VtValue(GfMatrix4d( - 1.0)); // We don't use the transform but use the position param of the GlfsimpleLight - // Hydra might crash when this is an empty VtValue. - } else if (key == HdLightTokens->shadowCollection) { - if (!_solidPrimitivesRootPaths.empty()) { - // Exclude lines/points primitives from casting shadows by only taking the primitives - // whose root path belongs to _solidPrimitivesRootPaths - HdRprimCollection coll(HdTokens->geometry, HdReprSelector(HdReprTokens->refined)); - coll.SetRootPaths(_solidPrimitivesRootPaths); - return VtValue(coll); - } else { - HdRprimCollection coll(HdTokens->geometry, HdReprSelector(HdReprTokens->refined)); - return VtValue(coll); - } - } else if (key == HdLightTokens->shadowParams) { - HdxShadowParams shadowParams; - shadowParams.enabled = false; - return VtValue(shadowParams); - } - return {}; -} - -VtValue MtohDefaultLightDelegate::GetLightParamValue(const SdfPath& id, const TfToken& paramName) -{ - TF_UNUSED(id); - - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_LIGHT_PARAM_VALUE) - .Msg( - "MtohDefaultLightDelegate::GetLightParamValue(%s, %s)\n", - id.GetText(), - paramName.GetText()); - - if (paramName == HdLightTokens->color || paramName == HdTokens->displayColor) { - const auto diffuse = _light.GetDiffuse(); - return VtValue(GfVec3f(diffuse[0], diffuse[1], diffuse[2])); - } else if (paramName == HdLightTokens->intensity) { - return VtValue(1.0f); - } else if (paramName == HdLightTokens->diffuse) { - return VtValue(1.0f); - } else if (paramName == HdLightTokens->specular) { - return VtValue(0.0f); - } else if (paramName == HdLightTokens->exposure) { - return VtValue(0.0f); - } else if (paramName == HdLightTokens->normalize) { - return VtValue(true); - } else if (paramName == HdLightTokens->angle) { - return VtValue(0.0f); - } else if (paramName == HdLightTokens->shadowEnable) { - return VtValue(false); - } else if (paramName == HdLightTokens->shadowColor) { - return VtValue(GfVec3f(0.0f, 0.0f, 0.0f)); - } else if (paramName == HdLightTokens->enableColorTemperature) { - return VtValue(false); - } - return {}; -} - -bool MtohDefaultLightDelegate::GetVisible(const SdfPath& id) -{ - TF_UNUSED(id); - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_VISIBLE) - .Msg("MtohDefaultLightDelegate::GetVisible(%s)\n", id.GetText()); - return true; -} - -void MtohDefaultLightDelegate::SetLightingOn(bool isLightingOn) -{ - if (_isLightingOn != isLightingOn) { - _isLightingOn = isLightingOn; - - RemovePrim(); - Populate(); - } -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.h b/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.h deleted file mode 100644 index 2e154a0fa4..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/defaultLightDelegate.h +++ /dev/null @@ -1,74 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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. -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -#ifndef MTOH_DEFAULT_LIGHT_DELEGATE_H -#define MTOH_DEFAULT_LIGHT_DELEGATE_H - -#include - -#include -#include -#include -#include -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -//! \brief MtohDefaultLightDelegate is a separate Hydra custom scene delegate to handle the default -//! lighting from Maya. We use another Hydra custom scene delegate to handle the other parts of the -//! Maya scene. See sceneDelegate.h in the mayaHydraLib project. If you want to know how to add a -//! custom scene index to this plug-in, then please see the registration.cpp file in the -//! mayaHydraLib project. - -class MtohDefaultLightDelegate - : public HdSceneDelegate - , public MayaHydraDelegate -{ -public: - MtohDefaultLightDelegate(const InitData& initData); - - ~MtohDefaultLightDelegate() override; - - void Populate() override; - void SetDefaultLight(const GlfSimpleLight& light); - void SetLightingOn(bool isLightingOn); - void SetSolidPrimitivesRootPaths(const SdfPathVector& solidPrimitivesPaths) - { - _solidPrimitivesRootPaths = solidPrimitivesPaths; - } - void RemovePrim(); - -protected: - GfMatrix4d GetTransform(const SdfPath& id) override; - VtValue Get(const SdfPath& id, const TfToken& key) override; - VtValue GetLightParamValue(const SdfPath& id, const TfToken& paramName) override; - bool GetVisible(const SdfPath& id) override; - -private: - GlfSimpleLight _light; - SdfPath _lightPath; - bool _isSupported = false; - /// Is used to avoid lighting any non solid wireframe prim (such as line/points prims) - SdfPathVector _solidPrimitivesRootPaths; - bool _isPopulated = false; - bool _isLightingOn = true; -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MTOH_DEFAULT_LIGHT_DELEGATE_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegate.cpp b/lib/mayaHydra/hydraExtensions/delegates/delegate.cpp deleted file mode 100644 index a9fed73957..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegate.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 "delegate.h" - -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -TF_REGISTRY_FUNCTION(TfType) { TfType::Define(); } - -MayaHydraDelegate::MayaHydraDelegate(const InitData& initData) - : _mayaDelegateID(initData.delegateID) - , _name(initData.name) - , _engine(initData.engine) - , _taskController(initData.taskController) - , _isHdSt(initData.isHdSt) - , _producer(initData.producer) -{ -} - -void MayaHydraDelegate::SetParams(const MayaHydraParams& params) { _params = params; } - -void MayaHydraDelegate::SetCameraForSampling(SdfPath const& camID) -{ - _cameraPathForSampling = camID; -} - -GfInterval MayaHydraDelegate::GetCurrentTimeSamplingInterval() const -{ - return GfInterval(_params.motionSampleStart, _params.motionSampleEnd); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegate.h b/lib/mayaHydra/hydraExtensions/delegates/delegate.h deleted file mode 100644 index 9e1aa169e6..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegate.h +++ /dev/null @@ -1,212 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 MAYAHYDRALIB_DELEGATE_H -#define MAYAHYDRALIB_DELEGATE_H - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -PXR_NAMESPACE_OPEN_SCOPE - -class MayaHydraSceneProducer; - -/** - * \brief MayaHydraDelegate is the base class for delegate classes. - */ -class MayaHydraDelegate -{ -public: - /// Structure passed to initialize this class - struct InitData - { - inline InitData( - TfToken nameIn, - HdEngine& engineIn, - HdRenderIndex* renderIndexIn, - HdRendererPlugin* rendererPluginIn, - HdxTaskController* taskControllerIn, - const SdfPath& delegateIDIn, - bool isHdStIn, - MayaHydraSceneProducer* producerIn = nullptr) - : name(nameIn) - , engine(engineIn) - , renderIndex(renderIndexIn) - , rendererPlugin(rendererPluginIn) - , taskController(taskControllerIn) - , delegateID(delegateIDIn) - , isHdSt(isHdStIn) - , producer(producerIn) - { - } - - TfToken name; - HdEngine& engine; - HdRenderIndex* renderIndex; - HdRendererPlugin* rendererPlugin; - HdxTaskController* taskController; - SdfPath delegateID; - bool isHdSt; - MayaHydraSceneProducer* producer; - ///name of the camera/viewport. - std::string cameraName; - ///viewport width. - int viewportWidth; - ///viewport height. - int viewportHeight; - /// Is the Hydra renderer name for this viewport such as "GL" for Storm or "Arnold" for the Arnold render delegate. - std::string rendererName; - }; - - MAYAHYDRALIB_API - MayaHydraDelegate(const InitData& initData); - MAYAHYDRALIB_API - virtual ~MayaHydraDelegate() = default; - - virtual void Populate() = 0; - virtual void PreFrame(const MHWRender::MDrawContext& context) { } - virtual void PostFrame() { } - - MAYAHYDRALIB_API - virtual void SetParams(const MayaHydraParams& params); - const MayaHydraParams& GetParams() const { return _params; } - - const SdfPath& GetMayaDelegateID() { return _mayaDelegateID; } - TfToken GetName() { return _name; } - bool IsHdSt() { return _isHdSt; } - - virtual void PopulateSelectedPaths( - const MSelectionList& mayaSelection, - SdfPathVector& selectedSdfPaths, - const HdSelectionSharedPtr& selection) - { - } - - virtual bool AddPickHitToSelectionList( - const HdxPickHit& hit, - const MHWRender::MSelectionInfo& selectInfo, - MSelectionList& mayaSelection, - MPointArray& worldSpaceHitPts) - { - return false; - } - - void SetLightsEnabled(const bool enabled) { _lightsEnabled = enabled; } - bool GetLightsEnabled() { return _lightsEnabled; } - - inline HdEngine& GetEngine() { return _engine; } - inline HdxTaskController* GetTaskController() { return _taskController; } - - /// Calls that mirror UsdImagingDelegate - - /// Setup for the shutter open and close to be used for motion sampling. - MAYAHYDRALIB_API - void SetCameraForSampling(SdfPath const& id); - - /// Returns the current interval that will be used when using the - /// sample* API in the scene delegate. - MAYAHYDRALIB_API - GfInterval GetCurrentTimeSamplingInterval() const; - - /// 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; - } - - MayaHydraSceneProducer* GetProducer() { return _producer; }; - -private: - MayaHydraParams _params; - - // Note that because there may not be a 1-to-1 relationship between - // a MayaHydraDelegate and a HdSceneDelegate, this may be different than - // "the" scene delegate id. In the case of MayaHydraSceneDelegate, - // which inherits from HdSceneDelegate, they are the same; but for, ie, - // MayaHydraALProxyDelegate, for which there are multiple HdSceneDelegates - // for each MayaHydraDelegate, the _mayaDelegateID is different from each - // HdSceneDelegate's id. - const SdfPath _mayaDelegateID; - SdfPath _cameraPathForSampling; - TfToken _name; - HdEngine& _engine; - HdxTaskController* _taskController; - bool _isHdSt = false; - bool _lightsEnabled = true; - - MayaHydraSceneProducer* _producer = nullptr; -}; - -using MayaHydraDelegatePtr = std::shared_ptr; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_DELEGATE_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.cpp b/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.cpp deleted file mode 100644 index 48e674672a..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.cpp +++ /dev/null @@ -1,248 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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. -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -#include "delegateCtx.h" - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -PXR_NAMESPACE_OPEN_SCOPE -// Bring the MayaHydra namespace into scope. -// The following code currently lives inside the pxr namespace, but it would make more sense to -// have it inside the MayaHydra namespace. This using statement allows us to use MayaHydra symbols -// from within the pxr namespace as if we were in the MayaHydra namespace. -// Remove this once the code has been moved to the MayaHydra namespace. -using namespace MayaHydra; - -namespace { - -static const SdfPath lightedObjectsPath = SdfPath(std::string("Lighted")); - -template SdfPath toSdfPath(const T& src); -template<> inline SdfPath toSdfPath(const MDagPath& dag) { - return DagPathToSdfPath(dag, false, false); -} -template<> inline SdfPath toSdfPath(const MRenderItem& ri) { - return RenderItemToSdfPath(ri, false); -} - -template SdfPath maybePrepend(const T& src, const SdfPath& inPath); -template<> inline SdfPath maybePrepend( - const MDagPath& , const SdfPath& inPath -) { - return inPath; -} -template<> inline SdfPath maybePrepend( - const MRenderItem& ri, const SdfPath& inPath -) { - // Prepend Maya node name, for organisation and readability. - std::string dependNodeNameString (MFnDependencyNode(ri.sourceDagPath().node()).name().asChar()); - SanitizeNameForSdfPath(dependNodeNameString); - return SdfPath(dependNodeNameString).AppendPath(inPath); -} - -///Returns false if this object should not be lighted, true if it should be lighted -template bool shouldBeLighted(const T& src); -//Template specialization for MDagPath -template<> inline bool shouldBeLighted(const MDagPath& dag) { - return (MFnDependencyNode(dag.node()).typeName().asChar() == TfToken("mesh")); -} -//Template specialization for MRenderItem -template<> inline bool shouldBeLighted(const MRenderItem& ri) { - - //Special case to recognize the Arnold skydome light - if (MayaHydraDelegateCtx::isRenderItem_aiSkyDomeLightTriangleShape(ri)){ - return false;//Don't light the sky dome light shape - } - - return (MHWRender::MGeometry::Primitive::kLines != ri.primitive() - && MHWRender::MGeometry::Primitive::kLineStrip != ri.primitive() - && MHWRender::MGeometry::Primitive::kPoints != ri.primitive()); -} - -template -SdfPath GetMayaPrimPath(const T& src) -{ - SdfPath mayaPath = toSdfPath(src); - if (mayaPath.IsEmpty() || mayaPath.IsAbsoluteRootPath()) - return {}; - - // We cannot append an absolute path (I.e : starting with "/") - if (mayaPath.IsAbsolutePath()) { - mayaPath = mayaPath.MakeRelativePath(SdfPath::AbsoluteRootPath()); - } - - mayaPath = maybePrepend(src, mayaPath); - - if (shouldBeLighted(src)) { - // Use a specific prefix when it's not an object that needs to interact with lights and shadows to be able - // We filter the objects that don't have this prefix in lights HdLightTokens->shadowCollection parameter - mayaPath = lightedObjectsPath.AppendPath(mayaPath); - } - - return mayaPath; -} - -SdfPath _GetRenderItemMayaPrimPath(const MRenderItem& ri) -{ - if (ri.InternalObjectId() == 0) - return {}; - - return GetMayaPrimPath(ri); -} - -SdfPath _GetPrimPath(const SdfPath& base, const MDagPath& dg) -{ - return base.AppendPath(GetMayaPrimPath(dg)); -} - -SdfPath _GetRenderItemPrimPath(const SdfPath& base, const MRenderItem& ri) -{ - return base.AppendPath(_GetRenderItemMayaPrimPath(ri)); -} - -SdfPath _GetRenderItemShaderPrimPath(const SdfPath& base, const MRenderItem& ri) -{ - return _GetRenderItemPrimPath(base, ri); -} - -SdfPath _GetMaterialPath(const SdfPath& base, const MObject& obj) -{ - MStatus status; - MFnDependencyNode node(obj, &status); - if (!status) { - return {}; - } - const auto* chr = node.name().asChar(); - if (chr == nullptr || chr[0] == '\0') { - return {}; - } - - std::string nodeName(chr); - SanitizeNameForSdfPath(nodeName); - return base.AppendPath(SdfPath(nodeName)); -} - -} // namespace - -// MayaHydraDelegateCtx is a set of common functions, and it is the aggregation of our -// MayaHydraDelegate base class and the hydra custom scene delegate class : HdSceneDelegate. -MayaHydraDelegateCtx::MayaHydraDelegateCtx(const InitData& initData) - : HdSceneDelegate(initData.renderIndex, initData.delegateID) - , MayaHydraDelegate(initData) - , _rprimPath(initData.delegateID.AppendPath(SdfPath(std::string("rprims")))) - , _sprimPath(initData.delegateID.AppendPath(SdfPath(std::string("sprims")))) - , _materialPath(initData.delegateID.AppendPath(SdfPath(std::string("materials")))) -{ - GetChangeTracker().AddCollection(TfToken("visible")); -} - -void MayaHydraDelegateCtx::InsertRprim( - const TfToken& typeId, - const SdfPath& id, - const SdfPath& instancerId) -{ - if (!instancerId.IsEmpty()) { - GetRenderIndex().InsertInstancer(this, instancerId); - } - GetRenderIndex().InsertRprim(typeId, this, id); -} - -void MayaHydraDelegateCtx::InsertSprim( - const TfToken& typeId, - const SdfPath& id, - HdDirtyBits initialBits) -{ - GetRenderIndex().InsertSprim(typeId, this, id); - GetChangeTracker().SprimInserted(id, initialBits); -} - -void MayaHydraDelegateCtx::RemoveRprim(const SdfPath& id) { GetRenderIndex().RemoveRprim(id); } - -void MayaHydraDelegateCtx::RemoveSprim(const TfToken& typeId, const SdfPath& id) -{ - GetRenderIndex().RemoveSprim(typeId, id); -} - -void MayaHydraDelegateCtx::RemoveInstancer(const SdfPath& id) -{ - GetRenderIndex().RemoveInstancer(id); -} - -SdfPath MayaHydraDelegateCtx::GetRprimPath() const { return _rprimPath; } - -SdfPath MayaHydraDelegateCtx::GetPrimPath(const MDagPath& dg, bool isSprim) -{ - if (isSprim) { - return _GetPrimPath(_sprimPath, dg); - } else { - return _GetPrimPath(_rprimPath, dg); - } -} - -SdfPath MayaHydraDelegateCtx::GetRenderItemPrimPath(const MRenderItem& ri) -{ - return _GetRenderItemPrimPath(_rprimPath, ri); -} - -SdfPath MayaHydraDelegateCtx::GetRenderItemShaderPrimPath(const MRenderItem& ri) -{ - return _GetRenderItemShaderPrimPath(_rprimPath, ri); -} - -SdfPath MayaHydraDelegateCtx::GetMaterialPath(const MObject& obj) -{ - return _GetMaterialPath(_materialPath, obj); -} - -SdfPath MayaHydraDelegateCtx::GetLightedPrimsRootPath() const -{ - return _rprimPath.AppendPath(lightedObjectsPath); -} - -bool MayaHydraDelegateCtx::isRenderItem_aiSkyDomeLightTriangleShape(const MRenderItem& renderItem) -{ - static const std::string _aiSkyDomeLight ("aiSkyDomeLight"); - - const auto prim = renderItem.primitive(); - MDagPath dag = renderItem.sourceDagPath(); - if( dag.isValid() && (MHWRender::MGeometry::Primitive::kTriangles == prim) && (MHWRender::MRenderItem::DecorationItem == renderItem.type()) ){ - std::string fpName = dag.fullPathName().asChar(); - if (fpName.find(_aiSkyDomeLight) != std::string::npos) { - //This render item is a aiSkyDomeLight - return true; - } - } - - return false; -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.h b/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.h deleted file mode 100644 index 7d8dc665fb..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateCtx.h +++ /dev/null @@ -1,110 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 MAYAHYDRALIB_DELEGATE_BASE_H -#define MAYAHYDRALIB_DELEGATE_BASE_H - -#include - -#include -#include -#include -#include - -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE -/** - * \brief MayaHydraDelegateCtx is a set of common functions, and it is the aggregation of our - * MayaHydraDelegate base class and the hydra custom scene delegate class : HdSceneDelegate. - */ -class MayaHydraDelegateCtx - : public HdSceneDelegate - , public MayaHydraDelegate -{ -protected: - MAYAHYDRALIB_API - MayaHydraDelegateCtx(const InitData& initData); - -public: - enum RebuildFlags : uint32_t - { - RebuildFlagPrim = 1 << 1, - RebuildFlagCallbacks = 1 << 2, - }; - - using HdSceneDelegate::GetRenderIndex; - HdChangeTracker& GetChangeTracker() { return GetRenderIndex().GetChangeTracker(); } - - MAYAHYDRALIB_API - void InsertRprim(const TfToken& typeId, const SdfPath& id, const SdfPath& instancerId = {}); - MAYAHYDRALIB_API - void InsertSprim(const TfToken& typeId, const SdfPath& id, HdDirtyBits initialBits); - MAYAHYDRALIB_API - void RemoveRprim(const SdfPath& id); - MAYAHYDRALIB_API - void RemoveSprim(const TfToken& typeId, const SdfPath& id); - MAYAHYDRALIB_API - void RemoveInstancer(const SdfPath& id); - - /** - * @brief Is used to identify a Maya RenderItem as an aiSkydomeLight triangle shape. - * - * @param[in] renderItem is the Maya RenderItem which you want to test. - * - * @return returns true if it is an aiSkydomeLight triangle shape, false if not. - */ - static bool isRenderItem_aiSkyDomeLightTriangleShape(const MRenderItem& renderItem); - - virtual void RemoveAdapter(const SdfPath& id) { } - virtual void RecreateAdapter(const SdfPath& id, const MObject& obj) { } - virtual void RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj) { } - virtual void RebuildAdapterOnIdle(const SdfPath& id, uint32_t flags) { } - virtual void UpdateDisplayStatusMaterial( - MHWRender::DisplayStatus displayStatus, - const MColor& wireframecolor) - { - } - - /// \brief Notifies the scene delegate when a material tag changes. - /// - /// \param id Id of the Material that changed its tag. - virtual void MaterialTagChanged(const SdfPath& id) { } - MAYAHYDRALIB_API - SdfPath GetPrimPath(const MDagPath& dg, bool isSprim); - MAYAHYDRALIB_API - SdfPath GetRenderItemPrimPath(const MRenderItem& ri); - MAYAHYDRALIB_API - SdfPath GetRenderItemShaderPrimPath(const MRenderItem& ri); - MAYAHYDRALIB_API - SdfPath GetMaterialPath(const MObject& obj); - - MAYAHYDRALIB_API - SdfPath - GetLightedPrimsRootPath() const; /// Get the root path for lighted objects, objects that don't have this in their SdfPath are not lighted - - MAYAHYDRALIB_API - SdfPath GetRprimPath() const; - -private: - SdfPath _rprimPath; - SdfPath _sprimPath; - SdfPath _materialPath; -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_DELEGATE_BASE_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.cpp b/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.cpp deleted file mode 100644 index 390b8e572c..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.cpp +++ /dev/null @@ -1,125 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 "delegateDebugCodes.h" - -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -// Some variables to enable debug printing information for our custom scene delegate - -TF_REGISTRY_FUNCTION(TfDebug) -{ - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET, "Print information about 'Get' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_CULL_STYLE, - "Print information about 'GetCullStyle' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_CURVE_TOPOLOGY, - "Print information about 'GetCurveTopology' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_DISPLAY_STYLE, - "Print information about 'GetDisplayStyle' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_DOUBLE_SIDED, - "Print information about 'GetDoubleSided' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_EXTENT, - "Print information about 'GetExtent' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_INSTANCER_ID, - "Print information about 'GetInstancerId' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_INSTANCE_INDICES, - "Print information about GetInstanceIndices calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_LIGHT_PARAM_VALUE, - "Print information about 'GetLightParamValue' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_MATERIAL_ID, - "Print information about 'GetMaterialId' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_MATERIAL_RESOURCE, - "Print information about 'GetMaterialResource' calls to the " - "delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_MESH_TOPOLOGY, - "Print information about 'GetMeshTopology' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_PRIMVAR_DESCRIPTORS, - "Print information about 'GetPrimvarDescriptors' calls to the " - "delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_RENDER_TAG, - "Print information about 'GetRenderTag' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_SUBDIV_TAGS, - "Print information about 'GetSubdivTags' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_TRANSFORM, - "Print information about 'GetTransform' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_GET_VISIBLE, - "Print information about 'GetVisible' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_INSERTDAG, - "Print information about 'InsertDag' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_IS_ENABLED, - "Print information about 'IsEnabled' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER, - "Print information when the delegate recreates adapters."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_REGISTRY, - "Print information about registration of MayaHydraDelegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_SAMPLE_PRIMVAR, - "Print information about 'SamplePrimvar' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_SAMPLE_TRANSFORM, - "Print information about 'SampleTransform' calls to the delegates."); - - TF_DEBUG_ENVIRONMENT_SYMBOL( - MAYAHYDRALIB_DELEGATE_SELECTION, - "Print information about mayaHydraLib delegate selection."); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.h b/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.h deleted file mode 100644 index ca002ad31a..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateDebugCodes.h +++ /dev/null @@ -1,58 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 MAYAHYDRALIB_DELEGATE_DEBUG_CODES_H -#define MAYAHYDRALIB_DELEGATE_DEBUG_CODES_H - -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -//! \brief Some variables to enable debug printing information for our custom scene delegate - -// clang-format off -TF_DEBUG_CODES( - MAYAHYDRALIB_DELEGATE_GET, - MAYAHYDRALIB_DELEGATE_GET_CULL_STYLE, - MAYAHYDRALIB_DELEGATE_GET_CURVE_TOPOLOGY, - MAYAHYDRALIB_DELEGATE_GET_DISPLAY_STYLE, - MAYAHYDRALIB_DELEGATE_GET_DOUBLE_SIDED, - MAYAHYDRALIB_DELEGATE_GET_EXTENT, - MAYAHYDRALIB_DELEGATE_GET_INSTANCER_ID, - MAYAHYDRALIB_DELEGATE_GET_INSTANCE_INDICES, - MAYAHYDRALIB_DELEGATE_GET_LIGHT_PARAM_VALUE, - MAYAHYDRALIB_DELEGATE_GET_MATERIAL_ID, - MAYAHYDRALIB_DELEGATE_GET_MATERIAL_RESOURCE, - MAYAHYDRALIB_DELEGATE_GET_MESH_TOPOLOGY, - MAYAHYDRALIB_DELEGATE_GET_PRIMVAR_DESCRIPTORS, - MAYAHYDRALIB_DELEGATE_GET_RENDER_TAG, - MAYAHYDRALIB_DELEGATE_GET_SUBDIV_TAGS, - MAYAHYDRALIB_DELEGATE_GET_TRANSFORM, - MAYAHYDRALIB_DELEGATE_GET_VISIBLE, - MAYAHYDRALIB_DELEGATE_INSERTDAG, - MAYAHYDRALIB_DELEGATE_IS_ENABLED, - MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER, - MAYAHYDRALIB_DELEGATE_REGISTRY, - MAYAHYDRALIB_DELEGATE_SAMPLE_PRIMVAR, - MAYAHYDRALIB_DELEGATE_SAMPLE_TRANSFORM, - MAYAHYDRALIB_DELEGATE_SELECTION, - MAYAHYDRALIB_DELEGATE_PRINT_LIGHTS_PARAMETERS_VALUES -); -// clang-format on - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_DELEGATE_DEBUG_CODES_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.cpp b/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.cpp deleted file mode 100644 index 2fabc3a581..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.cpp +++ /dev/null @@ -1,123 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 "delegateRegistry.h" - -#include - -#include -#include -#include -#include - -#include - -PXR_NAMESPACE_OPEN_SCOPE - -TF_INSTANTIATE_SINGLETON(MayaHydraDelegateRegistry); - -// MayaHydraDelegateRegistry is a singleton class to handle hydra delegates - -void MayaHydraDelegateRegistry::RegisterDelegate(const TfToken& name, DelegateCreator creator) -{ - auto& instance = GetInstance(); - for (auto it : instance._delegates) { - if (name == std::get<0>(it)) { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_REGISTRY) - .Msg( - "MayaHydraDelegateRegistry::RegisterDelegate(%s) - existing " - "delegate\n", - name.GetText()); - return; - } - } - - TF_DEBUG(MAYAHYDRALIB_DELEGATE_REGISTRY) - .Msg("MayaHydraDelegateRegistry::RegisterDelegate(%s) - new delegate\n", name.GetText()); - instance._delegates.emplace_back(name, creator); -} - -std::vector MayaHydraDelegateRegistry::GetDelegateNames() -{ - LoadAllDelegates(); - const auto& instance = GetInstance(); - std::vector ret; - ret.reserve(instance._delegates.size()); - for (auto it : instance._delegates) { - ret.push_back(std::get<0>(it)); - } - return ret; -} - -std::vector -MayaHydraDelegateRegistry::GetDelegateCreators() -{ - LoadAllDelegates(); - const auto& instance = GetInstance(); - std::vector ret; - ret.reserve(instance._delegates.size()); - for (auto it : instance._delegates) { - ret.push_back(std::get<1>(it)); - } - return ret; -} - -void MayaHydraDelegateRegistry::SignalDelegatesChanged() -{ - for (const auto& s : GetInstance()._signals) { - s(); - } -} - -void MayaHydraDelegateRegistry::LoadAllDelegates() -{ - static std::once_flag loadAllOnce; - std::call_once(loadAllOnce, _LoadAllDelegates); -} - -void MayaHydraDelegateRegistry::InstallDelegatesChangedSignal(DelegatesChangedSignal signal) -{ - GetInstance()._signals.emplace_back(signal); -} - -void MayaHydraDelegateRegistry::_LoadAllDelegates() -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_REGISTRY) - .Msg("MayaHydraDelegateRegistry::_LoadAllDelegates()\n"); - - TfRegistryManager::GetInstance().SubscribeTo(); - - const TfType& delegateType = TfType::Find(); - if (delegateType.IsUnknown()) { - TF_CODING_ERROR("Could not find MayaHydraDelegate type"); - return; - } - - std::set delegateTypes; - delegateType.GetAllDerivedTypes(&delegateTypes); - - PlugRegistry& plugReg = PlugRegistry::GetInstance(); - - for (auto& subType : delegateTypes) { - const PlugPluginPtr pluginForType = plugReg.GetPluginForType(subType); - if (!pluginForType) { - TF_CODING_ERROR("Could not find plugin for '%s'", subType.GetTypeName().c_str()); - return; - } - pluginForType->Load(); - } -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.h b/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.h deleted file mode 100644 index 177647b72d..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/delegateRegistry.h +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 MAYAHYDRALIB_DELEGATE_REGISTRY_H -#define MAYAHYDRALIB_DELEGATE_REGISTRY_H - -#include - -#include -#include -#include - -#include -#include - -PXR_NAMESPACE_OPEN_SCOPE - -/** - * \brief MayaHydraDelegateRegistry is a singleton class to handle hydra delegates - */ -class MayaHydraDelegateRegistry : public TfSingleton -{ - friend class TfSingleton; - MAYAHYDRALIB_API - MayaHydraDelegateRegistry() = default; - -public: - /// function creates and returns a pointer to a MayaHydraDelegate - may return - /// a nullptr indicate failure, or that the delegate is currently disabled - using DelegateCreator = std::function; - - MAYAHYDRALIB_API - static void RegisterDelegate(const TfToken& name, DelegateCreator creator); - MAYAHYDRALIB_API - static std::vector GetDelegateNames(); - MAYAHYDRALIB_API - static std::vector GetDelegateCreators(); - - /// Signal that some delegate types are now either valid or invalid. - /// ie, say some delegate type is only useful / works when a certain maya - /// plug-in is loaded - you would call this every time that plugin was loaded - /// or unloaded. - MAYAHYDRALIB_API - static void SignalDelegatesChanged(); - - /// Find all MayaHydraDelegate plug-ins, and load them all - MAYAHYDRALIB_API - static void LoadAllDelegates(); - - using DelegatesChangedSignal = std::function; - - MAYAHYDRALIB_API - static void InstallDelegatesChangedSignal(DelegatesChangedSignal signal); - -private: - static void _LoadAllDelegates(); - - std::vector> _delegates; - std::vector _signals; -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_DELEGATE_REGISTRY_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.cpp b/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.cpp deleted file mode 100644 index b17f6180d8..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.cpp +++ /dev/null @@ -1,1612 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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. -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -#include "sceneDelegate.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -int _profilerCategory = MProfiler::addCategory( - "MayaHydraSceneDelegate (mayaHydra)", - "Events for MayaHydraSceneDelegate"); - -#if PXR_VERSION < 2308 -#error USD version v0.23.08+ required -#endif - -#if MAYA_API_VERSION < 20240000 -#error Maya API version 2024+ required -#endif - -namespace { - -// Pixar macros require Pixar namespace. -PXR_NAMESPACE_USING_DIRECTIVE - -TF_DEFINE_ENV_SETTING(MAYA_HYDRA_USE_MESH_ADAPTER_WITH_SCENE_DELEGATE, false, - "Use mesh adapter instead of MRenderItem for Maya meshes."); - -bool useMeshAdapter() { - static bool uma = TfGetEnvSetting(MAYA_HYDRA_USE_MESH_ADAPTER_WITH_SCENE_DELEGATE); - return uma; -} - -bool filterMesh(const MRenderItem& ri) { - return useMeshAdapter() ? - // Filter our mesh render items, and let the mesh adapter handle Maya - // meshes. The MRenderItem::name() for meshes is "StandardShadedItem", - // their MRenderItem::type() is InternalMaterialItem, but - // this type can also be used for other purposes, e.g. face groups, so - // using the name is more appropriate. - (ri.name() == "StandardShadedItem") : false; -} - -} - -PXR_NAMESPACE_OPEN_SCOPE -// Bring the MayaHydra namespace into scope. -// The following code currently lives inside the pxr namespace, but it would make more sense to -// have it inside the MayaHydra namespace. This using statement allows us to use MayaHydra symbols -// from within the pxr namespace as if we were in the MayaHydra namespace. -// Remove this once the code has been moved to the MayaHydra namespace. -using namespace MayaHydra; - -SdfPath MayaHydraSceneDelegate::_fallbackMaterial; -SdfPath MayaHydraSceneDelegate::_mayaDefaultMaterialPath; // Common to all scene delegates -VtValue MayaHydraSceneDelegate::_mayaDefaultMaterial; - -namespace { - -void _onDagNodeAdded(MObject& obj, void* clientData) -{ - reinterpret_cast(clientData)->OnDagNodeAdded(obj); -} - -void _onDagNodeRemoved(MObject& obj, void* clientData) -{ - reinterpret_cast(clientData)->OnDagNodeRemoved(obj); -} - -const MString defaultLightSet("defaultLightSet"); - -void _connectionChanged(MPlug& srcPlug, MPlug& destPlug, bool made, void* clientData) -{ - TF_UNUSED(made); - const auto srcObj = srcPlug.node(); - if (!srcObj.hasFn(MFn::kTransform)) { - return; - } - const auto destObj = destPlug.node(); - if (!destObj.hasFn(MFn::kSet)) { - return; - } - if (srcPlug != MayaAttrs::dagNode::instObjGroups) { - return; - } - MStatus status; - MFnDependencyNode destNode(destObj, &status); - if (ARCH_UNLIKELY(!status)) { - return; - } - if (destNode.name() != defaultLightSet) { - return; - } - auto* delegate = reinterpret_cast(clientData); - MDagPath dag; - status = MDagPath::getAPathTo(srcObj, dag); - if (ARCH_UNLIKELY(!status)) { - return; - } - unsigned int shapesBelow = 0; - dag.numberOfShapesDirectlyBelow(shapesBelow); - for (auto i = decltype(shapesBelow) { 0 }; i < shapesBelow; ++i) { - auto dagCopy = dag; - dagCopy.extendToShapeDirectlyBelow(i); - delegate->UpdateLightVisibility(dagCopy); - } -} - -template inline bool _FindAdapter(const SdfPath&, F) { return false; } - -template -inline bool _FindAdapter(const SdfPath& id, F f, const M0& m0, const M&... m) -{ - auto* adapterPtr = TfMapLookupPtr(m0, id); - if (adapterPtr == nullptr) { - return _FindAdapter(id, f, m...); - } else { - f(static_cast(adapterPtr->get())); - return true; - } -} - -template inline bool _RemoveAdapter(const SdfPath&, F) { return false; } - -template -inline bool _RemoveAdapter(const SdfPath& id, F f, M0& m0, M&... m) -{ - auto* adapterPtr = TfMapLookupPtr(m0, id); - if (adapterPtr == nullptr) { - return _RemoveAdapter(id, f, m...); - } else { - f(static_cast(adapterPtr->get())); - m0.erase(id); - return true; - } -} - -template inline R _GetDefaultValue() { return {}; } - -// This will be nicer to use with automatic parameter deduction for lambdas in -// C++14. -template inline R _GetValue(const SdfPath&, F) -{ - return _GetDefaultValue(); -} - -template -inline R _GetValue(const SdfPath& id, F f, const M0& m0, const M&... m) -{ - auto* adapterPtr = TfMapLookupPtr(m0, id); - if (adapterPtr == nullptr) { - return _GetValue(id, f, m...); - } else { - return f(static_cast(adapterPtr->get())); - } -} - -template inline void _MapAdapter(F) -{ - // Do nothing. -} - -template -inline void _MapAdapter(F f, const M0& m0, const M&... m) -{ - for (auto& it : m0) { - f(static_cast(it.second.get())); - } - _MapAdapter(f, m...); -} - -} // namespace - -// clang-format off -TF_DEFINE_PRIVATE_TOKENS( - _tokens, - - (MayaHydraSceneDelegate) - ((MayaDefaultMaterial, "__maya_default_material__")) - (diffuseColor) - (emissiveColor) - (roughness) - (MayaHydraMeshPoints) - (constantLighting) -); -// clang-format on - -TF_REGISTRY_FUNCTION(TfType) -{ - TfType::Define>(); -} - -TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraDelegateRegistry, MayaHydraSceneDelegate) -{ - MayaHydraDelegateRegistry::RegisterDelegate( - _tokens->MayaHydraSceneDelegate, - [](const MayaHydraDelegate::InitData& initData) -> MayaHydraDelegatePtr { - return std::static_pointer_cast( - std::make_shared(initData)); - }); -} - -// MayaHydraSceneDelegate is a Hydra custom scene delegate used to translate from a Maya scene to -// hydra. If you want to know how to add a custom scene index to this plug-in, then please see the -// registration.cpp file. -MayaHydraSceneDelegate::MayaHydraSceneDelegate(const InitData& initData) - : MayaHydraDelegateCtx(initData) -{ - // TfDebug::Enable(MAYAHYDRALIB_DELEGATE_GET_MATERIAL_ID);//Enable this line to print to the - // output window all SceneDelegate::GetMaterialID(...) calls - // TfDebug::Enable(MAYAHYDRALIB_DELEGATE_GET); //Enable this line to print to the output window - // all SceneDelegate::Get(...) calls - - // Enable the following line to print to the output window the materials parameters type and - // values when there is a change in one of them. - // TfDebug::Enable(MAYAHYDRALIB_ADAPTER_MATERIALS_PRINT_PARAMETERS_VALUES); - - // Enable the following line to print to the output window the lights parameters type and - // values. TfDebug::Enable(MAYAHYDRALIB_DELEGATE_PRINT_LIGHTS_PARAMETERS_VALUES); - - static std::once_flag once; - std::call_once(once, []() { - _mayaDefaultMaterialPath = SdfPath::AbsoluteRootPath().AppendChild( - _tokens->MayaDefaultMaterial); // Is an absolute path, not linked to a scene delegate - _mayaDefaultMaterial = MayaHydraSceneDelegate::CreateMayaDefaultMaterial(); - _fallbackMaterial = SdfPath::EmptyPath(); // Empty path for hydra fallback material - }); -} - -MayaHydraSceneDelegate::~MayaHydraSceneDelegate() -{ - for (auto callback : _callbacks) { - MMessage::removeCallback(callback); - } - _MapAdapter( - [](MayaHydraAdapter* a) { a->RemoveCallbacks(); }, - _renderItemsAdapters, - _shapeAdapters, - _lightAdapters, - _materialAdapters); -} - -VtValue MayaHydraSceneDelegate::CreateMayaDefaultMaterial() -{ - static const MColor kDefaultGrayColor = MColor(0.5f, 0.5f, 0.5f) * 0.8f; - - HdMaterialNetworkMap networkMap; - HdMaterialNetwork network; - HdMaterialNode node; - node.identifier = UsdImagingTokens->UsdPreviewSurface; - node.path = _mayaDefaultMaterialPath; - node.parameters.insert( - { _tokens->diffuseColor, - VtValue(GfVec3f(kDefaultGrayColor[0], kDefaultGrayColor[1], kDefaultGrayColor[2])) }); - network.nodes.push_back(std::move(node)); - networkMap.map.insert({ HdMaterialTerminalTokens->surface, std::move(network) }); - networkMap.terminals.push_back(_mayaDefaultMaterialPath); - return VtValue(networkMap); -} - -void MayaHydraSceneDelegate::_AddRenderItem(const MayaHydraRenderItemAdapterPtr& ria) -{ - const SdfPath& primPath = ria->GetID(); - _renderItemsAdaptersFast.insert({ ria->GetFastID(), ria }); - _renderItemsAdapters.insert({ primPath, ria }); -} - -void MayaHydraSceneDelegate::_RemoveRenderItem(const MayaHydraRenderItemAdapterPtr& ria) -{ - const SdfPath& primPath = ria->GetID(); - _renderItemsAdaptersFast.erase(ria->GetFastID()); - _renderItemsAdapters.erase(primPath); -} - -void MayaHydraSceneDelegate::HandleCompleteViewportScene( - const MDataServerOperation::MViewportScene& scene, - MFrameContext::DisplayStyle displayStyle) -{ - const bool playbackRunning = MAnimControl::isPlaying(); - - if (_isPlaybackRunning != playbackRunning) { - // The value has changed, we are calling SetPlaybackChanged so that every render item that - // has its visibility dependent on the playback should dirty its hydra visibility flag so - // its gets recomputed. - for (auto it = _renderItemsAdapters.begin(); it != _renderItemsAdapters.end(); it++) { - it->second->SetPlaybackChanged(); - } - - _isPlaybackRunning = playbackRunning; - } - - // First loop to get rid of removed items - constexpr int kInvalidId = 0; - for (size_t i = 0; i < scene.mRemovalCount; i++) { - int fastId = scene.mRemovals[i]; - if (fastId == kInvalidId) - continue; - MayaHydraRenderItemAdapterPtr ria = nullptr; - if (_GetRenderItem(fastId, ria)) { - _RemoveRenderItem(ria); - } - assert(ria != nullptr); - } - - // My version, does minimal update - // This loop could, in theory, be parallelized. Unclear how large the gains would be, but maybe - // nothing to lose unless there is some internal contention in USD. - for (size_t i = 0; i < scene.mCount; i++) { - auto flags = scene.mFlags[i]; - if (flags == 0) { - continue; - } - - auto& ri = *scene.mItems[i]; - - // Meshes can optionally be handled by the mesh adapter, rather than by - // render items. - if (filterMesh(ri)) { - continue; - } - - int fastId = ri.InternalObjectId(); - MayaHydraRenderItemAdapterPtr ria = nullptr; - if (!_GetRenderItem(fastId, ria)) { - const SdfPath slowId = GetRenderItemPrimPath(ri); - if (slowId.IsEmpty()){ - continue; - } - // MAYA-128021: We do not currently support maya instances. - MDagPath dagPath(ri.sourceDagPath()); - ria = std::make_shared(dagPath, slowId, fastId, GetProducer(), ri); - - //Update the render item adapter if this render item is an aiSkydomeLight shape - ria->SetIsRenderITemAnaiSkydomeLightTriangleShape(isRenderItem_aiSkyDomeLightTriangleShape(ri)); - - _AddRenderItem(ria); - } - - SdfPath material; - MObject shadingEngineNode; - if (!_GetRenderItemMaterial(ri, material, shadingEngineNode)) { - if (material != kInvalidMaterial) { - _CreateMaterial(material, shadingEngineNode); - } - } - - if (flags & MDataServerOperation::MViewportScene::MVS_changedEffect) { - ria->SetMaterial(material); - } - - MColor wireframeColor; - MHWRender::DisplayStatus displayStatus = MHWRender::kNoStatus; - - MDagPath dagPath = ri.sourceDagPath(); - if (dagPath.isValid()) { - wireframeColor = MGeometryUtilities::wireframeColor( - dagPath); // This is a color managed VP2 color, it will need to be unmanaged at some - // point - displayStatus = MGeometryUtilities::displayStatus(dagPath); - } - - const MayaHydraRenderItemAdapter::UpdateFromDeltaData data( - ri, flags, wireframeColor, displayStatus); - ria->UpdateFromDelta(data); - if (flags & MDataServerOperation::MViewportScene::MVS_changedMatrix) { - ria->UpdateTransform(ri); - } - } -} - -void MayaHydraSceneDelegate::Populate() -{ - MayaHydraAdapterRegistry::LoadAllPlugin(); - auto& renderIndex = GetRenderIndex(); - MStatus status; - MItDag dagIt(MItDag::kDepthFirst); - dagIt.traverseUnderWorld(true); - if (useMeshAdapter()) { - for (; !dagIt.isDone(); dagIt.next()) { - MDagPath path; - dagIt.getPath(path); - InsertDag(path); - } - } - else { - for (; !dagIt.isDone(); dagIt.next()) { - MObject node = dagIt.currentItem(&status); - if (status != MS::kSuccess) - continue; - OnDagNodeAdded(node); - } - } - - auto id = MDGMessage::addNodeAddedCallback(_onDagNodeAdded, "dagNode", this, &status); - if (status) { - _callbacks.push_back(id); - } - id = MDGMessage::addNodeRemovedCallback(_onDagNodeRemoved, "dagNode", this, &status); - if (status) { - _callbacks.push_back(id); - } - id = MDGMessage::addConnectionCallback(_connectionChanged, this, &status); - if (status) { - _callbacks.push_back(id); - } - - // Adding materials sprim to the render index. - if (renderIndex.IsSprimTypeSupported(HdPrimTypeTokens->material)) { - renderIndex.InsertSprim(HdPrimTypeTokens->material, this, _mayaDefaultMaterialPath); - } -} - -MayaHydraSceneDelegate::LightDagPathMap -MayaHydraSceneDelegate::_GetActiveLightPaths() const -{ - LightDagPathMap activeLightPaths; - activeLightPaths.reserve(_lightAdapters.size()); - // By the time this function is called _lightAdapters should already have been populated - // with both Maya and Arnold light adapters. The adapters contain the DagPath information - // we store it here in unordered_map for fast retrieval - for(const auto& entry : _lightAdapters) - { - const auto& dagpath = entry.second->GetDagPath(); - activeLightPaths.emplace(dagpath.fullPathName().asChar(), - dagpath); - } - return activeLightPaths; -} - -// -void MayaHydraSceneDelegate::PreFrame(const MHWRender::MDrawContext& context) -{ - bool useDefaultMaterial - = (context.getDisplayStyle() & MHWRender::MFrameContext::kDefaultMaterial); - if (useDefaultMaterial != _useDefaultMaterial) { - _useDefaultMaterial = useDefaultMaterial; - if (useMeshAdapter()) { - for (const auto& shape : _shapeAdapters) - shape.second->MarkDirty(HdChangeTracker::DirtyMaterialId); - } - } - - const bool xRayEnabled = (context.getDisplayStyle() & MHWRender::MFrameContext::kXray); - if (xRayEnabled != _xRayEnabled) { - _xRayEnabled = xRayEnabled; - for (auto& matAdapter : _materialAdapters) - matAdapter.second->EnableXRayShadingMode(_xRayEnabled); - } - - if (!_materialTagsChanged.empty()) { - if (IsHdSt()) { - for (const auto& id : _materialTagsChanged) { - if (_GetValue( - id, - [](MayaHydraMaterialAdapter* a) { return a->UpdateMaterialTag(); }, - _materialAdapters)) { - auto& renderIndex = GetRenderIndex(); - for (const auto& rprimId : renderIndex.GetRprimIds()) { - const auto* rprim = renderIndex.GetRprim(rprimId); - if (rprim != nullptr && rprim->GetMaterialId() == id) { - RebuildAdapterOnIdle( - rprim->GetId(), MayaHydraDelegateCtx::RebuildFlagPrim); - } - } - } - } - } - _materialTagsChanged.clear(); - } - - if (!_lightsToAdd.empty()) { - for (auto& lightToAdd : _lightsToAdd) { - MDagPath dag; - MStatus status = MDagPath::getAPathTo(lightToAdd.first, dag); - if (!status) { - return; - } - CreateLightAdapter(dag); - } - _lightsToAdd.clear(); - } - - if (useMeshAdapter() && !_addedNodes.empty()) { - for (const auto& obj : _addedNodes) { - if (obj.isNull()) { - continue; - } - MDagPath dag; - MStatus status = MDagPath::getAPathTo(obj, dag); - if (!status) { - return; - } - // We need to check if there is an instanced shape below this dag - // and insert it as well, because they won't be inserted. - if (dag.hasFn(MFn::kTransform)) { - const auto childCount = dag.childCount(); - for (auto child = decltype(childCount) { 0 }; child < childCount; ++child) { - auto dagCopy = dag; - dagCopy.push(dag.child(child)); - if (dagCopy.isInstanced() && dagCopy.instanceNumber() > 0) { - AddNewInstance(dagCopy); - } - } - } else { - InsertDag(dag); - } - } - _addedNodes.clear(); - } - - // We don't need to rebuild something that's already being recreated. - // Since we have a few elements, linear search over vectors is going to - // be okay. - if (!_adaptersToRecreate.empty()) { - for (const auto& it : _adaptersToRecreate) { - RecreateAdapter(std::get<0>(it), std::get<1>(it)); - for (auto itr = _adaptersToRebuild.begin(); itr != _adaptersToRebuild.end(); ++itr) { - if (std::get<0>(it) == std::get<0>(*itr)) { - _adaptersToRebuild.erase(itr); - break; - } - } - } - _adaptersToRecreate.clear(); - } - if (!_adaptersToRebuild.empty()) { - for (const auto& it : _adaptersToRebuild) { - _FindAdapter( - std::get<0>(it), - [&](MayaHydraAdapter* a) { - if (std::get<1>(it) & MayaHydraDelegateCtx::RebuildFlagCallbacks) { - a->RemoveCallbacks(); - a->CreateCallbacks(); - } - if (std::get<1>(it) & MayaHydraDelegateCtx::RebuildFlagPrim) { - a->RemovePrim(); - a->Populate(); - } - }, - _shapeAdapters, - _lightAdapters, - _materialAdapters); - } - _adaptersToRebuild.clear(); - } - if (!IsHdSt()) { - return; - } - - LightDagPathMap activeLightPaths = _GetActiveLightPaths(); - constexpr auto considerAllSceneLights = MHWRender::MDrawContext::kFilteredIgnoreLightLimit; - MStatus status; - const auto numLights = context.numberOfActiveLights(considerAllSceneLights, &status); - - if ((!status || numLights == 0) && (0 == activeLightPaths.size())) { - _MapAdapter( - [](MayaHydraLightAdapter* a) { a->SetLightingOn(false); }, - _lightAdapters); // Turn off all lights - return; - } - - MIntArray intVals; - MMatrix matrixVal; - for (auto i = decltype(numLights) { 0 }; i < numLights; ++i) { - auto* lightParam = context.getLightParameterInformation(i, considerAllSceneLights); - if (lightParam == nullptr) { - continue; - } - const auto lightPath = lightParam->lightPath(); - if (!lightPath.isValid()) { - continue; - } - if (IsUfeItemFromMayaUsd(lightPath)) { - // If this is a UFE light created by maya-usd, it will have already added it to Hydra - continue; - } - - // we do a fast look up here for any new lights that may have been added - auto found = activeLightPaths.find(lightPath.fullPathName().asChar()); - if (found == activeLightPaths.end()) - activeLightPaths.emplace(lightPath.fullPathName().asChar(), - lightPath); - - if (!lightParam->getParameter(MHWRender::MLightParameterInformation::kShadowOn, intVals) - || intVals.length() < 1 || intVals[0] != 1) { - continue; - } - - if (lightParam->getParameter( - MHWRender::MLightParameterInformation::kShadowViewProj, matrixVal)) { - _FindAdapter( - GetPrimPath(lightPath, true), - [&matrixVal](MayaHydraLightAdapter* a) { - a->SetShadowProjectionMatrix(GetGfMatrixFromMaya(matrixVal)); - }, - _lightAdapters); - } - } - - // Turn on active lights, turn off non-active lights, and add non-created active lights. - _MapAdapter( - [&](MayaHydraLightAdapter* a) { - auto lgtAdapter = activeLightPaths.find(a->GetDagPath().fullPathName().asChar()); - if (lgtAdapter != activeLightPaths.end()) { - a->SetLightingOn(true); - activeLightPaths.erase(lgtAdapter); - } else { - a->SetLightingOn(false); - } - }, - _lightAdapters); - for(const auto& entry : activeLightPaths) { - CreateLightAdapter(entry.second); - } -} - -void MayaHydraSceneDelegate::RemoveAdapter(const SdfPath& id) -{ - if (!_RemoveAdapter( - id, - [](MayaHydraAdapter* a) { - a->RemoveCallbacks(); - a->RemovePrim(); - }, - _renderItemsAdapters, - _shapeAdapters, - _lightAdapters, - _materialAdapters)) { - TF_WARN( - "MayaHydraSceneDelegate::RemoveAdapter(%s) -- Adapter does not exists", id.GetText()); - } -} - -void MayaHydraSceneDelegate::RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj) -{ - // We expect this to be a small number of objects, so using a simple linear - // search and a vector is generally a good choice. - for (auto& it : _adaptersToRecreate) { - if (std::get<0>(it) == id) { - std::get<1>(it) = obj; - return; - } - } - _adaptersToRecreate.emplace_back(id, obj); -} - -void MayaHydraSceneDelegate::MaterialTagChanged(const SdfPath& id) -{ - if (std::find(_materialTagsChanged.begin(), _materialTagsChanged.end(), id) - == _materialTagsChanged.end()) { - _materialTagsChanged.push_back(id); - } -} - -void MayaHydraSceneDelegate::RebuildAdapterOnIdle(const SdfPath& id, uint32_t flags) -{ - // We expect this to be a small number of objects, so using a simple linear - // search and a vector is generally a good choice. - for (auto& it : _adaptersToRebuild) { - if (std::get<0>(it) == id) { - std::get<1>(it) |= flags; - return; - } - } - _adaptersToRebuild.emplace_back(id, flags); -} - -void MayaHydraSceneDelegate::RecreateAdapter(const SdfPath& id, const MObject& obj) -{ - if (_RemoveAdapter( - id, - [](MayaHydraAdapter* a) { - a->RemoveCallbacks(); - a->RemovePrim(); - }, - _lightAdapters)) { - if (MObjectHandle(obj).isValid()) { - OnDagNodeAdded(obj); - } else { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER) - .Msg( - "Light prim (%s) not re-created because node no " - "longer valid\n", - id.GetText()); - } - return; - } - - if (useMeshAdapter() && _RemoveAdapter( - id, - [](MayaHydraAdapter* a) { - a->RemoveCallbacks(); - a->RemovePrim(); - }, - _shapeAdapters)) { - MFnDagNode dgNode(obj); - MDagPath path; - dgNode.getPath(path); - if (path.isValid() && MObjectHandle(obj).isValid()) { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER) - .Msg( - "Shape prim (%s) re-created for dag path (%s)\n", - id.GetText(), - path.fullPathName().asChar()); - InsertDag(path); - } else { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER) - .Msg( - "Shape prim (%s) not re-created because node no " - "longer valid\n", - id.GetText()); - } - return; - } - - if (_RemoveAdapter( - id, - [](MayaHydraMaterialAdapter* a) { - a->RemoveCallbacks(); - a->RemovePrim(); - }, - _materialAdapters)) { - auto& renderIndex = GetRenderIndex(); - auto& changeTracker = renderIndex.GetChangeTracker(); - for (const auto& rprimId : renderIndex.GetRprimIds()) { - const auto* rprim = renderIndex.GetRprim(rprimId); - if (rprim != nullptr && rprim->GetMaterialId() == id) { - changeTracker.MarkRprimDirty(rprimId, HdChangeTracker::DirtyMaterialId); - } - } - if (MObjectHandle(obj).isValid()) { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER) - .Msg( - "Material prim (%s) re-created for node (%s)\n", - id.GetText(), - MFnDependencyNode(obj).name().asChar()); - _CreateMaterial(GetMaterialPath(obj), obj); - } else { - TF_DEBUG(MAYAHYDRALIB_DELEGATE_RECREATE_ADAPTER) - .Msg( - "Material prim (%s) not re-created because node no " - "longer valid\n", - id.GetText()); - } - - } else { - TF_WARN( - "MayaHydraSceneDelegate::RecreateAdapterOnIdle(%s) -- Adapter does " - "not exists", - id.GetText()); - } -} - -MayaHydraLightAdapterPtr MayaHydraSceneDelegate::GetLightAdapter(const SdfPath& id) -{ - auto iter = _lightAdapters.find(id); - return iter == _lightAdapters.end() ? nullptr : iter->second; -} - -MayaHydraMaterialAdapterPtr MayaHydraSceneDelegate::GetMaterialAdapter(const SdfPath& id) -{ - auto iter = _materialAdapters.find(id); - return iter == _materialAdapters.end() ? nullptr : iter->second; -} - -template -AdapterPtr MayaHydraSceneDelegate::_CreateAdapter( - const MDagPath& dag, - const std::function& adapterCreator, - Map& adapterMap, - bool isSprim) -{ - // Filter for whether we should even attempt to create the adapter - - if (!adapterCreator) { - return {}; - } - - if (IsUfeItemFromMayaUsd(dag)) { - // UFE items that have a Hydra representation will be added to Hydra by maya-usd - return {}; - } - - // Attempt to create the adapter - - TF_DEBUG(MAYAHYDRALIB_DELEGATE_INSERTDAG) - .Msg( - "MayaHydraSceneDelegate::_CreateAdapter::" - "found %s: %s\n", - MFnDependencyNode(dag.node()).typeName().asChar(), - dag.fullPathName().asChar()); - - const auto id = GetPrimPath(dag, isSprim); - if (TfMapLookupPtr(adapterMap, id) != nullptr) { - return {}; - } - auto adapter = adapterCreator(GetProducer(), dag); - if (adapter == nullptr || !adapter->IsSupported()) { - return {}; - } - adapter->Populate(); - adapter->CreateCallbacks(); - adapterMap.insert({ id, adapter }); - return adapter; -} - -MayaHydraLightAdapterPtr MayaHydraSceneDelegate::CreateLightAdapter(const MDagPath& dagPath) -{ - auto lightCreatorFunc = MayaHydraAdapterRegistry::GetLightAdapterCreator(dagPath); - return _CreateAdapter(dagPath, lightCreatorFunc, _lightAdapters, true); -} - -MayaHydraCameraAdapterPtr MayaHydraSceneDelegate::CreateCameraAdapter(const MDagPath& dagPath) -{ - auto cameraCreatorFunc = MayaHydraAdapterRegistry::GetCameraAdapterCreator(dagPath); - return _CreateAdapter(dagPath, cameraCreatorFunc, _cameraAdapters, true); -} - -MayaHydraShapeAdapterPtr MayaHydraSceneDelegate::CreateShapeAdapter(const MDagPath& dagPath) { - auto shapeCreatorFunc = MayaHydraAdapterRegistry::GetShapeAdapterCreator(dagPath); - return _CreateAdapter(dagPath, shapeCreatorFunc, _shapeAdapters); -} - -namespace { -bool GetShadingEngineNode(const MRenderItem& ri, MObject& shadingEngineNode) -{ - MDagPath dagPath = ri.sourceDagPath(); - if (dagPath.isValid()) { - MFnDagNode dagNode(dagPath.node()); - MObjectArray sets, comps; - dagNode.getConnectedSetsAndMembers(dagPath.instanceNumber(), sets, comps, true); - assert(sets.length() == comps.length()); - for (uint32_t i = 0; i < sets.length(); ++i) { - const MObject& object = sets[i]; - if (object.apiType() == MFn::kShadingEngine) { - // To support per-face shading, find the shading node matched with the render item - const MObject& comp = comps[i]; - MObject shadingComp = ri.shadingComponent(); - if (shadingComp.isNull() || comp.isNull() - || MFnComponent(comp).isEqual(shadingComp)) { - shadingEngineNode = object; - return true; - } - } - } - } - return false; -} -} // namespace - -bool MayaHydraSceneDelegate::_GetRenderItemMaterial( - const MRenderItem& ri, - SdfPath& material, - MObject& shadingEngineNode) -{ - if (MHWRender::MGeometry::Primitive::kLines == ri.primitive() - || MHWRender::MGeometry::Primitive::kLineStrip == ri.primitive()) { - material = _fallbackMaterial; // Use fallbackMaterial + constantLighting + displayColor - return true; - } - - if (GetShadingEngineNode(ri, shadingEngineNode)) - // Else try to find associated material node if this is a material shader. - // NOTE: The existing maya material support in hydra expects a shading engine node - { - material = GetMaterialPath(shadingEngineNode); - if (TfMapLookupPtr(_materialAdapters, material) != nullptr) { - return true; - } - } - - return false; -} - -// Analogous to MayaHydraSceneDelegate::InsertDag -bool MayaHydraSceneDelegate::_GetRenderItem(int fastId, MayaHydraRenderItemAdapterPtr& ria) -{ - // Using SdfPath as the hash table key is extremely slow. The cost appears to be GetPrimPath, - // which would depend on MdagPath, which is a wrapper on TdagPath. TdagPath is a very slow - // class and best to avoid in any performance- critical area. Simply workaround for the - // prototype is an additional lookup index based on InternalObjectID. Long term goal would be - // that the plug-in rarely, if ever, deals with TdagPath. - MayaHydraRenderItemAdapterPtr* result = TfMapLookupPtr(_renderItemsAdaptersFast, fastId); - - if (result != nullptr) { - // adapter already exists, return it - ria = *result; - return true; - } - - return false; -} - -void MayaHydraSceneDelegate::OnDagNodeAdded(const MObject& obj) -{ - if (obj.isNull()) - return; - - if (IsUfeItemFromMayaUsd(obj)) { - // UFE items that have a Hydra representation will be added to Hydra by maya-usd - return; - } - - // When not using the mesh adapter we care only about lights for this - // callback. It is used to create a LightAdapter when adding a new light - // in the scene for Hydra rendering. - if (auto lightFn = MayaHydraAdapterRegistry::GetLightAdapterCreator(obj)) { - _lightsToAdd.push_back({ obj, lightFn }); - } - else if (useMeshAdapter()) { - _addedNodes.push_back(obj); - } -} - -void MayaHydraSceneDelegate::OnDagNodeRemoved(const MObject& obj) -{ - const auto it - = std::remove_if(_lightsToAdd.begin(), _lightsToAdd.end(), [&obj](const auto& item) { - return item.first == obj; - }); - - if (it != _lightsToAdd.end()) { - _lightsToAdd.erase(it, _lightsToAdd.end()); - } - else if (useMeshAdapter()) { - const auto it = std::remove_if(_addedNodes.begin(), _addedNodes.end(), [&obj](const auto& item) { return item == obj; }); - - if (it != _addedNodes.end()) { - _addedNodes.erase(it, _addedNodes.end()); - } - } -} - -void MayaHydraSceneDelegate::InsertDag(const MDagPath& dag) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_INSERTDAG) - .Msg( - "MayaHydraSceneDelegate::InsertDag::" - "GetLightsEnabled()=%i\n", - GetLightsEnabled()); - // We don't care about transforms. - if (dag.hasFn(MFn::kTransform)) { - return; - } - - MFnDagNode dagNode(dag); - if (dagNode.isIntermediateObject()) { - return; - } - - if (IsUfeItemFromMayaUsd(dag)) { - // UFE items that have a Hydra representation will be added to Hydra by maya-usd - return; - } - - // Custom lights don't have MFn::kLight. - if (GetLightsEnabled()) { - if (CreateLightAdapter(dag)) - return; - } - if (CreateCameraAdapter(dag)) { - return; - } - // We are inserting a single prim and - // instancer for every instanced mesh. - if (dag.isInstanced() && dag.instanceNumber() > 0) { - return; - } - - auto adapter = CreateShapeAdapter(dag); - if (adapter) { - auto material = adapter->GetMaterial(); - if (material != MObject::kNullObj) { - const auto materialId = GetMaterialPath(material); - if (TfMapLookupPtr(_materialAdapters, materialId) == nullptr) { - _CreateMaterial(materialId, material); - } - } - } -} - -void MayaHydraSceneDelegate::UpdateLightVisibility(const MDagPath& dag) -{ - const auto id = GetPrimPath(dag, true); - _FindAdapter( - id, - [](MayaHydraLightAdapter* a) { - if (a->UpdateVisibility()) { - a->RemovePrim(); - a->Populate(); - a->InvalidateTransform(); - } - }, - _lightAdapters); -} - -// -void MayaHydraSceneDelegate::AddNewInstance(const MDagPath& dag) -{ - MDagPathArray dags; - MDagPath::getAllPathsTo(dag.node(), dags); - const auto dagsLength = dags.length(); - if (dagsLength == 0) { - return; - } - const auto masterDag = dags[0]; - const auto id = GetPrimPath(masterDag, false); - std::shared_ptr masterAdapter; - if (!TfMapLookup(_shapeAdapters, id, &masterAdapter) || masterAdapter == nullptr) { - return; - } - // If dags is 1, we have to recreate the adapter. - if (dags.length() == 1 || !masterAdapter->IsInstanced()) { - RecreateAdapterOnIdle(id, masterDag.node()); - } else { - // If dags is more than one, trigger rebuilding callbacks next call and - // mark dirty. - RebuildAdapterOnIdle(id, MayaHydraDelegateCtx::RebuildFlagCallbacks); - masterAdapter->MarkDirty( - HdChangeTracker::DirtyInstancer | HdChangeTracker::DirtyInstanceIndex - | HdChangeTracker::DirtyPrimvar); - } -} - -void MayaHydraSceneDelegate::SetParams(const MayaHydraParams& params) -{ - const auto& oldParams = GetParams(); - if (oldParams.displaySmoothMeshes != params.displaySmoothMeshes) { - // I couldn't find any other way to turn this on / off. - // I can't convert HdRprim to HdMesh easily and no simple way - // to get the type of the HdRprim from the render index. - // If we want to allow creating multiple rprims and returning an id - // to a subtree, we need to use the HasType function and the mark dirty - // from each adapter. - _MapAdapter( - [](MayaHydraRenderItemAdapter* a) { - if (a->HasType(HdPrimTypeTokens->mesh) || a->HasType(HdPrimTypeTokens->basisCurves) - || a->HasType(HdPrimTypeTokens->points)) { - a->MarkDirty(HdChangeTracker::DirtyTopology); - } - }, - _renderItemsAdapters); - _MapAdapter( - [](MayaHydraDagAdapter* a) { - if (a->HasType(HdPrimTypeTokens->mesh)) { - a->MarkDirty(HdChangeTracker::DirtyTopology); - } - }, - _shapeAdapters); - } - if (oldParams.motionSampleStart != params.motionSampleStart - || oldParams.motionSampleEnd != params.motionSampleEnd) { - _MapAdapter( - [](MayaHydraRenderItemAdapter* a) { - if (a->HasType(HdPrimTypeTokens->mesh) || a->HasType(HdPrimTypeTokens->basisCurves) - || a->HasType(HdPrimTypeTokens->points)) { - a->InvalidateTransform(); - a->MarkDirty(HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyTransform); - } - }, - _renderItemsAdapters); - _MapAdapter( - [](MayaHydraDagAdapter* a) { - if (a->HasType(HdPrimTypeTokens->mesh)) { - a->MarkDirty(HdChangeTracker::DirtyPoints); - } else if (a->HasType(HdPrimTypeTokens->camera)) { - a->MarkDirty(HdCamera::DirtyParams); - } - a->InvalidateTransform(); - a->MarkDirty(HdChangeTracker::DirtyTransform); - }, - _shapeAdapters, - _lightAdapters, - _cameraAdapters); - } - // We need to trigger rebuilding shaders. - if (oldParams.textureMemoryPerTexture != params.textureMemoryPerTexture) { - _MapAdapter( - [](MayaHydraMaterialAdapter* a) { a->MarkDirty(HdMaterial::AllDirty); }, - _materialAdapters); - } - if (oldParams.maximumShadowMapResolution != params.maximumShadowMapResolution) { - _MapAdapter( - [](MayaHydraLightAdapter* a) { a->MarkDirty(HdLight::AllDirty); }, _lightAdapters); - } - MayaHydraDelegate::SetParams(params); -} - -//! \brief Try to obtain maya object corresponding to HdxPickHit and add it to a maya selection -//! list \return whether the conversion was a success -bool MayaHydraSceneDelegate::AddPickHitToSelectionList( - const HdxPickHit& hit, - const MHWRender::MSelectionInfo& selectInfo, - MSelectionList& selectionList, - MPointArray& worldSpaceHitPts) -{ - SdfPath hitId = hit.objectId; - // validate that hit is indeed a maya item. Alternatively, the rprim hit could be an rprim - // defined by a scene index such as maya usd. - if (hitId.HasPrefix(GetRprimPath())) { - _FindAdapter( - hitId, - [&selectionList, &worldSpaceHitPts, &hit](MayaHydraRenderItemAdapter* a) { - // prepare the selection path of the hit item, the transform path is expected if available - const auto& itemPath = a->GetDagPath(); - MDagPath selectPath; - if (MS::kSuccess != MDagPath::getAPathTo(itemPath.transform(), selectPath)) { - selectPath = itemPath; - } - selectionList.add(selectPath); - worldSpaceHitPts.append( - hit.worldSpaceHitPoint[0], - hit.worldSpaceHitPoint[1], - hit.worldSpaceHitPoint[2]); - }, - _renderItemsAdapters); - return true; - } - - return false; -} - -HdMeshTopology MayaHydraSceneDelegate::GetMeshTopology(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_MESH_TOPOLOGY) - .Msg("MayaHydraSceneDelegate::GetMeshTopology(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraAdapter* a) -> HdMeshTopology { return a->GetMeshTopology(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -HdBasisCurvesTopology MayaHydraSceneDelegate::GetBasisCurvesTopology(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_CURVE_TOPOLOGY) - .Msg("MayaHydraSceneDelegate::GetBasisCurvesTopology(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraAdapter* a) -> HdBasisCurvesTopology { return a->GetBasisCurvesTopology(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -PxOsdSubdivTags MayaHydraSceneDelegate::GetSubdivTags(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_SUBDIV_TAGS) - .Msg("MayaHydraSceneDelegate::GetSubdivTags(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraShapeAdapter* a) -> PxOsdSubdivTags { return a->GetSubdivTags(); }, - _shapeAdapters); -} - -GfRange3d MayaHydraSceneDelegate::GetExtent(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_EXTENT) - .Msg("MayaHydraSceneDelegate::GetExtent(%s)\n", id.GetText()); - return _GetValue( - id, [](MayaHydraShapeAdapter* a) -> GfRange3d { return a->GetExtent(); }, _shapeAdapters); -} - -GfMatrix4d MayaHydraSceneDelegate::GetTransform(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_TRANSFORM) - .Msg("MayaHydraSceneDelegate::GetTransform(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraAdapter* a) -> GfMatrix4d { return a->GetTransform(); }, - _shapeAdapters, - _renderItemsAdapters, - _cameraAdapters, - _lightAdapters); -} - -size_t MayaHydraSceneDelegate::SampleTransform( - const SdfPath& id, - size_t maxSampleCount, - float* times, - GfMatrix4d* samples) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_SAMPLE_TRANSFORM) - .Msg( - "MayaHydraSceneDelegate::SampleTransform(%s, %u)\n", - id.GetText(), - static_cast(maxSampleCount)); - return _GetValue( - id, - [maxSampleCount, times, samples](MayaHydraDagAdapter* a) -> size_t { - return a->SampleTransform(maxSampleCount, times, samples); - }, - _shapeAdapters, - _cameraAdapters, - _lightAdapters); -} - -bool MayaHydraSceneDelegate::IsEnabled(const TfToken& option) const -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_IS_ENABLED) - .Msg("MayaHydraSceneDelegate::IsEnabled(%s)\n", option.GetText()); - // Maya scene can't be accessed on multiple threads, - // so I don't think this is safe to enable. - if (option == HdOptionTokens->parallelRprimSync) { - return false; - } - - TF_WARN("MayaHydraSceneDelegate::IsEnabled(%s) -- Unsupported option.\n", option.GetText()); - return false; -} - -VtValue MayaHydraSceneDelegate::Get(const SdfPath& id, const TfToken& key) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET) - .Msg("MayaHydraSceneDelegate::Get(%s, %s)\n", id.GetText(), key.GetText()); - - if (useMeshAdapter() && id.IsPropertyPath()) { - return _GetValue( - id.GetPrimPath(), - [&key](MayaHydraDagAdapter* a) -> VtValue { return a->GetInstancePrimvar(key); }, - _shapeAdapters); - } - - return _GetValue( - id, - [&key](MayaHydraAdapter* a) -> VtValue { return a->Get(key); }, - _shapeAdapters, - _renderItemsAdapters, - _cameraAdapters, - _lightAdapters, - _materialAdapters); -} - -size_t MayaHydraSceneDelegate::SamplePrimvar( - const SdfPath& id, - const TfToken& key, - size_t maxSampleCount, - float* times, - VtValue* samples) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_SAMPLE_PRIMVAR) - .Msg( - "MayaHydraSceneDelegate::SamplePrimvar(%s, %s, %u)\n", - id.GetText(), - key.GetText(), - static_cast(maxSampleCount)); - - if (!useMeshAdapter()) { - return HdSceneDelegate::SamplePrimvar(id, key, maxSampleCount, times, samples); - } - - if (maxSampleCount < 1) { - return 0; - } - if (id.IsPropertyPath()) { - times[0] = 0.0f; - samples[0] = _GetValue( - id.GetPrimPath(), - [&key](MayaHydraDagAdapter* a) -> VtValue { return a->GetInstancePrimvar(key); }, - _shapeAdapters); - return 1; - } - - return _GetValue( - id, - [&key, maxSampleCount, times, samples](MayaHydraShapeAdapter* a) -> size_t { - return a->SamplePrimvar(key, maxSampleCount, times, samples); - }, - _shapeAdapters); -} - -TfToken MayaHydraSceneDelegate::GetRenderTag(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_RENDER_TAG) - .Msg("MayaHydraSceneDelegate::GetRenderTag(%s)\n", id.GetText()); - return _GetValue( - id.GetPrimPath(), - [](MayaHydraAdapter* a) -> TfToken { return a->GetRenderTag(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -HdPrimvarDescriptorVector -MayaHydraSceneDelegate::GetPrimvarDescriptors(const SdfPath& id, HdInterpolation interpolation) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_PRIMVAR_DESCRIPTORS) - .Msg( - "MayaHydraSceneDelegate::GetPrimvarDescriptors(%s, %i)\n", id.GetText(), interpolation); - - if (useMeshAdapter() && id.IsPropertyPath()) { - return _GetValue( - id.GetPrimPath(), - [&interpolation](MayaHydraDagAdapter* a) -> HdPrimvarDescriptorVector { - return a->GetInstancePrimvarDescriptors(interpolation); - }, - _shapeAdapters); - } - - return _GetValue( - id, - [&interpolation](MayaHydraAdapter* a) -> HdPrimvarDescriptorVector { - return a->GetPrimvarDescriptors(interpolation); - }, - _shapeAdapters, - _renderItemsAdapters); -} - -VtValue MayaHydraSceneDelegate::GetLightParamValue(const SdfPath& id, const TfToken& paramName) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_LIGHT_PARAM_VALUE) - .Msg( - "MayaHydraSceneDelegate::GetLightParamValue(%s, %s)\n", - id.GetText(), - paramName.GetText()); - - const VtValue val = _GetValue( - id, - [¶mName](MayaHydraLightAdapter* a) -> VtValue { - return a->GetLightParamValue(paramName); - }, - _lightAdapters); - - if (TfDebug::IsEnabled(MAYAHYDRALIB_DELEGATE_PRINT_LIGHTS_PARAMETERS_VALUES)) { - // Print the lights parameters to the output window - std::string valueAsString = ConvertVtValueToString(val); - cout << "Light : " << id.GetText() << " Parameter : " << paramName.GetText() - << " Value : " << valueAsString << endl; - } - - return val; -} - -VtValue -MayaHydraSceneDelegate::GetCameraParamValue(const SdfPath& cameraId, const TfToken& paramName) -{ - return _GetValue( - cameraId, - [¶mName](MayaHydraCameraAdapter* a) -> VtValue { - return a->GetCameraParamValue(paramName); - }, - _cameraAdapters); -} - -VtIntArray -MayaHydraSceneDelegate::GetInstanceIndices(const SdfPath& instancerId, const SdfPath& prototypeId) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_INSTANCE_INDICES) - .Msg( - "MayaHydraSceneDelegate::GetInstanceIndices(%s, %s)\n", - instancerId.GetText(), - prototypeId.GetText()); - return _GetValue( - instancerId.GetPrimPath(), - [&prototypeId](MayaHydraDagAdapter* a) -> VtIntArray { - return a->GetInstanceIndices(prototypeId); - }, - _shapeAdapters); -} - -SdfPathVector MayaHydraSceneDelegate::GetInstancerPrototypes(SdfPath const& instancerId) -{ - return { instancerId.GetPrimPath() }; -} - -SdfPath MayaHydraSceneDelegate::GetInstancerId(const SdfPath& primId) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_INSTANCER_ID) - .Msg("MayaHydraSceneDelegate::GetInstancerId(%s)\n", primId.GetText()); - // Instancers don't have any instancers yet. - if (primId.IsPropertyPath()) { - return SdfPath(); - } - return _GetValue( - primId, - [](MayaHydraDagAdapter* a) -> SdfPath { return a->GetInstancerID(); }, - _shapeAdapters); -} - -GfMatrix4d MayaHydraSceneDelegate::GetInstancerTransform(SdfPath const& instancerId) -{ - return GfMatrix4d(1.0); -} - -SdfPath MayaHydraSceneDelegate::GetScenePrimPath( - const SdfPath& rprimPath, - int instanceIndex, - HdInstancerContext* instancerContext) -{ - return rprimPath; -} - -bool MayaHydraSceneDelegate::GetVisible(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_VISIBLE) - .Msg("MayaHydraSceneDelegate::GetVisible(%s)\n", id.GetText()); - - return _GetValue( - id, - [](MayaHydraAdapter* a) -> bool { return a->GetVisible(); }, - _shapeAdapters, - _renderItemsAdapters, - _lightAdapters); -} - -bool MayaHydraSceneDelegate::GetDoubleSided(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_DOUBLE_SIDED) - .Msg("MayaHydraSceneDelegate::GetDoubleSided(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraAdapter* a) -> bool { return a->GetDoubleSided(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -HdCullStyle MayaHydraSceneDelegate::GetCullStyle(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_CULL_STYLE) - .Msg("MayaHydraSceneDelegate::GetCullStyle(%s)\n", id.GetText()); - - return _GetValue( - id, - [](MayaHydraAdapter* a) -> HdCullStyle { return a->GetCullStyle(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -HdDisplayStyle MayaHydraSceneDelegate::GetDisplayStyle(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_DISPLAY_STYLE) - .Msg("MayaHydraSceneDelegate::GetDisplayStyle(%s)\n", id.GetText()); - return _GetValue( - id, - [](MayaHydraAdapter* a) -> HdDisplayStyle { return a->GetDisplayStyle(); }, - _shapeAdapters, - _renderItemsAdapters); -} - -SdfPath MayaHydraSceneDelegate::GetMaterialId(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_MATERIAL_ID) - .Msg("MayaHydraSceneDelegate::GetMaterialId(%s)\n", id.GetText()); - - if (_useDefaultMaterial) { - return _mayaDefaultMaterialPath; - } - - auto result = TfMapLookupPtr(_renderItemsAdapters, id); - if (result != nullptr) { - auto& renderItemAdapter = *result; - - // Check if this render item is a wireframe primitive - if (MHWRender::MGeometry::Primitive::kLines == renderItemAdapter->GetPrimitive() - || MHWRender::MGeometry::Primitive::kLineStrip == renderItemAdapter->GetPrimitive()) { - return _fallbackMaterial; - } - - auto& material = renderItemAdapter->GetMaterial(); - - if (material == kInvalidMaterial) { - return _fallbackMaterial; - } - - if (TfMapLookupPtr(_materialAdapters, material) != nullptr) { - return material; - } - } - - if (useMeshAdapter()) { - auto shapeAdapter = TfMapLookupPtr(_shapeAdapters, id); - if (shapeAdapter == nullptr) { - return _fallbackMaterial; - } - auto material = shapeAdapter->get()->GetMaterial(); - if (material == MObject::kNullObj) { - return _fallbackMaterial; - } - auto materialId = GetMaterialPath(material); - if (TfMapLookupPtr(_materialAdapters, materialId) != nullptr) { - return materialId; - } - - return _CreateMaterial(materialId, material) ? materialId : _fallbackMaterial; - } - - return _fallbackMaterial; -} - -VtValue MayaHydraSceneDelegate::GetMaterialResource(const SdfPath& id) -{ - TF_DEBUG(MAYAHYDRALIB_DELEGATE_GET_MATERIAL_RESOURCE) - .Msg("MayaHydraSceneDelegate::GetMaterialResource(%s)\n", id.GetText()); - - if (id == _mayaDefaultMaterialPath) { - return _mayaDefaultMaterial; - } - - if (id == _fallbackMaterial) { - return MayaHydraMaterialAdapter::GetPreviewMaterialResource(id); - } - - auto ret = _GetValue( - id, - [](MayaHydraMaterialAdapter* a) -> VtValue { return a->GetMaterialResource(); }, - _materialAdapters); - return ret.IsEmpty() ? MayaHydraMaterialAdapter::GetPreviewMaterialResource(id) : ret; -} - -bool MayaHydraSceneDelegate::_CreateMaterial(const SdfPath& id, const MObject& obj) -{ - TF_DEBUG(MAYAHYDRALIB_ADAPTER_MATERIALS) - .Msg("MayaHydraSceneDelegate::_CreateMaterial(%s)\n", id.GetText()); - - auto materialCreator = MayaHydraAdapterRegistry::GetMaterialAdapterCreator(obj); - if (materialCreator == nullptr) { - return false; - } - auto materialAdapter = materialCreator(id, GetProducer(), obj); - if (materialAdapter == nullptr || !materialAdapter->IsSupported()) { - return false; - } - - if (_xRayEnabled) { - materialAdapter->EnableXRayShadingMode(_xRayEnabled); // Enable XRay shading mode - } - materialAdapter->Populate(); - materialAdapter->CreateCallbacks(); - _materialAdapters.emplace(id, std::move(materialAdapter)); - return true; -} - -SdfPath MayaHydraSceneDelegate::SetCameraViewport(const MDagPath& camPath, const GfVec4d& viewport) -{ - const SdfPath camID = GetPrimPath(camPath, true); - auto&& cameraAdapter = TfMapLookupPtr(_cameraAdapters, camID); - if (cameraAdapter) { - (*cameraAdapter)->SetViewport(viewport); - return camID; - } - return {}; -} - -VtValue MayaHydraSceneDelegate::GetShadingStyle(SdfPath const& id) -{ - if (auto&& ri = TfMapLookupPtr(_renderItemsAdapters, id)) { - auto primitive = (*ri)->GetPrimitive(); - if (MHWRender::MGeometry::Primitive::kLines == primitive - || MHWRender::MGeometry::Primitive::kLineStrip == primitive) { - return VtValue( - _tokens - ->constantLighting); // Use fallbackMaterial + constantLighting + displayColor - } - } - return MayaHydraDelegateCtx::GetShadingStyle(id); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.h b/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.h deleted file mode 100644 index a1b1dc86b1..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/sceneDelegate.h +++ /dev/null @@ -1,311 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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. -// -// Copyright 2023 Autodesk, Inc. All rights reserved. -// -#ifndef MAYAHYDRALIB_SCENE_DELEGATE_H -#define MAYAHYDRALIB_SCENE_DELEGATE_H - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -/* - * Notes. - * - * To remove the need of casting between different adapter types or - * making the base adapter class too heavy I decided to use 3 different set - * or map types. This adds a bit of extra code to the RemoveAdapter function - * but simplifies the rest of the functions significantly (and no downcasting!). - * - * All this would be probably way nicer / easier with C++14 and the polymorphic - * lambdas. - * - * This also optimizes other things, like it's easier to separate functionality - * that only affects shapes, lights or materials. - */ - -PXR_NAMESPACE_OPEN_SCOPE - -/** - * \brief Hydra custom scene delegate. - * - * MayaHydraSceneDelegate is a Hydra custom scene delegate used to translate - * from a Maya scene to Hydra. - * - * If you want to know how to add a custom scene index to this plug-in, then please see the - * registration.cpp file. - */ - -class MayaHydraSceneDelegate : public MayaHydraDelegateCtx -{ -public: - template using AdapterMap = std::unordered_map; - - MAYAHYDRALIB_API - MayaHydraSceneDelegate(const InitData& initData); - - MAYAHYDRALIB_API - ~MayaHydraSceneDelegate() override; - - MAYAHYDRALIB_API - void Populate() override; - - MAYAHYDRALIB_API - void PreFrame(const MHWRender::MDrawContext& context) override; - - MAYAHYDRALIB_API - void RemoveAdapter(const SdfPath& id) override; - - MAYAHYDRALIB_API - void RecreateAdapter(const SdfPath& id, const MObject& obj) override; - - MAYAHYDRALIB_API - void RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj) override; - - MAYAHYDRALIB_API - void RebuildAdapterOnIdle(const SdfPath& id, uint32_t flags) override; - - /// \brief Notifies the scene delegate when a material tag changes. - /// - /// This function is only affects the render index when its using HdSt. - /// HdSt requires rebuilding the shapes whenever the tags affecting - /// translucency change. - /// - /// \param id Id of the Material that changed its tag. - MAYAHYDRALIB_API - void MaterialTagChanged(const SdfPath& id) override; - - MAYAHYDRALIB_API - MayaHydraLightAdapterPtr GetLightAdapter(const SdfPath& id); - - MAYAHYDRALIB_API - MayaHydraMaterialAdapterPtr GetMaterialAdapter(const SdfPath& id); - - MAYAHYDRALIB_API - void InsertDag(const MDagPath& dag); - - void OnDagNodeAdded(const MObject& obj); - - void OnDagNodeRemoved(const MObject& obj); - - MAYAHYDRALIB_API - void UpdateLightVisibility(const MDagPath& dag); - - MAYAHYDRALIB_API - void AddNewInstance(const MDagPath& dag); - - MAYAHYDRALIB_API - void SetParams(const MayaHydraParams& params) override; - - MAYAHYDRALIB_API - SdfPath SetCameraViewport(const MDagPath& camPath, const GfVec4d& viewport); - - MAYAHYDRALIB_API - void HandleCompleteViewportScene( - const MDataServerOperation::MViewportScene& scene, - MFrameContext::DisplayStyle ds); - - MAYAHYDRALIB_API - bool AddPickHitToSelectionList( - const HdxPickHit& hit, - const MHWRender::MSelectionInfo& selectInfo, - MSelectionList& selectionList, - MPointArray& worldSpaceHitPts) override; - - bool GetPlaybackRunning() const { return _isPlaybackRunning; } - -protected: - - MAYAHYDRALIB_API - HdMeshTopology GetMeshTopology(const SdfPath& id) override; - - MAYAHYDRALIB_API - HdBasisCurvesTopology GetBasisCurvesTopology(const SdfPath& id) override; - - MAYAHYDRALIB_API - PxOsdSubdivTags GetSubdivTags(const SdfPath& id) override; - - MAYAHYDRALIB_API - GfRange3d GetExtent(const SdfPath& id) override; - - MAYAHYDRALIB_API - GfMatrix4d GetTransform(const SdfPath& id) override; - - MAYAHYDRALIB_API - size_t - SampleTransform(const SdfPath& id, size_t maxSampleCount, float* times, GfMatrix4d* samples) - override; - - MAYAHYDRALIB_API - bool GetVisible(const SdfPath& id) override; - - MAYAHYDRALIB_API - bool IsEnabled(const TfToken& option) const override; - - MAYAHYDRALIB_API - bool GetDoubleSided(const SdfPath& id) override; - - MAYAHYDRALIB_API - HdCullStyle GetCullStyle(const SdfPath& id) override; - - MAYAHYDRALIB_API - VtValue GetShadingStyle(const SdfPath& id) override; - - MAYAHYDRALIB_API - HdDisplayStyle GetDisplayStyle(const SdfPath& id) override; - // TfToken GetReprName(const SdfPath& id) override; - - MAYAHYDRALIB_API - VtValue Get(const SdfPath& id, const TfToken& key) override; - - MAYAHYDRALIB_API - size_t SamplePrimvar( - const SdfPath& id, - const TfToken& key, - size_t maxSampleCount, - float* times, - VtValue* samples) override; - - MAYAHYDRALIB_API - TfToken GetRenderTag(SdfPath const& id) override; - - MAYAHYDRALIB_API - HdPrimvarDescriptorVector - GetPrimvarDescriptors(const SdfPath& id, HdInterpolation interpolation) override; - - MAYAHYDRALIB_API - VtValue GetLightParamValue(const SdfPath& id, const TfToken& paramName) override; - - MAYAHYDRALIB_API - VtValue GetCameraParamValue(const SdfPath& cameraId, const TfToken& paramName) override; - - MAYAHYDRALIB_API - VtIntArray GetInstanceIndices(const SdfPath& instancerId, const SdfPath& prototypeId) override; - - MAYAHYDRALIB_API - SdfPathVector GetInstancerPrototypes(SdfPath const& instancerId) override; - - MAYAHYDRALIB_API - SdfPath GetInstancerId(const SdfPath& primId) override; - - MAYAHYDRALIB_API - GfMatrix4d GetInstancerTransform(SdfPath const& instancerId) override; - - MAYAHYDRALIB_API - SdfPath GetScenePrimPath( - const SdfPath& rprimPath, - int instanceIndex, - HdInstancerContext* instancerContext) override; - - MAYAHYDRALIB_API - SdfPath GetMaterialId(const SdfPath& id) override; - - MAYAHYDRALIB_API - VtValue GetMaterialResource(const SdfPath& id) override; - -private: - template - AdapterPtr _CreateAdapter( - const MDagPath& dag, - const std::function& adapterCreator, - Map& adapterMap, - bool isSprim = false); - - MayaHydraLightAdapterPtr CreateLightAdapter(const MDagPath& dagPath); - MayaHydraCameraAdapterPtr CreateCameraAdapter(const MDagPath& dagPath); - MayaHydraShapeAdapterPtr CreateShapeAdapter(const MDagPath& dagPath); - - MAYAHYDRALIB_API - bool _GetRenderItem(int fastId, MayaHydraRenderItemAdapterPtr& adapter); - - - using LightDagPathMap = std::unordered_map; - LightDagPathMap _GetActiveLightPaths() const; - - MAYAHYDRALIB_API - void _AddRenderItem(const MayaHydraRenderItemAdapterPtr& ria); - - MAYAHYDRALIB_API - void _RemoveRenderItem(const MayaHydraRenderItemAdapterPtr& ria); - - MAYAHYDRALIB_API - bool - _GetRenderItemMaterial(const MRenderItem& ri, SdfPath& material, MObject& shadingEngineNode); - - static VtValue CreateMayaDefaultMaterial(); - - bool _CreateMaterial(const SdfPath& id, const MObject& obj); - - /// \brief Unordered Map storing the shape adapters. - AdapterMap _shapeAdapters; - - /// \brief Unordered Map storing the render item adapters. - AdapterMap _renderItemsAdapters; - std::unordered_map _renderItemsAdaptersFast; - - /// \brief Unordered Map storing the light adapters. - AdapterMap _lightAdapters; - /// \brief Unordered Map storing the camera adapters. - AdapterMap _cameraAdapters; - /// \brief Unordered Map storing the material adapters. - AdapterMap _materialAdapters; - std::vector _callbacks; - std::vector> _adaptersToRecreate; - std::vector> _adaptersToRebuild; - // Nodes accumulated during _onDagNodeAdded() callback. - std::vector _addedNodes; - - using LightAdapterCreator - = std::function; - std::vector> _lightsToAdd; - - std::vector _materialTagsChanged; - - /// _fallbackMaterial is an SdfPath used when there is no material assigned to a Maya object - static SdfPath _fallbackMaterial; - /// _mayaDefaultMaterialPath is common to all scene delegates, it's the SdfPath of - /// _mayaDefaultMaterial - static SdfPath _mayaDefaultMaterialPath; - /// _mayaDefaultMaterial is a Hydra material used to override all materials from the scene when - /// _useDefaultMaterial is true - static VtValue _mayaDefaultMaterial; - - bool _useDefaultMaterial = false; - bool _xRayEnabled = false; - bool _isPlaybackRunning = false; -}; - -typedef std::shared_ptr MayaSceneDelegateSharedPtr; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_SCENE_DELEGATE_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/testDelegate.cpp b/lib/mayaHydra/hydraExtensions/delegates/testDelegate.cpp deleted file mode 100644 index 527043fd64..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/testDelegate.cpp +++ /dev/null @@ -1,64 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 "testDelegate.h" - -#include - -#include - -PXR_NAMESPACE_OPEN_SCOPE - -TF_DEFINE_ENV_SETTING( - MAYAHYDRALIB_TEST_DELEGATE_FILE, - "", - "Path for MayaHydraTestDelegate to load"); - -// clang-format off -TF_DEFINE_PRIVATE_TOKENS( - _tokens, - - (MayaHydraTestDelegate) -); -// clang-format on - -TF_REGISTRY_FUNCTION_WITH_TAG(MayaHydraDelegateRegistry, MayaHydraTestDelegate) -{ - if (!TfGetEnvSetting(MAYAHYDRALIB_TEST_DELEGATE_FILE).empty()) { - MayaHydraDelegateRegistry::RegisterDelegate( - _tokens->MayaHydraTestDelegate, - [](const MayaHydraDelegate::InitData& initData) -> MayaHydraDelegatePtr { - return std::static_pointer_cast( - std::make_shared(initData)); - }); - } -} - -/* - * MayaHydraTestDelegate could be used as a test scene delegate, it is not used any more. - */ -MayaHydraTestDelegate::MayaHydraTestDelegate(const InitData& initData) - : MayaHydraDelegate(initData) -{ - _delegate.reset(new UsdImagingDelegate(initData.renderIndex, initData.delegateID)); -} - -void MayaHydraTestDelegate::Populate() -{ - _stage = UsdStage::Open(TfGetEnvSetting(MAYAHYDRALIB_TEST_DELEGATE_FILE)); - _delegate->Populate(_stage->GetPseudoRoot()); -} - -PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/delegates/testDelegate.h b/lib/mayaHydra/hydraExtensions/delegates/testDelegate.h deleted file mode 100644 index 3f3c3e4ec0..0000000000 --- a/lib/mayaHydra/hydraExtensions/delegates/testDelegate.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Copyright 2019 Luma Pictures -// -// 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 MAYAHYDRALIB_TEST_DELEGATE_H -#define MAYAHYDRALIB_TEST_DELEGATE_H - -#include - -#include -#include -#include -#include -#include - -#include - -PXR_NAMESPACE_OPEN_SCOPE - -/** - * \brief MayaHydraTestDelegate could be used as a test scene delegate, it is not used any more. - */ -class MayaHydraTestDelegate : public MayaHydraDelegate -{ -public: - MayaHydraTestDelegate(const InitData& initData); - - void Populate() override; - -private: - std::unique_ptr _delegate; - UsdStageRefPtr _stage; -}; - -PXR_NAMESPACE_CLOSE_SCOPE - -#endif // MAYAHYDRALIB_TEST_DELEGATE_H diff --git a/lib/mayaHydra/hydraExtensions/delegates/params.h b/lib/mayaHydra/hydraExtensions/mayaHydraParams.h similarity index 96% rename from lib/mayaHydra/hydraExtensions/delegates/params.h rename to lib/mayaHydra/hydraExtensions/mayaHydraParams.h index bff5a017a1..39ad9d9da1 100644 --- a/lib/mayaHydra/hydraExtensions/delegates/params.h +++ b/lib/mayaHydra/hydraExtensions/mayaHydraParams.h @@ -1,5 +1,5 @@ // -// Copyright 2019 Luma Pictures +// Copyright 2024 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. @@ -13,6 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // + #ifndef MAYAHYDRALIB_PARAMS_H #define MAYAHYDRALIB_PARAMS_H diff --git a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp index 25586d209d..3204cf303a 100644 --- a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp +++ b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.cpp @@ -16,9 +16,6 @@ #include "mayaHydraSceneProducer.h" -#include -#include -#include #include #include @@ -26,199 +23,78 @@ #include #include -#include - PXR_NAMESPACE_OPEN_SCOPE -TF_DEFINE_ENV_SETTING(MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX, true, - "Enable scene index for Maya native scene."); - -bool enableMayaNativeSceneIndex() { - static bool enable = TfGetEnvSetting(MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX); - return enable; -} - MayaHydraSceneProducer::MayaHydraSceneProducer( const std::shared_ptr& renderIndexProxy, const SdfPath& id, - MayaHydraDelegate::InitData& initData, + MayaHydraInitData& initData, bool lightEnabled ) : _renderIndexProxy(renderIndexProxy) { - if (enableMayaNativeSceneIndex()) - { - 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."); - } - else - { - SdfPathVector solidPrimsRootPaths; - auto delegateNames = MayaHydraDelegateRegistry::GetDelegateNames(); - auto creators = MayaHydraDelegateRegistry::GetDelegateCreators(); - TF_VERIFY(delegateNames.size() == creators.size()); - for (size_t i = 0, n = creators.size(); i < n; ++i) { - const auto& creator = creators[i]; - if (creator == nullptr) { - continue; - } - initData.name = delegateNames[i]; - initData.delegateID = id.AppendChild( - TfToken(TfStringPrintf("_Delegate_%s_%lu_%p", delegateNames[i].GetText(), i, this))); - initData.producer = this; - auto newDelegate = creator(initData); - if (newDelegate) { - // Call SetLightsEnabled before the delegate is populated - newDelegate->SetLightsEnabled(lightEnabled); - _sceneDelegate - = std::dynamic_pointer_cast(newDelegate); - if (TF_VERIFY( - _sceneDelegate, - "Maya Hydra scene delegate not found, check mayaHydra plugin installation.")) { - solidPrimsRootPaths.push_back(_sceneDelegate->GetLightedPrimsRootPath()); - } - _delegates.emplace_back(std::move(newDelegate)); - } - } - - initData.delegateID - = id.AppendChild(TfToken(TfStringPrintf("_DefaultLightDelegate_%p", this))); - _defaultLightDelegate.reset(new MtohDefaultLightDelegate(initData)); - // Set the scene delegate SolidPrimitivesRootPaths for the lines and points primitives to be - // ignored by the default light - _defaultLightDelegate->SetSolidPrimitivesRootPaths(solidPrimsRootPaths); - } + 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() { - if (enableMayaNativeSceneIndex()) - { - _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(); - } - _delegates.clear(); + _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() { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->RemoveCallbacksAndDeleteAdapters(); - } + _sceneIndex->RemoveCallbacksAndDeleteAdapters(); } #endif void MayaHydraSceneProducer::HandleCompleteViewportScene(const MDataServerOperation::MViewportScene& scene, MFrameContext::DisplayStyle ds) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->HandleCompleteViewportScene(scene, ds); - } - else - { - return _sceneDelegate->HandleCompleteViewportScene(scene, ds); - } + return _sceneIndex->HandleCompleteViewportScene(scene, ds); } void MayaHydraSceneProducer::Populate() { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->Populate(); - //Add the scene index as an input scene index of the merging scene index - _renderIndexProxy->InsertSceneIndex(_sceneIndex, SdfPath::AbsoluteRootPath()); - } - else - { - for (auto& it : _delegates) { - it->Populate(); - } - - if (_defaultLightDelegate && !_sceneDelegate->GetLightsEnabled()) { - _defaultLightDelegate->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) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->SetCameraViewport(camPath, viewport); - } - else - { - return _sceneDelegate->SetCameraViewport(camPath, viewport); - } + return _sceneIndex->SetCameraViewport(camPath, viewport); } void MayaHydraSceneProducer::SetLightsEnabled(const bool enabled) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->SetLightsEnabled(enabled); - } - else - { - return _sceneDelegate->SetLightsEnabled(enabled); - } + return _sceneIndex->SetLightsEnabled(enabled); } void MayaHydraSceneProducer::SetDefaultLightEnabled(const bool enabled) -{ - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->SetDefaultLightEnabled(enabled); - } - else - { - _defaultLightDelegate->SetLightingOn(enabled); - } +{ + _sceneIndex->SetDefaultLightEnabled(enabled); } void MayaHydraSceneProducer::SetDefaultLight(const GlfSimpleLight& light) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->SetDefaultLight(light); - } - else - { - _defaultLightDelegate->SetDefaultLight(light); - } + _sceneIndex->SetDefaultLight(light); } const MayaHydraParams& MayaHydraSceneProducer::GetParams() const { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetParams(); - } - else - { - return _sceneDelegate->GetParams(); - } + return _sceneIndex->GetParams(); } void MayaHydraSceneProducer::SetParams(const MayaHydraParams& params) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->SetParams(params); - } - else - { - for (auto& it : _delegates) { - it->SetParams(params); - } - } + return _sceneIndex->SetParams(params); } bool MayaHydraSceneProducer::AddPickHitToSelectionList( @@ -227,70 +103,31 @@ bool MayaHydraSceneProducer::AddPickHitToSelectionList( MSelectionList& selectionList, MPointArray& worldSpaceHitPts) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->AddPickHitToSelectionList( - hit, - selectInfo, - selectionList, - worldSpaceHitPts); - } - else - { - return _sceneDelegate->AddPickHitToSelectionList( + return _sceneIndex->AddPickHitToSelectionList( hit, selectInfo, selectionList, worldSpaceHitPts); - } } HdRenderIndex& MayaHydraSceneProducer::GetRenderIndex() { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetRenderIndex(); - } - else - { - return _sceneDelegate->GetRenderIndex(); - } + return _sceneIndex->GetRenderIndex(); } bool MayaHydraSceneProducer::IsHdSt() const { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->IsHdSt(); - } - else - { - return _sceneDelegate->IsHdSt(); - } + return _sceneIndex->IsHdSt(); } bool MayaHydraSceneProducer::GetPlaybackRunning() const { - if (enableMayaNativeSceneIndex()) - { - return false; - } - else - { - return _sceneDelegate->GetPlaybackRunning(); - } + return false; } SdfPath MayaHydraSceneProducer::GetPrimPath(const MDagPath& dg, bool isSprim) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetPrimPath(dg, isSprim); - } - else - { - return _sceneDelegate->GetPrimPath(dg, isSprim); - } + return _sceneIndex->GetPrimPath(dg, isSprim); } void MayaHydraSceneProducer::InsertRprim( @@ -299,50 +136,22 @@ void MayaHydraSceneProducer::InsertRprim( const SdfPath& id, const SdfPath& instancerId) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->InsertPrim(adapter, typeId, id); - } - else - { - return _sceneDelegate->InsertRprim(typeId, id, instancerId); - } + return _sceneIndex->InsertPrim(adapter, typeId, id); } void MayaHydraSceneProducer::RemoveRprim(const SdfPath& id) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->RemovePrim(id); - } - else - { - _sceneDelegate->RemoveRprim(id); - } + _sceneIndex->RemovePrim(id); } void MayaHydraSceneProducer::MarkRprimDirty(const SdfPath& id, HdDirtyBits dirtyBits) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->MarkRprimDirty(id, dirtyBits); - } - else - { - _sceneDelegate->GetRenderIndex().GetChangeTracker().MarkRprimDirty(id, dirtyBits); - } + _sceneIndex->MarkRprimDirty(id, dirtyBits); } void MayaHydraSceneProducer::MarkInstancerDirty(const SdfPath& id, HdDirtyBits dirtyBits) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->MarkInstancerDirty(id, dirtyBits); - } - else - { - _sceneDelegate->GetRenderIndex().GetChangeTracker().MarkInstancerDirty(id, dirtyBits); - } + _sceneIndex->MarkInstancerDirty(id, dirtyBits); } void MayaHydraSceneProducer::InsertSprim( @@ -351,143 +160,57 @@ void MayaHydraSceneProducer::InsertSprim( const SdfPath& id, HdDirtyBits initialBits) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->InsertPrim(adapter, typeId, id); - } - else - { - _sceneDelegate->InsertSprim(typeId, id, initialBits); - } + _sceneIndex->InsertPrim(adapter, typeId, id); } void MayaHydraSceneProducer::RemoveSprim(const TfToken& typeId, const SdfPath& id) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->RemovePrim(id); - } - else - { - _sceneDelegate->RemoveSprim(typeId, id); - } + _sceneIndex->RemovePrim(id); } void MayaHydraSceneProducer::MarkSprimDirty(const SdfPath& id, HdDirtyBits dirtyBits) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->MarkSprimDirty(id, dirtyBits); - } - else - { - _sceneDelegate->GetRenderIndex().GetChangeTracker().MarkSprimDirty(id, dirtyBits); - } + _sceneIndex->MarkSprimDirty(id, dirtyBits); } SdfPath MayaHydraSceneProducer::GetDelegateID(TfToken name) const { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetDelegateID(name); - } - else - { - for (auto& delegate : _delegates) { - if (delegate->GetName() == name) { - return delegate->GetMayaDelegateID(); - } - } - return SdfPath(); - } + return _sceneIndex->GetDelegateID(name); } void MayaHydraSceneProducer::PreFrame(const MHWRender::MDrawContext& drawContext) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->PreFrame(drawContext); - } - else - { - for (auto& it : _delegates) { - it->PreFrame(drawContext); - } - } + _sceneIndex->PreFrame(drawContext); } void MayaHydraSceneProducer::PostFrame() { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->PostFrame(); - } - else - { - for (auto& it : _delegates) { - it->PostFrame(); - } - } + _sceneIndex->PostFrame(); } void MayaHydraSceneProducer::RemoveAdapter(const SdfPath& id) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->RemoveAdapter(id); - } - else - { - return _sceneDelegate->RemoveAdapter(id); - } + return _sceneIndex->RemoveAdapter(id); } void MayaHydraSceneProducer::RecreateAdapterOnIdle(const SdfPath& id, const MObject& obj) { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->RecreateAdapterOnIdle(id, obj); - } - else - { - return _sceneDelegate->RecreateAdapterOnIdle(id, obj); - } + return _sceneIndex->RecreateAdapterOnIdle(id, obj); } SdfPath MayaHydraSceneProducer::GetLightedPrimsRootPath() const { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetLightedPrimsRootPath(); - } - else - { - return _sceneDelegate->GetLightedPrimsRootPath(); - } + return _sceneIndex->GetLightedPrimsRootPath(); } void MayaHydraSceneProducer::MaterialTagChanged(const SdfPath& id) { - if (enableMayaNativeSceneIndex()) - { - _sceneIndex->MaterialTagChanged(id); - } - else - { - _sceneDelegate->MaterialTagChanged(id); - } + _sceneIndex->MaterialTagChanged(id); } GfInterval MayaHydraSceneProducer::GetCurrentTimeSamplingInterval() const { - if (enableMayaNativeSceneIndex()) - { - return _sceneIndex->GetCurrentTimeSamplingInterval(); - } - else - { - return _sceneDelegate->GetCurrentTimeSamplingInterval(); - } + return _sceneIndex->GetCurrentTimeSamplingInterval(); } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h index 51c5c029bf..092082c86c 100644 --- a/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h +++ b/lib/mayaHydra/hydraExtensions/mayaHydraSceneProducer.h @@ -26,8 +26,7 @@ #include #include -#include -#include +#include #include #include @@ -45,16 +44,10 @@ class RenderIndexProxy; } PXR_NAMESPACE_OPEN_SCOPE - -class MayaHydraSceneDelegate; class MayaHydraAdapter; -class MtohDefaultLightDelegate; /** * \brief MayaHydraSceneProducer is used to produce the hydra scene from Maya native scene. - * Under the hood, the work is delegated to MayaHydraSceneIndex or MayaHydraSceneDelegate, depends on - * if MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX is enabled or not. - * Note that MayaHydraSceneDelegate could be deprecated in the future. */ class MAYAHYDRALIB_API MayaHydraSceneProducer { @@ -62,7 +55,7 @@ class MAYAHYDRALIB_API MayaHydraSceneProducer MayaHydraSceneProducer( const std::shared_ptr& renderIndexProxy, const SdfPath& id, - MayaHydraDelegate::InitData& initData, + MayaHydraInitData& initData, bool lightEnabled); ~MayaHydraSceneProducer(); @@ -194,14 +187,6 @@ class MAYAHYDRALIB_API MayaHydraSceneProducer private: - // - // Delegates, depends on if MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX is enabled or not. - // - // SceneDelegate - std::shared_ptr _sceneDelegate; - std::vector _delegates; - std::unique_ptr _defaultLightDelegate; - // SceneIndex MayaHydraSceneIndexRefPtr _sceneIndex; const std::shared_ptr _renderIndexProxy; diff --git a/lib/mayaHydra/hydraExtensions/plugInfo.json b/lib/mayaHydra/hydraExtensions/plugInfo.json index 769e5efd2e..d06bc4c452 100644 --- a/lib/mayaHydra/hydraExtensions/plugInfo.json +++ b/lib/mayaHydra/hydraExtensions/plugInfo.json @@ -3,22 +3,6 @@ { "Info": { "Types": { - # Delegates - "MayaHydraDelegate": { - "displayName": "Base type for all scene delegates in Hydra for Maya." - }, - "MayaHydraSceneDelegate": { - "bases": [ - "MayaHydraDelegate" - ], - "displayName": "Maya Shapes in Hydra for Maya." - }, - "MayaHydraProxyDelegate": { - "bases": [ - "MayaHydraDelegate" - ], - "displayName": "Proxy Shapes in Hydra for Maya" - }, # Adapters "MayaHydraAdapter": { "displayName": "Base type for all node adapters in Hydra for Maya." diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraDisplayStyleDataSource.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraDisplayStyleDataSource.h index e0104418fd..3cbc8b39c1 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraDisplayStyleDataSource.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraDisplayStyleDataSource.h @@ -31,7 +31,7 @@ class MayaHydraSceneIndex; /** * \brief A container data source representing data unique to display style */ - class MayaHydraDisplayStyleDataSource : public HdContainerDataSource +class MayaHydraDisplayStyleDataSource : public HdContainerDataSource { public: HD_DECLARE_DATASOURCE(MayaHydraDisplayStyleDataSource); diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp index 548717b0d4..823ecef43e 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp @@ -1,5 +1,5 @@ // -// Copyright 2023 Autodesk, Inc. All rights reserved. +// Copyright 2024 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. @@ -373,7 +373,7 @@ VtValue MayaHydraSceneIndex::_mayaDefaultMaterial; SdfPath MayaHydraSceneIndex::_mayaDefaultLightPath; // Common to all scene indexes MayaHydraSceneIndex::MayaHydraSceneIndex( - MayaHydraDelegate::InitData& initData, + MayaHydraInitData& initData, bool lightEnabled) : _ID(initData.delegateID) , _producer(initData.producer) diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h index 2d23955167..f6b1a2dee7 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h @@ -25,8 +25,7 @@ #include #include -#include -#include +#include #include #include #include @@ -57,6 +56,38 @@ class RenderIndexProxy; PXR_NAMESPACE_OPEN_SCOPE +struct MayaHydraInitData +{ + MayaHydraInitData( + TfToken nameIn, + HdEngine& engineIn, + HdRenderIndex* renderIndexIn, + HdRendererPlugin* rendererPluginIn, + HdxTaskController* taskControllerIn, + const SdfPath& delegateIDIn, + bool isHdStIn, + MayaHydraSceneProducer* producerIn = nullptr) + : name(nameIn) + , engine(engineIn) + , renderIndex(renderIndexIn) + , rendererPlugin(rendererPluginIn) + , taskController(taskControllerIn) + , delegateID(delegateIDIn) + , isHdSt(isHdStIn) + , producer(producerIn) + { + } + + TfToken name; + HdEngine& engine; + HdRenderIndex* renderIndex; + HdRendererPlugin* rendererPlugin; + HdxTaskController* taskController; + SdfPath delegateID; + bool isHdSt; + MayaHydraSceneProducer* producer; +}; + class MayaHydraSceneIndex; TF_DECLARE_WEAK_AND_REF_PTRS(MayaHydraSceneIndex); /** @@ -73,7 +104,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public template using AdapterMap = std::unordered_map; static MayaHydraSceneIndexRefPtr New( - MayaHydraDelegate::InitData& initData, + MayaHydraInitData& initData, bool lightEnabled) { return TfCreateRefPtr(new MayaHydraSceneIndex(initData, lightEnabled)); } @@ -177,7 +208,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public private: MayaHydraSceneIndex( - MayaHydraDelegate::InitData& initData, + MayaHydraInitData& initData, bool lightEnabled); template diff --git a/lib/mayaHydra/mayaPlugin/pluginUtils.h b/lib/mayaHydra/mayaPlugin/pluginUtils.h index 16152e78fd..c86f1211ac 100644 --- a/lib/mayaHydra/mayaPlugin/pluginUtils.h +++ b/lib/mayaHydra/mayaPlugin/pluginUtils.h @@ -28,7 +28,6 @@ #include #include - namespace MAYAHYDRA_NS_DEF { constexpr auto MTOH_RENDER_OVERRIDE_PREFIX = "mayaHydraRenderOverride_"; diff --git a/lib/mayaHydra/mayaPlugin/renderGlobals.h b/lib/mayaHydra/mayaPlugin/renderGlobals.h index b1f37860f7..6884e5ae64 100644 --- a/lib/mayaHydra/mayaPlugin/renderGlobals.h +++ b/lib/mayaHydra/mayaPlugin/renderGlobals.h @@ -19,7 +19,7 @@ #include "pluginUtils.h" #include "tokens.h" -#include +#include #include #include diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index e8ba62f90d..32bf7ebee7 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -1,5 +1,5 @@ // -// Copyright 2019 Luma Pictures +// Copyright 2024 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. @@ -13,8 +13,7 @@ // See the License for the specific language governing permissions and // limitations under the License. // -// Copyright 2023 Autodesk, Inc. All rights reserved. -// + // GL loading library needs to be included before any other OpenGL headers. #include @@ -26,8 +25,6 @@ #include "renderOverrideUtils.h" #include "tokens.h" -#include -#include #include #include #include @@ -230,7 +227,6 @@ MtohRenderOverride::MtohRenderOverride(const MtohRendererDescription& desc) _rendererDesc.rendererName.GetText(), _rendererDesc.overrideName.GetText(), _rendererDesc.displayName.GetText()); - MayaHydraDelegateRegistry::InstallDelegatesChangedSignal([this]() { _needsClear.store(true); }); _ID = SdfPath("/MayaHydraViewportRenderer") .AppendChild( TfToken(TfStringPrintf("_MayaHydra_%s_%p", desc.rendererName.GetText(), this))); @@ -781,7 +777,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw _taskController->SetRenderOutputs({ HdAovTokens->color }); } - MayaHydraDelegate::InitData delegateInitData( + MayaHydraInitData mhInitData( TfToken(), _engine, _renderIndex, @@ -800,7 +796,7 @@ void MtohRenderOverride::_InitHydraResources(const MHWRender::MDrawContext& draw _renderIndexProxy = std::make_shared(_renderIndex); - _mayaHydraSceneProducer.reset(new MayaHydraSceneProducer(_renderIndexProxy, _ID, delegateInitData, !_hasDefaultLighting)); + _mayaHydraSceneProducer.reset(new MayaHydraSceneProducer(_renderIndexProxy, _ID, mhInitData, !_hasDefaultLighting)); VtValue fvpSelectionTrackerValue(_fvpSelectionTracker); _engine.SetTaskContextData(FvpTokens->fvpSelectionState, fvpSelectionTrackerValue); diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.h b/lib/mayaHydra/mayaPlugin/renderOverride.h index f6b208bec5..18da6ee150 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.h +++ b/lib/mayaHydra/mayaPlugin/renderOverride.h @@ -33,8 +33,7 @@ #include "renderGlobals.h" #include "pluginUtils.h" -#include -#include +#include #include #include diff --git a/lib/mayaHydra/mayaPlugin/viewCommand.cpp b/lib/mayaHydra/mayaPlugin/viewCommand.cpp index 1f079b21d8..73e4a2d3d7 100644 --- a/lib/mayaHydra/mayaPlugin/viewCommand.cpp +++ b/lib/mayaHydra/mayaPlugin/viewCommand.cpp @@ -20,7 +20,6 @@ #include "renderGlobals.h" #include "renderOverride.h" -#include #include #include @@ -142,8 +141,6 @@ MSyntax MtohViewCmd::createSyntax() syntax.addFlag(_getRendererDisplayName, _getRendererDisplayNameLong); - syntax.addFlag(_listDelegates, _listDelegatesLong); - syntax.addFlag(_createRenderGlobals, _createRenderGlobalsLong); syntax.addFlag(_userDefaultsId, _userDefaultsIdLong); @@ -222,14 +219,6 @@ MStatus MtohViewCmd::doIt(const MArgList& args) const auto dn = MtohGetRendererPluginDisplayName(renderDelegateName); setResult(MString(dn.c_str())); - } else if (db.isFlagSet(_listDelegates)) { - for (const auto& delegate : MayaHydraDelegateRegistry::GetDelegateNames()) { - appendToResult(delegate.GetText()); - } - // Want to return an empty list, not None - if (!isCurrentResultArray()) { - setResult(MStringArray()); - } } else if (db.isFlagSet(_help)) { MString helpText = _helpText; if (db.isFlagSet(_verbose)) { diff --git a/test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt b/test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt index e7aa16344c..0b77552d64 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt +++ b/test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt @@ -93,8 +93,6 @@ foreach(script ${TEST_SCRIPT_FILES}) # Fallback to old color management. We will have to investigate # and introduce OCIOv2 compatible version of these tests. "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" - - "MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX=1" ) # Assign a CTest label to these tests for easy filtering. @@ -118,8 +116,6 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES_MESH_ADAPTER}) "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" "MAYA_HYDRA_USE_MESH_ADAPTER=1" - - "MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX=1" ) # Assign a CTest label to these tests for easy filtering. @@ -156,8 +152,6 @@ foreach(script ${INTERACTIVE_TEST_SCRIPT_FILES}) # Fallback to old color management. We will have to investigate # and introduce OCIOv2 compatible version of these tests. "MAYA_COLOR_MANAGEMENT_SYNCOLOR=1" - - "MAYA_HYDRA_ENABLE_NATIVE_SCENE_INDEX=1" ) # Add a ctest label to these tests for easy filtering. diff --git a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py index becc9c44aa..f7d0e77d8e 100644 --- a/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py +++ b/test/lib/mayaUsd/render/mayaToHydra/testMtohCommand.py @@ -98,11 +98,6 @@ def test_getRendererDisplayName(self): gn=True)) self.assertEqual(displayName, "Embree") - def test_listDelegates(self): - delegates = cmds.mayaHydra(listDelegates=1) - self.assertEqual(delegates, cmds.mayaHydra(ld=1)) - self.assertIn("MayaHydraSceneDelegate", delegates) - def test_createRenderGlobals(self): for flag in ("createRenderGlobals", "crg"): cmds.file(f=1, new=1)