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

EMSUSD-948 scale export to USD according to units #3937

Merged
merged 1 commit into from
Oct 1, 2024
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
6 changes: 5 additions & 1 deletion lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ their own purposes, similar to the Alembic export chaser example.
| `-defaultCameras` | `-dc` | noarg | false | Export the four Maya default cameras |
| `-defaultMeshScheme` | `-dms` | string | `catmullClark` | Sets the default subdivision scheme for exported Maya meshes, if the `USD_ATTR_subdivisionScheme` attribute is not present on the Mesh. Valid values are: `none`, `catmullClark`, `loop`, `bilinear` |
| `-exportDisplayColor` | `-dsp` | bool | false | Export display color |
| `-exportDistanceUnit` | `-edu` | bool | true | Export the Maya distance unit to USD for the stage under its `metersPerUnit` attribute |
| `-jobContext` | `-jc` | string (multi) | none | Specifies an additional export context to handle. These usually contains extra schemas, primitives, and materials that are to be exported for a specific task, a target renderer for example. |
| `-defaultUSDFormat` | `-duf` | string | `usdc` | The exported USD file format, can be `usdc` for binary format or `usda` for ASCII format. |
| `-exportBlendShapes` | `-ebs` | bool | false | Enable or disable export of blend shapes |
Expand Down Expand Up @@ -206,7 +205,12 @@ their own purposes, similar to the Alembic export chaser example.
| `-verbose` | `-v` | noarg | false | Make the command output more verbose |
| `-customLayerData` | `-cld` | string[3](multi) | none | Set the layers customLayerData metadata. Values are a list of three strings for key, value and data type |
| `-metersPerUnit` | `-mpu` | double | 0.0 | (Evolving) Exports with the given metersPerUnit. Use with care, as only certain attributes have their dimensions converted.<br/><br/> The default value of 0 will continue to use the Maya internal units (cm) and a value of -1 will use the display units. Any other positive value will be taken as an explicit metersPerUnit value to be used.<br/><br/> Currently, the following prim types are supported: <br/><ul><li>Meshes</li><li>Transforms</li></ul> |
| `-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. |

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.

#### Frame Samples

Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ MSyntax MayaUSDExportCommand::createSyntax()
syntax.addFlag(
kRootPrimTypeFlag, UsdMayaJobExportArgsTokens->rootPrimType.GetText(), MSyntax::kString);
syntax.addFlag(kUpAxisFlag, UsdMayaJobExportArgsTokens->upAxis.GetText(), MSyntax::kString);
syntax.addFlag(kUnitFlag, UsdMayaJobExportArgsTokens->unit.GetText(), MSyntax::kString);
syntax.addFlag(
kRenderableOnlyFlag, UsdMayaJobExportArgsTokens->renderableOnly.GetText(), MSyntax::kNoArg);
syntax.addFlag(
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/baseExportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kRootPrimFlag = "rpm";
static constexpr auto kRootPrimTypeFlag = "rpt";
static constexpr auto kUpAxisFlag = "upa";
static constexpr auto kUnitFlag = "unt";
static constexpr auto kRenderableOnlyFlag = "ro";
static constexpr auto kDefaultCamerasFlag = "dc";
static constexpr auto kRenderLayerModeFlag = "rlm";
Expand Down
20 changes: 19 additions & 1 deletion lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,22 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
{ UsdMayaJobExportArgsTokens->none,
UsdMayaJobExportArgsTokens->y,
UsdMayaJobExportArgsTokens->z }))
, unit(extractToken(
userArgs,
UsdMayaJobExportArgsTokens->unit,
UsdMayaJobExportArgsTokens->mayaPrefs,
{ UsdMayaJobExportArgsTokens->none,
UsdMayaJobExportArgsTokens->nm,
UsdMayaJobExportArgsTokens->um,
UsdMayaJobExportArgsTokens->mm,
UsdMayaJobExportArgsTokens->cm,
UsdMayaJobExportArgsTokens->m,
UsdMayaJobExportArgsTokens->km,
UsdMayaJobExportArgsTokens->lightyear,
UsdMayaJobExportArgsTokens->inch,
UsdMayaJobExportArgsTokens->foot,
UsdMayaJobExportArgsTokens->yard,
UsdMayaJobExportArgsTokens->mile }))
, renderLayerMode(extractToken(
userArgs,
UsdMayaJobExportArgsTokens->renderLayerMode,
Expand Down Expand Up @@ -1111,7 +1127,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->exportAssignedMaterials] = true;
d[UsdMayaJobExportArgsTokens->legacyMaterialScope] = false;
d[UsdMayaJobExportArgsTokens->exportDisplayColor] = false;
d[UsdMayaJobExportArgsTokens->exportDistanceUnit] = true;
d[UsdMayaJobExportArgsTokens->exportDistanceUnit] = false;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the default for the new unit option is "Maya Prefs", we are better off with exportDistanceUnit being off by deault, otherwise it would overwrite what the unit option would try to do.

d[UsdMayaJobExportArgsTokens->exportInstances] = true;
d[UsdMayaJobExportArgsTokens->exportMaterialCollections] = false;
d[UsdMayaJobExportArgsTokens->referenceObjectMode]
Expand Down Expand Up @@ -1147,6 +1163,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->rootPrim] = std::string();
d[UsdMayaJobExportArgsTokens->rootPrimType] = UsdMayaJobExportArgsTokens->scope.GetString();
d[UsdMayaJobExportArgsTokens->upAxis] = UsdMayaJobExportArgsTokens->mayaPrefs.GetString();
d[UsdMayaJobExportArgsTokens->unit] = UsdMayaJobExportArgsTokens->mayaPrefs.GetString();
d[UsdMayaJobExportArgsTokens->pythonPerFrameCallback] = std::string();
d[UsdMayaJobExportArgsTokens->pythonPostCallback] = std::string();
d[UsdMayaJobExportArgsTokens->renderableOnly] = false;
Expand Down Expand Up @@ -1253,6 +1270,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetGuideDictionary()
d[UsdMayaJobExportArgsTokens->rootPrim] = _string;
d[UsdMayaJobExportArgsTokens->rootPrimType] = _string;
d[UsdMayaJobExportArgsTokens->upAxis] = _string;
d[UsdMayaJobExportArgsTokens->unit] = _string;
d[UsdMayaJobExportArgsTokens->pythonPerFrameCallback] = _string;
d[UsdMayaJobExportArgsTokens->pythonPostCallback] = _string;
d[UsdMayaJobExportArgsTokens->renderableOnly] = _boolean;
Expand Down
17 changes: 17 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(rootPrim) \
(rootPrimType) \
(upAxis) \
(unit) \
(pythonPerFrameCallback) \
(pythonPostCallback) \
(renderableOnly) \
Expand All @@ -128,9 +129,24 @@ TF_DECLARE_PUBLIC_TOKENS(
/* Special "none" token */ \
(none) \
/* up axis values */ \
/* (none) */ \
(mayaPrefs) \
(y) \
(z) \
/* unit values */ \
/* (none) */ \
/* (mayaPrefs) */ \
(nm) \
(um) \
(mm) \
(cm) \
(m) \
(km) \
(lightyear) \
(inch) \
(foot) \
(yard) \
(mile) \
/* relative textures values */ \
(automatic) \
(absolute) \
Expand Down Expand Up @@ -272,6 +288,7 @@ struct UsdMayaJobExportArgs
const SdfPath rootPrim;
const TfToken rootPrimType;
const TfToken upAxis;
const TfToken unit;
const TfToken renderLayerMode;
const TfToken rootKind;
const bool disableModelKindProcessor;
Expand Down
Loading
Loading