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-550 - Control the Types of Objects to Export #3338

Merged
merged 7 commits into from
Oct 2, 2023
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: 6 additions & 0 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ MSyntax MayaUSDExportCommand::createSyntax()
MSyntax::kString);
syntax.makeFlagMultiUse(UsdMayaJobExportArgsTokens->customLayerData.GetText());

syntax.addFlag(
kExcludeExportTypesFlag,
UsdMayaJobExportArgsTokens->excludeExportTypes.GetText(),
MSyntax::kString);
syntax.makeFlagMultiUse((kExcludeExportTypesFlag));

// These are additional flags under our control.
syntax.addFlag(
kMetersPerUnit, UsdMayaJobExportArgsTokens->metersPerUnit.GetText(), MSyntax::kDouble);
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 @@ -93,6 +93,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kWorldspaceFlag = "wsp";
static constexpr auto kCustomLayerData = "cld";
static constexpr auto kMetersPerUnit = "mpu";
static constexpr auto kExcludeExportTypesFlag = "eet";

// Short and Long forms of flags defined by this command itself:
static constexpr auto kAppendFlag = "a";
Expand Down
5 changes: 4 additions & 1 deletion lib/mayaUsd/fileio/functorPrimWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ void UsdMaya_FunctorPrimWriter::Write(const UsdTimeCode& usdTime)
{
UsdMayaTransformWriter::Write(usdTime);

const UsdMayaPrimWriterArgs args(GetDagPath(), _GetExportArgs().exportRefsAsInstanceable);
const UsdMayaPrimWriterArgs args(
GetDagPath(),
_GetExportArgs().exportRefsAsInstanceable,
_GetExportArgs().excludeExportTypes);

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 @@ -664,6 +664,7 @@ UsdMayaJobExportArgs::UsdMayaJobExportArgs(
{ UsdMayaJobExportArgsTokens->single, UsdMayaJobExportArgsTokens->double_ }))
, includeAPINames(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->apiSchema))
, jobContextNames(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->jobContext))
, excludeExportTypes(extractTokenSet(userArgs, UsdMayaJobExportArgsTokens->excludeExportTypes))
, chaserNames(extractVector<std::string>(userArgs, UsdMayaJobExportArgsTokens->chaser))
, allChaserArgs(_ChaserArgs(userArgs, UsdMayaJobExportArgsTokens->chaserArgs))
, customLayerData(_CustomLayerData(userArgs, UsdMayaJobExportArgsTokens->customLayerData))
Expand Down Expand Up @@ -1012,6 +1013,7 @@ const VtDictionary& UsdMayaJobExportArgs::GetDefaultDictionary()
= UsdMayaJobExportArgsTokens->derived.GetString();
d[UsdMayaJobExportArgsTokens->customLayerData] = std::vector<VtValue>();
d[UsdMayaJobExportArgsTokens->metersPerUnit] = 0.0;
d[UsdMayaJobExportArgsTokens->excludeExportTypes] = std::vector<VtValue>();

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

return d;
Expand Down
3 changes: 3 additions & 0 deletions lib/mayaUsd/fileio/jobs/jobArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ TF_DECLARE_PUBLIC_TOKENS(
(writeDefaults) \
(customLayerData) \
(metersPerUnit) \
/* Types of objects to export */ \
(excludeExportTypes) \
/* Special "none" token */ \
(none) \
/* relative textures values */ \
Expand Down Expand Up @@ -245,6 +247,7 @@ struct UsdMayaJobExportArgs
const TfToken geomSidedness;
const TfToken::Set includeAPINames;
const TfToken::Set jobContextNames;
const TfToken::Set excludeExportTypes;

using ChaserArgs = std::map<std::string, std::string>;
const std::vector<std::string> chaserNames;
Expand Down
6 changes: 4 additions & 2 deletions lib/mayaUsd/fileio/primWriterArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
PXR_NAMESPACE_OPEN_SCOPE

UsdMayaPrimWriterArgs::UsdMayaPrimWriterArgs(
const MDagPath& dagPath,
const bool exportRefsAsInstanceable)
const MDagPath& dagPath,
const bool exportRefsAsInstanceable,
const TfToken::Set& excludeExportTypes)
: _dagPath(dagPath)
, _exportRefsAsInstanceable(exportRefsAsInstanceable)
, _excludeExportTypes(excludeExportTypes)
{
}

