Skip to content

Commit

Permalink
Merge pull request #2873 from Autodesk/minnins/LOOKDEVX-1015/Avoid-Sh…
Browse files Browse the repository at this point in the history
…ow-in-LookdevX-diving-into-material

MAYA-127699 - Avoid diving into material when user selects "Show in LookdevX"
  • Loading branch information
seando-adsk authored Feb 17, 2023
2 parents 3b3f6d7 + ade0d87 commit b3fb700
Showing 1 changed file with 4 additions and 40 deletions.
44 changes: 4 additions & 40 deletions lib/mayaUsd/ufe/UsdMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,12 @@

#include <mayaUsd/ufe/Utils.h>

#include <ufe/log.h>
#include <ufe/types.h>

#include <stdexcept>

PXR_NAMESPACE_USING_DIRECTIVE

namespace {

std::vector<PXR_NS::UsdPrim> getConnectedShaders(const PXR_NS::UsdShadeOutput& port)
{
// Dig down across NodeGraph boundaries until a surface shader is found.
std::vector<PXR_NS::UsdPrim> shaders;
for (const auto& sourceInfo : port.GetConnectedSources()) {
if (sourceInfo.source.GetPrim().GetTypeName() != "Shader") {
if (sourceInfo.sourceType == UsdShadeAttributeType::Output) {
const std::vector<PXR_NS::UsdPrim> connectedShaders
= getConnectedShaders(sourceInfo.source.GetOutput(sourceInfo.sourceName));
shaders.insert(
std::end(shaders), std::begin(connectedShaders), std::end(connectedShaders));
}
} else {
shaders.push_back(sourceInfo.source.GetPrim());
}
}
return shaders;
}

} // namespace

namespace MAYAUSD_NS_DEF {
namespace ufe {

Expand Down Expand Up @@ -83,11 +59,7 @@ std::vector<Ufe::SceneItem::Ptr> UsdMaterial::getMaterials() const
// 1. Simple case: A material is directly attached to our object.
const PXR_NS::UsdShadeMaterial material = directBinding.GetMaterial();
if (material) {
for (const auto& output : material.GetSurfaceOutputs()) {
for (const auto& shader : getConnectedShaders(output)) {
materialPrims.push_back(shader);
}
}
materialPrims.push_back(material.GetPrim());
}

// 2. Check whether multiple materials are attached to this object via geometry subsets.
Expand All @@ -96,20 +68,12 @@ std::vector<Ufe::SceneItem::Ptr> UsdMaterial::getMaterials() const
const UsdShadeMaterial material
= subsetBindingAPI.ComputeBoundMaterial(UsdShadeTokens->surface);
if (material) {
for (const auto& output : material.GetSurfaceOutputs()) {
for (const auto& shader : getConnectedShaders(output)) {
materialPrims.push_back(shader);
}
}
materialPrims.push_back(material.GetPrim());
}
}

// 3. Find the associated Ufe::SceneItem for each material attached to our object.
for (const auto& materialPrim : materialPrims) {
if (!materialPrim) {
continue;
}

for (auto& materialPrim : materialPrims) {
const PXR_NS::SdfPath& materialSdfPath = materialPrim.GetPath();
const Ufe::Path materialUfePath = usdPathToUfePathSegment(materialSdfPath);

Expand All @@ -122,7 +86,7 @@ std::vector<Ufe::SceneItem::Ptr> UsdMaterial::getMaterials() const
continue;
const auto ufePath = Ufe::Path({ stagePathSegments[0], materialPathSegments[0] });

// Now we have the full path to the material's SceneItem
// Now we have the full path to the material's SceneItem.
materials.push_back(UsdSceneItem::create(ufePath, materialPrim));
}

Expand Down

0 comments on commit b3fb700

Please sign in to comment.