Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
2 changes: 2 additions & 0 deletions lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ their own purposes, similar to the Alembic export chaser example.
| `-exportDistanceUnit` | `-edu` | bool | false | Use the metersPerUnit option specified above for the stage under its `metersPerUnit` attribute |
| `-upAxis` | `-upa` | string | mayaPrefs | How the up-axis of the exported USD is controlled. "mayaPrefs" follows the current Maya Preferences. "none" does not author up-axis. "y" or "z" author that axis and convert data if the Maya preferences does not match. |
| `-unit` | `-unt` | string | mayaPrefs | How the measuring units of the exported USD is controlled. "mayaPrefs" follows the current Maya Preferences. "none" does not author up-axis. Explicit units (cm, inch, etc) author that and convert data if the Maya preferences does not match. |
| `-accessibilityLabel` | `-al` | string | | Adds an Accessibility label to the default prim. This should be short and concise. |
| `-accessibilityDescription` | `-ad` | string | | Adds an Accessibility description to the default prim. This can be more verbose and detailed. |

Note: the -metersPerUnit and -exportDistanceUnit are one way to change the exported units, the -unit is another.
We keep both to keep backward compatibility, but the -unit option is the favored way to handle the units.
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ MSyntax MayaUSDExportCommand::createSyntax()
syntax.addFlag(kFilterTypesFlag, kFilterTypesFlagLong, MSyntax::kString);
syntax.makeFlagMultiUse(kFilterTypesFlag);

syntax.addFlag(
kAccessibilityLabelFlag, UsdMayaJobExportArgsTokens->accessibilityLabel.GetText(), MSyntax::kString);
syntax.addFlag(
kAccessibilityDescriptionFlag, UsdMayaJobExportArgsTokens->accessibilityDescription.GetText(), MSyntax::kString);

syntax.enableQuery(false);
syntax.enableEdit(false);

Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/commands/baseExportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kExcludeExportTypesFlag = "eet";
static constexpr auto kDefaultPrimFlag = "dp";
static constexpr auto kIncludeEmptyTransformsFlag = "iet";
static constexpr auto kAccessibilityLabelFlag = "al";
static constexpr auto kAccessibilityDescriptionFlag = "ad";

// Short and Long forms of flags defined by this command itself:
static constexpr auto kAppendFlag = "a";
Expand Down
10 changes: 10 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,9 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
, jobContextNames(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->jobContext))
, excludeExportTypes(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->excludeExportTypes))
, defaultPrim(extractString(userArgs, UsdMayaJobExportArgsTokens->defaultPrim))
, accessibilityLabel(extractString(userArgs, UsdMayaJobExportArgsTokens->accessibilityLabel))
, accessibilityDescription(
extractString(userArgs, UsdMayaJobExportArgsTokens->accessibilityDescription))
, chaserNames(extractVector<std::string>(userArgs, UsdMayaJobExportArgsTokens->chaser))
, allChaserArgs(_ChaserArgs(userArgs, UsdMayaJobExportArgsTokens->chaserArgs))
, customLayerData(_CustomLayerData(userArgs, UsdMayaJobExportArgsTokens->customLayerData))
Expand Down Expand Up @@ -913,6 +916,9 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr
<< "parentScope: " << exportArgs.parentScope << std::endl // Deprecated
<< "rootPrim: " << exportArgs.parentScope << std::endl
<< "defaultPrim: " << TfStringify(exportArgs.defaultPrim) << std::endl
<< "accessibilityLabel: " << TfStringify(exportArgs.accessibilityLabel) << std::endl
<< "accessibilityDescription: " << TfStringify(exportArgs.accessibilityDescription)
<< std::endl
<< "renderLayerMode: " << exportArgs.renderLayerMode << std::endl
<< "rootKind: " << exportArgs.rootKind << std::endl
<< "animationType: " << exportArgs.animationType << std::endl
Expand Down Expand Up @@ -1227,6 +1233,8 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->metersPerUnit] = 0.0;
d[UsdMayaJobExportArgsTokens->excludeExportTypes] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->defaultPrim] = std::string();
d[UsdMayaJobExportArgsTokens->accessibilityLabel] = std::string();
d[UsdMayaJobExportArgsTokens->accessibilityDescription] = std::string();

// plugInfo.json site defaults.
// The defaults dict should be correctly-typed, so enable
Expand Down Expand Up @@ -1330,6 +1338,8 @@ const VtDictionary& UsdMayaJobExportArgs::GetGuideDictionary()
d[UsdMayaJobExportArgsTokens->geomSidedness] = _string;
d[UsdMayaJobExportArgsTokens->excludeExportTypes] = _stringVector;
d[UsdMayaJobExportArgsTokens->defaultPrim] = _string;
d[UsdMayaJobExportArgsTokens->accessibilityLabel] = _string;
d[UsdMayaJobExportArgsTokens->accessibilityDescription] = _string;
});

