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-1196 material scope as default prim #3801

Merged
merged 1 commit into from
Jun 4, 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
2 changes: 1 addition & 1 deletion lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Each base command class is documented in the following sections.
| `-apiSchema` | `-api` | string (multi) | none | Imports the given API schemas' attributes as Maya custom attributes. This only recognizes API schemas that have been applied to prims on the stage. The attributes will properly round-trip if you re-export back to USD. |
| `-chaser` | `-chr` | string(multi) | none | Specify the import chasers to execute as part of the import. See "Import Chasers" below. |
| `-chaserArgs` | `-cha` | string[3] multi| none | Pass argument names and values to import chasers. Each argument to `-chaserArgs` should be a triple of the form: (`<chaser name>`, `<argument name>`, `<argument value>`). See "Import Chasers" below. |
| `-defaultPrim` | `-dp` | string | none | Set the default prim on export. |
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The doc was in the import section instead of the export section.

| `-excludePrimvar` | `-epv` | string (multi) | none | Excludes the named primvar(s) from being imported as color sets or UV sets. The primvar name should be the full name without the `primvars:` namespace prefix. |
| `-excludePrimvarNamespace` | `-epv` | string (multi) | none | Excludes the named primvar namespace(s) from being imported as color sets or UV sets. The namespance should be the name without the `primvars:` namespace prefix. Ex: `primvars:excludeNamespace:excludeMe:excludeMetoo` can be excluded by specifying `excludeNamespace` or `excludeNamespace:excludeMe`|
| `-excludeExportTypes` | `-eet` | string (multi) | none | Excludes the selected types of prims from being exported. The options are: Meshes, Cameras and Lights.|
Expand Down Expand Up @@ -190,6 +189,7 @@ their own purposes, similar to the Alembic export chaser example.
| `-pythonPerFrameCallback` | `-pfc` | string | none | Python function called after each frame is exported |
| `-pythonPostCallback` | `-ppc` | string | none | Python function called when the export is done |
| `-parentScope` | `-psc` | string | none | Deprecated. Use `-rootPrim` instead. Name of the USD scope that is the parent of the exported data |
| `-defaultPrim` | `-dp` | string | none | Set the default prim on export. If passed n empty string, then no default prim is used. If the flag is absent, the first root prim is set as the default prim. |
| `-rootPrim` | `-rpm` | string | none | Name of the USD root prim that is the parent of the exported data |
| `-rootPrimType` | `-rpt` | string | none | Type of the USD root prim. Currently Scope and Xform are supported. |
| `-renderableOnly` | `-ro` | noarg | | When set, only renderable prims are exported to USD. |
Expand Down
3 changes: 1 addition & 2 deletions lib/mayaUsd/fileio/functorPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ void UsdMaya_FunctorPrimWriter::Write(const UsdTimeCode& usdTime)
const UsdMayaPrimWriterArgs args(
GetDagPath(),
_GetExportArgs().exportRefsAsInstanceable,
_GetExportArgs().excludeExportTypes,
_GetExportArgs().defaultPrim);
_GetExportArgs().excludeExportTypes);

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

Expand Down
55 changes: 31 additions & 24 deletions lib/mayaUsd/fileio/jobs/jobArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,18 @@ bool _MergeJobContexts(bool isExport, const VtDictionary& userArgs, VtDictionary
return canMergeContexts;
}

