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

MAYA-114695 Properly detect animated compound plug #1939

Merged
merged 1 commit into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 19 additions & 2 deletions lib/mayaUsd/fileio/utils/writeUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,24 @@ VtValue UsdMayaWriteUtil::GetVtValue(
return VtValue();
}

namespace {
bool _IsAnimated(const MPlug& p)
{
if (p.isDestination()) {
return true;
}
if (p.isCompound()) {
const unsigned int numChildren = p.numChildren();
for (unsigned int i = 0; i < numChildren; ++i) {
if (_IsAnimated(p.child(i))) {
return true;
}
}
}
return false;
}
} // namespace

bool UsdMayaWriteUtil::SetUsdAttr(
const MPlug& attrPlug,
const UsdAttribute& usdAttr,
Expand All @@ -625,8 +643,7 @@ bool UsdMayaWriteUtil::SetUsdAttr(
return false;
}

bool isAnimated = attrPlug.isDestination();
if (usdTime.IsDefault() == isAnimated) {
if (!(usdTime.IsDefault() || _IsAnimated(attrPlug))) {
return true;
}

Expand Down
44 changes: 43 additions & 1 deletion test/lib/usd/translators/testUsdExportAnimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,46 @@ def testExportStaticSingleSampleOn(self):
prim = stage.GetPrimAtPath("/root")
attr = prim.GetAttribute("xformOp:translate")
num_samples = attr.GetNumTimeSamples()
self.assertEqual(num_samples, int(not state))
self.assertEqual(num_samples, int(not state))

def testExportAnimatedCompundValue(self):
"""MayaUSD Issue #1712: Test that animated custom compound attributes
on a mesh are exported."""
cmds.file(new=True, force=True)
cubeShape = "MyCubeShape"
cmds.polyCube(name="MyCube")
cmds.addAttr(cubeShape, sn="tf2", ln="TestFloatTwo", at="float2")
cmds.addAttr(cubeShape, sn="tf2u", ln="TestFloatTwoU", at="float", p="TestFloatTwo")
cmds.addAttr(cubeShape, sn="tf2v", ln="TestFloatTwoV", at="float", p="TestFloatTwo")
cmds.setAttr(cubeShape + ".TestFloatTwoU", e=True, keyable=True)
cmds.setAttr(cubeShape + ".TestFloatTwoV", e=True, keyable=True)
cmds.setKeyframe(cubeShape, attribute="tf2")
cmds.currentTime(10)
cmds.setAttr(cubeShape + ".TestFloatTwoU", 20.0)
cmds.setAttr(cubeShape + ".TestFloatTwoV", 40.0)
cmds.setKeyframe(cubeShape, attribute="tf2")
cmds.addAttr(cubeShape, ci=True, sn="USD_UserExportedAttributesJson", ln="USD_UserExportedAttributesJson", dt="string")
cmds.setAttr(cubeShape + ".USD_UserExportedAttributesJson", '{"TestFloatTwo": {}}', type="string")

# Exporting with a time range results in time samples:
path = os.path.join(self.temp_dir, "animatedCompoundValue.usda")
cmds.mayaUSDExport(f=path, exportSkels="auto", frameRange=(1, 10), sss=True)

stage = Usd.Stage.Open(path)

prim = stage.GetPrimAtPath("/MyCube")
attr = prim.GetAttribute("userProperties:TestFloatTwo")
self.assertGreater(attr.GetNumTimeSamples(), 1)

# Exporting without time range results in a single authored value:
path = os.path.join(self.temp_dir, "animatedCompoundValueStatic.usda")
cmds.mayaUSDExport(f=path)

stage = Usd.Stage.Open(path)

prim = stage.GetPrimAtPath("/MyCube")
attr = prim.GetAttribute("userProperties:TestFloatTwo")
self.assertEqual(attr.GetNumTimeSamples(), 0)
# Make sure value is there because previous code did not write any:
self.assertEqual(attr.Get(), [20.0, 40.0])