Skip to content

Commit

Permalink
Fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lanierd-adsk committed Jul 18, 2024
1 parent 9a227e0 commit 1d73fe3
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
14 changes: 0 additions & 14 deletions lib/mayaHydra/hydraExtensions/mayaUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 0 additions & 7 deletions lib/mayaHydra/hydraExtensions/mayaUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 6 additions & 5 deletions lib/mayaHydra/hydraExtensions/sceneIndex/mayaHydraSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 1d73fe3

Please sign in to comment.