Skip to content

Commit

Permalink
Merge pull request #2218 from AnimalLogic/csyshing/add_offset_parent_…
Browse files Browse the repository at this point in the history
…matrix_support_for_exporting

[al] Added export option to merge offset parent matrix
  • Loading branch information
seando-adsk authored Apr 6, 2022
2 parents cbcd729 + a67b460 commit 4423533
Show file tree
Hide file tree
Showing 10 changed files with 607 additions and 5 deletions.
15 changes: 15 additions & 0 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/AnimationTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <maya/MItDependencyGraph.h>
#include <maya/MMatrix.h>
#include <maya/MNodeClass.h>
#include <maya/MTypes.h> // For MAYA_APP_VERSION

namespace AL {
namespace usdmaya {
Expand Down Expand Up @@ -60,15 +61,29 @@ void AnimationTranslator::exportAnimation(const ExporterParams& params)
/// maya::Dg
/// usdmaya::Dg
/// usdmaya::fileio::translator::Dg
#if MAYA_APP_VERSION > 2019
translators::TransformTranslator::copyAttributeValue(
it->first, it->second, timeCode, params.m_mergeOffsetParentMatrix);
#else
translators::DgNodeTranslator::copyAttributeValue(it->first, it->second, timeCode);
#endif
}
for (auto it = startAttribScaled; it != endAttribScaled; ++it) {
/// \todo This feels wrong. Split the DgNodeTranslator class into 3 ...
/// maya::Dg
/// usdmaya::Dg
/// usdmaya::fileio::translator::Dg
#if MAYA_APP_VERSION > 2019
translators::TransformTranslator::copyAttributeValue(
it->first,
it->second.attr,
it->second.scale,
timeCode,
params.m_mergeOffsetParentMatrix);
#else
translators::DgNodeTranslator::copyAttributeValue(
it->first, it->second.attr, it->second.scale, timeCode);
#endif
}
for (auto it = startTransformAttrib; it != endTransformAttrib; ++it) {
translators::TransformTranslator::copyAttributeValue(
Expand Down
12 changes: 12 additions & 0 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <maya/MNodeClass.h>
#include <maya/MPlugArray.h>
#include <maya/MSyntax.h>
#include <maya/MTypes.h> // For MAYA_APP_VERSION

namespace AL {
namespace usdmaya {
Expand Down Expand Up @@ -1082,6 +1083,13 @@ MStatus ExportCommand::doIt(const MArgList& args)
argData.getFlagArgument("mt", 0, m_params.m_mergeTransforms),
"ALUSDExport: Unable to fetch \"merge transforms\" argument");
}
#if MAYA_APP_VERSION > 2019
if (argData.isFlagSet("mom", &status)) {
AL_MAYA_CHECK_ERROR(
argData.getFlagArgument("mom", 0, m_params.m_mergeOffsetParentMatrix),
"ALUSDExport: Unable to fetch \"merge offset parent matrix\" argument");
}
#endif
if (argData.isFlagSet("nc", &status)) {
bool option;
argData.getFlagArgument("nc", 0, option);
Expand Down Expand Up @@ -1240,6 +1248,10 @@ MSyntax ExportCommand::createSyntax()
AL_MAYA_CHECK_ERROR2(status, errorString);
status = syntax.addFlag("-mt", "-mergeTransforms", MSyntax::kBoolean);
AL_MAYA_CHECK_ERROR2(status, errorString);
#if MAYA_APP_VERSION > 2019
status = syntax.addFlag("-mom", "-mergeOffsetParentMatrix", MSyntax::kBoolean);
AL_MAYA_CHECK_ERROR2(status, errorString);
#endif
status = syntax.addFlag("-ani", "-animation", MSyntax::kNoArg);
AL_MAYA_CHECK_ERROR2(status, errorString);
status = syntax.addFlag("-fr", "-frameRange", MSyntax::kDouble, MSyntax::kDouble);
Expand Down
6 changes: 6 additions & 0 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportParams.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <maya/MSelectionList.h>
#include <maya/MStringArray.h>
#include <maya/MTypes.h> // For MAYA_APP_VERSION

PXR_NAMESPACE_USING_DIRECTIVE

Expand Down Expand Up @@ -53,6 +54,11 @@ struct ExporterParams
bool m_mergeTransforms
= true; ///< if true, shapes will be merged into their parent transforms in the exported
///< data. If false, the transform and shape will be exported seperately
#if MAYA_APP_VERSION > 2019
bool m_mergeOffsetParentMatrix
= false; ///< if true, offset parent matrix would be merged to produce local space matrix;
///< if false, offset parent matrix would be exported separately in USD.
#endif
bool m_animation = false; ///< if true, animation will be exported.
bool m_useTimelineRange = false; ///< if true, then the export uses Maya's timeline range.
bool m_filterSample = false; ///< if true, duplicate sample of attribute will be filtered out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ MStatus ExportTranslator::writer(
params.m_dynamicAttributes = options.getBool(kDynamicAttributes);
params.m_duplicateInstances = options.getBool(kDuplicateInstances);
params.m_mergeTransforms = options.getBool(kMergeTransforms);
#if MAYA_APP_VERSION > 2019
params.m_mergeOffsetParentMatrix = options.getBool(kMergeOffsetParentMatrix);
#endif
params.m_fileName = file.fullName();
params.m_selected = mode == MPxFileTranslator::kExportActiveAccessMode;
params.m_animation = options.getBool(kAnimation);
Expand Down
10 changes: 10 additions & 0 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/fileio/ExportTranslator.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <AL/usdmaya/Api.h>
#include <AL/usdmaya/fileio/ExportParams.h>

#include <maya/MTypes.h> // For MAYA_APP_VERSION

namespace AL {
namespace usdmaya {
namespace fileio {
Expand Down Expand Up @@ -60,6 +62,10 @@ static constexpr const char* const kDuplicateInstances
= "Duplicate Instances"; ///< export instances option name
static constexpr const char* const kMergeTransforms
= "Merge Transforms"; ///< export by merging transforms and shapes option name
#if MAYA_APP_VERSION > 2019
static constexpr const char* const kMergeOffsetParentMatrix
= "Merge Offset Parent Matrix"; ///< export by merging offset parent matrix
#endif
static constexpr const char* const kAnimation = "Animation"; ///< export animation data option name
static constexpr const char* const kUseTimelineRange
= "Use Timeline Range"; ///< export using the timeline range option name
Expand Down Expand Up @@ -103,6 +109,10 @@ static MStatus specifyOptions(AL::maya::utils::FileTranslatorOptions& options)
return MS::kFailure;
if (!options.addBool(kMergeTransforms, defaultValues.m_mergeTransforms))
return MS::kFailure;
#if MAYA_APP_VERSION > 2019
if (!options.addBool(kMergeOffsetParentMatrix, defaultValues.m_mergeOffsetParentMatrix))
return MS::kFailure;
#endif
if (!options.addBool(kAnimation, defaultValues.m_animation))
return MS::kFailure;
if (!options.addBool(kUseTimelineRange, defaultValues.m_useTimelineRange))
Expand Down
Loading

0 comments on commit 4423533

Please sign in to comment.