return d;
Expand Down
11 changes: 9 additions & 2 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ TF_DECLARE_PUBLIC_TOKENS(
(single) \
((double_, "double")) \
/* root prim type values */ \
(scope) \
(xform)
(scope) \
(xform) \
/* accessibility tokens */ \
(accessibilityLabel) \
(accessibilityDescription)
// clang-format on

TF_DECLARE_PUBLIC_TOKENS(
Expand Down Expand Up @@ -314,6 +317,10 @@ struct UsdMayaJobExportArgs
const TfToken::Set excludeExportTypes;
std::string defaultPrim;

// Accessibility Info
std::string accessibilityLabel;
std::string accessibilityDescription;

using ChaserArgs = std::map<std::string, std::string>;
const std::vector<std::string> chaserNames;
const std::map<std::string, ChaserArgs> allChaserArgs;
Expand Down
56 changes: 55 additions & 1 deletion lib/mayaUsd/fileio/jobs/writeJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
#include <pxr/usd/usdUtils/dependencies.h>
#include <pxr/usd/usdUtils/pipeline.h>

#if PXR_VERSION >= 2505
#include <pxr/usd/usdUI/accessibilityAPI.h>
#endif

PXR_NAMESPACE_OPEN_SCOPE

UsdMaya_WriteJob::UsdMaya_WriteJob(
Expand Down Expand Up @@ -434,7 +438,7 @@ bool UsdMaya_WriteJobImpl::WriteJobs(const std::vector<UsdMaya_WriteJob*>& jobs)
const bool showProgress = !timeSamples.empty();

// Animated export shows frame-by-frame progress.
int nbSteps = (jobs.size() * 3) + timeSamples.size() + 1;
int nbSteps = (jobs.size() * 3) + timeSamples.size() + 2;
MayaUsd::ProgressBarScope progressBar(showProgress, true /*interruptible */, nbSteps, "");

// Temporarily tweak the Maya scene for export if needed.
Expand Down Expand Up @@ -951,6 +955,9 @@ bool UsdMaya_WriteJob::_PostExport()

_extrasPrimsPaths.clear();

_AddDefaultPrimAccessibility();
progressBar.advance();

// Run post export function on the chasers.
MayaUsd::ProgressBarLoopScope chasersLoop(mChasers.size());
for (const UsdMayaExportChaserRefPtr& chaser : mChasers) {
Expand Down Expand Up @@ -1375,6 +1382,53 @@ bool UsdMaya_WriteJob::_CheckNameClashes(const SdfPath& path, const MDagPath& da
return true;
}

void UsdMaya_WriteJob::_AddDefaultPrimAccessibility()
{
auto defaultPrim = mJobCtx.mStage->GetDefaultPrim();
if (!defaultPrim) {
return;
}

auto accessibilityLabel = mJobCtx.mArgs.accessibilityLabel;
auto accessibilityDescription = mJobCtx.mArgs.accessibilityDescription;
if (accessibilityLabel.empty() && accessibilityDescription.empty()) {
return;
}

/* The USD AccessibilityAPI is only available from OpenUSD 25.5 onwards.
* We support writing the data with ad-hoc attributes on pre-25.5 versions,
* and use the actual API for 25.5 and beyond.
*/
#if PXR_VERSION >= 2505
auto api = UsdUIAccessibilityAPI::ApplyDefaultAPI(defaultPrim);
if (!accessibilityLabel.empty()) {
defaultAPI.CreateLabelAttr(VtValue(accessibilityLabel));
}
if (!accessibilityDescription.empty()) {
defaultAPI.CreateLabelAttr(VtValue(accessibilityDescription));
}
#else
defaultPrim.AddAppliedSchema(TfToken("AccessibilityAPI:default"));
if (!accessibilityLabel.empty()) {
auto labelAttr = defaultPrim.CreateAttribute(
TfToken("accessibility:default:label"),
SdfValueTypeNames->String,
false,
SdfVariabilityVarying);
labelAttr.Set(accessibilityLabel);
}

if (!accessibilityDescription.empty()) {
auto descriptionAttr = defaultPrim.CreateAttribute(
TfToken("accessibility:default:description"),
SdfValueTypeNames->String,
false,
SdfVariabilityVarying);
descriptionAttr.Set(accessibilityDescription);
}
#endif
}

const UsdMayaUtil::MDagPathMap<SdfPath>& UsdMaya_WriteJob::GetDagPathToUsdPathMap() const
{
return mDagPathToUsdPathMap;
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/fileio/jobs/writeJob.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class UsdMaya_WriteJob

bool _CheckNameClashes(const SdfPath& path, const MDagPath& dagPath);

void _AddDefaultPrimAccessibility();

// Name of the destination USD file.
std::string _fileName;

Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/python/wrapPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ void wrapJobExportArgs()
.def_readonly("verbose", &UsdMayaJobExportArgs::verbose)
.def("GetResolvedFileName", &UsdMayaJobExportArgs::GetResolvedFileName)
.def("GetDefaultMaterialsScopeName", &UsdMayaJobExportArgs::GetDefaultMaterialsScopeName)
.staticmethod("GetDefaultMaterialsScopeName");
.staticmethod("GetDefaultMaterialsScopeName")
.def_readonly("accessibilityLabel", &UsdMayaJobExportArgs::accessibilityLabel)
.def_readonly("accessibilityDescription", &UsdMayaJobExportArgs::accessibilityDescription);
}

TF_REGISTRY_FUNCTION(TfEnum)
Expand Down
Loading