Expand Down
10 changes: 7 additions & 3 deletions lib/mayaUsd/fileio/primWriterArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ class UsdMayaPrimWriterArgs
{
public:
MAYAUSD_CORE_PUBLIC
UsdMayaPrimWriterArgs(const MDagPath& dagPath, const bool exportRefsAsInstanceable);
UsdMayaPrimWriterArgs(
const MDagPath& dagPath,
const bool exportRefsAsInstanceable,
const TfToken::Set& excludeExportTypes);

/// \brief returns the MObject that should be exported.
MAYAUSD_CORE_PUBLIC
Expand All @@ -64,8 +67,9 @@ class UsdMayaPrimWriterArgs
/// \}

private:
MDagPath _dagPath;
bool _exportRefsAsInstanceable;
MDagPath _dagPath;
bool _exportRefsAsInstanceable;
TfToken::Set _excludeExportTypes;
};

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
34 changes: 34 additions & 0 deletions lib/mayaUsd/fileio/writeJobContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,40 @@ bool UsdMayaWriteJobContext::_NeedToTraverse(const MDagPath& curDag) const
return false;
}

// In addition to check for primless, we check for user selection of export types
if (!mArgs.excludeExportTypes.empty()) {
MDagPath shapeDagPath = curDag;
if (mArgs.mergeTransformAndShape) {
// if we're merging transforms, then we need to look at the shape.
shapeDagPath.extendToShape();
}

MStatus status;
MObject obj = shapeDagPath.node();
const MFnDependencyNode depFn(obj, &status);
if (!status) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

IDK if failure to cerate a MFnDependencyNode should be treated as failure. A node not being a MFnDependencyNode is not an error, it just that the node does not support the API.

It should just skip the type check.

return false;
}

const std::string mayaTypeName(depFn.typeName().asChar());

if ((mArgs.excludeExportTypes.count(TfToken("Meshes")) != 0)
|| (mArgs.excludeExportTypes.count(TfToken("meshes")) != 0)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be cleaner and more general to lowercase both strings and compare those.

if (mayaTypeName == "mesh")
return false;
}
if ((mArgs.excludeExportTypes.count(TfToken("Cameras")) != 0)
|| (mArgs.excludeExportTypes.count(TfToken("camera")) != 0)) {
if (mayaTypeName.find("camera") != std::string::npos)
return false;
}
if ((mArgs.excludeExportTypes.count(TfToken("Lights")) != 0)
|| (mArgs.excludeExportTypes.count(TfToken("light")) != 0)) {
if (mayaTypeName.find("Light") != std::string::npos)
return false;
}
}

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions plugin/adsk/scripts/mayaUSDRegisterStrings.mel
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ global proc mayaUSDRegisterStrings()
register("kExportBlendShapesLbl", "Blend Shapes");
register("kExportColorSetsAnn", "Exports Maya Color Sets as USD primvars.");
register("kExportColorSetsLbl", "Color Sets");
register("kExportMeshesLbl", "Meshes");
register("kExportMeshesAnn", "If selected, mesh geometry is extracted for USD export.");
register("kExportCamerasLbl", "Cameras");
register("kExportCamerasAnn", "If selected, cameras are extracted for USD export.");
register("kExportLightsLbl", "Lights");
register("kExportLightsAnn", "If selected, lights are extracted for USD export.");
register("kExportComponentTagsAnn", "If selected, component tags get exported as USDGeomSubsets. Note: Edges and vertices are unsupported in USD.");
register("kExportComponentTagsLbl", "Component Tags");
register("kExportCurvesAnn", "If selected, curves get exported to USD primTypes NurbsCurves or BasisCurves.");
Expand Down
83 changes: 74 additions & 9 deletions plugin/adsk/scripts/mayaUsdTranslatorExport.mel
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,29 @@ proc string mayaUsdTranslatorExport_SetFromCheckbox(string $currentOptions, stri
}
}

