Skip to content

Commit

Permalink
Convert MTimeUnit to Double instead of Float.
Browse files Browse the repository at this point in the history
Include higher precision calculation for drop frame time units
  • Loading branch information
dgovil committed Dec 16, 2020
1 parent a9674ae commit 6a9f673
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 73 deletions.
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/jobs/readJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ double UsdMaya_ReadJob::timeSampleMultiplier() const { return mTimeSampleMultipl

double UsdMaya_ReadJob::_setTimeSampleMultiplierFrom(const double layerFPS)
{
float sceneFPS = UsdMayaUtil::GetSceneMTimeUnitAsFloat();
double sceneFPS = UsdMayaUtil::GetSceneMTimeUnitAsDouble();
mTimeSampleMultiplier = sceneFPS / layerFPS;
return mTimeSampleMultiplier;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/fileio/jobs/writeJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ bool UsdMaya_WriteJob::_BeginWriting(const std::string& fileName, bool append)
if (!mJobCtx.mArgs.timeSamples.empty()) {
mJobCtx.mStage->SetStartTimeCode(mJobCtx.mArgs.timeSamples.front());
mJobCtx.mStage->SetEndTimeCode(mJobCtx.mArgs.timeSamples.back());
mJobCtx.mStage->SetTimeCodesPerSecond(UsdMayaUtil::GetSceneMTimeUnitAsFloat());
mJobCtx.mStage->SetFramesPerSecond(UsdMayaUtil::GetSceneMTimeUnitAsFloat());
mJobCtx.mStage->SetTimeCodesPerSecond(UsdMayaUtil::GetSceneMTimeUnitAsDouble());
mJobCtx.mStage->SetFramesPerSecond(UsdMayaUtil::GetSceneMTimeUnitAsDouble());
}

// Setup the requested render layer mode:
Expand Down
5 changes: 3 additions & 2 deletions lib/mayaUsd/fileio/translators/translatorCurves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ bool UsdMayaTranslatorCurves::Create(

// Construct the time array to be used for all the keys
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
MTimeArray timeArray(numTimeSamples, MTime());
double timeSampleMultiplier
= (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
MTimeArray timeArray(numTimeSamples, MTime());
for (unsigned int ti = 0; ti < numTimeSamples; ++ti) {
timeArray.set(MTime(pointsTimeSamples[ti] * timeSampleMultiplier, timeUnit), ti);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/translators/translatorMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ TranslatorMeshRead::TranslatorMeshRead(

// Get the values needed to convert time to the current maya scenes framerate
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;

// Construct the time array to be used for all the keys
MTimeArray timeArray;
Expand Down
5 changes: 3 additions & 2 deletions lib/mayaUsd/fileio/translators/translatorNurbsPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ bool UsdMayaTranslatorNurbsPatch::Read(

// Construct the time array to be used for all the keys
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
MTimeArray timeArray;
double timeSampleMultiplier
= (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
MTimeArray timeArray;
timeArray.setLength(numTimeSamples);
for (unsigned int ti = 0; ti < numTimeSamples; ++ti) {
timeArray.set(MTime(pointsTimeSamples[ti] * timeSampleMultiplier, timeUnit), ti);
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/translators/translatorPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void UsdMayaTranslatorPrim::Read(
{
UsdGeomImageable primSchema(prim);
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
if (!primSchema) {
TF_CODING_ERROR("Prim %s is not UsdGeomImageable.", prim.GetPath().GetText());
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/translators/translatorSkel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ bool _CopyAnimFromSkel(
MTimeArray mayaTimes;
mayaTimes.setLength(usdTimes.size());
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
for (size_t i = 0; i < usdTimes.size(); ++i) {
mayaTimes[i] = MTime(usdTimes[i] * timeSampleMultiplier, timeUnit);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/mayaUsd/fileio/translators/translatorXformable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static bool _pushUSDXformOpToMayaXform(
const UsdMayaPrimReaderContext* context)
{
MTime::Unit timeUnit = MTime::uiUnit();
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;
double timeSampleMultiplier = (context != nullptr) ? context->GetTimeSampleMultiplier() : 1.0;

std::vector<double> xValue;
std::vector<double> yValue;
Expand Down
110 changes: 55 additions & 55 deletions lib/mayaUsd/utils/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2079,171 +2079,171 @@ void UsdMayaUtil::GetFilteredSelectionToExport(
}
}

float UsdMayaUtil::ConvertMTimeUnitToFloat(const MTime::Unit& unit)
double UsdMayaUtil::ConvertMTimeUnitToDouble(const MTime::Unit& unit)
{
float ret = 0.f;
double ret = 0.0;
switch (unit) {
case MTime::k2FPS: {
ret = 2.f;
ret = 2.0;
} break;
case MTime::k3FPS: {
ret = 3.f;
ret = 3.0;
} break;
case MTime::k4FPS: {
ret = 4.f;
ret = 4.0;
} break;
case MTime::k5FPS: {
ret = 5.f;
ret = 5.0;
} break;
case MTime::k6FPS: {
ret = 6.f;
ret = 6.0;
} break;
case MTime::k8FPS: {
ret = 8.f;
ret = 8.0;
} break;
case MTime::k10FPS: {
ret = 10.f;
ret = 10.0;
} break;
case MTime::k12FPS: {
ret = 12.f;
ret = 12.0;
} break;
case MTime::k15FPS: {
ret = 15.f;
ret = 15.0;
} break;
case MTime::k16FPS: {
ret = 16.f;
ret = 16.0;
} break;
case MTime::k20FPS: {
ret = 20.f;
ret = 20.0;
} break;
case MTime::k23_976FPS: {
ret = 23.976f;
ret = (24.0 * 1000.0) / 1001.0;
} break;
case MTime::k24FPS: {
ret = 24.f;
ret = 24.0;
} break;
case MTime::k25FPS: {
ret = 25.f;
ret = 25.0;
} break;
case MTime::k29_97FPS: {
ret = 29.97f;
ret = (30.0 * 1000.0) / 1001.0;
} break;
case MTime::k29_97DF: {
ret = 29.97f;
ret = (30.0 * 1000.0) / 1001.0;
} break;
case MTime::k30FPS: {
ret = 30.f;
ret = 30.0;
} break;
case MTime::k40FPS: {
ret = 40.f;
ret = 40.0;
} break;
case MTime::k47_952FPS: {
ret = 47.952f;
ret = (48.0 * 1000.0) / 1001.0;
} break;
case MTime::k48FPS: {
ret = 48.f;
ret = 48.0;
} break;
case MTime::k50FPS: {
ret = 50.f;
ret = 50.0;
} break;
case MTime::k59_94FPS: {
ret = 59.94f;
ret = (60.0 * 1000.0) / 100;
} break;
case MTime::k60FPS: {
ret = 60.f;
ret = 60.0;
} break;
case MTime::k75FPS: {
ret = 75.f;
ret = 75.0;
} break;
case MTime::k80FPS: {
ret = 80.f;
ret = 80.0;
} break;
#if MAYA_API_VERSION >= 20200000
case MTime::k90FPS: {
ret = 90.f;
ret = 90.0;
} break;
#endif
case MTime::k100FPS: {
ret = 100.f;
ret = 100.0;
} break;
case MTime::k120FPS: {
ret = 120.f;
ret = 120.0;
} break;
case MTime::k125FPS: {
ret = 125.f;
ret = 125.0;
} break;
case MTime::k150FPS: {
ret = 150.f;
ret = 150.0;
} break;
case MTime::k200FPS: {
ret = 200.f;
ret = 200.0;
} break;
case MTime::k240FPS: {
ret = 240.f;
ret = 240.0;
} break;
case MTime::k250FPS: {
ret = 250.f;
ret = 250.0;
} break;
case MTime::k300FPS: {
ret = 300.f;
ret = 300.0;
} break;
case MTime::k375FPS: {
ret = 375.f;
ret = 375.0;
} break;
case MTime::k400FPS: {
ret = 400.f;
ret = 400.0;
} break;
case MTime::k500FPS: {
ret = 500.f;
ret = 500.0;
} break;
case MTime::k600FPS: {
ret = 600.f;
ret = 600.0;
} break;
case MTime::k750FPS: {
ret = 750.f;
ret = 750.0;
} break;
case MTime::k1200FPS: {
ret = 1200.f;
ret = 1200.0;
} break;
case MTime::k1500FPS: {
ret = 1500.f;
ret = 1500.0;
} break;
case MTime::k2000FPS: {
ret = 2000.f;
ret = 2000.0;
} break;
case MTime::k3000FPS: {
ret = 3000.f;
ret = 3000.0;
} break;
case MTime::k6000FPS: {
ret = 6000.f;
ret = 6000.0;
} break;
case MTime::k44100FPS: {
ret = 44100.f;
ret = 44100.0;
} break;
case MTime::k48000FPS: {
ret = 48000.f;
ret = 48000.0;
} break;
case MTime::kHours: {
ret = (1.f / 3600.f);
ret = (1.0 / 3600.0);
} break;
case MTime::kMinutes: {
ret = (1.f / 60.f);
ret = (1.0 / 60.0);
} break;
case MTime::kSeconds: {
ret = 1.0f;
ret = 1.0;
} break;
case MTime::kMilliseconds: {
ret = 1000.f;
ret = 1000.0;
} break;
default: {
ret = 0.0f;
ret = 0.0;
} break;
}
return ret;
}

float UsdMayaUtil::GetSceneMTimeUnitAsFloat()
double UsdMayaUtil::GetSceneMTimeUnitAsDouble()
{
const MTime::Unit sceneUnit = MTime::uiUnit();
return UsdMayaUtil::ConvertMTimeUnitToFloat(sceneUnit);
return UsdMayaUtil::ConvertMTimeUnitToDouble(sceneUnit);
}
12 changes: 6 additions & 6 deletions lib/mayaUsd/utils/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,15 @@ void GetFilteredSelectionToExport(
MSelectionList& objectList,
UsdMayaUtil::MDagPathSet& dagPaths);

/// Coverts a given \pMTime::\pUnit enum to a \pfloat value of samples per second
/// Returns 0.0f if the result is invalid.
/// Coverts a given \pMTime::\pUnit enum to a \pdouble value of samples per second
/// Returns 0.0 if the result is invalid.
MAYAUSD_CORE_PUBLIC
float ConvertMTimeUnitToFloat(const MTime::Unit& unit);
double ConvertMTimeUnitToDouble(const MTime::Unit& unit);

/// Get's the scene's \pMTime::\pUnit as a \pfloat value of samples per second
/// Returns 0.0f if the result is invalid.
/// Get's the scene's \pMTime::\pUnit as a \pdouble value of samples per second
/// Returns 0.0 if the result is invalid.
MAYAUSD_CORE_PUBLIC
float GetSceneMTimeUnitAsFloat();
double GetSceneMTimeUnitAsDouble();

} // namespace UsdMayaUtil

Expand Down
2 changes: 1 addition & 1 deletion test/lib/usd/translators/testUsdExportLayerAttributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setUpClass(cls):
def tearDownClass(cls):
standalone.uninitialize()

def test_fps_30(self):
def test_fps(self):
fps_map = {
"ntsc": 30,
"game": 15,
Expand Down

0 comments on commit 6a9f673

Please sign in to comment.