Skip to content

Commit

Permalink
Merge pull request #3301 from Autodesk/gamaj/fix_default_softmin_and_…
Browse files Browse the repository at this point in the history
…softmax

Report correct default soft min/max per type
  • Loading branch information
seando-adsk authored Aug 29, 2023
2 parents 2a3adf3 + 75163e1 commit 944c702
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::string geomNameFromIndex(const std::string& index)
// pxr\usdImaging\usdImaging\materialParamUtils.cpp would then be able to handle indexed values.
#if 0
int i = fromValueString<int>(index);
if (i < 0 || i < 9) {
if (i < 0 || i > 9) {
i = 0;
}
if (i > 0) {
Expand Down
34 changes: 30 additions & 4 deletions lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,39 @@ static const MetadataMap _metaMap = {
} },
{ MayaUsdMetadata->UISoftMin
.GetString(), // Maya has 0-100 sliders. In rendering, sliders are 0-1.
[](const PXR_NS::SdrShaderProperty&) {
return std::string { "0.0" }; // Will only be returned if the metadata does not exist.
[](const PXR_NS::SdrShaderProperty& p) {
// Will only be returned if the metadata does not exist.
static const auto defaultSoftMin = std::unordered_map<std::string, Ufe::Value> {
{ Ufe::Attribute::kFloat, std::string { "0" } },
{ Ufe::Attribute::kFloat3, std::string { "0,0,0" } },
{ Ufe::Attribute::kColorFloat3, std::string { "0,0,0" } },
{ Ufe::Attribute::kDouble, std::string { "0" } },
#ifdef UFE_V4_FEATURES_AVAILABLE
{ Ufe::Attribute::kFloat2, std::string { "0,0" } },
{ Ufe::Attribute::kFloat4, std::string { "0,0,0,0" } },
{ Ufe::Attribute::kColorFloat4, std::string { "0,0,0,0" } },
#endif
};
auto itDefault = defaultSoftMin.find(usdTypeToUfe(&p));
return itDefault != defaultSoftMin.end() ? itDefault->second : Ufe::Value();
} },
{ MayaUsdMetadata->UISoftMax
.GetString(), // Maya has 0-100 sliders. In rendering, sliders are 0-1.
[](const PXR_NS::SdrShaderProperty&) {
return std::string { "1.0" }; // Will only be returned if the metadata does not exist.
[](const PXR_NS::SdrShaderProperty& p) {
// Will only be returned if the metadata does not exist.
static const auto defaultSoftMax = std::unordered_map<std::string, Ufe::Value> {
{ Ufe::Attribute::kFloat, std::string { "1" } },
{ Ufe::Attribute::kFloat3, std::string { "1,1,1" } },
{ Ufe::Attribute::kColorFloat3, std::string { "1,1,1" } },
{ Ufe::Attribute::kDouble, std::string { "1" } },
#ifdef UFE_V4_FEATURES_AVAILABLE
{ Ufe::Attribute::kFloat2, std::string { "1,1" } },
{ Ufe::Attribute::kFloat4, std::string { "1,1,1,1" } },
{ Ufe::Attribute::kColorFloat4, std::string { "1,1,1,1" } },
#endif
};
auto itDefault = defaultSoftMax.find(usdTypeToUfe(&p));
return itDefault != defaultSoftMax.end() ? itDefault->second : Ufe::Value();
} },
// If Ufe decides to use another completely different convention, it can be added here:
};
Expand Down
23 changes: 23 additions & 0 deletions test/lib/ufe/testAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -1936,6 +1936,29 @@ def testMaterialXMetadata(self):
attr = shaderAttrs.attribute("inputs:" + attrName)
self.assertEqual(str(attr.getMetadata(metaName)), metaValue)

for rangedType in ("float", "vector2", "vector3", "vector4", "color3", "color4"):
numComponents = 1
if rangedType[-1].isdecimal():
numComponents = int(rangedType[-1])
dotDef = ufe.NodeDef.definition(materialItem.runTimeId(), "ND_dot_" + rangedType)
cmd = dotDef.createNodeCmd(materialItem, ufe.PathComponent("dotty_" + rangedType))
ufeCmd.execute(cmd)
shaderItem = cmd.insertedChild
shaderAttrs = ufe.Attributes.attributes(shaderItem)
attr = shaderAttrs.attribute("inputs:in")
self.assertEqual(str(attr.getMetadata("uisoftmin")), ",".join(["0" for i in range(numComponents)]))
self.assertEqual(str(attr.getMetadata("uisoftmax")), ",".join(["1" for i in range(numComponents)]))

for unrangedType in ("boolean", "integer", "matrix33", "matrix44", "string", "filename"):
dotDef = ufe.NodeDef.definition(materialItem.runTimeId(), "ND_dot_" + unrangedType)
cmd = dotDef.createNodeCmd(materialItem, ufe.PathComponent("dotty_" + unrangedType))
ufeCmd.execute(cmd)
shaderItem = cmd.insertedChild
shaderAttrs = ufe.Attributes.attributes(shaderItem)
attr = shaderAttrs.attribute("inputs:in")
self.assertFalse(attr.hasMetadata("uisoftmin"))
self.assertFalse(attr.hasMetadata("uisoftmax"))

@unittest.skipUnless(ufeUtils.ufeFeatureSetVersion() >= 4, 'Test only available in UFE v4 or greater')
@unittest.skipUnless(Usd.GetVersion() >= (0, 21, 8), 'Requires CanApplySchema from USD')
def testCreateUsdPreviewSurfaceAttribute(self):
Expand Down

0 comments on commit 944c702

Please sign in to comment.