Skip to content

Commit

Permalink
EMSUSD-1719 units prefs during import
Browse files Browse the repository at this point in the history
When using the overwrite-prefs method to change the units during import,
we need to compare with the Maya UI units, not the internal units.

(By comparison, when using the scaling method, we are scaling to
internal units.)
  • Loading branch information
pierrebai-adsk committed Oct 11, 2024
1 parent bcb5b3e commit 44bf4cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/mayaUsd/fileio/jobs/readJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,13 @@ void UsdMaya_ReadJob::_ConvertUpAxisAndUnits(const UsdStageRefPtr& stage)

// Convert units if required and different between Maya and USD.
const bool convertUnits = mArgs.unit;
conversion.mayaMetersPerUnit
= UsdMayaUtil::ConvertMDistanceUnitToUsdGeomLinearUnit(MDistance::internalUnit());
// Note: when changing preference, we need to compare to the UI units.
// When adding scaling transforms, we need to compare to internal units.
const MDistance::Unit mayaUnits
= (mArgs.axisAndUnitMethod == UsdMayaJobImportArgsTokens->overwritePrefs)
? MDistance::uiUnit()
: MDistance::internalUnit();
conversion.mayaMetersPerUnit = UsdMayaUtil::ConvertMDistanceUnitToUsdGeomLinearUnit(mayaUnits);
conversion.usdMetersPerUnit = UsdGeomGetStageMetersPerUnit(stage);
conversion.needUnitsConversion
= (convertUnits && (conversion.mayaMetersPerUnit != conversion.usdMetersPerUnit));
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/utils/utilSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ void setLayerUpAxisAndUnits(const SdfLayerRefPtr& layer)
= UsdMayaUtil::ConvertMDistanceUnitToUsdGeomLinearUnit(MDistance::internalUnit());

// Note: code similar to what UsdGeomSetStageUpAxis -> UsdStage::SetMetadata end-up doing,
// but without having to have a stage. We basically set metadat on the virtual root object
// but without having to have a stage. We basically set metadata on the virtual root object
// of the layer.
layer->SetField(
PXR_NS::SdfPath::AbsoluteRootPath(), PXR_NS::UsdGeomTokens->metersPerUnit, metersPerUnit);
Expand Down

0 comments on commit 44bf4cf

Please sign in to comment.