Skip to content

Commit

Permalink
Flatten Material config dictionary
Browse files Browse the repository at this point in the history
We are using HdCreateTypedRetainedDataSource() to convert the
config VtDictionary to a Container Data Source. This function does
not handle nested attributes, so mtlx:version was not making it
into Hydra. This change flattens the attributes so that the
mtlx:version does make it to Hydra.

(Internal change: 2356523)
  • Loading branch information
klucknav authored and pixar-oss committed Feb 11, 2025
1 parent 943c5a3 commit 67e851b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
5 changes: 3 additions & 2 deletions pxr/imaging/hd/materialNetwork2Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ HdMaterialNetwork2Interface::GetMaterialConfigKeys() const
VtValue
HdMaterialNetwork2Interface::GetMaterialConfigValue(const TfToken& key) const
{
if (auto result = _materialNetwork->config.GetValueAtPath(key.GetString())){
return *result;
const auto it = _materialNetwork->config.find(key.GetString());
if (it != _materialNetwork->config.end()) {
return it->second;
}
return VtValue();
}
Expand Down
15 changes: 7 additions & 8 deletions pxr/usdImaging/usdImaging/dataSourceMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,25 +802,23 @@ _BuildMaterial(
}

// Collect any 'config' on the Material prim
// Collect in to a VtDictionary to take advantage of SetValueAtPath for
// nested namespaces in the attribute names.
VtDictionary configDict;
TfTokenVector names;
std::vector<HdDataSourceBaseHandle> values;
for (const auto& prop : usdMat.GetPrim().GetPropertiesInNamespace(
UsdImagingTokens->configPrefix)) {
const auto& attr = prop.As<UsdAttribute>();
if (!attr) {
continue;
}

std::string name = attr.GetName().GetString();
const std::string name = attr.GetName().GetString();
std::pair<std::string, bool> result =
SdfPath::StripPrefixNamespace(name, UsdImagingTokens->configPrefix);
name = result.first;
names.push_back(TfToken(result.first));

VtValue value;
attr.Get(&value);

configDict.SetValueAtPath(name, value);
values.push_back(HdCreateTypedRetainedDataSource(value));
}

HdContainerDataSourceHandle nodesDs =
Expand All @@ -830,7 +828,8 @@ _BuildMaterial(
nodeValues.data());

HdContainerDataSourceHandle configDefaultContext =
HdUtils::ConvertVtDictionaryToContainerDS(configDict);
HdRetainedContainerDataSource::New(
names.size(), names.data(), values.data());

return HdMaterialNetworkSchema::Builder()
.SetNodes(nodesDs)
Expand Down
2 changes: 1 addition & 1 deletion pxr/usdImaging/usdImaging/materialAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ UsdImagingMaterialAdapter::GetMaterialResource(UsdPrim const &prim,
VtValue value;
attr.Get(&value);

configDict.SetValueAtPath(name, value);
configDict.insert({name, value});
}
networkMap.config = configDict;

Expand Down

0 comments on commit 67e851b

Please sign in to comment.