Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report correct default soft min/max per type #3301

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 defaultSoftMin = std::unordered_map<std::string, Ufe::Value> {
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
{ 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 = defaultSoftMin.find(usdTypeToUfe(&p));
return itDefault != defaultSoftMin.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
Loading