diff --git a/lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/TexcoordNodeMaya.cpp b/lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/TexcoordNodeMaya.cpp index c7c6e14b67..cf02c7bfc4 100644 --- a/lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/TexcoordNodeMaya.cpp +++ b/lib/mayaUsd/render/MaterialXGenOgsXml/Nodes/TexcoordNodeMaya.cpp @@ -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(index); - if (i < 0 || i < 9) { + if (i < 0 || i > 9) { i = 0; } if (i > 0) { diff --git a/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp b/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp index 7eafcc684c..7e3f4c48f7 100644 --- a/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp +++ b/lib/mayaUsd/ufe/UsdShaderAttributeDef.cpp @@ -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 { + { 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 { + { 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: }; diff --git a/test/lib/ufe/testAttribute.py b/test/lib/ufe/testAttribute.py index 1b0ee4964d..66c3778266 100644 --- a/test/lib/ufe/testAttribute.py +++ b/test/lib/ufe/testAttribute.py @@ -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):