bool _GetEncodedArg(const MString& option, std::string& argName, MString& argValue)
{
Copy link
Collaborator Author

@pierrebai-adsk pierrebai-adsk Jun 3, 2024

Choose a reason for hiding this comment

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

Refactored common code shared between import and export job args.

MStringArray theOption;
option.split('=', theOption);
if (theOption.length() < 1)
return false;

argName = theOption[0].asChar();
argValue = theOption.length() > 1 ? theOption[1] : MString();
return true;
}

} // namespace
UsdMayaJobExportArgs::UsdMayaJobExportArgs(
const VtDictionary& userArgs,
Expand Down Expand Up @@ -760,6 +772,7 @@ std::ostream& operator<<(std::ostream& out, const UsdMayaJobExportArgs& exportAr
<< "writeDefaults: " << TfStringify(exportArgs.writeDefaults) << std::endl
<< "parentScope: " << exportArgs.parentScope << std::endl // Deprecated
<< "rootPrim: " << exportArgs.parentScope << std::endl
<< "defaultPrim: " << TfStringify(exportArgs.defaultPrim) << std::endl
<< "renderLayerMode: " << exportArgs.renderLayerMode << std::endl
<< "rootKind: " << exportArgs.rootKind << std::endl
<< "disableModelKindProcessor: " << exportArgs.disableModelKindProcessor << std::endl
Expand Down Expand Up @@ -859,27 +872,27 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
// Get the options
if (optionsString.length() > 0) {
MStringArray optionList;
MStringArray theOption;
std::string argName;
MString argValue;
optionsString.split(';', optionList);
for (unsigned int i = 0; i < optionList.length(); ++i) {
theOption.clear();
optionList[i].split('=', theOption);
if (theOption.length() != 2) {
// We allow an empty string to be passed to exportRoots. We must process it here.
if (theOption.length() == 1
&& theOption[0] == UsdMayaJobExportArgsTokens->exportRoots.GetText()) {
if (!_GetEncodedArg(optionList[i], argName, argValue))
continue;

// We allow an empty string to be passed to exportRoots. We must process it here.
if (argName == UsdMayaJobExportArgsTokens->exportRoots.GetText()) {
if (argValue.length() == 0) {
std::vector<VtValue> userArgVals;
userArgVals.push_back(VtValue(""));
userArgs[UsdMayaJobExportArgsTokens->exportRoots] = userArgVals;
continue;
}
continue;
}

std::string argName(theOption[0].asChar());
if (argName == "filterTypes") {
std::vector<VtValue> userArgVals;
MStringArray filteredTypes;
theOption[1].split(',', filteredTypes);
argValue.split(',', filteredTypes);
unsigned int nbTypes = filteredTypes.length();
for (unsigned int idxType = 0; idxType < nbTypes; ++idxType) {
const std::string filteredType = filteredTypes[idxType].asChar();
Expand All @@ -889,7 +902,7 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
} else if (argName == "frameSample") {
std::vector<double> samples;
MStringArray samplesStrings;
theOption[1].split(' ', samplesStrings);
argValue.split(' ', samplesStrings);
unsigned int nbSams = samplesStrings.length();
for (unsigned int sam = 0; sam < nbSams; ++sam) {
if (samplesStrings[sam].isDouble()) {
Expand All @@ -900,7 +913,7 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
userArgs[argName] = samples;
} else if (argName == UsdMayaJobExportArgsTokens->exportRoots.GetText()) {
MStringArray exportRootStrings;
theOption[1].split(',', exportRootStrings);
argValue.split(',', exportRootStrings);

std::vector<VtValue> userArgVals;

Expand All @@ -924,7 +937,7 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
userArgs[argName] = userArgVals;
} else {
if (argName == "shadingMode") {
TfToken shadingMode(theOption[1].asChar());
TfToken shadingMode(argValue.asChar());
if (!shadingMode.IsEmpty()
&& UsdMayaShadingModeRegistry::GetInstance().GetExporter(shadingMode)
== nullptr
Expand All @@ -942,7 +955,7 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
const static bool reportError = false;
userArgs[argName] = UsdMayaUtil::ParseArgumentValue(
argName,
theOption[1].asChar(),
argValue.asChar(),
UsdMayaJobExportArgs::GetGuideDictionary(),
reportError);
}
Expand Down Expand Up @@ -1301,25 +1314,19 @@ MStatus UsdMayaJobImportArgs::GetDictionaryFromEncodedOptions(
// Get the options
if (optionsString.length() > 0) {
MStringArray optionList;
MStringArray theOption;
std::string argName;
MString argValue;
optionsString.split(';', optionList);
for (unsigned int i = 0; i < optionList.length(); ++i) {
theOption.clear();
optionList[i].split('=', theOption);
if (theOption.length() != 2) {
if (!_GetEncodedArg(optionList[i], argName, argValue))
continue;
}

// Note: if some argument needs special handling, do like in the
// same function in the export version in UsdMayaJobExportArgs
std::string argName(theOption[0].asChar());

// Note: when round-tripping settings, some extra settings are not part
// of the guiding dictionary. Ignore them.
const static bool reportError = false;
userArgs[argName] = UsdMayaUtil::ParseArgumentValue(
argName,
theOption[1].asChar(),
argValue.asChar(),
UsdMayaJobImportArgs::GetGuideDictionary(),
reportError);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/mayaUsd/fileio/jobs/writeJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@ bool UsdMaya_WriteJob::_FinishWriting()

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

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

Choose a reason for hiding this comment

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

The default prim was not used anywhere so I removed it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also checked and the _defaultPrim is private and isn't being used from anywhere. Good catch!

const TfToken::Set& excludeExportTypes);

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

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/shading/shadingModeExporterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ static UsdPrim _GetMaterialParent(
if (shaderExportLocation.IsEmpty())
shaderExportLocation = SdfPath::AbsoluteRootPath();

if (!defaultPrim.empty())
if (!defaultPrim.empty() && defaultPrim != materialsScopeName && defaultPrim != "None")
shaderExportLocation = shaderExportLocation.AppendChild(TfToken(defaultPrim));

if (!materialsScopeName.IsEmpty())
Expand Down
Loading
Loading