From 2873cdb826e4eb0d566587d0ad3a241b1152e249 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Wed, 24 Mar 2021 12:06:34 +0100 Subject: [PATCH] Use convertTime for time scale of animation --- modules/base/rendering/renderablemodel.cpp | 54 ++++++++++++++-------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index 47f0b45af6..c3e113f39c 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -149,13 +150,13 @@ namespace { std::variant> geometryFile; enum class ScaleUnit { - Nanometer [[codegen::key("nm")]], - Micrometer [[codegen::key("um")]], - Millimeter [[codegen::key("mm")]], - Centimeter [[codegen::key("cm")]], - Decimeter [[codegen::key("dm")]], - Meter [[codegen::key("m")]], - Kilometer [[codegen::key("km")]] + Nanometer, + Micrometer, + Millimeter, + Centimeter, + Decimeter, + Meter, + Kilometer }; // The scale of the model. For example if the model is in centimeters @@ -173,15 +174,18 @@ namespace { // In format 'YYYY MM DD hh:mm:ss'. std::optional animationStartTime [[codegen::dateTime()]]; - enum class TimeUnit { + enum class AnimationTimeUnit { + Nanosecond, + Microsecond, Millisecond, - Second + Second, + Minute }; // The time scale for the animation relative to seconds. // Ex, if animation is in milliseconds then AnimationTimeScale = 0.001 or // AnimationTimeScale = Millisecond, default is Second - std::optional> animationTimeScale; + std::optional> animationTimeScale; enum class AnimationMode { Once, @@ -395,18 +399,32 @@ RenderableModel::RenderableModel(const ghoul::Dictionary& dictionary) if (std::holds_alternative(*p.animationTimeScale)) { _geometry->setTimeScale(std::get(*p.animationTimeScale)); } - else if (std::holds_alternative(*p.animationTimeScale)) { - Parameters::TimeUnit timeUnit = - std::get(*p.animationTimeScale); + else if (std::holds_alternative(*p.animationTimeScale)) { + Parameters::AnimationTimeUnit animationTimeUnit = + std::get(*p.animationTimeScale); + TimeUnit timeUnit; - switch (timeUnit) { - case Parameters::TimeUnit::Millisecond: - _geometry->setTimeScale(0.001); + switch (animationTimeUnit) { + case Parameters::AnimationTimeUnit::Nanosecond: + timeUnit = TimeUnit::Nanosecond; break; - case Parameters::TimeUnit::Second: - _geometry->setTimeScale(1.0); + case Parameters::AnimationTimeUnit::Microsecond: + timeUnit = TimeUnit::Microsecond; break; + case Parameters::AnimationTimeUnit::Millisecond: + timeUnit = TimeUnit::Millisecond; + break; + case Parameters::AnimationTimeUnit::Second: + timeUnit = TimeUnit::Second; + break; + case Parameters::AnimationTimeUnit::Minute: + timeUnit = TimeUnit::Minute; + break; + default: + throw ghoul::MissingCaseException(); } + + _geometry->setTimeScale(convertTime(1.0, timeUnit, TimeUnit::Second)); } }