// For Suboptions we don't add semicolon
proc string mayaUsdTranslatorExport_SetSuboptionsFromCheckBox(string $currentOptions, string $trueValue, string $falseValue, string $widget) {
if (`checkBoxGrp -exists $widget` == 0)
return $currentOptions;

if (`checkBoxGrp -q -v1 $widget` == 1) {
if((size($currentOptions) > 0) && (size($trueValue) > 0)){
return $currentOptions + "," + $trueValue;
}
else {
return $currentOptions + $trueValue;
}
} else {
if((size($currentOptions) > 0) && (size($falseValue) > 0)) {
return $currentOptions + "," + $falseValue;
}
else {
return $currentOptions + $falseValue;
}
}
}


proc string mayaUsdTranslatorExport_AppendJobContexts(string $currentOptions, string $arg) {
if (`optionMenuGrp -exists jobContextPopup` == 0)
return $currentOptions;
Expand Down Expand Up @@ -226,6 +249,13 @@ global proc mayaUsdTranslatorExport_AnimationCB() {
columnLayout -e -enable (`checkBoxGrp -q -v1 animationCheckBox`) animOptsCol;
}

global proc mayaUsdTranslatorExport_MeshCB() {
if (`checkBoxGrp -exists exportMeshesCheckBox` == 0)
return;

columnLayout -e -enable (`checkBoxGrp -q -v1 exportMeshesCheckBox` == 1) meshExportOptsCol;
}

// Callback called when the animation frame layout is expanded.
// Set the animOptsCol layout visibility status based on the
// animationCheckBox checkbox value. By default, maya look
Expand Down Expand Up @@ -319,6 +349,7 @@ global proc mayaUsdTranslatorExport_EnableAllControls() {

// Restore all controls to fully interactive:
if (stringArrayContains("geometry", $sectionNames)) {
checkBoxGrp -e -en 1 exportMeshesCheckBox;
optionMenuGrp -e -en 1 defaultMeshSchemePopup;
checkBoxGrp -e -en 1 exportUVsCheckBox;
optionMenuGrp -e -en 1 skelsPopup;
Expand Down Expand Up @@ -359,6 +390,8 @@ global proc mayaUsdTranslatorExport_EnableAllControls() {
}

if (stringArrayContains("advanced", $sectionNames)) {
checkBoxGrp -e -en 1 exportCamerasCheckBox;
checkBoxGrp -e -en 1 exportLightsCheckBox;
optionMenuGrp -e -en 1 exportInstancesPopup;
checkBoxGrp -e -en 1 exportVisibilityCheckBox;
checkBoxGrp -e -en 1 mergeTransformAndShapeCheckBox;
Expand Down Expand Up @@ -405,6 +438,17 @@ global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $
if (mayaUsdTranslatorExport_HasFilteredPrimitive($optionBreakDown[1], "nurbsCurve")) {
$exportNurbsCurves = 0;
}
} else if($optionBreakDown[0] == "excludeExportTypes"){
if(mayaUsdTranslatorExport_HasFilteredPrimitive($optionBreakDown[1], "Meshes") == 0){
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportMeshesCheckBox");
mayaUsdTranslatorExport_MeshCB();
}
if(mayaUsdTranslatorExport_HasFilteredPrimitive($optionBreakDown[1], "Cameras") == 0){
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportCamerasCheckBox");
}
if(mayaUsdTranslatorExport_HasFilteredPrimitive($optionBreakDown[1], "Lights") == 0){
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportLightsCheckBox");
}
} else if ($optionBreakDown[0] == "exportColorSets") {
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportColorSetsCheckBox");
} else if ($optionBreakDown[0] == "exportComponentTags") {
Expand Down Expand Up @@ -444,6 +488,10 @@ global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportDisplayColorCheckBox");
} else if ($optionBreakDown[0] == "exportInstances") {
mayaUsdTranslatorExport_SetOptionMenuByBool($optionBreakDown[1], $enable, "exportInstancesPopup");
} else if($optionBreakDown[0] == "exportCameras"){
mayaUsdTranslatorExport_SetOptionMenuByBool($optionBreakDown[1], $enable, "exportInstancesPopup");
} else if($optionBreakDown[0] == "exportLights") {
mayaUsdTranslatorExport_SetOptionMenuByBool($optionBreakDown[1], $enable, "exportInstancesPopup");
} else if ($optionBreakDown[0] == "exportVisibility") {
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportVisibilityCheckBox");
} else if ($optionBreakDown[0] == "mergeTransformAndShape") {
Expand Down Expand Up @@ -630,19 +678,25 @@ global proc int mayaUsdTranslatorExport (string $parent,
int $collapse = stringArrayContains("geometry", $collapsedSections) ? true : false;
frameLayout -label `getMayaUsdString("kExportFrameGeometryLbl")` -collapsable true -collapse $collapse geometryFrameLayout;
separator -style "none";
optionMenuGrp -l `getMayaUsdString("kExportSubdMethodLbl")` -annotation `getMayaUsdString("kExportSubdMethodAnn")` defaultMeshSchemePopup;
menuItem -l `getMayaUsdString("kExportSubdMethodCCLbl")` -ann "catmullClark";
menuItem -l `getMayaUsdString("kExportSubdMethodBiLbl")` -ann "bilinear";
menuItem -l `getMayaUsdString("kExportSubdMethodLoLbl")` -ann "loop";
menuItem -l `getMayaUsdString("kExportSubdMethodNoLbl")` -ann "none";
// if export Meshes
checkBoxGrp -label "" -label1 `getMayaUsdString("kExportMeshesLbl")` -annotation `getMayaUsdString("kExportMeshesAnn")` -cc ("mayaUsdTranslatorExport_MeshCB") exportMeshesCheckBox;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportComponentTagsLbl")` -annotation `getMayaUsdString("kExportComponentTagsAnn")` exportComponentTagsCheckBox;
columnLayout -width 100 meshExportOptsCol;
optionMenuGrp -l `getMayaUsdString("kExportSubdMethodLbl")` -annotation `getMayaUsdString("kExportSubdMethodAnn")` defaultMeshSchemePopup;
menuItem -l `getMayaUsdString("kExportSubdMethodCCLbl")` -ann "catmullClark";
menuItem -l `getMayaUsdString("kExportSubdMethodBiLbl")` -ann "bilinear";
menuItem -l `getMayaUsdString("kExportSubdMethodLoLbl")` -ann "loop";
menuItem -l `getMayaUsdString("kExportSubdMethodNoLbl")` -ann "none";

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportCurvesLbl")` -annotation `getMayaUsdString("kExportCurvesAnn")` exportCurvesCheckBox;
checkBoxGrp -label "" -label1 `getMayaUsdString("kExportColorSetsLbl")` -annotation `getMayaUsdString("kExportColorSetsAnn")` exportColorSetsCheckBox;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportComponentTagsLbl")` -annotation `getMayaUsdString("kExportComponentTagsAnn")` exportComponentTagsCheckBox;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportColorSetsLbl")` -annotation `getMayaUsdString("kExportColorSetsAnn")` exportColorSetsCheckBox;
checkBoxGrp -label "" -label1 `getMayaUsdString("kExportUVSetsLbl")` -annotation `getMayaUsdString("kExportUVSetsAnn")` exportUVsCheckBox;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportUVSetsLbl")` -annotation `getMayaUsdString("kExportUVSetsAnn")` exportUVsCheckBox;
setParent ..;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportCurvesLbl")` -annotation `getMayaUsdString("kExportCurvesAnn")` exportCurvesCheckBox;

optionMenuGrp -l `getMayaUsdString("kExportSkelsLbl")` -annotation `getMayaUsdString("kExportSkelsAnn")` skelsPopup;
menuItem -l `getMayaUsdString("kExportSkelsNoneLbl")` -ann "none";
Expand Down Expand Up @@ -726,6 +780,9 @@ global proc int mayaUsdTranslatorExport (string $parent,
frameLayout -label `getMayaUsdString("kExportFrameAdvancedLbl")` -collapsable true -collapse $collapse advancedFrameLayout;
separator -style "none";

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportCamerasLbl")` -annotation `getMayaUsdString("kExportCamerasAnn")` exportCamerasCheckBox;
checkBoxGrp -label "" -label1 `getMayaUsdString("kExportLightsLbl")` -annotation `getMayaUsdString("kExportLightsAnn")` exportLightsCheckBox;

checkBoxGrp -label "" -label1 `getMayaUsdString("kExportVisibilityLbl")` -annotation `getMayaUsdString("kExportVisibilityAnn")` exportVisibilityCheckBox;

optionMenuGrp -l `getMayaUsdString("kExportInstancesLbl")` -annotation `getMayaUsdString("kExportInstancesAnn")` exportInstancesPopup;
Expand All @@ -749,8 +806,11 @@ global proc int mayaUsdTranslatorExport (string $parent,
string $expandedSections[];
string $collapsedSections[];
string $sectionNames[] = parseActionSectionNames($sections, $expandedSections, $collapsedSections);
// collect all exclude types before append to option list
string $excludeExportTypes = "";

if (stringArrayContains("geometry", $sectionNames)) {
$excludeExportTypes = mayaUsdTranslatorExport_SetSuboptionsFromCheckBox($excludeExportTypes, "", "Meshes", "exportMeshesCheckBox");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The flag is passed explicitly here, so changing from "Meshes" to "mesh" seem feasible without modifying UI shown to teh user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know if that will confuse the user.. Like they see "Meshes" in the UI but when use it in command it changes to "mesh". They won't know it unless they read extra documents to get that information...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But yea its definitely feasible

$currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "exportUVs", "exportUVsCheckBox");
$currentOptions = mayaUsdTranslatorExport_AppendFromPopup($currentOptions, "exportSkels", "skelsPopup");
$currentOptions = mayaUsdTranslatorExport_AppendFromPopup($currentOptions, "exportSkin", "skinClustersPopup");
Expand Down Expand Up @@ -787,6 +847,8 @@ global proc int mayaUsdTranslatorExport (string $parent,
}

if (stringArrayContains("advanced", $sectionNames)) {
$excludeExportTypes = mayaUsdTranslatorExport_SetSuboptionsFromCheckBox($excludeExportTypes, "", "Cameras", "exportCamerasCheckBox");
$excludeExportTypes = mayaUsdTranslatorExport_SetSuboptionsFromCheckBox($excludeExportTypes, "", "Lights", "exportLightsCheckBox");
$currentOptions = mayaUsdTranslatorExport_AppendFromBoolPopup($currentOptions, "exportInstances", "exportInstancesPopup");
$currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "exportVisibility", "exportVisibilityCheckBox");
$currentOptions = mayaUsdTranslatorExport_AppendFromCheckbox($currentOptions, "mergeTransformAndShape", "mergeTransformAndShapeCheckBox");
Expand All @@ -798,6 +860,9 @@ global proc int mayaUsdTranslatorExport (string $parent,
$currentOptions = mayaUsdTranslatorExport_AppendJobContexts($currentOptions, "jobContext");
}

// Append the final excludeExportTypes options to the options list
$currentOptions = $currentOptions + ";" + "excludeExportTypes=[" + $excludeExportTypes + "]";

eval($resultCallback+" \""+$currentOptions+"\"");
$bResult = 1;

Expand Down
1 change: 1 addition & 0 deletions test/lib/usd/translators/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(TEST_SCRIPT_FILES
testUsdExportOverImport.py
testUsdExportUsdPreviewSurface.py
testUsdExportParentScope.py
testUsdExportTypes.py

# To investigate: following test asserts in MFnParticleSystem, but passes.
# PPT, 17-Jun-20.
Expand Down
Loading