Skip to content

Commit f76dee6

Browse files
committed
Implement more suggestions from Copilot
1 parent 9eb450f commit f76dee6

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

lib/mayaHydra/hydraExtensions/mixedUtils.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ bool ExtractNumericDataFromPlug(
743743
return false;
744744
}
745745
outValue = VtValue(handle.asBool());
746+
supportsDefault = true;
746747
return true;
747748
}
748749
case MFnNumericData::kByte:
@@ -753,6 +754,7 @@ bool ExtractNumericDataFromPlug(
753754
return false;
754755
}
755756
outValue = VtValue(static_cast<int>(handle.asChar()));
757+
supportsDefault = true;
756758
return true;
757759
}
758760
case MFnNumericData::kShort: {
@@ -762,6 +764,7 @@ bool ExtractNumericDataFromPlug(
762764
return false;
763765
}
764766
outValue = VtValue(handle.asShort());
767+
supportsDefault = true;
765768
return true;
766769
}
767770
case MFnNumericData::kInt: {
@@ -771,6 +774,7 @@ bool ExtractNumericDataFromPlug(
771774
return false;
772775
}
773776
outValue = VtValue(handle.asInt());
777+
supportsDefault = true;
774778
return true;
775779
}
776780
case MFnNumericData::kInt64: {
@@ -780,6 +784,7 @@ bool ExtractNumericDataFromPlug(
780784
return false;
781785
}
782786
outValue = VtValue(handle.asInt64());
787+
supportsDefault = true;
783788
return true;
784789
}
785790
case MFnNumericData::kFloat: {
@@ -789,6 +794,7 @@ bool ExtractNumericDataFromPlug(
789794
return false;
790795
}
791796
outValue = VtValue(handle.asFloat());
797+
supportsDefault = true;
792798
return true;
793799
}
794800
case MFnNumericData::kDouble: {
@@ -798,6 +804,7 @@ bool ExtractNumericDataFromPlug(
798804
return false;
799805
}
800806
outValue = VtValue(handle.asDouble());
807+
supportsDefault = true;
801808
return true;
802809
}
803810
case MFnNumericData::kAddr: {
@@ -809,6 +816,7 @@ bool ExtractNumericDataFromPlug(
809816
void* ptr = handle.asAddr();
810817
MInt64 val = static_cast<MInt64>(reinterpret_cast<intptr_t>(ptr));
811818
outValue = VtValue(val);
819+
supportsDefault = true;
812820
return true;
813821
}
814822
default:
@@ -1644,6 +1652,16 @@ void GetExtensionAttributesFromNode(
16441652
case MFn::kMatrixAttribute: {
16451653
MStatus matrixStatus;
16461654
MObject dataObj = attrPlug.asMObject();
1655+
if (dataObj.isNull()) {
1656+
attrPlug.getValue(dataObj);
1657+
}
1658+
if (dataObj.isNull()) {
1659+
MStatus handleStatus;
1660+
MDataHandle handle = attrPlug.asMDataHandle(&handleStatus);
1661+
if (handleStatus) {
1662+
dataObj = handle.data();
1663+
}
1664+
}
16471665
if (dataObj.isNull()) {
16481666
break;
16491667
}

test/lib/mayaUsd/render/mayaToHydra/cpp/testCustomAttributes.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,21 @@ def _create_numeric_attr(node_fn, name, numeric_type, default_value=None):
8888
name + "W", name + "W", om.MFnNumericData.kDouble, 0.0)
8989
attr_obj = numeric_attr.create(name, name, child1, child2, child3, child4)
9090
else:
91-
default_val = 0.0 if default_value is None else default_value
91+
if default_value is None:
92+
# Use integer-like defaults for boolean/integer types,
93+
# and floating defaults for float/double types.
94+
if numeric_type in (
95+
om.MFnNumericData.kBoolean,
96+
om.MFnNumericData.kByte,
97+
om.MFnNumericData.kShort,
98+
om.MFnNumericData.kInt,
99+
om.MFnNumericData.kInt64,
100+
):
101+
default_val = 0
102+
else:
103+
default_val = 0.0
104+
else:
105+
default_val = default_value
92106
attr_obj = numeric_attr.create(name, name, numeric_type, default_val)
93107
numeric_attr.keyable = True
94108
numeric_attr.storable = True
@@ -463,7 +477,8 @@ class TestCustomAttributes(mtohUtils.MayaHydraBaseTestCase):
463477
def setUp(self):
464478
mayaUtils.openNewScene()
465479
modified = cmds.file(query=True, modified=True)
466-
assert not modified, (
480+
self.assertFalse(
481+
modified,
467482
'Internal test framework error: scene left as modified by mayaUtils.openNewScene()')
468483
cmds.file(modified=False)
469484

0 commit comments

Comments
 (0)