Skip to content

Commit

Permalink
Add command to set default prim on export
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelliu-adsk committed Jan 15, 2024
1 parent ce0a3bb commit 032a36e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ MSyntax MayaUSDExportCommand::createSyntax()
kExcludeExportTypesFlag,
UsdMayaJobExportArgsTokens->excludeExportTypes.GetText(),
MSyntax::kString);
syntax.makeFlagMultiUse((kExcludeExportTypesFlag));
syntax.makeFlagMultiUse(kExcludeExportTypesFlag);

syntax.addFlag(
kDefaultPrimFlag, UsdMayaJobExportArgsTokens->defaultPrim.GetText(), MSyntax::kString);

// These are additional flags under our control.
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 @@ -94,6 +94,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kCustomLayerData = "cld";
static constexpr auto kMetersPerUnit = "mpu";
static constexpr auto kExcludeExportTypesFlag = "eet";
static constexpr auto kDefaultPrimFlag = "dp";

// Short and Long forms of flags defined by this command itself:
static constexpr auto kAppendFlag = "a";
Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/fileio/functorPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void UsdMaya_FunctorPrimWriter::Write(const UsdTimeCode& usdTime)
const UsdMayaPrimWriterArgs args(
GetDagPath(),
_GetExportArgs().exportRefsAsInstanceable,
_GetExportArgs().excludeExportTypes);
_GetExportArgs().excludeExportTypes,
_GetExportArgs().defaultPrim);

UsdMayaPrimWriterContext ctx(usdTime, GetUsdPath(), GetUsdStage());

Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
, includeAPINames(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->apiSchema))
, jobContextNames(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->jobContext))
, excludeExportTypes(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->excludeExportTypes))
, defaultPrim(extractString(userArgs, UsdMayaJobExportArgsTokens->defaultPrim))
, chaserNames(extractVector<std::string>(userArgs, UsdMayaJobExportArgsTokens->chaser))
, allChaserArgs(_ChaserArgs(userArgs, UsdMayaJobExportArgsTokens->chaserArgs))
, customLayerData(_CustomLayerData(userArgs, UsdMayaJobExportArgsTokens->customLayerData))
Expand Down Expand Up @@ -1017,6 +1018,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
d[UsdMayaJobExportArgsTokens->customLayerData] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->metersPerUnit] = 0.0;
d[UsdMayaJobExportArgsTokens->excludeExportTypes] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->defaultPrim] = std::string();

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

return d;
Expand Down
2 changes: 2 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ TF_DECLARE_PUBLIC_TOKENS(
(compatibility) \
(defaultCameras) \
(defaultMeshScheme) \
(defaultPrim) \
(defaultUSDFormat) \
(eulerFilter) \
(exportBlendShapes) \
Expand Down Expand Up @@ -250,6 +251,7 @@ struct UsdMayaJobExportArgs
const TfToken::Set includeAPINames;
const TfToken::Set jobContextNames;
const TfToken::Set excludeExportTypes;
const std::string defaultPrim;

using ChaserArgs = std::map<std::string, std::string>;
const std::vector<std::string> chaserNames;
Expand Down
5 changes: 4 additions & 1 deletion lib/mayaUsd/fileio/jobs/writeJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,10 @@ bool UsdMaya_WriteJob::_FinishWriting()
UsdGeomSetStageMetersPerUnit(mJobCtx.mStage, mJobCtx.mArgs.metersPerUnit);
}

if (usdRootPrim) {
if (!mJobCtx.mArgs.defaultPrim.empty()) {
defaultPrim = TfToken(mJobCtx.mArgs.defaultPrim);
mJobCtx.mStage->GetRootLayer()->SetDefaultPrim(defaultPrim);
} else if (usdRootPrim) {
// We have already decided above that 'usdRootPrim' is the important
// prim for the export... usdVariantRootPrimPath
mJobCtx.mStage->GetRootLayer()->SetDefaultPrim(defaultPrim);
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/fileio/primWriterArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ PXR_NAMESPACE_OPEN_SCOPE
UsdMayaPrimWriterArgs::UsdMayaPrimWriterArgs(
const MDagPath& dagPath,
const bool exportRefsAsInstanceable,
const TfToken::Set& excludeExportTypes)
const TfToken::Set& excludeExportTypes,
const std::string& defaultPrim)
: _dagPath(dagPath)
, _exportRefsAsInstanceable(exportRefsAsInstanceable)
, _excludeExportTypes(excludeExportTypes)
, _defaultPrim(defaultPrim)
{
}

Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/fileio/primWriterArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ class UsdMayaPrimWriterArgs
UsdMayaPrimWriterArgs(
const MDagPath& dagPath,
const bool exportRefsAsInstanceable,
const TfToken::Set& excludeExportTypes);
const TfToken::Set& excludeExportTypes,
const std::string& defaultPrim);

/// \brief returns the MObject that should be exported.
MAYAUSD_CORE_PUBLIC
Expand Down Expand Up @@ -70,6 +71,7 @@ class UsdMayaPrimWriterArgs
MDagPath _dagPath;
bool _exportRefsAsInstanceable;
TfToken::Set _excludeExportTypes;
std::string _defaultPrim;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down

0 comments on commit 032a36e

Please sign in to comment.