Skip to content

Commit

Permalink
LOOKDEVX-1547 - Allow introspecting UsdAttribute UFE class
Browse files Browse the repository at this point in the history
Allows a downstream client to access the USD data wrapped in a UFE
Attribute class.

Also updates core and tests in case MaterialX starts remembering default
values for matrix33 inputs.
  • Loading branch information
JGamache-autodesk committed Jul 14, 2023
1 parent 785f636 commit 795b8dd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/mayaUsd/ufe/UsdAttribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace MAYAUSD_NS_DEF {
namespace ufe {

//! \brief Internal helper class to implement the pure virtual methods from Ufe::Attribute.
class UsdAttribute
class MAYAUSD_CORE_PUBLIC UsdAttribute
{
public:
UsdAttribute(UsdAttributeHolder::UPtr&& attrHolder);
Expand Down
11 changes: 9 additions & 2 deletions lib/mayaUsd/ufe/UsdShaderAttributeHolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ std::string UsdShaderAttributeHolder::isEditAllowedMsg() const

std::string UsdShaderAttributeHolder::defaultValue() const
{
// TODO: Add a PXR_VERSION if a fix is introduced in OpenUSD.
if (_sdrProp->GetType() == PXR_NS::SdfValueTypeNames->Matrix3d.GetAsToken()) {
// There is no Matrix3d type in Sdr, so the MaterialX default value is not kept
return "0,0,0,0,0,0,0,0,0";
std::string val = UsdShaderAttributeDef(_sdrProp).defaultValue();
if (val.empty()) {
// There is no Matrix3d type in Sdr, so the MaterialX default value is not kept
return "0,0,0,0,0,0,0,0,0";
}
// But if https://github.com/PixarAnimationStudios/OpenUSD/issues/2523 gets fixed
// then return that value:
return val;
}
#if PXR_VERSION < 2205
if (_sdrProp->GetType() == PXR_NS::SdfValueTypeNames->Bool.GetAsToken()) {
Expand Down
15 changes: 10 additions & 5 deletions test/lib/ufe/testAttribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import testUtils
import usdUtils

from pxr import Usd, UsdGeom, Vt, Gf, UsdLux, UsdUI
from pxr import Usd, UsdGeom, Vt, Gf, UsdLux, UsdUI, Sdr
from pxr import UsdShade

from maya import cmds
Expand All @@ -40,6 +40,11 @@
import random
import unittest

def UsdHasDefaultForMatrix33():
r = Sdr.Registry()
n = r.GetNodeByIdentifier("ND_add_matrix33")
i = n.GetShaderInput("in1")
return i.GetDefaultValue() is not None

class TestObserver(ufe.Observer):
def __init__(self):
Expand Down Expand Up @@ -1856,10 +1861,10 @@ def testCreateAttributeTypes(self):
newVector3 = ufe.Vector3f(0.2, 0.4, 0.6)
origVector4 = ufe.Vector4f(0.0, 0.0, 0.0, 0.0)
newVector4 = ufe.Vector4f(0.2, 0.4, 0.6, 0.8)
# Default Matrix33 should be identity, but USD does not store a default value for that type.
# Requires same fix as Boolean in pxr/usd/usdMtlx/parser.cpp
# See: https://github.com/PixarAnimationStudios/USD/pull/1789
origMatrix3 = ufe.Matrix3d([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
if UsdHasDefaultForMatrix33():
origMatrix3 = ufe.Matrix3d([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
else:
origMatrix3 = ufe.Matrix3d([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
newMatrix3 = ufe.Matrix3d([[2, 4, 6], [7, 5, 3], [1, 2, 3]])
origMatrix4 = ufe.Matrix4d([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
newMatrix4 = ufe.Matrix4d([[1, 2, 1, 1], [0, 1, 0, 1], [2, 3, 4, 1], [1, 1, 1, 1]])
Expand Down

0 comments on commit 795b8dd

Please sign in to comment.