From 1d73fe335e73a4d526d46c454424da535989ec23 Mon Sep 17 00:00:00 2001 From: "ADS\\lanierd" Date: Thu, 18 Jul 2024 16:59:03 +0200 Subject: [PATCH] Fixes from code review --- lib/mayaHydra/hydraExtensions/mayaUtils.cpp | 14 -------------- lib/mayaHydra/hydraExtensions/mayaUtils.h | 7 ------- .../sceneIndex/mayaHydraSceneIndex.cpp | 11 ++++++----- .../sceneIndex/mayaHydraSceneIndex.h | 6 +++--- lib/mayaHydra/mayaPlugin/renderOverride.cpp | 2 +- 5 files changed, 10 insertions(+), 30 deletions(-) diff --git a/lib/mayaHydra/hydraExtensions/mayaUtils.cpp b/lib/mayaHydra/hydraExtensions/mayaUtils.cpp index e026c94872..e3dd98e7ce 100644 --- a/lib/mayaHydra/hydraExtensions/mayaUtils.cpp +++ b/lib/mayaHydra/hydraExtensions/mayaUtils.cpp @@ -184,18 +184,4 @@ MObject GetShadingGroupFromShader(const MObject& shader) return shadingGroup; } -MObject GetDefaultStandardSurfaceShader() -{ - MSelectionList list; - MObject node; - - // Add the shader to the selection list - list.add("standardSurface1"); - - // Get the shader as an MObject - list.getDependNode(0, node); - - return node; -} - } // namespace MAYAHYDRA_NS_DEF diff --git a/lib/mayaHydra/hydraExtensions/mayaUtils.h b/lib/mayaHydra/hydraExtensions/mayaUtils.h index 75d573ff96..66740d4fbb 100644 --- a/lib/mayaHydra/hydraExtensions/mayaUtils.h +++ b/lib/mayaHydra/hydraExtensions/mayaUtils.h @@ -176,13 +176,6 @@ bool SetNodeAttribute(MObject node, std::string attrName, AttrType newValue) */ MObject GetShadingGroupFromShader(const MObject& shader); -/** - * @brief Get the default standard surface shader MObject (named "standardSurface1"). - * - * @return the MObject of the "standardSurface1" shader - */ -MObject GetDefaultStandardSurfaceShader(); - } // namespace MAYAHYDRA_NS_DEF #endif // MAYAHYDRALIB_MAYA_UTILS_H diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp index 8877d0d18c..5eccd560e0 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp @@ -84,7 +84,7 @@ TF_DEFINE_PRIVATE_TOKENS( SdfPath MayaHydraSceneIndex::_fallbackMaterial; SdfPath MayaHydraSceneIndex::_mayaDefaultMaterialPath; // Common to all scene indexes -VtValue MayaHydraSceneIndex::_mayaDefaultMaterialFallback;//Used only if we cannot find the default material named standardsurface1 +VtValue MayaHydraSceneIndex::_mayaDefaultMaterialFallback;//Used only if we cannot find the default material named standardSurface1 SdfPath MayaHydraSceneIndex::_mayaDefaultLightPath; // Common to all scene indexes SdfPath MayaHydraSceneIndex::_mayaFacesSelectionMaterialPath; // Common to all scene indexes @@ -659,11 +659,12 @@ VtValue MayaHydraSceneIndex::GetMaterialResource(const SdfPath& id) return ret.IsEmpty() ? MayaHydraMaterialAdapter::GetPreviewMaterialResource(id) : ret; } -//Create the default material from the "standardsurface1" maya material or create a fallback material if it cannot be found +//Create the default material from the "standardSurface1" maya material or create a fallback material if it cannot be found void MayaHydraSceneIndex::CreateMayaDefaultMaterialData() { - // Try to get the standardsurface1 material - MObject defaultShaderObj = GetDefaultStandardSurfaceShader(); // From mayautils.cpp + // Try to get the standardSurface1 material + MObject defaultShaderObj; + GetDependNodeFromNodeName("standardSurface1", defaultShaderObj); // From mayautils.cpp bool defaultMaterialSuccessfullyCreated = false; if (MObjectHandle(defaultShaderObj).isValid()) { //Get its shading group as it is what we use to create a material adapter @@ -676,7 +677,7 @@ void MayaHydraSceneIndex::CreateMayaDefaultMaterialData() if (! defaultMaterialSuccessfullyCreated){ TF_CODING_WARNING("standardSurface1 material and its shading group could not be retrieved, using a fallback material"); - // In case we could not create the default material from the standardsurface1 material, we + // In case we could not create the default material from the standardSurface1 material, we // create a fallback material _mayaDefaultMaterialFallback = MayaHydraSceneIndex::_CreateDefaultMaterialFallback(); diff --git a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h index eacf20db80..7fcb54815d 100644 --- a/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h +++ b/lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.h @@ -208,7 +208,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public //Sdfpath of the maya default material SdfPath GetDefaultMaterialPath() const{return _mayaDefaultMaterialPath;} - bool GetDefaultMaterialAlreadyCreated() const{return _defaultMaterialCreated;} + bool DefaultMaterialCreated() const{return _defaultMaterialCreated;} //Is the exclusion list of materials that should be skipped when using the default material SdfPathVector GetDefaultMaterialExclusionPaths()const{ return {_mayaFacesSelectionMaterialPath};} @@ -258,7 +258,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public /// Is using an environment variable to tell if we should pass normals to Hydra when using the render item and mesh adapters static bool passNormalsToHydra(); - ///Create the default material from the "standardsurface1" maya material or create a fallback material if it cannot be found + ///Create the default material from the "standardSurface1" maya material or create a fallback material if it cannot be found void CreateMayaDefaultMaterialData(); private: @@ -334,7 +334,7 @@ class MAYAHYDRALIB_API MayaHydraSceneIndex : public HdRetainedSceneIndex, public static SdfPath _fallbackMaterial; /// _mayaDefaultMaterialPath is common to all scene indexes static SdfPath _mayaDefaultMaterialPath; - static VtValue _mayaDefaultMaterialFallback;//Used only if we cannot find the default material named standardsurface1 + static VtValue _mayaDefaultMaterialFallback;//Used only if we cannot find the default material named standardSurface1 /// _mayaFacesSelectionMaterialPath is a path to a Hydra material used to display the faces selection on nodes when being in components selection mode static SdfPath _mayaFacesSelectionMaterialPath; diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index cd8710532a..4c2c6c46fb 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -1212,7 +1212,7 @@ MStatus MtohRenderOverride::Render( if (_defaultMaterialSceneIndex && _useDefaultMaterial != currentUseDefaultMaterial){ // Create default material data when switching to the default material in the viewport - if (_mayaHydraSceneIndex && !_mayaHydraSceneIndex->GetDefaultMaterialAlreadyCreated()) { + if (_mayaHydraSceneIndex && !_mayaHydraSceneIndex->DefaultMaterialCreated()) { _mayaHydraSceneIndex->CreateMayaDefaultMaterialData(); }