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

MAYA-112228 Use Adaptors for custom schema import-export #1814

Merged
merged 8 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ target_sources(${PROJECT_NAME}
PRIVATE
baseExportCommand.cpp
baseImportCommand.cpp
baseListJobContextsCommand.cpp
baseListShadingModesCommand.cpp
editTargetCommand.cpp
layerEditorCommand.cpp
Expand All @@ -15,6 +16,7 @@ set(HEADERS
abstractLayerEditorWindow.h
baseExportCommand.h
baseImportCommand.h
baseListJobContextsCommand.h
baseListShadingModesCommand.h
editTargetCommand.h
layerEditorCommand.h
Expand Down
19 changes: 19 additions & 0 deletions lib/mayaUsd/commands/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Each base command class is documented in the following sections.
| `-file` | `-f` | string | none | Name of the USD being loaded |
| `-frameRange` | `-fr` | float float | none | The frame range of animations to import |
| `-importInstances` | `-ii` | bool | true | Import USD instanced geometries as Maya instanced shapes. Will flatten the scene otherwise. |
| `-jobContext` | `-jc` | string (multi) | none | Specifies an additional import context to handle. These usually contains extra schemas, primitives, and materials that are to be imported for a specific task, a target renderer for example. |
| `-metadata` | `-md` | string (multi) | `hidden`, `instanceable`, `kind` | Imports the given USD metadata fields as Maya custom attributes (e.g. `USD_hidden`, `USD_kind`, etc.) if they're authored on the USD prim. The metadata will properly round-trip if you re-export back to USD. |
| `-parent` | `-p` | string | none | Name of the Maya scope that will be the parent of the imported data. |
| `-primPath` | `-pp` | string | none (defaultPrim) | Name of the USD scope where traversing will being. The prim at the specified primPath (including the prim) will be imported. Specifying the pseudo-root (`/`) means you want to import everything in the file. If the passed prim path is empty, it will first try to import the defaultPrim for the rootLayer if it exists. Otherwise, it will behave as if the pseudo-root was passed in. |
Expand Down Expand Up @@ -113,6 +114,7 @@ their own purposes, similar to the Alembic export chaser example.

| Long flag | Short flag | Type | Default | Description |
| -------------------------------- | ---------- | ---------------- | ------------------- | ----------- |
| `-apiSchema` | `-api` | string (multi) | none | Exports the given API schema. Requires registering schema exporters for the API. |
| `-append` | `-a` | bool | false | Appends into an existing USD file |
| `-chaser` | `-chr` | string(multi) | none | Specify the export chasers to execute as part of the export. See "Export Chasers" below. |
| `-chaserArgs` | `-cha` | string[3](multi) | none | Pass argument names and values to export chasers. Each argument to `-chaserArgs` should be a triple of the form: (`<chaser name>`, `<argument name>`, `<argument value>`). See "Export Chasers" below. |
Expand All @@ -121,6 +123,7 @@ 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_subdivisionScheme` attribute is not present on the Mesh. Valid values are: `none`, `catmullClark`, `loop`, `bilinear` |
| `-exportDisplayColor` | `-dsp` | bool | false | Export display color |
| `-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 |
| `-exportCollectionBasedBindings` | `-cbb` | bool | false | Enable or disable export of collection-based material assigments. If this option is enabled, export of material collections (`-mcs`) is also enabled, which causes collections representing sets of geometry with the same material binding to be exported. Materials are bound to the created collections on the prim at `materialCollectionsPath` (specfied via the `-mcp` option). Direct (or per-gprim) bindings are not authored when collection-based bindings are enabled. |
Expand Down Expand Up @@ -439,6 +442,22 @@ names and annotations for various elements passed to the other commands.
| `-importOptions` | `-io` | string | Retrieve the a pair of names that completely define a shading mode, as used by the import `shadingMode` option |
| `-importAnnotation` | `-ia` | string | Retrieve the description of the import shading mode option |

## `mayaUSDListJobContexts`

The purpose of this command is to find the names and annotations for registered import and export job contexts.

### Command Flags

| Long flag | Short flag | Type | Description |
| ---------------------- | ---------- | -------------- | ----------- |
| `-export` | `-ex` | noarg | Retrieve the list of export job context nice names. |
| `-exportAnnotation` | `-ea` | string | Retrieve the description of the export job context option nice name passed as parameter. |
| `-exportArguments` | `-eg` | string | Retrieve the export arguments affected by the export job context nice name passed as parameter |
| `-import` | `-im` | noarg | Retrieve the list of import job context nice names. |
| `-importAnnotation` | `-ia` | string | Retrieve the description of the import job context option nice name passed as parameter. |
| `-importArguments` | `-ig` | string | Retrieve the import arguments affected by the import job context nice name passed as parameter |
| `-jobContext` | `-jc` | string | Retrieve the job context name associated with a nice name. |


## `EditTargetCommand`

Expand Down
10 changes: 8 additions & 2 deletions lib/mayaUsd/commands/baseExportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ MSyntax MayaUSDExportCommand::createSyntax()
kMaterialsScopeNameFlag,
UsdMayaJobExportArgsTokens->materialsScopeName.GetText(),
MSyntax::kString);
syntax.addFlag(
kApiSchemaFlag, UsdMayaJobExportArgsTokens->apiSchema.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(kApiSchemaFlag);
syntax.addFlag(
kJobContextFlag, UsdMayaJobExportArgsTokens->jobContext.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(kJobContextFlag);
syntax.addFlag(
kExportUVsFlag, UsdMayaJobExportArgsTokens->exportUVs.GetText(), MSyntax::kBoolean);
syntax.addFlag(
Expand Down Expand Up @@ -146,15 +152,15 @@ MSyntax MayaUSDExportCommand::createSyntax()
kCompatibilityFlag, UsdMayaJobExportArgsTokens->compatibility.GetText(), MSyntax::kString);

syntax.addFlag(kChaserFlag, UsdMayaJobExportArgsTokens->chaser.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(UsdMayaJobExportArgsTokens->chaser.GetText());
syntax.makeFlagMultiUse(kChaserFlag);

syntax.addFlag(
kChaserArgsFlag,
UsdMayaJobExportArgsTokens->chaserArgs.GetText(),
MSyntax::kString,
MSyntax::kString,
MSyntax::kString);
syntax.makeFlagMultiUse(UsdMayaJobExportArgsTokens->chaserArgs.GetText());
syntax.makeFlagMultiUse(kChaserArgsFlag);

syntax.addFlag(
kMelPerFrameCallbackFlag,
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 @@ -82,6 +82,8 @@ class MAYAUSD_CORE_PUBLIC MayaUSDExportCommand : public MPxCommand
static constexpr auto kVerboseFlag = "v";
static constexpr auto kStaticSingleSample = "sss";
static constexpr auto kGeomSidednessFlag = "gs";
static constexpr auto kApiSchemaFlag = "api";
static constexpr auto kJobContextFlag = "jc";

// Short and Long forms of flags defined by this command itself:
static constexpr auto kAppendFlag = "a";
Expand Down
7 changes: 5 additions & 2 deletions lib/mayaUsd/commands/baseImportCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ MSyntax MayaUSDImportCommand::createSyntax()
syntax.addFlag(
kApiSchemaFlag, UsdMayaJobImportArgsTokens->apiSchema.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(kApiSchemaFlag);
syntax.addFlag(
kJobContextFlag, UsdMayaJobImportArgsTokens->jobContext.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(kJobContextFlag);
syntax.addFlag(
kExcludePrimvarFlag,
UsdMayaJobImportArgsTokens->excludePrimvar.GetText(),
Expand All @@ -81,15 +84,15 @@ MSyntax MayaUSDImportCommand::createSyntax()
// Import chasers
syntax.addFlag(
kImportChaserFlag, UsdMayaJobImportArgsTokens->chaser.GetText(), MSyntax::kString);
syntax.makeFlagMultiUse(UsdMayaJobImportArgsTokens->chaser.GetText());
syntax.makeFlagMultiUse(kImportChaserFlag);

syntax.addFlag(
kImportChaserArgsFlag,
UsdMayaJobImportArgsTokens->chaserArgs.GetText(),
MSyntax::kString,
MSyntax::kString,
MSyntax::kString);
syntax.makeFlagMultiUse(UsdMayaJobImportArgsTokens->chaserArgs.GetText());
syntax.makeFlagMultiUse(kImportChaserArgsFlag);

// These are additional flags under our control.
syntax.addFlag(kFileFlag, kFileFlagLong, MSyntax::kString);
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/commands/baseImportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MAYAUSD_CORE_PUBLIC MayaUSDImportCommand : public MPxCommand
static constexpr auto kImportUSDZTexturesFilePathFlag = "itf";
static constexpr auto kMetadataFlag = "md";
static constexpr auto kApiSchemaFlag = "api";
static constexpr auto kJobContextFlag = "jc";
static constexpr auto kExcludePrimvarFlag = "epv";
static constexpr auto kUseAsAnimationCacheFlag = "uac";
static constexpr auto kImportChaserFlag = "chr";
Expand Down
156 changes: 156 additions & 0 deletions lib/mayaUsd/commands/baseListJobContextsCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
//
// Copyright 2021 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "baseListJobContextsCommand.h"

#include <mayaUsd/fileio/jobContextRegistry.h>
#include <mayaUsd/utils/util.h>

#include <maya/MArgDatabase.h>
#include <maya/MArgList.h>
#include <maya/MStatus.h>
#include <maya/MString.h>
#include <maya/MSyntax.h>

PXR_NAMESPACE_USING_DIRECTIVE

namespace MAYAUSD_NS_DEF {

namespace {

const UsdMayaJobContextRegistry::ContextInfo&
_GetInfo(const MArgDatabase& argData, const char* optionName)
{
static const UsdMayaJobContextRegistry::ContextInfo emptyInfo;
MString contextName;
MStatus status = argData.getFlagArgument(optionName, 0, contextName);
if (status != MS::kSuccess) {
return emptyInfo;
}
for (auto const& c : UsdMayaJobContextRegistry::ListExportJobContexts()) {
JGamache-autodesk marked this conversation as resolved.
Show resolved Hide resolved
auto const& info = UsdMayaJobContextRegistry::GetJobContextInfo(c);
if (info.niceName == contextName.asChar()) {
return info;
}
}
return emptyInfo;
}

const char* _exportStr = "export";
const char* _exportAnnotationStr = "exportAnnotation";
const char* _exportArgumentsStr = "exportArguments";
const char* _importStr = "import";
const char* _importAnnotationStr = "importAnnotation";
const char* _importArgumentsStr = "importArguments";
const char* _jobContextStr = "jobContext";
} // namespace

MStatus MayaUSDListJobContextsCommand::doIt(const MArgList& args)
{
MStatus status;
MArgDatabase argData(syntax(), args, &status);

if (status != MS::kSuccess) {
return status;
}

if (argData.isFlagSet(_exportStr)) {
for (auto const& c : UsdMayaJobContextRegistry::ListExportJobContexts()) {
auto const& info = UsdMayaJobContextRegistry::GetJobContextInfo(c);
appendToResult(info.niceName.GetText());
}
} else if (argData.isFlagSet(_exportAnnotationStr)) {
auto const& info = _GetInfo(argData, _exportAnnotationStr);
if (!info.jobContext.IsEmpty()) {
setResult(info.exportDescription.GetText());
}
} else if (argData.isFlagSet(_exportArgumentsStr)) {
auto const& info = _GetInfo(argData, _exportArgumentsStr);
if (info.exportEnablerCallback) {
// Would be nice to return a Python dictionary, but we need something MEL-compatible
// Use the JobContextRegistry Python wrappers to get a dictionary.
std::ostringstream optionsStream;
for (const std::pair<std::string, VtValue> keyValue : info.exportEnablerCallback()) {

bool canConvert;
std::string valueStr;
std::tie(canConvert, valueStr) = UsdMayaUtil::ValueToArgument(keyValue.second);
// Options don't handle empty arrays well preventing users from passing actual
// values for options with such default value.
if (canConvert && valueStr != "[]") {
optionsStream << keyValue.first.c_str() << "=" << valueStr.c_str() << ";";
}
}
setResult(optionsStream.str().c_str());
}
} else if (argData.isFlagSet(_importStr)) {
for (auto const& c : UsdMayaJobContextRegistry::ListImportJobContexts()) {
auto const& info = UsdMayaJobContextRegistry::GetJobContextInfo(c);
appendToResult(info.niceName.GetText());
}
} else if (argData.isFlagSet(_importAnnotationStr)) {
auto const& info = _GetInfo(argData, _importAnnotationStr);
if (!info.jobContext.IsEmpty()) {
setResult(info.importDescription.GetText());
}
} else if (argData.isFlagSet(_importArgumentsStr)) {
auto const& info = _GetInfo(argData, _importArgumentsStr);
if (info.importEnablerCallback) {
// Would be nice to return a Python dictionary, but we need something MEL-compatible
// Use the JobContextRegistry Python wrappers to get a dictionary.
std::ostringstream optionsStream;
for (const std::pair<std::string, VtValue> keyValue : info.importEnablerCallback()) {

bool canConvert;
std::string valueStr;
std::tie(canConvert, valueStr) = UsdMayaUtil::ValueToArgument(keyValue.second);
// Options don't handle empty arrays well preventing users from passing actual
// values for options with such default value.
if (canConvert && valueStr != "[]") {
optionsStream << keyValue.first.c_str() << "=" << valueStr.c_str() << ";";
}
}
setResult(optionsStream.str().c_str());
}
} else if (argData.isFlagSet(_jobContextStr)) {
auto const& info = _GetInfo(argData, _jobContextStr);
if (!info.jobContext.IsEmpty()) {
setResult(info.jobContext.GetText());
}
}

return MS::kSuccess;
}

MSyntax MayaUSDListJobContextsCommand::createSyntax()
{
MSyntax syntax;
syntax.addFlag("-ex", "-export", MSyntax::kNoArg);
syntax.addFlag("-ea", "-exportAnnotation", MSyntax::kString);
syntax.addFlag("-eg", "-exportArguments", MSyntax::kString);
syntax.addFlag("-im", "-import", MSyntax::kNoArg);
syntax.addFlag("-ia", "-importAnnotation", MSyntax::kString);
syntax.addFlag("-ig", "-importArguments", MSyntax::kString);
syntax.addFlag("-jc", "-jobContext", MSyntax::kString);

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

return syntax;
}

void* MayaUSDListJobContextsCommand::creator() { return new MayaUSDListJobContextsCommand(); }

} // namespace MAYAUSD_NS_DEF
39 changes: 39 additions & 0 deletions lib/mayaUsd/commands/baseListJobContextsCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2021 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MAYA_LIST_IO_CONTEXTS_COMMAND_H
#define MAYA_LIST_IO_CONTEXTS_COMMAND_H

#include <mayaUsd/base/api.h>

#include <pxr/pxr.h>

#include <maya/MPxCommand.h>

namespace MAYAUSD_NS_DEF {

class MAYAUSD_CORE_PUBLIC MayaUSDListJobContextsCommand : public MPxCommand
{
public:
MStatus doIt(const MArgList& args) override;
bool isUndoable() const override { return false; };

static MSyntax createSyntax();
static void* creator();
};

} // namespace MAYAUSD_NS_DEF

#endif
6 changes: 6 additions & 0 deletions lib/mayaUsd/fileio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_sources(${PROJECT_NAME}
functorPrimWriter.cpp
importData.cpp
instancedNodeWriter.cpp
jobContextRegistry.cpp
primReader.cpp
primReaderArgs.cpp
primReaderContext.cpp
Expand All @@ -17,6 +18,8 @@ target_sources(${PROJECT_NAME}
primWriterContext.cpp
primWriterRegistry.cpp
registryHelper.cpp
schemaApiAdaptor.cpp
schemaApiAdaptorRegistry.cpp
shaderReader.cpp
shaderReaderRegistry.cpp
shaderWriter.cpp
Expand Down Expand Up @@ -44,6 +47,7 @@ set(HEADERS
functorPrimWriter.h
importData.h
instancedNodeWriter.h
jobContextRegistry.h
primReader.h
primReaderArgs.h
primReaderContext.h
Expand All @@ -53,6 +57,8 @@ set(HEADERS
primWriterContext.h
primWriterRegistry.h
registryHelper.h
schemaApiAdaptor.h
schemaApiAdaptorRegistry.h
shaderReader.h
shaderReaderRegistry.h
shaderWriter.h
Expand Down
Loading